summaryrefslogtreecommitdiff
path: root/app/bin/dlayer.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/bin/dlayer.c')
-rw-r--r--app/bin/dlayer.c143
1 files changed, 130 insertions, 13 deletions
diff --git a/app/bin/dlayer.c b/app/bin/dlayer.c
index 70f613f..352dbe1 100644
--- a/app/bin/dlayer.c
+++ b/app/bin/dlayer.c
@@ -29,6 +29,7 @@
#include "dynstring.h"
#include "fileio.h"
#include "i18n.h"
+#include "layout.h"
#include "messages.h"
#include "param.h"
#include "track.h"
@@ -43,6 +44,7 @@
#define LAYERPREF_FROZEN (1)
#define LAYERPREF_ONMAP (2)
#define LAYERPREF_VISIBLE (4)
+#define LAYERPREF_MODULE (8)
#define LAYERPREF_SECTION ("Layers")
#define LAYERPREF_NAME "name"
#define LAYERPREF_COLOR "color"
@@ -66,9 +68,11 @@ static wList_p setLayerL;
typedef struct {
char name[STR_SHORT_SIZE]; /**< Layer name */
wDrawColor color; /**< layer color, is an index into a color table */
+ BOOL_T useColor; /**< Use Layer color */
BOOL_T frozen; /**< Frozen flag */
BOOL_T visible; /**< visible flag */
BOOL_T onMap; /**< is layer shown map */
+ BOOL_T module; /**< is layer a module (all or nothing) */
long objCount; /**< number of objects on layer */
} layer_t;
@@ -176,6 +180,22 @@ BOOL_T GetLayerOnMap(unsigned int layer)
}
}
+BOOL_T GetLayerModule(unsigned int layer)
+{
+ if (!IsLayerValid(layer)) {
+ return TRUE;
+ } else {
+ return layers[layer].module;
+ }
+}
+
+void SetLayerModule(unsigned int layer, BOOL_T module)
+{
+ if (IsLayerValid(layer)) {
+ layers[layer].module = module;
+ }
+}
+
char * GetLayerName(unsigned int layer)
{
@@ -186,11 +206,26 @@ char * GetLayerName(unsigned int layer)
}
}
+void SetLayerName(unsigned int layer, char* name) {
+ if (IsLayerValid(layer)) {
+ strcpy(layers[layer].name,name);
+ }
+}
+
+BOOL_T GetLayerUseColor(unsigned int layer) {
+ return layers[layer].useColor;
+}
+
wDrawColor GetLayerColor(unsigned int layer)
{
return layers[layer].color;
}
+static void RedrawLayer( unsigned int l, BOOL_T draw )
+{
+ DoRedraw(); // RedrawLayer
+}
+
static void FlipLayer(unsigned int layer)
{
@@ -218,7 +253,7 @@ static void FlipLayer(unsigned int layer)
RedrawLayer(layer, TRUE);
}
-static void SetCurrLayer(wIndex_t inx, const char * name, wIndex_t op,
+void SetCurrLayer(wIndex_t inx, const char * name, wIndex_t op,
void * listContext, void * arg)
{
unsigned int newLayer = (unsigned int)inx;
@@ -422,9 +457,11 @@ static wDrawColor layerColorTab[COUNT(layerRawColorTab)];
static wWin_p layerW;
static char layerName[STR_SHORT_SIZE];
static wDrawColor layerColor;
+static long layerUseColor = TRUE;
static long layerVisible = TRUE;
static long layerFrozen = FALSE;
static long layerOnMap = TRUE;
+static long layerModule = FALSE;
static void LayerOk(void *);
static BOOL_T layerRedrawMap = FALSE;
@@ -435,6 +472,8 @@ static BOOL_T layerRedrawMap = FALSE;
static char *visibleLabels[] = { "", NULL };
static char *frozenLabels[] = { "", NULL };
static char *onMapLabels[] = { "", NULL };
+static char *moduleLabels[] = { "", NULL };
+static char *layerColorLabels[] = { "", NULL };
static paramIntegerRange_t i0_20 = { 0, NUM_BUTTONS };
static paramData_t layerPLs[] = {
@@ -444,13 +483,17 @@ static paramData_t layerPLs[] = {
{ PD_STRING, layerName, "name", PDO_NOPREF|PDO_STRINGLIMITLENGTH, (void*)(250-54), N_("Name"), 0, 0, sizeof(layerName) },
#define I_COLOR (2)
{ PD_COLORLIST, &layerColor, "color", PDO_NOPREF, NULL, N_("Color") },
-#define I_VIS (3)
+#define I_USE_COLOR (3)
+ { PD_TOGGLE, &layerUseColor, "layercolor", PDO_NOPREF|PDO_DLGHORZ, layerColorLabels, N_("Use Color"), BC_HORZ|BC_NOBORDER },
+#define I_VIS (4)
{ PD_TOGGLE, &layerVisible, "visible", PDO_NOPREF, visibleLabels, N_("Visible"), BC_HORZ|BC_NOBORDER },
-#define I_FRZ (4)
+#define I_FRZ (5)
{ PD_TOGGLE, &layerFrozen, "frozen", PDO_NOPREF|PDO_DLGHORZ, frozenLabels, N_("Frozen"), BC_HORZ|BC_NOBORDER },
-#define I_MAP (5)
+#define I_MAP (6)
{ PD_TOGGLE, &layerOnMap, "onmap", PDO_NOPREF|PDO_DLGHORZ, onMapLabels, N_("On Map"), BC_HORZ|BC_NOBORDER },
-#define I_COUNT (6)
+#define I_MOD (7)
+ { PD_TOGGLE, &layerModule, "module", PDO_NOPREF|PDO_DLGHORZ, moduleLabels, N_("Module"), BC_HORZ|BC_NOBORDER },
+#define I_COUNT (8)
{ PD_STRING, NULL, "object-count", PDO_NOPREF|PDO_DLGBOXEND, (void*)(80), N_("Count"), BO_READONLY },
{ PD_MESSAGE, N_("Personal Preferences"), NULL, PDO_DLGRESETMARGIN, (void *)180 },
{ PD_BUTTON, (void*)DoLayerOp, "reset", PDO_DLGRESETMARGIN, 0, N_("Load"), 0, (void *)ENUMLAYER_RELOAD },
@@ -477,6 +520,7 @@ LayerSystemDefaults(void)
layers[inx].visible = TRUE;
layers[inx].frozen = FALSE;
layers[inx].onMap = TRUE;
+ layers[inx].module = FALSE;
layers[inx].objCount = 0;
SetLayerColor(inx, layerColorTab[inx%COUNT(layerColorTab)]);
}
@@ -547,7 +591,7 @@ static void DoLayerOp(void * data)
if (layoutLayerChanged) {
MainProc(mainW, wResize_e, NULL, NULL);
layoutLayerChanged = FALSE;
- changed = TRUE;
+ changed++;
SetWindowTitle();
}
}
@@ -566,7 +610,9 @@ UpdateLayerDlg()
layerVisible = layers[curLayer].visible;
layerFrozen = layers[curLayer].frozen;
layerOnMap = layers[curLayer].onMap;
+ layerModule = layers[curLayer].module;
layerColor = layers[curLayer].color;
+ layerUseColor = layers[curLayer].useColor;
strcpy(layerName, layers[curLayer].name);
layerCurrent = curLayer;
/* now re-load the layer list boxes */
@@ -588,6 +634,28 @@ UpdateLayerDlg()
}
/**
+ * Fill a layer dropbox with the current layer settings
+ *
+ * \param listLayers the dropbox
+ * \return
+ */
+
+void
+FillLayerList( wList_p listLayers)
+{
+ wListClear(listLayers); // Rebuild list on each invovation
+
+ for (int inx = 0; inx < NUM_LAYERS; inx++) {
+ char *layerFormattedName;
+ layerFormattedName = FormatLayerName(inx);
+ wListAddValue((wList_p)listLayers, layerFormattedName, NULL, (void*)(long)inx);
+ free(layerFormattedName);
+ }
+
+ /* set current layer to selected */
+ wListSetIndex(listLayers, curLayer);
+}
+/**
* Initialize the layer lists.
*
* \param IN pointer to function that actually initialize tha data structures
@@ -646,6 +714,10 @@ LayerPrefSave(void)
flags |= LAYERPREF_VISIBLE;
}
+ if (layers[inx].module) {
+ flags |= LAYERPREF_MODULE;
+ }
+
sprintf(buffer, LAYERPREF_FLAGS ".%0u", inx);
wPrefSetInteger(LAYERPREF_SECTION, buffer, flags);
@@ -710,6 +782,7 @@ LayerPrefLoad(void)
layers[inx].frozen = ((flags & LAYERPREF_FROZEN) != 0);
layers[inx].onMap = ((flags & LAYERPREF_ONMAP) != 0);
layers[inx].visible = ((flags & LAYERPREF_VISIBLE) != 0);
+ layers[inx].module = ((flags & LAYERPREF_MODULE) !=0);
prefString = strtok(NULL, ",");
}
}
@@ -761,6 +834,15 @@ void LayerSetCounts(void)
}
}
+int FindUnusedLayer(unsigned int start) {
+ int inx;
+ for (inx=start; inx<NUM_LAYERS; inx++) {
+ if (layers[inx].objCount == 0 && !layers[inx].frozen) return inx;
+ }
+ ErrorMessage( MSG_NO_EMPTY_LAYER );
+ return -1;
+}
+
/**
* Reset layer options to their default values. The default values are loaded
* from the preferences file.
@@ -805,12 +887,20 @@ static void LayerUpdate(void)
ParamLoadControl(&layerPG, I_VIS);
}
+ if (layerCurrent == curLayer && layerModule) {
+ NoticeMessage(MSG_LAYER_MODULE, _("Ok"), NULL);
+ layerModule = FALSE;
+ ParamLoadControl(&layerPG, I_MOD);
+ }
+
if (strcmp(layers[(int)layerCurrent].name, layerName) ||
layerColor != layers[(int)layerCurrent].color ||
+ layers[(int)layerCurrent].useColor != (BOOL_T)layerUseColor ||
layers[(int)layerCurrent].visible != (BOOL_T)layerVisible ||
layers[(int)layerCurrent].frozen != (BOOL_T)layerFrozen ||
- layers[(int)layerCurrent].onMap != (BOOL_T)layerOnMap) {
- changed = TRUE;
+ layers[(int)layerCurrent].onMap != (BOOL_T)layerOnMap ||
+ layers[(int)layerCurrent].module != (BOOL_T)layerModule) {
+ changed++;
SetWindowTitle();
}
@@ -837,6 +927,7 @@ static void LayerUpdate(void)
}
redraw = (layerColor != layers[(int)layerCurrent].color ||
+ layers[(int)layerCurrent].useColor != (BOOL_T)layerUseColor ||
(BOOL_T)layerVisible != layers[(int)layerCurrent].visible);
if ((!layerRedrawMap) && redraw) {
@@ -850,9 +941,11 @@ static void LayerUpdate(void)
wButtonSetBusy(layer_btns[(int)layerCurrent], layerVisible);
}
+ layers[(int)layerCurrent].useColor = (BOOL_T)layerUseColor;
layers[(int)layerCurrent].visible = (BOOL_T)layerVisible;
layers[(int)layerCurrent].frozen = (BOOL_T)layerFrozen;
layers[(int)layerCurrent].onMap = (BOOL_T)layerOnMap;
+ layers[(int)layerCurrent].module = (BOOL_T)layerModule;
if (layerRedrawMap) {
DoRedraw();
@@ -878,7 +971,9 @@ static void LayerSelect(
layerVisible = layers[inx].visible;
layerFrozen = layers[inx].frozen;
layerOnMap = layers[inx].onMap;
+ layerModule = layers[inx].module;
layerColor = layers[inx].color;
+ layerUseColor = layers[inx].useColor;
sprintf(message, "%ld", layers[inx].objCount);
ParamLoadMessage(&layerPG, I_COUNT, message);
ParamLoadControls(&layerPG);
@@ -893,6 +988,7 @@ void ResetLayers(void)
layers[inx].visible = TRUE;
layers[inx].frozen = FALSE;
layers[inx].onMap = TRUE;
+ layers[inx].module = FALSE;
layers[inx].objCount = 0;
SetLayerColor(inx, layerColorTab[inx%COUNT(layerColorTab)]);
@@ -911,7 +1007,9 @@ void ResetLayers(void)
layerVisible = TRUE;
layerFrozen = FALSE;
layerOnMap = TRUE;
+ layerModule = FALSE;
layerColor = layers[0].color;
+ layerUseColor = TRUE;
strcpy(layerName, layers[0].name);
LoadLayerLists();
@@ -1024,7 +1122,7 @@ static void DoLayer(void * junk)
{
if (layerW == NULL) {
layerW = ParamCreateDialog(&layerPG, MakeWindowTitle(_("Layers")), _("Done"),
- LayerOk, NULL, TRUE, NULL, 0, LayerDlgUpdate);
+ LayerOk, wHide, TRUE, NULL, 0, LayerDlgUpdate);
}
/* set the globals to the values for the current layer */
@@ -1038,7 +1136,7 @@ static void DoLayer(void * junk)
BOOL_T ReadLayers(char * line)
{
char * name;
- int inx, visible, frozen, color, onMap;
+ int inx, visible, frozen, color, onMap, module, dontUseColor, ColorFlags;
unsigned long rgb;
/* older files didn't support layers */
@@ -1069,7 +1167,7 @@ BOOL_T ReadLayers(char * line)
/* get the properties for a layer from the file and update the layer accordingly */
- if (!GetArgs(line, "ddddu0000q", &inx, &visible, &frozen, &onMap, &rgb,
+ if (!GetArgs(line, "dddduddd0q", &inx, &visible, &frozen, &onMap, &rgb, &module, &dontUseColor, &ColorFlags,
&name)) {
return FALSE;
}
@@ -1093,7 +1191,12 @@ BOOL_T ReadLayers(char * line)
layers[inx].visible = visible;
layers[inx].frozen = frozen;
layers[inx].onMap = onMap;
+ layers[inx].module = module;
layers[inx].color = color;
+ layers[inx].useColor = !dontUseColor;
+
+ colorTrack = ColorFlags&1; //Make sure globals are set
+ colorDraw = ColorFlags&2;
if (inx<NUM_BUTTONS) {
if (strlen(name) > 0) {
@@ -1117,12 +1220,13 @@ BOOL_T ReadLayers(char * line)
* \return TRUE if configured, FALSE if not
*/
-bool
+BOOL_T
IsLayerConfigured(unsigned int layerNumber)
{
return (!layers[layerNumber].visible ||
layers[layerNumber].frozen ||
!layers[layerNumber].onMap ||
+ layers[layerNumber].module ||
layers[layerNumber].color !=
layerColorTab[layerNumber % (COUNT(layerColorTab))] ||
layers[layerNumber].name[0] ||
@@ -1140,6 +1244,11 @@ BOOL_T WriteLayers(FILE * f)
{
unsigned int inx;
+ int ColorFlags = 0;
+
+ if (colorTrack) ColorFlags |= 1;
+ if (colorDraw) ColorFlags |= 2;
+
for (inx = 0; inx < NUM_LAYERS; inx++) {
if (IsLayerConfigured(inx)) {
fprintf(f, "LAYERS %u %d %d %d %ld %d %d %d %d \"%s\"\n",
@@ -1148,7 +1257,9 @@ BOOL_T WriteLayers(FILE * f)
layers[inx].frozen,
layers[inx].onMap,
wDrawGetRGB(layers[inx].color),
- 0, 0, 0, 0,
+ layers[inx].module,
+ layers[inx].useColor?0:1,
+ ColorFlags, 0,
PutTitle(layers[inx].name));
}
}
@@ -1157,6 +1268,7 @@ BOOL_T WriteLayers(FILE * f)
return TRUE;
}
+#include "bitmaps/background.xpm"
void InitLayers(void)
{
@@ -1173,6 +1285,7 @@ void InitLayers(void)
show_layer_bmps[i] = wIconCreateBitMap(l1_width, l1_height, show_layer_bits[i],
layerColorTab[i%(COUNT(layerColorTab))]);
layers[i].color = layerColorTab[i%(COUNT(layerColorTab))];
+ layers[i].useColor = TRUE;
}
/* layer list for toolbar */
@@ -1180,6 +1293,10 @@ void InitLayers(void)
SetCurrLayer, NULL);
wControlSetBalloonText((wControl_p)setLayerL, GetBalloonHelpStr("cmdLayerSet"));
AddToolbarControl((wControl_p)setLayerL, IC_MODETRAIN_TOO);
+
+ backgroundB = AddToolbarButton("cmdBackgroundShow", wIconCreatePixMap(background), 0,
+ (addButtonCallBack_t)BackgroundToggleShow, NULL);
+ wControlActive((wControl_p)backgroundB, FALSE);
for (i = 0; i<NUM_LAYERS; i++) {
char *layerName;