From 830c85a262c2db457bddec1c7eac1d82158e1605 Mon Sep 17 00:00:00 2001 From: Alayan Date: Sat, 15 Dec 2018 08:04:08 +0100 Subject: [PATCH] Make list line height and alternate darkness .stkgui options --- src/guiengine/screen_loader.cpp | 2 ++ src/guiengine/widget.hpp | 2 ++ src/guiengine/widgets/CGUISTKListBox.cpp | 2 +- src/guiengine/widgets/CGUISTKListBox.hpp | 1 + src/guiengine/widgets/list_widget.cpp | 12 +++++++++--- src/guiengine/widgets/list_widget.hpp | 4 ---- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/guiengine/screen_loader.cpp b/src/guiengine/screen_loader.cpp index bef51e5de..0931555df 100644 --- a/src/guiengine/screen_loader.cpp +++ b/src/guiengine/screen_loader.cpp @@ -204,6 +204,8 @@ if(prop_name != NULL) widget.m_properties[prop_flag] = core::stringc(prop_name). READ_PROPERTY(child_width, PROP_CHILD_WIDTH); READ_PROPERTY(child_height, PROP_CHILD_HEIGHT); READ_PROPERTY(word_wrap, PROP_WORD_WRAP); + READ_PROPERTY(alternate_bg, PROP_ALTERNATE_BG); + READ_PROPERTY(line_height, PROP_LINE_HEIGHT); //READ_PROPERTY(grow_with_text, PROP_GROW_WITH_TEXT); READ_PROPERTY(x, PROP_X); READ_PROPERTY(y, PROP_Y); diff --git a/src/guiengine/widget.hpp b/src/guiengine/widget.hpp index 5247d3c34..614193802 100644 --- a/src/guiengine/widget.hpp +++ b/src/guiengine/widget.hpp @@ -89,6 +89,8 @@ namespace GUIEngine PROP_CHILD_WIDTH, PROP_CHILD_HEIGHT, PROP_WORD_WRAP, + PROP_ALTERNATE_BG, + PROP_LINE_HEIGHT, //PROP_GROW_WITH_TEXT, // yet unused PROP_X, PROP_Y, diff --git a/src/guiengine/widgets/CGUISTKListBox.cpp b/src/guiengine/widgets/CGUISTKListBox.cpp index c0d869e5a..5c01275a0 100644 --- a/src/guiengine/widgets/CGUISTKListBox.cpp +++ b/src/guiengine/widgets/CGUISTKListBox.cpp @@ -586,7 +586,7 @@ void CGUISTKListBox::draw() } core::rect lineRect = textRect; - int line_height = Font->getDimension(L"A").Height; + int line_height = Font->getDimension(L"A").Height*Items[i].m_line_height_scale; int supp_lines = Items[i].m_contents[x].m_text_lines.size() - 1; lineRect.UpperLeftCorner.Y -= (line_height*supp_lines)/2; lineRect.LowerRightCorner.Y -= (line_height*supp_lines)/2; diff --git a/src/guiengine/widgets/CGUISTKListBox.hpp b/src/guiengine/widgets/CGUISTKListBox.hpp index 42c10ed1c..f69ce47c2 100644 --- a/src/guiengine/widgets/CGUISTKListBox.hpp +++ b/src/guiengine/widgets/CGUISTKListBox.hpp @@ -55,6 +55,7 @@ namespace irr int m_current_id; bool m_word_wrap = false; + float m_line_height_scale = 0.0f; // A multicolor extension struct ListItemOverrideColor diff --git a/src/guiengine/widgets/list_widget.cpp b/src/guiengine/widgets/list_widget.cpp index bc08efbe8..192d80622 100644 --- a/src/guiengine/widgets/list_widget.cpp +++ b/src/guiengine/widgets/list_widget.cpp @@ -45,7 +45,6 @@ ListWidget::ListWidget() : Widget(WTYPE_LIST) m_sort_col = 0; m_sortable = true; m_header_created = false; - m_alternating_darkness = false; } // ----------------------------------------------------------------------------- @@ -111,7 +110,7 @@ void ListWidget::add() true, false); - list_box->setAlternatingDarkness(m_alternating_darkness); + list_box->setAlternatingDarkness(m_properties[PROP_ALTERNATE_BG] == "true"); if (current_skin && current_skin->getSpriteBank()) { list_box->setSpriteBank(current_skin->getSpriteBank()); @@ -228,7 +227,7 @@ void ListWidget::clearColumns() } //clearColumns // ----------------------------------------------------------------------------- - +//FIXME : remove the code duplication of the two addItem functions void ListWidget::addItem( const std::string& internal_name, const irr::core::stringw &name, const int icon, @@ -242,6 +241,10 @@ void ListWidget::addItem( const std::string& internal_name, newItem.m_internal_name = internal_name; newItem.m_contents.push_back(cell); newItem.m_word_wrap = (m_properties[PROP_WORD_WRAP] == "true"); + newItem.m_line_height_scale = m_properties[PROP_LINE_HEIGHT] == "small" ? 0.75f : + m_properties[PROP_LINE_HEIGHT] == "normal" ? 1.0f : + m_properties[PROP_LINE_HEIGHT] == "big" ? 1.25f : 1.0f; + CGUISTKListBox* list = getIrrlichtElement(); assert(list != NULL); @@ -270,6 +273,9 @@ void ListWidget::addItem(const std::string& internal_name, newItem.m_contents.push_back(contents[i]); } newItem.m_word_wrap = (m_properties[PROP_WORD_WRAP] == "true"); + newItem.m_line_height_scale = m_properties[PROP_LINE_HEIGHT] == "small" ? 0.75f : + m_properties[PROP_LINE_HEIGHT] == "normal" ? 1.0f : + m_properties[PROP_LINE_HEIGHT] == "big" ? 1.25f : 1.0f; CGUISTKListBox* list = getIrrlichtElement(); assert(list != NULL); diff --git a/src/guiengine/widgets/list_widget.hpp b/src/guiengine/widgets/list_widget.hpp index 2f89c3f91..4e14c41dc 100644 --- a/src/guiengine/widgets/list_widget.hpp +++ b/src/guiengine/widgets/list_widget.hpp @@ -91,8 +91,6 @@ namespace GUIEngine bool m_header_created; - bool m_alternating_darkness; - public: typedef irr::gui::CGUISTKListBox::ListItem ListItem; typedef ListItem::ListCell ListCell; @@ -278,8 +276,6 @@ namespace GUIEngine void addColumn(irr::core::stringw col, int proportion=1) { m_header.push_back( Column(col, proportion) ); } void setSortable(bool sortable) { m_sortable = sortable; } - - void setAlternatingDarkness(bool val) { m_alternating_darkness = val; } }; }