Developer Guide - Running the GUI

If you were to take the code from the Creating a Simple GUI section, insert it into a project and run it, you'd find that nothing happened. We're missing a few vital steps. We need to initialise the DS before we begin creating the GUI. Once the GUI is set up, we need to draw it and ensure that Woopsi is running.

Setting up the DS just entails calling this function at the top of your main() routine:

// Initialise the DS
initWoopsiGfxMode();

After calling that function, you need to set up the GUI as described in the Creating a Simple GUI section. Once your GUI is set up, Woopsi is run using the following code:

// Draw the GUI
woopsiApplication->draw();

// Infinite loop to keep the program running
while (1) {
	woopsiApplication->run();
	PA_WaitForVBL();
}

The code below provides a complete version of the GUI we've defined that you can copy into your "main.cpp" file and run:

// Includes
#include "woopsiheaders.h"

int main()
{
	// Create woopsi
	woopsiApplication = new Woopsi();

	// Create screen
	AmigaScreen* screen = new AmigaScreen("My Screen");
	woopsiApplication->addGadget(screen);

	// Create window
	AmigaWindow* window = new AmigaWindow(20, 20, 100, 100, "My Window", GADGET_DRAGGABLE);
	screen->addGadget(window);

	// Create button
	Button* button = new Button(5, 5, 60, 60, "Hello World!");
	window->addGadget(button);

	// Draw the GUI
	woopsiApplication->draw();

	// Infinite loop to keep the program running
	while (1)
	{
		woopsiApplication->run();
		PA_WaitForVBL();
	}
	
	// Clean up
	delete woopsiApplication;

	return 0;
}