A little clean up
This commit is contained in:
parent
3b389bdc17
commit
1155067b26
8 changed files with 234 additions and 407 deletions
|
|
@ -112,123 +112,6 @@ void Graphics::Canvas::text(
|
|||
popClamp();
|
||||
}
|
||||
|
||||
void Graphics::Canvas::drawColorwheel(const RectF& rec, const RGB& col) {
|
||||
|
||||
float const x = rec.x;
|
||||
float const y = rec.y;
|
||||
float const w = rec.z;
|
||||
float const h = rec.w;
|
||||
|
||||
HSV hsv = tp::HSV(col);
|
||||
float const hue = hsv.h / (NVG_PI * 2);
|
||||
|
||||
int i;
|
||||
float r0, r1, ax, ay, bx, by, cx, cy, aeps, r;
|
||||
NVGpaint paint;
|
||||
|
||||
nvgSave(mContext->vg);
|
||||
|
||||
cx = x + w * 0.5f;
|
||||
cy = y + h * 0.5f;
|
||||
r1 = (w < h ? w : h) * 0.5f - 5.0f;
|
||||
r0 = r1 - 13.0f;
|
||||
aeps = 0.5f / r1; // half a pixel arc length in radians (2pi cancels out).
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
float a0 = (float) i / 6.0f * NVG_PI * 2.0f - aeps;
|
||||
float a1 = (float) (i + 1.0f) / 6.0f * NVG_PI * 2.0f + aeps;
|
||||
nvgBeginPath(mContext->vg);
|
||||
nvgArc(mContext->vg, cx, cy, r0, a0, a1, NVG_CW);
|
||||
nvgArc(mContext->vg, cx, cy, r1, a1, a0, NVG_CCW);
|
||||
nvgClosePath(mContext->vg);
|
||||
ax = cx + cosf(a0) * (r0 + r1) * 0.5f;
|
||||
ay = cy + sinf(a0) * (r0 + r1) * 0.5f;
|
||||
bx = cx + cosf(a1) * (r0 + r1) * 0.5f;
|
||||
by = cy + sinf(a1) * (r0 + r1) * 0.5f;
|
||||
paint = nvgLinearGradient(
|
||||
mContext->vg,
|
||||
ax,
|
||||
ay,
|
||||
bx,
|
||||
by,
|
||||
nvgHSLA(a0 / (NVG_PI * 2), 1.0f, 0.55f, 255),
|
||||
nvgHSLA(a1 / (NVG_PI * 2), 1.0f, 0.55f, 255)
|
||||
);
|
||||
nvgFillPaint(mContext->vg, paint);
|
||||
nvgFill(mContext->vg);
|
||||
}
|
||||
|
||||
nvgBeginPath(mContext->vg);
|
||||
nvgCircle(mContext->vg, cx, cy, r0 - 0.5f);
|
||||
nvgCircle(mContext->vg, cx, cy, r1 + 0.5f);
|
||||
nvgStrokeColor(mContext->vg, nvgRGBA(0, 0, 0, 64));
|
||||
nvgStrokeWidth(mContext->vg, 1.0f);
|
||||
nvgStroke(mContext->vg);
|
||||
|
||||
// Selector
|
||||
nvgSave(mContext->vg);
|
||||
nvgTranslate(mContext->vg, cx, cy);
|
||||
nvgRotate(mContext->vg, hue * NVG_PI * 2);
|
||||
|
||||
// Marker on
|
||||
nvgStrokeWidth(mContext->vg, 2.0f);
|
||||
nvgBeginPath(mContext->vg);
|
||||
nvgRect(mContext->vg, r0 - 1, -3, r1 - r0 + 2, 6);
|
||||
nvgStrokeColor(mContext->vg, nvgRGBA(255, 255, 255, 192));
|
||||
nvgStroke(mContext->vg);
|
||||
|
||||
paint = nvgBoxGradient(mContext->vg, r0 - 3, -5, r1 - r0 + 6, 10, 2, 4, nvgRGBA(0, 0, 0, 128), nvgRGBA(0, 0, 0, 0));
|
||||
nvgBeginPath(mContext->vg);
|
||||
nvgRect(mContext->vg, r0 - 2 - 10, -4 - 10, r1 - r0 + 4 + 20, 8 + 20);
|
||||
nvgRect(mContext->vg, r0 - 2, -4, r1 - r0 + 4, 8);
|
||||
nvgPathWinding(mContext->vg, NVG_HOLE);
|
||||
nvgFillPaint(mContext->vg, paint);
|
||||
nvgFill(mContext->vg);
|
||||
|
||||
// Center triangle
|
||||
r = r0 - 6;
|
||||
ax = cosf(120.0f / 180.0f * NVG_PI) * r;
|
||||
ay = sinf(120.0f / 180.0f * NVG_PI) * r;
|
||||
bx = cosf(-120.0f / 180.0f * NVG_PI) * r;
|
||||
by = sinf(-120.0f / 180.0f * NVG_PI) * r;
|
||||
nvgBeginPath(mContext->vg);
|
||||
nvgMoveTo(mContext->vg, r, 0);
|
||||
nvgLineTo(mContext->vg, ax, ay);
|
||||
nvgLineTo(mContext->vg, bx, by);
|
||||
nvgClosePath(mContext->vg);
|
||||
paint = nvgLinearGradient(mContext->vg, r, 0, ax, ay, nvgHSLA(hue, 1.0f, 0.5f, 255), nvgRGBA(255, 255, 255, 255));
|
||||
nvgFillPaint(mContext->vg, paint);
|
||||
nvgFill(mContext->vg);
|
||||
paint = nvgLinearGradient(mContext->vg, (r + ax) * 0.5f, (0 + ay) * 0.5f, bx, by, nvgRGBA(0, 0, 0, 0), nvgRGBA(0, 0, 0, 255));
|
||||
nvgFillPaint(mContext->vg, paint);
|
||||
nvgFill(mContext->vg);
|
||||
nvgStrokeColor(mContext->vg, nvgRGBA(0, 0, 0, 64));
|
||||
nvgStroke(mContext->vg);
|
||||
|
||||
// Select circle on triangle
|
||||
float yt = hsv.v * hsv.s;
|
||||
float xt = hsv.v - 0.5 * yt;
|
||||
ay = sinf(120.0f / 180.0f * NVG_PI) * r * (-1.0f + xt * 2.0f);
|
||||
ax = cosf(120.0f / 180.0f * NVG_PI) * r * (1.0f - yt * 3.f);
|
||||
nvgStrokeWidth(mContext->vg, 2.0f);
|
||||
nvgBeginPath(mContext->vg);
|
||||
nvgCircle(mContext->vg, ax, ay, 5);
|
||||
nvgStrokeColor(mContext->vg, nvgRGBA(255, 255, 255, 192));
|
||||
nvgStroke(mContext->vg);
|
||||
|
||||
paint = nvgRadialGradient(mContext->vg, ax, ay, 7, 9, nvgRGBA(0, 0, 0, 64), nvgRGBA(0, 0, 0, 0));
|
||||
nvgBeginPath(mContext->vg);
|
||||
nvgRect(mContext->vg, ax - 20, ay - 20, 40, 40);
|
||||
nvgCircle(mContext->vg, ax, ay, 7);
|
||||
nvgPathWinding(mContext->vg, NVG_HOLE);
|
||||
nvgFillPaint(mContext->vg, paint);
|
||||
nvgFill(mContext->vg);
|
||||
|
||||
nvgRestore(mContext->vg);
|
||||
|
||||
nvgRestore(mContext->vg);
|
||||
}
|
||||
|
||||
void Graphics::Canvas::drawImage(const RectF& rec, ImageHandle* image, halnf angle, halnf alpha, halnf rounding) {
|
||||
auto imgPaint = nvgImagePattern(mContext->vg, rec.x, rec.y, rec.z, rec.w, angle, image->id, alpha);
|
||||
nvgBeginPath(mContext->vg);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue