24 #include "publication.rcd" 27 #include "pannableTab.rcd" 28 #include "pannableTab.xcd" 39 bool variableDisplay=
false, buttonDisplay=
false;
45 item(item), editorModeToggled(item.editorMode!=item.itemRef->editorMode()),
46 origIWidth(item.itemRef? item.itemRef->iWidth(): 0),
47 origIHeight(item.itemRef? item.itemRef->iHeight(): 0),
48 origRotation(item.itemRef? item.itemRef->rotation(): 0),
49 stashedZf(
cminsky().canvas.model->relZoom)
52 if (
auto g=item.
itemRef->group.lock())
55 g->relZoom=1/g->zoomFactor();
57 if (
auto g=item.
itemRef->godleyIconCast())
59 if ((variableDisplay=g->variableDisplay()))
60 g->toggleVariableDisplay();
61 buttonDisplay=g->editor.drawButtons;
62 g->editor.disableButtons();
64 if (editorModeToggled)
65 item.
itemRef->toggleEditorMode();
74 if (
auto g=item.
itemRef->group.lock())
77 if (editorModeToggled)
78 item.
itemRef->toggleEditorMode();
79 if (
auto g=item.
itemRef->godleyIconCast())
82 g->toggleVariableDisplay();
84 g->editor.enableButtons();
86 item.
itemRef->iWidth(origIWidth);
87 item.
itemRef->iHeight(origIHeight);
88 item.
itemRef->rotation(origRotation);
93 Point PubItem::itemCoords(
float x,
float y)
const 95 if (!itemRef)
return {0,0};
96 return {x-this->x+itemRef->x(), y-this->y+itemRef->y()};
99 void PubTab::addNote(
const std::string& note,
float x,
float y)
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;
110 void PubTab::removeSelf()
113 for (
auto i=publicationTabs.begin(); i!=publicationTabs.end(); ++i)
115 publicationTabs.erase(i);
121 void PubTab::removeItemAt(
float x,
float y)
124 if (
auto item=m_getItemAt(x,y))
125 for (
auto i=items.begin(); i!=items.end(); ++i)
135 void PubTab::rotateItemAt(
float x,
float y)
138 item=m_getItemAt(x,y);
140 rotateOrigin=
Point{x,y};
145 bool PubTab::redraw(
int x0,
int y0,
int width,
int height)
147 if (!surface.get()) {
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);
157 const CairoSave cs(cairo);
158 cairo_translate(cairo, i.x, i.y);
161 const EnsureEditorMode ensureEditorMode(i);
162 i.itemRef->draw(cairo);
166 if (clickType==ClickType::onResize)
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));
172 return !items.empty() || clickType!=ClickType::outside;
175 PubItem* PubTab::m_getItemAt(
float x,
float y)
179 const EnsureEditorMode e(i);
180 if (i.itemRef && i.itemRef->contains(i.itemCoords(x,y)))
186 void PubTab::zoomTranslate(
float& x,
float& y)
189 auto scale=1.f/m_zoomFactor;
196 item=m_getItemAt(x,y);
199 const EnsureEditorMode e(*item);
200 auto p=item->itemCoords(x,y);
201 clickType=item->itemRef->clickType(p.x(),p.y());
205 case ClickType::onResize:
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;
215 case ClickType::inItem:
216 item->itemRef->onMouseDown(p.x(),p.y());
226 void PubTab::mouseUp(
float x,
float y)
238 case ClickType::onResize:
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);
247 case ClickType::inItem:
250 const EnsureEditorMode e(*item);
251 auto p=item->itemCoords(x,y);
252 item->itemRef->onMouseUp(p.x(),p.y());
260 clickType=ClickType::outside;
264 void PubTab::mouseMove(
float x,
float y)
272 for (
auto& i: items) i.itemRef->mouseFocus=
false;
277 const EnsureEditorMode e(*item);
278 item->itemRef->rotate(
Point{x,y},rotateOrigin);
279 item->rotation=item->itemRef->rotation();
284 case ClickType::onResize:
288 case ClickType::inItem:
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()))
306 if (
auto i=m_getItemAt(x,y))
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());
318 float x=args.
x, y=args.
y;
320 if (
auto item=m_getItemAt(x,y))
322 const EnsureEditorMode em(*item);
CLASSDESC_ACCESS_EXPLICIT_INSTANTIATION(schema3::PublicationItem)
bool pushHistory()
push current model state onto history if it differs from previous
represents rectangular region of a lasso operation
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky's state cha...
std::vector< PubTab > publicationTabs
Mixin implementing common panning functionality in tabs.
boost::geometry::model::d2::point_xy< float > Point
const Minsky & cminsky()
const version to help in const correctness
EnsureEditorMode(PubItem &item)
Minsky & minsky()
global minsky object