| Close | Back |
/*
* rig_dc.c
* Author Rajesh _ThE gReAt
*/
#define MSGCOLOR LIGHTRED
#define YES 0+1
#define NO 1+1
#define NOOFPBS 5
#define GOODBYEMSG "\n You were right! \n Rajesh is Really Really Great!"
#define TOP1 100
#define TOP2 100
#define LEFT1 50
#define LEFT2 250
#define PRJ
#include<stdio.h>
#include<dos.h>
#include<conio.h>
#include"pb.c"
void relint(void);
void captureint(void);
void hidecursor(void);
void showcursor(void);
int initmouse(void);
void initgraphics(void);
void saygoodbye(void);
void swap(PUSHBUTTON *,PUSHBUTTON *);
void main(void /* int argc,char **argv */);
void main(void /* int argc,char **argv */)
{
/* Data type defined in pb.c */
PUSHBUTTON yes,no;
int x=0,y=0,button=0,flag=0,flagn=0,msestat;
int color;
/* The question to ask */
char *msg = " Is Rajesh Great?";
/* used to issue interrupts*/
union REGS i,o;
int stat;
/* Capture interrupts */
captureint();
/* Call to a function which intialises graphics mode */
initgraphics();
/* Ask MS-Mouse driver to reset and send reset info */
i.x.ax = 0x00;
/* Issue Interrupt */
int86(0x33,&i,&o);
stat = o.x.ax;
if(stat == 0x00) /* An error ! No interrupt handler */
{
closegraph(); /* Return to text mode */
fprintf(stderr,"\nError : No Mouse Found!\nPress any key to halt:");
getch(); /* Wait for a keystroke */
exit(1); /* Exit with error code to OS */
}
/* Show mouse cursor */
i.x.ax = 0x01;
int86(0x33,&i,&o);
/* Store prev color */
color = getcolor();
/* Set our color */
setcolor(MSGCOLOR);
/* Set text style & set font */
settextstyle(GOTHIC_FONT,HORIZ_DIR,4);
/* Display our message */
outtext(msg);
/* Restore Prev color*/
setcolor(color);
yes.dim.top = TOP1;
yes.dim.left = LEFT1;
yes.dim.right = DEFAULT;
yes.dim.bottom = DEFAULT;
strcpy(yes.string,"Yes");
yes.col.color = DEFAULT;
yes.col.topbor = DEFAULT;
yes.col.botbor = DEFAULT;
yes.col.text = DEFAULT;
yes.font2use = DEFAULT;
/* Draw PushButton */
drawpb(yes);
no.dim.top = TOP2;
no.dim.left = LEFT2;
no.dim.right = DEFAULT;
no.dim.bottom = DEFAULT;
strcpy(no.string,"No!");
no.col.color = DEFAULT;
no.col.topbor = DEFAULT;
no.col.botbor = DEFAULT;
no.col.text = DEFAULT;
no.font2use = DEFAULT;
/* Draw PushButton */
drawpb(no);
while(1)
{
/* Get x,y co-ordinates and button-click data */
i.x.ax = 0x03;
int86(0x33,&i,&o);
button = o.x.bx;
x = o.x.cx;
y = o.x.dx;
if(getstatus(x,y) == YES) /* Mouse over "Yes" Pushbutton*/
{
if(!flag) /* Mouse over not affected */
{
int pbno;
yes.col.text = RED;
hidecursor();
/* Create "mouseover" */
pbno = drawpb(yes);
showcursor();
/* This PushButton is not needed */
unregisterpb(pbno);
/* Tell the rest of the program that mouse over is
affected */
flag = 1;
}
}
else if(flag == 1) /* Mouse not over "yes" button and mouseover exists */
{
int pbno;
yes.col.text = DEFAULT;
hidecursor();
/* Reset "normal" PushButton */
pbno = drawpb(yes);
showcursor();
unregisterpb(pbno);
flag = !flag;
}
if(getstatus(x,y) == NO) /* Mouse over "No!" Pushbutton*/
{
if(!flagn) /* Mouse over not affected */
{
int pbno;
no.col.text = RED;
hidecursor();
pbno = drawpb(no);
showcursor();
unregisterpb(pbno);
flagn = 1;
}
/* Swap "Yes" and "No!" Buttons */
swap(&yes,&no);
}
/*
else
{
if(flagn == 1)
{
int pbno;
no.col.text = DEFAULT;
hidecursor();
pbno = drawpb(no);
showcursor();
unregisterpb(pbno);
flagn = !flagn;
}
}
*/
if(button == 1) /* Left button clicked ! */
{
if(getstatus(x,y) == YES) /* Mouse over "yes" button */
{
int pbno;
hidecursor();
/* Create rollover plus pressed effect */
clicked(YES,RED);
showcursor();
/* Some delay */
delay(150);
hidecursor();
/* Reset original PushButton */
pbno = drawpb(yes);
showcursor();
unregisterpb(pbno);
/* Only way of Quitting ;) */
saygoodbye();
}
}
}
}
void swap(PUSHBUTTON *yes,PUSHBUTTON *no)
{
int temp;
extern int no_of_pb_in_db;
no_of_pb_in_db = 0;
/* Swap two tops */
temp = yes->dim.top;
yes->dim.top = no->dim.top;
no->dim.top = temp;
/* Swap two lefts */
temp = yes->dim.left;
yes->dim.left = no->dim.left;
no->dim.left = temp;
/* Not required but still ....*/
no->col.text = DEFAULT;
hidecursor();
/* Draw the buttons */
drawpb(*yes);
drawpb(*no);
showcursor();
}
/* Here we Quit */
void saygoodbye(void)
{
hidecursor();
cleardevice();
printf(GOODBYEMSG);
showcursor();
getch();
closegraph();
relint();
exit(0);
}
/* Initialise graphics mode */
void initgraphics(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
#ifdef PRJ
registerfarbgidriver(ATT_driver_far);
registerfarbgidriver(CGA_driver_far);
registerfarbgidriver(EGAVGA_driver_far);
registerfarbgidriver(Herc_driver_far);
registerfarbgidriver(IBM8514_driver_far);
registerfarbgidriver(PC3270_driver_far);
registerfarbgifont(gothic_font_far);
registerfarbgifont(small_font_far);
/*
registerfarbgifont(sansserif_font_far);
registerfarbgifont(triplex_font_far);
*/
/* initialize graphics mode */
initgraph(&gdriver, &gmode, NULL);
#else
/* initialize graphics mode */
initgraph(&gdriver, &gmode, "C:\\tc\\bgi");
#endif
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* return with error code */
}
}
int initmouse(void)
{
union REGS i,o;
int stat;
i.x.ax = 0x00;
int86(0x33,&i,&o);
stat = o.x.ax;
if(stat == 0x00)
return -1;
}
void showcursor(void)
{
union REGS i,o;
i.x.ax = 0x0001;
int86(0x33,&i,&o);
}
void hidecursor(void)
{
union REGS wrkregs;
wrkregs.x.ax = 0x0002;
int86(0x33,&wrkregs,&wrkregs);
}
void interrupt (*prev_23)();
void interrupt (*prev_1b)();
void interrupt our();
void captureint(void)
{
prev_23 = getvect(0x23);
prev_1b = getvect(0x1b);
setvect(0x23,our);
setvect(0x1b,our);
}
void relint(void)
{
setvect(0x1b,prev_1b);
setvect(0x23,prev_23);
}
void interrupt our()
{
;
}