📄 inputline.c
字号:
#include <membox.h>
#include <stdio.h>
#include <math.h>
#include "GUI.h"
#include "Globalvars.h"
#include "pwin.h"
#include "guidebug.h"
void SendToHost(char * str, INT16U t);
#define INPUT_LINE_DEFAULT_FONT F9x15_pwf
extern unsigned char xhuge _HeapGUI[GUI_HEAP_SIZE];
void FormatDataValue (Pw_Window* win) {
struct TInputLineData * data;
data = (struct TInputLineData *) Pw_WindowGetClientData(win);
sprintf(data->Text, data->Format, data->Digit, data->Dec, *(data->Value));
}
void cbPaintInpLine (Pw_GC * gc) {
Pw_Window* win;
Pw_Coord w, h, x, y, wt;
struct TInputLineData * data;
win = Pw_GCGetWindow(gc);
Pw_WindowGetSize(win, &w, &h);
Pw_GCSetFont(gc, INPUT_LINE_DEFAULT_FONT);
Pw_DrawFrameRect(gc, 0, 0, w, h, 1, NULL);
data = (struct TInputLineData *) Pw_WindowGetClientData(win);
wt = Pw_FontGetStringWidth(gc->font, data->Text);
x = (w - wt)/2;
y = Pw_GCGetFontHeight(gc)+(h - Pw_GCGetFontHeight(gc))/2 - Pw_FontGetDescent(gc->font)+1;
if (Pw_WindowIsInFocus(win)) {
Pw_GCSetColor(gc, pw_white_pixel);
Pw_FillRect(gc, 0, 0, w, h);
Pw_GCSetColor(gc, pw_black_pixel);
}
else {
Pw_GCSetColor(gc, pw_white_pixel);
}
Pw_DrawString(gc, x, y, (Pw_Char *) data->Text);
}
int cbInputLine (Pw_Event * ev) {
Pw_Window * win;
int key;
int CtrlType;
struct TInputLineData * data;
win = Pw_EventGetWindow(ev);
CtrlType = Pw_WindowGetClientDataId(win);
data = (struct TInputLineData *) Pw_WindowGetClientData(win);
switch (Pw_EventGetType(ev)) {
case Pw_DestroyEventType :
// GUI_Log1("destroy INPUTLINE", Pw_EventGetWindow(ev));
_free_boxh (_HeapGUI, Pw_EventGetWindow(ev));
return TRUE;
case Pw_KeyPressEventType:
key = ev->key.keycode;
switch (key) {
case LEFT_KEY :
if (CtrlType == INPUTTEXT_ID) {
if (*(data->Value) > (data->MinValue)) {
*(data->Value) -= data->Inc;
FormatDataValue(win);
Pw_WindowRepaint(win);
}
}
else
if (CtrlType == ONOFFTEXT_ID) {
*(data->Value) = 0;
data->Text[0] = 'O';
data->Text[1] = 'F';
data->Text[2] = 'F';
data->Text[3] = 0;
Pw_WindowRepaint(win);
}
return TRUE;
case RIGHT_KEY :
if (CtrlType == INPUTTEXT_ID) {
if (*(data->Value) < (data->MaxValue)) {
*(data->Value) += data->Inc;
FormatDataValue(win);
Pw_WindowRepaint(win);
}
}
else
if (CtrlType == ONOFFTEXT_ID) {
*(data->Value) = 1;
data->Text[0] = 'O';
data->Text[1] = 'N';
data->Text[2] = 0;
Pw_WindowRepaint(win);
}
return TRUE;
}
}
return FALSE;
}
Pw_Window * CreateInputLine(const CONTROL_CREATE_INFO *info_struct ,
Pw_Window * Parent, Pw_EventCb cb) {
Pw_Window * InpLine;
struct TInputLineData * data;
InpLine = _calloc_boxh (_HeapGUI);
cb = cb;
Pw_WindowCreate(Parent, info_struct->x0, info_struct->y0,
info_struct->xSize, info_struct->ySize, InpLine);
data = info_struct->Data;
if(data->Format == NULL) data->Format = "%*.*f\0";
Pw_WindowSetClientDataId(InpLine, info_struct->ID);
Pw_WindowSetClientData(InpLine, data);
Pw_WindowSetRepaintCallback(InpLine, cbPaintInpLine);
Pw_WindowSetEventCallback(InpLine, cbInputLine);
Pw_WindowSetFocusAccept(InpLine, info_struct->FocusAccept);
if (info_struct->ID == INPUTTEXT_ID)
FormatDataValue(InpLine);
Pw_WindowMap(InpLine);
return InpLine;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -