public static WebGLRenderingContext Create3DContext(CanvasElement canvas) { string[] names = new string[] { "webgl", "experimental-webgl", "webkit-3d", "moz-webgl" }; WebGLRenderingContext context = null; foreach (string name in names) { try { context = canvas.GetContext(name).As<WebGLRenderingContext>(); } catch { } if (context != null) { break; } } return context; }
public CanvasContext(CanvasElement canvas, InputElement input) : base(canvas.Width, canvas.Height) { imageCache = new Dictionary<string, ImageElement>(); this.input = input; input.Type = InputType.Text; input.Value = "A"; input.OnInput = (e) => { if(input.Value == "") { KeyPressed("Back"); } KeyPressed(input.Value.Substr(Math.Max(0, input.Value.Length - 1), input.Value.Length)); input.Value = "A"; }; context = canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D); context.FillStyle = "#000000"; context.LineWidth = 2; context.TextBaseline = CanvasTypes.CanvasTextBaselineAlign.Middle; double canvasLeft = context.Canvas.GetBoundingClientRect().Left; double canvasRight = context.Canvas.GetBoundingClientRect().Left; context.Canvas.AddEventListener(EventType.Click, (e) => { Click(e.As<MouseEvent>().ClientX + Document.Body.ScrollLeft - (int)canvasLeft, e.As<MouseEvent>().ClientY + Document.Body.ScrollTop - (int)canvasRight); if (ContentView.Active == true) { input.Focus(); } }); Window.OnResize = (e) => ResizeContent(); }