这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 企业专区 » GD32 » GD32107C-EVAL-简易涂鸦板

共1条 1/1 1 跳转至

GD32107C-EVAL-简易涂鸦板

高工
2015-04-16 00:52:36     打赏

在前几次的实验中,已经将GUI和操作系统都移植完成。这次就做了一个简单的涂鸦板。功能:能调整画笔的粗细,任意涂鸦并能清屏。


基于上一个实验的代码继续编写代码:

重要的两个任务是:


void  GUI_TOUCH_TASK(void *pdata)
{
	pdata = pdata;
	for(;;)
	{
		OSTimeDly(TIMEDELAY_TOUCH);
		GUI_TOUCH_Exec();   //触屏检测
	}
}


void  GUI_EEPW_TASK(void *pdata)
{
	pdata = pdata;
	for(;;)
	{
		   OSTimeDlyHMSM(0,0,1,0);
	}
}



void  GUI_GD32_TASK(void *pdata)
{
		pdata = pdata;
    GUI_TaskFunc();
		for(;;)
		{
				WM_Exec();  //GUI重绘
				OSTimeDly(TIMEDELAY_PAINT);	
		}
}


为了方便,先在GUI懒人工具上完成界面布局,便可获取如下代码:



static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    { FRAMEWIN_CreateIndirect,  "GD32",              0,                       0,  0,  240,320,FRAMEWIN_CF_MOVEABLE,0},
    { SLIDER_CreateIndirect,     NULL,               GUI_ID_SLIDER0,          1,  264,160,26, 0,0},
    { BUTTON_CreateIndirect,    "CLEAR",             GUI_ID_BUTTON0,          167,264,68, 26, 0,0}
};

void InitDialog(WM_MESSAGE * pMsg)
{
    WM_HWIN hWin = pMsg->hWin;
    //
    //FRAMEWIN
    //
    FRAMEWIN_SetClientColor(hWin,0xffff80);
    FRAMEWIN_SetFont(hWin,&GUI_FontHZ16);
    FRAMEWIN_AddMinButton(hWin, FRAMEWIN_BUTTON_RIGHT, 2);
    FRAMEWIN_SetTitleHeight(hWin,17);
    //
    //GUI_ID_SLIDER0
    //
    SLIDER_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_SLIDER0),0xffff80);
    SLIDER_SetRange(WM_GetDialogItem(hWin,GUI_ID_SLIDER0),1,10);
    SLIDER_SetValue(WM_GetDialogItem(hWin,GUI_ID_SLIDER0),10);
    //
    //GUI_ID_BUTTON0
    //
    BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON0),BUTTON_CI_UNPRESSED,0x8080ff);
    BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON0),&GUI_FontHZ16);
}


添加了两个控件,一个用来调整画笔的大小,一个用来清屏:


回调函数是整个功能的核心:


static void _cbCallback(WM_MESSAGE * pMsg) 
{
    int NCode, Id;
	  static u16 x_draw,y_draw;
	  static u16 length_fram;
	  GUI_PID_STATE  GUI_PID_DRAW;
    WM_HWIN hWin = pMsg->hWin;
    switch (pMsg->MsgId) 
    {
        
		    case WM_CREATE:
			      length_fram = FRAMEWIN_GetTitleHeight(hWin);
			       break;			  
			  case WM_PAINT:
            PaintDialog(pMsg);
				    GUI_SetColor(GUI_RED);
						if(x_draw < 200 && x_draw > 40 && y_draw < 200 + length_fram && y_draw > 20 + length_fram)
						{
							 GUI_SetPenSize(SLIDER_GetValue(WM_GetDialogItem(hWin,GUI_ID_SLIDER0)));
							 GUI_DrawPoint(x_draw,y_draw - length_fram);	
							 DrawFlag = 0;
						}
            break;
        case WM_INIT_DIALOG:
            InitDialog(pMsg);
            break;
        case WM_KEY:
            switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) 
            {
                case GUI_KEY_ESCAPE:
                    GUI_EndDialog(hWin, 1);
                    break;
                case GUI_KEY_ENTER:
                    GUI_EndDialog(hWin, 0);
                    break;
            }
            break;
        case WM_NOTIFY_PARENT:
            Id = WM_GetId(pMsg->hWinSrc); 
            NCode = pMsg->Data.v;        
            switch (Id) 
            {
                case GUI_ID_OK:
                    if(NCode==WM_NOTIFICATION_RELEASED)
                        GUI_EndDialog(hWin, 0);
                    break;
                case GUI_ID_CANCEL:
                    if(NCode==WM_NOTIFICATION_RELEASED)
                        GUI_EndDialog(hWin, 0);
                    break;
								case GUI_ID_BUTTON0:
													if(NCode==WM_NOTIFICATION_RELEASED)
													{
															DrawFlag = 0;
															x_draw = 0;
															y_draw = 0;	     
															WM_InvalidateRect(WM_GetClientWindow(hWin),&RectDraw);
													}
													break;
            }
            break;
			 case  WM_TOUCH:
						GUI_TOUCH_GetState(&GUI_PID_DRAW);
						x_draw =  GUI_PID_DRAW.x;
						y_draw =  GUI_PID_DRAW.y;
						if(x_draw < 200 && x_draw > 40 && y_draw < 200 + length_fram && y_draw > 20 + length_fram)
						{
								DrawFlag = 1;
								WM_InvalidateRect(WM_GetClientWindow(hWin),&RectDraw);
						}
						break;	
        default:
            WM_DefaultProc(pMsg);
    }
}



看看效果图:




关键词: GD32107C-EVAL     涂鸦     简易    

共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]