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;
65 BEGIN_IGRAPHICS_NAMESPACE
68 NVGcolor NanoVGColor(
const IColor& color,
const IBlend* pBlend = 0);
71 void NanoVGRect(NVGcontext* pContext,
const IRECT& r);
74 void NanoVGSetBlendMode(NVGcontext* pContext,
const IBlend* pBlend);
77 NVGpaint 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;
107 void PathArc(
float cx,
float cy,
float r,
float a1,
float a2, EWinding winding)
override;
110 void PathCubicBezierTo(
float c1x,
float c1y,
float c2x,
float c2y,
float x2,
float y2)
override;
119 IBitmap LoadBitmap(
const char* name,
int nStates,
bool framesAreHorizontal,
int targetScale)
override;
124 void DeleteFBO(NVGframebuffer* pBuffer);
127 APIBitmap*
LoadAPIBitmap(
const char* fileNameOrResID,
int scale, EResourceLocation location,
const char* ext)
override;
131 bool LoadAPIFont(
const char* fontID,
const PlatformFontPtr& font)
override;
137 #if defined(IGRAPHICS_GL) 151 void PrepareAndMeasureText(
const IText& text,
const char* str,
IRECT& r,
double& x,
double & y)
const;
152 void PathTransformSetMatrix(
const IMatrix& m)
override;
153 void SetClipRegion(
const IRECT& r)
override;
154 void UpdateLayer()
override;
155 void ClearFBOStack();
157 bool mInDraw =
false;
159 std::stack<NVGframebuffer*> mFBOStack;
160 StaticStorage<APIBitmap> mBitmapCache;
161 NVGcontext* mVG =
nullptr;
162 NVGframebuffer* mMainFrameBuffer =
nullptr;
166 END_IGRAPHICS_NAMESPACE
void DoDrawText(const IText &text, const char *str, const IRECT &bounds, const IBlend *pBlend) override
IColor GetPoint(int x, int y) override
Get the color at an X, Y location in the graphics context.
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.
Used to manage a rectangular area, independent of draw class/platform.
void RetainBitmap(const IBitmap &bitmap, const char *cacheName) override
Adds an IBitmap to the cache/static storage.
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.
void PathFill(const IPattern &pattern, const IFillOptions &options, const IBlend *pBlend) override
Fill the current current path.
void DrawResize() override
Used to manage composite/blend operations, independent of draw class/platform.
User-facing bitmap abstraction that you use to manage bitmap data, independant of draw class/platform...
Used to manage fill behaviour for path based drawing back ends.
const char * GetDrawingAPIStr() override
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 EndFrame() override
Called by some drawing API classes to finally blit the draw bitmap onto the screen or perform other c...
Used to manage color data, independent of draw class/platform.
Used to manage stroke behaviour for path based drawing back ends.
int AlphaChannel() const override
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...
void PathArc(float cx, float cy, float r, float a1, float a2, EWinding winding) override
Add an arc to the current path.
float DoMeasureText(const IText &text, const char *str, IRECT &bounds) const override
void PathLineTo(float x, float y) override
Add a line to the current path from the current point to the specified location.
void * GetDrawContext() override
Gets a void pointer to underlying drawing context, for the IGraphics backend See draw class implement...
The lowest level base class of an IGraphics context.
An editor delegate base class for a SOMETHING that uses IGraphics for it's UI.
void OnViewInitialized(void *pContext) override
Called after platform view initialization, so that drawing classes can e.g.
IText is used to manage font and text/text entry style for a piece of text on the UI...
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...
APIBitmap * CreateAPIBitmap(int width, int height, int scale, double drawScale, bool cacheable=false) override
Creates a new API bitmap, either in memory or as a GPU texture.
The lowest level base class of an IGraphics context.
Used to specify properties of a drop-shadow to a layer.
void PathClose() override
Close the path that is being specified.
void OnViewDestroyed() override
Called after a platform view is destroyed, so that drawing classes can e.g.
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.
IBitmap LoadBitmap(const char *name, int nStates, bool framesAreHorizontal, int targetScale) override
Load a bitmap image from disk or from windows resource.
A base class interface for a bitmap abstraction around the different drawing back end bitmap represen...
void PathSetWinding(bool clockwise) override
NanoVG only.
void GetLayerBitmapData(const ILayerPtr &layer, RawBitmapData &data) override
Get the contents of a layers pixels as bitmap data.
APIBitmap * LoadAPIBitmap(const char *fileNameOrResID, int scale, EResourceLocation location, const char *ext) override
Drawing API method to load a bitmap, called internally.
void PathStroke(const IPattern &pattern, float thickness, const IStrokeOptions &options, const IBlend *pBlend) override
Stroke the current current path.
void PathMoveTo(float x, float y) override
Move the current point in the current path.
bool FlippedBitmap() const 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.
IGraphics draw class using NanoVG.
bool BitmapExtSupported(const char *ext) override
Checks a file extension and reports whether this drawing API supports loading that extension...
void PathClear() override
Clear the stack of path drawing commands.
std::unique_ptr< ILayer > ILayerPtr
ILayerPtr is a managed pointer for transferring the ownership of layers.
Used to store pattern information for gradients.
bool LoadAPIFont(const char *fontID, const PlatformFontPtr &font) override
Drawing API method to load a font from a PlatformFontPtr, called internally.
Used to store transformation matrices.
void BeginFrame() override
Called at the beginning of drawing.
void ReleaseBitmap(const IBitmap &bitmap) override
Releases an IBitmap from the cache/static storage.