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

📄 widget_edit.c

📁 从ucgui移植到windml的代码,cgui移植到windml的代码
💻 C
字号:
/*
*********************************************************************************************************
*                                                uC/GUI
*                        Universal graphic software for embedded applications
*
*                       (c) Copyright 2002, Micrium Inc., Weston, FL
*                       (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH
*
*              礐/GUI is protected by international copyright laws. Knowledge of the
*              source code may not be used to write a similar product. This file may
*              only be used in accordance with a license and should not be redistributed
*              in any way. We appreciate your understanding and fairness.
*
----------------------------------------------------------------------
File        : WIDGET_Edit.c
Purpose     : Example demonstrating the use of a EDIT widget
----------------------------------------------------------------------
*/

#include "gui.h"
#include "edit.h"
#include <ugl/ugl.h>
#include <ugl/uglinput.h>

/*******************************************************************
*
*       static code
*
********************************************************************
*/

extern UGL_INPUT_SERVICE_ID g_uglInputServiceId;

int a;
/*******************************************************************
*
*       _DemoEdit
*
  Edit a string until ESC or ENTER is pressed
*/
static void _DemoEdit(void) {
  EDIT_Handle hEdit, hEdit2;
  char aBuffer[28];
  char bBuffer[28];
  int Key;
  GUI_SetBkColor(GUI_BLUE);
  GUI_Clear();
  GUI_SetColor(GUI_BLUE);
  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), 0 );
  hEdit2 = EDIT_Create(50, 220, 220, 25, ' ', sizeof(bBuffer), 0 );
  /* Modify edit widget */
  EDIT_SetText(hEdit, "");
  EDIT_SetText(hEdit2, "");
  EDIT_SetFont(hEdit, &GUI_Font8x16);
  EDIT_SetFont(hEdit2, &GUI_Font8x16);
  EDIT_SetTextColor(hEdit, 0, GUI_RED);
  EDIT_SetTextColor(hEdit2, 0, GUI_GREEN);
  /* Set keyboard focus to edit widget */
  WM_SetFocus(hEdit);
  GUI_CURSOR_Show();
#if 0
  /* Handle keyboard until ESC or ENTER is pressed */
  do {
    WM_Exec();
    Key = GUI_GetKey();
    if (Key != 0)
    {
        int a = Key;
        a++;
    }
  } while ((Key != GUI_KEY_ENTER) && (Key != GUI_KEY_ESCAPE));
  /* Fetch result from edit widget */
  if (Key == GUI_ID_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_ID_ENTER) {
    GUI_Delay(250);
    GUI_DispStringHCenterAt("The string you have edit is:", 160, 90);
    GUI_DispStringHCenterAt(aBuffer, 160, 110);
    GUI_Delay(3000);
    GUI_ClearRect(0, 50, 319, 239);
  }
  GUI_Delay(500);
#endif
}

/*******************************************************************
*
*       MainTask
*
*       Demonstrates the use of a EDIT widget
*
********************************************************************
*/

int kbd_map(int key)
{
    return key;
}

void uglThread()
{
    UGL_MSG msg;
    int key;
    GUI_PID_STATE state;
    unsigned int timer = 0;
    int status;
    
    while(1)
    {
        timer = GUI_GetTime();
        status = uglInputMsgGet (g_uglInputServiceId, &msg, 200);
        if (status == UGL_STATUS_OK)
        {
            if (msg.type == MSG_KEYBOARD)
            {
                if (msg.data.keyboard.modifiers & UGL_KBD_KEYDOWN) 
                {
                    key = msg.data.keyboard.key;
                    GUI_StoreKeyMsg(key, 1);
                    WM_Exec();
                    timer = GUI_GetTime();
                }
            }
            else if (msg.type == MSG_POINTER)
            {
                state.x = msg.data.pointer.position.x;
                state.y = msg.data.pointer.position.y;
                state.Pressed = msg.data.pointer.buttonState;
                GUI_PID_StoreState(&state);
                WM_Exec();
                timer = GUI_GetTime();
            }
        }
        if (GUI_GetTime() - timer >= 5)
        {
            WM_Exec();
        }
     }
}

void MainTask(void) {
  GUI_Init();
  _DemoEdit();
    taskSpawn("uglThread", 70, 0, 1024, (FUNCPTR)uglThread, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}

⌨️ 快捷键说明

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