V 1.0 Programming III. Visual/FrameworkElement descendants.

Slides:



Advertisements
Similar presentations
Image Navigator Help Session. Review Graphics2D class for drawing shapes in a component – paintComponent(Graphics g) – Graphics2D g2 = (Graphics2D)g;
Advertisements

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.
Chapter 4 Transforming and Distorting Objects. Objectives Transform objects Offset and outline paths Create compound paths Work with the Pathfinder panel.
This terms course Last term we both worked on learning 2 things –Processing –The concepts of graphics etc. This term will focus more on the basic concepts.
2 D and 3 D Graphics and Animations Doncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer
Chapter 5 - Arrays CSC 200 Matt Kayala 2/27/06. Learning Objectives  Introduction to Arrays  Declaring and referencing arrays  For-loops and arrays.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Doncho Minkov Telerik School Academy academy.telerik.com Technical Trainer
V 1.0 Programming III. Creation of additional windows Routed events.
CSC461 Lecture 11: Interactive Programs Contents and Objectives Picking Writing modes – XOR/Copy Rubberbanding Display list.
V 1.1 Programming III. GUI APIs WPF Hello World Important UI elements UI elements / content models UI elements / inheritance.
Virtual techdays INDIA │ Nov 2010 Developing Office Biz Application using WPF on Windows 7 Sarang Datye │ Sr. Consultant, Microsoft Sridhar Poduri.
Tutorial 2 Drawing Text, Adding Shapes, and Creating Symbols.
BIM211 – Visual Programming Objects, Collections, and Events 1.
V 1.0 Programming III. Comparison of GUI APIs WPF Hello World UI elements Content models Inheritance chains.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
(C) 2010 Pearson Education, Inc. All rights reserved. Omer Boyaci.
V 1.1 Programming III. Creating additional windows Event handling: preview/routed events.
Adding Graphics to a Frame Application Applets: Can generate drawings by overriding paint Frame: Do not draw directly on a frame. Draw graphics on a JPanel.
Description, Classes, Interfaces, Hierarchy, Specifics George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
V 1.0 Programming III. Automatic notifications (…Changed, INofityPropertyChanged, ObservableCollection ) Data formatters Data conversions Resources.
tiled Map Case Study: Rendering with JPanel © Allan C. Milne v
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
 Agenda 2/20/13 o Review quiz, answer questions o Review database design exercises from 2/13 o Create relationships through “Lookup tables” o Discuss.
