CanvasLib
Loading...
Searching...
No Matches
CanvasLib.hpp
1#pragma once
2
3#include <functional>
4#include <memory>
5#include <string>
6
7#include "CanvasLib/Color.hpp"
8#include "CanvasLib/Colors.hpp"
9#include "CanvasLib/Vec2.hpp"
10#include <GLFW/glfw3.h>
11#include <RenderAbstraction.hpp>
12#include <glad/glad.h>
13
14#define CANVASLIB_EXPORT
15
43namespace canv
44{
45
54class CANVASLIB_EXPORT Canvas
55{
56public:
57 enum class DrawMode
58 {
59 Fill,
60 Outline
61 };
62
63 Canvas(const Canvas&) = delete;
64 Canvas(Canvas&&) = delete;
65 auto operator=(const Canvas&) -> Canvas& = delete;
66 auto operator=(Canvas&&) -> Canvas& = delete;
67
71 Canvas(uint32_t width, uint32_t height);
72 ~Canvas();
73
77 void start();
83 void setUpdateFunction(std::function<void(double)> upd);
84
88 void drawRectangle(float x, float y, float w, float h);
89
94 void drawEllipse(float cx, float cy, float rx, float ry, int segments = 40);
95
99 void setFillColor(const Color& color);
100
104 void setDrawMode(const DrawMode& drawMode);
105
109 static void enableWatches();
113 static void disableWatches();
120 static void setWatch(const std::string& key, const std::string& value);
125 static void removeWatch(const std::string& key);
126
127private:
128 [[nodiscard]] auto _xToGl(float x) const -> float;
129 [[nodiscard]] auto _yToGl(float y) const -> float;
130 [[nodiscard]] auto _normalizeSizeGl(const Vec2f& size) const -> Vec2f;
131
132 static void renderWatches();
133 static bool s_ShouldRenderWatches;
134 static std::unique_ptr<std::thread> s_WatchesRenderThread;
135 static std::mutex s_CustomWatchesMutex;
136 static std::unordered_map<std::string, std::string> s_CustomWatches;
137
138 void applyColorGl() const;
139
140 std::unique_ptr<Ra::Window> m_Window;
141 std::function<void(double)> m_UpdateFunction;
142 Color m_FillColor;
143 Ra::RendererAPI::DrawMode m_DrawMode;
144 Vec2<uint32_t> m_Size;
145 glm::mat4 m_Projection;
146 double m_LastFrameTime;
147};
148
149} // namespace canv
The main class representing the canvas. To use it you only need to:
Definition CanvasLib.hpp:55
static void disableWatches()
Disables rendering watches in terminal.
static void enableWatches()
Enables rendering watches in terminal.
void setFillColor(const Color &color)
sets the fill color
void drawRectangle(float x, float y, float w, float h)
draws a rectangle with specified coordinates and size
Canvas(uint32_t width, uint32_t height)
Initializes the name field to the name of the project.
static void setWatch(const std::string &key, const std::string &value)
Adds or updates entry in watches table.
void setDrawMode(const DrawMode &drawMode)
sets draw mode from Canvas::DrawMode enum
void drawEllipse(float cx, float cy, float rx, float ry, int segments=40)
draws an ellipse, if u want circle just pass same x and y radius for triangle use segments = 3
void setUpdateFunction(std::function< void(double)> upd)
sets update function that will be called every frame
static void removeWatch(const std::string &key)
Removes entry from watches table, does nothing if it doesn't exist.
void start()
starts the main window cycle IN MAIN THREAD
Utility Color class operating uint8(0..255) values.
Definition Color.hpp:15
Utility Vec2 class with x, y coordinates.
Definition Vec2.hpp:16
Definition CanvasLib.hpp:44