Skip to content

Commit 9b562d3

Browse files
committed
Replaced Widget's set(De)Activated functions with one setActive(bool)
function, which simplifies code for various screen a lot.
1 parent 8059544 commit 9b562d3

33 files changed

+161
-307
lines changed

src/guiengine/widget.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,29 +148,15 @@ void Widget::elementRemoved()
148148

149149
// -----------------------------------------------------------------------------
150150

151-
void Widget::setActivated()
151+
void Widget::setActive(bool active)
152152
{
153153
// even if this one is already active, do it anyway on purpose, maybe the
154154
// children widgets need to be updated
155-
m_deactivated = false;
155+
m_deactivated = !active;
156156
const int count = m_children.size();
157157
for (int n=0; n<count; n++)
158158
{
159-
m_children[n].setActivated();
160-
}
161-
}
162-
163-
// -----------------------------------------------------------------------------
164-
165-
void Widget::setDeactivated()
166-
{
167-
// even if this one is already inactive, do it anyway on purpose, maybe the
168-
// children widgets need to be updated
169-
m_deactivated = true;
170-
const int count = m_children.size();
171-
for (int n=0; n<count; n++)
172-
{
173-
m_children[n].setDeactivated();
159+
m_children[n].setActive(active);
174160
}
175161
}
176162

src/guiengine/widget.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ namespace GUIEngine
322322
/**
323323
* \brief Sets the widget (and its children, if any) visible or not.
324324
* Note that setting a widget invisible implicitely calls setDeactivated(), and setting
325-
* it visible implicitely calls setActivated(). If you mix visiblity and (de)activated calls,
325+
* it visible implicitely calls setActive(true). If you mix visiblity and (de)activated calls,
326326
* undefined behavior may ensue (like invisible but clickable buttons).
327327
*/
328328
void setVisible(bool visible);
@@ -352,12 +352,11 @@ namespace GUIEngine
352352
* \{
353353
*/
354354

355-
/** \brief undos setDeactivated() */
356-
virtual void setActivated();
357-
358-
/** \brief greys out the widget, making it not clickable for the user */
359-
virtual void setDeactivated();
360-
355+
/** \brief Sets an widget to be either activated or deactivated
356+
* (i.e. greyed out)
357+
* \param active Active (true) or deactive (false). Defaults to
358+
* true. */
359+
virtual void setActive(bool active=true);
361360

362361
/**
363362
* \}

src/guiengine/widgets/spinner_widget.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -395,36 +395,34 @@ void SpinnerWidget::setValue(irr::core::stringw new_value)
395395

396396
// -----------------------------------------------------------------------------
397397

398-
void SpinnerWidget::setActivated()
398+
void SpinnerWidget::setActive(bool active)
399399
{
400-
Widget::setActivated();
400+
Widget::setActive(active);
401401

402-
setText(L"");
403-
if (m_customText.empty())
402+
if (active)
404403
{
405-
setValue( getValue() ); // Update the display
404+
setText(L"");
405+
if (m_customText.empty())
406+
{
407+
setValue(getValue()); // Update the display
408+
}
409+
else
410+
{
411+
setCustomText(m_customText);
412+
}
406413
}
407414
else
408415
{
409-
setCustomText(m_customText);
416+
// Save it temporary because setValue(which is uses for update in
417+
// this case) overwrites it
418+
core::stringw customText = m_customText;
419+
setText(L"-");
420+
setValue(getValue()); // Update the display
421+
m_customText = customText;
410422
}
411-
}
412-
413-
// -----------------------------------------------------------------------------
414-
415-
void SpinnerWidget::setDeactivated()
416-
{
417-
Widget::setDeactivated();
418-
419-
// Save it temporary because setValue(which is uses for update in this case) overwrites it
420-
core::stringw customText = m_customText;
421-
setText(L"-");
422-
setValue( getValue() ); // Update the display
423-
m_customText = customText;
424-
}
423+
} // setActive
425424

426425
// -----------------------------------------------------------------------------
427-
428426
void SpinnerWidget::setCustomText(const core::stringw& text)
429427
{
430428
m_customText = text;

src/guiengine/widgets/spinner_widget.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,7 @@ namespace GUIEngine
193193

194194
// --------------------------------------------------------------------
195195
/** Override method from base class Widget */
196-
virtual void setActivated();
197-
198-
/** Override method from base class Widget */
199-
virtual void setDeactivated();
196+
virtual void setActive(bool active = true);
200197

201198
/** Display custom text in spinner */
202199
void setCustomText(const core::stringw& text);

src/guiengine/widgets/text_box_widget.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -174,30 +174,16 @@ void TextBoxWidget::elementRemoved()
174174

175175
// -----------------------------------------------------------------------------
176176

177-
void TextBoxWidget::setActivated()
177+
void TextBoxWidget::setActive(bool active)
178178
{
179-
Widget::setActivated();
179+
Widget::setActive(active);
180180

181181
if (m_element != NULL)
182182
{
183183
IGUIEditBox* textCtrl = Widget::getIrrlichtElement<IGUIEditBox>();
184184
assert(textCtrl != NULL);
185-
textCtrl->setEnabled(true);
185+
textCtrl->setEnabled(active);
186186
}
187-
}
188-
189-
// -----------------------------------------------------------------------------
190-
191-
void TextBoxWidget::setDeactivated()
192-
{
193-
Widget::setDeactivated();
194-
195-
if (m_element != NULL)
196-
{
197-
IGUIEditBox* textCtrl = Widget::getIrrlichtElement<IGUIEditBox>();
198-
assert(textCtrl != NULL);
199-
textCtrl->setEnabled(false);
200-
}
201-
}
187+
} // setActive
202188

