Drawing Utilities - Horizon-NTH/HorizonGUI GitHub Wiki
Drawing Utilities
Introduction
The graphics utilities in the hgui::kernel
namespace provide a comprehensive set of tools for drawing and
managing various shapes and lines in a graphical application. These classes simplify rendering operations by
allowing you to create and manage geometric shapes such as rectangles, triangles, circles, and lines.
These utilities will be usable inside a Canvas.
Table of Contents
Drawer
Overview
The Drawer
class, part of the hgui::kernel
namespace, provides a versatile tool for drawing shapes and
lines in a graphical application. It simplifies rendering operations by allowing you to create and manage
geometric shapes such as rectangles, triangles, circles, and lines. The class can be found inside the header file Drawer.h
.
Constructors
Drawer(const point& position, const size& size)
: Constructs aDrawer
object with the position and size of the drawing area.
Member Functions
-
void draw_rectangle(const point& topLeftVertex, const point& rightBottomVertex, const color& color, fill = true, float thickness = 10.0f)
: Draws a rectangle with the specified vertices, color, fill mode, and line thickness. -
void draw_triangle(const point& firstVertex, const point& secondVertex, const point& thirdVertex, const color& color, bool fill = true, float thickness = 10.0f)
: Draws a triangle with the specified vertices, color, fill mode, and line thickness. -
void draw_circle(const point& centerPosition, float radius, the color& color, bool fill = true, float thickness = 10.0f)
: Draws a circle with the specified center, radius, color, fill mode, and line thickness. -
void draw_line(const point& firstVertex, const point& secondVertex, const color& color, float thickness = 1.0f)
: Draws a line between two specified vertices with the given color and thickness. -
const std::shared_ptr<std::vector<std::shared_ptr<shape::Shape>>>& get_shapes() const
: Retrieves a collection of shapes drawn with theDrawer
. -
void draw() const
: Renders all the shapes created with theDrawer
. -
std::pair<point, size> get_placement() const
: Retrieves the position and size of the drawing area. -
void set_placement(const point& position, const size& size)
: Sets the position and size of the drawing area.
Shape
Overview
The Shape
class, part of the hgui::kernel::shape
namespace, serves as a base class for different geometric
shapes that can be drawn using the Drawer
class. It encapsulates common properties and functionality
for these shapes. The class is located in the header file Shape.h
.
ShapeData
ShapeData
is a typedef that represent different data that can be stored in function of each shape.
typedef std::variant<
std::pair<hgui::point, hgui::point>, // For rectangle
std::pair<hgui::point, HGUI_PRECISION>, // For circle
std::array<hgui::point, 3>, // For triangle
std::tuple<hgui::point, hgui::point, HGUI_PRECISION> // For line
> ShapeData;
Constructors
Shape(bool fill, float thickness, const color& color, const ShapeData& data)
: Constructs aShape
object with the specified fill mode, thickness, color and ShapeData.
Member Functions
-
virtual void draw(const point& canvasPosition, const size& canvasSize) const = 0
: A pure virtual function that must be implemented by derived shape classes. It defines how the shape is rendered and need the position and size of the canvas area. -
float get_thickness() const
: Retrieves the thickness of the shape's lines. -
bool is_fill() const
: Checks whether the shape is filled or not. -
const color& get_color() const
: Retrieves the color of the shape. -
void set_color(const color& newColor)
: Sets the color of the shape. -
const ShapeData& get_data() const
: Retrieves the ShapeData of the shape.
Circle
Overview
The Circle
class, part of the hgui::kernel::shape
namespace, represents a circle shape that can be drawn
using the Drawer
class. It inherits from the Shape
base class and implements the
draw
function to render a circle. The class is located in the header file Circle.h
.
Constructors
Circle(const point& centerPosition, float radius, const color& color, bool fill, float thickness)
: Constructs aCircle
object with the specified center position, radius, color, fill mode, and thickness.
Rectangle
Overview
The Rectangle
class, part of the hgui::kernel::shape
namespace, represents a rectangle shape that can be
drawn using the Drawer
class. It inherits from the Shape
base class and implements the
draw
function to render a rectangle. The class is located in the header file Rectangle.h
.
Constructors
Rectangle(const point& topLeftVertex, const point& bottomRightVertex, const color& color, bool fill, float thickness)
: Constructs aRectangle
object with the specified top-left and bottom-right vertices, color, fill mode, and thickness.
Straight Line
Overview
The Straight Line
class, part of the hgui::kernel::shape
namespace, represents a straight line segment
that can be drawn using the Drawer
class. It inherits from the Shape
base class and
the draw
function to render a straight line. The class is located in the header file StraightLine.h
.
Constructors
StraightLine(const point& firstVertex, const point& secondVertex, const color& color, float thickness)
: Constructs aStraight Line
object with the specified first and second vertices, color, and thickness.
Triangle
Overview
The Triangle
class, part of the hgui::kernel::shape
namespace, represents a triangular shape that can be drawn
using the Drawer
class. It inherits from the Shape
base class and implements the draw
function to render a triangle. The class is located in the header file Triangle.h
.