Presentation is loading. Please wait.

Presentation is loading. Please wait.

V 1.0 Programming III. Recap Drawing / Geometry classes.

Similar presentations


Presentation on theme: "V 1.0 Programming III. Recap Drawing / Geometry classes."— Presentation transcript:

1 V 1.0 Programming III. Recap Drawing / Geometry classes

2 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. 10-20(-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. 100-1000 objects) Visual descendants (System.Windows.Media.Visual) –Most complicated, fastest (10000-20000 objects) –We always use C# code 2

3 V 1.0ÓE-NIK, 2014 Drawings Descendants os System.Windows.Media.Drawing Can represents more complex shapes No built-in support for display/events, they require a hosting object (typically: Image) 3 GeometryDrawingSimple 2D shapes and their groups GlyphRunDrawingTextual data, special glyphs ImageDrawingDisplay image VideoDrawingDisplay video (instead, use: MediaPlayer) DrawingGroupIncorporate multiple drawings into one

4 V 1.0ÓE-NIK, 2014 Hosting objects DrawingImage –To be used in an Image control DrawingBrush –To be used in a Brush DrawingVisual –To be used in a Visual descendant (later) 4

5 V 1.0ÓE-NIK, 2014 Geometry classes Descendants of System.Windows.Media.Geometry –They define 2D structures, shapes, simple drawings/lines –No display – they only represent the structure! 5 RectangleGeometryRectangle EllipseGeometryEllipse LineGeometryLine (no area!) PathGeometryMultiple line segments GeometryGroupMultiple geometry instances …

6 V 1.0ÓE-NIK, 2014 Example of displaying Geometry in an Image XAML code: <EllipseGeometry Center="10,10” RadiusX="10" RadiusY="10"> 6 Can be specified in the GeometryDrawing: Geometry, Brush, Pen

7 V 1.0ÓE-NIK, 2014 Display GeometryDrawing in a DrawingImage, C# C# code: DrawingImage drawingImage = new DrawingImage(); GeometryDrawing geometryDrawing = new GeometryDrawing(); geometryDrawing.Brush = Brushes.Black; geometryDrawing.Geometry = new EllipseGeometry(new Point(10, 10), 10, 10); drawingImage.Drawing = geometryDrawing; image.Source = drawingImage; 7

8 V 1.0ÓE-NIK, 2014 Example – displaying Text EllipseGeometry myEllipse = new EllipseGeometry(new Point(10, 10), 10, 10); FormattedText text = new FormattedText("This is MINE.", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Tahoma"), 16, Brushes.Black); Geometry textGeometry = text.BuildGeometry(new Point(10, 20)); GeometryGroup group = new GeometryGroup(); group.Children.Add(ellipse); group.Children.Add(textGeometry); geometryDrawing.Geometry = group; 8 Display text as Geometry –Using the BuildGeometry method of the FormattedText class Then we can merge multiple Geometry instances into one GeometryGroup

9 V 1.0ÓE-NIK, 2014 Exercise 9

10 V 1.0ÓE-NIK, 2014 Exercise If the player finishes a level, a new one should be automatically loaded We should measure the time for every level (System.Diagnostics.Stopwatch class) In a new window, display the level times using a Garph drawn using a GeometryDrawing 10


Download ppt "V 1.0 Programming III. Recap Drawing / Geometry classes."

Similar presentations


Ads by Google