/**** * * Simple program that demonstrates InterViews push buttons. * */ #include "quit-exception.h" #include #include #include #include #include #include #include /** * Declaration of buttons as subclasses of InterViews' PushButton class. */ class RegularBurgerButton : public PushButton { public: RegularBurgerButton(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press(); }; class ChiliBurgerButton : public PushButton { public: ChiliBurgerButton(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press(); }; class FatBurgerButton : public PushButton { public: FatBurgerButton(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press(); }; class SLOBurgerButton : public PushButton { public: SLOBurgerButton(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press(); }; class FriesButton : public PushButton { public: FriesButton(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press(); }; class OnionRingsButton : public PushButton { public: OnionRingsButton(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press(); }; class ApplePieButton : public PushButton { public: ApplePieButton(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press(); }; class SmallSideOrderButton : public PushButton { public: SmallSideOrderButton(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press(); }; class MediumSideOrderButton : public PushButton { public: MediumSideOrderButton(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press(); }; class LargeSideOrderButton : public PushButton { public: LargeSideOrderButton(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press(); }; class CokeButton : public PushButton { public: CokeButton(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press(); }; class DietCokeButton : public PushButton { public: DietCokeButton(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press(); }; class SpriteButton : public PushButton { public: SpriteButton(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press(); }; class WaterButton : public PushButton { public: WaterButton(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press(); }; class ExitButton : public PushButton { public: ExitButton(const char* label, ButtonState* bs, int v) : PushButton(label, bs, v) {} protected: void Press(); }; /** * Implementations of button press functions. */ void RegularBurgerButton::Press() { printf("Ordering RegularBurger.\n"); } void ChiliBurgerButton::Press() { printf("Ordering ChiliBurger.\n"); } void FatBurgerButton::Press() { printf("Ordering FatBurger.\n"); } void SLOBurgerButton::Press() { printf("Ordering SLOBurger.\n"); } void FriesButton::Press() { printf("Ordering Fries.\n"); } void OnionRingsButton::Press() { printf("Ordering OnionRings.\n"); } void ApplePieButton::Press() { printf("Ordering ApplePie.\n"); } void SmallSideOrderButton::Press() { printf("Ordering SmallSideOrder.\n"); } void MediumSideOrderButton::Press() { printf("Ordering MediumSideOrder.\n"); } void LargeSideOrderButton::Press() { printf("Ordering LargeSideOrder.\n"); } void CokeButton::Press() { printf("Ordering Coke.\n"); } void DietCokeButton::Press() { printf("Ordering DietCoke.\n"); } void SpriteButton::Press() { printf("Ordering Sprite.\n"); } void WaterButton::Press() { printf("Ordering Water.\n"); } void ExitButton::Press() { #ifndef OLD_EXCEPTION_HANDLING throw new QuitException; #else throw(QuitException, NULL); #endif } /** * Function to build the buttons and lay them out in a window. */ Interactor *BuildButtons() { /* * The interface will be composed of four VBoxes, containing food ordering * buttons for burgers, side orders, drinks, and an exit button. These * VBoxes are in turn put in an HBox for alignment purposes. Finally, the * HBox is put in a tray to provide a nice background. */ /* * Initializes the boxes and tray. */ VBox* bbuttons = new VBox; VBox* sbuttons = new VBox; VBox* dbuttons = new VBox; VBox* ebuttons = new VBox; HBox* allbuttons = new HBox; Tray* buttonbox = new Tray; ButtonState* dummystate = new ButtonState; /* * Put the burger ordering buttons in their box, center aligned with 1/4 * inch spacing between each. */ bbuttons->Align(Center); bbuttons->Insert(new VGlue(round(0.25*inch))); bbuttons->Insert(new Message("Order Burgers:")); bbuttons->Insert(new VGlue(round(0.25*inch))); bbuttons->Insert(new RegularBurgerButton("Regular",dummystate,true)); bbuttons->Insert(new VGlue(round(0.25*inch))); bbuttons->Insert(new ChiliBurgerButton("Chili Burger",dummystate,true)); bbuttons->Insert(new VGlue(round(0.25*inch))); bbuttons->Insert(new FatBurgerButton("Fat Burger",dummystate,true)); bbuttons->Insert(new VGlue(round(0.25*inch))); bbuttons->Insert(new SLOBurgerButton("SLO Burger",dummystate,true)); bbuttons->Insert(new VGlue(round(0.25*inch))); /* * Put the side ordering buttons in their box, center aligned with 1/4 * inch spacing between each. */ sbuttons->Align(Center); sbuttons->Insert(new VGlue(round(0.25*inch))); sbuttons->Insert(new Message("Order Sides:")); sbuttons->Insert(new VGlue(round(0.25*inch))); sbuttons->Insert(new FriesButton("Fries",dummystate,true)); sbuttons->Insert(new VGlue(round(0.25*inch))); sbuttons->Insert(new OnionRingsButton("OnionRings",dummystate,true)); sbuttons->Insert(new VGlue(round(0.25*inch))); sbuttons->Insert(new ApplePieButton("ApplePie",dummystate,true)); sbuttons->Insert(new VGlue(round(0.25*inch))); /* * Put the drink ordering buttons in their box, center aligned with 1/4 * inch spacing between each. */ dbuttons->Align(Center); dbuttons->Insert(new VGlue(round(0.25*inch))); dbuttons->Insert(new Message("Order Drinks:")); dbuttons->Insert(new VGlue(round(0.25*inch))); dbuttons->Insert(new CokeButton("Coke",dummystate,true)); dbuttons->Insert(new VGlue(round(0.25*inch))); dbuttons->Insert(new DietCokeButton("Diet",dummystate,true)); dbuttons->Insert(new VGlue(round(0.25*inch))); dbuttons->Insert(new SpriteButton("Sprite",dummystate,true)); dbuttons->Insert(new VGlue(round(0.25*inch))); dbuttons->Insert(new WaterButton("Water",dummystate,true)); dbuttons->Insert(new VGlue(round(0.25*inch))); /* * Put the exit button in its box. */ ebuttons->Align(Center); ebuttons->Insert(new VGlue(round(0.25*inch))); ebuttons->Insert(new ExitButton("Exit",dummystate,true)); ebuttons->Insert(new VGlue(round(0.25*inch))); /* * Put the button HBoxes in their VBox, top aligned. */ allbuttons->Align(Top); allbuttons->Insert(new HGlue(round(0.25*inch))); allbuttons->Insert(bbuttons); allbuttons->Insert(new HGlue(round(0.25*inch))); allbuttons->Insert(sbuttons); allbuttons->Insert(new HGlue(round(0.25*inch))); allbuttons->Insert(dbuttons); allbuttons->Insert(new HGlue(round(0.25*inch))); allbuttons->Insert(ebuttons); allbuttons->Insert(new HGlue(round(0.25*inch))); /* * Put the VBox in the background tray. */ buttonbox->Insert(allbuttons); return buttonbox; } static PropertyData properties[] = { { "buttons*title", "Button Test" }, { nil } }; static OptionDesc options[] = { { "-title", "buttons*title", OptionValueNext }, { nil } }; /** * Initialize InterViews by building a world. Then call BuildButtons to * construct the UI, and World::InsertApplication to display the UI. */ int main (int argc, char* argv[]) { World* world = new World("buttons", properties, options, argc, argv); world->InsertApplication(BuildButtons()); #ifndef OLD_EXCEPTION_HANDLING try { world->Run(); } catch (QuitException*) { printf("Thank you for dining at Biggie Burger.\n\n"); delete world; return 0; } #else if (! catch(QuitException)) { world->Run(); } else { printf("Thank you for dining at Biggie Burger.\n\n"); delete world; return 0; } #endif }