Index: src/CEImagesetEditor.cpp =================================================================== --- src/CEImagesetEditor.cpp (revision 1450) +++ src/CEImagesetEditor.cpp (working copy) @@ -34,6 +34,7 @@ #include "EditorView.h" #include "CEGUIHelper.h" #include "DialogAbout.h" +#include "Options.h" using namespace CEGUI; @@ -60,6 +61,10 @@ // Log some platform info wxLogDebug( wxT( "Default Gui font: %s, %d" ), wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ).GetFaceName().c_str(), wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ).GetPointSize() ); + // Pre-load the ini file + COptions::GetInstancePtr(); + + // Create a document manager m_docManager = new wxDocManager; @@ -74,9 +79,12 @@ try { + int backgroundColorRed, backgroundColorGreen, backgroundColorBlue; + COptions::GetInstancePtr()->GetBackGroundColor(backgroundColorRed,backgroundColorGreen,backgroundColorBlue); // Create Single-Document main frame, just look default position and dimensions - GlobalFrame = new EditorFrame( m_docManager, 0, wxID_ANY, wxT( "CEImagesetEditor" ), wxDefaultPosition, wxSize( 800, 600 ), wxDEFAULT_FRAME_STYLE ); + GlobalFrame = new EditorFrame( m_docManager, 0, wxID_ANY, wxT( "CEImagesetEditor" ), wxDefaultPosition, wxSize( 800, 600 ), wxDEFAULT_FRAME_STYLE, + backgroundColorRed, backgroundColorGreen,backgroundColorBlue); // Prepare for the rendering canvas // We need to show the frame otherwise the CEGUI opengl renderer won't @@ -85,6 +93,9 @@ GlobalFrame->Show( true ); // This needs to be in the try-block! GlobalFrame->AttachCanvas( 0 ); + + GlobalFrame->LoadConfigFromIniFile(); + SetTopWindow( GlobalFrame ); return true; @@ -103,7 +114,7 @@ { // Cleanup delete m_docManager; - //delete COptions::GetInstancePtr(); + delete COptions::GetInstancePtr(); return 0; } Index: src/DialogResourceGroups.cpp =================================================================== --- src/DialogResourceGroups.cpp (revision 1450) +++ src/DialogResourceGroups.cpp (working copy) @@ -20,6 +20,7 @@ #include "DialogResourceGroups.h" #include "wxPathCellEditor.h" #include "CEGUIHelper.h" +#include "Options.h" #include #include @@ -54,6 +55,33 @@ CreateControls(); + // load and set group config from ini file + + //CEGUI::DefaultResourceProvider* rp = + // static_cast( + // CEGUI::System::getSingleton().getResourceProvider() ); + + for (int i=0;igetResourceGroup(i,groupName,groupDir); + if (!groupName.IsEmpty()) + { + addGroupEntry( groupName, groupDir ); + //rp->setResourceGroupDirectory( + // CEGUIHelper::ToCEGUIString( groupName ), + // CEGUIHelper::ToCEGUIString( groupDir ) ); + } + } + wxString defaultgroupName; + COptions::GetInstancePtr()->getDefaultResourceGroup(defaultgroupName); + if (!defaultgroupName.IsEmpty()) + { + setDefaultGroup(defaultgroupName); + //rp->setDefaultResourceGroup( + // CEGUIHelper::ToCEGUIString( defaultgroupName ) ); + } + return true; } @@ -254,7 +282,6 @@ rp->setResourceGroupDirectory( CEGUIHelper::ToCEGUIString( iter->first ), CEGUIHelper::ToCEGUIString( iter->second ) ); - ++iter; } @@ -266,6 +293,22 @@ m_backupResourceGroups.clear(); m_backupDefaultGroupName.clear(); + // save the data in the ini file + COptions::GetInstancePtr()->setDefaultResourceGroup(m_defaultGroupName); + iter = m_resourceGroups.begin(); + for (int groupid=0;groupidsetResourceGroup(groupid,iter->first,iter->second); + ++iter; + } + else + { + COptions::GetInstancePtr()->setResourceGroup(groupid,"",""); + } + } + event.Skip(); } Index: src/EditorFrame.cpp =================================================================== --- src/EditorFrame.cpp (revision 1450) +++ src/EditorFrame.cpp (working copy) @@ -28,8 +28,23 @@ #include "EditorFrame.h" #include "EditorGLCanvas.h" #include "DialogResourceGroups.h" + +// CEGUI includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + // Utility class for convertion between CEGUI- and wxWidgets types #include "CEGUIHelper.h" +#include "Options.h" // Toolbar icons #include "bitmaps/new.xpm" @@ -59,13 +74,13 @@ //----------------------------------------------------------------------- EditorFrame::EditorFrame( wxDocManager* manager, wxFrame* frame, wxWindowID id, const wxString& title, - const wxPoint& pos, const wxSize& size, const long type ) : + const wxPoint& pos, const wxSize& size, const long type, int backgroundColorR, int backgroundColorG, int backgroundColorB ) : wxDocParentFrame( manager, frame, id, title, pos, size, type ), m_document( 0 ), m_propsPanel( 0 ), m_glcanvasImageset( 0 ), m_resGrpsEditor( 0 ), - m_backgroundColour( 255, 170, 200 ) + m_backgroundColour( backgroundColorR, backgroundColorG, backgroundColorB ) { // Add a menu bar, a toolbar and a statusbar AttachMenubar(); @@ -86,6 +101,33 @@ } //----------------------------------------------------------------------- +void EditorFrame::LoadConfigFromIniFile() +{ + DefaultResourceProvider* rp = + static_cast( + CEGUI::System::getSingleton().getResourceProvider() ); + + for (int i=0;igetResourceGroup(i,groupName,groupDir); + if (!groupName.IsEmpty()) + { + rp->setResourceGroupDirectory( + CEGUIHelper::ToCEGUIString( groupName ), + CEGUIHelper::ToCEGUIString( groupDir ) ); + } + } + wxString defaultgroupName; + COptions::GetInstancePtr()->getDefaultResourceGroup(defaultgroupName); + if (!defaultgroupName.IsEmpty()) + { + rp->setDefaultResourceGroup( + CEGUIHelper::ToCEGUIString( defaultgroupName ) ); + } +} + +//----------------------------------------------------------------------- void EditorFrame::AttachMenubar() { wxMenuBar * menu_bar = new wxMenuBar; @@ -185,6 +227,12 @@ // set the colour on the canvas m_glcanvasImageset->setBackgroundColour( m_backgroundColour ); + + // save the new color in the ini file + COptions::GetInstancePtr()->SetBackGroundColor( + m_backgroundColour.Red(), + m_backgroundColour.Green(), + m_backgroundColour.Blue()); } } Index: src/EditorFrame.h =================================================================== --- src/EditorFrame.h (revision 1450) +++ src/EditorFrame.h (working copy) @@ -45,7 +45,7 @@ DECLARE_CLASS( EditorFrame ) public: /** Constructor. Attaches an OpenGL compatible canvas.*/ - EditorFrame( wxDocManager* manager, wxFrame* frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type ); + EditorFrame( wxDocManager* manager, wxFrame* frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type,int backgroundColorR, int backgroundColorG, int backgroundColorB ); /** Destructor.*/ ~EditorFrame(); @@ -69,6 +69,8 @@ return m_propsPanel; } + void LoadConfigFromIniFile(); + /** We listen to the Edit events (including the Align part) of the menubar.*/ DECLARE_EVENT_TABLE() Index: src/EditorGLCanvas.cpp =================================================================== --- src/EditorGLCanvas.cpp (revision 1450) +++ src/EditorGLCanvas.cpp (working copy) @@ -232,6 +232,8 @@ //----------------------------------------------------------------------- void EditorGLCanvas::initialiseCEGUI() { + CEGUI::OpenGLRenderer::setDefaultImageCodecName("SILLYImageCodec"); + // Initialise OpenGL renderer and the CEGUI system m_GUIRenderer = new OpenGLRenderer( 0 ); m_GUISystem = new System( m_GUIRenderer ); Index: src/iniFile.cpp =================================================================== --- src/iniFile.cpp (revision 0) +++ src/iniFile.cpp (revision 0) @@ -0,0 +1,487 @@ +// IniFile.cpp: Implementation of the CIniFile class. +// Written by: Adam Clauss +// Email: cabadam@houston.rr.com +// You may use this class/code as you wish in your programs. Feel free to distribute it, and +// email suggested changes to me. +// +// Rewritten by: Shane Hill +// Date: 21/08/2001 +// Email: Shane.Hill@dsto.defence.gov.au +// Reason: Remove dependancy on MFC. Code should compile on any +// platform. +////////////////////////////////////////////////////////////////////// + +// C++ Includes +#include +#include +#include + +using namespace std; + +// C Includes +#include +#include +#include + +// Local Includes +#include "iniFile.h" + +#if defined(WIN32) +#define iniEOL endl +#else +#define iniEOL '\r' << endl +#endif + +CIniFile::CIniFile( string const iniPath) +{ + Path( iniPath); + caseInsensitive = true; +} + +bool CIniFile::ReadFile() +{ + // Normally you would use ifstream, but the SGI CC compiler has + // a few bugs with ifstream. So ... fstream used. + fstream f; + string line; + string keyname, valuename, value; + string::size_type pLeft, pRight; + + f.open( path.c_str(), ios::in); + if ( f.fail()) + return false; + + while( getline( f, line)) { + if ( line.length()) { + // To be compatible with Win32, check for existence of '\r'. + // Win32 files have the '\r' and Unix files don't at the end of a line. + // Note that the '\r' will be written to INI files from + // Unix so that the created INI file can be read under Win32 + // without change. + if ( line[line.length() - 1] == '\r') + line = line.substr( 0, line.length() - 1); + + // Check that the user hasn't openned a binary file by checking the first + // character of each line! + if (line.length() != 0 && !isprint( line[0])) { + printf( "Failing on char %d\n", line[0]); + f.close(); + return false; + } + if (( pLeft = line.find_first_of(";#[=")) != string::npos) { + switch ( line[pLeft]) { + case '[': + if ((pRight = line.find_last_of("]")) != string::npos && + pRight > pLeft) { + keyname = line.substr( pLeft + 1, pRight - pLeft - 1); + AddKeyName( keyname); + } + break; + + case '=': + valuename = line.substr( 0, pLeft); + value = line.substr( pLeft + 1); + SetValue( keyname, valuename, value); + break; + + case ';': + case '#': + if ( !names.size()) + HeaderComment( line.substr( pLeft + 1)); + else + KeyComment( keyname, line.substr( pLeft + 1)); + break; + } + } + } + } + + f.close(); + if ( names.size()) + return true; + return false; +} + +bool CIniFile::WriteFile() +{ + unsigned commentID, keyID, valueID; + // Normally you would use ofstream, but the SGI CC compiler has + // a few bugs with ofstream. So ... fstream used. + fstream f; + + f.open( path.c_str(), ios::out); + if ( f.fail()) + return false; + + // Write header comments. + for ( commentID = 0; commentID < comments.size(); ++commentID) + f << ';' << comments[commentID] << iniEOL; + if ( comments.size()) + f << iniEOL; + + // Write keys and values. + for ( keyID = 0; keyID < keys.size(); ++keyID) { + f << '[' << names[keyID] << ']' << iniEOL; + // Comments. + for ( commentID = 0; commentID < keys[keyID].comments.size(); ++commentID) + f << ';' << keys[keyID].comments[commentID] << iniEOL; + // Values. + for ( valueID = 0; valueID < keys[keyID].names.size(); ++valueID) + f << keys[keyID].names[valueID] << '=' << keys[keyID].values[valueID] << iniEOL; + f << iniEOL; + } + f.close(); + + return true; +} + +long CIniFile::FindKey( string const keyname) const +{ + for ( unsigned keyID = 0; keyID < names.size(); ++keyID) + if ( CheckCase( names[keyID]) == CheckCase( keyname)) + return long(keyID); + return noID; +} + +long CIniFile::FindValue( unsigned const keyID, string const valuename) const +{ + if ( !keys.size() || keyID >= keys.size()) + return noID; + + for ( unsigned valueID = 0; valueID < keys[keyID].names.size(); ++valueID) + if ( CheckCase( keys[keyID].names[valueID]) == CheckCase( valuename)) + return long(valueID); + return noID; +} + +unsigned CIniFile::AddKeyName( string const keyname) +{ + names.resize( names.size() + 1, keyname); + keys.resize( keys.size() + 1); + return names.size() - 1; +} + +string CIniFile::KeyName( unsigned const keyID) const +{ + if ( keyID < names.size()) + return names[keyID]; + else + return ""; +} + +unsigned CIniFile::NumValues( unsigned const keyID) +{ + if ( keyID < keys.size()) + return keys[keyID].names.size(); + return 0; +} + +unsigned CIniFile::NumValues( string const keyname) +{ + long keyID = FindKey( keyname); + if ( keyID == noID) + return 0; + return keys[keyID].names.size(); +} + +string CIniFile::ValueName( unsigned const keyID, unsigned const valueID) const +{ + if ( keyID < keys.size() && valueID < keys[keyID].names.size()) + return keys[keyID].names[valueID]; + return ""; +} + +string CIniFile::ValueName( string const keyname, unsigned const valueID) const +{ + long keyID = FindKey( keyname); + if ( keyID == noID) + return ""; + return ValueName( keyID, valueID); +} + +bool CIniFile::SetValue( unsigned const keyID, unsigned const valueID, string const value) +{ + if ( keyID < keys.size() && valueID < keys[keyID].names.size()) + keys[keyID].values[valueID] = value; + + return false; +} + +bool CIniFile::SetValue( string const keyname, string const valuename, string const value, bool const create) +{ + long keyID = FindKey( keyname); + if ( keyID == noID) { + if ( create) + keyID = long( AddKeyName( keyname)); + else + return false; + } + + long valueID = FindValue( unsigned(keyID), valuename); + if ( valueID == noID) { + if ( !create) + return false; + keys[keyID].names.resize( keys[keyID].names.size() + 1, valuename); + keys[keyID].values.resize( keys[keyID].values.size() + 1, value); + } else + keys[keyID].values[valueID] = value; + + return true; +} + +bool CIniFile::SetValueI( string const keyname, string const valuename, int const value, bool const create) +{ + char svalue[MAX_VALUEDATA]; + + sprintf( svalue, "%d", value); + return SetValue( keyname, valuename, svalue); +} + +bool CIniFile::SetValueF( string const keyname, string const valuename, double const value, bool const create) +{ + char svalue[MAX_VALUEDATA]; + + sprintf( svalue, "%f", value); + return SetValue( keyname, valuename, svalue); +} + +bool CIniFile::SetValueV( string const keyname, string const valuename, char *format, ...) +{ + va_list args; + char value[MAX_VALUEDATA]; + + va_start( args, format); + vsprintf( value, format, args); + va_end( args); + return SetValue( keyname, valuename, value); +} + +string CIniFile::GetValue( unsigned const keyID, unsigned const valueID, string const defValue) const +{ + if ( keyID < keys.size() && valueID < keys[keyID].names.size()) + return keys[keyID].values[valueID]; + return defValue; +} + +string CIniFile::GetValue( string const keyname, string const valuename, string const defValue) const +{ + long keyID = FindKey( keyname); + if ( keyID == noID) + return defValue; + + long valueID = FindValue( unsigned(keyID), valuename); + if ( valueID == noID) + return defValue; + + return keys[keyID].values[valueID]; +} + +int CIniFile::GetValueI(string const keyname, string const valuename, int const defValue) const +{ + char svalue[MAX_VALUEDATA]; + + sprintf( svalue, "%d", defValue); + return atoi( GetValue( keyname, valuename, svalue).c_str()); +} + +double CIniFile::GetValueF(string const keyname, string const valuename, double const defValue) const +{ + char svalue[MAX_VALUEDATA]; + + sprintf( svalue, "%f", defValue); + return atof( GetValue( keyname, valuename, svalue).c_str()); +} + +// 16 variables may be a bit of over kill, but hey, it's only code. +unsigned CIniFile::GetValueV( string const keyname, string const valuename, char *format, + void *v1, void *v2, void *v3, void *v4, + void *v5, void *v6, void *v7, void *v8, + void *v9, void *v10, void *v11, void *v12, + void *v13, void *v14, void *v15, void *v16) +{ + string value; + // va_list args; + unsigned nVals; + + + value = GetValue( keyname, valuename); + if ( !value.length()) + return false; + // Why is there not vsscanf() function. Linux man pages say that there is + // but no compiler I've seen has it defined. Bummer! + // + // va_start( args, format); + // nVals = vsscanf( value.c_str(), format, args); + // va_end( args); + + nVals = sscanf( value.c_str(), format, + v1, v2, v3, v4, v5, v6, v7, v8, + v9, v10, v11, v12, v13, v14, v15, v16); + + return nVals; +} + +bool CIniFile::DeleteValue( string const keyname, string const valuename) +{ + long keyID = FindKey( keyname); + if ( keyID == noID) + return false; + + long valueID = FindValue( unsigned(keyID), valuename); + if ( valueID == noID) + return false; + + // This looks strange, but is neccessary. + vector::iterator npos = keys[keyID].names.begin() + valueID; + vector::iterator vpos = keys[keyID].values.begin() + valueID; + keys[keyID].names.erase( npos, npos + 1); + keys[keyID].values.erase( vpos, vpos + 1); + + return true; +} + +bool CIniFile::DeleteKey( string const keyname) +{ + long keyID = FindKey( keyname); + if ( keyID == noID) + return false; + + // Now hopefully this destroys the vector lists within keys. + // Looking at source, this should be the case using the destructor. + // If not, I may have to do it explicitly. Memory leak check should tell. + // memleak_test.cpp shows that the following not required. + //keys[keyID].names.clear(); + //keys[keyID].values.clear(); + + vector::iterator npos = names.begin() + keyID; + vector::iterator kpos = keys.begin() + keyID; + names.erase( npos, npos + 1); + keys.erase( kpos, kpos + 1); + + return true; +} + +void CIniFile::Erase() +{ + // This loop not needed. The vector<> destructor seems to do + // all the work itself. memleak_test.cpp shows this. + //for ( unsigned i = 0; i < keys.size(); ++i) { + // keys[i].names.clear(); + // keys[i].values.clear(); + //} + names.clear(); + keys.clear(); + comments.clear(); +} + +void CIniFile::HeaderComment( string const comment) +{ + comments.resize( comments.size() + 1, comment); +} + +string CIniFile::HeaderComment( unsigned const commentID) const +{ + if ( commentID < comments.size()) + return comments[commentID]; + return ""; +} + +bool CIniFile::DeleteHeaderComment( unsigned commentID) +{ + if ( commentID < comments.size()) { + vector::iterator cpos = comments.begin() + commentID; + comments.erase( cpos, cpos + 1); + return true; + } + return false; +} + +unsigned CIniFile::NumKeyComments( unsigned const keyID) const +{ + if ( keyID < keys.size()) + return keys[keyID].comments.size(); + return 0; +} + +unsigned CIniFile::NumKeyComments( string const keyname) const +{ + long keyID = FindKey( keyname); + if ( keyID == noID) + return 0; + return keys[keyID].comments.size(); +} + +bool CIniFile::KeyComment( unsigned const keyID, string const comment) +{ + if ( keyID < keys.size()) { + keys[keyID].comments.resize( keys[keyID].comments.size() + 1, comment); + return true; + } + return false; +} + +bool CIniFile::KeyComment( string const keyname, string const comment) +{ + long keyID = FindKey( keyname); + if ( keyID == noID) + return false; + return KeyComment( unsigned(keyID), comment); +} + +string CIniFile::KeyComment( unsigned const keyID, unsigned const commentID) const +{ + if ( keyID < keys.size() && commentID < keys[keyID].comments.size()) + return keys[keyID].comments[commentID]; + return ""; +} + +string CIniFile::KeyComment( string const keyname, unsigned const commentID) const +{ + long keyID = FindKey( keyname); + if ( keyID == noID) + return ""; + return KeyComment( unsigned(keyID), commentID); +} + +bool CIniFile::DeleteKeyComment( unsigned const keyID, unsigned const commentID) +{ + if ( keyID < keys.size() && commentID < keys[keyID].comments.size()) { + vector::iterator cpos = keys[keyID].comments.begin() + commentID; + keys[keyID].comments.erase( cpos, cpos + 1); + return true; + } + return false; +} + +bool CIniFile::DeleteKeyComment( string const keyname, unsigned const commentID) +{ + long keyID = FindKey( keyname); + if ( keyID == noID) + return false; + return DeleteKeyComment( unsigned(keyID), commentID); +} + +bool CIniFile::DeleteKeyComments( unsigned const keyID) +{ + if ( keyID < keys.size()) { + keys[keyID].comments.clear(); + return true; + } + return false; +} + +bool CIniFile::DeleteKeyComments( string const keyname) +{ + long keyID = FindKey( keyname); + if ( keyID == noID) + return false; + return DeleteKeyComments( unsigned(keyID)); +} + +string CIniFile::CheckCase( string s) const +{ + if ( caseInsensitive) + for ( string::size_type i = 0; i < s.length(); ++i) + s[i] = tolower(s[i]); + return s; +} Index: src/iniFile.h =================================================================== --- src/iniFile.h (revision 0) +++ src/iniFile.h (revision 0) @@ -0,0 +1,183 @@ +// IniFile.cpp: Implementation of the CIniFile class. +// Written by: Adam Clauss +// Email: cabadam@tamu.edu +// You may use this class/code as you wish in your programs. Feel free to distribute it, and +// email suggested changes to me. +// +// Rewritten by: Shane Hill +// Date: 21/08/2001 +// Email: Shane.Hill@dsto.defence.gov.au +// Reason: Remove dependancy on MFC. Code should compile on any +// platform. Tested on Windows/Linux/Irix +////////////////////////////////////////////////////////////////////// + +#ifndef CIniFile_H +#define CIniFile_H + +// C++ Includes +#include +#include + +// C Includes +#include + +#define MAX_KEYNAME 128 +#define MAX_VALUENAME 128 +#define MAX_VALUEDATA 2048 + +// Disables warning C4786: 'Some STL template class' : identifier was truncated to '255' characters in the debug information. +#pragma warning(disable:4786) + +class CIniFile +{ +private: + bool caseInsensitive; + std::string path; + struct key { + std::vector names; + std::vector values; + std::vector comments; + }; + std::vector keys; + std::vector names; + std::vector comments; + std::string CheckCase( std::string s) const; + +public: + enum errors{ noID = -1}; + CIniFile( std::string const iniPath = ""); + virtual ~CIniFile() {} + + // Sets whether or not keynames and valuenames should be case sensitive. + // The default is case insensitive. + void CaseSensitive() {caseInsensitive = false;} + void CaseInsensitive() {caseInsensitive = true;} + + // Sets path of ini file to read and write from. + void Path(std::string const newPath) {path = newPath;} + std::string Path() const {return path;} + void SetPath(std::string const newPath) {Path( newPath);} + + // Reads ini file specified using path. + // Returns true if successful, false otherwise. + bool ReadFile(); + + // Writes data stored in class to ini file. + bool WriteFile(); + + // Deletes all stored ini data. + void Erase(); + void Clear() {Erase();} + void Reset() {Erase();} + + // Returns index of specified key, or noID if not found. + long FindKey( std::string const keyname) const; + + // Returns index of specified value, in the specified key, or noID if not found. + long FindValue( unsigned const keyID, std::string const valuename) const; + + // Returns number of keys currently in the ini. + unsigned NumKeys() const {return names.size();} + unsigned GetNumKeys() const {return NumKeys();} + + // Add a key name. + unsigned AddKeyName( std::string const keyname); + + // Returns key names by index. + std::string KeyName( unsigned const keyID) const; + std::string GetKeyName( unsigned const keyID) const {return KeyName(keyID);} + + // Returns number of values stored for specified key. + unsigned NumValues( unsigned const keyID); + unsigned GetNumValues( unsigned const keyID) {return NumValues( keyID);} + unsigned NumValues( std::string const keyname); + unsigned GetNumValues( std::string const keyname) {return NumValues( keyname);} + + // Returns value name by index for a given keyname or keyID. + std::string ValueName( unsigned const keyID, unsigned const valueID) const; + std::string GetValueName( unsigned const keyID, unsigned const valueID) const { + return ValueName( keyID, valueID); + } + std::string ValueName( std::string const keyname, unsigned const valueID) const; + std::string GetValueName( std::string const keyname, unsigned const valueID) const { + return ValueName( keyname, valueID); + } + + // Gets value of [keyname] valuename =. + // Overloaded to return std::string, int, and double. + // Returns defValue if key/value not found. + std::string GetValue( unsigned const keyID, unsigned const valueID, std::string const defValue = "") const; + std::string GetValue(std::string const keyname, std::string const valuename, std::string const defValue = "") const; + int GetValueI(std::string const keyname, std::string const valuename, int const defValue = 0) const; + bool GetValueB(std::string const keyname, std::string const valuename, bool const defValue = false) const { + return GetValueI( keyname, valuename, int( defValue)) ? true : false; + } + double GetValueF(std::string const keyname, std::string const valuename, double const defValue = 0.0) const; + // This is a variable length formatted GetValue routine. All these voids + // are required because there is no vsscanf() like there is a vsprintf(). + // Only a maximum of 8 variable can be read. + unsigned GetValueV( std::string const keyname, std::string const valuename, char *format, + void *v1 = 0, void *v2 = 0, void *v3 = 0, void *v4 = 0, + void *v5 = 0, void *v6 = 0, void *v7 = 0, void *v8 = 0, + void *v9 = 0, void *v10 = 0, void *v11 = 0, void *v12 = 0, + void *v13 = 0, void *v14 = 0, void *v15 = 0, void *v16 = 0); + + // Sets value of [keyname] valuename =. + // Specify the optional paramter as false (0) if you do not want it to create + // the key if it doesn't exist. Returns true if data entered, false otherwise. + // Overloaded to accept std::string, int, and double. + bool SetValue( unsigned const keyID, unsigned const valueID, std::string const value); + bool SetValue( std::string const keyname, std::string const valuename, std::string const value, bool const create = true); + bool SetValueI( std::string const keyname, std::string const valuename, int const value, bool const create = true); + bool SetValueB( std::string const keyname, std::string const valuename, bool const value, bool const create = true) { + return SetValueI( keyname, valuename, int(value), create); + } + bool SetValueF( std::string const keyname, std::string const valuename, double const value, bool const create = true); + bool SetValueV( std::string const keyname, std::string const valuename, char *format, ...); + + // Deletes specified value. + // Returns true if value existed and deleted, false otherwise. + bool DeleteValue( std::string const keyname, std::string const valuename); + + // Deletes specified key and all values contained within. + // Returns true if key existed and deleted, false otherwise. + bool DeleteKey(std::string keyname); + + // Header comment functions. + // Header comments are those comments before the first key. + // + // Number of header comments. + unsigned NumHeaderComments() {return comments.size();} + // Add a header comment. + void HeaderComment( std::string const comment); + // Return a header comment. + std::string HeaderComment( unsigned const commentID) const; + // Delete a header comment. + bool DeleteHeaderComment( unsigned commentID); + // Delete all header comments. + void DeleteHeaderComments() {comments.clear();} + + // Key comment functions. + // Key comments are those comments within a key. Any comments + // defined within value names will be added to this list. Therefore, + // these comments will be moved to the top of the key definition when + // the CIniFile::WriteFile() is called. + // + // Number of key comments. + unsigned NumKeyComments( unsigned const keyID) const; + unsigned NumKeyComments( std::string const keyname) const; + // Add a key comment. + bool KeyComment( unsigned const keyID, std::string const comment); + bool KeyComment( std::string const keyname, std::string const comment); + // Return a key comment. + std::string KeyComment( unsigned const keyID, unsigned const commentID) const; + std::string KeyComment( std::string const keyname, unsigned const commentID) const; + // Delete a key comment. + bool DeleteKeyComment( unsigned const keyID, unsigned const commentID); + bool DeleteKeyComment( std::string const keyname, unsigned const commentID); + // Delete all comments for a key. + bool DeleteKeyComments( unsigned const keyID); + bool DeleteKeyComments( std::string const keyname); +}; + +#endif Index: src/Options.cpp =================================================================== --- src/Options.cpp (revision 0) +++ src/Options.cpp (revision 0) @@ -0,0 +1,197 @@ +/////////////////////////////////////////////////////////////////////////////// +// For project details and authors, refer to README and AUTHORS files +// +// This file is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This file is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +// To view the licence online, go to: http://www.gnu.org/copyleft/gpl.html +//////////////////////////////////////////////////////////////////////////////// + +// The portions of this code that relate to the text editing are basically +// taken from the built in wxWidgets text editor for cells: wxGridCellTextEditor. + +#include "Options.h" + +// CEGUI includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace CEGUI; + +#define BACKGROUND_COLOR_RED "BackgroundColorRed" +#define BACKGROUND_COLOR_GREEN "BackgroundColorGreen" +#define BACKGROUND_COLOR_BLUE "BackgroundColorBlue" + +#define DEFAULT_RESOURCE_GROUP "DefaultResourceGroup" + +std::string RESOURCE_GROUP_NAME[] = +{ + wxT( "ResourceGroupName1" ), + wxT( "ResourceGroupName2" ), + wxT( "ResourceGroupName3" ), + wxT( "ResourceGroupName4" ), + wxT( "ResourceGroupName5" ), + wxT( "ResourceGroupName6" ), + wxT( "ResourceGroupName7" ), + wxT( "ResourceGroupName8" ), + wxT( "ResourceGroupName9" ), + wxT( "ResourceGroupName10" ), + wxT( "ResourceGroupName11" ), + wxT( "ResourceGroupName12" ) +}; + +std::string RESOURCE_GROUP_DIR[] = +{ + wxT( "ResourceGroupDir1" ), + wxT( "ResourceGroupDir2" ), + wxT( "ResourceGroupDir3" ), + wxT( "ResourceGroupDir4" ), + wxT( "ResourceGroupDir5" ), + wxT( "ResourceGroupDir6" ), + wxT( "ResourceGroupDir7" ), + wxT( "ResourceGroupDir8" ), + wxT( "ResourceGroupDir9" ), + wxT( "ResourceGroupDir10" ), + wxT( "ResourceGroupDir11" ), + wxT( "ResourceGroupDir12" ) +}; + + + +#define INI_FILE "CEImagesetEditor.ini" +#define INI_SECTION "SETTINGS" +#define RESOURCE_GROUP_SECTION "RESOURCEGROUP" + +/** Declare the instance.*/ +COptions* COptions::m_instance = NULL; + +//----------------------------------------------------------------------- +COptions* COptions::GetInstancePtr() +{ + // Create instance, if not done yet + if (!m_instance) + { + m_instance = new COptions(); + } + return m_instance; +} + +//----------------------------------------------------------------------- +COptions::COptions() +{ + m_iniFile.Path(INI_FILE); + if (!m_iniFile.ReadFile()) + { // Warn user and set defaults to use + //wxLogWarning (wxT("The file '%s' could not be found; default settings will apply now."), wxT(INI_FILE)); + UseDefaults(); + } + else + { + UseSettings(); + } +} + +//----------------------------------------------------------------------- +COptions::~COptions() +{ // Save all current settings. + + m_iniFile.SetValueI(INI_SECTION, BACKGROUND_COLOR_RED, m_backgroundColorRed); + m_iniFile.SetValueI(INI_SECTION, BACKGROUND_COLOR_GREEN, m_backgroundColorGreen); + m_iniFile.SetValueI(INI_SECTION, BACKGROUND_COLOR_BLUE, m_backgroundColorBlue); + + for (int i=0;i +#include "iniFile.h" + +#define MAX_RESOURCE_GROUP 12 + +/** This class provides a central repository of application options & settings. The members + * are read from and written to an INI file. (Not each value can be modified at the moment). + */ +class COptions +{ +public: + /** Destructor.*/ + ~COptions(); + + /** Returns pointer to singleton (only instance).*/ + static COptions* GetInstancePtr(); + + + // ----------------------------------- + + void SetBackGroundColor(int ColorR,int ColorG,int ColorB) + { + m_backgroundColorRed = ColorR; + m_backgroundColorGreen = ColorG; + m_backgroundColorBlue = ColorB; + } + + void GetBackGroundColor(int &ColorR,int &ColorG,int &ColorB) + { + ColorR = m_backgroundColorRed; + ColorG = m_backgroundColorGreen; + ColorB = m_backgroundColorBlue; + } + + void setDefaultResourceGroup(const wxString& groupName) + { + m_defaultResourceGroup = groupName; + } + + void getDefaultResourceGroup(wxString& groupName) + { + groupName = m_defaultResourceGroup; + } + + void setResourceGroup(int groupid, const wxString& groupName,const wxString& groupDir) + { + m_ResourceGroupName[groupid] = groupName; + m_ResourceGroupDir[groupid] = groupDir; + } + + void getResourceGroup(int groupid, wxString& groupName, wxString& groupDir) + { + groupName = m_ResourceGroupName[groupid]; + groupDir = m_ResourceGroupDir[groupid]; + } + +private: + + /** The one-and-only instance of the class.*/ + static COptions *m_instance; + + /** Constructor. Singleton, that's why its private.*/ + COptions(); + + /** The handy ini file helper class.*/ + CIniFile m_iniFile; + + /** When the ini file is not found, default values are used. This + * method sets them.*/ + void UseDefaults(); + + /** When the ini file is found, the options are loaded by this method.*/ + void UseSettings(); + + // ------------------------------------------ + + int m_backgroundColorRed; + int m_backgroundColorGreen; + int m_backgroundColorBlue; + + wxString m_defaultResourceGroup; + wxString m_ResourceGroupName[MAX_RESOURCE_GROUP]; + wxString m_ResourceGroupDir[MAX_RESOURCE_GROUP]; + +}; + +#endif // _OPTIONS_H_ Index: src/PropertiesPanel.cpp =================================================================== --- src/PropertiesPanel.cpp (revision 1450) +++ src/PropertiesPanel.cpp (working copy) @@ -507,7 +507,7 @@ currFilespec.GetPath(), currFilespec.GetFullName(), wxT( "Image" ), - wxT( "tga files (*.tga)|*.tga|all files (*.*)|*.*" ) ); + wxT( "TGA files (*.tga)|*.tga|PNG files (*.png)|*.png|JPG files (*.jpg)|*.jpg|all files (*.*)|*.*" ) ); // if something was selected if ( !filename.empty() )