123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697 |
- #ifndef NANOVG_H
- #define NANOVG_H
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define NVG_PI 3.14159265358979323846264338327f
- #ifdef _MSC_VER
- #pragma warning(push)
- #pragma warning(disable: 4201)
- #endif
- typedef struct NVGcontext NVGcontext;
- struct NVGcolor {
- union {
- float rgba[4];
- struct {
- float r,g,b,a;
- };
- };
- };
- typedef struct NVGcolor NVGcolor;
- struct NVGpaint {
- float xform[6];
- float extent[2];
- float radius;
- float feather;
- NVGcolor innerColor;
- NVGcolor outerColor;
- int image;
- };
- typedef struct NVGpaint NVGpaint;
- enum NVGwinding {
- NVG_CCW = 1,
- NVG_CW = 2,
- };
- enum NVGsolidity {
- NVG_SOLID = 1,
- NVG_HOLE = 2,
- };
- enum NVGlineCap {
- NVG_BUTT,
- NVG_ROUND,
- NVG_SQUARE,
- NVG_BEVEL,
- NVG_MITER,
- };
- enum NVGalign {
-
- NVG_ALIGN_LEFT = 1<<0,
- NVG_ALIGN_CENTER = 1<<1,
- NVG_ALIGN_RIGHT = 1<<2,
-
- NVG_ALIGN_TOP = 1<<3,
- NVG_ALIGN_MIDDLE = 1<<4,
- NVG_ALIGN_BOTTOM = 1<<5,
- NVG_ALIGN_BASELINE = 1<<6,
- };
- enum NVGblendFactor {
- NVG_ZERO = 1<<0,
- NVG_ONE = 1<<1,
- NVG_SRC_COLOR = 1<<2,
- NVG_ONE_MINUS_SRC_COLOR = 1<<3,
- NVG_DST_COLOR = 1<<4,
- NVG_ONE_MINUS_DST_COLOR = 1<<5,
- NVG_SRC_ALPHA = 1<<6,
- NVG_ONE_MINUS_SRC_ALPHA = 1<<7,
- NVG_DST_ALPHA = 1<<8,
- NVG_ONE_MINUS_DST_ALPHA = 1<<9,
- NVG_SRC_ALPHA_SATURATE = 1<<10,
- };
- enum NVGcompositeOperation {
- NVG_SOURCE_OVER,
- NVG_SOURCE_IN,
- NVG_SOURCE_OUT,
- NVG_ATOP,
- NVG_DESTINATION_OVER,
- NVG_DESTINATION_IN,
- NVG_DESTINATION_OUT,
- NVG_DESTINATION_ATOP,
- NVG_LIGHTER,
- NVG_COPY,
- NVG_XOR,
- };
- struct NVGcompositeOperationState {
- int srcRGB;
- int dstRGB;
- int srcAlpha;
- int dstAlpha;
- };
- typedef struct NVGcompositeOperationState NVGcompositeOperationState;
- struct NVGglyphPosition {
- const char* str;
- float x;
- float minx, maxx;
- };
- typedef struct NVGglyphPosition NVGglyphPosition;
- struct NVGtextRow {
- const char* start;
- const char* end;
- const char* next;
- float width;
- float minx, maxx;
- };
- typedef struct NVGtextRow NVGtextRow;
- enum NVGimageFlags {
- NVG_IMAGE_GENERATE_MIPMAPS = 1<<0,
- NVG_IMAGE_REPEATX = 1<<1,
- NVG_IMAGE_REPEATY = 1<<2,
- NVG_IMAGE_FLIPY = 1<<3,
- NVG_IMAGE_PREMULTIPLIED = 1<<4,
- NVG_IMAGE_NEAREST = 1<<5,
- };
- void nvgBeginFrame(NVGcontext* ctx, float windowWidth, float windowHeight, float devicePixelRatio);
- void nvgCancelFrame(NVGcontext* ctx);
- void nvgEndFrame(NVGcontext* ctx);
- void nvgGlobalCompositeOperation(NVGcontext* ctx, int op);
- void nvgGlobalCompositeBlendFunc(NVGcontext* ctx, int sfactor, int dfactor);
- void nvgGlobalCompositeBlendFuncSeparate(NVGcontext* ctx, int srcRGB, int dstRGB, int srcAlpha, int dstAlpha);
- NVGcolor nvgRGB(unsigned char r, unsigned char g, unsigned char b);
- NVGcolor nvgRGBf(float r, float g, float b);
- NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
- NVGcolor nvgRGBAf(float r, float g, float b, float a);
- NVGcolor nvgLerpRGBA(NVGcolor c0, NVGcolor c1, float u);
- NVGcolor nvgTransRGBA(NVGcolor c0, unsigned char a);
- NVGcolor nvgTransRGBAf(NVGcolor c0, float a);
- NVGcolor nvgHSL(float h, float s, float l);
- NVGcolor nvgHSLA(float h, float s, float l, unsigned char a);
- void nvgSave(NVGcontext* ctx);
- void nvgRestore(NVGcontext* ctx);
- void nvgReset(NVGcontext* ctx);
- void nvgShapeAntiAlias(NVGcontext* ctx, int enabled);
- void nvgStrokeColor(NVGcontext* ctx, NVGcolor color);
- void nvgStrokePaint(NVGcontext* ctx, NVGpaint paint);
- void nvgFillColor(NVGcontext* ctx, NVGcolor color);
- void nvgFillPaint(NVGcontext* ctx, NVGpaint paint);
- void nvgMiterLimit(NVGcontext* ctx, float limit);
- void nvgStrokeWidth(NVGcontext* ctx, float size);
- void nvgLineCap(NVGcontext* ctx, int cap);
- void nvgLineJoin(NVGcontext* ctx, int join);
- void nvgGlobalAlpha(NVGcontext* ctx, float alpha);
- void nvgResetTransform(NVGcontext* ctx);
- void nvgTransform(NVGcontext* ctx, float a, float b, float c, float d, float e, float f);
- void nvgTranslate(NVGcontext* ctx, float x, float y);
- void nvgRotate(NVGcontext* ctx, float angle);
- void nvgSkewX(NVGcontext* ctx, float angle);
- void nvgSkewY(NVGcontext* ctx, float angle);
- void nvgScale(NVGcontext* ctx, float x, float y);
- void nvgCurrentTransform(NVGcontext* ctx, float* xform);
- void nvgTransformIdentity(float* dst);
- void nvgTransformTranslate(float* dst, float tx, float ty);
- void nvgTransformScale(float* dst, float sx, float sy);
- void nvgTransformRotate(float* dst, float a);
- void nvgTransformSkewX(float* dst, float a);
- void nvgTransformSkewY(float* dst, float a);
- void nvgTransformMultiply(float* dst, const float* src);
- void nvgTransformPremultiply(float* dst, const float* src);
- int nvgTransformInverse(float* dst, const float* src);
- void nvgTransformPoint(float* dstx, float* dsty, const float* xform, float srcx, float srcy);
- float nvgDegToRad(float deg);
- float nvgRadToDeg(float rad);
- int nvgCreateImage(NVGcontext* ctx, const char* filename, int imageFlags);
- int nvgCreateImageMem(NVGcontext* ctx, int imageFlags, unsigned char* data, int ndata);
- int nvgCreateImageRGBA(NVGcontext* ctx, int w, int h, int imageFlags, const unsigned char* data);
- void nvgUpdateImage(NVGcontext* ctx, int image, const unsigned char* data);
- void nvgImageSize(NVGcontext* ctx, int image, int* w, int* h);
- void nvgDeleteImage(NVGcontext* ctx, int image);
- NVGpaint nvgLinearGradient(NVGcontext* ctx, float sx, float sy, float ex, float ey,
- NVGcolor icol, NVGcolor ocol);
- NVGpaint nvgBoxGradient(NVGcontext* ctx, float x, float y, float w, float h,
- float r, float f, NVGcolor icol, NVGcolor ocol);
- NVGpaint nvgRadialGradient(NVGcontext* ctx, float cx, float cy, float inr, float outr,
- NVGcolor icol, NVGcolor ocol);
- NVGpaint nvgImagePattern(NVGcontext* ctx, float ox, float oy, float ex, float ey,
- float angle, int image, float alpha);
- void nvgScissor(NVGcontext* ctx, float x, float y, float w, float h);
- void nvgIntersectScissor(NVGcontext* ctx, float x, float y, float w, float h);
- void nvgResetScissor(NVGcontext* ctx);
- void nvgBeginPath(NVGcontext* ctx);
- void nvgMoveTo(NVGcontext* ctx, float x, float y);
- void nvgLineTo(NVGcontext* ctx, float x, float y);
- void nvgBezierTo(NVGcontext* ctx, float c1x, float c1y, float c2x, float c2y, float x, float y);
- void nvgQuadTo(NVGcontext* ctx, float cx, float cy, float x, float y);
- void nvgArcTo(NVGcontext* ctx, float x1, float y1, float x2, float y2, float radius);
- void nvgClosePath(NVGcontext* ctx);
- void nvgPathWinding(NVGcontext* ctx, int dir);
- void nvgArc(NVGcontext* ctx, float cx, float cy, float r, float a0, float a1, int dir);
- void nvgRect(NVGcontext* ctx, float x, float y, float w, float h);
- void nvgRoundedRect(NVGcontext* ctx, float x, float y, float w, float h, float r);
- void nvgRoundedRectVarying(NVGcontext* ctx, float x, float y, float w, float h, float radTopLeft, float radTopRight, float radBottomRight, float radBottomLeft);
- void nvgEllipse(NVGcontext* ctx, float cx, float cy, float rx, float ry);
- void nvgCircle(NVGcontext* ctx, float cx, float cy, float r);
- void nvgFill(NVGcontext* ctx);
- void nvgStroke(NVGcontext* ctx);
- int nvgCreateFont(NVGcontext* ctx, const char* name, const char* filename);
- int nvgCreateFontAtIndex(NVGcontext* ctx, const char* name, const char* filename, const int fontIndex);
- int nvgCreateFontMem(NVGcontext* ctx, const char* name, unsigned char* data, int ndata, int freeData);
- int nvgCreateFontMemAtIndex(NVGcontext* ctx, const char* name, unsigned char* data, int ndata, int freeData, const int fontIndex);
- int nvgFindFont(NVGcontext* ctx, const char* name);
- int nvgAddFallbackFontId(NVGcontext* ctx, int baseFont, int fallbackFont);
- int nvgAddFallbackFont(NVGcontext* ctx, const char* baseFont, const char* fallbackFont);
- void nvgResetFallbackFontsId(NVGcontext* ctx, int baseFont);
- void nvgResetFallbackFonts(NVGcontext* ctx, const char* baseFont);
- void nvgFontSize(NVGcontext* ctx, float size);
- void nvgFontBlur(NVGcontext* ctx, float blur);
- void nvgTextLetterSpacing(NVGcontext* ctx, float spacing);
- void nvgTextLineHeight(NVGcontext* ctx, float lineHeight);
- void nvgTextAlign(NVGcontext* ctx, int align);
- void nvgFontFaceId(NVGcontext* ctx, int font);
- void nvgFontFace(NVGcontext* ctx, const char* font);
- float nvgText(NVGcontext* ctx, float x, float y, const char* string, const char* end);
- void nvgTextBox(NVGcontext* ctx, float x, float y, float breakRowWidth, const char* string, const char* end);
- float nvgTextBounds(NVGcontext* ctx, float x, float y, const char* string, const char* end, float* bounds);
- void nvgTextBoxBounds(NVGcontext* ctx, float x, float y, float breakRowWidth, const char* string, const char* end, float* bounds);
- int nvgTextGlyphPositions(NVGcontext* ctx, float x, float y, const char* string, const char* end, NVGglyphPosition* positions, int maxPositions);
- void nvgTextMetrics(NVGcontext* ctx, float* ascender, float* descender, float* lineh);
- int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, float breakRowWidth, NVGtextRow* rows, int maxRows);
- enum NVGtexture {
- NVG_TEXTURE_ALPHA = 0x01,
- NVG_TEXTURE_RGBA = 0x02,
- };
- struct NVGscissor {
- float xform[6];
- float extent[2];
- };
- typedef struct NVGscissor NVGscissor;
- struct NVGvertex {
- float x,y,u,v;
- };
- typedef struct NVGvertex NVGvertex;
- struct NVGpath {
- int first;
- int count;
- unsigned char closed;
- int nbevel;
- NVGvertex* fill;
- int nfill;
- NVGvertex* stroke;
- int nstroke;
- int winding;
- int convex;
- };
- typedef struct NVGpath NVGpath;
- struct NVGparams {
- void* userPtr;
- int edgeAntiAlias;
- int (*renderCreate)(void* uptr);
- int (*renderCreateTexture)(void* uptr, int type, int w, int h, int imageFlags, const unsigned char* data);
- int (*renderDeleteTexture)(void* uptr, int image);
- int (*renderUpdateTexture)(void* uptr, int image, int x, int y, int w, int h, const unsigned char* data);
- int (*renderGetTextureSize)(void* uptr, int image, int* w, int* h);
- void (*renderViewport)(void* uptr, float width, float height, float devicePixelRatio);
- void (*renderCancel)(void* uptr);
- void (*renderFlush)(void* uptr);
- void (*renderFill)(void* uptr, NVGpaint* paint, NVGcompositeOperationState compositeOperation, NVGscissor* scissor, float fringe, const float* bounds, const NVGpath* paths, int npaths);
- void (*renderStroke)(void* uptr, NVGpaint* paint, NVGcompositeOperationState compositeOperation, NVGscissor* scissor, float fringe, float strokeWidth, const NVGpath* paths, int npaths);
- void (*renderTriangles)(void* uptr, NVGpaint* paint, NVGcompositeOperationState compositeOperation, NVGscissor* scissor, const NVGvertex* verts, int nverts, float fringe);
- void (*renderDelete)(void* uptr);
- };
- typedef struct NVGparams NVGparams;
- NVGcontext* nvgCreateInternal(NVGparams* params);
- void nvgDeleteInternal(NVGcontext* ctx);
- NVGparams* nvgInternalParams(NVGcontext* ctx);
- void nvgDebugDumpPathCache(NVGcontext* ctx);
- #ifdef _MSC_VER
- #pragma warning(pop)
- #endif
- #define NVG_NOTUSED(v) for (;;) { (void)(1 ? (void)0 : ( (void)(v) ) ); break; }
- #ifdef __cplusplus
- }
- #endif
- #endif
|