Minsky
minsky::PubTab Class Reference

#include <pubTab.h>

Inheritance diagram for minsky::PubTab:
Inheritance graph
Collaboration diagram for minsky::PubTab:
Collaboration graph

Public Member Functions

 PubTab ()=default
 
 PubTab (const char *name)
 
 PubTab (const std::string &name)
 
void addNote (const std::string &note, float x, float y)
 
void removeSelf ()
 remove this from the global minsky object calling this method will invalidate any references to this, and potentially call its destructor More...
 
void removeItemAt (float x, float y)
 
void rotateItemAt (float x, float y)
 
void toggleEditorModeAt (float x, float y)
 
bool getItemAt (float x, float y) override
 item or wire obtained by get*At() calls More...
 
void mouseDown (float x, float y) override
 
void controlMouseDown (float x, float y) override
 
void mouseUp (float x, float y) override
 
void mouseMove (float x, float y) override
 
bool keyPress (const EventInterface::KeyPressArgs &) override
 handle key press over current itemFocus, More...
 
bool hasScrollBars () const override
 return whether this window has scrollbars (needed for MacOSX). More...
 
- Public Member Functions inherited from minsky::PannableTab< PubTabBase >
 PannableTab ()
 
 PannableTab (A &arg)
 
void mouseDown (float x, float y) override
 
void mouseUp (float x, float y) override
 
void mouseMove (float x, float y) override
 
void moveTo (float x, float y) override
 
std::vector< float > position () const override
 
void zoom (double x, double y, double z) override
 
double zoomFactor () const override
 
- Public Member Functions inherited from minsky::RenderNativeWindow
const RenderFrameArgsframeArgs () const
 
 ~RenderNativeWindow () override
 
virtual void init ()
 perform any initialisation of any subclasses of this More...
 
void renderFrame (const RenderFrameArgs &args)
 
void destroyFrame ()
 
void draw ()
 
void requestRedraw ()
 
void macOSXRedraw ()
 
RenderNativeWindowoperator= (const RenderNativeWindow &x)
 
 RenderNativeWindow ()=default
 
 RenderNativeWindow (const RenderNativeWindow &)=default
 
- Public Member Functions inherited from minsky::EventInterface
virtual bool getWireAt (float x, float y)
 item or wire obtained by get*At() calls More...
 

Public Attributes

std::string name
 name of this publication tab More...
 
std::vector< PubItemitems
 list of wrapped items and annotations More...
 
- Public Attributes inherited from minsky::PubTabBase
float offsx =0
 
float offsy =0
 
float m_zoomFactor =1
 
bool panning =false
 
- Public Attributes inherited from minsky::EventInterface
ItemPtr item
 item or wire obtained by get*At() calls More...
 
WirePtr wire
 item or wire obtained by get*At() calls More...
 

Private Member Functions

bool redraw (int x0, int y0, int width, int height) override
 
 CLASSDESC_ACCESS (PubTab)
 
PubItemm_getItemAt (float x, float y)
 
void zoomTranslate (float &x, float &y)
 

Private Attributes

PubItemitem =nullptr
 
bool rotating =false
 
ClickType::Type clickType =ClickType::outside
 
float dx
 
float dy
 relative offset between mouse and item origin when moving More...
 
Exclude< PointrotateOrigin
 reference position for rotating More...
 
LassoBox lasso
 

Additional Inherited Members

- Static Public Member Functions inherited from minsky::RenderNativeWindow
static double scaleFactor ()
 
- Static Public Attributes inherited from minsky::RenderNativeWindow
static ecolab::cairo::Colour backgroundColour {0.8,0.8,0.8,1}
 

Detailed Description

Definition at line 51 of file pubTab.h.

Constructor & Destructor Documentation

◆ PubTab() [1/3]

minsky::PubTab::PubTab ( )
default

◆ PubTab() [2/3]

minsky::PubTab::PubTab ( const char *  name)
inline

Definition at line 65 of file pubTab.h.

65 : name(name) {}
std::string name
name of this publication tab
Definition: pubTab.h:67

◆ PubTab() [3/3]

minsky::PubTab::PubTab ( const std::string &  name)
inline

Definition at line 66 of file pubTab.h.

66 : name(name) {}
std::string name
name of this publication tab
Definition: pubTab.h:67

Member Function Documentation

◆ addNote()

void minsky::PubTab::addNote ( const std::string &  note,
float  x,
float  y 
)

