A optional header to list control (atm not very pretty and only supports 2 columns, but the basic features are there)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8613 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
8cd2eb1e16
commit
3cee2ddbe3
@ -176,6 +176,9 @@ when the border that intersect at this corner are enabled.
|
||||
<element type="left_arrow" state="focus" image="peach/left_arrow_focus.png" />
|
||||
<element type="right_arrow" state="focus" image="peach/right_arrow_focus.png" />
|
||||
|
||||
<element type="list_header" state="neutral" image="peach/table_header.png" />
|
||||
<element type="list_sort_up" state="neutral" image="peach/list_sort_up.png" />
|
||||
|
||||
<!-- Stateless -->
|
||||
<element type="section" image="peach/glass_section.png"
|
||||
left_border="15" right_border="15" top_border="15" bottom_border="15"
|
||||
|
BIN
data/gui/skins/glass/left_arrow.png
Normal file
BIN
data/gui/skins/glass/left_arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
BIN
data/gui/skins/glass/right_arrow.png
Normal file
BIN
data/gui/skins/glass/right_arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
BIN
data/gui/skins/peach/list_sort_up.png
Normal file
BIN
data/gui/skins/peach/list_sort_up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
BIN
data/gui/skins/peach/table_header.png
Normal file
BIN
data/gui/skins/peach/table_header.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 860 B |
@ -1265,6 +1265,27 @@ void Skin::drawListSelection(const core::rect< s32 > &rect, Widget* widget, bool
|
||||
}
|
||||
}
|
||||
|
||||
void Skin::drawListHeader(const irr::core::rect< irr::s32 > &rect, Widget* widget)
|
||||
{
|
||||
//ListWidget* list = dynamic_cast<ListWidget*>(widget);
|
||||
//assert(list != NULL);
|
||||
|
||||
drawBoxFromStretchableTexture(widget, rect,
|
||||
SkinConfig::m_render_params["list_header::neutral"], false, NULL /* clip */);
|
||||
|
||||
IGUIButton* btn = widget->getIrrlichtElement<IGUIButton>();
|
||||
if (btn->isPressed())
|
||||
{
|
||||
ITexture* img = SkinConfig::m_render_params["list_sort_up::neutral"].getImage();
|
||||
core::rect< s32 > destRect(rect.UpperLeftCorner,
|
||||
core::dimension2d<s32>(rect.getHeight(), rect.getHeight()));
|
||||
core::rect< s32 > srcRect(core::position2d<s32>(0,0), img->getSize());
|
||||
irr_driver->getVideoDriver()->draw2DImage(img, destRect, srcRect, NULL, NULL, true /* alpha */);
|
||||
}
|
||||
|
||||
//GUIEngine::getFont()->draw( list->getHeader(), rect, irr::video::SColor(255,0,0,0) ); //getColor("text") );
|
||||
}
|
||||
|
||||
/** recursive function to render all sections (recursion allows to easily traverse the tree of children
|
||||
* and sub-children)
|
||||
*/
|
||||
@ -1520,9 +1541,16 @@ void Skin::process3DPane(IGUIElement *element, const core::rect< s32 > &rect, co
|
||||
{
|
||||
drawIconButton(rect, widget, pressed, focused);
|
||||
}
|
||||
else if(type == WTYPE_BUTTON)
|
||||
else if (type == WTYPE_BUTTON)
|
||||
{
|
||||
drawButton(widget, rect, pressed, focused);
|
||||
if (widget->m_event_handler != NULL && widget->m_event_handler->getType() == WTYPE_LIST)
|
||||
{
|
||||
drawListHeader(rect, widget);
|
||||
}
|
||||
else
|
||||
{
|
||||
drawButton(widget, rect, pressed, focused);
|
||||
}
|
||||
}
|
||||
else if(type == WTYPE_PROGRESS)
|
||||
{
|
||||
@ -1718,7 +1746,19 @@ void Skin::draw3DSunkenPane (IGUIElement *element, video::SColor bgcolor, bool f
|
||||
}
|
||||
else if (type == WTYPE_LIST)
|
||||
{
|
||||
drawList(rect, widget, focused);
|
||||
//drawList(rect, widget, focused);
|
||||
|
||||
drawList(core::rect<s32>(widget->m_x, widget->m_y, widget->m_x + widget->m_w, widget->m_y + widget->m_h),
|
||||
widget, focused);
|
||||
|
||||
/*
|
||||
if (((ListWidget*)widget)->getHeader().size() > 0)
|
||||
{
|
||||
drawListHeader(core::rect<s32>(widget->m_x, widget->m_y, widget->m_x + widget->m_w, rect.UpperLeftCorner.Y),
|
||||
widget);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
else if (type == WTYPE_BUBBLE)
|
||||
{
|
||||
|
@ -265,6 +265,7 @@ namespace GUIEngine
|
||||
void drawGaugeFill(const irr::core::rect< irr::s32 > &rect, Widget* widget, bool focused);
|
||||
void drawCheckBox(const irr::core::rect< irr::s32 > &rect, Widget* widget, bool focused);
|
||||
void drawList(const irr::core::rect< irr::s32 > &rect, Widget* widget, bool focused);
|
||||
void drawListHeader(const irr::core::rect< irr::s32 > &rect, Widget* widget);
|
||||
void drawListSelection(const irr::core::rect< irr::s32 > &rect, Widget* widget, bool focused, const irr::core::rect< irr::s32 > *clip);
|
||||
void drawIconButton(const irr::core::rect< irr::s32 > &rect, Widget* widget, const bool pressed, bool focused);
|
||||
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
#include "guiengine/CGUISpriteBank.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using namespace GUIEngine;
|
||||
using namespace irr::core;
|
||||
using namespace irr::gui;
|
||||
@ -71,13 +73,47 @@ void ListWidget::setIcons(STKModifiedSpriteBank* icons)
|
||||
|
||||
void ListWidget::add()
|
||||
{
|
||||
rect<s32> widget_size = rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h);
|
||||
const int header_height = GUIEngine::getFontHeight() + 15;
|
||||
|
||||
rect<s32> widget_size = (m_header.size() > 0 ? rect<s32>(m_x, m_y + header_height, m_x + m_w, m_y + m_h) :
|
||||
rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h) );
|
||||
|
||||
IGUIListBox* list = GUIEngine::getGUIEnv()->addListBox (widget_size, m_parent, getNewID());
|
||||
list->setAutoScrollEnabled(false);
|
||||
|
||||
m_element = list;
|
||||
m_element->setTabOrder( list->getID() );
|
||||
|
||||
if (m_header.size() > 0)
|
||||
{
|
||||
const int col_size = m_w / m_header.size();
|
||||
|
||||
for (int n=0; n<m_header.size(); n++)
|
||||
{
|
||||
std::ostringstream name;
|
||||
name << m_properties[PROP_ID];
|
||||
name << "_column_";
|
||||
name << n;
|
||||
|
||||
ButtonWidget* header = new ButtonWidget();
|
||||
header->m_y = m_y;
|
||||
header->m_h = header_height;
|
||||
|
||||
header->m_x = m_x + col_size*n;
|
||||
header->m_w = col_size;
|
||||
|
||||
header->setText( m_header[n] );
|
||||
header->m_properties[PROP_ID] = name.str();
|
||||
|
||||
header->add();
|
||||
header->m_event_handler = this;
|
||||
|
||||
m_children.push_back(header);
|
||||
m_header_elements.push_back(header);
|
||||
}
|
||||
|
||||
m_check_inside_me = true;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -229,6 +265,13 @@ void ListWidget::elementRemoved()
|
||||
{
|
||||
Widget::elementRemoved();
|
||||
m_items.clear();
|
||||
|
||||
for (int n=0; n<m_header_elements.size(); n++)
|
||||
{
|
||||
m_header_elements[n].elementRemoved();
|
||||
m_children.remove( m_header_elements.get(n) );
|
||||
}
|
||||
m_header_elements.clearAndDeleteAll();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -267,3 +310,21 @@ void ListWidget::markItemRed(const int id, bool red)
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
EventPropagation ListWidget::transmitEvent(Widget* w, std::string& originator, const int playerID)
|
||||
{
|
||||
if (originator.find(m_properties[PROP_ID] + "_column_") != std::string::npos)
|
||||
{
|
||||
int col = originator[ (m_properties[PROP_ID] + "_column_").size() ] - '0';
|
||||
|
||||
for (int n=0; n<m_header_elements.size(); n++)
|
||||
{
|
||||
m_header_elements[n].getIrrlichtElement<IGUIButton>()->setPressed(false);
|
||||
}
|
||||
m_header_elements[col].getIrrlichtElement<IGUIButton>()->setPressed(true);
|
||||
|
||||
return EVENT_BLOCK;
|
||||
}
|
||||
|
||||
return EVENT_LET;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <irrlicht.h>
|
||||
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "guiengine/widgets/button_widget.hpp"
|
||||
#include "utils/ptr_vector.hpp"
|
||||
|
||||
namespace irr { namespace gui { class STKModifiedSpriteBank; } }
|
||||
@ -50,6 +51,11 @@ namespace GUIEngine
|
||||
};
|
||||
std::vector< ListItem > m_items;
|
||||
|
||||
PtrVector< ButtonWidget > m_header_elements;
|
||||
|
||||
/** Leave empty for no header */
|
||||
std::vector< irr::core::stringw > m_header;
|
||||
|
||||
public:
|
||||
ListWidget();
|
||||
|
||||
@ -161,6 +167,13 @@ namespace GUIEngine
|
||||
assert(id != -1);
|
||||
markItemRed( id, red );
|
||||
}
|
||||
|
||||
/** Override callback from Widget */
|
||||
virtual EventPropagation transmitEvent(Widget* w, std::string& originator, const int playerID);
|
||||
|
||||
/** To be called before Widget::add(); columns are persistent across multiple add/remove cycles
|
||||
*/
|
||||
void addColumn(irr::core::stringw col) { m_header.push_back( col ); }
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,11 @@ void AddonsScreen::loadedFromFile()
|
||||
m_icon_installed = m_icon_bank->addTextureAsSprite(icon1);
|
||||
m_icon_not_installed = m_icon_bank->addTextureAsSprite(icon2);
|
||||
m_icon_needs_update = m_icon_bank->addTextureAsSprite(icon3);
|
||||
|
||||
GUIEngine::ListWidget* w_list =
|
||||
getWidget<GUIEngine::ListWidget>("list_addons");
|
||||
w_list->addColumn( L"Add-on name" );
|
||||
w_list->addColumn( L"Updated date" );
|
||||
} // loadedFromFile
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -67,12 +72,14 @@ void AddonsScreen::init()
|
||||
if(UserConfigParams::logAddons())
|
||||
std::cout << "[addons] Using directory <" + file_manager->getAddonsDir()
|
||||
<< ">\n";
|
||||
|
||||
GUIEngine::ListWidget* w_list =
|
||||
getWidget<GUIEngine::ListWidget>("list_addons");
|
||||
w_list->setIcons(m_icon_bank);
|
||||
|
||||
|
||||
getWidget<GUIEngine::LabelWidget>("update_status")
|
||||
->setText(_("Updating the list..."), false);
|
||||
|
||||
m_type = "kart";
|
||||
loadList();
|
||||
} // init
|
||||
|
Loading…
x
Reference in New Issue
Block a user