Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Made the src/engine/video folder files use spaces.

  • Loading branch information...
commit d4823e7ce559f5e83897a3ec19418c469503ed8c 1 parent 02051d8
Yohann Ferreira authored
Showing with 10,127 additions and 9,779 deletions.
  1. +154 −122 src/engine/video/color.h
  2. +20 −17 src/engine/video/context.h
  3. +70 −54 src/engine/video/coord_sys.h
  4. +104 −106 src/engine/video/fade.cpp
  5. +81 −70 src/engine/video/fade.h
  6. +1,504 −1,467 src/engine/video/image.cpp
  7. +771 −716 src/engine/video/image.h
  8. +400 −391 src/engine/video/image_base.cpp
  9. +150 −144 src/engine/video/image_base.h
  10. +101 −95 src/engine/video/interpolator.cpp
  11. +92 −87 src/engine/video/interpolator.h
  12. +132 −132 src/engine/video/particle.h
  13. +407 −419 src/engine/video/particle_effect.cpp
  14. +201 −189 src/engine/video/particle_effect.h
  15. +110 −112 src/engine/video/particle_emitter.h
  16. +33 −33 src/engine/video/particle_keyframe.h
  17. +76 −79 src/engine/video/particle_manager.cpp
  18. +65 −63 src/engine/video/particle_manager.h
  19. +764 −840 src/engine/video/particle_system.cpp
  20. +361 −353 src/engine/video/particle_system.h
  21. +40 −40 src/engine/video/screen_rect.h
  22. +104 −101 src/engine/video/shake.cpp
  23. +26 −23 src/engine/video/shake.h
  24. +853 −830 src/engine/video/text.cpp
  25. +405 −366 src/engine/video/text.h
  26. +445 −422 src/engine/video/texture.cpp
  27. +269 −259 src/engine/video/texture.h
  28. +529 −513 src/engine/video/texture_controller.cpp
  29. +199 −192 src/engine/video/texture_controller.h
  30. +901 −829 src/engine/video/video.cpp
  31. +760 −715 src/engine/video/video.h
