Resolutions in options menu are now obtained from irrlicht

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3472 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-05-09 20:20:16 +00:00
parent 5d1727e5dd
commit b0b3b9d3ae
7 changed files with 122 additions and 37 deletions

BIN
data/gui/screen32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -65,17 +65,26 @@ void IrrDriver::initDevice()
video::IVideoModeList* modes = m_device->getVideoModeList();
const int count = modes->getVideoModeCount();
std::cout << "--------------\n allowed modes \n--------------\n";
std::cout << "Desktop depth : " << modes->getDesktopDepth() << std::endl;
std::cout << "Desktop resolution : " << modes->getDesktopResolution().Width << "," << modes->getDesktopResolution().Height << std::endl;
//std::cout << "--------------\n allowed modes \n--------------\n";
//std::cout << "Desktop depth : " << modes->getDesktopDepth() << std::endl;
//std::cout << "Desktop resolution : " << modes->getDesktopResolution().Width << "," << modes->getDesktopResolution().Height << std::endl;
std::cout << "Found " << count << " valid modes\n";
//std::cout << "Found " << count << " valid modes\n";
for(int i=0; i<count; i++)
{
std::cout <<
"bits : " << modes->getVideoModeDepth(i) <<
" resolution=" << modes->getVideoModeResolution(i).Width <<
"x" << modes->getVideoModeResolution(i).Height << std::endl;
// only consider 32-bit resolutions for now
if(modes->getVideoModeDepth(i) == 32)
{
VideoMode mode;
mode.width = modes->getVideoModeResolution(i).Width;
mode.height = modes->getVideoModeResolution(i).Height;
m_modes.push_back( mode );
}
//std::cout <<
//"bits : " << modes->getVideoModeDepth(i) <<
//" resolution=" << modes->getVideoModeResolution(i).Width <<
//"x" << modes->getVideoModeResolution(i).Height << std::endl;
}
m_device->closeDevice();
@ -91,7 +100,7 @@ void IrrDriver::initDevice()
: (driver_type==1
? video::EDT_DIRECT3D9
: video::EDT_DIRECT3D8);
// Try 32 and 16 bit per pixels
// Try 32 and, upon failure, 16 bit per pixels
for(int bits=32; bits>15; bits -=16)
{
m_device = createDevice(type,

View File

@ -26,6 +26,11 @@
#include "irrlicht.h"
using namespace irr;
struct VideoMode
{
int width, height;
};
class IrrDriver : public IEventReceiver
{
private:
@ -39,12 +44,15 @@ private:
irr::gui::IGUIFont *m_race_font;
void setAllMaterialFlags(scene::IAnimatedMesh *mesh) const;
std::vector<VideoMode> m_modes;
public:
IrrDriver();
~IrrDriver();
void initDevice();
const std::vector<VideoMode>& getVideoModes() const { return m_modes; }
IrrlichtDevice *getDevice() const { return m_device; }
scene::ISceneManager *getSceneManager() const { return m_scene_manager; }
scene::IAnimatedMesh *getAnimatedMesh(const std::string &name);

View File

@ -313,22 +313,64 @@ namespace StateManager
static bool resolutions_inited = false;
// --- get resolution list from irrlicht the first time
if(!resolutions_inited)
{
res->addItem("1280x1024","1280x1024","gui/screen54.png"); // 0
res->addItem("800x600","800x600","gui/screen43.png"); // 1
res->addItem("1024x768","1024x768","gui/screen43.png"); // 2
res->addItem("1152x864","1152x864","gui/screen43.png"); // 3
res->addItem("1280x960","1280x960","gui/screen43.png"); // 4
res->addItem("1400x1050","1400x1050","gui/screen43.png"); // 5
res->addItem("1280x800","1280x800","gui/screen1610.png"); // 6
res->addItem("1440x900","1440x900","gui/screen1610.png"); // 7
res->addItem("1680x1050","1680x1050","gui/screen1610.png"); // 8
res->addItem("1920x1200","1920x1200","gui/screen1610.png"); // 9
res->addItem("1280x768","1280x768","gui/screen53.png"); // 10
const std::vector<VideoMode>& modes = irr_driver->getVideoModes();
const int amount = modes.size();
for(int n=0; n<amount; n++)
{
const int w = modes[n].width;
const int h = modes[n].height;
const float ratio = (float)w / h;
char name[32];
sprintf( name, "%ix%i", w, h );
#define ABOUT_EQUAL(a , b) (fabsf( a - b ) < 0.01)
if( ABOUT_EQUAL( ratio, (5.0f/4.0f) ) )
res->addItem(name,name,"gui/screen54.png");
else if( ABOUT_EQUAL( ratio, (4.0f/3.0f) ) )
res->addItem(name,name,"gui/screen43.png");
else if( ABOUT_EQUAL( ratio, (16.0f/10.0f) ) )
res->addItem(name,name,"gui/screen1610.png");
else if( ABOUT_EQUAL( ratio, (5.0f/3.0f) ) )
res->addItem(name,name,"gui/screen53.png");
else if( ABOUT_EQUAL( ratio, (3.0f/2.0f) ) )
res->addItem(name,name,"gui/screen32.png");
else
{
std::cout << "Unknown screen size ratio : " << ratio << std::endl;
res->addItem(name,name,"gui/screen1610.png");
}
#undef ABOUT_EQUAL
} // next resolution
resolutions_inited = true;
}
} // end if not inited
res->updateItemDisplay();
// ---- select curernt resolution every time
const std::vector<VideoMode>& modes = irr_driver->getVideoModes();
const int amount = modes.size();
for(int n=0; n<amount; n++)
{
const int w = modes[n].width;
const int h = modes[n].height;
char name[32];
sprintf( name, "%ix%i", w, h );
if(w == user_config->m_width && h == user_config->m_height)
{
// that's the current one
res->setSelection(n);
break;
}
} // end for
}
}
else if(screen_name == "options_input.stkgui")

View File

@ -1073,6 +1073,30 @@ void RibbonGridWidget::addItem( std::string user_name, std::string code_name, st
m_items.push_back(desc);
}
// -----------------------------------------------------------------------------
void RibbonGridWidget::setSelection(int item_id)
{
setSelection(m_items[item_id].m_code_name);
}
void RibbonGridWidget::setSelection(const std::string& code_name)
{
if(m_rows.size() > 1)
{
std::cout << "/!\\ Warning, RibbonGridWidget::setSelection only makes sense on 1-row ribbons (since there can't logically be a selection with more than one row)\n";
}
// select the said item (mostly to get its ID)
RibbonWidget* ribbon = m_rows.get(0);
ribbon->select(code_name);
// scroll so selection is visible
m_scroll_offset = ribbon->m_selection;
updateItemDisplay();
// set selection again, because scrolling made it wrong
ribbon->select(code_name);
}
// -----------------------------------------------------------------------------
void RibbonGridWidget::updateItemDisplay()
{
int icon_id = 0;

View File

@ -240,10 +240,10 @@ namespace GUIEngine
int getSelection() const { return m_selection; }
void setSelection(const int i) { m_selection = i; updateSelection(); }
void select(std::string item);
RibbonType getRibbonType() const { return m_ribbon_type; }
const std::string& getSelectionName() { return m_children[m_selection].m_properties[PROP_ID]; }
void select(std::string item);
void setLabel(const int id, std::string new_name);
RibbonWidget(const RibbonType type=RIBBON_COMBO);
@ -302,6 +302,8 @@ namespace GUIEngine
bool mouseHovered(Widget* child);
const std::string& getSelectionName();
void setSelection(int item_id);
void setSelection(const std::string& code_name);
};
class ModelViewWidget : public Widget

View File

@ -1747,26 +1747,26 @@
95C2AE870F296542000D3E5D /* graphics */ = {
isa = PBXGroup;
children = (
95C65D8E0F532FCE00BE7BA7 /* moving_texture.hpp */,
95C65D8F0F532FCE00BE7BA7 /* shadow.hpp */,
95C65D900F532FCE00BE7BA7 /* skid_marks.hpp */,
95C65D910F532FCE00BE7BA7 /* particle_system.hpp */,
95C65D920F532FCE00BE7BA7 /* nitro.hpp */,
95C65D930F532FCE00BE7BA7 /* scene.hpp */,
95C65D980F532FD400BE7BA7 /* camera.cpp */,
95C65D960F532FCE00BE7BA7 /* camera.hpp */,
95C65D990F532FD400BE7BA7 /* irr_driver.cpp */,
95C65D940F532FCE00BE7BA7 /* irr_driver.hpp */,
95C65D950F532FCE00BE7BA7 /* mesh_tools.hpp */,
95C65D970F532FD400BE7BA7 /* smoke.hpp */,
95C65D980F532FD400BE7BA7 /* camera.cpp */,
95C65D990F532FD400BE7BA7 /* irr_driver.cpp */,
95C65D9A0F532FD400BE7BA7 /* mesh_tools.cpp */,
95C65D9B0F532FD400BE7BA7 /* moving_texture.cpp */,
95C65D9C0F532FD400BE7BA7 /* particle_system.cpp */,
95C65D9D0F532FD400BE7BA7 /* skid_marks.cpp */,
95C65D9E0F532FD400BE7BA7 /* smoke.cpp */,
95C65D9F0F532FD400BE7BA7 /* scene.cpp */,
95C65DA00F532FD400BE7BA7 /* shadow.cpp */,
95C65D8E0F532FCE00BE7BA7 /* moving_texture.hpp */,
95C65DA10F532FD400BE7BA7 /* nitro.cpp */,
95C65D960F532FCE00BE7BA7 /* camera.hpp */,
95C65D920F532FCE00BE7BA7 /* nitro.hpp */,
95C65D9C0F532FD400BE7BA7 /* particle_system.cpp */,
95C65D910F532FCE00BE7BA7 /* particle_system.hpp */,
95C65D9F0F532FD400BE7BA7 /* scene.cpp */,
95C65D930F532FCE00BE7BA7 /* scene.hpp */,
95C65D9D0F532FD400BE7BA7 /* skid_marks.cpp */,
95C65D900F532FCE00BE7BA7 /* skid_marks.hpp */,
95C65D9E0F532FD400BE7BA7 /* smoke.cpp */,
95C65D970F532FD400BE7BA7 /* smoke.hpp */,
95C65DA00F532FD400BE7BA7 /* shadow.cpp */,
95C65D8F0F532FCE00BE7BA7 /* shadow.hpp */,
);
name = graphics;
path = ../../graphics;