EzWindows API A Graphical Application Programmer Interface JPC and JWD © 2002 McGraw-Hill, Inc.

Slides:



Advertisements
Similar presentations
Games in Python – the easy way
Advertisements

What Was I Thinking??. Key Terms 1. Control 1. Control 2. Design Mode 2. Design Mode 3. Event 3. Event 4. Form 4. Form 5. Interface 5. Interface 6. Properties.
Microsoft® Small Basic
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
Object-Oriented programming in C++ Classes as units of encapsulation Information Hiding Inheritance polymorphism and dynamic dispatching Storage management.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
© by Pearson Education, Inc. All Rights Reserved. continued …
A graphical user interface (GUI) is a pictorial interface to a program. A good GUI can make programs easier to use by providing them with a consistent.
Chapter 1_2 Becoming Skilled at Information Technology.
Event Handling Events and Listeners Timers and Animation.
Based on slides created by Edward Angel
PictureBox, Timer, Resources. Resources An easy and effective way to add pictures (photos, graphics) to your programs Using Resources guarantees that.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Graphics and Multimedia In visual Studio. Net (C#)
Microsoft® Small Basic The Controls Object Estimated time to complete this lesson: 1 hour.
Chapter 5 - Making Music: An On-Screen Piano
Io package as Java’s basic I/O system continue’d.
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface A Brief Introduction to GDI+ S.R.G. Fraser, Pro Visual C++/CLI.
Java: Chapter 1 Computer Systems Computer Programming II.
J. P. Cohoon and J. W. Davidson © 1999 McGraw-Hill, Inc. Modifying objects Operators and Expressions.
Modifying objects Operators and Expressions JPC and JWD © 2002 McGraw-Hill, Inc.
EzWindows API A Graphical Application Programmer Interface JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S. Sudarshan.
How to create a Splash Screen in MS Access Carlos Coronel.
Graphics and Multimedia Part #2
B&W Default Settings Instructions for setting your Windows PC Ricoh printer default to B&W Click your mouse or press your “Down Arrow” key to advance Instructions.
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Visual Basic .NET BASICS
1Computer Graphics Input and Interaction Lecture 8 John Shearer Culture Lab – space 2
FLTK Help Session By Richard Yu Gu CS 638 -Graphics Fall, 1999.
Computer Graphics I, Fall 2010 Input and Interaction.
Lab 6: event & input intro User Interface Lab: GUI Lab Oct. 2 nd, 2013.
CS 480/680 Computer Graphics Programming with Open GL Part 7: Input and Interaction Dr. Frederick C Harris, Jr. Fall 2011.
CS350 – Windows Programming Formerly and more properly named: Event Driven Programming Dr. Randy Ribler.
Introduction to Windows Programming
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
1 Chapter 12 GUI C/C++ Language Programming Wanxiang Che.
CNS 1410 Graphical User Interfaces. Obectives Students should understand the difference between a procedural program and an Event Driven Program. Students.
Applications Development
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 9 GUI Programming Using Tkinter 1.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
Build-A-Button Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, October 8, 2003.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
Chapter 4 Introduction to Classes, Objects, Methods and strings
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
The Class Construct Defining objects with attributes and behavior JPC and JWD © 2002 McGraw-Hill, Inc.
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.
Registering a window class Windows allows many styles of window to be created. To tell Windows to create a window as you want it you need to define a class.
1 Input and Interaction. 2 Objectives Introduce the basic input devices ­Physical Devices ­Logical Devices ­Input Modes Event-driven input Introduce double.
University of New Mexico
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 2 – Welcome Application Introduction to Graphical.
Processing TYWu. Where can I download? 2.0b9 Windows 32-bit.
Resources & Bitmaps Adding clip art to your application.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
 You won’t write a single line of program code.  Instead, you’ll use visual programming techniques.  Visual Studio processes your actions (such as mouse.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Windows Programming Lecture 14. WM_PAINT message Whenever an application receives the WM_PAINT message, whether the entire window needs repainting? WM_PAINT.
CS345 – Event-driven Programming
Computer Graphics Lecture 3 Computer Graphics Hardware
Introduction to Event-Driven Programming
Review What is an object? What is a class?
CS1001 Programing Fundamental Lecture 14 HCI
Defining objects with attributes and behavior
Simple Windows Applications
Constructors, GUI’s(Using Swing) and ActionListner
Tonga Institute of Higher Education
A Graphical Application Programmer Interface
Presentation transcript:

EzWindows API A Graphical Application Programmer Interface JPC and JWD © 2002 McGraw-Hill, Inc.

Event-based Programming Messages are sent to your program by the operating system Mouse down Mouse up Key down Key up Refresh Quit Timer Handle messages by registering a call back

EzWindows Coordinate System Use centimeters Metric Simpler to understand than pixels Device independent Helps introduce notion of information hiding or encapsulation

Class Position For earlier objects, the position was specified by given both an x-coordinate and a y-coordinate We can now introduce a new object called Position and use it

Position class Position { public: Position(float x = 0.0, float y = 0.0); float GetXDistance() const; float GetYDistance() const; Position Add(const Position &p) const; protected: void SetXDistance(float x); void SetYDistance(float y); private: float XDistance; float YDistance; }; Position operator+(const Position &x, const Position &y);

EzWindows Auxiliary Functions long int GetMilliseconds() Returns the value of a timer that is ticking continuously. The resolution of the timer is milliseconds. void Terminate() Sends a terminate message to the EzWindows window manager.

Class SimpleWindow Writing text in a window void SimpleWindow::RenderText(const Position &UpperLeft, const Position &LowerRight, const string &Msg = "Message", const color &TextColor = Black, const color &BackGroundColor = White)

Hello EzWindows #include #include "ezwin.h" // Create a 10 x 4 window SimpleWindow HelloWindow("Hello EzWindows", 10.0, 4.0, Position(5.0, 6.0)); // ApiMain(): create a window and display greeting int ApiMain() { HelloWindow.Open(); assert(HelloWindow.GetStatus() == WindowOpen); // Get Center of Window Position Center = HelloWindow.GetCenter();

Hello EzWindows // Create bounding box for text Position UpperLeft = Center + Position(-1.0, -1.0); Position LowerRight = Center + Position(1.0, 1.0); // Display the text HelloWindow.RenderText(UpperLeft, LowerRight, "Hello EzWindows", Black, White); return 0; }

Hello EzWindows // ApiEnd(): shutdown the window int ApiEnd() { HelloWindow.Close(); return 0; }

Class SimpleWindow Simple Window constructor SimpleWindow::SimpleWindow( const string &t = "Untitled“ float w = 8, float h = 8, const Position &p = Position(0,0) )

Bitmaps

Class BitMap Uses BitMapStatus enum BitMapStatus { NoBitMap, BitMapOkay, NoWindow };

Class BitMap Class BitMap can display.bmp files in a SimpleWindow window BitMap’s constructor is BitMap::BitMap(SimpleWindow &w) Additional key member functions are BitMapStatus BitMap::Load(string Filename) BitMapStatus BitMap::GetStatus() const void BitMap::SetPosition(const Position &p) int BitMap::Draw() int BitMap::Erase() int BitMap::IsInside(const Position &p) const

Fun with Pictures // Display a bit map image of the authors in the // center of a window #include #include "bitmap.h" // Open a window to display photograph SimpleWindow PhotoWindow("The Authors", 10.0, 7.0, Position(5.0, 3.0)); // ApiMain(): display a bitmap photo int ApiMain() { PhotoWindow.Open(); assert(PhotoWindow.GetStatus() == WindowOpen); const Position WindowCenter = PhotoWindow.GetCenter();

Fun with Pictures // Create a bitmap BitMap Photo(PhotoWindow); // Load the image Photo.Load("photo.bmp"); assert(Photo.GetStatus() == BitMapOkay); // Compute position of logo so it is centered Position PhotoPosition = WindowCenter + Position(-.5 * Photo.GetWidth(), -.5 * Photo.GetHeight()); Photo.SetPosition(PhotoPosition); // Draw bitmap and we’re done Photo.Draw(); return 0; }

Fun with Pictures

Mouse Events Before we can react to a mouse event in a SimpleWindow Must tell window what function to call when an event occurs  Registering a callback To register a callback use the SimpleWindow member function SetMouseClickCallback. W1.SetMouseClickCallback(f); Says if the mouse is clicked in window W1, call function f()  f() is passed a Position that is the coordinate of the location of the mouse when the button was clicked

Mouse Events int ApiMain() { // Open the window W1.Open(); assert(W1.GetStatus() == WindowOpen); // Load the image B.Load("wizards.bmp"); assert(B.GetStatus() == BitMapOkay); // Display the bit maps at a starting position B.SetPosition(Position(1.0, 1.0)); B.Draw(); // Register the callbacks for each window W1.SetMouseClickCallback(ReceiveMouseClick); return 0; }

Mouse Events #include #include "bitmap.h" SimpleWindow W1("Window One", 10.0, 7.0, Position(1.0, 1.0)); BitMap B(W1); // Define a bitmap // Mouse callback function int ReceiveMouseClick(const Position &p) { // Erase the bitmap B.Erase(); // Set its new position and display it B.SetPosition(p); B.Draw(); return 1; }

Timer Events The SimpleWindow class supports a timer mechanism You can set a timer to go off periodically When the timer goes off, a call back is made to the function specified by the user

Timer Functions void SimpleWindow::SetTimerCallback( TimerTickCallbackFunction f) Registers a callback for a timer tick Function f() will be called when a timer tick occurs. The function f() must be declared to take no parameters, and it should return an int The return value of f() indicates whether the event was handled successfully A value of 1 is to indicate success A value of 0 is to indicate an error occurred

Timer Functions int SimpleWindow::StartTimer(int Interval) Starts timer running Parameter Interval is the number of milliseconds between timer events The return value indicates whether the timer was successfully started A return value of 1 indicates success A return value of 0 indicates the timer could not be set up void SimpleWindow::StopTimer() Turns timer off

#include #include "bitmap.h“ SimpleWindow W1("Fun", 15.0, 9.0, Position(1.0, 1.0)); BitMap B(W1); // Define a bitmap // W1TimerEvent(): move bitmap to a new location int W1TimerEvent() { // Erase the bitmap B.Erase(); // Compute a new position and display it // Make sure the bitmap is completely in the window int XCoord = Uniform(1, W1.GetWidth()); if (XCoord + B.GetWidth() > W1.GetWidth()) XCoord = XCoord - B.GetWidth(); int YCoord = Uniform(1, W1.GetHeight()); if (YCoord + B.GetHeight() > W1.GetHeight()) YCoord = YCoord - B.GetHeight(); B.SetPosition(Position(XCoord, YCoord)); B.Draw(); } Example

int ApiMain() { W1.Open(); // Open the window assert(W1.GetStatus() == WindowOpen); B.Load("davidson.bmp"); // Load the image assert(B.GetStatus() == BitMapOkay); // Display the bit maps at a starting position B.SetPosition(Position(1.0, 1.0)); B.Draw(); // Register the callbacks for each window // and start the timers to go off every 500 ms W1.SetTimerCallback(W1TimerEvent); W1.StartTimer(500); return 0; }

Example int ApiEnd() { // Stop the timers and close the windows W1.StopTimer(); W1.Close(); return 0; }