188 |
188 |
189 /** |
189 /** |
190 * Paint all widgets of a window. |
190 * Paint all widgets of a window. |
191 * @param w Window |
191 * @param w Window |
192 */ |
192 */ |
193 void DrawWindowWidgets(const Window *w) |
193 void Window::DrawWidgets() const |
194 { |
194 { |
195 const DrawPixelInfo* dpi = _cur_dpi; |
195 const DrawPixelInfo* dpi = _cur_dpi; |
196 |
196 |
197 for (uint i = 0; i < w->widget_count; i++) { |
197 for (uint i = 0; i < this->widget_count; i++) { |
198 const Widget *wi = &w->widget[i]; |
198 const Widget *wi = &this->widget[i]; |
199 bool clicked = w->IsWidgetLowered(i); |
199 bool clicked = this->IsWidgetLowered(i); |
200 Rect r; |
200 Rect r; |
201 |
201 |
202 if (dpi->left > (r.right = wi->right) || |
202 if (dpi->left > (r.right = wi->right) || |
203 dpi->left + dpi->width <= (r.left = wi->left) || |
203 dpi->left + dpi->width <= (r.left = wi->left) || |
204 dpi->top > (r.bottom = wi->bottom) || |
204 dpi->top > (r.bottom = wi->bottom) || |
205 dpi->top + dpi->height <= (r.top = wi->top) || |
205 dpi->top + dpi->height <= (r.top = wi->top) || |
206 w->IsWidgetHidden(i)) { |
206 this->IsWidgetHidden(i)) { |
207 continue; |
207 continue; |
208 } |
208 } |
209 |
209 |
210 switch (wi->type & WWT_MASK) { |
210 switch (wi->type & WWT_MASK) { |
211 case WWT_IMGBTN: |
211 case WWT_IMGBTN: |
302 case WWT_SCROLLBAR: { |
302 case WWT_SCROLLBAR: { |
303 assert(wi->data == 0); |
303 assert(wi->data == 0); |
304 assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
304 assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
305 |
305 |
306 /* draw up/down buttons */ |
306 /* draw up/down buttons */ |
307 clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP); |
307 clicked = ((this->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP); |
308 DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
308 DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
309 DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK); |
309 DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK); |
310 |
310 |
311 clicked = (((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN)); |
311 clicked = (((this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN)); |
312 DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
312 DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
313 DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK); |
313 DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK); |
314 |
314 |
315 int c1 = _colour_gradient[wi->color & 0xF][3]; |
315 int c1 = _colour_gradient[wi->color & 0xF][3]; |
316 int c2 = _colour_gradient[wi->color & 0xF][7]; |
316 int c2 = _colour_gradient[wi->color & 0xF][7]; |
323 GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1); |
323 GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1); |
324 GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2); |
324 GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2); |
325 GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1); |
325 GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1); |
326 GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2); |
326 GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2); |
327 |
327 |
328 Point pt = HandleScrollbarHittest(&w->vscroll, r.top, r.bottom); |
328 Point pt = HandleScrollbarHittest(&this->vscroll, r.top, r.bottom); |
329 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); |
329 DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (this->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_MIDDLE ? FR_LOWERED : FR_NONE); |
330 break; |
330 break; |
331 } |
331 } |
332 |
332 |
333 case WWT_SCROLL2BAR: { |
333 case WWT_SCROLL2BAR: { |
334 assert(wi->data == 0); |
334 assert(wi->data == 0); |
335 assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
335 assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
336 |
336 |
337 /* draw up/down buttons */ |
337 /* draw up/down buttons */ |
338 clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2)); |
338 clicked = ((this->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2)); |
339 DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
339 DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
340 DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK); |
340 DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK); |
341 |
341 |
342 clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2)); |
342 clicked = ((this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2)); |
343 DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
343 DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
344 DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK); |
344 DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK); |
345 |
345 |
346 int c1 = _colour_gradient[wi->color & 0xF][3]; |
346 int c1 = _colour_gradient[wi->color & 0xF][3]; |
347 int c2 = _colour_gradient[wi->color & 0xF][7]; |
347 int c2 = _colour_gradient[wi->color & 0xF][7]; |
354 GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1); |
354 GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1); |
355 GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2); |
355 GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2); |
356 GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1); |
356 GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1); |
357 GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2); |
357 GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2); |
358 |
358 |
359 Point pt = HandleScrollbarHittest(&w->vscroll2, r.top, r.bottom); |
359 Point pt = HandleScrollbarHittest(&this->vscroll2, r.top, r.bottom); |
360 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); |
360 DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (this->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_MIDDLE | WF_SCROLL2) ? FR_LOWERED : FR_NONE); |
361 break; |
361 break; |
362 } |
362 } |
363 |
363 |
364 /* horizontal scrollbar */ |
364 /* horizontal scrollbar */ |
365 case WWT_HSCROLLBAR: { |
365 case WWT_HSCROLLBAR: { |
366 assert(wi->data == 0); |
366 assert(wi->data == 0); |
367 assert(r.bottom - r.top == 11); // To ensure the same sizes are used everywhere! |
367 assert(r.bottom - r.top == 11); // To ensure the same sizes are used everywhere! |
368 |
368 |
369 clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL)); |
369 clicked = ((this->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL)); |
370 DrawFrameRect(r.left, r.top, r.left + 9, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
370 DrawFrameRect(r.left, r.top, r.left + 9, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
371 DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked); |
371 DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked); |
372 |
372 |
373 clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL)); |
373 clicked = ((this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL)); |
374 DrawFrameRect(r.right - 9, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
374 DrawFrameRect(r.right - 9, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
375 DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - 8 + clicked, r.top + 1 + clicked); |
375 DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - 8 + clicked, r.top + 1 + clicked); |
376 |
376 |
377 int c1 = _colour_gradient[wi->color & 0xF][3]; |
377 int c1 = _colour_gradient[wi->color & 0xF][3]; |
378 int c2 = _colour_gradient[wi->color & 0xF][7]; |
378 int c2 = _colour_gradient[wi->color & 0xF][7]; |
386 GfxFillRect(r.left + 10, r.top + 3, r.right - 10, r.top + 3, c2); |
386 GfxFillRect(r.left + 10, r.top + 3, r.right - 10, r.top + 3, c2); |
387 GfxFillRect(r.left + 10, r.top + 7, r.right - 10, r.top + 7, c1); |
387 GfxFillRect(r.left + 10, r.top + 7, r.right - 10, r.top + 7, c1); |
388 GfxFillRect(r.left + 10, r.top + 8, r.right - 10, r.top + 8, c2); |
388 GfxFillRect(r.left + 10, r.top + 8, r.right - 10, r.top + 8, c2); |
389 |
389 |
390 /* draw actual scrollbar */ |
390 /* draw actual scrollbar */ |
391 Point pt = HandleScrollbarHittest(&w->hscroll, r.left, r.right); |
391 Point pt = HandleScrollbarHittest(&this->hscroll, r.left, r.right); |
392 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); |
392 DrawFrameRect(pt.x, r.top, pt.y, r.bottom, wi->color, (this->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == (WF_SCROLL_MIDDLE | WF_HSCROLL) ? FR_LOWERED : FR_NONE); |
393 |
393 |
394 break; |
394 break; |
395 } |
395 } |
396 |
396 |
397 case WWT_FRAME: { |
397 case WWT_FRAME: { |
427 |
427 |
428 case WWT_STICKYBOX: |
428 case WWT_STICKYBOX: |
429 assert(wi->data == 0); |
429 assert(wi->data == 0); |
430 assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
430 assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
431 |
431 |
432 clicked = !!(w->flags4 & WF_STICKY); |
432 clicked = !!(this->flags4 & WF_STICKY); |
433 DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
433 DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
434 DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, PAL_NONE, r.left + 2 + clicked, r.top + 3 + clicked); |
434 DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, PAL_NONE, r.left + 2 + clicked, r.top + 3 + clicked); |
435 break; |
435 break; |
436 |
436 |
437 case WWT_RESIZEBOX: |
437 case WWT_RESIZEBOX: |
438 assert(wi->data == 0); |
438 assert(wi->data == 0); |
439 assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
439 assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere! |
440 |
440 |
441 clicked = !!(w->flags4 & WF_SIZING); |
441 clicked = !!(this->flags4 & WF_SIZING); |
442 DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
442 DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE); |
443 DrawSprite(SPR_WINDOW_RESIZE, PAL_NONE, r.left + 3 + clicked, r.top + 3 + clicked); |
443 DrawSprite(SPR_WINDOW_RESIZE, PAL_NONE, r.left + 3 + clicked, r.top + 3 + clicked); |
444 break; |
444 break; |
445 |
445 |
446 case WWT_CLOSEBOX: { |
446 case WWT_CLOSEBOX: { |
455 } |
455 } |
456 |
456 |
457 case WWT_CAPTION: |
457 case WWT_CAPTION: |
458 assert(r.bottom - r.top == 13); // To ensure the same sizes are used everywhere! |
458 assert(r.bottom - r.top == 13); // To ensure the same sizes are used everywhere! |
459 DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_BORDERONLY); |
459 DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_BORDERONLY); |
460 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); |
460 DrawFrameRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, wi->color, (this->caption_color == 0xFF) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY); |
461 |
461 |
462 if (w->caption_color != 0xFF) { |
462 if (this->caption_color != 0xFF) { |
463 GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, _colour_gradient[_player_colors[w->caption_color]][4]); |
463 GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, _colour_gradient[_player_colors[this->caption_color]][4]); |
464 } |
464 } |
465 |
465 |
466 DrawStringCenteredTruncated(r.left + 2, r.right - 2, r.top + 2, wi->data, 0x84); |
466 DrawStringCenteredTruncated(r.left + 2, r.right - 2, r.top + 2, wi->data, 0x84); |
467 break; |
467 break; |
468 |
468 |
487 if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 2, str, TC_BLACK, r.right - r.left - 12); |
487 if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 2, str, TC_BLACK, r.right - r.left - 12); |
488 break; |
488 break; |
489 } |
489 } |
490 } |
490 } |
491 |
491 |
492 if (w->IsWidgetDisabled(i)) { |
492 if (this->IsWidgetDisabled(i)) { |
493 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[wi->color & 0xF][2] | (1 << PALETTE_MODIFIER_GREYOUT)); |
493 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[wi->color & 0xF][2] | (1 << PALETTE_MODIFIER_GREYOUT)); |
494 } |
494 } |
495 } |
495 } |
496 |
496 |
497 |
497 |
498 if (w->flags4 & WF_WHITE_BORDER_MASK) { |
498 if (this->flags4 & WF_WHITE_BORDER_MASK) { |
499 DrawFrameRect(0, 0, w->width - 1, w->height - 1, 0xF, FR_BORDERONLY); |
499 DrawFrameRect(0, 0, this->width - 1, this->height - 1, 0xF, FR_BORDERONLY); |
500 } |
500 } |
501 |
501 |
502 } |
502 } |
503 |
503 |
504 static void ResizeWidgets(Window *w, byte a, byte b) |
504 static void ResizeWidgets(Window *w, byte a, byte b) |
595 /** Draw a sort button's up or down arrow symbol. |
595 /** Draw a sort button's up or down arrow symbol. |
596 * @param w Window of widget |
596 * @param w Window of widget |
597 * @param widget Sort button widget |
597 * @param widget Sort button widget |
598 * @param state State of sort button |
598 * @param state State of sort button |
599 */ |
599 */ |
600 void DrawSortButtonState(const Window *w, int widget, SortButtonState state) |
600 void Window::DrawSortButtonState(int widget, SortButtonState state) const |
601 { |
601 { |
602 if (state == SBS_OFF) return; |
602 if (state == SBS_OFF) return; |
603 |
603 |
604 int offset = w->IsWidgetLowered(widget) ? 1 : 0; |
604 int offset = this->IsWidgetLowered(widget) ? 1 : 0; |
605 DoDrawString(state == SBS_DOWN ? DOWNARROW : UPARROW, w->widget[widget].right - 11 + offset, w->widget[widget].top + 1 + offset, TC_BLACK); |
605 DoDrawString(state == SBS_DOWN ? DOWNARROW : UPARROW, this->widget[widget].right - 11 + offset, this->widget[widget].top + 1 + offset, TC_BLACK); |
606 } |
606 } |