Merge pull request #380 from ccawley2011/gdiplus-arcs

Implement arcs with GDI+
This commit is contained in:
Rob Loach 2021-12-16 22:16:58 -05:00 committed by GitHub
commit 156bfbfb26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 2 deletions

View File

@ -47,6 +47,8 @@ NK_API void nk_gdip_image_free(struct nk_image image);
#include <stdlib.h>
#include <malloc.h>
#define _USE_MATH_DEFINES
#include <math.h>
/* manually declare everything GDI+ needs, because
GDI+ headers are not usable from C */
@ -319,6 +321,10 @@ GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics *graphics, GpPen *pen, INT x, INT y,
INT width, INT height, REAL startAngle, REAL sweepAngle);
GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics *graphics, GpPen *pen, INT x, INT y,
INT width, INT height, REAL startAngle, REAL sweepAngle);
GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics *graphics, GpBrush *brush, INT x, INT y,
INT width, INT height, REAL startAngle, REAL sweepAngle);
@ -580,6 +586,21 @@ nk_gdip_stroke_curve(struct nk_vec2i p1,
GdipDrawBezierI(gdip.memory, gdip.pen, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y);
}
static void
nk_gdip_fill_arc(short cx, short cy, unsigned short r, float amin, float adelta, struct nk_color col)
{
GdipSetSolidFillColor(gdip.brush, convert_color(col));
GdipFillPieI(gdip.memory, gdip.brush, cx - r, cy - r, r * 2, r * 2, amin * (180/M_PI), adelta * (180/M_PI));
}
static void
nk_gdip_stroke_arc(short cx, short cy, unsigned short r, float amin, float adelta, unsigned short line_thickness, struct nk_color col)
{
GdipSetPenWidth(gdip.pen, (REAL)line_thickness);
GdipSetPenColor(gdip.pen, convert_color(col));
GdipDrawPieI(gdip.memory, gdip.pen, cx - r, cy - r, r * 2, r * 2, amin * (180/M_PI), adelta * (180/M_PI));
}
static void
nk_gdip_draw_text(short x, short y, unsigned short w, unsigned short h,
const char *text, int len, GdipFont *font, struct nk_color cbg, struct nk_color cfg)
@ -1165,9 +1186,15 @@ nk_gdip_prerender_gui(enum nk_anti_aliasing AA)
const struct nk_command_image *i = (const struct nk_command_image *)cmd;
nk_gdip_draw_image(i->x, i->y, i->w, i->h, i->img, i->col);
} break;
case NK_COMMAND_ARC: {
const struct nk_command_arc *i = (const struct nk_command_arc *)cmd;
nk_gdip_stroke_arc(i->cx, i->cy, i->r, i->a[0], i->a[1], i->line_thickness, i->color);
} break;
case NK_COMMAND_ARC_FILLED: {
const struct nk_command_arc_filled *i = (const struct nk_command_arc_filled *)cmd;
nk_gdip_fill_arc(i->cx, i->cy, i->r, i->a[0], i->a[1], i->color);
} break;
case NK_COMMAND_RECT_MULTI_COLOR:
case NK_COMMAND_ARC:
case NK_COMMAND_ARC_FILLED:
default: break;
}
}