Chapter 16 Graphical User Interfaces

Slides:



Advertisements
Similar presentations
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Getting Started with Java.
Advertisements

You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
CSWA Provider: Program and Tech Review
1 Application Software Course Simulink By: Mahdi Akbari 2010.
1. XP 2 * The Web is a collection of files that reside on computers, called Web servers. * Web servers are connected to each other through the Internet.
Chapter 15 Functions and graphing Bjarne Stroustrup
Chapter 12 A display model Bjarne Stroustrup
Chapter 13 Graphics classes Bjarne Stroustrup
Chapter 14 Graph class design Bjarne Stroustrup
Chapter 9 Technicalities: Classes, etc. Bjarne Stroustrup
BASIC SKILLS AND TOOLS USING ACCESS
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
Introduction to Metview
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Excel PivotTable List Feature Creating a PivotTable List Web Page Using Excel.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Determine Eligibility Chapter 4. Determine Eligibility 4-2 Objectives Search for Customer on database Enter application signed date and eligibility determination.
Mike Scott University of Texas at Austin
Word Lesson 6 Working with Graphics
Office 2003 Introductory Concepts and Techniques M i c r o s o f t Windows XP Project An Introduction to Microsoft Windows XP and Office 2003.
View-Based Application Development Lecture 1 1. Flows of Lecture 1 Before Lab Introduction to the Game to be developed in this workshop Comparison between.
Integrify 5.0 Tutorial : Creating a New Process
Microsoft Office 2010 Basics and the Internet
Variables Conditionals Boolean Expressions Conditional Statements How a program produces different results based on varying circumstances if, else if,
Course Registration Overrides SLCM_WP_220 1SLCM_WP_220 Overrides.
How To Use Google Forms to Create A Test Quick Easy Self-Graded!! Instant Reports.
ABC Technology Project
1 Web-Enabled Decision Support Systems Access Introduction: Touring Access Prof. Name Position (123) University Name.
Microsoft Access.
Review Chapter 11 - Tables © 2010, 2006 South-Western, Cengage Learning.
1 1 Mechanical Design and Production Dept, Faculty of Engineering, Zagazig University, Egypt. Mechanical Design and Production Dept, Faculty of Engineering,
Well-Being Icon Refer to Slide 2 for instructions on how to view the full-screen slideshow.Slide 2.
1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
XP New Perspectives on Introducing Microsoft Office 2003 Tutorial 1 1 Using Common Features of Microsoft Office 2003 Tutorial 1.
Office 2003 Introductory Concepts and Techniques M i c r o s o f t Office 2003 Integration Integrating Office 2003 Applications and the World Wide Web.
Pasewark & Pasewark Microsoft Office 2003 : Introductory 1 INTRODUCTORY MICROSOFT WORD Lesson 4 – Formatting Text.
Microsoft Office Illustrated Fundamentals Unit C: Getting Started with Unit C: Getting Started with Microsoft Office 2010 Microsoft Office 2010.
Chapter 11: The X Window System Guide To UNIX Using Linux Third Edition.
Progam.-(6)* Write a program to Display series of Leaner, Even and odd using by LOOP command and Direct Offset address. Design by : sir Masood.
COMPUTER INTERFACES.
1 Welcome to SAPS Webmail. 2 Things we will learn about: 1. Login to mail.
Adobe InDesign CS5 - Illustrated Unit F: Working with Layers
Lab # 03- SS Basic Graphic Commands. Lab Objectives: To understand M-files principle. To plot multiple plots on a single graph. To use different parameters.
Macromedia Dreamweaver MX 2004 – Design Professional Dreamweaver GETTING STARTED WITH.
CIS67 Foundations for Creating Web Pages Professor Al Fichera Rev. September 22, 2010—All HTML code brought to XHTML standards. Reference for CIS127 and.
Pasewark & Pasewark Microsoft Office XP: Introductory Course 1 INTRODUCTORY MICROSOFT WORD Lesson 8 – Increasing Efficiency Using Word.
25 seconds left…...
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
® Microsoft Office 2010 Browser and Basics.
Week 10 Creating Positioned Layouts
We will resume in: 25 Minutes.
Chapter 12 Working with Forms Principles of Web Design, 4 th Edition.
Excel Lesson 12 Creating PivotTables and PivotCharts Microsoft Office 2010 Advanced Cable / Morrison 1.
Chapters 12 and 13 A Display Model and Graphics Classes John Keyser’s Modifications of Slides by Bjarne Stroustrup
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Developing a Simple Graphical User Interface (GUI)
Chapter 8 Improving the User Interface
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
HTML Concepts and Techniques Fourth Edition Project 2 Creating and Editing a Web Page.
Chapter 14 Graph class design John Keyser’s Modifications of Slides by Bjarne Stroustrup
Graphical User Interfaces A Quick Outlook. Interface Many methods to create and “interface” with the user 2 most common interface methods: – Console –
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
FLTK Help Session By Richard Yu Gu CS 638 -Graphics Fall, 1999.
CSCE 121: Introduction to Program Design and Concepts Dr. J. Michael Moore Spring 2015 Set 12: A Display Model 1 Based on slides created by Bjarne.
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 15: GUIs 1.
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
GRAPHICAL USER INTERFACE
Chapter 16 Graphical User Interfaces
Chapter 16 Graphical User Interfaces
Chapter 16 Graphical User Interfaces
Presentation transcript:

