2 using System.Collections.Generic;
3 using Tizen.NUI.BaseComponents;
4 using Tizen.NUI.BaseComponents.VectorGraphics;
6 namespace Tizen.NUI.Samples
10 public class CanvasViewSample : IExample
12 const string tag = "NUITEST";
15 private CanvasView canvasView;
18 private int count = 0;
20 public void Activate()
22 Window window = NUIApplication.GetDefaultWindow();
27 ParentOrigin = ParentOrigin.Center,
28 PivotPoint = PivotPoint.Center,
29 PositionUsesPivotPoint = true,
33 canvasView = new CanvasView(window.Size)
36 ParentOrigin = ParentOrigin.Center,
37 PivotPoint = PivotPoint.Center,
38 PositionUsesPivotPoint = true,
41 Shape shape1 = new Shape()
43 FillColor = new Color(0.5f, 1.0f, 0.0f, 1.0f),
44 StrokeColor = new Color(0.5f, 0.0f, 0.0f, 0.5f),
47 shape1.Translate(100.0f, 100.0f);
50 shape1.AddRect(-50.0f, -50.0f, 100.0f, 100.0f, 10.0f, 10.0f);
52 canvasView.AddDrawable(shape1);
54 Shape shape2 = new Shape()
57 FillColor = new Color(0.0f, 0.0f, 1.0f, 1.0f),
58 StrokeColor = new Color(1.0f, 1.0f, 0.0f, 1.0f),
60 StrokeDash = new List<float>() { 15.0f, 30.0f }.AsReadOnly(),
62 shape2.AddCircle(0.0f, 0.0f, 150.0f, 100.0f);
63 shape2.Transform(new float[] { 0.6f, 0.0f, 350.0f, 0.0f, 0.6f, 100.0f, 0.0f, 0.0f, 1.0f });
65 canvasView.AddDrawable(shape2);
67 Shape shape3 = new Shape()
69 StrokeColor = new Color(0.0f, 0.5f, 0.0f, 0.5f),
71 StrokeJoin = Shape.StrokeJoinType.Miter,
73 shape3.Translate(100.0f, 300.0f);
74 shape3.AddArc(0.0f, 0.0f, 80.0f, 10.0f, 120.0f, true);
76 canvasView.AddDrawable(shape3);
78 Shape shape4 = new Shape()
81 FillColor = new Color(0.0f, 0.5f, 0.0f, 0.5f),
82 StrokeColor = new Color(0.5f, 0.0f, 0.5f, 0.5f),
84 FillRule = Shape.FillRuleType.EvenOdd,
85 StrokeJoin = Shape.StrokeJoinType.Round,
88 shape4.Translate(350.0f, 300.0f);
89 shape4.AddMoveTo(0.0f, -160.0f);
90 shape4.AddLineTo(125.0f, 160.0f);
91 shape4.AddLineTo(-180.0f, -45.0f);
92 shape4.AddLineTo(180.0f, -45.0f);
93 shape4.AddLineTo(-125.0f, 160.0f);
96 canvasView.AddDrawable(shape4);
101 FillColor = new Color(0.0f, 1.0f, 1.0f, 1.0f),
102 StrokeColor = new Color(0.5f, 1.0f, 0.5f, 1.0f),
104 StrokeCap = Shape.StrokeCapType.Round,
106 shape.Translate(250.0f, 550.0f);
108 shape.AddMoveTo(-1.0f, -165.0f);
109 shape.AddLineTo(53.0f, -56.0f);
110 shape.AddLineTo(174.0f, -39.0f);
111 shape.AddLineTo(87.0f, 45.0f);
112 shape.AddLineTo(107.0f, 166.0f);
113 shape.AddLineTo(-1.0f, 110.0f);
114 shape.AddLineTo(-103.0f, 166.0f);
115 shape.AddLineTo(-88.0f, 46.0f);
116 shape.AddLineTo(-174.0f, -38.0f);
117 shape.AddLineTo(-54.0f, -56.0f);
120 canvasView.AddDrawable(shape);
123 log.Debug(tag, "Shape2 Color : " + shape2.FillColor.R + " " + shape2.FillColor.G + " " + shape2.FillColor.B + " " + shape2.FillColor.A + "\n");
124 log.Debug(tag, "Shape2 StrokeColor : " + shape2.StrokeColor.R + " " + shape2.StrokeColor.G + " " + shape2.StrokeColor.B + " " + shape2.StrokeColor.A + "\n");
126 log.Debug(tag, "Shape3 StrokeCap : " + shape3.StrokeCap + "\n");
128 log.Debug(tag, "Shape4 FillRule : " + shape4.FillRule + "\n");
129 log.Debug(tag, "Shape4 StrokeWidth : " + shape4.StrokeWidth + "\n");
130 log.Debug(tag, "Shape4 StrokeJoin : " + shape4.StrokeJoin + "\n");
131 log.Debug(tag, "Shape4 Opacity : " + shape4.Opacity + "\n");
133 for (int i = 0; i < shape2.StrokeDash.Count; i++)
135 log.Debug(tag, "Shape4 StrokeDash : " + shape2.StrokeDash[i] + "\n");
141 shape2.Transform(new float[] { 0.6f, 0.0f });
143 catch (ArgumentException e)
145 log.Debug(tag, "Transform : " + e.Message + "\n");
149 shape2.Transform(null);
151 catch (ArgumentException e)
153 log.Debug(tag, "Transform : " + e.Message + "\n");
157 shape2.StrokeDash = null;
159 catch (ArgumentException e)
161 log.Debug(tag, "StrokeDash setter : " + e.Message + "\n");
164 root.Add(canvasView);
166 timer = new Timer(1000 / 32);
167 timer.Tick += onTick;
171 public void Deactivate()
175 NUIApplication.GetDefaultWindow().Remove(root);
176 canvasView.Dispose();
181 private bool onTick(object o, Timer.TickEventArgs e)
183 shape.Rotate((float)(count * 2.0f));
184 shape.Scale((float)(count % 100) * 0.01f + 0.6f);