Add Draw sample

This commit is contained in:
Frank A. Krueger 2017-07-07 22:55:23 -07:00
parent 906bb498c6
commit a171703b07
2 changed files with 51 additions and 1 deletions

49
Samples/DrawSample.cs Normal file
View File

@ -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);
}
}
}

View File

@ -25,8 +25,9 @@ namespace Samples
new ButtonSample ().Publish (); new ButtonSample ().Publish ();
new TodoSample ().Publish (); new TodoSample ().Publish ();
new DrawSample ().Publish ();
UI.Present ("/todo"); UI.Present ("/draw");
Console.ReadLine (); Console.ReadLine ();
} }