Refactor of proc names
This commit is contained in:
parent
ee2f3065b8
commit
734732fbbd
7 changed files with 132 additions and 155 deletions
|
|
@ -31,8 +31,8 @@ proc drawWindow*(title: string, x, y, w, h: float) =
|
|||
withState:
|
||||
nanovg.beginPath()
|
||||
nanovg.pathRoundedRect(x, y, w, h, cornerRadius)
|
||||
#nanovg.setFillColor(RGBA(255,255,255,192))
|
||||
nanovg.setFillColor(RGBA(28,30,34,192))
|
||||
#nanovg.setFillColor(rgba(255,255,255,192))
|
||||
nanovg.setFillColor(rgba(28,30,34,192))
|
||||
nanovg.pathFill()
|
||||
|
||||
nanovg.setFontSize(30.0)
|
||||
|
|
@ -40,11 +40,11 @@ proc drawWindow*(title: string, x, y, w, h: float) =
|
|||
nanovg.textAlign("center middle")
|
||||
|
||||
nanovg.setFontBlur(2)
|
||||
nanovg.setFillColor(RGBA(0,0,0,128))
|
||||
nanovg.setFillColor(rgba(0,0,0,128))
|
||||
nanovg.text(title, x+w/2, y+16+1)
|
||||
|
||||
nanovg.setFontBlur(0)
|
||||
nanovg.setFillColor(RGBA(220,220,220,160))
|
||||
nanovg.setFillColor(rgba(220,220,220,160))
|
||||
nanovg.text(title, x+w/2,y+16)
|
||||
|
||||
proc isBlack*(color: Color): bool =
|
||||
|
|
@ -96,13 +96,13 @@ proc cpToUtf8*(code: int): string =
|
|||
proc drawButton*(text: string, x, y, width, height: float) =
|
||||
let bg = linearGradient(
|
||||
x, y, x, y+height,
|
||||
RGBA(255, 255, 255, 16),
|
||||
RGBA(100, 100, 100, 16)
|
||||
rgba(255, 255, 255, 16),
|
||||
rgba(100, 100, 100, 16)
|
||||
)
|
||||
|
||||
let color = RGBA(29, 100, 210, 255)
|
||||
let shadowColor = RGBA(0, 0, 0, 90)
|
||||
let highlightColor = RGBA(255, 255, 255, 100)
|
||||
let color = rgba(29, 100, 210, 255)
|
||||
let shadowColor = rgba(0, 0, 0, 90)
|
||||
let highlightColor = rgba(255, 255, 255, 100)
|
||||
let radius = 3.0
|
||||
let lightWidth = 0.5
|
||||
let shadowOffset = 3.0
|
||||
|
|
@ -142,8 +142,8 @@ proc drawButton*(preicon: string, text: string, x, y, w, h: float, color: Color)
|
|||
|
||||
bg = nanovg.linearGradient(
|
||||
x,y,x,y+h,
|
||||
RGBA(255,255,255, if isBlack(color): 16 else:32),
|
||||
RGBA(0,0,0, if isBlack(color): 16 else:32)
|
||||
rgba(255,255,255, if isBlack(color): 16 else:32),
|
||||
rgba(0,0,0, if isBlack(color): 16 else:32)
|
||||
)
|
||||
|
||||
nanovg.beginPath()
|
||||
|
|
@ -158,7 +158,7 @@ proc drawButton*(preicon: string, text: string, x, y, w, h: float, color: Color)
|
|||
|
||||
nanovg.beginPath()
|
||||
nanovg.pathRoundedRect(x+0.5, y+0.5, w-1, h-1, cornerRadius-0.5)
|
||||
nanovg.setStrokeColor(RGBA(0,0,0,48))
|
||||
nanovg.setStrokeColor(rgba(0,0,0,48))
|
||||
nanovg.pathStroke()
|
||||
|
||||
nanovg.setFontSize(20.0)
|
||||
|
|
@ -174,16 +174,16 @@ proc drawButton*(preicon: string, text: string, x, y, w, h: float, color: Color)
|
|||
|
||||
nanovg.setFontSize(h*0.5)
|
||||
nanovg.setFont("fa")
|
||||
nanovg.setFillColor(RGBA(255,255,255,96))
|
||||
nanovg.setFillColor(rgba(255,255,255,96))
|
||||
nanovg.textAlign("left middle")
|
||||
nanovg.text(preicon, x+w*0.5-tw*0.5-iw*0.75, y+h*0.5)
|
||||
|
||||
nanovg.setFontSize(20.0)
|
||||
nanovg.setFont("sans-bold")
|
||||
nanovg.textAlign("left middle")
|
||||
nanovg.setFillColor(RGBA(0,0,0,160))
|
||||
nanovg.setFillColor(rgba(0,0,0,160))
|
||||
nanovg.text(text, x+w*0.5-tw*0.5+iw*0.25, y+h*0.5-1)
|
||||
nanovg.setFillColor(RGBA(255,255,255,160))
|
||||
nanovg.setFillColor(rgba(255,255,255,160))
|
||||
nanovg.text(text, x+w*0.5-tw*0.5+iw*0.25, y+h*0.5)
|
||||
|
||||
proc glewInit*() {.header:"<GL/glew.h>".}
|
||||
|
|
@ -47,8 +47,8 @@ proc main =
|
|||
let x = glyphPositions("Some仮名thing is up", 0, 0)
|
||||
drawWindow("Title", 50, 50, 300, 400)
|
||||
drawLabel("Hello!", 10, 10, 280, 20)
|
||||
drawButton(ICON_TRASH, "Delete", 100, 200, 160, 28, RGBA(128, 16, 8, 255))
|
||||
drawButton(ICON_TRASH, "Deleter", 100, 250, 160, 28, RGBA(12, 130, 80, 255))
|
||||
drawButton(ICON_TRASH, "Delete", 100, 200, 160, 28, rgba(128, 16, 8, 255))
|
||||
drawButton(ICON_TRASH, "Deleter", 100, 250, 160, 28, rgba(12, 130, 80, 255))
|
||||
drawButton("Testing", 100, 300, 160, 28)
|
||||
|
||||
fps.render(5, 5)
|
||||
|
|
|
|||
|
|
@ -90,8 +90,8 @@ proc main() =
|
|||
let x = glyphPositions("Some仮名thing is up", 0, 0)
|
||||
drawWindow("Title", 50, 50, 300, 400)
|
||||
drawLabel("Hello!", 10, 10, 280, 20)
|
||||
drawButton(ICON_TRASH, "Delete", 100, 200, 160, 28, RGBA(128, 16, 8, 255))
|
||||
drawButton(ICON_TRASH, "Deleter", 100, 250, 160, 28, RGBA(12, 130, 80, 255))
|
||||
drawButton(ICON_TRASH, "Delete", 100, 200, 160, 28, rgba(128, 16, 8, 255))
|
||||
drawButton(ICON_TRASH, "Deleter", 100, 250, 160, 28, rgba(12, 130, 80, 255))
|
||||
drawButton("Testing", 100, 300, 160, 28)
|
||||
|
||||
fps.render(5, 5)
|
||||
|
|
|
|||
|
|
@ -123,13 +123,11 @@ proc main() =
|
|||
gpu.flushBlitBuffer()
|
||||
|
||||
withFrame(window):
|
||||
let x = glyphPositions("Some仮名thing is up", 0, 0, 10)
|
||||
echo x
|
||||
text("Some仮名thing is up", 100, 100, 100)
|
||||
drawWindow("Title", 50, 50, 300, 400)
|
||||
drawLabel("Hello!", 10, 10, 500, 20)
|
||||
drawButton(ICON_TRASH, "Delete", 100, 200, 160, 28, RGBA(128, 16, 8, 255))
|
||||
drawButton(ICON_TRASH, "Deleter", 100, 250, 160, 28, RGBA(12, 130, 80, 255))
|
||||
drawButton(ICON_TRASH, "Delete", 100, 200, 160, 28, rgba(128, 16, 8, 255))
|
||||
drawButton(ICON_TRASH, "Deleter", 100, 250, 160, 28, rgba(12, 130, 80, 255))
|
||||
drawButton("Testing", 100, 300, 160, 28)
|
||||
|
||||
gpu.resetRendererState()
|
||||
|
|
|
|||
29
nim-gdb.bash
29
nim-gdb.bash
|
|
@ -1,29 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Exit if anything fails
|
||||
set -e
|
||||
|
||||
which nim > /dev/null || (echo "nim not in PATH"; exit 1)
|
||||
which gdb > /dev/null || (echo "gdb not in PATH"; exit 1)
|
||||
which readlink > /dev/null || \
|
||||
which greadline > /dev/null || \
|
||||
([[ "$OSTYPE" != "darwin"* ]] && (echo "readlink not in PATH. Please install coreutils from homebrew."; exit 1)) || \
|
||||
(echo "readlink not in PATH."; exit 1)
|
||||
|
||||
nreadlink () {
|
||||
(which greadlink > /dev/null && greadlink "$@") || \
|
||||
(which readlink > /dev/null && readlink "$@") || \
|
||||
echo "Readlink could not be found"
|
||||
}
|
||||
|
||||
# Find out where the pretty printer Python module is
|
||||
NIM_SYSROOT=$(dirname $(dirname $(nreadlink -e $(which nim))))
|
||||
GDB_PYTHON_MODULE_PATH="$NIM_SYSROOT/tools/nim-gdb.py"
|
||||
|
||||
# Run GDB with the additional arguments that load the pretty printers
|
||||
# Set the environment variable `NIM_GDB` to overwrite the call to a
|
||||
# different/specific command (defaults to `gdb`).
|
||||
NIM_GDB="${NIM_GDB:-gdb}"
|
||||
# exec replaces the new process of bash with gdb. It is always good to
|
||||
# have fewer processes.
|
||||
exec "${NIM_GDB}" -eval-command="source $GDB_PYTHON_MODULE_PATH" "$@"
|
||||
1
nim-gdb.bash
Symbolic link
1
nim-gdb.bash
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
nim-gdb
|
||||
192
src/nanovg.nim
192
src/nanovg.nim
|
|
@ -8,15 +8,15 @@ import nanovg/wrapper
|
|||
converter intToCuchar*(source: uint8 | int): cuchar =
|
||||
return source.cuchar
|
||||
|
||||
export HSL
|
||||
export HSLA
|
||||
export RGBA
|
||||
export RGBAf
|
||||
export RGB
|
||||
export RGBf
|
||||
export LerpRGBA
|
||||
export TransRGBA
|
||||
export TransRGBAf
|
||||
export hsl
|
||||
export hsla
|
||||
export rgba
|
||||
export rgbaf
|
||||
export rgb
|
||||
export rgbf
|
||||
export lerpRGBA
|
||||
export transRGBA
|
||||
export transRGBAf
|
||||
|
||||
#{.experimental: "dynamicBindSym".}
|
||||
|
||||
|
|
@ -150,7 +150,7 @@ proc createContext(antialias = true, stencilStrokes = true, debugChecks = false)
|
|||
if debugChecks:
|
||||
flags = flags or NVG_DEBUG.cint
|
||||
|
||||
result = CreateGL3(flags)
|
||||
result = createGL3(flags)
|
||||
|
||||
if result.isNil:
|
||||
raise newException(ContextInitError, "Could not initialize graphics context")
|
||||
|
|
@ -162,44 +162,44 @@ proc init*() =
|
|||
|
||||
proc loadFont*(path, name: string): Font {.discardable.} =
|
||||
## Load the font from `path` and give it a `name` that can be used to reference it.
|
||||
result = context.CreateFont(name, path)
|
||||
result = context.createFont(name, path)
|
||||
|
||||
if result == -1:
|
||||
raise newException(FontLoadError, fmt"Could not load font {name}.")
|
||||
|
||||
proc loadFontMem*(data: openArray[uint8], name: string, freeDataAutomatically = true): Font {.discardable.} =
|
||||
## Load the font from `path` and give it a `name` that can be used to reference it.
|
||||
result = context.CreateFontMem(name, cast[ptr cuchar](data[0].unsafeAddr), data.len.cint, freeDataAutomatically.cint)
|
||||
result = context.createFontMem(name, cast[ptr cuchar](data[0].unsafeAddr), data.len.cint, freeDataAutomatically.cint)
|
||||
|
||||
if result == -1:
|
||||
raise newException(FontLoadError, fmt"Could not load font {name}.")
|
||||
|
||||
proc findFont*(name: string): Font =
|
||||
return context.FindFont(name)
|
||||
return context.findFont(name)
|
||||
|
||||
proc setFallbackFont*(baseFont, fallbackFont: string): Font =
|
||||
return context.AddFallbackFont(baseFont, fallbackFont)
|
||||
return context.addFallbackFont(baseFont, fallbackFont)
|
||||
|
||||
proc setFallbackFont*(baseFont, fallbackFont: Font): Font =
|
||||
return context.AddFallbackFontId(baseFont, fallbackFont)
|
||||
return context.addFallbackFontId(baseFont, fallbackFont)
|
||||
|
||||
proc setFont*(font: Font) =
|
||||
context.FontFaceId(font)
|
||||
context.fontFaceId(font)
|
||||
|
||||
proc setFont*(name: string) =
|
||||
context.FontFace(name)
|
||||
context.fontFace(name)
|
||||
|
||||
proc setFontSize*(size: float) =
|
||||
context.FontSize(size)
|
||||
context.fontSize(size)
|
||||
|
||||
proc setFontBlur*(blur: float) =
|
||||
context.FontBlur(blur)
|
||||
context.fontBlur(blur)
|
||||
|
||||
proc setTextLetterSpacing*(spacing: float) =
|
||||
context.TextLetterSpacing(spacing)
|
||||
context.textLetterSpacing(spacing)
|
||||
|
||||
proc setTextLineHeight*(lineHeight: float) =
|
||||
context.TextLineHeight(lineHeight)
|
||||
context.textLineHeight(lineHeight)
|
||||
|
||||
proc `or`(align1: Alignment, align2: Alignment): Alignment =
|
||||
return (align1.cint or align2.cint).Alignment
|
||||
|
|
@ -207,35 +207,35 @@ proc `or`(align1: Alignment, align2: Alignment): Alignment =
|
|||
proc textAlign*(alignments: varargs[Alignment]) =
|
||||
var alignment = reduce(alignments, `or`)
|
||||
|
||||
context.TextAlign(alignment.cint)
|
||||
context.textAlign(alignment.cint)
|
||||
|
||||
macro textAlign*(descriptor: string) =
|
||||
result = createExpr("Alignment", "textAlign", descriptor)
|
||||
|
||||
proc textBounds*(text: string, x, y: float): TextBounds =
|
||||
var res: array[4, cfloat]
|
||||
let horizonalAdvance = context.TextBounds(x, y, text, nil, res[0].addr)
|
||||
let horizonalAdvance = context.textBounds(x, y, text, nil, res[0].addr)
|
||||
|
||||
let bounds: Bounds = (res[0].float, res[1].float, res[2].float, res[3].float)
|
||||
return (horizonalAdvance.float, bounds)
|
||||
|
||||
proc text*(text: string, x, y: float) =
|
||||
discard context.Text(x, y, text, nil)
|
||||
discard context.text(x, y, text, nil)
|
||||
|
||||
proc textBoxBounds*(text: string, x, y, breakRowWidth: float): Bounds =
|
||||
var res: array[4, cfloat]
|
||||
context.TextBoxBounds(x, y, breakRowWidth, text, nil, res[0].addr)
|
||||
context.textBoxBounds(x, y, breakRowWidth, text, nil, res[0].addr)
|
||||
|
||||
return (res[0].float, res[1].float, res[2].float, res[3].float)
|
||||
|
||||
proc textBox*(text: string, x, y, breakRowWidth: float) =
|
||||
context.TextBox(x, y, breakRowWidth, text, nil)
|
||||
context.textBox(x, y, breakRowWidth, text, nil)
|
||||
|
||||
proc textMetrics*(): TextMetrics =
|
||||
var
|
||||
ascender, descender, lineHeight: cfloat
|
||||
|
||||
context.TextMetrics(ascender.addr, descender.addr, lineHeight.addr)
|
||||
context.textMetrics(ascender.addr, descender.addr, lineHeight.addr)
|
||||
|
||||
return (ascender.float, descender.float, lineHeight.float)
|
||||
|
||||
|
|
@ -252,7 +252,7 @@ iterator glyphPositions(start: cstring, endPos: cstring, x, y: float): GlyphPosi
|
|||
let strLen = cast[ByteAddress](endPos) - cast[ByteAddress](start)
|
||||
|
||||
while (strIndex < strLen):
|
||||
numGlyphs = context.TextGlyphPositions(
|
||||
numGlyphs = context.textGlyphPositions(
|
||||
lastX, y, cast[cstring](start[strIndex].unsafeAddr), endPos,
|
||||
positions[0].addr, maxPositions
|
||||
)
|
||||
|
|
@ -303,7 +303,7 @@ iterator textRows(text: string, x, y, maxWidth: float): NVGtextRow =
|
|||
start = cast[cstring](text[0].unsafeAddr)
|
||||
|
||||
while true:
|
||||
numRows = context.TextBreakLines(
|
||||
numRows = context.textBreakLines(
|
||||
start,
|
||||
nil,
|
||||
maxWidth, rows[0].addr, maxRows
|
||||
|
|
@ -327,26 +327,26 @@ proc text*(text: string, x, y, maxWidth: float) =
|
|||
var newY = y
|
||||
|
||||
for row in textRows(text, x, y, maxWidth):
|
||||
discard context.Text(x, newY, row.start, row.`end`)
|
||||
discard context.text(x, newY, row.start, row.`end`)
|
||||
newY += textMetrics().lineHeight
|
||||
|
||||
proc beginFrame*(width, height, pxRatio: float) =
|
||||
context.BeginFrame(width, height, pxRatio)
|
||||
context.beginFrame(width, height, pxRatio)
|
||||
|
||||
proc cancelFrame*() =
|
||||
context.CancelFrame()
|
||||
context.cancelFrame()
|
||||
|
||||
proc endFrame*() =
|
||||
context.EndFrame()
|
||||
context.endFrame()
|
||||
|
||||
proc globalCompositeOperation*(op: CompositeOperation) =
|
||||
context.GlobalCompositeOperation(op.cint)
|
||||
context.globalCompositeOperation(op.cint)
|
||||
|
||||
proc globalCompositeBlendFunc*(sourceFactor, destFactor: BlendFactor) =
|
||||
context.GlobalCompositeBlendFunc(sourceFactor.cint, destFactor.cint)
|
||||
context.globalCompositeBlendFunc(sourceFactor.cint, destFactor.cint)
|
||||
|
||||
proc globalCompositeBlendFuncSeparate*(srcRGB, destRGB, srcAlpha, destAlpha: BlendFactor) =
|
||||
context.GlobalCompositeBlendFuncSeparate(srcRGB.cint, destRGB.cint, srcAlpha.cint, destAlpha.cint)
|
||||
context.globalCompositeBlendFuncSeparate(srcRGB.cint, destRGB.cint, srcAlpha.cint, destAlpha.cint)
|
||||
|
||||
template withFrame*(window: View, code: untyped) =
|
||||
let
|
||||
|
|
@ -369,15 +369,15 @@ template withFrame*(window: View, code: untyped) =
|
|||
proc saveState*() =
|
||||
## Pushes and saves the current render state into a state stack.
|
||||
## A matching restoreState() must be used to restore the state.
|
||||
context.Save()
|
||||
context.save()
|
||||
|
||||
proc restoreState*() =
|
||||
## Pops and restores current render state.
|
||||
context.Restore()
|
||||
context.restore()
|
||||
|
||||
proc resetState*() =
|
||||
## Resets current render state to default values. Does not affect the render state stack.
|
||||
context.Reset()
|
||||
context.reset()
|
||||
|
||||
template withState*(code: untyped) =
|
||||
saveState()
|
||||
|
|
@ -389,69 +389,69 @@ template withState*(code: untyped) =
|
|||
restoreState()
|
||||
|
||||
proc setShapeAntialias*(enabled = true) =
|
||||
context.ShapeAntiAlias(enabled.cint)
|
||||
context.shapeAntiAlias(enabled.cint)
|
||||
|
||||
proc setStrokeColor*(color: Color) =
|
||||
context.StrokeColor(color)
|
||||
context.strokeColor(color)
|
||||
|
||||
proc setStrokePaint*(paint: Paint) =
|
||||
context.StrokePaint(paint)
|
||||
context.strokePaint(paint)
|
||||
|
||||
proc setFillPaint*(paint: Paint) =
|
||||
context.FillPaint(paint)
|
||||
context.fillPaint(paint)
|
||||
|
||||
proc setFillColor*(color: Color) =
|
||||
context.FillColor(color)
|
||||
context.fillColor(color)
|
||||
|
||||
proc setFillColor*(r, g, b: uint8) =
|
||||
context.FillColor(RGB(r.cuchar, g.cuchar, b.cuchar))
|
||||
context.fillColor(rgb(r.cuchar, g.cuchar, b.cuchar))
|
||||
|
||||
proc setFillColor*(r, g, b: float) =
|
||||
context.FillColor(RGBf(r, g, b))
|
||||
context.fillColor(rgbf(r, g, b))
|
||||
|
||||
proc setFillColor*(r, g, b, a: float) =
|
||||
context.FillColor(RGBAf(r, g, b, a))
|
||||
context.fillColor(rgbaf(r, g, b, a))
|
||||
|
||||
proc setFillColor*(r, g, b, a: uint8) =
|
||||
context.FillColor(RGBA(r.cuchar, g.cuchar, b.cuchar, a.cuchar))
|
||||
context.fillColor(rgba(r.cuchar, g.cuchar, b.cuchar, a.cuchar))
|
||||
|
||||
proc setMiterLimit*(limit: float) =
|
||||
context.MiterLimit(limit)
|
||||
context.miterLimit(limit)
|
||||
|
||||
proc setStrokeWidth*(size: float) =
|
||||
context.StrokeWidth(size)
|
||||
context.strokeWidth(size)
|
||||
|
||||
proc setLineCap*(cap: LineCap) =
|
||||
context.LineCap(cap.cint)
|
||||
context.lineCap(cap.cint)
|
||||
|
||||
proc setLineJoin*(join: LineJoin) =
|
||||
context.LineJoin(join.cint)
|
||||
context.lineJoin(join.cint)
|
||||
|
||||
proc setGlobalAlpha*(alpha: float) =
|
||||
context.GlobalAlpha(alpha)
|
||||
context.globalAlpha(alpha)
|
||||
|
||||
# Transforms
|
||||
|
||||
proc resetTransform*() =
|
||||
context.ResetTransform()
|
||||
context.resetTransform()
|
||||
|
||||
proc transform*(a, b, c, d, e, f: float) =
|
||||
context.Transform(a, b, c, d, e, f)
|
||||
context.transform(a, b, c, d, e, f)
|
||||
|
||||
proc translate*(x, y: float) =
|
||||
context.Translate(x, y)
|
||||
context.translate(x, y)
|
||||
|
||||
proc rotate*(angle: float) =
|
||||
context.Rotate(angle)
|
||||
context.rotate(angle)
|
||||
|
||||
proc skewX*(angle: float) =
|
||||
context.SkewX(angle)
|
||||
context.skewX(angle)
|
||||
|
||||
proc skewY*(angle: float) =
|
||||
context.SkewY(angle)
|
||||
context.skewY(angle)
|
||||
|
||||
proc scale*(x, y: float) =
|
||||
context.Scale(x, y)
|
||||
context.scale(x, y)
|
||||
|
||||
proc copyArray[T, U](src: T): U =
|
||||
for i in 0..<src.len:
|
||||
|
|
@ -459,27 +459,27 @@ proc copyArray[T, U](src: T): U =
|
|||
|
||||
proc getCurrentTransform*(): array[6, float] =
|
||||
var res: array[6, cfloat]
|
||||
context.CurrentTransform(res[0].addr)
|
||||
context.currentTransform(res[0].addr)
|
||||
return copyArray[array[6, cfloat], array[6, float]](res)
|
||||
|
||||
proc setTransformIdentity*(dest: array[6, float]) =
|
||||
var dst = copyArray[array[6, float], array[6, cfloat]](dest)
|
||||
TransformIdentity(dst[0].addr)
|
||||
transformIdentity(dst[0].addr)
|
||||
|
||||
proc degreesToRadians*(degrees: float): float =
|
||||
return DegToRad(degrees)
|
||||
return degToRad(degrees)
|
||||
|
||||
proc radiansToDegrees*(radians: float): float =
|
||||
return RadToDeg(radians)
|
||||
return radToDeg(radians)
|
||||
|
||||
proc createFrameBuffer*(width, height: float, imageFlags: ImageFlagsGL = ImageFlagsGL.NONE): FrameBuffer =
|
||||
return context.CreateFramebuffer(width.cint, height.cint, imageFlags.cint)
|
||||
return context.createFramebuffer(width.cint, height.cint, imageFlags.cint)
|
||||
|
||||
proc binde*(fb: FrameBuffer) =
|
||||
BindFramebuffer(fb)
|
||||
bindFramebuffer(fb)
|
||||
|
||||
proc delete*(fb: FrameBuffer) =
|
||||
fb.DeleteFramebuffer()
|
||||
fb.deleteFramebuffer()
|
||||
|
||||
# Images
|
||||
|
||||
|
|
@ -488,7 +488,7 @@ proc `or`(imageflags1: ImageFlags, imageflags2: ImageFlags): ImageFlags =
|
|||
|
||||
proc loadImage*(fileName: string, flags: varargs[ImageFlags]): Image =
|
||||
var flagArgs = reduce(flags, `or`)
|
||||
result = context.CreateImage(fileName, flagArgs.cint)
|
||||
result = context.createImage(fileName, flagArgs.cint)
|
||||
|
||||
if result == -1:
|
||||
raise newException(ImageLoadError, fmt"Could not load image {fileName}.")
|
||||
|
|
@ -498,99 +498,99 @@ macro loadImage*(fileName, flags: string): Image =
|
|||
|
||||
proc createImageFromArray*(data: openArray[uint8], flags: varargs[ImageFlags]): Image =
|
||||
var flagArgs = reduce(flags, `or`)
|
||||
result = context.CreateImageMem(flagArgs.cint, cast[ptr cuchar](data[0].unsafeAddr), data.len.cint)
|
||||
result = context.createImageMem(flagArgs.cint, cast[ptr cuchar](data[0].unsafeAddr), data.len.cint)
|
||||
|
||||
if result == -1:
|
||||
raise newException(ImageLoadError, fmt"Could not load image from data.")
|
||||
|
||||
proc size*(image: Image): Size =
|
||||
var rw, rh: cint
|
||||
context.ImageSize(image, rw.addr, rh.addr)
|
||||
context.imageSize(image, rw.addr, rh.addr)
|
||||
result.width = rw
|
||||
result.height = rh
|
||||
|
||||
proc delete*(image: Image) =
|
||||
context.DeleteImage(image)
|
||||
context.deleteImage(image)
|
||||
|
||||
# Paths
|
||||
proc beginPath*() =
|
||||
context.BeginPath()
|
||||
context.beginPath()
|
||||
|
||||
proc pathMoveTo*(x, y: float) =
|
||||
context.MoveTo(x, y)
|
||||
context.moveTo(x, y)
|
||||
|
||||
proc pathLineTo*(x, y: float) =
|
||||
context.LineTo(x, y)
|
||||
context.lineTo(x, y)
|
||||
|
||||
proc pathBezierTo*(c1x, c1y, c2x, c2y, x, y: float) =
|
||||
context.BezierTo(c1x, c1y, c2x, c2y, x, y)
|
||||
context.bezierTo(c1x, c1y, c2x, c2y, x, y)
|
||||
|
||||
proc pathQuadTo*(cx, cy, x, y: float) =
|
||||
context.QuadTo(cx, cy, x, y)
|
||||
context.quadTo(cx, cy, x, y)
|
||||
|
||||
proc pathArcTo*(x1, y1, x2, y2, radius: float) =
|
||||
context.ArcTo(x1, y1, x2, y2, radius)
|
||||
context.arcTo(x1, y1, x2, y2, radius)
|
||||
|
||||
proc closePath*() =
|
||||
context.ClosePath()
|
||||
context.closePath()
|
||||
|
||||
proc pathWinding*(dir: Winding) =
|
||||
context.PathWinding(dir.cint)
|
||||
context.pathWinding(dir.cint)
|
||||
|
||||
proc setSolidity*(solidity: Solidity) =
|
||||
context.PathWinding(solidity.cint)
|
||||
context.pathWinding(solidity.cint)
|
||||
|
||||
proc pathArc*(cx, cy, r, a0, a1: float, dir: int) =
|
||||
context.Arc(cx, cy, r, a0, a1, dir.cint)
|
||||
context.arc(cx, cy, r, a0, a1, dir.cint)
|
||||
|
||||
proc pathRect*(x, y, width, height: float) =
|
||||
context.Rect(x, y, width, height)
|
||||
context.rect(x, y, width, height)
|
||||
|
||||
proc pathRoundedRect*(x, y, width, height, radius: float) =
|
||||
context.RoundedRect(x, y, width, height, radius)
|
||||
context.roundedRect(x, y, width, height, radius)
|
||||
|
||||
proc pathRoundedRectVarying*(x, y, width, height, radiusTopLeft, radiusTopRight,
|
||||
radiusBottomRight, radiusBottomLeft: float) =
|
||||
context.RoundedRectVarying(
|
||||
context.roundedRectVarying(
|
||||
x, y, width, height,
|
||||
radiusTopLeft, radiusTopRight, radiusBottomRight, radiusBottomLeft
|
||||
)
|
||||
|
||||
proc pathEllipse*(cx, cy, radiusX, radiusY: float) =
|
||||
context.Ellipse(cx, cy, radiusX, radiusY)
|
||||
context.ellipse(cx, cy, radiusX, radiusY)
|
||||
|
||||
proc pathCircle*(cx, cy, radius: float) =
|
||||
context.Circle(cx, cy, radius)
|
||||
context.circle(cx, cy, radius)
|
||||
|
||||
proc pathFill*() =
|
||||
context.Fill()
|
||||
context.fill()
|
||||
|
||||
proc pathStroke*() =
|
||||
context.Stroke()
|
||||
context.stroke()
|
||||
|
||||
proc linearGradient*(startX, startY, endX, endY: float, startColor, endColor: Color): Paint =
|
||||
result = context.LinearGradient(startX, startY, endX, endY, startColor, endColor)
|
||||
result = context.linearGradient(startX, startY, endX, endY, startColor, endColor)
|
||||
|
||||
proc boxGradient*(x, y, width, height, radius, feather: float, startColor, endColor: Color): Paint =
|
||||
result = context.BoxGradient(x, y, width, height, radius, feather, startColor, endColor)
|
||||
result = context.boxGradient(x, y, width, height, radius, feather, startColor, endColor)
|
||||
|
||||
proc radialGradient*(centerX, centerY, innerRadius, outerRadius: float, startColor, endColor: Color): Paint =
|
||||
result = context.RadialGradient(centerX, centerY, innerRadius, outerRadius, startColor, endColor)
|
||||
result = context.radialGradient(centerX, centerY, innerRadius, outerRadius, startColor, endColor)
|
||||
|
||||
proc imagePattern*(originX, originY, renderSizeX, renderSizeY, angle: float, image: Image, alpha: float): Paint =
|
||||
result = context.ImagePattern(originX, originY, renderSizeX, renderSizeY, angle, image, alpha)
|
||||
result = context.imagePattern(originX, originY, renderSizeX, renderSizeY, angle, image, alpha)
|
||||
|
||||
proc setScissor*(x, y, width, height: float) =
|
||||
context.Scissor(x, y, width, height)
|
||||
context.scissor(x, y, width, height)
|
||||
|
||||
proc intersectScissor*(x, y, width, height: float) =
|
||||
context.IntersectScissor(x, y, width, height)
|
||||
context.intersectScissor(x, y, width, height)
|
||||
|
||||
proc resetScissor*() =
|
||||
context.ResetScissor()
|
||||
context.resetScissor()
|
||||
|
||||
proc cleanup() {.noconv.} =
|
||||
echo "running cleanup"
|
||||
context.DeleteGL3()
|
||||
context.deleteGL3()
|
||||
|
||||
addQuitProc(cleanup)
|
||||
|
|
|
|||
|
|
@ -110,20 +110,27 @@ cCompile(srcDir/"src/*.c")
|
|||
cPlugin:
|
||||
import strutils, regex
|
||||
|
||||
const replacements = [
|
||||
re"^glnvg__(.)",
|
||||
re"^nvg__(.)",
|
||||
re"^nvglu(.)",
|
||||
re"^nvgl(.)",
|
||||
re"^nvg(.)",
|
||||
]
|
||||
|
||||
proc firstLetterLower(m: RegexMatch, s: string): string =
|
||||
if m.groupsCount > 0 and m.group(0).len > 0:
|
||||
return s[m.group(0)[0]].toLowerAscii
|
||||
|
||||
# Symbol renaming examples
|
||||
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
|
||||
# Get rid of leading and trailing underscores
|
||||
sym.name = sym.name.strip(chars = {'_'})
|
||||
|
||||
# Remove prefixes or suffixes from procs
|
||||
sym.name = sym.name.replace(re"^nvg__", "")
|
||||
|
||||
if sym.kind == nskProc:
|
||||
sym.name = sym.name.replace(re"^glnvg__", "")
|
||||
sym.name = sym.name.replace(re"^nvg__", "")
|
||||
sym.name = sym.name.replace(re"^nvglu", "")
|
||||
sym.name = sym.name.replace(re"^nvgl", "")
|
||||
sym.name = sym.name.replace(re"^nvg", "")
|
||||
for rep in replacements:
|
||||
sym.name = sym.name.replace(rep, firstLetterLower)
|
||||
|
||||
# Finally import wrapped header file. Recurse if #include files should also
|
||||
# be wrapped. Set dynlib if binding to dynamic library.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue