-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathLabelCellOption.cpp
More file actions
115 lines (100 loc) · 2.96 KB
/
LabelCellOption.cpp
File metadata and controls
115 lines (100 loc) · 2.96 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* Label Cell
*
* From: https://github.com/PokemonAutomation/
*
*/
#include "Common/Cpp/Containers/Pimpl.tpp"
#include "Common/Cpp/Json/JsonValue.h"
#include "Common/Cpp/Concurrency/SpinLock.h"
#include "LabelCellOption.h"
//#include <iostream>
//using std::cout;
//using std::endl;
namespace PokemonAutomation{
struct LabelCellOption::Data{
mutable SpinLock m_lock;
std::string m_text;
// ImageRGB32 m_icon_owner;
ImageViewRGB32 m_icon;
Resolution m_resolution;
Data(std::string text)
: m_text(std::move(text))
{}
Data(std::string text, const ImageViewRGB32& icon)
: m_text(std::move(text))
, m_icon(icon)
{}
Data(std::string text, const ImageViewRGB32& icon, size_t icon_size)
: m_text(std::move(text))
, m_icon(icon)
{
size_t width = icon.width();
size_t height = icon.height();
if (width < height){
width = width * icon_size / height;
height = icon_size;
}else{
height = height * icon_size / width;
width = icon_size;
}
m_resolution.width = width;
m_resolution.height = height;
}
// Data(std::string text, ImageRGB32 icon)
// : m_text(std::move(text))
// , m_icon_owner(std::move(icon))
// , m_icon(m_icon_owner)
// {}
};
LabelCellOption::~LabelCellOption() = default;
LabelCellOption::LabelCellOption(
LockMode lock_while_running,
std::string text
)
: ConfigOptionImpl<LabelCellOption>(lock_while_running)
, m_data(CONSTRUCT_TOKEN, std::move(text))
{}
LabelCellOption::LabelCellOption(
LockMode lock_while_running,
std::string text, const ImageViewRGB32& icon
)
: ConfigOptionImpl<LabelCellOption>(lock_while_running)
, m_data(CONSTRUCT_TOKEN, std::move(text), icon)
{}
LabelCellOption::LabelCellOption(
LockMode lock_while_running,
std::string text, const ImageViewRGB32& icon, size_t icon_size
)
: ConfigOptionImpl<LabelCellOption>(lock_while_running)
, m_data(CONSTRUCT_TOKEN, std::move(text), icon, icon_size)
{}
//LabelCellOption::LabelCellOption(std::string text, ImageRGB32 icon)
// : m_data(CONSTRUCT_TOKEN, std::move(text), std::move(icon))
//{}
const std::string& LabelCellOption::text() const{
ReadSpinLock lg(m_data->m_lock);
return m_data->m_text;
}
const ImageViewRGB32& LabelCellOption::icon() const{
return m_data->m_icon;
}
Resolution LabelCellOption::resolution() const{
return m_data->m_resolution;
}
void LabelCellOption::load_json(const JsonValue&){
}
JsonValue LabelCellOption::to_json() const{
return JsonValue();
}
void LabelCellOption::set_text(std::string x){
// sanitize(x);
{
WriteSpinLock lg(m_data->m_lock);
if (m_data->m_text == x){
return;
}
m_data->m_text = std::move(x);
}
report_value_changed(this);
}
}