NEURON
rubband.h
Go to the documentation of this file.
1 #ifndef rubberband_h
2 #define rubberband_h
3 
4 #include <InterViews/handler.h>
5 #include <InterViews/event.h>
6 #include <InterViews/transformer.h>
7 
8 #undef Rubberband
9 #undef RubberLine
10 #undef RubberRect
11 
12 class RubberAction;
13 class Rubberband;
14 class Color;
15 class Brush;
16 class Canvas;
17 class Printer;
18 
19 // called on rubberband release event
20 class RubberAction: public Resource {
21  protected:
23  virtual ~RubberAction();
24 
25  public:
26  virtual void execute(Rubberband*);
27  virtual void help();
28 };
29 
30 class OcHandler: public Handler {
31  public:
33  virtual ~OcHandler();
34  virtual void help();
35 };
36 
37 class Rubberband: public OcHandler {
38  public:
40  virtual ~Rubberband();
41  virtual bool event(Event&);
42  Coord x_begin() const, y_begin() const, x() const, y() const; // canvas coords
43  static const Color* color();
44  static const Brush* brush();
45  void canvas(Canvas*);
46  Canvas* canvas() const {
47  return canvas_;
48  }
49  const Transformer& transformer() const {
50  return t_;
51  }
52  const Event& event() const {
53  return *e_;
54  }
55  virtual void help();
56  virtual void snapshot(Printer*);
57  static Rubberband* current() {
58  return current_;
59  }
60 
61  protected:
62  // subclasses manipulate the rubberband glyph
63  virtual void draw(Coord x, Coord y);
64  virtual void undraw(Coord x, Coord y);
65 
66  virtual void press(Event&);
67  virtual void drag(Event&);
68  virtual void release(Event&);
69 
70  void rubber_on(Canvas*);
71  void rubber_off(Canvas*);
72 
73  private:
79  static const Color* xor_color_;
80  static const Brush* brush_;
82 };
83 
84 class RubberRect: public Rubberband {
85  public:
87  virtual ~RubberRect();
88 
89  virtual void draw(Coord, Coord);
90 
91  virtual void get_rect(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const;
92  virtual void get_rect_canvas(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const;
93  virtual void help();
94 };
95 
96 class RubberLine: public Rubberband {
97  public:
99  virtual ~RubberLine();
100 
101  virtual void draw(Coord, Coord);
102 
103  virtual void get_line(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const;
104  virtual void get_line_canvas(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const;
105  virtual void help();
106 };
107 
108 inline Coord Rubberband::x() const {
109  return x_;
110 }
111 inline Coord Rubberband::y() const {
112  return y_;
113 }
114 inline Coord Rubberband::x_begin() const {
115  return x_begin_;
116 }
117 inline Coord Rubberband::y_begin() const {
118  return y_begin_;
119 }
120 
121 /*
122  * RubberAction denoted by an object and member function to call on the object.
123  * Used the FieldEditorAction as a template
124  */
125 
126 #if defined(__STDC__) || defined(__ANSI_CPP__) || defined(WIN32) || MAC
127 #define __RubberCallback(T) T##_RubberCallback
128 #define RubberCallback(T) __RubberCallback(T)
129 #define __RubberMemberFunction(T) T##_RubberMemberFunction
130 #define RubberMemberFunction(T) __RubberMemberFunction(T)
131 #else
132 #define __RubberCallback(T) T /**/ _RubberCallback
133 #define RubberCallback(T) __RubberCallback(T)
134 #define __RubberMemberFunction(T) T /**/ _RubberMemberFunction
135 #define RubberMemberFunction(T) __RubberMemberFunction(T)
136 #endif
137 
138 #define declareRubberCallback(T) \
139  typedef void (T::*RubberMemberFunction(T))(Rubberband*); \
140  class RubberCallback(T) \
141  : public RubberAction { \
142  public: \
143  RubberCallback(T)(T*, RubberMemberFunction(T)); \
144  virtual ~RubberCallback(T)(); \
145  \
146  virtual void execute(Rubberband*); \
147  \
148  private: \
149  T* obj_; \
150  RubberMemberFunction(T) func_; \
151  };
152 
153 #define implementRubberCallback(T) \
154  RubberCallback(T)::RubberCallback(T)(T * obj, RubberMemberFunction(T) func) { \
155  obj_ = obj; \
156  func_ = func; \
157  } \
158  \
159  RubberCallback(T)::~RubberCallback(T)() {} \
160  \
161  void RubberCallback(T)::execute(Rubberband* rb) { \
162  (obj_->*func_)(rb); \
163  }
164 
165 #endif
#define Handler
Definition: _defines.h:146
#define Color
Definition: _defines.h:74
#define Transformer
Definition: _defines.h:316
#define Canvas
Definition: _defines.h:65
#define Coord
Definition: _defines.h:19
#define Brush
Definition: _defines.h:59
#define Printer
Definition: _defines.h:211
#define Event
Definition: _defines.h:107
virtual ~OcHandler()
virtual void help()
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:80
Coord x_begin_
Definition: rubband.h:78
Coord x() const
Definition: rubband.h:108
void rubber_off(Canvas *)
Definition: ivocmac.cpp:281
const Event & event() const
Definition: rubband.h:52
virtual void undraw(Coord x, Coord y)
Rubberband(RubberAction *=NULL, Canvas *=NULL)
Transformer t_
Definition: rubband.h:75
static const Color * xor_color_
Definition: rubband.h:79
Coord y_begin() const
Definition: rubband.h:117
virtual void drag(Event &)
static Rubberband * current()
Definition: rubband.h:57
virtual void release(Event &)
virtual ~Rubberband()
static const Color * color()
virtual void snapshot(Printer *)
RubberAction * ra_
Definition: rubband.h:77
Event * e_
Definition: rubband.h:76
Coord x_
Definition: rubband.h:78
Coord y() const
Definition: rubband.h:111
Canvas * canvas_
Definition: rubband.h:74
static Rubberband * current_
Definition: rubband.h:81
const Transformer & transformer() const
Definition: rubband.h:49
Coord x_begin() const
Definition: rubband.h:114
void rubber_on(Canvas *)
Definition: ivocmac.cpp:270
Canvas * canvas() const
Definition: rubband.h:46
static const Brush * brush()
virtual bool event(Event &)
virtual void press(Event &)
Coord y_
Definition: rubband.h:78
virtual void help()
Coord y_begin_
Definition: rubband.h:78
virtual void draw(Coord x, Coord y)
#define NULL
Definition: sptree.h:16