Main Page   Class Hierarchy   Compound List   File List   Compound Members  

gfxConfig.cpp

00001 //////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2001-2002 David Pritchard <drpritch@alumni.uwaterloo.ca>
00003 // 
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later
00008 // version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 #include <freecloth/gfx/gfxConfig.h>
00020 #include <freecloth/resmgt/resConfigRegistry.h>
00021 #include <freecloth/resmgt/rcShdPtr.h>
00022 
00023 ////////////////////////////////////////////////////////////////////////////////
00024 // LOCAL DECLARATIONS
00025 
00026 namespace {
00027     const char* WINDOW_WIDTH_NAME = "WindowWidth";
00028     const char* WINDOW_HEIGHT_NAME = "WindowHeight";
00029     const char* WINDOW_X_NAME = "WindowX";
00030     const char* WINDOW_Y_NAME = "WindowY";
00031     const char* VIDEO_MODE_WIDTH_NAME = "VideoModeWidth";
00032     const char* VIDEO_MODE_HEIGHT_NAME = "VideoModeHeight";
00033     const char* VIDEO_MODE_BITS_PER_PIXEL_NAME = "VideoModeBitsPerPixel";
00034     const char* FULLSCREEN_NAME = "Fullscreen";
00035 
00036     const GfxConfig::WindowInfo WINDOW_INFO_DEFAULT =
00037     { 320, 240, 0, 0 };
00038     const GfxConfig::VideoModeInfo VIDEO_MODE_INFO_DEFAULT =
00039     { 640, 480, 32 };
00040     bool FULLSCREEN_DEFAULT = false;
00041 };
00042 
00043 ////////////////////////////////////////////////////////////////////////////////
00044 // CLASS GfxConfig
00045 
00046 //------------------------------------------------------------------------------
00047 
00048 GfxConfig::GfxConfig()
00049   : _windowInfo( WINDOW_INFO_DEFAULT ),
00050     _videoModeInfo( VIDEO_MODE_INFO_DEFAULT ),
00051     _fullscreen( FULLSCREEN_DEFAULT )
00052 {
00053 }
00054 
00055 //------------------------------------------------------------------------------
00056 
00057 GfxConfig::GfxConfig( const GfxConfig& rhs )
00058   : _windowInfo( rhs._windowInfo ),
00059     _videoModeInfo( rhs._videoModeInfo ),
00060     _fullscreen( rhs._fullscreen )
00061 {
00062 }
00063 
00064 //------------------------------------------------------------------------------
00065 
00066 RCShdPtr<ResConfig> GfxConfig::clone() const
00067 {
00068     return RCShdPtr<ResConfig>( new GfxConfig( *this ) );
00069 }
00070 
00071 //------------------------------------------------------------------------------
00072 
00073 const GfxConfig::WindowInfo& GfxConfig::getWindowInfo() const
00074 {
00075     return _windowInfo;
00076 }
00077 
00078 //------------------------------------------------------------------------------
00079 
00080 const GfxConfig::VideoModeInfo& GfxConfig::getVideoModeInfo() const
00081 {
00082     return _videoModeInfo;
00083 }
00084 
00085 //------------------------------------------------------------------------------
00086 
00087 bool GfxConfig::getFullscreen() const
00088 {
00089     return _fullscreen;
00090 }
00091 
00092 //------------------------------------------------------------------------------
00093 
00094 void GfxConfig::setWindowInfo( const WindowInfo& value )
00095 {
00096     _windowInfo = value;
00097 }
00098 
00099 //------------------------------------------------------------------------------
00100 
00101 void GfxConfig::setVideoModeInfo( const VideoModeInfo& value )
00102 {
00103     // TODO: verify
00104     _videoModeInfo = value;
00105 }
00106 
00107 //------------------------------------------------------------------------------
00108 
00109 void GfxConfig::setFullscreen( bool value )
00110 {
00111     _fullscreen = value;
00112 }
00113 
00114 //------------------------------------------------------------------------------
00115 
00116 void GfxConfig::load( ResConfigRegistryR& reg )
00117 {
00118     WindowInfo windowInfo;
00119     VideoModeInfo videoModeInfo;
00120 
00121     windowInfo._width =
00122         reg.readUInt32( WINDOW_WIDTH_NAME, WINDOW_INFO_DEFAULT._width );
00123     windowInfo._height =
00124         reg.readUInt32( WINDOW_HEIGHT_NAME, WINDOW_INFO_DEFAULT._height );
00125     windowInfo._x =
00126         reg.readUInt32( WINDOW_X_NAME, WINDOW_INFO_DEFAULT._x );
00127     windowInfo._y =
00128         reg.readUInt32( WINDOW_Y_NAME, WINDOW_INFO_DEFAULT._y );
00129     setWindowInfo( windowInfo );
00130 
00131     videoModeInfo._width = reg.readUInt32(
00132         VIDEO_MODE_WIDTH_NAME,
00133         VIDEO_MODE_INFO_DEFAULT._width
00134     );
00135     videoModeInfo._height = reg.readUInt32(
00136         VIDEO_MODE_HEIGHT_NAME,
00137         VIDEO_MODE_INFO_DEFAULT._height
00138     );
00139     videoModeInfo._bitsPerPixel = reg.readUInt32(
00140         VIDEO_MODE_BITS_PER_PIXEL_NAME,
00141         VIDEO_MODE_INFO_DEFAULT._bitsPerPixel
00142     );
00143     setVideoModeInfo( videoModeInfo );
00144 
00145     setFullscreen( reg.readBool( FULLSCREEN_NAME, FULLSCREEN_DEFAULT) );
00146 }
00147 
00148 //------------------------------------------------------------------------------
00149 
00150 void GfxConfig::save( ResConfigRegistryW& reg ) const
00151 {
00152     reg.writeUInt32( WINDOW_WIDTH_NAME, _windowInfo._width );
00153     reg.writeUInt32( WINDOW_HEIGHT_NAME, _windowInfo._height );
00154     reg.writeUInt32( WINDOW_X_NAME, _windowInfo._x );
00155     reg.writeUInt32( WINDOW_Y_NAME, _windowInfo._y );
00156     reg.writeUInt32( VIDEO_MODE_WIDTH_NAME, _videoModeInfo._width );
00157     reg.writeUInt32( VIDEO_MODE_HEIGHT_NAME, _videoModeInfo._height );
00158     reg.writeUInt32(
00159         VIDEO_MODE_BITS_PER_PIXEL_NAME,
00160         _videoModeInfo._bitsPerPixel
00161     );
00162     reg.writeBool( FULLSCREEN_NAME, _fullscreen );
00163 }

Generated on Wed Apr 23 15:58:52 2003 for Freecloth by doxygen1.3-rc3