/********************************************************************* * * Exported routines: Various methods * ********************************************************************** */ void PROGBAR_SetValue(PROGBAR_Handle hObj, int v) { PROGBAR_Obj* pObj; GUI_RECT r; if (hObj) { WM_LOCK(); pObj= PROGBAR_H2P(hObj); /* Put v into legal range */ if (v < pObj->Min) v = pObj->Min; if (v > pObj->Max) v = pObj->Max; if (pObj->v != v) { /* Invalidate */ if (pObj->hpText) { /* Calculate invalid area */ r.x0 = _Value2X(hObj, pObj->v); r.x1 = _Value2X(hObj, v); /* Make sure x0 <= x1 */ if (r.x0 > r.x1) { int t = r.x0; r.x0 = r.x1; r.x1 = t; } r.y0 =0; r.y1 =4095; WM_InvalidateRect(hObj,&r); } else { Invalidate(hObj); } pObj->v = v; /* Update stored value */ } WM_UNLOCK(); } }
/********************************************************************* * * _Paint */ static void _Paint(PROGBAR_Handle hObj) { PROGBAR_Obj* pObj; GUI_RECT r, rInside, rClient, rText; const char* pText; char ac[5]; int tm, xPos; pObj = PROGBAR_H2P(hObj); WM_GetClientRect(&rClient); GUI__ReduceRect(&rInside, &rClient, pObj->Widget.pEffect->EffectSize); xPos = _Value2X(pObj, pObj->v); pText = _GetText(pObj, ac); GUI_SetFont(pObj->pFont); _GetTextRect(pObj, &rText, pText); tm = GUI_SetTextMode(GUI_TM_TRANS); /* Draw left bar */ r = rInside; r.x1 = xPos - 1; WM_SetUserClipArea(&r); _DrawPart(pObj, 0, rText.x0, rText.y0, pText); /* Draw right bar */ r = rInside; r.x0 = xPos; WM_SetUserClipArea(&r); _DrawPart(pObj, 1, rText.x0, rText.y0, pText); WM_SetUserClipArea(NULL); GUI_SetTextMode(tm); WIDGET__EFFECT_DrawDownRect(&pObj->Widget, &rClient); }
/********************************************************************* * * PROGBAR_SetText */ void PROGBAR_SetText(PROGBAR_Handle hObj, const char* s) { if (hObj) { PROGBAR_Obj* pObj; const GUI_FONT GUI_UNI_PTR * pOldFont; GUI_RECT r1; char acBuffer[5]; WM_LOCK(); pObj = PROGBAR_H2P(hObj); pOldFont = GUI_SetFont(pObj->Props.pFont); PROGBAR__GetTextRect(pObj, &r1, PROGBAR__GetText(pObj, acBuffer)); if (!s) { PROGBAR__FreeText(hObj); WM_InvalidateRect(hObj, &r1); } else { if (GUI__SetText(&pObj->hpText, s)) { GUI_RECT r2; PROGBAR__GetTextRect(pObj, &r2, PROGBAR__GetText(pObj, acBuffer)); GUI_MergeRect(&r1, &r1, &r2); WM_InvalidateRect(hObj, &r1); } } GUI_SetFont(pOldFont); WM_UNLOCK(); } }
/********************************************************************* * * PROGBAR_SetTextAlign */ void PROGBAR_SetTextAlign(PROGBAR_Handle hObj, int Align) { PROGBAR_Obj* pObj; if (hObj) { WM_LOCK(); pObj = PROGBAR_H2P(hObj); pObj->TextAlign = Align; WM_InvalidateWindow(hObj); WM_UNLOCK(); } }
/********************************************************************* * * PROGBAR_SetFont */ void PROGBAR_SetFont(PROGBAR_Handle hObj, const GUI_FONT GUI_UNI_PTR * pfont) { PROGBAR_Obj* pObj; if (hObj) { WM_LOCK(); pObj = PROGBAR_H2P(hObj); pObj->pFont = pfont; WM_InvalidateWindow(hObj); WM_UNLOCK(); } }
void PROGBAR_SetTextColor(PROGBAR_Handle hObj, int index, GUI_COLOR color) { PROGBAR_Obj* pObj; if (hObj) { WM_LOCK(); pObj = PROGBAR_H2P(hObj); pObj->TextColor[index] = color; Invalidate(hObj); WM_UNLOCK(); } }
/********************************************************************* * * PROGBAR_SetTextPos */ void PROGBAR_SetTextPos(PROGBAR_Handle hObj, int XOff, int YOff) { PROGBAR_Obj* pObj; if (hObj) { WM_LOCK(); pObj = PROGBAR_H2P(hObj); pObj->XOff = XOff; pObj->YOff = YOff; WM_InvalidateWindow(hObj); WM_UNLOCK(); } }
/********************************************************************* * * _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); }
/********************************************************************* * * _Value2X */ static int _Value2X(PROGBAR_Handle hObj, int v) { PROGBAR_Obj* pObj = PROGBAR_H2P(hObj); int xsize = WM_GetWindowSizeX(hObj); int Min = pObj->Min; int Max = pObj->Max; if (v<Min) v = Min; if (v> Max) v = Max; return (xsize* (I32)(v-Min)) / (Max-Min); }
/********************************************************************* * * PROGBAR_SetTextColor */ void PROGBAR_SetTextColor(PROGBAR_Handle hObj, unsigned int Index, GUI_COLOR color) { PROGBAR_Obj* pObj; if (hObj) { WM_LOCK(); pObj = PROGBAR_H2P(hObj); if (Index < GUI_COUNTOF(pObj->TextColor)) { pObj->TextColor[Index] = color; WM_InvalidateWindow(hObj); } WM_UNLOCK(); } }
void PROGBAR_SetText(PROGBAR_Handle hObj, const char* s) { PROGBAR_Obj* pObj; WM_HMEM hMem; if (hObj) { WM_LOCK(); pObj = PROGBAR_H2P(hObj); _FreeText(hObj); hMem = WM_ALLOC((int)strlen(s)+1); strcpy((char *) WM_HMEM2Ptr(hMem), s); pObj->hpText = hMem; Invalidate(hObj); WM_UNLOCK(); } }
/********************************************************************* * * PROGBAR_SetMinMax */ void PROGBAR_SetMinMax(PROGBAR_Handle hObj, int Min, int Max) { PROGBAR_Obj* pObj; if (hObj) { WM_LOCK(); pObj = PROGBAR_H2P(hObj); if (Max > Min) { if ((Max != pObj->Max) || (Min != pObj->Min)) { pObj->Min = Min; pObj->Max = Max; WM_InvalidateWindow(hObj); } } WM_UNLOCK(); } }
/********************************************************************* * * PROGBAR_SetValue */ void PROGBAR_SetValue(PROGBAR_Handle hObj, int v) { if (hObj) { PROGBAR_Obj* pObj; WM_LOCK(); pObj= PROGBAR_H2P(hObj); /* Put v into legal range */ if (v < pObj->Min) { v = pObj->Min; } if (v > pObj->Max) { v = pObj->Max; } if (pObj->v != v) { GUI_RECT r; /* Get x values */ if (v < pObj->v) { r.x0 = _Value2X(pObj, v); r.x1 = _Value2X(pObj, pObj->v); } else { r.x0 = _Value2X(pObj, pObj->v); r.x1 = _Value2X(pObj, v); } r.y0 = 0; r.y1 = 4095; if (pObj->hpText == 0) { const GUI_FONT GUI_UNI_PTR * pOldFont; char acBuffer[5]; GUI_RECT rText; pOldFont = GUI_SetFont(pObj->pFont); _GetTextRect(pObj, &rText, _GetText(pObj, acBuffer)); GUI_MergeRect(&r, &r, &rText); pObj->v = v; _GetTextRect(pObj, &rText, _GetText(pObj, acBuffer)); GUI_MergeRect(&r, &r, &rText); GUI_SetFont(pOldFont); } else { pObj->v = v; } WM_InvalidateRect(hObj, &r); } WM_UNLOCK(); } }
/********************************************************************* * * _Delete */ static void _Delete(PROGBAR_Handle hObj) { _FreeText(hObj); DEINIT_ID(PROGBAR_H2P(hObj)); }
/********************************************************************* * * _FreeText */ static void _FreeText(PROGBAR_Handle hObj) { PROGBAR_Obj* pObj = PROGBAR_H2P(hObj); GUI_ALLOC_FreePtr(&pObj->hpText); }
/********************************************************************* * * _FreeText */ static void _FreeText(PROGBAR_Handle hObj) { PROGBAR_Obj* pObj = PROGBAR_H2P(hObj); WM_FREEPTR(&pObj->hpText); }