Modules/Graphics/public/Graphics.hpp
Шурупов Илья Викторович b32b60d470 Give the colour popup wheel, square, RGB, HSV and HSL pages
The colour popup now has five pages like the reference panel: the
wheel, a saturation/value square with a hue strip, and RGB, HSV and HSL
sliders whose tracks show the colour they would pick. A footer holds
the old/new colour swatch (tapping the old half restores it), a hex
field and a Copy button. Grey colours keep their hue across pages.
On tablets the menu gains a Color submenu with the colour commands and
lightness presets, and Settings lists the Color menu.

Painter gains a linear gradient fill, Slider an optional gradient track
and Widgets a ColorSquare.
2026-10-18 01:36:19 +03:00

152 lines
No EOL
3.6 KiB
C++

#pragma once
#include "Window.hpp"
#include "Color.hpp"
#include "Rect.hpp"
#include "Buffer.hpp"
struct NVGcontext;
namespace tp {
class DebugGUI {
class Context;
Context* mContext;
public:
explicit DebugGUI(Window* window);
~DebugGUI();
void procBegin();
void procEnd();
void drawBegin();
void drawEnd();
};
class Canvas {
class Context;
Context* mContext;
public:
explicit Canvas(Window* window);
~Canvas();
void procBegin() {}
void procEnd() {}
void drawBegin();
void drawEnd();
void drawWindowChrome();
public:
enum Align : int2 {
CC = 0x0000,
CT = 0x0001,
CB = 0x0002,
LC = 0x0100,
LT = 0x0101,
LB = 0x0102,
RC = 0x0200,
RT = 0x0201,
RB = 0x0202,
};
struct ImageHandle {
ualni id = 0;
};
struct ColorWheel {
HSV color = { 0.13, 0.5, 1 };
halnf thickness = 20;
halnf margin = 5;
void fromPoint(const RectF& area, const Vec2F& point);
};
void setOrigin(const Vec2F& origin);
void pushClamp(const RectF& rec);
void popClamp();
[[nodiscard]] const RectF& getClampedArea() const;
void debugCross(RectF rec, const RGBA& col);
void rect(RectF rec, const RGBA& col, halnf round = 0);
void gradientRect(RectF rec, const RGBA& from, const RGBA& to, bool horizontal, halnf round = 0);
void frame(RectF rec, const RGBA& col, halnf round = 0);
void outline(RectF rec, const RGBA& col, halnf round, halnf width);
void circle(Vec2F pos, halnf size, const RGBA& col);
void circleOutline(Vec2F pos, halnf size, const RGBA& col, halnf width);
void polyline(const Vec2F* points, int count, const RGBA& col, halnf width);
void polygon(const Vec2F* points, int count, const RGBA& col);
void text(const char*, const RectF&, halnf size, Align, halnf padding, const RGBA&);
void rotatedText(const char* text, Vec2F center, halnf size, halnf angle, const RGBA& col);
[[nodiscard]] halnf textWidth(const char*, halnf size);
void colorWheel(const RectF& rec, const ColorWheel& colorWheel);
void line(Vec2F start, Vec2F end, const RGBA& col, halnf thickness);
ImageHandle createImageFromTextId(ualni id, Vec2F size);
void updateTextureID(ImageHandle handle, ualni id);
ImageHandle createImageFromFile(const char* path);
ImageHandle createImageFromMemoryRGBA(int width, int height, const unsigned char* rgba);
void updateImageRGBA(ImageHandle image, const unsigned char* rgba);
void deleteImageHandle(ImageHandle image);
void drawImage(RectF rec, ImageHandle* image, halnf angle = 0, halnf alpha = 1.f, halnf rounding = 0.f);
private:
void fillWindowBase(const WindowFrame& frame);
static void cutRoundedCorners(NVGcontext* vg, const WindowFrame& frame);
static void paintOutline(NVGcontext* vg, const WindowFrame& frame);
static void paintShadow(NVGcontext* vg, const WindowFrame& frame, bool focused);
Buffer<RectF> mScissors;
bool mIsClamping = false;
Vec2F mOrigin = { 0, 0 };
};
class Graphics {
public:
explicit Graphics(Window* window) :
mWindow(window),
mCanvas(window),
mGui(window) {}
void procBegin() {
mCanvas.procBegin();
mGui.procBegin();
}
void procEnd() {
mCanvas.procEnd();
mGui.procEnd();
}
void drawBegin() {
mFrameActive = mWindow->frameBegin();
if (!mFrameActive) return;
mCanvas.drawBegin();
mGui.drawBegin();
}
void drawEnd() {
if (!mFrameActive) return;
mCanvas.drawEnd();
mGui.drawEnd();
mCanvas.drawWindowChrome();
mWindow->frameEnd();
mFrameActive = false;
}
Canvas* getCanvas() { return &mCanvas; }
private:
Window* mWindow;
Canvas mCanvas;
DebugGUI mGui;
bool mFrameActive = false;
};
}