Definition at line 99 of file pubTab.cc.

References pyminsky::minsky, and minsky::Minsky::pushHistory().

100  {
101  items.emplace_back(std::make_shared<Item>());
102  items.back().itemRef->detailedText(note);
103  items.back().x=x-offsx;
104  items.back().y=y-offsy;
105  minsky().pushHistory();
106  requestRedraw();
107  }
bool pushHistory()
push current model state onto history if it differs from previous
Definition: minsky.cc:1265
std::vector< PubItem > items
list of wrapped items and annotations
Definition: pubTab.h:68
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ CLASSDESC_ACCESS()

minsky::PubTab::CLASSDESC_ACCESS ( PubTab  )
private

◆ controlMouseDown()

void minsky::PubTab::controlMouseDown ( float  x,
float  y 
)
inlineoverridevirtual

Reimplemented from minsky::EventInterface.

Definition at line 85 of file pubTab.h.

References minsky::PannableTab< Base >::mouseDown(), and minsky::PubTabBase::panning.

void mouseDown(float x, float y) override
Definition: pannableTab.h:44
Here is the call graph for this function:

◆ getItemAt()

bool minsky::PubTab::getItemAt ( float  x,
float  y 
)
inlineoverridevirtual

item or wire obtained by get*At() calls

Reimplemented from minsky::EventInterface.

Definition at line 80 of file pubTab.h.

References m_getItemAt(), and zoomTranslate().

80  {
81  zoomTranslate(x,y);
82  return m_getItemAt(x,y);
83  }
PubItem * m_getItemAt(float x, float y)
Definition: pubTab.cc:175
void zoomTranslate(float &x, float &y)
Definition: pubTab.cc:186
Here is the call graph for this function:

◆ hasScrollBars()

bool minsky::PubTab::hasScrollBars ( ) const
inlineoverridevirtual

return whether this window has scrollbars (needed for MacOSX).

Reimplemented from minsky::RenderNativeWindow.

Definition at line 89 of file pubTab.h.

89 {return true;}

◆ keyPress()

bool minsky::PubTab::keyPress ( const EventInterface::KeyPressArgs )
overridevirtual

handle key press over current itemFocus,

Parameters
keySymthe X key sym code
utf8utf8 encoded character
statemodifer state 1=shift, 2=caps lock, 4=ctrl, 8=alt
x& y contain mouse coordinates
Returns
true if event handled

Reimplemented from minsky::EventInterface.

Definition at line 316 of file pubTab.cc.

References minsky::EventInterface::KeyPressArgs::keySym, minsky::EventInterface::KeyPressArgs::state, minsky::EventInterface::KeyPressArgs::utf8, minsky::EventInterface::KeyPressArgs::x, and minsky::EventInterface::KeyPressArgs::y.

317  {
318  float x=args.x, y=args.y;
319  zoomTranslate(x,y);
320  if (auto item=m_getItemAt(x,y))
321  {
322  const EnsureEditorMode em(*item);
323  if (item->itemRef->onKeyPress(args.keySym,args.utf8,args.state))
324  {
325  requestRedraw();
326  return true;
327  }
328  }
329  return false;
330  }
ItemPtr itemRef
Definition: pubTab.h:39
PubItem * m_getItemAt(float x, float y)
Definition: pubTab.cc:175
void zoomTranslate(float &x, float &y)
Definition: pubTab.cc:186
PubItem * item
Definition: pubTab.h:55

◆ m_getItemAt()

PubItem * minsky::PubTab::m_getItemAt ( float  x,
float  y 
)
private

Definition at line 175 of file pubTab.cc.

Referenced by getItemAt(), and toggleEditorModeAt().

176  {
177  for (auto& i: items)
178  {
179  const EnsureEditorMode e(i);
180  if (i.itemRef && i.itemRef->contains(i.itemCoords(x,y)))
181  return &i;
182  }
183  return nullptr;
184  }
std::vector< PubItem > items
list of wrapped items and annotations
Definition: pubTab.h:68
Here is the caller graph for this function:

◆ mouseDown()

void minsky::PubTab::mouseDown ( float  x,
float  y 
)
overridevirtual

Reimplemented from minsky::EventInterface.

Definition at line 193 of file pubTab.cc.

