Edges are clickable now.
[av.git] / gtk / src / tree_model.hpp
blob69d46923bbbb2a42f629acfcaf61ebf3cdf13edc
1 #ifndef __TREE_MODEL_HPP__
2 #define __TREE_MODEL_HPP__
4 #include <vector>
5 #include <gtkmm/drawingarea.h>
6 #include <cairomm/context.h>
7 #include <libglademm.h>
9 #include "core/alignment.hpp"
10 #include "core/word.hpp"
11 #include "edge.hpp"
12 #include "vertex.hpp"
14 class TreeModel : public Gtk::DrawingArea
16 public:
17 TreeModel(GtkDrawingArea *cobject, Glib::RefPtr<Gnome::Glade::Xml> &glade);
18 virtual ~TreeModel(void);
19 void add_alignment(Alignment &alignment);
20 protected:
21 virtual bool on_expose_event(GdkEventExpose *event);
22 virtual bool on_button_press_event(GdkEventButton *event);
23 private:
24 void _add_source(void);
25 void _add_target(void);
26 void _add_word(const Word &word, bool source);
27 void _add_edges(void);
28 void _invalidate_window(void);
29 void _invalidate_vertex(Vertex *v);
30 void _invalidate_rect(gint x, gint y, gint width, gint height);
31 template <typename T>
32 bool _button_press_event_cb(std::vector<T> &obj, gdouble x, gdouble y);
33 gint _c2d_x(gdouble x) const;
34 gint _c2d_y(gdouble y) const;
35 gdouble _d2c_x(gint x) const;
36 gdouble _d2c_x(gdouble x) const;
37 gdouble _d2c_y(gint y) const;
38 gdouble _d2c_y(gdouble y) const;
40 // Layout details
41 const gdouble _SENTENCE_SPACING;
42 gdouble _BEARING;
43 const gdouble _WORD_SPACING;
44 gdouble _xc;
45 gdouble _yc;
47 Cairo::RefPtr<Cairo::Context> _cr;
48 Alignment *_alignment;
49 std::vector<Vertex *> _source;
50 std::vector<Vertex *> _target;
51 std::vector<Edge *> _edges;
52 Vertex *_selected;
55 inline gint TreeModel::_c2d_x(gdouble x) const
57 return gint(x + _xc);
60 inline gint TreeModel::_c2d_y(gdouble y) const
62 return gint(y + _yc);
65 inline gdouble TreeModel::_d2c_x(gint x) const
67 return x - _xc;
70 inline gdouble TreeModel::_d2c_x(gdouble x) const
72 return x - _xc;
75 inline gdouble TreeModel::_d2c_y(gint y) const
77 return y - _yc;
80 inline gdouble TreeModel::_d2c_y(gdouble y) const
82 return y - _yc;
85 #endif