DOC PREVIEW
USF CS 686 - Lecture Notes

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

On using the mouseThe Linux “gpm” packageProgramming stepsFields to be initializedResponding to mouse activityUseful fields in Gpm_EventA typical program loopA simple text-mode demoA simple graphics demoIn-class exercisesOn using the mouseA brief introduction to LIBGPM: the General Purpose Mouse programming interfaceThe Linux “gpm” package•It’s a mouse server for the Linux console•It “hides” details about mouse hardware•Intended for use with text-based programs•But we can use it with graphics programs•Requires that the gpm daemon is running•Type ‘info gpm’ to see official information•Also an online article by Pradeep PadalaProgramming steps•Your client application must establish a connection with the gpm server-daemon•You need a header-file: #include <gpm.h>•You declare an important data-structure:Gpm_Connect conn;•You will need to initialize its four fields•Then you call Gpm_Open( &conn, 0 );•Returns -1 if unsuccessful (otherwise 0)Fields to be initializedconn.eventMask = ~0; // events of interestconn.defaultMask = 0; // to handle for youconn.minMod = 0; // lowest modifierconn.maxMod = ~0; // highest modiferResponding to mouse activity•You create your own ‘handler’ function for those mouse events that you wish to act upon•Prototype of the handler-function is: int my_handler( Gpm_Event *evt, void *my_data );•To install the handler, use this assignment:gpm_handler = my_handler;•Whenever the mouse is moved, or its buttons are pressed or released, your function executesUseful fields in Gpm_EventGpm_Event *evt;evt->type == 1: // indicates a mouse-moveevt->x, evt->y: // current mouse ‘hot-spot’evt->dx, evt->dy: // changes in position(+/-) NOTE: Remember that GPM was developed for text-based applications, so the hot-spot coordinates are character-cell locations (not graphics-pixel locations)A typical program loopThis loop allows normal keyboard input to continue being processed (e.g., echoed, buffered) while any mouse activities are processed by your handler (or else by a default handler supplied by the daemon)int c;While ( ( c = Gpm_Getc( stdin ) ) != EOF );Gpm_Close();A simple text-mode demo•Pradeep Padala has published a short C program that illustrates ‘barebones’ usage of the gpm package (from Linux Journal)•We have adapted his code for C++•Our demo is called ‘trymouse.cpp’•It’s compiled like this: $ g++ trymouse.cpp –lgpm –o trymouseA simple graphics demo•We have created a minimal graphics demo •It shows how you could use the mouse to move a ‘slider’ object (e.g.,in Pong game)•It’s called ‘gpmslide.cpp’•You compile it like this:$ g++ gpmslide.cpp –lgpm –o gpmslideIn-class exercises•Compile and run the ‘trymouse.cpp’ demo•Compile and run the ‘gpmslide.cpp’ demo•Look at the C++ source-code in the demos•Can you replace the keyboard-based user controls (in your earlier pong animation) with mouse-based user-controls?•Can you incorporate mouse-based control into your 3D wire-frame model


View Full Document

USF CS 686 - Lecture Notes

Documents in this Course
Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?