2) use algorithms for circle , and elipses ... and other primitives
4) then make use of these primitives to draw buttons , checkboxes etc ( use your imagination -- that's all
Some code for guidance , you may look into it , but never copy this . its pathetic
. Its using borlands bgi .It's not very well commented either
Code: Select all
#include<dos.h>
#include<graphics.h>
#define DRAW 2
#define PUSH 1
#define UNPUSH 0
struct mouse
{
int button,x,y,gd,gm;
int initmouse();
void showmouseptr();
void restrictmouseptr(int x1,int y1,int x2,int y2);
void getmousepos(int *button,int *x,int *y);
void hidemouseptr();
void Win(char *header,int sx,int sy,int ex,int ey,int opt);
void Button(char *text,int sx,int sy,int ex,int ey,int opt);
void winp(int sx,int sy,int ex,int ey,int state);
void checkcircle(int xx,int yy);
void checkc(int xx,int yy,int on);
void checkbox(int xx,int yy);
void check(int xx,int yy,int choice);
void pressb(int sx,int sy,int ex,int ey);
void g();
void lg();
int click(int x1,int y1,int x2,int y2);
};
int mouse::initmouse()
{
_AX=0;
geninterrupt(0x33);
return(_AX);
}
void mouse::showmouseptr()
{
_AX=1;
geninterrupt(0x33);
}
void mouse::hidemouseptr()
{
_AX=2;
geninterrupt(0x33);
}
void mouse::restrictmouseptr(int x1,int y1,int x2,int y2)
{
_AX=7;
_CX=x1;
_DX=x2;
geninterrupt(0x33);
_AX=8;
_CX=y1;
_DX=y2;
geninterrupt(0x33);
}
void mouse::getmousepos(int *button,int *x,int *y)
{
_AX=3;
geninterrupt(0x33);
*button=_BX;
*x=_CX;
*y=_DX;
}
void mouse::Win(char *header,int sx,int sy,int ex,int ey,int opt)
{
int COLOR=7;// Try Different colors
setfillstyle(1,COLOR);
bar(sx,sy,ex,ey);
setcolor(8);
line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
if(opt)
rectangle(sx+4,sy+4,ex-2,ey-2);
setcolor(0);
line(ex-1,sy+2,ex-1,ey);
line(sx+2,ey-1,ex,ey-1);
line(ex,sy,ex,ey);
line(sx,ey,ex,ey);
setcolor(15);
line(sx+2,sy+2,sx+2,ey-2);
line(sx+2,sy+2,ex-2,sy+2);
if(opt==1)
{
setfillstyle(1,1);
bar(sx+5,sy+5,ex-2,sy+23);
setcolor(COLOR);
rectangle(sx+8,sy+8,sx+20,sy+19);
line(sx+8,sy+9,sx+20,sy+9);
line(sx+8,sy+10,sx+20,sy+10);
putpixel(sx+18,sy+9,15);
setcolor(15);
settextstyle(0,0,0);
outtextxy(sx+25,sy+10,header);
setfillstyle(1,COLOR); //for x
bar(ex-18,sy+7,ex-7,sy+18);
setcolor(15);
line(ex-18,sy+7,ex-7,sy+7);
line(ex-18,sy+7,ex-18,sy+18);
setcolor(0);
line(ex-18,sy+18,ex-7,sy+18);
line(ex-7,sy+7,ex-7,sy+18);
setcolor(15);
outtextxy(ex-15,sy+9,"x");
setcolor(0);
outtextxy(ex-16,sy+8,"x");
setfillstyle(1,7);
}
}
void mouse:: Button(char *text,int sx,int sy,int ex,int ey,int opt)
{
int COLOR=7;
if(opt==PUSH)
{
setcolor(COLOR);
rectangle(sx+1,sy+1,ex-1,ey-1);
}else
if(opt==UNPUSH)
{
setcolor(0);
rectangle(sx+1,sy+1,ex-1,ey-1);
setcolor(15);
line(sx+1,sy+1,sx+1,ey-2);
line(sx+1,sy+1,ex-2,sy+1);
}else
if(opt==DRAW)
{
setfillstyle(1,COLOR);
bar(sx,sy,ex,ey);
setcolor(0);
rectangle(sx,sy,ex,ey);
rectangle(sx+1,sy+1,ex-1,ey-1);
setcolor(15);
line(sx+1,sy+1,sx+1,ey-2);
line(sx+1,sy+1,ex-2,sy+1);
settextstyle(2,0,4);
setcolor(0);
outtextxy(sx+((ex-sx)/2)-textwidth(text)/2,sy+((ey-sy)/2)-6,text);
}
}
void mouse::winp(int sx,int sy,int ex,int ey,int state)
{
hidemouseptr();
if(state==1)
{
setcolor(0);
line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
setcolor(15);
line(ex,sy,ex,ey);
line(ex,sy,ex,ey);
line(sx,ey,ex,ey);
line(sx,ey,ex,ey);
}
else
{
setcolor(15);
line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
line(sx,sy,sx,ey);
line(sx,sy,ex,sy);
setcolor(0);
line(ex,sy,ex,ey);
line(ex,sy,ex,ey);
line(sx,ey,ex,ey);
line(sx,ey,ex,ey);
}
showmouseptr();
}
void mouse::checkcircle(int xx,int yy)// draw
{
xx+=5;
yy+=5;
setfillstyle(1,15);
setcolor(15);
circle(xx,yy,5);
floodfill(xx+1,yy+1,15);
setcolor(7);
circle(xx,yy,4);
setfillstyle(1,0);
floodfill(xx-5,yy,7);
floodfill(xx,yy-5,7);
}
void mouse::checkc(int xx,int yy,int on)// action
{
xx+=5;
yy+=5;
if(on==1)
{
setfillstyle(1,0);
fillellipse(xx,yy,2,2);
}
else
{
setfillstyle(1,15);
floodfill(xx,yy,7);
}
}
void mouse::checkbox(int xx,int yy)
{
setfillstyle(1,15);
bar(xx,yy,xx+10,yy+10);
winp(xx-2,yy-2,xx+12,yy+12,1);
winp(xx-1,yy-1,xx+12,yy+12,1);
}
void mouse::check(int xx,int yy,int choice) //action
{
if(choice==1)
{
//checked
setcolor(0);
line(xx+2,yy+4,xx+5,yy+9-2);
line(xx+2,yy+5,xx+5,yy+9-1);
line(xx+2,yy+6,xx+5,yy+9);
line(xx+5,yy+8-2,xx+8,yy+1);
line(xx+5,yy+9-2,xx+8,yy+2);
line(xx+5,yy+10-2,xx+8,yy+3);
}
else
{
setfillstyle(1,15);
bar(xx,yy,xx+10,yy+10);
}
}
void mouse::pressb(int sx,int sy,int ex,int ey)
{
hidemouseptr();
Button("",sx,sy,ex,ey,PUSH);
showmouseptr();
while((button & 1)==1)
getmousepos(&button,&x,&y);
hidemouseptr();
Button("",sx,sy,ex,ey,UNPUSH);
showmouseptr();
}
void mouse::g()
{
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"");//make sure that egavga.bgi is in the current directory
}
void mouse::lg()
{
closegraph();
restorecrtmode();
}
int mouse::click(int x1,int y1,int x2,int y2)
{
getmousepos(&button,&x,&y);
if(x>x1&&x<x2&&y>y1&&y<y2&&((button & 1)==1) )return 1;
else
return 0;
}