diff --git a/src/guiengine/widgets/dynamic_ribbon_widget.cpp b/src/guiengine/widgets/dynamic_ribbon_widget.cpp index 23224fa59..f233a5d46 100644 --- a/src/guiengine/widgets/dynamic_ribbon_widget.cpp +++ b/src/guiengine/widgets/dynamic_ribbon_widget.cpp @@ -518,6 +518,7 @@ void DynamicRibbonWidget::clearItems() m_scroll_offset = 0; m_max_label_width = 0; } + // ----------------------------------------------------------------------------- void DynamicRibbonWidget::elementRemoved() { diff --git a/src/guiengine/widgets/dynamic_ribbon_widget.hpp b/src/guiengine/widgets/dynamic_ribbon_widget.hpp index d2e842cf8..520bde76e 100644 --- a/src/guiengine/widgets/dynamic_ribbon_widget.hpp +++ b/src/guiengine/widgets/dynamic_ribbon_widget.hpp @@ -22,6 +22,8 @@ #include +#include + #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 + 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. diff --git a/src/states_screens/options_screen_video.cpp b/src/states_screens/options_screen_video.cpp index e875daa1c..958506182 100644 --- a/src/states_screens/options_screen_video.cpp +++ b/src/states_screens/options_screen_video.cpp @@ -103,6 +103,33 @@ static GFXPreset GFX_PRESETS[] = static const int GFX_LEVEL_AMOUNT = 5; +struct Resolution +{ + int width, height; + + Resolution() + { + width = 0; + height = 0; + } + + Resolution(int w, int h) + { + width = w; + height = h; + } + + bool operator< (Resolution r) const + { + return width < r.width || (width == r.width && height < r.height); + } + + float getRatio() const + { + return (float) width / height; + } +}; + // ---------------------------------------------------------------------------- OptionsScreenVideo::OptionsScreenVideo() : Screen("options_video.stkgui") @@ -176,6 +203,9 @@ void OptionsScreenVideo::init() irr_driver->getVideoModes(); const int amount = (int)modes.size(); + std::vector resolutions; + Resolution r; + bool found_config_res = false; // for some odd reason, irrlicht sometimes fails to report the good @@ -190,40 +220,95 @@ void OptionsScreenVideo::init() for (int n=0; n::iterator it = resolutions.begin(); + it != resolutions.end(); it++) + { + const float ratio = it->getRatio(); char name[32]; - sprintf( name, "%ix%i", w, h ); + sprintf(name, "%ix%i", it->width, it->height); core::stringw label; - label += w; + label += it->width; label += L"\u00D7"; - label += h; + label += it->height; #define ABOUT_EQUAL(a , b) (fabsf( a - b ) < 0.01) @@ -242,71 +327,7 @@ void OptionsScreenVideo::init() else res->addItem(label, name, "/gui/screen_other.png"); #undef ABOUT_EQUAL - } // next resolution - - if (!found_config_res) - { - const int w = UserConfigParams::m_width; - const int h = UserConfigParams::m_height; - const float ratio = (float)w / h; - - if (w == 800 && h == 600) - { -#ifdef DEBUG - found_800_600 = true; -#endif - } - else if (w == 1024 && h == 640) - { - found_1024_640 = true; - } - else if (w == 1024 && h == 768) - { - found_1024_768 = true; - } - - char name[32]; - sprintf( name, "%ix%i", w, h ); - - core::stringw label; - label += w; - label += L"\u00D7"; - label += h; - -#define ABOUT_EQUAL(a , b) (fabsf( a - b ) < 0.01) - - if (ABOUT_EQUAL( ratio, (5.0f/4.0f) )) - res->addItem(label, name, "/gui/screen54.png"); - else if (ABOUT_EQUAL( ratio, (4.0f/3.0f) )) - res->addItem(label, name, "/gui/screen43.png"); - else if (ABOUT_EQUAL( ratio, (16.0f/10.0f) )) - res->addItem(label, name, "/gui/screen1610.png"); - else if (ABOUT_EQUAL( ratio, (5.0f/3.0f) )) - res->addItem(label, name, "/gui/screen53.png"); - else if (ABOUT_EQUAL( ratio, (3.0f/2.0f) )) - res->addItem(label, name, "/gui/screen32.png"); - else if (ABOUT_EQUAL( ratio, (16.0f/9.0f) )) - res->addItem(label, name, "/gui/screen169.png"); - else - res->addItem(label, name, "/gui/screen_other.png"); -#undef ABOUT_EQUAL - } - -#ifdef DEBUG - if (!found_800_600) - { - res->addItem(L"800\u00D7600", "800x600", "/gui/screen43.png"); - } -#endif - if (!found_1024_640) - { - res->addItem(L"1024\u00D7640", "1024x640", "/gui/screen1610.png"); - } - if (!found_1024_768) - { - res->addItem(L"1024\u00D7768", "1024x768", "/gui/screen43.png"); - } - + } // add next resolution } // end if not inited res->updateItemDisplay();