Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

Graphics Class Reference

#include <graphics.h>

List of all members.

Public Methods

 Graphics (string title="", int w=1024, int h=768, bool opengl=true)
 Constructor for the graphics class.

 ~Graphics ()
 Destructor for the graphics class.

void PreOpenGLInit ()
 Preinitialize OpenGL.

void PostOpenGLInit ()
 Postinitialize OpenGL.

void toggleFullscreen ()
 Toggle fullscreen mode.

bool isFullscreen ()
 Returns the status of fullscreen mode.

bool isMouseLocked ()
 Get the status of the mouse lock.

bool isHWSurface ()
 Returns true if the surface is in hardware memory.

void hideMouse (bool f)
 Hides the mouse.

SurfacegetMainSurface () const
 Get a pointer to the main surface.

void flip ()
 Flips a double buffer to screen.

void update (int x, int y, int w, int h)
 Update a rectangle.

void update (Rect &r)
 Update a rectangle.

void blit (Surface *src, int dx=0, int dy=0)
 Blit surface to double buffer.

SurfacenewSurface (int w, int h)
 Create a new surface.

void deleteSurface (Surface *n)
 Free surface mem.

void fillSurface (Surface *n, int color)
 Fills Surface with a specific value.

int color (int r, int g, int b, Surface *n=NULL)
 Creates a single RGB value from individual components.

int getWidth () const
 Get the width of the graphics device.

int getHeight () const
 Get the height of the graphics device.

void RotateZ (float degrees)
 Rotate about the Z axis.


Static Public Methods

bool lockMouse (bool lock)
 Lock the Mouse.

void blit (Surface *target, int tx, int ty, Surface *src)
 Blit surface to surface.

void blit (Surface *target, Rect &t, Surface *src, Rect &s)
 Blit surface to surface.

SurfaceCreateSurfaceFrom (Surface *s)
 Create a surface based on another's pixelformat.

SurfaceCreateSurfaceFrom (Surface *s, int nw, int nh)
 Create a surface based on another's pixel.

SurfaceloadImage (const char *fname)
 Load an image from disk.

SurfaceloadImage (string fname)
 Load an image from disk.

SurfacefreeImage (Surface *surf)
 Free an image that was loaded with loadImage.

SurfacedisplayFormat (Surface *surf, bool alpha=false)
 Converts a surface to displayFormat of hwSurface.

void TexturizeSurface (Surface *s)
 Texturize a Surface.

void UntexturizeSurface (Surface *s)
 Free the texture of a Surface.


Static Private Methods

void blitclip (Surface *dest, int drx, int dry, int drw, int drh, Surface *src, int srx, int sry, int srw, int srh)
 Special clipping function for blit.

void blitGLtexture (Surface *src, int srx, int sry, int srw, int srh, int drx, int dry, int drw, int drh)
 Special clipping function for opengl.


Private Attributes

SurfacehwSurface
 the surface the graphics device uses

int width
 the width and height of the hwSurface.

int height
 the width and height of the hwSurface.


Constructor & Destructor Documentation

Graphics::Graphics string    title = "",
int    w = 1024,
int    h = 768,
bool    opengl = true
 

Constructor for the graphics class.

Initializes the graphics hardware and sets up a drawing window.

Parameters:
title The string placed in the title bar
w The width of the window
h The Height of the window
opengl true if you want to use opengl
See also:
~Graphics()

Definition at line 9 of file graphics.cpp.

References _Surface::h, height, hwSurface, PostOpenGLInit(), PreOpenGLInit(), _Surface::surface, _Surface::w, and width.

Graphics::~Graphics  
 

Destructor for the graphics class.

Closes the graphics drawing area and frees all necessary memory.

See also:
Graphics()

Definition at line 46 of file graphics.cpp.

References hwSurface, and _Surface::surface.


Member Function Documentation

void Graphics::blit Surface   target,
Rect   t,
Surface   src,
Rect   s
[static]
 

Blit surface to surface.

Parameters:
target the destination surface
t the target rectangle
src the source surface
s the source rectangle

Definition at line 242 of file graphics.cpp.

References blitclip(), Rect, and _Surface::w.

void Graphics::blit Surface   target,
int    tx,
int    ty,
Surface   src
[static]
 

Blit surface to surface.

Parameters:
target the destination blit
tx where on the target to blit
ty where on the target to blit
src what is going to be blit to the target

Definition at line 229 of file graphics.cpp.

References blitclip(), _Surface::h, and _Surface::w.

void Graphics::blit Surface   src,
int    dx = 0,
int    dy = 0
 

Blit surface to double buffer.

Blits a surface to the double buffer

  • this function doesn't flip

Parameters:
src a pointer to the surface to blit
dx location on the double buffer to blit
dy location on the double buffer to blit

Definition at line 222 of file graphics.cpp.

References hwSurface.

Referenced by Sprite::draw(), Background::DrawRect(), and Background::SetStatic().

