123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- /* GCSx
- ** ANIMGROUP.H
- **
- ** Animation group support, objects and drawing
- ** Doesn't include any editor-only functionality
- */
- /*****************************************************************************
- ** Copyright (C) 2003-2006 Janson
- **
- ** This program is free software; you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation; either version 2 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program; if not, write to the Free Software
- ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
- *****************************************************************************/
- #ifndef __GCSx_ANIMGROUP_H_
- #define __GCSx_ANIMGROUP_H_
- // One tile within a animation image
- class AnimComponent {
- public:
- class TileSet* tileset;
- Uint16 index; // specifically allowed to go past # of tiles without error- just blank
- Uint16 x; // ranges from 0 to size of image - 1
- Uint16 y; // (editor tries to enforce "size of image minus size of tile", but
- // this could be exceeded in some situations)
- Uint8 r;
- Uint8 g;
- Uint8 b;
- Uint8 alpha;
- Uint8 effects; // See enum
-
- enum {
- EFFECTS_FLIP = 0x01,
- EFFECTS_MIRROR = 0x02,
- EFFECTS_ROTATE = 0x04,
- EFFECTS_ALL = 0x07,
- };
-
- AnimComponent();
- };
- // An entire single animation image or frame
- class AnimFrame {
- public:
- AnimComponent* comps;
- int count; // zero is ok
-
- Sint16 xOrigin; // point of origin for display- 0,0 for standard upperleft corner
- Sint16 yOrigin;
- Sint16 xOffs; // no limit- this is the amount the sprite itself moves by
- Sint16 yOffs;
- Uint8 delay; // cycles to delay- 1 or more
- AnimFrame();
- ~AnimFrame();
- void setCount(int newCount);
- const AnimFrame& operator=(const AnimFrame& from);
- };
- // An entire animation sequence (one or more frames)
- class AnimSequence {
- public:
- std::string name; // @TODO: lowercase?
- AnimFrame* frames;
- int width;
- int height;
- int count; // minimum one frame once created/loaded, although constructed with zero
-
- enum AnimLoop {
- LOOP_NONE = 0,
- LOOP_FORWARD,
- LOOP_PINGPONG,
- };
-
- AnimLoop loopType;
- AnimSequence();
- ~AnimSequence();
- void setCount(int newCount);
- const AnimSequence& operator=(const AnimSequence& from);
- };
- class AnimGroup : virtual public LoadOnly {
- protected:
- // Is the library cached to our file and not in memory?
- int cached;
- FileRead* cacheFile;
- int lockCount;
- // Name of animation group, where it's located
- std::string name;
- std::string nameL;
- class World* world;
-
- // Numeric ID- computer-generated- unique to world- nonzero
- int id;
-
- // Default size for a new animation
- int defWidth;
- int defHeight;
-
- // Number of animations
- int numAnim;
-
- AnimSequence* anims; // CACHEABLE
-
- enum {
- // Default image size, when creating a blank set
- IMAGE_DEFAULT_SIZE = 32,
- };
-
- public:
- // Id must be unique; use ID of 0 if we're going to load anyways
- AnimGroup(class World* myWorld, int myId = 0); // Starts with default settings
- virtual ~AnimGroup();
-
- // Do any of our animation frames use a given tileset?
- int usesTileSet(const class TileSet* tileset) const;
-
- // Accessors
- int getCount() const { return numAnim; }
- const std::string& getName() const { return name; }
- const std::string& getNameL() const { return nameL; }
- const class World* getWorld() const { return world; }
- class World* getWorld() { return world; }
- int getId() const { return id; }
- int getBlockType() const { return WorldFileLoad::BLOCKTYPE_ANIMGROUP; }
-
- // File access
- void loadHeader(FileRead* file) throw_File;
- void loadContent(FileRead* file);
- int isContentCached() const;
- void cacheLoad() throw_File;
- int markLock() throw_File;
- int markUnlock();
- int isLocked() const;
-
- // Any content-accessor functions- remember to call markLock first!
- };
- #endif
|