* Draw a vertical scrollbar. * @param r Rectangle of the scrollbar widget. * @param colour Colour of the scrollbar widget. * @param up_clicked Up-arrow is clicked. * @param bar_dragged Bar is dragged. * @param down_clicked Down-arrow is clicked. * @param scrollbar Scrollbar size, offset, and capacity information. */
| 517 | * @param scrollbar Scrollbar size, offset, and capacity information. |
| 518 | */ |
| 519 | static inline void DrawVerticalScrollbar(const Rect &r, Colours colour, bool up_clicked, bool bar_dragged, bool down_clicked, const Scrollbar *scrollbar) |
| 520 | { |
| 521 | int height = NWidgetScrollbar::GetVerticalDimension().height; |
| 522 | |
| 523 | /* draw up/down buttons */ |
| 524 | DrawImageButtons(r.WithHeight(height, false), NWID_VSCROLLBAR, colour, up_clicked, SPR_ARROW_UP, SA_CENTER); |
| 525 | DrawImageButtons(r.WithHeight(height, true), NWID_VSCROLLBAR, colour, down_clicked, SPR_ARROW_DOWN, SA_CENTER); |
| 526 | |
| 527 | PixelColour c1 = GetColourGradient(colour, SHADE_DARK); |
| 528 | PixelColour c2 = GetColourGradient(colour, SHADE_LIGHTEST); |
| 529 | |
| 530 | /* draw "shaded" background */ |
| 531 | Rect bg = r.Shrink(0, height); |
| 532 | GfxFillRect(bg, c2); |
| 533 | GfxFillRect(bg, c1, FILLRECT_CHECKER); |
| 534 | |
| 535 | /* track positions. These fractions are based on original 1x dimensions, but scale better. */ |
| 536 | int left = r.left + r.Width() * 3 / 11; /* left track is positioned 3/11ths from the left */ |
| 537 | int right = r.left + r.Width() * 8 / 11; /* right track is positioned 8/11ths from the left */ |
| 538 | const uint8_t bl = WidgetDimensions::scaled.bevel.left; |
| 539 | const uint8_t br = WidgetDimensions::scaled.bevel.right; |
| 540 | |
| 541 | /* draw shaded lines */ |
| 542 | GfxFillRect(bg.WithX(left - bl, left - 1), c1); |
| 543 | GfxFillRect(bg.WithX(left, left + br - 1), c2); |
| 544 | GfxFillRect(bg.WithX(right - bl, right - 1), c1); |
| 545 | GfxFillRect(bg.WithX(right, right + br - 1), c2); |
| 546 | |
| 547 | auto [top, bottom] = HandleScrollbarHittest(scrollbar, r.top, r.bottom, false); |
| 548 | DrawFrameRect(r.left, top, r.right, bottom, colour, bar_dragged ? FrameFlag::Lowered : FrameFlags{}); |
| 549 | } |
| 550 | |
| 551 | /** |
| 552 | * Draw a horizontal scrollbar. |
no test coverage detected