📄 eeb_softkeyboard.cpp
字号:
#include "eeb.h"
const char * g_strNumber[10]={
"0","1","2","3","4","5","6","7","8","9"
};
//20*20
const unsigned char close_up[]={
0xff,0xff,0xf0,0xfe,0x3,0xf0,0xf8,0x0,0xf0,0xe0,0x0,0x30,0xe0,0x0,0x30,0xc0,0x0,0x10,0xc0,0x0,0x10,0x83,0xc,0x0,0x81,0x98,0x0,0x80,0xf0,0x0,0x80,0x60,0x0,0x80,0xf0,0x0,0x81,0x98,0x0,0xc3,0xc,0x10,0xc0,0x0,0x10,0xe0,0x0,0x30,0xe0,0x0,0x30,0xf8,0x0,0xf0,0xfe,0x3,0xf0,0xff,0xff,0xf0,
};
//20*20
const unsigned char close_down[]={
0xff,0xff,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0,0xfc,0xf3,0xf0,0xfe,0x67,0xf0,0xff,0xf,0xf0,0xff,0x9f,0xf0,0xff,0xf,0xf0,0xfe,0x67,0xf0,0xfc,0xf3,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0,
};
void NANA_SoftKeyBoard::OnCreate ()
{
int x,y,i;
int y_pos,x_pos;
NANARect rc;
GetWindowRect(&rc);
w_bCloseButtonDown = 0;
rc.w_nY2 -= 10;
rc.w_nX1 += 10;
y_pos = rc.w_nY2 - NUMBER_BUTTON_HEIGHT;
x_pos = rc.w_nX1;
if(!w_bMaskDisplay)
{
w_buts[0].CreateWnd(this,x_pos,y_pos,
NUMBER_BUTTON_WIDTH,NUMBER_BUTTON_HEIGHT);
}else{
w_buts[0].CreateWnd(this,x_pos,y_pos,
NUMBER_BUTTON_WIDTH*2+NUMBER_BUTTON_SPACE,NUMBER_BUTTON_HEIGHT);
}
w_buts[0].SetCaption("0");
x_pos += NUMBER_BUTTON_WIDTH + NUMBER_BUTTON_SPACE;
if(!w_bMaskDisplay)
{
w_dot.CreateWnd(this,x_pos,y_pos,
NUMBER_BUTTON_WIDTH,NUMBER_BUTTON_HEIGHT);
w_dot.SetCaption(".");
}
x_pos += NUMBER_BUTTON_WIDTH + NUMBER_BUTTON_SPACE;
w_butClr.CreateWnd(this,x_pos,y_pos,
NUMBER_BUTTON_WIDTH,NUMBER_BUTTON_HEIGHT);
x_pos += NUMBER_BUTTON_WIDTH + NUMBER_BUTTON_SPACE;
if(!w_bMaskDisplay)
{
w_butOK.CreateWnd(this,x_pos,y_pos - NUMBER_BUTTON_HEIGHT - NUMBER_BUTTON_SPACE,
NUMBER_BUTTON_WIDTH,NUMBER_BUTTON_HEIGHT*2+NUMBER_BUTTON_SPACE);
}else{
w_butOK.CreateWnd(this,x_pos,y_pos - NUMBER_BUTTON_HEIGHT*3 - 3*NUMBER_BUTTON_SPACE,
NUMBER_BUTTON_WIDTH,NUMBER_BUTTON_HEIGHT*4+3*NUMBER_BUTTON_SPACE);
}
if(!w_bMaskDisplay)
{
w_adj_down.CreateWnd(this,x_pos,y_pos - NUMBER_BUTTON_HEIGHT*2-2*NUMBER_BUTTON_SPACE,
NUMBER_BUTTON_WIDTH,NUMBER_BUTTON_HEIGHT);
w_adj_down.SetIcon(ICON16_ADJDOWN);
w_adj_up.CreateWnd(this,x_pos,y_pos - NUMBER_BUTTON_HEIGHT*3 - 3*NUMBER_BUTTON_SPACE,
NUMBER_BUTTON_WIDTH,NUMBER_BUTTON_HEIGHT);
w_adj_up.SetIcon(ICON16_ADJUP);
}
i = 1;
for(y=0;y<3;y++)
{
x_pos = rc.w_nX1;
y_pos -= NUMBER_BUTTON_HEIGHT + NUMBER_BUTTON_SPACE;
for(x=0;x<3;x++)
{
w_buts[i].CreateWnd(this,x_pos,y_pos,
NUMBER_BUTTON_WIDTH,NUMBER_BUTTON_HEIGHT);
w_buts[i].SetCaption(g_strNumber[i]);
x_pos += NUMBER_BUTTON_WIDTH+NUMBER_BUTTON_SPACE;
i++;
}
}
if(!w_bMaskDisplay)
{
w_plus_minus.CreateWnd(this,rc.w_nX1,y_pos-NUMBER_BUTTON_HEIGHT - NUMBER_BUTTON_SPACE,
NUMBER_BUTTON_WIDTH/2+5,NUMBER_BUTTON_HEIGHT);
w_plus_minus.SetCaption("+/-");
}
CaptureMouse();
}
void NANA_SoftKeyBoard::OnPaint()
{
int i;
char digit[DIGIT_COUNT];
NANA_BITMAP bmp;
int width;
NANARect rc;
GetWindowRect(&rc);
w_butOK.SetCaption(GetStringResource(strSOKBOK));
w_butClr.SetCaption(GetStringResource(strSOKBClear));
//rc.w_nX2 -= 3;
//rc.w_nY2 -= 3;
Rect(rc.w_nX1, rc.w_nY1, rc.w_nX2, rc.w_nY2,1,0);
RectFill(rc.w_nX1, rc.w_nY1, rc.w_nX2, rc.w_nY1+30,1);
//DrawVerticalLine(rc.w_nX2,rc.w_nY1+3,rc.GetHeight(),3);
//DrawHorizontalLine(rc.w_nX1+3,rc.w_nY2,rc.GetWidth(),3);
if( w_Icon >= 0 )
{
DrawICON(w_Icon,rc.w_nX1+5,rc.w_nY1+5,1);
TextPrint(w_strCaption,rc.w_nX1+25,rc.w_nY1+5,&NANA_FONT16,1);
}else{
TextPrint(w_strCaption,rc.w_nX1+5,rc.w_nY1+5,&NANA_FONT16,1);
}
if(w_Fraction>0)
{
sprintf(digit,"%s%d.%d",w_bNegative?"-":"",w_Interger,w_Fraction);
}else{
if(w_Interger>0 || (!w_bMaskDisplay))
{
sprintf(digit,"%s%d",w_bNegative?"-":"",w_Interger);
}else{
//密码输入状态清空时(w_Interger==0 && w_Fraction==0)不显示
sprintf(digit,"");
}
}
if(w_bMaskDisplay)
{
for(i=0;i<(int)strlen(digit);i++)
{
digit[i] = 'x';
}
}
width = GetTextWidth(digit,&NANA_FONT32,-1);
if(w_UnitIcon >= 0)
{
ICON *picon = GetIcon(w_UnitIcon);
DrawICON(w_UnitIcon,rc.w_nX2 - 50 ,rc.w_nY1+35+(32-picon->height)/2,0);
TextPrint(digit,rc.w_nX2 - 52 - width,rc.w_nY1+35,&NANA_FONT32,0);
}else{
TextPrint(digit,rc.w_nX2 - 20 - width,rc.w_nY1+35,&NANA_FONT32,0);
}
bmp.biBitCount=1;
bmp.biHeight=20;
bmp.biWidth=20;
bmp.biReverseColor=0;
if(w_bCloseButtonDown)
bmp.pData = (unsigned char *)close_down;
else
bmp.pData = (unsigned char *)close_up;
GHAL_put_bmp(rc.w_nX2-25,rc.w_nY1+5,&bmp);
}
void NANA_SoftKeyBoard::OnMouseDown(int x,int y)
{
NANARect rc;
GetWindowRect(&rc);
if(x>rc.w_nX2-25 && y<rc.w_nY1+25 && x<rc.w_nX2 && y>rc.w_nY1)
{
w_bCloseButtonDown = 1;
SetUIDirty(1);
}
}
void NANA_SoftKeyBoard::OnMouseUp(int x,int y)
{
NANARect rc;
GetWindowRect(&rc);
if(x>rc.w_nX2-25 && y<rc.w_nY1+25 && x<rc.w_nX2 && y>rc.w_nY1)
{
w_bCloseButtonDown = 0;
//close this window
CloseWindow();
}
}
void NANA_SoftKeyBoard::Show(NANAFrameWnd * pNotifyWnd,const char * pstrCaption,int bPasswordInput,int nIcon,int nUnitIcon)
{
int width,height;
w_pNotifyWnd = pNotifyWnd;
width = 200;
height = 200;
DEBUG_Assert( strlen(pstrCaption) < MAX_CAPTION_SIZE );
strcpy(w_strCaption,pstrCaption);
w_Icon = nIcon;
w_UnitIcon = nUnitIcon;
w_bMaskDisplay = bPasswordInput;
w_bAutoClear = 1;
w_AdjStep = 1;
this->CreateWnd(NULL,(SCREEN_WIDTH-width)/2,30+(SCREEN_HEIGHT- 30 -height)/2,
width,height);
}
void NANA_SoftKeyBoard::OnNotify(NANAWnd *pSrcWnd,int nMessageCode,int nParam1,int nParam2)
{
int i;
if(pSrcWnd == &w_butOK)
{
NotifyWindow(w_pNotifyWnd,SOKB_INPUT,0,0);
CloseWindow();
}else
if(&w_dot == pSrcWnd)
{
AddDisplay('.');
SetUIDirty(1);
}else
if(&w_butClr == pSrcWnd)
{
ClearDisplay();
SetUIDirty(1);
}else
if(&w_plus_minus == pSrcWnd)
{
w_bNegative = !w_bNegative;
SetUIDirty(1);
}else
if(&w_adj_up == pSrcWnd)
{
SetDisplay_float(GetDisplay_float() + w_AdjStep);
SetUIDirty(1);
}else
if(&w_adj_down == pSrcWnd)
{
SetDisplay_float(GetDisplay_float() - w_AdjStep);
SetUIDirty(1);
}else
{
for(i=0;i<10;i++)
{
if((&w_buts[i]) == pSrcWnd)
{
//auto clear will work only once since softkeyboard show
if(w_bAutoClear)
{
ClearDisplay();
w_bAutoClear = 0;
}
AddDisplay(i+'0');
SetUIDirty(1);
break;
}
}
}
}
void NANA_SoftKeyBoard::OnClose ()
{
ReleaseMouse();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -