22#if defined IGRAPHICS_GL
23 #define NANOVG_FBO_VALID 1
24 #include "nanovg_gl_utils.h"
25#elif defined IGRAPHICS_METAL
26 #include "nanovg_mtl.h"
28 #error you must define either IGRAPHICS_GL2, IGRAPHICS_GLES2 etc or IGRAPHICS_METAL when using IGRAPHICS_NANOVG
31#if defined IGRAPHICS_GL2
33 #define nvgCreateContext(flags) nvgCreateGL2(flags)
34 #define nvgDeleteContext(context) nvgDeleteGL2(context)
35#elif defined IGRAPHICS_GLES2
36 #define NANOVG_GLES2 1
37 #define nvgCreateContext(flags) nvgCreateGLES2(flags)
38 #define nvgDeleteContext(context) nvgDeleteGLES2(context)
39#elif defined IGRAPHICS_GL3
41 #define nvgCreateContext(flags) nvgCreateGL3(flags)
42 #define nvgDeleteContext(context) nvgDeleteGL3(context)
43#elif defined IGRAPHICS_GLES3
44 #define NANOVG_GLES3 1
45 #define nvgCreateContext(flags) nvgCreateGLES3(flags)
46 #define nvgDeleteContext(context) nvgDeleteGLES3(context)
47#elif defined IGRAPHICS_METAL
48 #define nvgCreateContext(layer, flags) nvgCreateMTL(layer, flags)
49 #define nvgDeleteContext(context) nvgDeleteMTL(context)
50 #define nvgBindFramebuffer(fb) mnvgBindFramebuffer(fb)
51 #define nvgCreateFramebuffer(ctx, w, h, flags) mnvgCreateFramebuffer(ctx, w, h, flags)
52 #define nvgDeleteFramebuffer(fb) mnvgDeleteFramebuffer(fb)
55#if defined IGRAPHICS_GL
56 #define nvgBindFramebuffer(fb) nvgluBindFramebuffer(fb)
57 #define nvgCreateFramebuffer(ctx, w, h, flags) nvgluCreateFramebuffer(ctx, w, h, flags)
58 #define nvgDeleteFramebuffer(fb) nvgluDeleteFramebuffer(fb)
59 using NVGframebuffer = NVGLUframebuffer;
60#elif defined IGRAPHICS_METAL
61 using NVGframebuffer = MNVGframebuffer;
65BEGIN_IGRAPHICS_NAMESPACE
68NVGcolor NanoVGColor(
const IColor& color,
const IBlend* pBlend = 0);
71void NanoVGRect(NVGcontext* pContext,
const IRECT& r);
74void NanoVGSetBlendMode(NVGcontext* pContext,
const IBlend* pBlend);
77NVGpaint NanoVGPaint(NVGcontext* pContext,
const IPattern& pattern,
const IBlend* pBlend = 0);
100 void DrawDottedLine(
const IColor& color,
float x1,
float y1,
float x2,
float y2,
const IBlend* pBlend,
float thickness,
float dashLen)
override;
103 void DrawFastDropShadow(
const IRECT& innerBounds,
const IRECT& outerBounds,
float xyDrop = 5.f,
float roundness = 0.f,
float blur = 10.f,
IBlend* pBlend =
nullptr)
override;
109 void PathArc(
float cx,
float cy,
float r,
float a1,
float a2, EWinding winding)
override;
112 void PathCubicBezierTo(
float c1x,
float c1y,
float c2x,
float c2y,
float x2,
float y2)
override;
121 IBitmap LoadBitmap(
const char* name,
int nStates,
bool framesAreHorizontal,
int targetScale)
override;
126 void DeleteFBO(NVGframebuffer* pBuffer);
129 APIBitmap*
LoadAPIBitmap(
const char* fileNameOrResID,
int scale, EResourceLocation location,
const char* ext)
override;
133 bool LoadAPIFont(
const char* fontID,
const PlatformFontPtr& font)
override;
139#if defined(IGRAPHICS_GL)
153 void PrepareAndMeasureText(
const IText& text,
const char* str,
IRECT& r,
double& x,
double & y)
const;
154 void PathTransformSetMatrix(
const IMatrix& m)
override;
155 void SetClipRegion(
const IRECT& r)
override;
156 void UpdateLayer()
override;
157 void ClearFBOStack();
159 bool mInDraw =
false;
161 std::stack<NVGframebuffer*> mFBOStack;
162 StaticStorage<APIBitmap> mBitmapCache;
163 NVGcontext* mVG =
nullptr;
164 NVGframebuffer* mMainFrameBuffer =
nullptr;
168END_IGRAPHICS_NAMESPACE
A base class interface for a bitmap abstraction around the different drawing back end bitmap represen...
User-facing bitmap abstraction that you use to manage bitmap data, independant of draw class/platform...
An editor delegate base class that uses IGraphics for the UI.
The lowest level base class of an IGraphics context.
IGraphics draw class using NanoVG
const char * GetDrawingAPIStr() override
void ApplyShadowMask(ILayerPtr &layer, RawBitmapData &mask, const IShadow &shadow) override
Implemented by a graphics backend to apply a calculated shadow mask to a layer, according to the shad...
void DrawResize() override
void PathClear() override
Clear the stack of path drawing commands.
IBitmap LoadBitmap(const char *name, int nStates, bool framesAreHorizontal, int targetScale) override
Load a bitmap image from disk or from windows resource.
void PathFill(const IPattern &pattern, const IFillOptions &options, const IBlend *pBlend) override
Fill the current current path.
void GetLayerBitmapData(const ILayerPtr &layer, RawBitmapData &data) override
Get the contents of a layer as Raw RGBA bitmap data NOTE: you should only call this within IControl::...
void DrawDottedRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend, float thickness, float dashLen) override
Draw a dotted rectangle to the graphics context.
void PathSetWinding(bool clockwise) override
NanoVG only.
APIBitmap * LoadAPIBitmap(const char *fileNameOrResID, int scale, EResourceLocation location, const char *ext) override
Drawing API method to load a bitmap, called internally.
void ReleaseBitmap(const IBitmap &bitmap) override
Releases an IBitmap from the cache/static storage.
void PathStroke(const IPattern &pattern, float thickness, const IStrokeOptions &options, const IBlend *pBlend) override
Stroke the current current path.
void PathArc(float cx, float cy, float r, float a1, float a2, EWinding winding) override
Add an arc to the current path.
void PathLineTo(float x, float y) override
Add a line to the current path from the current point to the specified location.
void OnViewDestroyed() override
Called after a platform view is destroyed, so that drawing classes can e.g.
void DrawMultiLineText(const IText &text, const char *str, const IRECT &bounds, const IBlend *pBlend) override
Draw some multi-line text to the graphics context in a specific rectangle (NanoVG only)
void DrawDottedLine(const IColor &color, float x1, float y1, float x2, float y2, const IBlend *pBlend, float thickness, float dashLen) override
Draw a dotted line to the graphics context.
void * GetDrawContext() override
Gets a void pointer to underlying drawing context, for the IGraphics backend See draw class implement...
void PathCubicBezierTo(float c1x, float c1y, float c2x, float c2y, float x2, float y2) override
Add a cubic bezier to the current path from the current point to the specified location.
IColor GetPoint(int x, int y) override
Get the color at an X, Y location in the graphics context.
bool LoadAPIFont(const char *fontID, const PlatformFontPtr &font) override
Drawing API method to load a font from a PlatformFontPtr, called internally.
void PathClose() override
Close the path that is being specified.
void DoDrawText(const IText &text, const char *str, const IRECT &bounds, const IBlend *pBlend) override
void DrawFastDropShadow(const IRECT &innerBounds, const IRECT &outerBounds, float xyDrop=5.f, float roundness=0.f, float blur=10.f, IBlend *pBlend=nullptr) override
NanoVG only.
void PathMoveTo(float x, float y) override
Move the current point in the current path.
void OnViewInitialized(void *pContext) override
Called after platform view initialization, so that drawing classes can e.g.
void BeginFrame() override
Called at the beginning of drawing.
void EndFrame() override
Called by some drawing API classes to finally blit the draw bitmap onto the screen or perform other c...
int AlphaChannel() const override
APIBitmap * CreateAPIBitmap(int width, int height, float scale, double drawScale, bool cacheable=false) override
Creates a new API bitmap, either in memory or as a GPU texture.
void RetainBitmap(const IBitmap &bitmap, const char *cacheName) override
Adds an IBitmap to the cache/static storage.
void PathQuadraticBezierTo(float cx, float cy, float x2, float y2) override
Add a quadratic bezier to the current path from the current point to the specified location.
bool BitmapExtSupported(const char *ext) override
Checks a file extension and reports whether this drawing API supports loading that extension.
float DoMeasureText(const IText &text, const char *str, IRECT &bounds) const override
bool FlippedBitmap() const override
void DrawBitmap(const IBitmap &bitmap, const IRECT &dest, int srcX, int srcY, const IBlend *pBlend) override
Draw a bitmap (raster) image to the graphics context.
std::unique_ptr< ILayer > ILayerPtr
ILayerPtr is a managed pointer for transferring the ownership of layers.
Used to manage stroke behaviour for path based drawing back ends.
Used to manage composite/blend operations, independent of draw class/platform.
Used to manage color data, independent of draw class/platform.
Used to manage fill behaviour.
Used to store transformation matrices.
Used to store pattern information for gradients.
Used to manage a rectangular area, independent of draw class/platform.
Used to specify properties of a drop-shadow to a layer.
IText is used to manage font and text/text entry style for a piece of text on the UI,...