Add properties to Context2D

This commit is contained in:
Frank A. Krueger 2017-06-19 21:55:20 -07:00
parent d2f1d7584a
commit 0537ccf2fe
4 changed files with 89 additions and 4 deletions

View File

@ -24,7 +24,7 @@ namespace Ooui
{ {
} }
public Context2d GetContext2d () public CanvasRenderingContext2D GetContext2D ()
{ {
if (System.Threading.Interlocked.CompareExchange (ref gotContext2d, 1, 0) == 0) { if (System.Threading.Interlocked.CompareExchange (ref gotContext2d, 1, 0) == 0) {
var mcall = Message.Call (Id, "getContext", "2d"); var mcall = Message.Call (Id, "getContext", "2d");

View File

@ -2,9 +2,89 @@ namespace Ooui
{ {
public class CanvasRenderingContext2D : EventTarget public class CanvasRenderingContext2D : EventTarget
{ {
object fillStyle = "#000";
public object FillStyle {
get => fillStyle;
set => SetProperty (ref fillStyle, value, "fillStyle");
}
double fontSize = 10;
public double FontSize {
get => fontSize;
set {
if (fontSize != value) {
fontSize = value;
SetProperty (ref font, GetFont (), "font", "Font");
OnPropertyChanged ("FontSize");
}
}
}
string fontFamily = "sans-serif";
public string FontFamily {
get => fontFamily;
set {
if (fontFamily != value) {
fontFamily = value ?? "sans-serif";
SetProperty (ref font, GetFont (), "font", "Font");
OnPropertyChanged ("FontFamily");
}
}
}
string font = "10px sans-serif";
public string Font => font;
string GetFont ()
{
var size = FontSize.ToString (System.Globalization.CultureInfo.InvariantCulture);
return $"{size}px {FontFamily}";
}
double globalAlpha = 1;
public double GlobalAlpha {
get => globalAlpha;
set => SetProperty (ref globalAlpha, value, "globalAlpha");
}
LineCap lineCap = LineCap.Butt;
public LineCap LineCap {
get => lineCap;
set => SetProperty (ref lineCap, value, "lineCap");
}
LineJoin lineJoin = LineJoin.Miter;
public LineJoin LineJoin {
get => lineJoin;
set => SetProperty (ref lineJoin, value, "lineJoin");
}
double lineWidth = 1;
public double LineWidth {
get => lineWidth;
set => SetProperty (ref lineWidth, value, "lineWidth");
}
object strokeStyle = "#000";
public object StrokeStyle {
get => strokeStyle;
set => SetProperty (ref strokeStyle, value, "strokeStyle");
}
public CanvasRenderingContext2D () public CanvasRenderingContext2D ()
: base ("#canvasRenderingContext2D") : base ("#canvasRenderingContext2D")
{ {
} }
} }
public enum LineCap
{
Butt,
Round,
Square
}
public enum LineJoin
{
Bevel,
Round,
Miter
}
} }

View File

@ -89,9 +89,14 @@ namespace Ooui
return false; return false;
backingStore = newValue; backingStore = newValue;
SendSet (attributeName, newValue); SendSet (attributeName, newValue);
OnPropertyChanged (propertyName);
return true; return true;
} }
protected virtual void OnPropertyChanged (string propertyName)
{
}
public const char IdPrefix = '\u2999'; public const char IdPrefix = '\u2999';
static long idCounter = 0; static long idCounter = 0;

View File

@ -9,13 +9,13 @@ namespace Tests
public class CanvasTests public class CanvasTests
{ {
[TestMethod] [TestMethod]
public void Context2dState () public void Context2DState ()
{ {
var c = new Canvas (); var c = new Canvas ();
Assert.AreEqual (1, c.StateMessages.Count); Assert.AreEqual (1, c.StateMessages.Count);
var c2d = c.GetContext2d (); var c2d = c.GetContext2D ();
Assert.AreEqual (2, c.StateMessages.Count); Assert.AreEqual (2, c.StateMessages.Count);
var c2d2 = c.GetContext2d (); var c2d2 = c.GetContext2D ();
Assert.AreEqual (2, c.StateMessages.Count); Assert.AreEqual (2, c.StateMessages.Count);
Assert.AreEqual (c2d, c2d2); Assert.AreEqual (c2d, c2d2);
} }