203189
// -----------------------------------------------------------------------------

src/guiengine/widgets/text_box_widget.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ namespace GUIEngine
7373
virtual void elementRemoved();
7474

7575
/** Override method from base class Widget */
76-
virtual void setActivated();
77-
78-
/** Override method from base class Widget */
79-
virtual void setDeactivated();
76+
virtual void setActive(bool active=true);
8077
};
8178
}
8279

src/states_screens/addons_screen.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void AddonsScreen::init()
143143
m_sort_default = true;
144144
m_sort_col = 0;
145145

146-
getWidget<GUIEngine::RibbonWidget>("category")->setDeactivated();
146+
getWidget<GUIEngine::RibbonWidget>("category")->setActive(false);
147147

148148
if(UserConfigParams::logAddons())
149149
Log::info("addons", "Using directory <%s>", file_manager->getAddonsDir().c_str());
@@ -157,10 +157,8 @@ void AddonsScreen::init()
157157
w_list->setIcons(m_icon_bank, (int)(m_icon_height));
158158

159159
m_type = "kart";
160-
if (UserConfigParams::m_internet_status != RequestManager::IPERM_ALLOWED)
161-
getWidget<GUIEngine::IconButtonWidget>("reload")->setDeactivated();
162-
else
163-
getWidget<GUIEngine::IconButtonWidget>("reload")->setActivated();
160+
bool ip = UserConfigParams::m_internet_status == RequestManager::IPERM_ALLOWED;
161+
getWidget<GUIEngine::IconButtonWidget>("reload")->setActive(ip);
164162

165163
// Reset filter.
166164
GUIEngine::TextBoxWidget* w_filter_name =
@@ -371,7 +369,7 @@ void AddonsScreen::loadList()
371369
}
372370
}
373371

374-
getWidget<GUIEngine::RibbonWidget>("category")->setActivated();
372+
getWidget<GUIEngine::RibbonWidget>("category")->setActive(true);
375373
if(m_type == "kart")
376374
getWidget<GUIEngine::RibbonWidget>("category")->select("tab_kart",
377375
PLAYER_ID_GAME_MASTER);