Chapter 16 Graphical User Interfaces Bjarne Stroustrup www.stroustrup.com/Programming

Overview Perspective GUI example GUI code I/O alternatives GUI Layers of software GUI example GUI code callbacks Stroustrup/Programming

I/O alternatives Use console input and output Graphic User Interface A strong contender for technical/professional work Command line interface Menu driven interface Graphic User Interface Use a GUI Library To match the “feel” of windows/Mac applications When you need drag and drop, WYSIWYG Event driven program design A web browser – this is a GUI library application HTML / a scripting language For remote access (and more) Stroustrup/Programming

Common GUI tasks Titles / Text Fields / Dialog boxes Buttons Names Prompts User instructions Fields / Dialog boxes Input Output Buttons Let the user initiate actions Let the user select among a set of alternatives e.g. yes/no, blue/green/red, etc. Stroustrup/Programming

Common GUI tasks (cont.) Display results Shapes Text and numbers Make a window “look right” Style and color Note: our windows look different (and appropriate) on different systems More advanced Tracking the mouse Dragging and dropping Free-hand drawing Stroustrup/Programming

GUI From a programming point of view GUI is based on two techniques Object-oriented programming For organizing program parts with common interfaces and common actions Events For connecting an event (like a mouse click) with a program action Stroustrup/Programming

Layers of software When we build software, we usually build upon existing code Example of a layer Provides services Uses services Our program Our GUI/Graphics interface library FLTK The operating system Graphics GUI facilities Device driver layer Stroustrup/Programming

GUI example Window with two Buttons, Two In_boxes, and an Out_box Stroustrup/Programming

GUI example Enter a point in the In_boxes Stroustrup/Programming

GUI example When you hit next point that point becomes the current (x,y) and is displayed in the Out_box Stroustrup/Programming

GUI example Add another point an you have a line Stroustrup/Programming

GUI example Three points give two lines Obviously, we are building a polyline Stroustrup/Programming

GUI example And so on, until you hit Quit. Stroustrup/Programming

So what? And How? We saw buttons, input boxes and an outbox in a window How do we define a window? How do we define buttons? How do we define input and output boxes? Click on a button and something happens How do we program that action? How do we connect our code to the button? You type something into a input box How do we get that value into our code? How do we convert from a string to numbers? We saw output in the output box How do we get the values there? Lines appeared in our window How do we store the lines? How do we draw them? Stroustrup/Programming

Mapping We map our ideas onto the FTLK version of the conventional Graphics/GUI ideas Stroustrup/Programming

Define class Lines_window struct Lines_window : Window // Lines_window inherits from Window { Lines_window(Point xy, int w, int h, const string& title); // declare constructor Open_polyline lines; private: Button next_button; // declare some buttons – type Button Button quit_button; In_box next_x; // declare some i/o boxes In_box next_y; Out_box xy_out; void next(); // what to do when next_button is pushed void quit(); // what to do when quit_botton is pushed static void cb_next(Address, Address window); // callback for next_button static void cb_quit(Address, Address window); // callback for quit_button }; Stroustrup/Programming

GUI example Window with two Buttons, Two In_boxes, and an Out_box Stroustrup/Programming

