Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
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
19#include "toymaker/shader_program.hpp"
20#include "toymaker/core/resource_database.hpp"
21#include "toymaker/texture.hpp"
22
38class NineSlicePanel: public ToyMaker::Resource<NineSlicePanel> {
39public:
44 enum ScaleMode: uint8_t {
45 STRETCH, //< UV coordinates remain within 0 and 1, even as the panel expands or contracts.
46 TILE, //< UV coordinates for the resized panel are computed as multiples of the original pixel size of the panel's base texture.
47 };
48
56 std::shared_ptr<ToyMaker::Texture> baseTexture,
57 SDL_FRect contentRegionUV
58 );
59
65
71 inline static std::string getResourceTypeName() { return "NineSlicePanel"; }
72
79 std::shared_ptr<ToyMaker::Texture> generateTexture(glm::uvec2 contentDimensions) const;
80
86 uint32_t getOffsetPixelLeft() const;
87
93 uint32_t getOffsetPixelRight() const;
94
100 uint32_t getOffsetPixelBottom() const;
101
107 uint32_t getOffsetPixelTop() const;
108
109private:
114 std::shared_ptr<ToyMaker::Texture> mTexture {};
115
120 SDL_FRect mContentRegion { .x{0.f}, .y{0.f}, .w{1.f}, .h{1.f} };
121
126 std::shared_ptr<ToyMaker::ShaderProgram> mShaderHandle { nullptr };
127
133};
134
156class NineSlicePanelFromDescription: public ToyMaker::ResourceConstructor<NineSlicePanel, NineSlicePanelFromDescription> {
157public:
163
169 inline static std::string getResourceConstructorName() { return "fromDescription"; }
170private:
177 std::shared_ptr<ToyMaker::IResource> createResource(const nlohmann::json& methodParameters) override;
178};
179
181NLOHMANN_JSON_SERIALIZE_ENUM(NineSlicePanel::ScaleMode, {
182 {NineSlicePanel::ScaleMode::STRETCH, "stretch"},
183 {NineSlicePanel::ScaleMode::TILE, "tile"},
184});
185
186#endif
NineSlicePanelFromDescription()
creates an instance of this constructor.
Definition nine_slice_panel.hpp:162
std::shared_ptr< ToyMaker::IResource > createResource(const nlohmann::json &methodParameters) override
Creates a NineSlicePanel resource from its JSON description.
Definition nine_slice_panel.cpp:163
static std::string getResourceConstructorName()
Gets the resource constructor type string associated with this class.
Definition nine_slice_panel.hpp:169
Resource responsible for resizing a texture using the 9-slice technique, for use in UI elements.
Definition nine_slice_panel.hpp:38
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:61
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:147
GLuint mVertexArrayObject
The vertex array object used by this resource's panel shader.
Definition nine_slice_panel.hpp:132
ScaleMode
The type of texture sampling to be used on the resizable regions of the base texture.
Definition nine_slice_panel.hpp:44
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:120
static std::string getResourceTypeName()
Gets the resource type string associated with this class.
Definition nine_slice_panel.hpp:71
std::shared_ptr< ToyMaker::Texture > mTexture
The base texture used to generate new textures.
Definition nine_slice_panel.hpp:114
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:153
std::shared_ptr< ToyMaker::ShaderProgram > mShaderHandle
The shader responsible for producing panell textures from a base texture.
Definition nine_slice_panel.hpp:126
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:138
~NineSlicePanel()
Destroys the NineSlicePanel object.
Definition nine_slice_panel.cpp:55
NineSlicePanel(std::shared_ptr< ToyMaker::Texture > baseTexture, SDL_FRect contentRegionUV)
Constructs a new NineSlicePanel aspect.
Definition nine_slice_panel.cpp:8
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:132
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 camera_system.hpp:20