Kiwano Engine v1.3.x
Button.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/base/component/MouseSensor.h>
23
24namespace kiwano
25{
26
36class KGE_API ButtonBase : public MouseSensor
37{
38public:
41 enum class Event
42 {
43 MouseEntered,
44 MouseExited,
45 Pressed,
46 Released,
47 Clicked,
48 };
49
50 ButtonBase();
51
52 virtual ~ButtonBase();
53
56 virtual void OnEvent(Event evt) = 0;
57
58protected:
61 void HandleEvent(kiwano::Event* evt) override;
62};
63
68class KGE_API Button : public ButtonBase
69{
70public:
73 using Callback = Function<void(Button* /* self */, Event /* evt */)>;
74
77 using ClickedCallback = Function<void(Button* /* self */)>;
78
79 Button();
80
84 Button(const Callback& cb);
85
89 void SetCallback(const Callback& cb);
90
94 void SetCallbackOnClicked(const ClickedCallback& cb);
95
98 void OnEvent(Event evt) override;
99
100private:
101 Callback cb_;
102 ClickedCallback clicked_cb_;
103};
104
108{
109 cb_ = cb;
110}
111
113{
114 clicked_cb_ = cb;
115}
116
117} // namespace kiwano
基础按钮组件
Definition: Button.h:37
virtual void OnEvent(Event evt)=0
按钮事件发生时
Event
按钮事件
Definition: Button.h:42
按钮组件
Definition: Button.h:69
void SetCallback(const Callback &cb)
设置按钮回调函数
Definition: Button.h:107
void SetCallbackOnClicked(const ClickedCallback &cb)
设置按钮回调函数
Definition: Button.h:112
事件
Definition: Event.h:43
鼠标传感器
Definition: MouseSensor.h:39