imagebutton.cpp

来自「SimpleGraphicOperatingSystem 32位图形化操作系统 」· C++ 代码 · 共 81 行

CPP
81
字号
#include <osdef.h>//WM_**
#include <System.h>
#include <Api.h>	//Sgos api

namespace System{
	
	
	int Button::OnSize( int w, int h ){
		Width = w;
		Height = h;
		Label::OnSize(w,h);
	}
	Button::~Button(){
	} 
	
	Button::Button( BaseWindow* form, string text, int style ):
		Label( form, text, LABEL_NOBACKGROUND|LABEL_NOFRAME )
	{
		frameColor1=Bitmap::MakeColor(0,0,0);	        //激活时窗体边框颜色
		frameColor2=Bitmap::MakeColor(123,123,123);	//非激活时窗体边框颜色
		frameColor3=Bitmap::MakeColor(65,92,109);	//按下时窗体边框颜色
		backColor1=Bitmap::MakeColor(207,207,207);	//激活时窗体背景颜色
		backColor2=Bitmap::MakeColor(207,207,207);	//非激活时窗体背景颜色
		backColor3=Bitmap::MakeColor(207,211,214);	//按下时窗体背景颜色
		textColor1=Bitmap::MakeColor(0,0,0);        	//激活时文字颜色
		textColor2=Bitmap::MakeColor(0,0,0);       	//非激活时文字颜色
		textColor3=Bitmap::MakeColor(0,0,0);        	//按下时文字颜色
		
		strText =text;
		
		type = TypeButton;
		Width = strText.Length()*8+12;
		Height = ch+7;
		mid_space = 4;
		SetSize( Width, Height );
	}
	
	int Button::DrawButton(int type){
		switch( type ){
		case 0:
			Bitmap::RectFill( bitmap, 0, 0, bitmap->Width-1, bitmap->Height-1, backColor2 );
			Bitmap::Rectangle( bitmap, 0, 0, bitmap->Width-1, bitmap->Height-1, frameColor2 );
			break;
		case 1:
			Bitmap::RectFill( bitmap, 0, 0, bitmap->Width-1, bitmap->Height-1, backColor1 );
			Bitmap::Rectangle( bitmap, 0, 0, bitmap->Width-1, bitmap->Height-1, frameColor1 );
			break;
		case 2:
			Bitmap::RectFill( bitmap, 0, 0, bitmap->Width-1, bitmap->Height-1, backColor3 );
			Bitmap::Rectangle( bitmap, 0, 0, bitmap->Width-1, bitmap->Height-1, frameColor3 );
			break;
		}
		DrawLabel(0);
	}
	
	int Button::OnPaint(){
		DrawButton(0);
		Label::OnPaint();
	}
	
	int Button::OnMouseHover( int button ){
		if( button==1 )
			DrawButton(2);
		else
			DrawButton(1);
	}
	
	int Button::OnMouseLeave( int button ){
		DrawButton(0);
	}
	
	int Button::OnMouseDown( int button, Point* p ){
		if( button==1)
			DrawButton(2);
	}
	
	int Button::OnMouseUp( int button, Point* p ){
		DrawButton(1);
	}
}

⌨️ 快捷键说明

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