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