00001
00002
00003
00004
00005
00006
00007
00009
00049 #ifndef __IMAGE_HEADER__
00050 #define __IMAGE_HEADER__
00051
00052 #include "defs.h"
00053 #include "utils.h"
00054 #include "color.h"
00055 #include "tex_mgmt.h"
00056
00057 namespace hoa_video {
00058
00059 namespace private_video {
00060
00067 class ImageLoadInfo {
00068 public:
00070 int32 width;
00071
00073 int32 height;
00074
00076 void* pixels;
00077
00079 ImageLoadInfo () :
00080 width (0),
00081 height (0),
00082 pixels (NULL)
00083 {}
00084
00085 };
00086
00087
00093 class Image {
00094 public:
00096 TexSheet* texture_sheet;
00097
00103 std::string filename;
00104
00106
00116 std::string tags;
00117
00119 int32 x, y;
00120
00126 float u1, v1, u2, v2;
00127
00129 int32 width, height;
00130
00132 bool grayscale;
00133
00137 int32 ref_count;
00138
00142 Image(const std::string &fname, const std::string &tags_, int32 width, int32 height, bool grayscale_);
00143
00145 Image(TexSheet *sheet, const std::string &fname, const std::string &tags_, int32 x_, int32 y_, float u1_, float v1_,
00146 float u2_, float v2_, int32 wifth, int32 height, bool grayscale_);
00147
00148 Image & operator=(Image &rhs)
00149 { return *this; }
00150 };
00151
00152
00157 class ImageElement {
00158 friend class AnimatedImage;
00159 public:
00161 Image* image;
00162
00164 float x_offset;
00165
00167 float y_offset;
00168
00172 float u1, v1, u2, v2;
00173
00175 float width;
00176
00178 float height;
00179
00181 Color color[4];
00182
00184 bool blend;
00185
00187 bool one_color;
00188
00190 bool white;
00191
00195 ImageElement(Image *image_, float x_offset_, float y_offset_, float u1_, float v1_,
00196 float u2_, float v2_, float width_, float height_, Color color_[4]);
00197
00199 ImageElement(Image *image_, float x_offset_, float y_offset_, float u1_, float v1_,
00200 float u2_, float v2_, float width_, float height_);
00201 };
00202
00203
00205
00210 struct MultiImageInfo {
00211 ImageLoadInfo multi_image;
00212 ImageLoadInfo image;
00213 };
00214
00215
00216 }
00217
00218
00219
00223 class ImageDescriptor {
00224 friend class GameVideo;
00225 public:
00226 ImageDescriptor();
00227
00228 virtual ~ImageDescriptor()
00229 {}
00230
00232 virtual void Clear() = 0;
00233
00235
00236
00239 virtual void SetStatic(const bool is_static) = 0;
00240
00244 virtual void SetWidth(const float width) = 0;
00245
00249 virtual void SetHeight(const float height) = 0;
00250
00255 virtual void SetDimensions(const float width, const float height) = 0;
00256
00260 virtual void SetColor(const Color &color) = 0;
00261
00268 virtual void SetVertexColors(const Color &tl, const Color &tr, const Color &bl, const Color &br) = 0;
00270
00272
00273
00274 virtual float GetWidth() const = 0;
00275
00277 virtual float GetHeight() const = 0;
00278
00280 bool IsGrayScale() const
00281 { return _grayscale; }
00282
00288 bool IsAnimated() const
00289 { return _animated; }
00291
00293 bool Load();
00294
00296 void Draw();
00297
00299
00304 bool Save(const std::string filename) const;
00305
00306 protected:
00311 float _width, _height;
00312
00314 Color _color[4];
00315
00317 bool _is_static;
00318
00320 bool _grayscale;
00321
00323 bool _animated;
00324
00326 bool _loaded;
00327
00328
00330 void _Clear ();
00331 };
00332
00333
00341 class StillImage : public ImageDescriptor {
00342 friend class GameVideo;
00343 friend class AnimatedImage;
00344 friend class private_video::ParticleSystem;
00345 public:
00346 StillImage(const bool grayscale = false);
00347
00349 void Clear();
00350
00352 void EnableGrayScale();
00353
00355 void DisableGrayScale();
00356
00370 bool AddImage(const StillImage &id, float x_offset, float y_offset, float u1 = 0.0f, float v1 = 0.0f,
00371 float u2 = 1.0f, float v2 = 1.0f);
00372
00374
00375
00378 void SetFilename(const std::string &filename)
00379 { _filename = filename; }
00380
00384 void SetWidth(const float width);
00385
00389 void SetHeight(const float height);
00390
00395 void SetDimensions(const float width, const float height);
00396
00400 void SetStatic(const bool is_static)
00401 { _is_static = is_static; }
00402
00406 void SetColor(const Color &color)
00407 { _color[0] = _color[1] = _color[2] = _color[3] = color; }
00408
00415 void SetVertexColors(const Color &tl, const Color &tr, const Color &bl, const Color &br)
00416 { _color[0] = tl; _color[1] = tr; _color[2] = bl; _color[3] = br; }
00418
00420
00421
00422 std::string GetFilename() const
00423 { return _filename; }
00424
00426 float GetWidth() const
00427 { return _width; }
00428
00430 float GetHeight() const
00431 { return _height; }
00432
00438 void GetVertexColor(Color &c, uint8 index)
00439 { if (index > 3) return; else c = _color[index]; }
00441
00442 private:
00447 std::string _filename;
00448
00452 std::vector <private_video::ImageElement> _elements;
00453 };
00454
00455
00456
00457 namespace private_video {
00458
00462 class AnimationFrame {
00463 public:
00465 uint32 frame_time;
00466
00468 StillImage image;
00469 };
00470
00471 }
00472
00473
00474
00485 class AnimatedImage : public ImageDescriptor {
00486 friend class GameVideo;
00487 public:
00488 AnimatedImage(const bool grayscale = false);
00489
00491 void Clear();
00492
00494 void EnableGrayScale();
00495
00497 void DisableGrayScale();
00498
00504 void Update();
00505
00507 void ResetAnimation()
00508 { _frame_index = 0; _frame_counter = 0; _loop_counter = 0; _loops_finished = false; }
00509
00515 bool AddFrame(const StillImage &frame, uint32 frame_time);
00516
00528 bool AddFrame(const std::string &frame, uint32 frame_time);
00529
00531
00532
00535 void SetWidth(const float width);
00536
00540 void SetHeight(const float height);
00541
00546 void SetDimensions(const float width, const float height);
00547
00551 void SetColor(const Color &color);
00552
00559 void SetVertexColors(const Color &tl, const Color &tr, const Color &bl, const Color &br);
00560
00566 void SetStatic(const bool is_static)
00567 { _is_static = is_static; }
00568
00573 void SetFrameIndex(const uint32 index)
00574 { if (index > _frames.size()) return; _frame_index = index; _frame_counter = 0; }
00575
00579 void SetTimeProgress(uint32 time)
00580 { _frame_counter = time; }
00581
00587 void SetNumberLoops(int32 loops)
00588 { _number_loops = loops; }
00589
00593 void SetLoopCounter(int32 loops)
00594 { _loop_counter = loops; }
00595
00599 void SetLoopsFinished(bool loops)
00600 { _loops_finished = loops; }
00602
00604
00605
00606
00607 float GetWidth() const
00608 { if (_frames.size() == 0) return 0.0f; else return _frames[0].image.GetWidth(); }
00609
00612 float GetHeight() const
00613 { if (_frames.size() == 0) return 0.0f; else return _frames[0].image.GetHeight(); }
00614
00616 uint32 GetNumFrames() const
00617 { return _frames.size(); }
00618
00620 uint32 GetCurrentFrameIndex() const
00621 { return _frame_index; }
00622
00631 StillImage *GetFrame(uint32 index) const
00632 { if (index >= _frames.size()) return NULL; else return const_cast<StillImage*>(&(_frames[index].image)); }
00633
00635 uint32 GetTimeProgress() const
00636 { return _frame_counter; }
00637
00641 float GetPercentProgress() const
00642 { return static_cast<float>(_frame_counter) / _frames[_frame_index].frame_time; }
00643
00645 bool IsLoopsFinished() const
00646 { return _loops_finished; }
00648
00649 private:
00651 uint32 _frame_index;
00652
00654 uint32 _frame_counter;
00655
00659 int32 _number_loops;
00660
00662 int32 _loop_counter;
00663
00667 bool _loops_finished;
00668
00670 std::vector<private_video::AnimationFrame> _frames;
00671 };
00672
00673 }
00674
00675 #endif // __IMAGE_HEADER__