00001 #include "Midad/Scene.h"
00002 #include "Midad/Scenery.h"
00003 #include "Midad/GuiMainWindow.h"
00004 #include "Midad/GuiCanvas.h"
00005 #include "Midad/GuiBox.h"
00006 #include "Midad/GuiButton.h"
00007
00008 #include "TApplication.h"
00009 #include "TRandom.h"
00010 #include "TCanvas.h"
00011 #include "TBox.h"
00012
00013 #include <iostream>
00014 #include <sigc++/sigc++.h>
00015 #include <sigc++/object_slot.h>
00016 #include <sigc++/class_slot.h>
00017
00018 class MyScenery : public Midad::Scenery
00019 {
00020 TRandom rand;
00021 public:
00022 MyScenery() { this->Diddle(); }
00023 ~MyScenery() {}
00024 void Diddle() {
00025 this->ClearPrimitives();
00026 double x1 = rand.Uniform();
00027 double y1 = rand.Uniform();
00028 double x2 = rand.Uniform();
00029 double y2 = rand.Uniform();
00030 cerr << "Diddle the box: "
00031 << "(" << x1 << "," << y1 << ")-->"
00032 << "(" << x2 << "," << y2 << ")\n";
00033 TBox* box = new TBox(x1,y1,x2,y2);
00034 this->AddPrimitive(box);
00035 box->SetFillColor(rand.Integer(50));
00036 modified.emit();
00037 }
00038 };
00039
00040 class DualSignal {
00041 public:
00042 SigC::Signal0<void> sig, done;
00043 void emit() { sig.emit(); done.emit(); }
00044 };
00045
00046 void add_box(Midad::Scene* s, SigC::Signal0<void>* sig)
00047 {
00048 cerr << "Add a box\n";
00049 MyScenery* ms = manage(new MyScenery);
00050 s->Add(*ms);
00051 sig->connect(SigC::slot(*ms,&MyScenery::Diddle));
00052 s->Update();
00053 }
00054
00055 int main (int argc, char *argv[])
00056 {
00057 TApplication theApp("App", &argc, argv);
00058
00059 GuiMainWindow mw(300,400);
00060 GuiVBox vbox(mw);
00061 vbox.SetLayoutHints(vbox.GetLayoutHints() | kLHintsExpandX);
00062 mw.Add(vbox);
00063
00064 GuiCanvas gc(vbox);
00065 vbox.Add(gc);
00066
00067 Midad::Scene s("test-scene","generic-scene-type");
00068
00069 TCanvas* canvas = gc.GetCanvas();
00070 canvas->cd();
00071 s.Draw();
00072
00073 GuiHBox hbox(vbox);
00074 vbox.Add(hbox);
00075
00076 DualSignal dualsig;
00077 dualsig.done.connect(SigC::slot(s,&Midad::Scene::Update));
00078
00079 GuiTextButton* but = manage(new GuiTextButton(hbox,"modify"));
00080 hbox.Add(*but);
00081 but->clicked.connect(SigC::slot_class(dualsig,&DualSignal::emit));
00082
00083 GuiTextButton* addbut = manage(new GuiTextButton(hbox,"add"));
00084 hbox.Add(*addbut);
00085 addbut->clicked.connect(SigC::bind(SigC::slot(add_box),&s,&dualsig.sig));
00086
00087 but = manage(new GuiTextButton(hbox,"update"));
00088 hbox.Add(*but);
00089 but->clicked.connect(SigC::slot(s,&Midad::Scene::Update));
00090
00091
00092 mw.ShowAll();
00093 mw.SetMinSize();
00094 mw.ConnectClose();
00095
00096 theApp.Run();
00097 return 0;
00098 }