📄 maintask.c
字号:
/*
*********************************************************************************************************
* 礐/GUI
* Universal graphic software for embedded applications
*
* (c) Copyright 2002, Micrium Inc., Weston, FL
* (c) Copyright 2000, SEGGER Microcontroller Systeme GmbH
*
* 礐/GUI is protected by international copyright laws. Knowledge of the
* source code may not be used to write a similar product. This file may
* only be used in accordance with a license and should not be redistributed
* in any way. We appreciate your understanding and fairness.
*
* File : MainTask.c
* Purpose : Application program in windows simulator
*********************************************************************************************************
*/
#include "GUI.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "framewin.h"
#include "Font.h"
#include "BitmapFile.h"
#define MSG_CHANGE_TEXT WM_USER+0
#ifndef NULL
#define NULL 0
#endif
void GUIDEMO_Dialog(void);
static WM_CALLBACK* _cbBkWindowOld;
static char _acInfoText[40];
typedef struct {
int x;
int y;
int xHere, yHere;
const GUI_BITMAP* pBitmap;
} tDrawContext;
static const GUI_POINT _aPointArrow[] = {
{ 0, 0},
{-40, -30},
{-10, -20},
{-10, -70},
{ 10, -70},
{ 10, -20},
{ 40, -30},
};
static const GUI_POINT _aPointStar[] = {
{ 0, -36},
{ 8, -8},
{ 36, 0},
{ 8, 8},
{ 0, 36},
{ -8, 8},
{-36, 0},
{ -8, -8}
};
static WM_HWIN _hNaviWindow;
static WM_HWIN _hWindow2;
static void _cbNaviWindow(WM_MESSAGE* pMsg) {
int x, y;
switch (pMsg->MsgId) {
case WM_CREATE:
/*to do add code here*/
break;
case WM_DELETE:
/*to do add code here*/
break;
case WM_HIDE:
/*to do add code here*/
break;
case WM_MOVE:
/*to do add code here*/
break;
case WM_NOTIFY_PARENT:
/*to do add code here*/
break;
case WM_PAINT:
GUI_SetBkColor(GUI_GREEN);
GUI_Clear();
GUI_SetColor(GUI_WHITE);
GUI_SetFont(&GUI_Font24_ASCII);
x = WM_GetWindowSizeX(pMsg->hWin);
y = WM_GetWindowSizeY(pMsg->hWin);
GUI_DrawBitmap(&bmmap, -500, -400);
break;
case WM_SHOW:
/*to do add code here*/
break;
case WM_SIZE:
/*to do add code here*/
break;
case WM_TOUCH:
/*to do add code here*/
break;
default:
WM_DefaultProc(pMsg);
}
}
static void _cbWindow2(WM_MESSAGE* pMsg) {
int x, y;
switch (pMsg->MsgId) {
case WM_CREATE:
/*to do add code here*/
break;
case WM_DELETE:
/*to do add code here*/
break;
case WM_HIDE:
/*to do add code here*/
break;
case WM_MOVE:
/*to do add code here*/
break;
case WM_NOTIFY_PARENT:
/*to do add code here*/
break;
case WM_PAINT:
GUI_SetBkColor(GUI_RED);
GUI_Clear();
GUI_SetColor(GUI_WHITE);
GUI_SetFont(&GUI_Font24_ASCII);
x = WM_GetWindowSizeX(pMsg->hWin);
y = WM_GetWindowSizeY(pMsg->hWin);
GUI_DispStringHCenterAt("Test Window No.2", x / 2, 1);
break;
case WM_SHOW:
/*to do add code here*/
break;
case WM_SIZE:
/*to do add code here*/
break;
case WM_TOUCH:
/*to do add code here*/
break;
default:
WM_DefaultProc(pMsg);
}
}
static void _ChangeInfoText(char* pStr) {
WM_MESSAGE Message;
Message.MsgId = MSG_CHANGE_TEXT;
Message.Data.p = pStr;
WM_SendMessage(WM_HBKWIN, &Message);
WM_InvalidateWindow(WM_HBKWIN);
}
static void _cbBkWindow(WM_MESSAGE* pMsg) {
switch (pMsg->MsgId) {
case MSG_CHANGE_TEXT:
strcpy(_acInfoText, pMsg->Data.p);
case WM_PAINT:
GUI_SetBkColor(GUI_CYAN);
GUI_Clear();
GUI_SetColor(GUI_RED);
GUI_SetFont(&GUI_FontHZ_FangSong_GB2312_16);
GUI_DispStringAt(_acInfoText, 60, 6);
GUI_DrawBitmap(&bm3, 50, 60);
break;
default:
WM_DefaultProc(pMsg);
}
}
static void _Draw(void*p) {
tDrawContext* pPara;
GUI_CONTEXT ContextOld;
GUI_SaveContext(&ContextOld);
pPara = (tDrawContext*)p;
GUI_DrawBitmap(pPara->pBitmap, -pPara->x, -pPara->y);
GUI_SetPenSize(3);
GUI_SetDrawMode(GUI_DRAWMODE_NORMAL);
GUI_SetColor(GUI_RED);
GUI_DrawCircle(pPara->xHere, pPara->yHere, 5);
GUI_SetTextMode(GUI_TM_TRANS);
GUI_SetFont(&GUI_FontComic18B_ASCII);
GUI_DispStringAt("You are here", pPara->xHere - 20, pPara->yHere - 20);
GUI_RestoreContext(&ContextOld);
}
static void _ShowMovingMap(void) {
int i;
tDrawContext DrawContext = {0};
GUI_RECT r;
int t0, t, tRef;
#if GUIDEMO_LARGE
int y0 = 70;
#else
int y0 = 20;
#endif
WM_HWIN hFrameWin, hClientWin;
int XSize = LCD_GetXSize();
hFrameWin = FRAMEWIN_Create("Map of Xi'an", NULL, WM_CF_SHOW,
10, 30, 500, 480 - 60);
hClientWin = WM_CreateWindowAsChild(0, 0, 0, 0, hFrameWin, WM_CF_SHOW , 0 , 0);
FRAMEWIN_SetActive(hFrameWin, 0);
WM_SelectWindow(hClientWin);
WM_GetWindowRect(&r);
DrawContext.pBitmap = &bmmap;
/* Move text */
for (i = 0, t0 = GUI_GetTime(); t = GUI_GetTime() - t0, (t < 2000); i++) {
DrawContext.x = 0;
DrawContext.y = 0;
DrawContext.xHere = y0 + 2 * i;
DrawContext.yHere = y0;
tRef = GUI_GetTime() + 100;
GUI_MEMDEV_Draw(&r, _Draw, &DrawContext, 0, GUI_MEMDEV_NOTRANS);
tRef -= GUI_GetTime();
GUI_Delay(tRef);
}
/* Move map in x */
for (t0 = GUI_GetTime(); t = GUI_GetTime() - t0, (t < 4000);) {
DrawContext.x += 2;
tRef = GUI_GetTime() + 100;
GUI_MEMDEV_Draw(&r, _Draw, &DrawContext, 0, GUI_MEMDEV_NOTRANS);
tRef -= GUI_GetTime();
GUI_Delay(tRef);
}
/* Move map in y */
for (t0 = GUI_GetTime(); t = GUI_GetTime() - t0, (t < 4000); ) {
DrawContext.y += 2;
tRef = GUI_GetTime() + 100;
GUI_MEMDEV_Draw(&r, _Draw, &DrawContext, 0, GUI_MEMDEV_NOTRANS);
tRef -= GUI_GetTime();
GUI_Delay(tRef);
}
/* Move map in x and y */
for (t0 = GUI_GetTime(); t = GUI_GetTime()- t0, (t < 4000);) {
DrawContext.x -= 2;
DrawContext.y -= 2;
tRef = GUI_GetTime() + 100;
GUI_MEMDEV_Draw(&r, _Draw, &DrawContext, 0, GUI_MEMDEV_NOTRANS);
tRef -= GUI_GetTime();
GUI_Delay(tRef);
}
WM_DeleteWindow(hFrameWin);
WM_DeleteWindow(hClientWin);
}
/*
*******************************************************************
*
* main()
*
*******************************************************************
*/
void MainTask(void) {
GUI_Init();
GUI_SetFont(&GUI_FontHZ_Times_New_Roman_16);
GUI_SetDrawMode(GUI_DRAWMODE_NORMAL);
GUI_SetBkColor(GUI_YELLOW);
GUI_Clear();
GUI_SetColor(GUI_RED);
GUI_FillCircle(300, 200, 130);
GUI_SetColor(GUI_GREEN);
GUI_FillCircle(140, 200, 130);
GUI_SetDrawMode(GUI_DRAWMODE_XOR);
GUI_FillCircle(460, 200, 130);
GUI_SetColor(GUI_BLUE);
GUI_DispStringAt("First Circle", 300, 340);
GUI_DispStringAt("Seconde Circle", 140, 340);
GUI_DispStringAt("Third Circle", 460, 340);
GUI_SetColor(GUI_BLACK);
GUI_SetDrawMode(GUI_DRAWMODE_NORMAL);
GUI_FillCircle(300, 200, 3);
GUI_FillCircle(140, 200, 3);
GUI_FillCircle(460, 200, 3);
GUI_DrawCircle(300, 200, 131);
GUI_Delay(500);
GUI_SetDrawMode(GUI_DRAWMODE_NORMAL);
GUI_SetBkColor(GUI_BLACK);
GUI_SetColor(GUI_WHITE);
GUI_Clear();
GUI_DrawBitmap(&bm3, 10,10);
GUI_Delay(500);
GUI_Clear();
GUI_Delay(200);
GUI_DrawBitmap(&bm3_compressed_with_palette, 50, 10);
GUI_Delay(500);
GUI_Clear();
GUI_Delay(200);
GUI_DrawBitmapExp(10, 10, 255, 255, 1, 1, bm3.BitsPerPixel, bm3.BytesPerLine, ac3, &Pal3);
GUI_Delay(500);
GUI_DrawBitmapExp(10, 10, 255, 255, -2, -2, bm3.BitsPerPixel, bm3.BytesPerLine, ac3, &Pal3);
GUI_Delay(500);
GUI_Clear();
GUI_DrawBitmapMag(&bm3 ,10, 10, 1, 1);
GUI_Delay(500);
GUI_Clear();
GUI_SetColor(GUI_BLUE);
GUI_FillPolygon (_aPointArrow, 7, 260, 180);
GUI_DrawPolygon(_aPointStar, 7, 460, 200);
GUI_Delay(500);
GUI_SetBkColor(GUI_CYAN);
GUI_SetColor(GUI_WHITE);
GUI_Clear();
WM_SetCallback(WM_HBKWIN, _cbBkWindow);
_ChangeInfoText("uC/GUI WM演示程序!喜欢的朋友来看看!");
_hWindow2 = WM_CreateWindow(330, 130, 300, 300, WM_CF_SHOW | WM_CF_FGND, _cbWindow2, 0);
GUI_Delay(2000);
WM_ResizeWindow(_hWindow2, -100, -100);
WM_MoveTo(_hWindow2, 50, 100);
GUI_Delay(1000);
_ShowMovingMap();
WM_DeleteWindow(_hWindow2);
GUI_Delay(1);
GUI_SetBkColor(GUI_BLACK);
GUI_SetColor(GUI_WHITE);
GUI_Clear();
_ChangeInfoText("有关Widget的演示,这部分好复杂的说!还没有完全弄明白!大家请耐心等!");
GUI_Delay(1);
GUIDEMO_Dialog();
GUI_Delay(2000);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -