Category : Tutorials + Patches
Archive   : ZIP-3-3.ZIP
Filename : MOUSE2.C

 
Output of file : MOUSE2.C contained in archive : ZIP-3-3.ZIP
/********************************/
/* Graphic Buttons Demo */
/* by */
/* Ron Balewski */
/* */
/* Demonstrates the seek_button */
/* button selection routine */
/* */
/********************************/

#include
#include
#include

/* Set up button parameters */
int numbuttons = 11;
int buttons[11][4] = { { 10, 10, 60, 20},
{ 40, 25, 90, 35},
{ 70, 40, 120, 50},
{100, 55, 150, 65},
{130, 70, 180, 80},
{160, 85, 210, 95},
{190, 100, 240, 110},
{220, 115, 270, 125},
{250, 130, 300, 140},
{260, 145, 319, 155},
{ 20, 170, 60, 190} };

main()
{
int counter, buttoncode, exitcode;
char output[10];
int graphdriver, graphmode;

/* Set up graphics driver & font */
registerbgidriver(CGA_driver);
registerbgifont(small_font);

/* Start up the graphics mode */
graphdriver = CGA;
graphmode = CGAC1;
initgraph(&graphdriver, &graphmode, "");

/* Draw the buttons */
setcolor(3);
setlinestyle(SOLID_LINE, 0, NORM_WIDTH);
for (counter=0; counter<11; counter++)
rectangle(buttons[counter][0], buttons[counter][1],
buttons[counter][2], buttons[counter][3]);


/* Label the buttons */
setcolor(2);
settextstyle(SMALL_FONT, HORIZ_DIR, 4);
for (counter=0; counter<10; counter++)
{
sprintf(output, "Button %d", counter+1);
outtextxy(buttons[counter][0]+3, buttons[counter][1], output);
}
outtextxy(buttons[10][0]+5, buttons[10][1]+5, "-EXIT-");

/* Set text & fill styles for messages */
settextstyle(SMALL_FONT, HORIZ_DIR, 7);
setfillstyle(SOLID_FILL, 0);

/* Set up & turn on rodent */
init_mouse();
show_cursor();

/* Wait for & process left-button clicks */
exitcode = 0;
while (exitcode == 0)
{
buttoncode = check_left();
if (buttoncode != -1) /* Do if left button clicked */
{
hide_cursor();
switch(buttoncode)
{
case 1:
{
show_message("Pressed button 1");
break;
}

case 2:
{
show_message("Pressed button 2");
break;
}

case 3:
{
show_message("Pressed button 3");
break;
}

case 4:
{
show_message("Pressed button 4");
break;
}

case 5:
{
show_message("Pressed button 5");
break;
}

case 6:
{
show_message("Pressed button 6");
break;
}

case 7:
{
show_message("Pressed button 7");
break;
}

case 8:
{
show_message("Pressed button 8");
break;
}

case 9:
{
show_message("Pressed button 9");
break;
}

case 10:
{
show_message("Pressed button 10");
break;
}
case 11:
{
show_message("Good-bye!!");
sleep(2);
exitcode = 1;
}

default:
{
show_message("No button!");
break;
}
}
show_cursor();
}
}

closegraph();
}


show_message(char *text)
/* Print a graphic message in upper right corner of screen */
{
bar(80, 0, 319, 24);
outtextxy(90, 0, text);
}


int check_left()
/* Determine if the left mouse button was clicked and, if so, */
/* whether or not it was clicked on an 0n-screen button */
/* Returns: -1 for no left click */
/* 0 for a click, but not on a valid button */
/* Button number when clicked on a valid button */
{
union REGS r;

/* Check on left button */
r.x.ax = 5;
r.x.bx = 0;
int86(0x33, &r, &r);

/* if no button, return -1 */
if (r.x.bx == 0) return(-1);

/* NOTE: In CGA mode, the mouse driver will return a horizontal */
/* value between 0 & 640, EVEN IF YOU'RE IN THE 320x200 4-COLOR */
/* MODE!!! To get around that problem, we'll divide the */
/*horizontal co-ordinate by two with a shift-right command. */
r.x.cx >>= 1;

/* Check if click was on a button & return */
return(seek_button(r.x.cx, r.x.dx));
}

int seek_button(int horiz, int vert)
/* This useful little routine will take two numbers (horizontal */
/* & vertical co-ordinates) and check if tyet're on a valid button.*/
/* If so, it'll return the button number. If not, it'll return */
/* zero. */
{
int count;

for (count=0; count {
if ( (horiz>buttons[count][0]) && (horiz && (vert>buttons[count][1]) && (vert return (count+1);
}
return (0);
}


init_mouse()
/* Initialize mouse */
{
union REGS r;

r.x.ax = 0;
int86(0x33, &r, &r);
}


show_cursor()
/* Turn on mouse cursor */
{
union REGS r;

r.x.ax = 1;
int86(0x33, &r, &r);
}

hide_cursor()
/* turn off mouse cursor */
{
union REGS r;

r.x.ax = 2;
int86(0x33,&r, &r);
}



  3 Responses to “Category : Tutorials + Patches
Archive   : ZIP-3-3.ZIP
Filename : MOUSE2.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/