#pragma once #include #include #include "gl.h" #include "vec.h" #include "framebuffer.h" #include "image.h" #include "model/draw.h" #include "shader.h" #include "types.h" // A box blur `radius` texels wide each way over the texture's `region` (UV min, max). Outside it is clear. struct TextureBlur { float radius = 0; Vec4 region{}; }; class Canvas : public Framebuffer { public: static constexpr float TEXTURE_VERTICES[] = {0, 0, 0.0f, 0.0f, 1, 0, 1.0f, 0.0f, 1, 1, 1.0f, 1.0f, 0, 1, 0.0f, 1.0f}; static constexpr auto PIVOT_SIZE = Vec2(8, 8); static constexpr auto ZOOM_MIN = 1.0f; static constexpr auto ZOOM_MAX = 2000.0f; static constexpr auto DASH_LENGTH = 4.0f; static constexpr auto DASH_GAP = 1.0f; static constexpr auto DASH_OFFSET = 1.0f; static constexpr auto STEP = 1.0f; static constexpr auto STEP_FAST = 5.0f; static constexpr auto ZOOM_LEVEL_STEP = 1; static constexpr std::array ZOOM_LEVELS = {1.0f, 2.0f, 5.0f, 10.0f, 15.0f, 25.0f, 33.0f, 50.0f, 66.0f, 75.0f, 100.0f, 125.0f, 150.0f, 200.0f, 300.0f, 400.0f, 600.0f, 800.0f, 1200.0f, 2000.0f}; static constexpr auto GRID_SIZE_MIN = 1; static constexpr auto GRID_SIZE_MAX = 10000; static constexpr auto GRID_OFFSET_MIN = 0; static constexpr auto GRID_OFFSET_MAX = 10000; static constexpr auto CHECKER_SIZE = 32.0f; static constexpr float AXIS_VERTICES[] = {-1.0f, 0.0f, 1.0f, 0.0f}; static constexpr float GRID_VERTICES[] = {-1.f, -1.f, 0.f, 0.f, 3.f, -1.f, 2.f, 0.f, -1.f, 3.f, 0.f, 2.f}; static constexpr float RECT_VERTICES[] = {0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f}; static constexpr int RECT_VERTEX_COUNT = 4; static constexpr int LINE_VERTEX_COUNT = 2; static constexpr GLuint TEXTURE_INDICES[] = {0, 1, 2, 2, 3, 0}; static constexpr auto BORDER_DASH_LENGTH = 1.0f; static constexpr auto BORDER_DASH_GAP = 0.5f; static constexpr auto BORDER_DASH_OFFSET = 0.0f; static constexpr auto PIVOT_COLOR = COLOR_PINK; GLuint axisVAO = 0; GLuint axisVBO = 0; GLuint rectVAO = 0; GLuint rectVBO = 0; GLuint gridVAO = 0; GLuint gridVBO = 0; GLuint textureVAO = 0; GLuint textureVBO = 0; GLuint textureEBO = 0; Canvas(); Canvas(Vec2); ~Canvas(); Mat4 transform_get(float = 100.0f, Vec2 = {}) const; void axes_render(ShaderProgram&, float, Vec2, Vec4 = Vec4(1.0f)) const; void grid_render(ShaderProgram&, float, Vec2, IVec2 = IVec2(32, 32), IVec2 = {}, Vec4 = Vec4(1.0f)) const; void texture_render(ShaderProgram&, GLuint, Mat4 = Mat4(1.0f), Vec4 = Vec4(1.0f), Vec4 = {}, float* = (float*)TEXTURE_VERTICES, Vec2 = {}, float = 0.0f, TextureBlur = {}) const; void layer_render(ShaderProgram&, GLuint, Vec2, const Mat4&, const Draw&, Vec4, Vec4) const; void rect_fill_render(ShaderProgram&, const Mat4&, const Mat4&, Vec4 = Vec4(1.0f)) const; void layers_render(ShaderProgram&, const Model&, const Animation&, const DrawOptions&, const Mat4&, const std::function&, const std::function& = {}) const; void dashed_render(ShaderProgram&, const Mat4&, const Mat4&, Vec4, float, float, float, GLenum, int) const; void rect_render(ShaderProgram&, const Mat4&, const Mat4&, Vec4 = Vec4(1.0f), float dashLength = DASH_LENGTH, float dashGap = DASH_GAP, float dashOffset = DASH_OFFSET) const; void line_render(ShaderProgram&, const Mat4&, Vec2, Vec2, Vec4 = Vec4(1.0f), float dashLength = DASH_LENGTH, float dashGap = DASH_GAP, float dashOffset = DASH_OFFSET) const; float zoom_level_get(float, int) const; void zoom_level_adjust(float&, Vec2&, Vec2, int) const; Vec2 position_translate(float&, Vec2&, Vec2) const; void set_to_rect(float& zoom, Vec2& pan, Vec4 rect) const; };