* Draw a horizontal scrollbar. * @param r Rectangle of the scrollbar widget. * @param colour Colour of the scrollbar widget. * @param left_clicked Left-arrow is clicked. * @param bar_dragged Bar is dragged. * @param right_clicked Right-arrow is clicked. * @param scrollbar Scrollbar size, offset, and capacity information. */
| 558 | * @param scrollbar Scrollbar size, offset, and capacity information. |
| 559 | */ |
| 560 | static inline void DrawHorizontalScrollbar(const Rect &r, Colours colour, bool left_clicked, bool bar_dragged, bool right_clicked, const Scrollbar *scrollbar) |
| 561 | { |
| 562 | int width = NWidgetScrollbar::GetHorizontalDimension().width; |
| 563 | |
| 564 | DrawImageButtons(r.WithWidth(width, false), NWID_HSCROLLBAR, colour, left_clicked, SPR_ARROW_LEFT, SA_CENTER); |
| 565 | DrawImageButtons(r.WithWidth(width, true), NWID_HSCROLLBAR, colour, right_clicked, SPR_ARROW_RIGHT, SA_CENTER); |
| 566 | |
| 567 | PixelColour c1 = GetColourGradient(colour, SHADE_DARK); |
| 568 | PixelColour c2 = GetColourGradient(colour, SHADE_LIGHTEST); |
| 569 | |
| 570 | /* draw "shaded" background */ |
| 571 | Rect bg = r.Shrink(width, 0); |
| 572 | GfxFillRect(bg, c2); |
| 573 | GfxFillRect(bg, c1, FILLRECT_CHECKER); |
| 574 | |
| 575 | /* track positions. These fractions are based on original 1x dimensions, but scale better. */ |
| 576 | int top = r.top + r.Height() * 3 / 11; /* top track is positioned 3/11ths from the top */ |
| 577 | int bottom = r.top + r.Height() * 8 / 11; /* bottom track is positioned 8/11ths from the top */ |
| 578 | const uint8_t bt = WidgetDimensions::scaled.bevel.top; |
| 579 | const uint8_t bb = WidgetDimensions::scaled.bevel.bottom; |
| 580 | |
| 581 | /* draw shaded lines */ |
| 582 | GfxFillRect(bg.WithY(top - bt, top - 1), c1); |
| 583 | GfxFillRect(bg.WithY(top, top + bb - 1), c2); |
| 584 | GfxFillRect(bg.WithY(bottom - bt, bottom - 1), c1); |
| 585 | GfxFillRect(bg.WithY(bottom, bottom + bb - 1), c2); |
| 586 | |
| 587 | /* draw actual scrollbar */ |
| 588 | auto [left, right] = HandleScrollbarHittest(scrollbar, r.left, r.right, true); |
| 589 | DrawFrameRect(left, r.top, right, r.bottom, colour, bar_dragged ? FrameFlag::Lowered : FrameFlags{}); |
| 590 | } |
| 591 | |
| 592 | /** |
| 593 | * Draw a frame widget. |
no test coverage detected