Home |
Creating PegThings Obtaining a Pointer to PegPresentationManager Determining the Position of an Object |
Creating PegThingsPegThing contains information about the physical location of the objects on the screen, the client area of an object, the clipping area of an object, the system status flags for the object (selected, sizable, etc.), and pointers used to maintain the object's position in the presentation tree. PegThing provides the member function Add(PegThing * what), which is used to add controls or windows to another. With Add(PegThing * what), parameter what is inserted into the current object's child list. If the current object is visible, the newly added object also becomes visible. The best way to create a complex window is to create the window, create all of the window's child objects and add them to the window, and finally add the window to PegPresentationManager. In this way, the window and all of the child objects become visible at the same time. A further result of the class hierarchy is that it is perfectly reasonable to create an object that one would normally consider to be a self-contained bottom level object, such as a PegPrompt, and add another object, such as a PegButton, to the PegPrompt. The result is a PegPrompt that first displays the text associated with the prompt, and then allows its child objects to draw themselves. In this example, the PegButton would appear next to or over the prompt text, depending on the Prompt dimensions and text justification flags. While this result may not appear very useful, you should be able to see that by deriving your own version of PegPrompt specifically for this purpose, you could easily create a powerful new object type simply by combining these two predefined objects. The following code fragment illustrates the ease of creating and displaying new windows. The newly created window will have a title, a menu bar, and a status bar: PegRect WinSize; WinSize.Set(10, 10, 120, 200); Presentation()->Add(new AppWindow(WinSize, "My First Window")); ... AppWindow::AppWindow(PegRect Rect, PEGCHAR * Title): PegDecoratedWindow(Rect) { Add(new PegTitle(Title)); // add a title to myself Add(new PegMenuBar(MainMenu)); // and a menu bar PegStatusBar * pStat = new PegStatusBar(); pStat->AddTextField(80, "Hello"); pStat->AddTextField(20, "How are you today?"); Add(pStat); // and a status bar }
|