pad object can be disabled and/or hidden
This commit is contained in:
parent
a91bc4b773
commit
333a7b73ac
43
src/Pad.hpp
43
src/Pad.hpp
|
@ -51,6 +51,7 @@ namespace sb
|
|||
sb::Plane _plane;
|
||||
Box box;
|
||||
int texture_index = 0;
|
||||
bool _enabled = true, _visible = true;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -223,6 +224,8 @@ namespace sb
|
|||
* @param texture_flag_uniform uniform ID for boolean enabling or disabling texture display
|
||||
*/
|
||||
void draw(GLuint transformation_uniform, glm::mat4 view, glm::mat4 projection, std::optional<GLuint> texture_flag_uniform = std::nullopt)
|
||||
{
|
||||
if (_visible)
|
||||
{
|
||||
if (!_plane.textures().empty())
|
||||
{
|
||||
|
@ -253,17 +256,26 @@ namespace sb
|
|||
glDrawArrays(GL_TRIANGLES, 0, _plane.attributes("position")->count());
|
||||
_plane.disable();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* Run the reaction function.
|
||||
*
|
||||
* @param args arguments to pass to the reaction function
|
||||
* @return result of the reaction function if it returns a value, or void otherwise
|
||||
* @param args Arguments to pass to the reaction function
|
||||
* @exception std::runtime_error if the pad is currently disabled
|
||||
* @return Result of the reaction function if it returns a value, or void otherwise
|
||||
*/
|
||||
ReturnType press(Arguments... args)
|
||||
{
|
||||
if (!_enabled)
|
||||
{
|
||||
throw std::runtime_error("The pad cannot be pressed because it is currently disabled. Please check Pad::enabled before calling Pad::press.");
|
||||
}
|
||||
else
|
||||
{
|
||||
return connection.flip(args...);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @return the state of the pad
|
||||
|
@ -290,5 +302,32 @@ namespace sb
|
|||
{
|
||||
return _plane.size();
|
||||
}
|
||||
|
||||
/*!
|
||||
* By default, a pad object is enabled to accept input presses. If the pad is disabled, however, the press function will not be able to be
|
||||
* used and will throw an exception. This function can be used both to check the state and to set the state.
|
||||
*
|
||||
* @param state Set to false to disable, true to enable, or omit to check the current state
|
||||
* @return True if button is set to enabled
|
||||
*/
|
||||
bool enabled(std::optional<bool> state = std::nullopt)
|
||||
{
|
||||
if (state.has_value())
|
||||
{
|
||||
_enabled = state.value();
|
||||
}
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Use this function to prevent the draw function from running, which will prevent the pad object from being rendered. Note that this does
|
||||
* not disable input. To do that, use Pad::enabled(bool)
|
||||
*
|
||||
* @param state Set to false to prevent the pad from being drawn, set to true to re-enable drawing
|
||||
*/
|
||||
void visible(bool state = true)
|
||||
{
|
||||
_visible = state;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue