File: MGCanvas.h

package info (click to toggle)
mysql-admin 1.2.5rc-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 80,944 kB
  • ctags: 43,103
  • sloc: sql: 295,916; pascal: 256,535; cpp: 74,487; ansic: 68,881; objc: 26,417; sh: 16,867; yacc: 10,755; java: 9,917; xml: 8,453; php: 2,806; python: 2,068; makefile: 1,252; perl: 3
file content (173 lines) | stat: -rw-r--r-- 5,343 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* Copyright (C) 2005 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */


#ifndef _MGCANVAS_H_
#define _MGCANVAS_H_

#include <gtkmm/layout.h>
#include <gtkmm/drawingarea.h>
#include <gdkmm/cursor.h>
#include <GL/gl.h>
#include <GL/glx.h>


#include <vector>

#include "myx_gc_canvas.h"


class MGCanvasScroller;

class MGCanvas : public Gtk::DrawingArea, CGCListenerInterface {
    typedef Gtk::DrawingArea superclass;
  public:
    struct Point {
      float x, y;
      Point() : x(0), y(0) {};
      Point(float ix, float iy) : x(ix), y(iy) {};
    };
    struct Size {
      float width, height;
      Size() : width(0), height(0) {};
      Size(float w, float h) : width(w), height(h) {};
    };
    struct Rectangle {
      Point origin;
      Size size;
      Rectangle(float x, float y, float w, float h) : origin(x,y), size(w,h) {};
      inline float get_x() { return origin.x; };
      inline float get_y() { return origin.y; };
      inline float get_width() { return size.width; };
      inline float get_height() { return size.height; };
    };
        
  protected:
    GLXContext _context;
    
    CGenericCanvas *_canvas;
    
    Size _baseSize;
    Point _offset;
    
    Gdk::Point _lastClickPoint;
    
    Gdk::Point _lastPressPoint;
    int _lastPressTime;

    Gdk::Rectangle _viewport;
    
    Gdk::Cursor _hand_cursor;
    Gdk::Cursor _hand_closed_cursor;
    
    double _zoom;
    int _currentZoomStep;
    
    bool _grabPanning;
    bool _changingScrollers;

    bool _refreshPending;

    Glib::Dispatcher _refresh;
    Glib::Dispatcher _switchView;
    
    struct {
      unsigned panning:2;
    } _state;
    
    sigc::slot<bool,MGCanvas*,int,int,Point> _handleMouseDown;
    sigc::slot<bool,MGCanvas*,int,int,Point> _handleMouseUp;
    sigc::slot<bool,MGCanvas*,int,Point> _handleMouseDrag;
    sigc::slot<void,CGCBase*,TAction*> _handleAction;

    virtual void on_realize();
    virtual bool on_expose_event(GdkEventExpose* event);
    virtual bool on_configure_event(GdkEventConfigure* event);

    virtual bool on_button_press_event(GdkEventButton* event);
    virtual bool on_button_release_event(GdkEventButton* event);
    virtual bool on_scroll_event(GdkEventScroll* event);
    virtual bool on_motion_notify_event(GdkEventMotion* event);
    
    virtual bool on_focus_in_event(GdkEventFocus* event);
    virtual bool on_focus_out_event(GdkEventFocus* event);
    
    virtual void onAction(CGCBase *sender, CGCBase *origin, TAction **action);
    virtual void onChange(CGCBase *sender, CGCBase *origin, TGCChangeReason Reason);
    virtual void onError(CGCBase *sender, CGCBase *origin, const char* Message);
    virtual void onDestroy(CGCBase *sender);

    bool pulse();
    void handle_switch_view();
    
    Point get_center_for_zoom();

    MGCanvasScroller *get_enclosing_scroller();
    
  public:
    MGCanvas();
    virtual ~MGCanvas();
    
    void set_hand_cursor(const Gdk::Cursor &hand, const Gdk::Cursor &closed_hand);
   
    void set_zoom(float zoom, Point center);
    void set_zoom_level(int level, Point center);
    void set_zoom_level(int level=-1);
    int zoom_level() { return _currentZoomStep; };
    
    void toggle_overview();
    
    void set_offset(Point offset);
    void set_base_size(Size size);
    Size base_size() { return _baseSize; };
    
    Point convert_to_canvas_point(Gdk::Point point);
    
    Size actual_size();
    Rectangle actual_visible_rect();
    
    bool load_layouts(const Glib::ustring &file);
    bool load_styles(const Glib::ustring &file, 
                     std::map<std::string,std::string> &variables);
    
    void render_scene();
    void update_from_scrollers();
    void update_scrollers();
    
    void force_reconfigure();
    
    void set_grab_panning(bool flag);
    
    void create_view(const Glib::ustring &name);
    void create_view(CGCView *view);
    void switch_to_view(CGCView *view);
    
    void set_grid_enabled(bool flag);
    
    void start_area_selection_at(Point point);
    Rectangle finish_area_selection();

    void set_mouse_down_handler(sigc::slot<bool,MGCanvas*,int,int,Point> handler);
    void set_mouse_up_handler(sigc::slot<bool,MGCanvas*,int,int,Point> handler);
    void set_mouse_move_handler(sigc::slot<bool,MGCanvas*,int,Point> handler);
    void set_action_handler(sigc::slot<void,CGCBase*,TAction*> handler);

    CGenericCanvas *canvas() { return _canvas; };

    std::vector<float> get_zoom_steps();
};

#endif /* _MGCANVAS_H_ */