📄 mbutton.cpp
字号:
#include"\sunshine\include\mbutton.h"
#include"\sunshine\include\app.h"
#include"\sunshine\include\mapp.h"
#include"\sunshine\include\define.h"
#include<string.h>
MButton::MButton(int x,int y,int w,int h,char *name,char *idname,char *stat,int k)
: MObj(x,y,w,h,idname)
{
BS=0;
topic=new char[strlen(name)+1];
strcpy(topic,name);
status=new char[strlen(stat)+1];
strcpy(status,stat);
firstrun=1;
sm=1;
trans=k;
}
MButton::~MButton()
{
delete topic;
delete status;
}
void MButton::GetFocus()
{
char pat[8]={0x55,0xaa,0x55,0xaa,
0x55,0xaa,0x55,0xaa};
Mouse am;
int x1=x(),y1=y(),x2=x()+w()-1,y2=h()+y()-1;
am.MouseOff();
setcolor(BLACK);
rectangle(x1,y1,x2,y2);
rectangle(x1+1,y1+1,x2-1,y2-1);
setcolor(DARKGRAY);
line(x1+2,y1+2,x2-2,y1+2);
line(x1+2,y1+2,x1+2,y2-2);
setfillpattern(pat,WHITE);
bar(x1+3,y1+3,x2-2,y2-2);
Write((char far*)topic,x1+(x2-x1)/2-strlen(topic)*8/2-1,y1+(y2-y1)/2-9,BLACK);
am.MouseOn();
}
void MButton::UnFocus()
{
Mouse am;
int x1=x(),y1=y(),x2=x()+w()-1,y2=h()+y()-1;
am.MouseOff();
setcolor(BLACK);
rectangle(x1,y1,x2,y2);
setcolor(WHITE);
line(x1+1,y1+1,x2-2,y1+1);
line(x1+1,y1+2,x2-3,y1+2);
line(x1+1,y1+1,x1+1,y2-2);
line(x1+2,y1+1,x1+2,y2-3);
setcolor(DARKGRAY);
line(x1+2,y2-1,x2-1,y2-1);
line(x1+3,y2-2,x2-1,y2-2);
line(x2-1,y1+2,x2-1,y2-1);
line(x2-2,y1+3,x2-2,y2-1);
putpixel(x2-1,y1+1,LIGHTGRAY);
putpixel(x2-2,y1+2,LIGHTGRAY);
putpixel(x1+1,y2-1,LIGHTGRAY);
putpixel(x1+2,y2-2,LIGHTGRAY);
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(x1+3,y1+3,x2-3,y2-3);
Write((char far*)topic,x1+(x2-x1)/2-strlen(topic)*8/2,y1+(y2-y1)/2-8,WHITE);
Write((char far*)topic,x1+(x2-x1)/2-strlen(topic)*8/2-1,y1+(y2-y1)/2-9,BLACK);
am.MouseOn();
}
int MButton::Process()
{
Mouse am;
int value=1;
if(firstrun){firstrun=0;UnFocus();return 1;}
if(Mes==NOPRO) return 1;
if(Mes==DEL) return DEL;
if(am.x()>=x() && am.x()<=(x()+w()-1) && am.y()>=y()
&& am.y()<=(y()+h()-1))
{
if(sm&&trans) {MApp::Application->GetObj("STATUSBAR").TransMes(SENDTEXT,GetMes());
sm=0;
}
if(am.lp())
{
GetFocus();
BS=1;
am.Reset();
while(am.lp())
{
if((am.x()<x() || am.y()<y() || am.x()>(x()+w()-1)
|| am.y()>(y()+h()-1)) && BS) {UnFocus();BS=0;}
else
{
if(am.x()>=x() && am.x()<=(x()+w()-1) && am.y()>=y()
&& am.y()<=(y()+h()-1))
if(BS==0) {GetFocus();BS=1;}
}
am.Reset();
}
}
if(BS){UnFocus();value=F();BS=0;}
BS=0;
}
else
{
sm=1;
}
return value;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -