/*******************************************************************
*
*       MainTask
*/
void MainTask(void) {
  int xPos;
  int yPos;
  int xSize;
  int i;
  
  i = 0;
  GUI_Init();
  //
  // Check if recommended memory for the sample is available
  //
  if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
    GUI_ErrorOut("Not enough memory available."); 
    return;
  }
  xPos = LCD_GetXSize() / 2;
  yPos = LCD_GetYSize() / 3;
  GUI_SetTextMode(GUI_TM_REV);
  GUI_SetFont(GUI_FONT_20F_ASCII);
  GUI_DispStringHCenterAt("Hello world!", xPos, yPos);
  GUI_SetFont(GUI_FONT_D24X32);
  xSize = GUI_GetStringDistX("0000");
  xPos -= xSize / 2;
  yPos += 24 + 10;
  while (1) {
    GUI_DispDecAt( i++, xPos, yPos, 4);
    if (i > 9999) {
      i = 0;
    }
  }
}
/*********************************************************************
*
*       _GetItemSizeX
*/
static int _GetItemSizeX(WM_HWIN hWin, int ItemIndex) {
  char acBuffer[100];
  int  DistX;
  LISTBOX_GetItemText(hWin, ItemIndex, acBuffer, sizeof(acBuffer));
  DistX = GUI_GetStringDistX(acBuffer);
  return DistX + bmSmilie0.XSize + 16;
}
예제 #3
0
/*********************************************************************
*
*       _GetPageSizeX
*
*  Returns the width of a page item.
*/
static int _GetPageSizeX(MULTIPAGE_Obj* pObj, unsigned Index) {
  int r = 0;
  if ((int)Index < pObj->Handles.NumItems) {
    MULTIPAGE_PAGE* pPage;
    GUI_SetFont(pObj->Font);
    pPage = (MULTIPAGE_PAGE*) GUI_ARRAY_GetpItem(&pObj->Handles, Index);
    r = GUI_GetStringDistX(&pPage->acText) + 10;
  }
  return r;
}
예제 #4
0
/*********************************************************************
*
*       _Paint
*/
static void _Paint(PROGBAR_Handle hObj) {
  PROGBAR_Obj* pObj = PROGBAR_H2P(hObj);
  WM_HWIN hWin = hObj;
  int xsize = WM_GetWindowSizeX(hWin);
  int ysize = WM_GetWindowSizeY(hWin);
  int tm;
  GUI_SetFont(pObj->pFont);
  {
    int x1;
    int FontSizeY = GUI_GetFontSizeY();
    int xText = 0;
    int yText = (ysize-FontSizeY)/2;
    GUI_RECT r;
    int XSizeChar;
    char ac[5];   /* Just enough for the percentage */
    char*s = ac;
    const char* pText;
    if (pObj->hpText != WM_HMEM_NULL) {
      pText = (const char*) WM_HMEM2Ptr(pObj->hpText);
    } else {
      GUI_AddDecMin((100*(I32)(pObj->v-pObj->Min))/(pObj->Max-pObj->Min), &s);
      *s = '%';
			*(s+1) =0;
			pText = &ac[0];
		}
/* Calculate text positions */
    XSizeChar = GUI_GetStringDistX(pText);
    x1 = _Value2X(hObj, pObj->v);
    switch (pObj->TextAlign &GUI_TA_HORIZONTAL) {
    case GUI_TA_CENTER:
      xText  = (xsize-XSizeChar)/2;
			break;
    case GUI_TA_LEFT:
      xText  = 0;
			break;
    case GUI_TA_RIGHT:
      xText  = xsize-XSizeChar-1;
			break;
		}
    xText += pObj->XOff;
    yText += pObj->YOff;
    tm = GUI_SetTextMode(GUI_TM_TRANS);
/* Draw left bar */
    r.x0=0; r.x1=x1-1; r.y0=0; r.y1 = GUI_YMAX;
    WM_SetUserClipArea(&r);
    _DrawPart(pObj, 0, xText, yText, pText);
/* Draw right bar */
    r.x0=r.x1+1; r.x1=GUI_XMAX;
    WM_SetUserClipArea(&r);
    _DrawPart(pObj, 1, xText, yText, pText);
  }
  WM_SetUserClipArea(NULL);
  GUI_SetTextMode(tm);
}
예제 #5
0
LISTBOX_Handle LISTBOX_CreateAsChild(
  const GUI_ConstString* ppText,
  WM_HWIN hWinParent,
  int x0, int y0, int xsize, int ysize, int Flags)
{
  LISTBOX_Handle hObj = WM_CreateWindowAsChild(x0, y0, xsize, ysize, 
                                               hWinParent, Flags, _LISTBOX_Callback,
                                               sizeof(LISTBOX_Obj)-sizeof(WM_Obj));
  if (hObj) {
    LISTBOX_Obj* pObj   = LISTBOX_H2P(hObj);
    /* init widget specific variables */
    WIDGET__Init(&pObj->Widget, WIDGET_STATE_FOCUSSABLE | WIDGET_STATE_ENABLED);
    /* pObj->ppText = 0; */   /* Zero init not required */
    pObj->pFont  = _pDefaultFont;
    pObj->aBackColor[0] = 0xffffff;            /* Non selected state */
    pObj->aBackColor[1] = LISTBOX_BKCOLOR1_DEFAULT;    /* selected state */
    pObj->aBackColor[2] = GUI_BLUE;            /* selected state with focus */
    pObj->aTextColor[0] = 0x000000;            /* Non selected state */
    pObj->aTextColor[1] = 0xffffff;            /* selected state */
    pObj->aTextColor[2] = 0xffffff;            /* selected state with focus */
    if (hObj && ppText) {
      LISTBOX_Obj* pObj   = LISTBOX_H2P(hObj);
      INIT_ID(pObj);
      /* init member variables */
      /* Check size */
      if (!xsize) {
        const GUI_FONT* pFontOld = GUI_SetFont(pObj->pFont);
        int i;
		    for (i=0; *(ppText+i); i++) {
          int Size = GUI_GetStringDistX(*(ppText+i));
          if (Size>xsize)
			      xsize = Size;
		    }
        GUI_SetFont(pFontOld);
	    }
      /* Set non-zero attributes */
      pObj->ppText = ppText;
    }
    _CalcScrollParas(hObj);
  }
  return hObj;
}
예제 #6
0
    /*****************************************************************************
    * Function
    * DESCRIPTION:
    * Redraws or clears the colon.
    *****************************************************************************/
    bool DataPointTime::RedrawColon()
    {
      if (mVisible)
      {
        int x = 0;
        int minutes = mTime.GetTime(MINUTES);

        char sz_time[10];
        if (mFormat == DATETIME_FORMAT_MDY_AMPM)// timeformat using am/pm
        {
          bool isAm;
          int hoursOffset;
          GetAs12HourClock(&isAm, &hoursOffset);
          sprintf(sz_time, ":%02d %s", minutes, isAm ? "am" : "pm");
        }
        else
        {
          sprintf(sz_time, ":%02d", minutes);
        }

        SelectWindow();
        GUI_SetColor(mColour);
        GUI_SetBkColor(mBackgroundColour);
        GUI_SetFont(GetFont());

        x = GetWidth() - GUI_GetStringDistX(sz_time);

        if (mShowColon)
        {
          GUI_DispStringAt(":", x, 2);
          mLastColonPosition = x;
        }
        else if (mLastColonPosition == x)
        {
          GUI_ClearRect(x, 0, x + 1, GetHeight() - 1);
        }

        Validate();
      }
      
      return true;
    }
