diff --git a/examples/common.nim b/examples/common.nim index 490d796..b470b0f 100644 --- a/examples/common.nim +++ b/examples/common.nim @@ -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:"".} \ No newline at end of file diff --git a/examples/demo.nim b/examples/demo.nim index 2b77240..e676ee7 100644 --- a/examples/demo.nim +++ b/examples/demo.nim @@ -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) diff --git a/examples/demo_sdl2.nim b/examples/demo_sdl2.nim index 04cf2e8..35d6569 100644 --- a/examples/demo_sdl2.nim +++ b/examples/demo_sdl2.nim @@ -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) diff --git a/examples/demo_sdl2_gpu.nim b/examples/demo_sdl2_gpu.nim index 3a748a0..e717315 100644 --- a/examples/demo_sdl2_gpu.nim +++ b/examples/demo_sdl2_gpu.nim @@ -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() diff --git a/nim-gdb.bash b/nim-gdb.bash deleted file mode 100755 index c307a3a..0000000 --- a/nim-gdb.bash +++ /dev/null @@ -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" "$@" \ No newline at end of file diff --git a/nim-gdb.bash b/nim-gdb.bash new file mode 120000 index 0000000..f6eba4b --- /dev/null +++ b/nim-gdb.bash @@ -0,0 +1 @@ +nim-gdb \ No newline at end of file diff --git a/src/nanovg.nim b/src/nanovg.nim index 230986a..3ddc968 100644 --- a/src/nanovg.nim +++ b/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.. 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.