src/widget.cpp
changeset 8320 6ffad7a5d242
parent 6977 67b989528f3d
child 8424 4a488a90ccab
equal deleted inserted replaced
8319:434ce8c1e463 8320:6ffad7a5d242
   227 		case WWT_LABEL: {
   227 		case WWT_LABEL: {
   228 			StringID str = wi->data;
   228 			StringID str = wi->data;
   229 
   229 
   230 			if ((wi->type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
   230 			if ((wi->type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
   231 
   231 
   232 			DrawStringCentered(((r.left + r.right + 1) >> 1) + clicked, ((r.top + r.bottom + 1) >> 1) - 5 + clicked, str, 0);
   232 			DrawStringCentered(((r.left + r.right + 1) >> 1) + clicked, ((r.top + r.bottom + 1) >> 1) - 5 + clicked, str, TC_FROMSTRING);
   233 			goto draw_default;
   233 			goto draw_default;
   234 		}
   234 		}
   235 
   235 
   236 		case WWT_TEXT: {
   236 		case WWT_TEXT: {
   237 			StringID str = wi->data;
   237 			StringID str = wi->data;
   242 
   242 
   243 		case WWT_INSET: {
   243 		case WWT_INSET: {
   244 			StringID str = wi->data;
   244 			StringID str = wi->data;
   245 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_LOWERED | FR_DARKENED);
   245 			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_LOWERED | FR_DARKENED);
   246 
   246 
   247 			if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 1, str, 0, r.right - r.left - 10);
   247 			if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 1, str, TC_FROMSTRING, r.right - r.left - 10);
   248 			goto draw_default;
   248 			goto draw_default;
   249 		}
   249 		}
   250 
   250 
   251 		case WWT_MATRIX: {
   251 		case WWT_MATRIX: {
   252 			int c, d, ctr;
   252 			int c, d, ctr;
   300 			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
   300 			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
   301 
   301 
   302 			/* draw up/down buttons */
   302 			/* draw up/down buttons */
   303 			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);
   304 			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);
   305 			DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, 0x10);
   305 			DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK);
   306 
   306 
   307 			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));
   308 			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);
   309 			DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, 0x10);
   309 			DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK);
   310 
   310 
   311 			c1 = _colour_gradient[wi->color&0xF][3];
   311 			c1 = _colour_gradient[wi->color&0xF][3];
   312 			c2 = _colour_gradient[wi->color&0xF][7];
   312 			c2 = _colour_gradient[wi->color&0xF][7];
   313 
   313 
   314 			/* draw "shaded" background */
   314 			/* draw "shaded" background */
   332 			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
   332 			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
   333 
   333 
   334 			/* draw up/down buttons */
   334 			/* draw up/down buttons */
   335 			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2));
   335 			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2));
   336 			DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color,  (clicked) ? FR_LOWERED : FR_NONE);
   336 			DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color,  (clicked) ? FR_LOWERED : FR_NONE);
   337 			DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, 0x10);
   337 			DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK);
   338 
   338 
   339 			clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2));
   339 			clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2));
   340 			DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color,  (clicked) ? FR_LOWERED : FR_NONE);
   340 			DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color,  (clicked) ? FR_LOWERED : FR_NONE);
   341 			DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, 0x10);
   341 			DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK);
   342 
   342 
   343 			c1 = _colour_gradient[wi->color&0xF][3];
   343 			c1 = _colour_gradient[wi->color&0xF][3];
   344 			c2 = _colour_gradient[wi->color&0xF][7];
   344 			c2 = _colour_gradient[wi->color&0xF][7];
   345 
   345 
   346 			/* draw "shaded" background */
   346 			/* draw "shaded" background */
   395 
   395 
   396 		case WWT_FRAME: {
   396 		case WWT_FRAME: {
   397 			int c1,c2;
   397 			int c1,c2;
   398 			int x2 = r.left; // by default the left side is the left side of the widget
   398 			int x2 = r.left; // by default the left side is the left side of the widget
   399 
   399 
   400 			if (wi->data != 0) x2 = DrawString(r.left + 6, r.top, wi->data, 0);
   400 			if (wi->data != 0) x2 = DrawString(r.left + 6, r.top, wi->data, TC_FROMSTRING);
   401 
   401 
   402 			c1 = _colour_gradient[wi->color][3];
   402 			c1 = _colour_gradient[wi->color][3];
   403 			c2 = _colour_gradient[wi->color][7];
   403 			c2 = _colour_gradient[wi->color][7];
   404 
   404 
   405 			/*Line from upper left corner to start of text */
   405 			/*Line from upper left corner to start of text */
   444 
   444 
   445 		case WWT_CLOSEBOX: {
   445 		case WWT_CLOSEBOX: {
   446 			assert(r.right - r.left == 10); // ensure the same sizes are used everywhere
   446 			assert(r.right - r.left == 10); // ensure the same sizes are used everywhere
   447 
   447 
   448 			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);
   449 			DrawString(r.left + 2, r.top + 2, STR_00C5, 0);
   449 			DrawString(r.left + 2, r.top + 2, STR_00C5, TC_FROMSTRING);
   450 			break;
   450 			break;
   451 		}
   451 		}
   452 
   452 
   453 		case WWT_CAPTION: {
   453 		case WWT_CAPTION: {
   454 			assert(r.bottom - r.top == 13); // XXX - to ensure the same sizes are used everywhere!
   454 			assert(r.bottom - r.top == 13); // XXX - to ensure the same sizes are used everywhere!
   528 				if (HASBIT(WP(w,dropdown_d).hidden_state, i)) continue;
   528 				if (HASBIT(WP(w,dropdown_d).hidden_state, i)) continue;
   529 
   529 
   530 				if (y >= 0 && y <= height) {
   530 				if (y >= 0 && y <= height) {
   531 					if (WP(w,dropdown_d).items[i] != STR_NULL) {
   531 					if (WP(w,dropdown_d).items[i] != STR_NULL) {
   532 						if (sel == 0) GfxFillRect(x + 1, y, x + width, y + 9, 0);
   532 						if (sel == 0) GfxFillRect(x + 1, y, x + width, y + 9, 0);
   533 						DrawStringTruncated(x + 2, y, WP(w,dropdown_d).items[i], sel == 0 ? 12 : 16, x + width);
   533 						DrawStringTruncated(x + 2, y, WP(w,dropdown_d).items[i], sel == 0 ? TC_WHITE : TC_BLACK, x + width);
   534 
   534 
   535 						if (HASBIT(WP(w,dropdown_d).disabled_state, i)) {
   535 						if (HASBIT(WP(w,dropdown_d).disabled_state, i)) {
   536 							GfxFillRect(x, y, x + width, y + 9,
   536 							GfxFillRect(x, y, x + width, y + 9,
   537 								(1 << PALETTE_MODIFIER_GREYOUT) | _colour_gradient[_dropdown_menu_widgets[0].color][5]
   537 								(1 << PALETTE_MODIFIER_GREYOUT) | _colour_gradient[_dropdown_menu_widgets[0].color][5]
   538 							);
   538 							);