From a171703b070917925e16f8960f69d29b77a32841 Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Fri, 7 Jul 2017 22:55:23 -0700 Subject: [PATCH] Add Draw sample --- Samples/DrawSample.cs | 49 +++++++++++++++++++++++++++++++++++++++++++ Samples/Program.cs | 3 ++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 Samples/DrawSample.cs diff --git a/Samples/DrawSample.cs b/Samples/DrawSample.cs new file mode 100644 index 0000000..1b54c79 --- /dev/null +++ b/Samples/DrawSample.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Ooui; + +namespace Samples +{ + public class DrawSample + { + public void Publish () + { + var heading = new Heading ("Draw"); + var subtitle = new Paragraph ("Click to draw a collaborative masterpiece"); + var canvas = new Canvas { + Width = 320, + Height = 240, + }; + var context = canvas.GetContext2D (); + + canvas.Clicked += (s, e) => { + context.BeginPath (); + context.Rect (e.OffsetX - 5, e.OffsetY - 5, 10, 10); + context.Fill (); + }; + canvas.Style.Cursor = "pointer"; + canvas.Style.BorderColor = "#CCC"; + canvas.Style.BorderStyle = "solid"; + canvas.Style.BorderWidth = "1px"; + + var clearbtn = new Button ("Clear") { + Type = ButtonType.Submit, + ClassName = "btn btn-danger", + }; + clearbtn.Clicked += (s, e) => { + context.ClearRect (0, 0, canvas.Width, canvas.Height); + }; + clearbtn.Style.Display = "block"; + + var app = new Div (); + app.AppendChild (heading); + app.AppendChild (subtitle); + app.AppendChild (canvas); + app.AppendChild (clearbtn); + UI.Publish ("/draw", app); + } + } +} + + diff --git a/Samples/Program.cs b/Samples/Program.cs index 6a6be46..251adf7 100644 --- a/Samples/Program.cs +++ b/Samples/Program.cs @@ -25,8 +25,9 @@ namespace Samples new ButtonSample ().Publish (); new TodoSample ().Publish (); + new DrawSample ().Publish (); - UI.Present ("/todo"); + UI.Present ("/draw"); Console.ReadLine (); }