blob: 2b51bde3994e1bc43e4a743ae1c7aba6ad274804 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#include "cru/ui/style/Condition.hpp"
#include <memory>
#include "cru/common/Event.hpp"
#include "cru/ui/controls/Control.hpp"
#include "cru/ui/controls/IClickableControl.hpp"
#include "cru/ui/helper/ClickDetector.hpp"
namespace cru::ui::style {
CompoundCondition::CompoundCondition(
std::vector<std::unique_ptr<Condition>> conditions)
: conditions_(std::move(conditions)) {
for (const auto& p : conditions_) readonly_conditions_.push_back(p.get());
}
std::vector<IBaseEvent*> CompoundCondition::ChangeOn(
controls::Control* control) const {
std::vector<IBaseEvent*> result;
for (auto condition : GetConditions()) {
for (auto e : condition->ChangeOn(control)) {
result.push_back(e);
}
}
return result;
}
std::vector<std::unique_ptr<Condition>> CompoundCondition::CloneConditions()
const {
std::vector<std::unique_ptr<Condition>> result;
for (auto condition : GetConditions()) {
result.push_back(condition->Clone());
}
return result;
}
bool AndCondition::Judge(controls::Control* control) const {
for (auto condition : GetConditions()) {
if (!condition->Judge(control)) return false;
}
return true;
}
bool OrCondition::Judge(controls::Control* control) const {
for (auto condition : GetConditions()) {
if (condition->Judge(control)) return true;
}
return false;
}
FocusCondition::FocusCondition(bool has_focus) : has_focus_(has_focus) {}
std::vector<IBaseEvent*> FocusCondition::ChangeOn(
controls::Control* control) const {
return {control->GainFocusEvent()->Direct(),
control->LoseFocusEvent()->Direct()};
}
bool FocusCondition::Judge(controls::Control* control) const {
return control->HasFocus() == has_focus_;
}
ClickStateCondition::ClickStateCondition(helper::ClickState click_state)
: click_state_(click_state) {}
std::vector<IBaseEvent*> ClickStateCondition::ChangeOn(
controls::Control* control) const {
auto clickable_control = dynamic_cast<controls::IClickableControl*>(control);
if (clickable_control) {
return {clickable_control->ClickStateChangeEvent()};
} else {
return {};
}
}
bool ClickStateCondition::Judge(controls::Control* control) const {
auto clickable_control = dynamic_cast<controls::IClickableControl*>(control);
if (clickable_control) {
return clickable_control->GetClickState() == click_state_;
}
return false;
}
} // namespace cru::ui::style
|