Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions gui-js/libs/shared/src/lib/backend/minsky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class Item extends CppClass {
async detailedText(...args: any[]): Promise<string> {return this.$callMethod('detailedText',...args);}
async disableDelayedTooltip(): Promise<void> {return this.$callMethod('disableDelayedTooltip');}
async displayDelayedTooltip(a1: number,a2: number): Promise<void> {return this.$callMethod('displayDelayedTooltip',a1,a2);}
async displayTooltip(a1: mansoura__IMansoura,a2: string): Promise<void> {return this.$callMethod('displayTooltip',a1,a2);}
async displayTooltip(a1: mansoura__IMansoura,a2: number): Promise<void> {return this.$callMethod('displayTooltip',a1,a2);}
async draw(a1: mansoura__IMansoura): Promise<void> {return this.$callMethod('draw',a1);}
async drawPorts(a1: mansoura__IMansoura): Promise<void> {return this.$callMethod('drawPorts',a1);}
async drawResizeHandles(a1: mansoura__IMansoura): Promise<void> {return this.$callMethod('drawResizeHandles',a1);}
Expand Down Expand Up @@ -113,6 +113,7 @@ export class Item extends CppClass {
async throw_error(a1: string): Promise<void> {return this.$callMethod('throw_error',a1);}
async toggleEditorMode(): Promise<void> {return this.$callMethod('toggleEditorMode');}
async tooltip(...args: any[]): Promise<string> {return this.$callMethod('tooltip',...args);}
async tooltipText(): Promise<string> {return this.$callMethod('tooltipText');}
async top(): Promise<number> {return this.$callMethod('top');}
async units(a1: boolean): Promise<object> {return this.$callMethod('units',a1);}
async updateBoundingBox(): Promise<void> {return this.$callMethod('updateBoundingBox');}
Expand Down Expand Up @@ -222,7 +223,7 @@ export class VariableBase extends Item {
async dims(): Promise<number[]> {return this.$callMethod('dims');}
async disableDelayedTooltip(): Promise<void> {return this.$callMethod('disableDelayedTooltip');}
async displayDelayedTooltip(a1: number,a2: number): Promise<void> {return this.$callMethod('displayDelayedTooltip',a1,a2);}
async displayTooltip(a1: mansoura__IMansoura,a2: string): Promise<void> {return this.$callMethod('displayTooltip',a1,a2);}
async displayTooltip(a1: mansoura__IMansoura,a2: number): Promise<void> {return this.$callMethod('displayTooltip',a1,a2);}
async draw(a1: mansoura__IMansoura): Promise<void> {return this.$callMethod('draw',a1);}
async drawPorts(a1: mansoura__IMansoura): Promise<void> {return this.$callMethod('drawPorts',a1);}
async drawResizeHandles(a1: mansoura__IMansoura): Promise<void> {return this.$callMethod('drawResizeHandles',a1);}
Expand Down Expand Up @@ -300,6 +301,7 @@ export class VariableBase extends Item {
async toggleEditorMode(): Promise<void> {return this.$callMethod('toggleEditorMode');}
async toggleLocal(): Promise<void> {return this.$callMethod('toggleLocal');}
async tooltip(...args: any[]): Promise<string> {return this.$callMethod('tooltip',...args);}
async tooltipText(): Promise<string> {return this.$callMethod('tooltipText');}
async top(): Promise<number> {return this.$callMethod('top');}
async type(): Promise<string> {return this.$callMethod('type');}
async typeName(a1: number): Promise<string> {return this.$callMethod('typeName',a1);}
Expand Down Expand Up @@ -965,7 +967,7 @@ export class Group extends Item {
async displayContents(): Promise<boolean> {return this.$callMethod('displayContents');}
async displayContentsChanged(): Promise<boolean> {return this.$callMethod('displayContentsChanged');}
async displayDelayedTooltip(a1: number,a2: number): Promise<void> {return this.$callMethod('displayDelayedTooltip',a1,a2);}
async displayTooltip(a1: mansoura__IMansoura,a2: string): Promise<void> {return this.$callMethod('displayTooltip',a1,a2);}
async displayTooltip(a1: mansoura__IMansoura,a2: number): Promise<void> {return this.$callMethod('displayTooltip',a1,a2);}
async displayZoom(...args: number[]): Promise<number> {return this.$callMethod('displayZoom',...args);}
async draw(a1: mansoura__IMansoura): Promise<void> {return this.$callMethod('draw',a1);}
async draw1edge(a1: Sequence<VariableBase>,a2: mansoura__IMansoura,a3: number): Promise<void> {return this.$callMethod('draw1edge',a1,a2,a3);}
Expand Down Expand Up @@ -1058,6 +1060,7 @@ export class Group extends Item {
async title(...args: string[]): Promise<string> {return this.$callMethod('title',...args);}
async toggleEditorMode(): Promise<void> {return this.$callMethod('toggleEditorMode');}
async tooltip(...args: any[]): Promise<string> {return this.$callMethod('tooltip',...args);}
async tooltipText(): Promise<string> {return this.$callMethod('tooltipText');}
async top(): Promise<number> {return this.$callMethod('top');}
async uniqueItems(...args: any[]): Promise<boolean> {return this.$callMethod('uniqueItems',...args);}
async units(a1: boolean): Promise<object> {return this.$callMethod('units',a1);}
Expand Down Expand Up @@ -1724,6 +1727,7 @@ export class Ravel extends Item {
async sortOrder(): Promise<string> {return this.$callMethod('sortOrder');}
async toggleDisplayFilterCaliper(): Promise<boolean> {return this.$callMethod('toggleDisplayFilterCaliper');}
async toggleEditorMode(): Promise<void> {return this.$callMethod('toggleEditorMode');}
async tooltipText(): Promise<string> {return this.$callMethod('tooltipText');}
async units(a1: boolean): Promise<object> {return this.$callMethod('units',a1);}
}

Expand Down Expand Up @@ -1854,7 +1858,7 @@ export class Selection extends CppClass {
async displayContents(): Promise<boolean> {return this.$callMethod('displayContents');}
async displayContentsChanged(): Promise<boolean> {return this.$callMethod('displayContentsChanged');}
async displayDelayedTooltip(a1: number,a2: number): Promise<void> {return this.$callMethod('displayDelayedTooltip',a1,a2);}
async displayTooltip(a1: mansoura__IMansoura,a2: string): Promise<void> {return this.$callMethod('displayTooltip',a1,a2);}
async displayTooltip(a1: mansoura__IMansoura,a2: number): Promise<void> {return this.$callMethod('displayTooltip',a1,a2);}
async displayZoom(...args: number[]): Promise<number> {return this.$callMethod('displayZoom',...args);}
async draw(a1: mansoura__IMansoura): Promise<void> {return this.$callMethod('draw',a1);}
async draw1edge(a1: Sequence<VariableBase>,a2: mansoura__IMansoura,a3: number): Promise<void> {return this.$callMethod('draw1edge',a1,a2,a3);}
Expand Down Expand Up @@ -1949,6 +1953,7 @@ export class Selection extends CppClass {
async toggleEditorMode(): Promise<void> {return this.$callMethod('toggleEditorMode');}
async toggleItemMembership(a1: Item): Promise<void> {return this.$callMethod('toggleItemMembership',a1);}
async tooltip(...args: any[]): Promise<string> {return this.$callMethod('tooltip',...args);}
async tooltipText(): Promise<string> {return this.$callMethod('tooltipText');}
async top(): Promise<number> {return this.$callMethod('top');}
async uniqueItems(...args: any[]): Promise<boolean> {return this.$callMethod('uniqueItems',...args);}
async units(a1: boolean): Promise<object> {return this.$callMethod('units',a1);}
Expand Down Expand Up @@ -2034,13 +2039,13 @@ export class UserFunction extends Item {
async compile(): Promise<void> {return this.$callMethod('compile');}
async create(a1: string): Promise<UserFunction> {return this.$callMethod('create',a1);}
async description(...args: any[]): Promise<string> {return this.$callMethod('description',...args);}
async displayTooltip(a1: mansoura__IMansoura,a2: string): Promise<void> {return this.$callMethod('displayTooltip',a1,a2);}
async draw(a1: mansoura__IMansoura): Promise<void> {return this.$callMethod('draw',a1);}
async evaluate(a1: number,a2: number): Promise<number> {return this.$callMethod('evaluate',a1,a2);}
async expression(...args: string[]): Promise<string> {return this.$callMethod('expression',...args);}
async name(): Promise<string> {return this.$callMethod('name');}
async nextId(...args: number[]): Promise<number> {return this.$callMethod('nextId',...args);}
async symbolNames(): Promise<string[]> {return this.$callMethod('symbolNames');}
async tooltipText(): Promise<string> {return this.$callMethod('tooltipText');}
async units(...args: any[]): Promise<object> {return this.$callMethod('units',...args);}
}

Expand Down
34 changes: 34 additions & 0 deletions model/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,40 @@ namespace minsky
return false;
});

// draw tooltips last, so they are on top of everything else (ticket #780)
{
// only clamp to a real viewport, not the huge region used for export
const double viewport[]={updateRegion.x0,updateRegion.y0,updateRegion.x1,updateRegion.y1};
const bool finite=updateRegion.x1-updateRegion.x0<1e5 && updateRegion.y1-updateRegion.y0<1e5;
auto drawTooltip=[&](const Item& it) {
const PreserveContext cs(mans);
mans.identityMatrix();
mans.translate(it.x(), it.y());
it.displayTooltip(mans,finite? viewport: nullptr);
};
auto hasFocus=[](const Item& it) {
if (it.mouseFocus) return true;
// io variables show their tooltips when the owning group is focused
if (!it.ioVar()) return false;
auto g=it.group.lock();
return g && g->mouseFocus;
};
model->recursiveDo
(&GroupItems::items, [&](const Items&, Items::const_iterator i)
{
if ((*i)->visible() && updateRegion.intersects(**i) && hasFocus(**i))
drawTooltip(**i);
return false;
});
model->recursiveDo
(&GroupItems::groups, [&](const Groups&, Groups::const_iterator i)
{
if ((*i)->visible() && updateRegion.intersects(**i) && hasFocus(**i))
drawTooltip(**i);
return false;
});
}

if (fromPort.get()) // we're in process of creating a wire
{
didDrawSomething = true;
Expand Down
1 change: 0 additions & 1 deletion model/godleyIcon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ namespace minsky
if (mouseFocus)
{
drawPorts(cairoShim);
displayTooltip(cairoShim,tooltip());
drawResizeHandles(cairoShim);
}

Expand Down
1 change: 0 additions & 1 deletion model/group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,6 @@ namespace minsky

if (mouseFocus)
{
displayTooltip(cairoShim,tooltip());
// Resize handles always visible on mousefocus. For ticket 92.
drawResizeHandles(cairoShim);
}
Expand Down
1 change: 0 additions & 1 deletion model/intOp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ namespace minsky
if (mouseFocus)
{
drawPorts(cairoShim);
displayTooltip(cairoShim,tooltip());
}
if (onResizeHandles) drawResizeHandles(cairoShim);

Expand Down
18 changes: 11 additions & 7 deletions model/item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,6 @@ namespace minsky
cairoShim.moveTo(r.x(-w+1,-h+2), r.y(-w+1,-h+2));
cairoShim.showText(tp);

if (mouseFocus) {
displayTooltip(cairoShim,tooltip());
}
if (onResizeHandles) drawResizeHandles(cairoShim);
cairoShim.moveTo(r.x(-w,-h), r.y(-w,-h));
cairoShim.lineTo(r.x(w,-h), r.y(w,-h));
Expand All @@ -394,20 +391,27 @@ namespace minsky
inkExtents([this](const IMansoura& shim) {draw(shim);});
}

void Item::displayTooltip(const mansoura::IMansoura& cairoShim, const std::string& tooltip) const
void Item::displayTooltip(const mansoura::IMansoura& cairoShim, const double* viewport) const
{
const string tooltip=tooltipText();
const string unitstr=units().latexStr();
if (!tooltip.empty() || !unitstr.empty())
{
cairoShim.save();
string toolTipText=latexToPango(tooltip);
if (!unitstr.empty())
toolTipText+=" Units:"+latexToPango(unitstr);
toolTipText+=(toolTipText.empty()? "": "\n")+("Units:"+latexToPango(unitstr)); // units on their own line
TextProperties tp(toolTipText);
const float z=zoomFactor();
cairoShim.translate(z*(0.5*bb.width())+10,
z*(-0.5*bb.height())-20);
auto bbox=cairoShim.textExtents(tp);
double tx=z*(0.5*bb.width())+10, ty=z*(-0.5*bb.height())-20;
if (viewport)
{
// keep tooltip on screen, favouring the top left corner if too big
tx=std::max(viewport[0]-x(), std::min(tx, viewport[2]-bbox.width-x()));
ty=std::max(viewport[1]-y(), std::min(ty, viewport[3]-bbox.height-y()));
}
cairoShim.translate(tx,ty);
cairoShim.rectangle(0,0,bbox.width,bbox.height);
cairoShim.setSourceRGB(1,1,1);
cairoShim.fill(true);
Expand Down
9 changes: 7 additions & 2 deletions model/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,13 @@ namespace minsky
/// port positions
void dummyDraw() const;

/// display tooltip text, eg on mouseover
virtual void displayTooltip(const mansoura::IMansoura&, const std::string&) const;
/// text to display as a tooltip on mouseover
virtual std::string tooltipText() const {return tooltip();}

/// display tooltip text, eg on mouseover. The current origin must
/// be (x(),y()). If viewport {x0,y0,x1,y1} is given, the tooltip
/// is shifted if necessary to lie within it.
virtual void displayTooltip(const mansoura::IMansoura&, const double* viewport=nullptr) const;

/// update display after a step()
virtual void updateIcon(double t) {}
Expand Down
1 change: 0 additions & 1 deletion model/lock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ namespace minsky
if (mouseFocus)
{
drawPorts(cairoShim);
displayTooltip(cairoShim,tooltip());
if (onResizeHandles) drawResizeHandles(cairoShim);
}

Expand Down
2 changes: 0 additions & 2 deletions model/operation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ namespace minsky
if (mouseFocus)
{
drawPorts(cairoShim);
displayTooltip(cairoShim,tooltip());
if (onResizeHandles) drawResizeHandles(cairoShim);
}
// Re-create the clip path
Expand Down Expand Up @@ -317,7 +316,6 @@ namespace minsky
if (mouseFocus)
{
drawPorts(cairoShim);
displayTooltip(cairoShim,tooltip());
if (onResizeHandles) drawResizeHandles(cairoShim);
}

Expand Down
1 change: 0 additions & 1 deletion model/plotWidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ namespace minsky
if (mouseFocus)
{
drawPorts(cairoShim);
displayTooltip(cairoShim,tooltip());
// Resize handles always visible on mousefocus. For ticket 92.
drawResizeHandles(cairoShim);
}
Expand Down
1 change: 0 additions & 1 deletion model/ravelWrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ namespace minsky
if (mouseFocus)
{
drawPorts(cairoShim);
displayTooltip(cairoShim,tooltip().empty()? explanation: tooltip());
// Resize handles always visible on mousefocus. For ticket 92.
if (m_editorMode) drawResizeHandles(cairoShim);
}
Expand Down
1 change: 1 addition & 0 deletions model/ravelWrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ namespace minsky
/// @param preservePositions if true, do not rotate handles
void applyState(const ravel::RavelState& state);
void displayDelayedTooltip(float x, float y) override;
std::string tooltipText() const override {return tooltip().empty()? explanation: tooltip();}
/// export the plotted data as a CSV file
/// @param tabular - if true, the longest dimension is split across columns as a horizontal dimension
void exportAsCSV(const std::string& filename, bool tabular) const;
Expand Down
1 change: 0 additions & 1 deletion model/sheet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ void Sheet::draw(const IMansoura& cairo) const
if (mouseFocus)
{
drawPorts(cairo);
displayTooltip(cairo,tooltip());
// Resize handles always visible on mousefocus. For ticket 92.
drawResizeHandles(cairo);
}
Expand Down
1 change: 0 additions & 1 deletion model/switchIcon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ namespace minsky
if (mouseFocus)
{
drawPorts(cairoShim);
displayTooltip(cairoShim,tooltip());
if (onResizeHandles) drawResizeHandles(cairoShim);
}

Expand Down
4 changes: 2 additions & 2 deletions model/userFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ namespace minsky
double operator()(const std::vector<double>& p) override;

Units units(bool check=false) const override;
void displayTooltip(const mansoura::IMansoura& cr, const std::string& tt) const override
{Item::displayTooltip(cr,tt.empty()? expression: tt+" "+expression);}
Units units(const std::vector<Units>& argUnits, bool check,
const std::vector<double>& argValues={}) const;
std::string tooltipText() const override
{return tooltip().empty()? expression: tooltip()+" "+expression;}

using NamedOp::description;
std::string description(const std::string&) override;
Expand Down
1 change: 0 additions & 1 deletion model/variable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,6 @@ void VariableBase::draw(const IMansoura& cairoShim) const
{
cairoShim.save();
drawPorts(cairoShim);
displayTooltip(cairoShim,tooltip());
if (onResizeHandles) drawResizeHandles(cairoShim);
cairoShim.restore();
}
Expand Down
Loading