mirror of
https://gitee.com/idea4good/GuiLite.git
synced 2026-01-02 12:27:22 +08:00
!27 Support header-only
This commit is contained in:
@@ -1,7 +1,20 @@
|
||||
#ifndef GUILITE_WIDGETS_INCLUDE_SPINBOX_H
|
||||
#define GUILITE_WIDGETS_INCLUDE_SPINBOX_H
|
||||
|
||||
#define GL_SPIN_CHANGE 0x3333
|
||||
#include "../core_include/api.h"
|
||||
#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/display.h"
|
||||
#include "../core_include/theme.h"
|
||||
#include "../widgets_include/button.h"
|
||||
|
||||
#define ARROW_BT_WIDTH 55
|
||||
#define ID_BT_ARROW_UP 0x1111
|
||||
#define ID_BT_ARROW_DOWN 0x2222
|
||||
#define GL_SPIN_CHANGE 0x3333
|
||||
|
||||
#define ON_SPIN_CHANGE(func) \
|
||||
{MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)},
|
||||
@@ -10,7 +23,7 @@ class c_spin_box;
|
||||
class c_spin_button : public c_button
|
||||
{
|
||||
friend class c_spin_box;
|
||||
virtual void on_touch(int x, int y, TOUCH_ACTION action);
|
||||
inline virtual void on_touch(int x, int y, TOUCH_ACTION action);
|
||||
c_spin_box* m_spin_box;
|
||||
};
|
||||
|
||||
@@ -29,10 +42,51 @@ public:
|
||||
short get_value_digit() { return m_digit; }
|
||||
|
||||
protected:
|
||||
virtual void on_paint();
|
||||
virtual void pre_create_wnd();
|
||||
void on_arrow_up_bt_click();
|
||||
void on_arrow_down_bt_click();
|
||||
virtual void on_paint()
|
||||
{
|
||||
c_rect rect;
|
||||
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);
|
||||
}
|
||||
virtual void 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);
|
||||
m_max = 6;
|
||||
m_min = 1;
|
||||
m_digit = 0;
|
||||
m_step = 1;
|
||||
|
||||
//link arrow button position.
|
||||
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());
|
||||
}
|
||||
void on_arrow_up_bt_click()
|
||||
{
|
||||
if (m_cur_value + m_step > m_max)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_cur_value += m_step;
|
||||
notify_parent(GL_SPIN_CHANGE, m_cur_value);
|
||||
on_paint();
|
||||
}
|
||||
void on_arrow_down_bt_click()
|
||||
{
|
||||
if (m_cur_value - m_step < m_min)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_cur_value -= m_step;
|
||||
notify_parent(GL_SPIN_CHANGE, m_cur_value);
|
||||
on_paint();
|
||||
}
|
||||
|
||||
short m_cur_value;
|
||||
short m_value;
|
||||
@@ -44,4 +98,12 @@ protected:
|
||||
c_spin_button m_bt_down;
|
||||
};
|
||||
|
||||
inline 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);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user