/* * Simple illustration of the use of a Viewport. */ #include #include #include #include "funcbutton.h" #include #include #include #include #include #include #include #include void DoButton(void* v, Event *e); class PVBox : public VBox { public: void SetPerspective(Perspective* p) {perspective = p;} }; main () { World* w = new World; Tray* t = new Tray; VBox* vb = new VBox; PVBox* vb1 = new PVBox; HBox* hb = new HBox; HBox* hb1; Viewport* vp; Shape* sh1, *sh2; Perspective* p; char *bname1, *bname2;; int i; /* * Make a vbox of 35 rows of hboxes, with each hbox containing a pair of * function buttons. */ for (i = 1; i <= 70; i+=2) { bname1 = new char[15]; bname2 = new char[15]; sprintf(bname1, "Button No. %d", i); sprintf(bname2, "Button No. %d", i+1); hb1 = new HBox( new FuncButton(DoButton, bname1, 0), new FuncButton(DoButton, bname2, 0)); vb1->Insert(hb1); } /* * Make the vbox into a viewport by adding a perspective. */ vb1->SetPerspective(p = new Perspective); p->Init(0,0, 100, 200); /* * Stick the vbox and a scroller into an outer hbox. */ hb->Insert(vb1); hb->Insert(new VBorder); hb->Insert( new VBox( new UpMover(vb1,1), new HBorder, new VScroller(vb1), new HBorder, new DownMover(vb1,1) ) ); /* * Stick some other stuff around the outer hbox, to confirm that things get * reconfig'd nicely. */ vb->Insert(new Message("Message 1")); vb->Insert(new Message("Message 2")); vb->Insert(new Message("Message 3")); vb->Insert(new HBorder); vb->Insert(hb); vb->Insert(new HBorder); vb->Insert(new Message("Message 4")); vb->Insert(new Message("Message 5")); vb->Insert(new Message("Message 6")); vb->Align(Center); /* * Insert the outermost tray into the world. */ w->InsertApplication(new Tray(vb)); /* * Get the shape of the hbox and halve the height, so that only half of it * will appear initially in the viewport. Note that this happens after * InsertApplication, since Config is called from InsertApplication, and * Config tries its very hardest to "shrink wrap" things, independent of * whatever shapes they have before the Config. E.g., in this case, Config * will size everything to show all of the buttons, even if the box is * initially shaped to be smaller than is big enough to hold all of the * buttons. Once the initial call to Config is done, we can reshape and * reconfig all we want. */ sh1 = hb->GetShape(); sh1->height /= 2; hb->Reshape(*sh1); w->Reconfig(); w->Run(); delete w; } void DoButton(void* v, Event *e) { printf("In button.\n"); }