NEURON
rubband.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #if HAVE_IV // to end of file
3 
4 #include <InterViews/session.h>
5 #include <InterViews/display.h>
6 #include <InterViews/color.h>
7 #include <InterViews/brush.h>
8 #include <InterViews/canvas.h>
9 #include <InterViews/printer.h>
10 #include <InterViews/window.h>
11 #include <InterViews/transformer.h>
12 #include "rubband.h"
13 
14 #include <OS/math.h>
15 #include <stdio.h>
16 
18 }
21  Resource::unref(rb);
22 }
23 void RubberAction::help() {
24  printf("no help for this Rubberband action\n");
25 }
26 
29 void OcHandler::help() {
30  printf("no help for this handler\n");
31 }
32 
34 
36 //printf("Rubberband\n");
37  canvas(c);
38  ra_ = ra;
39  Resource::ref(ra_);
40  if (!xor_color_) {
41  xor_color_ = new Color(0,0,0,1,Color::Xor);
42  Resource::ref(xor_color_);
43  brush_ = new Brush(0);
44  Resource::ref(brush_);
45  }
46 }
47 
49 //printf("~Rubberband\n");
50  Resource::unref(ra_);
51 }
52 
53 void Rubberband::help() {
54  if (ra_) {
55  ra_->help();
56  }
57 }
58 
59 void Rubberband::canvas(Canvas* c) {
60  canvas_ = c;
61  if (c) {
62  t_ = c->transformer();
63  }
64 }
65 
67 const Color* Rubberband::color() { return xor_color_;}
69 const Brush* Rubberband::brush() { return brush_;}
70 
71 bool Rubberband::event(Event& e) {
72  e_ = &e;
73  EventType type = e.type();
74  switch (type) {
75  case Event::down:
76  current_ = this;
77 //printf("Rubberband::event down\n");
78  Resource::ref(this);
79  if (canvas_) {
80  rubber_on(canvas_);
81  }
82  e.grab(this);
83 #ifdef WIN32
84  e.window()->grab_pointer();
85 #endif
86  x_ = x_begin_ = e.pointer_x();
87  y_ = y_begin_ = e.pointer_y();
88  press(e);
89  draw(x_, y_);
90  break;
91  case Event::motion:
92  undraw(x_, y_);
93  x_ = e.pointer_x();
94  y_ = e.pointer_y();
95  drag(e);
96  draw(x_, y_);
97  break;
98  case Event::up:
99 //printf("Rubberband::event up\n");
100  current_ = NULL;
101  e.ungrab(this);
102 #ifdef WIN32
103  e.window()->ungrab_pointer();
104 #endif
105  undraw(x_, y_);
106  if (canvas_) {
107  rubber_off(canvas_);
108  }
109  x_ = e.pointer_x();
110  y_ = e.pointer_y();
111  release(e);
112  if (ra_) {
113  ra_->execute(this);
114  }
115  Resource::unref(this); //destroyed here if user never ref'ed it
116  break;
117  }
118  return true;
119 }
120 
122 void Rubberband::undraw(Coord x, Coord y){ draw(x,y); }
123 void Rubberband::press(Event&){}
124 void Rubberband::drag(Event&){}
125 void Rubberband::release(Event&){}
127  Canvas* can = canvas();
128  canvas(pr);
129  draw(x(), y());
130  canvas(can);
131 }
132 
133 
134 //RubberRect
137 void RubberRect::draw(Coord x, Coord y) {
138 //printf("RubberRect::draw(%g %g)\n", x, y);
139  Coord x1, y1, x2, y2;
140  x1 = Math::min(x, x_begin());
141  y1 = Math::min(y, y_begin());
142  x2 = Math::max(x, x_begin());
143  y2 = Math::max(y, y_begin());
144  if (x1 < x2 && y1 < y2) {
145  Canvas* c = canvas();
146  c->push_transform();
147  Transformer t;
148  c->transformer(t);
149  c->new_path();
150  c->rect(x1, y1, x2, y2, Rubberband::color(), Rubberband::brush());
151 //printf("rect %g %g %g %g\n", x1, y1, x2, y2);
152  c->pop_transform();
153  }
154 }
155 void RubberRect::help() {
157  printf("RubberRect::help\n");
158 }
159 
160 void RubberRect::get_rect_canvas(Coord& x1, Coord& y1, Coord& x2, Coord& y2)const {
161  x1 = Math::min(x(), x_begin());
162  y1 = Math::min(y(), y_begin());
163  x2 = Math::max(x(), x_begin());
164  y2 = Math::max(y(), y_begin());
165 }
166 void RubberRect::get_rect(Coord& x1, Coord& y1, Coord& x2, Coord& y2)const {
167  get_rect_canvas(x1,y1,x2,y2);
168  const Transformer& t = transformer();
169  t.inverse_transform(x1, y1);
170  t.inverse_transform(x2, y2);
171 }
172 
173 //RubberLine
176 void RubberLine::help() {
178  printf("RubberRect::help\n");
179 }
180 
181 void RubberLine::draw(Coord x, Coord y) {
182 //printf("RubberLine::draw(%g %g)\n", x, y);
183  Canvas* c = canvas();
184  c->push_transform();
185  Transformer t;
186  c->transformer(t);
187  c->new_path();
188  c->line(x_begin(), y_begin(), x, y, Rubberband::color(), Rubberband::brush());
189  c->pop_transform();
190 }
191 void RubberLine::get_line_canvas(Coord& x1, Coord& y1, Coord& x2, Coord& y2)const {
192  x1 = x_begin();
193  y1 = y_begin();
194  x2 = x();
195  y2 = y();
196 }
197 void RubberLine::get_line(Coord& x1, Coord& y1, Coord& x2, Coord& y2)const {
198  get_line_canvas(x1,y1,x2,y2);
199  const Transformer& t = transformer();
200  t.inverse_transform(x1, y1);
201  t.inverse_transform(x2, y2);
202 }
203 #endif
virtual void get_rect(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
virtual void help()
double max(double a, double b)
Definition: geometry3d.cpp:22
short type
Definition: cabvars.h:10
virtual void draw(Coord, Coord)
virtual void help()
#define min(a, b)
Definition: matrix.h:157
#define Coord
Definition: _defines.h:19
#define Brush
Definition: _defines.h:59
#define Color
Definition: _defines.h:74
virtual void press(Event &)
virtual ~RubberAction()
virtual void ref() const
Definition: resource.cpp:47
virtual void undraw(Coord x, Coord y)
static void pr(N_Vector x)
virtual void help()
#define e
Definition: passive0.cpp:24
virtual void drag(Event &)
virtual ~OcHandler()
virtual void get_line(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
Canvas * canvas() const
Definition: rubband.h:45
virtual void draw(Coord, Coord)
static const Color * color()
#define Printer
Definition: _defines.h:211
static const Color * xor_color_
Definition: rubband.h:68
virtual void drag(const Event &e)
Definition: ocinput.h:21
virtual void get_rect_canvas(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
#define printf
Definition: mwprefix.h:26
static N_Vector x_
virtual void press(const Event &e)
Definition: ocinput.h:20
virtual ~RubberLine()
#define Canvas
Definition: _defines.h:65
virtual void draw(Coord x, Coord y)
virtual void unref() const
Definition: resource.cpp:52
const Event & event() const
Definition: rubband.h:47
static N_Vector y_
#define Event
Definition: _defines.h:107
virtual ~RubberRect()
virtual void release(const Event &e)
Definition: ocinput.h:22
RubberLine(RubberAction *=NULL, Canvas *=NULL)
static Rubberband * current_
Definition: rubband.h:70
#define Transformer
Definition: _defines.h:316
static const Brush * brush_
Definition: rubband.h:69
#define EventType
Definition: _defines.h:20
virtual void execute(Rubberband *)
#define c
virtual void help()
static const Brush * brush()
virtual void snapshot(Printer *)
Rubberband(RubberAction *=NULL, Canvas *=NULL)
virtual ~Rubberband()
double t
Definition: init.cpp:123
virtual void get_line_canvas(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
virtual void help()
return NULL
Definition: cabcode.cpp:461
virtual void release(Event &)
RubberRect(RubberAction *=NULL, Canvas *=NULL)