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