Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup www.stroustrup.com/Programming.

Slides:



Advertisements
Similar presentations
CSWA Provider: Program and Tech Review
Advertisements

Module 1: BLOCK 1 / MAIN MENU
1 Application Software Course Simulink By: Mahdi Akbari 2010.
Chapter 16 Graphical User Interfaces
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
1 Copyright © 2002 Pearson Education, Inc.. 2 Chapter 2 Getting Started.
Copyright © 2003 Pearson Education, Inc. Slide 1.
BASIC SKILLS AND TOOLS USING ACCESS
Introduction to Metview
Microsoft Access 2007 Advanced Level. © Cheltenham Courseware Pty. Ltd. Slide No 2 Forms Customisation.
Mike Scott University of Texas at Austin
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.
6. WinForms: GUI Programming in.NET. 2 Microsoft Objectives.NET supports two types of form-based apps, WinForms and WebForms. WinForms are the traditional,
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.
1 NatQuery 3/05 An End-User Perspective On Using NatQuery To Extract Data From ADABAS Presented by Treehouse Software, Inc.
PEPS Weekly Data Extracts User Guide September 2006.
Microsoft Access.
LFCDS SkyMail & SkyDrive Full Student Orientation
First Steps using AutoDESK Inventor
INTRODUCTION Lesson 1 – Microsoft Word Word Basics
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.
Microsoft Office Word is an example of ____ software. a. Database b
Chapter 11: The X Window System Guide To UNIX Using Linux Third Edition.
Benchmark Series Microsoft Excel 2013 Level 2
COMPUTER INTERFACES.
Services Course Outlook Live Participant Guide.
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
Services Course Windows Live SkyDrive Participant Guide.
1 How Do I Order From.decimal? Rev 05/04/09 This instructional training document may be updated at anytime. Please visit and check the.
Macromedia Dreamweaver MX 2004 – Design Professional Dreamweaver GETTING STARTED WITH.
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
2004 EBSCO Publishing Presentation on EBSCOadmin.
Chapter 9 Interactive Multimedia Authoring with Flash Introduction to Programming 1.
Chapter 12 Working with Forms Principles of Web Design, 4 th Edition.
Chapters 12 and 13 A Display Model and Graphics Classes John Keyser’s Modifications of Slides by Bjarne Stroustrup
Chapter 15 Functions and graphing John Keyser’s Modification of Slides by Bjarne Stroustrup
PSSA Preparation.
© Paradigm Publishing, Inc Excel 2013 Level 2 Unit 2Managing and Integrating Data and the Excel Environment Chapter 6Protecting and Sharing Workbooks.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Developing a Simple Graphical User Interface (GUI)
Chapter 8 Improving the User Interface
What’s new in WebSpace Changes and improvements with Xythos 7.2 Effective June 24,
Chapter 9: Using Classes and Objects. Understanding Class Concepts Types of classes – Classes that are only application programs with a Main() method.
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 –
Not in Text CP212 Winter No VBA Required “Regular” Programming traditional programming is sequential in nature o one command executed after another.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Introduction to Matlab & Data Analysis
FLTK Help Session By Richard Yu Gu CS 638 -Graphics Fall, 1999.
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 15: GUIs 1.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
EGR 115 Introduction to Computing for Engineers
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Event loops 16-Jun-18.
Event loops.
GRAPHICAL USER INTERFACE
Event loops 17-Jan-19.
Event loops 17-Jan-19.
Chapter 16 Graphical User Interfaces
Chapter 16 Graphical User Interfaces
Event loops 8-Apr-19.
Chapter 16 Graphical User Interfaces
Event loops.
Event loops 19-Aug-19.
Presentation transcript:

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

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

I/O alternatives Use console input and output – 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) 3Stroustrup/Programming

Common GUI tasks Titles / Text – 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. 4Stroustrup/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 5Stroustrup/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 6Stroustrup/Programming

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

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

GUI example Enter a point in the In_boxes 9Stroustrup/Programming

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

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

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

GUI example And so on, until you hit Quit. 13Stroustrup/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? 14Stroustrup/Programming

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

Our Code Window Setup Code Callback Handling Code How it works A bit more detail… 16 Window FLTK Attach Button Describe where the button is Describe what the button looks like Register Button’s callback Call “callback” when Button is pressed Stroustrup/Programming

Initial Setup/Programming Program Sets up Window/Layouts Program sets up Callback Functions

System Runs: Startup Main Program Executes: Program Sets up Window/Layouts Program sets up Callback Functions Callbacks are registered Window is Created WINDOW

System Runs Begin Loop Main Program: Infinite Loop Window/Layouts Callback Functions WINDOW

System Runs User Interacts Main Program: Infinite Loop Window/Layouts Callback Functions WINDOW User Interacts With Widget in Window

System Runs Callback is Made Main Program: Window/Layouts Callback Functions WINDOW User Interacts With Widget in Window Main Program Calls Appropriate Callback

System Runs Callback Executes Main Program: Window/Layouts Callback Functions WINDOW Main Program Calls Appropriate Callback Callback Function Executes

System Runs Callback Finishes Main Program: Window/Layouts Callback Functions WINDOW Main Program Calls Appropriate Callback Callback Function Finishes

System Runs See Results Main Program: Window/Layouts Callback Functions WINDOW Main Program Updates Window

System Runs Return to Loop Main Program: Infinite Loop Window/Layouts Callback Functions WINDOW

Mapping We map our ideas onto the FTLK version of the conventional Graphics/GUI ideas 26Stroustrup/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 }; 27Stroustrup/Programming

GUI example Window with – two Buttons, two In_boxes, and an Out_box 28Stroustrup/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 } 29Stroustrup/Programming

30 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

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) 31Stroustrup/Programming

GUI example Add another point and you have a line 32Stroustrup/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” by Microsoft) 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 … }; 33Stroustrup/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) { } }; 34Stroustrup/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++ 35Stroustrup/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 (pw).quit();// now call our function } 36 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” } 37Stroustrup/Programming

The next point function // our action for a click (“push”) on the next point 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 } 38Stroustrup/Programming

In_box // An In_box is a widget into which you can type characters // Its “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 (pw); // use it: return atoi(pi.value()); // get the value and convert // it from characters (alpha) to int } 39Stroustrup/Programming

Control Inversion But where is the program? – Our code just responds to the user clicking on our widgets – No loops? No if-then-else? “The program” is simply int main () { Lines_window win(Point(100,100),600,400,”lines”); return gui_main();// an “infinite loop” } Stroustrup/Programming40

Control Inversion Stroustrup/Programming41 Application Input function User “action” User responds System Application call prompt click callback

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 42Stroustrup/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. 43Stroustrup/Programming