public Task Delay(decimal milliSeconds) { // Update display if needed GraphicsDisplayStore.UpdateDisplay(); return(Task.Delay((int)milliSeconds)); }
public async Task StartLoop() { void onTextInput(string text) { this.engine.InputReceived(); } TextDisplayStore.TextInput += onTextInput; while (true) { switch (this.engine.State) { case ExecutionState.Running: await TextDisplayStore.SetInputMode(AcceptedInputMode.None).ConfigureAwait(false); await this.engine.Execute().ConfigureAwait(false); this.ExecutedStep?.Invoke(); break; case ExecutionState.BlockedOnNumberInput: await TextDisplayStore.SetInputMode(AcceptedInputMode.Numbers).ConfigureAwait(false); break; case ExecutionState.BlockedOnStringInput: await TextDisplayStore.SetInputMode(AcceptedInputMode.Strings).ConfigureAwait(false); break; case ExecutionState.Paused: await TextDisplayStore.SetInputMode(AcceptedInputMode.None).ConfigureAwait(false); break; case ExecutionState.Terminated: await TextDisplayStore.SetInputMode(AcceptedInputMode.None).ConfigureAwait(false); if (CompilationStore.Compilation.Analysis.UsesTextWindow) { await this.Libraries.TextWindow.WriteLine(EditorResources.TextDisplay_TerminateMessage).ConfigureAwait(false); } this.ExecutedStep?.Invoke(); TextDisplayStore.TextInput -= onTextInput; return; default: throw ExceptionUtilities.UnexpectedValue(this.engine.State); } // Libraries should not call this, so that we actually refresh the UI once every batch GraphicsDisplayStore.UpdateDisplay(); // Important to prevent th UI from freezing await Task.Delay(1).ConfigureAwait(false); } }
protected override void ComposeTree(TreeComposer composer) { if (!this.IsVisible) { return; } composer.Element( name: "graphics-display", attributes: new Dictionary <string, string> { { "tabindex", "0" }, // required to receive focus }, styles: new Dictionary <string, string> { { "cursor", this.IsMouseVisible ? "initial" : "none" } }, body: () => { if (!string.IsNullOrEmpty(this.Title)) { composer.Element( name: "title", body: () => composer.Text(this.Title)); } composer.Element( name: "svg", capture: element => this.RenderArea = element, attributes: new Dictionary <string, string> { { "height", "100%" }, { "width", "100%" }, }, events: new TreeComposer.Events { OnMouseDown = args => GraphicsDisplayStore.NotifyMouseDown(args.ClientX, args.ClientY, GetMouseButton(args.Button)), OnMouseUp = args => GraphicsDisplayStore.NotifyMouseUp(args.ClientX, args.ClientY, GetMouseButton(args.Button)), OnMouseMove = args => GraphicsDisplayStore.NotifyMouseMove(args.ClientX, args.ClientY), }, body: () => { if (!this.Libraries.IsDefault()) { this.Libraries.ImageList.EmbedImages(composer); this.Libraries.GraphicsWindow.ComposeTree(composer); this.Libraries.Shapes.ComposeTree(composer); this.Libraries.Turtle.ComposeTree(composer); } }); if (!this.Libraries.IsDefault()) { this.Libraries.Controls.ComposeTree(composer); } }); }
public Task OnKeyDown(string key) { GraphicsDisplayStore.NotifyKeyDown(key); return(Task.CompletedTask); }
public Task UpdateDisplayLocation(decimal x, decimal y) { GraphicsDisplayStore.UpdateDisplayLocation(x, y); return(Task.CompletedTask); }
public GraphicsDisplay() { this.IsVisible = true; this.IsMouseVisible = true; GraphicsDisplayStore.SetDisplay(this); }
public void ShowCursor() => GraphicsDisplayStore.SetMouseVisibility(true);
public void HideCursor() => GraphicsDisplayStore.SetMouseVisibility(false);