void Graphics::blitclip Surface   dest,
int    drx,
int    dry,
int    drw,
int    drh,
Surface   src,
int    srx,
int    sry,
int    srw,
int    srh
[static, private]
 

Special clipping function for blit.

  • only used to clip bounding rectangles to viewable regions on screen.

Definition at line 163 of file graphics.cpp.

References blitGLtexture(), _Surface::h, Rect, _Surface::surface, Util_BuildRect(), and _Surface::w.

Referenced by blit().

void Graphics::blitGLtexture Surface   src,
int    srx,
int    sry,
int    srw,
int    srh,
int    drx,
int    dry,
int    drw,
int    drh
[static, private]
 

Special clipping function for opengl.

  • only used to draw opengl textures to rects

Definition at line 144 of file graphics.cpp.

References _Surface::h, height, _Surface::tex, _Surface::ts, _Surface::w, and width.

Referenced by blitclip().

int Graphics::color int    r,
int    g,
int    b,
Surface   n = NULL
 

Creates a single RGB value from individual components.

  • color is created based on the given surface if surface is NULL, then the default hwSurface is used.

Parameters:
r the red component
g the green component
b the blue component
n the surface to use for the pixelformat.
Returns:
an integer representing the RGB value specified.

Definition at line 333 of file graphics.cpp.

References hwSurface, and _Surface::surface.

Referenced by fillSurface().

Surface * Graphics::CreateSurfaceFrom Surface   s,
int    nw,
int    nh
[static]
 

Create a surface based on another's pixel.

  • This does not copy the contents of the s surface to the new surface.

Parameters:
s the source surface
nw the new width of the surface
nh the new height of the surface
Returns:
a pointer to the newly allocated surface

Definition at line 300 of file graphics.cpp.

References _Surface::h, Surface, _Surface::surface, and _Surface::w.

Surface * Graphics::CreateSurfaceFrom Surface   s [static]
 

Create a surface based on another's pixelformat.

Parameters:
s the source surface
  • this will copy the contents of s to the new surface created
Returns:
a pointer to the newly made surface

Definition at line 277 of file graphics.cpp.

References _Surface::h, Surface, _Surface::surface, and _Surface::w.

Referenced by Background::SetStatic().

void Graphics::deleteSurface Surface   n
 

Free surface mem.

Parameters:
n the surface to delete from memory

Definition at line 322 of file graphics.cpp.

References _Surface::surface.

Surface * Graphics::displayFormat Surface   surf,
bool    alpha = false
[static]
 

Converts a surface to displayFormat of hwSurface.

  • useful for faster blits

Parameters:
surf the surface to convert
alpha true to keep the alpha channel.
Returns:
a pointer to the newly allocated surface

Definition at line 371 of file graphics.cpp.

References _Surface::h, _Surface::surface, and _Surface::w.

void Graphics::fillSurface Surface   n,
int    color
 

Fills Surface with a specific value.

  • use color() to obtain a value for color

Parameters:
n the surface to fill
color the value to color with

Definition at line 328 of file graphics.cpp.

References color(), and _Surface::surface.

void Graphics::flip  
 

Flips a double buffer to screen.

Really only useful in Windows hardware mode

See also:
update(Rect &)

Definition at line 393 of file graphics.cpp.

References hwSurface, and _Surface::surface.

Referenced by Game::RenderScreen().

Surface * Graphics::freeImage Surface   surf [static]
 

Free an image that was loaded with loadImage.

Parameters:
surf the surface to free
Returns:
NULL

Definition at line 362 of file graphics.cpp.

References _Surface::surface.

Referenced by Sprite::EmptyFrames(), Sprite::RemoveFrame(), Background::~Background(), and SpriteCache::~SpriteCache().

int Graphics::getHeight   const [inline]
 

Get the height of the graphics device.

Returns:
the height of the graphics device

Definition at line 261 of file graphics.h.

References height.

Referenced by Background::Draw(), Game::Game(), Game::GameLoop(), Game::RenderScreen(), RotateZ(), and Background::SetStatic().

Surface* Graphics::getMainSurface   const [inline]
 

Get a pointer to the main surface.

Returns:
a pointer to the main surface used in the Graphics device

Definition at line 100 of file graphics.h.

References hwSurface.

Referenced by Background::Draw(), and Background::DrawRect().

int Graphics::getWidth   const [inline]
 

Get the width of the graphics device.

Returns:
the width of the graphics device

Definition at line 255 of file graphics.h.

References width.

Referenced by Background::Draw(), Game::Game(), Game::GameLoop(), Background::GetScreenHeight(), Game::RenderScreen(), RotateZ(), and Background::SetStatic().

void Graphics::hideMouse bool    f [inline]
 

Hides the mouse.

Parameters:
f set to true to hide the mouse
See also:
isMouseLocked()

Definition at line 94 of file graphics.h.

Referenced by Application::Application().

bool Graphics::isFullscreen   [inline]
 

Returns the status of fullscreen mode.

Returns:
true if currently in fullscreen mode
See also:
toggleFullscreen

