uc/gui重绘机制

本文介绍uC/GUI环境下控件如何通过WM_Exec()或WM_Paint()进行绘制更新,并探讨了控件属性变化时的重绘机制。此外还讨论了在嵌入式应用中使用动态内存时,uC/GUI如何通过句柄引用管理控件内存,避免了内存碎片问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一个控件根据它的特性绘制自己。这一工作通过调用WMAPI函数WM_Exec()来完成。如果在程序中没有调用WM_Exec(),就必须调用WM_Paint函数来绘制控件。在多任务环境的uC/GUI,一个后台任务通常用于调用WM_Exec()并更新控件(及其它所有带有回调函数的窗口)。这样就不必手动的调用WM_Paint();然而,手工调用仍然是合法的,如果你想保证控件能立即内重绘的话,这样做也没有意义。

当一个控件的属性的改变时,控件的窗口(或者它的一部分)被标记为无效,但是它不会立即重绘。因此,这部分代码运行非常快。重绘在后面的时间通过WM完成,或通过为控件调用WM_Paint函数(或者WM_Exec(),直到所有的窗口都被重绘)来强制执行。

用于控件的动态存储器

      在嵌入式应用当中,通常来说,使用动态存储器确实不是非常合适,因为存储残片效果的缘故。有很多不同的方式可以用来这种情况,但是它们都工作在一个受限制的方式里,随时内存区域都可能被应用程序中的一个指针引用。因为这个原因,uC/GUI使用一个不同的方法:所有物体(以及所有在运行时存储的数据)被存入一个句柄引用的内存区域当中。这会使以分配好的内存区域在运行时重新分配成为可能。因而避免了使用指针时出现的长时间分配的问题。所有控件因此通过句柄引用。

static int UI_MainThread(void* arg)//线程入口函数 { int ret = 0; WM_HWIN handle = 0; //basic gui init ret = GUI_Init(); if(ret < 0) { Error("GUI Init Failed\n"); return -1; } //user config init WM_MULTIBUF_Enable(1); GUI_AA_SetFactor(4); GUI_UC_EnableBIDI(1); GUI_UC_SetEncodeUTF8(); //first window handle = UI_WindowHomeCreate(WM_HBKWIN); UI_HomeWindowSet(handle); //main loop for paint and display while(1) { GUI_Delay(10); } return 1; } /****************************************************************************** function : touch event process thread arguments : thread info return : fail < 0,ok >= 0 ******************************************************************************/ static int UI_TouchThread(void* arg) { int ret = 0; int32_t touch_fb = -1; WM_MESSAGE Msg; struct input_event touch_event; TOUCH_DATA touch_info; int first_touch = 0; touch_fb = open("/dev/input/event0", O_RDONLY); if(touch_fb < 0) { Error("open touch dev failed = %d\n", touch_fb ); return -1; } Log(UI_LOG_NORMAL, "touch event open ok\n"); while(1) { ret = read(touch_fb, &touch_event, sizeof(touch_event)); if(ret != sizeof(touch_event)) { Error("no touch\n"); continue; } //Log(UI_LOG_NORMAL, "touch info:%d, %d, %d\n", // touch_event.type, touch_event.code, touch_event.value); switch(touch_event.type) { case EV_ABS: if (ABS_X == touch_event.code) { touch_info.x = touch_event.value; } else if (ABS_Y == touch_event.code) { touch_info.y = touch_event.value; if(UI_HomeWindowGet() != UI_ActiveWindowGet()) { if (touch_info.y<=UI_WINDOW_CHILD_Y) { touch_info.y = 0; } else { touch_info.y -= UI_WINDOW_CHILD_Y; } } } break; case EV_KEY: if (BTN_TOUCH == touch_event.code) { if (TOUCH_DOWN == touch_event.value) { touch_info.type = TOUCH_DOWN; if (!first_touch) { first_touch = 1; ui_buzzer_alert(UI_BUZZER_ALERT_TOUCH); ui_power_notify(UI_POWER_NOTIFY_RESET); } } else if (TOUCH_UP == touch_event.value) { touch_info.type = TOUCH_UP; first_touch = 0; } } break; case EV_SYN: //set pose UI_TouchDataSet(&touch_info); //Log(UI_LOG_NOTICE, "touch x = %3d,y = %3d,t = %d to wm = %d\n", //touch_info.x, touch_info.y, touch_info.type, UI_ActiveWindowGet()); //send msg to active window Msg.MsgId = WM_USER_TOUCH_UP+touch_info.type; Msg.Data.v = 0x00; if (UI_ActiveWindowGet()) { WM_SendMessage(UI_ActiveWindowGet(), &Msg); } break; default: break; } } return 0; }
最新发布
03-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值