예제 #7
0
/*******************************************************************
*
*       MainTask
*/
void MainTask(void) {
  int xPos, yPos, xSize;
  int i = 0;

  GUI_Init();
  xPos = LCD_GetXSize() / 2;
  yPos = LCD_GetYSize() / 3;
  GUI_SetTextMode(GUI_TM_REV);
  GUI_SetFont(GUI_FONT_20F_ASCII);
  GUI_DispStringHCenterAt("Hello world!", xPos, yPos);
  GUI_SetFont(GUI_FONT_D24X32);
  xSize = GUI_GetStringDistX("0000");
  xPos -= xSize / 2;
  yPos += 24 + 10;
  while (1) {
    GUI_DispDecAt( i++, xPos, yPos, 4);
    if (i > 9999) {
      i = 0;
    }
  }
}
예제 #8
0
/*********************************************************************
*
*       GUI__CalcTextRect
*/
void GUI__CalcTextRect(const char GUI_UNI_PTR* pText, const GUI_RECT* pTextRectIn, GUI_RECT* pTextRectOut, int TextAlign) {
  if (pText) {
    int xPos, yPos, TextWidth, TextHeight;

    /* Calculate X-pos of text */
    TextWidth = GUI_GetStringDistX(pText);
    switch (TextAlign & GUI_TA_HORIZONTAL) {
    case GUI_TA_HCENTER:
      xPos = pTextRectIn->x0 + ((pTextRectIn->x1 - pTextRectIn->x0 + 1) - TextWidth) / 2;
      break;
    case GUI_TA_RIGHT:
      xPos = pTextRectIn->x1 - TextWidth + 1;
      break;
    default:
      xPos = pTextRectIn->x0;
    }

    /* Calculate Y-pos of text*/
    TextHeight = GUI_GetFontDistY();
    switch (TextAlign & GUI_TA_VERTICAL) {
    case GUI_TA_VCENTER:
      yPos = pTextRectIn->y0 + ((pTextRectIn->y1 - pTextRectIn->y0 + 1) - TextHeight) / 2;
      break;
    case GUI_TA_BOTTOM:
      yPos = pTextRectIn->y1 - TextHeight + 1;
      break;
    case GUI_TA_BASELINE:
    default:
      yPos = pTextRectIn->y0;
    }

    /* Return text rectangle */
    pTextRectOut->x0 = xPos;
    pTextRectOut->y0 = yPos;
    pTextRectOut->x1 = xPos + TextWidth  - 1;
    pTextRectOut->y1 = yPos + TextHeight - 1;
  } else {
    *pTextRectOut = *pTextRectIn;
  }
}
예제 #9
0
/*********************************************************************
*
*       _GetTextRect
*/
static void _GetTextRect(const PROGBAR_Obj* pObj, GUI_RECT* pRect, const char* pText) {
  int xSize      = pObj->Widget.Win.Rect.x1 - pObj->Widget.Win.Rect.x0 + 1;
  int ySize      = pObj->Widget.Win.Rect.y1 - pObj->Widget.Win.Rect.y0 + 1;
  int TextWidth  = GUI_GetStringDistX(pText);
  int TextHeight = GUI_GetFontSizeY();
  int EffectSize = pObj->Widget.pEffect->EffectSize;
  switch (pObj->TextAlign & GUI_TA_HORIZONTAL) {
  case GUI_TA_CENTER:
    pRect->x0 = (xSize - TextWidth) / 2;
		break;
  case GUI_TA_RIGHT:
    pRect->x0 = xSize - TextWidth - 1 - EffectSize;
		break;
  default:
    pRect->x0 = EffectSize;
	}
  pRect->y0  = (ySize - TextHeight) / 2;
  pRect->x0 += pObj->XOff;
  pRect->y0 += pObj->YOff;
  pRect->x1  = pRect->x0 + TextWidth  - 1;
  pRect->y1  = pRect->y0 + TextHeight - 1;
}
예제 #10
0
/*********************************************************************
*
*       EDIT_SetCursorAtPixel
*/
void EDIT_SetCursorAtPixel(EDIT_Handle hObj, int xPos) {
  if (hObj) {
    EDIT_Obj* pObj;
    WM_LOCK();
    pObj = EDIT_H2P(hObj);
    if (pObj->hpText) {    
      const GUI_FONT GUI_UNI_PTR *pOldFont;
      int xSize, TextWidth, NumChars;
      const char GUI_UNI_PTR * pText;
      pText = (char*) GUI_ALLOC_h2p(pObj->hpText);
      pOldFont = GUI_SetFont(pObj->Props.pFont);
      xSize = WM_GetWindowSizeX(hObj);
      TextWidth = GUI_GetStringDistX(pText);
      switch (pObj->Props.Align & GUI_TA_HORIZONTAL) {
      case GUI_TA_HCENTER:
        xPos -= (xSize - TextWidth + 1) / 2;
        break;
      case GUI_TA_RIGHT:
        xPos -= xSize - TextWidth - (pObj->Props.Border + EDIT_XOFF);
        break;
      default:
        xPos -= (pObj->Props.Border + EDIT_XOFF) + pObj->Widget.pEffect->EffectSize;
      }
      NumChars = GUI__GetNumChars(pText);
      if (xPos < 0) {
        EDIT__SetCursorPos(pObj, 0);
      } else if (xPos > TextWidth) {
        EDIT__SetCursorPos(pObj, NumChars);
      } else {
        EDIT__SetCursorPos(pObj, GUI__GetCursorPosChar(pText, xPos, NumChars));
      }
      GUI_SetFont(pOldFont);
      EDIT_Invalidate(hObj);
    }
    WM_UNLOCK();
  }
}
예제 #11
0
/*********************************************************************
*
*       _SetCursor
*/
static void _SetCursor(EDIT_Handle hObj, EDIT_Obj* pObj, int x) {
    int xPos, xSize, PixelLen, Len;
    char * s = (char*) WM_HMEM2Ptr(pObj->hpText);
    const GUI_FONT *pOldFont = GUI_SetFont(pObj->pFont);
    xSize = WM_GetWindowSizeX(hObj);
    PixelLen = GUI_GetStringDistX(s);
    xPos = x;
    switch (pObj->Align & GUI_TA_HORIZONTAL) {
    case GUI_TA_CENTER:
        xPos -= (xSize - PixelLen + 1) / 2;
        break;
    case GUI_TA_LEFT:
        xPos -= (pObj->Border + EDIT_XOFF);
        break;
    case GUI_TA_RIGHT:
        xPos -= xSize - PixelLen - (pObj->Border + EDIT_XOFF);
        break;
    }
    Len = (int)strlen(s);
    if (xPos < 0) {
        pObj->CursorPos = 0;
    } else if (xPos > PixelLen) {
        pObj->CursorPos = Len;
    } else {
        int i, x;
        for (i = 0, x = 0; (i < Len) && (x < xPos); i++) {
            int xLenChar = GUI_GetCharDistX(*(s + i));
            if (xPos < (x + xLenChar))
                break;
            x += xLenChar;
        }
        pObj->CursorPos = i;
        EDIT_Invalidate(hObj);
    }
    GUI_SetFont(pOldFont);
}
예제 #12
0
/*********************************************************************
*
*       MESSAGEBOX_Create
*/
WM_HWIN MESSAGEBOX_Create(const char * sMessage, const char * sCaption, int Flags) {
  GUI_WIDGET_CREATE_INFO _aDialogCreate[3];                                     /* 0: FrameWin, 1: Text, 2: Button */
  int BorderSize = FRAMEWIN_GetDefaultBorderSize();                             /* Default border size of frame window */
  int xSizeFrame = MESSAGEBOX_XSIZEOK + 2 * BorderSize + MESSAGEBOX_BORDER * 2; /* XSize of frame window */
  int ySizeFrame;                                                               /* YSize of frame window */
  int x0, y0;                                                                   /* Position of frame window */
  int xSizeMessage;                                                             /* Length in pixels of message */
  int xSizeCaption;                                                             /* Length in pixels of caption */
  int ySizeCaption;                                                             /* YSize of caption */
  int ySizeMessage;                                                             /* YSize of message */
  WM_HWIN hBox;
  GUI_RECT Rect;
  const GUI_FONT GUI_UNI_PTR * pOldFont;
  /* Zeroinit variables */
  memset(_aDialogCreate, 0, sizeof(_aDialogCreate));
  /* Get dimension of message */
  pOldFont = GUI_SetFont(TEXT_GetDefaultFont());
  GUI_GetTextExtend(&Rect, sMessage, 255);
  xSizeMessage = Rect.x1 - Rect.x0 + MESSAGEBOX_BORDER * 2;
  ySizeMessage = Rect.y1 - Rect.y0 + 1;
  if (xSizeFrame < (xSizeMessage + 4 + MESSAGEBOX_BORDER * 2)) {
    xSizeFrame = xSizeMessage + 4 + MESSAGEBOX_BORDER * 2;
  }
  ySizeCaption = GUI_GetYSizeOfFont(FRAMEWIN_GetDefaultFont());
  ySizeFrame = ySizeMessage +            /* size of message */
               MESSAGEBOX_YSIZEOK +      /* size of button */
               ySizeCaption +            /* caption size */
               MESSAGEBOX_BORDER * 3 +   /* inner border - text, text - button, button - bottom */
               BorderSize * 2 +          /* top & bottom border */
               1;                        /* inner border */
  /* Get xsize of caption */
  xSizeCaption = GUI_GetStringDistX(sCaption);
  if (xSizeFrame < xSizeCaption + BorderSize * 2) {
    xSizeFrame = xSizeCaption + BorderSize * 2;
  }
  /* Check maximum */
  if (xSizeFrame > LCD_GET_XSIZE()) {
    xSizeFrame = LCD_GET_XSIZE();
  }
  if (ySizeFrame > LCD_GET_YSIZE()) {
    ySizeFrame = LCD_GET_YSIZE();
  }
  /* Calculate position of framewin */
  x0 = GUI_OrgX + (LCD_GET_XSIZE() - xSizeFrame) / 2;
  y0 = GUI_OrgY + (LCD_GET_YSIZE() - ySizeFrame) / 2;
  /* restore modified Context */
  GUI_SetFont(pOldFont);
  /* Fill frame win resource */
  _aDialogCreate[0].pfCreateIndirect = FRAMEWIN_CreateIndirect;
  _aDialogCreate[0].pName            = sCaption;
  _aDialogCreate[0].x0               = x0;
  _aDialogCreate[0].y0               = y0;
  _aDialogCreate[0].xSize            = xSizeFrame;
  _aDialogCreate[0].ySize            = ySizeFrame;
  if (Flags & GUI_MESSAGEBOX_CF_MOVEABLE) {
    _aDialogCreate[0].Flags          = FRAMEWIN_CF_MOVEABLE;
  }
  /* Fill text resource */
  _aDialogCreate[1].pfCreateIndirect = TEXT_CreateIndirect;
  _aDialogCreate[1].pName            = sMessage;
  _aDialogCreate[1].x0               = (xSizeFrame - xSizeMessage - BorderSize * 2) / 2;
  _aDialogCreate[1].y0               = MESSAGEBOX_BORDER;
  _aDialogCreate[1].xSize            = xSizeMessage;
  _aDialogCreate[1].ySize            = ySizeMessage;
  _aDialogCreate[1].Para             = GUI_TA_TOP | GUI_TA_HCENTER;
  /* Fill button resource */
  _aDialogCreate[2].pfCreateIndirect = BUTTON_CreateIndirect;
  _aDialogCreate[2].pName            = "OK";
  _aDialogCreate[2].Id               = GUI_ID_OK;
  _aDialogCreate[2].x0               = (xSizeFrame - MESSAGEBOX_XSIZEOK - BorderSize * 2) / 2;
  _aDialogCreate[2].y0               = MESSAGEBOX_BORDER * 2 + ySizeMessage;
  _aDialogCreate[2].xSize            = MESSAGEBOX_XSIZEOK;
  _aDialogCreate[2].ySize            = MESSAGEBOX_YSIZEOK;
  /* Create dialog */
  hBox = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), MESSAGEBOX_Callback, 0, 0, 0);
  if (Flags & GUI_MESSAGEBOX_CF_MODAL) {
    WM_MakeModal(hBox);
  }
  return hBox;
}
예제 #13
0
/*********************************************************************
*
*       _Paint
*/
static void _Paint(EDIT_Obj* pObj) {
    int PixelLen, xSize, ySize, xPosText = 0,
                                xPosCursor = 0, yPosText = 0, yPosCursor = 0, XSizeCursor, YSizeCursor;
    int IsEnabled;
    GUI_RECT rClient, rWindow;
    char * s;
    s = (char*) WM_HMEM2Ptr(pObj->hpText);
    GUI_DEBUG_LOG("BUTTON: _Paint(..)\n");
    if (pObj->Border) {
        GUI_SetBkColor(pObj->aBkColor[0]);
        GUI_Clear();
    }
    IsEnabled = WIDGET__IsEnabled(&pObj->Widget);
    /* Set clipping rectangle */
    WIDGET__GetInsideRect(&pObj->Widget, &rWindow);
    WM_SetUserClipRect(&rWindow);
    /* Calculate size */
    GUI_GetClientRect(&rClient);
    xSize = rClient.x1 - rClient.x0 + 1;
    ySize = rClient.y1 - rClient.y0 + 1;
    /* Draw background */
    GUI_SetBkColor (pObj->aBkColor[IsEnabled]);
    GUI_SetColor   (pObj->aTextColor[0]);
    GUI_Clear();
    /* Calculate length */
    GUI_SetFont    (pObj->pFont);
    PixelLen = GUI_GetStringDistX(s);
    /* Calculate size of cursor */
    YSizeCursor = GUI_GetFontDistY();
    if (pObj->EditMode == GUI_EDIT_MODE_INSERT) {
        if (pObj->XSizeCursor != 0) {
            XSizeCursor = pObj->XSizeCursor;
        } else {
            XSizeCursor = GUI_GetCharDistX(' ');
        }
    } else {
        if (pObj->CursorPos < (int)strlen(s))  {
            XSizeCursor = GUI_GetCharDistX(*(s + pObj->CursorPos));
        } else {
            XSizeCursor = pObj->XSizeCursor;
        }
    }
    /* Calculate X-pos */
    switch (pObj->Align & GUI_TA_HORIZONTAL) {
    case GUI_TA_CENTER:
        xPosCursor = (xSize - PixelLen + 1) / 2;
        xPosText = xSize / 2;
        break;
    case GUI_TA_LEFT:
        xPosCursor = pObj->Border + EDIT_XOFF;
        xPosText   = pObj->Border + EDIT_XOFF;
        break;
    case GUI_TA_RIGHT:
        xPosCursor = xSize - (pObj->Border + EDIT_XOFF) - PixelLen;
        xPosText   = xSize - (pObj->Border + EDIT_XOFF);
        break;
    }
    /* Calculate Y-pos */
    switch (pObj->Align & GUI_TA_VERTICAL) {
    case GUI_TA_TOP:
        yPosCursor = 0;
        yPosText = 0;
        break;
    case GUI_TA_BOTTOM:
        yPosCursor = ySize - YSizeCursor;
        yPosText = ySize;
        break;
    case GUI_TA_VCENTER:
        yPosCursor = (ySize - YSizeCursor + 1) / 2;
        yPosText = ySize / 2;
        break;
    }
    /* Display text */
    GUI_SetTextAlign(pObj->Align);
    GUI_DispStringAt(s, xPosText, yPosText);
    /* Display cursor */
    if (pObj->Widget.State & WIDGET_STATE_FOCUS) {
        int i;
        for (i = 0; i != pObj->CursorPos; i++) {
            xPosCursor += GUI_GetCharDistX(*(s + i));
        }
        GUI_InvertRect(xPosCursor,
                       yPosCursor,
                       xPosCursor + XSizeCursor - 1,
                       yPosCursor + YSizeCursor - 1);
    }
    WM_SetUserClipRect(NULL);
    /* Draw the 3D effect (if configured) */
    WIDGET__EFFECT_DrawDown(&pObj->Widget);
}
예제 #14
0
/*********************************************************************
*
*       _OnPaint
*
* Purpose:
*   Paints the RADIO button.
*   The button can actually consist of multiple buttons (NumItems).
*   The focus rectangle will be drawn on top of the text if any text is set,
*   otherwise around the entire buttons.
*/
static void _OnPaint(RADIO_Handle hObj, RADIO_Obj* pObj) {
  const GUI_BITMAP* pBmRadio;
  const GUI_BITMAP* pBmCheck;
  const char* pText;
  GUI_FONTINFO FontInfo;
  GUI_RECT Rect, r, rFocus = {0};
  int i, y, HasFocus, FontDistY;
  U8 SpaceAbove, CHeight, FocusBorder;

  /* Init some data */
  WIDGET__GetClientRect(&pObj->Widget, &rFocus);
  HasFocus  = (pObj->Widget.State & WIDGET_STATE_FOCUS) ? 1 : 0;
  pBmRadio  = pObj->apBmRadio[WM__IsEnabled(hObj)];
  pBmCheck  = pObj->pBmCheck;
  rFocus.x1 = pBmRadio->XSize + RADIO_BORDER * 2 - 1;
  rFocus.y1 = pObj->Height + ((pObj->NumItems - 1) * pObj->Spacing) - 1;

  /* Select font and text color */
  LCD_SetColor(pObj->TextColor);
  GUI_SetFont(pObj->pFont);
  GUI_SetTextMode(GUI_TM_TRANS);

  /* Get font infos */
  GUI_GetFontInfo(pObj->pFont, &FontInfo);
  FontDistY   = GUI_GetFontDistY();
  CHeight     = FontInfo.CHeight;
  SpaceAbove  = FontInfo.Baseline - CHeight;
  Rect.x0     = pBmRadio->XSize + RADIO_BORDER * 2 + 2;
  Rect.y0     = (CHeight <= pObj->Height) ? ((pObj->Height - CHeight) / 2) : 0;
  Rect.y1     = Rect.y0 + CHeight - 1;
  FocusBorder = (FontDistY <= 12) ? 2 : 3;
  if (Rect.y0 < FocusBorder) {
    FocusBorder = Rect.y0;
  }

  /* Clear inside ... Just in case      */
  /* Fill with parents background color */
#if WM_SUPPORT_TRANSPARENCY
  if (!WM_GetHasTrans(hObj))
#endif
  {
    if (pObj->BkColor != GUI_INVALID_COLOR) {
      LCD_SetBkColor(pObj->BkColor);
    } else {
      LCD_SetBkColor(RADIO_DEFAULT_BKCOLOR);
    }
    GUI_Clear();
  }

  /* Iterate over all items */
  for (i = 0; i < pObj->NumItems; i++) {
    y = i * pObj->Spacing;
    /* Draw the radio button bitmap */
    GUI_DrawBitmap(pBmRadio, RADIO_BORDER, RADIO_BORDER + y);
    /* Draw the check bitmap */
    if (pObj->Sel == i) {
      GUI_DrawBitmap(pBmCheck, RADIO_BORDER +  (pBmRadio->XSize - pBmCheck->XSize) / 2, 
                               RADIO_BORDER + ((pBmRadio->YSize - pBmCheck->YSize) / 2) + y);
    }
    /* Draw text if available */
    pText = (const char*)GUI_ARRAY_GetpItem(&pObj->TextArray, i);
    if (pText) {
      if (*pText) {
        r = Rect;
        r.x1 = r.x0 + GUI_GetStringDistX(pText) - 2;
        GUI_MoveRect(&r, 0, y);
        GUI_DispStringAt(pText, r.x0, r.y0 - SpaceAbove);
        /* Calculate focus rect */
        if (HasFocus && (pObj->Sel == i)) {
          _ResizeRect(&rFocus, &r, FocusBorder);
        }
      }
    }
  }

  /* Draw the focus rect */
  if (HasFocus) {
    LCD_SetColor(GUI_BLACK);
    WIDGET__DrawFocusRect(&pObj->Widget, &rFocus, 0);
  }
}
예제 #15
0
/*********************************************************************
*
*       _Paint
*/
static void _Paint(CHECKBOX_Obj* pObj, CHECKBOX_Handle hObj) {
  GUI_RECT RectBox = {0};
  int ColorIndex, EffectSize, Index;
  EffectSize = pObj->Widget.pEffect->EffectSize;
  ColorIndex = WM__IsEnabled(hObj);
  /* Clear inside ... Just in case      */
  /* Fill with parents background color */
#if WM_SUPPORT_TRANSPARENCY
  if (!WM_GetHasTrans(hObj))
#endif
  {
    if (pObj->Props.BkColor == GUI_INVALID_COLOR) {
      LCD_SetBkColor(WIDGET__GetBkColor(hObj));
    } else {
      LCD_SetBkColor(pObj->Props.BkColor);
    }
    GUI_Clear();
  }
  /* Get size from bitmap */
  RectBox.x1 = pObj->Props.apBm[CHECKBOX_BI_ACTIV]->XSize - 1 + 2 * EffectSize;
  RectBox.y1 = pObj->Props.apBm[CHECKBOX_BI_ACTIV]->YSize - 1 + 2 * EffectSize;
  WM_SetUserClipRect(&RectBox);
  /* Clear inside  ... Just in case */
  LCD_SetBkColor(pObj->Props.aBkColorBox[ColorIndex]);
  GUI_Clear();
  Index = pObj->CurrentState * 2 + ColorIndex;
  if (pObj->Props.apBm[Index]) {
    GUI_DrawBitmap(pObj->Props.apBm[Index], EffectSize, EffectSize);
  }
  /* Draw the effect arround the box */
  WIDGET__EFFECT_DrawDownRect(&pObj->Widget, &RectBox);
  WM_SetUserClipRect(NULL);
  /* Draw text if needed */
  if (pObj->hpText) {
    const char * s;
    GUI_RECT RectText;
    /* Draw the text */
    s = (const char *) GUI_ALLOC_h2p(pObj->hpText);
    WM_GetClientRect(&RectText);
    RectText.x0 += RectBox.x1 + 1 + pObj->Props.Spacing;
    GUI_SetTextMode(GUI_TM_TRANS);
    LCD_SetColor(pObj->Props.TextColor);
    GUI_SetFont(pObj->Props.pFont);
    GUI_DispStringInRect(s, &RectText, pObj->Props.Align);
    /* Draw focus rectangle */
    if (pObj->Widget.State & WIDGET_STATE_FOCUS) {
      int xSizeText = GUI_GetStringDistX(s);
      int ySizeText = GUI_GetFontSizeY();
      GUI_RECT RectFocus = RectText;
      switch (pObj->Props.Align & ~(GUI_TA_HORIZONTAL)) {
      case GUI_TA_VCENTER:
        RectFocus.y0 = (RectText.y1 - ySizeText + 1) / 2;
        break;
      case GUI_TA_BOTTOM:
        RectFocus.y0 = RectText.y1 - ySizeText;
        break;
      }
      switch (pObj->Props.Align & ~(GUI_TA_VERTICAL)) {
      case GUI_TA_HCENTER:
        RectFocus.x0 += ((RectText.x1 - RectText.x0) - xSizeText) / 2;
        break;
      case GUI_TA_RIGHT:
        RectFocus.x0 += (RectText.x1 - RectText.x0) - xSizeText;
        break;
      }
      RectFocus.x1 = RectFocus.x0 + xSizeText - 1;
      RectFocus.y1 = RectFocus.y0 + ySizeText - 1;
      LCD_SetColor(pObj->Props.FocusColor);
      GUI_DrawFocusRect(&RectFocus, -1);
    }
  }
}
예제 #16
0
/*********************************************************************
*
*       LISTBOX_OwnerDraw
*/
int LISTBOX_OwnerDraw(const WIDGET_ITEM_DRAW_INFO* pDrawItemInfo) {
  switch (pDrawItemInfo->Cmd) {
    case WIDGET_ITEM_GET_XSIZE: {
      LISTBOX_Obj* pObj;
      const GUI_FONT GUI_UNI_PTR* pOldFont;
      const char* s;
      int DistX;
      pObj = LISTBOX_H2P(pDrawItemInfo->hWin);
      pOldFont = GUI_SetFont(pObj->Props.pFont);
      s = LISTBOX__GetpString(pObj, pDrawItemInfo->ItemIndex);
      DistX = GUI_GetStringDistX(s);
      GUI_SetFont(pOldFont);
      return DistX;
    }
    case WIDGET_ITEM_GET_YSIZE: {
      LISTBOX_Obj* pObj;
      pObj = LISTBOX_H2P(pDrawItemInfo->hWin);
      return GUI_GetYDistOfFont(pObj->Props.pFont) + pObj->ItemSpacing;
    }
    case WIDGET_ITEM_DRAW: {
      LISTBOX_Obj* pObj;
      LISTBOX_ITEM* pItem;
      WM_HMEM hItem;
      GUI_RECT r;
      int FontDistY;
      int ItemIndex = pDrawItemInfo->ItemIndex;
      const char* s;
      int ColorIndex;
      char IsDisabled;
      char IsSelected;
      pObj = LISTBOX_H2P(pDrawItemInfo->hWin);
      hItem = GUI_ARRAY_GethItem(&pObj->ItemArray, ItemIndex);
      pItem = (LISTBOX_ITEM *)GUI_ALLOC_h2p(hItem);
      WM_GetInsideRect(&r);
      FontDistY = GUI_GetFontDistY();
      /* Calculate color index */
      IsDisabled = (pItem->Status & LISTBOX_ITEM_DISABLED) ? 1 : 0;
      IsSelected = (pItem->Status & LISTBOX_ITEM_SELECTED) ? 1 : 0;
      if (pObj->Flags & LISTBOX_SF_MULTISEL) {
        if (IsDisabled) {
          ColorIndex = 3;
        } else {
          ColorIndex = (IsSelected) ? 2 : 0;
        }
      } else {
        if (IsDisabled) {
          ColorIndex = 3;
        } else {
          if (ItemIndex == pObj->Sel) {
            ColorIndex = (pObj->Widget.State & WIDGET_STATE_FOCUS) ? 2 : 1;
          } else {
            ColorIndex = 0;
          }
        }
      }
      /* Display item */
      LCD_SetBkColor(pObj->Props.aBackColor[ColorIndex]);
      LCD_SetColor  (pObj->Props.aTextColor[ColorIndex]);
      s = LISTBOX__GetpString(pObj, ItemIndex);
      GUI_SetTextMode(GUI_TM_TRANS);
      GUI_Clear();
      GUI_DispStringAt(s, pDrawItemInfo->x0 + 1, pDrawItemInfo->y0);
      /* Display focus rectangle */
      if ((pObj->Flags & LISTBOX_SF_MULTISEL) && (ItemIndex == pObj->Sel)) {
        GUI_RECT rFocus;
        rFocus.x0 = pDrawItemInfo->x0;
        rFocus.y0 = pDrawItemInfo->y0;
        rFocus.x1 = r.x1;
        rFocus.y1 = pDrawItemInfo->y0 + FontDistY - 1;
        LCD_SetColor(GUI_WHITE - pObj->Props.aBackColor[ColorIndex]);
        GUI_DrawFocusRect(&rFocus, 0);
      }
      return 0;
    }
  }
  return 0;
}
/*********************************************************************
*
*       _LCDBench
*/
static void _LCDBench(void) {
  GUI_POINT   Point;
  float       aPixelrateBitmap[5] = {0, 0, 0, 0, 0};
  float       PixelrateBigFont;
  float       PixelrateF6x8;
  float       FillratePPS;
  char      * s;
  char        ac[80];
  int         BitsPerPixel;
  int         xSizeString;
  int         ySizeFont;
  int         NumColors;
  int         MirrorX;
  int         MirrorY;
  int         SwapXY;
  int         xSize;
  int         ySize;

  BitsPerPixel = LCD_GetBitsPerPixelEx(0);
  xSize        = LCD_GetXSizeEx(0);
  ySize        = LCD_GetYSizeEx(0);
  MirrorX      = LCD_GetMirrorXEx(0);
  MirrorY      = LCD_GetMirrorYEx(0);
  SwapXY       = LCD_GetSwapXYEx(0);
  NumColors    = (1 << BitsPerPixel);
  _InitXbppDDP();
  //
  // Say hi !
  //
  GUI_X_Log("\nLCD driver benchmark. All values are  \xb5""s/pixel");
  GUI_X_Log("\nLower values are better.");
  GUI_SetBkColor(GUI_RED);
  GUI_SetColor(GUI_WHITE);
  GUI_Clear();
  GUI_SetFont(&GUI_FontComic18B_1);
  GUI_DispStringHCenterAt("LCD driver", xSize / 2, ySize / 3 - 10);
  GUI_DispStringHCenterAt("Benchmark" , xSize / 2, ySize / 3 + 20);
  GUI_Delay(1000);
  GUI_SetBkColor(GUI_BLACK);
  GUI_Clear();
  GUI_SetLBorder(1);
  //
  // Log color depth, controller, orientation and cache
  //
  sprintf(ac, "\nColor depth: %d", BitsPerPixel);
  GUI_X_Log(ac);
  sprintf(ac, "\nOrientation: LCD_MIRROR_X = %d, LCD_MIRROR_Y = %d, LCD_SWAP_XY = %d", MirrorX, MirrorY, SwapXY);
  GUI_X_Log(ac);
  //
  // Measure filling
  //
  Point.x             = xSize;
  Point.y             = ySize;
  FillratePPS         = _Measure(&_ExecFill, &Point)  * (float)(2 * ((U32)xSize - 4) * ((U32)ySize - 4));
  sprintf(ac, "\nFill: %f", (float)1E6 / FillratePPS);
  GUI_X_Log(ac);
  //
  // Measure small font
  //
  GUI_SetFont(&GUI_Font6x8);
  s                   = _acSmall;
  xSizeString         = GUI_GetStringDistX(s);
  ySizeFont           = GUI_GetFontSizeY();
  PixelrateF6x8       = _Measure(&_ExecSmallFont, s)  * (float)2 * xSizeString * ySizeFont * 8;
  sprintf(ac, "\nF6x8: %f", (float)1E6 / PixelrateF6x8);
  GUI_X_Log(ac);
  //
  // Measure big font
  //
  GUI_SetFont(&GUI_FontComic18B_ASCII);
  s                   = _acBig;
  xSizeString         = GUI_GetStringDistX(s);
  ySizeFont           = GUI_GetFontSizeY();
  PixelrateBigFont    = _Measure(&_ExecBigFont, s)    * (float)2 * xSizeString * ySizeFont * 2;
  sprintf(ac, "\nFBig: %f", (float)1E6 / PixelrateBigFont);
  GUI_X_Log(ac);
  //
  // Measure 1bpp bitmap
  //
  aPixelrateBitmap[0] = _Measure(&_Exec1bpp, NULL)    * (float)2 * _bm_1bpp_58x8.XSize * 8;
  sprintf(ac, "\n1bpp: %f", (float)1E6 / aPixelrateBitmap[0]);
  GUI_X_Log(ac);
  //
  // Measure 2bpp bitmap
  //
  aPixelrateBitmap[1] = _Measure(&_Exec2bpp, NULL)    * (float)2 * _bm_2bpp_32x11.XSize * 11;
  sprintf(ac, "\n2bpp: %f", (float)1E6 / aPixelrateBitmap[1]);
  GUI_X_Log(ac);
  //
  // Measure 4bpp bitmap
  //
  aPixelrateBitmap[2] = _Measure(&_Exec4bpp, NULL)    * (float)2 * _bm_4bpp_32x11.XSize * 11;
  sprintf(ac, "\n4bpp: %f", (float)1E6 / aPixelrateBitmap[2]);
  GUI_X_Log(ac);
  //
  // Measure 8bpp bitmap
  //
  aPixelrateBitmap[3] = _Measure(&_Exec8bpp, NULL)    * (float)2 * _bm_8bpp_32x11.XSize * 11;
  sprintf(ac, "\n8bpp: %f", (float)1E6 / aPixelrateBitmap[3]);
  GUI_X_Log(ac);
  //
  // Measure device dependent bitmap
  //
  aPixelrateBitmap[4] = _Measure(&_ExecXbppDDP, NULL) * (float)2 * XSIZE_XBPP * YSIZE_XBPP;
  sprintf(ac, "\nXDDP: %f", (float)1E6 / aPixelrateBitmap[4]);
  GUI_X_Log(ac);
  //
  // Show results on display
  //
  GUI_Clear();
  if (xSize < 320) {
    GUI_SetFont(&GUI_Font6x8);
  } else {
    GUI_SetFont(&GUI_Font8x16);
  }
  GUI_GotoXY(0, 0);
  GUI_DispDecMin(BitsPerPixel);
  GUI_DispString(" bpp, ");
  GUI_DispDecMin(NumColors);
  GUI_DispString(" colors\n\nMIRROR_X ");
  GUI_DispDecMin(MirrorX);
  GUI_DispString(", MIRROR_Y ");
  GUI_DispDecMin(MirrorY);
  GUI_DispString(", SWAPXY ");
  GUI_DispDecMin(SwapXY);
  GUI_SetLBorder(1);
  GUI_SetFont(&GUI_Font6x8);
  GUI_DispChar('\n');
  _DispFillrate("\nFill: ", FillratePPS,         " Fill");
  _DispFillrate("\nF6x8: ", PixelrateF6x8,       " F6x8");
  _DispFillrate("\nFBig: ", PixelrateBigFont,    " FComic18");
  _DispFillrate("\n1bpp: ", aPixelrateBitmap[0], " Bitmap 1bpp");
  _DispFillrate("\n2bpp: ", aPixelrateBitmap[1], " Bitmap 2bpp");
  _DispFillrate("\n4bpp: ", aPixelrateBitmap[2], " Bitmap 4bpp");
  _DispFillrate("\n8bpp: ", aPixelrateBitmap[3], " Bitmap 8bpp");
  _DispFillrate("\nXDDP: ", aPixelrateBitmap[4], " 8/16bppDDP");
}