Definition at line 67 of file graphics.h.

References hwSurface, and _Surface::surface.

bool Graphics::isHWSurface   [inline]
 

Returns true if the surface is in hardware memory.

Returns:
true if the surface in memory is a true hardware surface

Definition at line 87 of file graphics.h.

References hwSurface, and _Surface::surface.

Referenced by Game::RenderScreen().

bool Graphics::isMouseLocked   [inline]
 

Get the status of the mouse lock.

Returns:
true if the mouse is locked to the window
See also:
hideMouse(bool)

Definition at line 74 of file graphics.h.

Referenced by Game::step().

Surface * Graphics::loadImage string    fname [static]
 

Load an image from disk.

  • uses SDL_image to load

Parameters:
fname the name of the file to load
Returns:
a pointer to the surface loaded.

Definition at line 356 of file graphics.cpp.

References loadImage().

Surface * Graphics::loadImage const char *    fname [static]
 

Load an image from disk.

  • uses SDL_image to load

Parameters:
fname the name of the file to load
Returns:
a pointer to the surface loaded.

Definition at line 343 of file graphics.cpp.

References _Surface::h, _Surface::surface, and _Surface::w.

Referenced by loadImage(), and Background::SetStatic().

bool Graphics::lockMouse bool    lock [static]
 

Lock the Mouse.

Parameters:
lock set to true to lock the mouse to the current window.
Returns:
true if the mouse is locked.

Definition at line 388 of file graphics.cpp.

Referenced by Game::step().

Surface * Graphics::newSurface int    w,
int    h
 

Create a new surface.

Parameters:
w the width of the new surface
h the width of the new surface
  • this creates a surface using the Graphics class' surface to describe the pixel format.
Returns:
a pointer to the new surface

Definition at line 254 of file graphics.cpp.

References _Surface::h, hwSurface, Surface, _Surface::surface, and _Surface::w.

void Graphics::PostOpenGLInit  
 

Postinitialize OpenGL.

This function finalizes opengl initialization.

Definition at line 65 of file graphics.cpp.

References _Surface::h, hwSurface, and _Surface::w.

Referenced by Graphics().

void Graphics::PreOpenGLInit  
 

Preinitialize OpenGL.

This function does the preinitialize opengl calls.

Definition at line 54 of file graphics.cpp.

Referenced by Graphics().

void Graphics::RotateZ float    degrees
 

Rotate about the Z axis.

Rotates the screen about the Z axis, value in degrees

Parameters:
degrees the value in degrees to rotate

Definition at line 450 of file graphics.cpp.

References getHeight(), and getWidth().

Referenced by Game::RenderScreen().

void Graphics::TexturizeSurface Surface   s [static]
 

Texturize a Surface.

Definition at line 412 of file graphics.cpp.

References _Surface::h, _Surface::surface, _Surface::tex, _Surface::ts, _Surface::tx, _Surface::ty, Util_FindBestSurfaceSize(), and _Surface::w.

Referenced by Background::SetStatic().

void Graphics::toggleFullscreen   [inline]
 

Toggle fullscreen mode.

Calls the SDL function switch between fullscreen mode.

  • NOTE: doesn't do anything in Windows.

Definition at line 60 of file graphics.h.

References hwSurface, and _Surface::surface.

Referenced by Game::step().

void Graphics::UntexturizeSurface Surface   s [static]
 

Free the texture of a Surface.

Takes a surface and frees the surface memory from the vram

Definition at line 442 of file graphics.cpp.

References _Surface::tex.

Referenced by SpriteCache::~SpriteCache().

void Graphics::update Rect   r
 

Update a rectangle.

Parameters:
r the rectangle to update
See also:
update(int, int, int, int)

Definition at line 134 of file graphics.cpp.

References Rect, and update().

void Graphics::update int    x,
int    y,
int    w,
int    h
 

Update a rectangle.

Parameters:
x the x location
y the y location
w the width of the rect to update
h the height of the rect to update
See also:
update(Rect &)

Definition at line 92 of file graphics.cpp.

References hwSurface, and update().

Referenced by Game::RenderScreen(), and update().


Member Data Documentation

int Graphics::height [private]
 

the width and height of the hwSurface.

Definition at line 309 of file graphics.h.

Referenced by blitGLtexture(), getHeight(), and Graphics().

Surface* Graphics::hwSurface [private]
 

the surface the graphics device uses

Definition at line 306 of file graphics.h.

Referenced by blit(), color(), flip(), getMainSurface(), Graphics(), isFullscreen(), isHWSurface(), newSurface(), PostOpenGLInit(), toggleFullscreen(), update(), and ~Graphics().

int Graphics::width [private]
 

the width and height of the hwSurface.

Definition at line 309 of file graphics.h.

Referenced by blitGLtexture(), getWidth(), and Graphics().


The documentation for this class was generated from the following files:
Generated on Sun Dec 8 12:02:21 2002 for nnc by doxygen1.3-rc1