1 #include <../../nrnconf.h>
8 #include <InterViews/event.h>
9 #include <InterViews/hit.h>
10 #include <InterViews/canvas.h>
11 #include <InterViews/printer.h>
12 #include <InterViews/session.h>
14 #include <InterViews/monoglyph.h>
15 #include <InterViews/tformsetter.h>
16 #include <InterViews/layout.h>
17 #include <InterViews/style.h>
18 #include <IV-look/kit.h>
19 #include <InterViews/background.h>
34 virtual ~XYView_helper();
49 static XYView* current_pick_view_;
50 static XYView* current_draw_view_;
54 XYView_helper::current_pick_view_ =
v;
58 float a00, a01, a10, a11, a20, a21;
59 t.matrix(a00, a01, a10, a11, a20, a21);
60 printf(
"%s transform %g %g %g %g %g %g\n",
s, a00, a01, a10, a11, a20, a21);
66 void XYView_helper::request(
Requisition& req)
const {
67 Requirement rx(v_->width(), 0, 0, -v_->left() / v_->width());
68 Requirement ry(v_->height(), 0, 0, -v_->bottom() / v_->height());
74 t_ =
c->transformer();
76 body()->allocate(
c, a, ext);
80 current_draw_view_ = v_;
81 ((XYView_helper*)
this)->t_ =
c->transformer();
83 v_->set_damage_area(
c);
89 tr.translate(3 * 72, 4 * 72);
94 c->clip_rect(v_->left(), v_->bottom(), v_->right(), v_->top());
101 current_draw_view_ = v_;
103 c->clip_rect(v_->left(), v_->bottom(), v_->right(), v_->top());
107 v_->s2o().matrix(x, b, b, b, b, b);
116 Allotment ax(v_->left(), v_->width(), 0);
117 Allotment ay(v_->bottom(), v_->height(), 0);
121 body()->print(
c, a1);
126 if (
MyMath::inside(h.left(), h.bottom(), v_->left(), v_->bottom(), v_->right(), v_->top())) {
127 if (h.event()->grabber()) {
134 h.target(depth,
this, 0, h.event()->grabber());
139 current_pick_view_ = v_;
140 MonoGlyph::pick(
c, a, depth, h);
141 if (h.event()->type() == Event::down) {
143 printf(
"XYView_helper hit (%g, %g) event (%g, %g)\n", h.left(), h.bottom(),
144 h.event()->pointer_x(), h.event()->pointer_y());
151 static Coord pick_epsilon;
152 static void set_pick_epsilon() {
159 init(
s->x1(),
s->y1(),
s->x2() -
s->x1(),
s->y2() -
s->y1(),
s, xsize, ysize);
164 init(x1, y1, xs, ys,
s, xsize, ysize);
171 csize(0., xsize, 0., ysize);
180 Style* style = Session::instance()->style();
181 if (!style->find_attribute(
"view_margin",
view_margin_)) {
191 XYView_helper::~XYView_helper() {
192 if (v_ == current_pick_view_) {
193 current_pick_view_ =
NULL;
195 if (v_ == current_draw_view_) {
196 current_draw_view_ =
NULL;
208 return XYView_helper::current_pick_view_;
211 XYView* XYView_helper::current_pick_view_;
217 return XYView_helper::current_draw_view_;
220 XYView* XYView_helper::current_draw_view_;
223 s->append_view(
this);
231 if (
scene()->drawing_fixed_item()) {
232 c->stroke(color, brush);
236 c->stroke(color, brush);
247 TransformSetter::undraw();
254 canvas_->transformer(((XYView_helper*) body())->t_);
261 s2o().inverse_transform(a.
x(), a.
y(), x, y);
266 g->allocate(
canvas_, a_fix, e);
286 Coord tx1, ty1, tx2, ty2;
287 t.transform(x1, y1, tx1, ty1);
288 t.transform(x2, y2, tx2, ty2);
289 const float off =
canvas_->to_coord(1);
290 tx1 = std::max(tx1 - off,
Coord(0));
291 ty1 = std::max(ty1 - off,
Coord(0));
292 tx2 = std::min(tx2 + off,
canvas_->width());
293 ty2 = std::min(ty2 + off,
canvas_->height());
294 canvas_->damage(tx1, ty1, tx2, ty2);
300 c->restrict_damage(0., 0.,
c->width(),
c->height());
302 const float off =
c->to_coord(1);
315 TransformSetter::request(req);
333 TransformSetter::allocate(
c, a, ext);
340 if (h.event()->type() == Event::down) {
342 printf(
"XYView hit (%g, %g) event (%g, %g)\n", h.left(), h.bottom(),
343 h.event()->pointer_x(), h.event()->pointer_y());
346 TransformSetter::pick(
c, a, depth, h);
351 return (
Scene*) (((XYView_helper*) body())->body());
384 x1_ = std::min(x1, x2);
385 y1_ = std::min(y1, y2);
406 size(x1, y1, x2, y2);
438 dx = .1 / 1.2 * (x2 - x1);
439 dy = .1 / 1.2 * (y2 - y1);
457 Coord x1, y1, x2, y2;
460 "{save_window_.view(%g, %g, %g, %g, %g, %g, %g, %g)}",
469 o <<
buf << std::endl;
522 printf(
"XYView::transform ax origin=%g span=%g alignment=%g begin=%g\n",
524 printf(
"XYView::transform ay origin=%g span=%g alignment=%g begin=%g %g\n",
526 printf(
"XYView::transform natx origin=%g span=%g alignment=%g begin=%g\n",
528 printf(
"XYView::transform naty origin=%g span=%g alignment=%g begin=%g %g\n",
535 :
XYView(
s,
s->x2() -
s->x1(),
s->y2() -
s->y1()) {
540 :
XYView(x - span / 2., y - (ysize / xsize) * span / 2., span, span,
s, xsize, ysize) {
545 :
XYView(x1, y1, xs, ys,
s, xsize, ysize) {
569 origin((x1 + x2) / 2, (y1 + y2) / 2);
593 t.translate(-
x(), -
y());
596 v->x_pick_epsilon_ = pick_epsilon / sx;
597 v->y_pick_epsilon_ = pick_epsilon / sx;
605 t.inverse_transform(ax.
begin(), ay.
begin(), x1, y1);
606 v->x_span_ = 2 * (
x() - x1);
607 v->y_span_ = 2 * (
y() - y1);
608 v->size(x1, y1, x1 +
v->x_span_, y1 +
v->y_span_);
614 Coord x0, x1, y0, y1;
615 Coord dx = std::abs(dx1);
616 Coord dy = std::abs(dy1);
620 }
else if (dy < .9 * dx) {
627 s2o().transform(0, 0, x0, y0);
628 s2o().transform(dx, dy, x1, y1);
629 x0 = x0 - x1 +
left();
658 Coord dx = std::abs(dxscl);
659 Coord dy = std::abs(dyscl);
663 }
else if (dy < .9 * dx) {
675 t = -(
top() - y0) * dy +
top();
698 s2o().inverse_transform(x1, y1, l, b);
699 s2o().inverse_transform(x2, y2, r,
t);
700 return new XYView(x1, y1, x2 - x1, y2 - y1,
scene(), r - l,
t - b);
705 s2o().inverse_transform(x1, y1, l, b);
706 s2o().inverse_transform(x2, y2, r,
t);
707 return new View((x1 + x2) / 2, (y1 + y2) / 2, x2 - x1,
scene(), r - l,
t - b);
712 NPInsetFrame(
Glyph*);
713 virtual ~NPInsetFrame();
717 NPInsetFrame::NPInsetFrame(
Glyph* g)
719 NPInsetFrame::~NPInsetFrame() {}
721 Style*
s = WidgetKit::instance()->style();
723 s->find_attribute(
"scene_print_border",
i);
735 new NPInsetFrame(
LayoutKit::instance()->variable_span(
v)),
756 Sprintf(
buf,
"scene_vector_[%ld] = save_window_",
i);
758 Sprintf(
buf,
"save_window_ = scene_vector_[%ld]",
i);
760 o <<
buf << std::endl;
786 "%s %s x %g : %g y %g : %g",
788 v->scene()->picker()->select_name(),
void allot_y(const Allotment &)
Allotment & x_allotment()
Allotment & y_allotment()
void allot_x(const Allotment &)
virtual Glyph * glyph() const
virtual const char * name() const
static bool eq(T x, T y, T e)
static bool inside(Coord x, Coord min, Coord max)
static double round(float &x1, float &x2, int direction, int digits)
virtual void detach(Observer *)
virtual PrintableWindow * window()
static std::ostream * idraw_stream
virtual void save(std::ostream &)
virtual Coord save_left() const
virtual Coord save_bottom() const
const char * type() const
void require_x(const Requirement &)
void require_y(const Requirement &)
virtual void unref() const
static long scene_list_index(Scene *)
void remove_view(XYView *)
virtual void move_view(Coord dx, Coord dy)
virtual XYView * new_view(Coord x1, Coord y1, Coord x2, Coord y2)
virtual void transform(Transformer &, const Allocation &, const Allocation &natural) const
virtual void scale_view(Coord xorg, Coord yorg, float dxscale, float dyscale)
void origin(Coord x, Coord y)
virtual Coord view_height() const
virtual Coord view_width() const
virtual void box_size(Coord x1, Coord y1, Coord x2, Coord y2)
ViewWindow(XYView *, const char *name)
virtual void update(Observable *)
virtual void damage_area(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
virtual Coord bottom() const
virtual Coord height() const
XYView(Scene *, Coord xsize=200, Coord ysize=200)
virtual void move_view(Coord dx, Coord dy)
virtual Coord top() const
virtual void view_ratio(float xratio, float yratio, Coord &x, Coord &y) const
void init(Coord x1, Coord y1, Coord x_span, Coord y_span, Scene *, Coord xsize, Coord ysize)
virtual void zout(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
virtual void allocate(Canvas *, const Allocation &, Extension &)
void size(Coord x1, Coord y1, Coord x2, Coord y2)
virtual Scene * scene() const
virtual void set_damage_area(Canvas *)
virtual Coord width() const
void origin(Coord x1, Coord y1)
virtual void damage(Glyph *, const Allocation &, bool fixed=false, bool viewfixed=false)
static Coord view_margin_
virtual Coord left() const
void csize(Coord x0, Coord xsize, Coord y0, Coord ysize) const
virtual XYView * new_view(Coord x1, Coord y1, Coord x2, Coord y2)
Transformer scene2viewparent_
virtual void pick(Canvas *, const Allocation &, int depth, Hit &)
virtual void save(std::ostream &)
virtual void request(Requisition &) const
virtual void transform(Transformer &, const Allocation &, const Allocation &natural) const
virtual void ratio_view(Coord x, Coord y, float &xratio, float &yratio) const
virtual void damage_all()
virtual Coord right() const
virtual void scale_view(Coord xorg, Coord yorg, float dxscale, float dyscale)
virtual void box_size(Coord x1, Coord y1, Coord x2, Coord y2)
void scene2view(const Allocation &parent) const
virtual void zin(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
static XYView * current_draw_view()
static XYView * current_pick_view()
virtual void stroke(Canvas *, const Color *, const Brush *)
const Transformer & s2o() const
Coord view_margin() const
void append_view(Scene *)
void update(NrnThread *_nt)
int Sprintf(char(&buf)[N], const char *fmt, Args &&... args)
Redirect sprintf to snprintf if the buffer size can be deduced.
int const size_t const size_t n