void WIDGET__DrawFocusRect(WIDGET* pWidget, const GUI_RECT* pRect, int Dist) { GUI_RECT Rect; if (pWidget->State & WIDGET_STATE_VERTICAL) { _RotateRect90(pWidget, &Rect, pRect); pRect = &Rect; } GUI_DrawFocusRect(pRect, Dist); }
/********************************************************************* * * _Paint */ static void _Paint(BUTTON_Obj* pObj) { const char*s =NULL; int State = pObj->Widget.State; int PressedState = (State & BUTTON_STATE_PRESSED) ? 1:0; GUI_RECT rClient; GUI_RECT r; GUI_SetFont(pObj->pFont); GUI_DEBUG_LOG("BUTTON: Paint(..)\n"); if (pObj->hpText) { s = (const char*) WM_HMEM2Ptr(pObj->hpText); } GUI_GetClientRect(&rClient); r = rClient; /* Draw background */ GUI_SetBkColor (pObj->aBkColor[PressedState]); GUI_SetColor (pObj->aTextColor[PressedState]); GUI_Clear(); /* Draw bitmap. If we have only one, we will use it. If we have to we will use the second one (Index 1) for the pressed state */ { int Index =0; if (pObj->apBitmap[1] && PressedState) { Index =1; } if (pObj->apBitmap[Index]) { #if BUTTON_SUPPORT_STREAMED_BITMAP if(pObj->aBitmapIsStreamed[Index]) { #if BUTTON_SUPPORT_BITMAP_OFFSET GUI_DrawStreamedBitmap((const GUI_BITMAP_STREAM*)(pObj->apBitmap[Index]), pObj->xOffBitmap, pObj->yOffBitmap); #else GUI_DrawBitmapStreamed((const GUI_BITMAP_STREAM*)(pObj->apBitmap[Index]), 0,0); #endif } else #endif { #if BUTTON_SUPPORT_BITMAP_OFFSET GUI_DrawBitmap(pObj->apBitmap[Index], pObj->xOffBitmap[Index], pObj->yOffBitmap[Index]); #else GUI_DrawBitmap(pObj->apBitmap[Index], 0,0); #endif } } } /* Draw the actual button (background and text) */ #if BUTTON_USE_3D if (pObj->Widget.State & BUTTON_STATE_PRESSED) { GUI_MoveRect(&r, BUTTON_3D_MOVE_X,BUTTON_3D_MOVE_Y); } #endif GUI_SetTextMode(GUI_TM_TRANS); GUI_DispStringInRect(s, &r, GUI_TA_HCENTER | GUI_TA_VCENTER); /* Draw the 3D effect (if configured) */ #if BUTTON_USE_3D if ((State & BUTTON_STATE_PRESSED) == 0) { WIDGET_EFFECT_3D_DrawUp(); } else { GUI_SetColor(0x000000); /// TBD: Use halftone GUI_DrawRect(rClient.y0, rClient.x0, rClient.x1, rClient.y1); } #endif /* Draw focus */ if (State & BUTTON_STATE_FOCUS) { GUI_SetColor(GUI_BLACK); GUI_DrawFocusRect(&rClient, 2); } }
/********************************************************************* * * _Paint */ static void _Paint(BUTTON_Obj* pObj, BUTTON_Handle hObj) { const char* s = NULL; unsigned int Index; int State, PressedState, ColorIndex; GUI_RECT rClient, rInside; State = pObj->Widget.State; PressedState = (State & BUTTON_STATE_PRESSED) ? 1 : 0; ColorIndex = (WM__IsEnabled(hObj)) ? PressedState : 2; GUI_SetFont(pObj->Props.pFont); GUI_DEBUG_LOG("BUTTON: Paint(..)\n"); if (pObj->hpText) { s = (const char*) GUI_ALLOC_h2p(pObj->hpText); } GUI_GetClientRect(&rClient); /* Start drawing */ rInside = rClient; /* Draw the 3D effect (if configured) */ #if BUTTON_USE_3D { int EffectSize; if ((PressedState) == 0) { pObj->Widget.pEffect->pfDrawUp(); /* _WIDGET_EFFECT_3D_DrawUp(); */ EffectSize = pObj->Widget.pEffect->EffectSize; } else { LCD_SetColor(0x000000); GUI_DrawRect(rClient.y0, rClient.x0, rClient.x1, rClient.y1); EffectSize = 1; } GUI__ReduceRect(&rInside, &rInside, EffectSize); } #endif /* Draw background */ LCD_SetBkColor (pObj->Props.aBkColor[ColorIndex]); LCD_SetColor (pObj->Props.aTextColor[ColorIndex]); WM_SetUserClipRect(&rInside); GUI_Clear(); /* Draw bitmap. If we have only one, we will use it. If we have to we will use the second one (Index 1) for the pressed state */ if (ColorIndex < 2) { Index = (pObj->ahDrawObj[BUTTON_BI_PRESSED] && PressedState) ? BUTTON_BI_PRESSED : BUTTON_BI_UNPRESSED; } else { Index = pObj->ahDrawObj[BUTTON_BI_DISABLED] ? BUTTON_BI_DISABLED : BUTTON_BI_UNPRESSED; } GUI_DRAW__Draw(pObj->ahDrawObj[Index], 0, 0); /* Draw the actual button (background and text) */ { GUI_RECT r; r = rInside; #if BUTTON_USE_3D if (PressedState) { GUI_MoveRect(&r, BUTTON_3D_MOVE_X,BUTTON_3D_MOVE_Y); } #endif GUI_SetTextMode(GUI_TM_TRANS); GUI_DispStringInRect(s, &r, pObj->Props.Align); } /* Draw focus */ if (State & BUTTON_STATE_FOCUS) { LCD_SetColor(pObj->Props.FocusColor); GUI_DrawFocusRect(&rClient, 2); } WM_SetUserClipRect(NULL); }
/********************************************************************* * * _OwnerDraw * * Purpose: * This is the owner draw function. * It allows complete customization of how the items in the listbox are * drawn. A command specifies what the function should do; * The minimum is to react to the draw command (WIDGET_ITEM_DRAW); * If the item x-size differs from the default, then this information * needs to be returned in reaction to WIDGET_ITEM_GET_XSIZE. * To insure compatibility with future version, all unhandled commands * must call the default routine LISTBOX_OwnerDraw. */ static int _OwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) { WM_HWIN hWin; int Index; hWin = pDrawItemInfo->hWin; Index = pDrawItemInfo->ItemIndex; switch (pDrawItemInfo->Cmd) { case WIDGET_ITEM_GET_XSIZE: return _GetItemSizeX(hWin, Index); case WIDGET_ITEM_GET_YSIZE: return _GetItemSizeY(hWin, Index); case WIDGET_ITEM_DRAW: { int MultiSel, Sel, YSize, FontDistY; int IsDisabled, IsSelected; int ColorIndex = 0; char acBuffer[100]; const GUI_BITMAP * pBm; const GUI_FONT* pOldFont = 0; GUI_COLOR aColor[4] = {GUI_BLACK, GUI_WHITE, GUI_WHITE, GUI_GRAY}; GUI_COLOR aBkColor[4] = {GUI_WHITE, GUI_GRAY, GUI_BLUE, 0xC0C0C0}; IsDisabled = LISTBOX_GetItemDisabled(pDrawItemInfo->hWin, pDrawItemInfo->ItemIndex); IsSelected = LISTBOX_GetItemSel(hWin, Index); MultiSel = LISTBOX_GetMulti(hWin); Sel = LISTBOX_GetSel(hWin); YSize = _GetItemSizeY(hWin, Index); /* Calculate color index */ if (MultiSel) { if (IsDisabled) { ColorIndex = 3; } else { ColorIndex = (IsSelected) ? 2 : 0; } } else { if (IsDisabled) { ColorIndex = 3; } else { if (pDrawItemInfo->ItemIndex == Sel) { ColorIndex = WM_HasFocus(pDrawItemInfo->hWin) ? 2 : 1; } else { ColorIndex = 0; } } } /* Draw item */ GUI_SetBkColor(aBkColor[ColorIndex]); GUI_SetColor (aColor[ColorIndex]); LISTBOX_GetItemText(pDrawItemInfo->hWin, pDrawItemInfo->ItemIndex, acBuffer, sizeof(acBuffer)); GUI_Clear(); if ((ColorIndex == 1) || (ColorIndex == 2)) { pOldFont = GUI_SetFont(&GUI_Font13B_1); } FontDistY = GUI_GetFontDistY(); GUI_DispStringAt(acBuffer, pDrawItemInfo->x0 + bmSmilie0.XSize + 16, pDrawItemInfo->y0 + (YSize - FontDistY) / 2); if (pOldFont) { GUI_SetFont(pOldFont); } GUI_DispCEOL(); /* Draw bitmap */ pBm = MultiSel ? IsSelected ? &bmSmilie1 : &bmSmilie0 : (pDrawItemInfo->ItemIndex == Sel) ? &bmSmilie1 : &bmSmilie0; GUI_DrawBitmap(pBm, pDrawItemInfo->x0 + 7, pDrawItemInfo->y0 + (YSize - pBm->YSize) / 2); /* Draw focus rectangle */ if (MultiSel && (pDrawItemInfo->ItemIndex == Sel)) { GUI_RECT rFocus; GUI_RECT rInside; WM_GetInsideRectEx(pDrawItemInfo->hWin, &rInside); rFocus.x0 = pDrawItemInfo->x0; rFocus.y0 = pDrawItemInfo->y0; rFocus.x1 = rInside.x1; rFocus.y1 = pDrawItemInfo->y0 + YSize - 1; GUI_SetColor(GUI_WHITE - aBkColor[ColorIndex]); GUI_DrawFocusRect(&rFocus, 0); } } break; default: return LISTBOX_OwnerDraw(pDrawItemInfo); } return 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); } } }
/********************************************************************* * * 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; }