Skip to content
Ant edited this page Dec 27, 2013 · 2 revisions

We're still missing two gadgets from our initial objective:

  • A window
  • A textbox

Let's add the window next. To do so, open up your "woopsitest.cpp" file again and add the following line to the top:

#include "amigawindow.h"

Then replace the startup() method with the following:

void WoopsiTest::startup() {
    AmigaScreen* screen = new AmigaScreen(
        "Hello World Screen",
        true,
        true);

    addGadget(screen);

    // Create the window and add it to the screen.
    AmigaWindow* window = new AmigaWindow(10, 30, 145, 100,
        "Hello World Window",
        true,
        true);

    screen->addGadget(window);
}

When you compile this example, you will get this result in your emulator:

AmigaWindow

Try clicking on the window, then on the screen. When you click on the window, its border will turn blue; this shows that it is the currently active gadget and has "focus". When you click on the screen, the window loses focus and its border becomes grey again.

You can drag the window around by clicking on its title bar and moving it. The button on the top-left of the window will close it, whilst the button on the top-right will move it to the bottom of the window stack if there is more than one window on the screen.

If you try dragging the screen down again, by clicking on its title, youʼll find that the window is dragged down along with it. The screen "owns" the window, and so repositioning the screen will reposition any gadgets that it owns. A gadget that is owned by another is called its "child", whilst the owning gadget is called the "parent". In this situation, the window is a child of the screen, which is in turn a child of the WoopsiTest object. Ownership of gadgets is established via the "addGadget()" method used to add the screen to the WoopsiTest object, and the window to the screen.

The arguments passed to the windowʼs constructor should look familiar. The fifth argument is the window's name. The last two arguments control the visibility of the close and depth buttons, instead of the flip and depth buttons used by the screen. The only novel arguments are the four numeric parameters. These correspond to the x and y co-ordinates of the window and its width and height respectively. Try playing around with these values to see how they affect the window. Note that the co-ordinates are relative to the screen that contains the window, not the physical display itself.

Clone this wiki locally