GuiLite/workspace/widgets/spinbox.cpp

73 lines
1.9 KiB
C++
Raw Normal View History

#include "../core_include/api.h"
2019-08-08 12:53:31 +08:00
#include "../core_include/rect.h"
#include "../core_include/cmd_target.h"
#include "../core_include/wnd.h"
#include "../core_include/resource.h"
#include "../core_include/word.h"
#include "../core_include/surface.h"
#include "../core_include/theme.h"
#include "../widgets_include/button.h"
#include "../widgets_include/spinbox.h"
2017-12-06 21:43:47 +08:00
#define ARROW_BT_WIDTH 55
#define ID_BT_ARROW_UP 0x1111
#define ID_BT_ARROW_DOWN 0x2222
2017-12-06 21:43:47 +08:00
void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action)
{
if (action == TOUCH_UP)
{
(m_id == ID_BT_ARROW_UP) ? m_spin_box->on_arrow_up_bt_click() : m_spin_box->on_arrow_down_bt_click();
}
c_button::on_touch(x, y, action);
}
2017-12-06 21:43:47 +08:00
void c_spin_box::pre_create_wnd()
{
m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE);
m_font_type = c_theme::get_font(FONT_DEFAULT);
m_font_color = c_theme::get_color(COLOR_WND_FONT);
2017-12-06 21:43:47 +08:00
m_max = 6;
m_min = 1;
m_digit = 0;
m_step = 1;
//link arrow button position.
2017-12-06 21:43:47 +08:00
c_rect rect;
get_screen_rect(rect);
m_bt_down.m_spin_box = m_bt_up.m_spin_box = this;
m_bt_down.connect(m_parent, ID_BT_ARROW_DOWN, "-", rect.m_left - ARROW_BT_WIDTH, rect.m_top, ARROW_BT_WIDTH, rect.Height());
m_bt_up.connect(m_parent, ID_BT_ARROW_UP, "+", rect.m_right, rect.m_top, ARROW_BT_WIDTH, rect.Height());
2017-12-06 21:43:47 +08:00
}
void c_spin_box::on_paint()
{
c_rect rect;
2017-12-06 21:43:47 +08:00
get_screen_rect(rect);
m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order);
c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER);
2019-12-17 10:45:15 +08:00
}
void c_spin_box::on_arrow_up_bt_click()
2017-12-06 21:43:47 +08:00
{
2019-05-24 10:20:40 +08:00
if (m_cur_value + m_step > m_max)
2017-12-06 21:43:47 +08:00
{
2019-05-24 10:20:40 +08:00
return;
2017-12-06 21:43:47 +08:00
}
2019-05-24 10:20:40 +08:00
m_cur_value += m_step;
notify_parent(GL_SPIN_CHANGE, m_cur_value);
2019-05-24 10:20:40 +08:00
on_paint();
2017-12-06 21:43:47 +08:00
}
void c_spin_box::on_arrow_down_bt_click()
2017-12-06 21:43:47 +08:00
{
2019-05-24 10:20:40 +08:00
if (m_cur_value - m_step < m_min)
2017-12-06 21:43:47 +08:00
{
2019-05-24 10:20:40 +08:00
return;
2017-12-06 21:43:47 +08:00
}
2019-05-24 10:20:40 +08:00
m_cur_value -= m_step;
notify_parent(GL_SPIN_CHANGE, m_cur_value);
2019-05-24 10:20:40 +08:00
on_paint();
2017-12-06 21:43:47 +08:00
}