rubband.h

Go to the documentation of this file.
00001 #ifndef rubberband_h
00002 #define rubberband_h
00003 
00004 #include <InterViews/handler.h>
00005 #include <InterViews/event.h>
00006 #include <InterViews/transformer.h>
00007 
00008 #undef Rubberband
00009 #undef RubberLine
00010 #undef RubberRect
00011 
00012 class RubberAction;
00013 class Rubberband;
00014 class Color;
00015 class Brush;
00016 class Canvas;
00017 class Printer;
00018 
00019 //called on rubberband release event
00020 class RubberAction : public Resource {
00021 protected:
00022    RubberAction();
00023    virtual ~RubberAction();
00024 public:
00025    virtual void execute(Rubberband*);
00026    virtual void help();
00027 };
00028 
00029 class OcHandler : public Handler {
00030 public:
00031    OcHandler();
00032    virtual ~OcHandler();
00033    virtual void help();
00034 };
00035 
00036 class Rubberband : public OcHandler {
00037 public:
00038    Rubberband(RubberAction* = nil, Canvas* = nil);
00039    virtual ~Rubberband();
00040    virtual boolean event(Event&);
00041    Coord x_begin()const, y_begin()const, x()const, y()const; //canvas coords
00042    static const Color* color();
00043    static const Brush* brush();
00044    void canvas(Canvas*);
00045    Canvas* canvas()const {return canvas_;}
00046    const Transformer& transformer()const {return t_;}
00047    const Event& event()const {return *e_;}
00048    virtual void help();
00049    virtual void snapshot(Printer*);
00050    static Rubberband* current() {return current_;}
00051 protected:
00052    //subclasses manipulate the rubberband glyph
00053    virtual void draw(Coord x, Coord y);
00054    virtual void undraw(Coord x, Coord y);
00055 
00056    virtual void press(Event&);
00057    virtual void drag(Event&);
00058    virtual void release(Event&);
00059 
00060    void rubber_on(Canvas*);
00061    void rubber_off(Canvas*);
00062 private:
00063    Canvas* canvas_;
00064    Transformer t_;
00065    Event* e_;
00066    RubberAction* ra_;
00067    Coord x_begin_, y_begin_, x_, y_;
00068    static const Color* xor_color_;
00069    static const Brush* brush_;
00070    static Rubberband* current_;
00071 }; 
00072 
00073 class RubberRect : public Rubberband {
00074 public:
00075    RubberRect(RubberAction* = nil, Canvas* = nil);
00076    virtual ~RubberRect();
00077    
00078    virtual void draw(Coord, Coord);
00079    
00080    virtual void get_rect(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const;
00081    virtual void get_rect_canvas(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const;
00082    virtual void help();
00083 };
00084 
00085 class RubberLine : public Rubberband {
00086 public:
00087    RubberLine(RubberAction* = nil, Canvas* = nil);
00088    virtual ~RubberLine();
00089    
00090    virtual void draw(Coord, Coord);
00091    
00092    virtual void get_line(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const;
00093    virtual void get_line_canvas(Coord& x1, Coord& y1, Coord& x2, Coord& y2) const;
00094    virtual void help();
00095 };
00096 
00097 inline Coord Rubberband::x() const { return x_; }
00098 inline Coord Rubberband::y() const { return y_; }
00099 inline Coord Rubberband::x_begin() const { return x_begin_; }
00100 inline Coord Rubberband::y_begin() const { return y_begin_; }
00101 
00102 /*
00103  * RubberAction  denoted by an object and member function to call on the object.
00104  * Used the FieldEditorAction as a template
00105  */
00106  
00107 #if defined(__STDC__) || defined(__ANSI_CPP__) || defined(WIN32) || MAC
00108 #define __RubberCallback(T) T##_RubberCallback
00109 #define RubberCallback(T) __RubberCallback(T)
00110 #define __RubberMemberFunction(T) T##_RubberMemberFunction
00111 #define RubberMemberFunction(T) __RubberMemberFunction(T)
00112 #else
00113 #define __RubberCallback(T) T_RubberCallback
00114 #define RubberCallback(T) __RubberCallback(T)
00115 #define __RubberMemberFunction(T) T_RubberMemberFunction
00116 #define RubberMemberFunction(T) __RubberMemberFunction(T)
00117 #endif
00118 
00119 #define declareRubberCallback(T) \
00120 typedef void (T::*RubberMemberFunction(T))(Rubberband*); \
00121 class RubberCallback(T) : public RubberAction { \
00122 public: \
00123     RubberCallback(T)(T*, RubberMemberFunction(T)); \
00124     virtual ~RubberCallback(T)(); \
00125 \
00126     virtual void execute(Rubberband*); \
00127 private: \
00128     T* obj_; \
00129     RubberMemberFunction(T) func_; \
00130 };
00131 
00132 #define implementRubberCallback(T) \
00133 RubberCallback(T)::RubberCallback(T)( \
00134     T* obj, RubberMemberFunction(T) func \
00135 ) { \
00136     obj_ = obj; \
00137     func_ = func; \
00138 } \
00139 \
00140 RubberCallback(T)::~RubberCallback(T)() { } \
00141 \
00142 void RubberCallback(T)::execute(Rubberband* rb) { \
00143     (obj_->*func_)(rb); \
00144 }
00145 
00146 #endif
Generated on Mon Jun 13 08:10:24 2011 for NEURON by  doxygen 1.6.3