// FLTK demo program for CS559 // Fall, 2000, Mark Pingel // implementation of EventWindow class - see documentation in header #include "EventWindow.h" char * foo; // Constructor for the EventWindow // Arguments are the initial width and heigth for the window EventWindow::EventWindow(int width, int height) :Fl_Window(width, height, "") { label("Demo Window for CS 559"); } // This function changes the label on the window based // which mouse button was activated, where it was activated, and what // activity the mouse was doing at that time ( push, drag, release ) int EventWindow::handle_mouse(int event, int button, int x, int y) { // Deallocate the memory for foo if necessary if (foo) delete [] foo; // Reallocate new memory foo = new char[100]; int ret = 0; // Switch on the mouse button activated // 1 - Left Mouse Button // 2 - Middle Mouse Button // 3 - Right Mouse Button switch ( button ) { case 1: // LMB ret = 1; // Based on the action, print the action and // coordinates where it occurred. if ( event == FL_PUSH ) { sprintf(foo,"LMB PUSH ( %d , %d )",x,y); label(foo); damage(1); } else if (event == FL_DRAG ) { sprintf(foo,"LMB Drag ( %d , %d )",x,y); label(foo); damage(1); } else if ( event == FL_RELEASE ) { sprintf(foo,"LMB Release ( %d , %d )",x,y); label(foo); damage(1); } break; case 2: // MMB ret = 1; // Based on the action, print the action and // coordinates where it occurred. if ( event == FL_PUSH ) { sprintf(foo,"MMB Push ( %d , %d )",x,y); label(foo); damage(1); } else if (event == FL_DRAG ) { sprintf(foo,"MMB Drag ( %d , %d )",x,y); label(foo); damage(1); } else if ( event == FL_RELEASE ) { sprintf(foo,"MMB Release ( %d , %d )",x,y); label(foo); damage(1); } break; case 3: // RMB ret = 1; // Based on the action, print the action and // coordinates where it occurred. if ( event == FL_PUSH ) { sprintf(foo,"RMB Push ( %d , %d )",x,y); label(foo); damage(1); } else if (event == FL_DRAG ) { sprintf(foo,"RMB Drag ( %d , %d )",x,y); label(foo); damage(1); } else if ( event == FL_RELEASE ) { sprintf(foo,"RMB Release ( %d , %d )",x,y); label(foo); damage(1); } break; } return ret; } // This function handles keyboard events int EventWindow::handle_key(int event, int key) { switch ( key ) { // If the 'c' key is depressed, change the window // label case 'c': label ("letter c was depressed"); damage(1); return 1; default: label ("Nothing to do!"); damage(1); printf("nothing to do\n"); return 1; } }