/* * This is a simple example that illustrates how to raise and lower top-level * interactors within a World scene. */ #include #include #include #include #include #include /* * NOTE: Bad style here -- should pass these statics to button constructors. */ static World* w; /* The world */ static Message* m1; /* Text appearing in window 1 */ static Message* m2; /* Text appearing in window 2 */ static Coord x1,y1; /* Saved coords of window 1 */ static Coord x2,y2; /* Saved coords of window 2 */ static unsigned char m1_up=1, m2_up=1; /* Flags: true of window is exposed, false if window is hidden. */ /* * Button Raise1 raises window 1, if it's not hidden, and reports its position. */ class Raise1 : public PushButton { public: Raise1(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press() { Coord x=0, y=0; /* Note initialization of GetRelative parms. */ if (m1_up) { w->Raise(m1); m1->GetRelative(x,y); printf("Window 1 is at: %d, %d\n", x, y); } } }; /* * Button Raise2 raises window 2, if it's not hidden, and reports its position. */ class Raise2 : public PushButton { public: Raise2(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press() { Coord x=0, y=0; /* Note initialization of GetRelative parms. */ if (m2_up) { w->Raise(m2); m2->GetRelative(x,y); printf("Window 2 is at: %d, %d\n", x, y); } } }; /* * Button Lower1 lowers window 1, if it's not hidden. */ class Lower1 : public PushButton { public: Lower1(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press() { if (m1_up) w->Lower(m1); } }; /* * Button Lower2 lowers window 2, if it's not hidden. */ class Lower2 : public PushButton { public: Lower2(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press() { if (m2_up) w->Lower(m2); } }; /* * Button Expose1 exposes window 1, if it's been hidden. */ class Expose1 : public PushButton { public: Expose1(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press() { if (! m1_up) { w->InsertApplication(m1,x1,y1); m1_up = 1; } } }; /* * Button Expose2 exposes window 2, if it's been hidden. */ class Expose2 : public PushButton { public: Expose2(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press() { if (! m2_up) { w->InsertApplication(m2,x2,y2); m2_up = 1; } } }; /* * Button Hide1 hides window 1, if it's not hidden already. */ class Hide1 : public PushButton { public: Hide1(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press() { if (m1_up) { x1 = 0; y1 = 0; m1->GetRelative(x1,y1); w->Remove(m1); m1_up = 0; } } }; /* * Button Hide2 hides window 2, if it's not hidden already. */ class Hide2 : public PushButton { public: Hide2(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press() { if (m2_up) { x2 = 0; y2 = 0; m2->GetRelative(x2,y2); w->Remove(m2); m2_up = 0; } } }; main () { w = new World(); m1 = new Message("Hello 1"); m2 = new Message("Hello 2"); VBox* vb; w->InsertApplication( new Tray(vb = new VBox( new HBox( new Raise1("Raise Hello 1, and Report Its Position", new ButtonState(), true), new Raise2("Raise Hello 2, and Report Its Position", new ButtonState(), true)), new HBox( new Lower1("Lower Hello 1", new ButtonState(), true), new Lower2("Lower Hello 2", new ButtonState(), true)), new HBox( new Expose1("Expose Hello 1", new ButtonState(), true), new Expose2("Expose Hello 2", new ButtonState(), true)), new HBox( new Hide1("Hide Hello 1", new ButtonState(), true), new Hide2("Hide Hello 2", new ButtonState(), true))))); vb->Align(Center); vb->Change(); w->InsertApplication(m1); w->InsertApplication(m2); w->Run(); delete w; }