mirror of
https://gitee.com/idea4good/GuiLite.git
synced 2025-12-26 14:15:51 +08:00
!16 separate surface from c_wnd, merge core, gui into GuiLite
This commit is contained in:
96
widgets/src/button.cpp
Normal file
96
widgets/src/button.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#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_style = GL_ATTR_VISIBLE | GL_ATTR_FOCUS | ALIGN_HCENTER | ALIGN_VCENTER;
|
||||
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();
|
||||
}
|
||||
|
||||
void c_button::on_touch_down(int x, int y)
|
||||
{
|
||||
get_parent()->set_focus(this);
|
||||
m_status = STATUS_PUSHED;
|
||||
on_paint();
|
||||
}
|
||||
|
||||
void c_button::on_touch_up(int x, int y)
|
||||
{
|
||||
if (STATUS_PUSHED == m_status)
|
||||
{
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
|
||||
notify_parent(GL_BN_CLICKED, get_id(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void c_button::on_paint()
|
||||
{
|
||||
c_rect rect;
|
||||
get_screen_rect(rect);
|
||||
|
||||
switch(m_status)
|
||||
{
|
||||
case STATUS_NORMAL:
|
||||
if (m_bitmap_normal)
|
||||
{
|
||||
c_bitmap::draw_bitmap_in_rect(m_surface, m_z_order, m_bitmap_normal, rect, m_style);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order);
|
||||
}
|
||||
break;
|
||||
case STATUS_FOCUSED:
|
||||
if (m_bitmap_focus)
|
||||
{
|
||||
c_bitmap::draw_bitmap_in_rect(m_surface, m_z_order, m_bitmap_focus, rect, m_style);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order);
|
||||
}
|
||||
break;
|
||||
case STATUS_PUSHED:
|
||||
if (m_bitmap_pushed)
|
||||
{
|
||||
c_bitmap::draw_bitmap_in_rect(m_surface, m_z_order, m_bitmap_pushed, rect, m_style);
|
||||
}
|
||||
else
|
||||
{
|
||||
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_str)
|
||||
{
|
||||
c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_style);
|
||||
}
|
||||
}
|
||||
173
widgets/src/dialog.cpp
Normal file
173
widgets/src/dialog.cpp
Normal file
@@ -0,0 +1,173 @@
|
||||
#include "core_include/api.h"
|
||||
#include "core_include/rect.h"
|
||||
#include "core_include/cmd_target.h"
|
||||
#include "core_include/wnd.h"
|
||||
#include "core_include/msg.h"
|
||||
#include "core_include/surface.h"
|
||||
#include "core_include/display.h"
|
||||
#include "core_include/resource.h"
|
||||
#include "core_include/bitmap.h"
|
||||
#include "core_include/word.h"
|
||||
#include "core_include/theme.h"
|
||||
#include "../widgets_include/button.h"
|
||||
#include "../widgets_include/dialog.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
DIALOG_ARRAY c_dialog::ms_the_dialogs[SURFACE_CNT_MAX];
|
||||
void c_dialog::pre_create_wnd()
|
||||
{
|
||||
m_style = GL_ATTR_FOCUS;
|
||||
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 NULL;
|
||||
}
|
||||
|
||||
int c_dialog::open_dialog(c_dialog* p_dlg)
|
||||
{
|
||||
if (NULL == 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->modify_style(0, GL_ATTR_VISIBLE);
|
||||
}
|
||||
|
||||
c_rect rc;
|
||||
p_dlg->get_screen_rect(rc);
|
||||
p_dlg->get_surface()->set_frame_layer(rc, Z_ORDER_LEVEL_1);
|
||||
|
||||
p_dlg->modify_style(GL_ATTR_VISIBLE, 0);
|
||||
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 (NULL == dlg)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
c_rect rc;
|
||||
|
||||
dlg->modify_style(0, GL_ATTR_VISIBLE);
|
||||
surface->set_frame_layer(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 = NULL;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
ASSERT(FALSE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void c_dialog::on_touch_down(int x, int y)
|
||||
{
|
||||
c_wnd *child = m_top_child;
|
||||
c_rect rect;
|
||||
get_wnd_rect(rect);
|
||||
|
||||
if ( NULL != child )
|
||||
{
|
||||
while ( child )
|
||||
{
|
||||
if (child->m_z_order > m_z_order)
|
||||
{
|
||||
x -= rect.m_left;
|
||||
y -= rect.m_top;
|
||||
child->on_touch_down(x, y);
|
||||
return;
|
||||
}
|
||||
child = child->m_next_sibling;
|
||||
}
|
||||
}
|
||||
c_wnd::on_touch_down(x, y);
|
||||
}
|
||||
|
||||
void c_dialog::on_touch_up(int x, int y)
|
||||
{
|
||||
c_wnd *child = m_top_child;
|
||||
c_rect rect;
|
||||
get_wnd_rect(rect);
|
||||
if ( NULL != child )
|
||||
{
|
||||
while ( child )
|
||||
{
|
||||
if (child->m_z_order > m_z_order)
|
||||
{
|
||||
x -= rect.m_left;
|
||||
y -= rect.m_top;
|
||||
return child->on_touch_up(x, y);
|
||||
}
|
||||
child = child->m_next_sibling;
|
||||
}
|
||||
}
|
||||
c_wnd::on_touch_up(x, y);
|
||||
}
|
||||
|
||||
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 == NULL)
|
||||
{
|
||||
ms_the_dialogs[i].dialog = this;
|
||||
if(this)
|
||||
{
|
||||
ms_the_dialogs[i].surface = surface;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
ASSERT(FALSE);
|
||||
return -2;
|
||||
}
|
||||
206
widgets/src/edit.cpp
Normal file
206
widgets/src/edit.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/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/edit.h"
|
||||
#include "../widgets_include/keyboard.h"
|
||||
#include <string.h>
|
||||
|
||||
#define IDD_ALL_KEY_BOARD 0x5012
|
||||
#define IDD_NUM_KEY_BOARD 0x5013
|
||||
|
||||
GL_BEGIN_MESSAGE_MAP(c_edit)
|
||||
ON_KEYBORAD_UPDATE(IDD_ALL_KEY_BOARD, c_edit::on_key_board_click)
|
||||
ON_KEYBORAD_UPDATE(IDD_NUM_KEY_BOARD, c_edit::on_key_board_click)
|
||||
GL_END_MESSAGE_MAP()
|
||||
|
||||
static c_keyboard s_keyboard;
|
||||
|
||||
void c_edit::pre_create_wnd()
|
||||
{
|
||||
m_style = GL_ATTR_VISIBLE | GL_ATTR_FOCUS | ALIGN_HCENTER | ALIGN_VCENTER | KEY_BOARD_STYLE;
|
||||
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));
|
||||
}
|
||||
|
||||
void c_edit::set_text(const char* str)
|
||||
{
|
||||
if (str != NULL && strlen(str) < sizeof(m_str))
|
||||
{
|
||||
strcpy(m_str, str);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
get_parent()->set_focus(this);
|
||||
}
|
||||
}
|
||||
else if (kb_rect_relate_2_edit_parent.PtInRect(x,y))
|
||||
{//click key board
|
||||
c_wnd::on_touch_down(x, y);
|
||||
}
|
||||
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_up(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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(empty_rect, s_keyboard.get_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);
|
||||
break;
|
||||
case STATUS_FOCUSED:
|
||||
if (m_z_order > m_parent->get_z_order())
|
||||
{
|
||||
s_keyboard.disconnect();
|
||||
m_surface->set_frame_layer(empty_rect, s_keyboard.get_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);
|
||||
break;
|
||||
case STATUS_PUSHED:
|
||||
if (m_z_order == m_parent->get_z_order())
|
||||
{
|
||||
m_z_order++;
|
||||
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);
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
if (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, GL_ARGB(0, 0, 0, 0), m_style);
|
||||
}
|
||||
else
|
||||
{
|
||||
c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_style);
|
||||
}
|
||||
}
|
||||
|
||||
void c_edit::show_keyboard()
|
||||
{
|
||||
if (s_keyboard.get_id())
|
||||
{
|
||||
ASSERT(FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((get_style()&KEY_BOARD_STYLE) == KEY_BOARD_STYLE )
|
||||
{
|
||||
s_keyboard.set_style(STYLE_ALL_BOARD);
|
||||
s_keyboard.connect(this, IDD_ALL_KEY_BOARD);
|
||||
}
|
||||
else
|
||||
{
|
||||
s_keyboard.set_style(STYLE_NUM_BOARD);
|
||||
s_keyboard.connect(this, IDD_NUM_KEY_BOARD);
|
||||
}
|
||||
|
||||
c_rect kb_rect;
|
||||
s_keyboard.get_screen_rect(kb_rect);
|
||||
m_surface->set_frame_layer(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;
|
||||
}
|
||||
}
|
||||
252
widgets/src/gesture.cpp
Normal file
252
widgets/src/gesture.cpp
Normal file
@@ -0,0 +1,252 @@
|
||||
#include "core_include/api.h"
|
||||
#include "core_include/msg.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 FLIP_STEP 300//for arm
|
||||
#define FLIP_STEP 10//for PC & ANDROID
|
||||
#define MOVE_THRESHOLD 10
|
||||
|
||||
void* c_gesture::task_handle_msg(void* param)
|
||||
{
|
||||
c_gesture* This = (c_gesture*)param;
|
||||
MSG_INFO msg;
|
||||
while(1)
|
||||
{
|
||||
This->m_hid_fifo->read(&msg, sizeof(msg));
|
||||
if(This->handle_flip(msg))
|
||||
{
|
||||
This->handle_hid_msg(msg);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
c_gesture::c_gesture(c_wnd* root, c_slide_group* group, c_fifo* hid_fifo)
|
||||
{
|
||||
m_root = root;
|
||||
m_slide_group = group;
|
||||
m_hid_fifo = hid_fifo;
|
||||
m_action = TOUCH_IDLE;
|
||||
m_down_x = m_down_y = m_move_x = m_move_y = 0;
|
||||
|
||||
unsigned long pid;
|
||||
create_thread(&pid, NULL, task_handle_msg, this);
|
||||
}
|
||||
|
||||
bool c_gesture::handle_flip(MSG_INFO &msg)
|
||||
{
|
||||
int x = msg.dwParam1;
|
||||
|
||||
if(msg.dwMsgId == 0x4700)//MOUSE_LBUTTONDOWN
|
||||
{
|
||||
if(m_action == TOUCH_IDLE)
|
||||
{
|
||||
m_action = TOUCH_MOVE;
|
||||
m_move_x = m_down_x = x;
|
||||
return true;
|
||||
}
|
||||
else//TOUCH_MOVE
|
||||
{
|
||||
return on_move(x);
|
||||
}
|
||||
}
|
||||
else if(msg.dwMsgId == 0x4600)//MOUSE_LBUTTONUP
|
||||
{
|
||||
if(m_action == TOUCH_MOVE)
|
||||
{
|
||||
m_action = TOUCH_IDLE;
|
||||
return on_flip(x);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
//ASSERT(false);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool c_gesture::on_move(int x)
|
||||
{
|
||||
if (m_slide_group == NULL)
|
||||
{
|
||||
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_flip(int x)
|
||||
{
|
||||
if (m_slide_group == NULL)
|
||||
{
|
||||
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 = flip_right();
|
||||
}
|
||||
else
|
||||
{
|
||||
page = flip_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::flip_left()
|
||||
{
|
||||
if (m_slide_group == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int index = m_slide_group->get_active_slide_index();
|
||||
if((index + 1) >= MAX_PAGES ||
|
||||
m_slide_group->get_slide(index + 1) == NULL ||
|
||||
m_slide_group->get_slide(index) == NULL)
|
||||
{
|
||||
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()->merge_surface(s2, s1, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, step);
|
||||
step += FLIP_STEP;
|
||||
}
|
||||
if (step != rc.Width())
|
||||
{
|
||||
s1->get_display()->merge_surface(s2, s1, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, rc.Width());
|
||||
}
|
||||
return (index + 1);
|
||||
}
|
||||
|
||||
int c_gesture::flip_right()
|
||||
{
|
||||
if (m_slide_group == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int index = m_slide_group->get_active_slide_index();
|
||||
if(index <= 0 ||
|
||||
m_slide_group->get_slide(index - 1) == NULL ||
|
||||
m_slide_group->get_slide(index) == NULL)
|
||||
{
|
||||
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()->merge_surface(s1, s2, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, step);
|
||||
step -= FLIP_STEP;
|
||||
}
|
||||
if (step != 0)
|
||||
{
|
||||
s1->get_display()->merge_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) == NULL ||
|
||||
m_slide_group->get_slide(index) == NULL)
|
||||
{
|
||||
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()->merge_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) == NULL ||
|
||||
m_slide_group->get_slide(index) == NULL)
|
||||
{
|
||||
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()->merge_surface(s1, s2, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, (rc.Width() - (m_move_x - m_down_x)));
|
||||
}
|
||||
}
|
||||
|
||||
void c_gesture::handle_hid_msg(MSG_INFO &msg)
|
||||
{
|
||||
switch(msg.dwMsgId)
|
||||
{
|
||||
case 0x4700://MOUSE_LBUTTONDOWN
|
||||
m_root->on_touch_down(msg.dwParam1, msg.dwParam2);
|
||||
break;
|
||||
case 0x4600://MOUSE_LBUTTONUP
|
||||
m_root->on_touch_up(msg.dwParam1, msg.dwParam2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
290
widgets/src/keyboard.cpp
Normal file
290
widgets/src/keyboard.cpp
Normal file
@@ -0,0 +1,290 @@
|
||||
#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>
|
||||
|
||||
#define KEYBOARD_WIDTH (1024 * 2 / 3 - 10)//change this will change every key proportional
|
||||
#define KEYBOARD_HEIGHT 165
|
||||
#define NUM_BOARD_WIDTH (65 * 4 + 2 * 5)
|
||||
#define NUM_BOARD_HEIGHT (38 * 4 + 2 * 5)
|
||||
|
||||
#define CHAR_HEIGHT ((KEYBOARD_HEIGHT - 5* 2) / 4)
|
||||
#define CHAR_WIDTH ((KEYBOARD_WIDTH - 11 * 2) / 10)
|
||||
|
||||
#define CAPS_WIDTH (CHAR_WIDTH * 3 / 2)
|
||||
#define DEL_WIDTH (CHAR_WIDTH * 3 / 2 + 1)
|
||||
#define ESC_WIDTH (CHAR_WIDTH * 2 + 2)
|
||||
#define SWITCH_WIDTH (CHAR_WIDTH * 3 / 2 )
|
||||
#define SPACE_WIDTH (CHAR_WIDTH * 3 + 2 * 2)
|
||||
#define DOT_WIDTH (CHAR_WIDTH * 3 / 2 + 3)
|
||||
#define ENTER_WIDTH (CHAR_WIDTH * 2 + 2)
|
||||
|
||||
#define POS_X(c) ((CHAR_WIDTH * c) + (c + 1) * 2)
|
||||
#define POS_Y(r) ((CHAR_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), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_W, 'W', 0, POS_X(1), POS_Y(0), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_E, 'E', 0, POS_X(2), POS_Y(0), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_R, 'R', 0, POS_X(3), POS_Y(0), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_T, 'T', 0, POS_X(4), POS_Y(0), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_Y, 'Y', 0, POS_X(5), POS_Y(0), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_U, 'U', 0, POS_X(6), POS_Y(0), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_I, 'I', 0, POS_X(7), POS_Y(0), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_O, 'O', 0, POS_X(8), POS_Y(0), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_P, 'P', 0, POS_X(9), POS_Y(0), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
//Row 2
|
||||
{&s_button_A, 'A', 0, ((CHAR_WIDTH / 2) + POS_X(0)), POS_Y(1), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_S, 'S', 0, ((CHAR_WIDTH / 2) + POS_X(1)), POS_Y(1), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_D, 'D', 0, ((CHAR_WIDTH / 2) + POS_X(2)), POS_Y(1), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_F, 'F', 0, ((CHAR_WIDTH / 2) + POS_X(3)), POS_Y(1), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_G, 'G', 0, ((CHAR_WIDTH / 2) + POS_X(4)), POS_Y(1), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_H, 'H', 0, ((CHAR_WIDTH / 2) + POS_X(5)), POS_Y(1), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_J, 'J', 0, ((CHAR_WIDTH / 2) + POS_X(6)), POS_Y(1), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_K, 'K', 0, ((CHAR_WIDTH / 2) + POS_X(7)), POS_Y(1), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_L, 'L', 0, ((CHAR_WIDTH / 2) + POS_X(8)), POS_Y(1), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
//Row 3
|
||||
{&s_button_caps, 0x14, 0, POS_X(0), POS_Y(2), CAPS_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_Z, 'Z', 0, ((CHAR_WIDTH / 2) + POS_X(1)), POS_Y(2), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_X, 'X', 0, ((CHAR_WIDTH / 2) + POS_X(2)), POS_Y(2), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_C, 'C', 0, ((CHAR_WIDTH / 2) + POS_X(3)), POS_Y(2), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_V, 'V', 0, ((CHAR_WIDTH / 2) + POS_X(4)), POS_Y(2), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_B, 'B', 0, ((CHAR_WIDTH / 2) + POS_X(5)), POS_Y(2), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_N, 'N', 0, ((CHAR_WIDTH / 2) + POS_X(6)), POS_Y(2), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_M, 'M', 0, ((CHAR_WIDTH / 2) + POS_X(7)), POS_Y(2), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_del, 0x7F, 0, ((CHAR_WIDTH / 2) + POS_X(8)), POS_Y(2), DEL_WIDTH, CHAR_HEIGHT},
|
||||
//Row 4
|
||||
{&s_button_esc, 0x1B, 0, POS_X(0), POS_Y(3), ESC_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_num_switch, 0x90, 0, POS_X(2), POS_Y(3), SWITCH_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_space, ' ', 0, ((CHAR_WIDTH / 2) + POS_X(3)), POS_Y(3), SPACE_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_dot, '.', 0, ((CHAR_WIDTH / 2) + POS_X(6)), POS_Y(3), DOT_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_enter, '\n', 0, POS_X(8), POS_Y(3), ENTER_WIDTH, CHAR_HEIGHT},
|
||||
{NULL,0,0,0,0,0,0}
|
||||
};
|
||||
|
||||
WND_TREE g_number_board_children[] =
|
||||
{
|
||||
{&s_button_1, '1', 0, POS_X(0), POS_Y(0), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_2, '2', 0, POS_X(1), POS_Y(0), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_3, '3', 0, POS_X(2), POS_Y(0), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_del, 0x7F, 0, POS_X(3), POS_Y(0), CHAR_WIDTH, CHAR_HEIGHT * 2 + 2},
|
||||
|
||||
{&s_button_4, '4', 0, POS_X(0), POS_Y(1), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_5, '5', 0, POS_X(1), POS_Y(1), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_6, '6', 0, POS_X(2), POS_Y(1), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
|
||||
{&s_button_7, '7', 0, POS_X(0), POS_Y(2), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_8, '8', 0, POS_X(1), POS_Y(2), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_9, '9', 0, POS_X(2), POS_Y(2), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_enter,'\n', 0, POS_X(3), POS_Y(2), CHAR_WIDTH, CHAR_HEIGHT * 2 + 2},
|
||||
|
||||
{&s_button_esc, 0x1B, 0, POS_X(0), POS_Y(3), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_0, '0', 0, POS_X(1), POS_Y(3), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{&s_button_dot, '.', 0, POS_X(2), POS_Y(3), CHAR_WIDTH, CHAR_HEIGHT},
|
||||
{NULL,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)
|
||||
{
|
||||
c_rect user_rect;
|
||||
user->get_wnd_rect(user_rect);
|
||||
if (m_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, NULL, (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(m_style == STYLE_NUM_BOARD)
|
||||
{//Place keyboard below the user window.
|
||||
return c_wnd::connect(user, resource_id, NULL, 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_style = GL_ATTR_VISIBLE | GL_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, get_id(), CLICK_ENTER);
|
||||
}
|
||||
|
||||
void c_keyboard::on_esc_clicked(unsigned int ctrl_id)
|
||||
{
|
||||
memset(m_str, 0, sizeof(m_str));
|
||||
notify_parent(KEYBORAD_CLICK, get_id(), 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, get_id(), 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, get_id(), CLICK_CHAR);
|
||||
}
|
||||
|
||||
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_style);
|
||||
}
|
||||
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_style);
|
||||
}
|
||||
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_style);
|
||||
}
|
||||
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_style);
|
||||
}
|
||||
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_style);
|
||||
}
|
||||
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_style);
|
||||
}
|
||||
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_style);
|
||||
}
|
||||
|
||||
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_style);
|
||||
}
|
||||
30
widgets/src/label.cpp
Normal file
30
widgets/src/label.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#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_style = GL_ATTR_VISIBLE | ALIGN_LEFT | ALIGN_VCENTER;
|
||||
m_font_color = GL_RGB(255,255,255);
|
||||
|
||||
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, get_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, GL_ARGB(0, 0, 0, 0), m_style);
|
||||
}
|
||||
}
|
||||
205
widgets/src/list_box.cpp
Normal file
205
widgets/src/list_box.cpp
Normal file
@@ -0,0 +1,205 @@
|
||||
#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_style = GL_ATTR_VISIBLE | GL_ATTR_FOCUS | ALIGN_HCENTER | ALIGN_VCENTER;
|
||||
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);
|
||||
empty_rect.Empty();
|
||||
|
||||
switch(m_status)
|
||||
{
|
||||
case STATUS_NORMAL:
|
||||
if (m_z_order > m_parent->get_z_order())
|
||||
{
|
||||
m_surface->set_frame_layer(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);
|
||||
break;
|
||||
case STATUS_FOCUSED:
|
||||
if (m_z_order > m_parent->get_z_order())
|
||||
{
|
||||
m_surface->set_frame_layer(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);
|
||||
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(m_list_screen_rect, m_z_order);
|
||||
show_list();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
break;
|
||||
}
|
||||
c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER);
|
||||
|
||||
if (m_item_total)
|
||||
{
|
||||
c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_style);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
get_parent()->set_focus(this);
|
||||
}
|
||||
}
|
||||
else if (m_list_wnd_rect.PtInRect(x, y))
|
||||
{//click extend list
|
||||
c_wnd::on_touch_down(x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (STATUS_PUSHED == m_status)
|
||||
{
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
notify_parent(GL_LIST_CONFIRM, get_id(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void c_list_box::on_touch_up(int x, int y)
|
||||
{
|
||||
if (STATUS_FOCUSED == m_status)
|
||||
{
|
||||
m_status = STATUS_PUSHED;
|
||||
on_paint();
|
||||
notify_parent(GL_LIST_SELECT, get_id(), 0);
|
||||
}
|
||||
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, get_id(), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
c_wnd::on_touch_up(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
m_surface->fill_rect(m_list_screen_rect, GL_RGB(17, 17, 17), m_z_order);
|
||||
//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;
|
||||
c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER);
|
||||
m_surface->draw_hline(tmp_rect.m_left, tmp_rect.m_right, tmp_rect.m_bottom, GL_RGB(99, 108, 124), m_z_order);
|
||||
}
|
||||
//draw selected item
|
||||
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 + m_selected_item * ITEM_HEIGHT;
|
||||
tmp_rect.m_bottom = tmp_rect.m_top + ITEM_HEIGHT;
|
||||
|
||||
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[m_selected_item], tmp_rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), 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;
|
||||
}
|
||||
155
widgets/src/slide_group.cpp
Normal file
155
widgets/src/slide_group.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
#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/slide_group.h"
|
||||
|
||||
c_slide_group::c_slide_group()
|
||||
{
|
||||
for(int i = 0; i < MAX_PAGES; i++)
|
||||
{
|
||||
m_slides[i] = NULL;
|
||||
}
|
||||
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] == NULL)
|
||||
{
|
||||
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_scrren(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(NULL == slide)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
c_surface* old_surface = get_surface();
|
||||
c_surface* new_surface = old_surface->get_display()->alloc_surface(slide,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] == NULL)
|
||||
{
|
||||
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(NULL == slide)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
c_surface* old_surface = get_surface();
|
||||
c_surface* new_surface = old_surface->get_display()->alloc_surface(slide,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] == NULL)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
m_active_child = NULL;
|
||||
}
|
||||
218
widgets/src/spinbox.cpp
Normal file
218
widgets/src/spinbox.cpp
Normal file
@@ -0,0 +1,218 @@
|
||||
#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_style = GL_ATTR_VISIBLE | GL_ATTR_FOCUS | ALIGN_HCENTER | ALIGN_VCENTER;
|
||||
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;
|
||||
}
|
||||
|
||||
void c_spin_box::on_touch_down(int x, int y)
|
||||
{
|
||||
c_rect arrow_rect = m_wnd_rect;
|
||||
arrow_rect.m_right = m_bt_down_rect.m_right;
|
||||
arrow_rect.m_bottom = m_bt_down_rect.m_bottom;
|
||||
|
||||
if ( TRUE == m_wnd_rect.PtInRect(x, y) )
|
||||
{//click spin box
|
||||
if (STATUS_NORMAL == m_status)
|
||||
{
|
||||
get_parent()->set_focus(this);
|
||||
}
|
||||
}
|
||||
else if (TRUE == arrow_rect.PtInRect(x, y))
|
||||
{//click arrow button
|
||||
c_wnd::on_touch_down(x, y);
|
||||
}
|
||||
else
|
||||
{//click invalid place.
|
||||
if (STATUS_PUSHED == m_status)
|
||||
{
|
||||
if (m_value != m_cur_value)
|
||||
{
|
||||
m_value = m_cur_value;
|
||||
}
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
notify_parent(GL_SPIN_CONFIRM, get_id(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void c_spin_box::on_touch_up(int x, int y)
|
||||
{
|
||||
if (STATUS_FOCUSED == m_status)
|
||||
{
|
||||
m_status = STATUS_PUSHED;
|
||||
on_paint();
|
||||
notify_parent(GL_SPIN_SELECT, get_id(), 0);
|
||||
}
|
||||
else if (STATUS_PUSHED == m_status)
|
||||
{
|
||||
if (m_wnd_rect.PtInRect(x, y))
|
||||
{//click spin box.
|
||||
if (m_value != m_cur_value)
|
||||
{
|
||||
m_value = m_cur_value;
|
||||
}
|
||||
m_status = STATUS_FOCUSED;
|
||||
on_paint();
|
||||
notify_parent(GL_SPIN_CONFIRM, get_id(), 0);
|
||||
}
|
||||
else
|
||||
{//click arrow button.
|
||||
c_wnd::on_touch_up(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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_surface->fill_rect(m_bt_up_rect.m_left, m_bt_up_rect.m_top, m_bt_down_rect.m_right, m_bt_down_rect.m_bottom, GL_RGB(99,108,124), m_z_order);
|
||||
|
||||
m_bt_up.connect(this, ID_BT_ARROW_UP, 0, 0, m_wnd_rect.Height(), m_bt_up_rect.Width(),m_bt_up_rect.Height());
|
||||
m_bt_up.set_bitmap(c_theme::get_bmp(BITMAP_UP_ARROW1));
|
||||
m_bt_up.set_focus_bitmap(c_theme::get_bmp(BITMAP_UP_ARROW2));
|
||||
m_bt_up.set_pushed_bitmap(c_theme::get_bmp(BITMAP_UP_ARROW2));
|
||||
m_bt_up.show_window();
|
||||
|
||||
m_bt_down.connect(this, ID_BT_ARROW_DOWN, 0, m_bt_up_rect.Width(), m_wnd_rect.Height(), m_bt_down_rect.Width(),m_bt_down_rect.Height());
|
||||
m_bt_down.set_bitmap(c_theme::get_bmp(BITMAP_DOWN_ARROW1));
|
||||
m_bt_down.set_focus_bitmap(c_theme::get_bmp(BITMAP_DOWN_ARROW2));
|
||||
m_bt_down.set_pushed_bitmap(c_theme::get_bmp(BITMAP_DOWN_ARROW2));
|
||||
m_bt_down.show_window();
|
||||
}
|
||||
|
||||
void c_spin_box::hide_arrow_button()
|
||||
{
|
||||
m_bt_up.disconnect();
|
||||
m_bt_down.disconnect();
|
||||
}
|
||||
|
||||
void c_spin_box::on_paint()
|
||||
{
|
||||
c_rect rect,tmp_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();
|
||||
tmp_rect.Empty();
|
||||
m_surface->set_frame_layer(tmp_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);
|
||||
break;
|
||||
case STATUS_FOCUSED:
|
||||
if (m_z_order > m_parent->get_z_order())
|
||||
{
|
||||
hide_arrow_button();
|
||||
tmp_rect.Empty();
|
||||
m_surface->set_frame_layer(tmp_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);
|
||||
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(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, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), m_style);
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
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, GL_ARGB(0, 0, 0, 0), m_style);
|
||||
}
|
||||
|
||||
void c_spin_box::on_arrow_up_bt_click(unsigned int ctr_id)
|
||||
{
|
||||
m_cur_value += m_step;
|
||||
if (m_cur_value > m_max)
|
||||
{
|
||||
m_cur_value = m_max;
|
||||
}
|
||||
else
|
||||
{
|
||||
on_paint();
|
||||
}
|
||||
}
|
||||
|
||||
void c_spin_box::on_arrow_down_bt_click(unsigned int ctr_id)
|
||||
{
|
||||
m_cur_value -= m_step;
|
||||
if (m_cur_value < m_min)
|
||||
{
|
||||
m_cur_value = m_min;
|
||||
}
|
||||
else
|
||||
{
|
||||
on_paint();
|
||||
}
|
||||
}
|
||||
93
widgets/src/table.cpp
Normal file
93
widgets/src/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
widgets/src/wave_buffer.cpp
Normal file
102
widgets/src/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
widgets/src/wave_ctrl.cpp
Normal file
238
widgets/src/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 = NULL;
|
||||
m_bg_fb = NULL;
|
||||
m_wave_name_font = m_wave_unit_font = NULL;
|
||||
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 == NULL)
|
||||
{
|
||||
ASSERT(FALSE);
|
||||
return;
|
||||
}
|
||||
m_wave->clear_data();
|
||||
}
|
||||
|
||||
bool c_wave_ctrl::is_data_enough()
|
||||
{
|
||||
if(m_wave == NULL)
|
||||
{
|
||||
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 == NULL)
|
||||
{
|
||||
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