ucGUI 几个重要例程Demo

 
按钮的定制

#include <stddef.h>
#include <string.h> #include "WM.h"
#include "FRAMEWIN.h"
#include "BUTTON.h"
#include "BUTTON_Private.h"
#include "GUI_Protected.h" /*********************************************************************
*
* Static data
*
**********************************************************************
*/ static WM_CALLBACK * _pcbCallback;
static int _Color;
static int _Font;
static int _Pressed; static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ FRAMEWIN_CreateIndirect, "Round button sample", 0, 50, 60, 200, 120, FRAMEWIN_CF_MOVEABLE },
{ BUTTON_CreateIndirect, "Button", GUI_ID_BUTTON0, 100, 10, 80, 80 },
{ BUTTON_CreateIndirect, "Callback", GUI_ID_BUTTON1, 10, 10, 60, 20 },
{ BUTTON_CreateIndirect, "Font", GUI_ID_BUTTON2, 10, 30, 60, 20 },
{ BUTTON_CreateIndirect, "Color", GUI_ID_BUTTON3, 10, 50, 60, 20 },
{ BUTTON_CreateIndirect, "Cancel", GUI_ID_CANCEL, 10, 70, 60, 20 }
}; /*********************************************************************
*
* Static functions
*
**********************************************************************
*/ /*********************************************************************
*
* _OnPaint
*
* Purpose: Paints the owner drawn button
*/
static void _OnPaint(BUTTON_Handle hObj) {
int Index;
char ac[50];
GUI_RECT Rect;
BUTTON_Obj * pObj;
pObj = BUTTON_H2P(hObj);
Index = (WIDGET_GetState(hObj) & BUTTON_STATE_PRESSED) ? 1 : 0;
WM_GetClientRect(&Rect);
/* Draw filled ellipse with button background color */
GUI_SetColor(BUTTON_GetBkColor(hObj, Index));
GUI_FillEllipse(Rect.x1 / 2, Rect.y1 / 2, Rect.x1 / 2, Rect.y1 / 2);
/* Draw black shape */
GUI_SetColor(GUI_BLACK);
GUI_DrawEllipse(Rect.x1 / 2, Rect.y1 / 2, Rect.x1 / 2, Rect.y1 / 2);
/* Draw button text with widget attributes */
GUI_SetColor(BUTTON_GetTextColor(hObj, Index));
GUI_SetBkColor(BUTTON_GetBkColor(hObj, Index));
GUI_SetFont(BUTTON_GetFont(hObj));
BUTTON_GetText(hObj, ac, sizeof(ac));
if (_Pressed) {
strcpy(ac + strlen(ac), "\npressed");
}
GUI_DispStringInRect(ac, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
} /*********************************************************************
*
* _cbButton
*
* Purpose:
* 1. Calls the owner draw function if the WM_PAINT message has been send
* 2. Calls the original callback for further messages
* 3. After processing the messages the function evaluates the pressed-state
* if the WM_TOUCH message has been send
*/
static void _cbButton(WM_MESSAGE *pMsg) {
switch (pMsg->MsgId) {
case WM_PAINT:
_OnPaint(pMsg->hWin);
break;
default:
_pcbCallback(pMsg); /* The original callback */
break;
}
if (pMsg->MsgId == WM_TOUCH) {
if (BUTTON_IsPressed(pMsg->hWin)) {
if (!_Pressed) {
_Pressed = 1;
}
} else {
_Pressed = 0;
}
}
} /*********************************************************************
*
* _cbDialog
*
* Purpose: Dialog callback routine
*/
static void _cbDialog(WM_MESSAGE *pMsg) {
int NCode, Id;
WM_HWIN hDlg;
BUTTON_Handle hButton;
hDlg = pMsg->hWin;
switch (pMsg->MsgId) {
case WM_PAINT:
WM_DefaultProc(pMsg); /* Handle dialog items */
/* After drawing the dialog items add some user drawn items to the window */
GUI_SetPenSize(10);
GUI_SetColor(GUI_GREEN);
GUI_DrawLine( 95, 5, 185, 95);
GUI_SetColor(GUI_RED);
GUI_DrawLine( 95, 95, 185, 5);
break;
case WM_INIT_DIALOG:
hButton = WM_GetDialogItem(hDlg, GUI_ID_BUTTON0);
WM_SetHasTrans(hButton); /* Set transparency flag for button */
break;
case WM_KEY:
switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) {
case GUI_KEY_ESCAPE:
GUI_EndDialog(hDlg, 1);
break;
case GUI_KEY_ENTER:
GUI_EndDialog(hDlg, 0);
break;
}
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc); /* Id of widget */
NCode = pMsg->Data.v; /* Notification code */
switch (NCode) {
case WM_NOTIFICATION_RELEASED: /* React only if released */
hButton = WM_GetDialogItem(hDlg, GUI_ID_BUTTON0);
if (Id == GUI_ID_BUTTON1) { /* Toggle callback */
if (_pcbCallback) {
WM_SetCallback(hButton, _pcbCallback);
_pcbCallback = 0;
} else {
_pcbCallback = WM_SetCallback(hButton, _cbButton);
}
WM_InvalidateWindow(hButton);
}
if (Id == GUI_ID_BUTTON2) { /* Toggle font */
if (_Font) {
BUTTON_SetFont(hButton, &GUI_Font13_1);
} else {
BUTTON_SetFont(hButton, &GUI_Font8x16);
}
_Font ^= 1;
}
if (Id == GUI_ID_BUTTON3) { /* Toggle color */
if (_Color) {
BUTTON_SetBkColor(hButton, 0, 0xaaaaaa);
BUTTON_SetBkColor(hButton, 1, GUI_WHITE);
BUTTON_SetTextColor(hButton, 0, GUI_BLACK);
BUTTON_SetTextColor(hButton, 1, GUI_BLACK);
} else {
BUTTON_SetBkColor(hButton, 0, GUI_BLUE);
BUTTON_SetBkColor(hButton, 1, GUI_RED);
BUTTON_SetTextColor(hButton, 0, GUI_WHITE);
BUTTON_SetTextColor(hButton, 1, GUI_YELLOW);
}
_Color ^= 1;
}
if (Id == GUI_ID_OK) { /* OK Button */
GUI_EndDialog(hDlg, 0);
}
if (Id == GUI_ID_CANCEL) { /* Cancel Button */
GUI_EndDialog(hDlg, 1);
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
}
} /*********************************************************************
*
* MainTask
*
**********************************************************************
*/ void MainTask(void) {
GUI_Init();
/* Use memory devices for all windows */
WM_SetCreateFlags(WM_CF_MEMDEV);
WM_EnableMemdev(WM_HBKWIN);
WM_SetDesktopColor(GUI_GREEN);
while(1) {
_Font = 0;
_Color = 0;
_pcbCallback = 0;
GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbDialog, 0, 0, 0);
GUI_Delay(1000);
}
}
 
