2017-06-07 13:50:51 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Copyright. **/
|
|
|
|
/** FileName: HMI_Demo04_Graph.c **/
|
|
|
|
/** Author: Polarix **/
|
|
|
|
/** Version: 1.0.0.0 **/
|
|
|
|
/** Description: HMI demo for graph interface. **/
|
|
|
|
/*************************************************************************/
|
|
|
|
//=======================================================================//
|
|
|
|
//= Include files. =//
|
|
|
|
//=======================================================================//
|
2017-10-08 16:03:05 +00:00
|
|
|
#include "DemoProc.h"
|
2017-08-02 14:24:26 +00:00
|
|
|
#include "SGUI_Frame.h"
|
|
|
|
#include "SGUI_Notice.h"
|
2017-10-08 16:03:05 +00:00
|
|
|
#include "SGUI_VariableBox.h"
|
2017-06-07 13:50:51 +00:00
|
|
|
|
|
|
|
//=======================================================================//
|
|
|
|
//= User Macro definition. =//
|
|
|
|
//=======================================================================//
|
2017-08-02 14:24:26 +00:00
|
|
|
#define VARIABLE_DEMO_FONT_SIZE (SGUI_FONT_SIZE_H12)
|
|
|
|
#define FRAME_TITLE_HEIGHT (g_stFontSize[SGUI_FONT_SIZE_H12].Height+2)
|
2017-06-07 13:50:51 +00:00
|
|
|
#define TEXT_VARIABLE_LENGTH (20)
|
|
|
|
|
|
|
|
#define VARIABLE_BOX_WIDTH (100)
|
|
|
|
#define VARIABLE_BOX_POSX (10)
|
2017-10-08 16:03:05 +00:00
|
|
|
#define VARIABLE_BOX_NUMBER_POSY (19)
|
|
|
|
#define VARIABLE_BOX_TEXT_POSY (38)
|
2017-06-07 13:50:51 +00:00
|
|
|
//=======================================================================//
|
|
|
|
//= Static function declaration. =//
|
|
|
|
//=======================================================================//
|
2017-10-08 16:03:05 +00:00
|
|
|
static SGUI_INT HMI_DemoVariableBox_Initialize(void);
|
|
|
|
static SGUI_INT HMI_DemoVariableBox_PreProcess(const void* pstParameters);
|
|
|
|
static SGUI_INT HMI_DemoVariableBox_RefrershScreen(void);
|
|
|
|
static SGUI_INT HMI_DemoVariableBox_OnInternalEvent(SGUI_INT uiScreenID, const void* pstParameters);
|
|
|
|
static SGUI_INT HMI_DemoVariableBox_OnExternalEvent(SGUI_INT uiScreenID, const void* pstParameters);
|
|
|
|
static SGUI_INT HMI_DemoVariableBox_PostProcess(SGUI_INT iActionResult);
|
2017-08-02 14:24:26 +00:00
|
|
|
static void HMI_DemoVariableBox_DrawFrame(SGUI_PSZSTR szTitle);
|
2017-06-07 13:50:51 +00:00
|
|
|
|
|
|
|
//=======================================================================//
|
|
|
|
//= Static variable declaration. =//
|
|
|
|
//=======================================================================//
|
2017-10-08 16:03:05 +00:00
|
|
|
static SGUI_INT_VARBOX_STRUCT stNumberVariableBox = {VARIABLE_BOX_POSX+2, VARIABLE_BOX_NUMBER_POSY+2, VARIABLE_BOX_WIDTH, SGUI_FONT_SIZE_H12, -50, 100, 0};
|
2017-08-02 14:24:26 +00:00
|
|
|
static char arrTextVariable[TEXT_VARIABLE_LENGTH+1] = {"ABCDEFG"};
|
2017-10-08 16:03:05 +00:00
|
|
|
static SGUI_TEXT_VARBOX_STRUCT stTextVariableBox = {VARIABLE_BOX_POSX+2, VARIABLE_BOX_TEXT_POSY+2, VARIABLE_BOX_WIDTH, SGUI_FONT_SIZE_H16, 0, TEXT_VARIABLE_LENGTH, arrTextVariable};
|
2017-08-02 14:24:26 +00:00
|
|
|
static const char stFrameTitleDefault[] = {"数值/文本编辑演示"};
|
|
|
|
static const char* szFrameTitle = stFrameTitleDefault;
|
2017-06-07 13:50:51 +00:00
|
|
|
static uint16_t uiFocusedFlag;
|
2017-08-02 14:24:26 +00:00
|
|
|
static const char szHelpNoticeText[] = {"TAB键切换焦点编辑框。\n上下箭头调整数值。\n左右箭头调整焦点字符。\n按空格键继续。"};
|
2017-06-07 13:50:51 +00:00
|
|
|
static uint16_t uiNeedHelp = 5;
|
|
|
|
|
|
|
|
//=======================================================================//
|
|
|
|
//= Global variable declaration. =//
|
|
|
|
//=======================================================================//
|
|
|
|
HMI_SCREEN_ACTION stHMI_DemoVariableBoxActions = {HMI_DemoVariableBox_Initialize,
|
|
|
|
HMI_DemoVariableBox_PreProcess,
|
|
|
|
HMI_DemoVariableBox_RefrershScreen,
|
|
|
|
HMI_DemoVariableBox_OnInternalEvent,
|
|
|
|
HMI_DemoVariableBox_OnExternalEvent,
|
|
|
|
HMI_DemoVariableBox_PostProcess,
|
|
|
|
};
|
2017-10-08 16:03:05 +00:00
|
|
|
HMI_SCREEN_OBJECT g_stHMI_DemoVariableBox = { HMI_SCREEN_ID_ANY,
|
2017-06-07 13:50:51 +00:00
|
|
|
&stHMI_DemoVariableBoxActions
|
|
|
|
};
|
|
|
|
|
|
|
|
//=======================================================================//
|
|
|
|
//= Function implementation. =//
|
|
|
|
//=======================================================================//
|
2017-10-08 16:03:05 +00:00
|
|
|
SGUI_INT HMI_DemoVariableBox_Initialize(void)
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
|
|
|
uiFocusedFlag = 0;
|
2017-10-08 16:03:05 +00:00
|
|
|
return HMI_RET_NORMAL;
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
|
|
|
|
2017-10-08 16:03:05 +00:00
|
|
|
SGUI_INT HMI_DemoVariableBox_PreProcess(const void* pstParameters)
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
|
|
|
// Draw frame
|
2017-08-02 14:24:26 +00:00
|
|
|
HMI_DemoVariableBox_DrawFrame((SGUI_PSZSTR)szFrameTitle);
|
|
|
|
// Show notice
|
|
|
|
SGUI_Notice_RefreshNotice(szHelpNoticeText, 0, SGUI_ICON_INFORMATION);
|
2017-10-08 16:03:05 +00:00
|
|
|
return HMI_RET_NORMAL;
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
|
|
|
|
2017-10-08 16:03:05 +00:00
|
|
|
SGUI_INT HMI_DemoVariableBox_RefrershScreen(void)
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-10-08 16:03:05 +00:00
|
|
|
return HMI_RET_NORMAL;
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
|
|
|
|
2017-10-08 16:03:05 +00:00
|
|
|
SGUI_INT HMI_DemoVariableBox_OnInternalEvent(SGUI_INT uiScreenID, const void* pstParameters)
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
|
|
|
if(uiNeedHelp > 0)
|
|
|
|
{
|
|
|
|
uiNeedHelp--;
|
|
|
|
HMI_Action_Goto(3, szHelpNoticeText);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HMI_DemoVariableBox_PreProcess(NULL);
|
|
|
|
}
|
2017-10-08 16:03:05 +00:00
|
|
|
return HMI_RET_NOACTION;
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
|
|
|
|
2017-10-08 16:03:05 +00:00
|
|
|
SGUI_INT HMI_DemoVariableBox_OnExternalEvent(SGUI_INT uiScreenID,const void* pstParameters)
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
2017-10-08 16:03:05 +00:00
|
|
|
SGUI_INT iProcessResult;
|
2017-06-07 13:50:51 +00:00
|
|
|
USER_ACT_KEYPRESS* pstUserEvent;
|
2017-08-02 14:24:26 +00:00
|
|
|
static uint32_t iInitialized = 0;
|
2017-06-07 13:50:51 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Initialize */
|
|
|
|
/*----------------------------------*/
|
2017-10-08 16:03:05 +00:00
|
|
|
iProcessResult = HMI_RET_NORMAL;
|
2017-06-07 13:50:51 +00:00
|
|
|
pstUserEvent = (USER_ACT_KEYPRESS*)pstParameters;
|
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
if(0 == iInitialized)
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
switch(pstUserEvent->KeyValue[0])
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
case KEY_VALUE_SPACE:
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
if(0 == iInitialized)
|
|
|
|
{
|
|
|
|
// Draw frame
|
|
|
|
HMI_DemoVariableBox_DrawFrame((SGUI_PSZSTR)szFrameTitle);
|
|
|
|
// Draw number box
|
2017-10-08 16:03:05 +00:00
|
|
|
SGUI_Basic_DrawRectangle(VARIABLE_BOX_POSX, VARIABLE_BOX_NUMBER_POSY, VARIABLE_BOX_WIDTH+4, g_stFontSize[stNumberVariableBox.FontSize].Height+6, GUI_COLOR_FRGCLR, GUI_COLOR_BKGCLR);
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_IntegerVariableBox_Refresh(&stNumberVariableBox, SGUI_CENTER, GUI_DRAW_REVERSE);
|
|
|
|
// Draw text box
|
2017-10-08 16:03:05 +00:00
|
|
|
SGUI_Basic_DrawRectangle(VARIABLE_BOX_POSX, VARIABLE_BOX_TEXT_POSY, VARIABLE_BOX_WIDTH+4, g_stFontSize[stTextVariableBox.FontSize].Height+6, GUI_COLOR_FRGCLR, GUI_COLOR_BKGCLR);
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_TextVariableBox_Refresh(&stTextVariableBox, GUI_DRAW_NORMAL);
|
|
|
|
iInitialized = 1;
|
|
|
|
}
|
|
|
|
break;
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
2017-08-02 14:24:26 +00:00
|
|
|
break;
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-10-08 16:03:05 +00:00
|
|
|
iProcessResult = HMI_RET_NOACTION;
|
2017-08-02 14:24:26 +00:00
|
|
|
break;
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-02 14:24:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch(pstUserEvent->KeyValue[0])
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
case KEY_VALUE_TAB:
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
uiFocusedFlag = ((uiFocusedFlag+1)%2);
|
|
|
|
if(0 == uiFocusedFlag)
|
|
|
|
{
|
|
|
|
SGUI_IntegerVariableBox_Refresh(&stNumberVariableBox, SGUI_CENTER, GUI_DRAW_REVERSE);
|
|
|
|
SGUI_TextVariableBox_Refresh(&stTextVariableBox, GUI_DRAW_NORMAL);
|
|
|
|
}
|
|
|
|
else
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_IntegerVariableBox_Refresh(&stNumberVariableBox, SGUI_CENTER, GUI_DRAW_NORMAL);
|
|
|
|
SGUI_TextVariableBox_Refresh(&stTextVariableBox, GUI_DRAW_REVERSE);
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
2017-10-08 16:03:05 +00:00
|
|
|
iProcessResult = HMI_RET_NOACTION;
|
2017-08-02 14:24:26 +00:00
|
|
|
break;
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
2017-08-02 14:24:26 +00:00
|
|
|
case KEY_VALUE_ESC:
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-10-08 16:03:05 +00:00
|
|
|
iProcessResult = HMI_RET_CANCEL;
|
2017-08-02 14:24:26 +00:00
|
|
|
break;
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
2017-08-02 14:24:26 +00:00
|
|
|
case KEY_VALUE_LEFT:
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
if(1 == uiFocusedFlag)
|
|
|
|
{
|
|
|
|
if(stTextVariableBox.FocusIndex > 0)
|
|
|
|
{
|
|
|
|
stTextVariableBox.FocusIndex--;
|
|
|
|
SGUI_TextVariableBox_ChangeCharacter(&stTextVariableBox, GUI_DRAW_REVERSE, GUI_TEXT_ASCII, SGUI_TXT_VARBOX_OPT_NONE);
|
|
|
|
}
|
|
|
|
}
|
2017-10-08 16:03:05 +00:00
|
|
|
iProcessResult = HMI_RET_NOACTION;
|
2017-08-02 14:24:26 +00:00
|
|
|
break;
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
2017-08-02 14:24:26 +00:00
|
|
|
case KEY_VALUE_UP:
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
if(1 == uiFocusedFlag)
|
|
|
|
{
|
|
|
|
SGUI_TextVariableBox_ChangeCharacter(&stTextVariableBox, GUI_DRAW_REVERSE, GUI_TEXT_ASCII, SGUI_TXT_VARBOX_OPT_PREV);
|
|
|
|
}
|
|
|
|
else
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
stNumberVariableBox.Value++;
|
|
|
|
SGUI_IntegerVariableBox_Refresh(&stNumberVariableBox, SGUI_CENTER, GUI_DRAW_REVERSE);
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
2017-10-08 16:03:05 +00:00
|
|
|
iProcessResult = HMI_RET_NOACTION;
|
2017-08-02 14:24:26 +00:00
|
|
|
break;
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
2017-08-02 14:24:26 +00:00
|
|
|
case KEY_VALUE_RIGHT:
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
if(1 == uiFocusedFlag)
|
|
|
|
{
|
2017-08-21 14:25:23 +00:00
|
|
|
if(stTextVariableBox.FocusIndex < (stTextVariableBox.MaxTextLength-1))
|
2017-08-02 14:24:26 +00:00
|
|
|
{
|
|
|
|
stTextVariableBox.FocusIndex++;
|
|
|
|
SGUI_TextVariableBox_ChangeCharacter(&stTextVariableBox, GUI_DRAW_REVERSE, GUI_TEXT_ASCII, SGUI_TXT_VARBOX_OPT_NONE);
|
|
|
|
}
|
|
|
|
}
|
2017-10-08 16:03:05 +00:00
|
|
|
iProcessResult = HMI_RET_NOACTION;
|
2017-08-02 14:24:26 +00:00
|
|
|
break;
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
2017-08-02 14:24:26 +00:00
|
|
|
case KEY_VALUE_DOWN:
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
if(1 == uiFocusedFlag)
|
|
|
|
{
|
|
|
|
SGUI_TextVariableBox_ChangeCharacter(&stTextVariableBox, GUI_DRAW_REVERSE, GUI_TEXT_ASCII, SGUI_TXT_VARBOX_OPT_NEXT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stNumberVariableBox.Value--;
|
|
|
|
SGUI_IntegerVariableBox_Refresh(&stNumberVariableBox, SGUI_CENTER, GUI_DRAW_REVERSE);
|
|
|
|
}
|
2017-10-08 16:03:05 +00:00
|
|
|
iProcessResult = HMI_RET_NOACTION;
|
2017-08-02 14:24:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_ENTER:
|
|
|
|
{
|
|
|
|
if(1 == uiFocusedFlag)
|
|
|
|
{
|
|
|
|
szFrameTitle = stTextVariableBox.Value;
|
|
|
|
HMI_DemoVariableBox_DrawFrame((SGUI_PSZSTR)szFrameTitle);
|
|
|
|
// Draw number box
|
2017-10-08 16:03:05 +00:00
|
|
|
SGUI_Basic_DrawRectangle(VARIABLE_BOX_POSX, VARIABLE_BOX_NUMBER_POSY, VARIABLE_BOX_WIDTH+4, g_stFontSize[stNumberVariableBox.FontSize].Height+6, GUI_COLOR_FRGCLR, GUI_COLOR_BKGCLR);
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_IntegerVariableBox_Refresh(&stNumberVariableBox, SGUI_CENTER, GUI_DRAW_NORMAL);
|
|
|
|
// Draw text box
|
2017-10-08 16:03:05 +00:00
|
|
|
SGUI_Basic_DrawRectangle(VARIABLE_BOX_POSX, VARIABLE_BOX_TEXT_POSY, VARIABLE_BOX_WIDTH+4, g_stFontSize[stTextVariableBox.FontSize].Height+6, GUI_COLOR_FRGCLR, GUI_COLOR_BKGCLR);
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_TextVariableBox_Refresh(&stTextVariableBox, GUI_DRAW_REVERSE);
|
|
|
|
}
|
|
|
|
break;
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-08-02 14:24:26 +00:00
|
|
|
{
|
2017-10-08 16:03:05 +00:00
|
|
|
iProcessResult = HMI_RET_NOACTION;
|
2017-08-02 14:24:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return iProcessResult;
|
|
|
|
}
|
|
|
|
|
2017-10-08 16:03:05 +00:00
|
|
|
SGUI_INT HMI_DemoVariableBox_PostProcess(SGUI_INT iActionResult)
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-10-08 16:03:05 +00:00
|
|
|
if(HMI_RET_CANCEL == iActionResult)
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
|
|
|
HMI_Action_GoBack();
|
|
|
|
}
|
2017-10-08 16:03:05 +00:00
|
|
|
return HMI_RET_NORMAL;
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
2017-08-02 14:24:26 +00:00
|
|
|
|
|
|
|
void HMI_DemoVariableBox_DrawFrame(SGUI_PSZSTR szTitle)
|
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
|
|
|
SGUI_BOX_FRAME_STRUCT stFrameData;
|
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Initialize */
|
|
|
|
/*----------------------------------*/
|
|
|
|
stFrameData.Parameter.EdgeLayers = 2;
|
|
|
|
stFrameData.Parameter.FontSize = SGUI_FONT_SIZE_H12;
|
|
|
|
stFrameData.Data.Title = szTitle;
|
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
|
|
|
// Draw frame
|
|
|
|
SGUI_Frame_DrawFullScreenFrame(&stFrameData);
|
|
|
|
}
|