the bule color context is added or edited by myself. ^_^
the bold context is the c code to display the moving picture.
———————————————–follwo is the C file————————————————————-
/*********************************************************************
* SEGGER MICROCONTROLLER SYSTEME GmbH *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 1996 – 2007 SEGGER Microcontroller Systeme GmbH *
* *
* Internet: www.segger.com Support: [email protected] *
* *
**********************************************************************
** emWin V4.14 – 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 : GUIDEMO_Intro.c
Purpose : Introduction for emWin generic demo
(This is also a good file to demo and explain basic
emWin features by setting breakpoints)
———————————————————————-
*/
#include "GUI.h"
#include "GUIDEMO.h"
#include <string.h>
#include <stdlib.h>
/*********************************************************************
*
* GUIDEMO_Intro
*
**********************************************************************
*/
#if GUIDEMO_LARGE
void GUIDEMO_Intro(void) {
int xCenter = LCD_XSIZE >> 1;
int y, yPos;
char acText[50] = "Version of emWin: ";
/* test sprintf */
char str[30];
/* show large demo verion and lcd x and y size */
char lcdSizeInfo[40] = "The LCD size: X = ";
char xsize_str[5], ysize_str[5];
/* start draw the horizontal moving picture */
int i, currentXpos, currentYpos;
/* scroll string */
#define MAX_STR_LEN 100
#define MARGIN_LEN 40
#define SCROLL_XPOS_BEGIN MARGIN_LEN
#define SCROLL_XPOS_END (LCD_XSIZE-MARGIN_LEN)
#define SCROLL_Y_POS 10
#define TEXT_HEIGHT 20
#define SCROLL_STEP_LEN 2
#define SCROLL_DELAY_TIME 5
#define SCROLL_INTERVAL_LEN 16
char scrollBuffer[MAX_STR_LEN];
char *strToDisp = "This is a too long long name to be test to display.mp3";
int currXpos;
int strDispLen;
/* picture horizotal moving */
#define X_TOTAL_LEN (LCD_XSIZE/2)
#define STEP_LEN 4
#define STEPS (X_TOTAL_LEN/STEP_LEN)
#define STEP_DELAY_TIME 5
/* picture slash moving */
#define STEP_LEN_X 3
#define STEP_DELAY_TIME_SLASH 5
#define MOV_LEN_X (LCD_XSIZE>>1)
#define MOV_LEN_Y (LCD_YSIZE>>1)
#define MOV_TIMES (MOV_LEN_X/STEP_LEN_X)
#define STEP_LEN_Y (MOV_LEN_Y/MOV_TIMES)
strcat(acText, GUI_GetVersionString());
GUIDEMO_SetBkColor(GUI_BLUE);
GUIDEMO_SetColor(GUI_WHITE);
GUI_Clear();
GUI_SetFont(&GUI_FontComic18B_ASCII);
GUI_DispStringHCenterAt("emWin", xCenter, y = 12);
GUI_SetFont(&GUI_Font13H_ASCII);
GUI_DispStringHCenterAt("Universal graphic software"
"nfor embedded applications"
, xCenter, y += 23);
GUI_SetColor(GUI_RED);
GUI_SetFont(&GUI_Font16_ASCII);
GUI_DispStringHCenterAt("Any CPU – Any LCD – Any Application"
, xCenter, y += 32);
GUI_SetFont(&GUI_Font10S_ASCII);
GUI_DispStringHCenterAt("Compiled " __DATE__ " "__TIME__, xCenter, y += 18);
GUI_SetFont(&GUI_Font13HB_ASCII);
GUI_SetColor(GUI_WHITE);
GUI_DispStringHCenterAt(acText, xCenter, y += 15);
/* show large demo verion and lcd x and y size */
GUI_DispStringHCenterAt("This is large version of this demo.", xCenter, y += 15);
_itoa(LCD_XSIZE, xsize_str, 10);
_itoa(LCD_YSIZE, ysize_str, 10);
strcat(lcdSizeInfo,xsize_str);
strcat(lcdSizeInfo,", Y = ");
strcat(lcdSizeInfo,ysize_str);
strcat(lcdSizeInfo,".");
GUI_DispStringHCenterAt(lcdSizeInfo, xCenter, y += 15);
/** the end **/
GUI_SetFont(&GUI_FontComic18B_ASCII);
GUI_SetColor(GUI_WHITE);
GUI_DispStringAt("http://hi.baidu.com/serial_story", 0, LCD_YSIZE – 20);
yPos = y + 15 + ((LCD_YSIZE – y – 33) >> 1);
yPos -= bmSeggerLogoBlue.YSize >> 1;
if (yPos > 160) {
yPos = 160;
}
/* draw the scroll string */
/* init the scroll buffer */
/* clear margin */
GUI_ClearRect(0, SCROLL_Y_POS, MARGIN_LEN, SCROLL_Y_POS + TEXT_HEIGHT);
GUI_ClearRect(LCD_XSIZE – MARGIN_LEN, SCROLL_Y_POS, LCD_XSIZE, SCROLL_Y_POS + TEXT_HEIGHT);
memset(scrollBuffer, 0x00, MAX_STR_LEN);
currXpos = 0;
strDispLen = GUI_GetStringDistX(strToDisp);
currXpos = SCROLL_XPOS_BEGIN;
strcpy(scrollBuffer, strToDisp);
/**** start scroll ****/
while(1)
{
/* clear scroll area */
GUI_ClearRect(SCROLL_XPOS_BEGIN, SCROLL_Y_POS, SCROLL_XPOS_END, SCROLL_Y_POS + TEXT_HEIGHT);
/* display text */
GUI_DispStringAt(strToDisp, currXpos, SCROLL_Y_POS);
if( currXpos + strDispLen + SCROLL_INTERVAL_LEN < SCROLL_XPOS_END )
GUI_DispStringAt(strToDisp, currXpos + strDispLen + SCROLL_INTERVAL_LEN, SCROLL_Y_POS);
/* clear margin */
GUI_ClearRect(0, SCROLL_Y_POS, MARGIN_LEN, SCROLL_Y_POS + TEXT_HEIGHT);
GUI_ClearRect(LCD_XSIZE – MARGIN_LEN, SCROLL_Y_POS, LCD_XSIZE, SCROLL_Y_POS + TEXT_HEIGHT);
/* update */
currXpos -= SCROLL_STEP_LEN;
if( SCROLL_XPOS_BEGIN -currXpos > strDispLen )
currXpos = SCROLL_XPOS_END;
GUIDEMO_Delay(SCROLL_DELAY_TIME);
}
/* test sprintf */
sprintf(str, "%8d%8d", 123, 4567); //产生:" 123 4567"
GUI_DispStringAt(str, 10, 10);
#if 0
/* draw the slash mobving picture */
GUIDEMO_SetBkColor(GUI_BLACK);
currentXpos = 0;
currentYpos = 0;
GUI_ClearRect(0, 0, MOV_LEN_X + bmbmp_Mainmenu_photo1.XSize, MOV_LEN_Y+ bmbmp_Mainmenu_photo1.YSize);
for(i = 0; i < MOV_TIMES; i++)
{
/* clear last*/
GUI_ClearRect(currentXpos -STEP_LEN_X, currentYpos- STEP_LEN_Y, currentXpos -STEP_LEN_X + bmbmp_Mainmenu_photo1.XSize, currentYpos- STEP_LEN_Y + bmbmp_Mainmenu_photo1.YSize);
/* draw current */
GUI_DrawBitmap(&bmbmp_Mainmenu_photo1, currentXpos, currentYpos);
/* update the x position */
currentXpos += STEP_LEN_X;
currentYpos += STEP_LEN_Y;
/* if the last, then relocate to the start point */
if(MOV_TIMES-1 == i)
{
i = 0;
currentXpos = 0;
currentYpos = 0;
GUI_ClearRect(0, 0, MOV_LEN_X + bmbmp_Mainmenu_photo1.XSize, MOV_LEN_Y+ bmbmp_Mainmenu_photo1.YSize);
}
GUIDEMO_Delay(STEP_DELAY_TIME_SLASH);
}
/* start draw the moving picture */
GUIDEMO_SetBkColor(GUI_BLACK);
GUI_SetColor(GUI_BLACK);
currentXpos = 0;
GUI_ClearRect(0, yPos, X_TOTAL_LEN + bmSeggerLogoBlue.XSize, yPos + bmSeggerLogoBlue.YSize);
for(i = 0; i < STEPS; i++)
{
/* clear last*/
GUI_ClearRect(currentXpos -STEP_LEN, yPos, currentXpos, yPos + bmSeggerLogoBlue.YSize);
/* fill background ??? current color */
//GUI_FillRect(currentXpos -STEP_LEN, yPos, currentXpos, yPos + bmSeggerLogoBlue.YSize);
/* draw current */
GUI_DrawBitmap(&bmSeggerLogoBlue, currentXpos, yPos);
//GUI_DrawBitmap(&bmSeggerLogoBlue, 0, yPos);
/* update the x position */
currentXpos += STEP_LEN;
//currentXpos = currentXpos % X_TOTAL_LEN;
if(STEPS-1 == i)
{
i = 0;
currentXpos = 0;
//GUI_ClearRect(currentXpos, yPos, currentXpos + STEP_LEN, yPos + bmSeggerLogoBlue.YSize);
GUI_ClearRect(0, yPos, X_TOTAL_LEN + bmSeggerLogoBlue.XSize, yPos + bmSeggerLogoBlue.YSize);
}
GUIDEMO_Delay(STEP_DELAY_TIME);
}
/** the end **/
#endif
#if (LCD_YSIZE >= 220)
GUI_SetFont(&GUI_Font10S_ASCII);
GUI_DispStringAt("GUI_OS: ", 0, LCD_YSIZE – 30); GUI_DispDecMin(GUI_OS);
GUI_DispStringAt("GUI_ALLOC_SIZE: ",0, LCD_YSIZE – 20); GUI_DispDecMin(GUI_ALLOC_SIZE);
GUI_DispStringAt("Compiler: "
#ifdef _MSC_VER
"Microsoft"
#elif defined (NC308)
"Mitsubishi NC308"
#elif defined (NC30)
"Mitsubishi NC30"
#elif defined (__TID__)
#if (((__TID__ >>8) &0x7f) == 48) /* IAR MC80 */
"IAR M32C"
#elif (((__TID__ >>8) &0x7f) == 85) /* IAR V850 */
"IAR V850"
#elif defined (__ICCARM__) /* IAR ARM */
"IAR ARM"
#else /* IAR MC16 */
"IAR M32C"
#endif
#elif defined __WATCOMC__ /* WATCOM */
"WATCOM"
#elif defined __GNUC__
"GNU"
#else
"Unknown"
#endif
,0, LCD_YSIZE – 10);
#endif
GUIDEMO_Delay(5000);
GUIDEMO_NotifyStartNext();
}
#else /* GUIDEMO_LARGE */
void GUIDEMO_Intro(void) {
#if GUIDEMO_TINY
char acText[20] = "Version: ";
#else
char acText[32] = "Version of emWin: ";
#endif
int xCenter, dy, y0 = 0;
xCenter = LCD_XSIZE >> 1;
#if (LCD_YSIZE < 72)
dy = 0;
#else
dy = ((LCD_YSIZE – 72) >> 3);
if (dy > 14) dy = 14;
#endif
strcat(acText, GUI_GetVersionString());
/* Clear the background */
GUIDEMO_SetBkColor(GUI_BLUE);
GUIDEMO_SetColor(GUI_WHITE);
GUI_Clear();
/* Display headline */
GUI_SetFont(&GUI_Font13B_ASCII);
GUI_DispStringHCenterAt("emWin", xCenter, dy + 1);
/* Display description */
#if (LCD_XSIZE < 140)
GUI_SetFont(&GUI_Font8_ASCII);
#else
GUI_SetFont(&GUI_Font10_ASCII);
#endif
GUI_DispStringHCenterAt("Universal graphic softwaren"
"for embedded applications", xCenter, 2 * dy + 18);
/* Display compile time */
GUI_SetFont(&GUI_Font10S_ASCII);
GUI_DispStringHCenterAt("Compiled " __DATE__ " "__TIME__, xCenter, 3 * dy + 37);
/* Display version number */
#if (LCD_YSIZE < 80)
GUI_DispStringAt(acText, 6, LCD_YSIZE – 13);
#else
GUI_DispStringHCenterAt(acText, xCenter, 4 * dy + 49);
#endif
GUIDEMO_Delay(5000);
GUIDEMO_NotifyStartNext();
/* Show SEGGER logo */
GUI_Clear();
#if GUIDEMO_TINY
y0 = 2;
#endif
#if (LCD_YSIZE >= 90)
y0 += (LCD_YSIZE – 90) >> 1;
#endif
GUI_DrawBitmap(&bmSeggerLogoBlue, xCenter – (bmSeggerLogoBlue.XSize >> 1), y0);
/* Display URL */
#if (LCD_YSIZE < 80)
GUI_SetFont(&GUI_Font10_ASCII);
#else
GUI_SetFont(&GUI_Font13B_ASCII);
#endif
y0 += bmSeggerLogoBlue.YSize + 1;
GUI_DispStringHCenterAt("www.segger.com", xCenter, y0);
GUIDEMO_Delay(5000);
GUIDEMO_NotifyStartNext();
}
#endif
转载请注明:在路上 » display moving picture and scroll string on enWin Simulator