home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Learn 3D Graphics Programming on the PC
/
Learn_3D_Graphics_Programming_on_the_PC_Ferraro.iso
/
rwwin
/
xettings.c_
/
xettings.bin
Wrap
Text File
|
1995-11-14
|
10KB
|
295 lines
/**********************************************************************
*
* File : settings.c
*
* Abstract : The implementation of some functions which handle the
* persistent settings of the viewer.
*
* This application had been written to be compatible with
* both the fixed and floating-point versions of the
* RenderWare library, i.e., it uses the macros CREAL,
* INT2REAL, RAdd, RDiv, RSub etc. If your application is
* intended for the floating-point version of the library
* only these macros are not necessary.
*
* Please note that this application is intended for
* demonstration purposes only. No support will be
* provided for this code and it comes with no warranty.
*
**********************************************************************
*
* This file is a product of Criterion Software Ltd.
*
* This file is provided as is with no warranties of any kind and is
* provided without any obligation on Criterion Software Ltd. or
* Canon Inc. to assist in its use or modification.
*
* Criterion Software Ltd. will not, under any
* circumstances, be liable for any lost revenue or other damages arising
* from the use of this file.
*
* Copyright (c) 1994, 1995 Criterion Software Ltd.
* All Rights Reserved.
*
* RenderWare is a trademark of Canon Inc.
*
**********************************************************************/
/**********************************************************************
*
* Header files.
*
**********************************************************************/
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <rwlib.h>
#include <rwwin.h>
#include "resource.h"
#include "common.h"
#include "settings.h"
/**********************************************************************
*
* Constant definitions.
*
**********************************************************************/
/*
* Name of the initialization file itself.
*/
#define INIFILENAME "rwview.ini"
/*
* Initialization file section and option strings.
*/
#define OPTIONSSECTION "Options"
#define SHOWLIGHTSENTRY "ShowLights"
#define SHOWSELECTIONENTRY "ShowSelection"
#define PLAYMOVIESENTRY "PlayMovies"
#define OBJECTMOMENTUMENTRY "ObjectMomentum"
#define SHAPEPATHENTRY "ShapePath"
#define CENTERBACKDROP "CenterBackdrop"
#define BACKDROPFILENAME "BackdropFileName"
#define BACKGROUNDCOLORENTRY "BackgroundColor"
#define MRUFILESECTION "Files"
#define MRUFILEOPTION "File%d"
/**********************************************************************
*
* Exported Data.
*
**********************************************************************/
/*
* This flag is set if the user has modified the settings in this
* session.
*/
RwBool SettingsChanged = FALSE;
/*
* Basic options.
*/
COLORREF BackgroundColor;
char BackdropFileName[_MAX_PATH];
RwBool CenterBackdrop;
RwBool ShowHighlight;
RwBool ShowLights;
RwBool PlayMovies;
RwBool Momentum;
/*
* MRU file names.
*/
int NumMRUFiles = 0;
static char MRUFileStrings[MAXMRUFILES][_MAX_PATH];
char *MRUFiles[MAXMRUFILES];
/**********************************************************************
*
* Functions.
*
**********************************************************************/
/**********************************************************************/
/*
* Read the saved settings from the initialization file.
*/
void
ReadSettings(void)
{
char buffer[128];
int r;
int g;
int b;
int i;
char optionString[_MAX_PATH];
/*
* Parse the settings.
*/
GetPrivateProfileString(OPTIONSSECTION, BACKGROUNDCOLORENTRY, "0 0 0",
buffer, sizeof(buffer), INIFILENAME);
sscanf(buffer, "%d %d %d", &r, &g, &b);
BackgroundColor = PALETTERGB(r, g, b);
GetPrivateProfileString(OPTIONSSECTION, SHOWLIGHTSENTRY, "0",
buffer, sizeof(buffer), INIFILENAME);
ShowLights = (RwBool)atoi(buffer);
GetPrivateProfileString(OPTIONSSECTION, SHOWSELECTIONENTRY, "1",
buffer, sizeof(buffer), INIFILENAME);
ShowHighlight = (RwBool)atoi(buffer);
GetPrivateProfileString(OPTIONSSECTION, PLAYMOVIESENTRY, "0",
buffer, sizeof(buffer), INIFILENAME);
PlayMovies = (RwBool)atoi(buffer);
GetPrivateProfileString(OPTIONSSECTION, OBJECTMOMENTUMENTRY, "1",
buffer, sizeof(buffer), INIFILENAME);
Momentum = (RwBool)atoi(buffer);
GetPrivateProfileString(OPTIONSSECTION, CENTERBACKDROP, "0",
buffer, sizeof(buffer), INIFILENAME);
CenterBackdrop = (RwBool)atoi(buffer);
GetPrivateProfileString(OPTIONSSECTION, BACKDROPFILENAME, "",
BackdropFileName, sizeof(BackdropFileName), INIFILENAME);
/*
* Read the MRU file list.
*/
for (i = 0; i < MAXMRUFILES; i++)
MRUFiles[i] = MRUFileStrings[i];
for (i = 0; i < MAXMRUFILES; i++)
{
sprintf(optionString, MRUFILEOPTION, i);
GetPrivateProfileString(MRUFILESECTION, optionString, "",
MRUFiles[i], _MAX_PATH, INIFILENAME);
if (*MRUFiles[i] == '\0')
break;
}
NumMRUFiles = i;
}
/**********************************************************************/
/*
* Write the current settings back to the initialization file. If the
* parameter writeAll is TRUE then all settings are written otherwise
* only the MRU files are written.
*/
void
WriteSettings(BOOL writeAll)
{
char buffer[128];
int i;
if (writeAll)
{
wsprintf(buffer, "%d %d %d", GetRValue(BackgroundColor),
GetGValue(BackgroundColor),
GetBValue(BackgroundColor));
WritePrivateProfileString(OPTIONSSECTION, BACKGROUNDCOLORENTRY,
buffer, INIFILENAME);
WritePrivateProfileString(OPTIONSSECTION, SHOWLIGHTSENTRY,
(ShowLights ? "1" : "0"), INIFILENAME);
WritePrivateProfileString(OPTIONSSECTION, SHOWSELECTIONENTRY,
(ShowHighlight ? "1" : "0"), INIFILENAME);
WritePrivateProfileString(OPTIONSSECTION, PLAYMOVIESENTRY,
(PlayMovies ? "1" : "0"), INIFILENAME);
WritePrivateProfileString(OPTIONSSECTION, OBJECTMOMENTUMENTRY,
(Momentum ? "1" : "0"), INIFILENAME);
WritePrivateProfileString(OPTIONSSECTION, CENTERBACKDROP,
(CenterBackdrop ? "1" : "0"), INIFILENAME);
WritePrivateProfileString(OPTIONSSECTION, BACKDROPFILENAME,
BackdropFileName, INIFILENAME);
}
/*
* Write the MRU files. We write all the MRU files out - the ones
* we have not used will be written out as empty strings which
* ReadSettings() will ignore.
*/
for (i = 0; i < MAXMRUFILES; i++)
{
sprintf(buffer, MRUFILEOPTION, i);
WritePrivateProfileString(MRUFILESECTION, buffer, MRUFiles[i],
INIFILENAME);
}
}
/**********************************************************************/
/*
* Append the MRU files to the file menu.
*/
void
AppendMRUFileMenuItems(HWND window)
{
HMENU fileMenu;
int i;
char buffer[_MAX_PATH];
if (NumMRUFiles != 0)
{
fileMenu = GetSubMenu(GetMenu(window), 0);
AppendMenu(fileMenu, MF_SEPARATOR, IDM_FILE_MRUSEPARATOR, NULL);
for (i = 0; i < NumMRUFiles; i++)
{
sprintf(buffer, "&%d %s", i + 1, MRUFiles[i]);
AppendMenu(fileMenu, MF_ENABLED, IDM_FILE_MRUFILE + i, buffer);
}
}
}
/**********************************************************************/
/*
* Delete the MRU files from the file menu.
*/
void
DeleteMRUFileMenuItems(HWND window)
{
HMENU fileMenu;
int i;
if (NumMRUFiles != 0)
{
fileMenu = GetSubMenu(GetMenu(window), 0);
DeleteMenu(fileMenu, IDM_FILE_MRUSEPARATOR, MF_BYCOMMAND);
for (i = 0; i < NumMRUFiles; i++)
DeleteMenu(fileMenu, IDM_FILE_MRUFILE + i, MF_BYCOMMAND);
}
}
/**********************************************************************/
/*
* Add a new file to the MRU file list.
*/
void
AddFileToMRUFileList(char *fileName)
{
char *tmp;
int i;
/*
* Scroll the MRU list of file names to make room for the new
* file.
*/
tmp = MRUFiles[MAXMRUFILES - 1];
for (i = (MAXMRUFILES - 1); i > 0; i--)
MRUFiles[i] = MRUFiles[i - 1];
MRUFiles[0] = tmp;
/*
* Add the new file.
*/
strcpy(MRUFiles[0], fileName);
NumMRUFiles++;
if (NumMRUFiles > MAXMRUFILES)
NumMRUFiles = MAXMRUFILES;
}
/**********************************************************************/