COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/peter/canvas-test.cc @ 1212:d89e184cc24e

Last change on this file since 1212:d89e184cc24e was 1212:d89e184cc24e, checked in by Hegyi Péter, 19 years ago

i am getting familiar with gtkmm and gnomecanvasmm

File size: 2.7 KB
Line 
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.
5
6#include <libgnomecanvasmm.h>
7#include <libgnomecanvasmm/polygon.h>
8#include <iostream>
9
10class CanvasExample : public Gnome::Canvas::CanvasAA
11{
12        typedef Gnome::Canvas::CanvasAA Parent;
13
14public:
15        CanvasExample();
16        virtual ~CanvasExample();
17
18private:
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;
25};
26
27bool CanvasExample::event_handler(GdkEvent* e, bool b)
28{
29        bool isbutton=true;
30        switch(e->type)
31        {
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;
35        }
36        if(isbutton)
37        {
38                //(get_item_at(e->button.x, e->button.y))->move(5,5);
39                (get_item_at(e->button.x, e->button.y))->hide();
40        }
41}
42
43CanvasExample::CanvasExample():triangle(*(root()), 0, 0)
44{
45        double ax=100;
46        double ay=100;
47        double bx=-100;
48        double by=100;
49        double cx=0;
50        double cy=-100;
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));
54
55        sides=new Gnome::Canvas::Polygon(triangle, coos);
56        *sides << Gnome::Canvas::Properties::outline_color("green");
57        sides->property_width_pixels().set_value(10);
58
59        nodes=new ( Gnome::Canvas::Ellipse * ) [4];
60
61        for(int i=0; i<3;i++)
62        {
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));
67        }
68
69        wp=new Gnome::Art::Point((ax+bx+cx)/3,(ay+by+cy)/3);
70
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");
74
75
76}
77
78CanvasExample::~CanvasExample()
79{
80}
81
82//MainWin:
83
84class MainWin : public Gtk::Window
85{
86public:
87        MainWin(const std::string& title);
88
89protected:
90        //Member widgets:
91        CanvasExample m_canvas;
92};
93
94MainWin::MainWin(const std::string& title)
95{
96        set_title (title);
97        add(m_canvas);
98        set_default_size(900,600);
99
100        show_all();
101}
102
103//main():
104
105int main(int argc, char *argv[])
106{
107        Gnome::Canvas::init();
108        Gtk::Main app(argc, argv);
109
110        MainWin mainwin("Gnome::Canvas Example");
111        app.run(mainwin);
112
113        return 0;
114}
Note: See TracBrowser for help on using the repository browser.