Moved slider's code to onClick()
This commit is contained in:
parent
1ddc4afc14
commit
acd1628528
@ -1378,20 +1378,6 @@ void Skin::drawSpinnerBody(const core::recti &rect, Widget* widget,
|
||||
0 /* no clipping */, 0,
|
||||
true /* alpha */);
|
||||
|
||||
// ---- Set value by mouse position
|
||||
const float max_value = (float)(w->getMax() - w->getMin()) /
|
||||
(w->getMax() - w->getMin());
|
||||
|
||||
const core::recti mouse_area(rect.UpperLeftCorner.X + handle_size,
|
||||
rect.UpperLeftCorner.Y,
|
||||
rect.UpperLeftCorner.X + handle_size +
|
||||
(int)((widget->m_w
|
||||
- 2*handle_size)*max_value),
|
||||
rect.UpperLeftCorner.Y + widget->m_h);
|
||||
|
||||
const core::position2di mouse_position
|
||||
= irr_driver->getDevice()->getCursorControl()->getPosition();
|
||||
q->setValuesByMouse(mouse_position, mouse_area);
|
||||
}
|
||||
|
||||
if (focused && widget->hasTooltip())
|
||||
|
@ -46,7 +46,6 @@ SpinnerWidget::SpinnerWidget(const bool gauge) : Widget(WTYPE_SPINNER)
|
||||
m_supports_multiplayer = true;
|
||||
m_value = -1;
|
||||
m_use_background_color=false;
|
||||
m_allow_mouse_change = false;
|
||||
m_spinner_widget_player_id=-1;
|
||||
m_min = 0;
|
||||
m_max = 999;
|
||||
@ -435,40 +434,46 @@ void SpinnerWidget::setCustomText(const core::stringw& text)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void SpinnerWidget::setValuesByMouse(const core::position2di & mouse_position,
|
||||
const core::recti & body_rect)
|
||||
void SpinnerWidget::onClick()
|
||||
{
|
||||
int x = m_x;
|
||||
int y = m_y;
|
||||
|
||||
if (m_parent != NULL)
|
||||
{
|
||||
x += m_parent->getAbsolutePosition().UpperLeftCorner.X;
|
||||
y += m_parent->getAbsolutePosition().UpperLeftCorner.Y;
|
||||
}
|
||||
|
||||
if (m_children[1].m_deactivated) return;
|
||||
|
||||
if (m_children[1].m_properties[PROP_ID] != "spinnerbody"
|
||||
|| !isGauge()) { return; }
|
||||
|
||||
const core::position2di mouse_position
|
||||
= irr_driver->getDevice()->getCursorControl()->getPosition();
|
||||
|
||||
const int handle_size = m_h*110/128; //need params->m_left_border and params->getImage()->getSize().Height
|
||||
|
||||
rect<s32> body_rect = rect<s32>(x+handle_size,
|
||||
y,
|
||||
x+handle_size + (m_w-2*handle_size),
|
||||
y+handle_size);
|
||||
|
||||
if(body_rect.isPointInside(mouse_position))
|
||||
{
|
||||
if (m_allow_mouse_change)
|
||||
{
|
||||
float exact_hover = (float)((mouse_position.X -
|
||||
body_rect.UpperLeftCorner.X) /
|
||||
(float)body_rect.getWidth()) * (m_max-m_min) + 0.5f;
|
||||
float exact_hover = (float)((mouse_position.X -
|
||||
body_rect.UpperLeftCorner.X) /
|
||||
(float)body_rect.getWidth()) * (m_max-m_min) + 0.5f;
|
||||
|
||||
int new_value = ((exact_hover * (m_max-m_min)) /
|
||||
(m_max-m_min))+m_min;
|
||||
//Log::info("SpinnerWidget", "mouse_value: %d (%f)",
|
||||
// mouse_value, exact_hover);
|
||||
int new_value = ((exact_hover * (m_max-m_min)) /
|
||||
(m_max-m_min))+m_min;
|
||||
|
||||
if (new_value > m_max) new_value = m_max;
|
||||
if (new_value < m_min) new_value = m_min;
|
||||
if (new_value > m_max) new_value = m_max;
|
||||
if (new_value < m_min) new_value = m_min;
|
||||
|
||||
setValue(new_value);
|
||||
EventHandler::get()->processGUIAction(
|
||||
PlayerAction::PA_MENU_SELECT,
|
||||
1, Input::MAX_VALUE,
|
||||
Input::IT_MOUSEBUTTON, false); //process the changes
|
||||
m_allow_mouse_change = false;
|
||||
}
|
||||
setValue(new_value);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void SpinnerWidget::onClick()
|
||||
{
|
||||
m_allow_mouse_change = true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -59,7 +59,6 @@ namespace GUIEngine
|
||||
|
||||
int m_spinner_widget_player_id;
|
||||
bool m_use_background_color;
|
||||
bool m_allow_mouse_change;
|
||||
|
||||
/** If each value the spinner can take has an associated text, this vector will be non-empty */
|
||||
std::vector<irr::core::stringw> m_labels;
|
||||
@ -201,10 +200,6 @@ namespace GUIEngine
|
||||
|
||||
/** Display custom text in spinner */
|
||||
void setCustomText(const core::stringw& text);
|
||||
|
||||
/** Set m_value based on mouse position */
|
||||
void setValuesByMouse(const core::position2di & mouse_position,
|
||||
const core::recti & body_rect);
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user