Tutorial 2 Drawing Shapes, Adding Text, and Creating Symbols.
11 Adding Tomato Targets Session Session Overview  We now have a game which lets a player bounce a piece of cheese on a bread bat  Now we have.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
Android Graphics Library. Color Android colors are represented with four numbers, one each for alpha, red, green, and blue (ARGB). Each component can.
A Lap Around Windows Presentation Foundation. Why hasn’t UX taken off in software? It’s Difficult! Animation 2D 3D Documents Styled Controls Video Windows.
Windows Presentation Foundation (WPF). Introduction Separates appearance of user interface from behavior Appearance usually specified by XAML Behavior.
Session 16 Pinball Game Construction Kit:. Pinball Version 1 Replaced the fire button with a mouse event. Multiple balls can be in the air at once. –Uses.
Esri UC 2014 | Technical Workshop | Creating Geoprocessing Services Kevin Hibma.
More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.
V 1.0 Programming III. Converters Resources. V 1.0ÓE-NIK, 2014 Converters Data conversion: –Can be automatic! E.g.: SolidColorBrush  string, int  string.
Module 3 Designing and Developing a User Interface.
Slide 1 Chapter 5 Arrays. Slide 2 Learning Objectives  Introduction to Arrays  Declaring and referencing arrays  For-loops and arrays  Arrays in memory.
Chapter 5 Arrays. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 5-2 Learning Objectives  Introduction to Arrays  Declaring and referencing.
IS201 Agenda: 09/19  Modify contents of the database.  Discuss queries: Turning data stored in a database into information for decision making.  Create.
Copyright Curt Hill Arrays in C/C++ More on usage.
V 1.0 Programming III. Recap Drawing / Geometry classes.
Module 4 Taking Control of the User Interface. Module Overview Sharing Logical Resources in an Application Creating Consistent User Interfaces by Using.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.
V 1.0 Programming III. Automatic notifications with data binding (…Changed, INofityPropertyChanged, ObservableCollection, DataTemplate) Data formatters.
V 1.0 Programming III. Graphical possibilities Simple graphics (shapes)
CPSC 481 – Week #7 Sowmya Somanath
LISTS. LEARNING OBJECTIVES Create a block that accepts a parameter Create a block that returns a value Create scripts that manipulates lists Incorporate.
Sizing, Positioning, and Transforming Elements.
Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
V 1.0 Programming III. XAML Data Binding I.. V 1.0ÓE-NIK, 2014 XAML namespaces Namespaces define the allowed tags and attributes The one without the prefix.
XNA Tutorial 1 For CS134 Lecture. Overview Some of the hard work has already been done for you. If you build and run your game now, the GraphicsDeviceManager.
12 Copyright © 2004, Oracle. All rights reserved. Using ADF Struts Components.
CS320n –Visual Programming Execution Control with If / Else and Boolean Functions (Slides 6-2-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
Chapter 5 Arrays Copyright © 2016 Pearson, Inc. All rights reserved.
Exploring Networked Data and Data Stores Lesson 3.
Part of the Microsoft.NET Framework 3.0 Tomer Shamam.NET Technologies Expert Sela Group
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Data Binding, Binding Properties Doncho Minkov Telerik School Academy Technical Trainer
CS 480/680 Computer Graphics Programming with Open GL Part 2: Complete Programs Dr. Frederick C Harris, Jr. Fall 2011.
Arrays Chapter 7.
Phil Tayco Slide version 1.0 Created Sep 18, 2017
Jim Fawcett CSE775 – Distributed Objects Spring 2011
Programming with OpenGL Part 2: Complete Programs
CIS 199 Final Review.
Programming with OpenGL Part 2: Complete Programs
Chapter 10 Algorithms.
Sizing, Positioning, and Transforming Elements
Presentation transcript:

V 1.0 Programming III. Visual/FrameworkElement descendants

V 1.0ÓE-NIK, 2014 Possibilities in WPF Shapes (System.Windows.Shapes.Shape descendants) –Simple, pre-defined shapes –Can be (mostly) accessed from the Toolboxban –FrameworkElement descendants: input, focus, events… –Max (-100) objects Drawing objects (System.Windows.Media.Drawing namespace) –No built-in support for event management –No built-in support for display, requires a hosting object –Usually driven from the XAML, using converters/geometry instances –Faster (max objects) Visual descendants (System.Windows.Media.Visual) –Most complicated, fastest ( objects) –We always use C# code 2

V 1.0ÓE-NIK, 2014 Visual Provides ways to render the given type Special descendant classes: DrawingVisual (2D), Viewport3DVisual (3D) Two usages: –We add visual children to the visual element, and the children do the rendering –We define our own class + render method using the FrameworkElement class 3

V 1.0ÓE-NIK, 2014 DrawingVisual 2D drawing –We have to call RenderOpen(), which will return a DrawingContext instance We can use the DrawingContext method to „fill” the Visual (or the DrawingGroup) with content –DrawEllipse() –DrawRectangle() –DrawGeometry() –DrawImage() … –Retained mode: it only stores the objects to be drawn –Internally, the objects to be drawn are stored inside a Drawing (in a DrawingGroupb). –The time of the drawing is decided by the system / OS 4

V 1.0ÓE-NIK, 2014 Usage of Visuals – 1 st usage public partial class MainWindow : Window { DrawingVisual visualChild; //We could create a FrameworkElement public MainWindow() //descendant and put it to the { //MainWindow InitializeComponent(); visualChild = new DrawingVisual(); using (DrawingContext context = visualChild.RenderOpen()) { context.DrawEllipse(Brushes.Red, null, new Point(50, 50),10,10); } AddVisualChild(visualChild); AddLogicalChild(visualChild); } protected override int VisualChildrenCount { get { return base.VisualChildrenCount + 1; } } protected override Visual GetVisualChild(int index) { if (index < base.VisualChildrenCount) return base.GetVisualChild(index); else return visualChild; } 5

V 1.0ÓE-NIK, 2014 Usage of Visuals – 2 nd usage We create/use a FrameworkElement descendant Wen it is displayed, the OnRender() method is called –It can be overridden, it gets a DrawingContext typed parameter that can be used to draw to the Visual We can ask a re-draw using the InvalidateVisual method class MainWindow : Window //Typically we use a { //FrameworkElement descendant... protected override void OnRender(DrawingContext drawingContext) { drawingContext.DrawGeometry(Brushes.Blue, new Pen(Brushes.Red, 2), geometry); } 6

V 1.0ÓE-NIK, 2014 Example – Asteroids 7

V 1.0ÓE-NIK, 2014 Transformations Transform descendant (transformation matrix) –RotateTransform –ScaleTransform –SkewTransform –TranslateTransform –MatrixTransform –TransformGroup – multiple transformations 8

V 1.0ÓE-NIK, 2014 Applying tranformations UI elements –LayoutTransform (before the placement of the element) –RenderTransform (after the placement of the element) Geometry: –Transform It does not modify the coordinates!! –By removing the transformation (xxx.Transform = Transform.Identity) the object moves back to its original state –Can be a problem when detecting intersection/collision 9

V 1.0ÓE-NIK, 2014 Intersection (hit test) We have to create a combination of the two geometry instances, and check the surface area (GetArea()) Warning: the surface area for a LineGeometry is always zero – we have to “extend” the line to make it wider –geometry.GetWidenedPathGeometry(new Pen(Brushes.Blue, 2)) Geometry intersection = Geometry.Combine(geometry, otherGeometry, GeometryCombineMode.Intersect, null); return intersection.GetArea() != 0; 10

V 1.0ÓE-NIK, 2014 Exercise – Flappy Birds Turbo 11

V 1.0ÓE-NIK, 2014 Suggested approach Every game item should be created with a (0;0) centered geometry Before drawing / collision test, we transform into the appropriate position/rotation TransformGroup tg = new TransformGroup(); tg.Children.Add(new TranslateTransform(cx, cy)); tg.Children.Add(new RotateTransform(degree, cx, cy)); Geometry copy = area.Clone(); copy.Transform = tg; return copy.GetFlattenedPathGeometry(); 12

V 1.0ÓE-NIK, 2014 Review 13 ApproachEvent managementUsageNo. of objects ShapeSeparately for every object XAML + Binding~100 DrawingThere is a host- object that handles events / input XAML + Binding + Converters (xxx  Geometry) ~1000 VisualThere is a host- object that handles events / input / render CS code: OnRender + DrawingContext + Geometry ~10000