Commit c90a2c19 authored by hybrid's avatar hybrid

Use new strtoul10 method where appropriate.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3676 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 5d3424f5
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
ProjectType="Visual C++" ProjectType="Visual C++"
Version="9.00" Version="9.00"
Name="22.MaterialViewer_vc9" Name="22.MaterialViewer_vc9"
ProjectGUID="{4E6C2F8D-BA92-4C5B-96FD-72D4FE8BD7FA}" ProjectGUID="{F4C8112D-57A8-4D01-BB62-BAC6A09A6902}"
RootNamespace="MaterialViewer_vc9" RootNamespace="MaterialViewer_vc9"
TargetFrameworkVersion="131072" TargetFrameworkVersion="131072"
> >
......
...@@ -227,41 +227,37 @@ protected: ...@@ -227,41 +227,37 @@ protected:
{ {
video::SColor col; video::SColor col;
u32 alpha=col.getAlpha(); if (EditAlpha)
if ( EditAlpha )
{ {
alpha = (u32)core::strtol10( core::stringc( EditAlpha->getText() ).c_str(), 0); u32 alpha = core::strtoul10(core::stringc(EditAlpha->getText()).c_str());
if ( alpha > 255 ) if (alpha > 255)
alpha = 255; alpha = 255;
}
col.setAlpha(alpha); col.setAlpha(alpha);
}
u32 red=col.getRed(); if (EditRed)
if ( EditRed )
{ {
red = (u32)core::strtol10( core::stringc( EditRed->getText() ).c_str(), 0); u32 red = core::strtoul10(core::stringc(EditRed->getText()).c_str());
if ( red > 255 ) if (red > 255)
red = 255; red = 255;
}
col.setRed(red); col.setRed(red);
}
u32 green=col.getGreen(); if (EditGreen)
if ( EditGreen )
{ {
green = (u32)core::strtol10( core::stringc( EditGreen->getText() ).c_str(), 0); u32 green = core::strtoul10(core::stringc(EditGreen->getText()).c_str());
if ( green > 255 ) if (green > 255)
green = 255; green = 255;
}
col.setGreen(green); col.setGreen(green);
}
u32 blue=col.getBlue(); if (EditBlue)
if ( EditBlue )
{ {
blue = (u32)core::strtol10( core::stringc( EditBlue->getText() ).c_str(), 0); u32 blue = core::strtoul10(core::stringc(EditBlue->getText()).c_str());
if ( blue > 255 ) if (blue > 255)
blue = 255; blue = 255;
}
col.setBlue(blue); col.setBlue(blue);
}
return col; return col;
} }
......
...@@ -41,24 +41,22 @@ public: ...@@ -41,24 +41,22 @@ public:
// Irrlicht null device, we want to load settings before we actually created our device, therefore, nulldevice // Irrlicht null device, we want to load settings before we actually created our device, therefore, nulldevice
NullDevice = irr::createDevice(irr::video::EDT_NULL); NullDevice = irr::createDevice(irr::video::EDT_NULL);
//DriverOptions is an irrlicht map, //DriverOptions is an irrlicht map,
//we can insert values in the map in two ways by calling insert(key,value) or by using the [key] operator //we can insert values in the map in two ways by calling insert(key,value) or by using the [key] operator
//the [] operator overrides values if they already exist //the [] operator overrides values if they already exist
DriverOptions.insert(L"Software", EDT_SOFTWARE ); DriverOptions.insert(L"Software", EDT_SOFTWARE);
DriverOptions.insert(L"OpenGL", EDT_OPENGL ); DriverOptions.insert(L"OpenGL", EDT_OPENGL);
DriverOptions.insert(L"Direct3D9", EDT_DIRECT3D9 ); DriverOptions.insert(L"Direct3D9", EDT_DIRECT3D9);
//some resolution options //some resolution options
ResolutionOptions.insert(L"640x480", dimension2du(640,480) ); ResolutionOptions.insert(L"640x480", dimension2du(640,480));
ResolutionOptions.insert(L"800x600", dimension2du(800,600) ); ResolutionOptions.insert(L"800x600", dimension2du(800,600));
ResolutionOptions.insert(L"1024x768", dimension2du(1024,768) ); ResolutionOptions.insert(L"1024x768", dimension2du(1024,768));
//our preferred defaults //our preferred defaults
SettingMap.insert(L"driver", L"Direct3D9"); //0 is software SettingMap.insert(L"driver", L"Direct3D9");
SettingMap.insert(L"resolution", L"640x480"); //0 is 640x480 SettingMap.insert(L"resolution", L"640x480");
SettingMap.insert(L"fullscreen", L"0"); //0 is false SettingMap.insert(L"fullscreen", L"0"); //0 is false
} }
/** /**
...@@ -67,7 +65,7 @@ public: ...@@ -67,7 +65,7 @@ public:
*/ */
~SettingManager() ~SettingManager()
{ {
if(NullDevice) if (NullDevice)
{ {
NullDevice->closeDevice(); NullDevice->closeDevice();
NullDevice->drop(); NullDevice->drop();
...@@ -91,11 +89,11 @@ public: ...@@ -91,11 +89,11 @@ public:
bool load() bool load()
{ {
//if not able to create device dont attempt to load //if not able to create device dont attempt to load
if(!NullDevice) if (!NullDevice)
return false; return false;
irr::io::IXMLReader* xml = NullDevice->getFileSystem()->createXMLReader(SettingsFile); //create xml reader irr::io::IXMLReader* xml = NullDevice->getFileSystem()->createXMLReader(SettingsFile); //create xml reader
if ( !xml ) if (!xml)
return false; return false;
const stringw settingTag(L"setting"); //we'll be looking for this tag in the xml const stringw settingTag(L"setting"); //we'll be looking for this tag in the xml
...@@ -103,16 +101,16 @@ public: ...@@ -103,16 +101,16 @@ public:
const stringw videoTag(L"video"); //constant for videotag const stringw videoTag(L"video"); //constant for videotag
//while there is more to read //while there is more to read
while(xml->read()) while (xml->read())
{ {
//check the node type //check the node type
switch(xml->getNodeType()) switch (xml->getNodeType())
{ {
//we found a new element //we found a new element
case irr::io::EXN_ELEMENT: case irr::io::EXN_ELEMENT:
{ {
//we currently are in the empty or mygame section and find the video tag so we set our current section to video //we currently are in the empty or mygame section and find the video tag so we set our current section to video
if(currentSection.empty() && videoTag.equals_ignore_case(xml->getNodeName())) if (currentSection.empty() && videoTag.equals_ignore_case(xml->getNodeName()))
{ {
currentSection = videoTag; currentSection = videoTag;
} }
...@@ -122,19 +120,18 @@ public: ...@@ -122,19 +120,18 @@ public:
//read in the key //read in the key
stringw key = xml->getAttributeValueSafe(L"name"); stringw key = xml->getAttributeValueSafe(L"name");
//if there actually is a key to set //if there actually is a key to set
if( !key.empty()) if (!key.empty())
{ {
//set the setting in the map to the value, //set the setting in the map to the value,
//the [] operator overrides values if they already exist or inserts a new key value //the [] operator overrides values if they already exist or inserts a new key value
//pair into the settings map if it was not defined yet //pair into the settings map if it was not defined yet
SettingMap[ key ] = xml->getAttributeValueSafe(L"value"); SettingMap[key] = xml->getAttributeValueSafe(L"value");
} }
} }
//.. //..
// You can add your own sections and tags to read in here // You can add your own sections and tags to read in here
//.. //..
} }
break; break;
...@@ -160,12 +157,12 @@ public: ...@@ -160,12 +157,12 @@ public:
{ {
//if not able to create device don't attempt to save //if not able to create device don't attempt to save
if(!NullDevice) if (!NullDevice)
return false; return false;
//create xml writer //create xml writer
irr::io::IXMLWriter* xwriter = NullDevice->getFileSystem()->createXMLWriter( SettingsFile ); irr::io::IXMLWriter* xwriter = NullDevice->getFileSystem()->createXMLWriter( SettingsFile );
if(!xwriter) if (!xwriter)
return false; return false;
//write out the obligatory xml header. Each xml-file needs to have exactly one of those. //write out the obligatory xml header. Each xml-file needs to have exactly one of those.
...@@ -227,8 +224,8 @@ public: ...@@ -227,8 +224,8 @@ public:
/** /**
* Get setting as string * Get setting as string
* @param key name of setting * @param key Name of setting
* @return empty string if the settings is not found, else value of the setting * @return Empty string if the settings is not found, else value of the setting
*/ */
stringw getSetting(const stringw& key) const stringw getSetting(const stringw& key) const
{ {
...@@ -240,18 +237,17 @@ public: ...@@ -240,18 +237,17 @@ public:
return n->getValue(); return n->getValue();
else else
return L""; return L"";
} }
/** /**
* Get setting as bool * Get setting as bool
* @param key name of setting * @param key Name of setting
* @return false if the key cannot be found, else true if the setting == 1 * @return False if the key cannot be found, else true if the setting == 1
*/ */
bool getSettingAsBoolean(const stringw& key ) const bool getSettingAsBoolean(const stringw& key ) const
{ {
stringw s = getSetting(key); stringw s = getSetting(key);
if(s.empty()) if (s.empty())
return false; return false;
return s.equals_ignore_case(L"1"); return s.equals_ignore_case(L"1");
} }
...@@ -261,23 +257,20 @@ public: ...@@ -261,23 +257,20 @@ public:
* @param key name of setting * @param key name of setting
* @return 0 if the key cannot be found, else the setting converted to an integer * @return 0 if the key cannot be found, else the setting converted to an integer
*/ */
s32 getSettingAsInteger(const stringw& key ) const s32 getSettingAsInteger(const stringw& key) const
{ {
//we implicitly cast to string instead of stringw because strtol10 does not accept wide strings //we implicitly cast to string instead of stringw because strtol10 does not accept wide strings
stringc s = getSetting(key); const stringc s = getSetting(key);
if(s.empty()) if (s.empty())
return 0; return 0;
return strtol10(s.c_str()); return strtol10(s.c_str());
} }
public: public:
map<stringw, s32> DriverOptions; //available options for driver config map<stringw, s32> DriverOptions; //available options for driver config
map<stringw, dimension2du> ResolutionOptions; //available options for resolution config map<stringw, dimension2du> ResolutionOptions; //available options for resolution config
private: private:
SettingManager(const SettingManager& other); // defined but not implemented SettingManager(const SettingManager& other); // defined but not implemented
SettingManager& operator=(const SettingManager& other); // defined but not implemented SettingManager& operator=(const SettingManager& other); // defined but not implemented
...@@ -285,7 +278,6 @@ private: ...@@ -285,7 +278,6 @@ private:
stringw SettingsFile; // location of the xml, usually the stringw SettingsFile; // location of the xml, usually the
irr::IrrlichtDevice* NullDevice; irr::IrrlichtDevice* NullDevice;
}; };
/** /**
...@@ -302,17 +294,17 @@ struct SAppContext ...@@ -302,17 +294,17 @@ struct SAppContext
~SAppContext() ~SAppContext()
{ {
if(Settings) if (Settings)
delete Settings; delete Settings;
if(Device) if (Device)
{ {
Device->closeDevice(); Device->closeDevice();
Device->drop(); Device->drop();
} }
} }
IrrlichtDevice * Device; IrrlichtDevice* Device;
IGUIEnvironment* Gui; IGUIEnvironment* Gui;
IVideoDriver* Driver; IVideoDriver* Driver;
SettingManager* Settings; SettingManager* Settings;
...@@ -347,23 +339,23 @@ public: ...@@ -347,23 +339,23 @@ public:
if ( event.GUIEvent.Caller == App.ButtonSave ) if ( event.GUIEvent.Caller == App.ButtonSave )
{ {
//if there is a selection write it //if there is a selection write it
if( App.ListboxDriver->getSelected() != -1) if ( App.ListboxDriver->getSelected() != -1)
App.Settings->setSetting(L"driver", App.ListboxDriver->getListItem(App.ListboxDriver->getSelected())); App.Settings->setSetting(L"driver", App.ListboxDriver->getListItem(App.ListboxDriver->getSelected()));
//if there is a selection write it //if there is a selection write it
if( App.ListboxResolution->getSelected() != -1) if ( App.ListboxResolution->getSelected() != -1)
App.Settings->setSetting(L"resolution", App.ListboxResolution->getListItem(App.ListboxResolution->getSelected())); App.Settings->setSetting(L"resolution", App.ListboxResolution->getListItem(App.ListboxResolution->getSelected()));
App.Settings->setSetting(L"fullscreen", App.CheckboxFullscreen->isChecked()); App.Settings->setSetting(L"fullscreen", App.CheckboxFullscreen->isChecked());
if(App.Settings->save()) if (App.Settings->save())
{ {
App.Gui->addMessageBox(L"settings save",L"settings saved, please restart for settings to change effect","",true); App.Gui->addMessageBox(L"settings save",L"settings saved, please restart for settings to change effect","",true);
} }
} }
// cancel/exit button clicked, tell the application to exit // cancel/exit button clicked, tell the application to exit
else if( event.GUIEvent.Caller == App.ButtonExit) else if ( event.GUIEvent.Caller == App.ButtonExit)
{ {
App.ShouldQuit = true; App.ShouldQuit = true;
} }
...@@ -423,16 +415,20 @@ void createSettingsDialog(SAppContext& app) ...@@ -423,16 +415,20 @@ void createSettingsDialog(SAppContext& app)
app.ListboxResolution->setSelected(app.Settings->getSetting("resolution").c_str()); app.ListboxResolution->setSelected(app.Settings->getSetting("resolution").c_str());
//add checkbox to toggle fullscreen, initially set to loaded setting //add checkbox to toggle fullscreen, initially set to loaded setting
app.CheckboxFullscreen = app.Gui->addCheckBox(app.Settings->getSettingAsBoolean("fullscreen"), app.CheckboxFullscreen = app.Gui->addCheckBox(
rect<s32>(10,220,220,240), app.Settings->getSettingAsBoolean("fullscreen"),
windowSettings, -1, rect<s32>(10,220,220,240), windowSettings, -1,
L"Fullscreen"); L"Fullscreen");
//last but not least add save button //last but not least add save button
app.ButtonSave = app.Gui->addButton(rect<s32>(80,250,150,270), windowSettings, 2, L"Save video settings"); app.ButtonSave = app.Gui->addButton(
rect<s32>(80,250,150,270), windowSettings, 2,
L"Save video settings");
//exit/cancel button //exit/cancel button
app.ButtonExit = app.Gui->addButton(rect<s32>(160,250,240,270), windowSettings, 2, L"Cancel and exit"); app.ButtonExit = app.Gui->addButton(
rect<s32>(160,250,240,270), windowSettings, 2,
L"Cancel and exit");
} }
int main() int main()
...@@ -451,7 +447,7 @@ int main() ...@@ -451,7 +447,7 @@ int main()
* the only logical place to store config data for games. For all other operating systems I redirect to your manuals * the only logical place to store config data for games. For all other operating systems I redirect to your manuals
*/ */
app.Settings = new SettingManager("../../media/settings.xml"); app.Settings = new SettingManager("../../media/settings.xml");
if( !app.Settings->load() ) if ( !app.Settings->load() )
{ {
// ... // ...
// Here add your own exception handling, for now we continue because there are defaults set in SettingManager constructor // Here add your own exception handling, for now we continue because there are defaults set in SettingManager constructor
...@@ -467,9 +463,9 @@ int main() ...@@ -467,9 +463,9 @@ int main()
//see DriverOptions in the settingmanager class for details //see DriverOptions in the settingmanager class for details
map<stringw, s32>::Node* driver = app.Settings->DriverOptions.find( app.Settings->getSetting("driver") ); map<stringw, s32>::Node* driver = app.Settings->DriverOptions.find( app.Settings->getSetting("driver") );
if(driver) if (driver)
{ {
if( irr::IrrlichtDevice::isDriverSupported( static_cast<E_DRIVER_TYPE>( driver->getValue() ))) if ( irr::IrrlichtDevice::isDriverSupported( static_cast<E_DRIVER_TYPE>( driver->getValue() )))
{ {
// selected driver is supported, so we use it. // selected driver is supported, so we use it.
param.DriverType = static_cast<E_DRIVER_TYPE>( driver->getValue()); param.DriverType = static_cast<E_DRIVER_TYPE>( driver->getValue());
...@@ -478,7 +474,7 @@ int main() ...@@ -478,7 +474,7 @@ int main()
//map resolution setting to dimension in a similar way as demonstrated above //map resolution setting to dimension in a similar way as demonstrated above
map<stringw, dimension2du>::Node* res = app.Settings->ResolutionOptions.find( app.Settings->getSetting("resolution") ); map<stringw, dimension2du>::Node* res = app.Settings->ResolutionOptions.find( app.Settings->getSetting("resolution") );
if(res) if (res)
{ {
param.WindowSize = res->getValue(); param.WindowSize = res->getValue();
} }
...@@ -506,9 +502,9 @@ int main() ...@@ -506,9 +502,9 @@ int main()
app.Device->setEventReceiver(&receiver); app.Device->setEventReceiver(&receiver);
//enter main loop //enter main loop
while(!app.ShouldQuit && app.Device->run()) while (!app.ShouldQuit && app.Device->run())
{ {
if(app.Device->isWindowActive()) if (app.Device->isWindowActive())
{ {
app.Driver->beginScene(true, true, SColor(0,200,200,200)); app.Driver->beginScene(true, true, SColor(0,200,200,200));
app.Gui->drawAll(); app.Gui->drawAll();
...@@ -521,3 +517,4 @@ int main() ...@@ -521,3 +517,4 @@ int main()
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment