Moving the content of a window

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Moving the content of a window

      Hello
      I want to move the content (some widgets) of a window, I already found an example in another forum disccusion which i attached below. I also already looked through the MOTION part of the manuel but my issues couldn't get solved.

      What I done so far:
      I set the creation flags WM_CF_MOTION_Y (i want to move in y direction as compared to x direction in the example) and I called WM_MOTION_Enable(1).

      I think don't get quite what is happening in the callback routine.
      The way I think it is working is the following: In the case of WM_MOTION_MOVE we detect the movement and save it in the xPos variable.
      Then we update the WM_MOTION_INFO pointer in the case of WM_MOTION_GETPOS, so for what is this pointer update exactly who is going to use this pointer?

      I don't want to just draw 4 horizontally alligned rectangles as in the example, sho what exactly should my WM_PAINT case of the callback do?
      And when creating the window shouldn't I give it a size larger than my actual screen size (in vertical direction in my case) in order to make it possible to move something?

      Kind Regards
      Marc









      MainTask_WM_MotionMoveContent.zip
    • Hi,

      marc345 wrote:

      I don't want to just draw 4 horizontally alligned rectangles as in the example
      the sample you are describing sounds more like the WM_MOTION_MoveWindows sample to me, rather than the WM_MOTION_MoveContent sample?

      Anyways, I'll try to bring some clarity to your issue. I'll refer to the WM_MOTION_MoveContent example from now on, since this is closest to what you're trying to achieve.

      marc345 wrote:

      I set the creation flags WM_CF_MOTION_Y (i want to move in y direction as compared to x direction in the example) and I called WM_MOTION_Enable(1).
      You also need to set the flag WM_MOTION_MANAGE_BY_WINDOW to pInfo->Flags. Like in the sample:

      C Source Code

      1. case WM_MOTION_INIT:
      2. //
      3. // Tell the motion module to move in y direction and that we manage it on our own
      4. //
      5. pInfo->Flags = WM_CF_MOTION_Y | WM_MOTION_MANAGE_BY_WINDOW;
      6. break;
      The WM_MOTION_MOVE case gets sent the scrolled distance of the current moving operation via the pInfo->dx or pInfo->dy elements. We can then add this onto the total distance that we moved (yOffset in the sample) and make sure the movement is stopped at a certain maximum.

      We are using the offset in WM_PAINT to create the scrolling effect. Otherwise the text (or content) would not move. You can use this offset as well to move widgets using WM_MoveWindow().

      The WM_MOTION_GETPOS case is only used to get the current movement position. Since the motion is custom-handled (WM_MOTION_MANAGE_BY_WINDOW flag), you have to set the yPos value of the WM_MOTION_INFO structure. This is done in the sample as well:

      C Source Code

      1. case WM_MOTION_GETPOS:
      2. pInfo->yPos = yOffset;
      3. break;

      Best regards,

      Florian
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • Thanks for the great reply Florian. I was wondering if the same behaviour is also possible with a more "static" content.
      The content of my window is not created in the WM_PAIN case of the callback function but right after the creation of the window.
      I attached some example code to clarify more what I mean: The BuiltIn Button Widget also used and several Buttons are created, this has no practical use but should just somehow use all the screen size in y-direction and even more and thus I need to move the content of the window to navigate through the window.

      C Source Code

      1. #include <stdio.h>
      2. #include "gui_main.h"
      3. #include "GUI.h"
      4. #include "BUTTON.h"
      5. #include "radiogroup.h"
      6. #include "resources.h"
      7. #include "parambox.h"
      8. #include "ap_device_config.h"
      9. #include "ap_device_params.h"
      10. #include "ap_messages.h"
      11. #include "button_skins.h"
      12. #include "menu_hide.h"
      13. #include "TEXT.h"
      14. #define RG_WIDTH 280*GXF
      15. #define RG_HEIGHT 140*GYF
      16. #define BORDER_WIDTH 30*GXF
      17. #if defined(LCD480272)
      18. #define BTN_WIDTH 66
      19. #define BTN_HEIGHT 32
      20. #define BOTTOM_MARGIN 3
      21. #define BORDER_HEIGHT 10
      22. #define PB_HEIGHT 67
      23. #else
      24. #define BTN_HEIGHT 50
      25. #define BTN_WIDTH 133
      26. #define BOTTOM_MARGIN 15
      27. #define BORDER_HEIGHT 40
      28. #define PB_HEIGHT 120
      29. #endif
      30. #define RG_SOURCE_ID (GUI_ID_USER + 0)
      31. #define RG_POLARITY_ID (GUI_ID_USER + 1)
      32. #define BTN_STATE_ID (GUI_ID_USER + 2)
      33. #define BTN_MENU_ID (GUI_ID_USER + 3)
      34. #include "DIALOG.h"
      35. #define COLOR_1 GUI_RED
      36. #define COLOR_2 GUI_BLACK
      37. #define TEXT "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
      38. typedef struct {
      39. WM_HWIN hBtn;
      40. WM_HWIN hBtn2;
      41. WM_HWIN hBtn3;
      42. WM_HWIN hBtn4;
      43. WM_HWIN hBtn5;
      44. int numExtraBytes;
      45. }AP_MOVE_WINDOW_CONTENT_OBJ;
      46. void AP_MOVE_WINDOW_CONTENT_callback(WM_MESSAGE* pMsg);
      47. WM_HWIN AP_MOVE_WINDOW_CONTENT_create(int x0, int y0, int xSize, int ySize, WM_HWIN hWinParent, int numExtraBytes)
      48. {
      49. // Create window
      50. WM_HWIN hWin;
      51. AP_MOVE_WINDOW_CONTENT_OBJ obj;
      52. obj.numExtraBytes = numExtraBytes;
      53. //
      54. // Enable motion support
      55. //
      56. WM_MOTION_Enable(1);
      57. //
      58. // Enable multi-buffering to avoid flickering during motion
      59. // (already done in gui_main.c
      60. //WM_MULTIBUF_Enable(1);
      61. hWin = WM_CreateWindowAsChild(x0, y0, xSize, ySize, hWinParent, 0, AP_MOVE_WINDOW_CONTENT_callback, sizeof(AP_MOVE_WINDOW_CONTENT_OBJ) + numExtraBytes);
      62. WM_SetSize(hWin, LCD_GetXSize(), 5*LCD_GetYSize());
      63. // Create child widgets
      64. int x = BORDER_WIDTH;
      65. int y = BORDER_HEIGHT;
      66. obj.hBtn = BUTTON_CreateEx(LCD_GetXSize()-BTN_WIDTH, y, BTN_WIDTH, BTN_HEIGHT, hWin, WM_CF_SHOW, 0, NULL);
      67. BUTTON_SetText(obj.hBtn, "OFF");
      68. BUTTON_SetFont(obj.hBtn, GUI_FontMedium);
      69. BUTTON_SetFocussable(obj.hBtn, 0);
      70. BUTTON_SetSkin(obj.hBtn, BUTTON_skin_red);
      71. y += BTN_HEIGHT;
      72. obj.hBtn2 = BUTTON_CreateEx(LCD_GetXSize()-BTN_WIDTH, y, BTN_WIDTH, BTN_HEIGHT, hWin, WM_CF_SHOW, 0, NULL);
      73. BUTTON_SetText(obj.hBtn2, "OFF");
      74. BUTTON_SetFont(obj.hBtn2, GUI_FontMedium);
      75. BUTTON_SetFocussable(obj.hBtn2, 0);
      76. BUTTON_SetSkin(obj.hBtn2, BUTTON_skin_red);
      77. y += BTN_HEIGHT;
      78. obj.hBtn3 = BUTTON_CreateEx(LCD_GetXSize()-BTN_WIDTH, y, BTN_WIDTH, BTN_HEIGHT, hWin, WM_CF_SHOW, 0, NULL);
      79. BUTTON_SetText(obj.hBtn3, "OFF");
      80. BUTTON_SetFont(obj.hBtn3, GUI_FontMedium);
      81. BUTTON_SetFocussable(obj.hBtn3, 0);
      82. BUTTON_SetSkin(obj.hBtn3, BUTTON_skin_red);
      83. y += BTN_HEIGHT;
      84. obj.hBtn4 = BUTTON_CreateEx(LCD_GetXSize()-BTN_WIDTH, y, BTN_WIDTH, BTN_HEIGHT, hWin, WM_CF_SHOW, 0, NULL);
      85. BUTTON_SetText(obj.hBtn4, "OFF");
      86. BUTTON_SetFont(obj.hBtn4, GUI_FontMedium);
      87. BUTTON_SetFocussable(obj.hBtn4, 0);
      88. BUTTON_SetSkin(obj.hBtn4, BUTTON_skin_red);
      89. y += BTN_HEIGHT;
      90. obj.hBtn5 = BUTTON_CreateEx(LCD_GetXSize()-BTN_WIDTH, y, BTN_WIDTH, BTN_HEIGHT, hWin, WM_CF_SHOW, 0, NULL);
      91. BUTTON_SetText(obj.hBtn5, "OFF");
      92. BUTTON_SetFont(obj.hBtn5, GUI_FontMedium);
      93. BUTTON_SetFocussable(obj.hBtn5, 0);
      94. BUTTON_SetSkin(obj.hBtn5, BUTTON_skin_red);
      95. y += BTN_HEIGHT;
      96. WM_SetUserData(hWin, &obj, sizeof(AP_MOVE_WINDOW_CONTENT_OBJ));
      97. return hWin;
      98. }
      99. void AP_MOVE_WINDOW_CONTENT_callback(WM_MESSAGE * pMsg) {
      100. GUI_RECT Rect;
      101. GUI_RECT CRect;
      102. WM_MOTION_INFO* pInfo;
      103. static int yOffset;
      104. static int MaxOffset;
      105. switch (pMsg->MsgId) {
      106. case WM_MOTION:
      107. pInfo = (WM_MOTION_INFO*)pMsg->Data.p;
      108. switch (pInfo->Cmd) {
      109. case WM_MOTION_INIT:
      110. //
      111. // Tell the motion module to move in y direction and that we manage it on our own
      112. //
      113. pInfo->Flags = WM_CF_MOTION_Y | WM_MOTION_MANAGE_BY_WINDOW;
      114. break;
      115. case WM_MOTION_MOVE:
      116. //
      117. // Move the text rectangle up or down
      118. //
      119. yOffset += pInfo->dy;
      120. if (yOffset < MaxOffset) {
      121. //
      122. // If reach the end, make sure we stop there
      123. //
      124. yOffset = MaxOffset;
      125. //pInfo->StopMotion = 1;
      126. }
      127. else if (yOffset > 0) {
      128. //
      129. // If reach the top, make sure we stop there
      130. //
      131. yOffset = 0;
      132. //pInfo->StopMotion = 1;
      133. }
      134. //
      135. // Tell the window to redraw
      136. //
      137. WM_InvalidateWindow(pMsg->hWin);
      138. break;
      139. case WM_MOTION_GETPOS:
      140. pInfo->yPos = yOffset;
      141. break;
      142. }
      143. break;
      144. case WM_PAINT:
      145. /*//
      146. // Draw something
      147. //
      148. GUI_SetBkColor(GUI_WHITE);
      149. GUI_Clear();
      150. //
      151. GUI_SetColor(GUI_BLACK);
      152. WM_GetClientRect(&Rect);
      153. Rect.x0 += 20;
      154. Rect.y0 += 20;
      155. Rect.x1 -= 20;
      156. Rect.y1 -= 20;
      157. GUI_SetPenSize(2);
      158. GUI_DrawGradientRoundedV(Rect.x0, Rect.y0, Rect.x1, Rect.y1, 3, COLOR_1, COLOR_2);
      159. GUI_AA_DrawRoundedRectEx(&Rect, 3);
      160. //
      161. // Copy current rectangle into a clip rectangle
      162. //
      163. CRect = Rect;
      164. GUI_SetClipRect(&CRect);
      165. //
      166. // Prepare rect to display text
      167. //
      168. Rect.x0 += 10;
      169. Rect.y0 += 10;
      170. Rect.x1 -= 10;
      171. Rect.y1 -= 10;
      172. GUI_SetFont(&GUI_Font32_1);
      173. //
      174. // Calculate size of rectangle, so that the entire text will fit in
      175. //
      176. Rect.y1 += GUI_WrapGetNumLines(TEXT, Rect.x1 - Rect.x0, GUI_WRAPMODE_WORD) * GUI_GetFontSizeY();
      177. //
      178. // Calculate MaxOffset, so that the scrolling ends right at the end of the text
      179. //
      180. MaxOffset = -(Rect.y1) / 2;
      181. //
      182. // Add the current yOffset to the rectangle, so the text is displayed accordingly
      183. //
      184. Rect.y0 += yOffset;
      185. Rect.y1 += yOffset;
      186. GUI_SetTextMode(GUI_TM_TRANS);
      187. GUI_DispStringInRectWrap(TEXT, &Rect, GUI_TA_LEFT, GUI_WRAPMODE_WORD);
      188. //
      189. // Clear the clipping rectangle
      190. //
      191. GUI_SetClipRect(NULL);*/
      192. WM_GetInsideRect(&Rect);
      193. GUI_SetBkColor(GUI_WHITE);
      194. GUI_ClearRectEx(&Rect);
      195. menu_hide_registerWindowIfVisible(pMsg->hWin);
      196. break;
      197. default:
      198. WM_DefaultProc(pMsg);
      199. break;
      200. }
      201. }
      Display All

      The post was edited 2 times, last by marc345 ().