Sort resolutions by size

This commit is contained in:
Flakebi
2015-02-04 16:45:10 +01:00
parent cdb35b0804
commit 6e8f8a15bd
3 changed files with 30 additions and 0 deletions

View File

@@ -518,6 +518,7 @@ void DynamicRibbonWidget::clearItems()
m_scroll_offset = 0;
m_max_label_width = 0;
}
// -----------------------------------------------------------------------------
void DynamicRibbonWidget::elementRemoved()
{

View File

@@ -22,6 +22,8 @@
#include <irrString.h>
#include <algorithm>
#include "guiengine/widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "utils/leak_check.hpp"
@@ -237,6 +239,13 @@ namespace GUIEngine
'updateItemDisplay' to update the display. */
void clearItems();
/** Sort the list of items with a given comparator. */
template<typename Compare>
void sortItems(Compare comp)
{
std::sort(m_items.begin(), m_items.end(), comp);
}
/**
* \brief Register a listener to be notified of selection changes within the ribbon.
* \note The ribbon takes ownership of this listener and will delete it.

View File

@@ -126,6 +126,23 @@ void OptionsScreenVideo::loadedFromFile()
// ----------------------------------------------------------------------------
struct SortResolutions
{
bool operator()(GUIEngine::ItemDescription i1, GUIEngine::ItemDescription i2)
{
int w1 = -1, w2 = -1, h1 = -1, h2 = -1;
if (sscanf(i1.m_code_name.c_str(), "%ix%i", &w1, &h1) != 2 || w1 == -1 || h1 == -1 ||
sscanf(i2.m_code_name.c_str(), "%ix%i", &w2, &h2) != 2 || w2 == -1 || h2 == -1)
{
Log::error("OptionsScreenVideo", "Failed to decode resolution %s or %s",
i1.m_code_name.c_str(), i2.m_code_name.c_str());
return false;
}
return w1 < w2 || (w1 == w2 && h1 < h2);
}
} sortResolutions;
// ----------------------------------------------------------------------------
void OptionsScreenVideo::init()
{
Screen::init();
@@ -307,6 +324,9 @@ void OptionsScreenVideo::init()
res->addItem(L"1024\u00D7768", "1024x768", "/gui/screen43.png");
}
// Sort resolutions by size
res->sortItems(sortResolutions);
} // end if not inited
res->updateItemDisplay();