forked from 0ad/0ad
Okay, do what f5ab6255d0
was supposed to do.
This was SVN commit r13773.
This commit is contained in:
parent
b10a01645f
commit
89430de468
@ -135,6 +135,7 @@
|
||||
sprite_bar_vertical_pressed CDATA #IMPLIED
|
||||
sprite_back_vertical CDATA #IMPLIED
|
||||
minimum_bar_size CDATA #IMPLIED
|
||||
maximum_bar_size CDATA #IMPLIED
|
||||
>
|
||||
|
||||
<!--
|
||||
|
@ -1775,6 +1775,15 @@ void CGUI::Xeromyces_ReadScrollBarStyle(XMBElement Element, CXeromyces* pFile)
|
||||
scrollbar.m_MinimumBarSize = f;
|
||||
}
|
||||
else
|
||||
if (attr_name == "maximum_bar_size")
|
||||
{
|
||||
float f;
|
||||
if (!GUI<float>::ParseString(attr_value.FromUTF8(), f))
|
||||
LOGERROR(L"GUI: Error parsing '%hs' (\"%hs\")", attr_name.c_str(), attr_value.c_str());
|
||||
else
|
||||
scrollbar.m_MaximumBarSize = f;
|
||||
}
|
||||
else
|
||||
if (attr_name == "sprite_button_top")
|
||||
scrollbar.m_SpriteButtonTop = attr_value;
|
||||
else
|
||||
|
@ -22,7 +22,6 @@ IGUIScrollBar
|
||||
#include "precompiled.h"
|
||||
#include "GUI.h"
|
||||
#include "CGUIScrollBarVertical.h"
|
||||
|
||||
#include "ps/CLogger.h"
|
||||
|
||||
|
||||
@ -39,18 +38,22 @@ void CGUIScrollBarVertical::SetPosFromMousePos(const CPos &mouse)
|
||||
if (!GetStyle())
|
||||
return;
|
||||
|
||||
m_Pos = (m_PosWhenPressed + m_ScrollRange*(mouse.y-m_BarPressedAtPos.y)/(m_Length-GetStyle()->m_Width*2));
|
||||
/**
|
||||
* Calculate the position for the top of the item being scrolled
|
||||
*/
|
||||
m_Pos = m_PosWhenPressed + GetMaxPos() * (mouse.y - m_BarPressedAtPos.y) / (m_Length - GetStyle()->m_Width * 2 - m_BarSize);
|
||||
}
|
||||
|
||||
void CGUIScrollBarVertical::Draw()
|
||||
{
|
||||
if (!GetStyle())
|
||||
{
|
||||
// TODO Gee: Report in error log
|
||||
LOGWARNING(L"Attempt to draw scrollbar without a style.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetGUI())
|
||||
// Only draw the scrollbar if the GUI exists and there is something to scroll.
|
||||
if (GetGUI() && GetMaxPos() != 1)
|
||||
{
|
||||
CRect outline = GetOuterRect();
|
||||
|
||||
@ -79,7 +82,7 @@ void CGUIScrollBarVertical::Draw()
|
||||
}
|
||||
else button_top = &GetStyle()->m_SpriteButtonTop;
|
||||
|
||||
// figure out what sprite to use for top button
|
||||
// figure out what sprite to use for bottom button
|
||||
if (m_ButtonPlusHovered)
|
||||
{
|
||||
if (m_ButtonPlusPressed)
|
||||
@ -111,22 +114,10 @@ void CGUIScrollBarVertical::Draw()
|
||||
}
|
||||
|
||||
// Draw bar
|
||||
/*if (m_BarPressed)
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(GetStyle()->m_SpriteBarVerticalPressed, GetStyle()->m_SpriteBarVertical),
|
||||
0,
|
||||
m_Z+0.2f,
|
||||
GetBarRect());
|
||||
else
|
||||
if (m_BarHovered)
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(GetStyle()->m_SpriteBarVerticalOver, GetStyle()->m_SpriteBarVertical),
|
||||
0,
|
||||
m_Z+0.2f,
|
||||
GetBarRect());
|
||||
else*/
|
||||
GetGUI()->DrawSprite(GetStyle()->m_SpriteBarVertical,
|
||||
0,
|
||||
m_Z+0.2f,
|
||||
GetBarRect());
|
||||
GetGUI()->DrawSprite(GetStyle()->m_SpriteBarVertical,
|
||||
0,
|
||||
m_Z + 0.2f,
|
||||
GetBarRect());
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,32 +132,19 @@ CRect CGUIScrollBarVertical::GetBarRect() const
|
||||
if (!GetStyle())
|
||||
return ret;
|
||||
|
||||
float size;
|
||||
float from, to;
|
||||
// Get from where the scroll area begins to where it ends
|
||||
float from = m_Y;
|
||||
float to = m_Y + m_Length - m_BarSize;
|
||||
|
||||
// is edge buttons used?
|
||||
if (m_UseEdgeButtons)
|
||||
{
|
||||
size = (m_Length-GetStyle()->m_Width*2.f)*m_BarSize;
|
||||
if (size < GetStyle()->m_MinimumBarSize)
|
||||
size = GetStyle()->m_MinimumBarSize;
|
||||
|
||||
from = m_Y+GetStyle()->m_Width;
|
||||
to = m_Y+m_Length-GetStyle()->m_Width-size;
|
||||
}
|
||||
else
|
||||
{
|
||||
size = m_Length*m_BarSize;
|
||||
if (size < GetStyle()->m_MinimumBarSize)
|
||||
size = GetStyle()->m_MinimumBarSize;
|
||||
|
||||
from = m_Y;
|
||||
to = m_Y+m_Length-size;
|
||||
from += GetStyle()->m_Width;
|
||||
to -= GetStyle()->m_Width;
|
||||
}
|
||||
|
||||
// Setup rectangle
|
||||
ret.top = (from + (to-from)*(m_Pos/(std::max(1.f, m_ScrollRange - m_ScrollSpace))));
|
||||
ret.bottom = ret.top+size;
|
||||
ret.top = from + (to - from) * (m_Pos / GetMaxPos());
|
||||
ret.bottom = ret.top + m_BarSize;
|
||||
ret.right = m_X + ((m_RightAligned)?(0.f):(GetStyle()->m_Width));
|
||||
ret.left = ret.right - GetStyle()->m_Width;
|
||||
|
||||
|
@ -74,7 +74,7 @@ public:
|
||||
virtual void HandleMessage(SGUIMessage &Message);
|
||||
|
||||
/**
|
||||
* Set m_Pos with g_mouse_x/y input, i.e. when draggin.
|
||||
* Set m_Pos with g_mouse_x/y input, i.e. when dragging.
|
||||
*/
|
||||
virtual void SetPosFromMousePos(const CPos &mouse);
|
||||
|
||||
|
@ -21,7 +21,8 @@ IGUIScrollBar
|
||||
|
||||
#include "precompiled.h"
|
||||
#include "GUI.h"
|
||||
|
||||
#include "maths/MathUtil.h"
|
||||
#include "ps/CLogger.h"
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// IGUIScrollBar
|
||||
@ -30,7 +31,7 @@ IGUIScrollBar::IGUIScrollBar() : m_pStyle(NULL), m_pGUI(NULL),
|
||||
m_X(300.f), m_Y(300.f),
|
||||
m_ScrollRange(1.f), m_ScrollSpace(0.f), // MaxPos: not 0, due to division.
|
||||
m_Length(200.f), m_Width(20.f),
|
||||
m_BarSize(0.5f), m_Pos(0.f),
|
||||
m_BarSize(0.f), m_Pos(0.f),
|
||||
m_UseEdgeButtons(true),
|
||||
m_ButtonPlusPressed(false),
|
||||
m_ButtonMinusPressed(false),
|
||||
@ -47,7 +48,25 @@ IGUIScrollBar::~IGUIScrollBar()
|
||||
|
||||
void IGUIScrollBar::SetupBarSize()
|
||||
{
|
||||
m_BarSize = std::min((float)m_ScrollSpace/(float)m_ScrollRange, 1.f);
|
||||
float min = GetStyle()->m_MinimumBarSize;
|
||||
float max = GetStyle()->m_MaximumBarSize;
|
||||
float length = m_Length;
|
||||
|
||||
// Check for edge buttons
|
||||
if (m_UseEdgeButtons)
|
||||
length -= GetStyle()->m_Width * 2.f;
|
||||
|
||||
// Check min and max are valid
|
||||
if (min > length)
|
||||
{
|
||||
LOGWARNING(L"Minimum scrollbar size of %g is larger than the total scrollbar size of %g", min, length);
|
||||
min = 0.f;
|
||||
}
|
||||
if (max < min)
|
||||
max = length;
|
||||
|
||||
// Clamp size to not exceed a minimum or maximum.
|
||||
m_BarSize = clamp(length * std::min((float)m_ScrollSpace / (float)m_ScrollRange, 1.f), min, max);
|
||||
}
|
||||
|
||||
const SGUIScrollBarStyle *IGUIScrollBar::GetStyle() const
|
||||
@ -72,8 +91,8 @@ void IGUIScrollBar::UpdatePosBoundaries()
|
||||
m_ScrollRange < m_ScrollSpace) // <= scrolling not applicable
|
||||
m_Pos = 0.f;
|
||||
else
|
||||
if (m_Pos > m_ScrollRange - m_ScrollSpace)
|
||||
m_Pos = m_ScrollRange - m_ScrollSpace;
|
||||
if (m_Pos > GetMaxPos())
|
||||
m_Pos = GetMaxPos();
|
||||
}
|
||||
|
||||
void IGUIScrollBar::HandleMessage(SGUIMessage &Message)
|
||||
@ -93,12 +112,10 @@ void IGUIScrollBar::HandleMessage(SGUIMessage &Message)
|
||||
UpdatePosBoundaries();
|
||||
}
|
||||
|
||||
CRect bar_rect = GetBarRect();
|
||||
// check if components are being hovered
|
||||
m_BarHovered = bar_rect.PointInside(mouse);
|
||||
|
||||
m_ButtonMinusHovered = HoveringButtonMinus(m_pHostObject->GetMousePos());
|
||||
m_ButtonPlusHovered = HoveringButtonPlus(m_pHostObject->GetMousePos());
|
||||
m_BarHovered = GetBarRect().PointInside(mouse);
|
||||
m_ButtonMinusHovered = HoveringButtonMinus(mouse);
|
||||
m_ButtonPlusHovered = HoveringButtonPlus(mouse);
|
||||
|
||||
if (!m_ButtonMinusHovered)
|
||||
m_ButtonMinusPressed = false;
|
||||
|
@ -90,6 +90,13 @@ struct SGUIScrollBarStyle
|
||||
*/
|
||||
float m_MinimumBarSize;
|
||||
|
||||
/**
|
||||
* Sometimes you would like your scroll bar to have a fixed maximum size
|
||||
* so that the texture does not get too stretched, you can set a maximum
|
||||
* in pixels.
|
||||
*/
|
||||
float m_MaximumBarSize;
|
||||
|
||||
//@}
|
||||
//--------------------------------------------------------
|
||||
/** @name Horizontal Sprites */
|
||||
@ -199,27 +206,27 @@ public:
|
||||
virtual void SetPos(float f) { m_Pos = f; UpdatePosBoundaries(); }
|
||||
|
||||
/**
|
||||
* Get the value of Pos that corresponds to the bottom of the scrollable region
|
||||
* Get the value of m_Pos that corresponds to the bottom of the scrollable region
|
||||
*/
|
||||
float GetMaxPos() const { return m_ScrollRange - m_ScrollSpace; }
|
||||
float GetMaxPos() const { return std::max(1.f, m_ScrollRange - m_ScrollSpace); }
|
||||
|
||||
/**
|
||||
* Scroll towards 1.0 one step
|
||||
* Increase scroll one step
|
||||
*/
|
||||
virtual void ScrollPlus() { m_Pos += 30.f; UpdatePosBoundaries(); }
|
||||
|
||||
/**
|
||||
* Scroll towards 0.0 one step
|
||||
* Decrease scroll one step
|
||||
*/
|
||||
virtual void ScrollMinus() { m_Pos -= 30.f; UpdatePosBoundaries(); }
|
||||
|
||||
/**
|
||||
* Scroll towards 1.0 one step
|
||||
* Increase scroll three steps
|
||||
*/
|
||||
virtual void ScrollPlusPlenty() { m_Pos += 90.f; UpdatePosBoundaries(); }
|
||||
|
||||
/**
|
||||
* Scroll towards 0.0 one step
|
||||
* Decrease scroll three steps
|
||||
*/
|
||||
virtual void ScrollMinusPlenty() { m_Pos -= 90.f; UpdatePosBoundaries(); }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user