src/states_screens/create_server_screen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void CreateServerScreen::onUpdate(float delta)
109109
}
110110
delete m_server_creation_request;
111111
m_server_creation_request = NULL;
112-
//m_options_widget->setActivated();
112+
//m_options_widget->setActive(true);
113113
}
114114
else
115115
{

src/states_screens/dialogs/change_password_dialog.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void ChangePasswordDialog::submit()
148148
}
149149
else
150150
{
151-
m_options_widget->setDeactivated();
151+
m_options_widget->setActive(false);
152152
m_info_widget->setDefaultColor();
153153

154154
// We don't need to use password 2 anymore, it was already confirmed
@@ -208,7 +208,7 @@ void ChangePasswordDialog::success()
208208
{
209209
m_info_widget->setDefaultColor();
210210
m_info_widget->setText(_("Password successfully changed."), false);
211-
m_options_widget->setActivated();
211+
m_options_widget->setActive(true);
212212
m_current_password_widget->setText("");
213213
m_new_password1_widget->setText("");
214214
m_new_password2_widget->setText("");
@@ -220,7 +220,7 @@ void ChangePasswordDialog::error(const irr::core::stringw & error)
220220
SFXManager::get()->quickSound("anvil");
221221
m_info_widget->setErrorColor();
222222
m_info_widget->setText(error, false);
223-
m_options_widget->setActivated();
223+
m_options_widget->setActive(true);
224224
m_current_password_widget->setText("");
225225
m_new_password1_widget->setText("");
226226
m_new_password2_widget->setText("");

src/states_screens/dialogs/custom_video_settings.cpp

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ void CustomVideoSettingsDialog::beforeAddingWidgets()
107107
{
108108
CheckBoxWidget* cb_tex_cmp = getWidget<CheckBoxWidget>("texture_compression");
109109
cb_tex_cmp->setState(false);
110-
cb_tex_cmp->setDeactivated();
110+
cb_tex_cmp->setActive(false);
111111
}
112112

113113
if (!CVS->supportsGlobalIllumination())
114114
{
115-
shadows->setDeactivated();
116-
getWidget<CheckBoxWidget>("global_illumination")->setDeactivated();
115+
shadows->setActive(false);
116+
getWidget<CheckBoxWidget>("global_illumination")->setActive(false);
117117
}
118118
}
119119

@@ -227,37 +227,22 @@ GUIEngine::EventPropagation CustomVideoSettingsDialog::processEvent(const std::s
227227

228228
void CustomVideoSettingsDialog::updateActivation()
229229
{
230-
if(getWidget<CheckBoxWidget>("dynamiclight")->getState())
231-
{
232-
getWidget<CheckBoxWidget>("motionblur")->setActivated();
233-
getWidget<CheckBoxWidget>("dof")->setActivated();
234-
getWidget<SpinnerWidget>("shadows")->setActivated();
235-
getWidget<CheckBoxWidget>("mlaa")->setActivated();
236-
getWidget<CheckBoxWidget>("ssao")->setActivated();
237-
getWidget<CheckBoxWidget>("lightshaft")->setActivated();
238-
getWidget<CheckBoxWidget>("ibl")->setActivated();
239-
getWidget<CheckBoxWidget>("global_illumination")->setActivated();
240-
getWidget<CheckBoxWidget>("glow")->setActivated();
241-
getWidget<CheckBoxWidget>("bloom")->setActivated();
242-
}
243-
else
244-
{
245-
getWidget<CheckBoxWidget>("motionblur")->setDeactivated();
246-
getWidget<CheckBoxWidget>("dof")->setDeactivated();
247-
getWidget<SpinnerWidget>("shadows")->setDeactivated();
248-
getWidget<CheckBoxWidget>("mlaa")->setDeactivated();
249-
getWidget<CheckBoxWidget>("ssao")->setDeactivated();
250-
getWidget<CheckBoxWidget>("lightshaft")->setDeactivated();
251-
getWidget<CheckBoxWidget>("ibl")->setDeactivated();
252-
getWidget<CheckBoxWidget>("global_illumination")->setDeactivated();
253-
getWidget<CheckBoxWidget>("glow")->setDeactivated();
254-
getWidget<CheckBoxWidget>("bloom")->setDeactivated();
255-
}
230+
bool light = getWidget<CheckBoxWidget>("dynamiclight")->getState();
231+
getWidget<CheckBoxWidget>("motionblur")->setActive(light);
232+
getWidget<CheckBoxWidget>("dof")->setActive(true);
233+
getWidget<SpinnerWidget>("shadows")->setActive(light);
234+
getWidget<CheckBoxWidget>("mlaa")->setActive(light);
235+
getWidget<CheckBoxWidget>("ssao")->setActive(light);
236+
getWidget<CheckBoxWidget>("lightshaft")->setActive(light);
237+
getWidget<CheckBoxWidget>("ibl")->setActive(light);
238+
getWidget<CheckBoxWidget>("global_illumination")->setActive(light);
239+
getWidget<CheckBoxWidget>("glow")->setActive(light);
240+
getWidget<CheckBoxWidget>("bloom")->setActive(light);
256241

257242
if (!CVS->supportsShadows() && !CVS->supportsGlobalIllumination())
258243
{
259-
getWidget<SpinnerWidget>("shadows")->setDeactivated();
260-
getWidget<CheckBoxWidget>("global_illumination")->setDeactivated();
244+
getWidget<SpinnerWidget>("shadows")->setActive(false);
245+
getWidget<CheckBoxWidget>("global_illumination")->setActive(false);
261246
}
262247
} // updateActivation
263248

0 commit comments

Comments
 (0)