void _TestCalibration(void) { int IdleCnt=0; BUTTON_Handle hButton; GUI_SetBkColor(GUI_RED); GUI_SetColor(GUI_WHITE); GUI_Clear(); hButton = BUTTON_Create( 225, 15, 80, 40, 1, BUTTON_CF_SHOW ); BUTTON_SetText (hButton, "ABORT"); BUTTON_SetFont (hButton, &GUI_FontComic18B_ASCII); while ((IdleCnt<50) && (GUI_GetKey()==0)) { static GUI_PID_STATE StateLast; GUI_PID_STATE State; GUI_TOUCH_GetState(&State); if ((StateLast.Pressed != State.Pressed) && (State.Pressed == 0)) { GUI_Clear(); } if ((StateLast.x != State.x) || ((StateLast.y != State.y))) { if (State.Pressed) { GUI_FillCircle(State.x, State.y, 5); } StateLast = State; } if (State.Pressed) { IdleCnt =0; } else { IdleCnt++; } GUI_Delay (100); } EDIT_Delete(hButton); }
/********************************************************************* * * GUI_EditString */ void GUI_EditString(char * pString, int Len, int xsize) { int Key, x, y, ysize, Id; EDIT_Handle hEdit; EDIT_Obj* pObj; const GUI_FONT GUI_UNI_PTR * pOldFont; WM_LOCK(); pOldFont = GUI_SetFont(EDIT_GetDefaultFont()); x = GUI_GetDispPosX(); y = GUI_GetDispPosY(); if (xsize == 0) { xsize = GUI_GetCharDistX('X') * Len + 6; } ysize = GUI_GetFontSizeY(); Id = 0x1234; hEdit = EDIT_Create(x, y, xsize, ysize, Id, Len, 0); EDIT_SetText(hEdit, pString); pObj = EDIT_H2P(hEdit); WM_SetFocus(hEdit); do { Key = GUI_WaitKey(); } while ((Key != GUI_KEY_ESCAPE) && (Key != GUI_KEY_ENTER) && (Key != 0)); if (Key == GUI_KEY_ENTER) { EDIT_GetText(hEdit, pString, pObj->MaxLen); } GUI_SetFont(pOldFont); EDIT_Delete(hEdit); WM_UNLOCK(); }
EDIT_Handle EDIT_CreateAsChild (int x0, int y0, int xsize, int ysize, WM_HWIN hParent, int Id, int Flags, int MaxLen) { EDIT_Handle hObj; if (MaxLen == 0) { MaxLen = 8; } /* Alloc memory for obj */ WM_LOCK(); hObj = WM_CreateWindowAsChild(x0, y0, xsize, ysize, hParent, WM_CF_SHOW | Flags, EDIT__Callback, sizeof(EDIT_Obj)-sizeof(WM_Obj)); if (hObj) { EDIT_Obj* pObj = (EDIT_Obj*)WM_HMEM2Ptr(hObj); /* init widget specific variables */ WIDGET__Init(&pObj->Widget, WIDGET_STATE_FOCUSSABLE | WIDGET_STATE_ENABLED); pObj->Widget.Id = Id; /* init member variables */ INIT_ID(pObj); pObj->pFont = _pDefaultFont; pObj->aBkColor[0] = EDIT_BKCOLOR0_DEFAULT; pObj->aBkColor[1] = EDIT_BKCOLOR1_DEFAULT; pObj->aTextColor[0] = EDIT_TEXTCOLOR0_DEFAULT; pObj->aTextColor[1] = EDIT_TEXTCOLOR1_DEFAULT; pObj->Align = _DefaultAlign; pObj->Border = _DefaultBorder; pObj->XSizeCursor = 1; pObj->MaxLen = MaxLen; if ((pObj->hpText = WM_ALLOC(MaxLen+1)) ==0) { GUI_DEBUG_ERROROUT("EDIT_Create failed to alloc buffer"); EDIT_Delete(hObj); hObj =0; } } WM_UNLOCK(); return hObj; }
/********************************************************************* * * GUI_EditHex */ U32 GUI_EditHex(U32 Value, U32 Min, U32 Max, int Len, int xsize) { U32 Ret = Value; int Key, x, y, ysize, Id; EDIT_Handle hEdit; EDIT_Obj* pObj; const GUI_FONT GUI_UNI_PTR * pOldFont = GUI_SetFont(EDIT_GetDefaultFont()); x = GUI_GetDispPosX(); y = GUI_GetDispPosY(); if (xsize == 0) xsize = GUI_GetCharDistX('X') * Len + 6; ysize = GUI_GetFontSizeY(); Id = 0x1234; hEdit = EDIT_Create(x, y, xsize, ysize, Id, Len, 0); pObj = EDIT_H2P(hEdit); EDIT_SetHexMode(hEdit, Value, Min, Max); WM_SetFocus(hEdit); do { Key = GUI_WaitKey(); } while ((Key != GUI_KEY_ESCAPE) && (Key != GUI_KEY_ENTER) && (Key != 0)); GUI_SetFont(pOldFont); if (Key == GUI_KEY_ENTER) Ret = pObj->CurrentValue; EDIT_Delete(hEdit); return Ret; }
/********************************************************************* * * EDIT_CreateEx */ EDIT_Handle EDIT_CreateEx(int x0, int y0, int xsize, int ysize, WM_HWIN hParent, int WinFlags, int ExFlags, int Id, int MaxLen) { EDIT_Handle hObj; GUI_USE_PARA(ExFlags); WM_LOCK(); /* Alloc memory for obj */ WinFlags |= WM_CF_LATE_CLIP; /* Always use late clipping since widget is optimized for it. */ hObj = WM_CreateWindowAsChild(x0, y0, xsize, ysize, hParent, WM_CF_SHOW | WinFlags, EDIT_Callback, sizeof(EDIT_Obj) - sizeof(WM_Obj)); if (hObj) { EDIT_Obj* pObj; pObj = (EDIT_Obj *)GUI_ALLOC_h2p(hObj); /* Don't use use WIDGET_H2P because WIDGET_INIT_ID() has not be called at this point */ /* init widget specific variables */ WIDGET__Init(&pObj->Widget, Id, WIDGET_STATE_FOCUSSABLE); /* init member variables */ EDIT_INIT_ID(pObj); pObj->Props = EDIT__DefaultProps; pObj->XSizeCursor = 1; pObj->MaxLen = (MaxLen == 0) ? 8 : MaxLen; pObj->BufferSize = 0; pObj->hpText = 0; if (_IncrementBuffer(pObj, pObj->MaxLen + 1) == 0) { GUI_DEBUG_ERROROUT("EDIT_Create failed to alloc buffer"); EDIT_Delete(hObj); hObj = 0; } } WM_UNLOCK(); return hObj; }
int _ExecKeyboard(void) { int i; int Key; BUTTON_Handle ahButton[52]; BUTTON_Handle hButtonESC; EDIT_Handle hEdit; GUI_RECT rText = {000,0, LCD_XSIZE, 20}; GUI_SetBkColor(GUI_BLUE); GUI_Clear(); GUI_DrawBitmap(&bmMicriumLogo, 0, 0); GUI_SetFont(&GUI_Font16B_1); GUI_SetColor(GUI_WHITE); GUI_DispStringInRect("µC/GUI", &rText, GUI_TA_RIGHT | GUI_TA_VCENTER); rText.y0 +=20; rText.y1 +=20; GUI_DispStringInRect("Touch screen demo", &rText, GUI_TA_RIGHT | GUI_TA_VCENTER); /* Create Keyboard Buttons */ for (i=0; i< 51; i++) { int Pos = (i < 47) ? i : i+4; int x0 = 5 + 28*(Pos%11); int y0 = 100 + 28*(Pos/11); char c = _acText[i]; int Id = c ? c : 1; char ac[2] = {0}; char *s= ac; ac[0] = c; ahButton[i] = BUTTON_Create( x0, y0, 25, 25, Id,BUTTON_CF_SHOW ); BUTTON_SetText (ahButton[i], s); #if GUI_SUPPORT_MEMDEV BUTTON_EnableMemdev(ahButton[i]); #endif } ahButton[i] = BUTTON_Create( 89, 212, 109, 25, ' ',BUTTON_CF_SHOW ); hButtonESC = BUTTON_Create( 230, 40, 80, 25, GUI_ID_CANCEL,BUTTON_CF_SHOW ); BUTTON_SetText (hButtonESC, "ESC"); hEdit = EDIT_Create( 5, 70, 310, 25, ' ', 80, 0 ); EDIT_SetFont(hEdit, &GUI_Font8x16); BUTTON_SetBkColor(ahButton[49], 0, GUI_RED); BUTTON_SetBkColor(ahButton[50], 0, GUI_BLUE); /* Handle Keyboard until ESC or ENTER is pressed */ do { Key = GUIDEMO_WaitKey(); switch (Key) { case 0: case GUI_ID_CANCEL: break; default: EDIT_AddKey(hEdit, Key); } } while ((Key != 'N') && (Key!=GUI_ID_CANCEL) && (Key!=0)); /* Cleanup */ for (i=0; i< countof(ahButton); i++) { BUTTON_Delete(ahButton[i]); } BUTTON_Delete(hButtonESC); EDIT_Delete(hEdit); return Key; }
int _ExecKeyboard(void) { int y0 = 75; int XSize = LCD_GetXSize(); int YSize = LCD_GetYSize(); int XStep = XSize / 4; int YStep = (YSize - y0) / 4; int i; int Key; BUTTON_Handle ahButton[16]; BUTTON_Handle hButtonESC; EDIT_Handle hEdit; GUI_RECT rText = {0}; rText.x1 = LCD_GetXSize() - 3; rText.y1 = 20; GUI_SetBkColor(GUI_BLUE); GUI_Clear(); GUI_SetFont(&GUI_FontComic18B_ASCII); GUI_SetColor(GUI_WHITE); GUI_DispStringInRect("µC/GUI", &rText, GUI_TA_RIGHT | GUI_TA_VCENTER); rText.y0 +=20; rText.y1 +=20; GUI_DispStringInRect("Touch screen demo", &rText, GUI_TA_RIGHT | GUI_TA_VCENTER); /* Create Keyboard Buttons */ for (i=0; _acText[i]; i++) { int XPos = (i%4) * XStep + 3; int YPos = (i/4) * YStep + 3 + y0; char c = _acText[i]; int Id = c ? c : 1; char ac[2] = {0}; char *s= ac; ac[0] = c; ahButton[i] = BUTTON_Create( XPos, YPos, XStep - 5, YStep - 5, Id, BUTTON_CF_SHOW ); BUTTON_SetText(ahButton[i], s); BUTTON_EnableMemdev(ahButton[i]); } hButtonESC = BUTTON_Create( 3, 3, 80, 25, GUI_ID_CANCEL, BUTTON_CF_SHOW ); BUTTON_SetText(hButtonESC, "ESC"); hEdit = EDIT_Create( 5, y0 - 30, XSize - 10, 25, ' ', 80, 0 ); EDIT_SetFont(hEdit, &GUI_Font8x16); /* Handle Keyboard until ESC or ENTER is pressed */ do { Key = GUIDEMO_WaitKey(); switch (Key) { case 0: case GUI_ID_CANCEL: break; default: EDIT_AddKey(hEdit, Key); } } while ((Key != 'N') && (Key!=GUI_ID_CANCEL) && (Key!=0)); /* Cleanup */ for (i=0; i< countof(ahButton); i++) { BUTTON_Delete(ahButton[i]); } BUTTON_Delete(hButtonESC); EDIT_Delete(hEdit); return Key; }
/******************************************************************* * * _DemoEdit * Edit a string until ESC or ENTER is pressed */ static void _DemoEdit(void) { EDIT_Handle hEdit; char aBuffer[28]; int Key; GUI_SetBkColor(GUI_BLACK); GUI_Clear(); GUI_SetColor(GUI_WHITE); GUI_SetFont(&GUI_Font24_ASCII); GUI_DispStringHCenterAt("WIDGET_Edit - Sample", 160, 5); GUI_SetFont(&GUI_Font8x16); GUI_DispStringHCenterAt("Use keyboard to modify string...", 160, 90); /* Create edit widget */ hEdit = EDIT_Create( 50, 110, 220, 25, ' ', sizeof(aBuffer), WM_CF_SHOW); /* Modify edit widget */ EDIT_SetText(hEdit, "Press <ENTER> when done..."); EDIT_SetFont(hEdit, &GUI_Font8x16); EDIT_SetTextColor(hEdit, 0, GUI_RED); /* Set keyboard focus to edit widget */ WM_SetFocus(hEdit); /* Handle keyboard until ESC or ENTER is pressed */ do { WM_Exec(); Key = GUI_GetKey(); } while ((Key != GUI_KEY_ENTER) && (Key != GUI_KEY_ESCAPE)); /* Fetch result from edit widget */ if (Key == GUI_KEY_ENTER) { EDIT_GetText(hEdit, aBuffer, sizeof(aBuffer)); } /* Delete the edit widget */ EDIT_Delete(hEdit); GUI_ClearRect(0, 50, 319, 239); /* Display the changed string */ if (Key == GUI_KEY_ENTER) { GUI_Delay(250); GUI_DispStringHCenterAt("The string you have modified is:", 160, 90); GUI_DispStringHCenterAt(aBuffer, 160, 110); GUI_Delay(3000); GUI_ClearRect(0, 50, 319, 239); } GUI_Delay(500); }