The Lines_window constructor Lines_window::Lines_window(Point xy, int w, int h, const string& title) :Window(xy,w,h,title), // construct/initialize the parts of the window: // location size name action next_button(Point(x_max()-150,0), 70, 20, "Next point", cb_next), quit_button(Point(x_max()-70,0), 70, 20, "Quit", cb_quit), // quit button next_x(Point(x_max()-310,0), 50, 20, "next x:"), // io boxes next_y(Point(x_max()-210,0), 50, 20, "next y:"), xy_out(Point(100,0), 100, 20, "current (x,y):") { attach(next_button); // attach the parts to the window attach(quit_button); attach(next_x); attach(next_y); attach(xy_out); attach(lines); // attach the open_polylines to the window } Stroustrup/Programming

Widgets, Buttons, and Callbacks A Widget is something you see in the window which has an action associated with it A Button is a Widget that displays as a labeled rectangle on the screen, and when you click on the button, a Callback is triggered A Callback connects the button to some function or functions (the action to be performed) Stroustrup/Programming

Widgets, Buttons, and Callbacks // A widget is something you see in the window // which has an action associated with it // A Button is a Widget that displays as a labeled rectangle on the screen; // when you click on the button, a Callback is triggered // A Callback connects the button to some function struct Button : Widget { Button(Point xy, int w, int h, const string& s, Callback cb) :Widget(xy,w,h,s,cb) { } }; Stroustrup/Programming

How it works Window Our code FLTK Describe where the button is Describe what the button looks like Register Button’s callback Attach Button Our code FLTK Call “callback” when Button is pressed Stroustrup/Programming

GUI example Add another point an you have a line Stroustrup/Programming

Widget A basic concept in Windows and X windows systems Basically anything you can see on the screen and do something with is a widget (also called a "control") struct Widget { Widget(Point xy, int w, int h, const string& s, Callback cb) :loc(xy), width(w), height(h), label(s), do_it(cb) { } // … connection to FLTK … }; Stroustrup/Programming

Button A Button is a Widget that displays as a labeled rectangle on the screen; when you click on it, a Callback is triggered struct Button : Widget { Button(Point xy, int w, int h, const string& s, Callback cb) :Widget(xy,w,h,s,cb) { } }; Stroustrup/Programming

Callback Callbacks are part of our interface to “The system” Connecting functions to widgets is messy in most GUIs It need not be, but “the system” does not “know about” C++ the style/mess comes from systems designed in/for C/assembler Major systems always use many languages, this is one example of how to cross a language barrier A callback function maps from system conventions back to C++ void Lines_window::cb_quit(Address, Address pw) // Call Lines_window::quit() for the window located at address pw { reference_to<Lines_window>(pw).quit(); // now call our function } Map an address into a reference to the type of object residing at that address – to be explained the following chapters Stroustrup/Programming

Our “action” code // The action itself is simple enough to write void Lines_window::quit() { // here we can do just about anything with the Lines_window hide(); // peculiar FLTK idiom for “get rid of this window” } Stroustrup/Programming

The next function // our action for a click (“push”) on the next button void Lines_window::next() { int x = next_x.get_int(); int y = next_y.get_int(); lines.add(Point(x,y)); // update current position readout: stringstream ss; ss << '(' << x << ',' << y << ')'; xy_out.put(ss.str()); redraw(); // now redraw the screen } Stroustrup/Programming

In_box // An In_box is a widget into which you can type characters // It’s “action” is to receive characters struct In_box : Widget { In_box(Point xy, int w, int h, const string& s) :Widget(xy,w,h,s,0) { } int get_int(); string get_string(); }; int In_box::get_int() { // get a reference to the FLTK FL_Input widget: Fl_Input& pi = reference_to<Fl_Input>(pw); // use it: return atoi(pi.value()); // get the value and convert // it from characters (alpha) to int } Stroustrup/Programming

Summary We have seen Action on buttons Interactive I/O Text input Text output Graphical output Missing Menu (See Section 16.7) Window and Widget (see Appendix E) Anything to do with tracking the mouse Dragging Hovering Free-hand drawing What we haven’t shown, you can pick up if you need it Stroustrup/Programming

Next lecture The next three lectures will show how the standard vector is implemented using basic low-level language facilities. This is where we really get down to the hardware and work our way back up to a more comfortable and productive level of programming. Stroustrup/Programming