1
0
Fork 0

(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!!)
release/0.4.5
darkvater 2004-11-22 20:49:42 +00:00
parent d51887fbed
commit d4b723a7c9
1 changed files with 48 additions and 46 deletions

View File

@ -935,74 +935,76 @@ void ShowPatchesSelection()
AllocateWindowDesc(&_patches_selection_desc); 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) static void NewgrfWndProc(Window *w, WindowEvent *e)
{ {
uint i=0; switch (e->event) {
switch(e->event) {
case WE_PAINT: { case WE_PAINT: {
int x, y = 15; int x, y = NEwGRF_WND_PROC_OFFSET_TOP_WIDGET;
struct GRFFile *c=_first_grffile; uint16 i = 0;
struct GRFFile *c = _first_grffile;
DrawWindowWidgets(w); 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); DrawStringMultiCenter(140, 240, STR_NEWGRF_NO_FILES_INSTALLED, 250);
break; break;
} }
// draw list of all grf files // draw list of all grf files
while(c!=NULL) { while (c != NULL) {
if(i>=w->vscroll.pos) { // draw files according to scrollbar position 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 + 3);
DrawSprite(SPRITE_PALETTE(0x2EB | 0x30b8000), 5, y+2); // give highlighted item other colour
DoDrawString(c->filename, 25, y+2, 0x10); // will be grf name later // XXX - will be grf name later
y+=15; DoDrawString(c->filename, 25, y + 2, (_sel_grffile == c) ? 0xC : 0x10);
y += NEWGRF_WND_PROC_ROWSIZE;
} }
c=c->next; c = c->next;
if(++i>=12+w->vscroll.pos) break; // stop after displaying 12 items if (++i == w->vscroll.cap + w->vscroll.pos) break; // stop after displaying 12 items
} }
// DoDrawString(_sel_grffile->setname, 120, 200, 0x01); // draw grf name // DoDrawString(_sel_grffile->setname, 120, 200, 0x01); // draw grf name
if(_sel_grffile==NULL) { // no grf file selected yet if (_sel_grffile == NULL) { // no grf file selected yet
DrawStringMultiCenter(140, 240, STR_NEWGRF_TIP, 250); DrawStringMultiCenter(140, 229, STR_NEWGRF_TIP, 250);
} else { } else {
// draw filename // draw filename
x = DrawString(5, 210, STR_NEWGRF_FILENAME, 0); x = DrawString(5, 199, STR_NEWGRF_FILENAME, 0);
DoDrawString(_sel_grffile->filename, x+2, 210, 0x01); DoDrawString(_sel_grffile->filename, x + 2, 199, 0x01);
// draw grf id // 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); 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: case WE_CLICK:
switch(e->click.widget) { switch(e->click.widget) {
case 2: { // select a grf file 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 >= w->vscroll.cap) { return;} // click out of bounds
if (y < 0) return;
y += w->vscroll.pos;
y = (y/15) + w->vscroll.pos; // calc selected item
if (y >= _grffile_count) return; if (y >= _grffile_count) return;
_sel_grffile = _first_grffile; _sel_grffile = _first_grffile;
while(y) { // get selected grf-file
_sel_grffile = _sel_grffile->next; while (y-- != 0) _sel_grffile = _sel_grffile->next;
y--;
}
SetWindowDirty(w); SetWindowDirty(w);
} break; } break;
case 9: case 9: /* Cancel button */
DeleteWindowById(WC_GAME_OPTIONS, 0); DeleteWindowById(WC_GAME_OPTIONS, 0);
break; break;
} break; } break;
@ -1029,22 +1031,22 @@ static void NewgrfWndProc(Window *w, WindowEvent *e)
static const Widget _newgrf_widgets[] = { static const Widget _newgrf_widgets[] = {
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, { 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_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_MATRIX, 14, 0, 268, 14, 182, 0xC01,/*small rows*/ STR_NEWGRF_TIP},
{ WWT_PANEL, 14, 0, 279, 194, 332, 0x0, STR_NULL}, { WWT_PANEL, 14, 0, 279, 183, 321, 0x0, STR_NULL},
{ WWT_SCROLLBAR, 14, 269, 279, 14, 193, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, { WWT_SCROLLBAR, 14, 269, 279, 14, 182, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WWT_CLOSEBOX, 14, 147, 158, 300, 311, STR_0188, STR_NULL}, { WWT_CLOSEBOX, 14, 147, 158, 289, 300, STR_0188, STR_NULL},
{ WWT_CLOSEBOX, 14, 159, 170, 300, 311, STR_0189, STR_NULL}, { WWT_CLOSEBOX, 14, 159, 170, 289, 300, STR_0189, STR_NULL},
{ WWT_CLOSEBOX, 14, 175, 274, 300, 311, STR_NEWGRF_SET_PARAMETERS, STR_NULL}, { WWT_CLOSEBOX, 14, 175, 274, 289, 300, STR_NEWGRF_SET_PARAMETERS, STR_NULL},
{ WWT_CLOSEBOX, 3, 5, 138, 317, 328, STR_NEWGRF_APPLY_CHANGES, STR_NULL}, { WWT_CLOSEBOX, 3, 5, 138, 306, 317, STR_NEWGRF_APPLY_CHANGES, STR_NULL},
{ WWT_CLOSEBOX, 3, 142, 274, 317, 328, STR_012E_CANCEL, STR_NULL}, { WWT_CLOSEBOX, 3, 142, 274, 306, 317, STR_012E_CANCEL, STR_NULL},
{ WIDGETS_END}, { WIDGETS_END},
}; };
static const WindowDesc _newgrf_desc = { static const WindowDesc _newgrf_desc = {
WDP_CENTER, WDP_CENTER, 280, 333, WDP_CENTER, WDP_CENTER, 280, 322,
WC_GAME_OPTIONS,0, WC_GAME_OPTIONS,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
_newgrf_widgets, _newgrf_widgets,
@ -1059,11 +1061,11 @@ void ShowNewgrf()
{ // little helper function to calculate _grffile_count { // little helper function to calculate _grffile_count
// should be REMOVED once _grffile_count is calculated at loading // should be REMOVED once _grffile_count is calculated at loading
_grffile_count=0; struct GRFFile *c = _first_grffile;
struct GRFFile *c=_first_grffile; _grffile_count = 0;
while(c!=NULL) { while (c != NULL) {
_grffile_count++; _grffile_count++;
c=c->next; c = c->next;
} }
} }