3 Vertex::Vertex(Gtk::Widget
&parent
, const Word
&word
) :
11 _layout(parent
.create_pango_layout(_word
.get_word()))
13 Glib::RefPtr
<Pango::LayoutLine
> line
;
14 Pango::Rectangle ink_extents
;
15 Pango::Rectangle extents
;
20 // Set text and get layout information
21 _layout
->set_text(_word
.get_word());
23 line
= _layout
->get_line(0);
25 line
->get_extents(ink_extents
, extents
);
26 _descent
= extents
.get_descent() / Pango::SCALE
;
27 _width
= extents
.get_width() / Pango::SCALE
+
29 _height
= extents
.get_height() / Pango::SCALE
+
39 void Vertex::set_font(const Glib::ustring
&font
)
41 _layout
->set_font_description(Pango::FontDescription(font
));
44 void Vertex::draw(Cairo::RefPtr
<Cairo::Context
> cr
)
46 Glib::RefPtr
<Pango::LayoutLine
> line
;
49 line
= _layout
->get_line(0);
51 // Draw a rectangular box around the text
54 cr
->rectangle(_x
, _y
, _width
, _height
);
56 _path
= cr
->copy_path_flat();
58 cr
->set_source_rgb(0.6, 0.8, 0.6);
60 cr
->set_source_rgb(0.1, 0.6, 0.1);
62 cr
->set_source_rgb(0.8, 0.5, 0.5);
64 cr
->set_source_rgb(0.2, 0.2, 0);
66 cr
->set_line_width(0.5);
71 cr
->translate(_x
+ _PADDING
,
72 _y
+ _height
- _descent
- _PADDING
);
73 line
->show_in_cairo_context(cr
);
79 void Vertex::add_friend(const Vertex
&v
)
82 _friends
.push_back(&v
);
86 void Vertex::delete_friend(const Vertex
&v
)
88 std::vector
<const Vertex
*>::iterator iter
;
90 for (iter
= _friends
.begin(); iter
!= _friends
.end(); iter
++) {
98 bool Vertex::is_friend(const Vertex
&v
) const
100 std::vector
<const Vertex
*>::const_iterator iter
;
102 for (iter
= _friends
.begin(); iter
!= _friends
.end(); iter
++) {
111 bool Vertex::select(Cairo::RefPtr
<Cairo::Context
> cr
, gdouble x
, gdouble y
)
113 if (!_is_in_region(cr
, x
, y
)) {
117 if (!_is_highlight
) {
118 _is_highlight
= true;
125 void Vertex::deselect(void)
128 _is_highlight
= false;
133 bool Vertex::_is_in_region(Cairo::RefPtr
<Cairo::Context
> cr
,
134 gdouble x
, gdouble y
) const
139 cr
->begin_new_path();
140 cr
->append_path(*_path
);
141 result
= cr
->in_fill(x
, y
);