Allow updating kart color when slider moves with mouse
This commit is contained in:
parent
cc9980f2a4
commit
10af6f7a80
@ -1699,7 +1699,7 @@ void Skin::drawSpinnerChild(const core::recti &rect, Widget* widget,
|
||||
SpinnerWidget* spinner = dynamic_cast<SpinnerWidget*>(widget->m_event_handler);
|
||||
bool spinner_focused = spinner->isFocusedForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
if (pressed || (spinner->isRightButtonSelected() == right && spinner_focused))
|
||||
if (pressed || (spinner->isButtonSelected(right) && spinner_focused))
|
||||
{
|
||||
core::recti rect2(spinner->m_x, spinner->m_y,
|
||||
spinner->m_x + spinner->m_w,
|
||||
|
@ -28,8 +28,10 @@
|
||||
#include <IGUIElement.h>
|
||||
#include <IGUIEnvironment.h>
|
||||
#include <IGUIButton.h>
|
||||
#include <IGUIStaticText.h>
|
||||
#include <IGUIImage.h>
|
||||
|
||||
#include "../../../lib/irrlicht/source/Irrlicht/CGUIButton.h"
|
||||
|
||||
using namespace GUIEngine;
|
||||
using namespace irr::core;
|
||||
using namespace irr::gui;
|
||||
@ -37,6 +39,53 @@ using namespace irr::video;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class SpinnerIrrElement : public CGUIButton
|
||||
{
|
||||
private:
|
||||
bool m_pressed_moving;
|
||||
|
||||
SpinnerWidget* m_spinner;
|
||||
public:
|
||||
SpinnerIrrElement(const core::rect<s32>& rectangle, IGUIElement* parent,
|
||||
s32 id, SpinnerWidget* spinner)
|
||||
: CGUIButton(GUIEngine::getGUIEnv(), parent ?
|
||||
parent : dynamic_cast<IGUIElement*>(GUIEngine::getGUIEnv()),
|
||||
id, rectangle)
|
||||
{
|
||||
m_pressed_moving = false;
|
||||
m_spinner = spinner;
|
||||
setText(L"");
|
||||
// Parent or GUI environment grabbed it
|
||||
drop();
|
||||
}
|
||||
virtual bool OnEvent(const SEvent& event)
|
||||
{
|
||||
bool ret = CGUIButton::OnEvent(event);
|
||||
if (ret && event.EventType == EET_MOUSE_INPUT_EVENT)
|
||||
{
|
||||
if (!m_spinner->isActivated())
|
||||
return ret;
|
||||
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
|
||||
m_pressed_moving = true;
|
||||
else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
|
||||
{
|
||||
m_pressed_moving = false;
|
||||
// clearSelected so SpinnerWidget::activateSelectedButton
|
||||
// is not called in transmitEvent
|
||||
m_spinner->clearSelected();
|
||||
}
|
||||
if (m_pressed_moving &&
|
||||
(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN ||
|
||||
event.MouseInput.Event == EMIE_MOUSE_MOVED))
|
||||
{
|
||||
m_spinner->onPressed(event.MouseInput.X, event.MouseInput.Y);
|
||||
m_spinner->doValueUpdatedCallback();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
SpinnerWidget::SpinnerWidget(const bool gauge) : Widget(WTYPE_SPINNER)
|
||||
{
|
||||
m_gauge = gauge;
|
||||
@ -49,6 +98,7 @@ SpinnerWidget::SpinnerWidget(const bool gauge) : Widget(WTYPE_SPINNER)
|
||||
m_spinner_widget_player_id=-1;
|
||||
m_min = 0;
|
||||
m_max = 999;
|
||||
m_left_selected = false;
|
||||
m_right_selected = false;
|
||||
}
|
||||
|
||||
@ -107,7 +157,7 @@ void SpinnerWidget::add()
|
||||
}
|
||||
|
||||
rect<s32> widget_size = rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h);
|
||||
IGUIButton * btn = GUIEngine::getGUIEnv()->addButton(widget_size, m_parent, widgetID, L"");
|
||||
IGUIButton * btn = new SpinnerIrrElement(widget_size, m_parent, widgetID, this);
|
||||
m_element = btn;
|
||||
|
||||
m_element->setTabOrder( m_element->getID() );
|
||||
@ -252,13 +302,11 @@ EventPropagation SpinnerWidget::leftPressed(const int playerID)
|
||||
// if widget is deactivated, do nothing
|
||||
if (m_deactivated) return EVENT_BLOCK;
|
||||
|
||||
|
||||
// if right arrow is selected, select left arrow
|
||||
if (m_right_selected)
|
||||
setSelectedButton(/* right*/ false);
|
||||
// if left arrow is selected, let navigation move to next widget
|
||||
else
|
||||
// if left arrow is selected, let event handler move to next widget
|
||||
if (m_left_selected)
|
||||
return EVENT_BLOCK;
|
||||
else
|
||||
setSelectedButton(/* right*/ false);
|
||||
|
||||
return EVENT_BLOCK_BUT_HANDLED;
|
||||
} // leftPressed
|
||||
@ -276,7 +324,7 @@ void SpinnerWidget::activateSelectedButton()
|
||||
setValue(m_min);
|
||||
}
|
||||
}
|
||||
else // left button active
|
||||
else if (m_left_selected)
|
||||
{
|
||||
if (m_value-1 >= m_min)
|
||||
{
|
||||
@ -302,11 +350,13 @@ EventPropagation SpinnerWidget::transmitEvent(Widget* w,
|
||||
|
||||
if (originator == "left")
|
||||
{
|
||||
m_left_selected = true;
|
||||
m_right_selected = false;
|
||||
activateSelectedButton();
|
||||
}
|
||||
else if (originator == "right")
|
||||
{
|
||||
m_left_selected = false;
|
||||
m_right_selected = true;
|
||||
activateSelectedButton();
|
||||
}
|
||||
@ -455,18 +505,16 @@ void SpinnerWidget::setCustomText(const core::stringw& text)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
EventPropagation SpinnerWidget::onClick()
|
||||
void SpinnerWidget::onPressed(int x, int y)
|
||||
{
|
||||
if (m_children[1].m_deactivated ||
|
||||
m_children[1].m_properties[PROP_ID] != "spinnerbody" ||
|
||||
!isGauge())
|
||||
{
|
||||
return EVENT_LET;
|
||||
return;
|
||||
}
|
||||
|
||||
const core::position2di mouse_position
|
||||
= irr_driver->getDevice()->getCursorControl()->getPosition();
|
||||
|
||||
core::position2di mouse_position(x, y);
|
||||
core::recti body_rect
|
||||
= m_children[1].getIrrlichtElement()->getAbsolutePosition();
|
||||
|
||||
@ -485,8 +533,6 @@ EventPropagation SpinnerWidget::onClick()
|
||||
|
||||
setValue(new_value);
|
||||
}
|
||||
|
||||
return EVENT_LET;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define HEADER_SPINNER_HPP
|
||||
|
||||
#include <irrString.h>
|
||||
#include <functional>
|
||||
namespace irr
|
||||
{
|
||||
namespace video { class ITexture; }
|
||||
@ -52,7 +53,7 @@ namespace GUIEngine
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
std::function<void(SpinnerWidget* spinner)> m_value_updated_callback;
|
||||
ISpinnerConfirmListener* m_listener;
|
||||
|
||||
int m_value, m_min, m_max;
|
||||
@ -76,7 +77,10 @@ namespace GUIEngine
|
||||
/** \brief Whether to wrap back to the first value when going "beyond" the last value */
|
||||
bool m_wrap_around;
|
||||
|
||||
/** \brief Whether the right or left arrow is the currently selected one */
|
||||
/** \brief Whether the left arrow is the currently selected one */
|
||||
bool m_left_selected;
|
||||
|
||||
/** \brief Whether the right arrow is the currently selected one */
|
||||
bool m_right_selected;
|
||||
|
||||
/** \brief Keeps track of the custom text in spinner (a text which isn't related to a value)
|
||||
@ -94,9 +98,6 @@ namespace GUIEngine
|
||||
|
||||
/** \brief implementing method from base class Widget */
|
||||
virtual EventPropagation leftPressed(const int playerID);
|
||||
|
||||
/** \brief implementing method from base class Widget */
|
||||
virtual EventPropagation onClick();
|
||||
|
||||
/** When inferring widget size from its label length, this method will be called to
|
||||
* if/how much space must be added to the raw label's size for the widget to be large enough */
|
||||
@ -128,8 +129,32 @@ namespace GUIEngine
|
||||
void unsetUseBackgroundColor() {m_use_background_color=false; }
|
||||
|
||||
void activateSelectedButton();
|
||||
void setSelectedButton(bool right) {m_right_selected = right; }
|
||||
bool isRightButtonSelected() {return m_right_selected; }
|
||||
void setSelectedButton(bool right)
|
||||
{
|
||||
if (right)
|
||||
{
|
||||
m_left_selected = false;
|
||||
m_right_selected = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_left_selected = true;
|
||||
m_right_selected = false;
|
||||
}
|
||||
}
|
||||
void clearSelected()
|
||||
{
|
||||
m_left_selected = false;
|
||||
m_right_selected = false;
|
||||
}
|
||||
bool isButtonSelected(bool right)
|
||||
{
|
||||
if (right && m_right_selected)
|
||||
return true;
|
||||
else if (!right && m_left_selected)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -217,6 +242,17 @@ namespace GUIEngine
|
||||
/** Display custom text in spinner */
|
||||
void setCustomText(const core::stringw& text);
|
||||
const core::stringw& getCustomText() const { return m_custom_text; }
|
||||
void onPressed(int x, int y);
|
||||
void doValueUpdatedCallback()
|
||||
{
|
||||
if (m_value_updated_callback)
|
||||
m_value_updated_callback(this);
|
||||
}
|
||||
void setValueUpdatedCallback(
|
||||
std::function<void(SpinnerWidget* spinner)> callback)
|
||||
{
|
||||
m_value_updated_callback = callback;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -67,6 +67,11 @@ KartColorSliderDialog::KartColorSliderDialog(PlayerProfile* pp)
|
||||
m_model_view->getModelViewRenderInfo()->setHue(0.0f);
|
||||
}
|
||||
m_toggle_slider->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
m_color_slider->setValueUpdatedCallback([this](SpinnerWidget* spinner)
|
||||
{
|
||||
m_model_view->getModelViewRenderInfo()->setHue(
|
||||
float(spinner->getValue()) / 100.0f);
|
||||
});
|
||||
} // KartColorSliderDialog
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -355,7 +355,7 @@ void OptionsScreenUI::eventCallback(Widget* widget, const std::string& name, con
|
||||
assert( skinSelector != NULL );
|
||||
|
||||
const core::stringw selectedSkin = skinSelector->getStringValue();
|
||||
bool right = skinSelector->isRightButtonSelected();
|
||||
bool right = skinSelector->isButtonSelected(true/*right*/);
|
||||
UserConfigParams::m_skin_file = m_skins[selectedSkin];
|
||||
irr_driver->unsetMaxTextureSize();
|
||||
bool prev_icon_theme = GUIEngine::getSkin()->hasIconTheme();
|
||||
@ -407,7 +407,7 @@ void OptionsScreenUI::eventCallback(Widget* widget, const std::string& name, con
|
||||
{
|
||||
GUIEngine::SpinnerWidget* font_size = getWidget<GUIEngine::SpinnerWidget>("font_size");
|
||||
assert( font_size != NULL );
|
||||
bool right = font_size->isRightButtonSelected();
|
||||
bool right = font_size->isButtonSelected(true/*right*/);
|
||||
UserConfigParams::m_font_size = font_size->getValue();
|
||||
GUIEngine::clear();
|
||||
GUIEngine::cleanUp();
|
||||
|
Loading…
Reference in New Issue
Block a user