Canvas - Horizon-NTH/HorizonGUI GitHub Wiki

Canvas

Overview

The Canvas class, located in the hgui::kernel namespace, is an essential element within your graphical application for drawing and managing various shapes and lines. It extends the Widget class and provides a canvas for creating interactive graphics and visual elements. This class is highly versatile, enabling you to customize by drawing shapes with the associated Drawer class, or render complex graphics with a custom shader. The class can be found in the header file Canvas.h.

Constructors

  • Canvas(const std::shared_ptr<Shader>& shader, const size& size, const point& position, const color& color): Constructs a Canvas object with the specified shader, size, position and color.

Member Functions

  • const std::shared_ptr<kernel::Drawer>& get_drawer() const: Retrieves the associated Drawer object, allowing you to draw various shapes on the Canvas.

Example Usage

#include <hgui/header/Canvas.h>

// Example Usage of Canvas class
std::shared_ptr<hgui::kernel::Shader> shader = /* initialize shader */;
hgui::size canvasSize(800, 600);
hgui::point canvasPosition(100, 100);
hgui::color canvasColor(0.7f, 0.2f, 0.4f);

hgui::kernel::Canvas canvas(shader, canvasSize, canvasPosition, canvasColor);

// Set the position of the Canva
hgui::point newPosition(200, 200);
canvas.set_position(newPosition);

// Get the associated Drawer for drawing shapes and lines
std::shared_ptr<hgui::kernel::Drawer> canvasDrawer = canvas.get_drawer();
canvasDrawer->draw_rectangle(hgui::point(10, 10), hgui::point(50, 50), hgui::color(0.1f, 0.5f, 0.9f), true);
canvasDrawer->draw_line(hgui::point(20, 20), hgui::point(70, 70), hgui::color(0.4f, 0.8f, 0.1f), 2.0f);

// Draw the Canvas
canvas.draw();

Note: In the "Example Usage" section, we demonstrate how to create a Canvas object with a shader, size, position, color. You can customize the position of the Canvas, access the associated Drawer to draw shapes and lines, and render the Canvas. The Canvas class is an ideal tool for creating interactive graphics and visual elements within your graphical application.

⚠️ **GitHub.com Fallback** ⚠️