⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maindemo.c

📁 本代码包为该GUI LIB在PC上的测试移植. PIC_Graphics 为PIC GUI的源代码目录 Demo 为PIC GUI 测试代码目录 其他的代码和目录均是uCGUI
💻 C
📖 第 1 页 / 共 5 页
字号:
	// before moving to a new list the current focused object is set to be not focused.
	// this saves us the effort to save the pointer to the object and setting
	// the global pointer to the focused object to that saved object.
	// this application does not need it to be saved.
	pFObj = GOLGetFocus();				// get the focused object
	if (pFObj != NULL) {
		ClrState(pFObj, FOCUSED);		// clear the focus state
		SetState(pFObj, DRAW);			// set to be redrawn
	}
	pListSaved = GOLGetList();
	GOLNewList();

	LbCreate(ID_LISTBOX2,        		// ID
             40,BOTTOM_NORMAL,			// dimensions
             165,BOTTOM_DROPPED,
             LB_SINGLE_SEL|LB_DRAW|
             LB_FOCUSED,				// will be created with single select and focused
             (XCHAR*)ScreenItems,		// list of demo screens
             alt2Scheme);              	// use alternate scheme

	// This object is a ghost object to enable to get messages that touch is outside
	// the list box. It will never be displayed.
    GbCreate(ID_GROUPBOX2,             	// ID
              0,0,GetMaxX(),GetMaxY(), 	// cover the whole screen
              0,                 		// do not display
              NULL,             		// no text
              NULL);
}

/* this adds items on the items list of the list box */
void AddItemList(XCHAR* pText, LISTBOX *pLb) {
	XCHAR* pointer;
	WORD  ctr;

    if(pText != NULL){
        pointer = pText;
        ctr = 0;
        while(*pointer){
            if(NULL == LbAddItem(pLb, NULL, pointer, NULL, 0, ctr))
                break;
            while(*pointer++ > 31);
            if(*(pointer-1) == 0)
                break;
            ctr++;
        }
    }
}

WORD MsgPullDown(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg) {

LISTBOX *pLb2;
SHORT    item, left, top, right, bottom;
static SHORT  List2Enable = 0;


	pLb2 = (LISTBOX*)GOLFindObject(ID_LISTBOX2);					// find the pull down object
	if(pMsg->uiEvent == EVENT_RELEASE){								// state transition must be done

	   	if (GetObjID(pObj) == ID_LISTBOX2) {  						// if released outside list box, go back
			item = LbGetFocusedItem(pLb2);							// get selected page/screen
			if (!List2Enable) {										// For list 1
				switch (item) {
					default:
					case 0: screenState = CREATE_BUTTONS; 		break;
					case 1: screenState = CREATE_CHECKBOXES;  	break;
					case 2: screenState = CREATE_RADIOBUTTONS;  break;
					case 3: screenState = CREATE_STATICTEXT;  	break;
					case 4: screenState = CREATE_SLIDER;  		break;
					case 5: screenState = CREATE_PROGRESSBAR;   break;
					case 6: screenState = CREATE_LISTBOX;  		break;
					case 7: screenState = CREATE_EDITBOX;  		break;
					case 8: screenState = prevState;			break;
				}
			} else {
				switch (item) {										// For list 2
					default:
					case 0: screenState = prevState;  			break;
					case 1: screenState = CREATE_METER;  		break;
					case 2: screenState = CREATE_DIAL;  		break;
					case 3: screenState = CREATE_PICTURE;  		break;
					case 4: screenState = CREATE_CUSTOMCONTROL; break;
					case 5: screenState = CREATE_SIGNATURE;  	break;
					case 6: screenState = CREATE_POT;  			break;
					case 7: screenState = CREATE_ECG;  			break;
				}
			}
        } else {
			screenState = prevState;								// revert to saved state
    	}
    	left = pLb2->hdr.left; top = pLb2->hdr.top; 						// save the dimensions
    	right = pLb2->hdr.right; bottom = pLb2->hdr.bottom;
    	SetColor(pLb2->hdr.pGolScheme->CommonBkColor);					// set the color
        Bar(left, top, right, bottom);								// hide the pull down menu
		GOLFree();   												// remove the pull down menu
   		GOLSetList(pListSaved);										// set active list back to saved list
        GOLRedrawRec(left, top, right, bottom);						// redraw all objects that the pulldown
    																// menu has overlapped
		return 1;

	} else {
		if (	(pMsg->uiEvent == EVENT_MOVE) ||					// convert messages to press
				(pMsg->uiEvent == EVENT_PRESS))  {

			if (GetObjID(pObj) == ID_LISTBOX2) { 					// process only for list box(pull down menu)
				pMsg->uiEvent = EVENT_PRESS;						// now convert the message

				item = LbGetFocusedItem(pLb2);						// check item selected
				if ((!List2Enable) && (item == 8)) {				// if item MORE.... change menu
					List2Enable = 1;
					LbDelItemsList(pLb2);							// remove the current item
					AddItemList((XCHAR*)ScreenItems2, pLb2);			// set the items list to ScreenItems2
					SetState(pLb2, LB_DRAW);
				}
				if ((List2Enable) && (item == 0)) {					// if item BACK.... change back menu
					List2Enable = 0;								// remove the current item
					LbDelItemsList(pLb2);
					AddItemList((XCHAR*)ScreenItems, pLb2);			// set the items list to ScreenItems
					SetState(pLb2, LB_DRAW);
				}
				return 1;
			}
		}
		return 0;
	}

}


