@@ -77,7 +77,15 @@ void status_bar::set_min_value(float min_value) {
77
77
if (min_value_ > max_value_)
78
78
min_value_ = max_value_;
79
79
80
- value_ = std::clamp (value_, min_value_, max_value_);
80
+ const auto old_value = value_;
81
+ value_ = std::clamp (value_, min_value_, max_value_);
82
+
83
+ if (value_ != old_value) {
84
+ alive_checker checker (*this );
85
+ fire_script (" OnValueChanged" , {value_});
86
+ if (!checker.is_alive ())
87
+ return ;
88
+ }
81
89
82
90
notify_bar_texture_needs_update_ ();
83
91
}
@@ -90,7 +98,15 @@ void status_bar::set_max_value(float max_value) {
90
98
if (max_value_ < min_value_)
91
99
max_value_ = min_value_;
92
100
93
- value_ = std::clamp (value_, min_value_, max_value_);
101
+ const auto old_value = value_;
102
+ value_ = std::clamp (value_, min_value_, max_value_);
103
+
104
+ if (value_ != old_value) {
105
+ alive_checker checker (*this );
106
+ fire_script (" OnValueChanged" , {value_});
107
+ if (!checker.is_alive ())
108
+ return ;
109
+ }
94
110
95
111
notify_bar_texture_needs_update_ ();
96
112
}
@@ -102,7 +118,15 @@ void status_bar::set_min_max_values(float min_value, float max_value) {
102
118
min_value_ = std::min (min_value, max_value);
103
119
max_value_ = std::max (min_value, max_value);
104
120
105
- value_ = std::clamp (value_, min_value_, max_value_);
121
+ const auto old_value = value_;
122
+ value_ = std::clamp (value_, min_value_, max_value_);
123
+
124
+ if (value_ != old_value) {
125
+ alive_checker checker (*this );
126
+ fire_script (" OnValueChanged" , {value_});
127
+ if (!checker.is_alive ())
128
+ return ;
129
+ }
106
130
107
131
notify_bar_texture_needs_update_ ();
108
132
}
@@ -114,13 +138,21 @@ void status_bar::set_value(float value) {
114
138
return ;
115
139
116
140
value_ = value;
141
+
142
+ alive_checker checker (*this );
143
+ fire_script (" OnValueChanged" , {value_});
144
+ if (!checker.is_alive ())
145
+ return ;
146
+
117
147
notify_bar_texture_needs_update_ ();
118
148
}
119
149
120
150
void status_bar::set_bar_draw_layer (layer bar_layer) {
121
151
bar_layer_ = bar_layer;
122
- if (bar_texture_)
152
+
153
+ if (bar_texture_) {
123
154
bar_texture_->set_draw_layer (bar_layer_);
155
+ }
124
156
}
125
157
126
158
void status_bar::set_bar_texture (utils::observer_ptr<texture> bar_texture) {
@@ -133,10 +165,11 @@ void status_bar::set_bar_texture(utils::observer_ptr<texture> bar_texture) {
133
165
134
166
std::string parent = bar_texture_->get_parent ().get () == this ? " $parent" : name_;
135
167
136
- if (is_reversed_)
168
+ if (is_reversed_) {
137
169
bar_texture_->set_point (point::top_right, parent);
138
- else
170
+ } else {
139
171
bar_texture_->set_point (point::bottom_left, parent);
172
+ }
140
173
141
174
initial_text_coords_ = select_uvs (bar_texture_->get_tex_coord ());
142
175
notify_bar_texture_needs_update_ ();
@@ -164,13 +197,15 @@ void status_bar::set_reversed(bool reversed) {
164
197
is_reversed_ = reversed;
165
198
166
199
if (bar_texture_) {
167
- if (is_reversed_)
200
+ if (is_reversed_) {
168
201
bar_texture_->set_point (point::top_right);
169
- else
202
+ } else {
170
203
bar_texture_->set_point (point::bottom_left);
204
+ }
171
205
172
- if (!is_virtual_)
206
+ if (!is_virtual_) {
173
207
bar_texture_->notify_borders_need_update ();
208
+ }
174
209
}
175
210
}
176
211
@@ -215,41 +250,34 @@ void status_bar::create_bar_texture_() {
215
250
set_bar_texture (bar_texture);
216
251
}
217
252
218
- void status_bar::update (float delta) {
219
- if (update_bar_texture_flag_ && bar_texture_) {
220
- float coef = (value_ - min_value_) / (max_value_ - min_value_);
253
+ void status_bar::notify_bar_texture_needs_update_ () {
254
+ if (!bar_texture_)
255
+ return ;
256
+
257
+ float coef = (value_ - min_value_) / (max_value_ - min_value_);
221
258
222
- if (orientation_ == orientation::horizontal)
223
- bar_texture_->set_relative_dimensions (vector2f (coef, 1 .0f ));
224
- else
225
- bar_texture_->set_relative_dimensions (vector2f (1 .0f , coef));
259
+ if (orientation_ == orientation::horizontal) {
260
+ bar_texture_->set_relative_dimensions (vector2f (coef, 1 .0f ));
261
+ } else {
262
+ bar_texture_->set_relative_dimensions (vector2f (1 .0f , coef));
263
+ }
226
264
227
- std::array<float , 4 > uvs = initial_text_coords_;
228
- if (orientation_ == orientation::horizontal) {
229
- if (is_reversed_)
230
- uvs[0 ] = (uvs[0 ] - uvs[2 ]) * coef + uvs[2 ];
231
- else
232
- uvs[2 ] = (uvs[2 ] - uvs[0 ]) * coef + uvs[0 ];
265
+ std::array<float , 4 > uvs = initial_text_coords_;
266
+ if (orientation_ == orientation::horizontal) {
267
+ if (is_reversed_) {
268
+ uvs[0 ] = (uvs[0 ] - uvs[2 ]) * coef + uvs[2 ];
233
269
} else {
234
- if (is_reversed_)
235
- uvs[3 ] = (uvs[3 ] - uvs[1 ]) * coef + uvs[1 ];
236
- else
237
- uvs[1 ] = (uvs[1 ] - uvs[3 ]) * coef + uvs[3 ];
270
+ uvs[2 ] = (uvs[2 ] - uvs[0 ]) * coef + uvs[0 ];
271
+ }
272
+ } else {
273
+ if (is_reversed_) {
274
+ uvs[3 ] = (uvs[3 ] - uvs[1 ]) * coef + uvs[1 ];
275
+ } else {
276
+ uvs[1 ] = (uvs[1 ] - uvs[3 ]) * coef + uvs[3 ];
238
277
}
239
-
240
- bar_texture_->set_tex_rect (uvs);
241
-
242
- update_bar_texture_flag_ = false ;
243
278
}
244
279
245
- alive_checker checker (*this );
246
- base::update (delta);
247
- if (!checker.is_alive ())
248
- return ;
249
- }
250
-
251
- void status_bar::notify_bar_texture_needs_update_ () {
252
- update_bar_texture_flag_ = true ;
280
+ bar_texture_->set_tex_rect (uvs);
253
281
}
254
282
255
283
} // namespace lxgui::gui
0 commit comments