mirror of
https://gitee.com/idea4good/GuiLite.git
synced 2026-01-02 04:17:19 +08:00
refactor folder
This commit is contained in:
91
workspace/widgets/button.cpp
Normal file
91
workspace/widgets/button.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
#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/surface.h"
|
||||
#include "../core_include/theme.h"
|
||||
#include "../widgets_include/button.h"
|
||||
|
||||
void c_button::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);
|
||||
}
|
||||
|
||||
void c_button::on_focus()
|
||||
{
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
}
|
||||
|
||||
void c_button::on_kill_focus()
|
||||
{
|
||||
m_status = STATUS_NORMAL;
|
||||
on_paint();
|
||||
}
|
||||
|
||||
bool c_button::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);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool c_button::on_key(KEY_TYPE key)
|
||||
{
|
||||
if (key == KEY_ENTER)
|
||||
{
|
||||
notify_parent(GL_BN_CLICKED, 0);
|
||||
return false;// Do not handle KEY_ENTER by other wnd.
|
||||
}
|
||||
return true;// Handle KEY_FOWARD/KEY_BACKWARD by parent wnd.
|
||||
}
|
||||
|
||||
void c_button::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;
|
||||
}
|
||||
}
|
||||
124
workspace/widgets/dialog.cpp
Normal file
124
workspace/widgets/dialog.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
#include "../core_include/api.h"
|
||||
#include "../core_include/rect.h"
|
||||
#include "../core_include/cmd_target.h"
|
||||
#include "../core_include/wnd.h"
|
||||
#include "../core_include/surface.h"
|
||||
#include "../core_include/display.h"
|
||||
#include "../core_include/resource.h"
|
||||
#include "../core_include/word.h"
|
||||
#include "../core_include/theme.h"
|
||||
#include "../widgets_include/dialog.h"
|
||||
|
||||
DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX];
|
||||
void c_dialog::pre_create_wnd()
|
||||
{
|
||||
m_attr = WND_ATTRIBUTION(0);// no focus/visible
|
||||
m_z_order = Z_ORDER_LEVEL_1;
|
||||
m_bg_color = GL_RGB(33, 42, 53);
|
||||
}
|
||||
|
||||
void c_dialog::on_paint()
|
||||
{
|
||||
c_rect rect;
|
||||
get_screen_rect(rect);
|
||||
m_surface->fill_rect(rect, m_bg_color, m_z_order);
|
||||
|
||||
if (m_str)
|
||||
{
|
||||
c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left+35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
c_dialog* c_dialog::get_the_dialog(c_surface* surface)
|
||||
{
|
||||
for(int i = 0; i < SURFACE_CNT_MAX; i++)
|
||||
{
|
||||
if(ms_the_dialogs[i].surface == surface)
|
||||
{
|
||||
return ms_the_dialogs[i].dialog;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int c_dialog::open_dialog(c_dialog* p_dlg, bool modal_mode)
|
||||
{
|
||||
if (0 == p_dlg)
|
||||
{
|
||||
ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
c_dialog* cur_dlg = get_the_dialog(p_dlg->get_surface());
|
||||
if (cur_dlg == p_dlg)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(cur_dlg)
|
||||
{
|
||||
cur_dlg->set_attr(WND_ATTRIBUTION(0));
|
||||
}
|
||||
|
||||
c_rect rc;
|
||||
p_dlg->get_screen_rect(rc);
|
||||
p_dlg->get_surface()->set_frame_layer_visible_rect(rc, Z_ORDER_LEVEL_1);
|
||||
|
||||
p_dlg->set_attr(modal_mode ? (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_MODAL) : (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS));
|
||||
p_dlg->show_window();
|
||||
p_dlg->set_me_the_dialog();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int c_dialog::close_dialog(c_surface* surface)
|
||||
{
|
||||
c_dialog* dlg = get_the_dialog(surface);
|
||||
|
||||
if (0 == dlg)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
c_rect rc;
|
||||
|
||||
dlg->set_attr(WND_ATTRIBUTION(0));
|
||||
surface->set_frame_layer_visible_rect(rc, dlg->m_z_order);
|
||||
|
||||
//clear the dialog
|
||||
for(int i = 0; i < SURFACE_CNT_MAX; i++)
|
||||
{
|
||||
if(ms_the_dialogs[i].surface == surface)
|
||||
{
|
||||
ms_the_dialogs[i].dialog = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
ASSERT(false);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int c_dialog::set_me_the_dialog()
|
||||
{
|
||||
c_surface* surface = get_surface();
|
||||
for(int i = 0; i < SURFACE_CNT_MAX; i++)
|
||||
{
|
||||
if(ms_the_dialogs[i].surface == surface)
|
||||
{
|
||||
ms_the_dialogs[i].dialog = this;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < SURFACE_CNT_MAX; i++)
|
||||
{
|
||||
if(ms_the_dialogs[i].surface == 0)
|
||||
{
|
||||
ms_the_dialogs[i].dialog = this;
|
||||
if(this)
|
||||
{
|
||||
ms_the_dialogs[i].surface = surface;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
ASSERT(false);
|
||||
return -2;
|
||||
}
|
||||
195
workspace/widgets/edit.cpp
Normal file
195
workspace/widgets/edit.cpp
Normal file
@@ -0,0 +1,195 @@
|
||||
#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/surface.h"
|
||||
#include "../core_include/theme.h"
|
||||
#include "../widgets_include/button.h"
|
||||
#include "../widgets_include/label.h"
|
||||
#include "../widgets_include/keyboard.h"
|
||||
#include "../widgets_include/edit.h"
|
||||
#include "../widgets_include/keyboard.h"
|
||||
#include <string.h>
|
||||
|
||||
#define IDD_KEY_BOARD 0x1
|
||||
|
||||
GL_BEGIN_MESSAGE_MAP(c_edit)
|
||||
ON_KEYBORAD_UPDATE(IDD_KEY_BOARD, c_edit::on_key_board_click)
|
||||
GL_END_MESSAGE_MAP()
|
||||
|
||||
static c_keyboard s_keyboard;
|
||||
|
||||
void c_edit::pre_create_wnd()
|
||||
{
|
||||
m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS);
|
||||
m_kb_style = STYLE_ALL_BOARD;
|
||||
m_font_type = c_theme::get_font(FONT_DEFAULT);
|
||||
m_font_color = c_theme::get_color(COLOR_WND_FONT);
|
||||
|
||||
memset(m_str_input, 0, sizeof(m_str_input));
|
||||
memset(m_str, 0, sizeof(m_str));
|
||||
set_text(c_wnd::m_str);
|
||||
}
|
||||
|
||||
void c_edit::set_text(const char* str)
|
||||
{
|
||||
if (str != 0 && strlen(str) < sizeof(m_str))
|
||||
{
|
||||
strcpy(m_str, str);
|
||||
}
|
||||
}
|
||||
|
||||
bool c_edit::on_touch(int x, int y, TOUCH_ACTION action)
|
||||
{
|
||||
(action == TOUCH_DOWN) ? on_touch_down(x, y) : on_touch_up(x, y);
|
||||
return true;
|
||||
}
|
||||
|
||||
void c_edit::on_touch_down(int x, int y)
|
||||
{
|
||||
c_rect kb_rect_relate_2_edit_parent;
|
||||
s_keyboard.get_wnd_rect(kb_rect_relate_2_edit_parent);
|
||||
kb_rect_relate_2_edit_parent.m_left += m_wnd_rect.m_left;
|
||||
kb_rect_relate_2_edit_parent.m_right += m_wnd_rect.m_left;
|
||||
kb_rect_relate_2_edit_parent.m_top += m_wnd_rect.m_top;
|
||||
kb_rect_relate_2_edit_parent.m_bottom += m_wnd_rect.m_top;
|
||||
|
||||
if (m_wnd_rect.PtInRect(x, y))
|
||||
{//click edit box
|
||||
if (STATUS_NORMAL == m_status)
|
||||
{
|
||||
m_parent->set_child_focus(this);
|
||||
}
|
||||
}
|
||||
else if (kb_rect_relate_2_edit_parent.PtInRect(x,y))
|
||||
{//click key board
|
||||
c_wnd::on_touch(x, y, TOUCH_DOWN);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (STATUS_PUSHED == m_status)
|
||||
{
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void c_edit::on_touch_up(int x, int y)
|
||||
{
|
||||
if (STATUS_FOCUSED == m_status)
|
||||
{
|
||||
m_status = STATUS_PUSHED;
|
||||
on_paint();
|
||||
}
|
||||
else if (STATUS_PUSHED == m_status)
|
||||
{
|
||||
if (m_wnd_rect.PtInRect(x,y))
|
||||
{//click edit box
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
}
|
||||
else
|
||||
{
|
||||
c_wnd::on_touch(x, y, TOUCH_UP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void c_edit::on_focus()
|
||||
{
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
}
|
||||
|
||||
void c_edit::on_kill_focus()
|
||||
{
|
||||
m_status = STATUS_NORMAL;
|
||||
on_paint();
|
||||
}
|
||||
|
||||
void c_edit::on_paint()
|
||||
{
|
||||
c_rect rect;
|
||||
get_screen_rect(rect);
|
||||
c_rect empty_rect;
|
||||
empty_rect.Empty();
|
||||
switch(m_status)
|
||||
{
|
||||
case STATUS_NORMAL:
|
||||
if (m_z_order > m_parent->get_z_order())
|
||||
{
|
||||
s_keyboard.disconnect();
|
||||
m_surface->set_frame_layer_visible_rect(empty_rect, s_keyboard.get_z_order());
|
||||
m_z_order = m_parent->get_z_order();
|
||||
m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS);
|
||||
}
|
||||
m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order);
|
||||
c_word::draw_string_in_rect(m_surface, m_parent->get_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:
|
||||
if (m_z_order > m_parent->get_z_order())
|
||||
{
|
||||
s_keyboard.disconnect();
|
||||
m_surface->set_frame_layer_visible_rect(empty_rect, s_keyboard.get_z_order());
|
||||
m_z_order = m_parent->get_z_order();
|
||||
m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS);
|
||||
}
|
||||
m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order);
|
||||
c_word::draw_string_in_rect(m_surface, m_parent->get_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:
|
||||
if (m_z_order == m_parent->get_z_order())
|
||||
{
|
||||
m_z_order++;
|
||||
m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_MODAL);
|
||||
show_keyboard();
|
||||
}
|
||||
m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order());
|
||||
m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2);
|
||||
strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) :
|
||||
c_word::draw_string_in_rect(m_surface, m_parent->get_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);
|
||||
}
|
||||
}
|
||||
|
||||
void c_edit::show_keyboard()
|
||||
{
|
||||
s_keyboard.connect(this, IDD_KEY_BOARD, m_kb_style);
|
||||
|
||||
c_rect kb_rect;
|
||||
s_keyboard.get_screen_rect(kb_rect);
|
||||
m_surface->set_frame_layer_visible_rect(kb_rect, s_keyboard.get_z_order());
|
||||
s_keyboard.show_window();
|
||||
}
|
||||
|
||||
void c_edit::on_key_board_click(unsigned int ctrl_id, long param)
|
||||
{
|
||||
switch (param)
|
||||
{
|
||||
case CLICK_CHAR:
|
||||
strcpy(m_str_input, s_keyboard.get_str());
|
||||
on_paint();
|
||||
break;
|
||||
case CLICK_ENTER:
|
||||
if (strlen(m_str_input))
|
||||
{
|
||||
memcpy(m_str, m_str_input, sizeof(m_str_input));
|
||||
}
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
break;
|
||||
case CLICK_ESC:
|
||||
memset(m_str_input, 0, sizeof(m_str_input));
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
break;
|
||||
default:
|
||||
ASSERT(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
216
workspace/widgets/gesture.cpp
Normal file
216
workspace/widgets/gesture.cpp
Normal file
@@ -0,0 +1,216 @@
|
||||
#include "../core_include/api.h"
|
||||
#include "../core_include/rect.h"
|
||||
#include "../core_include/surface.h"
|
||||
#include "../core_include/display.h"
|
||||
#include "../core_include/cmd_target.h"
|
||||
#include "../core_include/wnd.h"
|
||||
#include "../widgets_include/gesture.h"
|
||||
#include "../widgets_include/slide_group.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
//#define SWIPE_STEP 300//for arm
|
||||
#define SWIPE_STEP 10//for PC & ANDROID
|
||||
#define MOVE_THRESHOLD 10
|
||||
|
||||
c_gesture::c_gesture(c_slide_group* group)
|
||||
{
|
||||
m_slide_group = group;
|
||||
m_state = TOUCH_IDLE;
|
||||
m_down_x = m_down_y = m_move_x = m_move_y = 0;
|
||||
}
|
||||
|
||||
bool c_gesture::handle_swipe(int x, int y, TOUCH_ACTION action)
|
||||
{
|
||||
if(action == TOUCH_DOWN)//MOUSE_LBUTTONDOWN
|
||||
{
|
||||
if(m_state == TOUCH_IDLE)
|
||||
{
|
||||
m_state = TOUCH_MOVE;
|
||||
m_move_x = m_down_x = x;
|
||||
return true;
|
||||
}
|
||||
else//TOUCH_MOVE
|
||||
{
|
||||
return on_move(x);
|
||||
}
|
||||
}
|
||||
else if(action == TOUCH_UP)//MOUSE_LBUTTONUP
|
||||
{
|
||||
if(m_state == TOUCH_MOVE)
|
||||
{
|
||||
m_state = TOUCH_IDLE;
|
||||
return on_swipe(x);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
//ASSERT(false);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool c_gesture::on_move(int x)
|
||||
{
|
||||
if (m_slide_group == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (abs(x - m_move_x) < MOVE_THRESHOLD)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_slide_group->disabel_all_slide();
|
||||
m_move_x = x;
|
||||
if ((m_move_x - m_down_x) > 0)
|
||||
{
|
||||
move_right();
|
||||
}
|
||||
else
|
||||
{
|
||||
move_left();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool c_gesture::on_swipe(int x)
|
||||
{
|
||||
if (m_slide_group == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ((m_down_x == m_move_x) && (abs(x - m_down_x) < MOVE_THRESHOLD))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
m_slide_group->disabel_all_slide();
|
||||
int page = -1;
|
||||
m_move_x = x;
|
||||
if ((m_move_x - m_down_x) > 0)
|
||||
{
|
||||
page = swipe_right();
|
||||
}
|
||||
else
|
||||
{
|
||||
page = swipe_left();
|
||||
}
|
||||
if (page >= 0)
|
||||
{
|
||||
m_slide_group->set_active_slide(page);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_slide_group->set_active_slide(m_slide_group->get_active_slide_index(), false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int c_gesture::swipe_left()
|
||||
{
|
||||
if (m_slide_group == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int index = m_slide_group->get_active_slide_index();
|
||||
if((index + 1) >= MAX_PAGES ||
|
||||
m_slide_group->get_slide(index + 1) == 0 ||
|
||||
m_slide_group->get_slide(index) == 0)
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
c_surface* s1 = m_slide_group->get_slide(index + 1)->get_surface();
|
||||
c_surface* s2 = m_slide_group->get_slide(index)->get_surface();
|
||||
if (s1->get_display() != s2->get_display())
|
||||
{
|
||||
return -3;
|
||||
}
|
||||
|
||||
int step = m_down_x - m_move_x;
|
||||
c_rect rc;
|
||||
m_slide_group->get_screen_rect(rc);
|
||||
while(step < rc.Width())
|
||||
{
|
||||
s1->get_display()->swipe_surface(s2, s1, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, step);
|
||||
step += SWIPE_STEP;
|
||||
}
|
||||
if (step != rc.Width())
|
||||
{
|
||||
s1->get_display()->swipe_surface(s2, s1, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, rc.Width());
|
||||
}
|
||||
return (index + 1);
|
||||
}
|
||||
|
||||
int c_gesture::swipe_right()
|
||||
{
|
||||
if (m_slide_group == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int index = m_slide_group->get_active_slide_index();
|
||||
if(index <= 0 ||
|
||||
m_slide_group->get_slide(index - 1) == 0 ||
|
||||
m_slide_group->get_slide(index) == 0)
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
c_surface* s1 = m_slide_group->get_slide(index -1)->get_surface();
|
||||
c_surface* s2 = m_slide_group->get_slide(index)->get_surface();
|
||||
if (s1->get_display() != s2->get_display())
|
||||
{
|
||||
return -3;
|
||||
}
|
||||
|
||||
c_rect rc;
|
||||
m_slide_group->get_screen_rect(rc);
|
||||
int step = rc.Width() - (m_move_x - m_down_x);
|
||||
while(step > 0)
|
||||
{
|
||||
s1->get_display()->swipe_surface(s1, s2, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, step);
|
||||
step -= SWIPE_STEP;
|
||||
}
|
||||
if (step != 0)
|
||||
{
|
||||
s1->get_display()->swipe_surface(s1, s2, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, 0);
|
||||
}
|
||||
return (index - 1);
|
||||
}
|
||||
|
||||
void c_gesture::move_left()
|
||||
{
|
||||
int index = m_slide_group->get_active_slide_index();
|
||||
if((index + 1) >= MAX_PAGES ||
|
||||
m_slide_group->get_slide(index + 1) == 0 ||
|
||||
m_slide_group->get_slide(index) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
c_surface* s1 = m_slide_group->get_slide(index +1)->get_surface();
|
||||
c_surface* s2 = m_slide_group->get_slide(index)->get_surface();
|
||||
c_rect rc;
|
||||
m_slide_group->get_screen_rect(rc);
|
||||
if(s1->get_display() == s2->get_display())
|
||||
{
|
||||
s1->get_display()->swipe_surface(s2, s1, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, (m_down_x - m_move_x));
|
||||
}
|
||||
}
|
||||
|
||||
void c_gesture::move_right()
|
||||
{
|
||||
int index = m_slide_group->get_active_slide_index();
|
||||
if(index <= 0 ||
|
||||
m_slide_group->get_slide(index - 1) == 0 ||
|
||||
m_slide_group->get_slide(index) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
c_surface* s1 = m_slide_group->get_slide(index -1)->get_surface();
|
||||
c_surface* s2 = m_slide_group->get_slide(index)->get_surface();
|
||||
c_rect rc;
|
||||
m_slide_group->get_screen_rect(rc);
|
||||
if(s1->get_display() == s2->get_display())
|
||||
{
|
||||
s1->get_display()->swipe_surface(s1, s2, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, (rc.Width() - (m_move_x - m_down_x)));
|
||||
}
|
||||
}
|
||||
298
workspace/widgets/keyboard.cpp
Normal file
298
workspace/widgets/keyboard.cpp
Normal file
@@ -0,0 +1,298 @@
|
||||
#include "../core_include/api.h"
|
||||
#include "../core_include/rect.h"
|
||||
#include "../core_include/resource.h"
|
||||
#include "../core_include/word.h"
|
||||
#include "../core_include/cmd_target.h"
|
||||
#include "../core_include/wnd.h"
|
||||
#include "../core_include/surface.h"
|
||||
#include "../core_include/theme.h"
|
||||
#include "../widgets_include/button.h"
|
||||
#include "../widgets_include/keyboard.h"
|
||||
#include <string.h>
|
||||
|
||||
//Changing key width/height will change the width/height of keyboard
|
||||
#define KEY_WIDTH 65
|
||||
#define KEY_HEIGHT 38
|
||||
|
||||
#define KEYBOARD_WIDTH ((KEY_WIDTH + 2) * 10)
|
||||
#define KEYBOARD_HEIGHT ((KEY_HEIGHT + 2) * 4)
|
||||
#define NUM_BOARD_WIDTH ((KEY_WIDTH + 2) * 4)
|
||||
#define NUM_BOARD_HEIGHT ((KEY_HEIGHT + 2) * 4)
|
||||
|
||||
#define CAPS_WIDTH (KEY_WIDTH * 3 / 2)
|
||||
#define DEL_WIDTH (KEY_WIDTH * 3 / 2 + 1)
|
||||
#define ESC_WIDTH (KEY_WIDTH * 2 + 2)
|
||||
#define SWITCH_WIDTH (KEY_WIDTH * 3 / 2 )
|
||||
#define SPACE_WIDTH (KEY_WIDTH * 3 + 2 * 2)
|
||||
#define DOT_WIDTH (KEY_WIDTH * 3 / 2 + 3)
|
||||
#define ENTER_WIDTH (KEY_WIDTH * 2 + 2)
|
||||
|
||||
#define POS_X(c) ((KEY_WIDTH * c) + (c + 1) * 2)
|
||||
#define POS_Y(r) ((KEY_HEIGHT * r) + (r + 1) * 2)
|
||||
|
||||
static c_keyboard_button s_button_0,s_button_1, s_button_2, s_button_3, s_button_4, s_button_5, s_button_6, s_button_7, s_button_8, s_button_9;
|
||||
static c_keyboard_button s_button_A, s_button_B, s_button_C, s_button_D, s_button_E, s_button_F, s_button_G, s_button_H, s_button_I, s_button_J;
|
||||
static c_keyboard_button s_button_K, s_button_L, s_button_M, s_button_N, s_button_O, s_button_P, s_button_Q, s_button_R, s_button_S, s_button_T;
|
||||
static c_keyboard_button s_button_U, s_button_V, s_button_W, s_button_X, s_button_Y, s_button_Z;
|
||||
static c_keyboard_button s_button_dot, s_button_caps, s_button_space, s_button_enter, s_button_del, s_button_esc, s_button_num_switch;
|
||||
|
||||
WND_TREE g_key_board_children[] =
|
||||
{
|
||||
//Row 1
|
||||
{&s_button_Q, 'Q', 0, POS_X(0), POS_Y(0), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_W, 'W', 0, POS_X(1), POS_Y(0), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_E, 'E', 0, POS_X(2), POS_Y(0), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_R, 'R', 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_T, 'T', 0, POS_X(4), POS_Y(0), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_Y, 'Y', 0, POS_X(5), POS_Y(0), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_U, 'U', 0, POS_X(6), POS_Y(0), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_I, 'I', 0, POS_X(7), POS_Y(0), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_O, 'O', 0, POS_X(8), POS_Y(0), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_P, 'P', 0, POS_X(9), POS_Y(0), KEY_WIDTH, KEY_HEIGHT},
|
||||
//Row 2
|
||||
{&s_button_A, 'A', 0, ((KEY_WIDTH / 2) + POS_X(0)), POS_Y(1), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_S, 'S', 0, ((KEY_WIDTH / 2) + POS_X(1)), POS_Y(1), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_D, 'D', 0, ((KEY_WIDTH / 2) + POS_X(2)), POS_Y(1), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_F, 'F', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(1), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_G, 'G', 0, ((KEY_WIDTH / 2) + POS_X(4)), POS_Y(1), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_H, 'H', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(1), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_J, 'J', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(1), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_K, 'K', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(1), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_L, 'L', 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(1), KEY_WIDTH, KEY_HEIGHT},
|
||||
//Row 3
|
||||
{&s_button_caps, 0x14, 0, POS_X(0), POS_Y(2), CAPS_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_Z, 'Z', 0, ((KEY_WIDTH / 2) + POS_X(1)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_X, 'X', 0, ((KEY_WIDTH / 2) + POS_X(2)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_C, 'C', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_V, 'V', 0, ((KEY_WIDTH / 2) + POS_X(4)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_B, 'B', 0, ((KEY_WIDTH / 2) + POS_X(5)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_N, 'N', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_M, 'M', 0, ((KEY_WIDTH / 2) + POS_X(7)), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_del, 0x7F, 0, ((KEY_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, KEY_HEIGHT},
|
||||
//Row 4
|
||||
{&s_button_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_space, ' ', 0, ((KEY_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_dot, '.', 0, ((KEY_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, KEY_HEIGHT},
|
||||
{0,0,0,0,0,0,0}
|
||||
};
|
||||
|
||||
WND_TREE g_number_board_children[] =
|
||||
{
|
||||
{&s_button_1, '1', 0, POS_X(0), POS_Y(0), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_2, '2', 0, POS_X(1), POS_Y(0), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_3, '3', 0, POS_X(2), POS_Y(0), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_del, 0x7F, 0, POS_X(3), POS_Y(0), KEY_WIDTH, KEY_HEIGHT * 2 + 2},
|
||||
|
||||
{&s_button_4, '4', 0, POS_X(0), POS_Y(1), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_5, '5', 0, POS_X(1), POS_Y(1), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_6, '6', 0, POS_X(2), POS_Y(1), KEY_WIDTH, KEY_HEIGHT},
|
||||
|
||||
{&s_button_7, '7', 0, POS_X(0), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_8, '8', 0, POS_X(1), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_9, '9', 0, POS_X(2), POS_Y(2), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_enter,'\n', 0, POS_X(3), POS_Y(2), KEY_WIDTH, KEY_HEIGHT * 2 + 2},
|
||||
|
||||
{&s_button_esc, 0x1B, 0, POS_X(0), POS_Y(3), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_0, '0', 0, POS_X(1), POS_Y(3), KEY_WIDTH, KEY_HEIGHT},
|
||||
{&s_button_dot, '.', 0, POS_X(2), POS_Y(3), KEY_WIDTH, KEY_HEIGHT},
|
||||
{0,0,0,0,0,0,0}
|
||||
};
|
||||
|
||||
GL_BEGIN_MESSAGE_MAP(c_keyboard)
|
||||
ON_GL_BN_CLICKED('A', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('B', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('C', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('D', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('E', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('F', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('G', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('H', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('I', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('J', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('K', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('L', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('M', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('N', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('O', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('P', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('Q', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('R', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('S', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('T', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('U', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('V', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('W', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('X', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('Y', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('Z', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('0', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('1', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('2', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('3', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('4', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('5', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('6', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('7', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('8', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('9', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED(' ', c_keyboard::on_char_clicked)
|
||||
ON_GL_BN_CLICKED('.', c_keyboard::on_char_clicked)
|
||||
|
||||
ON_GL_BN_CLICKED(0x7F, c_keyboard::on_del_clicked)
|
||||
ON_GL_BN_CLICKED(0x14, c_keyboard::on_caps_clicked)
|
||||
ON_GL_BN_CLICKED('\n', c_keyboard::on_enter_clicked)
|
||||
ON_GL_BN_CLICKED(0x1B, c_keyboard::on_esc_clicked)
|
||||
GL_END_MESSAGE_MAP()
|
||||
|
||||
int c_keyboard::connect(c_wnd *user, unsigned short resource_id, KEYBOARD_STYLE style)
|
||||
{
|
||||
c_rect user_rect;
|
||||
user->get_wnd_rect(user_rect);
|
||||
if (style == STYLE_ALL_BOARD)
|
||||
{//Place keyboard at the bottom of user's parent window.
|
||||
c_rect user_parent_rect;
|
||||
user->get_parent()->get_wnd_rect(user_parent_rect);
|
||||
return c_wnd::connect(user, resource_id, 0, (0 - user_rect.m_left), (user_parent_rect.Height() - user_rect.m_top - KEYBOARD_HEIGHT), KEYBOARD_WIDTH, KEYBOARD_HEIGHT, g_key_board_children);
|
||||
}
|
||||
else if(style == STYLE_NUM_BOARD)
|
||||
{//Place keyboard below the user window.
|
||||
return c_wnd::connect(user, resource_id, 0, 0, user_rect.Height(), NUM_BOARD_WIDTH, NUM_BOARD_HEIGHT, g_number_board_children);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void c_keyboard::pre_create_wnd()
|
||||
{
|
||||
m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS);
|
||||
m_cap_status = STATUS_UPPERCASE;
|
||||
memset(m_str, 0, sizeof(m_str));
|
||||
m_str_len = 0;
|
||||
}
|
||||
|
||||
void c_keyboard::on_caps_clicked(unsigned int ctrl_id)
|
||||
{
|
||||
m_cap_status = (m_cap_status == STATUS_LOWERCASE) ? STATUS_UPPERCASE : STATUS_LOWERCASE;
|
||||
show_window();
|
||||
}
|
||||
|
||||
void c_keyboard::on_enter_clicked(unsigned int ctrl_id)
|
||||
{
|
||||
memset(m_str, 0, sizeof(m_str));
|
||||
notify_parent(KEYBORAD_CLICK, CLICK_ENTER);
|
||||
}
|
||||
|
||||
void c_keyboard::on_esc_clicked(unsigned int ctrl_id)
|
||||
{
|
||||
memset(m_str, 0, sizeof(m_str));
|
||||
notify_parent(KEYBORAD_CLICK, CLICK_ESC);
|
||||
}
|
||||
|
||||
void c_keyboard::on_del_clicked(unsigned int ctrl_id)
|
||||
{
|
||||
if (m_str_len <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_str[--m_str_len] = 0;
|
||||
notify_parent(KEYBORAD_CLICK, CLICK_CHAR);
|
||||
}
|
||||
|
||||
void c_keyboard::on_char_clicked(unsigned int ctrl_id)
|
||||
{//ctrl_id = char ascii code.
|
||||
if (m_str_len >= sizeof(m_str))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ((ctrl_id >= '0' && ctrl_id <= '9') || ctrl_id == ' ' || ctrl_id == '.')
|
||||
{
|
||||
goto InputChar;
|
||||
}
|
||||
|
||||
if (ctrl_id >= 'A' && ctrl_id <= 'Z')
|
||||
{
|
||||
if (STATUS_LOWERCASE == m_cap_status)
|
||||
{
|
||||
ctrl_id += 0x20;
|
||||
}
|
||||
goto InputChar;
|
||||
}
|
||||
ASSERT(false);
|
||||
InputChar:
|
||||
m_str[m_str_len++] = ctrl_id;
|
||||
notify_parent(KEYBORAD_CLICK, CLICK_CHAR);
|
||||
}
|
||||
|
||||
void c_keyboard::on_paint()
|
||||
{
|
||||
c_rect rect;
|
||||
get_screen_rect(rect);
|
||||
m_surface->fill_rect(rect, GL_RGB(0, 0, 0), m_z_order);
|
||||
}
|
||||
|
||||
void c_keyboard_button::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);
|
||||
break;
|
||||
case STATUS_FOCUSED:
|
||||
m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order);
|
||||
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);
|
||||
break;
|
||||
default:
|
||||
ASSERT(false);
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_resource_id == 0x14)
|
||||
{
|
||||
return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr);
|
||||
}
|
||||
else if (m_resource_id == 0x1B)
|
||||
{
|
||||
return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr);
|
||||
}
|
||||
else if (m_resource_id == ' ')
|
||||
{
|
||||
return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr);
|
||||
}
|
||||
else if (m_resource_id == '\n')
|
||||
{
|
||||
return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr);
|
||||
}
|
||||
else if (m_resource_id == '.')
|
||||
{
|
||||
return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr);
|
||||
}
|
||||
else if (m_resource_id == 0x7F)
|
||||
{
|
||||
return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr);
|
||||
}
|
||||
else if (m_resource_id == 0x90)
|
||||
{
|
||||
return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr);
|
||||
}
|
||||
|
||||
char letter[] = { 0, 0 };
|
||||
if (m_resource_id >= 'A' && m_resource_id <= 'Z')
|
||||
{
|
||||
letter[0] = (((c_keyboard*)m_parent)->get_cap_status() == STATUS_UPPERCASE) ? m_resource_id : (m_resource_id + 0x20);
|
||||
}
|
||||
else if (m_resource_id >= '0' && m_resource_id <= '9')
|
||||
{
|
||||
letter[0] = m_resource_id;
|
||||
}
|
||||
c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr);
|
||||
}
|
||||
29
workspace/widgets/label.cpp
Normal file
29
workspace/widgets/label.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "../core_include/api.h"
|
||||
#include "../core_include/rect.h"
|
||||
#include "../core_include/cmd_target.h"
|
||||
#include "../core_include/wnd.h"
|
||||
#include "../core_include/surface.h"
|
||||
#include "../core_include/resource.h"
|
||||
#include "../core_include/bitmap.h"
|
||||
#include "../core_include/theme.h"
|
||||
#include "../core_include/word.h"
|
||||
#include "../widgets_include/label.h"
|
||||
|
||||
void c_label::pre_create_wnd()
|
||||
{
|
||||
m_attr = ATTR_VISIBLE;
|
||||
m_font_color = c_theme::get_color(COLOR_WND_FONT);
|
||||
m_font_type = c_theme::get_font(FONT_DEFAULT);
|
||||
}
|
||||
|
||||
void c_label::on_paint()
|
||||
{
|
||||
c_rect rect;
|
||||
get_screen_rect(rect);
|
||||
|
||||
if (m_str)
|
||||
{
|
||||
m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, m_parent->get_bg_color(), m_z_order);
|
||||
c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, m_parent->get_bg_color(), ALIGN_LEFT | ALIGN_VCENTER);
|
||||
}
|
||||
}
|
||||
206
workspace/widgets/list_box.cpp
Normal file
206
workspace/widgets/list_box.cpp
Normal file
@@ -0,0 +1,206 @@
|
||||
#include "../core_include/api.h"
|
||||
#include "../core_include/rect.h"
|
||||
#include "../core_include/cmd_target.h"
|
||||
#include "../core_include/resource.h"
|
||||
#include "../core_include/wnd.h"
|
||||
#include "../core_include/surface.h"
|
||||
#include "../core_include/bitmap.h"
|
||||
#include "../core_include/word.h"
|
||||
#include "../core_include/theme.h"
|
||||
|
||||
#include "../widgets_include/button.h"
|
||||
#include "../widgets_include/list_box.h"
|
||||
#include <string.h>
|
||||
|
||||
#define ITEM_HEIGHT 45
|
||||
|
||||
void c_list_box::pre_create_wnd()
|
||||
{
|
||||
m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS);
|
||||
memset(m_item_array, 0, sizeof(m_item_array));
|
||||
m_item_total = 0;
|
||||
m_selected_item = 0;
|
||||
m_font_type = c_theme::get_font(FONT_DEFAULT);
|
||||
m_font_color = c_theme::get_color(COLOR_WND_FONT);
|
||||
}
|
||||
|
||||
void c_list_box::on_focus()
|
||||
{
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
}
|
||||
|
||||
void c_list_box::on_kill_focus()
|
||||
{
|
||||
m_status = STATUS_NORMAL;
|
||||
on_paint();
|
||||
}
|
||||
|
||||
void c_list_box::on_paint()
|
||||
{
|
||||
c_rect rect, empty_rect;
|
||||
get_screen_rect(rect);
|
||||
|
||||
switch(m_status)
|
||||
{
|
||||
case STATUS_NORMAL:
|
||||
if (m_z_order > m_parent->get_z_order())
|
||||
{
|
||||
m_surface->set_frame_layer_visible_rect(empty_rect, m_z_order);
|
||||
m_z_order = m_parent->get_z_order();
|
||||
m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS);
|
||||
}
|
||||
m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order);
|
||||
c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER);
|
||||
break;
|
||||
case STATUS_FOCUSED:
|
||||
if (m_z_order > m_parent->get_z_order())
|
||||
{
|
||||
m_surface->set_frame_layer_visible_rect(empty_rect, m_z_order);
|
||||
m_z_order = m_parent->get_z_order();
|
||||
m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS);
|
||||
}
|
||||
m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order);
|
||||
c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], 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);
|
||||
c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER);
|
||||
//draw list
|
||||
if (m_item_total > 0)
|
||||
{
|
||||
if (m_z_order == m_parent->get_z_order())
|
||||
{
|
||||
m_z_order++;
|
||||
}
|
||||
m_surface->set_frame_layer_visible_rect(m_list_screen_rect, m_z_order);
|
||||
m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_MODAL);
|
||||
show_list();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
bool c_list_box::on_touch(int x, int y, TOUCH_ACTION action)
|
||||
{
|
||||
(action == TOUCH_DOWN) ? on_touch_down(x, y) : on_touch_up(x, y);
|
||||
return true;
|
||||
}
|
||||
|
||||
void c_list_box::on_touch_down(int x, int y)
|
||||
{
|
||||
if (m_wnd_rect.PtInRect(x, y) )
|
||||
{//click base
|
||||
if (STATUS_NORMAL == m_status)
|
||||
{
|
||||
m_parent->set_child_focus(this);
|
||||
}
|
||||
}
|
||||
else if (m_list_wnd_rect.PtInRect(x, y))
|
||||
{//click extend list
|
||||
c_wnd::on_touch(x, y, TOUCH_DOWN);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (STATUS_PUSHED == m_status)
|
||||
{
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
notify_parent(GL_LIST_CONFIRM, m_selected_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void c_list_box::on_touch_up(int x, int y)
|
||||
{
|
||||
if (STATUS_FOCUSED == m_status)
|
||||
{
|
||||
m_status = STATUS_PUSHED;
|
||||
on_paint();
|
||||
}
|
||||
else if (STATUS_PUSHED == m_status)
|
||||
{
|
||||
if (m_wnd_rect.PtInRect(x, y))
|
||||
{//click base
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
}
|
||||
else if (m_list_wnd_rect.PtInRect(x, y))
|
||||
{//click extend list
|
||||
m_status = STATUS_FOCUSED;
|
||||
select_item((y - m_list_wnd_rect.m_top) / ITEM_HEIGHT);
|
||||
on_paint();
|
||||
notify_parent(GL_LIST_CONFIRM, m_selected_item);
|
||||
}
|
||||
else
|
||||
{
|
||||
c_wnd::on_touch(x, y, TOUCH_UP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void c_list_box::update_list_size()
|
||||
{
|
||||
m_list_wnd_rect = m_wnd_rect;
|
||||
m_list_wnd_rect.m_top = m_wnd_rect.m_bottom + 1;
|
||||
m_list_wnd_rect.m_bottom = m_list_wnd_rect.m_top + m_item_total * ITEM_HEIGHT;
|
||||
|
||||
get_screen_rect(m_list_screen_rect);
|
||||
m_list_screen_rect.m_top = m_list_screen_rect.m_bottom + 1;
|
||||
m_list_screen_rect.m_bottom = m_list_screen_rect.m_top + m_item_total * ITEM_HEIGHT;
|
||||
}
|
||||
|
||||
void c_list_box::show_list()
|
||||
{
|
||||
//draw all items
|
||||
c_rect tmp_rect;
|
||||
for (int i = 0; i < m_item_total; i++)
|
||||
{
|
||||
tmp_rect.m_left = m_list_screen_rect.m_left;
|
||||
tmp_rect.m_right = m_list_screen_rect.m_right;
|
||||
tmp_rect.m_top = m_list_screen_rect.m_top + i * ITEM_HEIGHT;
|
||||
tmp_rect.m_bottom = tmp_rect.m_top + ITEM_HEIGHT;
|
||||
|
||||
if (m_selected_item == i)
|
||||
{
|
||||
m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order);
|
||||
c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order);
|
||||
c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int c_list_box::add_item(char* str)
|
||||
{
|
||||
if (m_item_total >= MAX_ITEM_NUM)
|
||||
{
|
||||
ASSERT(false);
|
||||
return -1;
|
||||
}
|
||||
m_item_array[m_item_total++] = str;
|
||||
update_list_size();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void c_list_box::clear_item()
|
||||
{
|
||||
m_selected_item = m_item_total = 0;
|
||||
memset(m_item_array, 0, sizeof(m_item_array));
|
||||
update_list_size();
|
||||
}
|
||||
|
||||
void c_list_box::select_item(short index)
|
||||
{
|
||||
if (index < 0 || index >= m_item_total)
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
m_selected_item = index;
|
||||
}
|
||||
180
workspace/widgets/slide_group.cpp
Normal file
180
workspace/widgets/slide_group.cpp
Normal file
@@ -0,0 +1,180 @@
|
||||
#include "../core_include/api.h"
|
||||
#include "../core_include/rect.h"
|
||||
#include "../core_include/surface.h"
|
||||
#include "../core_include/display.h"
|
||||
#include "../core_include/cmd_target.h"
|
||||
#include "../core_include/wnd.h"
|
||||
#include "../core_include/surface.h"
|
||||
#include "../widgets_include/dialog.h"
|
||||
#include "../widgets_include/gesture.h"
|
||||
#include "../widgets_include/slide_group.h"
|
||||
|
||||
c_slide_group::c_slide_group()
|
||||
{
|
||||
m_gesture = new c_gesture(this);
|
||||
for(int i = 0; i < MAX_PAGES; i++)
|
||||
{
|
||||
m_slides[i] = 0;
|
||||
}
|
||||
m_active_slide_index = 0;
|
||||
}
|
||||
|
||||
int c_slide_group::set_active_slide(int index, bool is_redraw)
|
||||
{
|
||||
if(index >= MAX_PAGES || index < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if(0 == m_slides[index])
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
m_active_slide_index = index;
|
||||
|
||||
for(int i = 0; i < MAX_PAGES; i++)
|
||||
{
|
||||
if(m_slides[i] == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(i == index)
|
||||
{
|
||||
m_slides[i]->get_surface()->set_active(true);
|
||||
add_child_2_tail(m_slides[i]);
|
||||
if(is_redraw)
|
||||
{
|
||||
c_rect rc;
|
||||
get_screen_rect(rc);
|
||||
m_slides[i]->get_surface()->flush_screen(rc.m_left, rc.m_top, rc.m_right, rc.m_bottom);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_slides[i]->get_surface()->set_active(false);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int c_slide_group::add_slide(c_wnd* slide, unsigned short resource_id, short x, short y,
|
||||
short width, short height, WND_TREE* p_child_tree, Z_ORDER_LEVEL max_zorder)
|
||||
{
|
||||
if(0 == slide)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
c_surface* old_surface = get_surface();
|
||||
c_surface* new_surface = old_surface->get_display()->alloc_surface(max_zorder);
|
||||
new_surface->set_active(false);
|
||||
set_surface(new_surface);
|
||||
slide->connect(this, resource_id ,0 , x, y, width, height, p_child_tree);
|
||||
set_surface(old_surface);
|
||||
|
||||
int i = 0;
|
||||
while(i < MAX_PAGES)
|
||||
{
|
||||
if(m_slides[i] == slide)
|
||||
{//slide has lived
|
||||
ASSERT(false);
|
||||
return -2;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
//new slide
|
||||
i = 0;
|
||||
while(i < MAX_PAGES)
|
||||
{
|
||||
if(m_slides[i] == 0)
|
||||
{
|
||||
m_slides[i] = slide;
|
||||
slide->show_window();
|
||||
return 0;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
//no more slide can be add
|
||||
ASSERT(false);
|
||||
return -3;
|
||||
}
|
||||
|
||||
int c_slide_group::add_clone_silde(c_wnd* slide, unsigned short resource_id, short x, short y,
|
||||
short width, short height, WND_TREE* p_child_tree, Z_ORDER_LEVEL max_zorder)
|
||||
{
|
||||
if(0 == slide)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
c_surface* old_surface = get_surface();
|
||||
c_surface* new_surface = old_surface->get_display()->alloc_surface(max_zorder);
|
||||
new_surface->set_active(false);
|
||||
set_surface(new_surface);
|
||||
c_wnd* page_tmp = slide->connect_clone(this,resource_id,0,x,y,width,height,p_child_tree);
|
||||
set_surface(old_surface);
|
||||
|
||||
int i = 0;
|
||||
while(i < MAX_PAGES)
|
||||
{
|
||||
if(m_slides[i] == page_tmp)
|
||||
{//slide has lived
|
||||
ASSERT(false);
|
||||
return -2;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
//new slide
|
||||
i = 0;
|
||||
while(i < MAX_PAGES)
|
||||
{
|
||||
if(m_slides[i] == 0)
|
||||
{
|
||||
m_slides[i] = page_tmp;
|
||||
page_tmp->show_window();
|
||||
return 0;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
//no more slide can be add
|
||||
ASSERT(false);
|
||||
return -3;
|
||||
}
|
||||
|
||||
void c_slide_group::disabel_all_slide()
|
||||
{
|
||||
for(int i = 0; i < MAX_PAGES; i++)
|
||||
{
|
||||
if(m_slides[i])
|
||||
{
|
||||
m_slides[i]->get_surface()->set_active(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool c_slide_group::on_touch(int x, int y, TOUCH_ACTION action)
|
||||
{
|
||||
x -= m_wnd_rect.m_left;
|
||||
y -= m_wnd_rect.m_top;
|
||||
|
||||
if (m_gesture->handle_swipe(x, y, action))
|
||||
{
|
||||
if (m_slides[m_active_slide_index])
|
||||
{
|
||||
m_slides[m_active_slide_index]->on_touch(x, y, action);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool c_slide_group::on_key(KEY_TYPE key)
|
||||
{
|
||||
if (m_slides[m_active_slide_index])
|
||||
{
|
||||
m_slides[m_active_slide_index]->on_key(key);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
184
workspace/widgets/spinbox.cpp
Normal file
184
workspace/widgets/spinbox.cpp
Normal file
@@ -0,0 +1,184 @@
|
||||
#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/surface.h"
|
||||
#include "../core_include/theme.h"
|
||||
#include "../widgets_include/button.h"
|
||||
#include "../widgets_include/spinbox.h"
|
||||
|
||||
#define ARROW_BT_HEIGHT 55
|
||||
#define ID_BT_ARROW_UP 1
|
||||
#define ID_BT_ARROW_DOWN 2
|
||||
|
||||
GL_BEGIN_MESSAGE_MAP(c_spin_box)
|
||||
ON_GL_BN_CLICKED(ID_BT_ARROW_UP, c_spin_box::on_arrow_up_bt_click)
|
||||
ON_GL_BN_CLICKED(ID_BT_ARROW_DOWN, c_spin_box::on_arrow_down_bt_click)
|
||||
GL_END_MESSAGE_MAP()
|
||||
|
||||
void c_spin_box::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);
|
||||
|
||||
m_max = 6;
|
||||
m_min = 1;
|
||||
m_digit = 0;
|
||||
m_step = 1;
|
||||
|
||||
//set arrow button position.
|
||||
c_rect rect;
|
||||
get_screen_rect(rect);
|
||||
|
||||
m_bt_up_rect.m_left = rect.m_left;
|
||||
m_bt_up_rect.m_right = rect.m_left + rect.Width() / 2 - 1;
|
||||
m_bt_up_rect.m_top = rect.m_bottom + 1;
|
||||
m_bt_up_rect.m_bottom = m_bt_up_rect.m_top + ARROW_BT_HEIGHT;
|
||||
|
||||
m_bt_down_rect.m_left = rect.m_left + rect.Width() / 2;
|
||||
m_bt_down_rect.m_right = rect.m_right;
|
||||
m_bt_down_rect.m_top = rect.m_bottom + 1;
|
||||
m_bt_down_rect.m_bottom = m_bt_down_rect.m_top + ARROW_BT_HEIGHT;
|
||||
}
|
||||
|
||||
bool c_spin_box::on_touch(int x, int y, TOUCH_ACTION action)
|
||||
{
|
||||
(action == TOUCH_DOWN) ? on_touch_down(x, y) : on_touch_up(x, y);
|
||||
return c_wnd::on_touch(x, y, action);
|
||||
}
|
||||
|
||||
void c_spin_box::on_touch_down(int x, int y)
|
||||
{
|
||||
if (false == m_wnd_rect.PtInRect(x, y))
|
||||
{//maybe click on up/down arrow button
|
||||
return;
|
||||
}
|
||||
if (STATUS_NORMAL == m_status)
|
||||
{
|
||||
m_parent->set_child_focus(this);
|
||||
}
|
||||
}
|
||||
|
||||
void c_spin_box::on_touch_up(int x, int y)
|
||||
{
|
||||
if (false == m_wnd_rect.PtInRect(x, y))
|
||||
{//maybe click on up/down arrow button
|
||||
return;
|
||||
}
|
||||
|
||||
if (STATUS_FOCUSED == m_status)
|
||||
{
|
||||
m_status = STATUS_PUSHED;
|
||||
on_paint();
|
||||
}
|
||||
else if (STATUS_PUSHED == m_status)
|
||||
{
|
||||
m_value = m_cur_value;
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
notify_parent(GL_SPIN_CONFIRM, m_value);
|
||||
}
|
||||
}
|
||||
|
||||
void c_spin_box::on_focus()
|
||||
{
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
}
|
||||
|
||||
void c_spin_box::on_kill_focus()
|
||||
{
|
||||
m_cur_value = m_value;
|
||||
m_status = STATUS_NORMAL;
|
||||
on_paint();
|
||||
}
|
||||
|
||||
void c_spin_box::show_arrow_button()
|
||||
{
|
||||
m_bt_up.connect(this, ID_BT_ARROW_UP, "\xe2\x96\xb2"/*unicode of up arrow*/, 0, m_wnd_rect.Height(), m_bt_up_rect.Width(),m_bt_up_rect.Height());
|
||||
m_bt_up.show_window();
|
||||
m_bt_down.connect(this, ID_BT_ARROW_DOWN, "\xe2\x96\xbc"/*unicode of down arrow*/, m_bt_up_rect.Width(), m_wnd_rect.Height(), m_bt_down_rect.Width(),m_bt_down_rect.Height());
|
||||
m_bt_down.show_window();
|
||||
|
||||
m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_MODAL);
|
||||
}
|
||||
|
||||
void c_spin_box::hide_arrow_button()
|
||||
{
|
||||
m_bt_up.disconnect();
|
||||
m_bt_down.disconnect();
|
||||
m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS);
|
||||
}
|
||||
|
||||
void c_spin_box::on_paint()
|
||||
{
|
||||
c_rect rect, tmp_rect, empty_rect;
|
||||
get_screen_rect(rect);
|
||||
tmp_rect.m_left = rect.m_left;
|
||||
tmp_rect.m_right = rect.m_right;
|
||||
|
||||
switch(m_status)
|
||||
{
|
||||
case STATUS_NORMAL:
|
||||
if (m_z_order > m_parent->get_z_order())
|
||||
{
|
||||
hide_arrow_button();
|
||||
m_surface->set_frame_layer_visible_rect(empty_rect, m_z_order);
|
||||
m_z_order = m_parent->get_z_order();
|
||||
}
|
||||
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);
|
||||
break;
|
||||
case STATUS_FOCUSED:
|
||||
if (m_z_order > m_parent->get_z_order())
|
||||
{
|
||||
hide_arrow_button();
|
||||
m_surface->set_frame_layer_visible_rect(empty_rect, m_z_order);
|
||||
m_z_order = m_parent->get_z_order();
|
||||
}
|
||||
m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), 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_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER);
|
||||
break;
|
||||
case STATUS_PUSHED:
|
||||
if (m_z_order == m_parent->get_z_order())
|
||||
{
|
||||
m_z_order++;
|
||||
}
|
||||
tmp_rect.m_top = m_bt_down_rect.m_top;
|
||||
tmp_rect.m_bottom = m_bt_down_rect.m_bottom;
|
||||
m_surface->set_frame_layer_visible_rect(tmp_rect, m_z_order);
|
||||
show_arrow_button();
|
||||
|
||||
m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order());
|
||||
m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2);
|
||||
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_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER);
|
||||
break;
|
||||
default:
|
||||
ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
void c_spin_box::on_arrow_up_bt_click(unsigned int ctr_id)
|
||||
{
|
||||
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 c_spin_box::on_arrow_down_bt_click(unsigned int ctr_id)
|
||||
{
|
||||
if (m_cur_value - m_step < m_min)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_cur_value -= m_step;
|
||||
notify_parent(GL_SPIN_CHANGE, m_cur_value);
|
||||
on_paint();
|
||||
}
|
||||
93
workspace/widgets/table.cpp
Normal file
93
workspace/widgets/table.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "../core_include/api.h"
|
||||
#include "../core_include/resource.h"
|
||||
#include "../core_include/rect.h"
|
||||
#include "../core_include/word.h"
|
||||
#include "../core_include/surface.h"
|
||||
#include "../core_include/cmd_target.h"
|
||||
#include "../core_include/wnd.h"
|
||||
#include "../widgets_include/table.h"
|
||||
|
||||
void c_table::set_item(int row, int col, char* str, unsigned int color)
|
||||
{
|
||||
draw_item( row, col, str, color);
|
||||
}
|
||||
|
||||
void c_table::draw_item(int row, int col, const char* str, unsigned int color)
|
||||
{
|
||||
c_rect rect = get_item_rect(row, col);
|
||||
m_surface->fill_rect(rect.m_left+1, rect.m_top+1, rect.m_right-1, rect.m_bottom-1, color, m_z_order);
|
||||
c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type);
|
||||
}
|
||||
|
||||
void c_table::set_row_height(unsigned int height)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_row_num; i ++)
|
||||
{
|
||||
m_row_height[i] = height;
|
||||
}
|
||||
}
|
||||
|
||||
void c_table::set_col_width(unsigned int width)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_col_num; i ++)
|
||||
{
|
||||
m_col_width[i] = width;
|
||||
}
|
||||
}
|
||||
|
||||
int c_table::set_row_height(unsigned int index, unsigned int height)
|
||||
{
|
||||
if (m_row_num > index)
|
||||
{
|
||||
m_row_height[index] = height;
|
||||
return index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int c_table::set_col_width(unsigned int index, unsigned int width)
|
||||
{
|
||||
if (m_col_num > index)
|
||||
{
|
||||
m_col_width[index] = width;
|
||||
return index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
c_rect c_table::get_item_rect(int row, int col)
|
||||
{
|
||||
static c_rect rect;
|
||||
if (row >= MAX_ROW_NUM || col >= MAX_COL_NUM)
|
||||
{
|
||||
return rect;
|
||||
}
|
||||
|
||||
unsigned int width = 0;
|
||||
unsigned int height = 0;
|
||||
for (int i = 0; i < col; i++)
|
||||
{
|
||||
width += m_col_width[i];
|
||||
}
|
||||
for (int j = 0; j < row; j++)
|
||||
{
|
||||
height += m_row_height[j];
|
||||
}
|
||||
|
||||
c_rect wRect;
|
||||
get_screen_rect(wRect);
|
||||
|
||||
rect.m_left = wRect.m_left + width;
|
||||
rect.m_right = rect.m_left + m_col_width[col];
|
||||
if (rect.m_right > wRect.m_right)
|
||||
{
|
||||
rect.m_right = wRect.m_right;
|
||||
}
|
||||
rect.m_top = wRect.m_top + height;
|
||||
rect.m_bottom = rect.m_top + m_row_height[row];
|
||||
if (rect.m_bottom > wRect.m_bottom)
|
||||
{
|
||||
rect.m_bottom = wRect.m_bottom;
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
102
workspace/widgets/wave_buffer.cpp
Normal file
102
workspace/widgets/wave_buffer.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
#include "../core_include/api.h"
|
||||
#include "../widgets_include/wave_buffer.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
|
||||
c_wave_buffer::c_wave_buffer()
|
||||
{
|
||||
m_head = m_tail = m_min_old = m_max_old =
|
||||
m_min_older = m_max_older = m_last_data = m_read_cache_sum = m_refresh_sequence = 0;
|
||||
memset(m_wave_buf, 0, sizeof(m_wave_buf));
|
||||
memset(m_read_cache_min, 0, sizeof(m_read_cache_min));
|
||||
memset(m_read_cache_mid, 0, sizeof(m_read_cache_mid));
|
||||
memset(m_read_cache_max, 0, sizeof(m_read_cache_max));
|
||||
}
|
||||
|
||||
short c_wave_buffer::get_cnt()
|
||||
{
|
||||
return (m_tail >= m_head)?(m_tail - m_head):(m_tail - m_head + WAVE_BUFFER_LEN);
|
||||
}
|
||||
|
||||
int c_wave_buffer::write_wave_data(short data)
|
||||
{
|
||||
if ((m_tail + 1) % WAVE_BUFFER_LEN == m_head)
|
||||
{//full
|
||||
//log_out("wave buf full\n");
|
||||
return BUFFER_FULL;
|
||||
}
|
||||
m_wave_buf[m_tail] = data;
|
||||
m_tail = (m_tail + 1) % WAVE_BUFFER_LEN;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int c_wave_buffer::read_data()
|
||||
{
|
||||
if (m_head == m_tail)
|
||||
{//empty
|
||||
//log_out("wave buf empty\n");
|
||||
return BUFFER_EMPTY;
|
||||
}
|
||||
int ret = m_wave_buf[m_head];
|
||||
m_head = (m_head + 1) % WAVE_BUFFER_LEN;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int c_wave_buffer::read_wave_data_by_frame(short &max, short &min, short frame_len, unsigned int sequence, short offset)
|
||||
{
|
||||
if (m_refresh_sequence != sequence)
|
||||
{
|
||||
m_refresh_sequence = sequence;
|
||||
m_read_cache_sum = 0;
|
||||
}
|
||||
else if(offset < m_read_cache_sum)//(m_refresh_sequence == sequence && offset < m_fb_sum)
|
||||
{
|
||||
max = m_read_cache_max[offset];
|
||||
min = m_read_cache_min[offset];
|
||||
return m_read_cache_mid[offset];
|
||||
}
|
||||
|
||||
m_read_cache_sum++;
|
||||
ASSERT(m_read_cache_sum <= WAVE_READ_CACHE_LEN);
|
||||
int i, data;
|
||||
int tmp_min = m_last_data;
|
||||
int tmp_max = m_last_data;
|
||||
int mid = (m_min_old + m_max_old)>>1;
|
||||
|
||||
i = 0;
|
||||
while(i++ < frame_len)
|
||||
{
|
||||
data = read_data();
|
||||
if(BUFFER_EMPTY == data)
|
||||
{
|
||||
break;
|
||||
}
|
||||
m_last_data = data;
|
||||
|
||||
if(data < tmp_min){tmp_min = data;}
|
||||
if(data > tmp_max){tmp_max = data;}
|
||||
}
|
||||
|
||||
min = m_read_cache_min[offset] = MIN(m_min_old, MIN(tmp_min, m_min_older));
|
||||
max = m_read_cache_max[offset] = MAX(m_max_old, MAX(tmp_max, m_max_older));
|
||||
|
||||
m_min_older = m_min_old;
|
||||
m_max_older = m_max_old;
|
||||
m_min_old = tmp_min;
|
||||
m_max_old = tmp_max;
|
||||
return (m_read_cache_mid[offset] = mid);
|
||||
}
|
||||
|
||||
void c_wave_buffer::clear_data()
|
||||
{
|
||||
m_head = m_tail = 0;
|
||||
memset(m_wave_buf, 0, sizeof(m_wave_buf));
|
||||
}
|
||||
|
||||
void c_wave_buffer::reset()
|
||||
{
|
||||
m_head = m_tail;
|
||||
}
|
||||
238
workspace/widgets/wave_ctrl.cpp
Normal file
238
workspace/widgets/wave_ctrl.cpp
Normal file
@@ -0,0 +1,238 @@
|
||||
#include "../core_include/api.h"
|
||||
#include "../core_include/rect.h"
|
||||
#include "../core_include/cmd_target.h"
|
||||
#include "../core_include/wnd.h"
|
||||
#include "../core_include/surface.h"
|
||||
#include "../core_include/resource.h"
|
||||
#include "../core_include/word.h"
|
||||
#include "../widgets_include/wave_buffer.h"
|
||||
#include "../widgets_include/wave_ctrl.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define CORRECT(x, high_limit, low_limit) {\
|
||||
x = (x > high_limit) ? high_limit : x;\
|
||||
x = (x < low_limit) ? low_limit : x;\
|
||||
}while(0)
|
||||
|
||||
#define WAVE_CURSOR_WIDTH 8
|
||||
#define WAVE_LINE_WIDTH 1
|
||||
#define WAVE_MARGIN 5
|
||||
|
||||
c_wave_ctrl::c_wave_ctrl()
|
||||
{
|
||||
m_wave = 0;
|
||||
m_bg_fb = 0;
|
||||
m_wave_name_font = m_wave_unit_font = 0;
|
||||
m_wave_name = m_wave_unit = 0;
|
||||
m_max_data = 500;
|
||||
m_min_data = 0;
|
||||
m_wave_speed = 1;
|
||||
m_wave_data_rate = 0;
|
||||
m_wave_refresh_rate = 1000;
|
||||
m_frame_len_map_index = 0;
|
||||
|
||||
m_wave_name_color = m_wave_unit_color = m_wave_color = GL_RGB(255,0,0);
|
||||
m_back_color = GL_RGB(0,0,0);
|
||||
}
|
||||
|
||||
void c_wave_ctrl::on_init_children()
|
||||
{
|
||||
c_rect rect;
|
||||
get_screen_rect(rect);
|
||||
|
||||
m_wave_left = rect.m_left + WAVE_MARGIN;
|
||||
m_wave_right = rect.m_right - WAVE_MARGIN;
|
||||
m_wave_top = rect.m_top + WAVE_MARGIN;
|
||||
m_wave_bottom = rect.m_bottom - WAVE_MARGIN;
|
||||
m_wave_cursor = m_wave_left;
|
||||
|
||||
m_bg_fb = (unsigned int*)calloc(rect.Width() * rect.Height(), 4);
|
||||
}
|
||||
|
||||
void c_wave_ctrl::set_max_min(short max_data, short min_data)
|
||||
{
|
||||
m_max_data = max_data;
|
||||
m_min_data = min_data;
|
||||
}
|
||||
|
||||
void c_wave_ctrl::set_wave_in_out_rate(unsigned int data_rate, unsigned int refresh_rate)
|
||||
{
|
||||
m_wave_data_rate = data_rate;
|
||||
m_wave_refresh_rate = refresh_rate;
|
||||
int read_times_per_second = m_wave_speed * 1000 / m_wave_refresh_rate;
|
||||
|
||||
memset(m_frame_len_map, 0, sizeof(m_frame_len_map));
|
||||
for (unsigned int i = 1; i < sizeof(m_frame_len_map) + 1; i++)
|
||||
{
|
||||
m_frame_len_map[i-1] = data_rate * i / read_times_per_second - data_rate * (i-1) / read_times_per_second;
|
||||
}
|
||||
m_frame_len_map_index = 0;
|
||||
}
|
||||
|
||||
void c_wave_ctrl::set_wave_speed(unsigned int speed)
|
||||
{
|
||||
m_wave_speed = speed;
|
||||
set_wave_in_out_rate(m_wave_data_rate, m_wave_refresh_rate);
|
||||
}
|
||||
|
||||
void c_wave_ctrl::clear_data()
|
||||
{
|
||||
if(m_wave == 0)
|
||||
{
|
||||
ASSERT(false);
|
||||
return;
|
||||
}
|
||||
m_wave->clear_data();
|
||||
}
|
||||
|
||||
bool c_wave_ctrl::is_data_enough()
|
||||
{
|
||||
if(m_wave == 0)
|
||||
{
|
||||
ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
return (m_wave->get_cnt() - m_frame_len_map[m_frame_len_map_index] * m_wave_speed);
|
||||
}
|
||||
|
||||
void c_wave_ctrl::refresh_wave(unsigned char frame)
|
||||
{
|
||||
if(m_wave == 0)
|
||||
{
|
||||
ASSERT(false);
|
||||
return;
|
||||
}
|
||||
|
||||
short max, min, mid;
|
||||
for(short offset = 0; offset < m_wave_speed; offset++)
|
||||
{
|
||||
//get wave value
|
||||
mid = m_wave->read_wave_data_by_frame(max, min,
|
||||
m_frame_len_map[m_frame_len_map_index++],
|
||||
frame, offset);
|
||||
m_frame_len_map_index %= sizeof(m_frame_len_map);
|
||||
|
||||
//map to wave ctrl
|
||||
int y_min,y_max;
|
||||
if(m_max_data == m_min_data)
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
y_max = m_wave_bottom + WAVE_LINE_WIDTH - (m_wave_bottom - m_wave_top)*(min - m_min_data)/(m_max_data - m_min_data);
|
||||
y_min = m_wave_bottom - WAVE_LINE_WIDTH - (m_wave_bottom - m_wave_top)*(max - m_min_data)/(m_max_data - m_min_data);
|
||||
mid = m_wave_bottom - (m_wave_bottom - m_wave_top)*(mid - m_min_data)/(m_max_data - m_min_data);
|
||||
|
||||
CORRECT(y_min, m_wave_bottom, m_wave_top);
|
||||
CORRECT(y_max, m_wave_bottom, m_wave_top);
|
||||
CORRECT(mid, m_wave_bottom, m_wave_top);
|
||||
|
||||
if (m_wave_cursor > m_wave_right)
|
||||
{
|
||||
m_wave_cursor = m_wave_left;
|
||||
}
|
||||
draw_smooth_vline(y_min, y_max, mid, m_wave_color);
|
||||
restore_background();
|
||||
m_wave_cursor++;
|
||||
}
|
||||
}
|
||||
|
||||
void c_wave_ctrl::draw_smooth_vline(int y_min, int y_max, int mid, unsigned int rgb)
|
||||
{
|
||||
int dy = y_max - y_min;
|
||||
short r = GL_RGB_R(rgb);
|
||||
short g = GL_RGB_G(rgb);
|
||||
short b = GL_RGB_B(rgb);
|
||||
int index = (dy >> 1) + 2;
|
||||
int y;
|
||||
|
||||
m_surface->draw_pixel(m_wave_cursor, mid, rgb, m_z_order);
|
||||
|
||||
if (dy < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned char cur_r,cur_g,cur_b;
|
||||
unsigned int cur_rgb;
|
||||
for (int i = 1; i <= (dy >> 1) + 1; ++i )
|
||||
{
|
||||
if ( (mid + i) <= y_max )
|
||||
{
|
||||
y = mid + i;
|
||||
cur_r = r * (index - i) / index;
|
||||
cur_g = g * (index - i) / index;
|
||||
cur_b = b * (index - i) / index;
|
||||
cur_rgb = GL_RGB(cur_r, cur_g, cur_b);
|
||||
m_surface->draw_pixel(m_wave_cursor, y, cur_rgb, m_z_order);
|
||||
}
|
||||
if ( (mid - i) >= y_min )
|
||||
{
|
||||
y = mid - i;
|
||||
cur_r = r * (index - i) / index;
|
||||
cur_g = g * (index - i) / index;
|
||||
cur_b = b * (index - i) / index;
|
||||
cur_rgb = GL_RGB(cur_r, cur_g, cur_b);
|
||||
m_surface->draw_pixel(m_wave_cursor, y, cur_rgb, m_z_order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void c_wave_ctrl::on_paint()
|
||||
{
|
||||
c_rect rect;
|
||||
get_screen_rect(rect);
|
||||
|
||||
m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, m_back_color, m_z_order);
|
||||
|
||||
//show name
|
||||
c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT);
|
||||
//show unit
|
||||
c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT);
|
||||
|
||||
save_background();
|
||||
}
|
||||
|
||||
void c_wave_ctrl::clear_wave(void)
|
||||
{
|
||||
m_surface->fill_rect(m_wave_left, m_wave_top, m_wave_right, m_wave_bottom, m_back_color, m_z_order);
|
||||
m_wave_cursor = m_wave_left;
|
||||
}
|
||||
|
||||
void c_wave_ctrl::restore_background()
|
||||
{
|
||||
int x = m_wave_cursor + WAVE_CURSOR_WIDTH;
|
||||
if (x > m_wave_right)
|
||||
{
|
||||
x -= (m_wave_right - m_wave_left + 1);
|
||||
}
|
||||
|
||||
c_rect rect;
|
||||
get_screen_rect(rect);
|
||||
register int width = rect.Width();
|
||||
register int top = rect.m_top;
|
||||
register int left = rect.m_left;
|
||||
for (int y_pos = (m_wave_top - 1); y_pos <= (m_wave_bottom + 1); y_pos++)
|
||||
{
|
||||
(m_bg_fb) ? m_surface->draw_pixel(x, y_pos, m_bg_fb[(y_pos - top) * width + (x - left)], m_z_order) : m_surface->draw_pixel(x, y_pos, 0, m_z_order);
|
||||
}
|
||||
}
|
||||
|
||||
void c_wave_ctrl::save_background()
|
||||
{
|
||||
if (!m_bg_fb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
c_rect rect;
|
||||
get_screen_rect(rect);
|
||||
|
||||
register unsigned int* p_des = m_bg_fb;
|
||||
for (int y = rect.m_top; y <= rect.m_bottom; y++)
|
||||
{
|
||||
for (int x = rect.m_left; x <= rect.m_right; x++)
|
||||
{
|
||||
*p_des++ = m_surface->get_pixel(x, y, m_z_order);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user