Difference between revisions of "WM MOTION - Move content (Sample)"
(Created page with "{| class="wikitable" style="float:right; margin-left: 10px; background-color: #f9f9f9;" ! colspan="2" style="font-weight:bold; font-size:17px; font-family:Arial, Helvetica, sa...") |
|||
Line 20: | Line 20: | ||
This sample demonstrates how motion support in emWin can be used for text scrolling or moving any other content. |
This sample demonstrates how motion support in emWin can be used for text scrolling or moving any other content. |
||
+ | |||
+ | == Demo == |
||
+ | |||
+ | <html><iframe src="https://wiki.segger.com/demo/emwin/WM_MOTION_MoveContent/WM_MOTION_MoveContent.html" width="480" height="272" style="border: 1px #c0c0c0 solid;" marginwidth="0" marginheight="0" hspace="0" vspace="0" scrolling="no"> </iframe></html> |
||
== Code == |
== Code == |
Latest revision as of 16:39, 7 March 2022
WM_MOTION_MoveContent.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | WM_MOTION_MoveContent.c |
This sample demonstrates how motion support in emWin can be used for text scrolling or moving any other content.
Demo
Code
/*********************************************************************
* SEGGER Microcontroller GmbH *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 1996 - 2020 SEGGER Microcontroller GmbH *
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
** emWin V6.10 - Graphical user interface for embedded applications **
emWin is protected by international copyright laws. Knowledge of the
source code may not be used to write a similar product. This file may
only be used in accordance with a license and should not be re-
distributed in any way. We appreciate your understanding and fairness.
----------------------------------------------------------------------
File : WM_MOTION_MoveContent.c
Purpose : Sample that shows how motion support works for movable
content in emWin.
Requirements: WindowManager - (x)
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define COLOR_1 GUI_MAKE_COLOR(0x00DFD9CF)
#define COLOR_2 GUI_MAKE_COLOR(0x00F0EBE2)
#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."
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _cbWin
*/
static void _cbWin(WM_MESSAGE * pMsg) {
GUI_RECT Rect;
GUI_RECT CRect;
WM_MOTION_INFO * pInfo;
static int yOffset;
static int MaxOffset;
switch (pMsg->MsgId) {
case WM_MOTION:
pInfo = (WM_MOTION_INFO *)pMsg->Data.p;
switch (pInfo->Cmd) {
case WM_MOTION_INIT:
//
// Tell the motion module to move in y direction and that we manage it on our own
//
pInfo->Flags = WM_CF_MOTION_Y | WM_MOTION_MANAGE_BY_WINDOW;
break;
case WM_MOTION_MOVE:
//
// Move the text rectangle up or down
//
yOffset += pInfo->dy;
if (yOffset < MaxOffset) {
//
// If reach the end, make sure we stop there
//
yOffset = MaxOffset;
pInfo->StopMotion = 1;
}
else if (yOffset > 0) {
//
// If reach the top, make sure we stop there
//
yOffset = 0;
pInfo->StopMotion = 1;
}
//
// Tell the window to redraw
//
WM_InvalidateWindow(pMsg->hWin);
break;
case WM_MOTION_GETPOS:
pInfo->yPos = yOffset;
break;
}
break;
case WM_PAINT:
//
// Draw something
//
GUI_SetBkColor(GUI_WHITE);
GUI_Clear();
//
GUI_SetColor(GUI_BLACK);
WM_GetClientRect(&Rect);
Rect.x0 += 20;
Rect.y0 += 20;
Rect.x1 -= 20;
Rect.y1 -= 20;
GUI_SetPenSize(2);
GUI_DrawGradientRoundedV(Rect.x0, Rect.y0, Rect.x1, Rect.y1, 3, COLOR_1, COLOR_2);
GUI_AA_DrawRoundedRectEx(&Rect, 3);
//
// Copy current rectangle into a clip rectangle
//
CRect = Rect;
GUI_SetClipRect(&CRect);
//
// Prepare rect to display text
//
Rect.x0 += 10;
Rect.y0 += 10;
Rect.x1 -= 10;
Rect.y1 -= 10;
GUI_SetFont(&GUI_Font32_1);
//
// Calculate size of rectangle, so that the entire text will fit in
//
Rect.y1 += GUI_WrapGetNumLines(TEXT, Rect.x1 - Rect.x0, GUI_WRAPMODE_WORD) * GUI_GetFontSizeY();
//
// Calculate MaxOffset, so that the scrolling ends right at the end of the text
//
MaxOffset = -(Rect.y1) / 2;
//
// Add the current yOffset to the rectangle, so the text is displayed accordingly
//
Rect.y0 += yOffset;
Rect.y1 += yOffset;
GUI_SetTextMode(GUI_TM_TRANS);
GUI_DispStringInRectWrap(TEXT, &Rect, GUI_TA_LEFT, GUI_WRAPMODE_WORD);
//
// Clear the clipping rectangle
//
GUI_SetClipRect(NULL);
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
GUI_Init();
//
// Enable motion support
//
WM_MOTION_Enable(1);
//
// Enable multi-buffering to avoid flickering during motion
//
WM_MULTIBUF_Enable(1);
//
// Create a window
//
WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW | WM_CF_HASTRANS, _cbWin, 0);
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/