src/widget.cpp
branchnoai
changeset 9826 9707ad4c9b60
parent 9724 b39bc69bb2f2
child 10142 56ee7da4ad56
equal deleted inserted replaced
9825:cc77111ebd85 9826:9707ad4c9b60
    52 {
    52 {
    53 	int mi, ma, pos;
    53 	int mi, ma, pos;
    54 	Scrollbar *sb;
    54 	Scrollbar *sb;
    55 
    55 
    56 	switch (wi->type) {
    56 	switch (wi->type) {
    57 		case WWT_SCROLLBAR: {
    57 		case WWT_SCROLLBAR:
    58 			/* vertical scroller */
    58 			/* vertical scroller */
    59 			w->flags4 &= ~WF_HSCROLL;
    59 			w->flags4 &= ~WF_HSCROLL;
    60 			w->flags4 &= ~WF_SCROLL2;
    60 			w->flags4 &= ~WF_SCROLL2;
    61 			mi = wi->top;
    61 			mi = wi->top;
    62 			ma = wi->bottom;
    62 			ma = wi->bottom;
    63 			pos = y;
    63 			pos = y;
    64 			sb = &w->vscroll;
    64 			sb = &w->vscroll;
    65 			break;
    65 			break;
    66 		}
    66 
    67 		case WWT_SCROLL2BAR: {
    67 		case WWT_SCROLL2BAR:
    68 			/* 2nd vertical scroller */
    68 			/* 2nd vertical scroller */
    69 			w->flags4 &= ~WF_HSCROLL;
    69 			w->flags4 &= ~WF_HSCROLL;
    70 			w->flags4 |= WF_SCROLL2;
    70 			w->flags4 |= WF_SCROLL2;
    71 			mi = wi->top;
    71 			mi = wi->top;
    72 			ma = wi->bottom;
    72 			ma = wi->bottom;
    73 			pos = y;
    73 			pos = y;
    74 			sb = &w->vscroll2;
    74 			sb = &w->vscroll2;
    75 			break;
    75 			break;
    76 		}
    76 
    77 		case  WWT_HSCROLLBAR: {
    77 		case  WWT_HSCROLLBAR:
    78 			/* horizontal scroller */
    78 			/* horizontal scroller */
    79 			w->flags4 &= ~WF_SCROLL2;
    79 			w->flags4 &= ~WF_SCROLL2;
    80 			w->flags4 |= WF_HSCROLL;
    80 			w->flags4 |= WF_HSCROLL;
    81 			mi = wi->left;
    81 			mi = wi->left;
    82 			ma = wi->right;
    82 			ma = wi->right;
    83 			pos = x;
    83 			pos = x;
    84 			sb = &w->hscroll;
    84 			sb = &w->hscroll;
    85 			break;
    85 			break;
    86 		}
    86 
    87 		default: return; //this should never happen
    87 		default: NOT_REACHED();
    88 	}
    88 	}
    89 	if (pos <= mi+9) {
    89 	if (pos <= mi+9) {
    90 		/* Pressing the upper button? */
    90 		/* Pressing the upper button? */
    91 		w->flags4 |= WF_SCROLL_UP;
    91 		w->flags4 |= WF_SCROLL_UP;
    92 		if (_scroller_click_timeout == 0) {
    92 		if (_scroller_click_timeout == 0) {
    93 			_scroller_click_timeout = 6;
    93 			_scroller_click_timeout = 6;
    94 			if (sb->pos != 0) sb->pos--;
    94 			if (sb->pos != 0) sb->pos--;
    95 		}
    95 		}
    96 		_left_button_clicked = false;
    96 		_left_button_clicked = false;
    97 	} else if (pos >= ma-10) {
    97 	} else if (pos >= ma - 10) {
    98 		/* Pressing the lower button? */
    98 		/* Pressing the lower button? */
    99 		w->flags4 |= WF_SCROLL_DOWN;
    99 		w->flags4 |= WF_SCROLL_DOWN;
   100 
   100 
   101 		if (_scroller_click_timeout == 0) {
   101 		if (_scroller_click_timeout == 0) {
   102 			_scroller_click_timeout = 6;
   102 			_scroller_click_timeout = 6;
   214 			if ((wi->type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++;
   214 			if ((wi->type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++;
   215 			DrawSprite(img, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked);
   215 			DrawSprite(img, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked);
   216 			break;
   216 			break;
   217 		}
   217 		}
   218 
   218 
   219 		case WWT_PANEL: {
   219 		case WWT_PANEL:
   220 			assert(wi->data == 0);
   220 			assert(wi->data == 0);
   221 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   221 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   222 			break;
   222 			break;
   223 		}
   223 
       
   224 		case WWT_EDITBOX:
       
   225 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_LOWERED | FR_DARKENED);
       
   226 			break;
   224 
   227 
   225 		case WWT_TEXTBTN:
   228 		case WWT_TEXTBTN:
   226 		case WWT_TEXTBTN_2: {
   229 		case WWT_TEXTBTN_2:
   227 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   230 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   228 			}
   231 			/* FALL THROUGH */
   229 		/* fall through */
       
   230 
   232 
   231 		case WWT_LABEL: {
   233 		case WWT_LABEL: {
   232 			StringID str = wi->data;
   234 			StringID str = wi->data;
   233 
   235 
   234 			if ((wi->type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
   236 			if ((wi->type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
   251 			if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 1, str, TC_FROMSTRING, r.right - r.left - 10);
   253 			if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 1, str, TC_FROMSTRING, r.right - r.left - 10);
   252 			break;
   254 			break;
   253 		}
   255 		}
   254 
   256 
   255 		case WWT_MATRIX: {
   257 		case WWT_MATRIX: {
   256 			int c, d, ctr;
       
   257 			int x, amt1, amt2;
       
   258 			int color;
       
   259 
       
   260 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   258 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   261 
   259 
   262 			c = GB(wi->data, 0, 8);
   260 			int c = GB(wi->data, 0, 8);
   263 			amt1 = (wi->right - wi->left + 1) / c;
   261 			int amt1 = (wi->right - wi->left + 1) / c;
   264 
   262 
   265 			d = GB(wi->data, 8, 8);
   263 			int d = GB(wi->data, 8, 8);
   266 			amt2 = (wi->bottom - wi->top + 1) / d;
   264 			int amt2 = (wi->bottom - wi->top + 1) / d;
   267 
   265 
   268 			color = _colour_gradient[wi->color & 0xF][6];
   266 			int color = _colour_gradient[wi->color & 0xF][6];
   269 
   267 
   270 			x = r.left;
   268 			int x = r.left;
   271 			for (ctr = c; ctr > 1; ctr--) {
   269 			for (int ctr = c; ctr > 1; ctr--) {
   272 				x += amt1;
   270 				x += amt1;
   273 				GfxFillRect(x, r.top + 1, x, r.bottom - 1, color);
   271 				GfxFillRect(x, r.top + 1, x, r.bottom - 1, color);
   274 			}
   272 			}
   275 
   273 
   276 			x = r.top;
   274 			x = r.top;
   277 			for (ctr = d; ctr > 1; ctr--) {
   275 			for (int ctr = d; ctr > 1; ctr--) {
   278 				x += amt2;
   276 				x += amt2;
   279 				GfxFillRect(r.left + 1, x, r.right - 1, x, color);
   277 				GfxFillRect(r.left + 1, x, r.right - 1, x, color);
   280 			}
   278 			}
   281 
   279 
   282 			color = _colour_gradient[wi->color & 0xF][4];
   280 			color = _colour_gradient[wi->color & 0xF][4];
   283 
   281 
   284 			x = r.left - 1;
   282 			x = r.left - 1;
   285 			for (ctr = c; ctr > 1; ctr--) {
   283 			for (int ctr = c; ctr > 1; ctr--) {
   286 				x += amt1;
   284 				x += amt1;
   287 				GfxFillRect(x, r.top + 1, x, r.bottom - 1, color);
   285 				GfxFillRect(x, r.top + 1, x, r.bottom - 1, color);
   288 			}
   286 			}
   289 
   287 
   290 			x = r.top - 1;
   288 			x = r.top - 1;
   291 			for (ctr = d; ctr > 1; ctr--) {
   289 			for (int ctr = d; ctr > 1; ctr--) {
   292 				x += amt2;
   290 				x += amt2;
   293 				GfxFillRect(r.left + 1, x, r.right - 1, x, color);
   291 				GfxFillRect(r.left + 1, x, r.right - 1, x, color);
   294 			}
   292 			}
   295 
   293 
   296 			break;
   294 			break;
   297 		}
   295 		}
   298 
   296 
   299 		/* vertical scrollbar */
   297 		/* vertical scrollbar */
   300 		case WWT_SCROLLBAR: {
   298 		case WWT_SCROLLBAR: {
   301 			Point pt;
       
   302 			int c1, c2;
       
   303 
       
   304 			assert(wi->data == 0);
   299 			assert(wi->data == 0);
   305 			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
   300 			assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere!
   306 
   301 
   307 			/* draw up/down buttons */
   302 			/* draw up/down buttons */
   308 			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP);
   303 			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP);
   309 			DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   304 			DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   310 			DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK);
   305 			DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK);
   311 
   306 
   312 			clicked = (((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN));
   307 			clicked = (((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN));
   313 			DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   308 			DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   314 			DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK);
   309 			DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK);
   315 
   310 
   316 			c1 = _colour_gradient[wi->color & 0xF][3];
   311 			int c1 = _colour_gradient[wi->color & 0xF][3];
   317 			c2 = _colour_gradient[wi->color & 0xF][7];
   312 			int c2 = _colour_gradient[wi->color & 0xF][7];
   318 
   313 
   319 			/* draw "shaded" background */
   314 			/* draw "shaded" background */
   320 			GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c2);
   315 			GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c2);
   321 			GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1 | (1 << PALETTE_MODIFIER_GREYOUT));
   316 			GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1 | (1 << PALETTE_MODIFIER_GREYOUT));
   322 
   317 
   324 			GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1);
   319 			GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1);
   325 			GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2);
   320 			GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2);
   326 			GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1);
   321 			GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1);
   327 			GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2);
   322 			GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2);
   328 
   323 
   329 			pt = HandleScrollbarHittest(&w->vscroll, r.top, r.bottom);
   324 			Point pt = HandleScrollbarHittest(&w->vscroll, r.top, r.bottom);
   330 			DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_MIDDLE ? FR_LOWERED : FR_NONE);
   325 			DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_MIDDLE ? FR_LOWERED : FR_NONE);
   331 			break;
   326 			break;
   332 		}
   327 		}
       
   328 
   333 		case WWT_SCROLL2BAR: {
   329 		case WWT_SCROLL2BAR: {
   334 			Point pt;
       
   335 			int c1, c2;
       
   336 
       
   337 			assert(wi->data == 0);
   330 			assert(wi->data == 0);
   338 			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
   331 			assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere!
   339 
   332 
   340 			/* draw up/down buttons */
   333 			/* draw up/down buttons */
   341 			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2));
   334 			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2));
   342 			DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color,  (clicked) ? FR_LOWERED : FR_NONE);
   335 			DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color,  (clicked) ? FR_LOWERED : FR_NONE);
   343 			DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK);
   336 			DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK);
   344 
   337 
   345 			clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2));
   338 			clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2));
   346 			DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color,  (clicked) ? FR_LOWERED : FR_NONE);
   339 			DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color,  (clicked) ? FR_LOWERED : FR_NONE);
   347 			DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK);
   340 			DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK);
   348 
   341 
   349 			c1 = _colour_gradient[wi->color & 0xF][3];
   342 			int c1 = _colour_gradient[wi->color & 0xF][3];
   350 			c2 = _colour_gradient[wi->color & 0xF][7];
   343 			int c2 = _colour_gradient[wi->color & 0xF][7];
   351 
   344 
   352 			/* draw "shaded" background */
   345 			/* draw "shaded" background */
   353 			GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c2);
   346 			GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c2);
   354 			GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1 | (1 << PALETTE_MODIFIER_GREYOUT));
   347 			GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1 | (1 << PALETTE_MODIFIER_GREYOUT));
   355 
   348 
   357 			GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1);
   350 			GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1);
   358 			GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2);
   351 			GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2);
   359 			GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1);
   352 			GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1);
   360 			GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2);
   353 			GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2);
   361 
   354 
   362 			pt = HandleScrollbarHittest(&w->vscroll2, r.top, r.bottom);
   355 			Point pt = HandleScrollbarHittest(&w->vscroll2, r.top, r.bottom);
   363 			DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_MIDDLE | WF_SCROLL2) ? FR_LOWERED : FR_NONE);
   356 			DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_MIDDLE | WF_SCROLL2) ? FR_LOWERED : FR_NONE);
   364 			break;
   357 			break;
   365 		}
   358 		}
   366 
   359 
   367 		/* horizontal scrollbar */
   360 		/* horizontal scrollbar */
   368 		case WWT_HSCROLLBAR: {
   361 		case WWT_HSCROLLBAR: {
   369 			Point pt;
       
   370 			int c1, c2;
       
   371 
       
   372 			assert(wi->data == 0);
   362 			assert(wi->data == 0);
   373 			assert(r.bottom - r.top == 11); // XXX - to ensure the same sizes are used everywhere!
   363 			assert(r.bottom - r.top == 11); // To ensure the same sizes are used everywhere!
   374 
   364 
   375 			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL));
   365 			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL));
   376 			DrawFrameRect(r.left, r.top, r.left + 9, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   366 			DrawFrameRect(r.left, r.top, r.left + 9, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   377 			DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked);
   367 			DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked);
   378 
   368 
   379 			clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL));
   369 			clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL));
   380 			DrawFrameRect(r.right - 9, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   370 			DrawFrameRect(r.right - 9, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   381 			DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - 8 + clicked, r.top + 1 + clicked);
   371 			DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - 8 + clicked, r.top + 1 + clicked);
   382 
   372 
   383 			c1 = _colour_gradient[wi->color & 0xF][3];
   373 			int c1 = _colour_gradient[wi->color & 0xF][3];
   384 			c2 = _colour_gradient[wi->color & 0xF][7];
   374 			int c2 = _colour_gradient[wi->color & 0xF][7];
   385 
   375 
   386 			/* draw "shaded" background */
   376 			/* draw "shaded" background */
   387 			GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c2);
   377 			GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c2);
   388 			GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c1 | (1 << PALETTE_MODIFIER_GREYOUT));
   378 			GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c1 | (1 << PALETTE_MODIFIER_GREYOUT));
   389 
   379 
   392 			GfxFillRect(r.left + 10, r.top + 3, r.right - 10, r.top + 3, c2);
   382 			GfxFillRect(r.left + 10, r.top + 3, r.right - 10, r.top + 3, c2);
   393 			GfxFillRect(r.left + 10, r.top + 7, r.right - 10, r.top + 7, c1);
   383 			GfxFillRect(r.left + 10, r.top + 7, r.right - 10, r.top + 7, c1);
   394 			GfxFillRect(r.left + 10, r.top + 8, r.right - 10, r.top + 8, c2);
   384 			GfxFillRect(r.left + 10, r.top + 8, r.right - 10, r.top + 8, c2);
   395 
   385 
   396 			/* draw actual scrollbar */
   386 			/* draw actual scrollbar */
   397 			pt = HandleScrollbarHittest(&w->hscroll, r.left, r.right);
   387 			Point pt = HandleScrollbarHittest(&w->hscroll, r.left, r.right);
   398 			DrawFrameRect(pt.x, r.top, pt.y, r.bottom, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == (WF_SCROLL_MIDDLE | WF_HSCROLL) ? FR_LOWERED : FR_NONE);
   388 			DrawFrameRect(pt.x, r.top, pt.y, r.bottom, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == (WF_SCROLL_MIDDLE | WF_HSCROLL) ? FR_LOWERED : FR_NONE);
   399 
   389 
   400 			break;
   390 			break;
   401 		}
   391 		}
   402 
   392 
   403 		case WWT_FRAME: {
   393 		case WWT_FRAME: {
   404 			const StringID str = wi->data;
   394 			const StringID str = wi->data;
   405 			int c1, c2;
       
   406 			int x2 = r.left; // by default the left side is the left side of the widget
   395 			int x2 = r.left; // by default the left side is the left side of the widget
   407 
   396 
   408 			if (str != STR_NULL) x2 = DrawString(r.left + 6, r.top, str, TC_FROMSTRING);
   397 			if (str != STR_NULL) x2 = DrawString(r.left + 6, r.top, str, TC_FROMSTRING);
   409 
   398 
   410 			c1 = _colour_gradient[wi->color][3];
   399 			int c1 = _colour_gradient[wi->color][3];
   411 			c2 = _colour_gradient[wi->color][7];
   400 			int c2 = _colour_gradient[wi->color][7];
   412 
   401 
   413 			/* Line from upper left corner to start of text */
   402 			/* Line from upper left corner to start of text */
   414 			GfxFillRect(r.left, r.top + 4, r.left + 4, r.top + 4, c1);
   403 			GfxFillRect(r.left, r.top + 4, r.left + 4, r.top + 4, c1);
   415 			GfxFillRect(r.left + 1, r.top + 5, r.left + 4, r.top + 5, c2);
   404 			GfxFillRect(r.left + 1, r.top + 5, r.left + 4, r.top + 5, c2);
   416 
   405 
   430 			GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2);
   419 			GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2);
   431 
   420 
   432 			break;
   421 			break;
   433 		}
   422 		}
   434 
   423 
   435 		case WWT_STICKYBOX: {
   424 		case WWT_STICKYBOX:
   436 			assert(wi->data == 0);
   425 			assert(wi->data == 0);
   437 			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
   426 			assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere!
   438 
   427 
   439 			clicked = !!(w->flags4 & WF_STICKY);
   428 			clicked = !!(w->flags4 & WF_STICKY);
   440 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   429 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   441 			DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, PAL_NONE, r.left + 2 + clicked, r.top + 3 + clicked);
   430 			DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, PAL_NONE, r.left + 2 + clicked, r.top + 3 + clicked);
   442 			break;
   431 			break;
   443 		}
   432 
   444 
   433 		case WWT_RESIZEBOX:
   445 		case WWT_RESIZEBOX: {
       
   446 			assert(wi->data == 0);
   434 			assert(wi->data == 0);
   447 			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
   435 			assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere!
   448 
   436 
   449 			clicked = !!(w->flags4 & WF_SIZING);
   437 			clicked = !!(w->flags4 & WF_SIZING);
   450 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   438 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
   451 			DrawSprite(SPR_WINDOW_RESIZE, PAL_NONE, r.left + 3 + clicked, r.top + 3 + clicked);
   439 			DrawSprite(SPR_WINDOW_RESIZE, PAL_NONE, r.left + 3 + clicked, r.top + 3 + clicked);
   452 			break;
   440 			break;
   453 		}
       
   454 
   441 
   455 		case WWT_CLOSEBOX: {
   442 		case WWT_CLOSEBOX: {
   456 			const StringID str = wi->data;
   443 			const StringID str = wi->data;
   457 
   444 
   458 			assert(str == STR_00C5 || str == STR_00C6); // black or silver cross
   445 			assert(str == STR_00C5 || str == STR_00C6); // black or silver cross
   459 			assert(r.right - r.left == 10); // ensure the same sizes are used everywhere
   446 			assert(r.right - r.left == 10); // To ensure the same sizes are used everywhere
   460 
   447 
   461 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_NONE);
   448 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_NONE);
   462 			DrawString(r.left + 2, r.top + 2, str, TC_FROMSTRING);
   449 			DrawString(r.left + 2, r.top + 2, str, TC_FROMSTRING);
   463 			break;
   450 			break;
   464 		}
   451 		}
   465 
   452 
   466 		case WWT_CAPTION: {
   453 		case WWT_CAPTION:
   467 			assert(r.bottom - r.top == 13); // XXX - to ensure the same sizes are used everywhere!
   454 			assert(r.bottom - r.top == 13); // To ensure the same sizes are used everywhere!
   468 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_BORDERONLY);
   455 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_BORDERONLY);
   469 			DrawFrameRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, wi->color, (w->caption_color == 0xFF) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY);
   456 			DrawFrameRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, wi->color, (w->caption_color == 0xFF) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY);
   470 
   457 
   471 			if (w->caption_color != 0xFF) {
   458 			if (w->caption_color != 0xFF) {
   472 				GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, _colour_gradient[_player_colors[w->caption_color]][4]);
   459 				GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, _colour_gradient[_player_colors[w->caption_color]][4]);
   473 			}
   460 			}
   474 
   461 
   475 			DrawStringCenteredTruncated(r.left + 2, r.right - 2, r.top + 2, wi->data, 0x84);
   462 			DrawStringCenteredTruncated(r.left + 2, r.right - 2, r.top + 2, wi->data, 0x84);
   476 			break;
   463 			break;
   477 		}
       
   478 
   464 
   479 		case WWT_DROPDOWN: {
   465 		case WWT_DROPDOWN: {
   480 			assert(r.bottom - r.top == 11); // ensure consistent size
   466 			assert(r.bottom - r.top == 11); // ensure consistent size
   481 
   467 
   482 			StringID str = wi->data;
   468 			StringID str = wi->data;
   514 static void ResizeWidgets(Window *w, byte a, byte b)
   500 static void ResizeWidgets(Window *w, byte a, byte b)
   515 {
   501 {
   516 	int16 offset = w->widget[a].left;
   502 	int16 offset = w->widget[a].left;
   517 	int16 length = w->widget[b].right - offset;
   503 	int16 length = w->widget[b].right - offset;
   518 
   504 
   519 	w->widget[a].right  = (length / 2) + offset;
   505 	w->widget[a].right = (length / 2) + offset;
   520 
   506 
   521 	w->widget[b].left  = w->widget[a].right + 1;
   507 	w->widget[b].left  = w->widget[a].right + 1;
   522 }
   508 }
   523 
   509 
   524 static void ResizeWidgets(Window *w, byte a, byte b, byte c)
   510 static void ResizeWidgets(Window *w, byte a, byte b, byte c)