⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 UC-GUI的源文件。可以无缝连接大多数常见的LCD。它的驱动代码我认为很有必要研究
💻 C
字号:
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"


#include "GUI.H"
#include "DIALOG.H"
#include "WM.h"

#include "button.h"
#include "progbar.h"



/*******************************************************************
*
*******************************************************************/
#define countof(Array) (sizeof(Array) / sizeof(Array[0]))
const GUI_POINT aPoints[] = {
{ 0, 20},
{ 40, 20},
{ 20, 0}
};
GUI_POINT aEnlargedPoints[countof(aPoints)];
void DrawPolygon(void) {
    int i;
    GUI_Clear();
    GUI_SetDrawMode(GUI_DM_XOR);
    GUI_FillPolygon(aPoints, countof(aPoints), 140, 110);
    for (i = 1; i < 10; i++) {
        GUI_EnlargePolygon(aEnlargedPoints, aPoints, countof(aPoints), i * 5);
        GUI_FillPolygon(aEnlargedPoints, countof(aPoints), 140, 110);
    }
}

/*********************************************************************
*
*       Dialog resource
*
* This table conatins the info required to create the dialog.
* It has been created manually, but could also be created by a GUI-builder.
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { FRAMEWIN_CreateIndirect, "www.arm88.com", 0,              10,  10, 180, 230, FRAMEWIN_CF_MOVEABLE, 0  },
  { BUTTON_CreateIndirect,   "OK",     GUI_ID_OK,     100,  5,   60,  20 },
  { BUTTON_CreateIndirect,   "Cancel", GUI_ID_CANCEL, 100,  30,  60,  20 },
  { TEXT_CreateIndirect,     "LText",  0,              10,  55,  48,  15, TEXT_CF_LEFT  },
  { TEXT_CreateIndirect,     "RText",  0,              10,  80,  48,  15, TEXT_CF_RIGHT },
  { EDIT_CreateIndirect,     NULL,     GUI_ID_EDIT0,   60,  55, 100,  15, 0, 50 },
  { EDIT_CreateIndirect,     NULL,     GUI_ID_EDIT1,   60,  80, 100,  15, 0, 50 },
  { TEXT_CreateIndirect,     "Hex",    0,              10, 100,  48,  15, TEXT_CF_RIGHT },
  { EDIT_CreateIndirect,     NULL,     GUI_ID_EDIT2,   60, 100, 100,  15, 0, 6 },
  { TEXT_CreateIndirect,     "Bin",    0,              10, 120,  48,  15, TEXT_CF_RIGHT },
  { EDIT_CreateIndirect,     NULL,     GUI_ID_EDIT3,   60, 120, 100,  15 },
  { LISTBOX_CreateIndirect,  NULL,     GUI_ID_LISTBOX0,10,  10,  60,  40 },
  { CHECKBOX_CreateIndirect, NULL,     GUI_ID_CHECK0,  10, 140,   0,   0 },
  { CHECKBOX_CreateIndirect, NULL,     GUI_ID_CHECK1,  30, 140,   0,   0 },
  { SLIDER_CreateIndirect,   NULL,     GUI_ID_SLIDER0, 60, 140, 100,  20 },
  { SLIDER_CreateIndirect,   NULL,     GUI_ID_SLIDER1, 10, 170, 150,  30 }
};


/*********************************************************************
*
*              Initializers for listbox
*/
static const GUI_ConstString _apListBox[] = {
  "English", "Deutsch", "Fran鏰is", "Japanese", "Italiano", NULL
};

/*********************************************************************
*
*       static code
*
**********************************************************************
*/

/*********************************************************************
*
*       Dialog callback routine
*/
static void _cbCallback(WM_MESSAGE * pMsg) {
  int NCode, Id;
  WM_HWIN hEdit0, hEdit1, hEdit2, hEdit3, hListBox;
  WM_HWIN hWin = pMsg->hWin;
  switch (pMsg->MsgId) {
    case WM_INIT_DIALOG:
      /* Get window handles for all widgets */
      hEdit0   = WM_GetDialogItem(hWin, GUI_ID_EDIT0);
      hEdit1   = WM_GetDialogItem(hWin, GUI_ID_EDIT1);
      hEdit2   = WM_GetDialogItem(hWin, GUI_ID_EDIT2);
      hEdit3   = WM_GetDialogItem(hWin, GUI_ID_EDIT3);
      hListBox = WM_GetDialogItem(hWin, GUI_ID_LISTBOX0);
      /* Initialize all widgets */
      EDIT_SetText(hEdit0, "Edit0");
      EDIT_SetText(hEdit1, "Edit1");
      EDIT_SetTextAlign(hEdit1, GUI_TA_LEFT);
      EDIT_SetHexMode(hEdit2, 0x1234, 0, 0xffff);
      EDIT_SetBinMode(hEdit3, 0x1234, 0, 0xffff);
      LISTBOX_SetText(hListBox, _apListBox);
      WM_DisableWindow (WM_GetDialogItem(hWin, GUI_ID_CHECK1));
      CHECKBOX_Check(  WM_GetDialogItem(hWin, GUI_ID_CHECK0));
      CHECKBOX_Check(  WM_GetDialogItem(hWin, GUI_ID_CHECK1));
      SLIDER_SetWidth( WM_GetDialogItem(hWin, GUI_ID_SLIDER0), 5);
      SLIDER_SetValue( WM_GetDialogItem(hWin, GUI_ID_SLIDER1), 50);
      SCROLLBAR_CreateAttached(hListBox, SCROLLBAR_CF_VERTICAL);
      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);    /* Id of widget */
      NCode = pMsg->Data.v;               /* Notification code */
      switch (NCode) {
        case WM_NOTIFICATION_RELEASED:    /* React only if released */
          if (Id == GUI_ID_OK) {          /* OK Button */
            GUI_EndDialog(hWin, 0);
          }
          if (Id == GUI_ID_CANCEL) {      /* Cancel Button */
            GUI_EndDialog(hWin, 1);
          }
          break;
      }
      break;
    default:
      WM_DefaultProc(pMsg);
  }
}
/*******************************************************************
*
*                 Draws 13 color bars
*
********************************************************************
*/
void ShowColorBar(void) {
  int x0 = 60, y0 = 40, yStep = 15, i;
  int xsize     = LCD_GetDevCap(LCD_DEVCAP_XSIZE) - x0;
	GUI_SetFont(&GUI_Font_HZK16);
  #if (LCD_FIXEDPALETTE) 
    GUI_DispString("调色板: ");
    GUI_DispDecMin(LCD_FIXEDPALETTE);
  #endif
  GUI_DispStringAt("红",     0, y0 +      yStep);
  GUI_DispStringAt("绿",   0, y0 +  3 * yStep);
  GUI_DispStringAt("蓝",    0, y0 +  5 * yStep);
  GUI_DispStringAt("灰",    0, y0 +  6 * yStep);
  GUI_DispStringAt("黄",  0, y0 +  8 * yStep);
  GUI_DispStringAt("靛",    0, y0 + 10 * yStep);
  GUI_DispStringAt("紫", 0, y0 + 12 * yStep);
  for (i = 0; i < xsize; i++) {
    U16 cs = (255 * (U32)i) / xsize;
    U16 x = x0 + i;;
    /* Red */
    GUI_SetColor(cs);
    GUI_DrawVLine(x, y0             , y0 +     yStep - 1);
    GUI_SetColor(0xff + (255 - cs) * 0x10100L);
    GUI_DrawVLine(x, y0 +      yStep, y0 + 2 * yStep - 1);
    /* Green */
    GUI_SetColor(cs<<8);
    GUI_DrawVLine(x, y0 +  2 * yStep, y0 + 3 * yStep - 1);
    GUI_SetColor(0xff00 + (255 - cs) * 0x10001L);
    GUI_DrawVLine(x, y0 +  3 * yStep, y0 + 4 * yStep - 1);
    /* Blue */
    GUI_SetColor(cs * 0x10000L);
    GUI_DrawVLine(x, y0 +  4 * yStep, y0 + 5 * yStep - 1);
    GUI_SetColor(0xff0000 + (255 - cs) * 0x101L);
    GUI_DrawVLine(x, y0 +  5 * yStep, y0 + 6 * yStep - 1);
    /* Gray */
    GUI_SetColor((U32)cs * 0x10101L);
    GUI_DrawVLine(x, y0 +  6 * yStep, y0 + 7 * yStep - 1);
    /* Yellow */
    GUI_SetColor(cs * 0x101);
    GUI_DrawVLine(x, y0 +  7 * yStep, y0 + 8 * yStep - 1);
    GUI_SetColor(0xffff + (255 - cs) * 0x10000L);
    GUI_DrawVLine(x, y0 +  8 * yStep, y0 + 9 * yStep - 1);
    /* Cyan */
    GUI_SetColor(cs * 0x10100L);
    GUI_DrawVLine(x, y0 +  9 * yStep, y0 + 10 * yStep - 1);
    GUI_SetColor(0xffff00 + (255 - cs) * 0x1L);
    GUI_DrawVLine(x, y0 + 10 * yStep, y0 + 11 * yStep - 1);
    /* Magenta */
    GUI_SetColor(cs * 0x10001);
    GUI_DrawVLine(x, y0 + 11 * yStep, y0 + 12 * yStep - 1);
    GUI_SetColor(0xff00ff + (255 - cs) * 0x100L);
    GUI_DrawVLine(x, y0 + 12 * yStep, y0 + 13 * yStep - 1);
  }
}

/*********************************************************************
*
*       GUIDEMO_Dialog
*
**********************************************************************
*/

void GUIDEMO_Messagebox(void) {
  GUI_COLOR Color;
  Color = WM_SetDesktopColor(GUI_BLACK);
  
  GUI_MessageBox("I LOVE YOU!", "Text111111", 0);
//  GUI_Delay(1000);
//  GUI_MessageBox("Message2", "Text", 0);
//  GUI_Delay(1000);
//  WM_SetDesktopColor(Color);

}

void Main(void)
{
	int i;
		
    rSYSCFG=CACHECFG;   // Using 8KB Cache//

    Port_Init();
    Uart_Init(0,57600);
    Delay(1000);
    Uart_Select(0); //Select UART0
        while(1) {
    	
    GUI_Init();
	Uart_Printf("\nGUI_Init");


	GUI_SetFont(&GUI_Font16B_ASCII);
	
	GUI_DispString("\nHellow,World!");
	

	GUI_SetFont(&GUI_Font_HZK16);
	
	GUI_DispString("\n\n你好,世界!");
	GUI_DispString("\n\n千驰科技");
	
	GUI_SetFont(&GUI_Font16B_ASCII);
	GUI_DispString("\n\nS344B0X");
	GUI_SetFont(&GUI_Font_HZK16);
	GUI_DispString("开发套件");
	GUI_SetFont(&GUI_Font16B_ASCII);
	GUI_DispString("\n\nuC/GUI");
	GUI_SetFont(&GUI_Font_HZK16);
	GUI_DispString("图形用户界面系统演示");
	Uart_Printf("\nGUI_Init6");
	Uart_Printf("\n请按电脑键盘测试!");

	Uart_Printf("\nKey %d Pressed",WaitKey());
	Uart_Printf("\nGUI_Init7");

	GUI_Clear();
	GUI_SetFont(&GUI_Font_HZK16);
	GUI_DispString("字体演示\n");
	GUI_SetFont(&GUI_Font6x8);
    GUI_DispString("\nGUI_Font6x8");
    GUI_SetFont(&GUI_Font8x8);
    GUI_DispString("\nGUI_Font8x8");
    GUI_SetFont(&GUI_Font8_ASCII);
    GUI_DispString("\nGUI_Font8_ASCII");
    GUI_SetFont(&GUI_Font8x16);
    GUI_DispString("\nGUI_Font8x16");
    GUI_SetFont(&GUI_Font16_ASCII);
    GUI_DispString("\nGUI_Font16_ASCII");
    GUI_SetFont(&GUI_Font16B_ASCII);
    GUI_DispString("\nGUI_Font16B_ASCII");
    GUI_SetFont(&GUI_Font16B_ASCII);
    GUI_DispString("\nGUI_Font16B_ASCII");
    GUI_SetFont(&GUI_Font24_ASCII);
    GUI_DispString("\nGUI_Font24_ASCII");
    GUI_SetFont(&GUI_FontComic24B_ASCII);
    GUI_DispString("\nGUI_FontComic24B_ASCII");
    GUI_SetFont(&GUI_Font32_ASCII);
    GUI_DispString("\nGUI_Font32_ASCII");
    GUI_SetFont(&GUI_Font32B_ASCII);
    GUI_DispString("\nGUI_Font32B_ASCII");
	
    
    Uart_Printf("\nKey %d Pressed",WaitKey());
    
    GUI_Clear();
    GUI_SetFont(&GUI_Font_HZK16);
	GUI_DispString("色彩演示(此屏最高支持十六级灰度)");
	ShowColorBar();
	
	Uart_Printf("\nKey %d Pressed",WaitKey());
	
	GUI_Clear();
    GUI_SetFont(&GUI_Font_HZK16);
	GUI_DispString("绘图函数演示");
//	GUI_Clear();
    GUI_SetDrawMode(GUI_DRAWMODE_NORMAL);
    GUI_FillCircle(120, 64, 40);
    GUI_SetDrawMode(GUI_DRAWMODE_XOR);
    GUI_FillCircle(140, 84, 40);
    
	Uart_Printf("\nKey %d Pressed",WaitKey());
	Uart_Printf("\nGUI_Init15");

	GUI_Clear();
	DrawPolygon();
	Uart_Printf("\nGUI_Init16");

	Uart_Printf("\nKey %d Pressed",WaitKey());
	
	GUI_Clear();
	for (i=10; i<50; i++)
		GUI_DrawCircle(100,100,i);
		
	Uart_Printf("\nKey %d Pressed",WaitKey());
	/*
    Demo ellipses
    */
    GUI_Clear();
    GUI_SetColor(0xff);
    GUI_FillEllipse(100, 100, 50, 70);
    GUI_SetColor(0x0);
    GUI_DrawEllipse(100, 100, 50, 70);
    GUI_SetColor(0x000000);
    GUI_FillEllipse(100, 100, 10, 50);
    Uart_Printf("\nGUI_Init17");

    Uart_Printf("\nKey %d Pressed",WaitKey());
	
	GUI_SetDefault();
	GUI_Clear();
	GUI_SetFont(&GUI_Font_HZK16);
	Uart_Printf("\nGUI_Init18");

	GUI_DispString("对话框演示");
	Uart_Printf("\nKey %d Pressed",WaitKey());

	GUI_SetFont(&GUI_Font6x8);
	GUIDEMO_Messagebox();
	Uart_Printf("\nGUI_Init19");
	
	Uart_Printf("\nKey %d Pressed",WaitKey());

	
    GUI_Clear();
    GUI_SetFont(&GUI_FontComic24B_ASCII);
    WM_SetDesktopColor(GUI_BLACK );      /* Automacally update desktop window */
    WM_SetCreateFlags(WM_CF_MEMDEV);  /* Use memory devices on all windows to avoid flicker */
    GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
    Uart_Printf("\nGUI_Init20");

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -