From df26a53a394b378c1360942f84b60ae728a606b5 Mon Sep 17 00:00:00 2001 From: Russell Standish Date: Wed, 18 Oct 2023 12:40:24 +1100 Subject: [PATCH] When an error occurs, only move the model if the error item is off screen, then move it to the centre of the screen. --- gui-js/libs/shared/src/lib/backend/minsky.ts | 13 +++++++++++++ model/minsky.cc | 10 ++++++++-- model/renderNativeWindow.cc | 1 + model/renderNativeWindow.h | 12 ++++++++---- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/gui-js/libs/shared/src/lib/backend/minsky.ts b/gui-js/libs/shared/src/lib/backend/minsky.ts index fc0a8e96c..dc7b089e7 100644 --- a/gui-js/libs/shared/src/lib/backend/minsky.ts +++ b/gui-js/libs/shared/src/lib/backend/minsky.ts @@ -324,6 +324,7 @@ export class CSVDialog extends CppClass { async disable(): Promise {return this.$callMethod('disable');} async draw(): Promise {return this.$callMethod('draw');} async flashNameRow(...args: boolean[]): Promise {return this.$callMethod('flashNameRow',...args);} + async frameArgs(): Promise {return this.$callMethod('frameArgs');} async getItemAt(a1: number,a2: number): Promise {return this.$callMethod('getItemAt',a1,a2);} async getWireAt(a1: number,a2: number): Promise {return this.$callMethod('getWireAt',a1,a2);} async guessSpecAndLoadFile(): Promise {return this.$callMethod('guessSpecAndLoadFile');} @@ -413,6 +414,7 @@ export class Canvas extends CppClass { async draw(): Promise {return this.$callMethod('draw');} async findVariableDefinition(): Promise {return this.$callMethod('findVariableDefinition');} async focusFollowsMouse(...args: boolean[]): Promise {return this.$callMethod('focusFollowsMouse',...args);} + async frameArgs(): Promise {return this.$callMethod('frameArgs');} async getItemAt(a1: number,a2: number): Promise {return this.$callMethod('getItemAt',a1,a2);} async getWireAt(a1: number,a2: number): Promise {return this.$callMethod('getWireAt',a1,a2);} async groupSelection(): Promise {return this.$callMethod('groupSelection');} @@ -580,6 +582,7 @@ export class EquationDisplay extends CppClass { async destroyFrame(): Promise {return this.$callMethod('destroyFrame');} async disable(): Promise {return this.$callMethod('disable');} async draw(): Promise {return this.$callMethod('draw');} + async frameArgs(): Promise {return this.$callMethod('frameArgs');} async getItemAt(a1: number,a2: number): Promise {return this.$callMethod('getItemAt',a1,a2);} async getWireAt(a1: number,a2: number): Promise {return this.$callMethod('getWireAt',a1,a2);} async hasScrollBars(): Promise {return this.$callMethod('hasScrollBars');} @@ -632,6 +635,7 @@ export class FontDisplay extends CppClass { async destroyFrame(): Promise {return this.$callMethod('destroyFrame');} async disable(): Promise {return this.$callMethod('disable');} async draw(): Promise {return this.$callMethod('draw');} + async frameArgs(): Promise {return this.$callMethod('frameArgs');} async getItemAt(a1: number,a2: number): Promise {return this.$callMethod('getItemAt',a1,a2);} async getWireAt(a1: number,a2: number): Promise {return this.$callMethod('getWireAt',a1,a2);} async hasScrollBars(): Promise {return this.$callMethod('hasScrollBars');} @@ -742,6 +746,7 @@ export class GodleyTab extends CppClass { async displayDelayedTooltip(a1: number,a2: number): Promise {return this.$callMethod('displayDelayedTooltip',a1,a2);} async draw(...args: any[]): Promise {return this.$callMethod('draw',...args);} async evenHeight(): Promise {return this.$callMethod('evenHeight');} + async frameArgs(): Promise {return this.$callMethod('frameArgs');} async getItemAt(a1: number,a2: number): Promise {return this.$callMethod('getItemAt',a1,a2);} async getVarName(a1: number): Promise {return this.$callMethod('getVarName',a1);} async getWireAt(a1: number,a2: number): Promise {return this.$callMethod('getWireAt',a1,a2);} @@ -946,6 +951,7 @@ export class GodleyTableWindow extends CppClass { async draw(...args: any[]): Promise {return this.$callMethod('draw',...args);} async drawButtons(...args: boolean[]): Promise {return this.$callMethod('drawButtons',...args);} async enableButtons(): Promise {return this.$callMethod('enableButtons');} + async frameArgs(): Promise {return this.$callMethod('frameArgs');} async getItemAt(a1: number,a2: number): Promise {return this.$callMethod('getItemAt',a1,a2);} async getWireAt(a1: number,a2: number): Promise {return this.$callMethod('getWireAt',a1,a2);} async godleyIcon(): Promise {return this.$callMethod('godleyIcon');} @@ -1492,6 +1498,7 @@ export class Panopticon extends CppClass { async destroyFrame(): Promise {return this.$callMethod('destroyFrame');} async disable(): Promise {return this.$callMethod('disable');} async draw(): Promise {return this.$callMethod('draw');} + async frameArgs(): Promise {return this.$callMethod('frameArgs');} async getItemAt(a1: number,a2: number): Promise {return this.$callMethod('getItemAt',a1,a2);} async getWireAt(a1: number,a2: number): Promise {return this.$callMethod('getWireAt',a1,a2);} async hasScrollBars(): Promise {return this.$callMethod('hasScrollBars');} @@ -1538,6 +1545,7 @@ export class PhillipsDiagram extends CppClass { async destroyFrame(): Promise {return this.$callMethod('destroyFrame');} async disable(): Promise {return this.$callMethod('disable');} async draw(): Promise {return this.$callMethod('draw');} + async frameArgs(): Promise {return this.$callMethod('frameArgs');} async getItemAt(a1: number,a2: number): Promise {return this.$callMethod('getItemAt',a1,a2);} async getWireAt(a1: number,a2: number): Promise {return this.$callMethod('getWireAt',a1,a2);} async hasScrollBars(): Promise {return this.$callMethod('hasScrollBars');} @@ -1647,6 +1655,7 @@ export class PlotTab extends CppClass { async displayDelayedTooltip(a1: number,a2: number): Promise {return this.$callMethod('displayDelayedTooltip',a1,a2);} async draw(...args: any[]): Promise {return this.$callMethod('draw',...args);} async evenHeight(): Promise {return this.$callMethod('evenHeight');} + async frameArgs(): Promise {return this.$callMethod('frameArgs');} async getItemAt(a1: number,a2: number): Promise {return this.$callMethod('getItemAt',a1,a2);} async getVarName(a1: number): Promise {return this.$callMethod('getVarName',a1);} async getWireAt(a1: number,a2: number): Promise {return this.$callMethod('getWireAt',a1,a2);} @@ -1754,6 +1763,7 @@ export class PlotWidget extends Item { async exportAsCSV(...args: any[]): Promise {return this.$callMethod('exportAsCSV',...args);} async extendPalette(): Promise {return this.$callMethod('extendPalette');} async fontScale(...args: number[]): Promise {return this.$callMethod('fontScale',...args);} + async frameArgs(): Promise {return this.$callMethod('frameArgs');} async getItemAt(a1: number,a2: number): Promise {return this.$callMethod('getItemAt',a1,a2);} async getWireAt(a1: number,a2: number): Promise {return this.$callMethod('getWireAt',a1,a2);} async grid(...args: boolean[]): Promise {return this.$callMethod('grid',...args);} @@ -1952,6 +1962,7 @@ export class RavelPopup extends CppClass { async destroyFrame(): Promise {return this.$callMethod('destroyFrame');} async disable(): Promise {return this.$callMethod('disable');} async draw(): Promise {return this.$callMethod('draw');} + async frameArgs(): Promise {return this.$callMethod('frameArgs');} async getItemAt(a1: number,a2: number): Promise {return this.$callMethod('getItemAt',a1,a2);} async getWireAt(a1: number,a2: number): Promise {return this.$callMethod('getWireAt',a1,a2);} async hasScrollBars(): Promise {return this.$callMethod('hasScrollBars');} @@ -1994,6 +2005,7 @@ export class RenderNativeWindow extends CppClass { async destroyFrame(): Promise {return this.$callMethod('destroyFrame');} async disable(): Promise {return this.$callMethod('disable');} async draw(): Promise {return this.$callMethod('draw');} + async frameArgs(): Promise {return this.$callMethod('frameArgs');} async getItemAt(a1: number,a2: number): Promise {return this.$callMethod('getItemAt',a1,a2);} async getWireAt(a1: number,a2: number): Promise {return this.$callMethod('getWireAt',a1,a2);} async hasScrollBars(): Promise {return this.$callMethod('hasScrollBars');} @@ -2317,6 +2329,7 @@ export class VariablePane extends CppClass { async disable(): Promise {return this.$callMethod('disable');} async draw(): Promise {return this.$callMethod('draw');} async evenHeight(): Promise {return this.$callMethod('evenHeight');} + async frameArgs(): Promise {return this.$callMethod('frameArgs');} async getItemAt(a1: number,a2: number): Promise {return this.$callMethod('getItemAt',a1,a2);} async getWireAt(a1: number,a2: number): Promise {return this.$callMethod('getWireAt',a1,a2);} async hasScrollBars(): Promise {return this.$callMethod('hasScrollBars');} diff --git a/model/minsky.cc b/model/minsky.cc index ead82c982..cdbedd69a 100644 --- a/model/minsky.cc +++ b/model/minsky.cc @@ -1236,8 +1236,14 @@ namespace minsky canvas.itemIndicator=canvas.item.get(); if (canvas.item) - canvas.model->moveTo(100-canvas.item->x()+canvas.model->x(), - 100-canvas.item->y()+canvas.model->y()); + { + auto physX=canvas.item->x(); + auto physY=canvas.item->y(); + if (physX<100 || physX>canvas.frameArgs().childWidth-100 || + physY<100 || physY>canvas.frameArgs().childHeight-100) + canvas.model->moveTo(0.5*canvas.frameArgs().childWidth-physX+canvas.model->x(), + 0.5*canvas.frameArgs().childHeight-physY+canvas.model->y()); + } //requestRedraw calls back into TCL, so don't call it from the simulation thread. See ticket #973 if (!RKThreadRunning) canvas.requestRedraw(); } diff --git a/model/renderNativeWindow.cc b/model/renderNativeWindow.cc index 8d6ae709c..8b559708c 100644 --- a/model/renderNativeWindow.cc +++ b/model/renderNativeWindow.cc @@ -81,6 +81,7 @@ namespace minsky void RenderNativeWindow::renderFrame(const RenderFrameArgs& args) { + m_frameArgs=args; init(); winInfoPtr.reset(); winInfoPtr = std::make_shared(stoull(args.parentWindowId), args.offsetLeft, args.offsetTop, args.childWidth, args.childHeight, args.scalingFactor, hasScrollBars(), [this](){draw();}); diff --git a/model/renderNativeWindow.h b/model/renderNativeWindow.h index ddd0530c3..898f5715b 100644 --- a/model/renderNativeWindow.h +++ b/model/renderNativeWindow.h @@ -30,10 +30,6 @@ namespace minsky class WindowInformation; class RenderNativeWindow : public ecolab::CairoSurface, public EventInterface { - private: - CLASSDESC_ACCESS(RenderNativeWindow); - classdesc::Exclude> winInfoPtr; - public: static ecolab::cairo::Colour backgroundColour; void disable(); @@ -47,6 +43,9 @@ namespace minsky int childHeight; double scalingFactor=0; }; + + + const RenderFrameArgs& frameArgs() const {return m_frameArgs;} ~RenderNativeWindow() override; /// perform any initialisation of any subclasses of this @@ -63,6 +62,11 @@ namespace minsky static double scaleFactor(); /// return whether this window has scrollbars (needed for MacOSX). virtual bool hasScrollBars() const {return false;} + + private: + CLASSDESC_ACCESS(RenderNativeWindow); + classdesc::Exclude> winInfoPtr; + RenderFrameArgs m_frameArgs; }; } // namespace minsky