📄 ppbutton.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 + -