diff --git a/example/demo.c b/example/demo.c index 944b330..766b837 100644 --- a/example/demo.c +++ b/example/demo.c @@ -24,9 +24,9 @@ #define ICON_LOGIN 0xE740 #define ICON_TRASH 0xE729 -static float minf(float a, float b) { return a < b ? a : b; } +//static float minf(float a, float b) { return a < b ? a : b; } static float maxf(float a, float b) { return a > b ? a : b; } -static float absf(float a) { return a >= 0.0f ? a : -a; } +//static float absf(float a) { return a >= 0.0f ? a : -a; } static float clampf(float a, float mn, float mx) { return a < mn ? mn : (a > mx ? mx : a); } // Returns 1 if col.rgba is 0.0f,0.0f,0.0f,0.0f, 0 otherwise diff --git a/example/perf.c b/example/perf.c index 94113b7..0a911c6 100644 --- a/example/perf.c +++ b/example/perf.c @@ -49,6 +49,8 @@ void startGPUTimer(struct GPUtimer* timer) int stopGPUTimer(struct GPUtimer* timer, float* times, int maxTimes) { + NVG_NOTUSED(times); + NVG_NOTUSED(maxTimes); GLint available = 1; int n = 0; if (!timer->supported) diff --git a/src/fontstash.h b/src/fontstash.h index bf167ff..ce57238 100644 --- a/src/fontstash.h +++ b/src/fontstash.h @@ -59,12 +59,14 @@ struct FONSparams { void (*renderDraw)(void* uptr, const float* verts, const float* tcoords, const unsigned int* colors, int nverts); void (*renderDelete)(void* uptr); }; +typedef struct FONSparams FONSparams; struct FONSquad { float x0,y0,s0,t0; float x1,y1,s1,t1; }; +typedef struct FONSquad FONSquad; struct FONStextIter { float x, y, nextx, nexty, scale, spacing; @@ -77,57 +79,60 @@ struct FONStextIter { const char* end; unsigned int utf8state; }; +typedef struct FONStextIter FONStextIter; + +typedef struct FONScontext FONScontext; // Contructor and destructor. -struct FONScontext* fonsCreateInternal(struct FONSparams* params); -void fonsDeleteInternal(struct FONScontext* s); +FONScontext* fonsCreateInternal(FONSparams* params); +void fonsDeleteInternal(FONScontext* s); -void fonsSetErrorCallback(struct FONScontext* s, void (*callback)(void* uptr, int error, int val), void* uptr); +void fonsSetErrorCallback(FONScontext* s, void (*callback)(void* uptr, int error, int val), void* uptr); // Returns current atlas size. -void fonsGetAtlasSize(struct FONScontext* s, int* width, int* height); +void fonsGetAtlasSize(FONScontext* s, int* width, int* height); // Expands the atlas size. -int fonsExpandAtlas(struct FONScontext* s, int width, int height); +int fonsExpandAtlas(FONScontext* s, int width, int height); // Reseta the whole stash. -int fonsResetAtlas(struct FONScontext* stash, int width, int height); +int fonsResetAtlas(FONScontext* stash, int width, int height); // Add fonts -int fonsAddFont(struct FONScontext* s, const char* name, const char* path); -int fonsAddFontMem(struct FONScontext* s, const char* name, unsigned char* data, int ndata, int freeData); -int fonsGetFontByName(struct FONScontext* s, const char* name); +int fonsAddFont(FONScontext* s, const char* name, const char* path); +int fonsAddFontMem(FONScontext* s, const char* name, unsigned char* data, int ndata, int freeData); +int fonsGetFontByName(FONScontext* s, const char* name); // State handling -void fonsPushState(struct FONScontext* s); -void fonsPopState(struct FONScontext* s); -void fonsClearState(struct FONScontext* s); +void fonsPushState(FONScontext* s); +void fonsPopState(FONScontext* s); +void fonsClearState(FONScontext* s); // State setting -void fonsSetSize(struct FONScontext* s, float size); -void fonsSetColor(struct FONScontext* s, unsigned int color); -void fonsSetSpacing(struct FONScontext* s, float spacing); -void fonsSetBlur(struct FONScontext* s, float blur); -void fonsSetAlign(struct FONScontext* s, int align); -void fonsSetFont(struct FONScontext* s, int font); +void fonsSetSize(FONScontext* s, float size); +void fonsSetColor(FONScontext* s, unsigned int color); +void fonsSetSpacing(FONScontext* s, float spacing); +void fonsSetBlur(FONScontext* s, float blur); +void fonsSetAlign(FONScontext* s, int align); +void fonsSetFont(FONScontext* s, int font); // Draw text -float fonsDrawText(struct FONScontext* s, float x, float y, const char* string, const char* end); +float fonsDrawText(FONScontext* s, float x, float y, const char* string, const char* end); // Measure text -float fonsTextBounds(struct FONScontext* s, float x, float y, const char* string, const char* end, float* bounds); -void fonsLineBounds(struct FONScontext* s, float y, float* miny, float* maxy); -void fonsVertMetrics(struct FONScontext* s, float* ascender, float* descender, float* lineh); +float fonsTextBounds(FONScontext* s, float x, float y, const char* string, const char* end, float* bounds); +void fonsLineBounds(FONScontext* s, float y, float* miny, float* maxy); +void fonsVertMetrics(FONScontext* s, float* ascender, float* descender, float* lineh); // Text iterator -int fonsTextIterInit(struct FONScontext* stash, struct FONStextIter* iter, float x, float y, const char* str, const char* end); -int fonsTextIterNext(struct FONScontext* stash, struct FONStextIter* iter, struct FONSquad* quad); +int fonsTextIterInit(FONScontext* stash, FONStextIter* iter, float x, float y, const char* str, const char* end); +int fonsTextIterNext(FONScontext* stash, FONStextIter* iter, struct FONSquad* quad); // Pull texture changes -const unsigned char* fonsGetTextureData(struct FONScontext* stash, int* width, int* height); -int fonsValidateTexture(struct FONScontext* s, int* dirty); +const unsigned char* fonsGetTextureData(FONScontext* stash, int* width, int* height); +int fonsValidateTexture(FONScontext* s, int* dirty); // Draws the stash texture for debugging -void fonsDrawDebug(struct FONScontext* s, float x, float y); +void fonsDrawDebug(FONScontext* s, float x, float y); -#endif // FONS_H +#endif // FONTSTASH_H #ifdef FONTSTASH_IMPLEMENTATION @@ -144,6 +149,7 @@ void fonsDrawDebug(struct FONScontext* s, float x, float y); struct FONSttFontImpl { FT_Face font; }; +typedef struct FONSttFontImpl FONSttFontImpl; static FT_Library ftLibrary; @@ -154,7 +160,7 @@ int fons__tt_init() return ftError == 0; } -int fons__tt_loadFont(struct FONScontext *context, struct FONSttFontImpl *font, unsigned char *data, int dataSize) +int fons__tt_loadFont(FONScontext *context, FONSttFontImpl *font, unsigned char *data, int dataSize) { FT_Error ftError; FONS_NOTUSED(context); @@ -164,24 +170,25 @@ int fons__tt_loadFont(struct FONScontext *context, struct FONSttFontImpl *font, return ftError == 0; } -void fons__tt_getFontVMetrics(struct FONSttFontImpl *font, int *ascent, int *descent, int *lineGap) +void fons__tt_getFontVMetrics(FONSttFontImpl *font, int *ascent, int *descent, int *lineGap) { *ascent = font->font->ascender; *descent = font->font->descender; *lineGap = font->font->height - (*ascent - *descent); } -float fons__tt_getPixelHeightScale(struct FONSttFontImpl *font, float size) +float fons__tt_getPixelHeightScale(FONSttFontImpl *font, float size) { return size / (font->font->ascender - font->font->descender); } -int fons__tt_getGlyphIndex(struct FONSttFontImpl *font, int codepoint) +int fons__tt_getGlyphIndex(FONSttFontImpl *font, int codepoint) { return FT_Get_Char_Index(font->font, codepoint); } -int fons__tt_buildGlyphBitmap(struct FONSttFontImpl *font, int glyph, float size, float scale, int *advance, int *lsb, int *x0, int *y0, int *x1, int *y1) +int fons__tt_buildGlyphBitmap(FONSttFontImpl *font, int glyph, float size, float scale, + int *advance, int *lsb, int *x0, int *y0, int *x1, int *y1) { FT_Error ftError; FT_GlyphSlot ftGlyph; @@ -202,7 +209,8 @@ int fons__tt_buildGlyphBitmap(struct FONSttFontImpl *font, int glyph, float size return 1; } -void fons__tt_renderGlyphBitmap(struct FONSttFontImpl *font, unsigned char *output, int outWidth, int outHeight, int outStride, float scaleX, float scaleY, int glyph) +void fons__tt_renderGlyphBitmap(FONSttFontImpl *font, unsigned char *output, int outWidth, int outHeight, int outStride, + float scaleX, float scaleY, int glyph) { FT_GlyphSlot ftGlyph = font->font->glyph; int ftGlyphOffset = 0; @@ -220,7 +228,7 @@ void fons__tt_renderGlyphBitmap(struct FONSttFontImpl *font, unsigned char *outp } } -int fons__tt_getGlyphKernAdvance(struct FONSttFontImpl *font, int glyph1, int glyph2) +int fons__tt_getGlyphKernAdvance(FONSttFontImpl *font, int glyph1, int glyph2) { FT_Vector ftKerning; FT_Get_Kerning(font->font, glyph1, glyph2, FT_KERNING_DEFAULT, &ftKerning); @@ -239,14 +247,15 @@ static void fons__tmpfree(void* ptr, void* up); struct FONSttFontImpl { stbtt_fontinfo font; }; +typedef struct FONSttFontImpl FONSttFontImpl; -int fons__tt_init(struct FONScontext *context) +int fons__tt_init(FONScontext *context) { FONS_NOTUSED(context); return 1; } -int fons__tt_loadFont(struct FONScontext *context, struct FONSttFontImpl *font, unsigned char *data, int dataSize) +int fons__tt_loadFont(FONScontext *context, FONSttFontImpl *font, unsigned char *data, int dataSize) { int stbError; FONS_NOTUSED(dataSize); @@ -256,22 +265,23 @@ int fons__tt_loadFont(struct FONScontext *context, struct FONSttFontImpl *font, return stbError; } -void fons__tt_getFontVMetrics(struct FONSttFontImpl *font, int *ascent, int *descent, int *lineGap) +void fons__tt_getFontVMetrics(FONSttFontImpl *font, int *ascent, int *descent, int *lineGap) { stbtt_GetFontVMetrics(&font->font, ascent, descent, lineGap); } -float fons__tt_getPixelHeightScale(struct FONSttFontImpl *font, float size) +float fons__tt_getPixelHeightScale(FONSttFontImpl *font, float size) { return stbtt_ScaleForPixelHeight(&font->font, size); } -int fons__tt_getGlyphIndex(struct FONSttFontImpl *font, int codepoint) +int fons__tt_getGlyphIndex(FONSttFontImpl *font, int codepoint) { return stbtt_FindGlyphIndex(&font->font, codepoint); } -int fons__tt_buildGlyphBitmap(struct FONSttFontImpl *font, int glyph, float size, float scale, int *advance, int *lsb, int *x0, int *y0, int *x1, int *y1) +int fons__tt_buildGlyphBitmap(FONSttFontImpl *font, int glyph, float size, float scale, + int *advance, int *lsb, int *x0, int *y0, int *x1, int *y1) { FONS_NOTUSED(size); stbtt_GetGlyphHMetrics(&font->font, glyph, advance, lsb); @@ -279,12 +289,13 @@ int fons__tt_buildGlyphBitmap(struct FONSttFontImpl *font, int glyph, float size return 1; } -void fons__tt_renderGlyphBitmap(struct FONSttFontImpl *font, unsigned char *output, int outWidth, int outHeight, int outStride, float scaleX, float scaleY, int glyph) +void fons__tt_renderGlyphBitmap(FONSttFontImpl *font, unsigned char *output, int outWidth, int outHeight, int outStride, + float scaleX, float scaleY, int glyph) { stbtt_MakeGlyphBitmap(&font->font, output, outWidth, outHeight, outStride, scaleX, scaleY, glyph); } -int fons__tt_getGlyphKernAdvance(struct FONSttFontImpl *font, int glyph1, int glyph2) +int fons__tt_getGlyphKernAdvance(FONSttFontImpl *font, int glyph1, int glyph2) { return stbtt_GetGlyphKernAdvance(&font->font, glyph1, glyph2); } @@ -343,10 +354,11 @@ struct FONSglyph short x0,y0,x1,y1; short xadv,xoff,yoff; }; +typedef struct FONSglyph FONSglyph; struct FONSfont { - struct FONSttFontImpl font; + FONSttFontImpl font; char name[64]; unsigned char* data; int dataSize; @@ -354,11 +366,12 @@ struct FONSfont float ascender; float descender; float lineh; - struct FONSglyph* glyphs; + FONSglyph* glyphs; int cglyphs; int nglyphs; int lut[FONS_HASH_LUT_SIZE]; }; +typedef struct FONSfont FONSfont; struct FONSstate { @@ -369,27 +382,30 @@ struct FONSstate float blur; float spacing; }; +typedef struct FONSstate FONSstate; struct FONSatlasNode { short x, y, width; }; +typedef struct FONSatlasNode FONSatlasNode; struct FONSatlas { int width, height; - struct FONSatlasNode* nodes; + FONSatlasNode* nodes; int nnodes; int cnodes; }; +typedef struct FONSatlas FONSatlas; struct FONScontext { - struct FONSparams params; + FONSparams params; float itw,ith; unsigned char* texData; int dirtyRect[4]; - struct FONSfont** fonts; - struct FONSatlas* atlas; + FONSfont** fonts; + FONSatlas* atlas; int cfonts; int nfonts; float verts[FONS_VERTEX_COUNT*2]; @@ -398,7 +414,7 @@ struct FONScontext int nverts; unsigned char* scratch; int nscratch; - struct FONSstate states[FONS_MAX_STATES]; + FONSstate states[FONS_MAX_STATES]; int nstates; void (*handleError)(void* uptr, int error, int val); void* errorUptr; @@ -407,7 +423,7 @@ struct FONScontext static void* fons__tmpalloc(size_t size, void* up) { unsigned char* ptr; - struct FONScontext* stash = (struct FONScontext*)up; + FONScontext* stash = (FONScontext*)up; // 16-byte align the returned pointer size = (size + 0xf) & ~0xf; @@ -470,29 +486,29 @@ static unsigned int fons__decutf8(unsigned int* state, unsigned int* codep, unsi // Atlas based on Skyline Bin Packer by Jukka Jylänki -static void fons__deleteAtlas(struct FONSatlas* atlas) +static void fons__deleteAtlas(FONSatlas* atlas) { if (atlas == NULL) return; if (atlas->nodes != NULL) free(atlas->nodes); free(atlas); } -static struct FONSatlas* fons__allocAtlas(int w, int h, int nnodes) +static FONSatlas* fons__allocAtlas(int w, int h, int nnodes) { - struct FONSatlas* atlas = NULL; + FONSatlas* atlas = NULL; // Allocate memory for the font stash. - atlas = (struct FONSatlas*)malloc(sizeof(struct FONSatlas)); + atlas = (FONSatlas*)malloc(sizeof(FONSatlas)); if (atlas == NULL) goto error; - memset(atlas, 0, sizeof(struct FONSatlas)); + memset(atlas, 0, sizeof(FONSatlas)); atlas->width = w; atlas->height = h; // Allocate space for skyline nodes - atlas->nodes = (struct FONSatlasNode*)malloc(sizeof(struct FONSatlasNode) * nnodes); + atlas->nodes = (FONSatlasNode*)malloc(sizeof(FONSatlasNode) * nnodes); if (atlas->nodes == NULL) goto error; - memset(atlas->nodes, 0, sizeof(struct FONSatlasNode) * nnodes); + memset(atlas->nodes, 0, sizeof(FONSatlasNode) * nnodes); atlas->nnodes = 0; atlas->cnodes = nnodes; @@ -509,13 +525,13 @@ error: return NULL; } -static int fons__atlasInsertNode(struct FONSatlas* atlas, int idx, int x, int y, int w) +static int fons__atlasInsertNode(FONSatlas* atlas, int idx, int x, int y, int w) { int i; // Insert node if (atlas->nnodes+1 > atlas->cnodes) { atlas->cnodes = atlas->cnodes == 0 ? 8 : atlas->cnodes * 2; - atlas->nodes = (struct FONSatlasNode*)realloc(atlas->nodes, sizeof(struct FONSatlasNode) * atlas->cnodes); + atlas->nodes = (FONSatlasNode*)realloc(atlas->nodes, sizeof(FONSatlasNode) * atlas->cnodes); if (atlas->nodes == NULL) return 0; } @@ -529,7 +545,7 @@ static int fons__atlasInsertNode(struct FONSatlas* atlas, int idx, int x, int y, return 1; } -static void fons__atlasRemoveNode(struct FONSatlas* atlas, int idx) +static void fons__atlasRemoveNode(FONSatlas* atlas, int idx) { int i; if (atlas->nnodes == 0) return; @@ -538,7 +554,7 @@ static void fons__atlasRemoveNode(struct FONSatlas* atlas, int idx) atlas->nnodes--; } -static void fons__atlasExpand(struct FONSatlas* atlas, int w, int h) +static void fons__atlasExpand(FONSatlas* atlas, int w, int h) { // Insert node for empty space if (w > atlas->width) @@ -547,7 +563,7 @@ static void fons__atlasExpand(struct FONSatlas* atlas, int w, int h) atlas->height = h; } -static void fons__atlasReset(struct FONSatlas* atlas, int w, int h) +static void fons__atlasReset(FONSatlas* atlas, int w, int h) { atlas->width = w; atlas->height = h; @@ -560,7 +576,7 @@ static void fons__atlasReset(struct FONSatlas* atlas, int w, int h) atlas->nnodes++; } -static int fons__atlasAddSkylineLevel(struct FONSatlas* atlas, int idx, int x, int y, int w, int h) +static int fons__atlasAddSkylineLevel(FONSatlas* atlas, int idx, int x, int y, int w, int h) { int i; @@ -597,7 +613,7 @@ static int fons__atlasAddSkylineLevel(struct FONSatlas* atlas, int idx, int x, i return 1; } -static int fons__atlasRectFits(struct FONSatlas* atlas, int i, int w, int h) +static int fons__atlasRectFits(FONSatlas* atlas, int i, int w, int h) { // Checks if there is enough space at the location of skyline span 'i', // and return the max height of all skyline spans under that at that location, @@ -618,7 +634,7 @@ static int fons__atlasRectFits(struct FONSatlas* atlas, int i, int w, int h) return y; } -static int fons__atlasAddRect(struct FONSatlas* atlas, int rw, int rh, int* rx, int* ry) +static int fons__atlasAddRect(FONSatlas* atlas, int rw, int rh, int* rx, int* ry) { int besth = atlas->height, bestw = atlas->width, besti = -1; int bestx = -1, besty = -1, i; @@ -650,7 +666,7 @@ static int fons__atlasAddRect(struct FONSatlas* atlas, int rw, int rh, int* rx, return 1; } -static void fons__addWhiteRect(struct FONScontext* stash, int w, int h) +static void fons__addWhiteRect(FONScontext* stash, int w, int h) { int x, y, gx, gy; unsigned char* dst; @@ -671,14 +687,14 @@ static void fons__addWhiteRect(struct FONScontext* stash, int w, int h) stash->dirtyRect[3] = fons__maxi(stash->dirtyRect[3], gy+h); } -struct FONScontext* fonsCreateInternal(struct FONSparams* params) +FONScontext* fonsCreateInternal(FONSparams* params) { - struct FONScontext* stash = NULL; + FONScontext* stash = NULL; // Allocate memory for the font stash. - stash = (struct FONScontext*)malloc(sizeof(struct FONScontext)); + stash = (FONScontext*)malloc(sizeof(FONScontext)); if (stash == NULL) goto error; - memset(stash, 0, sizeof(struct FONScontext)); + memset(stash, 0, sizeof(FONScontext)); stash->params = *params; @@ -698,9 +714,9 @@ struct FONScontext* fonsCreateInternal(struct FONSparams* params) if (stash->atlas == NULL) goto error; // Allocate space for fonts. - stash->fonts = (struct FONSfont**)malloc(sizeof(struct FONSfont*) * FONS_INIT_FONTS); + stash->fonts = (FONSfont**)malloc(sizeof(FONSfont*) * FONS_INIT_FONTS); if (stash->fonts == NULL) goto error; - memset(stash->fonts, 0, sizeof(struct FONSfont*) * FONS_INIT_FONTS); + memset(stash->fonts, 0, sizeof(FONSfont*) * FONS_INIT_FONTS); stash->cfonts = FONS_INIT_FONTS; stash->nfonts = 0; @@ -729,42 +745,42 @@ error: return NULL; } -static struct FONSstate* fons__getState(struct FONScontext* stash) +static FONSstate* fons__getState(FONScontext* stash) { return &stash->states[stash->nstates-1]; } -void fonsSetSize(struct FONScontext* stash, float size) +void fonsSetSize(FONScontext* stash, float size) { fons__getState(stash)->size = size; } -void fonsSetColor(struct FONScontext* stash, unsigned int color) +void fonsSetColor(FONScontext* stash, unsigned int color) { fons__getState(stash)->color = color; } -void fonsSetSpacing(struct FONScontext* stash, float spacing) +void fonsSetSpacing(FONScontext* stash, float spacing) { fons__getState(stash)->spacing = spacing; } -void fonsSetBlur(struct FONScontext* stash, float blur) +void fonsSetBlur(FONScontext* stash, float blur) { fons__getState(stash)->blur = blur; } -void fonsSetAlign(struct FONScontext* stash, int align) +void fonsSetAlign(FONScontext* stash, int align) { fons__getState(stash)->align = align; } -void fonsSetFont(struct FONScontext* stash, int font) +void fonsSetFont(FONScontext* stash, int font) { fons__getState(stash)->font = font; } -void fonsPushState(struct FONScontext* stash) +void fonsPushState(FONScontext* stash) { if (stash->nstates >= FONS_MAX_STATES) { if (stash->handleError) @@ -772,11 +788,11 @@ void fonsPushState(struct FONScontext* stash) return; } if (stash->nstates > 0) - memcpy(&stash->states[stash->nstates], &stash->states[stash->nstates-1], sizeof(struct FONSstate)); + memcpy(&stash->states[stash->nstates], &stash->states[stash->nstates-1], sizeof(FONSstate)); stash->nstates++; } -void fonsPopState(struct FONScontext* stash) +void fonsPopState(FONScontext* stash) { if (stash->nstates <= 1) { if (stash->handleError) @@ -786,9 +802,9 @@ void fonsPopState(struct FONScontext* stash) stash->nstates--; } -void fonsClearState(struct FONScontext* stash) +void fonsClearState(FONScontext* stash) { - struct FONSstate* state = fons__getState(stash); + FONSstate* state = fons__getState(stash); state->size = 12.0f; state->color = 0xffffffff; state->font = 0; @@ -797,7 +813,7 @@ void fonsClearState(struct FONScontext* stash) state->align = FONS_ALIGN_LEFT | FONS_ALIGN_BASELINE; } -static void fons__freeFont(struct FONSfont* font) +static void fons__freeFont(FONSfont* font) { if (font == NULL) return; if (font->glyphs) free(font->glyphs); @@ -805,20 +821,20 @@ static void fons__freeFont(struct FONSfont* font) free(font); } -static int fons__allocFont(struct FONScontext* stash) +static int fons__allocFont(FONScontext* stash) { - struct FONSfont* font = NULL; + FONSfont* font = NULL; if (stash->nfonts+1 > stash->cfonts) { stash->cfonts = stash->cfonts == 0 ? 8 : stash->cfonts * 2; - stash->fonts = (struct FONSfont**)realloc(stash->fonts, sizeof(struct FONSfont*) * stash->cfonts); + stash->fonts = (FONSfont**)realloc(stash->fonts, sizeof(FONSfont*) * stash->cfonts); if (stash->fonts == NULL) return -1; } - font = (struct FONSfont*)malloc(sizeof(struct FONSfont)); + font = (FONSfont*)malloc(sizeof(FONSfont)); if (font == NULL) goto error; - memset(font, 0, sizeof(struct FONSfont)); + memset(font, 0, sizeof(FONSfont)); - font->glyphs = (struct FONSglyph*)malloc(sizeof(struct FONSglyph) * FONS_INIT_GLYPHS); + font->glyphs = (FONSglyph*)malloc(sizeof(FONSglyph) * FONS_INIT_GLYPHS); if (font->glyphs == NULL) goto error; font->cglyphs = FONS_INIT_GLYPHS; font->nglyphs = 0; @@ -832,7 +848,7 @@ error: return FONS_INVALID; } -int fonsAddFont(struct FONScontext* stash, const char* name, const char* path) +int fonsAddFont(FONScontext* stash, const char* name, const char* path) { FILE* fp = 0; int dataSize = 0; @@ -858,10 +874,10 @@ error: return FONS_INVALID; } -int fonsAddFontMem(struct FONScontext* stash, const char* name, unsigned char* data, int dataSize, int freeData) +int fonsAddFontMem(FONScontext* stash, const char* name, unsigned char* data, int dataSize, int freeData) { int i, ascent, descent, fh, lineGap; - struct FONSfont* font; + FONSfont* font; int idx = fons__allocFont(stash); if (idx == FONS_INVALID) @@ -901,7 +917,7 @@ error: return FONS_INVALID; } -int fonsGetFontByName(struct FONScontext* s, const char* name) +int fonsGetFontByName(FONScontext* s, const char* name) { int i; for (i = 0; i < s->nfonts; i++) { @@ -912,11 +928,11 @@ int fonsGetFontByName(struct FONScontext* s, const char* name) } -static struct FONSglyph* fons__allocGlyph(struct FONSfont* font) +static FONSglyph* fons__allocGlyph(FONSfont* font) { if (font->nglyphs+1 > font->cglyphs) { font->cglyphs = font->cglyphs == 0 ? 8 : font->cglyphs * 2; - font->glyphs = (struct FONSglyph*)realloc(font->glyphs, sizeof(struct FONSglyph) * font->cglyphs); + font->glyphs = (FONSglyph*)realloc(font->glyphs, sizeof(FONSglyph) * font->cglyphs); if (font->glyphs == NULL) return NULL; } font->nglyphs++; @@ -970,7 +986,7 @@ static void fons__blurRows(unsigned char* dst, int w, int h, int dstStride, int } -static void fons__blur(struct FONScontext* stash, unsigned char* dst, int w, int h, int dstStride, int blur) +static void fons__blur(FONScontext* stash, unsigned char* dst, int w, int h, int dstStride, int blur) { int alpha; float sigma; @@ -989,12 +1005,12 @@ static void fons__blur(struct FONScontext* stash, unsigned char* dst, int w, int // fons__blurcols(dst, w, h, dstStride, alpha); } -static struct FONSglyph* fons__getGlyph(struct FONScontext* stash, struct FONSfont* font, unsigned int codepoint, - short isize, short iblur) +static FONSglyph* fons__getGlyph(FONScontext* stash, FONSfont* font, unsigned int codepoint, + short isize, short iblur) { int i, g, advance, lsb, x0, y0, x1, y1, gw, gh, gx, gy, x, y; float scale; - struct FONSglyph* glyph = NULL; + FONSglyph* glyph = NULL; unsigned int h; float size = isize/10.0f; int pad, added; @@ -1092,9 +1108,9 @@ static struct FONSglyph* fons__getGlyph(struct FONScontext* stash, struct FONSfo return glyph; } -static void fons__getQuad(struct FONScontext* stash, struct FONSfont* font, - int prevGlyphIndex, struct FONSglyph* glyph, - float scale, float spacing, float* x, float* y, struct FONSquad* q) +static void fons__getQuad(FONScontext* stash, FONSfont* font, + int prevGlyphIndex, FONSglyph* glyph, + float scale, float spacing, float* x, float* y, FONSquad* q) { float rx,ry,xoff,yoff,x0,y0,x1,y1; @@ -1144,7 +1160,7 @@ static void fons__getQuad(struct FONScontext* stash, struct FONSfont* font, *x += (int)(glyph->xadv / 10.0f + 0.5f); } -static void fons__flush(struct FONScontext* stash) +static void fons__flush(FONScontext* stash) { // Flush texture if (stash->dirtyRect[0] < stash->dirtyRect[2] && stash->dirtyRect[1] < stash->dirtyRect[3]) { @@ -1165,7 +1181,7 @@ static void fons__flush(struct FONScontext* stash) } } -static __inline void fons__vertex(struct FONScontext* stash, float x, float y, float s, float t, unsigned int c) +static __inline void fons__vertex(FONScontext* stash, float x, float y, float s, float t, unsigned int c) { stash->verts[stash->nverts*2+0] = x; stash->verts[stash->nverts*2+1] = y; @@ -1175,7 +1191,7 @@ static __inline void fons__vertex(struct FONScontext* stash, float x, float y, f stash->nverts++; } -static float fons__getVertAlign(struct FONScontext* stash, struct FONSfont* font, int align, short isize) +static float fons__getVertAlign(FONScontext* stash, FONSfont* font, int align, short isize) { if (stash->params.flags & FONS_ZERO_TOPLEFT) { if (align & FONS_ALIGN_TOP) { @@ -1201,20 +1217,20 @@ static float fons__getVertAlign(struct FONScontext* stash, struct FONSfont* font return 0.0; } -float fonsDrawText(struct FONScontext* stash, +float fonsDrawText(FONScontext* stash, float x, float y, const char* str, const char* end) { - struct FONSstate* state = fons__getState(stash); + FONSstate* state = fons__getState(stash); unsigned int codepoint; unsigned int utf8state = 0; - struct FONSglyph* glyph = NULL; - struct FONSquad q; + FONSglyph* glyph = NULL; + FONSquad q; int prevGlyphIndex = -1; short isize = (short)(state->size*10.0f); short iblur = (short)state->blur; float scale; - struct FONSfont* font; + FONSfont* font; float width; if (stash == NULL) return x; @@ -1265,10 +1281,10 @@ float fonsDrawText(struct FONScontext* stash, return x; } -int fonsTextIterInit(struct FONScontext* stash, struct FONStextIter* iter, +int fonsTextIterInit(FONScontext* stash, FONStextIter* iter, float x, float y, const char* str, const char* end) { - struct FONSstate* state = fons__getState(stash); + FONSstate* state = fons__getState(stash); float width; memset(iter, 0, sizeof(*iter)); @@ -1310,9 +1326,9 @@ int fonsTextIterInit(struct FONScontext* stash, struct FONStextIter* iter, return 1; } -int fonsTextIterNext(struct FONScontext* stash, struct FONStextIter* iter, struct FONSquad* quad) +int fonsTextIterNext(FONScontext* stash, FONStextIter* iter, FONSquad* quad) { - struct FONSglyph* glyph = NULL; + FONSglyph* glyph = NULL; const char* str = iter->next; iter->str = iter->next; @@ -1337,7 +1353,7 @@ int fonsTextIterNext(struct FONScontext* stash, struct FONStextIter* iter, struc return 1; } -void fonsDrawDebug(struct FONScontext* stash, float x, float y) +void fonsDrawDebug(FONScontext* stash, float x, float y) { int i; int w = stash->params.width; @@ -1368,7 +1384,7 @@ void fonsDrawDebug(struct FONScontext* stash, float x, float y) // Drawbug draw atlas for (i = 0; i < stash->atlas->nnodes; i++) { - struct FONSatlasNode* n = &stash->atlas->nodes[i]; + FONSatlasNode* n = &stash->atlas->nodes[i]; if (stash->nverts+6 > FONS_VERTEX_COUNT) fons__flush(stash); @@ -1385,21 +1401,21 @@ void fonsDrawDebug(struct FONScontext* stash, float x, float y) fons__flush(stash); } -float fonsTextBounds(struct FONScontext* stash, +float fonsTextBounds(FONScontext* stash, float x, float y, const char* str, const char* end, float* bounds) { - struct FONSstate* state = fons__getState(stash); + FONSstate* state = fons__getState(stash); unsigned int codepoint; unsigned int utf8state = 0; - struct FONSquad q; - struct FONSglyph* glyph = NULL; + FONSquad q; + FONSglyph* glyph = NULL; int prevGlyphIndex = -1; short isize = (short)(state->size*10.0f); short iblur = (short)state->blur; float scale; - struct FONSfont* font; + FONSfont* font; float startx, advance; float minx, miny, maxx, maxy; @@ -1462,11 +1478,11 @@ float fonsTextBounds(struct FONScontext* stash, return advance; } -void fonsVertMetrics(struct FONScontext* stash, +void fonsVertMetrics(FONScontext* stash, float* ascender, float* descender, float* lineh) { - struct FONSfont* font; - struct FONSstate* state = fons__getState(stash); + FONSfont* font; + FONSstate* state = fons__getState(stash); short isize; if (stash == NULL) return; @@ -1483,10 +1499,10 @@ void fonsVertMetrics(struct FONScontext* stash, *lineh = font->lineh*isize/10.0f; } -void fonsLineBounds(struct FONScontext* stash, float y, float* miny, float* maxy) +void fonsLineBounds(FONScontext* stash, float y, float* miny, float* maxy) { - struct FONSfont* font; - struct FONSstate* state = fons__getState(stash); + FONSfont* font; + FONSstate* state = fons__getState(stash); short isize; if (stash == NULL) return; @@ -1506,7 +1522,7 @@ void fonsLineBounds(struct FONScontext* stash, float y, float* miny, float* maxy } } -const unsigned char* fonsGetTextureData(struct FONScontext* stash, int* width, int* height) +const unsigned char* fonsGetTextureData(FONScontext* stash, int* width, int* height) { if (width != NULL) *width = stash->params.width; @@ -1515,7 +1531,7 @@ const unsigned char* fonsGetTextureData(struct FONScontext* stash, int* width, i return stash->texData; } -int fonsValidateTexture(struct FONScontext* stash, int* dirty) +int fonsValidateTexture(FONScontext* stash, int* dirty) { if (stash->dirtyRect[0] < stash->dirtyRect[2] && stash->dirtyRect[1] < stash->dirtyRect[3]) { dirty[0] = stash->dirtyRect[0]; @@ -1532,7 +1548,7 @@ int fonsValidateTexture(struct FONScontext* stash, int* dirty) return 0; } -void fonsDeleteInternal(struct FONScontext* stash) +void fonsDeleteInternal(FONScontext* stash) { int i; if (stash == NULL) return; @@ -1550,21 +1566,21 @@ void fonsDeleteInternal(struct FONScontext* stash) free(stash); } -void fonsSetErrorCallback(struct FONScontext* stash, void (*callback)(void* uptr, int error, int val), void* uptr) +void fonsSetErrorCallback(FONScontext* stash, void (*callback)(void* uptr, int error, int val), void* uptr) { if (stash == NULL) return; stash->handleError = callback; stash->errorUptr = uptr; } -void fonsGetAtlasSize(struct FONScontext* stash, int* width, int* height) +void fonsGetAtlasSize(FONScontext* stash, int* width, int* height) { if (stash == NULL) return; *width = stash->params.width; *height = stash->params.height; } -int fonsExpandAtlas(struct FONScontext* stash, int width, int height) +int fonsExpandAtlas(FONScontext* stash, int width, int height) { int i, maxy = 0; unsigned char* data = NULL; @@ -1620,7 +1636,7 @@ int fonsExpandAtlas(struct FONScontext* stash, int width, int height) return 1; } -int fonsResetAtlas(struct FONScontext* stash, int width, int height) +int fonsResetAtlas(FONScontext* stash, int width, int height) { int i, j; if (stash == NULL) return 0; @@ -1650,7 +1666,7 @@ int fonsResetAtlas(struct FONScontext* stash, int width, int height) // Reset cached glyphs for (i = 0; i < stash->nfonts; i++) { - struct FONSfont* font = stash->fonts[i]; + FONSfont* font = stash->fonts[i]; font->nglyphs = 0; for (j = 0; j < FONS_HASH_LUT_SIZE; j++) font->lut[j] = -1; diff --git a/src/nanovg.c b/src/nanovg.c index be6dcc6..a0b9d17 100644 --- a/src/nanovg.c +++ b/src/nanovg.c @@ -63,15 +63,15 @@ enum NVGpointFlags }; struct NVGstate { - struct NVGpaint fill; - struct NVGpaint stroke; + NVGpaint fill; + NVGpaint stroke; float strokeWidth; float miterLimit; int lineJoin; int lineCap; float alpha; float xform[6]; - struct NVGscissor scissor; + NVGscissor scissor; float fontSize; float letterSpacing; float lineHeight; @@ -79,6 +79,7 @@ struct NVGstate { int textAlign; int fontId; }; +typedef struct NVGstate NVGstate; struct NVGpoint { float x,y; @@ -87,29 +88,31 @@ struct NVGpoint { float dmx, dmy; unsigned char flags; }; +typedef struct NVGpoint NVGpoint; struct NVGpathCache { - struct NVGpoint* points; + NVGpoint* points; int npoints; int cpoints; - struct NVGpath* paths; + NVGpath* paths; int npaths; int cpaths; - struct NVGvertex* verts; + NVGvertex* verts; int nverts; int cverts; float bounds[4]; }; +typedef struct NVGpathCache NVGpathCache; struct NVGcontext { - struct NVGparams params; + NVGparams params; float* commands; int ccommands; int ncommands; float commandx, commandy; - struct NVGstate states[NVG_MAX_STATES]; + NVGstate states[NVG_MAX_STATES]; int nstates; - struct NVGpathCache* cache; + NVGpathCache* cache; float tessTol; float distTol; float fringeWidth; @@ -153,7 +156,7 @@ static float nvg__normalize(float *x, float* y) } -static void nvg__deletePathCache(struct NVGpathCache* c) +static void nvg__deletePathCache(NVGpathCache* c) { if (c == NULL) return; if (c->points != NULL) free(c->points); @@ -162,23 +165,23 @@ static void nvg__deletePathCache(struct NVGpathCache* c) free(c); } -static struct NVGpathCache* nvg__allocPathCache(void) +static NVGpathCache* nvg__allocPathCache(void) { - struct NVGpathCache* c = (struct NVGpathCache*)malloc(sizeof(struct NVGpathCache)); + NVGpathCache* c = (NVGpathCache*)malloc(sizeof(NVGpathCache)); if (c == NULL) goto error; - memset(c, 0, sizeof(struct NVGpathCache)); + memset(c, 0, sizeof(NVGpathCache)); - c->points = (struct NVGpoint*)malloc(sizeof(struct NVGpoint)*NVG_INIT_POINTS_SIZE); + c->points = (NVGpoint*)malloc(sizeof(NVGpoint)*NVG_INIT_POINTS_SIZE); if (!c->points) goto error; c->npoints = 0; c->cpoints = NVG_INIT_POINTS_SIZE; - c->paths = (struct NVGpath*)malloc(sizeof(struct NVGpath)*NVG_INIT_PATHS_SIZE); + c->paths = (NVGpath*)malloc(sizeof(NVGpath)*NVG_INIT_PATHS_SIZE); if (!c->paths) goto error; c->npaths = 0; c->cpaths = NVG_INIT_PATHS_SIZE; - c->verts = (struct NVGvertex*)malloc(sizeof(struct NVGvertex)*NVG_INIT_VERTS_SIZE); + c->verts = (NVGvertex*)malloc(sizeof(NVGvertex)*NVG_INIT_VERTS_SIZE); if (!c->verts) goto error; c->nverts = 0; c->cverts = NVG_INIT_VERTS_SIZE; @@ -189,7 +192,7 @@ error: return NULL; } -static void nvg__setDevicePixelRatio(struct NVGcontext* ctx, float ratio) +static void nvg__setDevicePixelRatio(NVGcontext* ctx, float ratio) { ctx->tessTol = 0.25f / ratio; ctx->distTol = 0.01f / ratio; @@ -197,13 +200,13 @@ static void nvg__setDevicePixelRatio(struct NVGcontext* ctx, float ratio) ctx->devicePxRatio = ratio; } -struct NVGcontext* nvgCreateInternal(struct NVGparams* params) +NVGcontext* nvgCreateInternal(NVGparams* params) { - struct FONSparams fontParams; - struct NVGcontext* ctx = (struct NVGcontext*)malloc(sizeof(struct NVGcontext)); + FONSparams fontParams; + NVGcontext* ctx = (NVGcontext*)malloc(sizeof(NVGcontext)); int i; if (ctx == NULL) goto error; - memset(ctx, 0, sizeof(struct NVGcontext)); + memset(ctx, 0, sizeof(NVGcontext)); ctx->params = *params; for (i = 0; i < NVG_MAX_FONTIMAGES; i++) @@ -249,12 +252,12 @@ error: return 0; } -struct NVGparams* nvgInternalParams(struct NVGcontext* ctx) +NVGparams* nvgInternalParams(NVGcontext* ctx) { return &ctx->params; } -void nvgDeleteInternal(struct NVGcontext* ctx) +void nvgDeleteInternal(NVGcontext* ctx) { int i; if (ctx == NULL) return; @@ -277,7 +280,7 @@ void nvgDeleteInternal(struct NVGcontext* ctx) free(ctx); } -void nvgBeginFrame(struct NVGcontext* ctx, int windowWidth, int windowHeight, float devicePixelRatio) +void nvgBeginFrame(NVGcontext* ctx, int windowWidth, int windowHeight, float devicePixelRatio) { /* printf("Tris: draws:%d fill:%d stroke:%d text:%d TOT:%d\n", ctx->drawCallCount, ctx->fillTriCount, ctx->strokeTriCount, ctx->textTriCount, @@ -297,7 +300,7 @@ void nvgBeginFrame(struct NVGcontext* ctx, int windowWidth, int windowHeight, fl ctx->textTriCount = 0; } -void nvgEndFrame(struct NVGcontext* ctx) +void nvgEndFrame(NVGcontext* ctx) { ctx->params.renderFlush(ctx->params.userPtr); if (ctx->fontImageIdx != 0) { @@ -327,19 +330,19 @@ void nvgEndFrame(struct NVGcontext* ctx) } } -struct NVGcolor nvgRGB(unsigned char r, unsigned char g, unsigned char b) +NVGcolor nvgRGB(unsigned char r, unsigned char g, unsigned char b) { return nvgRGBA(r,g,b,255); } -struct NVGcolor nvgRGBf(float r, float g, float b) +NVGcolor nvgRGBf(float r, float g, float b) { return nvgRGBAf(r,g,b,1.0f); } -struct NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a) +NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a) { - struct NVGcolor color; + NVGcolor color; // Use longer initialization to suppress warning. color.r = r / 255.0f; color.g = g / 255.0f; @@ -348,9 +351,9 @@ struct NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsig return color; } -struct NVGcolor nvgRGBAf(float r, float g, float b, float a) +NVGcolor nvgRGBAf(float r, float g, float b, float a) { - struct NVGcolor color; + NVGcolor color; // Use longer initialization to suppress warning. color.r = r; color.g = g; @@ -359,23 +362,23 @@ struct NVGcolor nvgRGBAf(float r, float g, float b, float a) return color; } -struct NVGcolor nvgTransRGBA(struct NVGcolor c, unsigned char a) +NVGcolor nvgTransRGBA(NVGcolor c, unsigned char a) { c.a = a / 255.0f; return c; } -struct NVGcolor nvgTransRGBAf(struct NVGcolor c, float a) +NVGcolor nvgTransRGBAf(NVGcolor c, float a) { c.a = a; return c; } -struct NVGcolor nvgLerpRGBA(struct NVGcolor c0, struct NVGcolor c1, float u) +NVGcolor nvgLerpRGBA(NVGcolor c0, NVGcolor c1, float u) { int i; float oneminu; - struct NVGcolor cint; + NVGcolor cint; u = nvg__clampf(u, 0.0f, 1.0f); oneminu = 1.0f - u; @@ -387,7 +390,7 @@ struct NVGcolor nvgLerpRGBA(struct NVGcolor c0, struct NVGcolor c1, float u) return cint; } -struct NVGcolor nvgHSL(float h, float s, float l) +NVGcolor nvgHSL(float h, float s, float l) { return nvgHSLA(h,s,l,255); } @@ -405,10 +408,10 @@ static float nvg__hue(float h, float m1, float m2) return m1; } -struct NVGcolor nvgHSLA(float h, float s, float l, unsigned char a) +NVGcolor nvgHSLA(float h, float s, float l, unsigned char a) { float m1, m2; - struct NVGcolor col; + NVGcolor col; h = nvg__modf(h, 1.0f); if (h < 0.0f) h += 1.0f; s = nvg__clampf(s, 0.0f, 1.0f); @@ -423,7 +426,7 @@ struct NVGcolor nvgHSLA(float h, float s, float l, unsigned char a) } -static struct NVGstate* nvg__getState(struct NVGcontext* ctx) +static NVGstate* nvg__getState(NVGcontext* ctx) { return &ctx->states[ctx->nstates-1]; } @@ -525,7 +528,7 @@ float nvgRadToDeg(float rad) return rad / NVG_PI * 180.0f; } -static void nvg__setPaintColor(struct NVGpaint* p, struct NVGcolor color) +static void nvg__setPaintColor(NVGpaint* p, NVGcolor color) { memset(p, 0, sizeof(*p)); nvgTransformIdentity(p->xform); @@ -537,25 +540,25 @@ static void nvg__setPaintColor(struct NVGpaint* p, struct NVGcolor color) // State handling -void nvgSave(struct NVGcontext* ctx) +void nvgSave(NVGcontext* ctx) { if (ctx->nstates >= NVG_MAX_STATES) return; if (ctx->nstates > 0) - memcpy(&ctx->states[ctx->nstates], &ctx->states[ctx->nstates-1], sizeof(struct NVGstate)); + memcpy(&ctx->states[ctx->nstates], &ctx->states[ctx->nstates-1], sizeof(NVGstate)); ctx->nstates++; } -void nvgRestore(struct NVGcontext* ctx) +void nvgRestore(NVGcontext* ctx) { if (ctx->nstates <= 1) return; ctx->nstates--; } -void nvgReset(struct NVGcontext* ctx) +void nvgReset(NVGcontext* ctx) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); memset(state, 0, sizeof(*state)); nvg__setPaintColor(&state->fill, nvgRGBA(255,255,255,255)); @@ -579,123 +582,123 @@ void nvgReset(struct NVGcontext* ctx) } // State setting -void nvgStrokeWidth(struct NVGcontext* ctx, float width) +void nvgStrokeWidth(NVGcontext* ctx, float width) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); state->strokeWidth = width; } -void nvgMiterLimit(struct NVGcontext* ctx, float limit) +void nvgMiterLimit(NVGcontext* ctx, float limit) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); state->miterLimit = limit; } -void nvgLineCap(struct NVGcontext* ctx, int cap) +void nvgLineCap(NVGcontext* ctx, int cap) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); state->lineCap = cap; } -void nvgLineJoin(struct NVGcontext* ctx, int join) +void nvgLineJoin(NVGcontext* ctx, int join) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); state->lineJoin = join; } -void nvgGlobalAlpha(struct NVGcontext* ctx, float alpha) +void nvgGlobalAlpha(NVGcontext* ctx, float alpha) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); state->alpha = alpha; } -void nvgTransform(struct NVGcontext* ctx, float a, float b, float c, float d, float e, float f) +void nvgTransform(NVGcontext* ctx, float a, float b, float c, float d, float e, float f) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); float t[6] = { a, b, c, d, e, f }; nvgTransformPremultiply(state->xform, t); } -void nvgResetTransform(struct NVGcontext* ctx) +void nvgResetTransform(NVGcontext* ctx) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); nvgTransformIdentity(state->xform); } -void nvgTranslate(struct NVGcontext* ctx, float x, float y) +void nvgTranslate(NVGcontext* ctx, float x, float y) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); float t[6]; nvgTransformTranslate(t, x,y); nvgTransformPremultiply(state->xform, t); } -void nvgRotate(struct NVGcontext* ctx, float angle) +void nvgRotate(NVGcontext* ctx, float angle) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); float t[6]; nvgTransformRotate(t, angle); nvgTransformPremultiply(state->xform, t); } -void nvgSkewX(struct NVGcontext* ctx, float angle) +void nvgSkewX(NVGcontext* ctx, float angle) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); float t[6]; nvgTransformSkewX(t, angle); nvgTransformPremultiply(state->xform, t); } -void nvgSkewY(struct NVGcontext* ctx, float angle) +void nvgSkewY(NVGcontext* ctx, float angle) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); float t[6]; nvgTransformSkewY(t, angle); nvgTransformPremultiply(state->xform, t); } -void nvgScale(struct NVGcontext* ctx, float x, float y) +void nvgScale(NVGcontext* ctx, float x, float y) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); float t[6]; nvgTransformScale(t, x,y); nvgTransformPremultiply(state->xform, t); } -void nvgCurrentTransform(struct NVGcontext* ctx, float* xform) +void nvgCurrentTransform(NVGcontext* ctx, float* xform) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); if (xform == NULL) return; memcpy(xform, state->xform, sizeof(float)*6); } -void nvgStrokeColor(struct NVGcontext* ctx, struct NVGcolor color) +void nvgStrokeColor(NVGcontext* ctx, NVGcolor color) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); nvg__setPaintColor(&state->stroke, color); } -void nvgStrokePaint(struct NVGcontext* ctx, struct NVGpaint paint) +void nvgStrokePaint(NVGcontext* ctx, NVGpaint paint) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); state->stroke = paint; nvgTransformMultiply(state->stroke.xform, state->xform); } -void nvgFillColor(struct NVGcontext* ctx, struct NVGcolor color) +void nvgFillColor(NVGcontext* ctx, NVGcolor color) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); nvg__setPaintColor(&state->fill, color); } -void nvgFillPaint(struct NVGcontext* ctx, struct NVGpaint paint) +void nvgFillPaint(NVGcontext* ctx, NVGpaint paint) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); state->fill = paint; nvgTransformMultiply(state->fill.xform, state->xform); } -int nvgCreateImage(struct NVGcontext* ctx, const char* filename, int imageFlags) +int nvgCreateImage(NVGcontext* ctx, const char* filename, int imageFlags) { int w, h, n, image; unsigned char* img; @@ -711,7 +714,7 @@ int nvgCreateImage(struct NVGcontext* ctx, const char* filename, int imageFlags) return image; } -int nvgCreateImageMem(struct NVGcontext* ctx, int imageFlags, unsigned char* data, int ndata) +int nvgCreateImageMem(NVGcontext* ctx, int imageFlags, unsigned char* data, int ndata) { int w, h, n, image; unsigned char* img = stbi_load_from_memory(data, ndata, &w, &h, &n, 4); @@ -724,33 +727,33 @@ int nvgCreateImageMem(struct NVGcontext* ctx, int imageFlags, unsigned char* dat return image; } -int nvgCreateImageRGBA(struct NVGcontext* ctx, int w, int h, int imageFlags, const unsigned char* data) +int nvgCreateImageRGBA(NVGcontext* ctx, int w, int h, int imageFlags, const unsigned char* data) { return ctx->params.renderCreateTexture(ctx->params.userPtr, NVG_TEXTURE_RGBA, w, h, imageFlags, data); } -void nvgUpdateImage(struct NVGcontext* ctx, int image, const unsigned char* data) +void nvgUpdateImage(NVGcontext* ctx, int image, const unsigned char* data) { int w, h; ctx->params.renderGetTextureSize(ctx->params.userPtr, image, &w, &h); ctx->params.renderUpdateTexture(ctx->params.userPtr, image, 0,0, w,h, data); } -void nvgImageSize(struct NVGcontext* ctx, int image, int* w, int* h) +void nvgImageSize(NVGcontext* ctx, int image, int* w, int* h) { ctx->params.renderGetTextureSize(ctx->params.userPtr, image, w, h); } -void nvgDeleteImage(struct NVGcontext* ctx, int image) +void nvgDeleteImage(NVGcontext* ctx, int image) { ctx->params.renderDeleteTexture(ctx->params.userPtr, image); } -struct NVGpaint nvgLinearGradient(struct NVGcontext* ctx, +NVGpaint nvgLinearGradient(NVGcontext* ctx, float sx, float sy, float ex, float ey, - struct NVGcolor icol, struct NVGcolor ocol) + NVGcolor icol, NVGcolor ocol) { - struct NVGpaint p; + NVGpaint p; float dx, dy, d; const float large = 1e5; NVG_NOTUSED(ctx); @@ -785,11 +788,11 @@ struct NVGpaint nvgLinearGradient(struct NVGcontext* ctx, return p; } -struct NVGpaint nvgRadialGradient(struct NVGcontext* ctx, +NVGpaint nvgRadialGradient(NVGcontext* ctx, float cx, float cy, float inr, float outr, - struct NVGcolor icol, struct NVGcolor ocol) + NVGcolor icol, NVGcolor ocol) { - struct NVGpaint p; + NVGpaint p; float r = (inr+outr)*0.5f; float f = (outr-inr); NVG_NOTUSED(ctx); @@ -812,11 +815,11 @@ struct NVGpaint nvgRadialGradient(struct NVGcontext* ctx, return p; } -struct NVGpaint nvgBoxGradient(struct NVGcontext* ctx, +NVGpaint nvgBoxGradient(NVGcontext* ctx, float x, float y, float w, float h, float r, float f, - struct NVGcolor icol, struct NVGcolor ocol) + NVGcolor icol, NVGcolor ocol) { - struct NVGpaint p; + NVGpaint p; NVG_NOTUSED(ctx); memset(&p, 0, sizeof(p)); @@ -838,11 +841,11 @@ struct NVGpaint nvgBoxGradient(struct NVGcontext* ctx, } -struct NVGpaint nvgImagePattern(struct NVGcontext* ctx, +NVGpaint nvgImagePattern(NVGcontext* ctx, float cx, float cy, float w, float h, float angle, int image, int repeat, float alpha) { - struct NVGpaint p; + NVGpaint p; NVG_NOTUSED(ctx); memset(&p, 0, sizeof(p)); @@ -862,9 +865,9 @@ struct NVGpaint nvgImagePattern(struct NVGcontext* ctx, } // Scissoring -void nvgScissor(struct NVGcontext* ctx, float x, float y, float w, float h) +void nvgScissor(NVGcontext* ctx, float x, float y, float w, float h) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); w = nvg__maxf(0.0f, w); h = nvg__maxf(0.0f, h); @@ -878,9 +881,9 @@ void nvgScissor(struct NVGcontext* ctx, float x, float y, float w, float h) state->scissor.extent[1] = h*0.5f; } -void nvgResetScissor(struct NVGcontext* ctx) +void nvgResetScissor(NVGcontext* ctx) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); memset(state->scissor.xform, 0, sizeof(state->scissor.xform)); state->scissor.extent[0] = -1.0f; state->scissor.extent[1] = -1.0f; @@ -910,9 +913,9 @@ static float nvg__distPtSeg(float x, float y, float px, float py, float qx, floa return dx*dx + dy*dy; } -static void nvg__appendCommands(struct NVGcontext* ctx, float* vals, int nvals) +static void nvg__appendCommands(NVGcontext* ctx, float* vals, int nvals) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); int i; if (ctx->ncommands+nvals > ctx->ccommands) { @@ -965,26 +968,26 @@ static void nvg__appendCommands(struct NVGcontext* ctx, float* vals, int nvals) } -static void nvg__clearPathCache(struct NVGcontext* ctx) +static void nvg__clearPathCache(NVGcontext* ctx) { ctx->cache->npoints = 0; ctx->cache->npaths = 0; } -static struct NVGpath* nvg__lastPath(struct NVGcontext* ctx) +static NVGpath* nvg__lastPath(NVGcontext* ctx) { if (ctx->cache->npaths > 0) return &ctx->cache->paths[ctx->cache->npaths-1]; return NULL; } -static void nvg__addPath(struct NVGcontext* ctx) +static void nvg__addPath(NVGcontext* ctx) { - struct NVGpath* path; + NVGpath* path; if (ctx->cache->npaths+1 > ctx->cache->cpaths) { - struct NVGpath* paths; + NVGpath* paths; int cpaths = ctx->cache->npaths+1 + ctx->cache->cpaths/2; - paths = (struct NVGpath*)realloc(ctx->cache->paths, sizeof(struct NVGpath)*cpaths); + paths = (NVGpath*)realloc(ctx->cache->paths, sizeof(NVGpath)*cpaths); if (paths == NULL) return; ctx->cache->paths = paths; ctx->cache->cpaths = cpaths; @@ -997,17 +1000,17 @@ static void nvg__addPath(struct NVGcontext* ctx) ctx->cache->npaths++; } -static struct NVGpoint* nvg__lastPoint(struct NVGcontext* ctx) +static NVGpoint* nvg__lastPoint(NVGcontext* ctx) { if (ctx->cache->npoints > 0) return &ctx->cache->points[ctx->cache->npoints-1]; return NULL; } -static void nvg__addPoint(struct NVGcontext* ctx, float x, float y, int flags) +static void nvg__addPoint(NVGcontext* ctx, float x, float y, int flags) { - struct NVGpath* path = nvg__lastPath(ctx); - struct NVGpoint* pt; + NVGpath* path = nvg__lastPath(ctx); + NVGpoint* pt; if (path == NULL) return; if (ctx->cache->npoints > 0) { @@ -1019,9 +1022,9 @@ static void nvg__addPoint(struct NVGcontext* ctx, float x, float y, int flags) } if (ctx->cache->npoints+1 > ctx->cache->cpoints) { - struct NVGpoint* points; + NVGpoint* points; int cpoints = ctx->cache->npoints+1 + ctx->cache->cpoints/2; - points = (struct NVGpoint*)realloc(ctx->cache->points, sizeof(struct NVGpoint)*cpoints); + points = (NVGpoint*)realloc(ctx->cache->points, sizeof(NVGpoint)*cpoints); if (points == NULL) return; ctx->cache->points = points; ctx->cache->cpoints = cpoints; @@ -1037,16 +1040,16 @@ static void nvg__addPoint(struct NVGcontext* ctx, float x, float y, int flags) path->count++; } -static void nvg__closePath(struct NVGcontext* ctx) +static void nvg__closePath(NVGcontext* ctx) { - struct NVGpath* path = nvg__lastPath(ctx); + NVGpath* path = nvg__lastPath(ctx); if (path == NULL) return; path->closed = 1; } -static void nvg__pathWinding(struct NVGcontext* ctx, int winding) +static void nvg__pathWinding(NVGcontext* ctx, int winding) { - struct NVGpath* path = nvg__lastPath(ctx); + NVGpath* path = nvg__lastPath(ctx); if (path == NULL) return; path->winding = winding; } @@ -1058,12 +1061,12 @@ static float nvg__getAverageScale(float *t) return (sx + sy) * 0.5f; } -static struct NVGvertex* nvg__allocTempVerts(struct NVGcontext* ctx, int nverts) +static NVGvertex* nvg__allocTempVerts(NVGcontext* ctx, int nverts) { if (nverts > ctx->cache->cverts) { - struct NVGvertex* verts; + NVGvertex* verts; int cverts = (nverts + 0xff) & ~0xff; // Round up to prevent allocations when things change just slightly. - verts = (struct NVGvertex*)realloc(ctx->cache->verts, sizeof(struct NVGvertex)*cverts); + verts = (NVGvertex*)realloc(ctx->cache->verts, sizeof(NVGvertex)*cverts); if (verts == NULL) return NULL; ctx->cache->verts = verts; ctx->cache->cverts = cverts; @@ -1081,22 +1084,22 @@ static float nvg__triarea2(float ax, float ay, float bx, float by, float cx, flo return acx*aby - abx*acy; } -static float nvg__polyArea(struct NVGpoint* pts, int npts) +static float nvg__polyArea(NVGpoint* pts, int npts) { int i; float area = 0; for (i = 2; i < npts; i++) { - struct NVGpoint* a = &pts[0]; - struct NVGpoint* b = &pts[i-1]; - struct NVGpoint* c = &pts[i]; + NVGpoint* a = &pts[0]; + NVGpoint* b = &pts[i-1]; + NVGpoint* c = &pts[i]; area += nvg__triarea2(a->x,a->y, b->x,b->y, c->x,c->y); } return area * 0.5f; } -static void nvg__polyReverse(struct NVGpoint* pts, int npts) +static void nvg__polyReverse(NVGpoint* pts, int npts) { - struct NVGpoint tmp; + NVGpoint tmp; int i = 0, j = npts-1; while (i < j) { tmp = pts[i]; @@ -1108,7 +1111,7 @@ static void nvg__polyReverse(struct NVGpoint* pts, int npts) } -static void nvg__vset(struct NVGvertex* vtx, float x, float y, float u, float v) +static void nvg__vset(NVGvertex* vtx, float x, float y, float u, float v) { vtx->x = x; vtx->y = y; @@ -1116,7 +1119,7 @@ static void nvg__vset(struct NVGvertex* vtx, float x, float y, float u, float v) vtx->v = v; } -static void nvg__tesselateBezier(struct NVGcontext* ctx, +static void nvg__tesselateBezier(NVGcontext* ctx, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, int level, int type) @@ -1159,15 +1162,15 @@ static void nvg__tesselateBezier(struct NVGcontext* ctx, nvg__tesselateBezier(ctx, x1234,y1234, x234,y234, x34,y34, x4,y4, level+1, type); } -static void nvg__flattenPaths(struct NVGcontext* ctx) +static void nvg__flattenPaths(NVGcontext* ctx) { - struct NVGpathCache* cache = ctx->cache; -// struct NVGstate* state = nvg__getState(ctx); - struct NVGpoint* last; - struct NVGpoint* p0; - struct NVGpoint* p1; - struct NVGpoint* pts; - struct NVGpath* path; + NVGpathCache* cache = ctx->cache; +// NVGstate* state = nvg__getState(ctx); + NVGpoint* last; + NVGpoint* p0; + NVGpoint* p1; + NVGpoint* pts; + NVGpath* path; int i, j; float* cp1; float* cp2; @@ -1264,7 +1267,7 @@ static int nvg__curveDivs(float r, float arc, float tol) return nvg__maxi(2, (int)ceilf(arc / da)); } -static void nvg__chooseBevel(int bevel, struct NVGpoint* p0, struct NVGpoint* p1, float w, +static void nvg__chooseBevel(int bevel, NVGpoint* p0, NVGpoint* p1, float w, float* x0, float* y0, float* x1, float* y1) { if (bevel) { @@ -1280,7 +1283,7 @@ static void nvg__chooseBevel(int bevel, struct NVGpoint* p0, struct NVGpoint* p1 } } -static struct NVGvertex* nvg__roundJoin(struct NVGvertex* dst, struct NVGpoint* p0, struct NVGpoint* p1, +static NVGvertex* nvg__roundJoin(NVGvertex* dst, NVGpoint* p0, NVGpoint* p1, float lw, float rw, float lu, float ru, int ncap, float fringe) { int i, n; @@ -1340,7 +1343,7 @@ static struct NVGvertex* nvg__roundJoin(struct NVGvertex* dst, struct NVGpoint* return dst; } -static struct NVGvertex* nvg__bevelJoin(struct NVGvertex* dst, struct NVGpoint* p0, struct NVGpoint* p1, +static NVGvertex* nvg__bevelJoin(NVGvertex* dst, NVGpoint* p0, NVGpoint* p1, float lw, float rw, float lu, float ru, float fringe) { float rx0,ry0,rx1,ry1; @@ -1413,7 +1416,7 @@ static struct NVGvertex* nvg__bevelJoin(struct NVGvertex* dst, struct NVGpoint* return dst; } -static struct NVGvertex* nvg__buttCapStart(struct NVGvertex* dst, struct NVGpoint* p, +static NVGvertex* nvg__buttCapStart(NVGvertex* dst, NVGpoint* p, float dx, float dy, float w, float d, float aa) { float px = p->x - dx*d; @@ -1427,7 +1430,7 @@ static struct NVGvertex* nvg__buttCapStart(struct NVGvertex* dst, struct NVGpoin return dst; } -static struct NVGvertex* nvg__buttCapEnd(struct NVGvertex* dst, struct NVGpoint* p, +static NVGvertex* nvg__buttCapEnd(NVGvertex* dst, NVGpoint* p, float dx, float dy, float w, float d, float aa) { float px = p->x + dx*d; @@ -1442,7 +1445,7 @@ static struct NVGvertex* nvg__buttCapEnd(struct NVGvertex* dst, struct NVGpoint* } -static struct NVGvertex* nvg__roundCapStart(struct NVGvertex* dst, struct NVGpoint* p, +static NVGvertex* nvg__roundCapStart(NVGvertex* dst, NVGpoint* p, float dx, float dy, float w, int ncap, float aa) { int i; @@ -1462,7 +1465,7 @@ static struct NVGvertex* nvg__roundCapStart(struct NVGvertex* dst, struct NVGpoi return dst; } -static struct NVGvertex* nvg__roundCapEnd(struct NVGvertex* dst, struct NVGpoint* p, +static NVGvertex* nvg__roundCapEnd(NVGvertex* dst, NVGpoint* p, float dx, float dy, float w, int ncap, float aa) { int i; @@ -1483,9 +1486,9 @@ static struct NVGvertex* nvg__roundCapEnd(struct NVGvertex* dst, struct NVGpoint } -static void nvg__calculateJoins(struct NVGcontext* ctx, float w, int lineJoin, float miterLimit) +static void nvg__calculateJoins(NVGcontext* ctx, float w, int lineJoin, float miterLimit) { - struct NVGpathCache* cache = ctx->cache; + NVGpathCache* cache = ctx->cache; int i, j; float iw = 0.0f; @@ -1493,10 +1496,10 @@ static void nvg__calculateJoins(struct NVGcontext* ctx, float w, int lineJoin, f // Calculate which joins needs extra vertices to append, and gather vertex count. for (i = 0; i < cache->npaths; i++) { - struct NVGpath* path = &cache->paths[i]; - struct NVGpoint* pts = &cache->points[path->first]; - struct NVGpoint* p0 = &pts[path->count-1]; - struct NVGpoint* p1 = &pts[0]; + NVGpath* path = &cache->paths[i]; + NVGpoint* pts = &cache->points[path->first]; + NVGpoint* p0 = &pts[path->count-1]; + NVGpoint* p1 = &pts[0]; int nleft = 0; path->nbevel = 0; @@ -1553,11 +1556,11 @@ static void nvg__calculateJoins(struct NVGcontext* ctx, float w, int lineJoin, f } -static int nvg__expandStroke(struct NVGcontext* ctx, float w, int lineCap, int lineJoin, float miterLimit) +static int nvg__expandStroke(NVGcontext* ctx, float w, int lineCap, int lineJoin, float miterLimit) { - struct NVGpathCache* cache = ctx->cache; - struct NVGvertex* verts; - struct NVGvertex* dst; + NVGpathCache* cache = ctx->cache; + NVGvertex* verts; + NVGvertex* dst; int cverts, i, j; float aa = ctx->fringeWidth; int ncap = nvg__curveDivs(w, NVG_PI, ctx->tessTol); // Calculate divisions per half circle. @@ -1567,7 +1570,7 @@ static int nvg__expandStroke(struct NVGcontext* ctx, float w, int lineCap, int l // Calculate max vertex usage. cverts = 0; for (i = 0; i < cache->npaths; i++) { - struct NVGpath* path = &cache->paths[i]; + NVGpath* path = &cache->paths[i]; int loop = (path->closed == 0) ? 0 : 1; if (lineCap == NVG_ROUND) cverts += (path->count + path->nbevel*(ncap+2) + 1) * 2; // plus one for loop @@ -1587,10 +1590,10 @@ static int nvg__expandStroke(struct NVGcontext* ctx, float w, int lineCap, int l if (verts == NULL) return 0; for (i = 0; i < cache->npaths; i++) { - struct NVGpath* path = &cache->paths[i]; - struct NVGpoint* pts = &cache->points[path->first]; - struct NVGpoint* p0; - struct NVGpoint* p1; + NVGpath* path = &cache->paths[i]; + NVGpoint* pts = &cache->points[path->first]; + NVGpoint* p0; + NVGpoint* p1; int s, e, loop; float dx, dy; @@ -1668,11 +1671,11 @@ static int nvg__expandStroke(struct NVGcontext* ctx, float w, int lineCap, int l return 1; } -static int nvg__expandFill(struct NVGcontext* ctx, float w, int lineJoin, float miterLimit) +static int nvg__expandFill(NVGcontext* ctx, float w, int lineJoin, float miterLimit) { - struct NVGpathCache* cache = ctx->cache; - struct NVGvertex* verts; - struct NVGvertex* dst; + NVGpathCache* cache = ctx->cache; + NVGvertex* verts; + NVGvertex* dst; int cverts, convex, i, j; float aa = ctx->fringeWidth; int fringe = w > 0.0f; @@ -1682,7 +1685,7 @@ static int nvg__expandFill(struct NVGcontext* ctx, float w, int lineJoin, float // Calculate max vertex usage. cverts = 0; for (i = 0; i < cache->npaths; i++) { - struct NVGpath* path = &cache->paths[i]; + NVGpath* path = &cache->paths[i]; cverts += path->count + path->nbevel + 1; if (fringe) cverts += (path->count + path->nbevel*5 + 1) * 2; // plus one for loop @@ -1694,10 +1697,10 @@ static int nvg__expandFill(struct NVGcontext* ctx, float w, int lineJoin, float convex = cache->npaths == 1 && cache->paths[0].convex; for (i = 0; i < cache->npaths; i++) { - struct NVGpath* path = &cache->paths[i]; - struct NVGpoint* pts = &cache->points[path->first]; - struct NVGpoint* p0; - struct NVGpoint* p1; + NVGpath* path = &cache->paths[i]; + NVGpoint* pts = &cache->points[path->first]; + NVGpoint* p0; + NVGpoint* p1; float rw, lw, woff; float ru, lu; @@ -1790,31 +1793,31 @@ static int nvg__expandFill(struct NVGcontext* ctx, float w, int lineJoin, float // Draw -void nvgBeginPath(struct NVGcontext* ctx) +void nvgBeginPath(NVGcontext* ctx) { ctx->ncommands = 0; nvg__clearPathCache(ctx); } -void nvgMoveTo(struct NVGcontext* ctx, float x, float y) +void nvgMoveTo(NVGcontext* ctx, float x, float y) { float vals[] = { NVG_MOVETO, x, y }; nvg__appendCommands(ctx, vals, NVG_COUNTOF(vals)); } -void nvgLineTo(struct NVGcontext* ctx, float x, float y) +void nvgLineTo(NVGcontext* ctx, float x, float y) { float vals[] = { NVG_LINETO, x, y }; nvg__appendCommands(ctx, vals, NVG_COUNTOF(vals)); } -void nvgBezierTo(struct NVGcontext* ctx, float c1x, float c1y, float c2x, float c2y, float x, float y) +void nvgBezierTo(NVGcontext* ctx, float c1x, float c1y, float c2x, float c2y, float x, float y) { float vals[] = { NVG_BEZIERTO, c1x, c1y, c2x, c2y, x, y }; nvg__appendCommands(ctx, vals, NVG_COUNTOF(vals)); } -void nvgQuadTo(struct NVGcontext* ctx, float cx, float cy, float x, float y) +void nvgQuadTo(NVGcontext* ctx, float cx, float cy, float x, float y) { float x0 = ctx->commandx; float y0 = ctx->commandy; @@ -1825,7 +1828,7 @@ void nvgQuadTo(struct NVGcontext* ctx, float cx, float cy, float x, float y) nvg__appendCommands(ctx, vals, NVG_COUNTOF(vals)); } -void nvgArcTo(struct NVGcontext* ctx, float x1, float y1, float x2, float y2, float radius) +void nvgArcTo(NVGcontext* ctx, float x1, float y1, float x2, float y2, float radius) { float x0 = ctx->commandx; float y0 = ctx->commandy; @@ -1881,19 +1884,19 @@ void nvgArcTo(struct NVGcontext* ctx, float x1, float y1, float x2, float y2, fl nvgArc(ctx, cx, cy, radius, a0, a1, dir); } -void nvgClosePath(struct NVGcontext* ctx) +void nvgClosePath(NVGcontext* ctx) { float vals[] = { NVG_CLOSE }; nvg__appendCommands(ctx, vals, NVG_COUNTOF(vals)); } -void nvgPathWinding(struct NVGcontext* ctx, int dir) +void nvgPathWinding(NVGcontext* ctx, int dir) { float vals[] = { NVG_WINDING, (float)dir }; nvg__appendCommands(ctx, vals, NVG_COUNTOF(vals)); } -void nvgArc(struct NVGcontext* ctx, float cx, float cy, float r, float a0, float a1, int dir) +void nvgArc(NVGcontext* ctx, float cx, float cy, float r, float a0, float a1, int dir) { float a = 0, da = 0, hda = 0, kappa = 0; float dx = 0, dy = 0, x = 0, y = 0, tanx = 0, tany = 0; @@ -1958,7 +1961,7 @@ void nvgArc(struct NVGcontext* ctx, float cx, float cy, float r, float a0, float nvg__appendCommands(ctx, vals, nvals); } -void nvgRect(struct NVGcontext* ctx, float x, float y, float w, float h) +void nvgRect(NVGcontext* ctx, float x, float y, float w, float h) { float vals[] = { NVG_MOVETO, x,y, @@ -1970,7 +1973,7 @@ void nvgRect(struct NVGcontext* ctx, float x, float y, float w, float h) nvg__appendCommands(ctx, vals, NVG_COUNTOF(vals)); } -void nvgRoundedRect(struct NVGcontext* ctx, float x, float y, float w, float h, float r) +void nvgRoundedRect(NVGcontext* ctx, float x, float y, float w, float h, float r) { if (r < 0.1f) { nvgRect(ctx, x,y,w,h); @@ -1994,7 +1997,7 @@ void nvgRoundedRect(struct NVGcontext* ctx, float x, float y, float w, float h, } } -void nvgEllipse(struct NVGcontext* ctx, float cx, float cy, float rx, float ry) +void nvgEllipse(NVGcontext* ctx, float cx, float cy, float rx, float ry) { float vals[] = { NVG_MOVETO, cx-rx, cy, @@ -2007,14 +2010,14 @@ void nvgEllipse(struct NVGcontext* ctx, float cx, float cy, float rx, float ry) nvg__appendCommands(ctx, vals, NVG_COUNTOF(vals)); } -void nvgCircle(struct NVGcontext* ctx, float cx, float cy, float r) +void nvgCircle(NVGcontext* ctx, float cx, float cy, float r) { nvgEllipse(ctx, cx,cy, r,r); } -void nvgDebugDumpPathCache(struct NVGcontext* ctx) +void nvgDebugDumpPathCache(NVGcontext* ctx) { - const struct NVGpath* path; + const NVGpath* path; int i, j; printf("Dumping %d cached paths\n", ctx->cache->npaths); @@ -2034,11 +2037,11 @@ void nvgDebugDumpPathCache(struct NVGcontext* ctx) } } -void nvgFill(struct NVGcontext* ctx) +void nvgFill(NVGcontext* ctx) { - struct NVGstate* state = nvg__getState(ctx); - const struct NVGpath* path; - struct NVGpaint fillPaint = state->fill; + NVGstate* state = nvg__getState(ctx); + const NVGpath* path; + NVGpaint fillPaint = state->fill; int i; nvg__flattenPaths(ctx); @@ -2063,13 +2066,13 @@ void nvgFill(struct NVGcontext* ctx) } } -void nvgStroke(struct NVGcontext* ctx) +void nvgStroke(NVGcontext* ctx) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); float scale = nvg__getAverageScale(state->xform); float strokeWidth = nvg__clampf(state->strokeWidth * scale, 0.0f, 200.0f); - struct NVGpaint strokePaint = state->stroke; - const struct NVGpath* path; + NVGpaint strokePaint = state->stroke; + const NVGpath* path; int i; if (strokeWidth < ctx->fringeWidth) { @@ -2104,62 +2107,62 @@ void nvgStroke(struct NVGcontext* ctx) } // Add fonts -int nvgCreateFont(struct NVGcontext* ctx, const char* name, const char* path) +int nvgCreateFont(NVGcontext* ctx, const char* name, const char* path) { return fonsAddFont(ctx->fs, name, path); } -int nvgCreateFontMem(struct NVGcontext* ctx, const char* name, unsigned char* data, int ndata, int freeData) +int nvgCreateFontMem(NVGcontext* ctx, const char* name, unsigned char* data, int ndata, int freeData) { return fonsAddFontMem(ctx->fs, name, data, ndata, freeData); } -int nvgFindFont(struct NVGcontext* ctx, const char* name) +int nvgFindFont(NVGcontext* ctx, const char* name) { if (name == NULL) return -1; return fonsGetFontByName(ctx->fs, name); } // State setting -void nvgFontSize(struct NVGcontext* ctx, float size) +void nvgFontSize(NVGcontext* ctx, float size) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); state->fontSize = size; } -void nvgFontBlur(struct NVGcontext* ctx, float blur) +void nvgFontBlur(NVGcontext* ctx, float blur) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); state->fontBlur = blur; } -void nvgTextLetterSpacing(struct NVGcontext* ctx, float spacing) +void nvgTextLetterSpacing(NVGcontext* ctx, float spacing) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); state->letterSpacing = spacing; } -void nvgTextLineHeight(struct NVGcontext* ctx, float lineHeight) +void nvgTextLineHeight(NVGcontext* ctx, float lineHeight) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); state->lineHeight = lineHeight; } -void nvgTextAlign(struct NVGcontext* ctx, int align) +void nvgTextAlign(NVGcontext* ctx, int align) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); state->textAlign = align; } -void nvgFontFaceId(struct NVGcontext* ctx, int font) +void nvgFontFaceId(NVGcontext* ctx, int font) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); state->fontId = font; } -void nvgFontFace(struct NVGcontext* ctx, const char* font) +void nvgFontFace(NVGcontext* ctx, const char* font) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); state->fontId = fonsGetFontByName(ctx->fs, font); } @@ -2168,12 +2171,12 @@ static float nvg__quantize(float a, float d) return ((int)(a / d + 0.5f)) * d; } -static float nvg__getFontScale(struct NVGstate* state) +static float nvg__getFontScale(NVGstate* state) { return nvg__minf(nvg__quantize(nvg__getAverageScale(state->xform), 0.01f), 4.0f); } -static void nvg__flushTextTexture(struct NVGcontext* ctx) +static void nvg__flushTextTexture(NVGcontext* ctx) { int dirty[4]; @@ -2192,7 +2195,7 @@ static void nvg__flushTextTexture(struct NVGcontext* ctx) } } -static int nvg__allocTextAtlas(struct NVGcontext* ctx) +static int nvg__allocTextAtlas(NVGcontext* ctx) { int iw, ih; nvg__flushTextTexture(ctx); @@ -2216,10 +2219,10 @@ static int nvg__allocTextAtlas(struct NVGcontext* ctx) return 1; } -static void nvg__renderText(struct NVGcontext* ctx, struct NVGvertex* verts, int nverts) +static void nvg__renderText(NVGcontext* ctx, NVGvertex* verts, int nverts) { - struct NVGstate* state = nvg__getState(ctx); - struct NVGpaint paint = state->fill; + NVGstate* state = nvg__getState(ctx); + NVGpaint paint = state->fill; // Render triangles. paint.image = ctx->fontImages[ctx->fontImageIdx]; @@ -2234,12 +2237,12 @@ static void nvg__renderText(struct NVGcontext* ctx, struct NVGvertex* verts, int ctx->textTriCount += nverts/3; } -float nvgText(struct NVGcontext* ctx, float x, float y, const char* string, const char* end) +float nvgText(NVGcontext* ctx, float x, float y, const char* string, const char* end) { - struct NVGstate* state = nvg__getState(ctx); - struct FONStextIter iter, prevIter; - struct FONSquad q; - struct NVGvertex* verts; + NVGstate* state = nvg__getState(ctx); + FONStextIter iter, prevIter; + FONSquad q; + NVGvertex* verts; float scale = nvg__getFontScale(state) * ctx->devicePxRatio; float invscale = 1.0f / scale; int cverts = 0; @@ -2301,10 +2304,10 @@ float nvgText(struct NVGcontext* ctx, float x, float y, const char* string, cons return iter.x; } -void nvgTextBox(struct NVGcontext* ctx, float x, float y, float breakRowWidth, const char* string, const char* end) +void nvgTextBox(NVGcontext* ctx, float x, float y, float breakRowWidth, const char* string, const char* end) { - struct NVGstate* state = nvg__getState(ctx); - struct NVGtextRow rows[2]; + NVGstate* state = nvg__getState(ctx); + NVGtextRow rows[2]; int nrows = 0, i; int oldAlign = state->textAlign; int haling = state->textAlign & (NVG_ALIGN_LEFT | NVG_ALIGN_CENTER | NVG_ALIGN_RIGHT); @@ -2319,7 +2322,7 @@ void nvgTextBox(struct NVGcontext* ctx, float x, float y, float breakRowWidth, c while ((nrows = nvgTextBreakLines(ctx, string, end, breakRowWidth, rows, 2))) { for (i = 0; i < nrows; i++) { - struct NVGtextRow* row = &rows[i]; + NVGtextRow* row = &rows[i]; if (haling & NVG_ALIGN_LEFT) nvgText(ctx, x, y, row->start, row->end); else if (haling & NVG_ALIGN_CENTER) @@ -2334,13 +2337,13 @@ void nvgTextBox(struct NVGcontext* ctx, float x, float y, float breakRowWidth, c state->textAlign = oldAlign; } -int nvgTextGlyphPositions(struct NVGcontext* ctx, float x, float y, const char* string, const char* end, struct NVGglyphPosition* positions, int maxPositions) +int nvgTextGlyphPositions(NVGcontext* ctx, float x, float y, const char* string, const char* end, NVGglyphPosition* positions, int maxPositions) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); float scale = nvg__getFontScale(state) * ctx->devicePxRatio; float invscale = 1.0f / scale; - struct FONStextIter iter, prevIter; - struct FONSquad q; + FONStextIter iter, prevIter; + FONSquad q; int npos = 0; if (state->fontId == FONS_INVALID) return 0; @@ -2383,13 +2386,13 @@ enum NVGcodepointType { NVG_CHAR, }; -int nvgTextBreakLines(struct NVGcontext* ctx, const char* string, const char* end, float breakRowWidth, struct NVGtextRow* rows, int maxRows) +int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, float breakRowWidth, NVGtextRow* rows, int maxRows) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); float scale = nvg__getFontScale(state) * ctx->devicePxRatio; float invscale = 1.0f / scale; - struct FONStextIter iter, prevIter; - struct FONSquad q; + FONStextIter iter, prevIter; + FONSquad q; int nrows = 0; float rowStartX = 0; float rowWidth = 0; @@ -2580,9 +2583,9 @@ int nvgTextBreakLines(struct NVGcontext* ctx, const char* string, const char* en return nrows; } -float nvgTextBounds(struct NVGcontext* ctx, float x, float y, const char* string, const char* end, float* bounds) +float nvgTextBounds(NVGcontext* ctx, float x, float y, const char* string, const char* end, float* bounds) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); float scale = nvg__getFontScale(state) * ctx->devicePxRatio; float invscale = 1.0f / scale; float width; @@ -2607,10 +2610,10 @@ float nvgTextBounds(struct NVGcontext* ctx, float x, float y, const char* string return width * invscale; } -void nvgTextBoxBounds(struct NVGcontext* ctx, float x, float y, float breakRowWidth, 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) { - struct NVGstate* state = nvg__getState(ctx); - struct NVGtextRow rows[2]; + NVGstate* state = nvg__getState(ctx); + NVGtextRow rows[2]; float scale = nvg__getFontScale(state) * ctx->devicePxRatio; float invscale = 1.0f / scale; int nrows = 0, i; @@ -2646,7 +2649,7 @@ void nvgTextBoxBounds(struct NVGcontext* ctx, float x, float y, float breakRowWi while ((nrows = nvgTextBreakLines(ctx, string, end, breakRowWidth, rows, 2))) { for (i = 0; i < nrows; i++) { - struct NVGtextRow* row = &rows[i]; + NVGtextRow* row = &rows[i]; float rminx, rmaxx, dx = 0; // Horizontal bounds if (haling & NVG_ALIGN_LEFT) @@ -2678,9 +2681,9 @@ void nvgTextBoxBounds(struct NVGcontext* ctx, float x, float y, float breakRowWi } } -void nvgTextMetrics(struct NVGcontext* ctx, float* ascender, float* descender, float* lineh) +void nvgTextMetrics(NVGcontext* ctx, float* ascender, float* descender, float* lineh) { - struct NVGstate* state = nvg__getState(ctx); + NVGstate* state = nvg__getState(ctx); float scale = nvg__getFontScale(state) * ctx->devicePxRatio; float invscale = 1.0f / scale; diff --git a/src/nanovg.h b/src/nanovg.h index 6487293..23d9e37 100644 --- a/src/nanovg.h +++ b/src/nanovg.h @@ -30,7 +30,7 @@ extern "C" { #pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union #endif -struct NVGcontext; +typedef struct NVGcontext NVGcontext; struct NVGcolor { union { @@ -40,17 +40,19 @@ struct NVGcolor { }; }; }; +typedef struct NVGcolor NVGcolor; struct NVGpaint { float xform[6]; float extent[2]; float radius; float feather; - struct NVGcolor innerColor; - struct NVGcolor outerColor; + NVGcolor innerColor; + NVGcolor outerColor; int image; int repeat; }; +typedef struct NVGpaint NVGpaint; enum NVGwinding { NVG_CCW = 1, // Winding for solid shapes @@ -93,6 +95,7 @@ struct NVGglyphPosition { float x; // The x-coordinate of the logical glyph position. float minx, maxx; // The bounds of the glyph shape. }; +typedef struct NVGglyphPosition NVGglyphPosition; struct NVGtextRow { const char* start; // Pointer to the input text where the row starts. @@ -101,6 +104,7 @@ struct NVGtextRow { float width; // Logical width of the row. float minx, maxx; // Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending. }; +typedef struct NVGtextRow NVGtextRow; enum NVGimage { NVG_IMAGE_GENERATE_MIPMAPS = 1 << 0 // Generate mipmaps during creation of the image. @@ -114,10 +118,10 @@ enum NVGimage { // For example, GLFW returns two dimension for an opened window: window size and // frame buffer size. In that case you would set windowWidth/Height to the window size // devicePixelRatio to: frameBufferWidth / windowWidth. -void nvgBeginFrame(struct NVGcontext* ctx, int windowWidth, int windowHeight, float devicePixelRatio); +void nvgBeginFrame(NVGcontext* ctx, int windowWidth, int windowHeight, float devicePixelRatio); // Ends drawing flushing remaining render state. -void nvgEndFrame(struct NVGcontext* ctx); +void nvgEndFrame(NVGcontext* ctx); // // Color utils @@ -125,35 +129,35 @@ void nvgEndFrame(struct NVGcontext* ctx); // Colors in NanoVG are stored as unsigned ints in ABGR format. // Returns a color value from red, green, blue values. Alpha will be set to 255 (1.0f). -struct NVGcolor nvgRGB(unsigned char r, unsigned char g, unsigned char b); +NVGcolor nvgRGB(unsigned char r, unsigned char g, unsigned char b); // Returns a color value from red, green, blue values. Alpha will be set to 1.0f. -struct NVGcolor nvgRGBf(float r, float g, float b); +NVGcolor nvgRGBf(float r, float g, float b); // Returns a color value from red, green, blue and alpha values. -struct NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a); +NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a); // Returns a color value from red, green, blue and alpha values. -struct NVGcolor nvgRGBAf(float r, float g, float b, float a); +NVGcolor nvgRGBAf(float r, float g, float b, float a); // Linearly interpoaltes from color c0 to c1, and returns resulting color value. -struct NVGcolor nvgLerpRGBA(struct NVGcolor c0, struct NVGcolor c1, float u); +NVGcolor nvgLerpRGBA(NVGcolor c0, NVGcolor c1, float u); // Sets transparency of a color value. -struct NVGcolor nvgTransRGBA(struct NVGcolor c0, unsigned char a); +NVGcolor nvgTransRGBA(NVGcolor c0, unsigned char a); // Sets transparency of a color value. -struct NVGcolor nvgTransRGBAf(struct NVGcolor c0, float a); +NVGcolor nvgTransRGBAf(NVGcolor c0, float a); // Returns color value specified by hue, saturation and lightness. // HSL values are all in range [0..1], alpha will be set to 255. -struct NVGcolor nvgHSL(float h, float s, float l); +NVGcolor nvgHSL(float h, float s, float l); // Returns color value specified by hue, saturation and lightness and alpha. // HSL values are all in range [0..1], alpha in range [0..255] -struct NVGcolor nvgHSLA(float h, float s, float l, unsigned char a); +NVGcolor nvgHSLA(float h, float s, float l, unsigned char a); // // State Handling @@ -164,13 +168,13 @@ struct NVGcolor nvgHSLA(float h, float s, float l, unsigned char a); // Pushes and saves the current render state into a state stack. // A matching nvgRestore() must be used to restore the state. -void nvgSave(struct NVGcontext* ctx); +void nvgSave(NVGcontext* ctx); // Pops and restores current render state. -void nvgRestore(struct NVGcontext* ctx); +void nvgRestore(NVGcontext* ctx); // Resets current render state to default values. Does not affect the render state stack. -void nvgReset(struct NVGcontext* ctx); +void nvgReset(NVGcontext* ctx); // // Render styles @@ -182,35 +186,35 @@ void nvgReset(struct NVGcontext* ctx); // Current render style can be saved and restored using nvgSave() and nvgRestore(). // Sets current stroke style to a solid color. -void nvgStrokeColor(struct NVGcontext* ctx, struct NVGcolor color); +void nvgStrokeColor(NVGcontext* ctx, NVGcolor color); // Sets current stroke style to a paint, which can be a one of the gradients or a pattern. -void nvgStrokePaint(struct NVGcontext* ctx, struct NVGpaint paint); +void nvgStrokePaint(NVGcontext* ctx, NVGpaint paint); // Sets current fill cstyle to a solid color. -void nvgFillColor(struct NVGcontext* ctx, struct NVGcolor color); +void nvgFillColor(NVGcontext* ctx, NVGcolor color); // Sets current fill style to a paint, which can be a one of the gradients or a pattern. -void nvgFillPaint(struct NVGcontext* ctx, struct NVGpaint paint); +void nvgFillPaint(NVGcontext* ctx, NVGpaint paint); // Sets the miter limit of the stroke style. // Miter limit controls when a sharp corner is beveled. -void nvgMiterLimit(struct NVGcontext* ctx, float limit); +void nvgMiterLimit(NVGcontext* ctx, float limit); // Sets the stroke witdth of the stroke style. -void nvgStrokeWidth(struct NVGcontext* ctx, float size); +void nvgStrokeWidth(NVGcontext* ctx, float size); // Sets how the end of the line (cap) is drawn, // Can be one of: NVG_BUTT (default), NVG_ROUND, NVG_SQUARE. -void nvgLineCap(struct NVGcontext* ctx, int cap); +void nvgLineCap(NVGcontext* ctx, int cap); // Sets how sharp path corners are drawn. // Can be one of NVG_MITER (default), NVG_ROUND, NVG_BEVEL. -void nvgLineJoin(struct NVGcontext* ctx, int join); +void nvgLineJoin(NVGcontext* ctx, int join); // Sets the transparency applied to all rendered shapes. // Alreade transparent paths will get proportionally more transparent as well. -void nvgGlobalAlpha(struct NVGcontext* ctx, float alpha); +void nvgGlobalAlpha(NVGcontext* ctx, float alpha); // // Transforms @@ -230,36 +234,36 @@ void nvgGlobalAlpha(struct NVGcontext* ctx, float alpha); // Current coordinate system (transformation) can be saved and restored using nvgSave() and nvgRestore(). // Resets current transform to a identity matrix. -void nvgResetTransform(struct NVGcontext* ctx); +void nvgResetTransform(NVGcontext* ctx); // Premultiplies current coordinate system by specified matrix. // The parameters are interpreted as matrix as follows: // [a c e] // [b d f] // [0 0 1] -void nvgTransform(struct NVGcontext* ctx, float a, float b, float c, float d, float e, float f); +void nvgTransform(NVGcontext* ctx, float a, float b, float c, float d, float e, float f); // Translates current coordinate system. -void nvgTranslate(struct NVGcontext* ctx, float x, float y); +void nvgTranslate(NVGcontext* ctx, float x, float y); // Rotates current coordinate system. Angle is specifid in radians. -void nvgRotate(struct NVGcontext* ctx, float angle); +void nvgRotate(NVGcontext* ctx, float angle); // Skews the current coordinate system along X axis. Angle is specifid in radians. -void nvgSkewX(struct NVGcontext* ctx, float angle); +void nvgSkewX(NVGcontext* ctx, float angle); // Skews the current coordinate system along Y axis. Angle is specifid in radians. -void nvgSkewY(struct NVGcontext* ctx, float angle); +void nvgSkewY(NVGcontext* ctx, float angle); // Scales the current coordinat system. -void nvgScale(struct NVGcontext* ctx, float x, float y); +void nvgScale(NVGcontext* ctx, float x, float y); // Stores the top part (a-f) of the current transformation matrix in to the specified buffer. // [a c e] // [b d f] // [0 0 1] // There should be space for 6 floats in the return buffer for the values a-f. -void nvgCurrentTransform(struct NVGcontext* ctx, float* xform); +void nvgCurrentTransform(NVGcontext* ctx, float* xform); // The following functions can be used to make calculations on 2x3 transformation matrices. @@ -308,24 +312,24 @@ float nvgRadToDeg(float rad); // Creates image by loading it from the disk from specified file name. // Returns handle to the image. -int nvgCreateImage(struct NVGcontext* ctx, const char* filename, int imageFlags); +int nvgCreateImage(NVGcontext* ctx, const char* filename, int imageFlags); // Creates image by loading it from the specified chunk of memory. // Returns handle to the image. -int nvgCreateImageMem(struct NVGcontext* ctx, int imageFlags, unsigned char* data, int ndata); +int nvgCreateImageMem(NVGcontext* ctx, int imageFlags, unsigned char* data, int ndata); // Creates image from specified image data. // Returns handle to the image. -int nvgCreateImageRGBA(struct NVGcontext* ctx, int w, int h, int imageFlags, const unsigned char* data); +int nvgCreateImageRGBA(NVGcontext* ctx, int w, int h, int imageFlags, const unsigned char* data); // Updates image data specified by image handle. -void nvgUpdateImage(struct NVGcontext* ctx, int image, const unsigned char* data); +void nvgUpdateImage(NVGcontext* ctx, int image, const unsigned char* data); // Returns the domensions of a created image. -void nvgImageSize(struct NVGcontext* ctx, int image, int* w, int* h); +void nvgImageSize(NVGcontext* ctx, int image, int* w, int* h); // Deletes created image. -void nvgDeleteImage(struct NVGcontext* ctx, int image); +void nvgDeleteImage(NVGcontext* ctx, int image); // // Paints @@ -336,29 +340,29 @@ void nvgDeleteImage(struct NVGcontext* ctx, int image); // Creates and returns a linear gradient. Parameters (sx,sy)-(ex,ey) specify the start and end coordinates // of the linear gradient, icol specifies the start color and ocol the end color. // The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint(). -struct NVGpaint nvgLinearGradient(struct NVGcontext* ctx, float sx, float sy, float ex, float ey, - struct NVGcolor icol, struct NVGcolor ocol); +NVGpaint nvgLinearGradient(NVGcontext* ctx, float sx, float sy, float ex, float ey, + NVGcolor icol, NVGcolor ocol); // Creates and returns a box gradient. Box gradient is a feathered rounded rectangle, it is useful for rendering // drop shadows or hilights for boxes. Parameters (x,y) define the top-left corner of the rectangle, // (w,h) define the size of the rectangle, r defines the corner radius, and f feather. Feather defines how blurry // the border of the rectangle is. Parameter icol specifies the inner color and ocol the outer color of the gradient. // The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint(). -struct NVGpaint nvgBoxGradient(struct NVGcontext* ctx, float x, float y, float w, float h, - float r, float f, struct NVGcolor icol, struct NVGcolor ocol); +NVGpaint nvgBoxGradient(NVGcontext* ctx, float x, float y, float w, float h, + float r, float f, NVGcolor icol, NVGcolor ocol); // Creates and returns a radial gradient. Parameters (cx,cy) specify the center, inr and outr specify // the inner and outer radius of the gradient, icol specifies the start color and ocol the end color. // The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint(). -struct NVGpaint nvgRadialGradient(struct NVGcontext* ctx, float cx, float cy, float inr, float outr, - struct NVGcolor icol, struct NVGcolor ocol); +NVGpaint nvgRadialGradient(NVGcontext* ctx, float cx, float cy, float inr, float outr, + NVGcolor icol, NVGcolor ocol); // Creates and returns an image patter. Parameters (ox,oy) specify the left-top location of the image pattern, // (ex,ey) the size of one image, angle rotation around the top-left corner, image is handle to the image to render, // and repeat is combination of NVG_REPEATX and NVG_REPEATY which tells if the image should be repeated across x or y. // The gradient is transformed by the current transform when it is passed to nvgFillPaint() or nvgStrokePaint(). -struct NVGpaint nvgImagePattern(struct NVGcontext* ctx, float ox, float oy, float ex, float ey, - float angle, int image, int repeat, float alpha); +NVGpaint nvgImagePattern(NVGcontext* ctx, float ox, float oy, float ex, float ey, + float angle, int image, int repeat, float alpha); // // Scissoring @@ -368,10 +372,10 @@ struct NVGpaint nvgImagePattern(struct NVGcontext* ctx, float ox, float oy, floa // Sets the current // The scissor rectangle is transformed by the current transform. -void nvgScissor(struct NVGcontext* ctx, float x, float y, float w, float h); +void nvgScissor(NVGcontext* ctx, float x, float y, float w, float h); // Reset and disables scissoring. -void nvgResetScissor(struct NVGcontext* ctx); +void nvgResetScissor(NVGcontext* ctx); // // Paths @@ -391,51 +395,51 @@ void nvgResetScissor(struct NVGcontext* ctx); // The curve segments and sub-paths are transformed by the current transform. // Clears the current path and sub-paths. -void nvgBeginPath(struct NVGcontext* ctx); +void nvgBeginPath(NVGcontext* ctx); // Starts new sub-path with specified point as first point. -void nvgMoveTo(struct NVGcontext* ctx, float x, float y); +void nvgMoveTo(NVGcontext* ctx, float x, float y); // Adds line segment from the last point in the path to the specified point. -void nvgLineTo(struct NVGcontext* ctx, float x, float y); +void nvgLineTo(NVGcontext* ctx, float x, float y); // Adds cubic bezier segment from last point in the path via two control points to the specified point. -void nvgBezierTo(struct NVGcontext* ctx, float c1x, float c1y, float c2x, float c2y, float x, float y); +void nvgBezierTo(NVGcontext* ctx, float c1x, float c1y, float c2x, float c2y, float x, float y); // Adds quadratic bezier segment from last point in the path via a control point to the specified point. -void nvgQuadTo(struct NVGcontext* ctx, float cx, float cy, float x, float y); +void nvgQuadTo(NVGcontext* ctx, float cx, float cy, float x, float y); // Adds an arc segment at the corner defined by the last path point, and two specified points. -void nvgArcTo(struct NVGcontext* ctx, float x1, float y1, float x2, float y2, float radius); +void nvgArcTo(NVGcontext* ctx, float x1, float y1, float x2, float y2, float radius); // Closes current sub-path with a line segment. -void nvgClosePath(struct NVGcontext* ctx); +void nvgClosePath(NVGcontext* ctx); // Sets the current sub-path winding, see NVGwinding and NVGsolidity. -void nvgPathWinding(struct NVGcontext* ctx, int dir); +void nvgPathWinding(NVGcontext* ctx, int dir); // Creates new circle arc shaped sub-path. The arc center is at cx,cy, the arc radius is r, // and the arc is drawn from angle a0 to a1, and swept in direction dir (NVG_CCW, or NVG_CW). // Angles are specified in radians. -void nvgArc(struct NVGcontext* ctx, float cx, float cy, float r, float a0, float a1, int dir); +void nvgArc(NVGcontext* ctx, float cx, float cy, float r, float a0, float a1, int dir); // Creates new rectangle shaped sub-path. -void nvgRect(struct NVGcontext* ctx, float x, float y, float w, float h); +void nvgRect(NVGcontext* ctx, float x, float y, float w, float h); // Creates new rounded rectangle shaped sub-path. -void nvgRoundedRect(struct NVGcontext* ctx, float x, float y, float w, float h, float r); +void nvgRoundedRect(NVGcontext* ctx, float x, float y, float w, float h, float r); // Creates new ellipse shaped sub-path. -void nvgEllipse(struct NVGcontext* ctx, float cx, float cy, float rx, float ry); +void nvgEllipse(NVGcontext* ctx, float cx, float cy, float rx, float ry); // Creates new circle shaped sub-path. -void nvgCircle(struct NVGcontext* ctx, float cx, float cy, float r); +void nvgCircle(NVGcontext* ctx, float cx, float cy, float r); // Fills the current path with current fill style. -void nvgFill(struct NVGcontext* ctx); +void nvgFill(NVGcontext* ctx); // Fills the current path with current stroke style. -void nvgStroke(struct NVGcontext* ctx); +void nvgStroke(NVGcontext* ctx); // @@ -473,67 +477,67 @@ void nvgStroke(struct NVGcontext* ctx); // Creates font by loading it from the disk from specified file name. // Returns handle to the font. -int nvgCreateFont(struct NVGcontext* ctx, const char* name, const char* filename); +int nvgCreateFont(NVGcontext* ctx, const char* name, const char* filename); // Creates image by loading it from the specified memory chunk. // Returns handle to the font. -int nvgCreateFontMem(struct NVGcontext* ctx, const char* name, unsigned char* data, int ndata, int freeData); +int nvgCreateFontMem(NVGcontext* ctx, const char* name, unsigned char* data, int ndata, int freeData); // Finds a loaded font of specified name, and returns handle to it, or -1 if the font is not found. -int nvgFindFont(struct NVGcontext* ctx, const char* name); +int nvgFindFont(NVGcontext* ctx, const char* name); // Sets the font size of current text style. -void nvgFontSize(struct NVGcontext* ctx, float size); +void nvgFontSize(NVGcontext* ctx, float size); // Sets the blur of current text style. -void nvgFontBlur(struct NVGcontext* ctx, float blur); +void nvgFontBlur(NVGcontext* ctx, float blur); // Sets the letter spacing of current text style. -void nvgTextLetterSpacing(struct NVGcontext* ctx, float spacing); +void nvgTextLetterSpacing(NVGcontext* ctx, float spacing); // Sets the proportional line height of current text style. The line height is specified as multiple of font size. -void nvgTextLineHeight(struct NVGcontext* ctx, float lineHeight); +void nvgTextLineHeight(NVGcontext* ctx, float lineHeight); // Sets the text align of current text style, see NVGaling for options. -void nvgTextAlign(struct NVGcontext* ctx, int align); +void nvgTextAlign(NVGcontext* ctx, int align); // Sets the font face based on specified id of current text style. -void nvgFontFaceId(struct NVGcontext* ctx, int font); +void nvgFontFaceId(NVGcontext* ctx, int font); // Sets the font face based on specified name of current text style. -void nvgFontFace(struct NVGcontext* ctx, const char* font); +void nvgFontFace(NVGcontext* ctx, const char* font); // Draws text string at specified location. If end is specified only the sub-string up to the end is drawn. -float nvgText(struct NVGcontext* ctx, float x, float y, const char* string, const char* end); +float nvgText(NVGcontext* ctx, float x, float y, const char* string, const char* end); // Draws multi-line text string at specified location wrapped at the specified width. If end is specified only the sub-string up to the end is drawn. // White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered. // Words longer than the max width are slit at nearest character (i.e. no hyphenation). -void nvgTextBox(struct NVGcontext* ctx, float x, float y, float breakRowWidth, const char* string, const char* end); +void nvgTextBox(NVGcontext* ctx, float x, float y, float breakRowWidth, const char* string, const char* end); // Measures the specified text string. Parameter bounds should be a pointer to float[4], // if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax] // Returns the horizontal advance of the measured text (i.e. where the next character should drawn). // Measured values are returned in local coordinate space. -float nvgTextBounds(struct NVGcontext* ctx, float x, float y, const char* string, const char* end, float* bounds); +float nvgTextBounds(NVGcontext* ctx, float x, float y, const char* string, const char* end, float* bounds); // Measures the specified multi-text string. Parameter bounds should be a pointer to float[4], // if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax] // Measured values are returned in local coordinate space. -void nvgTextBoxBounds(struct NVGcontext* ctx, float x, float y, float breakRowWidth, 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); // Calculates the glyph x positions of the specified text. If end is specified only the sub-string will be used. // Measured values are returned in local coordinate space. -int nvgTextGlyphPositions(struct NVGcontext* ctx, float x, float y, const char* string, const char* end, struct NVGglyphPosition* positions, int maxPositions); +int nvgTextGlyphPositions(NVGcontext* ctx, float x, float y, const char* string, const char* end, NVGglyphPosition* positions, int maxPositions); // Returns the vertical metrics based on the current text style. // Measured values are returned in local coordinate space. -void nvgTextMetrics(struct NVGcontext* ctx, float* ascender, float* descender, float* lineh); +void nvgTextMetrics(NVGcontext* ctx, float* ascender, float* descender, float* lineh); // Breaks the specified text into lines. If end is specified only the sub-string will be used. // White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered. // Words longer than the max width are slit at nearest character (i.e. no hyphenation). -int nvgTextBreakLines(struct NVGcontext* ctx, const char* string, const char* end, float breakRowWidth, struct NVGtextRow* rows, int maxRows); +int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, float breakRowWidth, NVGtextRow* rows, int maxRows); // // Internal Render API @@ -543,28 +547,30 @@ enum NVGtexture { NVG_TEXTURE_RGBA = 0x02, }; -struct NVGscissor -{ +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; - struct NVGvertex* fill; + NVGvertex* fill; int nfill; - struct NVGvertex* stroke; + NVGvertex* stroke; int nstroke; int winding; int convex; }; +typedef struct NVGpath NVGpath; struct NVGparams { void* userPtr; @@ -576,20 +582,21 @@ struct NVGparams { int (*renderGetTextureSize)(void* uptr, int image, int* w, int* h); void (*renderViewport)(void* uptr, int width, int height); void (*renderFlush)(void* uptr); - void (*renderFill)(void* uptr, struct NVGpaint* paint, struct NVGscissor* scissor, float fringe, const float* bounds, const struct NVGpath* paths, int npaths); - void (*renderStroke)(void* uptr, struct NVGpaint* paint, struct NVGscissor* scissor, float fringe, float strokeWidth, const struct NVGpath* paths, int npaths); - void (*renderTriangles)(void* uptr, struct NVGpaint* paint, struct NVGscissor* scissor, const struct NVGvertex* verts, int nverts); + void (*renderFill)(void* uptr, NVGpaint* paint, NVGscissor* scissor, float fringe, const float* bounds, const NVGpath* paths, int npaths); + void (*renderStroke)(void* uptr, NVGpaint* paint, NVGscissor* scissor, float fringe, float strokeWidth, const NVGpath* paths, int npaths); + void (*renderTriangles)(void* uptr, NVGpaint* paint, NVGscissor* scissor, const NVGvertex* verts, int nverts); void (*renderDelete)(void* uptr); }; +typedef struct NVGparams NVGparams; // Contructor and destructor, called by the render back-end. -struct NVGcontext* nvgCreateInternal(struct NVGparams* params); -void nvgDeleteInternal(struct NVGcontext* ctx); +NVGcontext* nvgCreateInternal(NVGparams* params); +void nvgDeleteInternal(NVGcontext* ctx); -struct NVGparams* nvgInternalParams(struct NVGcontext* ctx); +NVGparams* nvgInternalParams(NVGcontext* ctx); // Debug function to dump cached path data. -void nvgDebugDumpPathCache(struct NVGcontext* ctx); +void nvgDebugDumpPathCache(NVGcontext* ctx); #ifdef _MSC_VER #pragma warning(pop) diff --git a/src/nanovg_gl.h b/src/nanovg_gl.h index 22350ff..fc28b58 100644 --- a/src/nanovg_gl.h +++ b/src/nanovg_gl.h @@ -52,29 +52,29 @@ extern "C" { #if defined NANOVG_GL2 -struct NVGcontext* nvgCreateGL2(int flags); -void nvgDeleteGL2(struct NVGcontext* ctx); +NVGcontext* nvgCreateGL2(int flags); +void nvgDeleteGL2(NVGcontext* ctx); #endif #if defined NANOVG_GL3 -struct NVGcontext* nvgCreateGL3(int flags); -void nvgDeleteGL3(struct NVGcontext* ctx); +NVGcontext* nvgCreateGL3(int flags); +void nvgDeleteGL3(NVGcontext* ctx); #endif #if defined NANOVG_GLES2 -struct NVGcontext* nvgCreateGLES2(int flags); -void nvgDeleteGLES2(struct NVGcontext* ctx); +NVGcontext* nvgCreateGLES2(int flags); +void nvgDeleteGLES2(NVGcontext* ctx); #endif #if defined NANOVG_GLES3 -struct NVGcontext* nvgCreateGLES3(int flags); -void nvgDeleteGLES3(struct NVGcontext* ctx); +NVGcontext* nvgCreateGLES3(int flags); +void nvgDeleteGLES3(NVGcontext* ctx); #endif @@ -84,9 +84,9 @@ enum NVGLtextureflags { NVGL_TEXTURE_PREMULTIPLIED = 0x04 }; -int nvglCreateImageFromHandle(struct NVGcontext* ctx, GLuint textureId, int w, int h, int flags); -GLuint nvglImageHandle(struct NVGcontext* ctx, int image); -void nvglImageFlags(struct NVGcontext* ctx, int image, int flags); +int nvglCreateImageFromHandle(NVGcontext* ctx, GLuint textureId, int w, int h, int flags); +GLuint nvglImageHandle(NVGcontext* ctx, int image); +void nvglImageFlags(NVGcontext* ctx, int image, int flags); #ifdef __cplusplus @@ -145,6 +145,7 @@ struct GLNVGshader { GLuint vert; GLint loc[GLNVG_MAX_LOCS]; }; +typedef struct GLNVGshader GLNVGshader; struct GLNVGtexture { int id; @@ -153,6 +154,7 @@ struct GLNVGtexture { int type; int flags; }; +typedef struct GLNVGtexture GLNVGtexture; enum GLNVGcallType { GLNVG_NONE = 0, @@ -171,6 +173,7 @@ struct GLNVGcall { int triangleCount; int uniformOffset; }; +typedef struct GLNVGcall GLNVGcall; struct GLNVGpath { int fillOffset; @@ -178,6 +181,7 @@ struct GLNVGpath { int strokeOffset; int strokeCount; }; +typedef struct GLNVGpath GLNVGpath; struct GLNVGfragUniforms { float scissorMat[12]; // matrices are actually 3 vec4s @@ -194,10 +198,11 @@ struct GLNVGfragUniforms { int texType; int type; }; +typedef struct GLNVGfragUniforms GLNVGfragUniforms; struct GLNVGcontext { - struct GLNVGshader shader; - struct GLNVGtexture* textures; + GLNVGshader shader; + GLNVGtexture* textures; float view[2]; int ntextures; int ctextures; @@ -213,10 +218,10 @@ struct GLNVGcontext { int flags; // Per frame buffers - struct GLNVGcall* calls; + GLNVGcall* calls; int ccalls; int ncalls; - struct GLNVGpath* paths; + GLNVGpath* paths; int cpaths; int npaths; struct NVGvertex* verts; @@ -226,12 +231,13 @@ struct GLNVGcontext { int cuniforms; int nuniforms; }; +typedef struct GLNVGcontext GLNVGcontext; static int glnvg__maxi(int a, int b) { return a > b ? a : b; } -static struct GLNVGtexture* glnvg__allocTexture(struct GLNVGcontext* gl) +static GLNVGtexture* glnvg__allocTexture(GLNVGcontext* gl) { - struct GLNVGtexture* tex = NULL; + GLNVGtexture* tex = NULL; int i; for (i = 0; i < gl->ntextures; i++) { @@ -242,9 +248,9 @@ static struct GLNVGtexture* glnvg__allocTexture(struct GLNVGcontext* gl) } if (tex == NULL) { if (gl->ntextures+1 > gl->ctextures) { - struct GLNVGtexture* textures; + GLNVGtexture* textures; int ctextures = glnvg__maxi(gl->ntextures+1, 4) + gl->ctextures/2; // 1.5x Overallocate - textures = (struct GLNVGtexture*)realloc(gl->textures, sizeof(struct GLNVGtexture)*ctextures); + textures = (GLNVGtexture*)realloc(gl->textures, sizeof(GLNVGtexture)*ctextures); if (textures == NULL) return NULL; gl->textures = textures; gl->ctextures = ctextures; @@ -258,7 +264,7 @@ static struct GLNVGtexture* glnvg__allocTexture(struct GLNVGcontext* gl) return tex; } -static struct GLNVGtexture* glnvg__findTexture(struct GLNVGcontext* gl, int id) +static GLNVGtexture* glnvg__findTexture(GLNVGcontext* gl, int id) { int i; for (i = 0; i < gl->ntextures; i++) @@ -267,7 +273,7 @@ static struct GLNVGtexture* glnvg__findTexture(struct GLNVGcontext* gl, int id) return NULL; } -static int glnvg__deleteTexture(struct GLNVGcontext* gl, int id) +static int glnvg__deleteTexture(GLNVGcontext* gl, int id) { int i; for (i = 0; i < gl->ntextures; i++) { @@ -311,7 +317,7 @@ static int glnvg__checkError(const char* str) return 0; } -static int glnvg__createShader(struct GLNVGshader* shader, const char* name, const char* header, const char* opts, const char* vshader, const char* fshader) +static int glnvg__createShader(GLNVGshader* shader, const char* name, const char* header, const char* opts, const char* vshader, const char* fshader) { GLint status; GLuint prog, vert, frag; @@ -363,7 +369,7 @@ static int glnvg__createShader(struct GLNVGshader* shader, const char* name, con return 1; } -static void glnvg__deleteShader(struct GLNVGshader* shader) +static void glnvg__deleteShader(GLNVGshader* shader) { if (shader->prog != 0) glDeleteProgram(shader->prog); @@ -373,7 +379,7 @@ static void glnvg__deleteShader(struct GLNVGshader* shader) glDeleteShader(shader->frag); } -static void glnvg__getUniforms(struct GLNVGshader* shader) +static void glnvg__getUniforms(GLNVGshader* shader) { shader->loc[GLNVG_LOC_VIEWSIZE] = glGetUniformLocation(shader->prog, "viewSize"); shader->loc[GLNVG_LOC_TEX] = glGetUniformLocation(shader->prog, "tex"); @@ -399,7 +405,7 @@ static void glnvg__getUniforms(struct GLNVGshader* shader) static int glnvg__renderCreate(void* uptr) { - struct GLNVGcontext* gl = (struct GLNVGcontext*)uptr; + GLNVGcontext* gl = (GLNVGcontext*)uptr; int align = 4; // TODO: mediump float may not be enough for GLES2 in iOS. @@ -602,7 +608,7 @@ static int glnvg__renderCreate(void* uptr) glGenBuffers(1, &gl->fragBuf); glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &align); #endif - gl->fragSize = sizeof(struct GLNVGfragUniforms) + align - sizeof(struct GLNVGfragUniforms) % align; + gl->fragSize = sizeof(GLNVGfragUniforms) + align - sizeof(GLNVGfragUniforms) % align; glnvg__checkError("create done"); @@ -613,8 +619,8 @@ static int glnvg__renderCreate(void* uptr) static int glnvg__renderCreateTexture(void* uptr, int type, int w, int h, int imageFlags, const unsigned char* data) { - struct GLNVGcontext* gl = (struct GLNVGcontext*)uptr; - struct GLNVGtexture* tex = glnvg__allocTexture(gl); + GLNVGcontext* gl = (GLNVGcontext*)uptr; + GLNVGtexture* tex = glnvg__allocTexture(gl); if (tex == NULL) return 0; @@ -682,14 +688,14 @@ static int glnvg__renderCreateTexture(void* uptr, int type, int w, int h, int im static int glnvg__renderDeleteTexture(void* uptr, int image) { - struct GLNVGcontext* gl = (struct GLNVGcontext*)uptr; + GLNVGcontext* gl = (GLNVGcontext*)uptr; return glnvg__deleteTexture(gl, image); } static int glnvg__renderUpdateTexture(void* uptr, int image, int x, int y, int w, int h, const unsigned char* data) { - struct GLNVGcontext* gl = (struct GLNVGcontext*)uptr; - struct GLNVGtexture* tex = glnvg__findTexture(gl, image); + GLNVGcontext* gl = (GLNVGcontext*)uptr; + GLNVGtexture* tex = glnvg__findTexture(gl, image); if (tex == NULL) return 0; glBindTexture(GL_TEXTURE_2D, tex->tex); @@ -733,8 +739,8 @@ static int glnvg__renderUpdateTexture(void* uptr, int image, int x, int y, int w static int glnvg__renderGetTextureSize(void* uptr, int image, int* w, int* h) { - struct GLNVGcontext* gl = (struct GLNVGcontext*)uptr; - struct GLNVGtexture* tex = glnvg__findTexture(gl, image); + GLNVGcontext* gl = (GLNVGcontext*)uptr; + GLNVGtexture* tex = glnvg__findTexture(gl, image); if (tex == NULL) return 0; *w = tex->width; *h = tex->height; @@ -757,7 +763,7 @@ static void glnvg__xformToMat3x4(float* m3, float* t) m3[11] = 0.0f; } -static struct NVGcolor glnvg__premulColor(struct NVGcolor c) +static NVGcolor glnvg__premulColor(NVGcolor c) { c.r *= c.a; c.g *= c.a; @@ -765,10 +771,10 @@ static struct NVGcolor glnvg__premulColor(struct NVGcolor c) return c; } -static int glnvg__convertPaint(struct GLNVGcontext* gl, struct GLNVGfragUniforms* frag, struct NVGpaint* paint, - struct NVGscissor* scissor, float width, float fringe, float strokeThr) +static int glnvg__convertPaint(GLNVGcontext* gl, GLNVGfragUniforms* frag, NVGpaint* paint, + NVGscissor* scissor, float width, float fringe, float strokeThr) { - struct GLNVGtexture* tex = NULL; + GLNVGtexture* tex = NULL; float invxform[6]; memset(frag, 0, sizeof(*frag)); @@ -825,7 +831,7 @@ static int glnvg__convertPaint(struct GLNVGcontext* gl, struct GLNVGfragUniforms return 1; } -static struct GLNVGfragUniforms* nvg__fragUniformPtr(struct GLNVGcontext* gl, int i); +static GLNVGfragUniforms* nvg__fragUniformPtr(GLNVGcontext* gl, int i); #if !NANOVG_GL_USE_UNIFORMBUFFER static void glnvg__mat3(float* dst, float* src) @@ -844,12 +850,12 @@ static void glnvg__mat3(float* dst, float* src) } #endif -static void glnvg__setUniforms(struct GLNVGcontext* gl, int uniformOffset, int image) +static void glnvg__setUniforms(GLNVGcontext* gl, int uniformOffset, int image) { #if NANOVG_GL_USE_UNIFORMBUFFER - glBindBufferRange(GL_UNIFORM_BUFFER, GLNVG_FRAG_BINDING, gl->fragBuf, uniformOffset, sizeof(struct GLNVGfragUniforms)); + glBindBufferRange(GL_UNIFORM_BUFFER, GLNVG_FRAG_BINDING, gl->fragBuf, uniformOffset, sizeof(GLNVGfragUniforms)); #else - struct GLNVGfragUniforms* frag = nvg__fragUniformPtr(gl, uniformOffset); + GLNVGfragUniforms* frag = nvg__fragUniformPtr(gl, uniformOffset); float tmp[9]; // Maybe there's a way to get rid of this... glnvg__mat3(tmp, frag->scissorMat); glUniformMatrix3fv(gl->shader.loc[GLNVG_LOC_SCISSORMAT], 1, GL_FALSE, tmp); @@ -869,7 +875,7 @@ static void glnvg__setUniforms(struct GLNVGcontext* gl, int uniformOffset, int i #endif if (image != 0) { - struct GLNVGtexture* tex = glnvg__findTexture(gl, image); + GLNVGtexture* tex = glnvg__findTexture(gl, image); glBindTexture(GL_TEXTURE_2D, tex != NULL ? tex->tex : 0); glnvg__checkError("tex paint tex"); } else { @@ -879,14 +885,14 @@ static void glnvg__setUniforms(struct GLNVGcontext* gl, int uniformOffset, int i static void glnvg__renderViewport(void* uptr, int width, int height) { - struct GLNVGcontext* gl = (struct GLNVGcontext*)uptr; + GLNVGcontext* gl = (GLNVGcontext*)uptr; gl->view[0] = (float)width; gl->view[1] = (float)height; } -static void glnvg__fill(struct GLNVGcontext* gl, struct GLNVGcall* call) +static void glnvg__fill(GLNVGcontext* gl, GLNVGcall* call) { - struct GLNVGpath* paths = &gl->paths[call->pathOffset]; + GLNVGpath* paths = &gl->paths[call->pathOffset]; int i, npaths = call->pathCount; // Draw shapes @@ -928,9 +934,9 @@ static void glnvg__fill(struct GLNVGcontext* gl, struct GLNVGcall* call) glDisable(GL_STENCIL_TEST); } -static void glnvg__convexFill(struct GLNVGcontext* gl, struct GLNVGcall* call) +static void glnvg__convexFill(GLNVGcontext* gl, GLNVGcall* call) { - struct GLNVGpath* paths = &gl->paths[call->pathOffset]; + GLNVGpath* paths = &gl->paths[call->pathOffset]; int i, npaths = call->pathCount; glnvg__setUniforms(gl, call->uniformOffset, call->image); @@ -945,9 +951,9 @@ static void glnvg__convexFill(struct GLNVGcontext* gl, struct GLNVGcall* call) } } -static void glnvg__stroke(struct GLNVGcontext* gl, struct GLNVGcall* call) +static void glnvg__stroke(GLNVGcontext* gl, GLNVGcall* call) { - struct GLNVGpath* paths = &gl->paths[call->pathOffset]; + GLNVGpath* paths = &gl->paths[call->pathOffset]; int npaths = call->pathCount, i; if (gl->flags & NVG_STENCIL_STROKES) { @@ -992,7 +998,7 @@ static void glnvg__stroke(struct GLNVGcontext* gl, struct GLNVGcall* call) } } -static void glnvg__triangles(struct GLNVGcontext* gl, struct GLNVGcall* call) +static void glnvg__triangles(GLNVGcontext* gl, GLNVGcall* call) { glnvg__setUniforms(gl, call->uniformOffset, call->image); glnvg__checkError("triangles fill"); @@ -1002,7 +1008,7 @@ static void glnvg__triangles(struct GLNVGcontext* gl, struct GLNVGcall* call) static void glnvg__renderFlush(void* uptr) { - struct GLNVGcontext* gl = (struct GLNVGcontext*)uptr; + GLNVGcontext* gl = (GLNVGcontext*)uptr; int i; if (gl->ncalls > 0) { @@ -1034,11 +1040,11 @@ static void glnvg__renderFlush(void* uptr) glBindVertexArray(gl->vertArr); #endif glBindBuffer(GL_ARRAY_BUFFER, gl->vertBuf); - glBufferData(GL_ARRAY_BUFFER, gl->nverts * sizeof(struct NVGvertex), gl->verts, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, gl->nverts * sizeof(NVGvertex), gl->verts, GL_STREAM_DRAW); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(struct NVGvertex), (const GLvoid*)(size_t)0); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(struct NVGvertex), (const GLvoid*)(0 + 2*sizeof(float))); + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(NVGvertex), (const GLvoid*)(size_t)0); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(NVGvertex), (const GLvoid*)(0 + 2*sizeof(float))); // Set view and texture just once per frame. glUniform1i(gl->shader.loc[GLNVG_LOC_TEX], 0); @@ -1049,7 +1055,7 @@ static void glnvg__renderFlush(void* uptr) #endif for (i = 0; i < gl->ncalls; i++) { - struct GLNVGcall* call = &gl->calls[i]; + GLNVGcall* call = &gl->calls[i]; if (call->type == GLNVG_FILL) glnvg__fill(gl, call); else if (call->type == GLNVG_CONVEXFILL) @@ -1076,7 +1082,7 @@ static void glnvg__renderFlush(void* uptr) gl->nuniforms = 0; } -static int glnvg__maxVertCount(const struct NVGpath* paths, int npaths) +static int glnvg__maxVertCount(const NVGpath* paths, int npaths) { int i, count = 0; for (i = 0; i < npaths; i++) { @@ -1086,29 +1092,29 @@ static int glnvg__maxVertCount(const struct NVGpath* paths, int npaths) return count; } -static struct GLNVGcall* glnvg__allocCall(struct GLNVGcontext* gl) +static GLNVGcall* glnvg__allocCall(GLNVGcontext* gl) { - struct GLNVGcall* ret = NULL; + GLNVGcall* ret = NULL; if (gl->ncalls+1 > gl->ccalls) { - struct GLNVGcall* calls; + GLNVGcall* calls; int ccalls = glnvg__maxi(gl->ncalls+1, 128) + gl->ccalls/2; // 1.5x Overallocate - calls = (struct GLNVGcall*)realloc(gl->calls, sizeof(struct GLNVGcall) * ccalls); + calls = (GLNVGcall*)realloc(gl->calls, sizeof(GLNVGcall) * ccalls); if (calls == NULL) return NULL; gl->calls = calls; gl->ccalls = ccalls; } ret = &gl->calls[gl->ncalls++]; - memset(ret, 0, sizeof(struct GLNVGcall)); + memset(ret, 0, sizeof(GLNVGcall)); return ret; } -static int glnvg__allocPaths(struct GLNVGcontext* gl, int n) +static int glnvg__allocPaths(GLNVGcontext* gl, int n) { int ret = 0; if (gl->npaths+n > gl->cpaths) { - struct GLNVGpath* paths; + GLNVGpath* paths; int cpaths = glnvg__maxi(gl->npaths + n, 128) + gl->cpaths/2; // 1.5x Overallocate - paths = (struct GLNVGpath*)realloc(gl->paths, sizeof(struct GLNVGpath) * cpaths); + paths = (GLNVGpath*)realloc(gl->paths, sizeof(GLNVGpath) * cpaths); if (paths == NULL) return -1; gl->paths = paths; gl->cpaths = cpaths; @@ -1118,13 +1124,13 @@ static int glnvg__allocPaths(struct GLNVGcontext* gl, int n) return ret; } -static int glnvg__allocVerts(struct GLNVGcontext* gl, int n) +static int glnvg__allocVerts(GLNVGcontext* gl, int n) { int ret = 0; if (gl->nverts+n > gl->cverts) { - struct NVGvertex* verts; + NVGvertex* verts; int cverts = glnvg__maxi(gl->nverts + n, 4096) + gl->cverts/2; // 1.5x Overallocate - verts = (struct NVGvertex*)realloc(gl->verts, sizeof(struct NVGvertex) * cverts); + verts = (NVGvertex*)realloc(gl->verts, sizeof(NVGvertex) * cverts); if (verts == NULL) return -1; gl->verts = verts; gl->cverts = cverts; @@ -1134,7 +1140,7 @@ static int glnvg__allocVerts(struct GLNVGcontext* gl, int n) return ret; } -static int glnvg__allocFragUniforms(struct GLNVGcontext* gl, int n) +static int glnvg__allocFragUniforms(GLNVGcontext* gl, int n) { int ret = 0, structSize = gl->fragSize; if (gl->nuniforms+n > gl->cuniforms) { @@ -1150,12 +1156,12 @@ static int glnvg__allocFragUniforms(struct GLNVGcontext* gl, int n) return ret; } -static struct GLNVGfragUniforms* nvg__fragUniformPtr(struct GLNVGcontext* gl, int i) +static GLNVGfragUniforms* nvg__fragUniformPtr(GLNVGcontext* gl, int i) { - return (struct GLNVGfragUniforms*)&gl->uniforms[i]; + return (GLNVGfragUniforms*)&gl->uniforms[i]; } -static void glnvg__vset(struct NVGvertex* vtx, float x, float y, float u, float v) +static void glnvg__vset(NVGvertex* vtx, float x, float y, float u, float v) { vtx->x = x; vtx->y = y; @@ -1163,13 +1169,13 @@ static void glnvg__vset(struct NVGvertex* vtx, float x, float y, float u, float vtx->v = v; } -static void glnvg__renderFill(void* uptr, struct NVGpaint* paint, struct NVGscissor* scissor, float fringe, - const float* bounds, const struct NVGpath* paths, int npaths) +static void glnvg__renderFill(void* uptr, NVGpaint* paint, NVGscissor* scissor, float fringe, + const float* bounds, const NVGpath* paths, int npaths) { - struct GLNVGcontext* gl = (struct GLNVGcontext*)uptr; - struct GLNVGcall* call = glnvg__allocCall(gl); - struct NVGvertex* quad; - struct GLNVGfragUniforms* frag; + GLNVGcontext* gl = (GLNVGcontext*)uptr; + GLNVGcall* call = glnvg__allocCall(gl); + NVGvertex* quad; + GLNVGfragUniforms* frag; int i, maxverts, offset; if (call == NULL) return; @@ -1189,19 +1195,19 @@ static void glnvg__renderFill(void* uptr, struct NVGpaint* paint, struct NVGscis if (offset == -1) goto error; for (i = 0; i < npaths; i++) { - struct GLNVGpath* copy = &gl->paths[call->pathOffset + i]; - const struct NVGpath* path = &paths[i]; - memset(copy, 0, sizeof(struct GLNVGpath)); + GLNVGpath* copy = &gl->paths[call->pathOffset + i]; + const NVGpath* path = &paths[i]; + memset(copy, 0, sizeof(GLNVGpath)); if (path->nfill > 0) { copy->fillOffset = offset; copy->fillCount = path->nfill; - memcpy(&gl->verts[offset], path->fill, sizeof(struct NVGvertex) * path->nfill); + memcpy(&gl->verts[offset], path->fill, sizeof(NVGvertex) * path->nfill); offset += path->nfill; } if (path->nstroke > 0) { copy->strokeOffset = offset; copy->strokeCount = path->nstroke; - memcpy(&gl->verts[offset], path->stroke, sizeof(struct NVGvertex) * path->nstroke); + memcpy(&gl->verts[offset], path->stroke, sizeof(NVGvertex) * path->nstroke); offset += path->nstroke; } } @@ -1244,11 +1250,11 @@ error: if (gl->ncalls > 0) gl->ncalls--; } -static void glnvg__renderStroke(void* uptr, struct NVGpaint* paint, struct NVGscissor* scissor, float fringe, - float strokeWidth, const struct NVGpath* paths, int npaths) +static void glnvg__renderStroke(void* uptr, NVGpaint* paint, NVGscissor* scissor, float fringe, + float strokeWidth, const NVGpath* paths, int npaths) { - struct GLNVGcontext* gl = (struct GLNVGcontext*)uptr; - struct GLNVGcall* call = glnvg__allocCall(gl); + GLNVGcontext* gl = (GLNVGcontext*)uptr; + GLNVGcall* call = glnvg__allocCall(gl); int i, maxverts, offset; if (call == NULL) return; @@ -1265,13 +1271,13 @@ static void glnvg__renderStroke(void* uptr, struct NVGpaint* paint, struct NVGsc if (offset == -1) goto error; for (i = 0; i < npaths; i++) { - struct GLNVGpath* copy = &gl->paths[call->pathOffset + i]; - const struct NVGpath* path = &paths[i]; - memset(copy, 0, sizeof(struct GLNVGpath)); + GLNVGpath* copy = &gl->paths[call->pathOffset + i]; + const NVGpath* path = &paths[i]; + memset(copy, 0, sizeof(GLNVGpath)); if (path->nstroke) { copy->strokeOffset = offset; copy->strokeCount = path->nstroke; - memcpy(&gl->verts[offset], path->stroke, sizeof(struct NVGvertex) * path->nstroke); + memcpy(&gl->verts[offset], path->stroke, sizeof(NVGvertex) * path->nstroke); offset += path->nstroke; } } @@ -1299,12 +1305,12 @@ error: if (gl->ncalls > 0) gl->ncalls--; } -static void glnvg__renderTriangles(void* uptr, struct NVGpaint* paint, struct NVGscissor* scissor, - const struct NVGvertex* verts, int nverts) +static void glnvg__renderTriangles(void* uptr, NVGpaint* paint, NVGscissor* scissor, + const NVGvertex* verts, int nverts) { - struct GLNVGcontext* gl = (struct GLNVGcontext*)uptr; - struct GLNVGcall* call = glnvg__allocCall(gl); - struct GLNVGfragUniforms* frag; + GLNVGcontext* gl = (GLNVGcontext*)uptr; + GLNVGcall* call = glnvg__allocCall(gl); + GLNVGfragUniforms* frag; if (call == NULL) return; @@ -1316,7 +1322,7 @@ static void glnvg__renderTriangles(void* uptr, struct NVGpaint* paint, struct NV if (call->triangleOffset == -1) goto error; call->triangleCount = nverts; - memcpy(&gl->verts[call->triangleOffset], verts, sizeof(struct NVGvertex) * nverts); + memcpy(&gl->verts[call->triangleOffset], verts, sizeof(NVGvertex) * nverts); // Fill shader call->uniformOffset = glnvg__allocFragUniforms(gl, 1); @@ -1335,7 +1341,7 @@ error: static void glnvg__renderDelete(void* uptr) { - struct GLNVGcontext* gl = (struct GLNVGcontext*)uptr; + GLNVGcontext* gl = (GLNVGcontext*)uptr; int i; if (gl == NULL) return; @@ -1368,20 +1374,20 @@ static void glnvg__renderDelete(void* uptr) #if defined NANOVG_GL2 -struct NVGcontext* nvgCreateGL2(int flags) +NVGcontext* nvgCreateGL2(int flags) #elif defined NANOVG_GL3 -struct NVGcontext* nvgCreateGL3(int flags) +NVGcontext* nvgCreateGL3(int flags) #elif defined NANOVG_GLES2 -struct NVGcontext* nvgCreateGLES2(int flags) +NVGcontext* nvgCreateGLES2(int flags) #elif defined NANOVG_GLES3 -struct NVGcontext* nvgCreateGLES3(int flags) +NVGcontext* nvgCreateGLES3(int flags) #endif { - struct NVGparams params; - struct NVGcontext* ctx = NULL; - struct GLNVGcontext* gl = (struct GLNVGcontext*)malloc(sizeof(struct GLNVGcontext)); + NVGparams params; + NVGcontext* ctx = NULL; + GLNVGcontext* gl = (GLNVGcontext*)malloc(sizeof(GLNVGcontext)); if (gl == NULL) goto error; - memset(gl, 0, sizeof(struct GLNVGcontext)); + memset(gl, 0, sizeof(GLNVGcontext)); memset(¶ms, 0, sizeof(params)); params.renderCreate = glnvg__renderCreate; @@ -1412,22 +1418,22 @@ error: } #if NANOVG_GL2 -void nvgDeleteGL2(struct NVGcontext* ctx) +void nvgDeleteGL2(NVGcontext* ctx) #elif NANOVG_GL3 -void nvgDeleteGL3(struct NVGcontext* ctx) +void nvgDeleteGL3(NVGcontext* ctx) #elif NANOVG_GLES2 -void nvgDeleteGLES2(struct NVGcontext* ctx) +void nvgDeleteGLES2(NVGcontext* ctx) #elif NANOVG_GLES3 -void nvgDeleteGLES3(struct NVGcontext* ctx) +void nvgDeleteGLES3(NVGcontext* ctx) #endif { nvgDeleteInternal(ctx); } -int nvglCreateImageFromHandle(struct NVGcontext* ctx, GLuint textureId, int w, int h, int flags) +int nvglCreateImageFromHandle(NVGcontext* ctx, GLuint textureId, int w, int h, int flags) { - struct GLNVGcontext* gl = (struct GLNVGcontext*)nvgInternalParams(ctx)->userPtr; - struct GLNVGtexture* tex = glnvg__allocTexture(gl); + GLNVGcontext* gl = (GLNVGcontext*)nvgInternalParams(ctx)->userPtr; + GLNVGtexture* tex = glnvg__allocTexture(gl); if (tex == NULL) return 0; @@ -1440,17 +1446,17 @@ int nvglCreateImageFromHandle(struct NVGcontext* ctx, GLuint textureId, int w, i return tex->id; } -GLuint nvglImageHandle(struct NVGcontext* ctx, int image) +GLuint nvglImageHandle(NVGcontext* ctx, int image) { - struct GLNVGcontext* gl = (struct GLNVGcontext*)nvgInternalParams(ctx)->userPtr; - struct GLNVGtexture* tex = glnvg__findTexture(gl, image); + GLNVGcontext* gl = (GLNVGcontext*)nvgInternalParams(ctx)->userPtr; + GLNVGtexture* tex = glnvg__findTexture(gl, image); return tex->tex; } -void nvglImageFlags(struct NVGcontext* ctx, int image, int flags) +void nvglImageFlags(NVGcontext* ctx, int image, int flags) { - struct GLNVGcontext* gl = (struct GLNVGcontext*)nvgInternalParams(ctx)->userPtr; - struct GLNVGtexture* tex = glnvg__findTexture(gl, image); + GLNVGcontext* gl = (GLNVGcontext*)nvgInternalParams(ctx)->userPtr; + GLNVGtexture* tex = glnvg__findTexture(gl, image); tex->flags = flags; } diff --git a/src/nanovg_gl_utils.h b/src/nanovg_gl_utils.h index 34a2743..5eb28c8 100644 --- a/src/nanovg_gl_utils.h +++ b/src/nanovg_gl_utils.h @@ -19,16 +19,17 @@ #define NANOVG_GL_UTILS_H struct NVGLUframebuffer { - struct NVGcontext* ctx; + NVGcontext* ctx; GLuint fbo; GLuint rbo; GLuint texture; int image; }; +typedef struct NVGLUframebuffer NVGLUframebuffer; // Helper function to create GL frame buffer to render to. -struct NVGLUframebuffer* nvgluCreateFramebuffer(struct NVGcontext* ctx, int w, int h); -void nvgluDeleteFramebuffer(struct NVGcontext* ctx, struct NVGLUframebuffer* fb); +NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int w, int h); +void nvgluDeleteFramebuffer(NVGcontext* ctx, NVGLUframebuffer* fb); #endif // NANOVG_GL_UTILS_H @@ -45,13 +46,13 @@ void nvgluDeleteFramebuffer(struct NVGcontext* ctx, struct NVGLUframebuffer* fb) # endif #endif -struct NVGLUframebuffer* nvgluCreateFramebuffer(struct NVGcontext* ctx, int w, int h) +NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int w, int h) { #ifdef NANOVG_FBO_VALID - struct NVGLUframebuffer* fb = NULL; - fb = (struct NVGLUframebuffer*)malloc(sizeof(struct NVGLUframebuffer)); + NVGLUframebuffer* fb = NULL; + fb = (NVGLUframebuffer*)malloc(sizeof(NVGLUframebuffer)); if (fb == NULL) goto error; - memset(fb, 0, sizeof(struct NVGLUframebuffer)); + memset(fb, 0, sizeof(NVGLUframebuffer)); fb->image = nvgCreateImageRGBA(ctx, w, h, 0, NULL); fb->texture = nvglImageHandle(ctx, fb->image); @@ -84,7 +85,7 @@ error: #endif } -void nvgluBindFramebuffer(struct NVGLUframebuffer* fb) +void nvgluBindFramebuffer(NVGLUframebuffer* fb) { #ifdef NANOVG_FBO_VALID glBindFramebuffer(GL_FRAMEBUFFER, fb != NULL ? fb->fbo : 0); @@ -93,7 +94,7 @@ void nvgluBindFramebuffer(struct NVGLUframebuffer* fb) #endif } -void nvgluDeleteFramebuffer(struct NVGcontext* ctx, struct NVGLUframebuffer* fb) +void nvgluDeleteFramebuffer(NVGcontext* ctx, NVGLUframebuffer* fb) { #ifdef NANOVG_FBO_VALID if (fb == NULL) return;