summaryrefslogtreecommitdiff
path: root/app/bin/layout.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/bin/layout.c')
-rw-r--r--app/bin/layout.c847
1 files changed, 563 insertions, 284 deletions
diff --git a/app/bin/layout.c b/app/bin/layout.c
index 4bf1936..c61c23f 100644
--- a/app/bin/layout.c
+++ b/app/bin/layout.c
@@ -17,52 +17,70 @@
*
* 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.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <dynstring.h>
#include "custom.h"
#include "layout.h"
-#include "misc2.h"
#include "param.h"
#include "paths.h"
#include "track.h"
#include "fileio.h"
+#include "cselect.h"
#define MINTRACKRADIUSPREFS "minTrackRadius"
+#define MAXTRACKGRADEPREFS "maxTrackGrade"
+#define TEXT_FIELD_LEN 40
+
+/**
+ * @brief Layout properties in Dialog
+*/
struct sLayoutProps {
- char title1[TITLEMAXLEN];
- char title2[TITLEMAXLEN];
- SCALEINX_T curScaleInx;
- SCALEDESCINX_T curScaleDescInx;
- GAUGEINX_T curGaugeInx;
- DIST_T minTrackRadius;
- DIST_T maxTrackGrade;
- coOrd roomSize;
- DynString backgroundFileName;
- coOrd backgroundPos;
- ANGLE_T backgroundAngle;
- int backgroundScreen;
- double backgroundSize;
+ char title1[TITLEMAXLEN];
+ char title2[TITLEMAXLEN];
+ SCALEINX_T curScaleInx;
+ SCALEDESCINX_T curScaleDescInx;
+ GAUGEINX_T curGaugeInx;
+ DIST_T minTrackRadius;
+ DIST_T maxTrackGrade;
+ coOrd roomSize;
+ char backgroundTextBox[TEXT_FIELD_LEN+1];
+ coOrd backgroundPos;
+ ANGLE_T backgroundAngle;
+ int backgroundScreen;
+ double backgroundSize;
};
+
+/**
+ * @brief Layout properties not in dialog, and save values for Cancel
+*/
struct sDataLayout {
- struct sLayoutProps props;
- DynString fullFileName;
- struct sLayoutProps *copyOfLayoutProps;
+ struct sLayoutProps props;
+ DynString fullFileName;
+ DynString
+ backgroundFileName; /** This is used to hold the entire path string */
+ struct sLayoutProps
+ *copyOfLayoutProps; /** Copy of props used to restore initial values in the event of Cancel */
+ DynString
+ copyBackgroundFileName; /** Copy of Background Path used to restore initial value in the event of Cancel */
};
static struct sDataLayout thisLayout = {
- { "", "", -1, 0, 0, 0.0, 5.0, {0.0, 0.0}, NaS, {0.0, 0.0}, 0.0, 0, 0.0 },
- NaS,
- NULL,
+ { "", "", 0, 0, 0, 0.0, 0.0, {0.0, 0.0}, "", {0.0, 0.0}, 0.0, 0, 0.0},
+ NaS,
+ NaS,
+ NULL,
+ NaS
};
EXPORT wIndex_t changed = 0;
static paramFloatRange_t r0_90 = { 0, 90 };
+// static paramFloatRange_t r0o05_100 = { 0.05, 100 };
static paramFloatRange_t r0_10000 = { 0, 10000 };
static paramFloatRange_t r0_9999999 = { 0, 9999999 };
static paramFloatRange_t r1_9999999 = { 1, 9999999 };
@@ -84,19 +102,19 @@ static void LayoutDlgUpdate(paramGroup_p pg, int inx, void * valueP);
void
SetLayoutFullPath(const char *fileName)
{
- if (fileName && fileName[0]) {
- if (DynStringSize(&thisLayout.fullFileName)) {
- if (strcmp(DynStringToCStr(&thisLayout.fullFileName),fileName)==0) {
- return;
- }
- DynStringClear(&thisLayout.fullFileName);
- }
- DynStringMalloc(&thisLayout.fullFileName, strlen(fileName) + 1);
- DynStringCatCStr(&thisLayout.fullFileName, fileName);
- } else {
- DynStringMalloc(&thisLayout.fullFileName, 2);
- DynStringCatCStr(&thisLayout.fullFileName, "");
- }
+ if (fileName && fileName[0]) {
+ if (DynStringSize(&thisLayout.fullFileName)) {
+ if (strcmp(DynStringToCStr(&thisLayout.fullFileName),fileName)==0) {
+ return;
+ }
+ DynStringClear(&thisLayout.fullFileName);
+ }
+ DynStringMalloc(&thisLayout.fullFileName, strlen(fileName) + 1);
+ DynStringCatCStr(&thisLayout.fullFileName, fileName);
+ } else {
+ DynStringMalloc(&thisLayout.fullFileName, 2);
+ DynStringCatCStr(&thisLayout.fullFileName, "");
+ }
}
/**
@@ -105,23 +123,44 @@ SetLayoutFullPath(const char *fileName)
* \param scaleName IN name of the scale/gauge eg. HOn3
* \param defaltValue IN default value will be used if no preference is set
*/
-
void
LoadLayoutMinRadiusPref(char *scaleName, double defaultValue)
{
- DynString prefString = { NULL };
+ DynString prefString = { NULL };
- DynStringPrintf(&prefString, MINTRACKRADIUSPREFS "-%s", scaleName);
- wPrefGetFloat("misc", DynStringToCStr(&prefString),
- &thisLayout.props.minTrackRadius, defaultValue);
- DynStringFree(&prefString);
+ DynStringPrintf(&prefString, MINTRACKRADIUSPREFS "-%s", scaleName);
+ wPrefGetFloat("misc", DynStringToCStr(&prefString),
+ &thisLayout.props.minTrackRadius, defaultValue);
+ DynStringFree(&prefString);
}
+/**
+* Set the maximum grade for the selected scale/gauge into the dialog
+*
+* \param scaleName IN name of the scale/gauge eg. HOn3
+* \param defaltValue IN default value will be used if no preference is set
+*/
+void
+LoadLayoutMaxGradePref(char* scaleName, double defaultValue)
+{
+ DynString prefString = { NULL };
+
+ DynStringPrintf(&prefString, MAXTRACKGRADEPREFS "-%s", scaleName);
+ wPrefGetFloat("misc", DynStringToCStr(&prefString),
+ &thisLayout.props.maxTrackGrade, defaultValue);
+ DynStringFree(&prefString);
+}
+
+/**
+ * @brief Copy Layout title making sure there is a null at the end
+ * @param dest The destination to copy to
+ * @param src The source of the copy
+*/
static void
CopyLayoutTitle(char* dest, char *src)
{
- strncpy(dest, src, TITLEMAXLEN);
- *(dest + TITLEMAXLEN - 1) = '\0';
+ strncpy(dest, src, TITLEMAXLEN);
+ *(dest + TITLEMAXLEN - 1) = '\0';
}
@@ -136,91 +175,161 @@ SetFileChanged(void)
SetWindowTitle();
}
+/**
+ * @brief Set the Layout title
+ * @param title The Layout title
+*/
void
SetLayoutTitle(char *title)
{
- CopyLayoutTitle(thisLayout.props.title1, title);
+ CopyLayoutTitle(thisLayout.props.title1, title);
}
+/**
+ * @brief Set the layout Subtitle
+ * @param title The Layout subtitle
+*/
void
SetLayoutSubtitle(char *title)
{
- CopyLayoutTitle(thisLayout.props.title2, title);
+ CopyLayoutTitle(thisLayout.props.title2, title);
}
+/**
+ * @brief Set the Layout minimum track radius.
+ * @param radius
+*/
void
SetLayoutMinTrackRadius(DIST_T radius)
{
- thisLayout.props.minTrackRadius = radius;
+ thisLayout.props.minTrackRadius = radius;
}
+/**
+ * @brief Set the Layout maximum track grade.
+ * @param angle The maximum track grade.
+*/
void
SetLayoutMaxTrackGrade(ANGLE_T angle)
{
- thisLayout.props.maxTrackGrade = angle;
+ thisLayout.props.maxTrackGrade = angle;
}
-
+/**
+ * @brief Set the layout room size
+ * @param size The room size (coOrd)
+*/
void
SetLayoutRoomSize(coOrd size)
{
- thisLayout.props.roomSize = size;
+ thisLayout.props.roomSize = size;
}
+/**
+ * @brief Set the Layout scale (index). Also set the default Tie Data.
+ * @param scale The Layout scale index.
+*/
void
SetLayoutCurScale(SCALEINX_T scale)
{
- thisLayout.props.curScaleInx = scale;
+ thisLayout.props.curScaleInx = scale;
}
+/**
+ * @brief Set the Layout scale description (index)
+ * @param desc The Layout scale description index.
+*/
void
SetLayoutCurScaleDesc(SCALEDESCINX_T desc)
{
- thisLayout.props.curScaleDescInx = desc;
+ thisLayout.props.curScaleDescInx = desc;
}
+/**
+ * @brief Set the Layout current gauge (index)
+ * @param gauge The Layout gauge index.
+*/
void
SetLayoutCurGauge(GAUGEINX_T gauge)
{
- thisLayout.props.curGaugeInx = gauge;
+ thisLayout.props.curGaugeInx = gauge;
}
-void SetLayoutBackGroundFullPath(const char *fileName) {
+/**
+ * @brief Set the Layout background full path.
+ * @param fileName The Layout background full path string.
+*/
+void SetLayoutBackGroundFullPath(const char *fileName)
+{
if (fileName && fileName[0]) {
- if (DynStringSize(&thisLayout.props.backgroundFileName)) {
- if (strcmp(DynStringToCStr(&thisLayout.props.backgroundFileName),fileName)==0) {
+ if (DynStringSize(&thisLayout.backgroundFileName)) {
+ if (strcmp(DynStringToCStr(&thisLayout.backgroundFileName),fileName)==0) {
return;
}
- DynStringClear(&thisLayout.props.backgroundFileName);
+ DynStringClear(&thisLayout.backgroundFileName);
}
- DynStringMalloc(&thisLayout.props.backgroundFileName, strlen(fileName) + 1);
- DynStringCatCStr(&thisLayout.props.backgroundFileName, fileName);
+ DynStringMalloc(&thisLayout.backgroundFileName, strlen(fileName) + 1);
+ DynStringCatCStr(&thisLayout.backgroundFileName, fileName);
} else {
- DynStringClear(&thisLayout.props.backgroundFileName);
- DynStringCatCStr(&thisLayout.props.backgroundFileName, "");
+ DynStringClear(&thisLayout.backgroundFileName);
+ DynStringMalloc(&thisLayout.backgroundFileName, 1);
+ DynStringCatCStr(&thisLayout.backgroundFileName, "");
}
}
-void SetLayoutBackGroundSize(double size) {
- thisLayout.props.backgroundSize = size;
+/**
+ * @brief Set the Layout background size (relative to the layout width)
+ * @param size The Layout background size.
+*/
+void SetLayoutBackGroundSize(double size)
+{
+ thisLayout.props.backgroundSize = size;
}
-void SetLayoutBackGroundPos(coOrd pos) {
+/**
+ * @brief Set the Layout background position (origin).
+ * @param pos The Layout background origin (coOrd).
+*/
+void SetLayoutBackGroundPos(coOrd pos)
+{
thisLayout.props.backgroundPos = pos;
}
-void SetLayoutBackGroundAngle(ANGLE_T angle) {
+/**
+ * @brief Set the Layout Background angle.
+ * @param angle The Layout Background angle (ANGLE_T).
+*/
+void SetLayoutBackGroundAngle(ANGLE_T angle)
+{
thisLayout.props.backgroundAngle = angle;
}
-void SetLayoutBackGroundScreen(int screen) {
+/**
+ * @brief Set the Layout Background screen (percent of transparency)
+ * @param screen The Screen value (0-100)
+*/
+void SetLayoutBackGroundScreen(int screen)
+{
thisLayout.props.backgroundScreen = screen;
}
/**
+ * Get changed-State of layout.
+ *
+ * \return true if changed
+ */
+
+BOOL_T
+GetLayoutChanged(void)
+{
+ return(changed > 0);
+}
+
+
+/**
* Return the full filename.
*
* \return pointer to the full filename, should not be modified or freed
@@ -230,7 +339,7 @@ char *
GetLayoutFullPath()
{
char * s = DynStringToCStr(&thisLayout.fullFileName);
- return s;
+ return s;
}
/**
@@ -242,58 +351,90 @@ GetLayoutFullPath()
char *
GetLayoutFilename()
{
- char *string = DynStringToCStr(&thisLayout.fullFileName);
+ char *string = DynStringToCStr(&thisLayout.fullFileName);
- if (string) {
- return FindFilename(string);
- } else {
- return (NULL);
- }
+ if (string) {
+ return FindFilename(string);
+ } else {
+ return (NULL);
+ }
}
+/**
+ * @brief Return the layout title
+ * @return The title string
+*/
char *
GetLayoutTitle()
{
- return (thisLayout.props.title1);
+ return (thisLayout.props.title1);
}
+/**
+ * @brief Return the layout subtitle
+ * @return The subtitle string
+*/
char *
GetLayoutSubtitle()
{
- return (thisLayout.props.title2);
+ return (thisLayout.props.title2);
}
+/**
+ * @brief Returns the layout minimum radius
+ * @return The minimum radius (DIST_T)
+*/
DIST_T
GetLayoutMinTrackRadius()
{
- return (thisLayout.props.minTrackRadius);
+ return (thisLayout.props.minTrackRadius);
}
+/**
+ * @brief Returns the layout maximum track grade
+ * @return The Maximum grade (ANGLE_T)
+*/
ANGLE_T
GetLayoutMaxTrackGrade()
{
- return (thisLayout.props.maxTrackGrade);
+ return (thisLayout.props.maxTrackGrade);
}
+/**
+ * @brief Returns the scale index of layout scale description
+ * @return The Scale Description index
+*/
SCALEDESCINX_T
GetLayoutCurScaleDesc()
{
- return (thisLayout.props.curScaleDescInx);
+ return (thisLayout.props.curScaleDescInx);
}
+/**
+* @brief Returns the scale index of layout scale setting
+* @return The Scale Index
+*/
SCALEINX_T
GetLayoutCurScale()
{
- return (thisLayout.props.curScaleInx);
+ return (thisLayout.props.curScaleInx);
}
+/**
+ * @brief Returns the Layout Background full path
+ * @return The Background full path
+*/
char *
GetLayoutBackGroundFullPath()
{
- char * s = DynStringToCStr(&thisLayout.props.backgroundFileName);
+ char * s = DynStringToCStr(&thisLayout.backgroundFileName);
return s;
}
+/**
+ * @brief Returns the layout background size.
+ * @return The background size, or room size if zero
+*/
double
GetLayoutBackGroundSize()
{
@@ -304,18 +445,30 @@ GetLayoutBackGroundSize()
}
}
+/**
+ * @brief Returns the background position (origin)
+ * @return The background position (coOrd)
+*/
coOrd
GetLayoutBackGroundPos()
{
return (thisLayout.props.backgroundPos);
}
+/**
+ * @brief Returns the background angle
+ * @return The background angle (ANGLE_T)
+*/
ANGLE_T
GetLayoutBackGroundAngle()
{
return (thisLayout.props.backgroundAngle);
}
+/**
+ * @brief Returns the background screen percent (the amount of transparency)
+ * @return The background Screen value (0-100)
+*/
int GetLayoutBackGroundScreen()
{
return (thisLayout.props.backgroundScreen);
@@ -338,29 +491,23 @@ GetLayoutRoomSize(coOrd *roomSize)
* Layout Dialog
*
*/
-static char backgroundFileName[STR_LONG_SIZE];
-
-#define TEXT_FIELD_LEN 40
static wWin_p layoutW;
+static void LayoutChange(long changes);
-/**************************************************************************************
-* Show only the end of the background file path including the filename in the Dialog
+/**
+* Show only the filename in the Dialog
*/
-void SetName() {
- char * name = GetLayoutBackGroundFullPath();
+void SetName()
+{
+ char *name = GetLayoutBackGroundFullPath();
if (name && name[0]) { //Ignore ""
- if (name && (strlen(name)<=TEXT_FIELD_LEN)) {
- for (unsigned int i=0; i<=strlen(name);i++) {
- backgroundFileName[i] = name[i];
- }
- backgroundFileName[strlen(name)] = '\0';
+ char *f = FindFilename(name);
+ if ( f ) {
+ strncpy( thisLayout.props.backgroundTextBox,f,TEXT_FIELD_LEN );
} else {
- for (int i=TEXT_FIELD_LEN;i>=0; i--) {
- backgroundFileName[i] = name[strlen(name)-(TEXT_FIELD_LEN-i)];
- }
- backgroundFileName[TEXT_FIELD_LEN] = '\0'; //Insurance
+ thisLayout.props.backgroundTextBox[0] = '\0';
}
- } else backgroundFileName[0] = '\0';
+ } else { thisLayout.props.backgroundTextBox[0] = '\0'; }
}
static struct wFilSel_t * imageFile_fs;
@@ -374,6 +521,12 @@ BOOL_T backgroundVisible = TRUE;
char * noname = "";
+EXPORT wButton_p backgroundB;
+
+/**
+ * @brief Enable background visibility toggle from Menu or Button
+ * @param unused
+*/
void
BackgroundToggleShow( void * unused )
{
@@ -382,18 +535,27 @@ BackgroundToggleShow( void * unused )
MainRedraw();
}
+/**
+ * @brief Returns status of backgroundVisible
+ * @return backgroundVisible
+*/
int GetLayoutBackGroundVisible()
{
return(backgroundVisible);
}
+/**
+ * @brief Returns status of layout background.
+ * @return true if a background is defined, false otherwise
+*/
bool HasBackGround()
{
return(haveBackground);
}
-/*****************************************
-* Try to load the background image file
+/**
+* Try to load the background image file. Display notice if failed to load.
+* @return TRUE if successful, FALSE if not.
*/
wBool_t
LoadBackGroundImage(void)
@@ -410,72 +572,84 @@ LoadBackGroundImage(void)
return TRUE;
}
-/*******************************************************
+#define BACKGROUNDFILEENTRY (8)
+
+/**
* Callback from File Select for Background Image File
-*
+*
* \param files number of files selected (only first file is used)
* \param fileName array of pointers to filenames
* \param data unused
* \return FALSE
*/
EXPORT int LoadImageFile(
- int files,
- char ** fileName,
- void * data )
+ int files,
+ char ** fileName,
+ void * data )
{
- if (files >0) {
- SetLayoutBackGroundFullPath( strdup(fileName[0]));
+ if (files >0) {
+ SetLayoutBackGroundFullPath( strdup(fileName[0]) );
- if (!LoadBackGroundImage()) {
- SetLayoutBackGroundFullPath(noname);
- backgroundVisible = FALSE;
- }
- else {
- backgroundVisible = TRUE;
- SetCurrentPath(BACKGROUNDPATHKEY, fileName[0]);
- }
- } else {
+ if (!LoadBackGroundImage()) {
SetLayoutBackGroundFullPath(noname);
backgroundVisible = FALSE;
+ } else {
+ backgroundVisible = TRUE;
+ SetCurrentPath(BACKGROUNDPATHKEY, fileName[0]);
+
+ file_changed = TRUE;
+ haveBackground = TRUE;
+ ParamLoadControl(layout_pg_p, BACKGROUNDFILEENTRY);
+
+ MainRedraw();
}
- wControlActive((wControl_p)backgroundB, backgroundVisible);
- wButtonSetBusy(backgroundB, backgroundVisible);
+ } else {
+ SetLayoutBackGroundFullPath(noname);
+ backgroundVisible = FALSE;
+ }
+ wControlActive((wControl_p)backgroundB, backgroundVisible);
+ wButtonSetBusy(backgroundB, backgroundVisible);
- SetName();
- file_changed = TRUE;
- ParamLoadControl(layout_pg_p, 8);
- return FALSE;
+ SetName();
+ file_changed = TRUE;
+ ParamLoadControl(layout_pg_p, BACKGROUNDFILEENTRY);
+ LayoutChange( CHANGE_BACKGROUND );
+
+ return FALSE;
}
-/**********************************************************
- * Save the Background Parms - forcing a write
- */
-void LayoutBackGroundSave(void) {
- char * background = GetLayoutBackGroundFullPath();
+/**
+ * Save the Layout Background Parms in section [layout]. Force a write.
+*/
+void LayoutBackGroundSave(void)
+{
+ char * background = GetLayoutBackGroundFullPath();
wPrefSetString("layout", "BackgroundPath", background);
- wPrefSetFloat("layout", "BackgroundPosX", thisLayout.props.backgroundPos.x);
- wPrefSetFloat("layout", "BackgroundPosY", thisLayout.props.backgroundPos.y);
- wPrefSetFloat("layout", "BackgroundAngle", thisLayout.props.backgroundAngle);
- wPrefSetInteger("layout", "BackgroundScreen", thisLayout.props.backgroundScreen);
- wPrefSetFloat("layout", "BackgroundSize", thisLayout.props.backgroundSize);
-
- wPrefFlush("");
+ wPrefSetFloat("layout", "BackgroundPosX", thisLayout.props.backgroundPos.x);
+ wPrefSetFloat("layout", "BackgroundPosY", thisLayout.props.backgroundPos.y);
+ wPrefSetFloat("layout", "BackgroundAngle", thisLayout.props.backgroundAngle);
+ wPrefSetInteger("layout", "BackgroundScreen",
+ thisLayout.props.backgroundScreen);
+ wPrefSetFloat("layout", "BackgroundSize", thisLayout.props.backgroundSize);
+
+ wPrefFlush("");
}
-/************************************************************
+/**
* Run File Select for the Background Image File
- */
+*/
static void ImageFileBrowse( void * unused )
{
- imageFile_fs = wFilSelCreate( mainW, FS_LOAD, FS_PICTURES, _("Load Background"), sImageFilePattern, LoadImageFile, NULL );
+ imageFile_fs = wFilSelCreate( mainW, FS_LOAD, FS_PICTURES, _("Load Background"),
+ sImageFilePattern, LoadImageFile, NULL );
wFilSelect( imageFile_fs, GetCurrentPath( BACKGROUNDPATHKEY ) );
return;
}
-/************************************************************
+/**
* Remove the background Image File
- */
+*/
static void ImageFileClear( void * unused)
{
char * noname = "";
@@ -485,24 +659,27 @@ static void ImageFileClear( void * unused)
wControlActive((wControl_p)backgroundB, FALSE);
file_changed = TRUE;
haveBackground = false;
- ParamLoadControl(layout_pg_p, 8);
+ ParamLoadControl(layout_pg_p, BACKGROUNDFILEENTRY);
+
+ LayoutChange( CHANGE_BACKGROUND );
+
MainRedraw();
}
static paramData_t layoutPLs[] = {
- { PD_FLOAT, &thisLayout.props.roomSize.x, "roomsizeX", PDO_NOPREF | PDO_DIM | PDO_NOPSHUPD | PDO_DRAW, &r1_9999999, N_("Room Width"), 0, I2VP(CHANGE_MAIN | CHANGE_MAP) },
- { PD_FLOAT, &thisLayout.props.roomSize.y, "roomsizeY", PDO_NOPREF | PDO_DIM | PDO_NOPSHUPD | PDO_DRAW | PDO_DLGHORZ, &r1_9999999, N_(" Height"), 0, I2VP(CHANGE_MAIN | CHANGE_MAP) },
- { PD_STRING, &thisLayout.props.title1, "title1", PDO_NOPSHUPD | PDO_STRINGLIMITLENGTH, NULL, N_("Layout Title"), 0, 0, sizeof(thisLayout.props.title1)},
- { PD_STRING, &thisLayout.props.title2, "title2", PDO_NOPSHUPD | PDO_STRINGLIMITLENGTH, NULL, N_("Subtitle"), 0, 0, sizeof(thisLayout.props.title2)},
+ { PD_FLOAT, &thisLayout.props.roomSize.x, "roomsizeX", PDO_NOPREF | PDO_DIM | PDO_NOPSHUPD | PDO_DRAW, &r1_9999999, N_("Room Width"), 0, I2VP(CHANGE_MAIN | CHANGE_MAP) },
+ { PD_FLOAT, &thisLayout.props.roomSize.y, "roomsizeY", PDO_NOPREF | PDO_DIM | PDO_NOPSHUPD | PDO_DRAW | PDO_DLGHORZ, &r1_9999999, N_(" Height"), 0, I2VP(CHANGE_MAIN | CHANGE_MAP) },
+ { PD_STRING, &thisLayout.props.title1, "title1", PDO_NOPSHUPD | PDO_STRINGLIMITLENGTH, NULL, N_("Layout Title"), 0, 0, sizeof(thisLayout.props.title1)},
+ { PD_STRING, &thisLayout.props.title2, "title2", PDO_NOPSHUPD | PDO_STRINGLIMITLENGTH, NULL, N_("Subtitle"), 0, 0, sizeof(thisLayout.props.title2)},
#define SCALEINX (4)
- { PD_DROPLIST, &thisLayout.props.curScaleDescInx, "scale", PDO_NOPREF | PDO_NOPSHUPD | PDO_NORECORD | PDO_NOUPDACT, I2VP(180), N_("Scale"), 0, I2VP(CHANGE_SCALE) },
+ { PD_DROPLIST, &thisLayout.props.curScaleDescInx, "scale", PDO_NOPREF | PDO_NOPSHUPD | PDO_NORECORD | PDO_NOUPDACT, I2VP(180), N_("Scale"), 0, I2VP(CHANGE_SCALE) },
#define GAUGEINX (5)
- { PD_DROPLIST, &thisLayout.props.curGaugeInx, "gauge", PDO_NOPREF | PDO_NOPSHUPD | PDO_NORECORD | PDO_NOUPDACT | PDO_DLGHORZ, I2VP(180), N_(" Gauge"), 0, I2VP(CHANGE_SCALE) },
+ { PD_DROPLIST, &thisLayout.props.curGaugeInx, "gauge", PDO_NOPREF | PDO_NOPSHUPD | PDO_NORECORD | PDO_NOUPDACT | PDO_DLGHORZ, I2VP(180), N_(" Gauge"), 0, I2VP(CHANGE_SCALE) },
#define MINRADIUSENTRY (6)
- { PD_FLOAT, &thisLayout.props.minTrackRadius, "mintrackradius", PDO_DIM | PDO_NOPSHUPD | PDO_NOPREF, &r0_10000, N_("Min Track Radius"), 0, I2VP(CHANGE_MAIN | CHANGE_LIMITS) },
- { PD_FLOAT, &thisLayout.props.maxTrackGrade, "maxtrackgrade", PDO_NOPSHUPD | PDO_DLGHORZ, &r0_90, N_(" Max Track Grade (%)"), 0, I2VP(CHANGE_MAIN) },
-#define BACKGROUNDFILEENTRY (8) //Note this value used in the file section routines above - if it chnages, they will need to change
- { PD_STRING, &backgroundFileName, "backgroundfile", PDO_NOPSHUPD | PDO_NORECORD|PDO_STRINGLIMITLENGTH, NULL, N_("Background File Path"), 0, I2VP(CHANGE_BACKGROUND),sizeof(backgroundFileName) },
+ { PD_FLOAT, &thisLayout.props.minTrackRadius, "mintrackradius", PDO_DIM | PDO_NOPSHUPD | PDO_NOPREF, &r0_10000, N_("Min Track Radius"), 0, I2VP(CHANGE_MAIN | CHANGE_LIMITS) },
+ { PD_FLOAT, &thisLayout.props.maxTrackGrade, "maxtrackgrade", PDO_NOPSHUPD | PDO_DLGHORZ, &r0_90, N_(" Max Track Grade (%)"), 0, I2VP(CHANGE_MAIN) },
+#define BACKGROUNDFILECHECK (8) //Note this value used in the file section routines above - if it changes, they will need to change
+ { PD_STRING, &thisLayout.props.backgroundTextBox, "backgroundfile", PDO_NOPSHUPD|PDO_NOPREF|PDO_NORECORD|PDO_STRINGLIMITLENGTH, NULL, N_("Background File Path"), 0, I2VP(CHANGE_BACKGROUND), TEXT_FIELD_LEN },
{ PD_BUTTON, ImageFileBrowse, "browse", PDO_DLGHORZ, NULL, N_("Browse ...") },
{ PD_BUTTON, ImageFileClear, "clear", PDO_DLGHORZ, NULL, N_("Clear") },
#define BACKGROUNDPOSX (11)
@@ -518,46 +695,48 @@ static paramData_t layoutPLs[] = {
{ PD_MESSAGE, N_("Named Settings File"), NULL, PDO_DLGRESETMARGIN, I2VP(180) },
{ PD_BUTTON, SettingsWrite, "write", PDO_DLGHORZ, 0, N_("Write"), 0, I2VP(0) },
{ PD_BUTTON, SettingsRead, "read", PDO_DLGHORZ | PDO_DLGBOXEND, 0, N_("Read"), 0, I2VP(0) }
-
};
static paramGroup_t layoutPG = { "layout", PGO_RECORD | PGO_PREFMISC, layoutPLs, COUNT( layoutPLs ) };
+/**
+ * @brief Handle the Layout changes, setting the values of changed items from dialog.
+*/
+static void ChangeLayout()
+{
-static void ChangeLayout() {
-
- long changes;
+ long changes;
- changes = GetChanges(&layoutPG);
+ changes = GetChanges(&layoutPG);
- /* [mf Nov. 15, 2005] Get the gauge/scale settings */
- if (changes & CHANGE_SCALE) {
- SetScaleGauge(thisLayout.props.curScaleDescInx, thisLayout.props.curGaugeInx);
+ /* [mf Nov. 15, 2005] Get the gauge/scale settings */
+ if (changes & CHANGE_SCALE) {
+ SetScaleGauge(thisLayout.props.curScaleDescInx, thisLayout.props.curGaugeInx);
file_changed = TRUE;
}
- /* [mf Nov. 15, 2005] end */
+ /* [mf Nov. 15, 2005] end */
- if (changes & CHANGE_MAP) {
- SetRoomSize(thisLayout.props.roomSize);
+ if (changes & CHANGE_MAP) {
+ SetRoomSize(thisLayout.props.roomSize);
file_changed = TRUE;
}
- DoChangeNotification(changes);
+ DoChangeNotification(changes);
- if (changes & CHANGE_LIMITS) {
- char prefString[30];
- // now set the minimum track radius
- sprintf(prefString, "minTrackRadius-%s", curScaleName);
- wPrefSetFloat("misc", prefString, thisLayout.props.minTrackRadius);
+ if (changes & CHANGE_LIMITS) {
+ char prefString[30];
+ // now set the minimum track radius
+ sprintf(prefString, "minTrackRadius-%s", curScaleName);
+ wPrefSetFloat("misc", prefString, thisLayout.props.minTrackRadius);
file_changed = TRUE;
}
- if (changes & CHANGE_BACKGROUND) {
+ if (changes & CHANGE_BACKGROUND) {
- LayoutBackGroundSave();
- file_changed = TRUE;
- }
+ LayoutBackGroundSave();
+ file_changed = TRUE;
+ }
}
/**
@@ -569,15 +748,18 @@ static void ChangeLayout() {
static void LayoutOk(void * unused)
{
ChangeLayout();
- if(file_changed){
+ if(file_changed) {
+ LayoutBackGroundSave();
SetFileChanged();
file_changed = FALSE;
}
- free(thisLayout.copyOfLayoutProps);
- wHide(layoutW);
+ free(thisLayout.copyOfLayoutProps);
+ DynStringFree(&thisLayout.copyBackgroundFileName);
+
+ wHide(layoutW);
- MainLayout( TRUE, TRUE );
+ MainLayout( TRUE, TRUE );
}
@@ -590,52 +772,102 @@ static void LayoutOk(void * unused)
static void LayoutCancel(struct wWin_t *unused)
{
- thisLayout.props = *(thisLayout.copyOfLayoutProps);
- ParamLoadControls(&layoutPG);
- LayoutOk(unused);
+ // thisLayout.props = *(thisLayout.copyOfLayoutProps);
+ char* curr = DynStringToCStr(&thisLayout.backgroundFileName);
+ char* prev = DynStringToCStr(&thisLayout.copyBackgroundFileName);
+ if ((curr == NULL && prev != NULL) || (curr != NULL && prev == NULL)
+ || (strcmp(curr, prev) != 0) ) {
+ if (DynStringSize(&thisLayout.backgroundFileName)) {
+ DynStringClear(&thisLayout.backgroundFileName);
+ }
+ size_t bgSize = DynStringSize(&thisLayout.copyBackgroundFileName);
+ if ( bgSize ) {
+ DynStringMalloc(&thisLayout.backgroundFileName, bgSize + 1);
+ char* fileName = DynStringToCStr(&thisLayout.copyBackgroundFileName);
+ DynStringCatCStr(&thisLayout.backgroundFileName, fileName);
+ haveBackground = TRUE;
+ wDrawSetBackground( mainD.d, fileName, NULL);
+ } else {
+ haveBackground = FALSE;
+ wDrawSetBackground( mainD.d, NULL, NULL);
+ }
+ SetName();
+ // ChangeLayout();
+ }
+
+ ParamLoadControls(&layoutPG);
+
+ free(thisLayout.copyOfLayoutProps);
+ DynStringFree(&thisLayout.copyBackgroundFileName);
+
+ wHide(layoutW);
+
+ MainLayout( TRUE, TRUE );
}
+/**
+ * @brief Reload Layout parameters if changes
+ * @param changes
+*/
static void LayoutChange(long changes)
{
- if (changes & (CHANGE_SCALE | CHANGE_UNITS | CHANGE_BACKGROUND))
- if (layoutW != NULL && wWinIsVisible(layoutW)) {
- ParamLoadControls(&layoutPG);
- }
+ if (changes & (CHANGE_SCALE | CHANGE_UNITS | CHANGE_BACKGROUND))
+ if (layoutW != NULL && wWinIsVisible(layoutW)) {
+ ParamLoadControls(&layoutPG);
+ }
}
+/**
+ * @brief Initialize Layout dialog
+ * @param unused
+*/
void DoLayout(void * unused)
{
- SetLayoutRoomSize(mapD.size);
+ CHECK(BACKGROUNDFILEENTRY == BACKGROUNDFILECHECK);
+
+ SetLayoutRoomSize(mapD.size);
+
+ if (layoutW == NULL) {
+ layoutW = ParamCreateDialog(&layoutPG, MakeWindowTitle(_("Layout Options")),
+ _("Ok"), LayoutOk, LayoutCancel, TRUE, NULL, 0, LayoutDlgUpdate);
+ LoadScaleList((wList_p)layoutPLs[4].control);
+ }
- if (layoutW == NULL) {
- layoutW = ParamCreateDialog(&layoutPG, MakeWindowTitle(_("Layout Options")),
- _("Ok"), LayoutOk, LayoutCancel, TRUE, NULL, 0, LayoutDlgUpdate);
- LoadScaleList((wList_p)layoutPLs[4].control);
- }
+ ParamControlActive(&layoutPG, BACKGROUNDFILEENTRY, FALSE);
- ParamControlActive(&layoutPG, BACKGROUNDFILEENTRY, FALSE);
+ LoadGaugeList((wList_p)layoutPLs[5].control,
+ thisLayout.props.curScaleDescInx); /* set correct gauge list here */
+ thisLayout.copyOfLayoutProps = malloc(sizeof(struct sLayoutProps));
- LoadGaugeList((wList_p)layoutPLs[5].control,
- thisLayout.props.curScaleDescInx); /* set correct gauge list here */
- thisLayout.copyOfLayoutProps = malloc(sizeof(struct sLayoutProps));
+ if (!thisLayout.copyOfLayoutProps) {
+ exit(1);
+ }
+ SetName();
+ *(thisLayout.copyOfLayoutProps) = thisLayout.props;
- if (!thisLayout.copyOfLayoutProps) {
- exit(1);
- }
- SetName();
- *(thisLayout.copyOfLayoutProps) = thisLayout.props;
+ char* curr = DynStringToCStr(&thisLayout.backgroundFileName);
+ size_t bgSize = DynStringSize(&thisLayout.backgroundFileName);
+ if ( bgSize ) {
+ DynStringMalloc(&thisLayout.copyBackgroundFileName, bgSize + 1);
+ DynStringCatCStr(&thisLayout.copyBackgroundFileName, curr);
+ }
- ParamLoadControls(&layoutPG);
- wShow(layoutW);
+ ParamLoadControls(&layoutPG);
+ wShow(layoutW);
}
+/**
+ * @brief Callback for Menu and Shortcut key to open Layout Dialog.
+ * @param void
+ * @return Address of layout dialog (DoLayout)
+*/
EXPORT addButtonCallBack_t LayoutInit(void)
{
- ParamRegister(&layoutPG);
- RegisterChangeNotification(LayoutChange);
- layout_p = layoutPLs;
- layout_pg_p = &layoutPG;
- return &DoLayout;
+ ParamRegister(&layoutPG);
+ RegisterChangeNotification(LayoutChange);
+ layout_p = layoutPLs;
+ layout_pg_p = &layoutPG;
+ return &DoLayout;
}
/**
@@ -650,86 +882,98 @@ EXPORT addButtonCallBack_t LayoutInit(void)
static void
LayoutDlgUpdate(
- paramGroup_p pg,
- int inx,
- void * valueP)
-{
- /* did the scale change ? */
- if (inx == SCALEINX) {
- char prefString[100];
- char scaleDesc[100];
-
- LoadGaugeList((wList_p)layoutPLs[GAUGEINX].control, *((int *)valueP));
- // set the first entry as default, usually the standard gauge for a scale
- wListSetIndex((wList_p)layoutPLs[GAUGEINX].control, 0);
-
- // get the minimum radius
- // get the selected scale first
- wListGetValues((wList_p)layoutPLs[SCALEINX].control, scaleDesc, 99, NULL, NULL);
- strtok(scaleDesc, " ");
-
- // now get the minimum track radius
- sprintf(prefString, "minTrackRadius-%s", scaleDesc);
- wPrefGetFloat("misc", prefString, &thisLayout.props.minTrackRadius, 0.0);
-
- // put the scale's minimum value into the dialog
- wStringSetValue((wString_p)layoutPLs[MINRADIUSENTRY].control,
- FormatDistance(thisLayout.props.minTrackRadius));
- }
- if (inx == BACKGROUNDPOSX) {
- coOrd pos;
- pos.x = *(double *)valueP;
- pos.y = GetLayoutBackGroundPos().y;
- SetLayoutBackGroundPos(pos);
- MainRedraw();
- }
- if (inx == BACKGROUNDPOSY) {
- coOrd pos;
+ paramGroup_p pg,
+ int inx,
+ void * valueP)
+{
+ /* did the scale change ? */
+ if (inx == SCALEINX) {
+ char prefString[130];
+ char scaleDesc[100];
+
+ LoadGaugeList((wList_p)layoutPLs[GAUGEINX].control, *((int *)valueP));
+ // set the first entry as default, usually the standard gauge for a scale
+ wListSetIndex((wList_p)layoutPLs[GAUGEINX].control, 0);
+
+ // get the minimum radius
+ // get the selected scale first
+ wListGetValues((wList_p)layoutPLs[SCALEINX].control, scaleDesc, 99, NULL, NULL);
+ strtok(scaleDesc, " ");
+
+ // now get the minimum track radius
+ sprintf(prefString, "minTrackRadius-%s", scaleDesc);
+ wPrefGetFloat("misc", prefString, &thisLayout.props.minTrackRadius, 0.0);
+
+ // put the scale's minimum value into the dialog
+ wStringSetValue((wString_p)layoutPLs[MINRADIUSENTRY].control,
+ FormatDistance(thisLayout.props.minTrackRadius));
+ }
+ if (inx == BACKGROUNDFILEENTRY) {
+ SetName();
+ MainRedraw();
+ }
+ if (inx == BACKGROUNDPOSX) {
+ coOrd pos;
+ pos.x = *(double *)valueP;
+ pos.y = GetLayoutBackGroundPos().y;
+ SetLayoutBackGroundPos(pos);
+ MainRedraw();
+ }
+ if (inx == BACKGROUNDPOSY) {
+ coOrd pos;
pos.y = *(double *)valueP;
pos.x = GetLayoutBackGroundPos().x;
SetLayoutBackGroundPos(pos);
- MainRedraw();
- }
- if (inx == BACKGROUNDWIDTH) {
- SetLayoutBackGroundSize(*(double *)valueP);
- MainRedraw();
- }
- if (inx == BACKGROUNDSCREEN) {
- SetLayoutBackGroundScreen(*(int *)valueP);
- MainRedraw();
- }
- if (inx == BACKGROUNDANGLE) {
-
- ANGLE_T angle = NormalizeAngle(*(double *)valueP);
- wStringSetValue((wString_p)layoutPLs[BACKGROUNDANGLE].control,FormatFloat(angle));
- SetLayoutBackGroundAngle(angle);
- MainRedraw();
- }
-
-}
-/***************************************************************************************
- * Load Background Options from Saved Parms
- ***************************************************************************************/
+ MainRedraw();
+ }
+ if (inx == BACKGROUNDWIDTH) {
+ SetLayoutBackGroundSize(*(double *)valueP);
+ MainRedraw();
+ }
+ if (inx == BACKGROUNDSCREEN) {
+ SetLayoutBackGroundScreen(*(int *)valueP);
+ MainRedraw();
+ }
+ if (inx == BACKGROUNDANGLE) {
+
+ ANGLE_T angle = NormalizeAngle(*(double *)valueP);
+ wStringSetValue((wString_p)layoutPLs[BACKGROUNDANGLE].control,
+ FormatFloat(angle));
+ SetLayoutBackGroundAngle(angle);
+ MainRedraw();
+ }
+
+}
+/**
+ * Load Background Options from Saved Parms section [layout]
+*/
void
-LayoutBackGroundLoad(void) {
+LayoutBackGroundLoad(void)
+{
SetLayoutBackGroundFullPath(wPrefGetString("layout", "BackgroundPath"));
- wPrefGetFloat("layout", "BackgroundPosX", &thisLayout.props.backgroundPos.x, 0.0);
- wPrefGetFloat("layout", "BackgroundPosY", &thisLayout.props.backgroundPos.y, 0.0);
- wPrefGetFloat("layout", "BackgroundAngle", &thisLayout.props.backgroundAngle, 0.0);
+ wPrefGetFloat("layout", "BackgroundPosX", &thisLayout.props.backgroundPos.x,
+ 0.0);
+ wPrefGetFloat("layout", "BackgroundPosY", &thisLayout.props.backgroundPos.y,
+ 0.0);
+ wPrefGetFloat("layout", "BackgroundAngle", &thisLayout.props.backgroundAngle,
+ 0.0);
long screen_long;
wPrefGetInteger("layout", "BackgroundScreen", &screen_long, 0L);
thisLayout.props.backgroundScreen = screen_long;
- wPrefGetFloat("layout", "BackgroundSize", &thisLayout.props.backgroundSize, 0.0);
+ wPrefGetFloat("layout", "BackgroundSize", &thisLayout.props.backgroundSize,
+ 0.0);
}
static wBool_t inited;
-/**************************************************************************************
- * Either Clear Background Parms or (if the first time called) Load from Saved Parms
- **************************************************************************************/
+/**
+ * @brief Either Clear Background Parms or (if the first time called) Load from Saved Parms
+ * @param clear TRUE: Background is cleared, FALSE: Background is loaded (if defined)
+*/
void
-LayoutBackGroundInit(BOOL_T clear) {
+LayoutBackGroundInit(BOOL_T clear)
+{
if (clear) {
SetLayoutBackGroundFullPath(noname);
SetLayoutBackGroundPos(zero);
@@ -743,31 +987,48 @@ LayoutBackGroundInit(BOOL_T clear) {
}
char * str = GetLayoutBackGroundFullPath();
if (str && str[0]) {
- haveBackground = true;
- if (!LoadBackGroundImage()) { //Failed -> Wipe Out
+ haveBackground = true;
+ if (!LoadBackGroundImage()) { //Failed -> Wipe Out
SetLayoutBackGroundFullPath(noname);
SetLayoutBackGroundPos(zero);
SetLayoutBackGroundAngle(0.0);
SetLayoutBackGroundScreen(0);
SetLayoutBackGroundSize(0.0);
LayoutBackGroundSave();
- haveBackground = false;
+ haveBackground = false;
}
} else {
haveBackground = false;
+ }
+
+ if ( haveBackground ) {
+ char *error;
+ if (wDrawSetBackground( mainD.d, str, &error) == -1) {
+ NoticeMessage(_("Unable to load Image File - %s"),_("Ok"),NULL,error);
+ haveBackground = false;
+ }
+ } else {
wDrawSetBackground( mainD.d, NULL, NULL);
}
+ SetName();
}
+/**
+ * Read the settings defined in the file from sections [misc] and [DialogItem]
+ * @param files Number of files chosen
+ * @param fileName Filename(s) shosen. Only the first is used
+ * @param data Not used
+ * @return TRUE (always)
+*/
EXPORT int DoSettingsRead(
- int files,
- char ** fileName,
- void * data )
+ int files,
+ char ** fileName,
+ void * data )
{
char * pref;
- assert( files == 1 );
- if (fileName == NULL) wPrefsLoad(NULL);
- else wPrefsLoad(fileName[0]);
+ CHECK( files == 1 );
+ if (fileName == NULL) { wPrefsLoad(NULL); }
+ else { wPrefsLoad(fileName[0]); }
// get the preferred scale from the new configuration file
pref = wPrefGetString("misc", "scale");
if (pref) {
@@ -777,13 +1038,16 @@ EXPORT int DoSettingsRead(
}
//Get command options
wPrefGetInteger("DialogItem","cmdopt-preselect",&preSelect,preSelect);
- wPrefGetInteger("DialogItem","cmdopt-rightclickmode",&rightClickMode,rightClickMode);
+ wPrefGetInteger("DialogItem","cmdopt-rightclickmode",&rightClickMode,
+ rightClickMode);
wPrefGetInteger("DialogItem","cmdopt-selectmode",&selectMode,selectMode);
wPrefGetInteger("DialogItem","cmdopt-selectzero",&selectZero,selectZero);
//Get Toolbar showing
wPrefGetInteger( "misc", "toolbarset",&toolbarSet,toolbarSet);
+ LayoutBackGroundInit( FALSE );
+
//Redraw the screen to reflect changes
MainProc( mainW, wResize_e, NULL, NULL );
return TRUE;
@@ -791,34 +1055,49 @@ EXPORT int DoSettingsRead(
static struct wFilSel_t * settingsRead_fs;
+/**
+ * @brief Read button in Layout. File Open dialog to read a Settings file (*.xset)
+ * @param void
+ */
static void SettingsRead( void )
{
if (settingsRead_fs == NULL)
settingsRead_fs = wFilSelCreate( mainW, FS_LOAD, 0, _("Read Settings"),
- _("Settings File (*.xset)|*.xset"), DoSettingsRead, NULL );
+ _("Settings File (*.xset)|*.xset"), DoSettingsRead, NULL );
bExample = FALSE;
wFilSelect( settingsRead_fs, wGetAppWorkDir());
}
+/**
+ * @brief Write the settings file (after Dialog)
+ * @param files Number of Files selected (must be 1)
+ * @param fileName The selected Filename
+ * @param data Not used
+ * @return TRUE (always)
+*/
static int DoSettingsWrite(
- int files,
- char ** fileName,
- void * data )
+ int files,
+ char ** fileName,
+ void * data )
{
- assert( fileName != NULL );
- assert( files == 1 );
+ CHECK( fileName != NULL );
+ CHECK( files == 1 );
wPrefFlush(fileName[0]);
return TRUE;
}
static struct wFilSel_t * settingsWrite_fs;
+/**
+ * @brief Write button in Layout. File Save dialog for a settings file (*.xset)
+ * @param void
+*/
static void SettingsWrite( void )
{
ChangeLayout();
if ( settingsWrite_fs == NULL )
settingsWrite_fs = wFilSelCreate( mainW, FS_UPDATE, 0, _("Write Settings"),
- _("Settings File (*.xset)|*.xset"), DoSettingsWrite, NULL );
+ _("Settings File (*.xset)|*.xset"), DoSettingsWrite, NULL );
wFilSelect( settingsWrite_fs, wGetAppWorkDir());
}