194  {
195  zoomTranslate(x,y);
196  item=m_getItemAt(x,y);
197  if (item)
198  {
199  const EnsureEditorMode e(*item);
200  auto p=item->itemCoords(x,y);
201  clickType=item->itemRef->clickType(p.x(),p.y());
202  dx=dy=0;
203  switch (clickType)
204  {
205  case ClickType::onResize:
206  {
207  auto w=item->itemRef->width()/item->zoomX;
208  auto h=item->itemRef->height()/item->zoomY;
209  lasso.x0=x>item->x? x-w: x+w;
210  lasso.y0=y>item->y? y-h: y+h;
211  lasso.x1=x;
212  lasso.y1=y;
213  }
214  break;
215  case ClickType::inItem:
216  item->itemRef->onMouseDown(p.x(),p.y());
217  break;
218  default:
219  dx=item->x-x;
220  dy=item->y-y;
221  break;
222  }
223  }
224  }
float dy
relative offset between mouse and item origin when moving
Definition: pubTab.h:60
float dx
Definition: pubTab.h:60
ItemPtr itemRef
Definition: pubTab.h:39
ClickType::Type clickType
Definition: pubTab.h:59
PubItem * m_getItemAt(float x, float y)
Definition: pubTab.cc:175
Point itemCoords(float x, float y) const
given (x,y) in PubTab, returns coordinates within item. Nb: must be wrapped by EnsureEditorMode ...
Definition: pubTab.cc:93
void zoomTranslate(float &x, float &y)
Definition: pubTab.cc:186
PubItem * item
Definition: pubTab.h:55
float x0
Definition: lasso.h:30
float y1
Definition: lasso.h:30
float x1
Definition: lasso.h:30
float y0
Definition: lasso.h:30
LassoBox lasso
Definition: pubTab.h:62

◆ mouseMove()

void minsky::PubTab::mouseMove ( float  x,
float  y 
)
overridevirtual

Reimplemented from minsky::EventInterface.

Definition at line 264 of file pubTab.cc.

265  {
266  zoomTranslate(x,y);
267  if (panning)
268  {
270  return;
271  }
272  for (auto& i: items) i.itemRef->mouseFocus=false;
273  if (item)
274  {
275  if (rotating)
276  {
277  const EnsureEditorMode e(*item);
278  item->itemRef->rotate(Point{x,y},rotateOrigin);
279  item->rotation=item->itemRef->rotation();
280  }
281  else
282  switch (clickType)
283  {
284  case ClickType::onResize:
285  lasso.x1=x;
286  lasso.y1=y;
287  break;
288  case ClickType::inItem:
289  {
290  const EnsureEditorMode e(*item);
291  auto p=item->itemCoords(x,y);
292  item->itemRef->mouseFocus=true;
293  if (item->itemRef->onMouseMotion(p.x(),p.y()))
294  requestRedraw();
295  }
296  break;
297  default:
298  item->x=x+dx;
299  item->y=y+dy;
300  break;
301  }
302  requestRedraw();
303  }
304  else
305  // indicate mouse focus
306  if (auto i=m_getItemAt(x,y))
307  {
308  i->itemRef->mouseFocus=true;
309  const EnsureEditorMode e(*i);
310  auto p=i->itemCoords(x,y);
311  i->itemRef->onMouseOver(p.x(),p.y());
312  requestRedraw();
313  }
314  }
float dy
relative offset between mouse and item origin when moving
Definition: pubTab.h:60
float dx
Definition: pubTab.h:60
ItemPtr itemRef
Definition: pubTab.h:39
std::vector< PubItem > items
list of wrapped items and annotations
Definition: pubTab.h:68
ClickType::Type clickType
Definition: pubTab.h:59
void mouseMove(float x, float y) override
Definition: pannableTab.h:55
PubItem * m_getItemAt(float x, float y)
Definition: pubTab.cc:175
Point itemCoords(float x, float y) const
given (x,y) in PubTab, returns coordinates within item. Nb: must be wrapped by EnsureEditorMode ...
Definition: pubTab.cc:93
bool rotating
Definition: pubTab.h:58
void zoomTranslate(float &x, float &y)
Definition: pubTab.cc:186
boost::geometry::model::d2::point_xy< float > Point
Definition: geometry.h:34
PubItem * item
Definition: pubTab.h:55
Exclude< Point > rotateOrigin
reference position for rotating
Definition: pubTab.h:61
float y1
Definition: lasso.h:30
float x1
Definition: lasso.h:30
LassoBox lasso
Definition: pubTab.h:62

◆ mouseUp()

void minsky::PubTab::mouseUp ( float  x,
float  y 
)
overridevirtual

Reimplemented from minsky::EventInterface.

Definition at line 226 of file pubTab.cc.

References pyminsky::minsky, minsky::Minsky::pushHistory(), and minsky::Minsky::requestReset().

227  {
228  if (panning)
229  {
231  panning=false;
232  return;
233  }
234  mouseMove(x,y);
235  if (item)
236  switch (clickType)
237  {
238  case ClickType::onResize:
239  {
240  const EnsureEditorMode e(*item);
241  item->zoomX*=abs(lasso.x1-lasso.x0)/(item->itemRef->width());
242  item->zoomY*=abs(lasso.y1-lasso.y0)/(item->itemRef->height());
243  item->x=0.5*(lasso.x0+lasso.x1);
244  item->y=0.5*(lasso.y0+lasso.y1);
245  }
246  break;
247  case ClickType::inItem:
248  {
249  zoomTranslate(x,y);
250  const EnsureEditorMode e(*item);
251  auto p=item->itemCoords(x,y);
252  item->itemRef->onMouseUp(p.x(),p.y());
253  minsky().requestReset();
254  }
255  break;
256  default: break;
257  }
258  minsky().pushHistory();
259  item=nullptr;
261  rotating=false;
262  }
ItemPtr itemRef
Definition: pubTab.h:39
void requestReset()
Definition: minsky.cc:467
void mouseMove(float x, float y) override
Definition: pubTab.cc:264
bool pushHistory()
push current model state onto history if it differs from previous
Definition: minsky.cc:1265
ClickType::Type clickType
Definition: pubTab.h:59
Point itemCoords(float x, float y) const
given (x,y) in PubTab, returns coordinates within item. Nb: must be wrapped by EnsureEditorMode ...
Definition: pubTab.cc:93
bool rotating
Definition: pubTab.h:58
void zoomTranslate(float &x, float &y)
Definition: pubTab.cc:186
PubItem * item
Definition: pubTab.h:55
float x0
Definition: lasso.h:30
float y1
Definition: lasso.h:30
float x1
Definition: lasso.h:30
float y0
Definition: lasso.h:30
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
void mouseUp(float x, float y) override
Definition: pannableTab.h:50
LassoBox lasso
Definition: pubTab.h:62
Here is the call graph for this function:

◆ redraw()

bool minsky::PubTab::redraw ( int  x0,
int  y0,
int  width,
int  height 
)
overrideprivate

Definition at line 145 of file pubTab.cc.

146  {
147  if (!surface.get()) {
148  return false;
149  }
150  auto cairo=surface->cairo();
151  const CairoSave cs(cairo);
152  cairo_translate(cairo, offsx, offsy);
153  cairo_scale(cairo, m_zoomFactor, m_zoomFactor);
154  cairo_set_line_width(cairo, 1);
155  for (auto& i: items)
156  {
157  const CairoSave cs(cairo);
158  cairo_translate(cairo, i.x, i.y);
159  try
160  {
161  const EnsureEditorMode ensureEditorMode(i);
162  i.itemRef->draw(cairo);
163  }
164  catch (...) {}
165  }
167  {
168  cairo_rectangle(cairo,std::min(lasso.x0,lasso.x1), std::min(lasso.y0,lasso.y1),
169  abs(lasso.x0-lasso.x1), abs(lasso.y0-lasso.y1));
170  cairo_stroke(cairo);
171  }
172  return !items.empty() || clickType!=ClickType::outside;
173  }
std::vector< PubItem > items
list of wrapped items and annotations
Definition: pubTab.h:68
ClickType::Type clickType
Definition: pubTab.h:59
float m_zoomFactor
Definition: pubTab.h:47
float x0
Definition: lasso.h:30
float y1
Definition: lasso.h:30
float x1
Definition: lasso.h:30
float y0
Definition: lasso.h:30
LassoBox lasso
Definition: pubTab.h:62

◆ removeItemAt()

void minsky::PubTab::removeItemAt ( float  x,
float  y 
)

Definition at line 121 of file pubTab.cc.

References pyminsky::minsky, and minsky::Minsky::pushHistory().

