GUICore.c
上传用户:zbk8730
上传日期:2017-08-10
资源大小:12168k
文件大小:4k
源码类别:

uCOS

开发平台:

C/C++

  1. /*
  2. *********************************************************************************************************
  3. *                                                uC/GUI
  4. *                        Universal graphic software for embedded applications
  5. *
  6. *                       (c) Copyright 2002, Micrium Inc., Weston, FL
  7. *                       (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH
  8. *
  9. *              礐/GUI is protected by international copyright laws. Knowledge of the
  10. *              source code may not be used to write a similar product. This file may
  11. *              only be used in accordance with a license and should not be redistributed
  12. *              in any way. We appreciate your understanding and fairness.
  13. *
  14. ----------------------------------------------------------------------
  15. File        : GUICore.C
  16. Purpose     : Core file for emWin GSC
  17. ---------------------------END-OF-HEADER------------------------------
  18. */
  19. #include <stddef.h>           /* needed for definition of NULL */
  20. #define  GL_CORE_C
  21. #include "GUI_Private.H"
  22. #include "GUIDebug.h"
  23. /*********************************************************************
  24. *
  25. *            GUI_ClearRect
  26. *
  27. **********************************************************************
  28. */
  29. void GUI_ClearRect(int x0, int y0, int x1, int y1) {
  30.   GUI_DRAWMODE PrevDraw;
  31.   GUI_LOCK();
  32.   PrevDraw = LCD_SetDrawMode(GUI_DRAWMODE_REV);
  33.   #if GUI_WINSUPPORT
  34.     WM_ADDORG(x0,y0);
  35.     WM_ADDORG(x1,y1);
  36.     WM_ITERATE_START(NULL) {
  37.   #endif
  38.   LCD_FillRect(x0,y0,x1,y1);
  39.   #if GUI_WINSUPPORT
  40.     } WM_ITERATE_END();
  41.   #endif
  42.   LCD_SetDrawMode(PrevDraw);
  43.   GUI_UNLOCK();
  44. }
  45. /*********************************************************************
  46. *
  47. *            GUI_Clear
  48. *
  49. **********************************************************************
  50. */
  51. void GUI_Clear(void) {
  52.   GUI_GotoXY(1,1);     /* Reset text cursor to upper left */
  53.   GUI_ClearRect(GUI_XMIN, GUI_YMIN, GUI_XMAX, GUI_YMAX);
  54. }
  55. /*
  56.         ********************************************************
  57.         *                                                      *
  58.         *                 GUI_SelectLCD                        *
  59.         *                                                      *
  60.         ********************************************************
  61. */
  62. #if GUI_SUPPORT_MEMDEV
  63. void GUI_SelectLCD(void) {
  64.   int hDevDataOld = GUI_Context.hDevData;
  65.   GUI_Context.hDevData = 0;
  66.   GUI_Context.pDeviceAPI   = &LCD_L0_APIList;
  67.   GUI_Context.pClipRect_HL = &GUI_Context.ClipRect;
  68.   LCD_SetClipRectMax();
  69.   /* If we are switching batck, restore the former clip rect */
  70.   if (hDevDataOld)
  71.     GUI_Context.ClipRect = GUI_Context.ClipRectPrev;
  72.   #if GUI_WINSUPPORT
  73.     WM_Activate();
  74.   #endif
  75. }
  76. #endif
  77. /*
  78.         ********************************************************
  79.         *                                                      *
  80.         *                 GUI_Init                             *
  81.         *                                                      *
  82.         *     Init of GUI internal data structures & variables *
  83.         *                                                      *
  84.         ********************************************************
  85. */
  86. const tLCD_HL_APIList LCD_HL_APIList = {
  87.   LCD_DrawHLine,
  88.   LCD_DrawPixel
  89. };
  90. static void _InitContext(GUI_CONTEXT* pContext) {
  91. memset(pContext,0,sizeof(GUI_CONTEXT));//add
  92.   #if GUI_SUPPORT_MEMDEV
  93.     GUI_SelectLCD();
  94.   #else
  95.     LCD_SetClipRectMax();
  96.   #endif
  97.   pContext->pLCD_HL      = &LCD_HL_APIList;
  98.   pContext->pAFont       = GUI_DEFAULT_FONT;
  99.   pContext->pClipRect_HL = &GUI_Context.ClipRect;
  100.   pContext->PenSize      = 1;
  101.   
  102. pContext->DrawMode = GUI_DRAWMODE_NORMAL;//add
  103.   
  104.    pContext->TextMode = GUI_TEXTMODE_NORMAL;//add
  105.   
  106.    pContext->TextAlign = GUI_TA_LEFT|GUI_TA_TOP;//add
  107.   
  108.   pContext->AA_HiResEnable = 0;//add
  109.   /* Variables in WM module */
  110.   #if GUI_WINSUPPORT
  111.     pContext->hAWin    = WM_GetDesktopWindow();
  112.   #endif
  113.   /* Variables in GUI_AA module */
  114.   pContext->AA_Factor = 3;
  115.   LCD_SetBkColor(GUI_DEFAULT_BKCOLOR);
  116.   LCD_SetColor(GUI_DEFAULT_COLOR);
  117. }
  118. int GUI_Init(void) {
  119.   int r;
  120.   GUI_DEBUG_LOG("nGUI_Init()");
  121.   /* Init system wide globals first */
  122.   GUI_DecChar = '.';
  123.   GUI_X_Init();
  124.   /* Init context */
  125.   _InitContext(&GUI_Context);
  126.   GUITASK_INIT();
  127.   r = LCD_Init();
  128.   #if GUI_WINSUPPORT
  129.     WM_Init();
  130.   #endif
  131.   return r;
  132. }