Changeset View
Standalone View
source/gui/CList.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2019 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 "CList.h" | #include "CList.h" | ||||
#include "CGUIScrollBarVertical.h" | #include "CGUIScrollBarVertical.h" | ||||
#include "lib/external_libraries/libsdl.h" | #include "lib/external_libraries/libsdl.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Globals.h" | |||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "soundmanager/ISoundManager.h" | #include "soundmanager/ISoundManager.h" | ||||
CList::CList() | CList::CList() | ||||
: m_Modified(false), m_PrevSelectedItem(-1), m_LastItemClickTime(0) | : m_Modified(false), m_PrevSelectedItem(-1), m_LastItemClickTime(0), m_AddMultiSelection(false), m_IsMultiSelecting(false) | ||||
{ | { | ||||
// Add sprite_disabled! TODO | // Add sprite_disabled! TODO | ||||
AddSetting(GUIST_float, "buffer_zone"); | AddSetting(GUIST_float, "buffer_zone"); | ||||
AddSetting(GUIST_CStrW, "font"); | AddSetting(GUIST_CStrW, "font"); | ||||
AddSetting(GUIST_bool, "scrollbar"); | AddSetting(GUIST_bool, "scrollbar"); | ||||
AddSetting(GUIST_CStr, "scrollbar_style"); | AddSetting(GUIST_CStr, "scrollbar_style"); | ||||
AddSetting(GUIST_CStrW, "sound_disabled"); | AddSetting(GUIST_CStrW, "sound_disabled"); | ||||
AddSetting(GUIST_CStrW, "sound_selected"); | AddSetting(GUIST_CStrW, "sound_selected"); | ||||
AddSetting(GUIST_CGUISpriteInstance, "sprite"); | AddSetting(GUIST_CGUISpriteInstance, "sprite"); | ||||
AddSetting(GUIST_CGUISpriteInstance, "sprite_selectarea"); | AddSetting(GUIST_CGUISpriteInstance, "sprite_selectarea"); | ||||
AddSetting(GUIST_int, "cell_id"); | AddSetting(GUIST_int, "cell_id"); | ||||
AddSetting(GUIST_EAlign, "text_align"); | AddSetting(GUIST_EAlign, "text_align"); | ||||
AddSetting(GUIST_CColor, "textcolor"); | AddSetting(GUIST_CColor, "textcolor"); | ||||
AddSetting(GUIST_CColor, "textcolor_selected"); | AddSetting(GUIST_CColor, "textcolor_selected"); | ||||
AddSetting(GUIST_int, "selected"); // Index selected. -1 is none. | AddSetting(GUIST_int, "selected"); // Index selected. -1 is none. | ||||
AddSetting(GUIST_CIntList, "multiSelected"); | |||||
AddSetting(GUIST_bool, "multiSelection_enabled"); | |||||
AddSetting(GUIST_bool, "auto_scroll"); | AddSetting(GUIST_bool, "auto_scroll"); | ||||
AddSetting(GUIST_int, "hovered"); | AddSetting(GUIST_int, "hovered"); | ||||
AddSetting(GUIST_CStrW, "tooltip"); | AddSetting(GUIST_CStrW, "tooltip"); | ||||
AddSetting(GUIST_CStr, "tooltip_style"); | AddSetting(GUIST_CStr, "tooltip_style"); | ||||
// Each list item has both a name (in 'list') and an associated data string (in 'list_data') | // Each list item has both a name (in 'list') and an associated data string (in 'list_data') | ||||
AddSetting(GUIST_CGUIList, "list"); | AddSetting(GUIST_CGUIList, "list"); | ||||
AddSetting(GUIST_CGUIList, "list_data"); // TODO: this should be a list of raw strings, not of CGUIStrings | AddSetting(GUIST_CGUIList, "list_data"); // TODO: this should be a list of raw strings, not of CGUIStrings | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | if (scrollbar) | ||||
CRect rect = GetListRect(); | CRect rect = GetListRect(); | ||||
GetScrollBar(0).SetX(rect.right); | GetScrollBar(0).SetX(rect.right); | ||||
GetScrollBar(0).SetY(rect.top); | GetScrollBar(0).SetY(rect.top); | ||||
GetScrollBar(0).SetZ(GetBufferedZ()); | GetScrollBar(0).SetZ(GetBufferedZ()); | ||||
GetScrollBar(0).SetLength(rect.bottom - rect.top); | GetScrollBar(0).SetLength(rect.bottom - rect.top); | ||||
} | } | ||||
} | } | ||||
void CList::SingleSelectionControl(int& select) | |||||
{ | |||||
CIntList sel; | |||||
GUI<CIntList>::GetSetting(this, "multiSelected", sel); | |||||
m_SelectedItems = sel.m_Items; | |||||
if (!m_SelectedItems.empty()) | |||||
vladislavbelov: Space after `if`. | |||||
m_SelectedItems.at(0) = select; | |||||
else | |||||
m_SelectedItems.push_back(select); | |||||
sel.m_Items = m_SelectedItems; | |||||
GUI<CIntList>::SetSetting(this, "multiSelected", sel); | |||||
Done Inline ActionsIt's not used anywhere except the for, so it should be removed. Also you have to use size_t with size() methods. vladislavbelov: It's not used anywhere except the for, so it should be removed. Also you have to use `size_t`… | |||||
Done Inline ActionsI think it is better to ask for size once and not every iteration. Thats why I used it. And you are right with type. Silier: I think it is better to ask for size once and not every iteration. Thats why I used it. And you… | |||||
Done Inline ActionsIt's not a bottleneck, vector's size() just return a value of its member (also a compiler can/will optimize it). So we have to avoid the size variable (as in other our code). vladislavbelov: It's not a bottleneck, vector's `size()` just return a value of its member (also a compiler… | |||||
} | |||||
void CList::MultiSelectionControl(int& select) | |||||
{ | |||||
Not Done Inline ActionsRange loop maybe. Else ++it if you can't find a better name. Stan: Range loop maybe. Else ++it if you can't find a better name. | |||||
m_IsMultiSelecting = g_keys[SDLK_LSHIFT] || g_keys[SDLK_RSHIFT]; | |||||
m_AddMultiSelection = g_keys[SDLK_LCTRL] || g_keys[SDLK_RCTRL]; | |||||
// Add current item to selection | |||||
if (m_AddMultiSelection) | |||||
{ | |||||
CIntList sel; | |||||
GUI<CIntList>::GetSetting(this, "multiSelected", sel); | |||||
m_MultiSelectionFromItem = select; | |||||
Done Inline ActionsUse .empty() instead of .size() == 0. vladislavbelov: Use `.empty()` instead of `.size() == 0`. | |||||
m_SelectedItems = sel.m_Items; | |||||
Not Done Inline ActionsBraces around one line can be avoided. vladislavbelov: Braces around one line can be avoided. | |||||
bool add = true; | |||||
size_t pos = -1; | |||||
for (size_t it = 0; it < m_SelectedItems.size(); ++it) | |||||
if (m_SelectedItems.at(it) == select) | |||||
{ | |||||
add = false; | |||||
pos = it; | |||||
break; | |||||
} | |||||
if (add) | |||||
m_SelectedItems.push_back(select); | |||||
else | |||||
Done Inline ActionsDon't we put if on the same line as else? vladislavbelov: Don't we put `if` on the same line as `else`? | |||||
Not Done Inline ActionsIt looks like other comments start with a capital letter, so it'd be good to have the same style everywhere. vladislavbelov: It looks like other comments start with a capital letter, so it'd be good to have the same… | |||||
{ | |||||
m_SelectedItems.erase(m_SelectedItems.begin() + pos); | |||||
// Select last item in multiselection | |||||
if (m_SelectedItems.size() == 1) | |||||
select = m_SelectedItems.at(0); | |||||
} | |||||
sel.m_Items = m_SelectedItems; | |||||
GUI<CIntList>::SetSetting(this, "multiSelected", sel); | |||||
} | |||||
// Select everything from last clicked item to current | |||||
else if (m_IsMultiSelecting) | |||||
{ | |||||
if (m_MultiSelectionFromItem == select) | |||||
return; | |||||
CIntList sel; | |||||
GUI<CIntList>::GetSetting(this, "multiSelected", sel); | |||||
m_SelectedItems = sel.m_Items; | |||||
int firstId = m_MultiSelectionFromItem; | |||||
int lastId = select; | |||||
Not Done Inline ActionsiItemId replace by i or itemId. vladislavbelov: `iItemId` replace by `i` or `itemId`. | |||||
if (select < m_MultiSelectionFromItem) | |||||
{ | |||||
firstId = select; | |||||
lastId = m_MultiSelectionFromItem; | |||||
} | |||||
m_SelectedItems.clear(); | |||||
for (size_t itemId = firstId; itemId < lastId + 1; ++itemId) | |||||
m_SelectedItems.push_back(itemId); | |||||
sel.m_Items = m_SelectedItems; | |||||
GUI<CIntList>::SetSetting(this, "multiSelected", sel); | |||||
} | |||||
// Clear multi selection | |||||
else | |||||
{ | |||||
CIntList sel; | |||||
GUI<CIntList>::GetSetting(this, "multiSelected", sel); | |||||
m_SelectedItems = sel.m_Items; | |||||
m_SelectedItems.clear(); | |||||
m_SelectedItems.push_back(select); | |||||
sel.m_Items = m_SelectedItems; | |||||
m_MultiSelectionFromItem = select; | |||||
GUI<CIntList>::SetSetting(this, "multiSelected", sel); | |||||
} | |||||
} | |||||
void CList::HandleMessage(SGUIMessage& Message) | void CList::HandleMessage(SGUIMessage& Message) | ||||
{ | { | ||||
IGUIScrollBarOwner::HandleMessage(Message); | IGUIScrollBarOwner::HandleMessage(Message); | ||||
//IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead! | //IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead! | ||||
m_Modified = false; | m_Modified = false; | ||||
switch (Message.type) | switch (Message.type) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if (!enabled) | ||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) | if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) | ||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false); | g_SoundManager->PlayAsUI(soundPath.c_str(), false); | ||||
break; | break; | ||||
} | } | ||||
int hovered = GetHoveredItem(); | int hovered = GetHoveredItem(); | ||||
if (hovered == -1) | if (hovered == -1) | ||||
break; | break; | ||||
bool multiSelectionEnabled; | |||||
GUI<bool>::GetSetting(this, "multiSelection_enabled", multiSelectionEnabled); | |||||
if (multiSelectionEnabled) | |||||
MultiSelectionControl(hovered); | |||||
else | |||||
SingleSelectionControl(hovered); | |||||
GUI<int>::SetSetting(this, "selected", hovered); | GUI<int>::SetSetting(this, "selected", hovered); | ||||
UpdateAutoScroll(); | UpdateAutoScroll(); | ||||
CStrW soundPath; | CStrW soundPath; | ||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) | if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) | ||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false); | g_SoundManager->PlayAsUI(soundPath.c_str(), false); | ||||
if (timer_Time() - m_LastItemClickTime < SELECT_DBLCLICK_RATE && hovered == m_PrevSelectedItem) | if (timer_Time() - m_LastItemClickTime < SELECT_DBLCLICK_RATE && hovered == m_PrevSelectedItem && | ||||
(!multiSelectionEnabled || (!m_IsMultiSelecting && !m_AddMultiSelection))) | |||||
Not Done Inline Actionsremove trailing whitespace elexis: remove trailing whitespace | |||||
this->SendEvent(GUIM_MOUSE_DBLCLICK_LEFT_ITEM, "mouseleftdoubleclickitem"); | this->SendEvent(GUIM_MOUSE_DBLCLICK_LEFT_ITEM, "mouseleftdoubleclickitem"); | ||||
else | else | ||||
this->SendEvent(GUIM_MOUSE_PRESS_LEFT_ITEM, "mouseleftclickitem"); | this->SendEvent(GUIM_MOUSE_PRESS_LEFT_ITEM, "mouseleftclickitem"); | ||||
m_LastItemClickTime = timer_Time(); | m_LastItemClickTime = timer_Time(); | ||||
m_PrevSelectedItem = hovered; | m_PrevSelectedItem = hovered; | ||||
break; | break; | ||||
} | } | ||||
Show All 37 Lines | void CList::HandleMessage(SGUIMessage& Message) | ||||
} | } | ||||
IGUITextOwner::HandleMessage(Message); | IGUITextOwner::HandleMessage(Message); | ||||
} | } | ||||
InReaction CList::ManuallyHandleEvent(const SDL_Event_* ev) | InReaction CList::ManuallyHandleEvent(const SDL_Event_* ev) | ||||
{ | { | ||||
InReaction result = IN_PASS; | InReaction result = IN_PASS; | ||||
if (ev->ev.type == SDL_KEYDOWN) | if (ev->ev.type == SDL_KEYDOWN) | ||||
{ | { | ||||
int szChar = ev->ev.key.keysym.sym; | int szChar = ev->ev.key.keysym.sym; | ||||
switch (szChar) | switch (szChar) | ||||
{ | { | ||||
case SDLK_HOME: | case SDLK_HOME: | ||||
SelectFirstElement(); | SelectFirstElement(); | ||||
Show All 28 Lines | case SDLK_PAGEDOWN: | ||||
GetScrollBar(0).ScrollPlusPlenty(); | GetScrollBar(0).ScrollPlusPlenty(); | ||||
result = IN_HANDLED; | result = IN_HANDLED; | ||||
break; | break; | ||||
default: // Do nothing | default: // Do nothing | ||||
result = IN_PASS; | result = IN_PASS; | ||||
} | } | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
void CList::Draw() | void CList::Draw() | ||||
{ | { | ||||
int selected; | DrawList(-1, "sprite", "sprite_selectarea", "textcolor"); | ||||
GUI<int>::GetSetting(this, "selected", selected); | } | ||||
DrawList(selected, "sprite", "sprite_selectarea", "textcolor"); | void CList::DrawSelection(const int selected, const bool scrollbar, const float scroll, CGUISpriteInstance& sprite_selectarea, const int cell_id, const float bz, CRect& rect) | ||||
{ | |||||
if (!GetGUI()) | |||||
return; | |||||
if (selected < 0 || selected + 1 >= (int)m_ItemsYPositions.size()) | |||||
return; | |||||
// Get rectangle of selection: | |||||
CRect rect_sel(rect.left, rect.top + m_ItemsYPositions[selected] - scroll, | |||||
rect.right, rect.top + m_ItemsYPositions[selected + 1] - scroll); | |||||
if (rect_sel.top > rect.bottom || rect_sel.bottom < rect.top) | |||||
return; | |||||
Not Done Inline ActionsWe need to avoid C-style casts. vladislavbelov: We need to avoid C-style casts. | |||||
if (rect_sel.bottom > rect.bottom) | |||||
rect_sel.bottom = rect.bottom; | |||||
if (rect_sel.top < rect.top) | |||||
rect_sel.top = rect.top; | |||||
if (scrollbar) | |||||
{ | |||||
// Remove any overlapping area of the scrollbar. | |||||
if (rect_sel.right > GetScrollBar(0).GetOuterRect().left && | |||||
rect_sel.right <= GetScrollBar(0).GetOuterRect().right) | |||||
rect_sel.right = GetScrollBar(0).GetOuterRect().left; | |||||
if (rect_sel.left >= GetScrollBar(0).GetOuterRect().left && | |||||
rect_sel.left < GetScrollBar(0).GetOuterRect().right) | |||||
rect_sel.left = GetScrollBar(0).GetOuterRect().right; | |||||
} | } | ||||
void CList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor) | GetGUI()->DrawSprite(sprite_selectarea, cell_id, bz + 0.05f, rect_sel); | ||||
} | |||||
void CList::DrawList(const int selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor) | |||||
Done Inline ActionsSpace after selected, and sprite_selectarea,. vladislavbelov: Space after `selected,` and `sprite_selectarea,`. | |||||
{ | { | ||||
float bz = GetBufferedZ(); | float bz = GetBufferedZ(); | ||||
// First call draw on ScrollBarOwner | // First call draw on ScrollBarOwner | ||||
bool scrollbar; | bool scrollbar; | ||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar); | GUI<bool>::GetSetting(this, "scrollbar", scrollbar); | ||||
if (scrollbar) | if (scrollbar) | ||||
Show All 14 Lines | if (GetGUI()) | ||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList); | GUI<CGUIList>::GetSettingPointer(this, "list", pList); | ||||
GetGUI()->DrawSprite(*sprite, cell_id, bz, rect); | GetGUI()->DrawSprite(*sprite, cell_id, bz, rect); | ||||
float scroll = 0.f; | float scroll = 0.f; | ||||
if (scrollbar) | if (scrollbar) | ||||
scroll = GetScrollBar(0).GetPos(); | scroll = GetScrollBar(0).GetPos(); | ||||
if (selected >= 0 && selected+1 < (int)m_ItemsYPositions.size()) | CIntList sel; | ||||
{ | GUI<CIntList>::GetSetting(this, "multiSelected", sel); | ||||
// Get rectangle of selection: | m_SelectedItems = sel.m_Items; | ||||
CRect rect_sel(rect.left, rect.top + m_ItemsYPositions[selected] - scroll, | // Draw multi selection | ||||
rect.right, rect.top + m_ItemsYPositions[selected+1] - scroll); | if (!m_SelectedItems.empty()) | ||||
for (size_t selection = 0; selection < m_SelectedItems.size(); ++selection) | |||||
if (rect_sel.top <= rect.bottom && | DrawSelection(m_SelectedItems[selection], scrollbar, scroll, *sprite_selectarea, cell_id, bz, rect); | ||||
rect_sel.bottom >= rect.top) | else if (selected != -1) | ||||
{ | DrawSelection(selected, scrollbar, scroll, *sprite_selectarea, cell_id, bz, rect); | ||||
if (rect_sel.bottom > rect.bottom) | |||||
rect_sel.bottom = rect.bottom; | |||||
if (rect_sel.top < rect.top) | |||||
rect_sel.top = rect.top; | |||||
if (scrollbar) | |||||
{ | |||||
// Remove any overlapping area of the scrollbar. | |||||
if (rect_sel.right > GetScrollBar(0).GetOuterRect().left && | |||||
rect_sel.right <= GetScrollBar(0).GetOuterRect().right) | |||||
rect_sel.right = GetScrollBar(0).GetOuterRect().left; | |||||
if (rect_sel.left >= GetScrollBar(0).GetOuterRect().left && | |||||
rect_sel.left < GetScrollBar(0).GetOuterRect().right) | |||||
rect_sel.left = GetScrollBar(0).GetOuterRect().right; | |||||
} | |||||
GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect_sel); | |||||
} | |||||
} | |||||
CColor color; | CColor color; | ||||
GUI<CColor>::GetSetting(this, _textcolor, color); | GUI<CColor>::GetSetting(this, _textcolor, color); | ||||
for (size_t i = 0; i < pList->m_Items.size(); ++i) | for (size_t i = 0; i < pList->m_Items.size(); ++i) | ||||
{ | { | ||||
if (m_ItemsYPositions[i+1] - scroll < 0 || | if (m_ItemsYPositions[i+1] - scroll < 0 || | ||||
m_ItemsYPositions[i] - scroll > rect.GetHeight()) | m_ItemsYPositions[i] - scroll > rect.GetHeight()) | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | void CList::SelectNextElement() | ||||
int selected; | int selected; | ||||
GUI<int>::GetSetting(this, "selected", selected); | GUI<int>::GetSetting(this, "selected", selected); | ||||
CGUIList* pList; | CGUIList* pList; | ||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList); | GUI<CGUIList>::GetSettingPointer(this, "list", pList); | ||||
if (selected != (int)pList->m_Items.size()-1) | if (selected != (int)pList->m_Items.size()-1) | ||||
{ | { | ||||
m_PrevSelectedItem = selected; | |||||
++selected; | ++selected; | ||||
GUI<int>::SetSetting(this, "selected", selected); | GUI<int>::SetSetting(this, "selected", selected); | ||||
CStrW soundPath; | CStrW soundPath; | ||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) | if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) | ||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false); | g_SoundManager->PlayAsUI(soundPath.c_str(), false); | ||||
bool multiSelectionEnabled; | |||||
GUI<bool>::GetSetting(this, "multiSelection_enabled", multiSelectionEnabled); | |||||
if (multiSelectionEnabled) | |||||
MultiSelectionControl(selected); | |||||
else | |||||
SingleSelectionControl(selected); | |||||
} | } | ||||
} | } | ||||
void CList::SelectPrevElement() | void CList::SelectPrevElement() | ||||
{ | { | ||||
int selected; | int selected; | ||||
GUI<int>::GetSetting(this, "selected", selected); | GUI<int>::GetSetting(this, "selected", selected); | ||||
if (selected > 0) | if (selected > 0) | ||||
{ | { | ||||
m_PrevSelectedItem = selected; | |||||
--selected; | --selected; | ||||
GUI<int>::SetSetting(this, "selected", selected); | GUI<int>::SetSetting(this, "selected", selected); | ||||
CStrW soundPath; | CStrW soundPath; | ||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) | if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) | ||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false); | g_SoundManager->PlayAsUI(soundPath.c_str(), false); | ||||
bool multiSelectionEnabled; | |||||
GUI<bool>::GetSetting(this, "multiSelection_enabled", multiSelectionEnabled); | |||||
if (multiSelectionEnabled) | |||||
MultiSelectionControl(selected); | |||||
else | |||||
SingleSelectionControl(selected); | |||||
} | } | ||||
} | } | ||||
void CList::SelectFirstElement() | void CList::SelectFirstElement() | ||||
{ | { | ||||
int selected; | int selected; | ||||
GUI<int>::GetSetting(this, "selected", selected); | GUI<int>::GetSetting(this, "selected", selected); | ||||
if (selected >= 0) | if (selected >= 0) { | ||||
GUI<int>::SetSetting(this, "selected", 0); | m_PrevSelectedItem = selected; | ||||
selected = 0; | |||||
GUI<int>::SetSetting(this, "selected", selected); | |||||
Done Inline ActionsIt's the wrong usage of the static, member is better. How much prev will you have with 2 CList? vladislavbelov: It's the wrong usage of the static, member is better. How much `prev` will you have with 2… | |||||
bool multiSelectionEnabled; | |||||
GUI<bool>::GetSetting(this, "multiSelection_enabled", multiSelectionEnabled); | |||||
Done Inline ActionsIf you want a debug information, use debug_printf. vladislavbelov: If you want a debug information, use `debug_printf`. | |||||
if (multiSelectionEnabled) | |||||
MultiSelectionControl(selected); | |||||
else | |||||
SingleSelectionControl(selected); | |||||
} | |||||
} | } | ||||
void CList::SelectLastElement() | void CList::SelectLastElement() | ||||
{ | { | ||||
int selected; | int selected; | ||||
GUI<int>::GetSetting(this, "selected", selected); | GUI<int>::GetSetting(this, "selected", selected); | ||||
CGUIList* pList; | CGUIList* pList; | ||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList); | GUI<CGUIList>::GetSettingPointer(this, "list", pList); | ||||
if (selected != (int)pList->m_Items.size()-1) | if (selected != (int)pList->m_Items.size() - 1) { | ||||
GUI<int>::SetSetting(this, "selected", (int)pList->m_Items.size()-1); | m_PrevSelectedItem = selected; | ||||
selected = (int)pList->m_Items.size() - 1; | |||||
GUI<int>::SetSetting(this, "selected", selected); | |||||
bool multiSelectionEnabled; | |||||
GUI<bool>::GetSetting(this, "multiSelection_enabled", multiSelectionEnabled); | |||||
if (multiSelectionEnabled) | |||||
MultiSelectionControl(selected); | |||||
else | |||||
SingleSelectionControl(selected); | |||||
} | |||||
} | } | ||||
void CList::UpdateAutoScroll() | void CList::UpdateAutoScroll() | ||||
{ | { | ||||
int selected; | int selected; | ||||
bool scrollbar; | bool scrollbar; | ||||
float scroll; | float scroll; | ||||
GUI<int>::GetSetting(this, "selected", selected); | GUI<int>::GetSetting(this, "selected", selected); | ||||
Show All 40 Lines | if (scrollbar && GetScrollBar(0).IsVisible() && | ||||
return -1; | return -1; | ||||
for (size_t i = 0; i < pList->m_Items.size(); ++i) | for (size_t i = 0; i < pList->m_Items.size(); ++i) | ||||
if (mouse.y >= rect.top + m_ItemsYPositions[i] && | if (mouse.y >= rect.top + m_ItemsYPositions[i] && | ||||
mouse.y < rect.top + m_ItemsYPositions[i + 1]) | mouse.y < rect.top + m_ItemsYPositions[i + 1]) | ||||
return i; | return i; | ||||
return -1; | return -1; | ||||
} | } | ||||
Not Done Inline Actionsno whitespace in empty linesa elexis: no whitespace in empty linesa | |||||
Not Done Inline Actionsno whitespace in empty lines elexis: no whitespace in empty lines | |||||
Not Done Inline Actionsno whietspace in empty lines elexis: no whietspace in empty lines |
Space after if.