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

📄 eeb_softkeyboard.h

📁 基于ARM平台的控制系统,自己带有MINIGUI,可以直接在VC下运行界面演示程序
💻 H
字号:
#ifndef _EEB_SOFTKEY_H_
#define _EEB_SOFTKEY_H_


#define NUMBER_BUTTON_WIDTH		42
#define NUMBER_BUTTON_HEIGHT	28
#define NUMBER_BUTTON_SPACE		3		

#define SOKB_INPUT				0x100A

#define DIGIT_COUNT				10

#define MAX_CAPTION_SIZE		50



class NANA_SoftKeyBoard:public NANAFrameWnd
{
public:
	NANAFrameWnd *	w_pNotifyWnd;
	NANAButton		w_buts[10];
	NANAButton		w_dot;
	NANAButton		w_butOK;		//ok and exit
	NANAButton		w_butClr;		//clear input
	NANAButton		w_adj_up;		//adjust up
	NANAButton		w_adj_down;		//adjust down
	NANAButton		w_plus_minus;	//
	
	char			w_strCaption[MAX_CAPTION_SIZE];	//caption 

	int				w_bCloseButtonDown;
	int				w_Icon;
	
	int				w_Interger;
	int				w_Fraction;
	int				w_InputIntPart;
	int				w_bNegative;
	float			w_AdjStep;

	int				w_UnitIcon;
	int				w_bMaskDisplay;			//mask with start * for password input

	int				w_bAutoClear;			//auto clear old data when press number button
	float GetDisplay_float()
	{
		float fret;
		fret = (float)w_Fraction;
		while( ((int)(fret)) > 0 )
		{
			fret = fret/(float)(9.999999999);
		}
		fret += w_Interger;
		if(w_bNegative) 
			fret = -fret;
		return fret;
	}
	void SetDisplay_float(float fValue)
	{
		ClearDisplay();
		w_Interger = (int)fValue;
		w_Fraction = (int)(fValue * 100) - (w_Interger*100);
	}
	void AddDisplay(char c)
	{
		if(w_InputIntPart)
		{
			if(c=='.')
			{
				w_InputIntPart = 0;
			}
			if(c>='0' && c<='9')
			{
				if(w_Interger<99999)
				{
					w_Interger = w_Interger*10 + (c-'0');
				}
			}
		}else{
			if(c>='0' && c<='9')
			{
				if( w_Fraction*10 + (c-'0') < 100)
				{
					w_Fraction = w_Fraction*10 + (c-'0');
				}
			}
		}
	}
	void ClearDisplay()
	{
		w_Interger = 0;
		w_Fraction = 0;
		w_InputIntPart = 1;
		w_bNegative = 0;
	}
	virtual void OnCreate ();
	virtual void OnClose ();
	virtual void OnPaint();
	virtual void OnMouseDown(int x,int y);
	virtual void OnMouseUp(int x,int y);
	void Show(NANAFrameWnd * pNotifyWnd,const char * pstrCaption,int bPasswordInput,int nIcon=-1,int nUnitIcon=-1);
	virtual void OnNotify(NANAWnd *pSrcWnd,int nMessageCode,int nParam1,int nParam2);
};

extern NANA_SoftKeyBoard *pSOKB;		//全局软键盘
extern NANAMessageBox	 *pMSGBOX;		//全局提示框

class NANA_NumberEdit:public NANAFrameWnd
{
public:
	MLString		w_Name;
	MLString		w_Label;

	int				w_Icon;
	float			w_Value;
	float			w_minValue;
	float			w_maxValue;