对话框

代码

static void _cbBkWindow(WM_MESSAGE* pMsg) {
switch (pMsg->MsgId) {
case WM_PAINT:
GUI_SetBkColor(GUI_RED);
GUI_Clear();
GUI_SetColor(GUI_WHITE);
GUI_SetFont(&GUI_Font24_ASCII);
GUI_DispStringHCenterAt("DIALOG_MessageBox - Sample", 160, 5);
break;
default:
WM_DefaultProc(pMsg);
}
}
/*******************************************************************
*
* MainTask
* Demonstrates a message box
*
********************************************************************
*/
void MainTask(void) {
GUI_Init();
WM_SetCallback(WM_HBKWIN, &_cbBkWindow);
/* Create message box and wait until it is closed */
while (1) {
GUI_MessageBox("This text is shown\nin a message box",
"Caption/Title", GUI_MESSAGEBOX_CF_MOVEABLE);
GUI_Delay(750); /* Wait for a short moment ... */
GUI_MessageBox("New message !",
"Caption/Title", GUI_MESSAGEBOX_CF_MOVEABLE);
GUI_Delay(750);
}
}
回调函数(窗口创建)

  代码:

	#include "GUI.h"
#include "WM.h" /*******************************************************************
*
* static code
*
********************************************************************
*/
/*******************************************************************
*
* _cbBkWindow
*/
static void _cbBkWindow(WM_MESSAGE* pMsg) {
switch (pMsg->MsgId) {
case WM_PAINT:
GUI_ClearRect(0, 50, 319, 239);
default:
WM_DefaultProc(pMsg);
}
} /*******************************************************************
*
* _cbWindow
*/
static void _cbWindow(WM_MESSAGE* pMsg) {
GUI_RECT Rect;
switch (pMsg->MsgId) {
case WM_PAINT:
WM_GetInsideRect(&Rect);
GUI_SetBkColor(GUI_RED);
GUI_SetColor(GUI_YELLOW);
GUI_ClearRectEx(&Rect);
GUI_DrawRectEx(&Rect);
GUI_SetColor(GUI_BLACK);
GUI_SetFont(&GUI_Font8x16);
GUI_DispStringHCenterAt("Foreground window", 75, 40);
break;
default:
WM_DefaultProc(pMsg);
}
} /*******************************************************************
*
* _MoveWindow
*/
static void _MoveWindow(const char* pText) {
WM_HWIN hWnd;
int i;
/* Create foreground window */
hWnd = WM_CreateWindow(10, 50, 150, 100, WM_CF_SHOW, _cbWindow, 0);
GUI_Delay(500);
/* Move foreground window */
for (i = 0; i < 40; i++) {
WM_MoveWindow(hWnd, 2, 2);
GUI_Delay(10);
}
/* Show text before deleting window if we have one */
if (pText) {
GUI_DispStringAt(pText, 5, 50);
GUI_Delay(2500);
}
/* Delete foreground window */
WM_DeleteWindow(hWnd);
WM_Invalidate(WM_HBKWIN);
GUI_Exec();
} /*******************************************************************
*
* _DemoRedraw
*/
static void _DemoRedraw(void) {
WM_CALLBACK* _cbOldBk;
GUI_SetBkColor(GUI_BLACK);
GUI_Clear();
GUI_SetColor(GUI_WHITE);
GUI_SetFont(&GUI_Font24_ASCII);
GUI_DispStringHCenterAt("WM_Redraw - Sample", 160, 5);
GUI_SetFont(&GUI_Font8x16);
while(1) {
/* Move a window over background */
_MoveWindow("Background has not been redrawn");
/* Clear background */
GUI_ClearRect(0, 50, 319, 239);
GUI_Delay(1000);
/* Set callback for background window */
_cbOldBk = WM_SetCallback(WM_HBKWIN, _cbBkWindow);
/* Move a window over background */
_MoveWindow("Background has been redrawn");
/* Delete callback for Background window */
WM_SetCallback(WM_HBKWIN, _cbOldBk);
}
} /*******************************************************************
*
* MainTask
*
* Demonstrates redrawing
*
********************************************************************
*/
void MainTask(void) {
GUI_Init();
_DemoRedraw();
}

ucGUI例程收藏的更多相关文章

  1. 【资料下载区】【iCore、 iCore2相关资料】更新日期2017/1/11

    [新产品发布][iCore2 ARM / FPGA 双核心板] [iCore系列核心板视频教程]之 SDRAM 读写实验[iCore双核心组合是开发板例程][uCGUI 例程及代码包下载][iCore ...

  2. [stm32][ucos][ucgui] 2、LED闪烁、串口、滑块、文本编辑框简单例程

    上一篇:[stm32][ucos] 1.基于ucos操作系统的LED闪烁.串口通信简单例程 * 内容简述: 本例程操作系统采用ucos2.86a版本, 建立了7个任务            任务名   ...

  3. emWin(ucGui)数值显示例程 -【worldsing笔记】

    本例程下载:2.emWin5.26(ucGui)VS2008数字显示.zip   在emWin显示文本字符还是容易,我们也可以使用字符串和标准 C 库的函数来显示数值.然而,有时候这会是件困难的事.通 ...

  4. stm32——modbus例程网址收藏

    https://blog.csdn.net/baidu_31437863/article/details/82178708 STM32(五) Modbus https://blog.csdn.net/ ...

  5. 【资料分享】 OpenCV精华收藏

    OpenCV精华收藏 SkySeraph Dec.29th 2010  HQU Email:zgzhaobo@gmail.com    QQ:452728574 Latest Modified Dat ...

  6. 3.emWin5.26(ucGui)VS2008 2-D图形库-基本绘图【Worldsing笔记】

    UCGUI(emWin) 2-D图形库--之基本板绘图,在ucgui的基本绘图功能上来看,功能还是比较全的,本例程主要使用基本的接口,两个主要的概念是绘制(draw)和填充(Fill),这两的区别是一 ...

  7. emWin 2天速成实例教程000_如何快速入门ucGUI/emWin

    备注:(1)打开工程目录下的"Exe\GUISimulationDebug.exe"即可看到效果.(2)看完教程000-005就基本会用emWin做项目,其他章节可以需要时再参考. ...

  8. (转)linux下和云端通讯的例程, ubuntu和openwrt实验成功(一)

    一.  HTTP请求的数据流总结#上传数据, yeelink的数据流如下POST /v1.0/device/4420/sensor/9089/datapoints HTTP/1.1Host: api. ...

  9. h5应用缓存及收藏时Icon显示

    h5应用实现离线缓存,加载后,断网仍然可以继续使用. 一.需求 转行做h5,目前做赛道游戏,动手做了个赛道编辑器web版的,由于web版需要开启服务器才能使用,策划要想回家使用就要发布到外网服务器了, ...

随机推荐

  1. 1651. Shortest Subchain(bfs)

    1651 终于A了 看这题容易想到最短路 看到错的很多 还特意注意了好几处 后来发现 必须按给出的顺序出边 想了想 这不就是BFS 然后就是各种细节 i->i+1ori->j(a[i]== ...

  2. bzoj1876: [SDOI2009]SuperGCD

    更相减损数. 上手就debug了3个小时,直接给我看哭了. 3个函数都写错了是什么感受? 乘2函数要从前往后乘,这样后面的数乘2进位以后不会干扰前面的数. 除2函数要从后往前除,这样前面的数借来的位不 ...

  3. UVa 12230 (期望) Crossing Rivers

    题意: 从A到B两地相距D,之间有n段河,每段河有一条小船,船的位置以及方向随机分布,速度大小不变.每段河之间是陆地,而且在陆地上行走的速度为1.求从A到B的时间期望. 分析: 我们只要分析每段河的期 ...

  4. tomcat 默认项目设置

    正常情况下,我们启动tomcat后,直接输入“http://localhost:端口/“ 后,默认访问道是webapp目录下的ROOT应用. 我们要通过上述方式访问自己的应用,有俩种方式. 第一:把自 ...

  5. centos使用denyhosts的问题,会将自己的IP自动加到hosts.deny的解决办法。

    先吐槽, 很多网站\博客,技术文章也玩伪原创, 害人不浅. 全TMD是COPY, COPY, COPY过来. 拷过来就算了, 你TMD还改了其中的内容... 改成错的.然后众多网站转载, 将错进行到底 ...

  6. QuartZ Cron表达式在java定时框架中的应用

    CronTrigger CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表. CronT ...

  7. OSGI框架学习

    OSGI框架三个重要概念 OSGi框架是根据OSGi规范中定义的三个概念层设计的:模块.模块生命周期.服务. 模块层定义了OSGi模块的概念(bundle,即包含一个元数据MANIFEST.MF的JA ...

  8. 如何获取数据块结构信息dump

    有个pub_department的表,索引为PK_PUB_DEPARTMENT. 1.找到object_id select   object_id from dba_objects s  where  ...

  9. loadrunner 发送gzip压缩json格式(转)

    转:http://blog.csdn.net/gzh0222/article/details/7711281 使用java vuser实现,发送gzip压缩json格式. /* * LoadRunne ...

  10. CAKeyframeAnimation

    之所以叫做关键帧动画是因为,这个类可以实现,某一属性按照一串的数值进行动画,就好像制作动画的时候一帧一帧的制作一样. 一般使用的时候  首先通过 animationWithKeyPath 方法 创建一 ...