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

Slides:



Advertisements
Similar presentations
Introduction to C++ An object-oriented language Unit - 01.
Advertisements

OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Week 4 – Functions Introduction. Functions: Purpose Breaking a large problem into a series of smaller problems is a common problem- solving technique.
UFCFSU-30-13D Technologies for the Web Creating and Using GUI Components.
FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2010/2011.
On using the mouse A brief introduction to LIBGPM: the General Purpose Mouse programming interface.
ObjectDraw and Objects Early Chris Nevison Barbara Wells.
SE320: Introduction to Computer Games Week 8: Game Programming Gazihan Alankus.
Functions in C++ Eric Roberts CS 106B January 9, 2013.
Chapter 10 Introduction to Components. Process Phases Discussed in This Chapter Requirements Analysis Design Implementation ArchitectureFramework Detailed.
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.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Introduction to Linux ( I ) Sidney Fong 4 th Feb 2006.
GNU Compiler Collection (GCC) and GNU C compiler (gcc) tools used to compile programs in Linux.
Lecture 3 OpenGL.
1 Input and Interaction. 2 Input Devices Physical input devices Keyboard devices and pointing devices Logical input devices.
SIMPLE PROBLEM SOLVING in Java: a Problem Set Framework Viera K. Proulx Richard Rasala Jason Jay Rodrigues CCSCNE 2002 Conference.
Introduction to Windows Programming
Computer Science 112 Fundamentals of Programming II Command Buttons and Responding to Events.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
COMP 321 Week 2. Outline Event-Driven Programming Events, Event Sources, Event Listeners Button and Timer Events Mouse Events, Adapters.
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
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.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Programming in the Simple Raster Graphics Package (SRGP) Chapter 2.
Unity GUI Creating and Using GUI Components. Agenda GUI Components GUI Layout Using Styles and Skins for Design ‘Look and Feel’ Scripting GUI Communication.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6: Transition to Java Programming with Alice and Java First Edition.
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.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
SCRIPT PROGRAMMING WITH FLASH Introductory Level 1.
CompSci Introduction to Jam’s Video Game Package.
1 Getting Started with C++ Part 2 Linux. 2 Getting Started on Linux Now we will look at Linux. See how to copy files between Windows and Linux Compile.
CISC 110 Day 6 Introduction to Events. Outline Event-Driven Programming Event Classes Hierarchy –Event Class –Mouse Events –Keyboard Events Registering.
CompSci 44.1 Game Package Introduction to Jam’s Video Game Package.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
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.
CHARACTER INPUT / OUTPUT AND INPUT VALIDATION. Introduction Input and output devices: keyboards, disk drives, mouse, monitors, printers. I/O functions.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
Events and Event Handling
CompSci 230 S Programming Techniques
Java Exceptions a quick review….
Topics Graphical User Interfaces Using the tkinter Module
Event Loops and GUI Intro2CS – weeks
Chapter 12 Event-Driven Programming
Introduction to Event-Driven Programming
Router Startup and Setup
Introduction to C Language
CSC461 Lecture 8: Input Devices
Understand Windows Forms Applications and Console-based Applications
The User Interface Lecture 2 Mon, Aug 27, 2007.
Programming Assignment 1
Event Driven Programming
The slides must be understood in Lecture 5
Introduction to Computing Using Java
Topics Introduction to File Input and Output
Event Driven Programming & User Defined Functions
Introduction to Classes and Objects
Isaac Gang University of Mary Hardin-Baylor
Router Startup and Setup
Constructors, GUI’s(Using Swing) and ActionListner
Tonga Institute of Higher Education
ICT Programming Lesson 5:
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
User Input Keyboard input.
Topics Introduction to File Input and Output
Input and Interaction Ed Angel Professor Emeritus of Computer Science,
Switch Case Structures
Presentation transcript:

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

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 <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 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)

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) 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 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

In-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 animation?