	float			w_NewValue;	//value modified by SoftKeyBoard
	int				w_bPressed;
	int				w_bLocked;	//un-editable
	NANA_FONT		w_Font;
	NANA_NumberEdit()
	{
		w_bPressed = 0;
		w_minValue = (float)-99999999.0;
		w_maxValue = (float)99999999.0;
		
		w_bLocked = 0;
		w_Font = &NANA_FONT12;
		w_Icon = -1;
	}
	void SetIcon(int nIcon)
	{
		w_Icon = nIcon;
	}
	void SetLock(int bLock)
	{
		w_bLocked = bLock;
	}
	void SetFont(NANA_FONT font)
	{
		w_Font = font;
	}
	void SetValueRange(float fmin,float fmax)
	{
		w_minValue = fmin;
		w_maxValue = fmax;
	}
	void SetValue(float fValue)
	{
		w_Value = fValue;
		SetUIDirty(1);
	}
	float GetValue(void)
	{
		return w_Value;
	}
	virtual void OnPaint()
	{
		char		strValue[10];
		int			label_width;
		int			value_width;
		int			icon_width;
		int			x_pos,y_pos;
		int			bNeg;
		NANARect	rc;
		GetWindowRect(&rc);

		bNeg = 0;
		if(w_bPressed && !w_bLocked)
			bNeg = 1;

		RectFill(rc.w_nX1,rc.w_nY1,rc.w_nX2,rc.w_nY2,bNeg);
		

		if( (int)(w_Value*100) == ((int)w_Value)*100 )
		{
			sprintf(strValue,"%d",(int)w_Value);
		}else
		{
			sprintf(strValue,"%.2f",w_Value);
		}
		value_width = GetTextWidth(strValue,w_Font,-1); 
		label_width = GetTextWidth(w_Label.Get(),w_Font,-1);
		icon_width = 20;
		
		x_pos = rc.w_nX1 + 3;
		y_pos = rc.w_nY1 + (rc.GetHeight() - w_Font->GBFontSize)/2;
		TextPrint(w_Label.Get(),x_pos,y_pos,w_Font,bNeg);

		x_pos += label_width;
		if(!w_bPressed && !w_bLocked)
		{
			DrawHorizontalLine(x_pos,rc.w_nY2-3,(rc.GetWidth() - icon_width - label_width),1);
		}
		//x_pos += (rc.GetWidth() - icon_width - label_width - value_width)/2;
		
		x_pos = rc.w_nX2 - icon_width - value_width;//(rc.GetWidth() - icon_width - label_width - value_width)/2;
		TextPrint(strValue,x_pos,y_pos,w_Font,bNeg);
		
		if(w_Icon >= 0)
		{
			ICON * picon = GetIcon(w_Icon);
			y_pos = rc.w_nY1 + (rc.GetHeight() - picon->height)/2;
			DrawICON(w_Icon,rc.w_nX2 - icon_width,y_pos,bNeg);
		}

		if(w_bPressed && w_bLocked)
		{
			RoundRectangle_little(rc.w_nX1,rc.w_nY1,rc.w_nX2,rc.w_nY2);
		}
	}
	virtual void OnMouseDown(int x,int y)
	{
		w_bPressed = 1;
		SetUIDirty(1);
	}
	virtual void OnMouseUp(int x,int y)
	{
		w_bPressed = 0;
		SetUIDirty(1);
		//popup soft key board
		if(!w_bLocked)
		{
			pSOKB->Show(this,w_Name.Get(),0,-1,w_Icon);
			pSOKB->SetDisplay_float(w_Value);
		}
	}
	virtual void OnNotify(NANAWnd *pSrcWnd,int nMessageCode,int nParam1,int nParam2)
	{
		char strInfo[200];
		if(pSrcWnd == pSOKB)
		{
			NANAWnd *pParentWnd = GetParentWnd();
			w_NewValue = pSOKB->GetDisplay_float();
			if(w_maxValue >= w_NewValue && w_NewValue>= w_minValue)
			{
				SetValue(w_NewValue);
				NotifyWindow(pParentWnd,0,0,0);
			}else{
				
				sprintf(strInfo,GetStringResource(strInValidInputWarnning),w_minValue,w_maxValue);
				pMSGBOX->Show(this, GetStringResource(strInValidInputCap),strInfo,UGMB_OK,ICON32_WARNING);
			}
		}
	}
};



#endif

⌨️ 快捷键说明

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