ucGUI例程收藏

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();
	}
时间: 2024-11-06 01:11:55

ucGUI例程收藏的相关文章

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

本例程下载:2.emWin5.26(ucGui)VS2008数字显示.zip ? 在emWin显示文本字符还是容易,我们也可以使用字符串和标准 C 库的函数来显示数值.然而,有时候这会是件困难的事.通常,较为容易(也更为有效)的是调用一个例程显示所需结 构的数值. emWin 支持各种十进制.十六进制和二进制输出.本章将对这些例程进行逐一描述.所有函数不需要使用浮点库,并对速度和大小进行了优化.当然"Sprintf"可以用于任何系统.使 用本章介绍的例程,有时可以简化操作,节省 ROM

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

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

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

UCGUI(emWin) 2-D图形库--之基本板绘图,在ucgui的基本绘图功能上来看,功能还是比较全的,本例程主要使用基本的接口,两个主要的概念是绘制(draw)和填充(Fill),这两的区别是一个空心的,另一个是实心的,用时注意加于区分,另一个值得注意的是绘制模式,GUI_SetDrawMode(),目前emWin5.2有两模式,一个是正常的绘制,另一个是取反的方式绘制. ? 例程代码下载:3.emWin5.26(ucGui)VS2008 2-D图形库-基本绘图.zip ? GUI_Get

S3C2416裸机开发系列十四_GCC下UCGUI的移植(2)

S3C2416裸机开发系列十四 GCC下UCGUI的移植(2) 象棋小子    1048272975 现在主要讲解一下在GCC移植UCGUI,Makefile工程如何加入目录,加入源码,c标准库,编译选项的设置. 笔者的Makefile模板提取自uboot,工程中加入目录,加入源码都是很简单的,详细的介绍请参考前面章节" GCC启动代码工程应用实例".下面主要介绍UCGUI目录下很多的源码文件Makefile的编写,一种可行的方式就是把GUI目录上所有的c文件,不管有无用到,均加入工程

S3C2416裸机开发系列十四_GCC下UCGUI的移植(1)

S3C2416裸机开发系列十四 GCC下UCGUI的移植(1) 象棋小子    1048272975 GUI(图形用户界面)极大地方便了非专业用户的使用,用户无需记忆大量的命令,取而代之的是可以通过窗口.菜单.按键等方式进行操作.在某些场合,设计一款人机界面丰富友好的嵌入式产品能赢得更多的用户.笔者此处就s3c2416基于UCGUI图形用户界面的使用作一个简单的介绍. 1. 代码准备 UCGUI 3.98源码,这个版本的UCGUI是开放源码的最高版本,之后版本只提供库文件,不再开源.笔者以UCG

在深圳有娃的家长必须要懂的社保少儿医保,不然亏大了!(收藏)

在深圳有娃的家长必须要懂的社保少儿医保,不然亏大了!(收藏) 转载2016-07-26 17:21:47 标签:深圳少儿医保社保医疗保险住院 在深圳工作或生活的家长们可能还有人不清楚,其实小孩子最大的基础保障福利就是少儿医保.如果以前没重视关注的,现在您看到这篇文章还来得及!少儿医保每年政府财政补贴384元,自己只需交200元左右,就可以享受门诊报销1000元,住院报销比例90%,最高报销额度达148万,大病门诊最高报销比例90%!如何享受?有哪些待遇?接下来就详细来做一个介绍: 少儿医保投保需

原创 导出微信收藏到电脑

1.安装模拟器(如:天天模拟器)2.模拟器安装打开微信3.模拟器安装es文件浏览器4.打开微信文件路径:在sdcard的Tencent的MicroMsg的ebb34e976d3351bfe0ab(就是那个最长的,后面就不打出来了)5.模拟器设置共享位置(如:/mnt/asec/share --> 桌面/自定义文件夹)6.用es文件浏览器复制微信收藏文件夹到共享目录(/sdcard/tencent/MicroMsg/********/favorite --> /mnt/asec/share)7.

《鸡啄米C++编程入门系列》系列技术文章整理收藏

<鸡啄米C++编程入门系列>系列技术文章整理收藏 收藏整理鸡啄米C++编程入门系列文章,供个人和网友学习C++时参考 1鸡啄米:C++编程入门系列之前言 2鸡啄米:C++编程入门系列之一(进制数) 3鸡啄米:C++编程入门系列之二(原码.反码与补码) 4鸡啄米:C++编程入门系列之三(VS2010的使用介绍) 5鸡啄米:C++编程入门系列之四(数据类型) 6鸡啄米:C++编程入门系列之五(运算符和表达式) 7鸡啄米:C++编程入门系列之六(算法的基本控制结构之选择结构) 8鸡啄米:C++编程入

设为首页与加入收藏

通用代码: <a href="javascript:;"onclick="this.style.behavior='url(#default#homepage)';this.setHomePage(location.href);">设为首页</a> | <a href="javascript:;" onClick="window.external.AddFavorite(location.href,docu