1 // This example was started by Guillaume Laurent.
2 // It has become a place to dump code that tests parts of the
3 // gnomemm canvas code. Little thought has been given to the
4 // actual on-screen output.
6 #include <libgnomecanvasmm.h>
7 #include <libgnomecanvasmm/polygon.h>
10 class CanvasExample : public Gnome::Canvas::CanvasAA
12 typedef Gnome::Canvas::CanvasAA Parent;
16 virtual ~CanvasExample();
19 bool event_handler(GdkEvent* e, bool b);
20 Gnome::Canvas::Points coos;
21 Gnome::Art::Point * wp;
22 Gnome::Canvas::Ellipse ** nodes;
23 Gnome::Canvas::Polygon * sides;
24 Gnome::Canvas::Group triangle;
27 bool CanvasExample::event_handler(GdkEvent* e, bool b)
32 case GDK_BUTTON_PRESS: printf("Node is pressed!\n"); break;
33 //case GDK_BUTTON_RELEASE: printf("Node is released!\n"); break;
34 default: isbutton=false; break;
38 //(get_item_at(e->button.x, e->button.y))->move(5,5);
39 (get_item_at(e->button.x, e->button.y))->hide();
43 CanvasExample::CanvasExample():triangle(*(root()), 0, 0)
51 coos.push_back(Gnome::Art::Point(100, 100));
52 coos.push_back(Gnome::Art::Point(-100, 100));
53 coos.push_back(Gnome::Art::Point(0, -100));
55 sides=new Gnome::Canvas::Polygon(triangle, coos);
56 *sides << Gnome::Canvas::Properties::outline_color("green");
57 sides->property_width_pixels().set_value(10);
59 nodes=new ( Gnome::Canvas::Ellipse * ) [4];
63 nodes[i]= new Gnome::Canvas::Ellipse(triangle, coos[i].get_x()-20, coos[i].get_y()-20, coos[i].get_x()+20, coos[i].get_y()+20);
64 *(nodes[i]) << Gnome::Canvas::Properties::fill_color("blue");
65 *(nodes[i]) << Gnome::Canvas::Properties::outline_color("black");
66 (nodes[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &CanvasExample::event_handler),true));
69 wp=new Gnome::Art::Point((ax+bx+cx)/3,(ay+by+cy)/3);
71 nodes[3]= new Gnome::Canvas::Ellipse(triangle, wp->get_x()-20, wp->get_y()-20, wp->get_x()+20, wp->get_y()+20);
72 *(nodes[3]) << Gnome::Canvas::Properties::fill_color("blue");
73 *(nodes[3]) << Gnome::Canvas::Properties::outline_color("black");
78 CanvasExample::~CanvasExample()
84 class MainWin : public Gtk::Window
87 MainWin(const std::string& title);
91 CanvasExample m_canvas;
94 MainWin::MainWin(const std::string& title)
98 set_default_size(900,600);
105 int main(int argc, char *argv[])
107 Gnome::Canvas::init();
108 Gtk::Main app(argc, argv);
110 MainWin mainwin("Gnome::Canvas Example");