我想用快速层显示刚刚输入的字符,vre 3.0 实例代码input如下:
void handle_sysevt(VMINT message, VMINT param)
{
switch(message)
{
case VM_MSG_CREATE:
screen_width = vm_graphic_get_screen_width();
screen_height = vm_graphic_get_screen_height();
character_height = vm_graphic_get_character_height();
layer_hdl[0] = vm_graphic_create_layer(0, 0, screen_width, screen_height, -1);
break;
case VM_MSG_PAINT:
draw_screen();
break;
/* this message will be triggered when call input function */
case VM_MSG_INACTIVE:
vm_graphic_delete_layer(layer_hdl[0]);
break;
/* this message will be triggered when come back from input window */
case VM_MSG_ACTIVE:
layer_hdl[0] = vm_graphic_create_layer(0, 0, screen_width, screen_height, -1);
/* layer_buf[0] = vm_graphic_get_layer_buffer(layer_hdl[0]);*/
break;
case VM_MSG_QUIT:
vm_graphic_delete_layer(layer_hdl[0]);
vm_exit_app();
break;
}
}
input函数和回调就不用说了。
void draw_screen(void)
{
VMWCHAR w_softkey_text[8];
VMINT string_width;
layer_buf[0] = vm_graphic_get_layer_buffer(layer_hdl[0]);
vm_graphic_fill_rect(layer_buf[0], 0, 0, screen_width, screen_height, VM_COLOR_BLACK, VM_COLOR_BLACK);
vm_graphic_fill_rect(layer_buf[0], 0, 0, screen_width, screen_height / 2, VM_COLOR_RED, VM_COLOR_WHITE);
/*draw input text*/
draw_text_in_rect(layer_buf[0], w_text, 2, 2, screen_width, screen_height / 2, VM_COLOR_BLACK);
/*draw soft key*/
vm_gb2312_to_ucs2(w_softkey_text, 8, softkey_text[0]);
vm_graphic_textout(layer_buf[0], 2, screen_height - character_height - 2, w_softkey_text, wstrlen(w_softkey_text), VM_COLOR_WHITE);
vm_gb2312_to_ucs2(w_softkey_text, 8, softkey_text[1]);
string_width = vm_graphic_get_string_width(w_softkey_text);
vm_graphic_textout(layer_buf[0], screen_width - string_width - 2, screen_height - character_height - 2, w_softkey_text, wstrlen(w_softkey_text), VM_COLOR_WHITE);
vm_graphic_flush_layer(layer_hdl, 1);
}
以上是正常的!!!!
但是,问题来了:
我想在快速层上显示该输入的字符串;将handle_sysevt()修改如下:
void handle_sysevt(VMINT message, VMINT param)
{
switch(message)
{
case VM_MSG_CREATE:
screen_width = vm_graphic_get_screen_width();
screen_height = vm_graphic_get_screen_height();
character_height = vm_graphic_get_character_height();
layer_hdl[0] = vm_graphic_create_layer(0, 0, screen_width, screen_height, -1);
layer_hdl[1] = vm_graphic_create_layer(0, 0, screen_width, screen_height, 0xFFFD);
break;
case VM_MSG_PAINT:
draw_screen();
break;
/* this message will be triggered when call input function */
case VM_MSG_INACTIVE:
vm_graphic_delete_layer(layer_hdl[1]);
vm_graphic_delete_layer(layer_hdl[0]);
break;
/* this message will be triggered when come back from input window */
case VM_MSG_ACTIVE:
layer_hdl[0] = vm_graphic_create_layer(0, 0, screen_width, screen_height, -1);
layer_hdl[1] = vm_graphic_create_layer(0, 0, screen_width, screen_height, 0xFFFD);
break;
case VM_MSG_QUIT:
vm_graphic_delete_layer(layer_hdl[1]);
vm_graphic_delete_layer(layer_hdl[0]);
vm_exit_app();
break;
}
}
void draw_screen(void)
{
VMWCHAR w_softkey_text[8];
VMINT string_width;
layer_buf[1] = vm_graphic_get_layer_buffer(layer_hdl[1]);//快速层声明
vm_graphic_fill_rect(layer_buf[1], 0, 0, screen_width, screen_height, VM_COLOR_BLACK, VM_COLOR_BLACK);
vm_graphic_fill_rect(layer_buf[1], 0, 0, screen_width, screen_height / 2, VM_COLOR_RED, VM_COLOR_WHITE);
/*draw input text*/
draw_text_in_rect(layer_buf[1], w_text, 2, 2, screen_width, screen_height / 2, VM_COLOR_BLACK);//输出到快速层上
/*draw soft key*/
vm_gb2312_to_ucs2(w_softkey_text, 8, softkey_text[0]);
vm_graphic_textout(layer_buf[1], 2, screen_height - character_height - 2, w_softkey_text, wstrlen(w_softkey_text), VM_COLOR_WHITE);
vm_gb2312_to_ucs2(w_softkey_text, 8, softkey_text[1]);
string_width = vm_graphic_get_string_width(w_softkey_text);
vm_graphic_textout(layer_buf[1], screen_width - string_width - 2, screen_height - character_height - 2, w_softkey_text, wstrlen(w_softkey_text), VM_COLOR_WHITE);
vm_graphic_flush_layer(layer_hdl, 2);//将两层合并在一起刷屏,注意,如果刷一层的话,估计将只刷掉了基层;
}
结果:输进去了,单步运行可以看到输入的东西。但是显示不出来!!!!!!!!
到drawscreen()函数体内,w_text的内容还正常,却显示不出来...........
还有一个问题是:有时候,input输入框,并不能触发inactive这个系统事件。
什么原因?太诡异了............