void CreateButtons(){

    GOLFree();   // free memory for the objects in the previous linked list and start new list

	CreatePage(ButtonStr);	// CreatePage("Buttons");

    BtnCreate(ID_BUTTON1, 				// button ID
              30,50,156,100,           	// dimension
              10,					   	// set radius
              BTN_DRAW,  			   	// draw a beveled button
              NULL,                    	// no bitmap
              ButtonStr, 				// "Button",     	// text
              altScheme);              	// use alternate scheme

    BtnCreate(ID_BUTTON2, 				// button ID
              30,110,156,160,         	// dimension
              0,
              BTN_DRAW, 				// will be dislayed after creation
              (void*)&gradientButton,          // use bitmap
              HomeStr, 					// "HOME", 	    // text
              altScheme);	            // alternative GOL scheme

    BtnCreate(ID_BUTTON3,             	// button ID
              165,50,215,160,          	// dimension
              25,					   	// set radius
              BTN_DRAW|BTN_TOGGLE,   	// draw a vertical capsule button
              						   	// that has a toggle behavior
              NULL,                    	// no bitmap
              LowStr, 					// "LO",       	// text
              yellowScheme);           	// use alternate scheme

    BtnCreate(ID_BUTTON4,             	// button ID
              225,43,285,103,          	// dimension
              30,					   	// set radius
              BTN_DRAW, 			   	// draw a vertical capsule button
              NULL,                    	// no bitmap
              OnStr, 					// "ON",		// text
              greenScheme);             // use alternate scheme

    BtnCreate(ID_BUTTON5,             	// button ID
              225,107,285,167,         	// dimension
              30,					   	// set radius
              BTN_DRAW|BTN_PRESSED,  	// draw a vertical capsule button
              							// that is initially pressed
              NULL,                    	// no bitmap
              OffStr, 					// "OFF",      	// text
              redScheme);            	// use alternate scheme

    BtnCreate(ID_BUTTON6, 				// button ID
              30,170,156,220,         	// dimension
              0,
              BTN_DRAW|BTN_TEXTLEFT 	// will be dislayed after creation with text
              |BTN_TEXTTOP, 			// left top position
              (void*)&bulboff,          // use bitmap
              OffBulbStr, 				// text
              alt2Scheme);	            // alternative GOL scheme

    BtnCreate(ID_BUTTON7,          		// button ID
              162,170,288,220,         	// dimension
              0,
              BTN_DRAW|BTN_DISABLED, 	// will be dislayed and disabled after creation
              NULL,                    	// no bitmap
              DisabledStr, 				// "Disabled",  // text
              altScheme);              	// use alternate scheme

}

