Jazz2::UI::Windows::Painter class

Draws the interface.

All positions and sizes are in pixels of the screen. The interface is drawn in slots — the docked panels in one, a floating window in another, a menu over them in yet another — and a later slot is always drawn over an earlier one. Inside a slot, things are drawn in layers, see PaintLayer.

Public static variables

static std::int32_t SlotDepth constexpr
Number of depth values a slot takes.
static std::uint16_t BaseDepth constexpr
Depth of the first slot, the interface is drawn over everything else.

Constructors, destructors, conversion operators

Painter(UI::Canvas& canvas, Skin& skin, UI::Font* font, float scale, Rendering::PolylineRenderer* lines = nullptr)
Creates a new instance, lines draws slanted lines antialiased, they're rough without it.

Public functions

auto GetScale() const -> float
Returns how many pixels a unit takes.
auto Px(float units) const -> float
Converts units to whole pixels.
auto GetFont() const -> UI::Font*
Returns the font.
void SetSlot(std::int32_t slot)
Sets the slot things are drawn in.
auto GetSlot() const -> std::int32_t
Returns the slot things are drawn in.
auto GetDepth(PaintLayer layer) const -> std::uint16_t
Returns the depth of a layer of the current slot.
void PushClip(const Rectf& rect)
Clips everything drawn to a rectangle, inside of the current clipping.
void PopClip()
Ends the last clipping.
auto GetClip() const -> const Rectf&
Returns the current clipping, empty if nothing is clipped.
auto IsVisible(const Rectf& rect) const -> bool
Returns false if nothing drawn in a rectangle, or a little around it, would be seen inside of the clipping.
void PushOpacity(float opacity)
Makes everything drawn more transparent.
void PopOpacity()
Ends the last transparency.
void FillRect(const Rectf& rect, const Colorf& color, PaintLayer layer = PaintLayer::Fill)
Fills a rectangle.
void Frame(const Rectf& rect, const Colorf& color, float thickness, PaintLayer layer = PaintLayer::Overlay)
Draws the outline of a rectangle, inside of it.
void RoundRect(const Rectf& rect, const Colorf& color, PaintLayer layer = PaintLayer::Fill)
Fills a rounded rectangle.
void RoundRectBorder(const Rectf& rect, const Colorf& color, PaintLayer layer = PaintLayer::Fill)
Draws the border of a rounded rectangle.
void Shadow(const Rectf& rect, float opacity = 1.0f)
Draws a soft shadow of a rectangle.
void FocusRing(const Rectf& rect)
Draws the ring around an element that has the keyboard focus.
void SetBackdrop(const Texture* texture, const Rectf& bounds, float fillOpacity, std::int32_t firstSlot = 0)
Sets a blurred picture of what is behind the interface and the part of the screen it covers, nullptr for none.
auto Backdrop(const Rectf& rect, const Colorf& fill, bool rounded) -> Colorf
Draws the blurred picture behind a background of a color, see SetBackdrop().
void SetRaster(float raster)
Draws into a target with more or fewer pixels than units, as a window on a display with another scale.
auto GetRaster() const -> float
Returns the pixels of the target for a pixel of the interface, see SetRaster().
void SetSquareWindow(const Rectf& bounds)
Sets the bounds of a window of the system that has square corners, Rectf() for none.
void Panel(const Rectf& rect, bool shadow = true, const Colorf& fill = Theme::PanelFill, const Colorf& border = Theme::PanelBorderDim, bool rounded = true)
Draws a panel, its shadow, background and border, with square corners unless rounded.
void Line(Vector2f from, Vector2f to, float thickness, const Colorf& color, PaintLayer layer = PaintLayer::Overlay)
Draws a line, antialiased unless it's horizontal or vertical.
void Polyline(ArrayView<const Vector2f> points, float thickness, const Colorf& color, PaintLayer layer = PaintLayer::Overlay)
Draws an antialiased line through points, with mitered corners.
void Circle(Vector2f center, float radius, const Colorf& color, PaintLayer layer = PaintLayer::Content)
Draws a filled circle.
void Icon(IconId icon, const Rectf& rect, const Colorf& color, PaintLayer layer = PaintLayer::Content)
Draws an icon centered in a rectangle, at the size of an icon at the scale of the interface.
auto GetTextSize() const -> float
Returns the size of text relative to the usual size of the interface.
void SetTextSize(float size)
Makes text drawn and measured from now on larger or smaller than usual, 1 is the usual size.
auto GetTextHeight() const -> float
Returns the height of a line of text.
auto MeasureText(StringView text) const -> float
Returns the width of a text.
void Text(StringView text, Vector2f pos, const Colorf& color, Alignment align = Alignment::TopLeft, PaintLayer layer = PaintLayer::Text)
Draws a text.
void TextInRect(StringView text, const Rectf& rect, const Colorf& color, Alignment align = Alignment::Left, PaintLayer layer = PaintLayer::Text)
Draws a text in a rectangle, vertically centered.
void Image(const Texture& texture, const Rectf& rect, const Vector4f& texCoords, const Colorf& color, std::int32_t paletteOffset = -1, PaintLayer layer = PaintLayer::Content, float angle = 0.0f, UI::BlendMode blend = UI::BlendMode::Normal)
Draws a part of a texture, rotated clockwise by angle in radians around the center of the rectangle.
void Command(RenderCommand* command)
Draws a prepared render command, its depth has to be set already, see GetDepth().

Function documentation

void Jazz2::UI::Windows::Painter::SetBackdrop(const Texture* texture, const Rectf& bounds, float fillOpacity, std::int32_t firstSlot = 0)

Sets a blurred picture of what is behind the interface and the part of the screen it covers, nullptr for none.

Backgrounds drawn over it keep fillOpacity of their opacity, see Theme::BackdropFillOpacity. Those drawn in a slot before firstSlot aren't drawn over it, they may be in the picture.

Colorf Jazz2::UI::Windows::Painter::Backdrop(const Rectf& rect, const Colorf& fill, bool rounded)

Draws the blurred picture behind a background of a color, see SetBackdrop().

Returns the color made more transparent if it was drawn, the color as it is otherwise — there's no picture, the background is opaque or the rectangle isn't all inside of the picture. The corners of a rounded background are left out.

void Jazz2::UI::Windows::Painter::SetRaster(float raster)

Draws into a target with more or fewer pixels than units, as a window on a display with another scale.

Everything is still laid out and drawn in units of the interface, the skin and the font given to the painter have to be made for the scale of the interface times raster though, so they're drawn a pixel of them to a pixel of the target. Positions are put on whole pixels of the target.

void Jazz2::UI::Windows::Painter::SetSquareWindow(const Rectf& bounds)

Sets the bounds of a window of the system that has square corners, Rectf() for none.

A panel that fills it gets square corners too and no shadow, rounded ones would leave the corners of the window showing the background, see Panel().

void Jazz2::UI::Windows::Painter::Text(StringView text, Vector2f pos, const Colorf& color, Alignment align = Alignment::TopLeft, PaintLayer layer = PaintLayer::Text)

Draws a text.

The color is a text color (see Theme::Text), a color of anything else — its alpha is above 0.5 — is toned down, as it would glare otherwise.