|
本帖最后由 gck 于 2022-9-6 17:31 编辑
关于guix按键,同一页面下两个按键,点击按键1,按键1和按键2文本内容都变化
有用到gx_widget_text_id_draw相关函数,未实现功能?请教有实现方法没?
纯粹是官网例子更改的,实际为秒表的例子,只是打算新加一个分段的功能,代码和视频如下,附件所示;
#define STOPWATCH_TIMER 10
static GX_VALUE minute = 0;
static GX_VALUE second = 0;
static GX_VALUE ticks = 0;
GX_RESOURCE_ID start_stop_text_id = GX_STRING_ID_START;//开始
GX_RESOURCE_ID reset_section_text_id = GX_STRING_ID_RESET;//开始
void stopwatch_reset();
void stopwatch_update();
//回调函数
UINT stopwatch_event_handler(GX_WINDOW *window, GX_EVENT *event_ptr)
{
switch(event_ptr -> gx_event_type){
case GX_SIGNAL(ID_START_STOP, GX_EVENT_CLICKED):
if (start_stop_text_id == GX_STRING_ID_START){//开始
start_stop_text_id = GX_STRING_ID_STOP; //暂停
reset_section_text_id = GX_STRING_ID_SECTION;//分段
gx_system_timer_start(window, STOPWATCH_TIMER, 1, 1);
}else{//暂停
start_stop_text_id = GX_STRING_ID_START;
reset_section_text_id = GX_STRING_ID_RESET;
gx_system_timer_stop(window, STOPWATCH_TIMER);
}
break;
case GX_SIGNAL(ID_RESET, GX_EVENT_CLICKED):
if(reset_section_text_id == GX_STRING_ID_RESET){//清空
stopwatch_reset();
gx_system_timer_stop(window, STOPWATCH_TIMER);
}else{//分段
//列表插入数据
}
break;
case GX_EVENT_TIMER:
if (event_ptr -> gx_event_payload.gx_event_timer_id == STOPWATCH_TIMER){
stopwatch_update();
}
break;
case GX_EVENT_HIDE:
gx_system_timer_stop(window, STOPWATCH_TIMER);
start_stop_text_id = GX_STRING_ID_START;
reset_section_text_id = GX_STRING_ID_RESET;
gx_window_event_process(window, event_ptr);
break;
default:
break;
}
return screen_template_event_process(window, event_ptr);
}
VOID stopwatch_pixelmap_button_draw(GX_PIXELMAP_BUTTON *widget)
{
INT x_offset = 0;
INT y_offset = 0;
GX_PIXELMAP *map;
GX_RESOURCE_ID text_id;
//获取正常下的id
gx_context_pixelmap_get(widget->gx_pixelmap_button_normal_id, &map);
if (widget->gx_widget_style & GX_STYLE_BUTTON_PUSHED){
x_offset++;
y_offset++;
}
if (map){
gx_canvas_pixelmap_draw(widget->gx_widget_size.gx_rectangle_left + x_offset,
widget->gx_widget_size.gx_rectangle_top + y_offset, map);
}
switch (widget->gx_widget_id){
case ID_START_STOP:
text_id = start_stop_text_id; //开始
break;
case ID_RESET:
text_id = reset_section_text_id;//重置
break;
}
gx_widget_text_id_draw((GX_WIDGET *)widget, widget->gx_widget_normal_fill_color,
GX_FONT_ID_CHINESE, text_id, x_offset - 2, y_offset - 2);
}
//秒表重置
void stopwatch_reset()
{
ticks = 0;
second = 0;
minute = 0;
gx_prompt_text_id_set(&my_stopwatch.my_stopwatch_msz, GX_STRING_ID_ZERO);
gx_prompt_text_id_set(&my_stopwatch.my_stopwatch_mz, GX_STRING_ID_ZERO);
gx_prompt_text_id_set(&my_stopwatch.my_stopwatch_fz, GX_STRING_ID_ZERO);
start_stop_text_id = GX_STRING_ID_START;
gx_system_dirty_mark((GX_WIDGET *)&my_stopwatch.my_stopwatch_start_stop);
}
//秒表更新
void stopwatch_update()
{
GX_CHAR string_buffer[3];
GX_STRING string;
int ms;
string.gx_string_ptr = string_buffer;
string.gx_string_length = 2;
if (ticks < GX_TICKS_SECOND){
ticks++;
ms = ticks * GX_SYSTEM_TIMER_MS / 10;
gx_utility_ltoa(ms / 10, string_buffer, 2);
gx_utility_ltoa(ms % 10, string_buffer + 1, 2);
gx_prompt_text_set_ext(&my_stopwatch.my_stopwatch_msz, &string);
}else if(second < 59){
ticks = 0;
second ++;
gx_prompt_text_id_set(&my_stopwatch.my_stopwatch_msz, GX_STRING_ID_ZERO);
gx_utility_ltoa(second / 10, string_buffer, 2);
gx_utility_ltoa(second % 10, string_buffer + 1, 2);
gx_prompt_text_set_ext(&my_stopwatch.my_stopwatch_mz, &string);
}else if(minute < 59){
second = 0;
minute ++;
gx_prompt_text_id_set(&my_stopwatch.my_stopwatch_fz, GX_STRING_ID_ZERO);
gx_utility_ltoa(minute / 10, string_buffer, 2);
gx_utility_ltoa(minute % 10, string_buffer + 1, 2);
gx_prompt_text_set_ext(&my_stopwatch.my_stopwatch_fz, &string);
}else {
minute = 0;
gx_prompt_text_id_set(&my_stopwatch.my_stopwatch_fz, GX_STRING_ID_ZERO);
}
}
|
|