|
有一个疑问,我看了很多历程,做仪表盘采用的是贴图加多边形旋转,我在emwin仿真里面也测了,能转动,但是我想加几图标控件,就要用到窗口管理器,然后所有的教程都是在不用窗口的情况下使用的代码如下:/*************************** End of file ****************************/
#define countof(Obj) (sizeof(Obj) / sizeof(Obj[0]))
#define DEG2RAD (3.1415926f / 180)
#define MAG 4
const GUI_POINT aNEEDLE1[] = {
{0 * MAG,60 * MAG},
{-3 * MAG,45 * MAG},
{-3 * MAG,0 * MAG},
{3 * MAG,0 * MAG},
{3 * MAG,45 * MAG},
};
const GUI_POINT aNEEDLE2[] = {
{ 0 * MAG, 0 * MAG},
{ -2 * MAG, -6 * MAG},
{ -89 * MAG, 29 * MAG},
//{ 1,4}
{2 * MAG,6 * MAG}
};
const GUI_POINT aNEEDLE3[] = {
{ 0 * MAG,0 * MAG},
{ -2 * MAG, -4 * MAG},
{ -55 * MAG,32 * MAG},
{ 2 * MAG, 4 * MAG}
};
typedef struct {
GUI_AUTODEV_INFO AutoDevInfo; // Information about what has to be displayed
GUI_POINT aPoints1[7]; // Polygon data
float Angle1;
GUI_POINT aPoints2[7]; // Polygon data
float Angle2;
GUI_POINT aPoints3[7]; // Polygon data
float Angle3;
} PARAM;
static void _Draw(void* p) {
PARAM* pParam;
pParam = (PARAM*)p;
if (pParam->AutoDevInfo.DrawFixed)
{
GUI_ClearRect(0, 0, 800, 480);
GUI_DrawBitmap(&bmsoc, 42, 160);
GUI_DrawBitmap(&bmsudupan, 250, 40);
GUI_DrawBitmap(&bmdianji, 560, 160);
}
GUI_SetColor(GUI_RED);
// GUI_AA_FillPolygon(aPoints1, 5, 155, 342);
GUI_AA_FillPolygon(pParam->aPoints1, countof(aNEEDLE1), 136 * MAG, 263 * MAG);
GUI_AA_FillPolygon(pParam->aPoints2, countof(aNEEDLE2), 395*MAG, 185* MAG);
GUI_AA_FillPolygon(pParam->aPoints3, countof(aNEEDLE3), 657 * MAG, 259 * MAG);
//GUI_FillPolygon(aPoints3, 4, 648, 346);
if (pParam->AutoDevInfo.DrawFixed)
{
// GUI_SetTextMode(GUI_TM_TRANS);
// GUI_SetColor(GUI_BLACK);
// GUI_SetFont(&GUI_Font24B_ASCII);
// GUI_DispStringHCenterAt("armfly", LCD_GetXSize()/2, LCD_GetYSize()/2+30);
}
}
static float _GetAngle(int tDiff) {
if (tDiff < 15000) {
return 225 - 0.006 * tDiff;
}
tDiff -= 15000;
if (tDiff < 7500) {
return 225 - 90 + 0.012 * tDiff;
}
return 225;
}
static void _DemoScale(void)
{
GUI_AUTODEV AutoDev;
PARAM Param;
int Cnt;
int tDiff;
int t0;
GUI_AA_EnableHiRes();
GUI_AA_SetFactor(MAG);
//GUI_MEMDEV_CreateAuto(&AutoDev);
while (1)
{
t0 = GUI_GetTime();
GUI_MEMDEV_CreateAuto(&AutoDev);
for (Cnt = 0; (tDiff = GUI_GetTime() - t0) < 24000; Cnt++)
{
Param.Angle1 = _GetAngle(tDiff) * 1.2 * DEG2RAD;
Param.Angle2 = _GetAngle(tDiff) * 1.6 * DEG2RAD;
Param.Angle3 = _GetAngle(tDiff) * 1.6 * DEG2RAD;
GUI_AA_EnableHiRes();
GUI_AA_SetFactor(MAG);
//GUI_SetBkColor(GUI_RED);
GUI_RotatePolygon(Param.aPoints1, aNEEDLE1, countof(aNEEDLE1), Param.Angle1);
GUI_RotatePolygon(Param.aPoints2, aNEEDLE2, countof(aNEEDLE2), Param.Angle2);
GUI_RotatePolygon(Param.aPoints3, aNEEDLE3, countof(aNEEDLE3), Param.Angle3);
GUI_MEMDEV_DrawAuto(&AutoDev, &Param.AutoDevInfo, &_Draw, &Param);
}
GUI_Delay(10);
GUI_ClearRect(0, 0, 800, 480);
GUI_MEMDEV_DeleteAuto(&AutoDev);
}
}
#include "DIALOG.h"
/*
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define ID_WINDOW_0 (GUI_ID_USER + 0x00)
#define ID_ICONVIEW_0 (GUI_ID_USER + 0x01)
#define ID_ICONVIEW_1 (GUI_ID_USER + 0x02)
#define ID_ICONVIEW_2 (GUI_ID_USER + 0x03)
#define ID_ICONVIEW_3 (GUI_ID_USER + 0x04)
#define ID_ICONVIEW_4 (GUI_ID_USER + 0x05)
#define ID_TEXT_0 (GUI_ID_USER + 0x06)
// USER START (Optionally insert additional defines)
// USER END
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
// USER START (Optionally insert additional static data)
// USER END
/*********************************************************************
*
* _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 800, 480, 0, 0x0, 0 },
{ ICONVIEW_CreateIndirect, "Iconview", ID_ICONVIEW_0, 100, 350, 75, 75, 0, 0x0, 0 },
{ ICONVIEW_CreateIndirect, "Iconview", ID_ICONVIEW_1, 180, 350, 75, 75, 0, 0x0, 0 },
{ ICONVIEW_CreateIndirect, "Iconview", ID_ICONVIEW_2, 290, 350, 75, 75, 0, 0x0, 0 },
{ ICONVIEW_CreateIndirect, "Iconview", ID_ICONVIEW_3, 401, 349, 75, 75, 0, 0x0, 0 },
{ ICONVIEW_CreateIndirect, "Iconview", ID_ICONVIEW_4, 510, 350, 75, 75, 0, 0x0, 0 },
{ TEXT_CreateIndirect, "Text", ID_TEXT_0, 567, 10, 224, 65, 0, 0x0, 0 },
// USER START (Optionally insert additional widgets)
// USER END
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
// USER START (Optionally insert additional static code)
// USER END
/*********************************************************************
*
* _cbDialog
*/
static void _cbDialog(WM_MESSAGE* pMsg) {
WM_HWIN hItem;
int NCode;
int Id;
// USER START (Optionally insert additional variables)
// USER END
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
//
// Initialization of 'Text'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
TEXT_SetFont(hItem, GUI_FONT_20F_ASCII);
TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x000080FF));
// USER START (Optionally insert additional code for further widget initialization)
// USER END
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch (Id) {
case ID_ICONVIEW_0: // Notifications sent by 'Iconview'
switch (NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_MOVED_OUT:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SCROLL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SEL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_ICONVIEW_1: // Notifications sent by 'Iconview'
switch (NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_MOVED_OUT:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SCROLL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SEL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_ICONVIEW_2: // Notifications sent by 'Iconview'
switch (NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_MOVED_OUT:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SCROLL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SEL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_ICONVIEW_3: // Notifications sent by 'Iconview'
switch (NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_MOVED_OUT:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SCROLL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SEL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_ICONVIEW_4: // Notifications sent by 'Iconview'
switch (NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_MOVED_OUT:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SCROLL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SEL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
// USER START (Optionally insert additional code for further Ids)
// USER END
}
break;
// USER START (Optionally insert additional message handling)
// USER END
case WM_PAINT:
// GUI_Clear();
_DemoScale();
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* CreateWindow
*/
WM_HWIN CreateWindow(void);
WM_HWIN CreateWindow(void) {
WM_HWIN hWin;
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, WM_CF_MEMDEV, 0);
return hWin;
}
// USER START (Optionally insert additional public code)
// USER END
/*************************** End of file ****************************/
void MainTask(void)
{
WM_SetCreateFlags(WM_CF_MEMDEV);
GUI_Init();
CreateWindow();
while (1)
{
GUI_Delay(10);
// WM_InvalidateWindow(GUI_CreateDialogBox);
}
}
|
|