Chapter 16 Graphical User Interfaces

Similar documents
Chapter 16 Graphical User Interfaces

Chapter 13 Graphics classes

Chapter 12 A display model

Chapter 13 Graphics Classes

Chapter 13 Graphics classes. Bjarne Stroustrup

Graphical Interface Object Oriented Programming

Chapter 17 vector and Free Store

Vector and Free Store (Pointers and Memory Allocation)

Chapter 12 A display model

Chapter 12 A display model

Chapter 4 Computation

And Even More and More C++ Fundamentals of Computer Science

PTN-202: Advanced Python Programming Course Description. Course Outline

Chapter 7 Applets. Answers

Programming: Practice and Core Guidelines

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi

OpenGL and Qt Creator: a Gentle Introduction

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Java Object Oriented Design. CSC207 Fall 2014

Welcome to Lab! Feel free to get started until we start talking! The lab document is located on the course website:

Introduction to C++ with content from

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Intermediate Python 3.x

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011

ICS Tutorials: Basic Operations

CMPT 117: Tutorial 1. Craig Thompson. 12 January 2009

Fall UI Design and Implementation 1

Programming. Principles and Practice Using C++ Bjarne Stroustrup. / Addison-Wesley. Second Edition

Topic 7: Algebraic Data Types

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Generating Vectors Overview

Creating a nice GUI. OpenGL and Windows. Note: VS 2003 shown. Create a new Project

Working with Batches of Data

CS 4300 Computer Graphics

CSE 331 Software Design & Implementation

CS 160: Interactive Programming

JavaScript: the language of browser interactions. Claudia Hauff TI1506: Web and Database Technology

EXAM Microsoft MTA Software Development Fundamentals. Buy Full Product.

CSE 331 Software Design and Implementation. Lecture 17 Events, Listeners, Callbacks

Chapter 17 vector and Free Store

The vector Class and Memory Management Chapter 17. Bjarne Stroustrup Lawrence "Pete" Petersen Walter Daugherity Fall 2007

Implementing vector<>

UI Toolkits. HCID 520 User Interface Software & Technology

EL2310 Scientific Programming

Lecture 19 GUI Events

CSE 331 Software Design and Implementation. Lecture 16 Callbacks and Observers

Center for Advanced Research in Drying WordPress Manual

OhioState::OpenGLPanel. OpenGL and Windows. Public methods. OpenGLPanel : Forms::Control

Hanley s Survival Guide for Visual Applications with NetBeans 2.0 Last Updated: 5/20/2015 TABLE OF CONTENTS

Autodesk Fusion 360: Model. Overview. Modeling techniques in Fusion 360

Visual Dialogue User Guide. Version 6.0

Smoother Graphics Taking Control of Painting the Screen

Asynchronous Programming

G52CPP C++ Programming Lecture 12

HBS Training - IT Solutions. PlanWeb. Introduction

Review for Final Exam Chapters 1 20 ( Programming and C++ in 75 minutes ) Bjarne Stroustrup Ronnie Ward

Quick Tips to Using I-DEAS. Learn about:

UI Toolkits. HCID 520 User Interface Software & Technology

CSE 331 Software Design & Implementation

Windows and Events. created originally by Brian Bailey

Prototyping a Swing Interface with the Netbeans IDE GUI Editor

Ali Malik Handout 12 CS106L Winter 2018 Jan 30th, C++ Reference

Coursework Lab A. Open the coursework project

EVENT-DRIVEN PROGRAMMING

Introduction. Create a New Project. Create the Main Form. Assignment 1 Lights Out! in C# GUI Programming 10 points

Tableau Tutorial Using Canadian Arms Sales Data

Chapter 9 Technicalities: Classes, etc.

Chapter 6 Introduction to Defining Classes

Namespaces and Class Hierarchies

Chapter 17 vector and Free Store. Bjarne Stroustrup

Digitizer Leapfrogging

Chapter 8. Implementation Support

Organization of User Interface Software

Welcome to Lab! You do not need to keep the same partner from last lab. We will come around checking your prelabs after we introduce the lab

PROGRAMMING LANGUAGE 2

Grade: 7 Lesson name: Creating a School News Letter Microsoft Word 2007

CS61B Lecture #13: Packages, Access, Etc.

CS260. UI Toolkits. Björn Hartmann University of California, Berkeley EECS, Computer Science Division Fall 2010

CS61B Lecture #13: Packages, Access, Etc.

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Central Bucks School District 6 th Grade Assessment Presentation Rubric

Inheritance, and Polymorphism.

City of Richmond Interactive Map (RIM) User Guide for the Public

Click the buttons in the interactive below to become familiar with the drawing tool's commands.

CSE 331 Software Design and Implementation. Lecture 19 GUI Events

Stroustrup Default comparisons N4175. Default comparisons. Bjarne Stroustrup

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

Multimedia-Programmierung Übung 3

Bouml Tutorial. The tutorial must be read in order because I will not repeat each time the general commands to call a menu etc...

EXCEL + POWERPOINT. Analyzing, Visualizing, and Presenting Data-Rich Insights to Any Audience KNACK TRAINING

stanford hci group / cs376 UI Software Tools Scott Klemmer 14 October research topics in human-computer interaction

UI Software Organization

Widgets. Widgets Widget Toolkits. User Interface Widget

CHAPTER 1 COPYRIGHTED MATERIAL. Finding Your Way in the Inventor Interface

6.S096 Lecture 10 Course Recap, Interviews, Advanced Topics

Apple Modelling Tutorial

Exercises Lecture 3 Layouts and widgets

IBM WebSphere Lombardi Edition 7.2 Business Process Management Workshop

G52CPP C++ Programming Lecture 10. Dr Jason Atkin

Tutorial Corner: Attack of the Clones. Tutorial Corner: Attack of the Clones. Anything but Lutfisk

Transcription:

Chapter 16 Graphical User Interfaces Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/~hkaiser/fall_2010/csc1253.html Slides adapted from: Bjarne Stroustrup, Programming Principles and Practice using C++

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

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

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. 4

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 5

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 6

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

GUI example Window with two Buttons, Two In_boxes, and an Out_box 8

GUI example Enter a point in the In_boxes 9

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

GUI example Add another point an you have a line 11

GUI example Three points give two lines Obviously, we are building a polyline 12

GUI example And so on, until you hit Quit. 13

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? 14

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

Define the struct 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; Button quit_button; In_box next_x; In_box next_y; Out_box xy_out; void next(); void quit(); // declare some buttons type Button // declare some i/o boxes // what to do when next_button is pushed // what to do when quit_botton is pushed }; static void cb_next(address, Address window); static void cb_quit(address, Address window); // callback for next_button // callback for quit_button 17

GUI example Window with two Buttons, Two In_boxes, and an Out_box 18

The 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 } 19

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

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) { } }; 21

How it works Describe where the button is Window Describe what the button looks like Register Button s callback Attach Button Our code FLTK Call callback when Button is pressed 22

GUI example Add another point an you have a line 23

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 }; 24

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) { } }; 25

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 } 26 Map an address into a reference to the type of object residing at that address to be explained the following chapters

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 } 27

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 } 28

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 29

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 30

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. 31