Changeset View
Changeset View
Standalone View
Standalone View
source/gui/IGUIScrollBar.cpp
/* Copyright (C) 2015 Wildfire Games. | /* Copyright (C) 2017 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "GUI.h" | #include "GUI.h" | ||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
IGUIScrollBar::IGUIScrollBar() : m_pStyle(NULL), m_pGUI(NULL), | IGUIScrollBar::IGUIScrollBar() : m_pStyle(NULL), m_pGUI(NULL), | ||||
Stan: ? | |||||
Not Done Inline Actionsm_pStyle isn't used anywhere. Available scrollbar styles are all stored (within a std::map) in CGUI and are referred to (by their name) via the m_ScrollbarStyle attribute on the objects that use scrollbars. s0600204: `m_pStyle` isn't used anywhere.
Available scrollbar styles are all stored (within a `std… | |||||
m_X(300.f), m_Y(300.f), | m_X(300.f), m_Y(300.f), | ||||
m_ScrollRange(1.f), m_ScrollSpace(0.f), // MaxPos: not 0, due to division. | m_ScrollRange(1.f), m_ScrollSpace(0.f), // MaxPos: not 0, due to division. | ||||
m_Length(200.f), m_Width(20.f), | m_Length(200.f), m_Breadth(20.f), | ||||
m_BarSize(0.f), m_Pos(0.f), | m_BarSize(0.f), m_Pos(0.f), | ||||
m_ButtonPlusPressed(false), | m_ButtonPlusPressed(false), | ||||
m_ButtonMinusPressed(false), | m_ButtonMinusPressed(false), | ||||
m_ButtonPlusHovered(false), | m_ButtonPlusHovered(false), | ||||
m_ButtonMinusHovered(false), | m_ButtonMinusHovered(false), | ||||
m_BarHovered(false), | m_BarHovered(false), | ||||
m_BarPressed(false) | m_BarPressed(false) | ||||
{ | { | ||||
Show All 9 Lines | if (!GetStyle()) | ||||
return; | return; | ||||
float min = GetStyle()->m_MinimumBarSize; | float min = GetStyle()->m_MinimumBarSize; | ||||
float max = GetStyle()->m_MaximumBarSize; | float max = GetStyle()->m_MaximumBarSize; | ||||
float length = m_Length; | float length = m_Length; | ||||
// Check for edge buttons | // Check for edge buttons | ||||
if (GetStyle()->m_UseEdgeButtons) | if (GetStyle()->m_UseEdgeButtons) | ||||
length -= GetStyle()->m_Width * 2.f; | length -= GetStyle()->m_Breadth * 2.f; | ||||
// Check min and max are valid | // Check min and max are valid | ||||
if (min > length) | if (min > length) | ||||
min = 0.f; | min = 0.f; | ||||
if (max < min) | if (max < min) | ||||
max = length; | max = length; | ||||
// Clamp size to not exceed a minimum or maximum. | // Clamp size to not exceed a minimum or maximum. | ||||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | void IGUIScrollBar::HandleMessage(SGUIMessage& Message) | ||||
case GUIM_MOUSE_RELEASE_LEFT: | case GUIM_MOUSE_RELEASE_LEFT: | ||||
m_ButtonMinusPressed = false; | m_ButtonMinusPressed = false; | ||||
m_ButtonPlusPressed = false; | m_ButtonPlusPressed = false; | ||||
break; | break; | ||||
case GUIM_MOUSE_WHEEL_UP: | case GUIM_MOUSE_WHEEL_UP: | ||||
{ | { | ||||
ScrollMinus(); | if (m_Pos <= 0) | ||||
m_pHostObject->m_pParent->HandleMessage(Message); | |||||
// Since the scroll was changed, let's simulate a mouse movement | // Since the scroll was changed, let's simulate a mouse movement | ||||
// to check if scrollbar now is hovered | // to check if scrollbar now is hovered | ||||
SGUIMessage msg(GUIM_MOUSE_MOTION); | SGUIMessage msg(GUIM_MOUSE_MOTION); | ||||
HandleMessage(msg); | HandleMessage(msg); | ||||
break; | break; | ||||
} | } | ||||
case GUIM_MOUSE_WHEEL_DOWN: | case GUIM_MOUSE_WHEEL_DOWN: | ||||
{ | { | ||||
ScrollPlus(); | if (m_Pos >= GetMaxPos()) | ||||
m_pHostObject->m_pParent->HandleMessage(Message); | |||||
// Since the scroll was changed, let's simulate a mouse movement | // Since the scroll was changed, let's simulate a mouse movement | ||||
// to check if scrollbar now is hovered | // to check if scrollbar now is hovered | ||||
SGUIMessage msg(GUIM_MOUSE_MOTION); | SGUIMessage msg(GUIM_MOUSE_MOTION); | ||||
HandleMessage(msg); | HandleMessage(msg); | ||||
break; | break; | ||||
} | } | ||||
case GUIM_SETTINGS_UPDATED: | |||||
if (Message.value == "scrollbar_style") | |||||
{ | |||||
CStr scrollbar_style; | |||||
GUI<CStr>::GetSetting(m_pHostObject, "scrollbar_style", scrollbar_style); | |||||
SetScrollBarStyle(scrollbar_style); | |||||
} | |||||
break; | |||||
case GUIM_LOAD: | |||||
{ | |||||
CStr scrollbar_style; | |||||
GUI<CStr>::GetSetting(m_pHostObject, "scrollbar_style", scrollbar_style); | |||||
SetScrollBarStyle(scrollbar_style); | |||||
break; | |||||
} | |||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
} | } |
Wildfire Games · Phabricator
?