122  {
123  zoomTranslate(x,y);
124  if (auto item=m_getItemAt(x,y))
125  for (auto i=items.begin(); i!=items.end(); ++i)
126  if (&*i==item)
127  {
128  items.erase(i);
129  minsky().pushHistory();
130  requestRedraw();
131  return;
132  }
133  }
bool pushHistory()
push current model state onto history if it differs from previous
Definition: minsky.cc:1265
std::vector< PubItem > items
list of wrapped items and annotations
Definition: pubTab.h:68
PubItem * m_getItemAt(float x, float y)
Definition: pubTab.cc:175
void zoomTranslate(float &x, float &y)
Definition: pubTab.cc:186
PubItem * item
Definition: pubTab.h:55
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ removeSelf()

void minsky::PubTab::removeSelf ( )

remove this from the global minsky object calling this method will invalidate any references to this, and potentially call its destructor

Definition at line 110 of file pubTab.cc.

References pyminsky::minsky, minsky::minsky(), minsky::Minsky::publicationTabs, and minsky::Minsky::pushHistory().

111  {
112  auto& publicationTabs=minsky::minsky().publicationTabs;
113  for (auto i=publicationTabs.begin(); i!=publicationTabs.end(); ++i)
114  if (this==&*i) {
115  publicationTabs.erase(i);
116  minsky().pushHistory();
117  return;
118  }
119  }
bool pushHistory()
push current model state onto history if it differs from previous
Definition: minsky.cc:1265
std::vector< PubTab > publicationTabs
Definition: minsky.h:156
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ rotateItemAt()

void minsky::PubTab::rotateItemAt ( float  x,
float  y 
)

Definition at line 135 of file pubTab.cc.

136  {
137  zoomTranslate(x,y);
138  item=m_getItemAt(x,y);
139  if (item) {
140  rotateOrigin=Point{x,y};
141  rotating=true;
142  }
143  }
PubItem * m_getItemAt(float x, float y)
Definition: pubTab.cc:175
bool rotating
Definition: pubTab.h:58
void zoomTranslate(float &x, float &y)
Definition: pubTab.cc:186
boost::geometry::model::d2::point_xy< float > Point
Definition: geometry.h:34
PubItem * item
Definition: pubTab.h:55
Exclude< Point > rotateOrigin
reference position for rotating
Definition: pubTab.h:61

◆ toggleEditorModeAt()

void minsky::PubTab::toggleEditorModeAt ( float  x,
float  y 
)
inline

Definition at line 75 of file pubTab.h.

References m_getItemAt(), and zoomTranslate().

75  {
76  zoomTranslate(x,y);
77  if (auto i=m_getItemAt(x,y))
78  i->editorMode=!i->editorMode;
79  }
PubItem * m_getItemAt(float x, float y)
Definition: pubTab.cc:175
void zoomTranslate(float &x, float &y)
Definition: pubTab.cc:186
Here is the call graph for this function:

◆ zoomTranslate()

void minsky::PubTab::zoomTranslate ( float &  x,
float &  y 
)
private

Definition at line 186 of file pubTab.cc.

References minsky::anonymous_namespace{minskyTCL.cc}::scale().

Referenced by getItemAt(), and toggleEditorModeAt().

187  {
188  x-=offsx; y-=offsy;
189  auto scale=1.f/m_zoomFactor;
190  x*=scale; y*=scale;
191  }
float m_zoomFactor
Definition: pubTab.h:47
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ clickType

ClickType::Type minsky::PubTab::clickType =ClickType::outside
private

Definition at line 59 of file pubTab.h.

◆ dx

float minsky::PubTab::dx
private

Definition at line 60 of file pubTab.h.

◆ dy

float minsky::PubTab::dy
private

relative offset between mouse and item origin when moving

Definition at line 60 of file pubTab.h.

◆ item

PubItem* minsky::PubTab::item =nullptr
private

Definition at line 55 of file pubTab.h.

◆ items

std::vector<PubItem> minsky::PubTab::items

list of wrapped items and annotations

Definition at line 68 of file pubTab.h.

◆ lasso

LassoBox minsky::PubTab::lasso
private

Definition at line 62 of file pubTab.h.

◆ name

std::string minsky::PubTab::name

name of this publication tab

Definition at line 67 of file pubTab.h.

◆ rotateOrigin

Exclude<Point> minsky::PubTab::rotateOrigin
private

reference position for rotating

Definition at line 61 of file pubTab.h.

◆ rotating

bool minsky::PubTab::rotating =false
private

Definition at line 58 of file pubTab.h.


The documentation for this class was generated from the following files: