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
UIImage Class Reference

The aspect class responsible for displaying an image from a file scaled to some specific dimensions. More...

#include <ui_image.hpp>

Inheritance diagram for UIImage:
ToyMaker::SimObjectAspect< UIImage > ToyMaker::BaseSimObjectAspect ToyMaker::SignalTracker ToyMaker::IActionHandler

Public Member Functions

 UIImage ()
 Constructs a new UIImage aspect.
 
std::shared_ptr< BaseSimObjectAspect > clone () const override
 Constructs a new UIImage using this object as its blueprint.
 
void onActivated () override
 Loads and displays the image associated with this aspect when it is added to the active scene.
 
void updateImage (const std::string &imageFilepath)
 Updates the image associated with this object.
 
void updateDimensions (const glm::uvec2 &dimensions)
 Changes the dimensions the loaded image should be confined or scaled to (while maintaining its original aspect).
 
void updateAnchor (const glm::vec2 &anchor)
 Updates the point considered the origin of this object's StaticModel.
 
- Public Member Functions inherited from ToyMaker::BaseSimObjectAspect
virtual ~BaseSimObjectAspect ()=default
 Destroys this object.
 
virtual void simulationUpdate (uint32_t simStepMillis)
 Overriding this allows an aspect to respond to simulation updates.
 
virtual void variableUpdate (uint32_t variableStepMillis)
 Overriding this allows an aspect to respond to variable updates.
 
bool handleAction (const ActionData &actionData, const ActionDefinition &actionDefinition) override final
 Pipes an action received from the InputManager via our SimObject to all that action's handler methods on this aspect.
 
ViewportNodegetLocalViewport ()
 Returns the closest ancestor viewport to this node, if one exists (which it should, since this shouldn't be called until this aspect is attached to an active SimObject).
 
- Public Member Functions inherited from ToyMaker::SignalTracker
 SignalTracker ()
 Constructs a new SignalTracker object.
 
 SignalTracker (const SignalTracker &other)
 Constructs a new SignalTracker.
 
SignalTrackeroperator= (const SignalTracker &other)
 Copy assignment operator.
 
 SignalTracker (SignalTracker &&other)
 Moves resources from another SignalTracker into this one, invalidating them from the other.
 
SignalTrackeroperator= (SignalTracker &&other)
 Moves resources from another SignalTracker into this one, destroying this tracker's resources in the process.
 
void connect (const std::string &theirSignal, const std::string &ourObserver, SignalTracker &other)
 Method that connects one of this objects SignalObservers to another tracker's Signal.
 

Static Public Member Functions

static std::string getSimObjectAspectTypeName ()
 Gets the aspect type string associated with this class.
 
static std::shared_ptr< BaseSimObjectAspect > create (const nlohmann::json &jsonAspectProperties)
 Creates a new UIImage instance from its description in JSON.
 

Private Member Functions

void recomputeTexture ()
 Recomputes the texture associated with this object's StaticModel.
 

Private Attributes

std::string mImageFilepath {}
 The file from which the image to be displayed was loaded.
 
glm::vec2 mAnchor {0.f, 0.f}
 The point considered the origin of this object, with (0,0) being its top left corner and (1,1) being its bottom right corner.
 
glm::uvec2 mDimensions { 0.f, 0.f }
 The dimensions within which the loaded image will be displayed.
 

Additional Inherited Members

- Protected Member Functions inherited from ToyMaker::SimObjectAspect< UIImage >
 SimObjectAspect (int explicitlyInitializeMe)
 
- Protected Member Functions inherited from ToyMaker::BaseSimObjectAspect
 BaseSimObjectAspect (const BaseSimObjectAspect &other)=delete
 
 BaseSimObjectAspect (BaseSimObjectAspect &&other)=delete
 
SimObjectgetSimObject ()
 Returns the sim object that this aspect is attached to.
 
template<typename TComponent>
void addComponent (const TComponent &component)
 Adds a component of some type to the underlying entity.
 
template<typename TComponent>
bool hasComponent ()
 Tests whether a component of some specific type is present on the object.
 
template<typename TComponent>
void updateComponent (const TComponent &component)
 Updates the value of a component belonging to this object to a new one.
 
template<typename TComponent>
TComponent getComponent (const float simulationProgress=1.f) const
 Gets the value of a component belonging to this object.
 
template<typename TComponent>
void removeComponent ()
 Removes a component of some type belonging to the underlying SimObject.
 
void addAspect (const nlohmann::json &jsonAspectProperties)
 Adds a new aspect to the underlying SimObject constructed based on its properties in JSON.
 
void addAspect (const BaseSimObjectAspect &aspect)
 Adds a new aspect to the underlying SimObject copied from an already existing aspect.
 
template<typename TSimObjectAspect>
bool hasAspect () const
 Tests whether an aspect of a particular type is attached to the underlying SimObject.
 
bool hasAspect (const std::string &aspectType) const
 Tests whether an aspect of a particular type is attached to the underlying SimObject.
 
template<typename TSimObjectAspect>
TSimObjectAspect & getAspect ()
 Gets an aspect of a particular type belonging to the underlying SimObject.
 
BaseSimObjectAspectgetAspect (const std::string &aspectType)
 Gets (a base class reference to) an aspect of a particular type belonging to the underlying SimObject.
 
template<typename TSimObjectAspect>
void removeAspect ()
 Removes an aspect from the underlying SimObject.
 
void addOrReplaceAspect (const BaseSimObjectAspect &aspect)
 Adds or replaces an aspect on the underlying SimObject with a new aspect constructed as a copy of another.
 
void addOrReplaceAspect (const nlohmann::json &jsonAspectProperties)
 Adds or replaces an aspect on the underlying SimObject with a new aspect constructed from its JSON description.
 
std::weak_ptr< FixedActionBindingdeclareFixedActionBinding (const std::string &context, const std::string &action, std::function< bool(const ActionData &, const ActionDefinition &)>)
 Binds some method (or any function) present on this object to an action generated by the InputManager.
 
EntityID getEntityID () const
 Gets the ID of the ECSWorld Entity belonging to our SimObject.
 
std::weak_ptr< ECSWorldgetWorld () const
 Gets a weak reference to the ECSWorld to which our SimObject's entity belongs.
 
- Static Protected Member Functions inherited from ToyMaker::BaseSimObjectAspect
template<typename TSimObjectAspectDerived>
static void registerAspect ()
 Registers an implementation of an aspect with the SimSystem.
 

Detailed Description

The aspect class responsible for displaying an image from a file scaled to some specific dimensions.

Usage:

Its appearance in JSON is as follows:

{
"type": "UIImage",
"image_filepath": "data/textures/button_active.png",
"dimensions": [620, 440],
"anchor": [0.5, 0.5]
}

To change the image associated with this aspect, call UIImage::updateImage(), passing the path to the file from which the new image is to be loaded.

Member Function Documentation

◆ clone()

std::shared_ptr< ToyMaker::BaseSimObjectAspect > UIImage::clone ( ) const
overridevirtual

Constructs a new UIImage using this object as its blueprint.

Returns
std::shared_ptr<BaseSimObjectAspect> A pointer to the base aspect class of the new UIImage object.

Implements ToyMaker::BaseSimObjectAspect.

◆ create()

std::shared_ptr< ToyMaker::BaseSimObjectAspect > UIImage::create ( const nlohmann::json & jsonAspectProperties)
static

Creates a new UIImage instance from its description in JSON.

Parameters
jsonAspectPropertiesThe JSON description of the UIImage instance.
Returns
std::shared_ptr<BaseSimObjectAspect> The newly constructed UIImage object.

◆ getSimObjectAspectTypeName()

static std::string UIImage::getSimObjectAspectTypeName ( )
inlinestatic

Gets the aspect type string associated with this class.

Returns
std::string This class' aspect type string.

◆ onActivated()

void UIImage::onActivated ( )
overridevirtual

Loads and displays the image associated with this aspect when it is added to the active scene.

Reimplemented from ToyMaker::BaseSimObjectAspect.

◆ updateAnchor()

void UIImage::updateAnchor ( const glm::vec2 & anchor)

Updates the point considered the origin of this object's StaticModel.

(0, 0) corresponds to the top left corner of this object, while (1, 1) corresponds to the bottom right corner.

Parameters
anchorThe new origin of the object, relative to its top left corner and the objects total dimensions.

◆ updateDimensions()

void UIImage::updateDimensions ( const glm::uvec2 & dimensions)

Changes the dimensions the loaded image should be confined or scaled to (while maintaining its original aspect).

Parameters
dimensionsThe new dimensions of the image.

◆ updateImage()

void UIImage::updateImage ( const std::string & imageFilepath)

Updates the image associated with this object.

Parameters
imageFilepathThe path to the file containing the new image to be displayed.

The documentation for this class was generated from the following files: