47 #ifndef __CU_BUTTON_H__
48 #define __CU_BUTTON_H__
49 #include <cugl/2d/CUNode.h>
50 #include <cugl/2d/CUPolygonNode.h>
51 #include <cugl/math/CUColor4.h>
52 #include <unordered_map>
57 #pragma mark ButtonListener
77 typedef std::function<void(const std::string& name, bool down)>
ButtonListener;
120 #pragma mark Constructors
129 Button() : _down(false), _active(false), _mouse(false), _listener(nullptr) {}
146 virtual void dispose()
override;
157 CUAssertLog(
false,
"This node does not support the empty initializer");
171 bool init(
const std::shared_ptr<Node>& up) {
186 bool init(
const std::shared_ptr<Node>& up,
Color4 down);
200 bool init(
const std::shared_ptr<Node>& up,
const std::shared_ptr<Node>& down);
202 #pragma mark Static Constructors
213 static std::shared_ptr<Button>
alloc(
const std::shared_ptr<Node>& up) {
214 std::shared_ptr<Button> node = std::make_shared<Button>();
215 return (node->init(up) ? node :
nullptr);
229 static std::shared_ptr<Button>
alloc(
const std::shared_ptr<Node>& up,
Color4 down) {
230 std::shared_ptr<Button> node = std::make_shared<Button>();
231 return (node->init(up,down) ? node :
nullptr);
246 static std::shared_ptr<Button>
alloc(
const std::shared_ptr<Node>& up,
const std::shared_ptr<Node>& down) {
247 std::shared_ptr<Button> node = std::make_shared<Button>();
248 return (node->init(up,down) ? node :
nullptr);
251 #pragma mark Button State
312 #pragma mark Listeners
346 void setListener(ButtonListener listener) { _listener = listener; }
bool contains(const Rect &rect) const
Vec2 screenToNodeCoords(const Vec2 &screenPoint) const
const Size & getContentSize() const
Definition: CUNode.h:652
std::function< void(const std::string &name, bool down)> ButtonListener
Definition: CUButton.h:77
static const Color4 GRAY
Definition: CUColor4.h:1144
Definition: CUColor4.h:1104
Definition: CUAnimationNode.h:52
static const Vec2 ZERO
Definition: CUVec2.h:71