ToyMaker Game Engine 0.0.2
ToyMaker is a game engine developed and maintained by Zoheb Shujauddin.
Loading...
Searching...
No Matches
nine_slice_panel.hpp
Go to the documentation of this file.
1
11
12#ifndef ZOAPPNINESLICE_H
13#define ZOAPPNINESLICE_H
14
15#include <SDL2/SDL.h>
16#include <nlohmann/json.hpp>
17#include <glm/glm.hpp>
18
22
23namespace ToyMaker{
24
40 class NineSlicePanel: public ToyMaker::Resource<NineSlicePanel> {
41 public:
46 enum ScaleMode: uint8_t {
47 STRETCH, //< UV coordinates remain within 0 and 1, even as the panel expands or contracts.
48 TILE, //< UV coordinates for the resized panel are computed as multiples of the original pixel size of the panel's base texture.
49 };
50
58 std::shared_ptr<ToyMaker::Texture> baseTexture,
59 SDL_FRect contentRegionUV
60 );
61
67
73 inline static std::string getResourceTypeName() { return "NineSlicePanel"; }
74
81 std::shared_ptr<ToyMaker::Texture> generateTexture(glm::uvec2 contentDimensions) const;
82
88 uint32_t getOffsetPixelLeft() const;
89
95 uint32_t getOffsetPixelRight() const;
96
102 uint32_t getOffsetPixelBottom() const;
103
109 uint32_t getOffsetPixelTop() const;
110
111 private:
116 std::shared_ptr<ToyMaker::Texture> mTexture {};
117
122 SDL_FRect mContentRegion { .x{0.f}, .y{0.f}, .w{1.f}, .h{1.f} };
123
128 std::shared_ptr<ToyMaker::ShaderProgram> mShaderHandle { nullptr };
129
135 };
136
158 class NineSlicePanelFromDescription: public ToyMaker::ResourceConstructor<NineSlicePanel, NineSlicePanelFromDescription> {
159 public:
165
171 inline static std::string getResourceConstructorName() { return "fromDescription"; }
172 private:
179 std::shared_ptr<ToyMaker::IResource> createResource(const nlohmann::json& methodParameters) override;
180 };
181
183 NLOHMANN_JSON_SERIALIZE_ENUM(NineSlicePanel::ScaleMode, {
184 {NineSlicePanel::ScaleMode::STRETCH, "stretch"},
185 {NineSlicePanel::ScaleMode::TILE, "tile"},
186 });
187
188}
189
190#endif
static std::string getResourceConstructorName()
Gets the resource constructor type string associated with this class.
Definition nine_slice_panel.hpp:171
std::shared_ptr< ToyMaker::IResource > createResource(const nlohmann::json &methodParameters) override
Creates a NineSlicePanel resource from its JSON description.
Definition nine_slice_panel.cpp:165
NineSlicePanelFromDescription()
creates an instance of this constructor.
Definition nine_slice_panel.hpp:164
Resource responsible for resizing a texture using the 9-slice technique, for use in UI elements.
Definition nine_slice_panel.hpp:40
std::shared_ptr< ToyMaker::Texture > generateTexture(glm::uvec2 contentDimensions) const
Generates a new texture based on this panel resource, where the dimensions of the central region of t...
Definition nine_slice_panel.cpp:63
uint32_t getOffsetPixelBottom() const
Gets the height, in pixels, of the panel slices on the bottom side of this resource's base texture.
Definition nine_slice_panel.cpp:149
ScaleMode
The type of texture sampling to be used on the resizable regions of the base texture.
Definition nine_slice_panel.hpp:46
SDL_FRect mContentRegion
The central region of the texture, resized to fit any content placed within a panel generated from th...
Definition nine_slice_panel.hpp:122
std::shared_ptr< ToyMaker::ShaderProgram > mShaderHandle
The shader responsible for producing panell textures from a base texture.
Definition nine_slice_panel.hpp:128
uint32_t getOffsetPixelTop() const
Gets the height, in pixels, of the panel slices on the top side of this resource's base texture.
Definition nine_slice_panel.cpp:155
uint32_t getOffsetPixelRight() const
Gets the width, in pixels, of the panel slices on the right hand side of this resource's base texture...
Definition nine_slice_panel.cpp:140
~NineSlicePanel()
Destroys the NineSlicePanel object.
Definition nine_slice_panel.cpp:57
NineSlicePanel(std::shared_ptr< ToyMaker::Texture > baseTexture, SDL_FRect contentRegionUV)
Constructs a new NineSlicePanel aspect.
Definition nine_slice_panel.cpp:10
uint32_t getOffsetPixelLeft() const
Gets the width, in pixels, of the panel slices on the left hand side of this resource's base texture.
Definition nine_slice_panel.cpp:134
std::shared_ptr< ToyMaker::Texture > mTexture
The base texture used to generate new textures.
Definition nine_slice_panel.hpp:116
static std::string getResourceTypeName()
Gets the resource type string associated with this class.
Definition nine_slice_panel.hpp:73
GLuint mVertexArrayObject
The vertex array object used by this resource's panel shader.
Definition nine_slice_panel.hpp:134
An object representing one method for creating a resource of a given kind.
Definition resource_database.hpp:474
ResourceConstructor(int explicitlyInitializeMe)
Definition resource_database.hpp:491
The base class for any type whose creation and storage should be managed by the ResourceDatabase.
Definition resource_database.hpp:372
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition application.hpp:24
Headers relating to resources and their management for a given project.
A file containing class definitions for wrappers over OpenGL shader programs.
Header containing definitions of classes and functions related to loading and using Texture resources...