2019-08-19 16:03:27 +08:00
|
|
|
#ifndef GUILITE_WIDGETS_INCLUDE_BUTTON_H
|
|
|
|
#define GUILITE_WIDGETS_INCLUDE_BUTTON_H
|
2017-12-06 21:43:47 +08:00
|
|
|
|
2020-01-22 11:03:29 +08:00
|
|
|
#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"
|
|
|
|
|
2018-12-02 22:39:43 +08:00
|
|
|
#define GL_BN_CLICKED 0x1111
|
2019-12-17 10:45:15 +08:00
|
|
|
#define ON_GL_BN_CLICKED(func) \
|
|
|
|
{MSG_TYPE_WND, GL_BN_CLICKED, 0, msgCallback(&func)},
|
2017-12-06 21:43:47 +08:00
|
|
|
|
2018-10-04 14:30:29 +08:00
|
|
|
typedef struct struct_bitmap_info BITMAP_INFO;
|
2017-12-06 21:43:47 +08:00
|
|
|
class c_button : public c_wnd
|
|
|
|
{
|
|
|
|
protected:
|
2020-01-22 11:03:29 +08:00
|
|
|
virtual void on_paint()
|
|
|
|
{
|
|
|
|
c_rect rect;
|
|
|
|
get_screen_rect(rect);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2018-10-04 14:30:29 +08:00
|
|
|
|
2020-01-22 11:03:29 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2020-06-10 23:36:35 +08:00
|
|
|
virtual void on_navigate(NAVIGATION_KEY key)
|
2020-01-22 11:03:29 +08:00
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
2020-06-10 23:36:35 +08:00
|
|
|
case NAV_ENTER:
|
2020-01-22 11:03:29 +08:00
|
|
|
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;
|
2020-06-10 23:36:35 +08:00
|
|
|
case NAV_FORWARD:
|
|
|
|
case NAV_BACKWARD:
|
2020-01-22 11:03:29 +08:00
|
|
|
break;
|
|
|
|
}
|
2020-06-10 23:36:35 +08:00
|
|
|
return c_wnd::on_navigate(key);
|
2020-01-22 11:03:29 +08:00
|
|
|
}
|
2017-12-06 21:43:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|