Category : C++ Source Code
Archive   : MOUSPP30.ZIP
Filename : MICEDEMO.CPP

 
Output of file : MICEDEMO.CPP contained in archive : MOUSPP30.ZIP
/* -------------------------------------------------------------------- */
/* Mouse++ Version 3.0 micedemo.cpp Revised 02/21/92 */
/* */
/* Demonstration of a general mouse class for Turbo C++/Borland C++. */
/* Copyright 1991, 1992 by Carl W. Moreland */
/* This source code may be freely distributed as long as the copyright */
/* notice remains intact. */
/* -------------------------------------------------------------------- */

#include
#include
#include
#include
#include "mouse.h"
#include "cursor.h"

void textdemo(void);
int textscreen(void);
void nexttdemo(TextCursor&, char *);
void graphicdemo(void);
int graphicscreen(void);
void nextgdemo (GraphicsCursor&, char *);

int maxx, maxy;
int text_width, text_height;
struct text_info t_info;
int done = 0;

main()
{
if(mouse.Exists()) // check for mouse
{
mouse.InstallHandler(0xff); // install event handler
mouse.Enable(); // enable mouse
textdemo(); // run text mode demo
graphicdemo(); // run graphics mode demo
return(0); // normal termination
}
return(1); // abnormal termination
}

/* ----- text mode demo ----------------------------------------------- */

void textdemo() // main routine for text mode demo
{
if(textscreen() == 0) // draw the screen
{
textcolor(13);
gotoxy(1,3);

if(mouse.Info.type == 1) cprintf(" Bus mouse found\n");
if(mouse.Info.type == 2) cprintf(" Serial mouse found\n");
if(mouse.Info.type == 3) cprintf(" InPort mouse found\n");
if(mouse.Info.type == 4) cprintf(" PS/2 mouse found\n");
if(mouse.Info.type == 5) cprintf(" HP mouse found\n");
gotoxy(1,4);
cprintf(" Software version is %d.%d\n", (int)mouse.Info.majorvers,
(int)mouse.Info.minorvers);

mouse.yLimit(0, 199); // set y limit
mouse.Show(); // initial turn-on

if(!done) nexttdemo(tdef, " Default Cursor ");
if(!done) nexttdemo(txt1, " 0000h 0E0Fh Soft Cursor ");
if(!done) nexttdemo(txt2, " 7000h 0E0Fh Soft Cursor ");
if(!done) nexttdemo(txt3, " 7F00h FF0Fh Soft Cursor ");
mouse.xLimit(16, 623);
if(!done) nexttdemo(txt4, " 00FFh 0FD4h Soft Cursor ");

textmode(C4350); // 43/50 line mode
_setcursortype(_NOCURSOR); // turn the hardware cursor off
mouse.xLimit(0, 639); // set x limit
gettextinfo(&t_info);
if(t_info.screenheight == 43)
mouse.yLimit(0, 349); // set y limit to EGA 43 line
else
mouse.yLimit(0, 399); // set y limit to VGA 50 line
if(!done) nexttdemo(tdef, " Default Cursor ");
}
}

int textscreen() // draws screen for demo
{
int i, j;
char far *video;
int video_seg = 0xB800, // pointer to video memory
video_off = 0x0000;

textmode(C80); // 80x25 color text mode
video = (char far *)MK_FP(video_seg, video_off);

clrscr(); // clear screen
_setcursortype(_NOCURSOR); // turn the hardware cursor off

for(i=0; i<50; i++) // draw the text screen background
{
for(j=0; j<80; j++)
{
*video++ = 0xDB+2*(j/10); // write the character to video memory
*video++ = 16*(j/10)+j/10+1; // write the color
}
}

gotoxy(1,1);
textattr(RED);
cprintf(" Mouse Enabled... ");
gotoxy(27,1);
textattr(4);
cprintf(" Text Mode Demonstration ");

textattr(LIGHTGRAY);
for(i=5; i<13; i++)
{
gotoxy(5, i);
cprintf("ÛÛÛÛÛÛÛÛÛÛ");
}
textattr(DARKGRAY);
for(i=6; i<8; i++)
{
gotoxy(6, i);
cprintf("ÛÛ");
gotoxy(9, i);
cprintf("ÛÛ");
gotoxy(12, i);
cprintf("ÛÛ");
}
textattr(WHITE);
gotoxy(6,9);
cprintf("Position");

textattr(LIGHTBLUE);
gotoxy(37,22); cprintf("ÉÍÍÍÍÍÍ»");
gotoxy(37,23); cprintf("º Next º");
gotoxy(37,24); cprintf("ÈÍÍÍÍÍͼ");

return(0);
}


void nexttdemo(TextCursor& cursor, char *str)
{
mouse.SetTextCursor(cursor); // set text cursor
textattr(4);
gotoxy(27,2);
cprintf(str); // print title
textattr(13);
for(;;)
{
mouse.GetEvent();
textattr(WHITE);
gotoxy(6,10);
cprintf(" %2d %2d ", mouse.xPos() >> 3, mouse.yPos() >> 3);

(mouse.LB_Dn()) ? textattr(RED) :
textattr(DARKGRAY);
gotoxy(6,6);
cprintf("ÛÛ");
gotoxy(6,7);
cprintf("ÛÛ");
(mouse.CB_Dn()) ? textattr(RED) :
textattr(DARKGRAY);
gotoxy(9,6);
cprintf("ÛÛ");
gotoxy(9,7);
cprintf("ÛÛ");

(mouse.RB_Dn()) ? textattr(RED) :
textattr(DARKGRAY);
gotoxy(12,6);
cprintf("ÛÛ");
gotoxy(12,7);
cprintf("ÛÛ");

if(mouse.Released(LEFTBUTTON)) // check for LB release
if(mouse.InBox(36*8, 21*8, 43*8, 23*8))
return;

if(mouse.DoubleClick(LEFTBUTTON))
{
mouse.ClearClick(LEFTBUTTON);

return;
}

if(mouse.DoubleClick(RIGHTBUTTON))
{
mouse.Disable();
gotoxy(1,1);
textattr(RED + BLINK);
cprintf(" Hit any key... ");

while(!getch());

gotoxy(1,1);
textattr(RED);
cprintf(" Mouse Enabled... ");
mouse.Enable();
mouse.Show();
}

if(mouse.Pressed(LEFTBUTTON) && (mouse.Button() & CTRL_PRESSED))
{
done = 1;
return;
}
}
}

/* ----- graphics mode demo ------------------------------------------- */

void graphicdemo() // main routine for graphics demo
{
if(graphicscreen() == 0) // draw the screen
{
done = 0;
mouse.yLimit(0, maxy); // set y limit (EGA=350, VGA=480)
mouse.Show(); // initial turn on

mouse.SetSpeedThreshold(32);
mouse.MickToPix(8, 8);
if(!done) nextgdemo(gdef, " Default ");
if(!done) nextgdemo(cross, " Cross ");
if(!done) nextgdemo(check, " Check ");
if(!done) nextgdemo(plus, " Plus ");
if(!done) nextgdemo(gun, " Gun ");
if(!done) nextgdemo(hand, " Hand ");
if(!done) nextgdemo(hourglass,"Hourglass");
if(!done) nextgdemo(bullseye, " Bullseye");
mouse.MickToPix(4, 4);
if(!done) nextgdemo(ibeam, " IBeam ");
mouse.MickToPix(2, 2);
if(!done) nextgdemo(jet, " Jet ");
mouse.MickToPix(16, 16);
mouse.Move(maxx/2, maxy/2);
if(!done) nextgdemo(face, " Face ");

closegraph();
}
}

int graphicscreen()
{
int x, y;
int driver = EGA, mode = EGAHI;

initgraph(&driver, &mode, "");
if(graphresult() == grOk)
{
maxx = getmaxx();
maxy = getmaxy();
text_width = textwidth("O");
text_height = textheight("O");

setcolor(RED); // paint background
rectangle(0, 0, maxx/3, maxy);
setfillstyle(SOLID_FILL, RED);
floodfill(maxx/6, maxy/2, RED);
setcolor(GREEN);
rectangle(maxx/3, 0, 2*maxx/3, maxy);
setfillstyle(SOLID_FILL, GREEN);
floodfill(maxx/2, maxy/2, GREEN);
setcolor(BLUE);
rectangle(2*maxx/3, 0, maxx, maxy);
setfillstyle(SOLID_FILL, BLUE);
floodfill(5*maxx/6, maxy/2, BLUE);

x = (maxx/2)-75; // center white block
y = (maxy/2)-75;
setcolor(WHITE);
rectangle(x, y, x+150, y+150);
setfillstyle(SOLID_FILL, WHITE);
floodfill(x+10, y+10, WHITE);

x = (maxx/2)-40; // center black box
y = (maxy/2)-40;
setcolor(BLACK);
rectangle(x, y, x+80, y+80);
setfillstyle(SOLID_FILL, BLACK);
floodfill(maxx/2, maxy/2, BLACK);

setcolor(BLACK); // "Next" box
moveto(37*text_width, 40*text_height);
outtext("ÛÛÛÛÛÛÛÛ");
moveto(37*text_width, 41*text_height);
outtext("ÛÛÛÛÛÛÛÛ");
moveto(37*text_width, 42*text_height);
outtext("ÛÛÛÛÛÛÛÛ");
setcolor(WHITE);
moveto(37*text_width, 40*text_height);
outtext("ÉÍÍÍÍÍÍ»");
moveto(37*text_width, 41*text_height);
outtext("º Next º");
moveto(37*text_width, 42*text_height);
outtext("ÈÍÍÍÍÍͼ");

setfillstyle(SOLID_FILL, LIGHTGRAY);// draw mouse and buttons
setcolor(LIGHTGRAY);
rectangle(40, 40, 140, 140);
floodfill(90, 90, LIGHTGRAY);
setfillstyle(SOLID_FILL, DARKGRAY);
setcolor(DARKGRAY);
rectangle(50, 60, 70, 80);
floodfill(60, 70, DARKGRAY);
rectangle(80, 60, 100, 80);
floodfill(90, 70, DARKGRAY);
rectangle(110, 60, 130, 80);
floodfill(120, 70, DARKGRAY);
setcolor(BLACK);
moveto(60, 100);
outtext("Position");

return(0);
}
return(1);
}

