src/work/peter/canvas-test.cc
author deba
Fri, 11 Mar 2005 16:44:20 +0000
changeset 1213 6cc106135d31
child 1221 6706c788ebb5
permissions -rw-r--r--
Solve conflict.
hegyi@1212
     1
// This example was started by Guillaume Laurent.
hegyi@1212
     2
// It has become a place to dump code that tests parts of the
hegyi@1212
     3
// gnomemm canvas code. Little thought has been given to the
hegyi@1212
     4
// actual on-screen output.
hegyi@1212
     5
hegyi@1212
     6
#include <libgnomecanvasmm.h>
hegyi@1212
     7
#include <libgnomecanvasmm/polygon.h>
hegyi@1212
     8
#include <iostream>
hegyi@1212
     9
hegyi@1212
    10
class CanvasExample : public Gnome::Canvas::CanvasAA
hegyi@1212
    11
{
hegyi@1212
    12
	typedef Gnome::Canvas::CanvasAA Parent;
hegyi@1212
    13
hegyi@1212
    14
public:
hegyi@1212
    15
	CanvasExample();
hegyi@1212
    16
	virtual ~CanvasExample();
hegyi@1212
    17
hegyi@1212
    18
private:
hegyi@1212
    19
	bool event_handler(GdkEvent* e, bool b);
hegyi@1212
    20
	Gnome::Canvas::Points coos;
hegyi@1212
    21
	Gnome::Art::Point * wp;
hegyi@1212
    22
	Gnome::Canvas::Ellipse ** nodes;
hegyi@1212
    23
	Gnome::Canvas::Polygon * sides;
hegyi@1212
    24
	Gnome::Canvas::Group triangle;
hegyi@1212
    25
};
hegyi@1212
    26
hegyi@1212
    27
bool CanvasExample::event_handler(GdkEvent* e, bool b)
hegyi@1212
    28
{
hegyi@1212
    29
	bool isbutton=true;
hegyi@1212
    30
	switch(e->type)
hegyi@1212
    31
	{
hegyi@1212
    32
		case GDK_BUTTON_PRESS: printf("Node is pressed!\n"); break;
hegyi@1212
    33
		//case GDK_BUTTON_RELEASE: printf("Node is released!\n"); break;
hegyi@1212
    34
		default: isbutton=false; break;
hegyi@1212
    35
	}
hegyi@1212
    36
	if(isbutton)
hegyi@1212
    37
	{
hegyi@1212
    38
		//(get_item_at(e->button.x, e->button.y))->move(5,5);
hegyi@1212
    39
		(get_item_at(e->button.x, e->button.y))->hide();
hegyi@1212
    40
	}
hegyi@1212
    41
}
hegyi@1212
    42
hegyi@1212
    43
CanvasExample::CanvasExample():triangle(*(root()), 0, 0)
hegyi@1212
    44
{
hegyi@1212
    45
	double ax=100;
hegyi@1212
    46
	double ay=100;
hegyi@1212
    47
	double bx=-100;
hegyi@1212
    48
	double by=100;
hegyi@1212
    49
	double cx=0;
hegyi@1212
    50
	double cy=-100;
hegyi@1212
    51
	coos.push_back(Gnome::Art::Point(100, 100));
hegyi@1212
    52
	coos.push_back(Gnome::Art::Point(-100, 100));
hegyi@1212
    53
	coos.push_back(Gnome::Art::Point(0, -100));
hegyi@1212
    54
hegyi@1212
    55
	sides=new Gnome::Canvas::Polygon(triangle, coos);
hegyi@1212
    56
	*sides << Gnome::Canvas::Properties::outline_color("green");
hegyi@1212
    57
	sides->property_width_pixels().set_value(10);
hegyi@1212
    58
hegyi@1212
    59
	nodes=new ( Gnome::Canvas::Ellipse * ) [4];
hegyi@1212
    60
hegyi@1212
    61
	for(int i=0; i<3;i++)
hegyi@1212
    62
	{
hegyi@1212
    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);
hegyi@1212
    64
		*(nodes[i]) << Gnome::Canvas::Properties::fill_color("blue");
hegyi@1212
    65
		*(nodes[i]) << Gnome::Canvas::Properties::outline_color("black");
hegyi@1212
    66
		(nodes[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &CanvasExample::event_handler),true));
hegyi@1212
    67
	}
hegyi@1212
    68
hegyi@1212
    69
	wp=new Gnome::Art::Point((ax+bx+cx)/3,(ay+by+cy)/3);
hegyi@1212
    70
hegyi@1212
    71
	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
    72
	*(nodes[3]) << Gnome::Canvas::Properties::fill_color("blue");
hegyi@1212
    73
	*(nodes[3]) << Gnome::Canvas::Properties::outline_color("black");
hegyi@1212
    74
hegyi@1212
    75
hegyi@1212
    76
}
hegyi@1212
    77
hegyi@1212
    78
CanvasExample::~CanvasExample()
hegyi@1212
    79
{
hegyi@1212
    80
}
hegyi@1212
    81
hegyi@1212
    82
//MainWin:
hegyi@1212
    83
hegyi@1212
    84
class MainWin : public Gtk::Window
hegyi@1212
    85
{
hegyi@1212
    86
public:
hegyi@1212
    87
	MainWin(const std::string& title);
hegyi@1212
    88
hegyi@1212
    89
protected:
hegyi@1212
    90
	//Member widgets:
hegyi@1212
    91
	CanvasExample m_canvas;
hegyi@1212
    92
};
hegyi@1212
    93
hegyi@1212
    94
MainWin::MainWin(const std::string& title)
hegyi@1212
    95
{
hegyi@1212
    96
	set_title (title);
hegyi@1212
    97
	add(m_canvas);
hegyi@1212
    98
	set_default_size(900,600);
hegyi@1212
    99
hegyi@1212
   100
	show_all();
hegyi@1212
   101
}
hegyi@1212
   102
hegyi@1212
   103
//main():
hegyi@1212
   104
hegyi@1212
   105
int main(int argc, char *argv[])
hegyi@1212
   106
{
hegyi@1212
   107
	Gnome::Canvas::init();
hegyi@1212
   108
	Gtk::Main app(argc, argv);
hegyi@1212
   109
hegyi@1212
   110
	MainWin mainwin("Gnome::Canvas Example");
hegyi@1212
   111
	app.run(mainwin);
hegyi@1212
   112
hegyi@1212
   113
	return 0;
hegyi@1212
   114
}