1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/work/peter/canvas-test.cc Fri Mar 11 16:43:41 2005 +0000
1.3 @@ -0,0 +1,114 @@
1.4 +// This example was started by Guillaume Laurent.
1.5 +// It has become a place to dump code that tests parts of the
1.6 +// gnomemm canvas code. Little thought has been given to the
1.7 +// actual on-screen output.
1.8 +
1.9 +#include <libgnomecanvasmm.h>
1.10 +#include <libgnomecanvasmm/polygon.h>
1.11 +#include <iostream>
1.12 +
1.13 +class CanvasExample : public Gnome::Canvas::CanvasAA
1.14 +{
1.15 + typedef Gnome::Canvas::CanvasAA Parent;
1.16 +
1.17 +public:
1.18 + CanvasExample();
1.19 + virtual ~CanvasExample();
1.20 +
1.21 +private:
1.22 + bool event_handler(GdkEvent* e, bool b);
1.23 + Gnome::Canvas::Points coos;
1.24 + Gnome::Art::Point * wp;
1.25 + Gnome::Canvas::Ellipse ** nodes;
1.26 + Gnome::Canvas::Polygon * sides;
1.27 + Gnome::Canvas::Group triangle;
1.28 +};
1.29 +
1.30 +bool CanvasExample::event_handler(GdkEvent* e, bool b)
1.31 +{
1.32 + bool isbutton=true;
1.33 + switch(e->type)
1.34 + {
1.35 + case GDK_BUTTON_PRESS: printf("Node is pressed!\n"); break;
1.36 + //case GDK_BUTTON_RELEASE: printf("Node is released!\n"); break;
1.37 + default: isbutton=false; break;
1.38 + }
1.39 + if(isbutton)
1.40 + {
1.41 + //(get_item_at(e->button.x, e->button.y))->move(5,5);
1.42 + (get_item_at(e->button.x, e->button.y))->hide();
1.43 + }
1.44 +}
1.45 +
1.46 +CanvasExample::CanvasExample():triangle(*(root()), 0, 0)
1.47 +{
1.48 + double ax=100;
1.49 + double ay=100;
1.50 + double bx=-100;
1.51 + double by=100;
1.52 + double cx=0;
1.53 + double cy=-100;
1.54 + coos.push_back(Gnome::Art::Point(100, 100));
1.55 + coos.push_back(Gnome::Art::Point(-100, 100));
1.56 + coos.push_back(Gnome::Art::Point(0, -100));
1.57 +
1.58 + sides=new Gnome::Canvas::Polygon(triangle, coos);
1.59 + *sides << Gnome::Canvas::Properties::outline_color("green");
1.60 + sides->property_width_pixels().set_value(10);
1.61 +
1.62 + nodes=new ( Gnome::Canvas::Ellipse * ) [4];
1.63 +
1.64 + for(int i=0; i<3;i++)
1.65 + {
1.66 + 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);
1.67 + *(nodes[i]) << Gnome::Canvas::Properties::fill_color("blue");
1.68 + *(nodes[i]) << Gnome::Canvas::Properties::outline_color("black");
1.69 + (nodes[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &CanvasExample::event_handler),true));
1.70 + }
1.71 +
1.72 + wp=new Gnome::Art::Point((ax+bx+cx)/3,(ay+by+cy)/3);
1.73 +
1.74 + nodes[3]= new Gnome::Canvas::Ellipse(triangle, wp->get_x()-20, wp->get_y()-20, wp->get_x()+20, wp->get_y()+20);
1.75 + *(nodes[3]) << Gnome::Canvas::Properties::fill_color("blue");
1.76 + *(nodes[3]) << Gnome::Canvas::Properties::outline_color("black");
1.77 +
1.78 +
1.79 +}
1.80 +
1.81 +CanvasExample::~CanvasExample()
1.82 +{
1.83 +}
1.84 +
1.85 +//MainWin:
1.86 +
1.87 +class MainWin : public Gtk::Window
1.88 +{
1.89 +public:
1.90 + MainWin(const std::string& title);
1.91 +
1.92 +protected:
1.93 + //Member widgets:
1.94 + CanvasExample m_canvas;
1.95 +};
1.96 +
1.97 +MainWin::MainWin(const std::string& title)
1.98 +{
1.99 + set_title (title);
1.100 + add(m_canvas);
1.101 + set_default_size(900,600);
1.102 +
1.103 + show_all();
1.104 +}
1.105 +
1.106 +//main():
1.107 +
1.108 +int main(int argc, char *argv[])
1.109 +{
1.110 + Gnome::Canvas::init();
1.111 + Gtk::Main app(argc, argv);
1.112 +
1.113 + MainWin mainwin("Gnome::Canvas Example");
1.114 + app.run(mainwin);
1.115 +
1.116 + return 0;
1.117 +}