kick
|
00001 // 00002 // Created by morten on 26/07/14. 00003 // 00004 00005 00006 #pragma once 00007 00008 #include "kick/scene/component_renderable.h" 00009 #include "kick/scene/updatable.h" 00010 #include "kick/scene/camera.h" 00011 #include "kick/2d/component2d.h" 00012 #include "kick/texture/texture_atlas.h" 00013 #include "kick/core/mouse_input.h" 00014 #include <vector> 00015 00016 namespace kick { 00017 class Camera; 00018 class Button; 00019 class ToggleButton; 00020 class Sprite; 00021 class Label; 00022 class Mesh; 00023 class MeshData; 00024 class SpriteMouseListener; 00025 00026 00027 class Canvas : public ComponentRenderable, public Updatable { 00028 00029 public: 00030 Canvas(GameObject *gameObject); 00031 virtual ~Canvas(); 00032 00033 virtual void deactivated() override; 00034 00035 virtual void render(EngineUniforms *engineUniforms, Material* replacementMaterial = nullptr) override; 00036 00037 virtual void update() override; 00038 00039 virtual int renderOrder(); 00040 00041 std::shared_ptr<Camera> camera() const; 00042 void setCamera(std::shared_ptr<Camera> camera); 00043 00044 template <typename C, typename... T> 00045 std::shared_ptr<C> addComponent(T... t); 00046 00047 // 00048 std::shared_ptr<ToggleButton> createToggleButton(std::string text = ""); 00049 00050 // 00051 std::shared_ptr<Button> createButton(std::string text = ""); 00052 // helper function, which creates a gameobject and attaches an sprite object 00053 std::shared_ptr<Sprite> createSprite(std::shared_ptr<TextureAtlas> textureAtlas, std::string spriteName, glm::vec2 pos = glm::vec2{0}); 00054 // 00055 std::shared_ptr<Label> createLabel(std::string text, int fontsize = 16); 00056 00057 private: 00058 void updateVertexBuffer(std::vector<Sprite*> &sprites); 00059 void renderSprites(std::vector<Sprite*> &sprites, kick::EngineUniforms *engineUniforms, Material* replacementMaterial); 00060 friend class Component2D; 00061 void updateRenderOrder(std::shared_ptr<Component2D> comp); 00062 void registerComponent2D(std::shared_ptr<Component2D> comp); 00063 void deregisterComponent2D(std::shared_ptr<Component2D> comp); 00064 std::shared_ptr<Camera> mCamera; 00065 std::shared_ptr<Camera> mOwnCamera; 00066 std::vector<std::shared_ptr<Component2D>> mComponents; 00067 std::vector<std::shared_ptr<SpriteMouseListener>> mMouseListeners; 00068 std::vector<std::shared_ptr<SpriteMouseListener>> mMouseOver; 00069 std::vector<std::pair<std::shared_ptr<SpriteMouseListener>, int>> mMousePressed; 00070 Mesh *mMesh = nullptr; 00071 std::shared_ptr<MeshData> mMeshData; 00072 Material*mMaterial = nullptr; 00073 GameObject *createGameObject(); 00074 }; 00075 } 00076 00077 #include "kick/2d/canvas.inl"