/********************************************************************* * * WM_SetCaptureMove */ void WM_SetCaptureMove(WM_HWIN hWin, const GUI_PID_STATE* pState, int MinVisibility) { if (!WM_HasCaptured(hWin)) { WM_SetCapture(hWin, 1); /* Set capture with auto release */ WM__CapturePoint.x = pState->x; WM__CapturePoint.y = pState->y; } else { /* Moving ... let the window move ! */ int dx, dy; dx = pState->x - WM__CapturePoint.x; dy = pState->y - WM__CapturePoint.y; /* make sure at least a part of the windows stays inside of its parent */ if (MinVisibility == 0) { WM_MoveWindow(hWin, dx, dy); } else { GUI_RECT Rect, RectParent; /* make sure at least a part of the windows stays inside of its parent */ WM_GetWindowRectEx(hWin, &Rect); WM_GetWindowRectEx(WM_GetParent(hWin), &RectParent); GUI_MoveRect(&Rect, dx, dy); GUI__ReduceRect(&RectParent, &RectParent, MinVisibility); if (GUI_RectsIntersect(&Rect, &RectParent)) { WM_MoveWindow(hWin, dx, dy); } } } }
/********************************************************************* * * WM_GetInsideRectExScrollbar * Purpose: Return the inside rectangle in client coordinates. The inside rectangle is the client rectangle minus the effect, which typically reduces the rectangle by 0 - 3 pixels on either side (2 for the standard 3D effect). */ void WM_GetInsideRectExScrollbar(WM_HWIN hWin, GUI_RECT* pRect) { GUI_RECT rWin, rInside, rScrollbar; WM_HWIN hBarV, hBarH; U16 WinFlags; if (hWin) { if (pRect) { hBarH = WM_GetDialogItem(hWin, GUI_ID_HSCROLL); hBarV = WM_GetDialogItem(hWin, GUI_ID_VSCROLL); WM_GetWindowRectEx(hWin, &rWin); /* The entire window in screen coordinates */ WM_GetInsideRectEx(hWin, &rInside); if (hBarV) { WM_GetWindowRectEx(hBarV, &rScrollbar); GUI_MoveRect(&rScrollbar, -rWin.x0, -rWin.y0); WinFlags = WM_GetFlags(hBarV); if ((WinFlags & WM_SF_ANCHOR_RIGHT) && (WinFlags & WM_SF_ISVIS)) { rInside.x1 = rScrollbar.x0 - 1; } } if (hBarH) { WM_GetWindowRectEx(hBarH, &rScrollbar); GUI_MoveRect(&rScrollbar, -rWin.x0, -rWin.y0); WinFlags = WM_GetFlags(hBarH); if ((WinFlags & WM_SF_ANCHOR_BOTTOM) && (WinFlags & WM_SF_ISVIS)) { rInside.y1 = rScrollbar.y0 - 1; } } *pRect = rInside; } } }
/********************************************************************* * * _CalcPositions * * Calculates all positions required for drawing or for mouse / touch * evaluation. */ static void _CalcPositions(SCROLLBAR_Obj* pObj, SCROLLBAR_POSITIONS* pPos) { int xSizeArrow, xSize, xSizeMoveable, ThumbSize, NumItems, xSizeThumbArea; WM_HWIN hWin; GUI_RECT r, rSub; int x0, y0; r = pObj->Widget.Win.Rect; x0 = r.x0; y0 = r.y0; pPos->x1 = (pObj->Widget.State & WIDGET_STATE_VERTICAL) ? r.y1 : r.x1; /* Subtract the rectangle of the other scrollbar (if existing and visible) */ if (pObj->Widget.Id == GUI_ID_HSCROLL) { hWin = WM_GetScrollbarV(pObj->Widget.Win.hParent); if (hWin) { WM_GetWindowRectEx(hWin, &rSub); if (r.x1 == rSub.x1) { r.x1 = rSub.x0 -1; } } } if (pObj->Widget.Id == GUI_ID_VSCROLL) { hWin = WM_GetScrollbarH(pObj->Widget.Win.hParent); if (hWin) { WM_GetWindowRectEx(hWin, &rSub); if (r.y1 == rSub.y1) { r.y1 = rSub.y0 -1; } } } /* Convert coordinates of this window */ GUI_MoveRect(&r, -x0, -y0); /* Convert real into virtual coordinates */ _WIDGET__RECT2VRECT(&pObj->Widget, &r); NumItems = pObj->NumItems; xSize = r.x1 - r.x0 + 1; xSizeArrow = _GetArrowSize(pObj); xSizeThumbArea= xSize - 2 * xSizeArrow; /* Number of pixels available for thumb and movement */ ThumbSize = GUI__DivideRound(xSizeThumbArea * pObj->PageSize, NumItems); if (ThumbSize < 4) { ThumbSize = 4; } if (ThumbSize > xSizeThumbArea) { ThumbSize = xSizeThumbArea; } xSizeMoveable = xSizeThumbArea - ThumbSize; pPos->x0_LeftArrow = r.x0; pPos->x1_LeftArrow = xSizeArrow - 1; pPos->x1_RightArrow = xSize - 1; pPos->x0_RightArrow = xSize - xSizeArrow; pPos->x0_Thumb = pPos->x1_LeftArrow + 1+ GUI__DivideRound(xSizeMoveable * pObj->v, NumItems - pObj->PageSize); pPos->x1_Thumb = pPos->x0_Thumb + ThumbSize - 1; pPos->xSizeMoveable = xSizeMoveable; pPos->ThumbSize = ThumbSize; }
/********************************************************************* * * _ToggleFullScreenMode * * Purpose: * This routine switches between full screen mode and normal mode by hiding or showing the * widgets of the dialog, enlarging/shrinking the graph widget and modifying some other * attributes of the dialog widgets. */ static void _ToggleFullScreenMode(WM_HWIN hDlg) { static int FullScreenMode; static GUI_RECT Rect; static unsigned ScalePos; WM_HWIN hGraph, hButton; hGraph = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0); hButton = WM_GetDialogItem(hDlg, GUI_ID_BUTTON0); FullScreenMode ^= 1; if (FullScreenMode) { /* Enter the full screen mode */ WM_HWIN hClient; GUI_RECT RectInside; hClient = WM_GetClientWindow(hDlg); BUTTON_SetText(hButton, "Back"); WM_MoveWindow(hButton, 0, 11); FRAMEWIN_SetTitleVis(hDlg, 0); WM_GetInsideRectEx(hClient, &RectInside); WM_GetWindowRectEx(hGraph, &Rect); WM_ForEachDesc(hClient, _ForEach, &FullScreenMode); /* Hide all descendants */ WM_SetWindowPos(hGraph, WM_GetWindowOrgX(hClient), WM_GetWindowOrgX(hClient), RectInside.x1, RectInside.y1); ScalePos = GRAPH_SCALE_SetPos(_hScaleH, RectInside.y1 - 105); } else { /* Return to normal mode */ BUTTON_SetText(hButton, "Full Screen"); WM_MoveWindow(hButton, 0, -11); WM_ForEachDesc(WM_GetClientWindow(hDlg), _ForEach, &FullScreenMode); /* Show all descendants */ WM_SetWindowPos(hGraph, Rect.x0, Rect.y0, Rect.x1 - Rect.x0 + 1, Rect.y1 - Rect.y0 + 1); FRAMEWIN_SetTitleVis(hDlg, 1); GRAPH_SCALE_SetPos(_hScaleH, ScalePos); } }
/********************************************************************* * * MYWIDGET_Callback */ void MYWIDGET_Callback(WM_MESSAGE * pMsg) { MYWIDGET_Handle hWin; GUI_PID_STATE * pState; MYWIDGET_Obj MyWidget; GUI_RECT WinRect; int ColorIndex; U8 Pressed; hWin = pMsg->hWin; WM_GetWindowRectEx(hWin, &WinRect); GUI_MoveRect(&WinRect, -WinRect.x0, -WinRect.y0); WM_GetUserData(hWin, &MyWidget, sizeof(MYWIDGET_Obj)); switch (pMsg->MsgId) { case WM_PAINT: if (WM_IsEnabled(hWin)) { if (MyWidget.Pressed) { ColorIndex = MYWIDGET_CI_PRESSED; } else { ColorIndex = MYWIDGET_CI_UNPRESSED; } } else { ColorIndex = MYWIDGET_CI_DISABLED; } GUI_SetColor(MyWidget.aBkColor[ColorIndex]); GUI_FillRectEx(&WinRect); if (WM_HasFocus(hWin)) { GUI_SetColor(MyWidget.FocusColor); GUI_DrawRectEx(&WinRect); } GUI_SetColor(MyWidget.aTextColor[ColorIndex]); GUI_SetTextMode(GUI_TM_TRANS); GUI_DispStringInRect(MyWidget.pText, &WinRect, GUI_TA_HCENTER | GUI_TA_VCENTER); break; case WM_TOUCH: pState = (GUI_PID_STATE *)pMsg->Data.p; if (pState) { Pressed = pState->Pressed; } else { Pressed = 0; } if (MyWidget.Pressed != Pressed) { MyWidget.Pressed = Pressed; WM_SetUserData(hWin, &MyWidget, sizeof(MYWIDGET_Obj)); if (Pressed) { WM_SetFocus(hWin); } WM_InvalidateWindow(hWin); } break; case WM_SET_FOCUS: if (pMsg->Data.v) { pMsg->Data.v = 0; } WM_InvalidateWindow(hWin); break; default: WM_DefaultProc(pMsg); } }
/********************************************************************* * * _CreateMessageBox */ static WM_HWIN _CreateMessageBox(const char * sMessage, const char * sCaption, int Flags, const GUI_FONT * pFont) { WM_HWIN hWin, hItem; GUI_RECT Rect; hWin = MESSAGEBOX_Create(sMessage, sCaption, Flags); /* * Change font of message box window */ FRAMEWIN_SetFont(hWin, pFont); /* * Adjust size */ WM_GetWindowRectEx(hWin, &Rect); WM_SetWindowPos(hWin, Rect.x0 - 15, Rect.y0 - 15, Rect.x1 - Rect.x0 + 1 + 30, Rect.y1 - Rect.y0 + 1 + 30); /* * Change font of button widget */ hItem = WM_GetDialogItem(hWin, GUI_ID_OK); BUTTON_SetFont(hItem, pFont); /* * Adjust size of button widget */ WM_GetWindowRectEx(hItem, &Rect); WM_SetWindowPos(hItem, Rect.x0, Rect.y0 + 10, Rect.x1 - Rect.x0 + 1 + 30, Rect.y1 - Rect.y0 + 1 + 5); /* * Change font of text widget */ hItem = WM_GetDialogItem(hWin, GUI_ID_TEXT0); TEXT_SetFont(hItem, pFont); /* * Adjust size text widget */ WM_GetWindowRectEx(hItem, &Rect); WM_SetWindowPos(hItem, Rect.x0, Rect.y0, Rect.x1 - Rect.x0 + 1 + 30, Rect.y1 - Rect.y0 + 1 + 12); return hWin; }
// Find if the point is over a Synth String Panel and, if yes, the function returns the handle on the window found // and update the coordinates relatively to this window. WM_HWIN SynthScreen_GetStringHWin(int &x, int &y) { for(int i = 0; i < 6; i++) { GUI_RECT rect; WM_GetWindowRectEx(hSynthItems[SYNTH_STRINGPANEL1+i], &rect); if (x >= rect.x0 && y >= rect.y0 && x <= rect.x1 && y <= rect.y1) { x -= rect.x0; y -= rect.y0; return hSynthItems[SYNTH_STRINGPANEL1+i]; } } return NULL; }
/********************************************************************* * * _cbMyWidget */ static void _cbMyWidget(WM_MESSAGE * pMsg) { GUI_RECT WinRect; char acText[20] = { 0 }; switch (pMsg->MsgId) { case WM_PAINT: MYWIDGET_Callback(pMsg); MYWIDGET_GetUserData(pMsg->hWin, acText, sizeof(acText)); GUI_SetColor(GUI_WHITE); GUI_SetTextMode(GUI_TM_TRANS); WM_GetWindowRectEx(pMsg->hWin, &WinRect); GUI_MoveRect(&WinRect, -WinRect.x0, -WinRect.y0); GUI_DispStringInRect(acText, &WinRect, GUI_TA_HCENTER | GUI_TA_VCENTER); break; default: MYWIDGET_Callback(pMsg); } }
/********************************************************************* * * _Paint */ static void _Paint(xIconSelBtn_Handle hWin) { GUI_RECT WinRect; xIconSelBtn_OBJ tWidget; GUI_CONST_STORAGE GUI_BITMAP* pBMP; int xSize, ySize; if(!hWin) return; DEBUGOUT("xIconSelBtn hWin = 0x%08x\r\n", hWin); WM_GetWindowRectEx(hWin, &WinRect); GUI_MoveRect(&WinRect, -WinRect.x0, -WinRect.y0); DEBUGOUT("xIconSelBtn Paint(%d,%d,%d,%d)\r\n",WinRect.x0, WinRect.y0, WinRect.x1, WinRect.y1); BUTTON_GetUserData(hWin, &tWidget, sizeof(xIconSelBtn_OBJ)); tWidget.hThis = hWin; BUTTON_SetUserData(hWin, &tWidget, sizeof(xIconSelBtn_OBJ)); if(tWidget.pBkBMP) { GUI_DrawBitmap(tWidget.pBkBMP, WinRect.x0, WinRect.y0); } else { //Draw Window Frame Outline, and Background. GUI_SetColor(tWidget.aBkColor[0]); //Draw Window Frame Outline, and Background. GUI_FillRoundedRect(WinRect.x0, WinRect.y0, WinRect.x1, WinRect.y1, 1); } xSize = WinRect.x1 - WinRect.x0; ySize = WinRect.y1 - WinRect.y0; pBMP = tWidget.xIconArray[tWidget.SelectedIndex].pBMP; if(pBMP) { //Draw BMP in H & V center GUI_DrawBitmap(pBMP, WinRect.x0 + (xSize - pBMP->XSize)/2 , WinRect.y0 + (ySize - pBMP->YSize)/2 ); } }
/********************************************************************* * * _cbCallback */ static void _cbCallback(WM_MESSAGE * pMsg) { WM_HWIN hWin = pMsg->hWin; #if GUIDEMO_LARGE int NCode, Id; #endif switch (pMsg->MsgId) { case WM_INIT_DIALOG: /* Initialize all widgets */ #if GUIDEMO_TINY EDIT_SetText(WM_GetDialogItem(hWin, GUI_ID_EDIT0), "EDIT"); #else EDIT_SetText(WM_GetDialogItem(hWin, GUI_ID_EDIT0), "EDIT widget 0"); EDIT_SetText(WM_GetDialogItem(hWin, GUI_ID_EDIT1), "EDIT widget 1"); #endif { #if GUIDEMO_LARGE WM_HWIN hListBox; EDIT_SetHexMode(WM_GetDialogItem(hWin, GUI_ID_EDIT2), 0x1234, 0, 0xffffff); EDIT_SetBinMode(WM_GetDialogItem(hWin, GUI_ID_EDIT3), 0x1234, 0, 0xffff); hListBox = WM_GetDialogItem(hWin, GUI_ID_LISTBOX0); LISTBOX_SetText(hListBox, _apListBox); SCROLLBAR_CreateAttached(hListBox, SCROLLBAR_CF_VERTICAL); #else GUI_RECT Rect; int x, y, ySize; ySize = LCD_GetYSize(); if (ySize < 120) { WM_ResizeWindow(hWin, 0, -24); } WM_GetWindowRectEx(hWin, &Rect); x = (LCD_GetXSize() - (Rect.x1 - Rect.x0 + 1)) >> 1; y = (ySize - (Rect.y1 - Rect.y0 + 1)) >> 1; #if GUIDEMO_TINY WM_MoveTo(hWin, x, y); #else WM_MoveTo(hWin, x, y - 4); #endif #endif } break; case WM_KEY: switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) { case GUI_KEY_ESCAPE: GUI_EndDialog(hWin, 1); break; case GUI_KEY_ENTER: GUI_EndDialog(hWin, 0); break; } break; #if GUIDEMO_LARGE case WM_NOTIFY_PARENT: Id = WM_GetId(pMsg->hWinSrc); /* Id of widget */ NCode = pMsg->Data.v; /* Notification code */ switch (NCode) { case WM_NOTIFICATION_RELEASED: /* React only if released */ if (Id == GUI_ID_OK) { /* OK Button */ GUI_EndDialog(hWin, 0); } if (Id == GUI_ID_CANCEL) { /* Cancel Button */ GUI_EndDialog(hWin, 1); } break; case WM_NOTIFICATION_SEL_CHANGED: /* Selection changed */ FRAMEWIN_SetText(hWin, "Dialog - sel changed"); break; default: FRAMEWIN_SetText(hWin, "Dialog - notification received"); } break; #endif default: WM_DefaultProc(pMsg); } }
/********************************************************************* * * MainTask */ void MainTask(void) { WM_HWIN hScrollbar, hDlgOptions; GUI_RECT RectDlg, RectClient; int Cnt = 0, IndexEffect = 0, ButtonState = 0, DropdownState = 0; int ProgbarValue = 0, ProgbarInc = 1; int SliderValue = 0, SliderInc = 1; int ScrollbarValue = 0, ScrollbarInc = 1; int ListViewInc = 1; int ListBoxInc = 1; int MultiEditInc = 1; int Vz = 1; const WIDGET_EFFECT * _apEffect[] = {&WIDGET_Effect_3D, /* Array of effects */ &WIDGET_Effect_Simple, &WIDGET_Effect_None}; const char * _apEffects[] = {"Widget effect: 3D", "Widget effect: Simple", "Widget effect: None"}; GUI_Init(); GUI_CURSOR_Show(); WM_SetCallback(WM_HBKWIN, _cbBkWindow); WM_SetCreateFlags(WM_CF_MEMDEV); /* Use memory devices on all windows to avoid flicker */ WM_EnableMemdev(WM_HBKWIN); /* Enable use of memory devices for desktop windows */ /* Create framewindow and set its properties */ _hFrameWin = FRAMEWIN_CreateEx(0, 0, 640, 480, 0, WM_CF_SHOW, 0, 0, "", &_cbCallbackFramewin); FRAMEWIN_SetMoveable(_hFrameWin, 1); FRAMEWIN_SetText(_hFrameWin, _apEffects[0]); FRAMEWIN_SetFont(_hFrameWin, &GUI_Font13B_ASCII); /* Create main dialog window as child from framewindows client window */ _hDlg = GUI_CreateDialogBox(_aDlgWidgets, GUI_COUNTOF(_aDlgWidgets), &_cbCallbackWidgets, WM_GetClientWindow(_hFrameWin), 0, 0); /* Attach scrollbar to framewindows client window and set its properties */ hScrollbar = SCROLLBAR_CreateAttached(WM_GetClientWindow(_hFrameWin), 0); WM_GetWindowRectEx(_hDlg, &RectDlg); WM_GetClientRectEx(WM_GetClientWindow(_hFrameWin), &RectClient); SCROLLBAR_SetNumItems(hScrollbar, RectDlg.x1); SCROLLBAR_SetPageSize(hScrollbar, RectClient.x1); /* Create options dialog with 'stay on top' and 'moveable' attribute */ hDlgOptions = GUI_CreateDialogBox(_aDlgOptions, GUI_COUNTOF(_aDlgOptions), &_cbCallbackOptions, WM_HBKWIN, 0, 0); FRAMEWIN_SetMoveable(hDlgOptions, 1); WM_SetStayOnTop(hDlgOptions, 1); /* Main loop for modifying the widgets */ while (1) { if (_AutoMode) { Cnt++; /* Modify progbar */ if ((Cnt % 2) == 0) { ProgbarValue += ProgbarInc; if ((ProgbarValue == 110) || (ProgbarValue == -10)) { ProgbarInc *= -1; } PROGBAR_SetValue(_ahWin[PROGBAR0], ProgbarValue); } /* Modify slider */ if ((Cnt % 2) == 0) { int j; SliderValue += SliderInc; if ((SliderValue == 100) || (SliderValue == 0)) { SliderInc *= -1; } for (j = 0; j < 3; j++) { SLIDER_SetValue(_ahWin[SLIDER0 + j], SliderValue); } } /* Modify scrollbar */ if ((Cnt % 3) == 0) { int j; ScrollbarValue += ScrollbarInc; if ((ScrollbarValue == 90) || (ScrollbarValue == 0)) { ScrollbarInc *= -1; } for (j = 0; j < 3; j++) { SCROLLBAR_SetValue(_ahWin[SCROLLBAR0 + j], ScrollbarValue); } } /* Modify multipage */ if ((Cnt % 120) == 0) { MULTIPAGE_SelectPage(_ahWin[MULTIPAGE0], MULTIPAGE_GetSelection(_ahWin[MULTIPAGE0]) ^ 1); } /* Modify dropdown */ if ((Cnt % 120) == 0) { DropdownState ^= 1; if (DropdownState) { DROPDOWN_Expand(_ahWin[DROPDOWN0]); } else { DROPDOWN_Collapse(_ahWin[DROPDOWN0]); } } /* Modify button */ if ((Cnt % 40) == 0) { ButtonState ^= 1; BUTTON_SetPressed(_ahWin[BUTTON0], ButtonState); } /* Modify listbox */ if ((Cnt % 30) == 0) { int Sel; Sel = LISTBOX_GetSel(_ahWin[LISTBOX0]); if (Sel < 0) { Sel = 0; } LISTBOX_SetSel(_ahWin[LISTBOX0], Sel + ListBoxInc); Sel = LISTBOX_GetSel(_ahWin[LISTBOX0]); if ((Sel == (int)LISTBOX_GetNumItems(_ahWin[LISTBOX0]) - 1) || (Sel == 0)) { ListBoxInc *= -1; } } /* Modify listview */ if ((Cnt % 50) == 0) { int Sel; Sel = LISTVIEW_GetSel(_ahWin[LISTVIEW0]); if (Sel < 0) { Sel = 0; } LISTVIEW_SetSel(_ahWin[LISTVIEW0], Sel + ListViewInc); Sel = LISTVIEW_GetSel(_ahWin[LISTVIEW0]); if ((Sel == (int)LISTVIEW_GetNumRows(_ahWin[LISTVIEW0]) - 1) || (Sel == 0)) { ListViewInc *= -1; } } /* Modify multiedit */ if ((Cnt % 5) == 0) { int Sel, Len; char acBuffer[100]; MULTIEDIT_SetCursorOffset(_ahWin[MULTIEDIT0], MULTIEDIT_GetCursorCharPos(_ahWin[MULTIEDIT0]) + MultiEditInc); MULTIEDIT_GetText(_ahWin[MULTIEDIT0], acBuffer, sizeof(acBuffer)); Sel = MULTIEDIT_GetCursorCharPos(_ahWin[MULTIEDIT0]); Len = strlen(acBuffer); if ((Sel == (Len - 1)) || (Sel == 0)) { MultiEditInc *= -1; } if (!DropdownState) { WM_SetFocus(_ahWin[MULTIEDIT0]); } } /* Modify graph */ _AddValues(_ahWin[GRAPH0], 95); /* Move window */ if ((Cnt % 1200) == 0) { int Inc; WM_HWIN hScroll; WM_SCROLL_STATE ScrollState; hScroll = WM_GetScrollbarH(WM_GetClientWindow(_hFrameWin)); WM_GetScrollState(hScroll, &ScrollState); Inc = (ScrollState.NumItems - ScrollState.PageSize) / 2; ScrollState.v += Inc * Vz; if ((ScrollState.v >= Inc * 2) || (ScrollState.v <= 0)) { Vz *= -1; } SCROLLBAR_SetValue(hScroll, ScrollState.v); } /* Change effect */ if ((Cnt % 400) == 0) { int Index; WM_HWIN hWin; IndexEffect++; Index = IndexEffect % GUI_COUNTOF(_apEffect); _SetEffect(Index); hWin = WM_GetDialogItem(hDlgOptions, GUI_ID_RADIO0); RADIO_SetValue(hWin, Index); } } /* Wait a while */ GUI_Delay(10); } }