 2006 Pearson Education, Inc. All rights reserved. 1 17 Graphics and Multimedia.

Slides:



Advertisements
Similar presentations
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Advertisements

 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 30 - Dynamic HTML: Structured Graphics ActiveX Control Outline 30.1Introduction 30.2Shape Primitives.
Graphics Chapter 16.  If you want to draw shapes such as a bar chart, a clock, or a stop sign, how do you do it?
Chapter 9 Color, Sound and Graphics
COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
Graphics and Multimedia Session 13 Mata kuliah: M0874 – Programming II Tahun: 2010.
User Interface Programming in C#: Graphics
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
Working with Vector Graphics – Lesson 21 Working with Vector Graphics Lesson 2.
1 L36 Graphics and Java 2D™ (1). 2 OBJECTIVES  To understand graphics contexts and graphics objects.  To understand and be able to manipulate colors.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
 Pearson Education, Inc. All rights reserved Multimedia: Applets and Applications.
Graphics and Multimedia. Outline Introduction Graphics Contexts and Graphics Objects Color Control.
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
1 Chapter 26 D&D – Graphics Outline 26.1 Introduction 26.3 Graphics Contexts and Graphics Objects 26.4 Color Control 26.5 Font Control 26.6 Drawing Lines,
CS324e - Elements of Graphics and Visualization Java2D Graphics.
Graphics and Multimedia In visual Studio. Net (C#)
Lecture Set 13 Drawing Mouse and Keyboard Events Part A - Drawing.
Graphics and Multimedia. Outline Introduction to Multimedia Loading, Displaying and Scaling Images Windows Media Player Adding a Flash Movie Microsoft.
Chapter 3 Working with Symbols and Interactivity.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface A Brief Introduction to GDI+ S.R.G. Fraser, Pro Visual C++/CLI.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 26 – CheckWriter Application Introducing Graphics.
Java Software Solutions Lewis and Loftus Chapter 7 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphics -- Introduction The.
1 Graphical User Components (II) Outline JTextArea Creating a Customized Subclass of JPanel JPanel Subclass that Handles Its Own Events Windows: Additional.
 2005 Pearson Education, Inc. All rights reserved Multimedia: Applets and Applications.
1-1 OBJ Copyright 2003, Paradigm Publishing Inc. Dr. Joseph Otto Silvia Castaneda Christopher deCastro CSULA Macromedia Flash MX Introduction.
Object Oriented Programming Graphics and Multimedia Dr. Mike Spann
Graphics and Multimedia Part #2
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
XP Tutorial 1 Introduction to Macromedia Flash MX 2004.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
Chapter 15 Graphics and Java 2D™ Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction.
Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction 28.2Graphics Contexts and Graphics Objects 28.3Color Control 28.4Font Control 28.5Drawing.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 27 - Phone Book Application Introducing Multimedia.
 Pearson Education, Inc. All rights reserved. 1 Ch 12 Graphics and Java 2D In this chapter you will learn:  To understand graphics contexts.
Tutorial 1 Introducing Adobe Flash CS3 Professional
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Computer Science 112 Fundamentals of Programming II Graphics Programming.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. M I C R O S O F T ® Refining Original Illustrations Lesson 9.
Introduction to Flash Animation CS 318. Topics Introduction to Flash and animation The Flash development environment Creating Flash animations  Layers.
Chapter 4 Working with Frames. Align and distribute objects on a page Stack and layer objects Work with graphics frames Work with text frames Chapter.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Graphics ikt403 – Object-Oriented Software Development.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
16.9 Introduction to Multimedia Visual Basic offers many convenient ways to include images and animations in programs Computing field decades ago mainly.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 19 – Dynamic HTML: Structured Graphics ActiveX Control Outline 19.1Introduction 19.2Shape.
Graphics and Multimedia. OUTLINE Font Control Drawing Lines, Rectangles and Ovals Drawing Arcs Drawing a General Path.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
GDI +. Graphics class's methods System.Drawing Graphics Objects.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
Graphics and Multimedia 2 Lecture 8. OUTLINE Font Control Drawing Lines, Rectangles and Ovals Drawing a General Path.
Introducing Macromedia Flash 8
Graphics and Multimedia
12 Graphics and Java 2D™.
Flash Interface, Commands and Functions
Graphics and Multimedia
JAVA 2 Design and programming of GUI
Drawing Mouse and Keyboard Events Part A - Drawing
Project title Scheduled dates Team members JAN FEB MAR APR MAY JUN
CASE Tools Graphical User Interface Programming Using C#
Graphics -- Introduction
Chapter Lessons Use the Macromedia Flash drawing tools
Topics Graphical User Interfaces Using the tkinter Module
Chapter 12 Graphics in Windows and the Web
Presentation transcript:

 2006 Pearson Education, Inc. All rights reserved Graphics and Multimedia

 2006 Pearson Education, Inc. All rights reserved. 2 One picture is worth ten thousand words. — Chinese proverb Treat nature in terms of the cylinder, the sphere, the cone, all in perspective. — Paul Cezanne Nothing ever becomes real till it is experienced— even a proverb is no proverb to you till your life has illustrated it. — John Keats A picture shows me at a glance what it takes dozens of pages of a book to expound. — Ivan Sergeyevich

 2006 Pearson Education, Inc. All rights reserved. 3 OBJECTIVES In this chapter you will learn:  To understand graphics contexts and graphics objects.  To manipulate colors and fonts.  To understand and use GDI+ Graphics methods to draw lines, rectangles, string s and images.  To use class Image to manipulate and display images.  To draw complex shapes from simple shapes with class GraphicsPath.  To use Windows Media Player to play audio or video in a C# application.  To use Microsoft Agent to add interactive animated characters to a C# application.

 2006 Pearson Education, Inc. All rights reserved Introduction 17.2 Drawing Classes and the Coordinate System 17.3 Graphics Contexts and Graphics Objects 17.4 Color Control 17.5 Font Control 17.6 Drawing Lines, Rectangles and Ovals 17.7 Drawing Arcs 17.8 Drawing Polygons and Polylines 17.9 Advanced Graphics Capabilities Introduction to Multimedia Loading, Displaying and Scaling Images Animating a Series of Images Windows Media Player Microsoft Agent Wrap-Up

 2006 Pearson Education, Inc. All rights reserved Introduction Overview of C#’s tools for drawing 2-D shapes and for controlling colors and fonts – Namespace System.Drawing Many sophisticated drawing capabilities that make up the.NET resource GDI+ – GDI+ is an application programming interface (API) For creating 2-D vector graphics, manipulating fonts and inserting images – Class Image Store and manipulate images of various formats Multimedia examples – Build an animation – Use the Windows Media Player control – Use Microsoft Agent For adding interactive animated characters to applications or Web pages

 2006 Pearson Education, Inc. All rights reserved Drawing Classes and the Coordinate System System.Drawing – Class Graphics Methods used for drawing string s, lines, rectangles and etc. – Class Pen and/or Brush Render a specified shape – Color structure Set colors of various graphical components Allow to create new colors – Class Font Contains properties that define unique fonts – Class FontFamily Contains methods for obtaining font information

 2006 Pearson Education, Inc. All rights reserved. 7 Fig | System.Drawing namespace’s classes and structures.

 2006 Pearson Education, Inc. All rights reserved Drawing Classes and the Coordinate System (Cont.) GDI’s coordinate system – By default, the upper-left corner of a GUI component has the coordinates (0, 0) – A coordinate pair x-coordinate – The horizontal distance from the upper-left corner y-coordinate – The vertical distance from the upper-left corner – Coordinate units are measured in pixels The smallest units of resolution on a display monitor – Point structure Represents the x-y coordinates of a point on a two 2-D plane – Size structure Represents width and height of a shape

 2006 Pearson Education, Inc. All rights reserved. 9 Portability Tip 17.1 Different display monitors have different resolutions, so the density of pixels on such monitors will vary. This might cause the sizes of graphics to appear different on different monitors.

 2006 Pearson Education, Inc. All rights reserved. 10 Fig | GDI+ coordinate system. Units are measured in pixels.

 2006 Pearson Education, Inc. All rights reserved Graphics Contexts and Graphical Objects Graphics – Graphical context represents drawing surface – Graphics objects contain methods for graphics-related actions – Derived classes of System.Windows.Forms.Form inherits virtual OnPaint method OnPaint method’s argument includes a PaintEventArgs object to obtain a Graphics object for the Form – Programmers seldom call the OnPaint method directly Drawing graphics is an event-driven process – Control’s Invalidate method forces a call to OnPaint – By default, controls do not have their own graphics contexts

 2006 Pearson Education, Inc. All rights reserved. 12 Performance Tip 17.1 Calling the Invalidate method to refresh the Control can be inefficient if only a small portion of a Control needs refreshing. Calling Invalidate with a Rectangle parameter refreshes only the area designated by the rectangle. This improves program performance.

 2006 Pearson Education, Inc. All rights reserved Color Control Colors – Are created from a combination of alpha, red, green and blue components (called ARGB values) All four ARGB components are byte s that represent integer values in the range 0 to 255 The alpha value determines the opacity of the color Method FromArgb – Allows you to set these values Some methods/classes related to color control – Derived classes from abstract class Brush Define the color of interiors of graphical shapes – Graphics has several overloaded DrawString methods – Color ’s static method FromName Create new Color defined by user – ColorDialog GUI component A dialog box that allows users to select from a palette of available colors or to create custom colors

 2006 Pearson Education, Inc. All rights reserved. 14 Fig | Color structure static constants and their RGB values.

 2006 Pearson Education, Inc. All rights reserved. 15 Fig | Color structure members.

 2006 Pearson Education, Inc. All rights reserved. 16 Fig | Classes that derive from class Brush.

 2006 Pearson Education, Inc. All rights reserved. 17 Outline ShowColors.cs (1 of 4) private instance variable to store the back rectangle's color private instance variable to store the front rectangle's color Override OnPaint to customize the graphics operations that are performed Retrieve the Graphics object Create SolidBrush object to for drawing solid shape

 2006 Pearson Education, Inc. All rights reserved. 18 Outline ShowColors.cs (2 of 4) Create SolidBrush object for drawing solid shape Give the retrieved Graphics object a white background using brush Output the background color by drawing to the Graphics object Draw the back rectangle to Graphics object Draw the front rectangle to Graphics object Output the Argb value of front rectangle by drawing to the Graphics object

 2006 Pearson Education, Inc. All rights reserved. 19 Outline ShowColors.cs (3 of 4) Allow user to change background color Call OnPaint to redraw Allow user to change the front rectangle’s color Call OnPaint to redraw

 2006 Pearson Education, Inc. All rights reserved. 20 Outline ShowColors.cs (4 of 4)

 2006 Pearson Education, Inc. All rights reserved. 21 Outline ShowColors Complex.cs (1 of 3) Create a ColorDialog object Allow user to choose from a variety of colors Check to see if the user pressed “Cancel”

 2006 Pearson Education, Inc. All rights reserved. 22 Outline ShowColors Complex.cs (2 of 3) Change color to user’s selection Allow user to choose from a variety of colors

 2006 Pearson Education, Inc. All rights reserved. 23 Outline ShowColors Complex.cs (3 of 3)

 2006 Pearson Education, Inc. All rights reserved Font Control Font – Properties of Font objects cannot be modified If you need a different Font, must create a new Font object – Size property Returns the font size as measured in design units – SizeInPoints property Returns the font size as measured in points – GraphicsUnit enumeration Unit of measurement that describes the font size FontFamily – Defines characteristics common to a group of related fonts – Provides several methods to determine the font metrics that are shared by members of a particular family

 2006 Pearson Education, Inc. All rights reserved. 25 Fig | Font class read-only properties.

 2006 Pearson Education, Inc. All rights reserved. 26 Common Programming Error 17.1 Specifying a font that is not available on a system is a logic error. If this occurs, C# will substitute that system’s default font.

 2006 Pearson Education, Inc. All rights reserved. 27 Outline UsingFonts.cs (1 of 3) Change font style to bold Arial Change font style to Times New Roman

 2006 Pearson Education, Inc. All rights reserved. 28 Outline UsingFonts.cs (2 of 3) Change font style to italic Courier New Change font style to strikeout Tahoma Output font styles to screen by drawing to graphicsObject

 2006 Pearson Education, Inc. All rights reserved. 29 Outline UsingFonts.cs (3 of 3) Output font styles to screen by drawing to graphicsObject

 2006 Pearson Education, Inc. All rights reserved. 30 Fig | Font metrics illustration.

 2006 Pearson Education, Inc. All rights reserved. 31 Fig | FontFamily methods that return font-metric information.

 2006 Pearson Education, Inc. All rights reserved. 32 Outline UsingFont Metrics.cs (1 of 3) Create a FontFamily object to determine the front metrics of Arial

 2006 Pearson Education, Inc. All rights reserved. 33 Outline UsingFont Metrics.cs (2 of 3) Output font style’s ascent Output font style’s descent Output font style’s height Output font style’s spacing Change the FontFamily object to determine the front metrics of Sans Serif Output font style’s ascent

 2006 Pearson Education, Inc. All rights reserved. 34 Outline UsingFont Metrics.cs (3 of 3) Output font style’s descent Output font style’s height Output font style’s spacing

 2006 Pearson Education, Inc. All rights reserved Drawing Lines, Rectangles and Ovals Each of the drawing methods has several overloaded versions – Methods that draw hollow shapes Typically require as arguments a Pen and four int s – Methods that draw solid shapes Typically require as arguments a Brush and four int s – The first two int arguments represent the coordinates of the upper- left corner of the shape – The last two int s indicate the shape’s width and height – Methods FillRectangle and DrawRectangle Draw rectangles on the screen – Methods FillEllipse and DrawEllipse Draw ellipses on the screen

 2006 Pearson Education, Inc. All rights reserved. 36 Fig | Graphics methods that draw lines, rectangles and ovals. (Part 1 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 37 Fig | Graphics methods that draw lines, rectangles and ovals. (Part 2 of 2.)

 2006 Pearson Education, Inc. All rights reserved. 38 Outline LinesRectangles Ovals.cs (1 of 3) Draw the back rectangle filled in with blue

 2006 Pearson Education, Inc. All rights reserved. 39 Outline LinesRectangles Ovals.cs (2 of 3) Draw lines to connect the rectangle to make a box Draw the front rectangle Draw the bottom ellipse filled in with red Draw lines to connect the ellipses to make a cylinder

 2006 Pearson Education, Inc. All rights reserved. 40 Outline LinesRectangles Ovals.cs (3 of 3) Draw the top ellipse

 2006 Pearson Education, Inc. All rights reserved Drawing Arcs Arcs – Portions of ellipses and are measured in degrees Begin at a starting angle Continue for a specified number of degrees (the arc angle) – An arc is said to sweep its arc angle Begin from its starting angle Clockwise direction is measured in + degree Counterclockwise direction is measured in - degree – The Graphics methods used to draw arcs: DrawArc DrawPie FillPie

 2006 Pearson Education, Inc. All rights reserved. 42 Fig | Ellipse bounded by a rectangle.

 2006 Pearson Education, Inc. All rights reserved. 43 Fig | Positive and negative arc angles.

 2006 Pearson Education, Inc. All rights reserved. 44 Fig | Graphics methods for drawing arcs.

 2006 Pearson Education, Inc. All rights reserved. 45 Outline DrawingArcs.cs (1 of 3) Draws a circle

 2006 Pearson Education, Inc. All rights reserved. 46 Outline DrawingArcs.cs (2 of 3) Draws an arc from 0 to 110 degrees Draws an arc from 0 to -270 degrees Draws filled circle Draws a filled arc from 270 to -90 degrees Draws a filled arc from 0 to -270 degrees

 2006 Pearson Education, Inc. All rights reserved. 47 Outline DrawingArcs.cs (3 of 3)

 2006 Pearson Education, Inc. All rights reserved Drawing Polygons and Polylines Polygons – Multisided shapes – Several Graphics methods used to draw polygons: – DrawLines Draws a series of connected lines – DrawPolygon Draws a closed polygon – FillPolygon Draws a solid polygon

 2006 Pearson Education, Inc. All rights reserved. 49 Fig | Graphics methods for drawing polygons.

 2006 Pearson Education, Inc. All rights reserved. 50 Outline DrawPolygons.cs (1 of 5) Declare a dynamic array to store the vertices of the polygon Store the polygon’s vertices determined by the mouse position

 2006 Pearson Education, Inc. All rights reserved. 51 Outline DrawPolygons.cs (2 of 5) Make sure there is more than one point Extract an array from an ArrayList Determine which option(s) are checked and draw its corresponding shape Clear the points store in the ArrayList

 2006 Pearson Education, Inc. All rights reserved. 52 Outline DrawPolygons.cs (3 of 5) Refresh and redraw

 2006 Pearson Education, Inc. All rights reserved. 53 Outline DrawPolygons.cs (4 of 5) Check to see if user pressed “Cancel” Change to the appropriate color

 2006 Pearson Education, Inc. All rights reserved. 54 Outline DrawPolygons.cs (5 of 5)

 2006 Pearson Education, Inc. All rights reserved Advanced Graphics Capabilities Class LinearGradientBrush – Enables users to draw with a color gradient – LinearGradientMode enumeration Specifies the gradient’s direction Class Bitmap – Produce images in color and gray scale – Graphic ’s static method FromImage Retrieves the Graphics object associated with an Image Class GraphicsPath – Enables the creation of complex shapes from vector-based primitive graphics objects – Method CloseFigure Attaches the final vector-graphic object end point to the initial starting point for the current figure by a straight line Then starts a new figure – Method StartFigure Begins a new figure within the path without closing the previous figure – Method AddLine Append a line to the shape

 2006 Pearson Education, Inc. All rights reserved. 56 Outline DrawShapes.cs (1 of 4) Create a Rectangle object Enable user to draw with a color gradient

 2006 Pearson Education, Inc. All rights reserved. 57 Outline DrawShapes.cs (2 of 4) Draw a filled gradient ellipse Draw a red outlined rectangle Create a new Bitmap image Fill Bitmap Retrieves Graphics object associate with an Image

 2006 Pearson Education, Inc. All rights reserved. 58 Outline DrawShapes.cs (3 of 4) Fill Bitmap Draw rectangle with Bitmap image Draw white pie arc Draw a green line Draw a yellow dashed line

 2006 Pearson Education, Inc. All rights reserved. 59 Outline DrawShapes.cs (4 of 4)

 2006 Pearson Education, Inc. All rights reserved. 60 Outline DrawStarsForm.cs (1 of 3) Create two arrays of x and y points where stars will be drawn

 2006 Pearson Education, Inc. All rights reserved. 61 Outline DrawStarsForm.cs (2 of 3) Translate to a new origin Create a GraphicsPath object for a star Create a star Move to the next position on the form The rotation angle in degrees Draw rectangle with random color

 2006 Pearson Education, Inc. All rights reserved. 62 Outline DrawStarsForm.cs (3 of 3)

 2006 Pearson Education, Inc. All rights reserved Introduction to Multimedia Multimedia applications demand extraordinary computing power – Today’s ultrafast processors make multimedia-based applications commonplace

 2006 Pearson Education, Inc. All rights reserved Loading, Displaying and Scaling Images Image ’s static method FromFile – Loads an image from a file on the disk Graphics – Form ’s CreateGraphics method Creates a Graphics object for drawing on the Form – Graphic ’s Clear method Paint the entire Form in the current background color – Graphic ’s DrawImage method If the width and height do not correspond to the image’s original dimensions, the image is scaled to fit the new width and height

 2006 Pearson Education, Inc. All rights reserved. 65 Outline DisplayLogoForm.cs (1 of 3) Load image from specified location

 2006 Pearson Education, Inc. All rights reserved. 66 Outline DisplayLogoForm.cs (2 of 3) Retrieve the height and width the image should be scaled to Draw image with the specified width and height

 2006 Pearson Education, Inc. All rights reserved. 67 Outline DisplayLogoForm.cs (3 of 3)

 2006 Pearson Education, Inc. All rights reserved Animating a Series of Images 2-D collision detection – Enables a program to detect whether two shapes overlap or if a point is contained within a shape – Rectangle ’s method Contains Useful for determining whether a point is inside a rectangular area Artifacts – Unintended visual abnormality in a graphical program

 2006 Pearson Education, Inc. All rights reserved. 69 Outline LogoAnimator.cs (1 of 2) Store and load the images that will be displayed Start by displaying the first image

 2006 Pearson Education, Inc. All rights reserved. 70 Outline LogoAnimator.cs (2 of 2) For every Tick event, display the next image

 2006 Pearson Education, Inc. All rights reserved. 71 Performance Tip 17.2 It is more efficient to load an animation’s frames as one image than to load each image separately. (A painting program, such as Adobe Photoshop ®, or Jasc ® Paint Shop Pro ™, can be used to combine the animation’s frames into one image.) If the images are being loaded separately from the Web, each loaded image requires a separate connection to the site on which the images are stored; this process can result in poor performance.

 2006 Pearson Education, Inc. All rights reserved. 72 Outline ChessPiece.cs (1 of 2) Enumeration for chess pieces Define the image location on the chessboard

 2006 Pearson Education, Inc. All rights reserved. 73 Outline ChessPiece.cs (2 of 2) Extract a sub-image that contains only the current piece’s bitmap data Draws the chess piece Change the chess piece location

 2006 Pearson Education, Inc. All rights reserved. 74 Outline ChessGame.cs (1 of 11) private instance variables representing the chessboard and pieces

 2006 Pearson Education, Inc. All rights reserved. 75 Outline ChessGame.cs (2 of 11) Load the chess board tile images from a specified location Load the images for the white chess pieces

 2006 Pearson Education, Inc. All rights reserved. 76 Outline ChessGame.cs (3 of 11) Load the images for the black chess pieces Put the chess pieces in the appropriate position using a switch statement

 2006 Pearson Education, Inc. All rights reserved. 77 Outline ChessGame.cs (4 of 11) Add the pawns to its appropriate positions

 2006 Pearson Education, Inc. All rights reserved. 78 Outline ChessGame.cs (5 of 11) Shift the origin of the form by 24 pixels

 2006 Pearson Education, Inc. All rights reserved. 79 Outline ChessGame.cs (6 of 11) Draw the chessboard tiles Determine if the specified point is contained in the rectangles Retrieve the piece’s rectangle

 2006 Pearson Education, Inc. All rights reserved. 80 Outline ChessGame.cs (7 of 11) Draw every chess piece Determine if user selected a piece Create a region of 2 tiles from every direction of the mouse cursor

 2006 Pearson Education, Inc. All rights reserved. 81 Outline ChessGame.cs (8 of 11) Set and center the selected piece location to the mouse- cursor position Refresh only the specified region Determine is there is a collision Align the current piece to the closest square and deselect it

 2006 Pearson Education, Inc. All rights reserved. 82 Outline ChessGame.cs (9 of 11) Refresh chessboard Remove the selected piece

 2006 Pearson Education, Inc. All rights reserved. 83 Outline ChessGame.cs (10 of 11)

 2006 Pearson Education, Inc. All rights reserved. 84 Outline ChessGame.cs (11 of 11)

 2006 Pearson Education, Inc. All rights reserved Window Media Player Windows Media Player control – Type AxMediaPlayer – Enables an application to play video and sound in many multimedia formats – URL property Specifies the file that Windows Media Player is currently using

 2006 Pearson Education, Inc. All rights reserved. 86 Outline MediaPlayer Test.cs (1 of 2) Allow the user to select a file Specifies the file that Windows Media Player is using

 2006 Pearson Education, Inc. All rights reserved. 87 Outline MediaPlayer Test.cs (2 of 2)

 2006 Pearson Education, Inc. All rights reserved Microsoft Agent Microsoft Agent – Add interactive animated characters to Windows applications or Web pages – Characters can speak and respond to user input Via speech recognition and synthesis – The control uses a speech recognition engine Translates vocal sound input from a microphone to language that the computer understands – Programmers can even create their own animated characters, with the help from: Microsoft Agent Character Editor Microsoft Linguistic Sound Editing Tool

 2006 Pearson Education, Inc. All rights reserved. 89 Fig | Peedy introducing himself when the window opens. Bubble contains text equivalent to words Peedy speaks

 2006 Pearson Education, Inc. All rights reserved. 90 Look-and-Feel Observation 17.1 Agent characters remain on top of all active windows while a Microsoft Agent application is running. Their motions are not limited by the boundaries of the browser or application window.

 2006 Pearson Education, Inc. All rights reserved. 91 Fig | Peedy’s Pleased animation.

 2006 Pearson Education, Inc. All rights reserved. 92 Fig | Peedy’s reaction when he is clicked. Pointer clicking Peedy

 2006 Pearson Education, Inc. All rights reserved. 93 Fig | Peedy flying animation.

 2006 Pearson Education, Inc. All rights reserved. 94 Fig | Peedy waiting for speech input. Pizza style optionsTool tip indicates that Peedy is waiting for user input

 2006 Pearson Education, Inc. All rights reserved. 95 Fig | Peedy repeating a request for Seattle-style pizza. Tool tip indicates recognized speech

 2006 Pearson Education, Inc. All rights reserved. 96 Fig | Peedy repeating a request for anchovies as an additional topping.

 2006 Pearson Education, Inc. All rights reserved. 97 Fig | Peedy recounting the order.

 2006 Pearson Education, Inc. All rights reserved. 98 Fig | Peedy calculating the total.

 2006 Pearson Education, Inc. All rights reserved. 99 Outline Agent.cs (1 of 8) Load Microsoft agents

 2006 Pearson Education, Inc. All rights reserved. 100 Outline Agent.cs (2 of 8) Show and set default agent to Genie Prompt user for an input for what he/she wants the agent to say Agent will speak the user’s input

 2006 Pearson Education, Inc. All rights reserved. 101 Outline Agent.cs (3 of 8) Stop current animation and plays specified animation Switch Microsoft agent

 2006 Pearson Education, Inc. All rights reserved. 102 Outline Agent.cs (4 of 8) Create an IEnumerator object to iterate through the characters’ animations Add a new command to the current character Clear existing items

 2006 Pearson Education, Inc. All rights reserved. 103 Outline Agent.cs (5 of 8) Stop current animation and play specified animation Assign the userInput object to an IAgentCtlUserInput object to identify command Add the “MoveToMouse” command to the agent

 2006 Pearson Education, Inc. All rights reserved. 104 Outline Agent.cs (6 of 8) Moves the agent to the specified screen position Stop current animation and play specified animation

 2006 Pearson Education, Inc. All rights reserved. 105 Outline Agent.cs (7 of 8) Genie performing Writing animation Drop-down list from which you can choose a character animation Writing animation selected Tool tip indicating that Merlin is listening for a voice command Merlin responding to user spoken animation command. Tool tip shows the words that the speech recognition engine translated to the application

 2006 Pearson Education, Inc. All rights reserved. 106 Outline Agent.cs (8 of 8) Text input Peedy repeating the words entered by the user. Peedy’s speech can be heard through your computer’s speakers. Robby responding to being clicked with the mouse pointer. The commands pop-up window

 2006 Pearson Education, Inc. All rights reserved Microsoft Agent (Cont.) IAgentCtlCharacter – Represents the current character – Method Play Plays an animation – Accepts a string representing one of the predefined animations for the character – Method Speak Receives a string that the character should speak – Method MoveTo Moves the character to the specified position on the screen

 2006 Pearson Education, Inc. All rights reserved Microsoft Agent (Cont.) Commands – Method Add Adds a new command to the command list – Property Commands List of valid commands that is contained in the IAgentCtlCharacter – Commands can be viewed in the Commands pop-up window Displays when the user right-clicks an Agent character – Triggered when the user selects the command from the Commands pop- up window or speaks the voice input into a microphone Command logic is handled in the Command event handler of the AxAgent control When a user clicks a character, the AxAgent control’s ClickEvent event handler executes