Presentation is loading. Please wait.

Presentation is loading. Please wait.

V 1.0 Programming III. Graphical possibilities Simple graphics (shapes)

Similar presentations


Presentation on theme: "V 1.0 Programming III. Graphical possibilities Simple graphics (shapes)"— Presentation transcript:

1 V 1.0 Programming III. Graphical possibilities Simple graphics (shapes)

2 V 1.0ÓE-NIK, 2014 Possibilities for displaying graphics Retained mode: –The scene (lines, shapes, images...) is kept in the memory –The actual drawing is performed once, using the stored model –The application simply adds and removes drawing primitives Immediate mode: –The framework doesn’t store anything –The application directly draws to the container element –The management of the drawn objects is the task of the appication WPF uses only the retained mode! (immediate: GDI, old D3D) 2

3 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 3

4 V 1.0ÓE-NIK, 2014 WPF basics – coordinate system The origin is in the top-left corner, every position is based on these coordinates –The position can be affected by the HorizontalAlignment, Margin, Padding, layout manager settings, … –Too complex – HARD to find out how the objects are placed! –We usually use the Canvas to use the easiest, absolute positioning 4

5 V 1.0ÓE-NIK, 2014 WPF graphics basics – types (System.Windows) They are not displayed, they are only used for representing 2D data! (Struct (value types)) Point: (2D) –X, Y Size –Width, Height Rect, Int32Rect: 2D Rectangle –X, Y, Width, Height, Top, Bottom, Left, Right Vector: 2D vector with useful methods –X, Y, Length, LengthSquared 5

6 V 1.0ÓE-NIK, 2014 WPF graphics basics – colors Every color is represented by four 8 bit bytes: Red (R), Green (G), Blue (B) – 0-255 interval (altogether 256^3 ≈ 16 million colors). The bigger the number, the bigger the intensity for the given channel Alpha channel – Defines the transparency, also 0-255... 0: completely transparent, 255: non-transparent / opaque. We can use the Color struct: 6 Color color = Colors.Red; Color color = Color.FromArgb(20, 255, 0, 0);

7 V 1.0ÓE-NIK, 2014 WPF graphics basics – Brushes We use brushes to fill areas / lines / fonts... Descendants of the System.Windows.Media.Brush abstract class –SolidColorBrush –LinearGradientBrush –RadialGradientBrush –ImageBrush –DrawingBrush –VisualBrush 7

8 V 1.0ÓE-NIK, 2014 WPF graphics basics – Brushes Source: http://i.msdn.microsoft.com/dynimg/IC107818.jpg 8

9 V 1.0ÓE-NIK, 2014 WPF graphics basics – Brushes C# code: In XAML: 9 //pre-defined brush: button.Background = Brushes.Red; //pre-defined color: button.Background = new SolidColorBrush(Colors.Aqua); //custom color: Color almostRed = Color.FromArgb(20, 255, 0, 0); button.Background = new SolidColorBrush(almostRed);...

10 V 1.0ÓE-NIK, 2014 Shapes Ellipse Rectangle Line Polygon Polyline Path –Adding elements to the toolbox: Toolbox  Right click  Choose Items…  WPF Components No good design-time support... 10

11 V 1.0ÓE-NIK, 2014 Shape properties Ellipse, Rectangle: –Width, Height: requested dimensions (ActualWidth, ActualHeight: dimensions after the layout / initialization) –Stroke: the brush of the line –StrokeThickness: thickness of the line –StrokeDashArray, StrokeEndLineCap: decorating elements –Fill: Fill brush –RenderTransform/LayoutTransform: transformations (rotation/scaling/translation) Line: –Stroke, StrokeThickness, StrokeDashArray, StrokeEndLineCap, RenderTransform/LayoutTransform –X1, X2, Y1, Y2: the two points of the line 11

12 V 1.0ÓE-NIK, 2014 Shape-ek tulajdonságai Polygon, Polyline: –Stroke, StrokeThickness, StrokeDashArray, StrokeEndLineCap, Fill, RenderTransform/LayoutTransform –Points: PointCollection type (the elements are Point types) 12 Polygon polygon = new Polygon(); //... Point[] points = new Point[3]; points[0] = new Point(0, 0); points[1] = new Point(20, 40); points[2] = new Point(70, 0); polygon.Points = new PointCollection(points); //...

13 V 1.0ÓE-NIK, 2014 Exercise 13

14 V 1.0ÓE-NIK, 2014 System.Windows.Threading.DispatcherTimer Can be used to perform regular operations Interval –Property that specifies the frequency of the timer (TimeSpan) Start(), Stop() –Methods Tick –Event that signals that the interval has passed There are many different timers – do not mix! (System.Windows.Forms.Timer, System.Timers.Timer, System.Threading.Timer, System.Web.Ui.Timer…) 14


Download ppt "V 1.0 Programming III. Graphical possibilities Simple graphics (shapes)"

Similar presentations


Ads by Google