00001
00002 #include "Demo.h"
00003
00004
00005 #include "gui/GuiMgr.h"
00006 #include "gui/DisplayControl.h"
00007 #include <strstream>
00008
00009
00010
00011 class SimpleBox
00012 {
00013 public:
00014 SimpleBox(double a, double b, const std::string& name)
00015 :m_a(a), m_b(b), m_name(name){}
00016 ~SimpleBox(){}
00017 double a()const{return m_a;}
00018 double b()const{return m_b;}
00019 const std::string& name()const{return m_name;}
00020 private:
00021 double m_a, m_b;
00022 std::string m_name;
00023 };
00024
00025
00026
00027 class SimpleBoxRep : public gui::DisplayRep
00028 {
00029 public:
00030 SimpleBoxRep(const SimpleBox* pbox):m_pbox(pbox)
00031 {
00032
00033 }
00034 void update()
00035 {
00036 using namespace gui;
00037 if( hasRepresentation() ) return;
00038 set_color("blue");
00039 double a = m_pbox->a(), b = m_pbox->b();
00040
00041
00042 addVertex(GraphicsVector( a, a, a));
00043 addVertex(GraphicsVector( a, b, a));
00044 addVertex(GraphicsVector( b, b, a));
00045 addVertex(GraphicsVector( b, a, a));
00046 addVertex(GraphicsVector( a, a, b));
00047 addVertex(GraphicsVector( a, b, b));
00048 addVertex(GraphicsVector( b, b, b));
00049 addVertex(GraphicsVector( b, a, b));
00050
00051
00052 static int q[]={0,1,2,3,0,4,5,6,7,4,-1, 1,5,-1,2,6,-1,3,7,-1};
00053 indexedLineSet(q,sizeof(q)/sizeof(int));
00054
00055
00056 double c = 0.5*(a+b); move_to(GraphicsVector(c,c,c));
00057 drawText(m_pbox->name());
00058 set_color("black");
00059 }
00060 private:
00061 const SimpleBox* m_pbox;
00062 };
00063
00064
00065
00066 Demo::Demo(gui::DisplayControl & display) : _number(0)
00067 , _box1(new SimpleBox(-400,400, "1"))
00068 , _box2(new SimpleBox(-300,-200, "2"))
00069 , _box3(new SimpleBox(-200,-100, "3"))
00070 , _box4(new SimpleBox(-100, 100, "4"))
00071 {
00072 using namespace gui;
00073
00074
00075
00076
00077
00078 DisplayRep* r1 = new SimpleBoxRep(_box1);
00079 DisplayRep* r11 = new SimpleBoxRep(_box2);
00080 DisplayRep* r12 = new SimpleBoxRep(_box3);
00081
00082 DisplayControl::DisplaySubMenu& sm1 = display.subMenu("Boxes..", r1);
00083 DisplayControl::DisplaySubMenu& sm2 = sm1.subMenu("box 2", r11);
00084 sm1.add(r12, "box3");
00085 sm2.add(new SimpleBoxRep(_box4), "box4");
00086
00087
00088 }
00089
00090 void Demo::process()
00091 {
00092
00093 ++_number;
00094 }
00095
00096 Demo::~Demo()
00097 {
00098 delete _box1;
00099 delete _box2;
00100 delete _box3;
00101 delete _box4;
00102 }
00103