Show
Ignore:
Timestamp:
08/26/10 15:38:59 (21 months ago)
Author:
Carsten
Message:

Revised custom video mode handling and initialization.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cafu/branches/cafu_to_wx/Ca3DE/ConDefs.cpp

    r126 r130  
    7777 
    7878 
     79static bool CompareModes(const wxVideoMode& Mode1, const wxVideoMode& Mode2) 
     80{ 
     81    // Compare the widths. 
     82    if (Mode1.w < Mode2.w) return true; 
     83    if (Mode1.w > Mode2.w) return false; 
     84 
     85    // The widths are equal, now compare the heights. 
     86    if (Mode1.h < Mode2.h) return true; 
     87    if (Mode1.h > Mode2.h) return false; 
     88 
     89    // The widths and heights are equal, now compare the BPP. 
     90    if (Mode1.bpp < Mode2.bpp) return true; 
     91    if (Mode1.bpp > Mode2.bpp) return false; 
     92 
     93    // The widths, heights and BPPs are equal, now compare the refresh rate. 
     94    if (Mode1.refresh < Mode2.refresh) return true; 
     95    if (Mode1.refresh > Mode2.refresh) return false; 
     96 
     97    // The modes are equal. 
     98    return false; 
     99} 
     100 
     101static std::string GetVideoModes() 
     102{ 
     103    ArrayT<wxVideoMode> Modes; 
     104 
     105    { 
     106        wxDisplay         Display; 
     107        wxArrayVideoModes wxModes=Display.GetModes(); 
     108 
     109        for (size_t ModeNr=0; ModeNr<wxModes.GetCount(); ModeNr++) 
     110            Modes.PushBack(wxModes[ModeNr]); 
     111    } 
     112 
     113    // Remove modes according to certain filter criteria, cutting excessively long mode lists. 
     114    for (unsigned long ModeNr=0; ModeNr<Modes.Size(); ModeNr++) 
     115    { 
     116        const wxVideoMode& Mode=Modes[ModeNr]; 
     117 
     118        if (Mode.w==0 || Mode.h==0 || Mode.bpp<15) 
     119        { 
     120            Modes.RemoveAt(ModeNr); 
     121            ModeNr--; 
     122            continue; 
     123        } 
     124 
     125        for (unsigned long OtherNr=0; OtherNr<Modes.Size(); OtherNr++) 
     126        { 
     127            if (OtherNr==ModeNr) continue; 
     128 
     129            const wxVideoMode& Other=Modes[OtherNr]; 
     130 
     131            if (Mode==Other || (Mode.w==Other.w && Mode.h==Other.h && Mode.bpp<32 && Mode.bpp<Other.bpp)) 
     132            { 
     133                Modes.RemoveAt(ModeNr); 
     134                ModeNr--; 
     135                break; 
     136            } 
     137        } 
     138 
     139        // Note that the above loop is written in a way that allows no additional statements here. 
     140    } 
     141 
     142    // Sort the modes by increasing width, height, BPP and refresh rate. 
     143    Modes.QuickSort(CompareModes); 
     144 
     145    // Build the result string. 
     146    wxString List; 
     147 
     148    for (unsigned long ModeNr=0; ModeNr<Modes.Size(); ModeNr++) 
     149    { 
     150        const wxVideoMode& Mode=Modes[ModeNr]; 
     151 
     152        List+=wxString::Format("%i x %i, %i bpp, %i Hz\n", Mode.w, Mode.h, Mode.bpp, Mode.refresh); 
     153    } 
     154 
     155    return List.ToStdString(); 
     156} 
     157 
     158// Note that the format of the VideoModes string is fixed - it is parsed by the Main Menu GUI in order to populate the choice box. 
     159static ConVarT VideoModes("VideoModes", GetVideoModes(), ConVarT::FLAG_MAIN_EXE | ConVarT::FLAG_READ_ONLY, "The list of video modes that are available on your system."); 
     160 
     161 
    79162static int ConFunc_CleanupPersistentConfig_Callback(lua_State* LuaState) 
    80163{