Skip to content

Commit

Permalink
fix slider mouse positioning. still not perfect, but I think that's b…
Browse files Browse the repository at this point in the history
…ecause the skin (buttonBorderWidth) is wrong for this skin
  • Loading branch information
robn committed Oct 8, 2012
1 parent 08c670a commit 1ea96da
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/ui/Slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace UI {

static const float MIN_SLIDER_INNER_SIZE = 32.0f; // XXX skin
static const Uint32 MIN_SLIDER_INNER_SIZE = 32; // XXX skin

Point Slider::PreferredSize()
{
Expand All @@ -25,7 +25,7 @@ void Slider::Layout()

void Slider::UpdateButton()
{
const float buttonBorderWidth = Skin::s_buttonNormal.borderWidth;
const Uint32 buttonBorderWidth = Skin::s_buttonNormal.borderWidth;
const Point activeArea(GetActiveArea());
if (m_orient == SLIDER_HORIZONTAL) {
m_buttonSize = Point(std::min(activeArea.x-buttonBorderWidth*2, MIN_SLIDER_INNER_SIZE), activeArea.y-buttonBorderWidth*2);
Expand Down Expand Up @@ -67,10 +67,16 @@ void Slider::HandleMouseUp(const MouseButtonEvent &event)

void Slider::HandleMouseMove(const MouseMotionEvent &event)
{
if (m_buttonDown && IsMouseActive())
SetValue(m_orient == SLIDER_HORIZONTAL ?
float(Clamp(event.pos.x, 0, GetActiveArea().x)) / GetActiveArea().x :
float(Clamp(event.pos.y, 0, GetActiveArea().y)) / GetActiveArea().y);
if (m_buttonDown && IsMouseActive()) {
const Point::Component c = m_orient == SLIDER_HORIZONTAL ? Point::X : Point::Y;

const int effectiveLength = GetActiveArea()[c] - m_buttonSize[c];
const int pos = Clamp(event.pos[c] - GetActiveOffset()[c], 0, effectiveLength);
const float travel = float(pos) / effectiveLength;

SetValue(travel);
}

Widget::HandleMouseMove(event);
}

Expand Down

0 comments on commit 1ea96da

Please sign in to comment.