/**** * * Simpler graphics demonstration program. All this example does is draw a * single diagonal line. Cf. ./graphic.C, which is a more involved graphics * demonstration. * */ #include #include #include #include #include #include #include #include /* * Graphics class defines and implements the outer-level interactor for * the application. An instance of Graphic is inserted into the world. */ class Graphics : public MonoScene { public: Graphics(); protected: Picture* InitPicture(); }; /* * MainWindow is a GraphicBlock with its Handle member function redefined to * detect hits on the Graphic objects it contains. */ class MainWindow : public GraphicBlock { public: MainWindow(Graphic*); virtual ~MainWindow(); }; /* * Primordial root object creation and initialization function. A pointer * to this function is passed to the object manager constructor. */ void GraphicsInitialize (RefList* root) { Picture* pict = new Picture; FullGraphic dfault; InitPPaint(); root->Append(new RefList(pict)); dfault.FillBg(true); dfault.SetColors(pblack, pwhite); dfault.SetPattern(psolid); dfault.SetBrush(psingle); dfault.SetFont(pstdfont); Line* line = new Line (0, 0, 75, 75, &dfault); pict->Append(line); } /* Implementation of Graphics class ******************************************/ Graphics::Graphics () { Picture* pict = InitPicture(); MainWindow* view = new MainWindow(pict); Tray* interior = new Tray(view); Perspective* p = new Perspective(); Insert(interior); } Picture* Graphics::InitPicture () { TheManager = new ObjectMan( "graphics", &GraphicsInitialize, &GraphicConstruct ); Picture* pict = (Picture*) (*(*TheManager->GetRoot())[1])(); pict->SetTransformer(nil); return pict; } /* Implementation of MainWindow class ****************************************/ MainWindow::MainWindow (Graphic* g) : GraphicBlock(nil, g) { input = new Sensor(updownEvents); input->Catch(KeyEvent); } MainWindow::~MainWindow () {} /* Main program **************************************************************/ int main (int argc, char* argv[]) { register int i; bool save = false; World* world = new World("graphics", argc, argv); for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-s") == 0) { save = true; } else { fprintf(stderr, "bad arg %s\n", argv[i]); exit(1); } } Graphics* graphics = new Graphics; world->InsertApplication(graphics); graphics->Run(); delete graphics; if (save) { delete TheManager; } return 0; }