1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 18:35:06 +00:00
serenity/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h
Linus Groh 57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00

71 lines
2.5 KiB
C++

/*
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/DeprecatedString.h>
#include <LibWeb/HTML/Canvas/CanvasState.h>
#include <LibWeb/HTML/CanvasGradient.h>
namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/canvas.html#canvasfillstrokestyles
template<typename IncludingClass>
class CanvasFillStrokeStyles {
public:
~CanvasFillStrokeStyles() = default;
void set_fill_style(DeprecatedString style)
{
// FIXME: 2. If the given value is a CanvasPattern object that is marked as not origin-clean, then set this's origin-clean flag to false.
my_drawing_state().fill_style = Gfx::Color::from_string(style).value_or(Color::Black);
}
DeprecatedString fill_style() const
{
return my_drawing_state().fill_style.to_deprecated_string();
}
void set_stroke_style(DeprecatedString style)
{
// FIXME: 2. If the given value is a CanvasPattern object that is marked as not origin-clean, then set this's origin-clean flag to false.
my_drawing_state().stroke_style = Gfx::Color::from_string(style).value_or(Color::Black);
}
DeprecatedString stroke_style() const
{
return my_drawing_state().stroke_style.to_deprecated_string();
}
JS::NonnullGCPtr<CanvasGradient> create_radial_gradient(double x0, double y0, double r0, double x1, double y1, double r1)
{
auto& realm = static_cast<IncludingClass&>(*this).realm();
return CanvasGradient::create_radial(realm, x0, y0, r0, x1, y1, r1);
}
JS::NonnullGCPtr<CanvasGradient> create_linear_gradient(double x0, double y0, double x1, double y1)
{
auto& realm = static_cast<IncludingClass&>(*this).realm();
return CanvasGradient::create_linear(realm, x0, y0, x1, y1);
}
JS::NonnullGCPtr<CanvasGradient> create_conic_gradient(double start_angle, double x, double y)
{
auto& realm = static_cast<IncludingClass&>(*this).realm();
return CanvasGradient::create_conic(realm, start_angle, x, y);
}
protected:
CanvasFillStrokeStyles() = default;
private:
CanvasState::DrawingState& my_drawing_state() { return reinterpret_cast<IncludingClass&>(*this).drawing_state(); }
CanvasState::DrawingState const& my_drawing_state() const { return reinterpret_cast<IncludingClass const&>(*this).drawing_state(); }
};
}