Re: Goocanvasmm
- From: Gennaro Bellizio <genbell tiscali it>
- To: <jonathon quotidian org>
- Cc: gtkmm-list gnome org
- Subject: Re: Goocanvasmm
- Date: Wed, 20 Feb 2008 22:45:26 +0100 (CET)
>----Messaggio originale----
>Da: jonathon quotidian org
>Data: 20/02/2008 16.54
>A: "Gennaro Bellizio"<genbell tiscali it>
>Cc: <gtkmm-list gnome org>
>Ogg: Re: Goocanvasmm
>
>I'm afraid I don't really understand exactly what the problem is.
>Could you provide a small code example that shows the issue that
>you're having?
>
>--
>jonner
>
Let's consider the coordinates example. When I run the application no
rectangle is displayed onto the canvas. Nevertheless if I click some
button the item bounds labels are updated correctly. By applying the
following patch to window.h
Index: window.h
===================================================================
--- window.h (revisione 1357)
+++ window.h (copia locale)
@@ -29,7 +29,7 @@
void update_label();
Goocanvas::Canvas m_canvas;
- Glib::RefPtr<Goocanvas::Rect> m_rect;
+ Glib::RefPtr<Goocanvas::RectModel> m_rect;
Gtk::VBox m_box;
Gtk::HBox m_button_box;
and the following to window.cc
Index: window.cc
===================================================================
--- window.cc (revisione 1357)
+++ window.cc (copia locale)
@@ -34,8 +34,9 @@
m_canvas.set_size_request(640, 480);
m_canvas.set_bounds(0, 0, 1000, 1000);
- Glib::RefPtr<Goocanvas::Item> root = m_canvas.get_root_item();
- m_rect = Goocanvas::Rect::create(10, 10, 60, 60);
+ Glib::RefPtr<Goocanvas::ItemModel> root = Goocanvas::GroupModel::
create() ;
+ m_canvas->set_root_item_model(root) ;
+ m_rect = Goocanvas::RectModel::create(10, 10, 60, 60);
root->add_child(m_rect);
m_rect->property_line_width().set_value(10.0);
m_rect->property_stroke_color().set_value("yellow");
@@ -74,6 +75,7 @@
", width=" << m_rect->property_width() << ", height=" <<
m_rect->property_height() <<
", line_width=" << m_rect->property_line_width() << std::
endl;
+ // No bounds are available now, so the following will not compile
Goocanvas::Bounds bounds = m_rect->get_bounds();
str << "Item bounds: x1=" << bounds.get_x1() << ", y1=" << bounds.
get_y1() << ", x2=" << bounds.get_x2() << ", y2=" << bounds.get_y2() <<
std::endl;
the rectangle is displayed but now its bounds aren't available because
the *Model classes do not provide the get_bounds() method. The same
happens for the Goocanvas::Ellipse instances.
Goocanvas::Text instances, instead, are displayed correctly like it
can be seen by applying the following patch
Index: window.h
===================================================================
--- window.h (revisione 1357)
+++ window.h (copia locale)
@@ -29,7 +29,7 @@
void update_label();
Goocanvas::Canvas m_canvas;
- Glib::RefPtr<Goocanvas::Rect> m_rect;
+ Glib::RefPtr<Goocanvas::Text> m_text;
Gtk::VBox m_box;
Gtk::HBox m_button_box;
Index: window.cc
===================================================================
--- window.cc (revisione 1357)
+++ window.cc (copia locale)
@@ -35,11 +35,9 @@
m_canvas.set_bounds(0, 0, 1000, 1000);
Glib::RefPtr<Goocanvas::Item> root = m_canvas.get_root_item();
- m_rect = Goocanvas::Rect::create(10, 10, 60, 60);
- root->add_child(m_rect);
- m_rect->property_line_width().set_value(10.0);
- m_rect->property_stroke_color().set_value("yellow");
- m_rect->property_fill_color().set_value("gray");
+ m_text = Goocanvas::Text::create("This is displayed\nand bounds are
available");
+ root->add_child(m_text);
+ m_text->property_fill_color().set_value("blue");
Gtk::ScrolledWindow* sw = Gtk::manage(new Gtk::ScrolledWindow());
@@ -70,11 +68,11 @@
void ExampleWindow::update_label()
{
std::stringstream str;
- str << "Rect: x=" << m_rect->property_x() << ", y=" << m_rect-
>property_y() <<
- ", width=" << m_rect->property_width() << ", height=" <<
m_rect->property_height() <<
- ", line_width=" << m_rect->property_line_width() << std::
endl;
+ str << "Rect: x=" << m_text->property_x() << ", y=" << m_text-
>property_y() <<
+ ", width=" << m_text->property_width() <<
+ ", line_width=" << m_text->property_line_width() << std::
endl;
- Goocanvas::Bounds bounds = m_rect->get_bounds();
+ Goocanvas::Bounds bounds = m_text->get_bounds();
str << "Item bounds: x1=" << bounds.get_x1() << ", y1=" << bounds.
get_y1() << ", x2=" << bounds.get_x2() << ", y2=" << bounds.get_y2() <<
std::endl;
@@ -84,21 +82,21 @@
void ExampleWindow::on_button_translate()
{
- m_rect->translate(20, 20);
+ m_text->translate(20, 20);
update_label();
}
void ExampleWindow::on_button_setxy()
{
- m_rect->property_x() = 50;
- m_rect->property_y() = 50;
+ m_text->property_x() = 50;
+ m_text->property_y() = 50;
update_label();
}
void ExampleWindow::on_button_scale()
{
- m_rect->scale(1.2, 1.2);
+ m_text->scale(1.2, 1.2);
update_label();
}
In my application I used a Goocanvas::GroupModel for stacking a
Goocanvas::EllipseModel and a Goocanvas::TextModel in order to draw a
graph node with a text-label. My problem is to get the text-label
bounds in order to correctly center it into the node.
I hope I have been more clear this time. :-)
Thanks in advance.
Gennaro Bellizio
________________________________________________________________
Tiscali Voce 8 Mega: attiva la promozione entro il 21/02/08, in esclusiva TELEFONO+ADSL a soli 4,95 Euro al mese!
http://abbonati.tiscali.it/promo/mail/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]