malena
Why malena
Quick start
Tutorials
API docs
GitHub
GitHub
Tutorials
Loading...
Searching...
No Matches
Graphics
Controls
ColorButton.h
Go to the documentation of this file.
1
// Copyright (c) 2025 Dave R. Smith.
2
// Malena Framework — Licensed under PolyForm Noncommercial 1.0.0; commercial use requires a paid license. See LICENSE.
3
4
#ifndef MALENA_COLORBUTTON_H
5
#define MALENA_COLORBUTTON_H
6
7
#pragma once
8
9
#include <
Malena/Core/malena_export.h
>
10
#include <
Malena/Graphics/Base/Graphic.h
>
11
#include <
SFML/Graphics/RectangleShape.hpp
>
12
#include <functional>
13
14
namespace
ml
15
{
24
class
MALENA_API
ColorButton
:
public
Graphic
<sf::RectangleShape>
25
{
26
public
:
27
ColorButton
();
28
29
void
setColor
(
const
sf::Color
& c);
30
[[nodiscard]]
sf::Color
color
()
const
{
return
_color; }
31
34
void
setColorProvider
(std::function<
sf::Color
()> provider);
35
36
void
onClick
(std::function<
void
()> cb);
37
38
void
setSize
(
const
sf::Vector2f
& size);
39
[[nodiscard]]
sf::Vector2f
getSize
()
const
{
return
_size; }
40
41
void
setPosition
(
const
sf::Vector2f
& pos)
override
;
42
[[nodiscard]]
sf::Vector2f
getPosition
()
const override
;
43
[[nodiscard]]
sf::FloatRect
getGlobalBounds
()
const override
;
44
45
void
draw
(
sf::RenderTarget
& target,
sf::RenderStates
states)
const override
;
46
47
private
:
48
sf::Color
_color { 30, 30, 30 };
49
sf::Vector2f
_pos { 0.f, 0.f };
50
sf::Vector2f
_size { 26.f, 26.f };
51
bool
_prevMouseDown =
false
;
52
mutable
bool
_hover =
false
;
53
std::function<void()> _onClick;
54
std::function<sf::Color()> _colorProvider;
55
};
56
57
}
// namespace ml
58
59
#endif
// MALENA_COLORBUTTON_H
Graphic.h
RectangleShape.hpp
ml::ColorButton::onClick
void onClick(std::function< void()> cb)
ml::ColorButton::setColorProvider
void setColorProvider(std::function< sf::Color()> provider)
ml::ColorButton::getGlobalBounds
sf::FloatRect getGlobalBounds() const override
Return the axis-aligned bounding box in world space.
ml::ColorButton::ColorButton
ColorButton()
ml::ColorButton::getSize
sf::Vector2f getSize() const
Definition
ColorButton.h:39
ml::ColorButton::getPosition
sf::Vector2f getPosition() const override
Return the current world-space position.
ml::ColorButton::color
sf::Color color() const
Definition
ColorButton.h:30
ml::ColorButton::setPosition
void setPosition(const sf::Vector2f &pos) override
Set the world-space position immediately (no animation).
ml::ColorButton::setColor
void setColor(const sf::Color &c)
ml::ColorButton::setSize
void setSize(const sf::Vector2f &size)
ml::ColorButton::draw
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
ml::Graphic< sf::RectangleShape >::Graphic
Graphic()
sf::Color
sf::RenderTarget
malena_export.h
MALENA_API
#define MALENA_API
Definition
malena_export.h:18
ml
Definition
Component.h:22
sf::FloatRect
Rect< float > FloatRect
sf::Vector2f
Vector2< float > Vector2f
sf::RenderStates