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 
20  Resource::unref(rb);
21 }
22 void RubberAction::help() {
23  printf("no help for this Rubberband action\n");
24 }
25 
28 void OcHandler::help() {
29  printf("no help for this handler\n");
30 }
31 
33 
35  // printf("Rubberband\n");
36  canvas(c);
37  ra_ = ra;
39  if (!xor_color_) {
40  xor_color_ = new Color(0, 0, 0, 1, Color::Xor);
42  brush_ = new Brush(0);
44  }
45 }
46 
48  // printf("~Rubberband\n");
50 }
51 
52 void Rubberband::help() {
53  if (ra_) {
54  ra_->help();
55  }
56 }
57 
59  canvas_ = c;
60  if (c) {
61  t_ = c->transformer();
62  }
63 }
64 
66 const Color* Rubberband::color() {
67  return xor_color_;
68 }
70 const Brush* Rubberband::brush() {
71  return brush_;
72 }
73 
74 bool Rubberband::event(Event& e) {
75  e_ = &e;
76  EventType type = e.type();
77  switch (type) {
78  case Event::down:
79  current_ = this;
80  // printf("Rubberband::event down\n");
81  Resource::ref(this);
82  if (canvas_) {
84  }
85  e.grab(this);
86 #ifdef WIN32
87  e.window()->grab_pointer();
88 #endif
89  x_ = x_begin_ = e.pointer_x();
90  y_ = y_begin_ = e.pointer_y();
91  press(e);
92  draw(x_, y_);
93  break;
94  case Event::motion:
95  undraw(x_, y_);
96  x_ = e.pointer_x();
97  y_ = e.pointer_y();
98  drag(e);
99  draw(x_, y_);
100  break;
101  case Event::up:
102  // printf("Rubberband::event up\n");
103  current_ = NULL;
104  e.ungrab(this);
105 #ifdef WIN32
106  e.window()->ungrab_pointer();
107 #endif
108  undraw(x_, y_);
109  if (canvas_) {
111  }
112  x_ = e.pointer_x();
113  y_ = e.pointer_y();
114  release(e);
115  if (ra_) {
116  ra_->execute(this);
117  }
118  Resource::unref(this); // destroyed here if user never ref'ed it
119  break;
120  }
121  return true;
122 }
123 
124 void Rubberband::draw(Coord, Coord) {}
125 void Rubberband::undraw(Coord x, Coord y) {
126  draw(x, y);
127 }
128 void Rubberband::press(Event&) {}
129 void Rubberband::drag(Event&) {}
130 void Rubberband::release(Event&) {}
132  Canvas* can = canvas();
133  canvas(pr);
134  draw(x(), y());
135  canvas(can);
136 }
137 
138 
139 // RubberRect
141  : Rubberband(ra, c) {}
143 void RubberRect::draw(Coord x, Coord y) {
144  // printf("RubberRect::draw(%g %g)\n", x, y);
145  Coord x1, y1, x2, y2;
146  x1 = Math::min(x, x_begin());
147  y1 = Math::min(y, y_begin());
148  x2 = Math::max(x, x_begin());
149  y2 = Math::max(y, y_begin());
150  if (x1 < x2 && y1 < y2) {
151  Canvas* c = canvas();
152  c->push_transform();
153  Transformer t;
154  c->transformer(t);
155  c->new_path();
156  c->rect(x1, y1, x2, y2, Rubberband::color(), Rubberband::brush());
157  // printf("rect %g %g %g %g\n", x1, y1, x2, y2);
158  c->pop_transform();
159  }
160 }
161 void RubberRect::help() {
163  printf("RubberRect::help\n");
164 }
165 
166 void RubberRect::get_rect_canvas(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const {
167  x1 = Math::min(x(), x_begin());
168  y1 = Math::min(y(), y_begin());
169  x2 = Math::max(x(), x_begin());
170  y2 = Math::max(y(), y_begin());
171 }
172 void RubberRect::get_rect(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const {
173  get_rect_canvas(x1, y1, x2, y2);
174  const Transformer& t = transformer();
175  t.inverse_transform(x1, y1);
176  t.inverse_transform(x2, y2);
177 }
178 
179 // RubberLine
181  : Rubberband(ra, c) {}
183 void RubberLine::help() {
185  printf("RubberRect::help\n");
186 }
187 
188 void RubberLine::draw(Coord x, Coord y) {
189  // printf("RubberLine::draw(%g %g)\n", x, y);
190  Canvas* c = canvas();
191  c->push_transform();
192  Transformer t;
193  c->transformer(t);
194  c->new_path();
195  c->line(x_begin(), y_begin(), x, y, Rubberband::color(), Rubberband::brush());
196  c->pop_transform();
197 }
198 void RubberLine::get_line_canvas(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const {
199  x1 = x_begin();
200  y1 = y_begin();
201  x2 = x();
202  y2 = y();
203 }
204 void RubberLine::get_line(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const {
205  get_line_canvas(x1, y1, x2, y2);
206  const Transformer& t = transformer();
207  t.inverse_transform(x1, y1);
208  t.inverse_transform(x2, y2);
209 }
210 #endif
#define EventType
Definition: _defines.h:18
#define Color
Definition: _defines.h:72
#define Transformer
Definition: _defines.h:313
#define Canvas
Definition: _defines.h:63
#define Coord
Definition: _defines.h:17
#define Brush
Definition: _defines.h:57
#define Printer
Definition: _defines.h:209
#define Event
Definition: _defines.h:105
virtual ~OcHandler()
virtual void help()
virtual void ref() const
Definition: resource.cpp:42
virtual void unref() const
Definition: resource.cpp:47
virtual void execute(Rubberband *)
virtual ~RubberAction()
virtual void help()
virtual void get_line(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
virtual void help()
virtual ~RubberLine()
virtual void draw(Coord, Coord)
RubberLine(RubberAction *=NULL, Canvas *=NULL)
virtual void get_line_canvas(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
virtual void get_rect(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
virtual void get_rect_canvas(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
virtual void draw(Coord, Coord)
virtual ~RubberRect()
virtual void help()
RubberRect(RubberAction *=NULL, Canvas *=NULL)
static const Brush * brush_
Definition: rubband.h:79
Coord x_begin_
Definition: rubband.h:77
Coord x() const
Definition: rubband.h:107
void rubber_off(Canvas *)
const Event & event() const
Definition: rubband.h:51
virtual void undraw(Coord x, Coord y)
Rubberband(RubberAction *=NULL, Canvas *=NULL)
Transformer t_
Definition: rubband.h:74
static const Color * xor_color_
Definition: rubband.h:78
Coord y_begin() const
Definition: rubband.h:116
virtual void drag(Event &)
virtual void release(Event &)
virtual ~Rubberband()
static const Color * color()
virtual void snapshot(Printer *)
RubberAction * ra_
Definition: rubband.h:76
Event * e_
Definition: rubband.h:75
Coord x_
Definition: rubband.h:77
Coord y() const
Definition: rubband.h:110
Canvas * canvas_
Definition: rubband.h:73
static Rubberband * current_
Definition: rubband.h:80
const Transformer & transformer() const
Definition: rubband.h:48
Coord x_begin() const
Definition: rubband.h:113
void rubber_on(Canvas *)
Canvas * canvas() const
Definition: rubband.h:45
static const Brush * brush()
virtual void press(Event &)
Coord y_
Definition: rubband.h:77
virtual void help()
Coord y_begin_
Definition: rubband.h:77
virtual void draw(Coord x, Coord y)
static int c
Definition: hoc.cpp:169
printf
Definition: extdef.h:5
short type
Definition: cabvars.h:10
static void pr(N_Vector x)
#define NULL
Definition: spdefs.h:105