Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 12 A display model Hartmut Kaiser

Slides:



Advertisements
Similar presentations
Chapter 16 Graphical User Interfaces
Advertisements

Chapter 15 Functions and graphing Bjarne Stroustrup
Chapter 12 A display model Bjarne Stroustrup
Chapter 8 Technicalities: Functions, etc. Bjarne Stroustrup
Chapter 13 Graphics classes Bjarne Stroustrup
Chapter 14 Graph class design Bjarne Stroustrup
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
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
Chapter 14 Graph class design John Keyser’s Modifications of Slides by Bjarne Stroustrup
UEC 01 : Computer Skills & Programming Concepts I 1PUA – Computer Engineering Department – UEC01 – Dr. Mona Abou - Of Lecture 10: Presentation Graphic.
Go through this show in OpenOffice Impress by using the right scrollbar or clicking individual slide thumbnails on the left side. This hands-on demo is.
1 The MITRE Using XSLT and XPath to Generate SVG Roger L. Costello XML Technologies.
© by Pearson Education, Inc. All Rights Reserved. continued …
A Simple Applet.
1 Python Programming: An Introduction to Computer Science Chapter 3 Objects and Graphics.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
DIGITAL GRAPHICS & ANIMATION
Academic Computing Services 2010 Microsoft ® Office Visio ® 2007 Training Get to know Visio.
Graphical User Interfaces A Quick Outlook. Interface Many methods to create and “interface” with the user 2 most common interface methods: – Console –
By: Zaiba Mustafa Copyright ©
Desktop Publishing Features Designing Documents. Publication Terms  Graphics - Objects used to convey a message.  Multiple Columns - Layout used to.
1 Word Lesson 4 Working with Graphic Objects Microsoft Office 2010 Fundamentals Story / Walls.
1 Bitmap Graphics It is represented by a dot pattern in which each dot is called a pixel. Each pixel can be in any one of the colors available and the.
Microsoft Office Illustrated Fundamentals
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 14 Graphics class design Hartmut Kaiser
1 Using XSLT and XPath to Generate SVG Roger L. Costello XML Technologies.
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 12 A display model Hartmut Kaiser
Introduction to Scratch!
Microsoft PowerPoint Getting Started Guide Prepared for Towson University Dr. Jeff M. Kenton Amy Chase Martin 2007.
IE 411/511: Visual Programming for Industrial Applications
Ranjeet Department of Physics & Astrophysics University of Delhi Working with Origin.
Chapter 13 Graphics classes Bjarne Stroustrup
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
© 2011 Delmar, Cengage Learning Chapter 1 Getting to Know Illustrator.
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.
Learning Unity. Getting Unity
1 Chapter 12 GUI C/C++ Language Programming Wanxiang Che.
Android Graphics Library. Color Android colors are represented with four numbers, one each for alpha, red, green, and blue (ARGB). Each component can.
Creating HUD Rings. Step 1 Open a new document in Illustrator. You can set it to the size you prefer to work in. In my case I have it set at 500px by.
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
PowerPoint Basics Tutorial 1: Objects These tutorials will introduce you to the most basic and useful functions of Microsoft PowerPoint We’re going.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 6 Writing a Program Hartmut Kaiser
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
Chapter 14 Graph class design Bjarne Stroustrup
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 13 Graphics classes Hartmut Kaiser
Chapter 14 Graph class design Bjarne Stroustrup
Review for Final Exam Chapters 1–14,16,17-19 Bjarne Stroustrup
Illustrator For illustrations. Vector Graphics  Can resize shapes without losing quality  Place dots ( anchor points )  Connect the dots with paths.
5. COMPUTING WITH GRAPHICS OBJECTS Dennis Y. W. Liu and Rocky K. C. Chang October 8, 2015 (Adapted from John Zelle’s slides)
CIS 205—Web Design & Development Flash Chapter 3 Working with Symbols and Interactivity.
Main characteristics of Vector graphics  Vector graphics provide an elegant way of constructing digital images (diagrams, technical illustration and.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
Graphics CIS 40 – Introduction to Programming in Python
Python: Simple Graphics and Event-driven Programming
Chapter 3:- Graphics Eyad Alshareef Eyad Alshareef.
Building Java Programs
Chapter 13 Graphics classes
Chapter 13 Graphics classes
Desktop Publishing Features
Chapter 12 A display model
Chapter 16 Graphical User Interfaces
Chapter 16 Graphical User Interfaces
LING 408/508: Computational Techniques for Linguists
Graphics and FLTK CSCE 121 J. Michael Moore
Chapter 16 Graphical User Interfaces
Microsoft Office Illustrated Fundamentals
Presentation transcript:

Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 12 A display model Hartmut Kaiser

Abstract This lecture presents a display model (the output part of a GUI), giving examples of use and fundamental notions such as screen coordinates, lines, and color. Some examples of shapes are Lines, Polygons, Axis, and Text. 2 March 17th, 2011 CSC1253, Spring 2011, L16

Overview Why graphics? A graphics model Examples 3 March 17th, 2011 CSC1253, Spring 2011, L16

Why bother with graphics and GUI? It’s very common If you write conventional PC applications, you’ll have to do it It’s useful Instant feedback Graphing functions Displaying results It can illustrate some generally useful concepts and techniques 4 March 17th, 2011 CSC1253, Spring 2011, L16

Why bother with graphics and GUI? It can only be done well using some pretty neat language features Lots of good (small) code examples It can be non-trivial to “get” the key concepts So it’s worth teaching If we don’t show how it’s done, you might think it was “magic” Graphics is fun! 5 March 17th, 2011 CSC1253, Spring 2011, L16

Why Graphics/GUI? WYSIWYG What you see (in your code) is what you get (on your screen) Direct correspondence between concepts, code, and output 6 March 17th, 2011 CSC1253, Spring 2011, L16

Display model Objects (such as graphs) are “attached to” a window. The “display engine” invokes display commands (such as “draw line from x to y”) for the objects in a window Objects such as Square contain vectors of lines, text, etc. for the window to draw 7 March 17th, 2011 CSC1253, Spring 2011, L16 Shape Square “window” Display Engine attach() draw()

Display model An example illustrating the display model int main() { using namespace Graph_lib;// use our graphics interface library Point tl(100, 200);// a point (obviously) Simple_window win(tl, 600, 400, "Canvas"); // make a simple // window Polygon poly;// make a shape (a polygon, obviously) poly.add(Point(300, 200));// add three points poly.add(Point(350, 100)); poly.add(Point(400, 200)); poly.set_color(Color::red);// make the polygon red (obviously) win.attach(poly);// connect poly to the window win.wait_for_button();// give control to the display engine } 8 March 17th, 2011 CSC1253, Spring 2011, L16

The resulting screen 9 March 17th, 2011 CSC1253, Spring 2011, L16

Graphics/GUI Libraries You’ll be using a few interface classes we wrote Interfacing to a popular GUI toolkit GUI == Graphical User Interface FLTK: Fast Light Tool Kit, pronounced ‘FullTick’ Installation, etc. see Appendix D and ask instructor/friend FLTK Our GUI and graphics classes Project settings This model is far simpler than common toolkit interfaces The FLTK (very terse) documentation is 370 pages Our interface library is < 20 classes and < 500 lines of code You can write a lot of code with these classes And what you can build on them 10 March 17th, 2011 CSC1253, Spring 2011, L16

Graphics/GUI libraries (cont.) The code is portable Windows, Unix, Mac, etc. This model extends to most common graphics and GUI uses The general ideas can be used with any popular GUI toolkit Once you understand the graphics classes you can easily learn any GUI/graphics library Well, relatively easily – these libraries are huge 11 March 17th, 2011 CSC1253, Spring 2011, L16

Graphics/GUI libraries Often called “a layered architecture” 12 CSC1253, Spring 2011, L16 Our code The operating system (e.g. Windows or Linux) Our screen Our interface library A graphics/GUI library (here FLTK) March 17th, 2011

Coordinates Oddly, y-coordinates “grow downwards” // right, down Coordinates identify pixels in the window on the screen You can re-size a window (changing x_max() and y_max()) 13 March 17th, 2011 CSC1253, Spring 2011, L16 0,0 0, ,0 50,50 200,100

Interface classes An arrow means “is a kind of” Color, Line_style, and Point are “utility classes” used by the other classes Window is our interface to the GUI library (which is our interface to the screen) 14 March 17th, 2011 CSC1253, Spring 2011, L16 Window Simple_window Shape LinesPolygonRectangleText Point Color Line_style Line …

Interface classes Current Color, Line_style, Font, Point, Window, Simple_window Shape, Text, Polygon, Line, Lines, Rectangle, … Axis Easy to add (for some definition of “easy”) Grid, Block_chart, Pie_chart, etc. Later, GUI Button, In_box, Out_box, … 15 March 17th, 2011 CSC1253, Spring 2011, L16

Demo code 1 // Getting access to the graphics system (don’t forget to install): #include “Simple_window.h" // stuff to deal with your system’s // windows #include "Graph.h" // graphical shapes using namespace Graph_lib;// make names available // in main(): Simple_window win(Point(100,100), 600, 400, "Canvas"); // screen coordinate (100, 100) top left of window // window size(600*400) // title: Canvas win.wait_for_button();// Display! 16 March 17th, 2011 CSC1253, Spring 2011, L16

A “blank canvas” 17 March 17th, 2011 CSC1253, Spring 2011, L16

Demo code 2 Axis xa(Axis::x, Point(20, 300), 280, 10, "x axis"); // make an Axis // an axis is a kind of Shape // Axis::x means horizontal // starting at (20,300) // 280 pixels long // 10 “notches” // text “x axis win.set_label("Canvas #2"); win.attach(xa);// attach axis xa to the window win.wait_for_button(); 18 March 17th, 2011 CSC1253, Spring 2011, L16

Add an X-axis 19 March 17th, 2011 CSC1253, Spring 2011, L16

Demo code 3 win.set_label("Canvas #3"); Axis ya(Axis::y, Point(20, 300), 280, 10, "y axis"); ya.set_color(Color::cyan);// choose a color for the axis ya.label.set_color(Color::dark_red);// choose a color for the text win.attach(ya); win.wait_for_button(); 20 March 17th, 2011 CSC1253, Spring 2011, L16

Add a Y-axis (colored) 21 March 17th, 2011 CSC1253, Spring 2011, L16 Yes, it’s ugly, but this is a programming course, not a graphics design course

Demo code 4 win.set_label("Canvas #4"); Function sine(sin,0,100,Point(20,150),1000,50,50); // sine curve // plot sin() in the range [0:100) // with (0,0) at (20,150) // using 1000 points // scale x values *50, scale y values *50 win.attach(sine); win.wait_for_button(); 22 March 17th, 2011 CSC1253, Spring 2011, L16

Add a sine curve 23 March 17th, 2011 CSC1253, Spring 2011, L16

Demo code 5 win.set_label("Canvas #5"); sine.set_color(Color::blue);// I changed my mind about sine’s color Polygon poly;// a polygon, a Polygon is a kind of // Shape poly.add(Point(300,200));// three points makes a triangle poly.add(Point(350,100)); poly.add(Point(400,200)); poly.set_color(Color::red);// change the color poly.set_style(Line_style::dash);// change the line style win.attach(poly); win.wait_for_button(); 24 March 17th, 2011 CSC1253, Spring 2011, L16

Add a triangle (and color the curve) 25 March 17th, 2011 CSC1253, Spring 2011, L16

Demo code 6 win.set_label("Canvas #6"); Rectangle r(Point(200,200), 100, 50); win.attach(r); win.wait_for_button(); 26 March 17th, 2011 CSC1253, Spring 2011, L16

Add a rectangle 27 March 17th, 2011 CSC1253, Spring 2011, L16

Demo code 6.1 Add a shape that looks like a rectangle Closed_polyline poly_rect; poly_rect.add(Point(100,50)); poly_rect.add(Point(200,50)); poly_rect.add(Point(200,100)); poly_rect.add(Point(100,100)); win.set_label("Canvas #6.1"); 28 March 17th, 2011 CSC1253, Spring 2011, L16

Add a shape that looks like a rectangle 29 March 17th, 2011 CSC1253, Spring 2011, L16 But is it a rectangle?

Demo code 6.2 We can add a point poly_rect.add(Point(50,75));// now poly_rect has 5 points win.set_label("Canvas #6.2"); “looking like” is not the same as “is” 30 March 17th, 2011 CSC1253, Spring 2011, L16

Obviously a polygon 31 March 17th, 2011 CSC1253, Spring 2011, L16

Add fill r.set_fill_color(Color::yellow);// color the inside of the rectangle poly.set_style(Line_style(Line_style::dash,4)); // make the triangle fat poly_rect.set_fill_color(Color::green); poly_rect.set_style(Line_style(Line_style::dash,2)); win.set_label("Canvas #7"); 32 March 17th, 2011 CSC1253, Spring 2011, L16

Add fill 33 March 17th, 2011 CSC1253, Spring 2011, L16

Demo Code 8 Text t(Point(100,100),"Hello, graphical world!"); // add text win.set_label("Canvas #8"); 34 March 17th, 2011 CSC1253, Spring 2011, L16

Add text 35 March 17th, 2011 CSC1253, Spring 2011, L16

Demo Code 9 Modify text font and size t.set_font(Font::times_bold); t.set_font_size(20); 36 March 17th, 2011 CSC1253, Spring 2011, L16

Text font and size 37 March 17th, 2011 CSC1253, Spring 2011, L16

Add an image Image ii(Point(100,50),"image.jpg");// open an image file win.attach(ii); win.set_label("Canvas #10"); 38 March 17th, 2011 CSC1253, Spring 2011, L16

Add an image 39 March 17th, 2011 CSC1253, Spring 2011, L16

Oops! The image obscures the other shapes Move it a bit out of the way ii.move(100, 200); win.set_label("Canvas #11"); win.wait_for_button(); 40 March 17th, 2011 CSC1253, Spring 2011, L16

Move the image 41 March 17th, 2011 CSC1253, Spring 2011, L16 Note how the parts of a shape that don’t fit in the window is “clipped” away

Demo Code 12 Circle c(Point(100,200),50); Ellipse e(Point(100,200), 75,25); e.set_color(Color::dark_red); Mark m(Point(100,200),'x'); ostringstream oss; oss << "screen size: " << x_max() << "*" << y_max() << "; window size: " << win.x_max() << "*" << win.y_max(); Text sizes(Point(100,20),oss.str()); Image cal(Point(225,225),“snow_cpp.gif");// 320*240 pixel gif cal.set_mask(Point(40,40),200,150);// display center of // image win.set_label("Canvas #12"); win.wait_for_button(); 42 March 17th, 2011 CSC1253, Spring 2011, L16

Add shapes, more text 43 March 17th, 2011 CSC1253, Spring 2011, L16

Boiler plate #include "Graph.h"// header for graphs #include “Simple_window.h"// header containing window interface int main () try { // the main part of your code } catch(exception& e) { cerr << "exception: " << e.what() << '\n'; return 1; } catch (...) { cerr << "Some exception\n"; return 2; } 44 March 17th, 2011 CSC1253, Spring 2011, L16

Primitives and algorithms The demo shows the use of library primitives Just the primitives Just the use Typically what we display is the result of an algorithm reading data Next lectures 17: Graphics Classes 18: Graphics Class Design 19: Graphing Functions and Data 20: Graphical User Interfaces 45 March 17th, 2011 CSC1253, Spring 2011, L16