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,6 +1,16 @@
|
||||
#ifndef GUILITE_WIDGETS_INCLUDE_BUTTON_H
|
||||
#define GUILITE_WIDGETS_INCLUDE_BUTTON_H
|
||||
|
||||
#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/bitmap.h"
|
||||
#include "../core_include/word.h"
|
||||
#include "../core_include/display.h"
|
||||
#include "../core_include/theme.h"
|
||||
|
||||
#define GL_BN_CLICKED 0x1111
|
||||
#define ON_GL_BN_CLICKED(func) \
|
||||
{MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)},
|
||||
@@ -9,13 +19,86 @@ typedef struct struct_bitmap_info BITMAP_INFO;
|
||||
class c_button : public c_wnd
|
||||
{
|
||||
protected:
|
||||
virtual void on_paint();
|
||||
virtual void on_focus();
|
||||
virtual void on_kill_focus();
|
||||
virtual void pre_create_wnd();
|
||||
virtual void on_paint()
|
||||
{
|
||||
c_rect rect;
|
||||
get_screen_rect(rect);
|
||||
|
||||
virtual void on_touch(int x, int y, TOUCH_ACTION action);
|
||||
virtual void on_key(KEY_TYPE key);
|
||||
switch (m_status)
|
||||
{
|
||||
case STATUS_NORMAL:
|
||||
m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order);
|
||||
if (m_str)
|
||||
{
|
||||
c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER);
|
||||
}
|
||||
break;
|
||||
case STATUS_FOCUSED:
|
||||
m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order);
|
||||
if (m_str)
|
||||
{
|
||||
c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER);
|
||||
}
|
||||
break;
|
||||
case STATUS_PUSHED:
|
||||
m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order);
|
||||
m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order);
|
||||
if (m_str)
|
||||
{
|
||||
c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
virtual void on_focus()
|
||||
{
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
}
|
||||
virtual void on_kill_focus()
|
||||
{
|
||||
m_status = STATUS_NORMAL;
|
||||
on_paint();
|
||||
}
|
||||
virtual void pre_create_wnd()
|
||||
{
|
||||
m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS);
|
||||
m_font_type = c_theme::get_font(FONT_DEFAULT);
|
||||
m_font_color = c_theme::get_color(COLOR_WND_FONT);
|
||||
}
|
||||
|
||||
virtual void on_touch(int x, int y, TOUCH_ACTION action)
|
||||
{
|
||||
if (action == TOUCH_DOWN)
|
||||
{
|
||||
m_parent->set_child_focus(this);
|
||||
m_status = STATUS_PUSHED;
|
||||
on_paint();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
notify_parent(GL_BN_CLICKED, 0);
|
||||
}
|
||||
}
|
||||
virtual void on_key(KEY_TYPE key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case KEY_ENTER:
|
||||
on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_DOWN);
|
||||
on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_UP);
|
||||
break;
|
||||
case KEY_FORWARD:
|
||||
case KEY_BACKWARD:
|
||||
break;
|
||||
}
|
||||
return c_wnd::on_key(key);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user