hegyi@1212: // This example was started by Guillaume Laurent. hegyi@1212: // It has become a place to dump code that tests parts of the hegyi@1212: // gnomemm canvas code. Little thought has been given to the hegyi@1212: // actual on-screen output. hegyi@1212: hegyi@1212: #include hegyi@1212: #include hegyi@1212: #include hegyi@1212: hegyi@1212: class CanvasExample : public Gnome::Canvas::CanvasAA hegyi@1212: { hegyi@1212: typedef Gnome::Canvas::CanvasAA Parent; hegyi@1212: hegyi@1212: public: hegyi@1212: CanvasExample(); hegyi@1212: virtual ~CanvasExample(); hegyi@1212: hegyi@1212: private: hegyi@1212: bool event_handler(GdkEvent* e, bool b); hegyi@1212: Gnome::Canvas::Points coos; hegyi@1212: Gnome::Art::Point * wp; hegyi@1212: Gnome::Canvas::Ellipse ** nodes; hegyi@1212: Gnome::Canvas::Polygon * sides; hegyi@1212: Gnome::Canvas::Group triangle; hegyi@1212: }; hegyi@1212: hegyi@1212: bool CanvasExample::event_handler(GdkEvent* e, bool b) hegyi@1212: { hegyi@1212: bool isbutton=true; hegyi@1212: switch(e->type) hegyi@1212: { hegyi@1212: case GDK_BUTTON_PRESS: printf("Node is pressed!\n"); break; hegyi@1212: //case GDK_BUTTON_RELEASE: printf("Node is released!\n"); break; hegyi@1212: default: isbutton=false; break; hegyi@1212: } hegyi@1212: if(isbutton) hegyi@1212: { hegyi@1212: //(get_item_at(e->button.x, e->button.y))->move(5,5); hegyi@1212: (get_item_at(e->button.x, e->button.y))->hide(); hegyi@1212: } hegyi@1212: } hegyi@1212: hegyi@1212: CanvasExample::CanvasExample():triangle(*(root()), 0, 0) hegyi@1212: { hegyi@1212: double ax=100; hegyi@1212: double ay=100; hegyi@1212: double bx=-100; hegyi@1212: double by=100; hegyi@1212: double cx=0; hegyi@1212: double cy=-100; hegyi@1212: coos.push_back(Gnome::Art::Point(100, 100)); hegyi@1212: coos.push_back(Gnome::Art::Point(-100, 100)); hegyi@1212: coos.push_back(Gnome::Art::Point(0, -100)); hegyi@1212: hegyi@1212: sides=new Gnome::Canvas::Polygon(triangle, coos); hegyi@1212: *sides << Gnome::Canvas::Properties::outline_color("green"); hegyi@1212: sides->property_width_pixels().set_value(10); hegyi@1212: hegyi@1212: nodes=new ( Gnome::Canvas::Ellipse * ) [4]; hegyi@1212: hegyi@1212: for(int i=0; i<3;i++) hegyi@1212: { hegyi@1212: 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); hegyi@1212: *(nodes[i]) << Gnome::Canvas::Properties::fill_color("blue"); hegyi@1212: *(nodes[i]) << Gnome::Canvas::Properties::outline_color("black"); hegyi@1212: (nodes[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &CanvasExample::event_handler),true)); hegyi@1212: } hegyi@1212: hegyi@1212: wp=new Gnome::Art::Point((ax+bx+cx)/3,(ay+by+cy)/3); hegyi@1212: hegyi@1212: nodes[3]= new Gnome::Canvas::Ellipse(triangle, wp->get_x()-20, wp->get_y()-20, wp->get_x()+20, wp->get_y()+20); hegyi@1212: *(nodes[3]) << Gnome::Canvas::Properties::fill_color("blue"); hegyi@1212: *(nodes[3]) << Gnome::Canvas::Properties::outline_color("black"); hegyi@1212: hegyi@1212: hegyi@1212: } hegyi@1212: hegyi@1212: CanvasExample::~CanvasExample() hegyi@1212: { hegyi@1212: } hegyi@1212: hegyi@1212: //MainWin: hegyi@1212: hegyi@1212: class MainWin : public Gtk::Window hegyi@1212: { hegyi@1212: public: hegyi@1212: MainWin(const std::string& title); hegyi@1212: hegyi@1212: protected: hegyi@1212: //Member widgets: hegyi@1212: CanvasExample m_canvas; hegyi@1212: }; hegyi@1212: hegyi@1212: MainWin::MainWin(const std::string& title) hegyi@1212: { hegyi@1212: set_title (title); hegyi@1212: add(m_canvas); hegyi@1212: set_default_size(900,600); hegyi@1212: hegyi@1212: show_all(); hegyi@1212: } hegyi@1212: hegyi@1212: //main(): hegyi@1212: hegyi@1212: int main(int argc, char *argv[]) hegyi@1212: { hegyi@1212: Gnome::Canvas::init(); hegyi@1212: Gtk::Main app(argc, argv); hegyi@1212: hegyi@1212: MainWin mainwin("Gnome::Canvas Example"); hegyi@1212: app.run(mainwin); hegyi@1212: hegyi@1212: return 0; hegyi@1212: }