(svn r766) -Fix: compilation problems on windows
authordarkvater
Mon, 22 Nov 2004 20:49:42 +0000
changeset 484 3fad52d29f00
parent 483 e27622930ddc
child 485 453c096beb1b
(svn r766) -Fix: compilation problems on windows
-There is nothing wrong with uses spacebars in the code; they are not a luxury item
-Please use standard rowsizes of 14px and less magic numbers (highlighted items drawn in white as all other windows do)
-TYPEDEF structs (this goes to pasky!!)
settings_gui.c
--- a/settings_gui.c	Mon Nov 22 18:42:03 2004 +0000
+++ b/settings_gui.c	Mon Nov 22 20:49:42 2004 +0000
@@ -935,74 +935,76 @@
 	AllocateWindowDesc(&_patches_selection_desc);
 }
 
+struct GRFFile *_sel_grffile;
 
-
-struct GRFFile *_sel_grffile;
+enum {
+	NEwGRF_WND_PROC_OFFSET_TOP_WIDGET = 14,
+	NEWGRF_WND_PROC_ROWSIZE = 14
+};
 
 static void NewgrfWndProc(Window *w, WindowEvent *e)
 {
-	uint i=0;
-	switch(e->event) {
+	switch (e->event) {
 	case WE_PAINT: {
-		int x, y = 15;
-		struct GRFFile *c=_first_grffile;
+		int x, y = NEwGRF_WND_PROC_OFFSET_TOP_WIDGET;
+		uint16 i = 0;
+		struct GRFFile *c = _first_grffile;
 
 		DrawWindowWidgets(w);
 		
-		if(_first_grffile==NULL) { // no grf sets installed
+		if (_first_grffile == NULL) { // no grf sets installed
 			DrawStringMultiCenter(140, 240, STR_NEWGRF_NO_FILES_INSTALLED, 250);
 			break;
 		}
 
 		// draw list of all grf files
-		while(c!=NULL) {
-			if(i>=w->vscroll.pos) { // draw files according to scrollbar position
-				if(_sel_grffile==c) GfxFillRect(2, y-1, 267, y + 12, 10); // show highlighted item with a different background
-				DrawSprite(SPRITE_PALETTE(0x2EB | 0x30b8000), 5, y+2);
-				DoDrawString(c->filename, 25, y+2, 0x10); // will be grf name later
-				y+=15;
+		while (c != NULL) {
+			if (i >= w->vscroll.pos) { // draw files according to scrollbar position
+				DrawSprite(SPRITE_PALETTE(0x2EB | 0x30b8000), 5, y + 3);
+				// give highlighted item other colour
+				// XXX - will be grf name later
+				DoDrawString(c->filename, 25, y + 2, (_sel_grffile == c) ? 0xC : 0x10); 
+				y += NEWGRF_WND_PROC_ROWSIZE;
 			}
 			
-			c=c->next;
-			if(++i>=12+w->vscroll.pos) break; // stop after displaying 12 items
+			c = c->next;
+			if (++i == w->vscroll.cap + w->vscroll.pos) break; // stop after displaying 12 items
 		}
 
 // 		DoDrawString(_sel_grffile->setname, 120, 200, 0x01); // draw grf name
 
-		if(_sel_grffile==NULL) { // no grf file selected yet
-			DrawStringMultiCenter(140, 240, STR_NEWGRF_TIP, 250);
+		if (_sel_grffile == NULL) { // no grf file selected yet
+			DrawStringMultiCenter(140, 229, STR_NEWGRF_TIP, 250);
 		} else {
 			// draw filename
-			x = DrawString(5, 210, STR_NEWGRF_FILENAME, 0);
-			DoDrawString(_sel_grffile->filename, x+2, 210, 0x01);
+			x = DrawString(5, 199, STR_NEWGRF_FILENAME, 0);
+			DoDrawString(_sel_grffile->filename, x + 2, 199, 0x01);
 	
 			// draw grf id
-			x = DrawString(5, 220, STR_NEWGRF_GRF_ID, 0);
+			x = DrawString(5, 209, STR_NEWGRF_GRF_ID, 0);
 			SET_DPARAM16(0, _sel_grffile->grfid);
-			DrawString(x+2, 220, STR_7024, 0x01);
+			DrawString(x + 2, 209, STR_7024, 0x01);
 		}
-
-		} break;
+	} break;
 
 	case WE_CLICK:
 		switch(e->click.widget) {
 		case 2: { // select a grf file
-			int y;
+			int y = (e->click.pt.y - NEwGRF_WND_PROC_OFFSET_TOP_WIDGET) / NEWGRF_WND_PROC_ROWSIZE;
 
-			y = e->click.pt.y - 16;
-			if (y < 0) return;
+			if (y >= w->vscroll.cap) { return;} // click out of bounds
 
-			y = (y/15) + w->vscroll.pos; // calc selected item
+			y += w->vscroll.pos;
+
 			if (y >= _grffile_count) return;
 
 			_sel_grffile = _first_grffile;
-			while(y) {
-				_sel_grffile = _sel_grffile->next;
-				y--;
-			}
+			// get selected grf-file
+			while (y-- != 0) _sel_grffile = _sel_grffile->next;
+
 			SetWindowDirty(w);
-			} break;
-		case 9:
+		} break;
+		case 9: /* Cancel button */
 			DeleteWindowById(WC_GAME_OPTIONS, 0);
 			break;
 		} break;
@@ -1029,22 +1031,22 @@
 static const Widget _newgrf_widgets[] = {
 {   WWT_CLOSEBOX,    14,     0,    10,     0,    13, STR_00C5,									STR_018B_CLOSE_WINDOW},
 {    WWT_CAPTION,    14,    11,   279,     0,    13, STR_NEWGRF_SETINGS_CAPTION,STR_018C_WINDOW_TITLE_DRAG_THIS},
-{     WWT_MATRIX,    14,     0,   268,    14,   193, 0xC01,											STR_NEWGRF_TIP},
-{      WWT_PANEL,    14,     0,   279,   194,   332, 0x0,												STR_NULL},
-
-{  WWT_SCROLLBAR,    14,   269,   279,    14,   193, 0x0,												STR_0190_SCROLL_BAR_SCROLLS_LIST},
+{     WWT_MATRIX,    14,     0,   268,    14,   182, 0xC01,/*small rows*/				STR_NEWGRF_TIP},
+{      WWT_PANEL,    14,     0,   279,   183,   321, 0x0,												STR_NULL},
 
-{   WWT_CLOSEBOX,    14,   147,   158,   300,   311, STR_0188,	STR_NULL},
-{   WWT_CLOSEBOX,    14,   159,   170,   300,   311, STR_0189,	STR_NULL},
-{   WWT_CLOSEBOX,    14,   175,   274,   300,   311, STR_NEWGRF_SET_PARAMETERS,	STR_NULL},
+{  WWT_SCROLLBAR,    14,   269,   279,    14,   182, 0x0,												STR_0190_SCROLL_BAR_SCROLLS_LIST},
 
-{   WWT_CLOSEBOX,     3,     5,   138,   317,   328, STR_NEWGRF_APPLY_CHANGES,	STR_NULL},
-{   WWT_CLOSEBOX,     3,   142,   274,   317,   328, STR_012E_CANCEL,						STR_NULL},
+{   WWT_CLOSEBOX,    14,   147,   158,   289,   300, STR_0188,	STR_NULL},
+{   WWT_CLOSEBOX,    14,   159,   170,   289,   300, STR_0189,	STR_NULL},
+{   WWT_CLOSEBOX,    14,   175,   274,   289,   300, STR_NEWGRF_SET_PARAMETERS,	STR_NULL},
+
+{   WWT_CLOSEBOX,     3,     5,   138,   306,   317, STR_NEWGRF_APPLY_CHANGES,	STR_NULL},
+{   WWT_CLOSEBOX,     3,   142,   274,   306,   317, STR_012E_CANCEL,						STR_NULL},
 {   WIDGETS_END},
 };
 
 static const WindowDesc _newgrf_desc = {
-	WDP_CENTER, WDP_CENTER, 280, 333,
+	WDP_CENTER, WDP_CENTER, 280, 322,
 	WC_GAME_OPTIONS,0,
 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
 	_newgrf_widgets,
@@ -1059,11 +1061,11 @@
 
 	{ // little helper function to calculate _grffile_count
 	  // should be REMOVED once _grffile_count is calculated at loading
-		_grffile_count=0;
-		struct GRFFile *c=_first_grffile;
-		while(c!=NULL) {
+		struct GRFFile *c = _first_grffile;
+		_grffile_count = 0;
+		while (c != NULL) {
 			_grffile_count++;
-			c=c->next;
+			c = c->next;
 		}
 	}