From 5155c4bd1fb8e21d537195d2fefb53109af33ddb Mon Sep 17 00:00:00 2001 From: James Turk Date: Mon, 24 Nov 2003 22:20:49 +0000 Subject: [PATCH] blank lines removed --- include/ZE_ZConfigFile.h | 534 ++++++++--------- include/ZE_ZFont.h | 486 +++++++-------- include/ZE_ZImage.h | 912 ++++++++++++++--------------- include/ZE_ZMusic.h | 362 ++++++------ include/ZE_ZRect.h | 536 ++++++++--------- include/ZE_ZSimpleParticleSystem.h | 875 ++++++++++++++------------- include/ZE_ZTimer.h | 113 +--- src/ZE_ZConfigFile.cpp | 756 ++++++++++++------------ src/ZE_ZRect.cpp | 466 +++++++-------- src/ZE_ZTimer.cpp | 164 +++--- 10 files changed, 2546 insertions(+), 2658 deletions(-) diff --git a/include/ZE_ZConfigFile.h b/include/ZE_ZConfigFile.h index a096c52..8489a89 100644 --- a/include/ZE_ZConfigFile.h +++ b/include/ZE_ZConfigFile.h @@ -1,267 +1,267 @@ -/******************************************************************************* - This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk - - Licensed under a BSD-style license. - - The maintainer of this library is James Turk (james@conceptofzero.net) - and the home of this Library is http://www.zengine.sourceforge.net -*******************************************************************************/ - -/*! - \file ZE_ZConfigFile.h - \brief Definition file for ZConfigFile. - - Definition file for ZConfigFile, an INI-style config file format.
- $ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $ - \author James Turk -**/ - - -#ifndef __ze_zconfigfile_h__ -#define __ze_zconfigfile_h__ - -#include "ZE_ZEngine.h" - -namespace ZE -{ - -/*! - \brief ZConfigFile Class for use in ZEngine. - - ZConfigFile class for INI-style configuration files for games or applications. - ZConfigFile can have comments using the semicolon (;) or octothorpe (#) characters. - Sections are delimited by [section-name], and variables must start with a letter - and should be in the format variable = data. -**/ -class ZConfigFile -{ - private: - - //Private Types// - - /*! - \brief ZConfigFile Variable class. - - ZConfigFile class for mapping a variable name to it's value, stored in std::string form (later converted to - bool or int if needed). - **/ - class ZCF_Variable - { - public: - //! Variable name. - std::string var; - //! Value associated with variable. - std::string val; - }; - - /*! - \brief ZConfigFile Section class. - - ZConfigFile class for mapping a section name to a list of variables in that section. - **/ - class ZCF_Section - { - public: - //! Section name. - std::string section; - //! STL list of variables. - std::list varList; - }; - - protected: - //! List of sections of internal type. - std::list rFileLayout; - //! Filename of file currently open. - std::string rFilename; - - /*! - \brief Reformat a std::string in a form more suitable to parsing. - - Removes whitespace from a std::string and makes all characters lowercase. - \param str The std::string to get a clean version of. - \return Cleaned std::string. - **/ - std::string CleanString(std::string str) const; - - /*! - \brief Check if a section exists. - - Find out if a section currently exists. - \param sec Section to check for. - \return bool, true if section exists in file. - **/ - bool Exists(std::string sec) const; - - /*! - \brief Check if a variable exists. - - Find out if a variable currently exists. - \param sec Section to check in. - \param var Variable to check for. - \return bool, true if section exists in file. - **/ - bool Exists(std::string sec, std::string var) const; - - /*! - \brief Internal function to set variables. - - Set variable to value, called internally only. - \param sec Section for variable. - \param var Variable to set. - \param val Value to set variable to. - **/ - void SetVariable(std::string sec, std::string var, std::string val); - - /*! - \brief Internal function to get value of a variable. - - Get value of variable, called internally only. - \param sec Section for variable. - \param var Variable to get. - \param defVal Value to return if variable doesnt exist. - \return Value of variable. - **/ - std::string GetVariable(std::string sec, std::string var, std::string defVal) const; - - public: - - /*! - \brief Default constructor. - - A no-op default constructor. - **/ - ZConfigFile(); - - /*! - \brief Constructor which takes filename. - - Constructor takes filename, and calls process on it. - \param filename File to load as ZConfigFile. - **/ - ZConfigFile(std::string filename); - - /*! - \brief Destructor, flushes file. - - Flushes the file, ensures a flush if the file is left open. - **/ - virtual ~ZConfigFile(); - - /*! - \brief Parse a file. - - Parses the file, reading the contents into the fileLayout map. - \param filename File to parse and attach this ZDataFile to. - **/ - void Process(std::string filename); - - /*! - \brief Get value in floating point format from file. - - Get the current value of a variable in the file, or defVal if not found in file. - \since 0.8.3 - \param section Name of section to seek variable under. - \param var Name of variable to seek value for. - \param defVal Value to return if var does not exist within section. - \return Contents of the variable in floating point format. - **/ - float GetFloat(std::string section, std::string var, float defVal) const; - - /*! - \brief Get value in integer format from file. - - Get the current value of a variable in the file, or defVal if not found in file. - \param section Name of section to seek variable under. - \param var Name of variable to seek value for. - \param defVal Value to return if var does not exist within section. - \return Contents of the variable in integer format. - **/ - int GetInt(std::string section, std::string var, int defVal) const; - - /*! - \brief Get value in boolean format from file. - - Get the current value of a variable in the file, or defVal if not found in file. - (Valid values are "0","1","true" and "false") - \param section Name of section to seek variable under. - \param var Name of variable to seek value for. - \param defVal Value to return if var does not exist within section. - \return Contents of the variable in boolean format. - **/ - bool GetBool(std::string section, std::string var, bool defVal) const; - - /*! - \brief Get value in std::string format from file. - - Get the current value of a variable in the file, or defVal if not found in file. - \param section Name of section to seek variable under. - \param var Name of variable to seek value for. - \param defVal Value to return if var does not exist within section. - \return Contents of the variable in std::string format. - **/ - std::string GetString(std::string section, std::string var, std::string defVal) const; - - /*! - \brief Set value in floating point format in file. - - Set the new value of a variable in the file to val, creating the section and variable - if not already found in file. - \since 0.8.3 - \param section Name of section to edit variable under. - \param var Name of variable to set value for. - \param val Floating point value to set variable to in file. - **/ - void SetFloat(std::string section, std::string var, float val); - - /*! - \brief Set value in integer format in file. - - Set the new value of a variable in the file to val, creating the section and variable - if not already found in file. - \param section Name of section to edit variable under. - \param var Name of variable to set value for. - \param val Integer value to set variable to in file. - **/ - void SetInt(std::string section, std::string var, int val); - - /*! - \brief Set value in boolean format in file. - - Set the new value of a variable in the file to val, creating the section and variable - if not already found in file. - \param section Name of section to edit variable under. - \param var Name of variable to set value for. - \param val Boolean value to set variable to in file. - **/ - void SetBool(std::string section, std::string var, bool val); - - /*! - \brief Set value in std::string format in file. - - Set the new value of a variable in the file to val, creating the section and variable - if not already found in file. - \param section Name of section to edit variable under. - \param var Name of variable to set value for. - \param val String value to set variable to in file. - **/ - void SetString(std::string section, std::string var, std::string val); - - /*! - \brief Write all values to file - - Writes all values and sections to file. - **/ - void Flush(); - - /*! - \brief Close the file. - - Flush the file and clear the filename. - **/ - void Close(); -}; - -} - -#endif //__ze_zconfigfile_h__ +/******************************************************************************* + This file is Part of the ZEngine Library for 2D game development. + Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. + + The maintainer of this library is James Turk (james@conceptofzero.net) + and the home of this Library is http://www.zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZConfigFile.h + \brief Definition file for ZConfigFile. + + Definition file for ZConfigFile, an INI-style config file format.
+ $ id: ZE_ZConfigFile.h,v 1.9 2003/02/10 04:40:16 cozman Exp $ + \author James Turk +**/ + + +#ifndef __ze_zconfigfile_h__ +#define __ze_zconfigfile_h__ + +#include "ZE_ZEngine.h" + +namespace ZE +{ + +/*! + \brief ZConfigFile Class for use in ZEngine. + + ZConfigFile class for INI-style configuration files for games or applications. + ZConfigFile can have comments using the semicolon (;) or octothorpe (#) characters. + Sections are delimited by [section-name], and variables must start with a letter + and should be in the format variable = data. +**/ +class ZConfigFile +{ + private: + + //Private Types// + + /*! + \brief ZConfigFile Variable class. + + ZConfigFile class for mapping a variable name to it's value, stored in std::string form (later converted to + bool or int if needed). + **/ + class ZCF_Variable + { + public: + //! Variable name. + std::string var; + //! Value associated with variable. + std::string val; + }; + + /*! + \brief ZConfigFile Section class. + + ZConfigFile class for mapping a section name to a list of variables in that section. + **/ + class ZCF_Section + { + public: + //! Section name. + std::string section; + //! STL list of variables. + std::list varList; + }; + + protected: + //! List of sections of internal type. + std::list rFileLayout; + //! Filename of file currently open. + std::string rFilename; + + /*! + \brief Reformat a std::string in a form more suitable to parsing. + + Removes whitespace from a std::string and makes all characters lowercase. + \param str The std::string to get a clean version of. + \return Cleaned std::string. + **/ + std::string CleanString(std::string str) const; + + /*! + \brief Check if a section exists. + + Find out if a section currently exists. + \param sec Section to check for. + \return bool, true if section exists in file. + **/ + bool Exists(std::string sec) const; + + /*! + \brief Check if a variable exists. + + Find out if a variable currently exists. + \param sec Section to check in. + \param var Variable to check for. + \return bool, true if section exists in file. + **/ + bool Exists(std::string sec, std::string var) const; + + /*! + \brief Internal function to set variables. + + Set variable to value, called internally only. + \param sec Section for variable. + \param var Variable to set. + \param val Value to set variable to. + **/ + void SetVariable(std::string sec, std::string var, std::string val); + + /*! + \brief Internal function to get value of a variable. + + Get value of variable, called internally only. + \param sec Section for variable. + \param var Variable to get. + \param defVal Value to return if variable doesnt exist. + \return Value of variable. + **/ + std::string GetVariable(std::string sec, std::string var, std::string defVal) const; + + public: + + /*! + \brief Default constructor. + + A no-op default constructor. + **/ + ZConfigFile(); + + /*! + \brief Constructor which takes filename. + + Constructor takes filename, and calls process on it. + \param filename File to load as ZConfigFile. + **/ + ZConfigFile(std::string filename); + + /*! + \brief Destructor, flushes file. + + Flushes the file, ensures a flush if the file is left open. + **/ + virtual ~ZConfigFile(); + + /*! + \brief Parse a file. + + Parses the file, reading the contents into the fileLayout map. + \param filename File to parse and attach this ZDataFile to. + **/ + void Process(std::string filename); + + /*! + \brief Get value in floating point format from file. + + Get the current value of a variable in the file, or defVal if not found in file. + \since 0.8.3 + \param section Name of section to seek variable under. + \param var Name of variable to seek value for. + \param defVal Value to return if var does not exist within section. + \return Contents of the variable in floating point format. + **/ + float GetFloat(std::string section, std::string var, float defVal) const; + + /*! + \brief Get value in integer format from file. + + Get the current value of a variable in the file, or defVal if not found in file. + \param section Name of section to seek variable under. + \param var Name of variable to seek value for. + \param defVal Value to return if var does not exist within section. + \return Contents of the variable in integer format. + **/ + int GetInt(std::string section, std::string var, int defVal) const; + + /*! + \brief Get value in boolean format from file. + + Get the current value of a variable in the file, or defVal if not found in file. + (Valid values are "0","1","true" and "false") + \param section Name of section to seek variable under. + \param var Name of variable to seek value for. + \param defVal Value to return if var does not exist within section. + \return Contents of the variable in boolean format. + **/ + bool GetBool(std::string section, std::string var, bool defVal) const; + + /*! + \brief Get value in std::string format from file. + + Get the current value of a variable in the file, or defVal if not found in file. + \param section Name of section to seek variable under. + \param var Name of variable to seek value for. + \param defVal Value to return if var does not exist within section. + \return Contents of the variable in std::string format. + **/ + std::string GetString(std::string section, std::string var, std::string defVal) const; + + /*! + \brief Set value in floating point format in file. + + Set the new value of a variable in the file to val, creating the section and variable + if not already found in file. + \since 0.8.3 + \param section Name of section to edit variable under. + \param var Name of variable to set value for. + \param val Floating point value to set variable to in file. + **/ + void SetFloat(std::string section, std::string var, float val); + + /*! + \brief Set value in integer format in file. + + Set the new value of a variable in the file to val, creating the section and variable + if not already found in file. + \param section Name of section to edit variable under. + \param var Name of variable to set value for. + \param val Integer value to set variable to in file. + **/ + void SetInt(std::string section, std::string var, int val); + + /*! + \brief Set value in boolean format in file. + + Set the new value of a variable in the file to val, creating the section and variable + if not already found in file. + \param section Name of section to edit variable under. + \param var Name of variable to set value for. + \param val Boolean value to set variable to in file. + **/ + void SetBool(std::string section, std::string var, bool val); + + /*! + \brief Set value in std::string format in file. + + Set the new value of a variable in the file to val, creating the section and variable + if not already found in file. + \param section Name of section to edit variable under. + \param var Name of variable to set value for. + \param val String value to set variable to in file. + **/ + void SetString(std::string section, std::string var, std::string val); + + /*! + \brief Write all values to file + + Writes all values and sections to file. + **/ + void Flush(); + + /*! + \brief Close the file. + + Flush the file and clear the filename. + **/ + void Close(); +}; + +} + +#endif //__ze_zconfigfile_h__ diff --git a/include/ZE_ZFont.h b/include/ZE_ZFont.h index e5c09a7..98383f9 100644 --- a/include/ZE_ZFont.h +++ b/include/ZE_ZFont.h @@ -1,243 +1,243 @@ -/******************************************************************************* - This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk - - Licensed under a BSD-style license. - - The maintainer of this library is James Turk (james@conceptofzero.net) - and the home of this Library is http://www.zengine.sourceforge.net -*******************************************************************************/ - -/*! - \file ZE_ZFont.h - \brief Definition file for ZFont. - - Definition file for ZFont, the basic Font class for ZEngine. -
$Id: ZE_ZFont.h,v 1.15 2003/11/10 02:53:41 cozman Exp $
- \author James Turk -**/ - -#ifndef __ze_zfont_h__ -#define __ze_zfont_h__ - -#include "ZE_ZEngine.h" -#include "ZE_ZImage.h" - -#ifdef USE_SDL_TTF - -namespace ZE -{ - -/*! - \brief ZFont class for basic Font use. - - ZFont font container class, class wraps common features of SDL_TTF. -**/ -class ZFont -{ - protected: - //! Pointer to ZEngine Object - ZEngine* rEngine; - //! Pointer to font data. - TTF_Font *rFont; - //! Filename, for resizing. - std::string rFilename; - //! Zip filename, for resizing when file was from archive. - std::string rZipname; - //! SDL_Color for current text color. - SDL_Color rColor; - //! SDL_Color for background color to be used in shaded draws. - SDL_Color rBGColor; - - public: - - /////////////////////// - //Opening and Closing// - /////////////////////// - - /*! - \brief Default Constructor. - - Default Constructor, does nothing. - **/ - ZFont(); - - /*! - \brief Constructor that opens a font with a certain size. - - Constructor simply calls ZFont::Open() with same parameters. - \param filename Font to open. - \param size Size to use for font. - **/ - ZFont(std::string filename, int size); - - /*! - \brief Destructor, frees memory. - - Destructor calls ZFont::Release(). - **/ - virtual ~ZFont(); - - /*! - \brief Opens a font with a certain size. - - Opens a font given a filename and a point size. - \param filename Font to open. - \param size Size to use for font. - **/ - void Open(std::string filename, int size); - - /*! - \brief Opens a font from within a zip archive. - - Open a font from within a zip archive using zlib and SDL_RWops. - \param zipname Zip file to open image from. - \param filename File to open as new image. - \param size Size to use for font. - **/ - void OpenFromZip(std::string zipname, std::string filename, int size); - - /*! - \brief Release font. - - Release memory held by font. (Called by destructor). - **/ - void Release(); - - //////////////////////// - //Settings and Drawing// - //////////////////////// - - /*! - \brief Draws a std::string in a color to a ZImage. - - Draw to a surface in specified color and associate that surface with a ZImage. - \param text String to write. - \param image ZImage to draw to. - **/ - void DrawText(std::string text, ZImage &image) const; - - /*! - \brief Draws a std::string with a colored background to a ZImage. - - Draw to a surface a std::string with a background of rBGColor and lettering in the normal color and associate that surface with a ZImage. - \param text String to write. - \param image ZImage to draw to. - **/ - void DrawShadedText(std::string text, ZImage &image) const; - - /*! - \brief Set Text rColor. - - Set rColor of Text Output. - \param r Red component of color (0-255). - \param g Green component of color (0-255). - \param b Blue component of color (0-255). - \param a Alpha component of drawn font, including background if present. (0-255) (Optional, defaults to 255.) - **/ - void SetColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a=255); - - /*! - \brief Set Background rColor. - - Set rColor of Background for Shaded Draw. - \param r Red component of color (0-255). - \param g Green component of color (0-255). - \param b Blue component of color (0-255). - **/ - void SetBGColor(Uint8 r, Uint8 g, Uint8 b); - - /*! - \brief Set display format. - - Set display format (bold, italic, underline). - \param bold Decides bold setting of font. - \param italic Decides italic setting of font. - \param underline Decides underline setting of font. - **/ - void SetStyle(bool bold, bool italic, bool underline); - - /*! - \brief Resize Font. - - Release and Reopen font in new size. - \param size New size for font. - **/ - void Resize(int size); - - ///////////// - //Accessors// - ///////////// - - /*! - \brief Check if file is loaded. - - Check if file is loaded and pointer to data is non-NULL. - \return Loaded or Unloaded state of data. - **/ - bool IsLoaded() const; - - /*! - \brief Get Bold Setting. - - Check if font output is currently bold. - \return True or False state of bold. - **/ - bool IsBold() const; - - /*! - \brief Get Italic Setting. - - Check if font output is currently italic. - \return True or False state of italic. - **/ - bool IsItalic() const; - - /*! - \brief Get Underlined Setting. - - Check if font output is currently underline. - \return True or False state of underline. - **/ - bool IsUnderlined() const; - - /*! - \brief Get Height of Font. - - Check font height as reported by SDL_ttf. - \return Height of font. - **/ - int Height() const; - - /*! - \brief Get Line Skip for Font. - - Check font line skip as reported by SDL_ttf. - \return Recommended Line Skip of font. - **/ - int LineSkip() const; - - /*! - \brief Get String Width. - - Get Width of String in Current Font in Pixels. - \param text String to get width of. - \return Width of String in Current font. - **/ - int StringWidth(std::string text) const; - - /*! - \brief Get String Height. - - Get Height of String in Current Font in Pixels. - \param text String to get height of. - \return Height of String in Current font. - **/ - int StringHeight(std::string text) const; -}; - -} - -#endif //USE_SDL_TTF - -#endif //__ze_zfont_h__ +/******************************************************************************* + This file is Part of the ZEngine Library for 2D game development. + Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. + + The maintainer of this library is James Turk (james@conceptofzero.net) + and the home of this Library is http://www.zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZFont.h + \brief Definition file for ZFont. + + Definition file for ZFont, the basic Font class for ZEngine. +
$Id: ZE_ZFont.h,v 1.16 2003/11/24 22:22:07 cozman Exp $
+ \author James Turk +**/ + +#ifndef __ze_zfont_h__ +#define __ze_zfont_h__ + +#include "ZE_ZEngine.h" +#include "ZE_ZImage.h" + +#ifdef USE_SDL_TTF + +namespace ZE +{ + +/*! + \brief ZFont class for basic Font use. + + ZFont font container class, class wraps common features of SDL_TTF. +**/ +class ZFont +{ + protected: + //! Pointer to ZEngine Object + ZEngine* rEngine; + //! Pointer to font data. + TTF_Font *rFont; + //! Filename, for resizing. + std::string rFilename; + //! Zip filename, for resizing when file was from archive. + std::string rZipname; + //! SDL_Color for current text color. + SDL_Color rColor; + //! SDL_Color for background color to be used in shaded draws. + SDL_Color rBGColor; + + public: + + /////////////////////// + //Opening and Closing// + /////////////////////// + + /*! + \brief Default Constructor. + + Default Constructor, does nothing. + **/ + ZFont(); + + /*! + \brief Constructor that opens a font with a certain size. + + Constructor simply calls ZFont::Open() with same parameters. + \param filename Font to open. + \param size Size to use for font. + **/ + ZFont(std::string filename, int size); + + /*! + \brief Destructor, frees memory. + + Destructor calls ZFont::Release(). + **/ + virtual ~ZFont(); + + /*! + \brief Opens a font with a certain size. + + Opens a font given a filename and a point size. + \param filename Font to open. + \param size Size to use for font. + **/ + void Open(std::string filename, int size); + + /*! + \brief Opens a font from within a zip archive. + + Open a font from within a zip archive using zlib and SDL_RWops. + \param zipname Zip file to open image from. + \param filename File to open as new image. + \param size Size to use for font. + **/ + void OpenFromZip(std::string zipname, std::string filename, int size); + + /*! + \brief Release font. + + Release memory held by font. (Called by destructor). + **/ + void Release(); + + //////////////////////// + //Settings and Drawing// + //////////////////////// + + /*! + \brief Draws a std::string in a color to a ZImage. + + Draw to a surface in specified color and associate that surface with a ZImage. + \param text String to write. + \param image ZImage to draw to. + **/ + void DrawText(std::string text, ZImage &image) const; + + /*! + \brief Draws a std::string with a colored background to a ZImage. + + Draw to a surface a std::string with a background of rBGColor and lettering in the normal color and associate that surface with a ZImage. + \param text String to write. + \param image ZImage to draw to. + **/ + void DrawShadedText(std::string text, ZImage &image) const; + + /*! + \brief Set Text rColor. + + Set rColor of Text Output. + \param r Red component of color (0-255). + \param g Green component of color (0-255). + \param b Blue component of color (0-255). + \param a Alpha component of drawn font, including background if present. (0-255) (Optional, defaults to 255.) + **/ + void SetColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a=255); + + /*! + \brief Set Background rColor. + + Set rColor of Background for Shaded Draw. + \param r Red component of color (0-255). + \param g Green component of color (0-255). + \param b Blue component of color (0-255). + **/ + void SetBGColor(Uint8 r, Uint8 g, Uint8 b); + + /*! + \brief Set display format. + + Set display format (bold, italic, underline). + \param bold Decides bold setting of font. + \param italic Decides italic setting of font. + \param underline Decides underline setting of font. + **/ + void SetStyle(bool bold, bool italic, bool underline); + + /*! + \brief Resize Font. + + Release and Reopen font in new size. + \param size New size for font. + **/ + void Resize(int size); + + ///////////// + //Accessors// + ///////////// + + /*! + \brief Check if file is loaded. + + Check if file is loaded and pointer to data is non-NULL. + \return Loaded or Unloaded state of data. + **/ + bool IsLoaded() const; + + /*! + \brief Get Bold Setting. + + Check if font output is currently bold. + \return True or False state of bold. + **/ + bool IsBold() const; + + /*! + \brief Get Italic Setting. + + Check if font output is currently italic. + \return True or False state of italic. + **/ + bool IsItalic() const; + + /*! + \brief Get Underlined Setting. + + Check if font output is currently underline. + \return True or False state of underline. + **/ + bool IsUnderlined() const; + + /*! + \brief Get Height of Font. + + Check font height as reported by SDL_ttf. + \return Height of font. + **/ + int Height() const; + + /*! + \brief Get Line Skip for Font. + + Check font line skip as reported by SDL_ttf. + \return Recommended Line Skip of font. + **/ + int LineSkip() const; + + /*! + \brief Get String Width. + + Get Width of String in Current Font in Pixels. + \param text String to get width of. + \return Width of String in Current font. + **/ + int StringWidth(std::string text) const; + + /*! + \brief Get String Height. + + Get Height of String in Current Font in Pixels. + \param text String to get height of. + \return Height of String in Current font. + **/ + int StringHeight(std::string text) const; +}; + +} + +#endif //USE_SDL_TTF + +#endif //__ze_zfont_h__ diff --git a/include/ZE_ZImage.h b/include/ZE_ZImage.h index 361186e..f141771 100644 --- a/include/ZE_ZImage.h +++ b/include/ZE_ZImage.h @@ -1,456 +1,456 @@ -/******************************************************************************* - This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk - - Licensed under a BSD-style license. - - The maintainer of this library is James Turk (james@conceptofzero.net) - and the home of this Library is http://www.zengine.sourceforge.net -*******************************************************************************/ - -/*! - \file ZE_ZImage.h - \brief Definition file for ZImage. - - Definition file for ZImage, the ZImage class for ZEngine. -
$Id: ZE_ZImage.h,v 1.28 2003/10/13 21:48:13 cozman Exp $
- \author James Turk -**/ - -#ifndef __ze_zimage_h__ -#define __ze_zimage_h__ - -#include "ZE_ZEngine.h" -#include "ZE_ZRect.h" - -namespace ZE -{ - -/*! - \brief ZImage class for basic Image use. - - ZImage image drawing class, class wraps 2d textures under OpenGL or SDL_Surface under SDL. -**/ -class ZImage -{ - protected: - //! Pointer to ZEngine Object - ZEngine* rEngine; - //! Stored texture. - SDL_Surface *rImage; - //! Stored alpha value for drawing texture. - Uint8 rAlpha; -#if (GFX_BACKEND == ZE_OGL) - //! Texture lower X, used internally for flip. - GLfloat rTexMinX; - //! Texture lower Y, used internally for flip - GLfloat rTexMinY; - //! Texture X width ratio, used internally by OpenGL. - GLfloat rTexMaxX; - //! Texture Y width ratio, used internally by OpenGL. - GLfloat rTexMaxY; - //! Texture ID for OpenGL. - unsigned int rTexID; - //! Current draw width of Texture. - GLfloat rWidth; - //! Current draw height of Texture. - GLfloat rHeight; - - /*! - \brief Rounds a number up to the nearest power of two. - - Rounds a number up to the next highest power of two, used for OpenGL textures. (From testgl.c) - Used internally, generally shouldn't be called by users. - \param in Number to round up. - \return num rounded up to closest power of two. - \since 0.8.6 - **/ - int PowerOfTwo(int num); - - /*! - \brief Converts an SDL_Surface to an OpenGL texture ID. - - Given an SDL_Surface returns a texture ID representing the OpenGL - texture assigned to that surface. Also returns texture coordinates - via texcoord parameter. (From SDL_GL_LoadTexture in testgl.c) - Used internally, generally shouldn't be called by users. - \param surface SDL_Surface to assign an OpenGL ID, returns unmodified. - \param texcoord Should be an array of 4 GLfloat, assigned texture coordinates for OpenGL use. - \return OpenGL texture ID for SDL_Surface, 0 if an error occurs. - \since 0.8.6 - **/ - GLuint SurfaceToTexture(SDL_Surface *surface, GLfloat *texcoord); -#endif //GFX_BACKEND == OGL - - public: - - /*! - \brief Default Constructor. - - Default Constructor, initializes variables. - **/ - ZImage(); - - /*! - \brief Copy constructor for ZImage. - - Creates one ZImage using another. - \param rhs A previously created ZImage to copy. - **/ - ZImage(const ZImage &rhs); - - /*! - \brief Constructor to Construct from File. - - Constructor is same as calling ZImage::Open() on passed filename. - \param filename File to open as rImage. - **/ - ZImage(std::string filename); - - /*! - \brief Constructor to Construct from SDL_Surface*. - - Constructor is same as calling ZImage::Attach() on passed SDL_Surface*. - \param surface SDL_Surface* to use as rImage. - **/ - ZImage(SDL_Surface *surface); - - /*! - \brief Constructor to Construct from part of an SDL_Surface*. - - Constructor is same as calling ZImage::OpenFromImage with an SDL_Surface*. - - \param img Image to take new image from. - \param x X Coordinate in source of top left corner. - \param y Y Coordinate in source of top left corner. - \param w Width of new image. - \param h Height of new image. - **/ - ZImage(SDL_Surface *img, Sint16 x, Sint16 y, Sint16 w, Sint16 h); - - /*! - \brief Constructor to Construct from part of another ZImage. - - Constructor is same as calling ZImage::OpenFromImage with a ZImage. - - \param img Image to take new image from. - \param x X Coordinate in source of top left corner. - \param y Y Coordinate in source of top left corner. - \param w Width of new image. - \param h Height of new image. - **/ - ZImage(const ZImage &img, Sint16 x, Sint16 y, Sint16 w, Sint16 h); - - /*! - \brief Destructor, frees memory. - - Destructor calls ZImage::Release(). - **/ - virtual ~ZImage(); - - /////////////////////// - //Opening and Closing// - /////////////////////// - - /*! - \brief Opens a file. - - Open an image file using ZEngine. - \param filename File to open as new image. - **/ - void Open(std::string filename); - - /*! - \brief Opens an image file from within a zip archive. - - Open an image file from within a zip archive using zlib and SDL_RWops. - \param zipname Zip file to open image from. - \param filename File to open as new image. - **/ - void OpenFromZip(std::string zipname, std::string filename); - - /*! - \brief Cuts part of an existing image to create a new image. - - Cut part of an SDL_Surface to create a new Image. - - \param img SDL_Surface* to take new image from. - \param x X Coordinate in source of top left corner. - \param y Y Coordinate in source of top left corner. - \param w Width of new image. - \param h Height of new image. - **/ - void OpenFromImage(SDL_Surface *img, Sint16 x, Sint16 y, Sint16 w, Sint16 h); - - /*! - \brief Cuts part of an existing ZImage to create a new image. - - Cut part of another ZImage to create a new Image. - - \param img ZImage to take new image from. - \param x X Coordinate in source of top left corner. - \param y Y Coordinate in source of top left corner. - \param w Width of new image. - \param h Height of new image. - **/ - void OpenFromImage(const ZImage &img, Sint16 x, Sint16 y, Sint16 w, Sint16 h); - - /*! - \brief Attach an existing surface to class. - - Attach a pointer to instance of ZImage. (NOTE: Should not be used on a surface that is owned elsewhere.) - \param surface SDL_Surface* to use as rImage. - **/ - void Attach(SDL_Surface *surface); - - /*! - \brief Reattach a preloaded texture that has been lost. - - Attach loaded textures which have been lost due to loss of focus, should be called when ZEngine::ImagesNeedReload is true. - **/ - void Reload(); - - /*! - \brief Releases image. - - Frees memory for the image. (Called by destructor). - **/ - void Release(); - - //////////// - //Graphics// - //////////// - - /*! - \brief Set alpha value (translucency) of image. - - Set translucency value 0-255 (0 is transparent, 255 = opaque). - \since 0.8.2 - \param alpha Number 0-255 setting translucency for image. - **/ - void SetAlpha(Uint8 alpha); - - /*! - \brief Set Color Key (transparent color) of image. - - Set color which will not be drawn in image. - \param red Red component of colorkey (0-255). - \param green Green component of colorkey (0-255). - \param blue Blue component of colorkey (0-255). - **/ - void SetColorKey(Uint8 red, Uint8 green, Uint8 blue); - - /*! - \brief Draw Image to Screen. - - Draw Image to screen at specified location. - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - **/ - void Draw(int x, int y) const; - - /*! - \brief Draw Image, clipped within a given rectangle to the screen. - - Image is drawn such that only portions of image which fall within a certain area appear. This clipping rectangle - can be used for areas of the screen which are separated from others such as a splitscreen mode in a game or a - map on a HUD. - \since 0.8.5 - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - \param clipRect Rectangle to clip within. - **/ - void DrawClipped(int x, int y, ZRect clipRect) const; - -#if (GFX_BACKEND == ZE_OGL) - /*! - \brief Draw Image to Screen. - - Draw Image to screen at specified location. - \since 0.8.3 - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - **/ - void Draw(float x, float y) const; - - /*! - \brief Draw Image to screen with shaded/colored vertices. - - Draw Image to screen using OpenGL to shade and color vertices. - \since 0.8.5 - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - \param vc Uint8 vcolor[16] - Vertex colors for the four vertices. - Arranged so that vcolor[0],vcolor[1],vcolor[2],vcolor[3] - R,G,B,A (respectively) - of top left corner (after top-left corner goes around clockwise). - **/ - void Draw(float x, float y, Uint8 vc[]) const; - - /*! - \brief Draw Image rotated to screen. - - Image is rotated about it's own center by specified angle, then drawn to screen. - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - \param angle Angle in degrees to rotate image. - **/ - void DrawRotated(int x, int y, float angle) const; - - /*! - \brief Draw Image rotated to screen. - - Image is rotated about it's own center by specified angle, then drawn to screen. - \since 0.8.3 - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - \param angle Angle in degrees to rotate image. - **/ - void DrawRotated(float x, float y, float angle) const; - - /*! - \brief Draw Image rotated to screen with shaded/colored vertices. - - Image is rotated about it's own center by specified angle, then drawn to screen with shaded or colored vertices. - \since 0.8.5 - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - \param angle Angle in degrees to rotate image. - \param vc Uint8 vcolor[16] - Vertex colors for the four vertices. - Arranged so that vcolor[0],vcolor[1],vcolor[2],vcolor[3] - R,G,B,A (respectively) - of top left corner (after top-left corner goes around clockwise). - **/ - void DrawRotated(float x, float y, float angle, Uint8 vc[]) const; - - /*! - \brief Draw Image, clipped within a given rectangle to the screen. - - Image is drawn such that only portions of image which fall within a certain area appear. This clipping rectangle - can be used for areas of the screen which are separated from others such as a splitscreen mode in a game or a - map on a HUD. - \since 0.8.5 - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - \param clipRect Rectangle to clip within. - **/ - void DrawClipped(float x, float y, ZRect clipRect) const; - - /*! - \brief Draw Image, clipped within a given rectangle to the screen with colored/shaded vertices. - - Image is drawn such that only portions of image which fall within a certain area appear. This clipping rectangle - can be used for areas of the screen which are separated from others such as a splitscreen mode in a game or a - map on a HUD. Image is drawn with colored/shaded vertices. - \since 0.8.5 - \param x X coord to draw Image to. - \param y Y coord to draw Image to. - \param clipRect Rectangle to clip within. - \param vc Uint8 vcolor[16] - Vertex colors for the four vertices. - Arranged so that vcolor[0],vcolor[1],vcolor[2],vcolor[3] - R,G,B,A (respectively) - of top left corner (after top-left corner goes around clockwise). - **/ - void DrawClipped(float x, float y, ZRect clipRect, Uint8 vc[]) const; - - /*! - \brief Flip image over one or both axes. - - Flip image vertical and/or horizontal. - \param horizontal Boolean, true will flip image horizontally. - \param vertical Boolean, true will flip image vertically. - **/ - void Flip(bool horizontal, bool vertical); - - /*! - \brief Stretch the image by a certain X and Y factor. - - Stretch image using a factor to multiply width and height by. - \param xFactor Stretch factor for width. [newWidth = oldWidth * xStretch] - \param yFactor Stretch factor for height. [newHeight = oldHeight * yStretch] - **/ - void Stretch(float xFactor, float yFactor); - - /*! - \brief Resizes an image, stretching to new size. - - Stretch image to new width and height. - \param width New width to stretch image to. - \param height New height to stretch image to. - **/ - void Resize(float width, float height); - - /*! - \brief OpenGL related bind call. - - OpenGL related bind call, only available in case you want to bind image in 3D. - Draw uses this but the average user should never need to call this. - **/ - void Bind() const; -#endif //GFX_BACKEND == OGL - - ///////////// - //Accessors// - ///////////// - - /*! - \brief Check if file is loaded. - - Check if surface is a valid GL texture. (does not detect surface loss) - \return Loaded or Unloaded state of data. - **/ - bool IsLoaded() const; - - /*! - \brief Get SDL_Surface. - Get SDL_Surface pointer to actual image data. - \return SDL_Surface* of rImage. - **/ - SDL_Surface *Surface() const; - -#if (GFX_BACKEND == ZE_OGL) - - /*! - \brief Get Width. - - Get Current Width of Image. - \return Image Width. - **/ - float Width() const; - - /*! - \brief Get Height. - - Get Current Height of Image. - \return Image Height. - **/ - float Height() const; - -#elif (GFX_BACKEND == ZE_SDL) - /*! - \brief Get Width. - - Get Current Width of Image. - \return Image Width. - **/ - int Width() const; - - /*! - \brief Get Height. - - Get Current Height of Image. - \return Image Height. - **/ - int Height() const; -#endif //GFX_BACKEND - - /*! - \brief Get Alpha component. - - Get current alpha value of image. - \since 0.8.2 - \return Image Alpha. - **/ - Uint8 Alpha() const; -}; - -} - -#endif +/******************************************************************************* + This file is Part of the ZEngine Library for 2D game development. + Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. + + The maintainer of this library is James Turk (james@conceptofzero.net) + and the home of this Library is http://www.zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZImage.h + \brief Definition file for ZImage. + + Definition file for ZImage, the ZImage class for ZEngine. +
$Id: ZE_ZImage.h,v 1.29 2003/11/24 22:22:07 cozman Exp $
+ \author James Turk +**/ + +#ifndef __ze_zimage_h__ +#define __ze_zimage_h__ + +#include "ZE_ZEngine.h" +#include "ZE_ZRect.h" + +namespace ZE +{ + +/*! + \brief ZImage class for basic Image use. + + ZImage image drawing class, class wraps 2d textures under OpenGL or SDL_Surface under SDL. +**/ +class ZImage +{ + protected: + //! Pointer to ZEngine Object + ZEngine* rEngine; + //! Stored texture. + SDL_Surface *rImage; + //! Stored alpha value for drawing texture. + Uint8 rAlpha; +#if (GFX_BACKEND == ZE_OGL) + //! Texture lower X, used internally for flip. + GLfloat rTexMinX; + //! Texture lower Y, used internally for flip + GLfloat rTexMinY; + //! Texture X width ratio, used internally by OpenGL. + GLfloat rTexMaxX; + //! Texture Y width ratio, used internally by OpenGL. + GLfloat rTexMaxY; + //! Texture ID for OpenGL. + unsigned int rTexID; + //! Current draw width of Texture. + GLfloat rWidth; + //! Current draw height of Texture. + GLfloat rHeight; + + /*! + \brief Rounds a number up to the nearest power of two. + + Rounds a number up to the next highest power of two, used for OpenGL textures. (From testgl.c) + Used internally, generally shouldn't be called by users. + \param in Number to round up. + \return num rounded up to closest power of two. + \since 0.8.6 + **/ + int PowerOfTwo(int num); + + /*! + \brief Converts an SDL_Surface to an OpenGL texture ID. + + Given an SDL_Surface returns a texture ID representing the OpenGL + texture assigned to that surface. Also returns texture coordinates + via texcoord parameter. (From SDL_GL_LoadTexture in testgl.c) + Used internally, generally shouldn't be called by users. + \param surface SDL_Surface to assign an OpenGL ID, returns unmodified. + \param texcoord Should be an array of 4 GLfloat, assigned texture coordinates for OpenGL use. + \return OpenGL texture ID for SDL_Surface, 0 if an error occurs. + \since 0.8.6 + **/ + GLuint SurfaceToTexture(SDL_Surface *surface, GLfloat *texcoord); +#endif //GFX_BACKEND == OGL + + public: + + /*! + \brief Default Constructor. + + Default Constructor, initializes variables. + **/ + ZImage(); + + /*! + \brief Copy constructor for ZImage. + + Creates one ZImage using another. + \param rhs A previously created ZImage to copy. + **/ + ZImage(const ZImage &rhs); + + /*! + \brief Constructor to Construct from File. + + Constructor is same as calling ZImage::Open() on passed filename. + \param filename File to open as rImage. + **/ + ZImage(std::string filename); + + /*! + \brief Constructor to Construct from SDL_Surface*. + + Constructor is same as calling ZImage::Attach() on passed SDL_Surface*. + \param surface SDL_Surface* to use as rImage. + **/ + ZImage(SDL_Surface *surface); + + /*! + \brief Constructor to Construct from part of an SDL_Surface*. + + Constructor is same as calling ZImage::OpenFromImage with an SDL_Surface*. + + \param img Image to take new image from. + \param x X Coordinate in source of top left corner. + \param y Y Coordinate in source of top left corner. + \param w Width of new image. + \param h Height of new image. + **/ + ZImage(SDL_Surface *img, Sint16 x, Sint16 y, Sint16 w, Sint16 h); + + /*! + \brief Constructor to Construct from part of another ZImage. + + Constructor is same as calling ZImage::OpenFromImage with a ZImage. + + \param img Image to take new image from. + \param x X Coordinate in source of top left corner. + \param y Y Coordinate in source of top left corner. + \param w Width of new image. + \param h Height of new image. + **/ + ZImage(const ZImage &img, Sint16 x, Sint16 y, Sint16 w, Sint16 h); + + /*! + \brief Destructor, frees memory. + + Destructor calls ZImage::Release(). + **/ + virtual ~ZImage(); + + /////////////////////// + //Opening and Closing// + /////////////////////// + + /*! + \brief Opens a file. + + Open an image file using ZEngine. + \param filename File to open as new image. + **/ + void Open(std::string filename); + + /*! + \brief Opens an image file from within a zip archive. + + Open an image file from within a zip archive using zlib and SDL_RWops. + \param zipname Zip file to open image from. + \param filename File to open as new image. + **/ + void OpenFromZip(std::string zipname, std::string filename); + + /*! + \brief Cuts part of an existing image to create a new image. + + Cut part of an SDL_Surface to create a new Image. + + \param img SDL_Surface* to take new image from. + \param x X Coordinate in source of top left corner. + \param y Y Coordinate in source of top left corner. + \param w Width of new image. + \param h Height of new image. + **/ + void OpenFromImage(SDL_Surface *img, Sint16 x, Sint16 y, Sint16 w, Sint16 h); + + /*! + \brief Cuts part of an existing ZImage to create a new image. + + Cut part of another ZImage to create a new Image. + + \param img ZImage to take new image from. + \param x X Coordinate in source of top left corner. + \param y Y Coordinate in source of top left corner. + \param w Width of new image. + \param h Height of new image. + **/ + void OpenFromImage(const ZImage &img, Sint16 x, Sint16 y, Sint16 w, Sint16 h); + + /*! + \brief Attach an existing surface to class. + + Attach a pointer to instance of ZImage. (NOTE: Should not be used on a surface that is owned elsewhere.) + \param surface SDL_Surface* to use as rImage. + **/ + void Attach(SDL_Surface *surface); + + /*! + \brief Reattach a preloaded texture that has been lost. + + Attach loaded textures which have been lost due to loss of focus, should be called when ZEngine::ImagesNeedReload is true. + **/ + void Reload(); + + /*! + \brief Releases image. + + Frees memory for the image. (Called by destructor). + **/ + void Release(); + + //////////// + //Graphics// + //////////// + + /*! + \brief Set alpha value (translucency) of image. + + Set translucency value 0-255 (0 is transparent, 255 = opaque). + \since 0.8.2 + \param alpha Number 0-255 setting translucency for image. + **/ + void SetAlpha(Uint8 alpha); + + /*! + \brief Set Color Key (transparent color) of image. + + Set color which will not be drawn in image. + \param red Red component of colorkey (0-255). + \param green Green component of colorkey (0-255). + \param blue Blue component of colorkey (0-255). + **/ + void SetColorKey(Uint8 red, Uint8 green, Uint8 blue); + + /*! + \brief Draw Image to Screen. + + Draw Image to screen at specified location. + \param x X coord to draw Image to. + \param y Y coord to draw Image to. + **/ + void Draw(int x, int y) const; + + /*! + \brief Draw Image, clipped within a given rectangle to the screen. + + Image is drawn such that only portions of image which fall within a certain area appear. This clipping rectangle + can be used for areas of the screen which are separated from others such as a splitscreen mode in a game or a + map on a HUD. + \since 0.8.5 + \param x X coord to draw Image to. + \param y Y coord to draw Image to. + \param clipRect Rectangle to clip within. + **/ + void DrawClipped(int x, int y, ZRect clipRect) const; + +#if (GFX_BACKEND == ZE_OGL) + /*! + \brief Draw Image to Screen. + + Draw Image to screen at specified location. + \since 0.8.3 + \param x X coord to draw Image to. + \param y Y coord to draw Image to. + **/ + void Draw(float x, float y) const; + + /*! + \brief Draw Image to screen with shaded/colored vertices. + + Draw Image to screen using OpenGL to shade and color vertices. + \since 0.8.5 + \param x X coord to draw Image to. + \param y Y coord to draw Image to. + \param vc Uint8 vcolor[16] - Vertex colors for the four vertices. + Arranged so that vcolor[0],vcolor[1],vcolor[2],vcolor[3] - R,G,B,A (respectively) + of top left corner (after top-left corner goes around clockwise). + **/ + void Draw(float x, float y, Uint8 vc[]) const; + + /*! + \brief Draw Image rotated to screen. + + Image is rotated about it's own center by specified angle, then drawn to screen. + \param x X coord to draw Image to. + \param y Y coord to draw Image to. + \param angle Angle in degrees to rotate image. + **/ + void DrawRotated(int x, int y, float angle) const; + + /*! + \brief Draw Image rotated to screen. + + Image is rotated about it's own center by specified angle, then drawn to screen. + \since 0.8.3 + \param x X coord to draw Image to. + \param y Y coord to draw Image to. + \param angle Angle in degrees to rotate image. + **/ + void DrawRotated(float x, float y, float angle) const; + + /*! + \brief Draw Image rotated to screen with shaded/colored vertices. + + Image is rotated about it's own center by specified angle, then drawn to screen with shaded or colored vertices. + \since 0.8.5 + \param x X coord to draw Image to. + \param y Y coord to draw Image to. + \param angle Angle in degrees to rotate image. + \param vc Uint8 vcolor[16] - Vertex colors for the four vertices. + Arranged so that vcolor[0],vcolor[1],vcolor[2],vcolor[3] - R,G,B,A (respectively) + of top left corner (after top-left corner goes around clockwise). + **/ + void DrawRotated(float x, float y, float angle, Uint8 vc[]) const; + + /*! + \brief Draw Image, clipped within a given rectangle to the screen. + + Image is drawn such that only portions of image which fall within a certain area appear. This clipping rectangle + can be used for areas of the screen which are separated from others such as a splitscreen mode in a game or a + map on a HUD. + \since 0.8.5 + \param x X coord to draw Image to. + \param y Y coord to draw Image to. + \param clipRect Rectangle to clip within. + **/ + void DrawClipped(float x, float y, ZRect clipRect) const; + + /*! + \brief Draw Image, clipped within a given rectangle to the screen with colored/shaded vertices. + + Image is drawn such that only portions of image which fall within a certain area appear. This clipping rectangle + can be used for areas of the screen which are separated from others such as a splitscreen mode in a game or a + map on a HUD. Image is drawn with colored/shaded vertices. + \since 0.8.5 + \param x X coord to draw Image to. + \param y Y coord to draw Image to. + \param clipRect Rectangle to clip within. + \param vc Uint8 vcolor[16] - Vertex colors for the four vertices. + Arranged so that vcolor[0],vcolor[1],vcolor[2],vcolor[3] - R,G,B,A (respectively) + of top left corner (after top-left corner goes around clockwise). + **/ + void DrawClipped(float x, float y, ZRect clipRect, Uint8 vc[]) const; + + /*! + \brief Flip image over one or both axes. + + Flip image vertical and/or horizontal. + \param horizontal Boolean, true will flip image horizontally. + \param vertical Boolean, true will flip image vertically. + **/ + void Flip(bool horizontal, bool vertical); + + /*! + \brief Stretch the image by a certain X and Y factor. + + Stretch image using a factor to multiply width and height by. + \param xFactor Stretch factor for width. [newWidth = oldWidth * xStretch] + \param yFactor Stretch factor for height. [newHeight = oldHeight * yStretch] + **/ + void Stretch(float xFactor, float yFactor); + + /*! + \brief Resizes an image, stretching to new size. + + Stretch image to new width and height. + \param width New width to stretch image to. + \param height New height to stretch image to. + **/ + void Resize(float width, float height); + + /*! + \brief OpenGL related bind call. + + OpenGL related bind call, only available in case you want to bind image in 3D. + Draw uses this but the average user should never need to call this. + **/ + void Bind() const; +#endif //GFX_BACKEND == OGL + + ///////////// + //Accessors// + ///////////// + + /*! + \brief Check if file is loaded. + + Check if surface is a valid GL texture. (does not detect surface loss) + \return Loaded or Unloaded state of data. + **/ + bool IsLoaded() const; + + /*! + \brief Get SDL_Surface. + Get SDL_Surface pointer to actual image data. + \return SDL_Surface* of rImage. + **/ + SDL_Surface *Surface() const; + +#if (GFX_BACKEND == ZE_OGL) + + /*! + \brief Get Width. + + Get Current Width of Image. + \return Image Width. + **/ + float Width() const; + + /*! + \brief Get Height. + + Get Current Height of Image. + \return Image Height. + **/ + float Height() const; + +#elif (GFX_BACKEND == ZE_SDL) + /*! + \brief Get Width. + + Get Current Width of Image. + \return Image Width. + **/ + int Width() const; + + /*! + \brief Get Height. + + Get Current Height of Image. + \return Image Height. + **/ + int Height() const; +#endif //GFX_BACKEND + + /*! + \brief Get Alpha component. + + Get current alpha value of image. + \since 0.8.2 + \return Image Alpha. + **/ + Uint8 Alpha() const; +}; + +} + +#endif diff --git a/include/ZE_ZMusic.h b/include/ZE_ZMusic.h index 4693913..e89b176 100644 --- a/include/ZE_ZMusic.h +++ b/include/ZE_ZMusic.h @@ -1,181 +1,181 @@ -/******************************************************************************* - This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk - - Licensed under a BSD-style license. - - The maintainer of this library is James Turk (james@conceptofzero.net) - and the home of this Library is http://www.zengine.sourceforge.net -*******************************************************************************/ - -/*! - \file ZE_ZMusic.h - \brief Definition file for ZMusic. - - Definition file for ZMusic, the Music file wrapper for ZEngine. -
$Id: ZE_ZMusic.h,v 1.9 2003/06/11 00:15:26 cozman Exp $
- \author James Turk -**/ - -#ifndef __ze_zmusic_h__ -#define __ze_zmusic_h__ - -#include "ZE_ZEngine.h" - -#ifdef USE_SDL_MIXER - -namespace ZE -{ - -/*! - \brief ZMusic class for playing full length music (eg. ogg or wav). - - ZMusic music class, class wraps common features for SDL_Mixer's Mix_Music. Inherited from ZObject. -**/ -class ZMusic -{ - protected: - //! Pointer to ZEngine Object - ZEngine* rEngine; - //! Pointer to music data. - Mix_Music *rMusic; - - public: - //! Static Variable For Infinite loop of sound. (Defined as -1) - static const int LoopInfinite; - - /////////////////////// - //Opening and Closing// - /////////////////////// - - /*! - \brief Default Constructor. - - Default Constructor, does nothing. - **/ - ZMusic(); - - /*! - \brief Constructor that opens a music file. - - Constructor simply calls ZMusic::Open() with same filename. (WAV,MOD,MID,OGG) - \param filename Music to open. - **/ - ZMusic(std::string filename); - - /*! - \brief Destructor, frees memory. - - Destructor calls ZMusic::Release(). - **/ - virtual ~ZMusic(); - - /*! - \brief Opens a music file. - - Open a music file to be used. - \param filename Music to open. - **/ - void Open(std::string filename); - - /*! - \brief Release music. - - Release memory held by music data. - **/ - void Release(); - - ///////////////// - //Play Controls// - ///////////////// - - /*! - \brief Play currently loaded music. - - Play music currently loaded in ZMusic, looping loopNum times. (use ZMusic::LoopInfinite to loop forever.) - If fade is not zero (which it defaults to) music will fade in over specified number of milliseconds. - \param loopNum Number of times to loop song, defaults to zero. - \param fadeTime Milliseconds to fade to full volume, defaults to zero for no fade. - **/ - void Play(int loopNum=0, int fadeTime=0) const; - - /*! - \brief Pause music. - - Pause currently playing music. - **/ - void Pause() const; - - /*! - \brief Unpause music. - - Unpause currently paused music. - **/ - void Unpause() const; - - /*! - \brief Rewind music. - - Rewind music to beginning. - **/ - void Rewind() const; - - /*! - \brief Stop music. - - Stop currently playing music, if fadeTime is not zero, fade out over specified time. - \param fadeTime Milliseconds to fade out over, defaults to zero for immediate stop. - **/ - void Stop(int fadeTime=0) const; - - /*! - \brief Change Volume. - - Change volume of currently playing music. - \param volume Volume to change to, can be in a range from 0 to 128 - **/ - void SetVolume(int volume); - - ///////////// - //Accessors// - ///////////// - - /*! - \brief Check if file is loaded. - - Check if file is loaded and pointer to data is non-NULL. - \return Loaded or Unloaded state of data. - **/ - bool IsLoaded() const; - - /*! - \brief Check if music is Playing. - - Check if music is playing, specifically if it is not stopped. (Paused state should be checked for by IsPaused) - \return Playing / Not Playing State of Music. - **/ - bool IsPlaying() const; - - /*! - \brief Check if music is Paused. - - Check if music is "playing" but currently paused. - \return Paused / Not Paused State of Music. - **/ - bool IsPaused() const; - - /*! - \brief Find Current Volume of Music. - - Get current volume of music represented as a value from 0-128. - \return Volume of music, 0-128. - **/ - int Volume() const; -}; - - -} - -#endif //USE_SDL_MIXER - -#endif //__ze_zmusic_h__ +/******************************************************************************* + This file is Part of the ZEngine Library for 2D game development. + Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. + + The maintainer of this library is James Turk (james@conceptofzero.net) + and the home of this Library is http://www.zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZMusic.h + \brief Definition file for ZMusic. + + Definition file for ZMusic, the Music file wrapper for ZEngine. +
$Id: ZE_ZMusic.h,v 1.10 2003/11/24 22:22:07 cozman Exp $
+ \author James Turk +**/ + +#ifndef __ze_zmusic_h__ +#define __ze_zmusic_h__ + +#include "ZE_ZEngine.h" + +#ifdef USE_SDL_MIXER + +namespace ZE +{ + +/*! + \brief ZMusic class for playing full length music (eg. ogg or wav). + + ZMusic music class, class wraps common features for SDL_Mixer's Mix_Music. Inherited from ZObject. +**/ +class ZMusic +{ + protected: + //! Pointer to ZEngine Object + ZEngine* rEngine; + //! Pointer to music data. + Mix_Music *rMusic; + + public: + //! Static Variable For Infinite loop of sound. (Defined as -1) + static const int LoopInfinite; + + /////////////////////// + //Opening and Closing// + /////////////////////// + + /*! + \brief Default Constructor. + + Default Constructor, does nothing. + **/ + ZMusic(); + + /*! + \brief Constructor that opens a music file. + + Constructor simply calls ZMusic::Open() with same filename. (WAV,MOD,MID,OGG) + \param filename Music to open. + **/ + ZMusic(std::string filename); + + /*! + \brief Destructor, frees memory. + + Destructor calls ZMusic::Release(). + **/ + virtual ~ZMusic(); + + /*! + \brief Opens a music file. + + Open a music file to be used. + \param filename Music to open. + **/ + void Open(std::string filename); + + /*! + \brief Release music. + + Release memory held by music data. + **/ + void Release(); + + ///////////////// + //Play Controls// + ///////////////// + + /*! + \brief Play currently loaded music. + + Play music currently loaded in ZMusic, looping loopNum times. (use ZMusic::LoopInfinite to loop forever.) + If fade is not zero (which it defaults to) music will fade in over specified number of milliseconds. + \param loopNum Number of times to loop song, defaults to zero. + \param fadeTime Milliseconds to fade to full volume, defaults to zero for no fade. + **/ + void Play(int loopNum=0, int fadeTime=0) const; + + /*! + \brief Pause music. + + Pause currently playing music. + **/ + void Pause() const; + + /*! + \brief Unpause music. + + Unpause currently paused music. + **/ + void Unpause() const; + + /*! + \brief Rewind music. + + Rewind music to beginning. + **/ + void Rewind() const; + + /*! + \brief Stop music. + + Stop currently playing music, if fadeTime is not zero, fade out over specified time. + \param fadeTime Milliseconds to fade out over, defaults to zero for immediate stop. + **/ + void Stop(int fadeTime=0) const; + + /*! + \brief Change Volume. + + Change volume of currently playing music. + \param volume Volume to change to, can be in a range from 0 to 128 + **/ + void SetVolume(int volume); + + ///////////// + //Accessors// + ///////////// + + /*! + \brief Check if file is loaded. + + Check if file is loaded and pointer to data is non-NULL. + \return Loaded or Unloaded state of data. + **/ + bool IsLoaded() const; + + /*! + \brief Check if music is Playing. + + Check if music is playing, specifically if it is not stopped. (Paused state should be checked for by IsPaused) + \return Playing / Not Playing State of Music. + **/ + bool IsPlaying() const; + + /*! + \brief Check if music is Paused. + + Check if music is "playing" but currently paused. + \return Paused / Not Paused State of Music. + **/ + bool IsPaused() const; + + /*! + \brief Find Current Volume of Music. + + Get current volume of music represented as a value from 0-128. + \return Volume of music, 0-128. + **/ + int Volume() const; +}; + + +} + +#endif //USE_SDL_MIXER + +#endif //__ze_zmusic_h__ diff --git a/include/ZE_ZRect.h b/include/ZE_ZRect.h index f6873f9..eca16db 100644 --- a/include/ZE_ZRect.h +++ b/include/ZE_ZRect.h @@ -1,268 +1,268 @@ -/******************************************************************************* - This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk - - Licensed under a BSD-style license. - - The maintainer of this library is James Turk (james@conceptofzero.net) - and the home of this Library is http://www.zengine.sourceforge.net -*******************************************************************************/ - -/*! - \file ZE_ZRect.h - \brief Definition file for ZRect. - - Definition file for ZRect, the Rectangle class for ZEngine. -
$Id: ZE_ZRect.h,v 1.13 2003/10/03 22:03:29 cozman Exp $
- \author James Turk -**/ - -#ifndef __ze_zrect_h__ -#define __ze_zrect_h__ - -#include "ZE_ZEngine.h" - -namespace ZE -{ - -/*! - \brief ZEngine class for simplified rectangle use. - - ZRect Rectangle class, used to define a rectangular area or perform operations on the defined area. -**/ -class ZRect -{ - protected: - //! Pointer to ZEngine Object - ZEngine* rEngine; - //! X Position of top left corner of rectangle. - float rX; - //! Y Position of top left corner of rectangle. - float rY; - //! Width of Rectangle. - float rWidth; - //! Height of Rectangle. - float rHeight; - - public: - - /*! - \brief Default constructor for ZRect. - - Default constructor, initializes all values to zero. - **/ - ZRect(); - - /*! - \brief Constructor for ZRect that takes inital values. - - Constructor for ZRect that takes inital values for all four members. - \param x Value for x position. - \param y Value for y position. - \param width Value for width. - \param height Value for height. - **/ - ZRect(float x, float y, float width, float height); - - /*! - \brief Constructor for ZRect that uses an SDL_Rect. - - Constructor for ZRect that initializes from an SDL_Rect. - \param rect SDL_Rect to intialize from. - **/ - ZRect(const SDL_Rect &rect); - - /*! - \brief Copy constructor for ZRect. - - Takes a ZRect and constructs a new identical rectangle. - \param rhs Rectangle to construct from. - **/ - ZRect(const ZRect &rhs); - - /*! - \brief Virtual Destructor. - - Virtual destructor making future inheritance safe. - **/ - virtual ~ZRect(); - - /*! - \brief Overload for = operator with ZRect. - - Copies all values from one ZRect into another. - \param rhs Rectangle to copy values from. - \return New value of the ZRect. - **/ - const ZRect& operator=(const ZRect &rhs); - - /*! - \brief Overload for < operator with ZRect, based upon location then size. - - Rectangles are sorted by y value, followed by x value, if they start at the same place, - the smaller of the two is deemed less than the other. - \param rhs Rectangle to compare. - \return True if this rectangle is smaller than the rhs rectangle, false otherwise. - **/ - bool operator<(const ZRect &rhs) const; - - /*! - \brief Draw rectangle. (filled) - - Draw the ZRect, this function is mainly provided for testing purposes. - \param red Red component of color (0-255). - \param green Green component of color (0-255). - \param blue Blue component of color (0-255). - \param alpha Alpha component of color (0-255). - **/ - void Draw(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha=255) const; - - /*! - \brief Changes the location of the rectangle. - - Changes the current x,y position of the rectangle. - \param x New x position for rectangle. - \param y New y position for rectangle. - **/ - void Move(float x, float y); - - /*! - \brief Changes the location of the rectangle based upon the current location. - - Changes the current x,y position of the rectangle relative to the current location. - \param xMove Offset for new x position from current. - \param yMove Offset for new y position from current. - **/ - void MoveRel(float xMove, float yMove); - - /*! - \brief Resize rectangle. - - Changes the current width and height of the rectangle. - \param width New width for rectangle. - \param height New height for rectangle. - **/ - void Resize(float width, float height); - - /*! - \brief Grows or shrinks current rectangle. - - Changes the current width and height of the rectangle based upon current values. - \param widthChange Amount to add or subtract from width. - \param heightChange Amount to add or subtract from height. - **/ - void ResizeRel(float widthChange, float heightChange); - - /*! - \brief Check if one ZRect intersects another. - - Checks for overlap and returns boolean value based on if overlap exists. - \param rect Rectangle to check for intersection with. - \return True if intersection occured, false otherwise. - **/ - bool Intersects(const ZRect &rect) const; - - /*! - \brief Check if a rectangle contains a given point. - - Checks point against boundaries of rectangle and returns result. - \param x X value of point to check. - \param y Y value of poitn to check. - \return Boolean variable, true if point is inside rectangle, false otherwise. - **/ - bool Contains(float x, float y) const; - - /*! - \brief Check if a rectangle contains a given point. - - Checks point against boundaries of rectangle and returns result. - \param rect Rectangle to check for point. - \return Boolean variable, true if point is inside rectangle, false otherwise. - **/ - bool Contains(const ZRect &rect) const; - - /*! - \brief Finds intersection of two rectangles. - - Checks for intersection, and returns rectangle where the two rectangles intersect. - \param rect Rectangle to check intersection with. - \return ZRect describing intersection area. - **/ - ZRect Intersection(const ZRect &rect) const; - - /*! - \brief Returns an SDL_Rect representing the rectangle. - - Makes a SDL_Rect representing the rectangle, for use where functions require an SDL_Rect. - \return SDL_Rect representing the ZRect. - **/ - SDL_Rect SDLrect() const; - - /*! - \brief Returns X Location. - - Access private X location member. - \return Value of mX. - **/ - float X() const; - - /*! - \brief Returns Y Location. - - Access private Y location member. - \return Value of mY. - **/ - float Y() const; - - /*! - \brief Return position of left side. - - Find X position of left side of rectangle. - \return X position of left side. - **/ - float Left() const; - - /*! - \brief Return position of right side. - - Find X position of right side of rectangle. - \return X position of right side. - **/ - float Right() const; - - /*! - \brief Return position of top side. - - Find Y position of top side of rectangle. - \return Y position of top side. - **/ - float Top() const; - - /*! - \brief Return position of bottom side. - - Find Y position of left side of rectangle. - \return Y position of bottom side. - **/ - float Bottom() const; - - /*! - \brief Returns Width. - - Access private width member. - \return Value of mWidth. - **/ - float Width() const; - - /*! - \brief Returns Height. - - Access private height member. - \return Value of mHeight. - **/ - float Height() const; -}; - -} //namespace ZE - -#endif //__ze_zrect_h__ +/******************************************************************************* + This file is Part of the ZEngine Library for 2D game development. + Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. + + The maintainer of this library is James Turk (james@conceptofzero.net) + and the home of this Library is http://www.zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZRect.h + \brief Definition file for ZRect. + + Definition file for ZRect, the Rectangle class for ZEngine. +
$Id: ZE_ZRect.h,v 1.14 2003/11/24 22:22:07 cozman Exp $
+ \author James Turk +**/ + +#ifndef __ze_zrect_h__ +#define __ze_zrect_h__ + +#include "ZE_ZEngine.h" + +namespace ZE +{ + +/*! + \brief ZEngine class for simplified rectangle use. + + ZRect Rectangle class, used to define a rectangular area or perform operations on the defined area. +**/ +class ZRect +{ + protected: + //! Pointer to ZEngine Object + ZEngine* rEngine; + //! X Position of top left corner of rectangle. + float rX; + //! Y Position of top left corner of rectangle. + float rY; + //! Width of Rectangle. + float rWidth; + //! Height of Rectangle. + float rHeight; + + public: + + /*! + \brief Default constructor for ZRect. + + Default constructor, initializes all values to zero. + **/ + ZRect(); + + /*! + \brief Constructor for ZRect that takes inital values. + + Constructor for ZRect that takes inital values for all four members. + \param x Value for x position. + \param y Value for y position. + \param width Value for width. + \param height Value for height. + **/ + ZRect(float x, float y, float width, float height); + + /*! + \brief Constructor for ZRect that uses an SDL_Rect. + + Constructor for ZRect that initializes from an SDL_Rect. + \param rect SDL_Rect to intialize from. + **/ + ZRect(const SDL_Rect &rect); + + /*! + \brief Copy constructor for ZRect. + + Takes a ZRect and constructs a new identical rectangle. + \param rhs Rectangle to construct from. + **/ + ZRect(const ZRect &rhs); + + /*! + \brief Virtual Destructor. + + Virtual destructor making future inheritance safe. + **/ + virtual ~ZRect(); + + /*! + \brief Overload for = operator with ZRect. + + Copies all values from one ZRect into another. + \param rhs Rectangle to copy values from. + \return New value of the ZRect. + **/ + const ZRect& operator=(const ZRect &rhs); + + /*! + \brief Overload for < operator with ZRect, based upon location then size. + + Rectangles are sorted by y value, followed by x value, if they start at the same place, + the smaller of the two is deemed less than the other. + \param rhs Rectangle to compare. + \return True if this rectangle is smaller than the rhs rectangle, false otherwise. + **/ + bool operator<(const ZRect &rhs) const; + + /*! + \brief Draw rectangle. (filled) + + Draw the ZRect, this function is mainly provided for testing purposes. + \param red Red component of color (0-255). + \param green Green component of color (0-255). + \param blue Blue component of color (0-255). + \param alpha Alpha component of color (0-255). + **/ + void Draw(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha=255) const; + + /*! + \brief Changes the location of the rectangle. + + Changes the current x,y position of the rectangle. + \param x New x position for rectangle. + \param y New y position for rectangle. + **/ + void Move(float x, float y); + + /*! + \brief Changes the location of the rectangle based upon the current location. + + Changes the current x,y position of the rectangle relative to the current location. + \param xMove Offset for new x position from current. + \param yMove Offset for new y position from current. + **/ + void MoveRel(float xMove, float yMove); + + /*! + \brief Resize rectangle. + + Changes the current width and height of the rectangle. + \param width New width for rectangle. + \param height New height for rectangle. + **/ + void Resize(float width, float height); + + /*! + \brief Grows or shrinks current rectangle. + + Changes the current width and height of the rectangle based upon current values. + \param widthChange Amount to add or subtract from width. + \param heightChange Amount to add or subtract from height. + **/ + void ResizeRel(float widthChange, float heightChange); + + /*! + \brief Check if one ZRect intersects another. + + Checks for overlap and returns boolean value based on if overlap exists. + \param rect Rectangle to check for intersection with. + \return True if intersection occured, false otherwise. + **/ + bool Intersects(const ZRect &rect) const; + + /*! + \brief Check if a rectangle contains a given point. + + Checks point against boundaries of rectangle and returns result. + \param x X value of point to check. + \param y Y value of poitn to check. + \return Boolean variable, true if point is inside rectangle, false otherwise. + **/ + bool Contains(float x, float y) const; + + /*! + \brief Check if a rectangle contains a given point. + + Checks point against boundaries of rectangle and returns result. + \param rect Rectangle to check for point. + \return Boolean variable, true if point is inside rectangle, false otherwise. + **/ + bool Contains(const ZRect &rect) const; + + /*! + \brief Finds intersection of two rectangles. + + Checks for intersection, and returns rectangle where the two rectangles intersect. + \param rect Rectangle to check intersection with. + \return ZRect describing intersection area. + **/ + ZRect Intersection(const ZRect &rect) const; + + /*! + \brief Returns an SDL_Rect representing the rectangle. + + Makes a SDL_Rect representing the rectangle, for use where functions require an SDL_Rect. + \return SDL_Rect representing the ZRect. + **/ + SDL_Rect SDLrect() const; + + /*! + \brief Returns X Location. + + Access private X location member. + \return Value of mX. + **/ + float X() const; + + /*! + \brief Returns Y Location. + + Access private Y location member. + \return Value of mY. + **/ + float Y() const; + + /*! + \brief Return position of left side. + + Find X position of left side of rectangle. + \return X position of left side. + **/ + float Left() const; + + /*! + \brief Return position of right side. + + Find X position of right side of rectangle. + \return X position of right side. + **/ + float Right() const; + + /*! + \brief Return position of top side. + + Find Y position of top side of rectangle. + \return Y position of top side. + **/ + float Top() const; + + /*! + \brief Return position of bottom side. + + Find Y position of left side of rectangle. + \return Y position of bottom side. + **/ + float Bottom() const; + + /*! + \brief Returns Width. + + Access private width member. + \return Value of mWidth. + **/ + float Width() const; + + /*! + \brief Returns Height. + + Access private height member. + \return Value of mHeight. + **/ + float Height() const; +}; + +} //namespace ZE + +#endif //__ze_zrect_h__ diff --git a/include/ZE_ZSimpleParticleSystem.h b/include/ZE_ZSimpleParticleSystem.h index 3656e9a..397885e 100755 --- a/include/ZE_ZSimpleParticleSystem.h +++ b/include/ZE_ZSimpleParticleSystem.h @@ -1,438 +1,437 @@ -/******************************************************************************* - This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk - - Licensed under a BSD-style license. - - The maintainer of this library is James Turk (james@conceptofzero.net) - and the home of this Library is http://www.zengine.sourceforge.net -*******************************************************************************/ - -/*! - \file ZE_ZSimpleParticleSystem.h - \brief Definition and implementation file for a simple particle system for ZEngine. - - Definition and implementation file for ZEngine simple particle system, ZSimpleParticleSystem based on ZBaseParticleSystem. - Due to problems with template classes the template implementation needs to be in the same file as the declaration. -
$Id: ZE_ZSimpleParticleSystem.h,v 1.4 2003/08/02 01:18:45 cozman Exp $
- \author James Turk -**/ - -#ifndef __ze_zsimpleparticlesystem_h__ -#define __ze_zsimpleparticlesystem_h__ - -#include "ZEngine.h" - -namespace ZE -{ - -/*! - \brief Simple particle class for ZSimpleParticleSystem. - - General purpose particle, contains needed variables for a functional particle system. -**/ -class ZSimpleParticle : public ZBaseParticle -{ - public: - //! Previous X position of particle. - float xPrev; - //! Previous Y position of particle. - float yPrev; - //! X Velocity of particle per second. - float xVel; - //! Y Velocity of particle per second. - float yVel; - //! Energy change per second. - float energyDelta; - //! Size of particle. - float size; - //! Size change per second. - float sizeDelta; - //! Red component of particle color. - Uint8 r; - //! Green component of particle color. - Uint8 g; - //! Blue component of particle color. - Uint8 b; - //! Alpha component of particle color. - Uint8 a; -}; - -/*! - \brief Possible draw styles for ZSimpleParticleSystem. - - Possible draw styles for ZSimpleParticleSystem, each specifies different code with which the particles will be drawn. -**/ -enum ParticleDrawStyle -{ - DS_POINT, /*!< Draw particles as simple points. */ - DS_LINE, /*!< Draw particles as lines between the current position and the last. */ - DS_IMAGE /*!< Draw particles as an image. */ -}; - -/*! - \brief ZSimpleParticleSystem class, a simple particle system provided originally as an example. - - ZSimpleParticleSystem class, example of implementation of a particle system on top of ZBaseParticleSystem base, - designed for flexibility and ease of use over speed. More specific, therefore even less optimized for specific - circumstances. Should be concidered usable but not optimal. (Although it is a great source of code for your - own implementations.) -**/ -template -class ZSimpleParticleSystem : public ZBaseParticleSystem -{ - protected: - //! Draw style, one of the three enumerated values specifying how particles will be drawn. - ParticleDrawStyle rStyle; - //! Image to draw (only used if rStyle is DS_IMAGE). - ZImage rImage; - //! Minimum X value for starting position. - float rMinX; - //! Maximum X value for starting position. - float rMaxX; - //! Minimum Y value for starting position. - float rMinY; - //! Maximum Y value for starting position. - float rMaxY; - //! Minimum X velocity, particle moves it's velocity every second. - float rMinXVel; - //! Maximum X velocity, particle moves it's velocity every second. - float rMaxXVel; - //! Minimum Y velocity, particle moves it's velocity every second. - float rMinYVel; - //! Maximum Y velocity, particle moves it's velocity every second. - float rMaxYVel; - //! Minimum starting energy. (Remember particles with energy values <= 0 are removed.) - float rMinEnergy; - //! Maximum starting energy. - float rMaxEnergy; - //! Minimum energy change per second. - float rMinEnergyDelta; - //! Maximum energy change per second. - float rMaxEnergyDelta; - //! Minimum starting size. - float rMinSize; - //! Maximum starting size. - float rMaxSize; - //! Minimum size change per second. - float rMinSizeDelta; - //! Maximum size change per second. - float rMaxSizeDelta; - //! Minimum red component of color, 0-255. - Uint8 rMinRed; - //! Maximum red component of color, 0-255. - Uint8 rMaxRed; - //! Minimum green component of color, 0-255. - Uint8 rMinGreen; - //! Maximum green component of color, 0-255. - Uint8 rMaxGreen; - //! Minimum blue component of color, 0-255. - Uint8 rMinBlue; - //! Maximum blue component of color, 0-255. - Uint8 rMaxBlue; - //! Minimum alpha of particle, 0-255. - Uint8 rMinAlpha; - //! Maximum alpha of particle, 0-255. - Uint8 rMaxAlpha; - - /*! - \brief Function which creates a new particle. - - Implementation of pure virtual NewParticle from ZBaseParticleSystem, creates a new particle with - it's members set to values between their min and max value as set by the system. - **/ - virtual particleType NewParticle(); - - /*! - \brief Updates a given particle given it's index and the elapsedTime. - - Implementation of pure virtual UpdateParticle from ZBaseParticleSystem, updates a given particle - relative to the elapsed time. - \param index Index of particle in rParticles array to update. - \param elapsedTime Decimal portion of a second since last call. - **/ - virtual void UpdateParticle(int index, float elapsedTime); - - public: - /*! - \brief Draws all particles. - - Implementation of pure virtual Render from ZBaseParticleSystem, draws all particles in specified - ParticleDrawStyle. - **/ - virtual void Render(); - - /*! - \brief Reload image. - - Reload image if mode is DS_IMAGE, usage is same as ZImage::Reload. - **/ - void ReloadImage(); - - /*! - \brief Sets ParticleDrawStyle for this system. - - Sets the method of drawing particles, point, line, or image particles. - \param style ParticleDrawStyle for this particle system to use. - **/ - void SetDrawStyle(ParticleDrawStyle style); - - /*! - \brief Sets image for particle system. - - Sets image for particle system to use, assuming the drawing style is DS_IMAGE. - \brief filename Filename of image to load for the system. - **/ - void SetImage(std::string filename); - - /*! - \brief Sets the range of initial positions. - - Sets the range of initial positions for a new particle. - \param minX Minimum X coordinate for new particles. - \param minY Minimum Y coordinate for new particles. - \param maxX Maximum X coordinate for new particles. - \param maxY Maximum Y coordinate for new particles. - **/ - void SetPosRange(float minX, float minY, float maxX, float maxY); - - /*! - \brief Sets range of velocities for particles. - - Sets range from which a new particle obtains it's random velocity, - \param minXVel Minimum X velocity of a particle. - \param minYVel Minimum Y velocity of a particle. - \param maxXVel Maximum X velocity of a particle. - \param maxYVel Maximum Y velocity of a particle. - **/ - void SetVelocityRange(float minXVel, float minYVel, float maxXVel, float maxYVel); - - /*! - \brief Sets range of initial energy and energyDelta. - - Sets the possible ranges for a particles starting energy and it's energyDelta. Particles with - energy less than or equal to 0 are deleted by ZBaseParticleSystem::Update. - \param minEnergy Minimum initial energy. - \param maxEnergy Maximum initial energy. - \param minEnergyDelta Minimum energy delta. - \param maxEnergyDelta Maximum energy delta. - **/ - void SetEnergyRange(float minEnergy, float maxEnergy, float minEnergyDelta=0, float maxEnergyDelta=0); - - /*! - \brief Sets range of initial size and sizeDelta. - - Sets the possible ranges for a particles starting size and it's sizeDelta. - \param minSize Minimum initial size. - \param maxSize Maximum initial size. - \param minSizeDelta Minimum size delta. - \param maxSizeDelta Maximum size delta. - **/ - void SetSizeRange(float minSize, float maxSize, float minSizeDelta=0, float maxSizeDelta=0); - - /*! - \brief Set range of color for a new particle. - - Sets range of possible colors, by component, for a new particle. - \param minRed Minimum value of red component (0-255). - \param maxRed Minimum value of red component (0-255). - \param minGreen Minimum value of green component (0-255). - \param maxGreen Minimum value of green component (0-255). - \param minBlue Minimum value of blue component (0-255). - \param maxBlue Minimum value of blue component (0-255). - \param minAlpha Minimum value of alpha value (0-255). - \param maxAlpha Minimum value of alpha value (0-255). - **/ - void SetColorRange(Uint8 minRed, Uint8 maxRed, Uint8 minGreen, Uint8 maxGreen, - Uint8 minBlue, Uint8 maxBlue, Uint8 minAlpha, Uint8 maxAlpha); -}; - -//implementation// - -template -particleType ZSimpleParticleSystem::NewParticle() -{ - particleType p; - - p.xPrev = p.xPos = rEngine->Rand(rMinX,rMaxX); - p.yPrev = p.yPos = rEngine->Rand(rMinY,rMaxY); - p.xVel = rEngine->Rand(rMinXVel,rMaxXVel); - p.yVel = rEngine->Rand(rMinYVel,rMaxYVel); - p.energy = rEngine->Rand(rMinEnergy,rMaxEnergy); - p.energyDelta = rEngine->Rand(rMinEnergyDelta,rMaxEnergyDelta); - p.size = rEngine->Rand(rMinSize,rMaxSize); - p.sizeDelta = rEngine->Rand(rMinSizeDelta,rMaxSizeDelta); - p.r = rEngine->Rand(rMinRed,rMaxRed); - p.g = rEngine->Rand(rMinGreen,rMaxGreen); - p.b = rEngine->Rand(rMinBlue,rMaxBlue); - p.a = rEngine->Rand(rMinAlpha,rMaxAlpha); - - return p; -} - -template -void ZSimpleParticleSystem::UpdateParticle(int index, float elapsedTime) -{ - rParticles[index].xPrev = rParticles[index].xPos; - rParticles[index].yPrev = rParticles[index].yPos; - rParticles[index].xPos += rParticles[index].xVel*elapsedTime; - rParticles[index].yPos += rParticles[index].yVel*elapsedTime; - rParticles[index].size += rParticles[index].sizeDelta*elapsedTime; - rParticles[index].energy += rParticles[index].energyDelta*elapsedTime; - if(rParticles[index].size <= 0) - rParticles[index].energy = 0; -} - -#if (GFX_BACKEND == ZE_OGL) - -template -void ZSimpleParticleSystem::Render() -{ - switch(rStyle) - { - case DS_POINT: - glBindTexture(GL_TEXTURE_2D,0); - for(unsigned int i=0; i < rCurParticles; i++) - { - glPointSize(rParticles[i].size); - glBegin(GL_POINTS); - glColor4ub(rParticles[i].r,rParticles[i].g,rParticles[i].b,rParticles[i].a); - glVertex2f(rParticles[i].xPos,rParticles[i].yPos); - glEnd(); - } - break; - case DS_LINE: - glBindTexture(GL_TEXTURE_2D,0); - for(unsigned int i=0; i < rCurParticles; i++) - { - glLineWidth(rParticles[i].size); - glBegin(GL_LINES); - glColor4ub(rParticles[i].r,rParticles[i].g,rParticles[i].b,rParticles[i].a); - glVertex2f(rParticles[i].xPos,rParticles[i].yPos); - glVertex2f(rParticles[i].xPrev,rParticles[i].yPrev); - glEnd(); - } - break; - case DS_IMAGE: - float x,y,size; - rImage.Bind(); - glBegin(GL_QUADS); - for(unsigned int i=0; i < rCurParticles; i++) - { - x = rParticles[i].xPos; - y = rParticles[i].yPos; - size = rParticles[i].size; - - glColor4ub(rParticles[i].r,rParticles[i].g,rParticles[i].b,rParticles[i].a); - glTexCoord2f(0,1); glVertex2f(x,y); - glTexCoord2f(1,1); glVertex2f(x+size,y); - glTexCoord2f(0,1); glVertex2f(x+size,y-size); - glTexCoord2f(0,0); glVertex2f(x,y-size); - } - glEnd(); - break; - } -} - -#elif (GFX_BACKEND == ZE_SDL) - -template -void ZSimpleParticleSystem::Render() -{ - switch(rStyle) - { - case DS_POINT: - for(unsigned int i=0; i < rCurParticles; i++) - { - //draw point - } - break; - case DS_LINE: - for(unsigned int i=0; i < rCurParticles; i++) - { - //draw line - } - break; - case DS_IMAGE: - for(unsigned int i=0; i < rCurParticles; i++) - { - //draw image - } - break; - } -} - -#endif //GFX_BACKEND - -template -void ZSimpleParticleSystem::ReloadImage() -{ - if(rStyle == DS_IMAGE) - rImage.Reload(); -} - -template -void ZSimpleParticleSystem::SetDrawStyle(ParticleDrawStyle style) -{ - rStyle = style; -} - -template -void ZSimpleParticleSystem::SetImage(std::string filename) -{ - rImage.Open(filename); -} - -template -void ZSimpleParticleSystem::SetPosRange(float minX, float minY, float maxX, float maxY) -{ - rMinX = minX; - rMaxX = maxX; - rMinY = minY; - rMaxY = maxY; -} - -template -void ZSimpleParticleSystem::SetVelocityRange(float minXVel, float minYVel, float maxXVel, float maxYVel) -{ - rMinXVel = minXVel; - rMaxXVel = maxXVel; - rMinYVel = minYVel; - rMaxYVel = maxYVel; -} - -template -void ZSimpleParticleSystem::SetEnergyRange(float minEnergy, float maxEnergy, float minEnergyDelta, float maxEnergyDelta) -{ - rMinEnergy = minEnergy; - rMaxEnergy = maxEnergy; - rMinEnergyDelta = minEnergyDelta; - rMaxEnergyDelta = maxEnergyDelta; -} - -template -void ZSimpleParticleSystem::SetSizeRange(float minSize, float maxSize, float minSizeDelta, float maxSizeDelta) -{ - rMinSize = minSize; - rMaxSize = maxSize; - rMinSizeDelta = minSizeDelta; - rMaxSizeDelta = maxSizeDelta; -} - -template -void ZSimpleParticleSystem::SetColorRange(Uint8 minRed, Uint8 maxRed, Uint8 minGreen, Uint8 maxGreen, - Uint8 minBlue, Uint8 maxBlue, Uint8 minAlpha, Uint8 maxAlpha) -{ - rMinRed = minRed; - rMaxRed = maxRed; - rMinGreen = minGreen; - rMaxGreen = maxGreen; - rMinBlue = minBlue; - rMaxBlue = maxBlue; - rMinAlpha = minAlpha; - rMaxAlpha = maxAlpha; -} - -} //namespace ZE - -#endif //__ze_zsimpleparticlesystem_h__ +/******************************************************************************* + This file is Part of the ZEngine Library for 2D game development. + Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. + + The maintainer of this library is James Turk (james@conceptofzero.net) + and the home of this Library is http://www.zengine.sourceforge.net +*******************************************************************************/ + +/*! + \file ZE_ZSimpleParticleSystem.h + \brief Definition and implementation file for a simple particle system for ZEngine. + + Definition and implementation file for ZEngine simple particle system, ZSimpleParticleSystem based on ZBaseParticleSystem. + Due to problems with template classes the template implementation needs to be in the same file as the declaration. +
$Id: ZE_ZSimpleParticleSystem.h,v 1.5 2003/11/24 22:22:07 cozman Exp $
+ \author James Turk +**/ + +#ifndef __ze_zsimpleparticlesystem_h__ +#define __ze_zsimpleparticlesystem_h__ + +#include "ZEngine.h" + +namespace ZE +{ + +/*! + \brief Simple particle class for ZSimpleParticleSystem. + + General purpose particle, contains needed variables for a functional particle system. +**/ +class ZSimpleParticle : public ZBaseParticle +{ + public: + //! Previous X position of particle. + float xPrev; + //! Previous Y position of particle. + float yPrev; + //! X Velocity of particle per second. + float xVel; + //! Y Velocity of particle per second. + float yVel; + //! Energy change per second. + float energyDelta; + //! Size of particle. + float size; + //! Size change per second. + float sizeDelta; + //! Red component of particle color. + Uint8 r; + //! Green component of particle color. + Uint8 g; + //! Blue component of particle color. + Uint8 b; + //! Alpha component of particle color. + Uint8 a; +}; + +/*! + \brief Possible draw styles for ZSimpleParticleSystem. + + Possible draw styles for ZSimpleParticleSystem, each specifies different code with which the particles will be drawn. +**/ +enum ParticleDrawStyle +{ + DS_POINT, /*!< Draw particles as simple points. */ + DS_LINE, /*!< Draw particles as lines between the current position and the last. */ + DS_IMAGE /*!< Draw particles as an image. */ +}; + +/*! + \brief ZSimpleParticleSystem class, a simple particle system provided originally as an example. + + ZSimpleParticleSystem class, example of implementation of a particle system on top of ZBaseParticleSystem base, + designed for flexibility and ease of use over speed. More specific, therefore even less optimized for specific + circumstances. Should be concidered usable but not optimal. (Although it is a great source of code for your + own implementations.) +**/ +template +class ZSimpleParticleSystem : public ZBaseParticleSystem +{ + protected: + //! Draw style, one of the three enumerated values specifying how particles will be drawn. + ParticleDrawStyle rStyle; + //! Image to draw (only used if rStyle is DS_IMAGE). + ZImage rImage; + //! Minimum X value for starting position. + float rMinX; + //! Maximum X value for starting position. + float rMaxX; + //! Minimum Y value for starting position. + float rMinY; + //! Maximum Y value for starting position. + float rMaxY; + //! Minimum X velocity, particle moves it's velocity every second. + float rMinXVel; + //! Maximum X velocity, particle moves it's velocity every second. + float rMaxXVel; + //! Minimum Y velocity, particle moves it's velocity every second. + float rMinYVel; + //! Maximum Y velocity, particle moves it's velocity every second. + float rMaxYVel; + //! Minimum starting energy. (Remember particles with energy values <= 0 are removed.) + float rMinEnergy; + //! Maximum starting energy. + float rMaxEnergy; + //! Minimum energy change per second. + float rMinEnergyDelta; + //! Maximum energy change per second. + float rMaxEnergyDelta; + //! Minimum starting size. + float rMinSize; + //! Maximum starting size. + float rMaxSize; + //! Minimum size change per second. + float rMinSizeDelta; + //! Maximum size change per second. + float rMaxSizeDelta; + //! Minimum red component of color, 0-255. + Uint8 rMinRed; + //! Maximum red component of color, 0-255. + Uint8 rMaxRed; + //! Minimum green component of color, 0-255. + Uint8 rMinGreen; + //! Maximum green component of color, 0-255. + Uint8 rMaxGreen; + //! Minimum blue component of color, 0-255. + Uint8 rMinBlue; + //! Maximum blue component of color, 0-255. + Uint8 rMaxBlue; + //! Minimum alpha of particle, 0-255. + Uint8 rMinAlpha; + //! Maximum alpha of particle, 0-255. + Uint8 rMaxAlpha; + + /*! + \brief Function which creates a new particle. + + Implementation of pure virtual NewParticle from ZBaseParticleSystem, creates a new particle with + it's members set to values between their min and max value as set by the system. + **/ + virtual particleType NewParticle(); + + /*! + \brief Updates a given particle given it's index and the elapsedTime. + + Implementation of pure virtual UpdateParticle from ZBaseParticleSystem, updates a given particle + relative to the elapsed time. + \param index Index of particle in rParticles array to update. + \param elapsedTime Decimal portion of a second since last call. + **/ + virtual void UpdateParticle(int index, float elapsedTime); + + public: + /*! + \brief Draws all particles. + + Implementation of pure virtual Render from ZBaseParticleSystem, draws all particles in specified + ParticleDrawStyle. + **/ + virtual void Render(); + + /*! + \brief Reload image. + + Reload image if mode is DS_IMAGE, usage is same as ZImage::Reload. + **/ + void ReloadImage(); + + /*! + \brief Sets ParticleDrawStyle for this system. + + Sets the method of drawing particles, point, line, or image particles. + \param style ParticleDrawStyle for this particle system to use. + **/ + void SetDrawStyle(ParticleDrawStyle style); + + /*! + \brief Sets image for particle system. + + Sets image for particle system to use, assuming the drawing style is DS_IMAGE. + \brief filename Filename of image to load for the system. + **/ + void SetImage(std::string filename); + + /*! + \brief Sets the range of initial positions. + + Sets the range of initial positions for a new particle. + \param minX Minimum X coordinate for new particles. + \param minY Minimum Y coordinate for new particles. + \param maxX Maximum X coordinate for new particles. + \param maxY Maximum Y coordinate for new particles. + **/ + void SetPosRange(float minX, float minY, float maxX, float maxY); + + /*! + \brief Sets range of velocities for particles. + + Sets range from which a new particle obtains it's random velocity, + \param minXVel Minimum X velocity of a particle. + \param minYVel Minimum Y velocity of a particle. + \param maxXVel Maximum X velocity of a particle. + \param maxYVel Maximum Y velocity of a particle. + **/ + void SetVelocityRange(float minXVel, float minYVel, float maxXVel, float maxYVel); + + /*! + \brief Sets range of initial energy and energyDelta. + + Sets the possible ranges for a particles starting energy and it's energyDelta. Particles with + energy less than or equal to 0 are deleted by ZBaseParticleSystem::Update. + \param minEnergy Minimum initial energy. + \param maxEnergy Maximum initial energy. + \param minEnergyDelta Minimum energy delta. + \param maxEnergyDelta Maximum energy delta. + **/ + void SetEnergyRange(float minEnergy, float maxEnergy, float minEnergyDelta=0, float maxEnergyDelta=0); + + /*! + \brief Sets range of initial size and sizeDelta. + Sets the possible ranges for a particles starting size and it's sizeDelta. + \param minSize Minimum initial size. + \param maxSize Maximum initial size. + \param minSizeDelta Minimum size delta. + \param maxSizeDelta Maximum size delta. + **/ + void SetSizeRange(float minSize, float maxSize, float minSizeDelta=0, float maxSizeDelta=0); + + /*! + \brief Set range of color for a new particle. + + Sets range of possible colors, by component, for a new particle. + \param minRed Minimum value of red component (0-255). + \param maxRed Minimum value of red component (0-255). + \param minGreen Minimum value of green component (0-255). + \param maxGreen Minimum value of green component (0-255). + \param minBlue Minimum value of blue component (0-255). + \param maxBlue Minimum value of blue component (0-255). + \param minAlpha Minimum value of alpha value (0-255). + \param maxAlpha Minimum value of alpha value (0-255). + **/ + void SetColorRange(Uint8 minRed, Uint8 maxRed, Uint8 minGreen, Uint8 maxGreen, + Uint8 minBlue, Uint8 maxBlue, Uint8 minAlpha, Uint8 maxAlpha); +}; + +//implementation// + +template +particleType ZSimpleParticleSystem::NewParticle() +{ + particleType p; + + p.xPrev = p.xPos = rEngine->Rand(rMinX,rMaxX); + p.yPrev = p.yPos = rEngine->Rand(rMinY,rMaxY); + p.xVel = rEngine->Rand(rMinXVel,rMaxXVel); + p.yVel = rEngine->Rand(rMinYVel,rMaxYVel); + p.energy = rEngine->Rand(rMinEnergy,rMaxEnergy); + p.energyDelta = rEngine->Rand(rMinEnergyDelta,rMaxEnergyDelta); + p.size = rEngine->Rand(rMinSize,rMaxSize); + p.sizeDelta = rEngine->Rand(rMinSizeDelta,rMaxSizeDelta); + p.r = rEngine->Rand(rMinRed,rMaxRed); + p.g = rEngine->Rand(rMinGreen,rMaxGreen); + p.b = rEngine->Rand(rMinBlue,rMaxBlue); + p.a = rEngine->Rand(rMinAlpha,rMaxAlpha); + + return p; +} + +template +void ZSimpleParticleSystem::UpdateParticle(int index, float elapsedTime) +{ + rParticles[index].xPrev = rParticles[index].xPos; + rParticles[index].yPrev = rParticles[index].yPos; + rParticles[index].xPos += rParticles[index].xVel*elapsedTime; + rParticles[index].yPos += rParticles[index].yVel*elapsedTime; + rParticles[index].size += rParticles[index].sizeDelta*elapsedTime; + rParticles[index].energy += rParticles[index].energyDelta*elapsedTime; + if(rParticles[index].size <= 0) + rParticles[index].energy = 0; +} + +#if (GFX_BACKEND == ZE_OGL) + +template +void ZSimpleParticleSystem::Render() +{ + switch(rStyle) + { + case DS_POINT: + glBindTexture(GL_TEXTURE_2D,0); + for(unsigned int i=0; i < rCurParticles; i++) + { + glPointSize(rParticles[i].size); + glBegin(GL_POINTS); + glColor4ub(rParticles[i].r,rParticles[i].g,rParticles[i].b,rParticles[i].a); + glVertex2f(rParticles[i].xPos,rParticles[i].yPos); + glEnd(); + } + break; + case DS_LINE: + glBindTexture(GL_TEXTURE_2D,0); + for(unsigned int i=0; i < rCurParticles; i++) + { + glLineWidth(rParticles[i].size); + glBegin(GL_LINES); + glColor4ub(rParticles[i].r,rParticles[i].g,rParticles[i].b,rParticles[i].a); + glVertex2f(rParticles[i].xPos,rParticles[i].yPos); + glVertex2f(rParticles[i].xPrev,rParticles[i].yPrev); + glEnd(); + } + break; + case DS_IMAGE: + float x,y,size; + rImage.Bind(); + glBegin(GL_QUADS); + for(unsigned int i=0; i < rCurParticles; i++) + { + x = rParticles[i].xPos; + y = rParticles[i].yPos; + size = rParticles[i].size; + + glColor4ub(rParticles[i].r,rParticles[i].g,rParticles[i].b,rParticles[i].a); + glTexCoord2f(0,1); glVertex2f(x,y); + glTexCoord2f(1,1); glVertex2f(x+size,y); + glTexCoord2f(0,1); glVertex2f(x+size,y-size); + glTexCoord2f(0,0); glVertex2f(x,y-size); + } + glEnd(); + break; + } +} + +#elif (GFX_BACKEND == ZE_SDL) + +template +void ZSimpleParticleSystem::Render() +{ + switch(rStyle) + { + case DS_POINT: + for(unsigned int i=0; i < rCurParticles; i++) + { + //draw point + } + break; + case DS_LINE: + for(unsigned int i=0; i < rCurParticles; i++) + { + //draw line + } + break; + case DS_IMAGE: + for(unsigned int i=0; i < rCurParticles; i++) + { + //draw image + } + break; + } +} + +#endif //GFX_BACKEND + +template +void ZSimpleParticleSystem::ReloadImage() +{ + if(rStyle == DS_IMAGE) + rImage.Reload(); +} + +template +void ZSimpleParticleSystem::SetDrawStyle(ParticleDrawStyle style) +{ + rStyle = style; +} + +template +void ZSimpleParticleSystem::SetImage(std::string filename) +{ + rImage.Open(filename); +} + +template +void ZSimpleParticleSystem::SetPosRange(float minX, float minY, float maxX, float maxY) +{ + rMinX = minX; + rMaxX = maxX; + rMinY = minY; + rMaxY = maxY; +} + +template +void ZSimpleParticleSystem::SetVelocityRange(float minXVel, float minYVel, float maxXVel, float maxYVel) +{ + rMinXVel = minXVel; + rMaxXVel = maxXVel; + rMinYVel = minYVel; + rMaxYVel = maxYVel; +} + +template +void ZSimpleParticleSystem::SetEnergyRange(float minEnergy, float maxEnergy, float minEnergyDelta, float maxEnergyDelta) +{ + rMinEnergy = minEnergy; + rMaxEnergy = maxEnergy; + rMinEnergyDelta = minEnergyDelta; + rMaxEnergyDelta = maxEnergyDelta; +} + +template +void ZSimpleParticleSystem::SetSizeRange(float minSize, float maxSize, float minSizeDelta, float maxSizeDelta) +{ + rMinSize = minSize; + rMaxSize = maxSize; + rMinSizeDelta = minSizeDelta; + rMaxSizeDelta = maxSizeDelta; +} + +template +void ZSimpleParticleSystem::SetColorRange(Uint8 minRed, Uint8 maxRed, Uint8 minGreen, Uint8 maxGreen, + Uint8 minBlue, Uint8 maxBlue, Uint8 minAlpha, Uint8 maxAlpha) +{ + rMinRed = minRed; + rMaxRed = maxRed; + rMinGreen = minGreen; + rMaxGreen = maxGreen; + rMinBlue = minBlue; + rMaxBlue = maxBlue; + rMinAlpha = minAlpha; + rMaxAlpha = maxAlpha; +} + +} //namespace ZE + +#endif //__ze_zsimpleparticlesystem_h__ diff --git a/include/ZE_ZTimer.h b/include/ZE_ZTimer.h index 2d9b5f6..8f45fde 100644 --- a/include/ZE_ZTimer.h +++ b/include/ZE_ZTimer.h @@ -1,112 +1 @@ -/******************************************************************************* - This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk - - Licensed under a BSD-style license. - - The maintainer of this library is James Turk (james@conceptofzero.net) - and the home of this Library is http://www.zengine.sourceforge.net -*******************************************************************************/ - -/*! - \file ZE_ZTimer.h - \brief Definition file for ZTimer. - - Definition file for ZTimer, the Timer class for ZEngine. -
$Id: ZE_ZTimer.h,v 1.8 2003/05/13 01:30:51 cozman Exp $
- \author James Turk -**/ - -#ifndef __ze_ztimer_h__ -#define __ze_ztimer_h__ - -#include "ZE_ZEngine.h" - -namespace ZE -{ - -/*! - \brief ZTimer class for Timer use. - - ZTimer timing class, class wraps common features of SDL timer. Inherited from ZObject and tied to ZEngine main timer. -**/ -class ZTimer -{ - protected: - //! Pointer to ZEngine Object - ZEngine* rEngine; - //! Paused / Unpaused state of Timer - bool rPaused; - //! Using ZEngine timer or SDL global timer. - bool rUseZEngine; - //! Total time this timer has been paused. - Uint32 rPausedTime; - //! Time this Timer was paused. - Uint32 rLastPause; - - /*! - \brief Get time from parent timer. - - Protected method to get time from whichever timer is parent. - \return Time on parent timer. - **/ - Uint32 GetParentTime() const; - - public: - - /*! - \brief Constructs a new Timer. - - Sets TimePaused to current ZEngine time if useZEngine is true, otherwise uses SDL timer. - \param useZEngine Tells if timer should use ZEngine or SDL. - **/ - ZTimer(bool useZEngine=true); - - /*! - \brief Virtual Destructor. - - Virtual destructor making future inheritance safe. - **/ - virtual ~ZTimer(); - - /*! - \brief Reset Timer. - - Set Timer back to Zero, will also unpause timer if it was paused. - **/ - void Reset(); - - /*! - \brief Pause Timer. - - Pause the timer if it is unpaused. - **/ - void Pause(); - - /*! - \brief Unpause Timer. - - Unpause the timer if it is paused. - **/ - void Unpause(); - - /*! - \brief Get Time of Timer. - - Get current time accounting for time paused. - \return Current Timer Time. - **/ - Uint32 GetTime() const; - - /*! - \brief Get paused state. - - Find out paused state of timer. - \return Paused state for timer. - **/ - bool IsPaused() const; -}; - -} - -#endif //__ze_ztimer_h__ +/******************************************************************************* This file is Part of the ZEngine Library for 2D game development. Copyright (C) 2002, 2003 James Turk Licensed under a BSD-style license. The maintainer of this library is James Turk (james@conceptofzero.net) and the home of this Library is http://www.zengine.sourceforge.net *******************************************************************************/ /*! \file ZE_ZTimer.h \brief Definition file for ZTimer. Definition file for ZTimer, the Timer class for ZEngine.
$Id: ZE_ZTimer.h,v 1.9 2003/11/24 22:22:07 cozman Exp $
\author James Turk **/ #ifndef __ze_ztimer_h__ #define __ze_ztimer_h__ #include "ZE_ZEngine.h" namespace ZE { /*! \brief ZTimer class for Timer use. ZTimer timing class, class wraps common features of SDL timer. Inherited from ZObject and tied to ZEngine main timer. **/ class ZTimer { protected: //! Pointer to ZEngine Object ZEngine* rEngine; //! Paused / Unpaused state of Timer bool rPaused; //! Using ZEngine timer or SDL global timer. bool rUseZEngine; //! Total time this timer has been paused. Uint32 rPausedTime; //! Time this Timer was paused. Uint32 rLastPause; /*! \brief Get time from parent timer. Protected method to get time from whichever timer is parent. \return Time on parent timer. **/ Uint32 GetParentTime() const; public: /*! \brief Constructs a new Timer. Sets TimePaused to current ZEngine time if useZEngine is true, otherwise uses SDL timer. \param useZEngine Tells if timer should use ZEngine or SDL. **/ ZTimer(bool useZEngine=true); /*! \brief Virtual Destructor. Virtual destructor making future inheritance safe. **/ virtual ~ZTimer(); /*! \brief Reset Timer. Set Timer back to Zero, will also unpause timer if it was paused. **/ void Reset(); /*! \brief Pause Timer. Pause the timer if it is unpaused. **/ void Pause(); /*! \brief Unpause Timer. Unpause the timer if it is paused. **/ void Unpause(); /*! \brief Get Time of Timer. Get current time accounting for time paused. \return Current Timer Time. **/ Uint32 GetTime() const; /*! \brief Get paused state. Find out paused state of timer. \return Paused state for timer. **/ bool IsPaused() const; }; } #endif //__ze_ztimer_h__ \ No newline at end of file diff --git a/src/ZE_ZConfigFile.cpp b/src/ZE_ZConfigFile.cpp index 45a0495..891a5aa 100644 --- a/src/ZE_ZConfigFile.cpp +++ b/src/ZE_ZConfigFile.cpp @@ -1,378 +1,378 @@ -/******************************************************************************* - This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk - - Licensed under a BSD-style license. - - The maintainer of this library is James Turk (james@conceptofzero.net) - and the home of this Library is http://www.zengine.sourceforge.net -*******************************************************************************/ - -/** - \file ZE_ZConfigFile.cpp - \brief Source file for ZConfigFile. - - Implementation of ZConfigFile, the ZEngine INI-Style Config File. -
$Id: ZE_ZConfigFile.cpp,v 1.14 2003/07/11 20:51:44 cozman Exp $
- \author James Turk -**/ - -#include "ZE_ZConfigFile.h" - -namespace ZE -{ - -std::string ZConfigFile::CleanString(std::string str) const -{ - std::string tmpStr; - bool inQuotes = false; - - //cycle through, only copy spaces and if a character is uppercase, convert it to lowercase - for(std::string::size_type i = 0; i < str.length(); ++i) - { - if(!std::isspace(str[i]) || inQuotes) //if it's in quotes leave it be - { - if(str[i] == '\"') - inQuotes = !inQuotes; //each quote toggles the quote state - if(std::isupper(str[i]) && !inQuotes) - str[i] = static_cast(std::tolower(str[i])); - tmpStr += str[i]; - } - } - return tmpStr; -} - -bool ZConfigFile::Exists(std::string sec) const -{ - std::list::const_iterator secIter; - - sec = CleanString(sec); - - //check list for 'cleaned' version of string - for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter) - { - if(CleanString((*secIter).section) == sec) - return true; - } - return false; -} - -bool ZConfigFile::Exists(std::string sec, std::string var) const -{ - std::list::const_iterator secIter; - std::list::const_iterator varIter; - - sec = CleanString(sec); - var = CleanString(var); - - //first find section, then do same search for variable - for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter) - { - if(CleanString((*secIter).section) == sec) - { - for(varIter = (*secIter).varList.begin(); varIter != (*secIter).varList.end(); ++varIter) - { - if(CleanString((*varIter).var) == var) - return true; - } - } - } - return false; -} - -void ZConfigFile::SetVariable(std::string sec, std::string var, std::string val) -{ - std::list::iterator secIter; - std::list::iterator varIter; - - if(Exists(CleanString(sec))) //if section exists find it - { - sec = CleanString(sec); - for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter) - { - if(CleanString((*secIter).section) == sec) //if this is the section - { - if(Exists(sec,var)) //if variable exists find it - { - var = CleanString(var); - for(varIter = (*secIter).varList.begin(); varIter != (*secIter).varList.end(); ++varIter) - { - if(CleanString((*varIter).var) == var) //once variable found, set value - { - (*varIter).val = val; - break; //break from this loop - } - } - break; //done in the for loop, time to go - } - else - { - ZCF_Variable tempVar; - tempVar.var = var; - (*secIter).varList.push_back(tempVar); - SetVariable(sec,var,val); - } - } - } - } - else - { - ZCF_Section tempSec; - tempSec.section = sec; - rFileLayout.push_back(tempSec); - SetVariable(sec,var,val); - } -} - -std::string ZConfigFile::GetVariable(std::string sec, std::string var, std::string defVal) const -{ - //finds variable in same manner as SetVariable, but if not found doesn't create, just returns default value - std::list::const_iterator secIter; - std::list::const_iterator varIter; - - sec = CleanString(sec); - var = CleanString(var); - - if(Exists(sec)) - { - for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter) - { - if(CleanString((*secIter).section) == sec) //if this is the section - { - if(Exists(sec,var)) - { - for(varIter = (*secIter).varList.begin(); varIter != (*secIter).varList.end(); ++varIter) - { - if(CleanString((*varIter).var) == var) //if this is the variable - return (*varIter).val; //return now - } - break; //done in the for loop, time to go - } - else - { - return defVal; - break; - } - } - } - } - - return defVal; //if it gets to the end just return the default -} - -ZConfigFile::ZConfigFile() -{ -} - -ZConfigFile::ZConfigFile(std::string rFilename) -{ - Process(rFilename); //process does all the work -} - -ZConfigFile::~ZConfigFile() -{ - Close(); -} - -void ZConfigFile::Process(std::string filename) -{ - rFilename = filename; - int commentNum=0; - int newlineNum=0; - - std::ifstream cfile(rFilename.c_str()); - std::string section, str, var, tmp; - - rFileLayout.clear(); //layout must be cleared, in case variable is being used multiple times - - while(!cfile.eof() && cfile.is_open()) //parses entire file - { - std::getline(cfile,str); //read in a line - tmp = CleanString(str); //get a clean version - - //if std::string is bracketed it is a section, if it begins in a letter it is a variable - if(tmp[0] == '[' && tmp[tmp.length()-1] == ']') - section = str; - else if(std::isalpha(tmp[0])) //variables must start with a letter - { - var = str.substr(0,str.find('=')); //split the std::string at the equals sign - SetVariable(section,var,str.substr(str.find('=')+1,str.length()-var.length()-1)); - } - else if(tmp[0] == '#' || tmp[0] == ';') //acceptable comment characters - { - SetVariable(section,FormatStr("__comment%d",commentNum),str); - ++commentNum; - } - else if(tmp.length() == 0 && !cfile.eof()) //prevent writing a new newline with every write to disk - { - SetVariable(section,FormatStr("__newline%d",newlineNum),""); - ++newlineNum; - } - - } - cfile.close(); -} - -//each get* gets the variable (stored as a string) from using GetVariable, then converts it to the desired format -float ZConfigFile::GetFloat(std::string section, std::string var, float defVal) const -{ - std::string val; - char tmp[20]; - - section = CleanString(section); - var = CleanString(var); - - section = '[' + section + ']'; - - sprintf(tmp,"%f",defVal); - val = GetVariable(section,var,tmp); - - if(!atof(val.c_str()) && val[0] !='0') //if it is zero but doesn't start with a zero - return defVal; - else - return static_cast(atof(val.c_str())); //atof returns a double(?!) -} - -int ZConfigFile::GetInt(std::string section, std::string var, int defVal) const -{ - std::string val; - char tmp[20]; - - section = CleanString(section); - var = CleanString(var); - - section = '[' + section + ']'; - - sprintf(tmp,"%d",defVal); - val = GetVariable(section,var,tmp); - - if(!atoi(val.c_str()) && val[0] !='0') //if it is zero but doesn't start with a zero - return defVal; - else - return atoi(val.c_str()); -} - -bool ZConfigFile::GetBool(std::string section, std::string var, bool defVal) const -{ - std::string val,tmp; - - section = CleanString(section); - var = CleanString(var); - - section = '[' + section + ']'; - - tmp = defVal ? "true" : "false"; - val = CleanString(GetVariable(section,var,tmp)); - - if(val == "true" || val == "1") - return true; - else if(val == "false" || val == "0") - return false; - else - return defVal; -} - -std::string ZConfigFile::GetString(std::string section, std::string var, std::string defVal) const -{ - std::string val; - - section = CleanString(section); - var = CleanString(var); - - section = '[' + section + ']'; - - val = CleanString(GetVariable(section,var,defVal)); - if(val == CleanString(defVal)) - val = defVal; - - - if(val[0] == '\"' && val[val.length()-1] == '\"') - return val.substr(1,val.length()-2); //chop off quotes - else - return val; -} - -//each set* converts it's variable to a string, then places it in using SetVariable -void ZConfigFile::SetFloat(std::string section, std::string var, float val) -{ - char buf[20]; - sprintf(buf,"%f",val); - - section = '[' + section + ']'; - SetVariable(section,var,buf); -} - -void ZConfigFile::SetInt(std::string section, std::string var, int val) -{ - char buf[20]; - sprintf(buf,"%d",val); - - section = '[' + section + ']'; - SetVariable(section,var,buf); -} - -void ZConfigFile::SetBool(std::string section, std::string var, bool val) -{ - std::string tmp = val ? "true" : "false"; - - section = '[' + section + ']'; - SetVariable(section,var,tmp); -} - -void ZConfigFile::SetString(std::string section, std::string var, std::string val) -{ - section = '[' + section + ']'; - val = "\"" + val + "\""; - SetVariable(section,var,val); -} - -void ZConfigFile::Flush() -{ - std::list::iterator secIter; - std::list::iterator varIter; - std::string secName; - - //in case the filename is already cleared somehow - if(rFilename.length()) - { - //open the file blanked out, to not duplicate entries - std::ofstream cfile(rFilename.c_str(), std::ios::out|std::ios::trunc); - - if(cfile) - { - //iteration through sections - for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter) - { - //ensure that section is valid - secName = CleanString((*secIter).section); - if(secName.length() && secName[0] == '[' && secName[secName.length()-1] == ']') - { - cfile << (*secIter).section << std::endl; //write out raw section title - - //for each variable in section, write out variable=value - for(varIter = (*secIter).varList.begin(); varIter != (*secIter).varList.end(); ++varIter) - { - if((*varIter).var[0] == '_') - { - if( ((*varIter).var).substr(2,7) == "comment") - cfile << (*varIter).val << std::endl; - else if( ((*varIter).var).substr(2,7) == "newline") - cfile << std::endl; - } - else if(CleanString((*varIter).var).length()) //ensures that variable is valid - cfile << (*varIter).var << '=' << (*varIter).val << std::endl; - } - } - } - cfile.close(); - } - } -} - -void ZConfigFile::Close() -{ - Flush(); //when the file is closed it should be flushed to disk - rFilename = ""; -} - -} +/******************************************************************************* + This file is Part of the ZEngine Library for 2D game development. + Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. + + The maintainer of this library is James Turk (james@conceptofzero.net) + and the home of this Library is http://www.zengine.sourceforge.net +*******************************************************************************/ + +/** + \file ZE_ZConfigFile.cpp + \brief Source file for ZConfigFile. + + Implementation of ZConfigFile, the ZEngine INI-Style Config File. +
$Id: ZE_ZConfigFile.cpp,v 1.15 2003/11/24 22:20:49 cozman Exp $
+ \author James Turk +**/ + +#include "ZE_ZConfigFile.h" + +namespace ZE +{ + +std::string ZConfigFile::CleanString(std::string str) const +{ + std::string tmpStr; + bool inQuotes = false; + + //cycle through, only copy spaces and if a character is uppercase, convert it to lowercase + for(std::string::size_type i = 0; i < str.length(); ++i) + { + if(!std::isspace(str[i]) || inQuotes) //if it's in quotes leave it be + { + if(str[i] == '\"') + inQuotes = !inQuotes; //each quote toggles the quote state + if(std::isupper(str[i]) && !inQuotes) + str[i] = static_cast(std::tolower(str[i])); + tmpStr += str[i]; + } + } + return tmpStr; +} + +bool ZConfigFile::Exists(std::string sec) const +{ + std::list::const_iterator secIter; + + sec = CleanString(sec); + + //check list for 'cleaned' version of string + for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter) + { + if(CleanString((*secIter).section) == sec) + return true; + } + return false; +} + +bool ZConfigFile::Exists(std::string sec, std::string var) const +{ + std::list::const_iterator secIter; + std::list::const_iterator varIter; + + sec = CleanString(sec); + var = CleanString(var); + + //first find section, then do same search for variable + for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter) + { + if(CleanString((*secIter).section) == sec) + { + for(varIter = (*secIter).varList.begin(); varIter != (*secIter).varList.end(); ++varIter) + { + if(CleanString((*varIter).var) == var) + return true; + } + } + } + return false; +} + +void ZConfigFile::SetVariable(std::string sec, std::string var, std::string val) +{ + std::list::iterator secIter; + std::list::iterator varIter; + + if(Exists(CleanString(sec))) //if section exists find it + { + sec = CleanString(sec); + for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter) + { + if(CleanString((*secIter).section) == sec) //if this is the section + { + if(Exists(sec,var)) //if variable exists find it + { + var = CleanString(var); + for(varIter = (*secIter).varList.begin(); varIter != (*secIter).varList.end(); ++varIter) + { + if(CleanString((*varIter).var) == var) //once variable found, set value + { + (*varIter).val = val; + break; //break from this loop + } + } + break; //done in the for loop, time to go + } + else + { + ZCF_Variable tempVar; + tempVar.var = var; + (*secIter).varList.push_back(tempVar); + SetVariable(sec,var,val); + } + } + } + } + else + { + ZCF_Section tempSec; + tempSec.section = sec; + rFileLayout.push_back(tempSec); + SetVariable(sec,var,val); + } +} + +std::string ZConfigFile::GetVariable(std::string sec, std::string var, std::string defVal) const +{ + //finds variable in same manner as SetVariable, but if not found doesn't create, just returns default value + std::list::const_iterator secIter; + std::list::const_iterator varIter; + + sec = CleanString(sec); + var = CleanString(var); + + if(Exists(sec)) + { + for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter) + { + if(CleanString((*secIter).section) == sec) //if this is the section + { + if(Exists(sec,var)) + { + for(varIter = (*secIter).varList.begin(); varIter != (*secIter).varList.end(); ++varIter) + { + if(CleanString((*varIter).var) == var) //if this is the variable + return (*varIter).val; //return now + } + break; //done in the for loop, time to go + } + else + { + return defVal; + break; + } + } + } + } + + return defVal; //if it gets to the end just return the default +} + +ZConfigFile::ZConfigFile() +{ +} + +ZConfigFile::ZConfigFile(std::string rFilename) +{ + Process(rFilename); //process does all the work +} + +ZConfigFile::~ZConfigFile() +{ + Close(); +} + +void ZConfigFile::Process(std::string filename) +{ + rFilename = filename; + int commentNum=0; + int newlineNum=0; + + std::ifstream cfile(rFilename.c_str()); + std::string section, str, var, tmp; + + rFileLayout.clear(); //layout must be cleared, in case variable is being used multiple times + + while(!cfile.eof() && cfile.is_open()) //parses entire file + { + std::getline(cfile,str); //read in a line + tmp = CleanString(str); //get a clean version + + //if std::string is bracketed it is a section, if it begins in a letter it is a variable + if(tmp[0] == '[' && tmp[tmp.length()-1] == ']') + section = str; + else if(std::isalpha(tmp[0])) //variables must start with a letter + { + var = str.substr(0,str.find('=')); //split the std::string at the equals sign + SetVariable(section,var,str.substr(str.find('=')+1,str.length()-var.length()-1)); + } + else if(tmp[0] == '#' || tmp[0] == ';') //acceptable comment characters + { + SetVariable(section,FormatStr("__comment%d",commentNum),str); + ++commentNum; + } + else if(tmp.length() == 0 && !cfile.eof()) //prevent writing a new newline with every write to disk + { + SetVariable(section,FormatStr("__newline%d",newlineNum),""); + ++newlineNum; + } + + } + cfile.close(); +} + +//each get* gets the variable (stored as a string) from using GetVariable, then converts it to the desired format +float ZConfigFile::GetFloat(std::string section, std::string var, float defVal) const +{ + std::string val; + char tmp[20]; + + section = CleanString(section); + var = CleanString(var); + + section = '[' + section + ']'; + + sprintf(tmp,"%f",defVal); + val = GetVariable(section,var,tmp); + + if(!atof(val.c_str()) && val[0] !='0') //if it is zero but doesn't start with a zero + return defVal; + else + return static_cast(atof(val.c_str())); //atof returns a double(?!) +} + +int ZConfigFile::GetInt(std::string section, std::string var, int defVal) const +{ + std::string val; + char tmp[20]; + + section = CleanString(section); + var = CleanString(var); + + section = '[' + section + ']'; + + sprintf(tmp,"%d",defVal); + val = GetVariable(section,var,tmp); + + if(!atoi(val.c_str()) && val[0] !='0') //if it is zero but doesn't start with a zero + return defVal; + else + return atoi(val.c_str()); +} + +bool ZConfigFile::GetBool(std::string section, std::string var, bool defVal) const +{ + std::string val,tmp; + + section = CleanString(section); + var = CleanString(var); + + section = '[' + section + ']'; + + tmp = defVal ? "true" : "false"; + val = CleanString(GetVariable(section,var,tmp)); + + if(val == "true" || val == "1") + return true; + else if(val == "false" || val == "0") + return false; + else + return defVal; +} + +std::string ZConfigFile::GetString(std::string section, std::string var, std::string defVal) const +{ + std::string val; + + section = CleanString(section); + var = CleanString(var); + + section = '[' + section + ']'; + + val = CleanString(GetVariable(section,var,defVal)); + if(val == CleanString(defVal)) + val = defVal; + + + if(val[0] == '\"' && val[val.length()-1] == '\"') + return val.substr(1,val.length()-2); //chop off quotes + else + return val; +} + +//each set* converts it's variable to a string, then places it in using SetVariable +void ZConfigFile::SetFloat(std::string section, std::string var, float val) +{ + char buf[20]; + sprintf(buf,"%f",val); + + section = '[' + section + ']'; + SetVariable(section,var,buf); +} + +void ZConfigFile::SetInt(std::string section, std::string var, int val) +{ + char buf[20]; + sprintf(buf,"%d",val); + + section = '[' + section + ']'; + SetVariable(section,var,buf); +} + +void ZConfigFile::SetBool(std::string section, std::string var, bool val) +{ + std::string tmp = val ? "true" : "false"; + + section = '[' + section + ']'; + SetVariable(section,var,tmp); +} + +void ZConfigFile::SetString(std::string section, std::string var, std::string val) +{ + section = '[' + section + ']'; + val = "\"" + val + "\""; + SetVariable(section,var,val); +} + +void ZConfigFile::Flush() +{ + std::list::iterator secIter; + std::list::iterator varIter; + std::string secName; + + //in case the filename is already cleared somehow + if(rFilename.length()) + { + //open the file blanked out, to not duplicate entries + std::ofstream cfile(rFilename.c_str(), std::ios::out|std::ios::trunc); + + if(cfile) + { + //iteration through sections + for(secIter = rFileLayout.begin(); secIter != rFileLayout.end(); ++secIter) + { + //ensure that section is valid + secName = CleanString((*secIter).section); + if(secName.length() && secName[0] == '[' && secName[secName.length()-1] == ']') + { + cfile << (*secIter).section << std::endl; //write out raw section title + + //for each variable in section, write out variable=value + for(varIter = (*secIter).varList.begin(); varIter != (*secIter).varList.end(); ++varIter) + { + if((*varIter).var[0] == '_') + { + if( ((*varIter).var).substr(2,7) == "comment") + cfile << (*varIter).val << std::endl; + else if( ((*varIter).var).substr(2,7) == "newline") + cfile << std::endl; + } + else if(CleanString((*varIter).var).length()) //ensures that variable is valid + cfile << (*varIter).var << '=' << (*varIter).val << std::endl; + } + } + } + cfile.close(); + } + } +} + +void ZConfigFile::Close() +{ + Flush(); //when the file is closed it should be flushed to disk + rFilename = ""; +} + +} diff --git a/src/ZE_ZRect.cpp b/src/ZE_ZRect.cpp index f23e6d5..dbb6140 100644 --- a/src/ZE_ZRect.cpp +++ b/src/ZE_ZRect.cpp @@ -1,233 +1,233 @@ -/******************************************************************************* - This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk - - Licensed under a BSD-style license. - - The maintainer of this library is James Turk (james@conceptofzero.net) - and the home of this Library is http://www.zengine.sourceforge.net -*******************************************************************************/ - -/** - \file ZE_ZRect.cpp - \brief Source file for ZRect. - - Implementation of ZRect, the Rectangle class for ZEngine. -
$Id: ZE_ZRect.cpp,v 1.14 2003/08/02 01:18:45 cozman Exp $
- \author James Turk -**/ - -#include "ZE_ZRect.h" - -namespace ZE -{ - -ZRect::ZRect() : - rEngine(ZEngine::GetInstance()), - rX(0),rY(0),rWidth(0),rHeight(0) -{ -} - -ZRect::ZRect(float x, float y, float width, float height) : - rEngine(ZEngine::GetInstance()), - rX(x),rY(y),rWidth(width),rHeight(height) -{ -} - -ZRect::ZRect(const SDL_Rect &rect) : - rEngine(ZEngine::GetInstance()), - rX(static_cast(rect.x)), - rY(static_cast(rect.y)), - rWidth(static_cast(rect.w)), - rHeight(static_cast(rect.h)) -{ -} - -ZRect::ZRect(const ZRect &rhs) : - rEngine(ZEngine::GetInstance()), - rX(rhs.X()),rY(rhs.Y()),rWidth(rhs.Width()),rHeight(rhs.Height()) -{ -} - -ZRect::~ZRect() -{ -} - -const ZRect& ZRect::operator=(const ZRect &rhs) -{ - if(this != &rhs) - { - rX = rhs.X(); - rY = rhs.Y(); - rWidth = rhs.Width(); - rHeight = rhs.Height(); - } - return *this; -} - -bool ZRect::operator<(const ZRect &rhs) const -{ - //< is the one that is closer to top corner (as a whole)// - - if(rY < rhs.Y()) //check Ys - return true; - else if(rY > rhs.Y()) - return false; - else - { - if(rX < rhs.X()) //check Xs - return true; - else if(rX > rhs.X()) - return false; - else - { - if(rHeight < rhs.Height()) //check heights - return true; - else if(rHeight > rhs.Height()) - return false; - else - { - if(rWidth < rhs.Width()) //check widths - return true; - else if(rWidth > rhs.Width()) - return false; - else - return false; //nothing left to check, they are == - } - } - } -} - -void ZRect::Draw(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) const -{ -#if (GFX_BACKEND == ZE_OGL) - glBindTexture(GL_TEXTURE_2D,0); //reset to blank texture - glColor4ub(red,green,blue,alpha); - glBegin(GL_QUADS); - glVertex2f(rX, rY); - glVertex2f(rX+rWidth, rY); - glVertex2f(rX+rWidth, rY+rHeight); - glVertex2f(rX, rY+rHeight); - glEnd(); - glColor4ub(255,255,255,255); //restore color setting -#elif (GFX_BACKEND == ZE_SDL) - SDL_Rect rect = SDLrect(); - SDL_FillRect(rEngine->Display(), &rect, SDL_MapRGBA(rEngine->Display()->format,red,green,blue,alpha)); -#endif //GFX_BACKEND - -} - -void ZRect::Move(float x, float y) -{ - rX = x; - rY = y; -} - -void ZRect::MoveRel(float xMove, float yMove) -{ - rX += xMove; - rY += yMove; -} - -void ZRect::Resize(float width, float height) -{ - rWidth = width; - rHeight = height; -} - -void ZRect::ResizeRel(float widthChange, float heightChange) -{ - rWidth += widthChange; - rHeight += heightChange; -} - -bool ZRect::Intersects(const ZRect &rect) const -{ - return !(rX > rect.Right() || rect.Left() > rX+rWidth || - rY > rect.Bottom() || rect.Top() > rY+rHeight); -} - -bool ZRect::Contains(float x, float y) const -{ - return x > rX && x < rX+rWidth && y > rY && y < rY+rHeight; -} - -bool ZRect::Contains(const ZRect &rect) const -{ - //contains all 4 points - return Contains(rect.Left(),rect.Top()) && Contains(rect.Right(),rect.Top()) && - Contains(rect.Left(),rect.Bottom()) && Contains(rect.Right(),rect.Bottom()); -} - -ZRect ZRect::Intersection(const ZRect &rect) const -{ - float tempX=0,tempY=0,tempW=0,tempH=0; - - //can only grab the intersection if they intersect - if(Intersects(rect)) - { - tempX = rX > rect.X() ? rX : rect.X(); - tempY = rY > rect.Y() ? rY : rect.Y(); - tempW = rX+rWidth < rect.Right() ? rX+rWidth : rect.Right(); - tempH = rY+rHeight < rect.Bottom() ? rY+rHeight : rect.Bottom(); - - tempW -= tempX; //adjust width and height - tempH -= tempY; - } - - return ZRect(tempX,tempY,tempW,tempH); -} - -SDL_Rect ZRect::SDLrect() const -{ - SDL_Rect ret; - - ret.x = static_cast(rX); - ret.y = static_cast(rY); - ret.w = static_cast(rWidth); - ret.h = static_cast(rHeight); - - return ret; -} - -float ZRect::X() const -{ - return rX; -} - -float ZRect::Y() const -{ - return rY; -} - -float ZRect::Left() const -{ - return rX; -} - -float ZRect::Right() const -{ - return rX+rWidth; -} - -float ZRect::Top() const -{ - return rY; -} - -float ZRect::Bottom() const -{ - return rY+rHeight; -} - -float ZRect::Width() const -{ - return rWidth; -} - -float ZRect::Height() const -{ - return rHeight; -} - -} //namespace ZE +/******************************************************************************* + This file is Part of the ZEngine Library for 2D game development. + Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. + + The maintainer of this library is James Turk (james@conceptofzero.net) + and the home of this Library is http://www.zengine.sourceforge.net +*******************************************************************************/ + +/** + \file ZE_ZRect.cpp + \brief Source file for ZRect. + + Implementation of ZRect, the Rectangle class for ZEngine. +
$Id: ZE_ZRect.cpp,v 1.15 2003/11/24 22:20:49 cozman Exp $
+ \author James Turk +**/ + +#include "ZE_ZRect.h" + +namespace ZE +{ + +ZRect::ZRect() : + rEngine(ZEngine::GetInstance()), + rX(0),rY(0),rWidth(0),rHeight(0) +{ +} + +ZRect::ZRect(float x, float y, float width, float height) : + rEngine(ZEngine::GetInstance()), + rX(x),rY(y),rWidth(width),rHeight(height) +{ +} + +ZRect::ZRect(const SDL_Rect &rect) : + rEngine(ZEngine::GetInstance()), + rX(static_cast(rect.x)), + rY(static_cast(rect.y)), + rWidth(static_cast(rect.w)), + rHeight(static_cast(rect.h)) +{ +} + +ZRect::ZRect(const ZRect &rhs) : + rEngine(ZEngine::GetInstance()), + rX(rhs.X()),rY(rhs.Y()),rWidth(rhs.Width()),rHeight(rhs.Height()) +{ +} + +ZRect::~ZRect() +{ +} + +const ZRect& ZRect::operator=(const ZRect &rhs) +{ + if(this != &rhs) + { + rX = rhs.X(); + rY = rhs.Y(); + rWidth = rhs.Width(); + rHeight = rhs.Height(); + } + return *this; +} + +bool ZRect::operator<(const ZRect &rhs) const +{ + //< is the one that is closer to top corner (as a whole)// + + if(rY < rhs.Y()) //check Ys + return true; + else if(rY > rhs.Y()) + return false; + else + { + if(rX < rhs.X()) //check Xs + return true; + else if(rX > rhs.X()) + return false; + else + { + if(rHeight < rhs.Height()) //check heights + return true; + else if(rHeight > rhs.Height()) + return false; + else + { + if(rWidth < rhs.Width()) //check widths + return true; + else if(rWidth > rhs.Width()) + return false; + else + return false; //nothing left to check, they are == + } + } + } +} + +void ZRect::Draw(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) const +{ +#if (GFX_BACKEND == ZE_OGL) + glBindTexture(GL_TEXTURE_2D,0); //reset to blank texture + glColor4ub(red,green,blue,alpha); + glBegin(GL_QUADS); + glVertex2f(rX, rY); + glVertex2f(rX+rWidth, rY); + glVertex2f(rX+rWidth, rY+rHeight); + glVertex2f(rX, rY+rHeight); + glEnd(); + glColor4ub(255,255,255,255); //restore color setting +#elif (GFX_BACKEND == ZE_SDL) + SDL_Rect rect = SDLrect(); + SDL_FillRect(rEngine->Display(), &rect, SDL_MapRGBA(rEngine->Display()->format,red,green,blue,alpha)); +#endif //GFX_BACKEND + +} + +void ZRect::Move(float x, float y) +{ + rX = x; + rY = y; +} + +void ZRect::MoveRel(float xMove, float yMove) +{ + rX += xMove; + rY += yMove; +} + +void ZRect::Resize(float width, float height) +{ + rWidth = width; + rHeight = height; +} + +void ZRect::ResizeRel(float widthChange, float heightChange) +{ + rWidth += widthChange; + rHeight += heightChange; +} + +bool ZRect::Intersects(const ZRect &rect) const +{ + return !(rX > rect.Right() || rect.Left() > rX+rWidth || + rY > rect.Bottom() || rect.Top() > rY+rHeight); +} + +bool ZRect::Contains(float x, float y) const +{ + return x > rX && x < rX+rWidth && y > rY && y < rY+rHeight; +} + +bool ZRect::Contains(const ZRect &rect) const +{ + //contains all 4 points + return Contains(rect.Left(),rect.Top()) && Contains(rect.Right(),rect.Top()) && + Contains(rect.Left(),rect.Bottom()) && Contains(rect.Right(),rect.Bottom()); +} + +ZRect ZRect::Intersection(const ZRect &rect) const +{ + float tempX=0,tempY=0,tempW=0,tempH=0; + + //can only grab the intersection if they intersect + if(Intersects(rect)) + { + tempX = rX > rect.X() ? rX : rect.X(); + tempY = rY > rect.Y() ? rY : rect.Y(); + tempW = rX+rWidth < rect.Right() ? rX+rWidth : rect.Right(); + tempH = rY+rHeight < rect.Bottom() ? rY+rHeight : rect.Bottom(); + + tempW -= tempX; //adjust width and height + tempH -= tempY; + } + + return ZRect(tempX,tempY,tempW,tempH); +} + +SDL_Rect ZRect::SDLrect() const +{ + SDL_Rect ret; + + ret.x = static_cast(rX); + ret.y = static_cast(rY); + ret.w = static_cast(rWidth); + ret.h = static_cast(rHeight); + + return ret; +} + +float ZRect::X() const +{ + return rX; +} + +float ZRect::Y() const +{ + return rY; +} + +float ZRect::Left() const +{ + return rX; +} + +float ZRect::Right() const +{ + return rX+rWidth; +} + +float ZRect::Top() const +{ + return rY; +} + +float ZRect::Bottom() const +{ + return rY+rHeight; +} + +float ZRect::Width() const +{ + return rWidth; +} + +float ZRect::Height() const +{ + return rHeight; +} + +} //namespace ZE diff --git a/src/ZE_ZTimer.cpp b/src/ZE_ZTimer.cpp index 3637a7b..9b5456f 100644 --- a/src/ZE_ZTimer.cpp +++ b/src/ZE_ZTimer.cpp @@ -1,82 +1,82 @@ -/******************************************************************************* - This file is Part of the ZEngine Library for 2D game development. - Copyright (C) 2002, 2003 James Turk - - Licensed under a BSD-style license. - - The maintainer of this library is James Turk (james@conceptofzero.net) - and the home of this Library is http://www.zengine.sourceforge.net -*******************************************************************************/ - -/** - \file ZE_ZTimer.cpp - \brief Source file for ZTimer. - - Implementation of ZTimer, the basic Timer class for ZEngine. -
$Id: ZE_ZTimer.cpp,v 1.11 2003/07/12 09:22:13 cozman Exp $
- \author James Turk -**/ - -#include "ZE_ZTimer.h" - -namespace ZE -{ - -Uint32 ZTimer::GetParentTime() const -{ - if(rUseZEngine) - return rEngine->GetTime(); - else - return SDL_GetTicks(); -} - -ZTimer::ZTimer(bool useZEngine) : - rEngine(ZEngine::GetInstance()), - rUseZEngine(useZEngine) -{ - Reset(); //initializes other members -} - -ZTimer::~ZTimer() -{ -} - -void ZTimer::Reset() -{ - rLastPause = rPausedTime = GetParentTime(); - rPaused = false; -} - -void ZTimer::Pause() -{ - if(!rPaused) - { - rLastPause = GetParentTime(); - rPaused = true; - } -} - -void ZTimer::Unpause() -{ - if(rPaused) - { - //when unpausing update the total paused time by that pause - rPausedTime += (GetParentTime()-rLastPause); - rPaused = false; - } -} - -Uint32 ZTimer::GetTime() const -{ - if(rPaused) //when paused timer adjusted to subtract currently paused time - return GetParentTime() - (rPausedTime + (GetParentTime() - rLastPause)); - else - return GetParentTime() - rPausedTime; //paused time is the cotal amt of time the program has been paused -} - -bool ZTimer::IsPaused() const -{ - return rPaused; -} - -} +/******************************************************************************* + This file is Part of the ZEngine Library for 2D game development. + Copyright (C) 2002, 2003 James Turk + + Licensed under a BSD-style license. + + The maintainer of this library is James Turk (james@conceptofzero.net) + and the home of this Library is http://www.zengine.sourceforge.net +*******************************************************************************/ + +/** + \file ZE_ZTimer.cpp + \brief Source file for ZTimer. + + Implementation of ZTimer, the basic Timer class for ZEngine. +
$Id: ZE_ZTimer.cpp,v 1.12 2003/11/24 22:20:49 cozman Exp $
+ \author James Turk +**/ + +#include "ZE_ZTimer.h" + +namespace ZE +{ + +Uint32 ZTimer::GetParentTime() const +{ + if(rUseZEngine) + return rEngine->GetTime(); + else + return SDL_GetTicks(); +} + +ZTimer::ZTimer(bool useZEngine) : + rEngine(ZEngine::GetInstance()), + rUseZEngine(useZEngine) +{ + Reset(); //initializes other members +} + +ZTimer::~ZTimer() +{ +} + +void ZTimer::Reset() +{ + rLastPause = rPausedTime = GetParentTime(); + rPaused = false; +} + +void ZTimer::Pause() +{ + if(!rPaused) + { + rLastPause = GetParentTime(); + rPaused = true; + } +} + +void ZTimer::Unpause() +{ + if(rPaused) + { + //when unpausing update the total paused time by that pause + rPausedTime += (GetParentTime()-rLastPause); + rPaused = false; + } +} + +Uint32 ZTimer::GetTime() const +{ + if(rPaused) //when paused timer adjusted to subtract currently paused time + return GetParentTime() - (rPausedTime + (GetParentTime() - rLastPause)); + else + return GetParentTime() - rPausedTime; //paused time is the cotal amt of time the program has been paused +} + +bool ZTimer::IsPaused() const +{ + return rPaused; +} + +}