View
276 src/engine/video/color.h
@@ -20,7 +20,8 @@
#include "utils.h"
-namespace hoa_video {
+namespace hoa_video
+{
/** ****************************************************************************
*** \brief Representation of a single RGBA color.
@@ -28,130 +29,161 @@ namespace hoa_video {
*** This class encapsulates an array of 4 floats, and allows you to do basic
*** operations like adding and multiplying colors.
*** ***************************************************************************/
-class Color {
+class Color
+{
public:
- /** \brief Default colors for user convenience.
- *** These are defined in the file video.cpp. All colors are opaque (1.0f alpha value) except for "clear".
- **/
- //@{
- static Color clear; //!< Clear (transparent) color (r=0.0, g=0.0, b=0.0, a=0.0)
- static Color white; //!< White color (r=1.0, g=1.0, b=1.0, a=1.0)
- static Color gray; //!< Gray color (r=0.5, g=0.5, b=0.5, a=1.0)
- static Color black; //!< Black color (r=0.0, g=0.0, b=0.0, a=1.0)
- static Color red; //!< Red color (r=1.0, g=0.0, b=0.0, a=1.0)
- static Color orange; //!< Orangecolor (r=1.0, g=0.4, b=0.0, a=1.0)
- static Color yellow; //!< Yellow color (r=1.0, g=1.0, b=0.0, a=1.0)
- static Color green; //!< Green color (r=0.0, g=1.0, b=0.0, a=1.0)
- static Color aqua; //!< Aqua color (r=0.0, g=1.0, b=1.0, a=1.0)
- static Color blue; //!< Blue color (r=0.0, g=0.0, b=1.0, a=1.0)
- static Color violet; //!< Violet color (r=1.0, g=0.0, b=1.0, a=1.0)
- static Color brown; //!< Brown color (r=0.6, g=0.3, b=0.1, a=1.0)
- //@}
-
- Color()
- { _colors[0] = 0.0f; _colors[1] = 0.0f; _colors[2] = 0.0f; _colors[3] = 1.0f; }
-
- Color(float r, float g, float b, float a)
- { _colors[0] = r; _colors[1] = g; _colors[2] = b; _colors[3] = a; }
-
- //! \brief Overloaded Operators
- //@{
- bool operator == (const Color &c) const
- {
- return (hoa_utils::IsFloatEqual(_colors[0], c._colors[0]) && hoa_utils::IsFloatEqual(_colors[1], c._colors[1]) &&
- hoa_utils::IsFloatEqual(_colors[2], c._colors[2]) && hoa_utils::IsFloatEqual(_colors[3], c._colors[3]));
- }
-
- bool operator != (const Color &c) const
- { return _colors[0] != c._colors[0] || _colors[1] != c._colors[1] || _colors[2] != c._colors[2] || _colors[3] != c._colors[3]; }
-
- Color operator + (const Color &c) const
- {
- Color col = Color(_colors[0] + c._colors[0], _colors[1] + c._colors[1], _colors[2] + c._colors[2], _colors[3] + c._colors[3]);
- if (col[0] > 1.0f) col[0] = 1.0f; else if (col[0] < 0.0f) col[0] = 0.0f;
- if (col[1] > 1.0f) col[1] = 1.0f; else if (col[1] < 0.0f) col[1] = 0.0f;
- if (col[2] > 1.0f) col[2] = 1.0f; else if (col[2] < 0.0f) col[2] = 0.0f;
- if (col[3] > 1.0f) col[3] = 1.0f; else if (col[3] < 0.0f) col[3] = 0.0f;
- return col;
- }
-
- Color& operator *= (const Color &c)
- {
- _colors[0] *= c._colors[0];
- _colors[1] *= c._colors[1];
- _colors[2] *= c._colors[2];
- _colors[3] *= c._colors[3];
- return *this;
- }
-
- Color operator * (const Color &c) const
- { return Color(_colors[0] * c._colors[0], _colors[1] * c._colors[1], _colors[2] * c._colors[2], _colors[3] * c._colors[3]); }
-
- Color operator * (float f) const
- { return Color(_colors[0] * f, _colors[1] * f, _colors[2] * f, _colors[3]); }
-
- /** \note No checking of array bounds are done here for efficiency reasons. If safety is a concern, use the
- *** class member access functions instead.
- **/
- float& operator[](int32 i)
- { return _colors[i]; }
-
- /** \note No checking of array bounds are done here for efficiency reasons. If safety is a concern, use the
- *** class member access functions instead.
- **/
- const float& operator[](int32 i) const
- { return _colors[i]; }
- //@}
-
- /** \brief Converts the color into a SDL_Color structure
- *** \return A new SDL_Color with the four uint8 values ranging from 0 to 255
- **/
- SDL_Color CreateSDLColor()
- {
- SDL_Color sdl_color;
- sdl_color.r = static_cast<uint8>(_colors[0] * 0xFF);
- sdl_color.g = static_cast<uint8>(_colors[1] * 0xFF);
- sdl_color.b = static_cast<uint8>(_colors[2] * 0xFF);
- sdl_color.unused = static_cast<uint8>(_colors[3] * 0xFF);
- return sdl_color;
- }
-
- //! \brief Class member access functions
- //@{
- const float* GetColors() const
- { return _colors; }
-
- float GetRed() const
- { return _colors[0]; }
-
- float GetGreen() const
- { return _colors[1]; }
-
- float GetBlue() const
- { return _colors[2]; }
-
- float GetAlpha() const
- { return _colors[3]; }
-
- void SetRed(float r)
- { _colors[0] = r; if (_colors[0] > 1.0f) _colors[0] = 1.0f; else if (_colors[0] < 0.0f) _colors[0] = 0.0f; }
-
- void SetGreen(float g)
- { _colors[1] = g; if (_colors[1] > 1.0f) _colors[1] = 1.0f; else if (_colors[1] < 0.0f) _colors[1] = 0.0f; }
-
- void SetBlue(float b)
- { _colors[2] = b; if (_colors[2] > 1.0f) _colors[2] = 1.0f; else if (_colors[2] < 0.0f) _colors[2] = 0.0f; }
-
- void SetAlpha(float a)
- { _colors[3] = a; if (_colors[3] > 1.0f) _colors[3] = 1.0f; else if (_colors[3] < 0.0f) _colors[3] = 0.0f; }
- //@}
+ /** \brief Default colors for user convenience.
+ *** These are defined in the file video.cpp. All colors are opaque (1.0f alpha value) except for "clear".
+ **/
+ //@{
+ static Color clear; //!< Clear (transparent) color (r=0.0, g=0.0, b=0.0, a=0.0)
+ static Color white; //!< White color (r=1.0, g=1.0, b=1.0, a=1.0)
+ static Color gray; //!< Gray color (r=0.5, g=0.5, b=0.5, a=1.0)
+ static Color black; //!< Black color (r=0.0, g=0.0, b=0.0, a=1.0)
+ static Color red; //!< Red color (r=1.0, g=0.0, b=0.0, a=1.0)
+ static Color orange; //!< Orangecolor (r=1.0, g=0.4, b=0.0, a=1.0)
+ static Color yellow; //!< Yellow color (r=1.0, g=1.0, b=0.0, a=1.0)
+ static Color green; //!< Green color (r=0.0, g=1.0, b=0.0, a=1.0)
+ static Color aqua; //!< Aqua color (r=0.0, g=1.0, b=1.0, a=1.0)
+ static Color blue; //!< Blue color (r=0.0, g=0.0, b=1.0, a=1.0)
+ static Color violet; //!< Violet color (r=1.0, g=0.0, b=1.0, a=1.0)
+ static Color brown; //!< Brown color (r=0.6, g=0.3, b=0.1, a=1.0)
+ //@}
+
+ Color() {
+ _colors[0] = 0.0f;
+ _colors[1] = 0.0f;
+ _colors[2] = 0.0f;
+ _colors[3] = 1.0f;
+ }
+
+ Color(float r, float g, float b, float a) {
+ _colors[0] = r;
+ _colors[1] = g;
+ _colors[2] = b;
+ _colors[3] = a;
+ }
+
+ //! \brief Overloaded Operators
+ //@{
+ bool operator == (const Color &c) const {
+ return (hoa_utils::IsFloatEqual(_colors[0], c._colors[0]) && hoa_utils::IsFloatEqual(_colors[1], c._colors[1]) &&
+ hoa_utils::IsFloatEqual(_colors[2], c._colors[2]) && hoa_utils::IsFloatEqual(_colors[3], c._colors[3]));
+ }
+
+ bool operator != (const Color &c) const {
+ return _colors[0] != c._colors[0] || _colors[1] != c._colors[1] || _colors[2] != c._colors[2] || _colors[3] != c._colors[3];
+ }
+
+ Color operator + (const Color &c) const {
+ Color col = Color(_colors[0] + c._colors[0], _colors[1] + c._colors[1], _colors[2] + c._colors[2], _colors[3] + c._colors[3]);
+ if(col[0] > 1.0f) col[0] = 1.0f;
+ else if(col[0] < 0.0f) col[0] = 0.0f;
+ if(col[1] > 1.0f) col[1] = 1.0f;
+ else if(col[1] < 0.0f) col[1] = 0.0f;
+ if(col[2] > 1.0f) col[2] = 1.0f;
+ else if(col[2] < 0.0f) col[2] = 0.0f;
+ if(col[3] > 1.0f) col[3] = 1.0f;
+ else if(col[3] < 0.0f) col[3] = 0.0f;
+ return col;
+ }
+
+ Color &operator *= (const Color &c) {
+ _colors[0] *= c._colors[0];
+ _colors[1] *= c._colors[1];
+ _colors[2] *= c._colors[2];
+ _colors[3] *= c._colors[3];
+ return *this;
+ }
+
+ Color operator * (const Color &c) const {
+ return Color(_colors[0] * c._colors[0], _colors[1] * c._colors[1], _colors[2] * c._colors[2], _colors[3] * c._colors[3]);
+ }
+
+ Color operator * (float f) const {
+ return Color(_colors[0] * f, _colors[1] * f, _colors[2] * f, _colors[3]);
+ }
+
+ /** \note No checking of array bounds are done here for efficiency reasons. If safety is a concern, use the
+ *** class member access functions instead.
+ **/
+ float &operator[](int32 i) {
+ return _colors[i];
+ }
+
+ /** \note No checking of array bounds are done here for efficiency reasons. If safety is a concern, use the
+ *** class member access functions instead.
+ **/
+ const float &operator[](int32 i) const {
+ return _colors[i];
+ }
+ //@}
+
+ /** \brief Converts the color into a SDL_Color structure
+ *** \return A new SDL_Color with the four uint8 values ranging from 0 to 255
+ **/
+ SDL_Color CreateSDLColor() {
+ SDL_Color sdl_color;
+ sdl_color.r = static_cast<uint8>(_colors[0] * 0xFF);
+ sdl_color.g = static_cast<uint8>(_colors[1] * 0xFF);
+ sdl_color.b = static_cast<uint8>(_colors[2] * 0xFF);
+ sdl_color.unused = static_cast<uint8>(_colors[3] * 0xFF);
+ return sdl_color;
+ }
+
+ //! \brief Class member access functions
+ //@{
+ const float *GetColors() const {
+ return _colors;
+ }
+
+ float GetRed() const {
+ return _colors[0];
+ }
+
+ float GetGreen() const {
+ return _colors[1];
+ }
+
+ float GetBlue() const {
+ return _colors[2];
+ }
+
+ float GetAlpha() const {
+ return _colors[3];
+ }
+
+ void SetRed(float r) {
+ _colors[0] = r;
+ if(_colors[0] > 1.0f) _colors[0] = 1.0f;
+ else if(_colors[0] < 0.0f) _colors[0] = 0.0f;
+ }
+
+ void SetGreen(float g) {
+ _colors[1] = g;
+ if(_colors[1] > 1.0f) _colors[1] = 1.0f;
+ else if(_colors[1] < 0.0f) _colors[1] = 0.0f;
+ }
+
+ void SetBlue(float b) {
+ _colors[2] = b;
+ if(_colors[2] > 1.0f) _colors[2] = 1.0f;
+ else if(_colors[2] < 0.0f) _colors[2] = 0.0f;
+ }
+
+ void SetAlpha(float a) {
+ _colors[3] = a;
+ if(_colors[3] > 1.0f) _colors[3] = 1.0f;
+ else if(_colors[3] < 0.0f) _colors[3] = 0.0f;
+ }
+ //@}
private:
- /** \brief The four RGBA values that represent the color
- *** These values range from 0.0 to 1.0. The indeces of the array represent:
- *** red, green, blue, and alpha in that order.
- **/
- float _colors[4];
+ /** \brief The four RGBA values that represent the color
+ *** These values range from 0.0 to 1.0. The indeces of the array represent:
+ *** red, green, blue, and alpha in that order.
+ **/
+ float _colors[4];
}; // class Color
} // namespace hoa_video
View
37 src/engine/video/context.h
@@ -20,9 +20,11 @@
#include "coord_sys.h"
#include "screen_rect.h"
-namespace hoa_video {
+namespace hoa_video
+{
-namespace private_video {
+namespace private_video
+{
/** ****************************************************************************
*** \brief Retains the current graphics context.
@@ -38,28 +40,29 @@ namespace private_video {
*** \note Transformations are actually handled separately by the OpenGL
*** transformation stack
*** ***************************************************************************/
-class Context {
+class Context
+{
public:
- //! \brief Flag to indicate whether normal alpha blending is to take place.
- int8 blend;
+ //! \brief Flag to indicate whether normal alpha blending is to take place.
+ int8 blend;
- //! \brief Draw alignment flags to determine where an element is drawn relative to the cursor.
- int8 x_align, y_align;
+ //! \brief Draw alignment flags to determine where an element is drawn relative to the cursor.
+ int8 x_align, y_align;
- //! \brief Draw flip flags to determine if an element should be drawn flipped across an axis.
- int8 x_flip, y_flip;
+ //! \brief Draw flip flags to determine if an element should be drawn flipped across an axis.
+ int8 x_flip, y_flip;
- //! \brief The coordinate system being used by this context.
- CoordSys coordinate_system;
+ //! \brief The coordinate system being used by this context.
+ CoordSys coordinate_system;
- //! \brief Defines the screen subset to draw the graphics into.
- ScreenRect viewport;
+ //! \brief Defines the screen subset to draw the graphics into.
+ ScreenRect viewport;
- //! \brief A rectangle to define which portions of the viewport should be cut away when drawing.
- ScreenRect scissor_rectangle;
+ //! \brief A rectangle to define which portions of the viewport should be cut away when drawing.
+ ScreenRect scissor_rectangle;
- //! \brief Used to enable or disable the scissoring rectangle.
- bool scissoring_enabled;
+ //! \brief Used to enable or disable the scissoring rectangle.
+ bool scissoring_enabled;
}; // class Context
} // namespace private_video
View
124 src/engine/video/coord_sys.h
@@ -20,7 +20,8 @@
#include <cmath>
-namespace hoa_video {
+namespace hoa_video
+{
/** ****************************************************************************
*** \brief Determines the drawing coordinates
@@ -32,64 +33,79 @@ namespace hoa_video {
*** \note The default coordinate system is (0, 1024, 0, 768), which is the same
*** as the game's default 1024x768 resolution.
*** ***************************************************************************/
-class CoordSys {
+class CoordSys
+{
public:
- CoordSys()
- {}
-
- CoordSys(float left, float right, float bottom, float top)
- {
- _left = left; _right = right; _bottom = bottom; _top = top;
- if (_right > _left) _horizontal_direction = 1.0f; else _horizontal_direction = -1.0f;
- if (_top > _bottom) _vertical_direction = 1.0f; else _vertical_direction = -1.0f;
- }
-
- //! \brief Class member access functions
- //@{
- float GetVerticalDirection() const
- { return _vertical_direction; }
-
- float GetHorizontalDirection() const
- { return _horizontal_direction; }
-
- float GetLeft() const
- { return _left; }
-
- float GetRight() const
- { return _right; }
-
- float GetBottom() const
- { return _bottom; }
-
- float GetTop() const
- { return _top; }
-
- float GetWidth() const
- { return std::fabs(_left - _right); }
-
- float GetHeight() const
- { return std::fabs(_top - _bottom); }
- //@}
-
- //! \brief Normalisation functions
- //@{
- void ConvertNormalisedToLocal(float& localX, float& localY, float normalisedX, float normalisedY) const
- { localX = _left + normalisedX * (_right - _left);
- localY = _bottom + normalisedY * (_top - _bottom); }
- void ConvertLocalToNormalised(float& normalisedX, float& normalisedY, float localX, float localY) const
- { normalisedX = (_left - localX) / (_right - _left);
- normalisedY = (_bottom - localY) / (_top - _bottom); }
- //@}
+ CoordSys()
+ {}
+
+ CoordSys(float left, float right, float bottom, float top) {
+ _left = left;
+ _right = right;
+ _bottom = bottom;
+ _top = top;
+ if(_right > _left) _horizontal_direction = 1.0f;
+ else _horizontal_direction = -1.0f;
+ if(_top > _bottom) _vertical_direction = 1.0f;
+ else _vertical_direction = -1.0f;
+ }
+
+ //! \brief Class member access functions
+ //@{
+ float GetVerticalDirection() const {
+ return _vertical_direction;
+ }
+
+ float GetHorizontalDirection() const {
+ return _horizontal_direction;
+ }
+
+ float GetLeft() const {
+ return _left;
+ }
+
+ float GetRight() const {
+ return _right;
+ }
+
+ float GetBottom() const {
+ return _bottom;
+ }
+
+ float GetTop() const {
+ return _top;
+ }
+
+ float GetWidth() const {
+ return std::fabs(_left - _right);
+ }
+
+ float GetHeight() const {
+ return std::fabs(_top - _bottom);
+ }
+ //@}
+
+ //! \brief Normalisation functions
+ //@{
+ void ConvertNormalisedToLocal(float &localX, float &localY, float normalisedX, float normalisedY) const {
+ localX = _left + normalisedX * (_right - _left);
+ localY = _bottom + normalisedY * (_top - _bottom);
+ }
+ void ConvertLocalToNormalised(float &normalisedX, float &normalisedY, float localX, float localY) const {
+ normalisedX = (_left - localX) / (_right - _left);
+ normalisedY = (_bottom - localY) / (_top - _bottom);
+ }
+ //@}
private:
- //! \brief If the y-coordinates increase from bottom to top, this is 1.0f. Otherwise it is -1.0f.
- float _vertical_direction;
+ //! \brief If the y-coordinates increase from bottom to top, this is 1.0f. Otherwise it is -1.0f.
+ float _vertical_direction;
- //! \brief If the y-coordinates increase from left to right, this is 1.0f. Otherwise it is -1.0f.
- float _horizontal_direction;
+ //! \brief If the y-coordinates increase from left to right, this is 1.0f. Otherwise it is -1.0f.
+ float _horizontal_direction;
- //! \brief The values of the four sides of the screen that determine the drawing coordinates.
- float _left, _right, _bottom, _top;
+ //! \brief The values of the four sides of the screen that determine the drawing coordinates.
+ float _left, _right, _bottom, _top;
}; // class CoordSys
} // namespace hoa_video
View
210 src/engine/video/fade.cpp
@@ -22,125 +22,123 @@
using namespace hoa_utils;
using namespace hoa_mode_manager;
-namespace hoa_video {
+namespace hoa_video
+{
-namespace private_video {
+namespace private_video
+{
ScreenFader::ScreenFader() :
- _current_color(0.0f, 0.0f, 0.0f, 0.0f),
- _initial_color(0.0f, 0.0f, 0.0f, 0.0f),
- _final_color(0.0f, 0.0f, 0.0f, 0.0f),
- _current_time(0),
- _end_time(0),
- _is_fading(false),
- _use_fade_overlay(false),
- _fade_overlay_color(0.0f, 0.0f, 0.0f, 0.0f),
- _fade_modulation(1.0f),
- _interpolate_rgb_values(false),
- _transitional_fading(false)
+ _current_color(0.0f, 0.0f, 0.0f, 0.0f),
+ _initial_color(0.0f, 0.0f, 0.0f, 0.0f),
+ _final_color(0.0f, 0.0f, 0.0f, 0.0f),
+ _current_time(0),
+ _end_time(0),
+ _is_fading(false),
+ _use_fade_overlay(false),
+ _fade_overlay_color(0.0f, 0.0f, 0.0f, 0.0f),
+ _fade_modulation(1.0f),
+ _interpolate_rgb_values(false),
+ _transitional_fading(false)
{}
-void ScreenFader::BeginFade(const Color& final, uint32 time, bool transitional) {
- // If last fade is made by the system, don't permit to fade:
- if (!transitional && _is_fading && _transitional_fading)
- return;
-
- _transitional_fading = transitional;
- _is_fading = true;
-
- _end_time = time;
-
- _initial_color = _current_color;
- _final_color = final;
- _current_time = 0;
-
- // Figure out if this is a simple fade or if an overlay is required
- // A simple fade is defined as a fade from clear to black, from black
- // to clear, or from somewhere between clear and black to either clear
- // or black. More simply, it's a fade where both the initial and final
- // color's RGB values are zeroed out
-
- _use_fade_overlay = true;
-
- if ((IsFloatEqual(_initial_color[0], 0.0f) && IsFloatEqual(_initial_color[1], 0.0f)
- && IsFloatEqual(_initial_color[2], 0.0f) && IsFloatEqual(_final_color[0], 0.0f)
- && IsFloatEqual(_final_color[1], 0.0f) && IsFloatEqual(_final_color[2], 0.0f)))
- {
- _use_fade_overlay = false;
- }
- else {
- _fade_modulation = 1.0f;
- }
-
- // If we are fading to or from transparent, then the RGB values do not need to be interpolated
- if (IsFloatEqual(_final_color[3], 0.0f)) {
- _interpolate_rgb_values = true;
- _current_color[0] = _initial_color[0];
- _current_color[1] = _initial_color[1];
- _current_color[2] = _initial_color[2];
- }
- else if (IsFloatEqual(_initial_color[3], 0.0f)) {
- _interpolate_rgb_values = true;
- _current_color[0] = _final_color[0];
- _current_color[1] = _final_color[1];
- _current_color[2] = _final_color[2];
- }
- else {
- _interpolate_rgb_values = false;
- }
-
- Update(0); // Do an initial update
+void ScreenFader::BeginFade(const Color &final, uint32 time, bool transitional)
+{
+ // If last fade is made by the system, don't permit to fade:
+ if(!transitional && _is_fading && _transitional_fading)
+ return;
+
+ _transitional_fading = transitional;
+ _is_fading = true;
+
+ _end_time = time;
+
+ _initial_color = _current_color;
+ _final_color = final;
+ _current_time = 0;
+
+ // Figure out if this is a simple fade or if an overlay is required
+ // A simple fade is defined as a fade from clear to black, from black
+ // to clear, or from somewhere between clear and black to either clear
+ // or black. More simply, it's a fade where both the initial and final
+ // color's RGB values are zeroed out
+
+ _use_fade_overlay = true;
+
+ if((IsFloatEqual(_initial_color[0], 0.0f) && IsFloatEqual(_initial_color[1], 0.0f)
+ && IsFloatEqual(_initial_color[2], 0.0f) && IsFloatEqual(_final_color[0], 0.0f)
+ && IsFloatEqual(_final_color[1], 0.0f) && IsFloatEqual(_final_color[2], 0.0f))) {
+ _use_fade_overlay = false;
+ } else {
+ _fade_modulation = 1.0f;
+ }
+
+ // If we are fading to or from transparent, then the RGB values do not need to be interpolated
+ if(IsFloatEqual(_final_color[3], 0.0f)) {
+ _interpolate_rgb_values = true;
+ _current_color[0] = _initial_color[0];
+ _current_color[1] = _initial_color[1];
+ _current_color[2] = _initial_color[2];
+ } else if(IsFloatEqual(_initial_color[3], 0.0f)) {
+ _interpolate_rgb_values = true;
+ _current_color[0] = _final_color[0];
+ _current_color[1] = _final_color[1];
+ _current_color[2] = _final_color[2];
+ } else {
+ _interpolate_rgb_values = false;
+ }
+
+ Update(0); // Do an initial update
} // void ScreenFader::BeginFade(const Color &final, uint32 time)
-void ScreenFader::Update(uint32 time) {
- if (!_is_fading)
- return;
- // TODO: Remove the video manager need from the editor build
+void ScreenFader::Update(uint32 time)
+{
+ if(!_is_fading)
+ return;
+ // TODO: Remove the video manager need from the editor build
#ifndef EDITOR_BUILD // Avoid a useless dependency on the mode manager for the editor build
- // Don't update fading while in pause
- if (ModeManager->GetGameType() == MODE_MANAGER_PAUSE_MODE)
- return;
+ // Don't update fading while in pause
+ if(ModeManager->GetGameType() == MODE_MANAGER_PAUSE_MODE)
+ return;
#endif
- // Check for fading finish condition
- if (_current_time >= _end_time) {
- _current_color = _final_color;
- _is_fading = false;
-
- if (_use_fade_overlay) {
- // Check if we have faded to black or clear. If so, we can use modulation
- if (IsFloatEqual(_final_color[3], 0.0f) || (IsFloatEqual(_final_color[0], 0.0f)
- && IsFloatEqual(_final_color[1], 0.0f) && IsFloatEqual(_final_color[2], 0.0f)))
- {
- _use_fade_overlay = false;
- _fade_modulation = 1.0f - _final_color[3];
- }
- }
- else
- _fade_modulation = 1.0f - _final_color[3];
-
- return;
- }
-
- // Calculate the new interpolated color
- float percent_complete = static_cast<float>(_current_time) / static_cast<float>(_end_time);
-
- if (_interpolate_rgb_values == true) {
- _current_color[0] = Lerp(percent_complete, _initial_color[0], _final_color[0]);
- _current_color[1] = Lerp(percent_complete, _initial_color[1], _final_color[1]);
- _current_color[2] = Lerp(percent_complete, _initial_color[2], _final_color[2]);
- }
- _current_color[3] = Lerp(percent_complete, _initial_color[3], _final_color[3]);
-
- if (_use_fade_overlay == false)
- _fade_modulation = 1.0f - _current_color[3];
- else
- _fade_overlay_color = _current_color;
-
- _current_time += time;
+ // Check for fading finish condition
+ if(_current_time >= _end_time) {
+ _current_color = _final_color;
+ _is_fading = false;
+
+ if(_use_fade_overlay) {
+ // Check if we have faded to black or clear. If so, we can use modulation
+ if(IsFloatEqual(_final_color[3], 0.0f) || (IsFloatEqual(_final_color[0], 0.0f)
+ && IsFloatEqual(_final_color[1], 0.0f) && IsFloatEqual(_final_color[2], 0.0f))) {
+ _use_fade_overlay = false;
+ _fade_modulation = 1.0f - _final_color[3];
+ }
+ } else
+ _fade_modulation = 1.0f - _final_color[3];
+
+ return;
+ }
+
+ // Calculate the new interpolated color
+ float percent_complete = static_cast<float>(_current_time) / static_cast<float>(_end_time);
+
+ if(_interpolate_rgb_values == true) {
+ _current_color[0] = Lerp(percent_complete, _initial_color[0], _final_color[0]);
+ _current_color[1] = Lerp(percent_complete, _initial_color[1], _final_color[1]);
+ _current_color[2] = Lerp(percent_complete, _initial_color[2], _final_color[2]);
+ }
+ _current_color[3] = Lerp(percent_complete, _initial_color[3], _final_color[3]);
+
+ if(_use_fade_overlay == false)
+ _fade_modulation = 1.0f - _current_color[3];
+ else
+ _fade_overlay_color = _current_color;
+
+ _current_time += time;
} // void FadeScreen::Update(uint32 time)
} // namespace private_video
View
151 src/engine/video/fade.h
@@ -18,9 +18,11 @@
#include "color.h"
-namespace hoa_video {
+namespace hoa_video
+{
-namespace private_video {
+namespace private_video
+{
/** ****************************************************************************
*** \brief Used to monitor progress for a fading screen.
@@ -32,87 +34,96 @@ namespace private_video {
*** \note Fades are either implemented with overlays or with modulation, depending
*** on whether it's a simple fade to black or a fade to a different color.
*** ***************************************************************************/
-class ScreenFader {
+class ScreenFader
+{
public:
- ScreenFader();
-
- /** \brief Begins a new screen fading process
- *** \param final The color to fade the screen to.
- *** \param time The number of milliseconds that the fade should last for.
- *** \param transitional whether the fading is done between two game modes.
- **/
- void BeginFade(const Color &final, uint32 time, bool transitional = false);
-
- /** \brief Updates the amount of fading for the screen
- *** \param time The number of milliseconds that have passed since last update.
- **/
- void Update(uint32 time);
-
- //! \brief Class Member Accessor Functions
- bool ShouldUseFadeOverlay() const
- { return _use_fade_overlay; }
-
- Color GetFadeOverlayColor() const
- { return _fade_overlay_color; }
-
- float GetFadeModulation() const
- { return _fade_modulation; }
-
- bool IsFading() const
- { return _is_fading; }
-
- /** \brief start a fade used as a transition between two game modes.
- *** It's a simple fade but flagged as special to let the mode manager handle it.
- **/
- void StartTransitionFadeOut(const Color &final, uint32 time)
- { BeginFade(final, time, true); }
-
- //! \brief A shortcut function used to make a fade in more explicitely.
- void TransitionalFadeIn(uint32 time)
- { BeginFade(Color::clear, time, true); }
-
- //! \brief A shortcut function used to make a fade in more explicitely.
- void FadeIn(uint32 time)
- { BeginFade(Color::clear, time); }
-
- //! \brief tells whether the last fade effect was transitional.
- bool IsLastFadeTransitional() const
- { return _transitional_fading; }
+ ScreenFader();
+
+ /** \brief Begins a new screen fading process
+ *** \param final The color to fade the screen to.
+ *** \param time The number of milliseconds that the fade should last for.
+ *** \param transitional whether the fading is done between two game modes.
+ **/
+ void BeginFade(const Color &final, uint32 time, bool transitional = false);
+
+ /** \brief Updates the amount of fading for the screen
+ *** \param time The number of milliseconds that have passed since last update.
+ **/
+ void Update(uint32 time);
+
+ //! \brief Class Member Accessor Functions
+ bool ShouldUseFadeOverlay() const {
+ return _use_fade_overlay;
+ }
+
+ Color GetFadeOverlayColor() const {
+ return _fade_overlay_color;
+ }
+
+ float GetFadeModulation() const {
+ return _fade_modulation;
+ }
+
+ bool IsFading() const {
+ return _is_fading;
+ }
+
+ /** \brief start a fade used as a transition between two game modes.
+ *** It's a simple fade but flagged as special to let the mode manager handle it.
+ **/
+ void StartTransitionFadeOut(const Color &final, uint32 time) {
+ BeginFade(final, time, true);
+ }
+
+ //! \brief A shortcut function used to make a fade in more explicitely.
+ void TransitionalFadeIn(uint32 time) {
+ BeginFade(Color::clear, time, true);
+ }
+
+ //! \brief A shortcut function used to make a fade in more explicitely.
+ void FadeIn(uint32 time) {
+ BeginFade(Color::clear, time);
+ }
+
+ //! \brief tells whether the last fade effect was transitional.
+ bool IsLastFadeTransitional() const {
+ return _transitional_fading;
+ }
private:
- //! \brief The color that the screen is currently faded to.
- Color _current_color;
+ //! \brief The color that the screen is currently faded to.
+ Color _current_color;
- //! \brief The initial color of the screen before the fade started.
- Color _initial_color;
+ //! \brief The initial color of the screen before the fade started.
+ Color _initial_color;
- //! \brief The destination color that the screen is being fade to.
- Color _final_color;
+ //! \brief The destination color that the screen is being fade to.
+ Color _final_color;
- //! \brief The number of milliseconds that have passed since the fading began.
- uint32 _current_time;
+ //! \brief The number of milliseconds that have passed since the fading began.
+ uint32 _current_time;
- //! \brief The number of milliseconds that this fade was set to last for.
- uint32 _end_time;
+ //! \brief The number of milliseconds that this fade was set to last for.
+ uint32 _end_time;
- //! \brief True if the class is currently in the process of fading
- bool _is_fading;
+ //! \brief True if the class is currently in the process of fading
+ bool _is_fading;
- //! \brief Set to true if using an overlay, false if using modulation.
- bool _use_fade_overlay;
+ //! \brief Set to true if using an overlay, false if using modulation.
+ bool _use_fade_overlay;
- //! \brief Color of the overlay, if one is being used.
- Color _fade_overlay_color;
+ //! \brief Color of the overlay, if one is being used.
+ Color _fade_overlay_color;
- //! \brief A float determining the degree of modulation.
- float _fade_modulation;
+ //! \brief A float determining the degree of modulation.
+ float _fade_modulation;
- //! \brief Set to true if the fading process requires interpolation of RGB values between colors
- bool _interpolate_rgb_values;
+ //! \brief Set to true if the fading process requires interpolation of RGB values between colors
+ bool _interpolate_rgb_values;
- //! \brief Tells whether the current fading is used to make a transition between two game mode.
- bool _transitional_fading;
- //@}
+ //! \brief Tells whether the current fading is used to make a transition between two game mode.
+ bool _transitional_fading;
+ //@}
}; // class ScreenFader
} // namespace private_video
View
2,971 src/engine/video/image.cpp
1,504 additions, 1,467 deletions not shown
View
1,487 src/engine/video/image.h
@@ -49,11 +49,13 @@
#include "image_base.h"
struct U;
-namespace hoa_mode_manager {
+namespace hoa_mode_manager
+{
class ParticleSystem;
}
-namespace hoa_video {
+namespace hoa_video
+{
class StillImage;
@@ -84,251 +86,260 @@ class StillImage;
*** it from any container in the TextureManager class, so that is up to the
*** destructors of the derived classes to implement.
*** ***************************************************************************/
-class ImageDescriptor {
- friend class VideoEngine;
+class ImageDescriptor
+{
+ friend class VideoEngine;
public:
- ImageDescriptor();
-
- virtual ~ImageDescriptor();
-
- ImageDescriptor(const ImageDescriptor& copy);
-
- ImageDescriptor& operator=(const ImageDescriptor& copy);
-
- //! \brief Clears all data retained by the object (color, width, height, etc.)
- virtual void Clear() = 0;
-
- /** \brief Draws the image to the display buffer
- *** The location and orientation of the drawn image is dependent upon the current cursor position
- *** and context (draw flags) set in the VideoEngine class.
- **/
- virtual void Draw() const = 0;
-
- /** \brief Draws a color modulated version of the image to the display buffer
- *** \param draw_color The color to modulate the image by
- **/
- virtual void Draw(const Color& draw_color) const = 0;
-
- //! \name Class Member Access Functions
- //@{
- //! \brief Returns the image width
- virtual float GetWidth() const
- { return _width; }
-
- //! \brief Returns image height
- virtual float GetHeight() const
- { return _height; }
-
- //! \brief Set whether the image should be drawn smoothed.
- void Smooth(bool smooth)
- { _smooth = smooth; }
-
- //! \brief Returns true if the image is grayscale.
- bool IsGrayScale() const
- { return _grayscale; }
-
- virtual void EnableGrayScale() = 0;
-
- virtual void DisableGrayScale() = 0;
-
- /** \brief Enables or disables the image's static property
- *** \param is_static If true, the image will be made static
- **/
- virtual void SetStatic(bool is_static) = 0;
-
- /** \brief Sets the image's width, expressed as coordinate system units
- *** \param width The desired width of the image
- **/
- virtual void SetWidth(float width) = 0;
-
- /** \brief Sets the image's height, expressed as coordinate system units
- *** \param height The desired height of the image
- **/
- virtual void SetHeight(float height) = 0;
-
- /** \brief Sets the image's dimensions, expressed as coordinate system units
- *** \param width The desired width of the image
- *** \param height The desired height of the image
- **/
- virtual void SetDimensions(float width, float height) = 0;
-
- /** \brief Sets the UV coordinates for the image
- *** \param u1 First u coordinate
- *** \param v1 First v coordinate
- *** \param u2 Second u coordinate
- *** \param v2 Second v coordinate
- ***
- *** This method rarely needs to be called, as the default UV coordinates suffice
- *** for nearly all images.
- **/
- virtual void SetUVCoordinates(float u1, float v1, float u2, float v2)
- { _u1 = u1; _v1 = v1; _u2 = u2; _v2 = v2; }
-
- /** \brief Sets the image's four vertices to a single color
- *** \param color The desired color of all image vertices
- **/
- virtual void SetColor(const Color& color);
-
- /** \brief Sets the image's vertex colors
- *** \param tl The top left vertex color
- *** \param tr The top right vertex color
- *** \param bl The bottom left vertex color
- *** \param br The bottom right vertex color
- **/
- virtual void SetVertexColors(const Color& tl, const Color& tr, const Color& bl, const Color& br);
- //@}
-
- /** \name Static Image Manipulation Functions
- *** This series of static functions provide additional image mainpulation that does not operate
- *** on a single instance of a derived image type.
- **/
- //@{
- /** \brief Retrieves various properties about an image file
- *** \param filename The name of the image file (.png or .jpg) to retrieve the properties of
- *** \param rows The number of rows of pixels in the image
- *** \param cols The number of columns of pixels in the image
- *** \param bpp The number of bits per pixel of the image
- *** \throw Exception If any of the properties are not retrieved successfully
- **/
- static void GetImageInfo(const std::string& filename, uint32& rows, uint32& cols, uint32& bpp) throw(hoa_utils::Exception);
-
- /** \brief Loads a multi image into a vector of StillImage objects
- *** \param images Reference to the vector of StillImages to be loaded with elements from the multi image
- *** \param filename The name of the multi image file to load the image data from
- *** \param elem_width The width of each sub-image element, in pixels
- *** \param elem_height The height of each sub-image element, in pixels
- *** \return True upon successful loading, false if there was an error
- ***
- *** This function determines the image elements to extract from the multi image by the width and height
- *** of each element (in pixels) specified in the function arguments. Upon success, the size of the images
- *** reference vector will always be equal to the area of the multi image divided by the area of each
- *** element image.
- *** \note All image elements within the multi image should be of the same size
- */
- static bool LoadMultiImageFromElementSize(std::vector<StillImage>& images, const std::string& filename,
- const uint32 elem_width, const uint32 elem_height);
-
- /** \brief Loads a multi image into a vector of StillImage objects
- *** \param images Reference to the vector of StillImages to be loaded with elements from the multi image
- *** \param filename The name of the multi image file to load the image data from
- *** \param grid_rows The number of rows of image elements contained in the multi image
- *** \param grid_cols The number of columns of image elements contained in the multi image
- *** \return True upon successful loading, false if there was an error
- ***
- *** This function determines the image elements to extract from dividing the multi image into a number
- *** of rows and columns, as given through the function's arguments. Upon success, the size of the images
- *** reference vector will always be equal to grid_rows * grid_cols.
- *** \note All image elements within the multi image should be of the same size
- **/
- static bool LoadMultiImageFromElementGrid(std::vector<StillImage>& images, const std::string& filename,
- const uint32 grid_rows, const uint32 grid_cols);
-
- /** \brief Saves a vector of images into a single image file (a multi image)
- *** \param images A reference to the vector of StillImage pointers to save into a multi image
- *** \param filename The name of the multi image file to write (.png of .jpg extension required)
- *** \param grid_rows The number of rows of sub-images in the MultiImage.
- *** \param grid_cols Number of columns of sub-images in the MultiImage.
- *** \return True upon successful loading, false if there was an error
- *** \note All images within the images vector should be of the same size
- **/
- static bool SaveMultiImage(const std::vector<StillImage*>& images, const std::string& filename,
- const uint32 grid_rows, const uint32 grid_cols);
- //@}
-
- //! \brief A debug function which prints the image's information to the screen
- void DEBUG_PrintInfo();
+ ImageDescriptor();
+
+ virtual ~ImageDescriptor();
+
+ ImageDescriptor(const ImageDescriptor &copy);
+
+ ImageDescriptor &operator=(const ImageDescriptor &copy);
+
+ //! \brief Clears all data retained by the object (color, width, height, etc.)
+ virtual void Clear() = 0;
+
+ /** \brief Draws the image to the display buffer
+ *** The location and orientation of the drawn image is dependent upon the current cursor position
+ *** and context (draw flags) set in the VideoEngine class.
+ **/
+ virtual void Draw() const = 0;
+
+ /** \brief Draws a color modulated version of the image to the display buffer
+ *** \param draw_color The color to modulate the image by
+ **/
+ virtual void Draw(const Color &draw_color) const = 0;
+
+ //! \name Class Member Access Functions
+ //@{
+ //! \brief Returns the image width
+ virtual float GetWidth() const {
+ return _width;
+ }
+
+ //! \brief Returns image height
+ virtual float GetHeight() const {
+ return _height;
+ }
+
+ //! \brief Set whether the image should be drawn smoothed.
+ void Smooth(bool smooth) {
+ _smooth = smooth;
+ }
+
+ //! \brief Returns true if the image is grayscale.
+ bool IsGrayScale() const {
+ return _grayscale;
+ }
+
+ virtual void EnableGrayScale() = 0;
+
+ virtual void DisableGrayScale() = 0;
+
+ /** \brief Enables or disables the image's static property
+ *** \param is_static If true, the image will be made static
+ **/
+ virtual void SetStatic(bool is_static) = 0;
+
+ /** \brief Sets the image's width, expressed as coordinate system units
+ *** \param width The desired width of the image
+ **/
+ virtual void SetWidth(float width) = 0;
+
+ /** \brief Sets the image's height, expressed as coordinate system units
+ *** \param height The desired height of the image
+ **/
+ virtual void SetHeight(float height) = 0;
+
+ /** \brief Sets the image's dimensions, expressed as coordinate system units
+ *** \param width The desired width of the image
+ *** \param height The desired height of the image
+ **/
+ virtual void SetDimensions(float width, float height) = 0;
+
+ /** \brief Sets the UV coordinates for the image
+ *** \param u1 First u coordinate
+ *** \param v1 First v coordinate
+ *** \param u2 Second u coordinate
+ *** \param v2 Second v coordinate
+ ***
+ *** This method rarely needs to be called, as the default UV coordinates suffice
+ *** for nearly all images.
+ **/
+ virtual void SetUVCoordinates(float u1, float v1, float u2, float v2) {
+ _u1 = u1;
+ _v1 = v1;
+ _u2 = u2;
+ _v2 = v2;
+ }
+
+ /** \brief Sets the image's four vertices to a single color
+ *** \param color The desired color of all image vertices
+ **/
+ virtual void SetColor(const Color &color);
+
+ /** \brief Sets the image's vertex colors
+ *** \param tl The top left vertex color
+ *** \param tr The top right vertex color
+ *** \param bl The bottom left vertex color
+ *** \param br The bottom right vertex color
+ **/
+ virtual void SetVertexColors(const Color &tl, const Color &tr, const Color &bl, const Color &br);
+ //@}
+
+ /** \name Static Image Manipulation Functions
+ *** This series of static functions provide additional image mainpulation that does not operate
+ *** on a single instance of a derived image type.
+ **/
+ //@{
+ /** \brief Retrieves various properties about an image file
+ *** \param filename The name of the image file (.png or .jpg) to retrieve the properties of
+ *** \param rows The number of rows of pixels in the image
+ *** \param cols The number of columns of pixels in the image
+ *** \param bpp The number of bits per pixel of the image
+ *** \throw Exception If any of the properties are not retrieved successfully
+ **/
+ static void GetImageInfo(const std::string &filename, uint32 &rows, uint32 &cols, uint32 &bpp) throw(hoa_utils::Exception);
+
+ /** \brief Loads a multi image into a vector of StillImage objects
+ *** \param images Reference to the vector of StillImages to be loaded with elements from the multi image
+ *** \param filename The name of the multi image file to load the image data from
+ *** \param elem_width The width of each sub-image element, in pixels
+ *** \param elem_height The height of each sub-image element, in pixels
+ *** \return True upon successful loading, false if there was an error
+ ***
+ *** This function determines the image elements to extract from the multi image by the width and height
+ *** of each element (in pixels) specified in the function arguments. Upon success, the size of the images
+ *** reference vector will always be equal to the area of the multi image divided by the area of each
+ *** element image.
+ *** \note All image elements within the multi image should be of the same size
+ */
+ static bool LoadMultiImageFromElementSize(std::vector<StillImage>& images, const std::string &filename,
+ const uint32 elem_width, const uint32 elem_height);
+
+ /** \brief Loads a multi image into a vector of StillImage objects
+ *** \param images Reference to the vector of StillImages to be loaded with elements from the multi image
+ *** \param filename The name of the multi image file to load the image data from
+ *** \param grid_rows The number of rows of image elements contained in the multi image
+ *** \param grid_cols The number of columns of image elements contained in the multi image
+ *** \return True upon successful loading, false if there was an error
+ ***
+ *** This function determines the image elements to extract from dividing the multi image into a number
+ *** of rows and columns, as given through the function's arguments. Upon success, the size of the images
+ *** reference vector will always be equal to grid_rows * grid_cols.
+ *** \note All image elements within the multi image should be of the same size
+ **/
+ static bool LoadMultiImageFromElementGrid(std::vector<StillImage>& images, const std::string &filename,
+ const uint32 grid_rows, const uint32 grid_cols);
+
+ /** \brief Saves a vector of images into a single image file (a multi image)
+ *** \param images A reference to the vector of StillImage pointers to save into a multi image
+ *** \param filename The name of the multi image file to write (.png of .jpg extension required)
+ *** \param grid_rows The number of rows of sub-images in the MultiImage.
+ *** \param grid_cols Number of columns of sub-images in the MultiImage.
+ *** \return True upon successful loading, false if there was an error
+ *** \note All images within the images vector should be of the same size
+ **/
+ static bool SaveMultiImage(const std::vector<StillImage *>& images, const std::string &filename,
+ const uint32 grid_rows, const uint32 grid_cols);
+ //@}
+
+ //! \brief A debug function which prints the image's information to the screen
+ void DEBUG_PrintInfo();
protected:
- /** \brief A pointer to the texture used by the image
- *** The purpose of this member is for the ImageDescriptor class to be able to manage
- **/
- private_video::BaseTexture* _texture;
+ /** \brief A pointer to the texture used by the image
+ *** The purpose of this member is for the ImageDescriptor class to be able to manage
+ **/
+ private_video::BaseTexture *_texture;
- //! \brief The width and height of the image, in coordinate system units.
- float _width, _height;
+ //! \brief The width and height of the image, in coordinate system units.
+ float _width, _height;
- /** \brief The texture coordinates for the image
- *** (u1, v1) represents the upper-left corner while (u2, v2) represents the bottom-right corner. These coordinates
- *** are typically (0.0f, 0.0f), (1.0f, 1.0f) and do not need to be modified except in special cases.
- **/
- float _u1, _v1, _u2, _v2;
+ /** \brief The texture coordinates for the image
+ *** (u1, v1) represents the upper-left corner while (u2, v2) represents the bottom-right corner. These coordinates
+ *** are typically (0.0f, 0.0f), (1.0f, 1.0f) and do not need to be modified except in special cases.
+ **/
+ float _u1, _v1, _u2, _v2;
//! \brief Holds the color of the upper left, upper right, lower left, and lower right vertices, respectively.
- Color _color[4];
-
- //! \brief True indicates to perform blending with this image
- bool _blend;
-
- //! \brief Set to true if all vertices are the same color
- bool _unichrome_vertices;
-
- //! \brief Indicates whether the image being loaded should be loaded into a non-volatile area of texture memory.
- bool _is_static;
-
- //! \brief True if this image is grayscale.
- bool _grayscale;
-
- //! \brief Whether the image should be smoothed.
- bool _smooth;
-
- /** \brief Removes a reference to _texture, and frees or deletes it if it has no remaining references
- ***
- *** This method will set _texture to NULL before returning. If your derived class has a duplicate texture
- *** pointer (ie, ImageTexture pointer for StillImage class), you should make sure to set that member to
- *** NULL as well.
- **/
- void _RemoveTextureReference();
-
- /** \brief A draw helper function which adjusts the draw orientation (translation and scaling)
- ***
- *** \note This method modifies the draw cursor position and does not restore it before finishing. Therefore
- *** under most circumstances, you will want to call VideoManager->PushState()/PopState(), or
- *** glPushMatrix()/glPopMatrix() before and after calling this function. The latter is preferred due to the
- *** lower cost of the call, but some circumstances may require using the former when more state information
- *** needs to be retained.
- **/
- void _DrawOrientation() const;
-
- /** \brief Draws the OpenGL texture referred to by the object on the screen
- *** \param draw_color A non-NULL pointer to an array of four valid Color objects
- ***
- *** This method is typically a helper method to other draw calls in some way. It assumes that
- *** all of the appropriate transformation, scaling, and other image property opertaions have been
- *** completed prior to the calling of this function. The draw_color argument is usually nothing
- *** more than a pointer to the _color member of this very class, but in certain cases like during
- *** a screen fade these colors may differ.
- **/
- void _DrawTexture(const Color* draw_color) const;
+ Color _color[4];
+
+ //! \brief True indicates to perform blending with this image
+ bool _blend;
+
+ //! \brief Set to true if all vertices are the same color
+ bool _unichrome_vertices;
+
+ //! \brief Indicates whether the image being loaded should be loaded into a non-volatile area of texture memory.
+ bool _is_static;
+
+ //! \brief True if this image is grayscale.
+ bool _grayscale;
+
+ //! \brief Whether the image should be smoothed.
+ bool _smooth;
+
+ /** \brief Removes a reference to _texture, and frees or deletes it if it has no remaining references
+ ***
+ *** This method will set _texture to NULL before returning. If your derived class has a duplicate texture
+ *** pointer (ie, ImageTexture pointer for StillImage class), you should make sure to set that member to
+ *** NULL as well.
+ **/
+ void _RemoveTextureReference();
+
+ /** \brief A draw helper function which adjusts the draw orientation (translation and scaling)
+ ***
+ *** \note This method modifies the draw cursor position and does not restore it before finishing. Therefore
+ *** under most circumstances, you will want to call VideoManager->PushState()/PopState(), or
+ *** glPushMatrix()/glPopMatrix() before and after calling this function. The latter is preferred due to the
+ *** lower cost of the call, but some circumstances may require using the former when more state information
+ *** needs to be retained.
+ **/
+ void _DrawOrientation() const;
+
+ /** \brief Draws the OpenGL texture referred to by the object on the screen
+ *** \param draw_color A non-NULL pointer to an array of four valid Color objects
+ ***
+ *** This method is typically a helper method to other draw calls in some way. It assumes that
+ *** all of the appropriate transformation, scaling, and other image property opertaions have been
+ *** completed prior to the calling of this function. The draw_color argument is usually nothing
+ *** more than a pointer to the _color member of this very class, but in certain cases like during
+ *** a screen fade these colors may differ.
+ **/
+ void _DrawTexture(const Color *draw_color) const;
private:
- /** \brief Retrieves various properties about a PNG image file
- *** \param filename The name of the PNG image file to retrieve the properties of
- *** \param rows The number of rows of pixels in the image
- *** \param cols The number of columns of pixels in the image
- *** \param bpp The number of bits per pixel of the image
- *** \throw Exception If any of the properties are not retrieved successfully
- **/
- static void _GetPngImageInfo(const std::string& filename, uint32& rows, uint32& cols, uint32& bpp) throw(hoa_utils::Exception);
-
- /** \brief Retrieves various properties about a JPG image file
- *** \param filename The name of the JPG image file to retrieve the properties of
- *** \param rows The number of rows of pixels in the image
- *** \param cols The number of columns of pixels in the image
- *** \param bpp The number of bits per pixel of the image
- *** \throw Exception If any of the properties are not retrieved successfully
- **/
- static void _GetJpgImageInfo(const std::string& filename, uint32& rows, uint32& cols, uint32& bpp) throw(hoa_utils::Exception);
-
- /** \brief A helper function to the public LoadMultiImage* calls
- *** \param images Reference to the vector of StillImages to be loaded
- *** \param filename The name of the multi image file to read
- *** \param grid_rows The number of rows of image elements in the multi image
- *** \param grid_cols The number of columns of image elements in the multi image
- *** \return True if the image file was loaded and parsed successfully, false if there was an error.
- **/
- static bool _LoadMultiImage(std::vector<StillImage>& images, const std::string& filename,
- const uint32 grid_rows, const uint32 grid_cols);
+ /** \brief Retrieves various properties about a PNG image file
+ *** \param filename The name of the PNG image file to retrieve the properties of
+ *** \param rows The number of rows of pixels in the image
+ *** \param cols The number of columns of pixels in the image
+ *** \param bpp The number of bits per pixel of the image
+ *** \throw Exception If any of the properties are not retrieved successfully
+ **/
+ static void _GetPngImageInfo(const std::string &filename, uint32 &rows, uint32 &cols, uint32 &bpp) throw(hoa_utils::Exception);
+
+ /** \brief Retrieves various properties about a JPG image file
+ *** \param filename The name of the JPG image file to retrieve the properties of
+ *** \param rows The number of rows of pixels in the image
+ *** \param cols The number of columns of pixels in the image
+ *** \param bpp The number of bits per pixel of the image
+ *** \throw Exception If any of the properties are not retrieved successfully
+ **/
+ static void _GetJpgImageInfo(const std::string &filename, uint32 &rows, uint32 &cols, uint32 &bpp) throw(hoa_utils::Exception);
+
+ /** \brief A helper function to the public LoadMultiImage* calls
+ *** \param images Reference to the vector of StillImages to be loaded
+ *** \param filename The name of the multi image file to read
+ *** \param grid_rows The number of rows of image elements in the multi image
+ *** \param grid_cols The number of columns of image elements in the multi image
+ *** \return True if the image file was loaded and parsed successfully, false if there was an error.
+ **/
+ static bool _LoadMultiImage(std::vector<StillImage>& images, const std::string &filename,
+ const uint32 grid_rows, const uint32 grid_cols);
}; // class ImageDescriptor
@@ -339,155 +350,169 @@ class ImageDescriptor {
*** of this class are used in the construction of some of the more advanced image
*** classes.
*** ***************************************************************************/
-class StillImage : public ImageDescriptor {
- friend class VideoEngine;
- friend class ImageDescriptor;
- friend class AnimatedImage;
- friend class CompositeImage;
- friend class TextureController;
- friend class hoa_mode_manager::ParticleSystem;
+class StillImage : public ImageDescriptor
+{
+ friend class VideoEngine;
+ friend class ImageDescriptor;
+ friend class AnimatedImage;
+ friend class CompositeImage;
+ friend class TextureController;
+ friend class hoa_mode_manager::ParticleSystem;
public:
- //! \brief Supply the constructor with "true" if you want this to represent a grayscale image
- StillImage(const bool grayscale = false);
-
- ~StillImage();
-
- //! \brief Resets the image's properties and removes any references to image data that it maintains
- void Clear();
-
- /** \brief Loads a single image file to be represented by the class object
- *** \param filename The filename of the image to load (should have a .png or .jpg extension)
- *** \return True if the image was successfully loaded and is now represented by this object
- ***
- *** \note Invoking this function will clear all image elements currently used by this class.
- *** \note Passing in an emptry string for filename is a special case, and will construct
- *** a colored quad for the image procedurally. It is not an error to pass an empty string to
- *** the function.
- **/
- bool Load(const std::string& filename);
-
- bool Load(const std::string& filename, float width, float height)
- { SetDimensions(width, height); return Load(filename); }
-
- //! \brief Draws the image to the screen
- void Draw() const;
-
- /** \brief Draws a color-modulated version of the image
- *** \param draw_color The color to modulate the image by
- **/
- void Draw(const Color& draw_color) const;
-
- /** \brief Saves the image to a file
- *** \param filename The filename of the image to save (should have a .png or .jpg extension)
- *** \return True if the image was successfully saved to a file
- ***
- *** \note The image being saved should contain only one image element. Support for saving of
- *** composite (multi-element) images is not yet supported
- **/
- bool Save(const std::string& filename) const;
-
- //! \brief Enables grayscaling for the image then reloads it
- void EnableGrayScale();
-
- //! \brief Disables grayscaling for the image then reloads it
- void DisableGrayScale();
-
- //! \name Class Member Access Functions
- //@{
- //! \brief Returns the filename string for the image
- const std::string& GetFilename() const
- { return _filename; }
-
- /** \brief Returns the color of a particular vertex
- *** \param c The Color object to place the color in.
- *** \param index The vertex index of the color to fetch
- *** \note If an invalid index value is used, the function will return with no warning.
- **/
- void GetVertexColor(Color& c, uint8 index)
- { if (index > 3) return; else c = _color[index]; }
-
- /** \brief Sets width of the image
- *** \param width Width of the image
- **/
- void SetWidth(float width)
- { _width = width; }
-
- /** \brief Sets height of the image
- *** \param height Height of the image
- **/
- void SetHeight(float height)
- { _height = height; }
-
- /** \brief Sets width of the image while keeping height ratio.
- *** \param height Width of the image
- **/
- void SetWidthKeepRatio(float width);
-
- /** \brief Sets height of the image while keeping width ratio.
- *** \param height Height of the image
- **/
- void SetHeightKeepRatio(float height);
-
- /** \brief Sets the dimensions of the image for a desired coordinate system
- *** \param width The width of the image
- *** \param height The height of the image
- **/
- void SetDimensions(float width, float height)
- { SetWidth(width); SetHeight(height); }
-
- /** \brief Sets image to static/animated
- *** \param is_static Flag indicating whether the image should be made static or not
- **/
- void SetStatic(bool is_static)
- { _is_static = is_static; }
- //@}
+ //! \brief Supply the constructor with "true" if you want this to represent a grayscale image
+ StillImage(const bool grayscale = false);
+
+ ~StillImage();
+
+ //! \brief Resets the image's properties and removes any references to image data that it maintains
+ void Clear();
+
+ /** \brief Loads a single image file to be represented by the class object
+ *** \param filename The filename of the image to load (should have a .png or .jpg extension)
+ *** \return True if the image was successfully loaded and is now represented by this object
+ ***
+ *** \note Invoking this function will clear all image elements currently used by this class.
+ *** \note Passing in an emptry string for filename is a special case, and will construct
+ *** a colored quad for the image procedurally. It is not an error to pass an empty string to
+ *** the function.
+ **/
+ bool Load(const std::string &filename);
+
+ bool Load(const std::string &filename, float width, float height) {
+ SetDimensions(width, height);
+ return Load(filename);
+ }
+
+ //! \brief Draws the image to the screen
+ void Draw() const;
+
+ /** \brief Draws a color-modulated version of the image
+ *** \param draw_color The color to modulate the image by
+ **/
+ void Draw(const Color &draw_color) const;
+
+ /** \brief Saves the image to a file
+ *** \param filename The filename of the image to save (should have a .png or .jpg extension)
+ *** \return True if the image was successfully saved to a file
+ ***
+ *** \note The image being saved should contain only one image element. Support for saving of
+ *** composite (multi-element) images is not yet supported
+ **/
+ bool Save(const std::string &filename) const;
+
+ //! \brief Enables grayscaling for the image then reloads it
+ void EnableGrayScale();
+
+ //! \brief Disables grayscaling for the image then reloads it
+ void DisableGrayScale();
+
+ //! \name Class Member Access Functions
+ //@{
+ //! \brief Returns the filename string for the image
+ const std::string &GetFilename() const {
+ return _filename;
+ }
+
+ /** \brief Returns the color of a particular vertex
+ *** \param c The Color object to place the color in.
+ *** \param index The vertex index of the color to fetch
+ *** \note If an invalid index value is used, the function will return with no warning.
+ **/
+ void GetVertexColor(Color &c, uint8 index) {
+ if(index > 3) return;
+ else c = _color[index];
+ }
+
+ /** \brief Sets width of the image
+ *** \param width Width of the image
+ **/
+ void SetWidth(float width) {
+ _width = width;
+ }
+
+ /** \brief Sets height of the image
+ *** \param height Height of the image
+ **/
+ void SetHeight(float height) {
+ _height = height;
+ }
+
+ /** \brief Sets width of the image while keeping height ratio.
+ *** \param height Width of the image
+ **/
+ void SetWidthKeepRatio(float width);
+
+ /** \brief Sets height of the image while keeping width ratio.
+ *** \param height Height of the image
+ **/
+ void SetHeightKeepRatio(float height);
+
+ /** \brief Sets the dimensions of the image for a desired coordinate system
+ *** \param width The width of the image
+ *** \param height The height of the image
+ **/
+ void SetDimensions(float width, float height) {
+ SetWidth(width);
+ SetHeight(height);
+ }
+
+ /** \brief Sets image to static/animated
+ *** \param is_static Flag indicating whether the image should be made static or not
+ **/
+ void SetStatic(bool is_static) {
+ _is_static = is_static;
+ }
+ //@}
protected:
- /** \brief The name of the image file from which this image was created
- *** This member is only valid for StillImage objects which had their Load() function
- *** invoked successfully and have no additional elements. This member will be set to
- *** the empty string otherwise.
- **/
- std::string _filename;
-
- //! \brief The texture image that is referenced by this element
- private_video::ImageTexture* _image_texture;
+ /** \brief The name of the image file from which this image was created
+ *** This member is only valid for StillImage objects which had their Load() function
+ *** invoked successfully and have no additional elements. This member will be set to
+ *** the empty string otherwise.
+ **/
+ std::string _filename;
+
+ //! \brief The texture image that is referenced by this element
+ private_video::ImageTexture *_image_texture;
}; // class StillImage : public ImageDescriptor
-namespace private_video {
+namespace private_video
+{
/** ****************************************************************************
*** \brief Represents a single frame in an animation
*** ***************************************************************************/
-class AnimationFrame {
+class AnimationFrame
+{
public:
- //! \brief The amount of time to display this frame, in milliseconds
- uint32 frame_time;
+ //! \brief The amount of time to display this frame, in milliseconds
+ uint32 frame_time;
- //! \brief The StillImage used for this frame in the animation
- StillImage image;
+ //! \brief The StillImage used for this frame in the animation
+ StillImage image;
}; // class AnimationFrame
/** ****************************************************************************
*** \brief Represents a single element in a composite image
*** ***************************************************************************/
-class ImageElement {
+class ImageElement
+{
public:
- ImageElement() :
- x_offset(0.0f), y_offset(0.0f) {}
+ ImageElement() :
+ x_offset(0.0f), y_offset(0.0f) {}
- ImageElement(const StillImage& img, float x, float y) :
- image(img), x_offset(x), y_offset(y) {}
+ ImageElement(const StillImage &img, float x, float y) :
+ image(img), x_offset(x), y_offset(y) {}
- //! \brief The singular image that represents this element
- StillImage image;
+ //! \brief The singular image that represents this element
+ StillImage image;
- //! \brief X and y draw position offsets of this element
- float x_offset, y_offset;
+ //! \brief X and y draw position offsets of this element
+ float x_offset, y_offset;
}; // class ImageElement
} // namespace private_video
@@ -503,275 +528,301 @@ class ImageElement {
*** sized frame images in an animation, you'll need to implement the code
*** to do so yourself.
*** ***************************************************************************/
-class AnimatedImage : public ImageDescriptor {
- friend class VideoEngine;
+class AnimatedImage : public ImageDescriptor
+{
+ friend class VideoEngine;
public:
- //! \brief Supply the constructor with "true" if you want this to represent a grayscale image.
- AnimatedImage(bool grayscale = false);
-
- //! \brief A constructor which also sets the image's dimensions
- AnimatedImage(float width, float height, bool grayscale = false);
-
- //! \brief Resets the image's properties and removes any references to image data that it maintains
- void Clear();
-
- /** \brief Loads an AnimatedImage by opening a multi image file
- *** \param filename The name of the file to load, which should end in a .png or .jpg extension
- *** \param timings A vector reference which holds the timing information for each animation frame
- *** \param frame_width The width (in pixels) of each frame in the multi image file
- *** \param frame_height The height (in pixels) of each frame in the multi image file
- *** \param trim The number of frame images to "ignore" from the multi image (default == 0)
- *** \return True if the animation was successfully constructed from the loaded multi image
- ***
- *** The trim factor must be less than the total number of frames that are stored in the multi image.
- *** The size of the timings vector must be at least (# of frames in multi image - trim). It may
- *** be larger than this, but the rest of the elements beyond the minimum size will be ignored.
- **/
- bool LoadFromFrameSize(const std::string& filename, const std::vector<uint32>& timings, const uint32 frame_width, const uint32 frame_height, const uint32 trim = 0);
-
- /** \brief Loads an AnimatedImage from a multi image file
- *** \param filename The name of the file to load, which should end in a .png or .jpg extension
- *** \param timings A vector reference which holds the timing information for each animation frame
- *** \param frame_rows The number of rows of frame images in the image file
- *** \param frame_cols The number of columns of frame images in the image file
- *** \param trim The number of frame images to "ignore" from the multi image (default == 0)
- *** \return True if the animation was successfully constructed from the loaded multi image
- ***
- *** The trim factor is useful for indicating if any of the final frames in a multi image
- *** contain no relevant image data that we are interested in. For example, if we have a
- *** multi image with 2 rows and 4 columns of frames, but only the first 6 frames (the entire
- *** top row, and the left-most two frames in the bottom row) are valid, we would set the trim
- *** factor to two. Obviously, trim must be less than frame_rows * frame_cols, otherwise we
- *** can't load even a single frame.
- ***
- *** The timings vector must have a minimum size of (frame_rows * frame_cols - trim) so that each
- *** frame we will add has a timing value associated with it. The timings vector may be larger
- *** than this minimum size, but only the first (frame_rows * frame_cols - trim) elements will
- *** be used, and the rest of the vector ignored.
- **/
- bool LoadFromFrameGrid(const std::string& filename, const std::vector<uint32>& timings, const uint32 frame_rows, const uint32 frame_cols, const uint32 trim = 0);
-
- /** \brief Loads an animated image from a lua script
- *** \param filename The name of the multi image lua script to load the image data from
- *** \return True upon successful loading, false if there was an error
- ***
- *** This function determines the image elements to extract from the multi image by the width and height
- *** of each element (in pixels) specified in the function arguments. Upon success, the size of the images
- *** reference vector will always be equal to the area of the multi image divided by the area of each
- *** element image.
- *** \note All image elements within the multi image should be of the same size
- */
- bool LoadFromAnimationScript(const std::string& filename);
-
- //! \brief Draws the current frame image to the screen
- void Draw() const;
-
- /** \brief Draws the current frame image which is modulated by a color
- *** \param draw_color The color to modulate the image by
- **/
- void Draw(const Color& draw_color) const;
-
- /** \brief Saves all frame images into a single file (a multi image file)
- *** \param filename The filename of the image to save (should have a .png or .jpg extension)
- *** \param grid_rows The number of grid rows to save in the multi image
- *** \param grid_cols The number of grid columns to save in the multi image
- *** \return True if all frames were successfully saved to a file
- ***
- *** This function
- ***
- *** \note No frame images should contain more than one image element. Support for saving of
- *** composite (multi-element) images is not yet supported.
- **/
- bool Save(const std::string& filename, const uint32 grid_rows = 0, const uint32 grid_cols = 0) const;
-
- //! \brief Enables grayscale for all image frames
- void EnableGrayScale();
-
- //! \brief Disables grayscale for all image frames
- void DisableGrayScale();
-
- //! \brief Resets the animation's frame, counter, and looping.
- void ResetAnimation()
- { _frame_index = 0; _frame_counter = 0; _loop_counter = 0; _loops_finished = false; }
-
- /** \brief Called every frame to update the animation's current frame
- *** This will automatically synchronize the animation according to the time passed
- *** since the last call.
- *** \param elapsed_time Used to force a certain amount of time, i.e: accelerate an animation.
- *** The function will use actual elapsed time if equal to 0.
- *** \note This method will do nothing if there are no frames contained in the animation,
- *** or if the _loops_finished member is set to true.
- **/
- void Update(uint32 elapsed_time);
- void Update()
- { Update(0); }
-
- /** \brief Adds an animation frame using the filename of the image to add.
- *** \param frame The filename of the frame image to add.
- *** \param frame_time The number of milliseconds that this animation should last for
- *** \return True on success, false on failure.
- ***
- *** This is perhaps a more convenient way to add frames, <b>but</b> this makes it impossible
- *** to control the image properties such as vertex colors, and size. If you use this function,
- *** the width and height will be the pixel width/height of the image itself. This is not what
- *** you always will want. For example, if your coordinate system is in terms of 32x32 pixel
- *** tiles, then a tile image would have a width and height of 1, not 32.
- **/
- bool AddFrame(const std::string& frame, uint32 frame_time);
-
- /** \brief Adds an animation frame by using an existing static image.
- *** \param frame The still image to use as the frame image.
- *** \param frame_time The amount of millseconds to display the frame.
- *** \return True on success, false on failure.
- ***
- *** The frame argument should have at least one element prepared. Passing a StillImage
- *** that does not contain any image data will result in failure for this call.
- **/
- bool AddFrame(const StillImage& frame, uint32 frame_time);
-
- //! \name Class Member Access Functions
- //@{
- //! \brief Returns the number of frames in this animation
- uint32 GetNumFrames() const
- { return _frames.size(); }
-
- //! \brief Retuns a pointer to the StillImage representing the current frame
- StillImage* GetCurrentFrame() const
- { return GetFrame(_frame_index); }
-
- //! \brief Returns the index number of the current frame in the animation.
- uint32 GetCurrentFrameIndex() const
- { return _frame_index; }
-
- /** \brief Returns a pointer to the StillImage at a specified frame.
- *** \param index index of the frame you want
- *** \return A pointer to the image at that index, or NULL if the index parameter was invalid
- ***
- *** Using this function is dangerous since it provides direct access to an image frame.
- *** If you find yourself in constant need of using this function, think twice about
- *** what you are doing.
- **/
- StillImage* GetFrame(uint32 index) const
- { if (index >= _frames.size()) return NULL; else return const_cast<StillImage*>(&(_frames[index].image)); }
-
- //! \brief Returns the number of milliseconds that the current frame has been shown for.
- uint32 GetTimeProgress() const
- { return _frame_counter; }
-
- /** \brief Returns the percentage of timing complete for the current frame being shown.
- *** \return A float from 0.0f to 1.0f, indicate how much of its allotted time this frame has spent
- *** \note The divide by 0.0f case is not checked for here, so this function could potentially throw
- *** a divide by zero exception at run-time.
- **/
- float GetPercentProgress() const
- { return static_cast<float>(_frame_counter) / _frames[_frame_index].frame_time; }
-
- //! \brief Returns the total time used to play the animation in milliseconds.
- uint32 GetAnimationLength() const
- { return _animation_time; }
-
- //! \brief Returns true if the loops have finished, false otherwise
- bool IsLoopsFinished() const
- { return _loops_finished; }
-
- /** \brief Sets all animation frames to be a certain width
- *** \param width Width to set each frame (in coordinate system units)
- **/
- void SetWidth(float width);
-
- /** \brief Sets all animation frames to be a certain height
- *** \param height Height to set each frame (in coordinate system units)
- **/
- void SetHeight(float height);
-
- /** \brief Sets all animation frames to be a certain width and height
- *** \param width Width to set each frame (in coordinate system units)
- *** \param height Height to set each frame (in coordinate system units)
- **/
- void SetDimensions(float width, float height);
-
- /** \brief Sets the static member for all animation frame images
- *** \param is_static Flag indicating whether the image will be static or not.
- *** \note If the frames are already loaded, it doesn't bother to try to unload them
- *** and then reload them again statically.
- **/
- void SetStatic(bool is_static)
- { _is_static = is_static; }
-
- /** \brief sets All frames to be of a certain color (all vertices are set to the same color)
- *** \param color Color of the 4 vertices
- **/
- void SetColor(const Color &color);
-
- /** \brief sets all frames to have the specified vertex colors
- *** \param tl The top left vertex color
- *** \param tr The top right vertex color
- *** \param bl The bottom left vertex color
- *** \param br The bottom right vertex color
- **/
- void SetVertexColors(const Color &tl, const Color &tr, const Color &bl, const Color &br);
-
- /** \brief Sets the current frame index of the animation.
- *** \param index The index of the frame to access
- *** \note Passing in an invalid value for the index will not change the current frame
- **/
- void SetFrameIndex(const uint32 index)
- { if (index > _frames.size()) return; _frame_index = index; _frame_counter = 0; }
-
- /** \brief Sets the number of milliseconds that the current frame has been shown for.
- *** \param time The time to set the frame counter
- *** \note This does not set the frame timer for the current frame
- **/
- void SetTimeProgress(uint32 time)
- { _frame_counter = time; }
-
- /** \brief Set the number of loops for the animation.
- *** A value less than zero indicates to loop forever. Zero indicates do not loop: just run the
- *** animation from beginning to end and stop.
- *** \param loops Number of loops for the animation
- **/
- void SetNumberLoops(int32 loops)
- { _number_loops = loops; if (_loop_counter >= _number_loops && _number_loops >= 0) _loops_finished = true; }
-
- /** \brief Set the current number of loops that the animation has completed.
- *** \param loops The urrent loop count
- **/
- void SetLoopCounter(int32 loops)
- { _loop_counter = loops; if (_loop_counter >= _number_loops && _number_loops >= 0) _loops_finished = true; }
-
- /** \brief Effectively stops the animation in its track if this member is set to true.
- *** \param loops True to stop the looping process. Setting it to false will restart the loop counter
- **/
- void SetLoopsFinished(bool loops)
- { _loops_finished = loops; if (loops == false) _loop_counter = 0; }
- //@}
+ //! \brief Supply the constructor with "true" if you want this to represent a grayscale image.
+ AnimatedImage(bool grayscale = false);
+
+ //! \brief A constructor which also sets the image's dimensions
+ AnimatedImage(float width, float height, bool grayscale = false);
+
+ //! \brief Resets the image's properties and removes any references to image data that it maintains
+ void Clear();
+
+ /** \brief Loads an AnimatedImage by opening a multi image file
+ *** \param filename The name of the file to load, which should end in a .png or .jpg extension
+ *** \param timings A vector reference which holds the timing information for each animation frame
+ *** \param frame_width The width (in pixels) of each frame in the multi image file
+ *** \param frame_height The height (in pixels) of each frame in the multi image file
+ *** \param trim The number of frame images to "ignore" from the multi image (default == 0)
+ *** \return True if the animation was successfully constructed from the loaded multi image
+ ***
+ *** The trim factor must be less than the total number of frames that are stored in the multi image.
+ *** The size of the timings vector must be at least (# of frames in multi image - trim). It may
+ *** be larger than this, but the rest of the elements beyond the minimum size will be ignored.
+ **/
+ bool LoadFromFrameSize(const std::string &filename, const std::vector<uint32>& timings, const uint32 frame_width, const uint32 frame_height, const uint32 trim = 0);
+
+ /** \brief Loads an AnimatedImage from a multi image file
+ *** \param filename The name of the file to load, which should end in a .png or .jpg extension
+ *** \param timings A vector reference which holds the timing information for each animation frame
+ *** \param frame_rows The number of rows of frame images in the image file
+ *** \param frame_cols The number of columns of frame images in the image file
+ *** \param trim The number of frame images to "ignore" from the multi image (default == 0)
+ *** \return True if the animation was successfully constructed from the loaded multi image
+ ***
+ *** The trim factor is useful for indicating if any of the final frames in a multi image
+ *** contain no relevant image data that we are interested in. For example, if we have a
+ *** multi image with 2 rows and 4 columns of frames, but only the first 6 frames (the entire
+ *** top row, and the left-most two frames in the bottom row) are valid, we would set the trim
+ *** factor to two. Obviously, trim must be less than frame_rows * frame_cols, otherwise we
+ *** can't load even a single frame.
+ ***
+ *** The timings vector must have a minimum size of (frame_rows * frame_cols - trim) so that each
+ *** frame we will add has a timing value associated with it. The timings vector may be larger
+ *** than this minimum size, but only the first (frame_rows * frame_cols - trim) elements will
+ *** be used, and the rest of the vector ignored.
+ **/
+ bool LoadFromFrameGrid(const std::string &filename, const std::vector<uint32>& timings, const uint32 frame_rows, const uint32 frame_cols, const uint32 trim = 0);
+
+ /** \brief Loads an animated image from a lua script
+ *** \param filename The name of the multi image lua script to load the image data from
+ *** \return True upon successful loading, false if there was an error
+ ***
+ *** This function determines the image elements to extract from the multi image by the width and height
+ *** of each element (in pixels) specified in the function arguments. Upon success, the size of the images
+ *** reference vector will always be equal to the area of the multi image divided by the area of each
+ *** element image.
+ *** \note All image elements within the multi image should be of the same size
+ */
+ bool LoadFromAnimationScript(const std::string &filename);
+
+ //! \brief Draws the current frame image to the screen
+ void Draw() const;
+
+ /** \brief Draws the current frame image which is modulated by a color
+ *** \param draw_color The color to modulate the image by
+ **/
+ void Draw(const Color &draw_color) const;
+
+ /** \brief Saves all frame images into a single file (a multi image file)
+ *** \param filename The filename of the image to save (should have a .png or .jpg extension)
+ *** \param grid_rows The number of grid rows to save in the multi image
+ *** \param grid_cols The number of grid columns to save in the multi image
+ *** \return True if all frames were successfully saved to a file
+ ***
+ *** This function
+ ***
+ *** \note No frame images should contain more than one image element. Support for saving of
+ *** composite (multi-element) images is not yet supported.
+ **/
+ bool Save(const std::string &filename, const uint32 grid_rows = 0, const uint32 grid_cols = 0) const;
+
+ //! \brief Enables grayscale for all image frames
+ void EnableGrayScale();
+
+ //! \brief Disables grayscale for all image frames
+ void DisableGrayScale();
+
+ //! \brief Resets the animation's frame, counter, and looping.
+ void ResetAnimation() {
+ _frame_index = 0;
+ _frame_counter = 0;
+ _loop_counter = 0;
+ _loops_finished = false;
+ }
+
+ /** \brief Called every frame to update the animation's current frame
+ *** This will automatically synchronize the animation according to the time passed
+ *** since the last call.
+ *** \param elapsed_time Used to force a certain amount of time, i.e: accelerate an animation.
+ *** The function will use actual elapsed time if equal to 0.
+ *** \note This method will do nothing if there are no frames contained in the animation,
+ *** or if the _loops_finished member is set to true.
+ **/
+ void Update(uint32 elapsed_time);
+ void Update() {
+ Update(0);
+ }
+
+ /** \brief Adds an animation frame using the filename of the image to add.
+ *** \param frame The filename of the frame image to add.
+ *** \param frame_time The number of milliseconds that this animation should last for
+ *** \return True on success, false on failure.
+ ***
+ *** This is perhaps a more convenient way to add frames, <b>but</b> this makes it impossible
+ *** to control the image properties such as vertex colors, and size. If you use this function,
+ *** the width and height will be the pixel width/height of the image itself. This is not what
+ *** you always will want. For example, if your coordinate system is in terms of 32x32 pixel
+ *** tiles, then a tile image would have a width and height of 1, not 32.
+ **/
+ bool AddFrame(const std::string &frame, uint32 frame_time);
+
+ /** \brief Adds an animation frame by using an existing static image.
+ *** \param frame The still image to use as the frame image.
+ *** \param frame_time The amount of millseconds to display the frame.
+ *** \return True on success, false on failure.
+ ***
+ *** The frame argument should have at least one element prepared. Passing a StillImage
+ *** that does not contain any image data will result in failure for this call.
+ **/
+ bool AddFrame(const StillImage &frame, uint32 frame_time);
+
+ //! \name Class Member Access Functions
+ //@{
+ //! \brief Returns the number of frames in this animation
+ uint32 GetNumFrames() const {
+ return _frames.size();
+ }
+
+ //! \brief Retuns a pointer to the StillImage representing the current frame
+ StillImage *GetCurrentFrame() const {
+ return GetFrame(_frame_index);
+ }
+
+ //! \brief Returns the index number of the current frame in the animation.
+ uint32 GetCurrentFrameIndex() const {
+ return _frame_index;
+ }
+
+ /** \brief Returns a pointer to the StillImage at a specified frame.
+ *** \param index index of the frame you want
+ *** \return A pointer to the image at that index, or NULL if the index parameter was invalid
+ ***
+ *** Using this function is dangerous since it provides direct access to an image frame.
+ *** If you find yourself in constant need of using this function, think twice about
+ *** what you are doing.
+ **/
+ StillImage *GetFrame(uint32 index) const {
+ if(index >= _frames.size()) return NULL;
+ else return const_cast<StillImage *>(&(_frames[index].image));
+ }
+
+ //! \brief Returns the number of milliseconds that the current frame has been shown for.
+ uint32 GetTimeProgress() const {
+ return _frame_counter;
+ }
+
+ /** \brief Returns the percentage of timing complete for the current frame being shown.
+ *** \return A float from 0.0f to 1.0f, indicate how much of its allotted time this frame has spent
+ *** \note The divide by 0.0f case is not checked for here, so this function could potentially throw
+ *** a divide by zero exception at run-time.
+ **/
+ float GetPercentProgress() const {
+ return static_cast<float>(_frame_counter) / _frames[_frame_index].frame_time;
+ }
+
+ //! \brief Returns the total time used to play the animation in milliseconds.
+ uint32 GetAnimationLength() const {
+ return _animation_time;
+ }
+
+ //! \brief Returns true if the loops have finished, false otherwise
+ bool IsLoopsFinished() const {
+ return _loops_finished;
+ }
+
+ /** \brief Sets all animation frames to be a certain width
+ *** \param width Width to set each frame (in coordinate system units)
+ **/
+ void SetWidth(float width);
+
+ /** \brief Sets all animation frames to be a certain height
+ *** \param height Height to set each frame (in coordinate system units)
+ **/
+ void SetHeight(float height);
+
+ /** \brief Sets all animation frames to be a certain width and height
+ *** \param width Width to set each frame (in coordinate system units)
+ *** \param height Height to set each frame (in coordinate system units)
+ **/
+ void SetDimensions(float width, float height);
+
+ /** \brief Sets the static member for all animation frame images
+ *** \param is_static Flag indicating whether the image will be static or not.
+ *** \note If the frames are already loaded, it doesn't bother to try to unload them
+ *** and then reload them again statically.
+ **/
+ void SetStatic(bool is_static) {
+ _is_static = is_static;
+ }
+
+ /** \brief sets All frames to be of a certain color (all vertices are set to the same color)
+ *** \param color Color of the 4 vertices
+ **/
+ void SetColor(const Color &color);
+
+ /** \brief sets all frames to have the specified vertex colors
+ *** \param tl The top left vertex color
+ *** \param tr The top right vertex color
+ *** \param bl The bottom left vertex color
+ *** \param br The bottom right vertex color
+ **/
+ void SetVertexColors(const Color &tl, const Color &tr, const Color &bl, const Color &br);
+
+ /** \brief Sets the current frame index of the animation.
+ *** \param index The index of the frame to access
+ *** \note Passing in an invalid value for the index will not change the current frame
+ **/
+ void SetFrameIndex(const uint32 index) {
+ if(index > _frames.size()) return;
+ _frame_index = index;
+ _frame_counter = 0;
+ }
+
+ /** \brief Sets the number of milliseconds that the current frame has been shown for.
+ *** \param time The time to set the frame counter
+ *** \note This does not set the frame timer for the current frame
+ **/
+ void SetTimeProgress(uint32 time) {
+ _frame_counter = time;
+ }
+
+ /** \brief Set the number of loops for the animation.
+ *** A value less than zero indicates to loop forever. Zero indicates do not loop: just run the
+ *** animation from beginning to end and stop.
+ *** \param loops Number of loops for the animation
+ **/
+ void SetNumberLoops(int32 loops) {
+ _number_loops = loops;
+ if(_loop_counter >= _number_loops && _number_loops >= 0) _loops_finished = true;
+ }
+
+ /** \brief Set the current number of loops that the animation has completed.
+ *** \param loops The urrent loop count
+ **/
+ void SetLoopCounter(int32 loops) {
+ _loop_counter = loops;
+ if(_loop_counter >= _number_loops && _number_loops >= 0) _loops_finished = true;
+ }
+
+ /** \brief Effectively stops the animation in its track if this member is set to true.
+ *** \param loops True to stop the looping process. Setting it to false will restart the loop counter
+ **/
+ void SetLoopsFinished(bool loops) {
+ _loops_finished = loops;
+ if(loops == false) _loop_counter = 0;
+ }
+ //@}
private:
- //! \brief The index of which animation frame to display.
- uint32 _frame_index;
+ //! \brief The index of which animation frame to display.
+ uint32 _frame_index;
//! \brief Counts how long each frame has been shown for.
- uint32 _frame_counter;
+ uint32 _frame_counter;
- /** \brief The number of times to loop the animation frames.
- *** A negative value indicates to loop forever, which is the default.
- **/
- int32 _number_loops;
+ /** \brief The number of times to loop the animation frames.
+ *** A negative value indicates to loop forever, which is the default.
+ **/
+ int32 _number_loops;
- //! \brief Counts the number of loops remaining for the animation.
- int32 _loop_counter;
+ //! \brief Counts the number of loops remaining for the animation.
+ int32 _loop_counter;
- /** \brief Set to true when the loop counter has expired.
- *** This member will remain eternally false if the looping is set to infinite mode.
- **/
- bool _loops_finished;
+ /** \brief Set to true when the loop counter has expired.
+ *** This member will remain eternally false if the looping is set to infinite mode.
+ **/
+ bool _loops_finished;
- //! \brief The vector of animation frames (contains both images and timing)
- std::vector<private_video::AnimationFrame> _frames;
+ //! \brief The vector of animation frames (contains both images and timing)
+ std::vector<private_video::AnimationFrame> _frames;
- //! \brief The total time used to play the animation
- uint32 _animation_time;
+ //! \brief The total time used to play the animation
+ uint32 _animation_time;
}; // class AnimatedImage : public ImageDescriptor
@@ -789,106 +840,110 @@ class AnimatedImage : public ImageDescriptor {
*** member is always NULL, since the class itself does not make use of any
*** textures.
*** ***************************************************************************/
-class CompositeImage : public ImageDescriptor {
+class CompositeImage : public ImageDescriptor
+{
public:
- CompositeImage()
- {}
-
- ~CompositeImage()
- {}
-
- //! \brief Removes all image elements held by this class
- void Clear();
-
- /** \brief Draws the image to the display buffer
- *** The location and orientation of the drawn image is dependent upon the current cursor position
- *** and context (draw flags) set in the VideoEngine class.
- **/
- void Draw() const;
-
- /** \brief Draws a color modulated version of the image to the display buffer
- *** \param draw_color The color to modulate the image by
- **/
- void Draw(const Color& draw_color) const;
-
- /** \brief Sets the static member for all future element images
- *** \param is_static Flag indicating whether the image will be static or not
- *** \note If the elements are already loaded, it doesn't bother to try to unload them
- *** and then reload them again statically.
- **/
- void SetStatic(bool is_static)
- { _is_static = is_static; }
-
- /** \brief Sets the image's width, expressed as coordinate system units
- *** \param width The desired width of the image
- **/
- void SetWidth(float width);
-
- /** \brief Sets the image's height, expressed as coordinate system units
- *** \param height The desired height of the image
- **/
- void SetHeight(float height);
-
- /** \brief Sets the image's dimensions, expressed as coordinate system units
- *** \param width The desired width of the image
- *** \param height The desired height of the image
- **/
- void SetDimensions(float width, float height)
- { SetWidth(width); SetHeight(height); }
-
- void EnableGrayScale()
- {}
-
- void DisableGrayScale()
- {}
-
- /** \brief Sets the image's four vertices to a single color
- *** \param color The desired color of all image vertices
- **/
- void SetColor(const Color& color);
-
- /** \brief Sets the image's vertex colors
- *** \param tl The top left vertex color
- *** \param tr The top right vertex color
- *** \param bl The bottom left vertex color
- *** \param br The bottom right vertex color
- **/
- void SetVertexColors(const Color& tl, const Color& tr, const Color& bl, const Color& br);
-
- /** \brief Adds a new image element to the composite image
- *** \param img The image to add to the composite image.
- *** \param x_offset The x offset of the composite image.
- *** \param y_offset The y offset of the composite image.
- *** \param u1 The upper-left u coordinate for the image. The default is 0.0f.
- *** \param v1 The upper-left v coordinate for the image. The default is 0.0f.
- *** \param u2 The lower-right u coordinate for the image. The default is 1.0f.
- *** \param v2 The lower-right v coordinate for the image. The default is 1.0f.
- ***
- *** Starting with a newly created StillImage, call AddImage(), for all of the images you wish
- *** to add, along with the x and y offsets that they should be positioned at. The u1, v1, u2, v2
- *** coordinates tell which portion of the image to use (usually 0.0f, 0.0f, 1.0f, 1.0f)
- **/
- void AddImage(const StillImage& img, float x_offset, float y_offset, float u1 = 0.0f, float v1 = 0.0f,
- float u2 = 1.0f, float v2 = 1.0f);
-
- /** \brief Creates a single composite image from a 2D array of like-sized images
- *** \param tiles A 1D vector of StillImage objects that will be used to construct the composite image
- *** \param indeces A 2D vector in row-column order (e.g. indices[y][x]) with indeces into the tiles vector
- ***
- *** This method is useful for constructing variable-sized objects within a map from multiple smaller tile
- *** images. The StillImage object that this method is invoked upon will be cleared prior to constructing
- *** the composite image.
- ***
- *** \note This should be obvious, but don't include "this" StillImage object inside the tiles argument vector
- *** \note All StillImages in the tiles vector should have the same dimensions
- *** \note Every vector row in indeces must be the same size
- *** \note Every index element (indices[y][x]) should range from 0 to tiles.size() - 1
- **/
+ CompositeImage()
+ {}
+
+ ~CompositeImage()
+ {}
+
+ //! \brief Removes all image elements held by this class
+ void Clear();
+
+ /** \brief Draws the image to the display buffer
+ *** The location and orientation of the drawn image is dependent upon the current cursor position
+ *** and context (draw flags) set in the VideoEngine class.
+ **/
+ void Draw() const;
+
+ /** \brief Draws a color modulated version of the image to the display buffer
+ *** \param draw_color The color to modulate the image by
+ **/
+ void Draw(const Color &draw_color) const;
+
+ /** \brief Sets the static member for all future element images
+ *** \param is_static Flag indicating whether the image will be static or not
+ *** \note If the elements are already loaded, it doesn't bother to try to unload them
+ *** and then reload them again statically.
+ **/
+ void SetStatic(bool is_static) {
+ _is_static = is_static;
+ }
+
+ /** \brief Sets the image's width, expressed as coordinate system units
+ *** \param width The desired width of the image
+ **/
+ void SetWidth(float width);
+
+ /** \brief Sets the image's height, expressed as coordinate system units
+ *** \param height The desired height of the image
+ **/
+ void SetHeight(float height);
+
+ /** \brief Sets the image's dimensions, expressed as coordinate system units
+ *** \param width The desired width of the image
+ *** \param height The desired height of the image
+ **/
+ void SetDimensions(float width, float height) {
+ SetWidth(width);
+ SetHeight(height);
+ }
+
+ void EnableGrayScale()
+ {}
+
+ void DisableGrayScale()
+ {}
+
+ /** \brief Sets the image's four vertices to a single color
+ *** \param color The desired color of all image vertices
+ **/
+ void SetColor(const Color &color);
+
+ /** \brief Sets the image's vertex colors
+ *** \param tl The top left vertex color
+ *** \param tr The top right vertex color
+ *** \param bl The bottom left vertex color
+ *** \param br The bottom right vertex color
+ **/
+ void SetVertexColors(const Color &tl, const Color &tr, const Color &bl, const Color &br);
+
+ /** \brief Adds a new image element to the composite image
+ *** \param img The image to add to the composite image.
+ *** \param x_offset The x offset of the composite image.
+ *** \param y_offset The y offset of the composite image.
+ *** \param u1 The upper-left u coordinate for the image. The default is 0.0f.
+ *** \param v1 The upper-left v coordinate for the image. The default is 0.0f.
+ *** \param u2 The lower-right u coordinate for the image. The default is 1.0f.
+ *** \param v2 The lower-right v coordinate for the image. The default is 1.0f.
+ ***
+ *** Starting with a newly created StillImage, call AddImage(), for all of the images you wish
+ *** to add, along with the x and y offsets that they should be positioned at. The u1, v1, u2, v2
+ *** coordinates tell which portion of the image to use (usually 0.0f, 0.0f, 1.0f, 1.0f)
+ **/
+ void AddImage(const StillImage &img, float x_offset, float y_offset, float u1 = 0.0f, float v1 = 0.0f,
+ float u2 = 1.0f, float v2 = 1.0f);
+
+ /** \brief Creates a single composite image from a 2D array of like-sized images
+ *** \param tiles A 1D vector of StillImage objects that will be used to construct the composite image
+ *** \param indeces A 2D vector in row-column order (e.g. indices[y][x]) with indeces into the tiles vector
+ ***
+ *** This method is useful for constructing variable-sized objects within a map from multiple smaller tile
+ *** images. The StillImage object that this method is invoked upon will be cleared prior to constructing
+ *** the composite image.
+ ***
+ *** \note This should be obvious, but don't include "this" StillImage object inside the tiles argument vector
+ *** \note All StillImages in the tiles vector should have the same dimensions
+ *** \note Every vector row in indeces must be the same size
+ *** \note Every index element (indices[y][x]) should range from 0 to tiles.size() - 1
+ **/
// void ConstructCompositeImage(const std::vector<ImageElement>& tiles, const std::vector<std::vector<uint32> >& indeces);
private:
- //! \brief A container for each element in the composite image
- std::vector<private_video::ImageElement> _elements;
+ //! \brief A container for each element in the composite image
+ std::vector<private_video::ImageElement> _elements;
}; // class CompositeImage : public ImageDescriptor
} // namespace hoa_video
View
791 src/engine/video/image_base.cpp
@@ -18,7 +18,7 @@
#include <png.h>
extern "C" {
- #include <jpeglib.h>
+#include <jpeglib.h>
}
#include <cstdarg>
@@ -28,374 +28,381 @@ extern "C" {
using namespace hoa_utils;
-namespace hoa_video {
+namespace hoa_video
+{
-namespace private_video {
+namespace private_video
+{
// -----------------------------------------------------------------------------
// ImageMemory class
// -----------------------------------------------------------------------------
ImageMemory::ImageMemory() :
- width(0),
- height(0),
- pixels(NULL),
- rgb_format(false)
+ width(0),
+ height(0),
+ pixels(NULL),
+ rgb_format(false)
{}
-ImageMemory::~ImageMemory() {
+ImageMemory::~ImageMemory()
+{
// Winter Knight - I commented this out because it was causing double free
// segfaults when ImageMemory objects were copied via copy constructor.
- if (pixels != NULL) {
- IF_PRINT_WARNING(VIDEO_DEBUG) << "pixels member was not NULL upon object destruction" << std::endl;
+ if(pixels != NULL) {
+ IF_PRINT_WARNING(VIDEO_DEBUG) << "pixels member was not NULL upon object destruction" << std::endl;
// free(pixels);
// pixels = NULL;
- }
+ }
}