2020-06-10 16:10:26 -04:00
|
|
|
#include <iostream>
|
|
|
|
|
2020-05-22 10:46:37 -04:00
|
|
|
#include <gtkmm/adjustment.h>
|
|
|
|
#include <gtkmm/main.h>
|
|
|
|
#include <gtkmm/window.h>
|
|
|
|
|
2020-06-10 16:10:26 -04:00
|
|
|
#include "gtkmm2ext/colors.h"
|
|
|
|
|
|
|
|
#include "canvas/box.h"
|
2020-05-22 10:46:37 -04:00
|
|
|
#include "canvas/canvas.h"
|
2020-06-10 16:10:26 -04:00
|
|
|
#include "canvas/circle.h"
|
|
|
|
#include "canvas/constrained_item.h"
|
2020-05-22 10:46:37 -04:00
|
|
|
#include "canvas/constraint_packer.h"
|
2020-06-10 16:10:26 -04:00
|
|
|
#include "canvas/rectangle.h"
|
|
|
|
#include "canvas/text.h"
|
2020-05-22 10:46:37 -04:00
|
|
|
|
|
|
|
using namespace ArdourCanvas;
|
|
|
|
using namespace Gtk;
|
2020-06-10 16:10:26 -04:00
|
|
|
using std::cerr;
|
|
|
|
using std::endl;
|
2020-05-22 10:46:37 -04:00
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char* argv[])
|
|
|
|
{
|
|
|
|
Gtk::Main app (&argc, &argv);
|
|
|
|
|
|
|
|
Gtk::Window win;
|
|
|
|
Gtk::Adjustment hadj (0, 0, 1000, 1, 10);
|
|
|
|
Gtk::Adjustment vadj (0, 0, 1000, 1, 10);
|
|
|
|
GtkCanvasViewport cview (hadj, vadj);
|
2020-06-10 16:10:26 -04:00
|
|
|
Canvas* c = cview.canvas ();
|
|
|
|
|
|
|
|
c->set_background_color (0xffffffff);
|
|
|
|
|
|
|
|
srandom (time ((time_t) 0));
|
|
|
|
|
|
|
|
// cview.set_size_request (100, 100);
|
2020-05-22 10:46:37 -04:00
|
|
|
|
|
|
|
win.add (cview);
|
2020-06-10 16:10:26 -04:00
|
|
|
|
2020-06-11 02:44:11 -04:00
|
|
|
Rectangle* r1 = new Rectangle (c);
|
|
|
|
Rectangle* r2 = new Rectangle (c);
|
|
|
|
Rectangle* r3 = new Rectangle (c);
|
2020-06-10 16:10:26 -04:00
|
|
|
|
2020-06-11 02:44:11 -04:00
|
|
|
r1->set_fill_color (Gtkmm2ext::random_color());
|
|
|
|
r2->set_fill_color (Gtkmm2ext::random_color());
|
|
|
|
r3->set_fill_color (Gtkmm2ext::random_color());
|
2020-06-10 16:10:26 -04:00
|
|
|
|
2020-06-11 02:44:11 -04:00
|
|
|
r1->name = "r1";
|
|
|
|
r2->name = "r2";
|
|
|
|
r3->name = "r3";
|
2020-06-10 16:10:26 -04:00
|
|
|
|
2020-06-11 02:44:11 -04:00
|
|
|
//r1->set_intrinsic_size (20, 20);
|
|
|
|
//r2->set_intrinsic_size (30, 30);
|
|
|
|
//r3->set_intrinsic_size (40, 40);
|
2020-06-10 16:10:26 -04:00
|
|
|
|
2020-07-10 22:21:47 -04:00
|
|
|
ConstraintPacker* vbox = new ConstraintPacker (c->root(), Vertical);
|
2020-06-11 02:44:11 -04:00
|
|
|
vbox->name = "vbox";
|
2020-06-21 14:53:10 -04:00
|
|
|
vbox->set_fill (true);
|
|
|
|
vbox->set_fill_color (0xff0000ff);
|
|
|
|
vbox->set_margin (20);
|
2020-06-11 02:44:11 -04:00
|
|
|
|
|
|
|
vbox->pack_start (r1, PackOptions(PackExpand|PackFill));
|
|
|
|
vbox->pack_start (r2, PackOptions(PackExpand|PackFill));
|
|
|
|
vbox->pack_start (r3, PackOptions(PackExpand|PackFill));
|
|
|
|
|
2020-07-10 22:21:47 -04:00
|
|
|
ConstraintPacker* hbox1 = new ConstraintPacker (c, Horizontal);
|
2020-06-11 02:44:11 -04:00
|
|
|
hbox1->name = "hbox1";
|
2020-06-21 14:53:10 -04:00
|
|
|
hbox1->set_fill (true);
|
|
|
|
hbox1->set_fill_color (0x00ff00ff);
|
2020-06-11 02:44:11 -04:00
|
|
|
|
2020-06-25 17:03:26 -04:00
|
|
|
hbox1->set_margin (10);
|
2020-06-11 02:44:11 -04:00
|
|
|
|
|
|
|
Rectangle* r4 = new Rectangle (c);
|
|
|
|
Rectangle* r5 = new Rectangle (c);
|
|
|
|
Rectangle* r6 = new Rectangle (c);
|
|
|
|
|
|
|
|
r4->set_fill_color (Gtkmm2ext::random_color());
|
|
|
|
r5->set_fill_color (Gtkmm2ext::random_color());
|
|
|
|
r6->set_fill_color (Gtkmm2ext::random_color());
|
|
|
|
|
|
|
|
r4->name = "r4";
|
|
|
|
r5->name = "r5";
|
|
|
|
r6->name = "r6";
|
2020-06-19 16:02:24 -04:00
|
|
|
|
2020-06-21 14:53:10 -04:00
|
|
|
ConstrainedItem* ci4 = hbox1->pack_start (r4, PackOptions(PackExpand|PackFill));
|
2020-06-11 02:44:11 -04:00
|
|
|
hbox1->pack_start (r5, PackOptions(PackExpand|PackFill));
|
|
|
|
hbox1->pack_start (r6, PackOptions(PackExpand|PackFill));
|
|
|
|
|
|
|
|
BoxConstrainedItem* hb1;
|
2020-06-28 23:36:22 -04:00
|
|
|
BoxConstrainedItem* ci;
|
2020-06-11 02:44:11 -04:00
|
|
|
|
|
|
|
hb1 = vbox->pack_start (hbox1, PackOptions (PackExpand|PackFill));
|
|
|
|
|
2020-06-21 14:53:10 -04:00
|
|
|
ci4->add_constraint (ci4->width() == hb1->width() / 2.);
|
2020-06-19 16:02:24 -04:00
|
|
|
|
2020-06-11 02:44:11 -04:00
|
|
|
Circle* circle = new Circle (c);
|
|
|
|
circle->name = "circle";
|
|
|
|
//circle->set_radius (30);
|
|
|
|
circle->set_fill_color (Gtkmm2ext::random_color());
|
|
|
|
circle->set_outline_color (Gtkmm2ext::random_color());
|
|
|
|
|
|
|
|
ci = vbox->pack_start (circle, PackOptions (PackExpand|PackFill));
|
|
|
|
ci->add_constraint (ci->height() == 0.5 * hb1->height());
|
2020-06-21 14:53:10 -04:00
|
|
|
ci->add_constraint (ci->center_x() == ci4->center_x());
|
2020-06-28 23:36:22 -04:00
|
|
|
ci->add_constraint (ci->top_padding() == 10);
|
|
|
|
ci->add_constraint (ci->bottom_padding() == 10);
|
2020-06-11 02:44:11 -04:00
|
|
|
|
2020-07-10 22:21:47 -04:00
|
|
|
ConstraintPacker* hbox2 = new ConstraintPacker (c, Horizontal);
|
2020-06-11 02:44:11 -04:00
|
|
|
hbox2->name = "hbox2";
|
|
|
|
hbox2->set_fill (true);
|
|
|
|
hbox2->set_fill_color (Gtkmm2ext::random_color());
|
2020-06-25 17:03:26 -04:00
|
|
|
hbox2->set_outline (true);
|
2020-06-11 02:44:11 -04:00
|
|
|
|
|
|
|
Text* txt = new Text (c);
|
|
|
|
txt->name = "text";
|
|
|
|
|
|
|
|
Pango::FontDescription font ("Sans");
|
|
|
|
|
|
|
|
txt->set_font_description (font);
|
2020-06-19 16:02:24 -04:00
|
|
|
txt->set ("hello world");
|
2020-06-11 02:44:11 -04:00
|
|
|
|
2020-06-25 17:03:26 -04:00
|
|
|
ConstrainedItem* hb2 = vbox->pack_start (hbox2, PackOptions (PackExpand|PackFill));
|
2020-06-28 23:36:22 -04:00
|
|
|
ConstrainedItem* ti = hbox2->pack_start (txt, PackOptions (PackExpand), PackOptions (0));
|
2020-06-11 02:44:11 -04:00
|
|
|
|
2020-06-25 17:03:26 -04:00
|
|
|
ti->add_constraint (ti->center_x() == hb2->center_x());
|
2020-06-28 23:36:22 -04:00
|
|
|
ti->add_constraint (ti->center_y() == hb2->center_y());
|
|
|
|
|
2020-06-11 02:44:11 -04:00
|
|
|
win.show_all ();
|
|
|
|
app.run ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|