Gel2D - The free/open source game creation suite

Static Public Member Functions
gel::GelWindow Class Reference

Window handling. More...

#include <gelWindow.h>

List of all members.

Static Public Member Functions

static bool createWindow (const char *title="Gel2D Game Engine", int width=800, int height=600, int bpp=32, int mode=GEL_WINDOWED, int flags=0)
 Creates a new top-level window.
static void destroyWindow ()
 Destroys the window.
static void setMode (int width, int height, int mode, int flags)
 Sets the size, video mode, and style of the window.
static void setMode (GelVideoMode videoMode)
 Sets the window size and video mode.
static GelString getTitle ()
 Gets the title of the window.
static void setTitle (const GelString &title)
 Sets the title of the window.
static void setIcon (const GelString &filename)
 Sets the window's icon.
static bool setSize (int width, int height)
 Sets the dimensions of the window.
static void getSize (int *width, int *height)
 Gets the dimensions of the window.
static GelSize getSize ()
 Gets the dimensions of the window.
static int getWidth ()
 Gets the width of the window.
static int getHeight ()
 Gets the height of the window.
static void setPos (int x, int y)
 Sets the window's position on the screen.
static void minimize ()
 Minimizes the window to the taskbar.
static void restore ()
 Restores the window to the state it was in prior to being minimized.
static int getParam (int param)
 Gets the value of a specified window parameter.
static void pollEvents ()
 Polls for events.

Detailed Description

Window handling.

All members of GelWindow are static, so you shouldn't ever need to create an instance of this class; just call the functions directly.


Member Function Documentation

static bool gel::GelWindow::createWindow ( const char *  title = "Gel2D Game Engine",
int  width = 800,
int  height = 600,
int  bpp = 32,
int  mode = GEL_WINDOWED,
int  flags = 0 
) [static]

Creates a new top-level window.

Only one window can be open at any one time, so any subsequent calls to createWindow() will return false.
If you're feeling lazy, you don't have to specify any parameters in this function, as all of them are set to reasonable defaults.

As for the window flags, they can be any of the following, combined with the bitwise OR operator in any way you choose:
GEL_WND_SIZE : Specifies that that the window should be resizeable.
GEL_WND_MIN : Places a minimize button in the window's title bar.
GEL_WND_MAX : Places a maximize button in the window's title bar.

Parameters:
title: Title of the window.
width: Width of the window.
height: Height of the window.
bpp: Video mode bits per pixel.
mode: Video mode. Either GEL_WINDOWED or GEL_FULLSCREEN.
flags: Flags to customize the window's style.
Returns:
False if the window fails to open, else true
static void gel::GelWindow::destroyWindow ( ) [static]

Destroys the window.

In most if not all circumstances, you won't have to call this function.
Destroying the window does not end the program, unless you include the the proper code in your game loop.

Example:

bool running;

...

// Game loop
while( running )
{
    // Animate stuff...
    // Render stuff...
    // Poll for events...

    // Set running to false if Escape key is pressed or window is closed
    running = !GelInput::keyPressed(GEL_KEY_ESC) && GelWindow::getParam(GEL_WND_OPEN);
}

As you have just seen, setting running to the opened (or closed) state of the window will take care of exiting the game loop if destroyWindow() is called or if the window is in some other way closed.

Although I don't recommend it, destroying the window might be useful when changing from windowed to fullscreen mode, or vice versa.

Example:

GelWindow::createWindow( "My Game", 800, 600, 32, GEL_WINDOWED, 0 ); // windowed

...

    if ( GelInput::getKey(GEL_KEY_F) ) // if 'F' key pressed...
    {
        GelWindow::destroyWindow();
        GelWindow::createWindow( "My Game", 800, 600, 32, GEL_FULLSCREEN, 0 ); // fullscreen
    }

If you wish to dynamically change the window's size, video mode, and/or style, use setWindowMode().

static void gel::GelWindow::setMode ( int  width,
int  height,
int  mode,
int  flags 
) [static]

Sets the size, video mode, and style of the window.

This is THE way to do video mode switching in Gel2D.
This function can change the window's size and style, and change the screen resolution if fullscreen mode is requested; all without having to destroy the window. Very convenient.

Parameters:
width: Width of the window.
height: Height of the window.
mode: Video mode. Either GEL_WINDOWED or GEL_FULLSCREEN.
flags: Flags to customize the window's style.
static void gel::GelWindow::setMode ( GelVideoMode  videoMode) [static]

Sets the window size and video mode.

This is an easier alternative to the above function.

Parameters:
videoMode: The video mode to switch to.
See also:
setWindowMode( int width, int height, int mode, int flags );
static GelString gel::GelWindow::getTitle ( ) [static]

Gets the title of the window.

Returns:
The title of the window.
static void gel::GelWindow::setTitle ( const GelString title) [static]

Sets the title of the window.

Parameters:
title: The new title for the window.
static void gel::GelWindow::setIcon ( const GelString filename) [static]

Sets the window's icon.

Parameters:
filename: The new icon for the window.
static bool gel::GelWindow::setSize ( int  width,
int  height 
) [static]

Sets the dimensions of the window.

Parameters:
width: The new width for the window.
height: The new height for the window.
static void gel::GelWindow::getSize ( int *  width,
int *  height 
) [static]

Gets the dimensions of the window.

Parameters:
width: Pointer to an integer that will hold the width of the window.
height: Pointer to an integer that will hold the height of the window.
static GelSize gel::GelWindow::getSize ( ) [static]

Gets the dimensions of the window.

Returns:
The window's dimensions.
static int gel::GelWindow::getWidth ( ) [static]

Gets the width of the window.

Returns:
The width of the window in pixels.
static int gel::GelWindow::getHeight ( ) [static]

Gets the height of the window.

Returns:
The height of the window in pixels.
static void gel::GelWindow::setPos ( int  x,
int  y 
) [static]

Sets the window's position on the screen.

The x and y positions are relative to the upper left corner of the desktop.
For example, if x = 50 and y = 25, then the window will be positioned 50 pixels from the extreme left of the screen, and 25 pixels from the top of the screen.

Parameters:
x: The new horizontal position for the window.
y: The new vertical position for the window.
static void gel::GelWindow::minimize ( ) [static]

Minimizes the window to the taskbar.

If the window was in fullscreen mode, it will restore the desktop video mode.

static void gel::GelWindow::restore ( ) [static]

Restores the window to the state it was in prior to being minimized.

static int gel::GelWindow::getParam ( int  param) [static]

Gets the value of a specified window parameter.

The parameter can be one of the following: GEL_WND_OPEN, GEL_WND_ACTIVE, GEL_WND_ICONIFIED, or GEL_WND_FULLSCREEN.

Parameters:
param: The parameter to query.
Returns:
GEL_TRUE or GEL_FALSE depending on the status of the requested parameter.
static void gel::GelWindow::pollEvents ( ) [static]

Polls for events.

This must be called somewhere in your game loop to handle window, input and other events.


The documentation for this class was generated from the following file: