added the necessary core code to allow resolution switching. currently you can't choose from list, but clicking the 'apply video changes' button will test it by going into 800x480 resolution (so don't try this when fullscreen...)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3417 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-04-23 23:27:06 +00:00
parent 8bc4ed83e9
commit db978329ad
7 changed files with 127 additions and 35 deletions

View File

@ -22,29 +22,54 @@
#include "material_manager.hpp"
#include "user_config.hpp"
#include "gui/engine.hpp"
#include "gui/state_manager.hpp"
#include "io/file_manager.hpp"
#include "items/item_manager.hpp"
#include "items/powerup_manager.hpp"
#include "items/attachment_manager.hpp"
#include "items/projectile_manager.hpp"
#include "karts/kart_properties_manager.hpp"
#include "material_manager.hpp"
#include "gui/font.hpp"
IrrDriver *irr_driver = NULL;
IrrDriver::IrrDriver()
{
file_manager->dropFileSystem();
initDevice();
} // IrrDriver
// ----------------------------------------------------------------------------
IrrDriver::~IrrDriver()
{
m_device->drop();
} // ~IrrDriver
// ----------------------------------------------------------------------------
void IrrDriver::initDevice()
{
std::cout << "initDevice ::> creating device, size = " << user_config->m_width << ", " << user_config->m_height << std::endl;
// Try different drivers: start with opengl, then DirectX
for(int driver_type=0; driver_type<3; driver_type++)
{
// FIXME: directX+SLD is not supported anyway - so we could
// remove support for this here anyway.
video::E_DRIVER_TYPE type = driver_type==0
? video::EDT_OPENGL
: (driver_type==1
? video::EDT_DIRECT3D9
: video::EDT_DIRECT3D8);
? video::EDT_OPENGL
: (driver_type==1
? video::EDT_DIRECT3D9
: video::EDT_DIRECT3D8);
// Try 32 and 16 bit per pixels
for(int bits=32; bits>15; bits -=16)
{
m_device = createDevice(type,
core::dimension2d<s32>(user_config->m_width,
user_config->m_height ),
core::dimension2d<s32>(user_config->m_width,
user_config->m_height ),
bits, //bits per pixel
user_config->m_fullscreen,
false, // stencil buffers
@ -62,7 +87,7 @@ IrrDriver::IrrDriver()
}
m_device->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS,true);
// Stores the new file system pointer.
file_manager->setDevice(m_device);
m_device->setWindowCaption(L"SuperTuxKart");
@ -70,15 +95,43 @@ IrrDriver::IrrDriver()
m_gui_env = m_device->getGUIEnvironment();
const std::string &font = file_manager->getFontFile("DomesticManners.xml");
m_race_font = m_gui_env->getFont(font.c_str());
} // IrrDriver
}
// ----------------------------------------------------------------------------
IrrDriver::~IrrDriver()
void IrrDriver::changeResolution()
{
// startScreen -> removeTextures();
attachment_manager -> removeTextures();
projectile_manager -> removeTextures();
item_manager -> removeTextures();
kart_properties_manager -> removeTextures();
powerup_manager -> removeTextures();
GUIEngine::free();
m_device->closeDevice();
m_device->drop();
} // ~IrrDriver
initDevice();
material_manager->reInit();
powerup_manager -> loadPowerups();
kart_properties_manager -> loadKartData();
item_manager -> loadDefaultItems();
projectile_manager -> loadData();
attachment_manager -> loadModels();
//FIXME: the font reinit funcs should be inside the font class
//Reinit fonts
delete_fonts();
init_fonts();
//void init(irr::IrrlichtDevice* device, irr::video::IVideoDriver* driver, void (*eventCallback)(Widget* widget, std::string& name) );
//void free();
StateManager::initGUI();
//GUIEngine::init();
GUIEngine::reshowCurrentScreen();
// startScreen -> installMaterial();
}
// ----------------------------------------------------------------------------
/** Loads an animated mesh and returns a pointer to it.
* \param filename File to load.

View File

@ -43,6 +43,8 @@ private:
public:
IrrDriver();
~IrrDriver();
void initDevice();
IrrlichtDevice *getDevice() const { return m_device; }
scene::ISceneManager *getSceneManager() const { return m_scene_manager; }
scene::IAnimatedMesh *getAnimatedMesh(const std::string &name);
@ -71,6 +73,8 @@ public:
scene::ICameraSceneNode
*addCamera();
void update(float dt);
void changeResolution();
}; // IrrDriver
extern IrrDriver *irr_driver;

View File

@ -11,14 +11,16 @@
namespace GUIEngine
{
IGUIEnvironment* g_env;
IGUISkin* g_skin;
IGUISkin* g_skin = NULL;
IGUIFont* g_font;
IrrlichtDevice* g_device;
irr::video::IVideoDriver* g_driver;
std::vector<Screen*> g_loaded_screens;
ptr_vector<Screen, HOLD> g_loaded_screens;
Screen* g_current_screen = NULL;
ITexture* bg_image = NULL;
float dt = 0;
float getLatestDt()
@ -64,9 +66,9 @@ void switchToScreen(const char* screen_name)
const int screen_amount = g_loaded_screens.size();
for(int n=0; n<screen_amount; n++)
{
if((*g_loaded_screens[n]) == screen_name)
if(g_loaded_screens[n].getName() == screen_name)
{
g_current_screen = g_loaded_screens[n];
g_current_screen = g_loaded_screens.get(n);
break;
}
}
@ -82,12 +84,31 @@ void switchToScreen(const char* screen_name)
g_current_screen->addWidgets();
}
// -----------------------------------------------------------------------------
/** to be called after e.g. a resolution switch */
void reshowCurrentScreen()
{
StateManager::reshowTopMostMenu();
//g_current_screen->addWidgets();
}
// -----------------------------------------------------------------------------
Screen* getCurrentScreen()
{
assert(g_current_screen != NULL);
return g_current_screen;
}
// -----------------------------------------------------------------------------
void free()
{
if(g_skin != NULL) delete g_skin;
g_skin = NULL;
bg_image = NULL;
g_loaded_screens.clearAndDeleteAll();
g_current_screen = NULL;
// nothing else to delete for now AFAIK, irrlicht will automatically kill everything along the device
}
// -----------------------------------------------------------------------------
void (*g_event_callback)(Widget* widget, std::string& name);
void init(IrrlichtDevice* device_a, IVideoDriver* driver_a, void (*eventCallback)(Widget* widget, std::string& name) )
{
@ -124,9 +145,6 @@ void render(float elapsed_time)
// on one end, making these static is not too clean.
// on another end, these variables are really only used locally,
// and making them static avoids doing the same stupid computations every frame
// FIXME - not totally true, resolution switches need to be handled
static ITexture* bg_image = NULL;
static core::rect<s32> dest;
static core::rect<s32> source_area;

View File

@ -180,10 +180,12 @@ namespace GUIEngine
float getLatestDt();
void init(irr::IrrlichtDevice* device, irr::video::IVideoDriver* driver, void (*eventCallback)(Widget* widget, std::string& name) );
void free();
void switchToScreen(const char* );
void clear();
Screen* getCurrentScreen();
void reshowCurrentScreen();
void render(float dt);
void transmitEvent(Widget* widget, std::string& name);

View File

@ -310,23 +310,23 @@ namespace StateManager
if(!resolutions_inited)
{
res->addItem("1280x1024","1280x1024","gui/screen54.png");
res->addItem("800x600","800x600","gui/screen43.png");
res->addItem("1024x768","1024x768","gui/screen43.png");
res->addItem("1152x864","1152x864","gui/screen43.png");
res->addItem("1280x960","1280x960","gui/screen43.png");
res->addItem("1400x1050","1400x1050","gui/screen43.png");
res->addItem("1280x800","1280x800","gui/screen1610.png");
res->addItem("1440x900","1440x900","gui/screen1610.png");
res->addItem("1680x1050","1680x1050","gui/screen1610.png");
res->addItem("1920x1200","1920x1200","gui/screen1610.png");
res->addItem("1280x768","1280x768","gui/screen53.png");
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
resolutions_inited = true;
}
res->updateItemDisplay();
}
}
}
} // end init
// -- options
else if(name == "options_choice")
{
@ -385,7 +385,12 @@ namespace StateManager
user_config->setSFX(w->getState() ? UserConfig::UC_ENABLE : UserConfig::UC_DISABLE);
}
else if(name == "apply_resolution")
{
user_config->m_width = 800;
user_config->m_height = 480;
irr_driver->changeResolution();
}
}
/**
@ -516,6 +521,12 @@ namespace StateManager
eventCallback(NULL, g_init_event);
}
void reshowTopMostMenu()
{
GUIEngine::switchToScreen( g_menu_stack[g_menu_stack.size()-1].c_str() );
eventCallback(NULL, g_init_event);
}
void popMenu()
{
g_menu_stack.pop_back();

View File

@ -13,6 +13,7 @@ namespace StateManager
void resetAndGoToMenu(std::string name);
void enterGameState();
bool isGameState();
void reshowTopMostMenu();
void escapePressed();
}

View File

@ -839,8 +839,11 @@ void RibbonGridWidget::add()
// add rows
for(int n=0; n<row_amount; n++)
{
RibbonWidget* ribbon = new RibbonWidget(RIBBON_TOOLBAR);
// RibbonWidget* ribbon = new RibbonWidget(RIBBON_COMBO);
RibbonWidget* ribbon;
if(m_max_rows == 1) // cheap way to detect if it's a regular grid or a scrollable_ribbon. FIXME
ribbon = new RibbonWidget(RIBBON_COMBO);
else
ribbon = new RibbonWidget(RIBBON_TOOLBAR);
ribbon->x = x;
ribbon->y = y + (int)(n*row_height);
ribbon->w = w;