On using the mouse A brief introduction to LIBGPM: the General Purpose Mouse programming interface.

Slides:



Advertisements
Similar presentations
Game with US Beginner Tutorial. Welcome!! Who I am What is Processing? Basic Coding Input Methods Images Classes Arrays.
Advertisements

VMWare Workstation Installation. Starting Vmware Workstation Go to the start menu and start the VMware Workstation program. *Note: The following instructions.
Loops, and sub-routines Interrupts Can be very useful in control applications particularly when the microprocessor must perform two tasks apparently.
Microsoft Access A Hands-On Introduction Chapter 4.
FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2010/2011.
Lecture 2Slide 1 Event Driven Computing Basic Interaction Handling –Interactive programs - must pay attention to the user interface.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
Concurrent TCP connections A look at design-changes which permit a TCP server to handle multiple clients without delays.
Dynamic visualizations On ‘non-canonical’ keyboard-input and terminal escape-sequences for visualization effects.
Painterly Rendering CMPS Assignment 2. OpenGL OpenGL is a cross-language, cross- platform specification defining and API for 2D and 3D graphics.
Graphics not part of C++ libraries –X libraries –QT library –OS specific.
XP Tutorial 8 New Perspectives on JavaScript, Comprehensive1 Working with the Event Model Creating a Drag-and-Drop Shopping Cart.
Linux game programming An introduction to the use of interval timers and asynchronous input notifications.
SE320: Introduction to Computer Games Week 8: Game Programming Gazihan Alankus.
Systems Software Operating Systems.
1 Semester 2 Module 2 Introduction to Routers Yuda college of business James Chen
2 What is pyGame? A set of Python modules to make it easier to write games. –home page: –documentation:
Chapter 5 - Making Music: An On-Screen Piano
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
CS 0004 –Lecture 1 Wednesday, Jan 5 th, 2011 Roxana Gheorghiu.
XP Tutorial 5 Buttons, Behaviors, and Sounds. XP New Perspectives on Macromedia Flash MX Buttons Interactive means that the user has some level.
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Java: Chapter 1 Computer Systems Computer Programming II.
Flash Lesson 1 Simple Animation. Get Acquainted With The Software.
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Visual Basic .NET BASICS
Developing the Game User Interface (UI) Lesson 5.
Keyboard and Events. What about the keyboard? Keyboard inputs can be used in many ways---not just for text The boolean variable keyPressed is true if.
1 Input and Interaction. 2 Input Devices Physical input devices Keyboard devices and pointing devices Logical input devices.
CHAPTER TEN AUTHORING.
Scientific Computing Division A tutorial Introduction to Fortran Siddhartha Ghosh Consulting Services Group.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
SIMPLE PROBLEM SOLVING in Java: a Problem Set Framework Viera K. Proulx Richard Rasala Jason Jay Rodrigues CCSCNE 2002 Conference.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Introduction to Windows Programming
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
X-WindowsP.K.K.Thambi The X Window System Module 5.
Software refer to all the programs that can be run on the computer.
Program 2 due 02/01  Be sure to document your program  program level doc  your name  what the program does  each function  describe the arguments.
UNIX signals & pipes. UNIX Signals A UNIX signal corresponds to an event –It is raised by one process (or hardware) to call another process’s attention.
Microprocessor and Interfacing Example: Writing a Game Need to Check Keyboard Input.
Implementing ‘noecho’ Programming details regarding the Linux implementation for ‘struct termios’ objects.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
* Bitmap images are based on a grid of pixels * Each pixel is assigned a specific location and color value * Bitmaps contain a limited number of pixels,
G RAPHICS & I NTERACTIVE P ROGRAMMING Lecture 2 More Programming with Processing.
Purpose of Operating System Monil Adhikari. Agenda Introduction Responsibilities of Operating System User Interfaces Command Line Interface Graphical.
Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.
CompSci 44.1 Game Package Introduction to Jam’s Video Game Package.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
Creating your own Handheld Games Console
IPEmotion License Management PM (V1.2).
Introducing Scratch Learning resources for the implementation of the scenario
Events and Event Handling
CompSci 230 S Programming Techniques
Reading and Writing Image Files
EE 200 Design Tools Laboratory 14
Microprocessor Systems Design I
An Introduction to Computers and Visual Basic
An Introduction to Computers and Visual Basic
JavaScript and Events.
Computation as an Expressive Medium
An Introduction to Computers and Visual Basic
On using the mouse A brief introduction to LIBGPM: the General Purpose Mouse programming interface.
Presentation transcript:

On using the mouse A brief introduction to LIBGPM: the General Purpose Mouse programming interface

Diversity of hardware As with SVGA devices, there are computer mice from a diversity of vendors – and no universal standard hardware design The customary solution: a software layer is created which ‘hides’ hardware differences For Linux platforms, the ‘libgpm’ package provides one such software-layer – though it was intended for text-based applications

Example: the PS/2 Mouse X-coordinate data (bits 7..0) Y-coordinate data (bits 7..0) Byte 0 Byte 1 Byte 2 The Mouse Report Format (3 bytes) Left Button down Right Button down Middle Button down 0 X-data sign Y-data sign Y-data over flow X-data over flow Other types of computer mice use different report formats with possibly a different number of bytes (e.g., 4 or 5)

The 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 Padala

Programming steps Your client application must establish a connection with the gpm server-daemon You need a header-file: #include 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 initialized conn.eventMask = ~0;// events of interest conn.defaultMask = 0;// to handle for you conn.minMod = 0;// lowest modifier conn.maxMod = ~0;// highest modifer

Responding 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 executes

Useful fields in Gpm_Event Gpm_Event*evt; evt->type == 1: // indicates a mouse-move evt->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)

The GPM mouse-event mask LEAVELEAVE ENTERENTER HARDHARD MOVCLKMOVCLK TRIPLETRIPLE DOUBLEDOUBLE SINGLESINGLE UPUP DOWNDOWN DRAGDRAG MOVEMOVE #include Your event-handler function will ‘test’ one or more of these flag-bits to determine what type of state-change the mouse has undergone, so that your application can respond to it in an appropriate manner

A typical program loop This 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) intc; 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 trymouse

A 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 gpmslide

More elaborate graphics demo We also created a more elaborate mouse- demo (called ‘seemouse.cpp’) It defines its own custom mouse-cursor It handles the four most common types of mouse events: –GPM_MOVE –GPM_DOWN –GPM_DRAG –GPM_UP

Our mouse cursor We built a 2-color 16-by-16 pixel image ‘0’ = transparent color ‘1’ = background color ‘2’ = foreground color We used an array of character-strings to define our image with only three character-values

Our mouse cache Each time we want to draw our cursor, we first copy the existing 16-by-16 pixel-grid that occupies the planned cursor-location Then we can draw our cursor threre When the mouse is moved, we need to ‘erase’ our cursor-image (by copying the saved background there), and then save- and-draw our cursor in the new location

In-class exercise #1 Can you create a different cursor-image, based on your own design ideas? Will your design define a different ‘hot-spot’? Will you need to modify the boundaries to keep your cursor from going out-of-view?

Demo: ‘persists.cpp’ We created a sound-playing program that plays a continuous tone – until a ‘signal’ is received (asynchronous notification) that the user has pressed the key We used an ‘ioctl’ command to ‘RESET’ the playback device – to stop the tone’s sound almost immediately when our user presses the key

In-class exercise #2 Try commenting out the final ‘ioctl’() call in our ‘persists.cpp’ demo, then recompile it and execute that demo again. Does the sound cease immediately? Can you incorporate the sound-effect into our ‘seemouse.cpp’ demo, so that a user can start the tone by pressing the mouse- button, and stop the tone by releasing it?