MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DrawBoolButton

Function DrawBoolButton

src/settings_gui.cpp:1947–1960  ·  view source on GitHub ↗

* Draw a toggle button. * @param x the x position to draw * @param y the y position to draw * @param button_colour the colour of the button. * @param background background colour. * @param state true = lowered * @param clickable is the button clickable? */

Source from the content-addressed store, hash-verified

1945 * @param clickable is the button clickable?
1946 */
1947void DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable)
1948{
1949 Rect r = {x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1};
1950 DrawFrameRect(r, state ? COLOUR_GREEN : background, state ? FrameFlags{FrameFlag::Lowered} : FrameFlags{FrameFlag::Lowered, FrameFlag::BorderOnly});
1951 if (!clickable) {
1952 GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(state ? COLOUR_GREEN : background, SHADE_DARKER), FILLRECT_CHECKER);
1953 }
1954
1955 Rect button_rect = r.WithWidth(SETTING_BUTTON_WIDTH / 3, state ^ (_current_text_dir == TD_RTL));
1956 DrawFrameRect(button_rect, button_colour, {});
1957 if (!clickable) {
1958 GfxFillRect(button_rect.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(button_colour, SHADE_DARKER), FILLRECT_CHECKER);
1959 }
1960}
1961
1962struct CustomCurrencyWindow : Window {
1963 WidgetID query_widget{};

Callers 9

DrawSettingMethod · 0.85
DrawWidgetMethod · 0.85
DrawMethod · 0.85
DrawCheatWidgetMethod · 0.85
DrawSettingMethod · 0.85
DrawWidgetMethod · 0.85
DrawMethod · 0.85
DrawWidgetMethod · 0.85
DrawWidgetMethod · 0.85

Calls 5

GetColourGradientFunction · 0.85
ShrinkMethod · 0.80
WithWidthMethod · 0.80
DrawFrameRectFunction · 0.70
GfxFillRectFunction · 0.70

Tested by

no test coverage detected