Allow using icon in list header
This commit is contained in:
parent
0eca431627
commit
a98baf847f
@ -2009,6 +2009,18 @@ void Skin::process3DPane(IGUIElement *element, const core::recti &rect,
|
||||
// irrLicht does not have widgets for everything we need. so at render
|
||||
// time, we just check which type this button represents and render
|
||||
// accordingly
|
||||
bool list_header_widget = widget->m_event_handler != NULL &&
|
||||
widget->m_event_handler->getType() == WTYPE_LIST;
|
||||
if (list_header_widget)
|
||||
{
|
||||
drawListHeader(rect, widget);
|
||||
if (type == WTYPE_ICON_BUTTON)
|
||||
{
|
||||
drawIconButton(
|
||||
dynamic_cast<IconButtonWidget*>(widget)->getListHeaderIconRect(),
|
||||
widget, pressed, focused);
|
||||
}
|
||||
}
|
||||
|
||||
if (widget->m_event_handler != NULL &&
|
||||
widget->m_event_handler->m_type == WTYPE_RIBBON)
|
||||
@ -2028,22 +2040,14 @@ void Skin::process3DPane(IGUIElement *element, const core::recti &rect,
|
||||
mvw->drawRTTScene(rect);
|
||||
#endif
|
||||
}
|
||||
else if (type == WTYPE_ICON_BUTTON)
|
||||
else if (type == WTYPE_ICON_BUTTON && !list_header_widget)
|
||||
{
|
||||
drawIconButton(rect, widget, pressed, focused);
|
||||
}
|
||||
else if (type == WTYPE_BUTTON)
|
||||
{
|
||||
if (widget->m_event_handler != NULL &&
|
||||
widget->m_event_handler->getType() == WTYPE_LIST)
|
||||
{
|
||||
drawListHeader(rect, widget);
|
||||
}
|
||||
else
|
||||
else if (type == WTYPE_BUTTON && !list_header_widget)
|
||||
{
|
||||
drawButton(widget, rect, pressed, focused);
|
||||
}
|
||||
}
|
||||
else if(type == WTYPE_PROGRESS)
|
||||
{
|
||||
drawProgress(widget, rect, pressed, focused);
|
||||
|
@ -123,7 +123,8 @@ void IconButtonWidget::add()
|
||||
m_scale_mode = SCALE_MODE_KEEP_CUSTOM_ASPECT_RATIO;
|
||||
}
|
||||
|
||||
if (m_scale_mode == SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO)
|
||||
if (m_scale_mode == SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO ||
|
||||
m_scale_mode == SCALE_MODE_LIST_WIDGET)
|
||||
{
|
||||
assert(m_texture->getOriginalSize().Height > 0);
|
||||
useAspectRatio = (float)m_texture->getOriginalSize().Width /
|
||||
@ -143,14 +144,24 @@ void IconButtonWidget::add()
|
||||
suggested_w = (int)(suggested_w*needed_scale_factor);
|
||||
suggested_h = (int)(suggested_h*needed_scale_factor);
|
||||
}
|
||||
const int x_from = m_x + (m_w - suggested_w)/2; // center horizontally
|
||||
const int y_from = m_y + (m_h - suggested_h)/2; // center vertically
|
||||
const int x_from = m_x + (float)(m_w - suggested_w)/2; // center horizontally
|
||||
const int y_from = m_y + (float)(m_h - suggested_h)/2; // center vertically
|
||||
|
||||
rect<s32> widget_size = rect<s32>(x_from,
|
||||
y_from,
|
||||
x_from + suggested_w,
|
||||
y_from + suggested_h);
|
||||
|
||||
if (m_scale_mode == SCALE_MODE_LIST_WIDGET)
|
||||
{
|
||||
m_list_header_icon_rect = widget_size;
|
||||
m_list_header_icon_rect.UpperLeftCorner.X = m_list_header_icon_rect.UpperLeftCorner.X + 4;
|
||||
m_list_header_icon_rect.UpperLeftCorner.Y = m_list_header_icon_rect.UpperLeftCorner.Y + 4;
|
||||
m_list_header_icon_rect.LowerRightCorner.X = m_list_header_icon_rect.LowerRightCorner.X - 4;
|
||||
m_list_header_icon_rect.LowerRightCorner.Y = m_list_header_icon_rect.LowerRightCorner.Y - 4;
|
||||
widget_size = rect<s32>(m_x, m_y, m_x + m_w, m_y + m_h);
|
||||
}
|
||||
|
||||
IGUIButton* btn = GUIEngine::getGUIEnv()->addButton(widget_size,
|
||||
m_parent,
|
||||
(m_tab_stop ? getNewID() : getNewNoFocusID()),
|
||||
|
@ -43,6 +43,7 @@ namespace GUIEngine
|
||||
class IconButtonWidget : public Widget
|
||||
{
|
||||
private:
|
||||
irr::core::rect<s32> m_list_header_icon_rect;
|
||||
irr::video::ITexture* m_texture;
|
||||
irr::video::ITexture* m_deactivated_texture;
|
||||
irr::video::ITexture* m_highlight_texture;
|
||||
@ -55,6 +56,7 @@ namespace GUIEngine
|
||||
enum ScaleMode
|
||||
{
|
||||
SCALE_MODE_STRETCH,
|
||||
SCALE_MODE_LIST_WIDGET,
|
||||
SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO,
|
||||
SCALE_MODE_KEEP_CUSTOM_ASPECT_RATIO
|
||||
};
|
||||
@ -170,6 +172,11 @@ namespace GUIEngine
|
||||
Widget::elementRemoved();
|
||||
m_label = NULL;
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
const irr::core::rect<s32>& getListHeaderIconRect() const
|
||||
{
|
||||
return m_list_header_icon_rect;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
#include "guiengine/widgets/list_widget.hpp"
|
||||
|
||||
#include "guiengine/widgets/button_widget.hpp"
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
#include "guiengine/CGUISpriteBank.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
@ -158,8 +160,21 @@ void ListWidget::createHeader()
|
||||
name << "_column_";
|
||||
name << n;
|
||||
|
||||
ButtonWidget* header = new ButtonWidget();
|
||||
|
||||
Widget* header = NULL;
|
||||
if (n == m_header.size() || m_header[n].m_texture == NULL)
|
||||
{
|
||||
ButtonWidget* button = new ButtonWidget();
|
||||
if (n < m_header.size())
|
||||
button->setText(m_header[n].m_text);
|
||||
header = button;
|
||||
}
|
||||
else
|
||||
{
|
||||
IconButtonWidget* icon = new IconButtonWidget(
|
||||
IconButtonWidget::SCALE_MODE_LIST_WIDGET, true, false);
|
||||
icon->setImage(m_header[n].m_texture);
|
||||
header = icon;
|
||||
}
|
||||
header->m_reserved_id = getNewNoFocusID();
|
||||
|
||||
header->m_y = m_y;
|
||||
@ -180,8 +195,6 @@ void ListWidget::createHeader()
|
||||
|
||||
x += header->m_w;
|
||||
|
||||
if (n < m_header.size())
|
||||
header->setText( m_header[n].m_text );
|
||||
header->m_properties[PROP_ID] = name.str();
|
||||
|
||||
header->add();
|
||||
|
@ -24,7 +24,6 @@
|
||||
|
||||
#include "guiengine/widgets/CGUISTKListBox.hpp"
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "guiengine/widgets/button_widget.hpp"
|
||||
#include "utils/leak_check.hpp"
|
||||
#include "utils/ptr_vector.hpp"
|
||||
#include "IGUIElement.h"
|
||||
@ -57,9 +56,9 @@ namespace GUIEngine
|
||||
/** \brief if m_use_icons is true, this will contain the icon bank */
|
||||
irr::gui::STKModifiedSpriteBank* m_icons;
|
||||
|
||||
PtrVector< ButtonWidget > m_header_elements;
|
||||
PtrVector< Widget > m_header_elements;
|
||||
|
||||
ButtonWidget* m_selected_column;
|
||||
Widget* m_selected_column;
|
||||
|
||||
/** \brief whether this list is sorted in descending order */
|
||||
bool m_sort_desc;
|
||||
@ -74,11 +73,17 @@ namespace GUIEngine
|
||||
{
|
||||
irr::core::stringw m_text;
|
||||
int m_proportion;
|
||||
|
||||
irr::video::ITexture* m_texture;
|
||||
Column(irr::core::stringw text, int proportion)
|
||||
{
|
||||
m_text = text;
|
||||
m_proportion = proportion;
|
||||
m_texture = NULL;
|
||||
}
|
||||
Column(irr::video::ITexture* texture, int proportion)
|
||||
{
|
||||
m_proportion = proportion;
|
||||
m_texture = texture;
|
||||
}
|
||||
};
|
||||
|
||||
@ -274,6 +279,7 @@ namespace GUIEngine
|
||||
* \param proportion A column with proportion 2 will be twice as large as a column with proportion 1
|
||||
*/
|
||||
void addColumn(irr::core::stringw col, int proportion=1) { m_header.push_back( Column(col, proportion) ); }
|
||||
void addColumn(irr::video::ITexture* tex, int proportion=1) { m_header.push_back( Column(tex, proportion) ); }
|
||||
|
||||
void setSortable(bool sortable) { m_sortable = sortable; }
|
||||
};
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "config/player_manager.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "guiengine/widgets/button_widget.hpp"
|
||||
#include "guiengine/widgets/list_widget.hpp"
|
||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||
#include "input/device_manager.hpp"
|
||||
|
Loading…
Reference in New Issue
Block a user