Fixes and improvements to the graphics module

This commit is contained in:
IlyaShurupov 2024-07-17 09:40:49 +03:00 committed by Ilya Shurupov
parent 860474654a
commit 5e3f5594b8
19 changed files with 161 additions and 55 deletions

View file

@ -37,7 +37,9 @@ Canvas::~Canvas() {
delete mContext;
}
void Canvas::rect(const RectF& rec, const RGBA& col, halnf round) {
void Canvas::rect(RectF rec, const RGBA& col, halnf round) {
rec.pos += mOrigin;
nvgBeginPath(mContext->vg);
if (round == 0) {
@ -50,7 +52,9 @@ void Canvas::rect(const RectF& rec, const RGBA& col, halnf round) {
nvgFill(mContext->vg);
}
void Canvas::circle(const Vec2F& pos, halnf size, const RGBA& col) {
void Canvas::circle(Vec2F pos, halnf size, const RGBA& col) {
pos += mOrigin;
nvgBeginPath(mContext->vg);
nvgCircle(mContext->vg, pos.x, pos.y, size);
@ -58,6 +62,10 @@ void Canvas::circle(const Vec2F& pos, halnf size, const RGBA& col) {
nvgFill(mContext->vg);
}
void Canvas::setOrigin(const Vec2F& origin) {
mOrigin = origin;
}
void Canvas::pushClamp(const RectF& rec) {
RectF intersection = rec;
if (mScissors.size()) {
@ -82,7 +90,9 @@ void Canvas::popClamp() {
void Canvas::text(
const char* string, const RectF& aRec, halnf size, Align align, halnf marging, const RGBA& col
) {
RectF rec = { aRec.x + marging, aRec.y + marging, aRec.z - marging * 2, aRec.w - marging * 2 };
rec.pos += mOrigin;
pushClamp(rec);
@ -121,7 +131,9 @@ void Canvas::text(
popClamp();
}
void Canvas::drawImage(const RectF& rec, ImageHandle* image, halnf angle, halnf alpha, halnf rounding) {
void Canvas::drawImage(RectF rec, ImageHandle* image, halnf angle, halnf alpha, halnf rounding) {
rec.pos += mOrigin;
auto imgPaint = nvgImagePattern(mContext->vg, rec.x, rec.y, rec.z, rec.w, angle, image->id, alpha);
nvgBeginPath(mContext->vg);
nvgRoundedRect(mContext->vg, rec.x, rec.y, rec.z, rec.w, rounding);