WORD MsgButtons(WORD objMsg, OBJ_HEADER* pObj){
	OBJ_HEADER* pOtherRbtn;

    switch(GetObjID(pObj)){

        case ID_BUTTON_NEXT:
            if(objMsg == BTN_MSG_RELEASED){
               screenState = CREATE_CHECKBOXES;// goto check box demo screen
            }
            return 1; 							// process by default

        case ID_BUTTON_BACK:
            if(objMsg == BTN_MSG_RELEASED){
                screenState = CREATE_ECG; 		// goto ECG demo screen
            }
            return 1; 							// process by default

        case ID_BUTTON3:
        	if(objMsg == BTN_MSG_PRESSED){ 		// change text and scheme
                BtnSetText((BUTTON*)pObj, HighStr);
            }
            else {
                BtnSetText((BUTTON*)pObj, LowStr);
            }
            return 1;  							// process by default

        case ID_BUTTON4:

			if(objMsg == BTN_MSG_PRESSED) {
				if (!GetState(pObj,BTN_PRESSED)) {
	            	pOtherRbtn = GOLFindObject(ID_BUTTON5);
	            	ClrState(pOtherRbtn, BTN_PRESSED);
		        	SetState(pOtherRbtn, BTN_DRAW);
	            	SetState(pObj, BTN_PRESSED|BTN_DRAW);
	            	GOLSetFocus(pObj); 			// set focus for the button
	            }
	        }
		    return 0; 							// Do not process by default

        case ID_BUTTON5:

			if(objMsg == BTN_MSG_PRESSED) {
				if (!GetState(pObj,BTN_PRESSED)) {
	        		pOtherRbtn = GOLFindObject(ID_BUTTON4);
	            	ClrState(pOtherRbtn, BTN_PRESSED);
		        	SetState(pOtherRbtn, BTN_DRAW);
	            	SetState(pObj, BTN_PRESSED|BTN_DRAW);
	            	GOLSetFocus(pObj); 			// set focus for the button
	            }
	        }
		    return 0; 							// Do not process by default

        case ID_BUTTON6:
            if(objMsg == BTN_MSG_PRESSED){ 		// change face picture
                BtnSetBitmap(pObj,(void*)&bulbon);
                BtnSetText((BUTTON*)pObj, OnBulbStr);

            }
            if(objMsg == BTN_MSG_RELEASED){
                BtnSetBitmap(pObj,(void*)&bulboff);
                BtnSetText((BUTTON*)pObj, OffBulbStr);
	        	ClrState(pObj, 0x00F0);
	        	SetState(pObj, BTN_TEXTTOP|BTN_TEXTLEFT);
            }
            return 1; 							// process by default

        default:
            return 1; 							// process by default
    }
}

void CreateCheckBoxes(){

    GOLFree();   // free memory for the objects in the previous linked list and start new list

	CreatePage(CheckBoxStr); 	// CreatePage("Checkboxes");

    CbCreate(ID_CHECKBOX1,             	// ID
              100,110,265,145,         	// dimension
              CB_DRAW,                 	// will be dislayed after creation
              TextLeftStr, 				// "Text Left"
              altScheme);              	// alternative GOL scheme

    CbCreate(ID_CHECKBOX2,             	// ID
              100,150,265,185,         	// dimension
              CB_DRAW,      			// will be dislayed and checked after creation
              TextBottomStr, 			// "Text Bottom"
              altScheme);              	// alternative GOL scheme

    CbCreate(ID_CHECKBOX3,             	// ID
              100,190,250,225,         	// dimension
              CB_DRAW|CB_DISABLED,     	// will be dislayed and disabled after creation
              DisabledStr, 				// "Disabled"
              altScheme);              	// alternative GOL scheme

    pGenObj = (OBJ_HEADER*)BtnCreate(
    		  ID_BUTTON1, 				// button ID
              100,50,215,100,         	// dimension
              10,					   	// set radius
              BTN_DRAW,  			   	// draw a beveled button
              NULL,                    	// no bitmap
              HomeStr, 					// "HOME"
              altScheme);              	// use alternate scheme

}

WORD MsgCheckBoxes(WORD objMsg, OBJ_HEADER* pObj){

    switch(GetObjID(pObj)){

        case ID_CHECKBOX1:
        	if (objMsg == CB_MSG_CHECKED) {
				SetState(pGenObj,
						 BTN_TEXTLEFT|
						 BTN_DRAW);        			// set align left and redraw button
			} else {
				ClrState(pGenObj, BTN_TEXTLEFT);	// clear all text alignment
				SetState(pGenObj, BTN_DRAW);       	// set align left and redraw button
			}
            return 1; 								// process by default

        case ID_CHECKBOX2:
        	if (objMsg == CB_MSG_CHECKED) {
				SetState(pGenObj,
						 BTN_TEXTBOTTOM|
						 BTN_DRAW);        			// set align bottom and redraw button
			} else {
				ClrState(pGenObj, BTN_TEXTBOTTOM);	// clear all text alignment
				SetState(pGenObj, BTN_DRAW)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -