Ismouseclick
Ismouseclick
Ismouseclick
Syntax
#include "graphics.h" bool ismouseclick(int kind);
Description The ismouseclick function is available in the winbgim implementation of BGI graphics. This function returns true if there is an unprocessed mouse event of the specified kind. The argument to ismouseclick is one of these constants from the graphics.h file:
WM_MOUSEMOVE
...detect when the right mouse button is released up The middle mouse button handlers aren't working on my machine. I haven't yet tracked down the reason--it could be a broken mouse or it could be a bug in my programming. A mouse event can be processed by calling getmouseclick (which gets the coordinates of the event), or by calling clearmouseclick (which processes the event without providing its coordinates). Return Value True if there is an unprocessed mouse event of the specified kind; otherwise false. Example
/* mouse example */ #include "graphics.h"
void main(void) { int maxx, maxy; int x, y; int divisor; // Maximum x and y pixel coordinates // Coordinates of the mouse click // Divisor for the length of a triangle side
// Put the machine into graphics mode and get the maximum coordinates: initwindow(450, 300); maxx = getmaxx( ); maxy = getmaxy( );
// Draw a white circle with red inside and a radius of 50 pixels: setfillstyle(SOLID_FILL, RED); setcolor(WHITE); fillellipse(maxx/2, maxy/2, 50, 50);
// Print a message and wait for a red pixel to be double clicked: settextstyle(DEFAULT_FONT, HORIZ_DIR, 2); outtextxy(20, 20, "Left click in to end."); setcolor(BLUE); divisor = 2; while (!ismouseclick(WM_LBUTTONDOWN)) { triangle(maxx/divisor, maxy/divisor); delay(500); divisor++; }
getmouseclick(WM_LBUTTONDOWN, x, y); cout << "The mouse was clicked at: "; cout << "x=" << x; cout << " y=" << y << endl;
clearmouseclick
Syntax
#include "graphics.h" void clearmouseclick(int kind);
Description The clearmouseclick function is available in the winbgim implementation of BGI graphics. This is just like getmouseclick, except it does not provide the x and y coordinates of the event. The value of the argument kind may be any of the constants listed above. After calling getmouseclick, for a particular kind of event, the ismouseclick will return false for that kind of event until another such event occurs. The kind argument to clearmouseclick is one of these constants from the graphics.h file:
WM_MOUSEMOVE
WM_RBUTTONDBLCLK
...detect when the right mouse button is released up The middle mouse button handlers aren't working on my machine. I haven't yet tracked down the reason--it could be a broken mouse or it could be a bug in my programming. Example
/* mouse example */ #include "graphics.h"
void main(void) { const int LIMIT = 10; // Number of clicks to stop program. int maxx, maxy; int count = 0; int divisor; // Maximum x and y pixel coordinates // Number of mouse clicks // Divisor for the length of a triangle side
// Put the machine into graphics mode and get the maximum coordinates: initwindow(450, 300); maxx = getmaxx( ); maxy = getmaxy( );
// Draw a white circle with red inside and a radius of 50 pixels: setfillstyle(SOLID_FILL, RED); setcolor(WHITE); fillellipse(maxx/2, maxy/2, 50, 50);
settextstyle(DEFAULT_FONT, HORIZ_DIR, 2); outtextxy(20, 20, "Left click " << LIMIT << " times to end."); setcolor(BLUE); divisor = 2; while (count < LIMIT) { triangle(maxx/divisor, maxy/divisor); delay(500); divisor++; if (ismouseclick(WM_LBUTTONDOWN)) { clearmouseclick(WM_LBUTTONDOWN)); count++; } }
getmouseclick
Syntax
#include "graphics.h"
Description The getmouseclick function is available in the winbgim implementation of BGI graphics. This function sets x and y to the pixel coordinates of an unprocessed event of the specified kind. If there is no such event, then the function sets both x and y to -1. The value of the argument kind may be any of the constants listed above. After calling getmouseclick, for a particular kind of event, the ismouseclick will return false for that kind of event until another such event occurs. The kind argument to getmouseclick is one of these constants from the graphics.h file:
WM_MOUSEMOVE
...detect when the right mouse button is released up The middle mouse button handlers aren't working on my machine. I haven't yet tracked down the reason--it could be a broken mouse or it could be a bug in my programming. Note: Normally, getmouseclick returns the coordinates of the most recent event of the requested kind. If you want mouse clicks of a particular kind to be queued for processing, then call setmousequeuestatus. Example
/* mouse example */ #include "graphics.h"
void main(void) { int maxx, maxy; int x, y; int divisor; // Maximum x and y pixel coordinates // Coordinates of the mouse click // Divisor for the length of a triangle side
// Put the machine into graphics mode and get the maximum coordinates: initwindow(450, 300); maxx = getmaxx( ); maxy = getmaxy( );
// Draw a white circle with red inside and a radius of 50 pixels: setfillstyle(SOLID_FILL, RED); setcolor(WHITE); fillellipse(maxx/2, maxy/2, 50, 50);
// Print a message and wait for a red pixel to be double clicked: settextstyle(DEFAULT_FONT, HORIZ_DIR, 2); outtextxy(20, 20, "Left click in to end."); setcolor(BLUE); divisor = 2; while (!ismouseclick(WM_LBUTTONDOWN)) { triangle(maxx/divisor, maxy/divisor); delay(500); divisor++; }
getmouseclick(WM_LBUTTONDOWN, x, y); cout << "The mouse was clicked at: "; cout << "x=" << x; cout << " y=" << y << endl;