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

📄 ppbutton.cpp

📁 基于ARM平台的控制系统,自己带有MINIGUI,可以直接在VC下运行界面演示程序
💻 CPP
字号:
#include "Glib.h"
#include "GUIpp.h"

#include "ppButton.h"

#if _USE_GUI == 1


void NANAButton::SetCaption(const char * pStrCaption)
{
	//DEBUG_Assert(strlen(pStrCaption)<CBUTTON_MAX_CAPTION_CHARS);
	
	w_strCaption = pStrCaption;
	
	SetUIDirty(1);
}
void NANAButton::SetIcon(int nIcon)
{
	w_nIcon = nIcon;

	SetUIDirty(1);
}
void NANAButton::SetPress(int bPress)
{
	w_bPressed = bPress;
	
	SetUIDirty(1);
}
void NANAButton::OnMouseDown(int x,int y)
{
	CaptureMouse();
	SetPress(1);
}
void NANAButton::OnMouseUp(int x,int y)
{
	ReleaseMouse();
	if(w_Rect.IsPointInside(x,y))
	{
		NotifyWindow(GetParentWnd(),UGNC_CLICK,0,0);
	}
	SetPress(0);
}
void NANAButton::OnPaint()
{
	NANARect 	rc;
    NANA_FONT	font;
    int 		nTextLenght;
	int			nStartX,nIconWidth,nIconHeight;
 
	font = &NANA_FONT12;
	GetWindowRect(&rc);
	if(w_strCaption)
	{
		nTextLenght=GetTextWidth(w_strCaption,font,-1);
	}
	else
	{
		nTextLenght = 0;
	}
	
	if( w_nIcon>=0 )
	{
		nIconWidth = GetIcon(w_nIcon)->width;
		nIconHeight = GetIcon(w_nIcon)->height;
		nStartX = rc.w_nX1+(rc.GetWidth() - nTextLenght - nIconWidth - 2 )/2;
	}
	else
	{
		nIconWidth = 0;
		nIconHeight = 0;
		nStartX = rc.w_nX1+(rc.GetWidth() - nTextLenght)/2;
	}
	if(w_bPressed){
		
		if(w_StyleEx & BUTTON_STYLE_NORMAL)
		{
			ButtonFrame(rc.w_nX1,rc.w_nY1,rc.w_nX2-rc.w_nX1,rc.w_nY2-rc.w_nY1,w_bPressed);
		}else
		if(w_StyleEx & BUTTON_STYLE_FLAT)
		{
			RectFill(rc.w_nX1,rc.w_nY1,rc.w_nX2,rc.w_nY2,COLOR_BORDER);
		}

		if( w_nIcon>=0 )
		{
			if(w_StyleEx & BUTTON_STYLE_NORMAL)
			{
				DrawICON(w_nIcon,
						nStartX + 1,
						rc.w_nY1 + (rc.GetHeight() - nIconHeight)/2 + 1,
						0);
				nStartX += nIconWidth + 2;
			}else
			if(w_StyleEx & BUTTON_STYLE_FLAT)
			{
				DrawICON(w_nIcon,
					nStartX ,
					rc.w_nY1 + (rc.GetHeight() - nIconHeight)/2,
					1);
				nStartX += nIconWidth + 2;
			}	
		}
		
		if(w_strCaption)
		{
			if(w_StyleEx & BUTTON_STYLE_NORMAL)
			{
				TextPrint(
						(w_strCaption),
						nStartX + 1,
						rc.w_nY1+ (rc.w_nY2-rc.w_nY1- font->GBFontSize )/2 + 1,
						font,0);
			}else
			if(w_StyleEx & BUTTON_STYLE_FLAT)
			{
				TextPrint(
					(w_strCaption),
					nStartX,
					rc.w_nY1+ (rc.w_nY2-rc.w_nY1- font->GBFontSize )/2,
					font,1);
			}
		}
	}
	else
	{
		if(w_StyleEx & BUTTON_STYLE_NORMAL)
		{
			ButtonFrame(rc.w_nX1,rc.w_nY1,rc.w_nX2-rc.w_nX1,rc.w_nY2-rc.w_nY1,w_bPressed);
		}
		
		if( w_nIcon>=0 )
		{
			DrawICON(w_nIcon,
				nStartX ,
				rc.w_nY1 + (rc.GetHeight() - nIconHeight)/2,
				0);
			nStartX += nIconWidth + 2;
		}
		
		if(w_strCaption)
		{
			TextPrint(
				(w_strCaption),
				nStartX,
				rc.w_nY1+ (rc.w_nY2-rc.w_nY1- font->GBFontSize )/2,
				font,0);
		}
	}
}


#endif

⌨️ 快捷键说明

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