📄 maindemo.c
字号:
/////////////////////////////////////////////////////////////////////////////
// Function: WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg)
// Input: objMsg - translated message for the object,
// pObj - pointer to the object,
// pMsg - pointer to the non-translated, raw GOL message
// Output: if the function returns non-zero the message will be processed by default
// Overview: this function must be implemented by user. GOLMsg() function calls it each
// time the valid message for the object received
/////////////////////////////////////////////////////////////////////////////
WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg){
// beep if button is pressed
if(objMsg == BTN_MSG_PRESSED){
Beep();
}else{
if(GetObjType(pObj) == OBJ_RADIOBUTTON){
Beep();
}else{
if(GetObjType(pObj) == OBJ_CHECKBOX)
Beep();
}
}
if ((screenState & 0xF300) != 0xF300) {
// check for time setting press, process only when not setting time and date
if (objMsg == ST_MSG_SELECTED) {
/* note how the states are arranged in the enumeration, the display state is
right after the create state. So at the time the static text box of the
time is selected, the state is in one of the displays. So a minus one is needed
to adjust to go back to the create state of the current page.
After the date and time adjust screen is exited, the saved create state will
be entered as the next state. So we get the effect of going back to the previous
screen after date and time settings are done.
*/
if ((GetObjID(pObj) == ID_STATICTEXT1) || (GetObjID(pObj) == ID_STATICTEXT2)) {
prevState = screenState - 1; // save the current create state
screenState = CREATE_DATETIME; // go to date and time setting screen
return 1;
}
}
}
// check if pull down menu is called
if (GetObjID(pObj) == ID_WINDOW1) {
if ((objMsg == WND_MSG_TITLE) && (screenState != DISPLAY_PULLDOWN)){
// check area of press
if ((pMsg->param1 <= 40) && (pMsg->param2 <= 40)) {
switch(screenState) {
// if one of these states we redraw the whole screen since
// these screens have customized graphics.
case DISPLAY_SLIDER:
prevState = CREATE_SLIDER; break;
case DISPLAY_CUSTOMCONTROL:
prevState = CREATE_CUSTOMCONTROL; break;
case DISPLAY_SIGNATURE:
prevState = CREATE_SIGNATURE; break;
case DISPLAY_POT:
prevState = CREATE_POT; break;
case DISPLAY_ECG:
prevState = CREATE_ECG; break;
case DISPLAY_PROGRESSBAR:
prevState = CREATE_PROGRESSBAR; break;
// pull down is disabled when setting date and time
case CREATE_DATETIME:
case DISPLAY_DATETIME:
case DISPLAY_DATE_PDMENU:
case SHOW_DATE_PDMENU:
case HIDE_DATE_PDMENU:
return 0;
default:
prevState = screenState; // save the current create state
break;
}
screenState = CREATE_PULLDOWN; // go to show pulldown menu state
return 1;
}
}
}
// process messages for demo screens
switch(screenState){
case DISPLAY_BUTTONS:
return MsgButtons(objMsg, pObj);
case DISPLAY_CHECKBOXES:
return MsgCheckBoxes(objMsg, pObj);
case DISPLAY_RADIOBUTTONS:
return MsgRadioButtons(objMsg, pObj);
case DISPLAY_STATICTEXT:
return MsgStaticText(objMsg, pObj);
case DISPLAY_PICTURE:
return MsgPicture(objMsg, pObj);
case DISPLAY_SLIDER:
return MsgSlider(objMsg, pObj, pMsg);
case DISPLAY_PROGRESSBAR:
return MsgProgressBar(objMsg, pObj);
// date and time settings display
case DISPLAY_DATETIME:
return MsgDateTime(objMsg, pObj);
case DISPLAY_DATE_PDMENU:
return MsgSetDate(objMsg, pObj, pMsg);
case CREATE_DATETIME:
case SHOW_DATE_PDMENU:
case HIDE_DATE_PDMENU:
return 0;
case DISPLAY_METER:
return MsgMeter(objMsg, pObj);
case DISPLAY_DIAL:
return MsgDial(objMsg, pObj);
case DISPLAY_CUSTOMCONTROL:
return MsgCustomControl(objMsg, pObj, pMsg);
case DISPLAY_LISTBOX:
return MsgListBox(objMsg, pObj, pMsg);
case DISPLAY_EDITBOX:
return MsgEditBox(objMsg, pObj, pMsg);
case DISPLAY_SIGNATURE:
return MsgSignature(objMsg, pObj, pMsg);
case DISPLAY_POT:
return MsgPotentiometer(objMsg, pObj);
case DISPLAY_ECG:
return MsgECG(objMsg, pObj);
case DISPLAY_PULLDOWN:
return MsgPullDown(objMsg, pObj, pMsg);
default:
// process message by default
return 1;
}
}
/////////////////////////////////////////////////////////////////////////////
// Function: WORD GOLDrawCallback()
// Output: if the function returns non-zero the draw control will be passed to GOL
// Overview: this function must be implemented by user. GOLDraw() function calls it each
// time when GOL objects drawing is completed. User drawing should be done here.
// GOL will not change color, line type and clipping region settings while
// this function returns zero.
/////////////////////////////////////////////////////////////////////////////
WORD GOLDrawCallback(){
static DWORD prevTick = 0; // keeps previous value of tick
static DWORD prevTime = 0; // keeps previous value of time tick
static BYTE direction = 1; // direction switch for progress bar
static BYTE arrowPos = 0; // arrows pictures position for custom control demo
static BYTE pBDelay = 40; // progress bar delay variable
OBJ_HEADER *pObj; // used to change text in Window
SLIDER *pSld; // used when updating date and time
LISTBOX *pLb; // used when updating date and time
WORD i;
// update the time display
if ((screenState & 0x0000F300) != 0x0000F300) { // process only when NOT setting time and date
if ((tick-prevTime) > 1000){
RTCCProcessEvents(); // update the date and time string variabes
i = 0;
while (i < 12) {
dateTimeStr[i] = _time_str[i];
dateTimeStr[i+13] = _date_str[i];
i++;
}
dateTimeStr[12] = 0x000A; // (XCHAR)'\n';
dateTimeStr[25] = 0x0000; // (XCHAR)'\0';
if (pObj = GOLFindObject(ID_STATICTEXT1)) { // get the time display obj pointer
StSetText((STATICTEXT *)pObj, dateTimeStr); // now display the new date & time
SetState(pObj, ST_DRAW); // redraw the time display
}
prevTime = tick; // reset tick timer
}
} else { // process only when setting time and date
// do not update when pull down menus are on
if ((screenState != DISPLAY_DATE_PDMENU) && (screenState != HIDE_DATE_PDMENU))
{
if ((tick-prevTime) > 1000){
updateDateTimeEb(); // update edit boxes for date and time settings
prevTime = tick; // reset tick timer
}
}
}
switch(screenState){
case CREATE_BUTTONS:
CreateButtons(); // create window and buttons
screenState = DISPLAY_BUTTONS; // switch to next state
return 1; // draw objects created
case DISPLAY_BUTTONS:
return 1; // redraw objects if needed
case CREATE_CHECKBOXES:
CreateCheckBoxes(); // create window and check boxes
screenState = DISPLAY_CHECKBOXES; // switch to next state
return 1; // draw objects created
case DISPLAY_CHECKBOXES:
return 1; // redraw objects if needed
case CREATE_RADIOBUTTONS:
CreateRadioButtons(); // create window and radio buttons
screenState = DISPLAY_RADIOBUTTONS; // switch to next state
return 1; // draw objects created
case DISPLAY_RADIOBUTTONS:
return 1; // redraw objects if needed
case CREATE_STATICTEXT:
CreateStaticText(); // create window, group box, static text
// and radio buttons for control
screenState = DISPLAY_STATICTEXT; // switch to next state
return 1; // draw objects created
case DISPLAY_STATICTEXT:
if((tick-prevTick)>4000) {
pObj = GOLFindObject(ID_WINDOW1);
if (direction) {
WndSetText((WINDOW*)pObj, GroupBoxStr); // "Group Box");
direction = 0;
} else {
WndSetText((WINDOW*)pObj, StaticTextStr); // "Static text");
direction = 1;
}
SetState(pObj, WND_DRAW_TITLE);
prevTick = tick;
}
return 1; // redraw objects if needed
case CREATE_SLIDER:
CreateSlider(); // create window and sliders
screenState = CURSOR_DRAW_SLIDER; // switch to next state
return 1; // draw objects created
case CURSOR_DRAW_SLIDER:
DrawSliderCursor(BLACK); // draw sliders position cursor
screenState = DISPLAY_SLIDER; // switch to next state
case DISPLAY_SLIDER:
return 1; // redraw objects if needed
case CREATE_PROGRESSBAR:
CreateProgressBar(); // create window and progress bar
screenState = DISPLAY_PROGRESSBAR; // switch to next state
return 1; // draw objects created
case DISPLAY_PROGRESSBAR:
if(GetState(pGenObj, BTN_PRESSED))
pBDelay = 8;
else
pBDelay = 40;
if((tick-prevTick)>pBDelay){
if(direction){
if(pProgressBar->pos == pProgressBar->range)
direction = 0; // change direction
else
PbSetPos(pProgressBar,PbGetPos(pProgressBar)+1); // increase
}else{
if(pProgressBar->pos == 0)
direction = 1; // change direction
else
PbSetPos(pProgressBar,PbGetPos(pProgressBar)-1); // decrease
}
SetState(pProgressBar,PB_DRAW_BAR); // redraw bar only
prevTick = tick;
}
return 1; // redraw objects if needed
case CREATE_EDITBOX:
CreateEditBox(); // create edit box test screen
screenState = DISPLAY_EDITBOX; // switch to next state
return 1; // draw objects created
case DISPLAY_EDITBOX:
return 1; // draw objects
case CREATE_LISTBOX:
CreateListBox(); // create list box test screen
screenState = DISPLAY_LISTBOX; // switch to next state
return 1; // draw objects created
case DISPLAY_LISTBOX:
// this moves the slider and editbox for the date setting to
// move while the up or down arrow buttons are pressed
if((tick-prevTick)>100) {
pLb = (LISTBOX*)GOLFindObject(ID_LISTBOX1);
pSld = (SLIDER*)GOLFindObject(ID_SLIDER1);
pObj = GOLFindObject(ID_BUTTON1);
if(GetState(pObj, BTN_PRESSED)) {
LbSetFocusedItem(pLb,LbGetFocusedItem(pLb)-1);
SetState(pLb, LB_DRAW_ITEMS);
SldSetPos(pSld,SldGetPos(pSld)+1);
SetState(pSld, SLD_DRAW_THUMB);
}
pObj = GOLFindObject(ID_BUTTON2);
if(GetState(pObj, BTN_PRESSED)) {
LbSetFocusedItem(pLb,LbGetFocusedItem(pLb)+1);
SetState(pLb, LB_DRAW_ITEMS);
SldSetPos(pSld,SldGetPos(pSld)-1);
SetState(pSld, SLD_DRAW_THUMB);
}
prevTick = tick;
}
return 1; // draw objects
case CREATE_DATETIME:
CreateDateTime(); // create date and time demo
screenState = DISPLAY_DATETIME; // switch to next state
return 1; // draw objects created
case SHOW_DATE_PDMENU:
ShowPullDownMenu();
screenState = DISPLAY_DATE_PDMENU;
return 1;
case HIDE_DATE_PDMENU:
if (RemovePullDownMenu())
screenState = DISPLAY_DATETIME; // switch to next state
return 1;
case DISPLAY_DATE_PDMENU:
// this moves the slider and editbox for the date setting to
// move while the up or down arrow buttons are pressed
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -