1 #include <../../nrnconf.h> 2 #if HAVE_IV // to end of file 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> 33 virtual ~XYView_helper();
46 static XYView* current_pick_view_;
47 static XYView* current_draw_view_;
51 XYView_helper::current_pick_view_ =
v;
55 float a00, a01, a10, a11, a20, a21;
56 t.matrix(a00, a01, a10, a11, a20, a21);
57 printf(
"%s transform %g %g %g %g %g %g\n", s, a00, a01, a10, a11, a20, a21);
62 void XYView_helper::request(
Requisition& req)
const {
63 Requirement rx(v_->width(), 0, 0, -v_->left()/v_->width());
64 Requirement ry(v_->height(), 0, 0, -v_->bottom()/v_->height());
70 t_ = c->transformer();
72 body()->allocate(c, a, ext);
76 current_draw_view_ = v_;
77 ((XYView_helper*)
this)->t_ = c->transformer();
79 v_->set_damage_area(c);
85 tr.translate(3*72, 4*72);
90 c->clip_rect(v_->left(), v_->bottom(), v_->right(), v_->top());
97 current_draw_view_ = v_;
99 c->clip_rect(v_->left(), v_->bottom(), v_->right(), v_->top());
103 v_->s2o().matrix(x, b, b, b, b, b);
104 sprintf(buf,
"\n%g setlinewidth", x);
112 Allotment ax(v_->left(), v_->width(), 0);
113 Allotment ay(v_->bottom(), v_->height(), 0);
117 body()->print(c, a1);
122 if (
MyMath::inside(h.left(), h.bottom(), v_->left(), v_->bottom(),
123 v_->right(), v_->top())) {
124 if (h.event()->grabber()) {
131 h.target(depth,
this, 0, h.event()->grabber());
136 current_pick_view_ = v_;
137 MonoGlyph::pick(c, a, depth, h);
138 if (h.event()->type() == Event::down) {
140 printf(
"XYView_helper hit (%g, %g) event (%g, %g)\n", h.left(), h.bottom(),
141 h.event()->pointer_x(), h.event()->pointer_y());
148 static Coord pick_epsilon;
149 static void set_pick_epsilon() {
163 init(x1, y1, xs, ys, s, xsize, ysize);
170 csize(0., xsize, 0., ysize);
178 if (view_margin_ ==
fil) {
179 Style* style = Session::instance()->style();
180 if (!style->find_attribute(
"view_margin", view_margin_)) {
190 XYView_helper::~XYView_helper() {
191 if (v_ == current_pick_view_) {
192 current_pick_view_ =
NULL;
194 if (v_ == current_draw_view_) {
195 current_draw_view_ =
NULL;
201 scene()->remove_view(
this);
207 return XYView_helper::current_pick_view_;
210 XYView* XYView_helper::current_pick_view_;
216 return XYView_helper::current_draw_view_;
219 XYView* XYView_helper::current_draw_view_;
230 if (scene()->drawing_fixed_item()) {
231 c->stroke(color, brush);
235 c->stroke(color, brush);
246 TransformSetter::undraw();
252 canvas_->push_transform();
253 canvas_->transformer(((XYView_helper*)body())->t_);
256 canvas_->transform(s2o());
258 view_ratio(a.
x(), a.
y(), x, y);
260 s2o().inverse_transform(a.
x(), a.
y(), x, y);
265 g->allocate(canvas_, a_fix, e);
267 g->allocate(canvas_, a, e);
271 canvas_->pop_transform();
278 canvas_->damage(xc0_, yc0_, xc0_ + xsize_, yc0_ + ysize_);
285 Coord tx1, ty1, tx2, ty2;
286 t.transform(x1, y1, tx1, ty1);
287 t.transform(x2, y2, tx2, ty2);
288 const float off = canvas_->to_coord(1);
291 tx2 =
Math::min(tx2+off, canvas_->width());
292 ty2 =
Math::min(ty2+off, canvas_->height());
293 canvas_->damage(tx1, ty1, tx2, ty2);
299 c->restrict_damage(0.,0., c->width(), c->height());
301 const float off = c->to_coord(1);
302 c->transformer().inverse_transform(e.
left()-off, e.
bottom()-off, xd1_, yd1_);
303 c->transformer().inverse_transform(e.
right()+off, e.
top()+off, xd2_, yd2_);
314 TransformSetter::request(req);
322 #if defined(WIN32) || defined(CYGWIN) 328 if (canvas_ ==
NULL) {
332 TransformSetter::allocate(c, a, ext);
339 if (h.event()->type() == Event::down) {
341 printf(
"XYView hit (%g, %g) event (%g, %g)\n", h.left(), h.bottom(),
342 h.event()->pointer_x(), h.event()->pointer_y());
345 TransformSetter::pick(c, a, depth, h);
359 x = xrat*xsize_ + xc0_;
360 y = yrat*ysize_ + yc0_;
364 xrat = (x - xc0_)/xsize_;
365 yrat = (y - yc0_)/ysize_;
391 size(x1, y1, x2, y2);
401 y1 = bottom(); y2 = top();
404 x1 -= dx; x2 += dx; y1 -= dy; y2 += dy;
409 y1 = bottom(); y2 = top();
410 dx = .1/1.2*(x2 - x1);
411 dy = .1/1.2*(y2 - y1);
412 x1 += dx; x2 -= dx; y1 += dy; y2 -= dy;
426 Coord x1, y1, x2, y2;
428 sprintf(buf,
"{save_window_.view(%g, %g, %g, %g, %g, %g, %g, %g)}",
429 x1, y1, x2 - x1, y2 - y1,
458 ax.
span(alx.
span() - 2*view_margin());
462 ay.
span(aly.
span() - 2*view_margin());
482 float sx = xsize_/width();
483 float sy = ysize_/height();
487 t.translate( -
left(), -bottom());
491 printf(
"XYView::transform ax origin=%g span=%g alignment=%g begin=%g\n",
493 printf(
"XYView::transform ay origin=%g span=%g alignment=%g begin=%g %g\n",
495 printf(
"XYView::transform natx origin=%g span=%g alignment=%g begin=%g\n",
497 printf(
"XYView::transform naty origin=%g span=%g alignment=%g begin=%g %g\n",
508 :
XYView(x - span/2., y - (ysize/xsize)*span/2., span, span, s, xsize, ysize)
514 :
XYView(x1, y1, xs, ys, s, xsize, ysize) {
527 Coord magx = w/x_span_;
528 Coord magy = h/y_span_;
538 origin((x1+x2)/2, (y1+y2)/2);
556 t.translate( -x(), -y());
565 t.transform(x() - x_span_/2, y() - y_span_/2, x1, y1);
567 t.inverse_transform(ax.
begin(), ay.
begin(), x1, y1);
577 Coord x0, x1, y0, y1;
583 }
else if (dy < .9*dx) {
590 s2o().transform(0, 0, x0, y0);
591 s2o().transform(dx, dy, x1, y1);
592 x0 = x0 - x1 +
left();
593 y0 = y0 - y1 + bottom();
626 }
else if (dy < .9*dx) {
633 s2o().transform(xorg, yorg, x0, y0);
636 b = -(bottom()-y0)*dy + bottom();
638 t = -(top()-y0)*dy + top();
661 s2o().inverse_transform(x1,y1,l,b);
662 s2o().inverse_transform(x2,y2,r,t);
663 return new XYView( x1, y1, x2-x1, y2-y1, scene(), r-l, t-b);
668 s2o().inverse_transform(x1,y1,l,b);
669 s2o().inverse_transform(x2,y2,r,t);
670 return new View( (x1+x2)/2, (y1+y2)/2, x2-x1, scene(), r-l, t-b);
675 NPInsetFrame(
Glyph*);
676 virtual ~NPInsetFrame();
680 NPInsetFrame::NPInsetFrame(
Glyph* g)
682 NPInsetFrame::~NPInsetFrame(){}
684 Style* s = WidgetKit::instance()->style();
686 s->find_attribute(
"scene_print_border", i);
691 ((
MonoGlyph*)body())->body()->print(p, a);
721 Scene* s = v_->scene();
726 sprintf(buf,
"scene_vector_[%ld] = save_window_", i);
728 sprintf(buf,
"save_window_ = scene_vector_[%ld]", i);
Transformer scene2viewparent_
void allot_x(const Allotment &)
virtual void scale_view(Coord xorg, Coord yorg, float dxscale, float dyscale)
virtual void damage_all()
static ostream * idraw_stream
virtual void transform(Transformer &, const Allocation &, const Allocation &natural) const
void scene2view(const Allocation &parent) const
double max(double a, double b)
virtual Coord bottom() const
virtual void save_phase2(std::ostream &)
virtual XYView * new_view(Coord x1, Coord y1, Coord x2, Coord y2)
virtual void pick(Canvas *, const Allocation &, int depth, Hit &)
virtual void move_view(Coord dx, Coord dy)
static bool equal(float x, float y, float e)
virtual const char * select_name()
virtual Coord top() const
virtual void stroke(Canvas *, const Color *, const Brush *)
virtual void box_size(Coord x1, Coord y1, Coord x2, Coord y2)
virtual void request(Requisition &) const
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
static bool inside(Coord x, Coord min, Coord max)
void size(Coord x1, Coord y1, Coord x2, Coord y2)
static double round(float &x1, float &x2, int direction, int digits)
void allot_y(const Allotment &)
int const size_t const size_t n
virtual void box_size(Coord x1, Coord y1, Coord x2, Coord y2)
virtual void damage(Glyph *, const Allocation &, bool fixed=false, bool viewfixed=false)
virtual void view_ratio(float xratio, float yratio, Coord &x, Coord &y) const
virtual Coord left() const
static Coord view_margin_
XYView(Scene *, Coord xsize=200, Coord ysize=200)
virtual void transform(Transformer &, const Allocation &, const Allocation &natural) const
virtual void attach(Observer *)
static XYView * current_draw_view()
virtual XYView * new_view(Coord x1, Coord y1, Coord x2, Coord y2)
void require_y(const Requirement &)
virtual void save_phase1(std::ostream &)
virtual Coord view_width() const
virtual void unref() const
virtual void zout(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
virtual void move_view(Coord dx, Coord dy)
void init(Coord x1, Coord y1, Coord x_span, Coord y_span, Scene *, Coord xsize, Coord ysize)
void csize(Coord x0, Coord xsize, Coord y0, Coord ysize) const
ViewWindow(XYView *, const char *name)
virtual void save(std::ostream &)
virtual Coord save_bottom() const
virtual void update(Observable *)
void append_view(XYView *)
void require_x(const Requirement &)
virtual Scene * scene() const
virtual void set_damage_area(Canvas *)
virtual void scale_view(Coord xorg, Coord yorg, float dxscale, float dyscale)
virtual Coord width() const
void origin(Coord x, Coord y)
void origin(Coord x1, Coord y1)
virtual void detach(Observer *)
Allotment & x_allotment()
virtual void ratio_view(Coord x, Coord y, float &xratio, float &yratio) const
virtual void damage_area(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
virtual void allocate(Canvas *, const Allocation &, Extension &)
virtual Coord view_height() const
virtual Coord save_left() const
Allotment & y_allotment()
static XYView * current_pick_view()
void append_view(Scene *)
virtual Coord height() const
virtual void save(std::ostream &)
virtual Coord right() const
virtual void zin(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
static long scene_list_index(Scene *)
virtual void update(Observable *)