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

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        : MARQUEE.c
  16. Purpose     : emWin GSC bitmap widget, which allows to show blinking
  17.               bitmaps
  18. ----------------------------------------------------------------------
  19. Version-Date---Author-Explanation
  20. ----------------------------------------------------------------------
  21. 1.02     001011 RS     a) Debug info (logging option) added.
  22.                        b) Support for Zero-time (transparent)
  23.                           bitmaps added.
  24. 1.00     000613 RS     Release.
  25. 0.50     000223 RS     First (Beta) release
  26. 0.00     000107 RS     Start of development
  27. ----------------------------------------------------------------------
  28. Known problems or limitations with current version
  29. ----------------------------------------------------------------------
  30. None.
  31. ----------------------------------------------------------------------
  32. Open issues
  33. ----------------------------------------------------------------------
  34. None
  35. ---------------------------END-OF-HEADER------------------------------
  36. */
  37. #include "stdlib.h"
  38. #include "string.h"
  39. #include "MARQUEE.h"
  40. #include "GUIDEBUG.h"
  41. #include "GUI.h"
  42. #if GUI_WINSUPPORT
  43. /*
  44.   *****************************************************************
  45.   *                                                               *
  46.   *              Config defaults                                  *
  47.   *                                                               *
  48.   *****************************************************************
  49. */
  50. #ifndef MARQUEE_LOG_ENABLE
  51.   #ifdef _DEBUG
  52.     #define MARQUEE_LOG_ENABLE 0
  53.   #else
  54.     #define MARQUEE_LOG_ENABLE 0
  55.   #endif
  56. #endif
  57. /*
  58.   *****************************************************************
  59.   *
  60.   *              Internal macros
  61.   *
  62.   *****************************************************************
  63. */
  64. #define Invalidate(h) WM_InvalidateWindow(h)
  65. #if MARQUEE_LOG_ENABLE
  66.   #define LOG(s) SIM_Log(s)
  67.   #define LOG1(s,p1) SIM_Log(s,p1)
  68.   #define LOG_TIME() SIM_LogTime()
  69. #else
  70.   #define LOG(s)
  71.   #define LOG1(s)
  72.   #define LOG_TIME()
  73. #endif
  74. /*
  75.       *************************************************************
  76.       *                                                           *
  77.       *                 LIST ITEM  definition                     *
  78.       *                                                           *
  79.       *************************************************************
  80. */
  81. /*
  82.       *************************************************************
  83.       *                                                           *
  84.       *                 Object definition                         *
  85.       *                                                           *
  86.       *************************************************************
  87. */
  88. typedef struct {
  89.   WM_Obj WMObj;
  90.   GUI_TIMER_Handle hTimer;
  91.   WM_HMEM hpText;
  92.   GUI_COLOR TextColor;
  93.   GUI_COLOR BkColor;
  94.   const GUI_FONT* pFont;
  95. #ifdef _DEBUG
  96.   int Id;
  97. #endif  
  98. } MARQUEE_Obj;
  99. /*
  100.   *****************************************************************
  101.   *                                                               *
  102.   *              Static data                                      *
  103.   *                                                               *
  104.   *****************************************************************
  105. */
  106. /* None */
  107. /*
  108.   ********************************************************************
  109.   *                                                                  *
  110.   *                 Macros for internal use                          *
  111.   *                                                                  *
  112.   ********************************************************************
  113. */
  114. #define MARQUEE_ID 0x4249544d
  115. #define MARQUEE_H2P(h) (MARQUEE_Obj*) WM_HMEM2Ptr(h)
  116. #define LI_H2P(h)     (LI_Obj*)     WM_HMEM2Ptr(h)
  117. #ifdef _DEBUG
  118.   #define MARQUEE_ASSERT_IS_VALID_PTR(p) WM_ASSERT(p->Id == MARQUEE_ID)
  119.   #define MARQUEE_INIT_ID(p)   p->Id = MARQUEE_ID
  120.   #define MARQUEE_DEINIT_ID(p) p->Id = MARQUEE_ID+1
  121. #else
  122.   #define MARQUEE_ASSERT_IS_VALID_PTR(p)
  123.   #define MARQUEE_INIT_ID(p)
  124.   #define MARQUEE_DEINIT_ID(p)
  125. #endif
  126. /*
  127.   ********************************************************************
  128.   *                                                                  *
  129.   *                    Static routines                               *
  130.   *                                                                  *
  131.   ********************************************************************
  132. */
  133. static void FreeAttached(MARQUEE_Handle hObj) {
  134.   MARQUEE_Obj* pObj = MARQUEE_H2P(hObj);
  135.   WM_FREEPTR(&pObj->hpText);
  136. }
  137. static void Paint(MARQUEE_Obj* pObj/*, GUI_RECT*pRect*/) {
  138.   const char*s = (const char*) WM_HMEM2Ptr(pObj->hpText);
  139.   GUI_SetFont    (pObj->pFont);
  140.   GUI_SetBkColor (pObj->BkColor);
  141.   GUI_SetColor   (pObj->TextColor);
  142.   GUI_DispStringAt(s,0,0);
  143.   LOG_TIME(); LOG("MARQUEE: Paint(..)n");
  144. }
  145. static void Delete(MARQUEE_Obj* pObj) {
  146.   if (pObj->hTimer) {
  147.     GUI_TIMER_Delete(pObj->hTimer);
  148.     pObj->hTimer =0;
  149. }
  150.   if (pObj->hpText) {
  151. //    GUI_ALLOC_Free(hLI);
  152.     LOG_TIME(); LOG("MARQUEE: Delete: Deleting attached stringn");
  153.   }
  154. }
  155. static void _Callback (WM_MESSAGE * pMsg) {
  156.   MARQUEE_Handle hObj = (MARQUEE_Handle)pMsg->hWin;
  157.   MARQUEE_Obj* pObj = MARQUEE_H2P(hObj);
  158.   switch (pMsg->MsgId) {
  159.   case WM_PAINT:
  160.     LOG_TIME(); LOG("MARQUEE: _Callback(WM_PAINT)n");
  161.     Paint(pObj/*, (GUI_RECT*)pMsg->Data.p*/);
  162.     return;
  163.   case WM_DELETE:
  164.     LOG_TIME(); LOG("MARQUEE: _Callback(WM_DELETE)n");
  165.     Delete(pObj);
  166.     break;       /* No return here ... WM_DefaultProc needs to be called */
  167. #if MARQUEE_LOG_ENABLE  /* Debug code ... normally not compiled */
  168.   case WM_CREATE:
  169.     LOG_TIME(); LOG("MARQUEE: _Callback(WM_CREATE)n");
  170.     break;       /* No return here ... WM_DefaultProc needs to be called */
  171.   default:
  172.     LOG_TIME(); LOG("MARQUEE: _Callback(unhandle message)n");
  173. #endif
  174.   }
  175.   WM_DefaultProc(pMsg);
  176. }
  177. static void cbTimer (GUI_TIMER_MESSAGE *pMsg) {
  178.   MARQUEE_Handle hObj = pMsg->Context;
  179.   MARQUEE_Obj*   pObj = MARQUEE_H2P(hObj);
  180.   pObj = pObj;
  181.   MARQUEE_ASSERT_IS_VALID_PTR(pObj);
  182.   LOG_TIME(); LOG("MARQUEE: cbTimern");
  183. //  ShowNext(pObj);
  184. }
  185. /*
  186.   ********************************************************************
  187.   *                                                                  *
  188.   *        Exported routines:  Create                                *
  189.   *                                                                  *
  190.   ********************************************************************
  191. */
  192. /* Note: the parameters to a create function may vary.
  193.          Some widgets may have multiple create functions */
  194. MARQUEE_Handle MARQUEE_Create      (
  195.                                     int x0, int y0, int xsize, int ysize,
  196.                                     int Flags)
  197. {
  198.   /* Alloc memory for obj */
  199.   MARQUEE_Handle hObj =  WM_CreateWindow(x0, y0, xsize, ysize,
  200.                   WM_CF_SHOW |Flags, _Callback,
  201.                   sizeof(MARQUEE_Obj)-sizeof(WM_Obj));
  202.   if (hObj) {
  203.     MARQUEE_Obj* pObj = MARQUEE_H2P(hObj);
  204.     /* init widget specific variables */
  205.     /* init member variables */
  206.     MARQUEE_INIT_ID(pObj);
  207.     pObj->pFont =GUI_DEFAULT_FONT;
  208.     pObj->BkColor   = GUI_BLACK;
  209.     pObj->TextColor = GUI_WHITE;
  210. /* Create Timer */
  211.     pObj->hTimer = GUI_TIMER_Create(cbTimer,
  212.                             0,    /* Time, 0 means not yet active */
  213.                                 hObj, /* Instance handle */
  214. 0);
  215.   }
  216.   return hObj;
  217. }
  218. /*
  219.   ********************************************************************
  220.   *                                                                  *
  221.   *        Exported routines:  Various methods                       *
  222.   *                                                                  *
  223.   ********************************************************************
  224. */
  225. void MARQUEE_SetText(MARQUEE_Handle hObj, const char* s) {
  226.   MARQUEE_Obj* pObj = MARQUEE_H2P(hObj);
  227.   FreeAttached(hObj);
  228.   {
  229.     WM_HMEM hMem = WM_ALLOC(strlen(s)+1);
  230.     strcpy((char *) WM_HMEM2Ptr(hMem), s);
  231.     pObj->hpText = hMem;
  232.   }
  233.   Invalidate(hObj);
  234. }
  235. void MARQUEE_SetFont(MARQUEE_Handle hObj, const GUI_FONT* pfont) {
  236.   MARQUEE_Obj* pObj = MARQUEE_H2P(hObj);
  237.   pObj->pFont = pfont;
  238.   Invalidate(hObj);
  239. }
  240. void MARQUEE_SetBkColor(MARQUEE_Handle hObj, GUI_COLOR color) {
  241.   MARQUEE_Obj* pObj = MARQUEE_H2P(hObj);
  242.   pObj->BkColor = color;
  243.   Invalidate(hObj);
  244. }
  245. void MARQUEE_SetTextColor(MARQUEE_Handle hObj, GUI_COLOR color) {
  246.   MARQUEE_Obj* pObj = MARQUEE_H2P(hObj);
  247.   pObj->TextColor = color;
  248.   Invalidate(hObj);
  249. }
  250. #else
  251. void WIDGET_Marquee(void) {} /* avoid empty object files */
  252. #endif