void nextgdemo(GraphicsCursor& cursor, char *str)
{
int LBDN = 0, CBDN = 0, RBDN = 0;
char str2[10];
int color;

mouse.SetGraphicsCursor(cursor); // set graphics cursor
setcolor(BLACK); // print label
moveto((maxx/2-5*text_width),text_height);
outtext("ÛÛÛÛÛÛÛÛÛ");
setcolor(WHITE);
moveto((maxx/2-5*text_width),text_height);
outtext(str);

mouse.ClearBuffer();
mouse.ClearEvent();


for(;;)
{
mouse.GetEvent();
// set exclusion area
mouse.Exclude(40, 40, 140, 140);
// see if mouse has moved
if(mouse.xCount() || mouse.yCount())
{
sprintf(str2, "%3d %3d", mouse.xPos(), mouse.yPos());
setcolor(LIGHTGRAY);
moveto(60, 108);
outtext("ÛÛÛÛÛÛÛ");
setcolor(BLACK);
moveto(60, 108);
outtext(str2); // print cursor position
}
// check all button status for change
if((mouse.LB_Dn() && !LBDN) || (!mouse.LB_Dn() && LBDN))
{
color = LBDN ? DARKGRAY : RED;
if(mouse.MultiClick(LEFTBUTTON) == 2) color = BLUE;
if(mouse.MultiClick(LEFTBUTTON) == 3) color = GREEN;
if(mouse.MultiClick(LEFTBUTTON) == 4) color = YELLOW;

setcolor(color);
setfillstyle(SOLID_FILL, color);
rectangle(50, 60, 70, 80);
floodfill(60, 70, color);
LBDN = !LBDN;
}
if((mouse.CB_Dn() && !CBDN) || (!mouse.CB_Dn() && CBDN))
{
color = CBDN ? DARKGRAY : RED;
if(mouse.MultiClick(CENTERBUTTON) == 2)
{
if(mouse.CB_Dn())
color = BLUE;
}
if(mouse.MultiClick(CENTERBUTTON) == 3)
{
if(mouse.CB_Dn())
color = GREEN;
}
if(mouse.MultiClick(CENTERBUTTON) == 4)
{
color = YELLOW;
mouse.ClearClick(CENTERBUTTON);
}

setcolor(color);
setfillstyle(SOLID_FILL, color);
rectangle(80, 60, 100, 80);
floodfill(90, 70, color);
CBDN = !CBDN;
}
if((mouse.RB_Dn() && !RBDN) || (!mouse.RB_Dn() && RBDN))
{
color = RBDN ? DARKGRAY : RED;
if(mouse.MultiClick(RIGHTBUTTON) == 2) color = BLUE;
if(mouse.MultiClick(RIGHTBUTTON) == 3) color = GREEN;
if(mouse.MultiClick(RIGHTBUTTON) == 4) color = YELLOW;

setcolor(color);
setfillstyle(SOLID_FILL, color);
rectangle(110, 60, 130, 80);
floodfill(120, 70, color);
RBDN = !RBDN;
}

if(mouse.Released(LEFTBUTTON)) // check for LB release
{
if(mouse.InBox(37*text_width, 40*text_height,
45*text_width, 43*text_height))
{
if(LBDN) // check for LBDN status
{
setcolor(DARKGRAY); // dehilite mouse button
setfillstyle(SOLID_FILL, DARKGRAY);
rectangle(50, 60, 70, 80);
floodfill(60, 70, DARKGRAY);
}
return;
}
}

if(mouse.MultiClick(LEFTBUTTON) == 3)
{
mouse.ClearClick(LEFTBUTTON);
return;
}

if(mouse.Pressed(LEFTBUTTON) && (mouse.Button() & CTRL_PRESSED))
{
done = 1;
return;
}
}
}


  3 Responses to “Category : C++ Source Code
Archive   : MOUSPP30.ZIP
Filename : MICEDEMO.CPP

  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/