/********************************************************************* * * 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(); }
/********************************************************************* * * 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; }
/********************************************************************* * * _GetFileName * * Purpose: * Returns the file name of the XBF file to be used */ static void _GetFileName(char * pPath, unsigned MaxSize) { WM_HWIN hWin; /* Set default value on first call */ if (!strlen(pPath)) { strcpy(pPath, "Sample\\GUI\\FONT_ShowXBF\\ExtBinFont.xbf"); } /* Display small hint */ GUI_SetFont(&GUI_Font10_ASCII); GUI_DispStringHCenterAt("Please enter the file name of the XBF-file:", 160, 80); /* Create edit widget */ hWin = EDIT_Create(10, 120, 300, 20, 0, MaxSize, WM_CF_SHOW); EDIT_SetText(hWin, pPath); WM_SetFocus(hWin); /* Wait until GUI_KEY_ENTER has been pressed */ while (GUI_GetKey() != GUI_KEY_ENTER) { GUI_Delay(100); } /* Get filename from EDIT widget */ EDIT_GetText(hWin, pPath, MaxSize); /* Create edit widget */ WM_DeleteWindow(hWin); /* Clear screen */ GUI_ClearRect(0, 40, 319, 239); }
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; }
egx_wnd_t egx_edit_create_(int res_id,char *name,egx_uint32_t style,int x,int y,int width,int height,egx_wnd_t parent) { EDIT_Handle hEdit; if(parent){ hEdit = EDIT_CreateAsChild(x, y, width,height,GUIWND_TO_HWND(parent), res_id,WM_CF_SHOW,256); }else{ hEdit = EDIT_Create(x, y, width,height, res_id, 256, WM_CF_SHOW ); } EDIT_SetInsertMode(hEdit, 0); return HWND_TO_GUIWND(hEdit); }
/******************************************************************* * * _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); }