Event Models James Landay, UCB Outline Event overview Event overview Windowing systems Windowing systems Window events Window events Event dispatching.

Slides:



Advertisements
Similar presentations
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
Advertisements

Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
CS0004: Introduction to Programming Visual Studio 2010 and Controls.
© by Pearson Education, Inc. All Rights Reserved.
6/13/20151 CS 160: Lecture 13 Professor John Canny Fall 2004.
Using Visual Basic 6.0 to Create Web-Based Database Applications
1 Model View Controller. 2 Outline Review Definitions of MVC Why do we need it? Administiriva Changing the display Event flow Dragging at interactive.
Graphical User Interface (GUI) Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Graphical User Interface (GUI) Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
0 CS 160: Design Process: Implement Event-based UI Programming, Model-View-Controller, and the Web Jeffrey Nichols IBM Almaden Research Center
Object-Oriented Analysis and Design
Based on slides created by Edward Angel
Interaction Models I Marti Hearst (UCB SIMS) SIMS 213, UI Design & Development March 9, 1999.
Stanford hci group / cs376 research topics in human-computer interaction UI Software Tools Scott Klemmer 27 October 2005.
1 Introduction to Human Computer Interaction  Livecode Overview  Based on Livecode User Guide from RunRev Ltd. (2010) 
1 Introduction to Web Development. Web Basics The Web consists of computers on the Internet connected to each other in a specific way Used in all levels.
Using Visual Basic 6.0 to Create Web-Based Database Applications
Welcome to CIS 083 ! Events CIS 068.
JavaScript II ECT 270 Robin Burke. Outline JavaScript review Processing Syntax Events and event handling Form validation.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Microsoft Windows Vista Chapter 1 Fundamentals of Using Microsoft Windows Vista.
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
1Computer Graphics Input and Interaction Lecture 8 John Shearer Culture Lab – space 2
Gary MarsdenSlide 1University of Cape Town Human-Computer Interaction - 3 Programmer Support Gary Marsden ( ) July 2002.
Computer Graphics I, Fall 2010 Input and Interaction.
CS 480/680 Computer Graphics Programming with Open GL Part 7: Input and Interaction Dr. Frederick C Harris, Jr. Fall 2011.
Oct 071 Example Program DemoLookAndFeel.java Metal (java) Motif Windows.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
Window and Events The structure of Interactive Software.
Exploring Windows and Essential Computing Concepts 1 Windows Desktop u Windows Basics u Icon u Start Button u My Computer u Network Neighborhood u Recycle.
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 15: GUIs 1.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
C# GUI - Basics. Objectives.NET supports two types: WinForms, traditional, desktop GUI apps. WebForms – newer, for Web apps. Visual Studio.NET supports.
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
X-WindowsP.K.K.Thambi The X Window System Module 5.
MIT 6.893; SMA 5508 Spring 2004 Larry Rudolph Lecture 4: Graphic User Interface Graphical User Interface Larry Rudolph MIT 6.893; SMA 5508 Spring 2004.
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.
1 Input and Interaction. 2 Objectives Introduce the basic input devices ­Physical Devices ­Logical Devices ­Input Modes Event-driven input Introduce double.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
Introducing Dreamweaver. Dreamweaver The web development application used to create web pages Part of the Adobe creative suite.
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
CompSci 230 S Software Construction
An Introduction to Computers and Visual Basic
Console and GUI Programs
CSC461 Lecture 8: Input Devices
An Introduction to Computers and Visual Basic
Program and Graphical User Interface Design
Chapter 2 – Introduction to the Visual Studio .NET IDE
Event loops.
Professor John Canny Spring 2004 March 3
Professor John Canny Spring 2004 Feb 25
Event loops 17-Jan-19.
Event loops 17-Jan-19.
An Introduction to Computers and Visual Basic
Professor John Canny Spring 2003 March 10
Professor John Canny Spring 2003 March 12
ACM programming contest
Event loops.
Event loops 19-Aug-19.
Presentation transcript:

Event Models James Landay, UCB

Outline Event overview Event overview Windowing systems Windowing systems Window events Window events Event dispatching and handling Event dispatching and handling

Sequential Programs Program takes control, prompts for input Program takes control, prompts for input Examples include Examples include –command-line prompts (DOS, UNIX) –LISP interpreter The user waits on the program The user waits on the program –Program tells user it’s ready for more input –User enters more input

Sequential Programs (cont.) Architecture Architecture Program reads in a line of text Program parses the text Program evaluates the result Maybe some output Loop back to beginning But how do you model the many actions a user can take? But how do you model the many actions a user can take? –For example, a word processor? –Need to do printing, editing, inserting, etc.

Sequential Programs (cont.) Usually end up with lots of modes Usually end up with lots of modes –Lots of state variables Other examples of modes Other examples of modes –Paint programs (line, bucket-fill, rectangle, etc) –Universal remotes with TV / VCR mode –VI edit mode and command mode Problems with modes? Problems with modes?

Sequential Programs (cont.) Problems with modes? Problems with modes? –Gets confusing if too many modes –Can be easy to make errors –Need feedback as to what mode you are in –How to switch between modes? We’ll need a more advanced model to simplify windows programming We’ll need a more advanced model to simplify windows programming

Event-Driven Programming Instead of the user waiting on program, have the program wait on the user Instead of the user waiting on program, have the program wait on the user All communication from user to computer is done via “events” All communication from user to computer is done via “events” An event is something “interesting” that happens in the system An event is something “interesting” that happens in the system –Mouse button goes down –Item is being dragged –Keyboard button was hit

Event Example close box title bar folder scroll bar size control

Major Issues How to decompose the UI into interactive objects? How to decompose the UI into interactive objects? How to distribute inputs to the interactive objects How to distribute inputs to the interactive objects How to partition between application & system software? How to partition between application & system software? Models for programming interactive objects Models for programming interactive objects Models for communications between objects Models for communications between objects

Windowing Systems Partitioning to prevent chaos Partitioning to prevent chaos Infrastructure to support common services Infrastructure to support common services Two major aspects Two major aspects –software services to applications create and organize windows implement interaction in those windows –window manager UI allowing user to control size & placement of windows

Interactor Tree Decompose interactive objects into a tree Decompose interactive objects into a tree –interactive objects also known as “widgets” –based on screen geometry of objects –nested rectangles Used for dispatching events Used for dispatching events –Events are dispatched (sent) to code in widget –The code then handles the event Variety of methods for dispatching events Variety of methods for dispatching events –Return to this later

Interactor Tree Display Screen “F:\cs160\Public” window Inner Window title bar horizontal scroll bar contents area “CDJukebox” folder “Home Ent…” folder … size control … “Web Newspaper” window …

Interactor Tree Display Screen Outer Win [black] = ENT ?????

Interactor Tree Display Screen Outer Win [black] Result Win [tan] Result String Inner Win [green] Keypad [Teal] - button + button 0 button = button = ENT

Interactor Tree (Java) Display Screen Frame [black] Text Entry [tan] Result String Panel [green] Keypad Panel [Teal] Button(“-”) Button(“+”) Button(“0”) Button(“=”) = ENT

Windows Top level windows known as root windows Top level windows known as root windows –provide UI abstraction for multiple apps –windowing system arbitrates interactive resources Each root window belongs to an app. Each root window belongs to an app. –all descendant windows belong to same app –violated by OLE (ActiveX) and OpenDoc (dead?)

Windows (cont.) Windows vs. widgets/controls Windows vs. widgets/controls –X, NeXTStep, MS Windows everything is window –Mac: only roots are windows  controls manage rect. space in a window (Motif gadgets similar)

Networked Windowing Systems X Window & NeWS designed to allow apps to run on remote machines X Window & NeWS designed to allow apps to run on remote machines Uses client-server model Uses client-server model X Server std system software Client app software Network User

X Window Note backwards terminology Note backwards terminology –User is on “server” not “client” X Server X Server –interprets X commands and can send events –determines which window receives events and forwards over network to proper client X Client X Client –software interface to X (Xlib) –assembles the output from Xlib routines into packets for transmission to server

X Window Interaction Problems? Interaction Problems? Network Bandwidth is bits per second Network Latency is time to transfer and process data. X Server std system software Client app software Network User Latency (time) Bandwidth (bps) Relation to Model Human Processor?

Network Round Trips (NRT) Every mouse move on thumb involves NRT Every mouse move on thumb involves NRT Solutions? Solutions? –download code that knows how to scroll –NeWS used display PostScript to do this scroll bar thumb (elevator)

Window Events User interacts with input device User interacts with input device –action translated into software events –must distribute events to appropriate window –doesn’t need IPC, use method/procedure call Events have Events have –type –mouse position or character key –the window the event is directed to

Input Events Mouse button events Mouse button events –mouse up and down –modifier (shift keys, etc.) –double click (X doesn’t have this  fakes it) Mouse movement events Mouse movement events –implement painting with mouse –mouse drag can “mask off” mouse moves w/o button down Mouse enter and exit events Mouse enter and exit events –e.g. if you entered / exited a button region

Implementing Buttons Button mouse enter mouse exit (But using mouse move events would be overkill)

Events (cont.) Keyboard events Keyboard events –must translate raw “scan codes” into ASCII Windowing events on window Windowing events on window –creation / destruction –opening / closing –iconifying / deiconifying –selection / deselection –resize –redraw redraw newly exposed portions of the window (rect.)

Main Event Loop Main event loop Main event loop Initialization While (not time to quit) { Get next event E Dispatch event E } The meat of the program is in the code that handles the “dispatch” The meat of the program is in the code that handles the “dispatch”

Event Dispatch Dispatch (event E) { switch (E.window) {... case FIVE-KEY: if (E.type == left-down){ cur = *cur; display (cur); last-op = NUMBER; } = 0 ENT Hit the ‘5’ key

Event Dispatch Dispatch (event E) { switch (E.window) {... case TWO-KEY: if (E.type == left-down) { cur = *cur; display (cur); last-op = NUMBER; } = 5 ENT Hit the ‘2’ key

Event Dispatch Dispatch (event E) { switch (E.window) {... case ENTER-KEY: if (E.type == left-down){ push (cur); cur = 0; last-op = COM; } = 52 ENT Hit the ‘enter’ key

Event Dispatch Dispatch (event E) { switch (E.window) {... case SIX-KEY: if (E.type == left-down) { cur = *cur; display (cur); last-op = NUMBER; } = 0 ENT Hit the ‘6’ key

Event Dispatch Dispatch (event E) { switch (E.window) {... case PLUS-WIN: if (E.type == left-down){ if (last-op == NUMBER) push (cur); result = pop() + pop(); push (result); display (result); cur = 0; last-op = COM; } = 6 ENT Hit the ‘+’ key

Event Dispatch = 58 ENT

Event Queues Input events are placed in a queue Input events are placed in a queue –Ensures events are processed in order Main event loop removes them from the queue (get_next_event) & dispatches for processing Main event loop removes them from the queue (get_next_event) & dispatches for processing Mouse move (22, 33) Mouse move (40, 30) Mouse down left (45, 34) Mouse up left (46, 35)

Event Queues (cont.) Can use event masks to filter unwanted events Can use event masks to filter unwanted events –e.g., filter mouse moves in a forms-based program just get enter/exit events

Object-Oriented Event Handling Older methods prone to programmer error Older methods prone to programmer error OO languages more naturally handle passing messages between independent objects OO languages more naturally handle passing messages between independent objects Basis for NeXTStep, Mac App, Visual C++, Java Basis for NeXTStep, Mac App, Visual C++, Java

Object-Oriented Event Loop Tool kit defines an application class Tool kit defines an application class –provides a run method which contains event loop –technique used by Visual C++ and MacApp Application myApp; Intialize windows & application data structures Set any special event masks by sending messages to myApp myApp.Run();

Dispatching Events If user scrolls the text, the software must: If user scrolls the text, the software must: –direct the mouse events to the scroll bar –update the scroll bar display during the drag –notify the text editing window it needs to scroll itself so that the text appears to have moved

Dispatching Events (cont.) Algorithm selects the bottom-most, front- most region in the interactor tree Algorithm selects the bottom-most, front- most region in the interactor tree –scroll bar or contents over outerwin (bottom- most) –scroll bar over contents (front-most) –each window need only consider its own events –difficult to impose a high level of control –known as bottom-first event dispatch Top-down event dispatch Top-down event dispatch –events passed to top-most, front-most window –it dispatches to one or more of its children...

Event Focus Where should keyboard events go? Where should keyboard events go? –mouse-based attach mouse position to all key events and dispatch events in the same way as mouse events –click-to-type (Mac) send all key events to last window where mouse down occurred key focus –windows take and give away keyboard focus Mouse focus Mouse focus –long narrow scrollbar...

Simple Event Handling Event tables (in the early days…) Event tables (in the early days…) –indexed by event types (integer from ) –holds pointers to functions that handle each event –one table per / window –lots of things to maintain when attached to a widget that you want to make reusable Callbacks Callbacks –separate things like labels/colors into resources read from files –each kind of widget defines a set of named callbacks which it will invoke

Callback Example How do we notify text window to scroll when the scroll bar is moved? How do we notify text window to scroll when the scroll bar is moved? –create a vertical scroll bar widget –write a callback procedure which has code to notify text windows of their new position –register callback with scroll bar as callback to invoke when the scroll bar is moved –also register a pointer to the text window as the callback data  knows which window to scroll

Simple Event Handling (cont.) WindowProc style (MS Windows) WindowProc style (MS Windows) –newer and better than older models –define window classes, each of which have a WindowProc (similar to callback) –whenever event dispatch algorithm identifies a window that should receive an event, that window’s WindowProc is invoked –body of WindowProc is a switch on the event type with a handler for each event –100s of events, but most is inherited/delegated

Summary Windowing systems Windowing systems –special problems with networked WS Interactor trees Interactor trees Input events Input events Main event loop Main event loop Dispatching events Dispatching events Event focus Event focus Simple event handling Simple event handling