kick
/Users/morten/Programmering/cpp/kick/src/kick/2d/sprite.h
00001 //
00002 // Created by morten on 30/06/14.
00003 //
00004 
00005 #include "glm/glm.hpp"
00006 #include "kick/2d/component2d.h"
00007 #include "kick/scene/game_object.h"
00008 #include "kick/texture/texture_atlas.h"
00009 #include <string>
00010 #include "kick/core/event.h"
00011 #include "kick/math/bounds2.h"
00012 
00013 #pragma once
00014 
00015 namespace kick {
00016     class SpriteManager;
00017     class TextureAtlas;
00018 
00019     enum class SpriteType {
00020         Simple,
00021         // sliced in 9-patch
00022         Sliced
00023     };
00024 
00025     class Sprite : public Component2D {
00026     public:
00027         Sprite(GameObject *gameObject, std::shared_ptr<Canvas> canvas);
00028 
00029         std::shared_ptr<TextureAtlas> textureAtlas() const;
00030 
00031         void setTextureAtlas(std::shared_ptr<TextureAtlas> textureAtlas);
00032 
00033         std::string const &spriteName() const;
00034 
00035         void setSpriteName(std::string const &spriteName);
00036 
00037         TextureAtlasEntry entry() const;
00038 
00039         Bounds2 trimmedBounds() const;
00040         virtual Bounds2 bounds() const override;
00041         virtual void setBounds(Bounds2 b) override;
00042 
00043         virtual Shader *shader() const;
00044 
00045         // when sprite is sliced slice x is two relative slice positions (between 0.0 and 1.0)
00046         glm::vec2 sliceX() const;
00047         // when sprite is sliced slice x is two relative slice positions (between 0.0 and 1.0)
00048         void setSliceX(glm::vec2 sliceX);
00049         // when sprite is sliced slice y is two relative slice positions (between 0.0 and 1.0)
00050         glm::vec2 sliceY() const;
00051         // when sprite is sliced slice y is two relative slice positions (between 0.0 and 1.0)
00052         void setSliceY(glm::vec2 sliceY);
00053         // anchor (or pivot point). Default is (0.0) which is the lower left corner.
00054         glm::vec2 anchor() const;
00055         void setAnchor(glm::vec2 anchor);
00056         glm::vec2 scale() const;
00057         // scale is useful when type is sliced
00058         void setScale(glm::vec2 scale);
00059         SpriteType type() const;
00060         void setType(SpriteType type);
00061 
00062         glm::vec4 color() const;
00063         void setColor(glm::vec4 color);
00064     private:
00065         std::shared_ptr<TextureAtlas> mTextureAtlas = nullptr;
00066         std::string mSpriteName;
00067         TextureAtlasEntry mEntry;
00068         glm::vec2 mSliceX{0.333f, 0.667f};
00069         glm::vec2 mSliceY{0.333f, 0.667f};
00070         glm::vec2 mAnchor{0,0};
00071         glm::vec2 mScale{1,1};
00072         glm::vec4 mColor{1,1,1,1};
00073         SpriteType mType = SpriteType::Simple;
00074     };
00075 }
00076 
00077 
00078 
 All Classes Functions Variables