nanovg-bindings 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8209efc95a9fc19d21d3add4f79d05c5069c6951a06b7a9e0c1c523efd19e57
4
- data.tar.gz: faefdcbaf05388d9fa1f11d047c525057d8141c52f077965250f100f60d4ecd5
3
+ metadata.gz: b808f00a46b19da2e7185ef70dbde23c8d9924b61ea9560a608a5a0dcf7a8111
4
+ data.tar.gz: 49236305e012afccb6419883058959388c93e030581e4a9ad710f496fa84761a
5
5
  SHA512:
6
- metadata.gz: f5668466e097988fa2ac37b7b84ac318e7c66b9c6f2220ce04486f3756b46af922e7bb5167be3b44f17d7a56e59f910b767b72b72dfdbb2f2d5c7be2ec6f9e18
7
- data.tar.gz: ab406e4b5d22ddf6fd8428cc0f2b92259e4b95914aa25425a2b45ea3274b9e8b099008463916d3db1b3ab0d7a995ecce26257fdbcc9f6f9933849f6fe4cffc85
6
+ metadata.gz: 03570ae3e2ed85ac9436a7a34ad3d1d40a37b9e3ad0fe59ffb570eb34e2c00ff9f7381b571c5e78dc234f3c3605186cd00b5fb49cb0193551e2e1880369e3d18
7
+ data.tar.gz: 99be93bf4196c37296b209a628f3b6760189463f43bd77b43153e4c2a359a688faf3f8a57ceb155d347c29aa599cfa5b9c00415fad98cbc4950b027a88ebba53
data/ChangeLog CHANGED
@@ -1,65 +1,69 @@
1
- 2022-01-08 vaiorabbit <http://twitter.com/vaiorabbit>
2
-
3
- * Changed API
4
-
5
- 2022-01-07 vaiorabbit <http://twitter.com/vaiorabbit>
6
-
7
- * Use opengl-bindings2
8
-
9
- 2022-01-01 vaiorabbit <http://twitter.com/vaiorabbit>
10
-
11
- * nanovg-bindings.gemspec: Added
12
-
13
- 2021-12-31 vaiorabbit <http://twitter.com/vaiorabbit>
14
-
15
- * libnanovg_gl2.dll, libnanovg_gl3.dll: Added Windows binary
16
- * demo/util: Added for automatic library loading
17
- * nanovg_dll/nanovg.c: Fixed for Windows build
18
-
19
- 2021-12-30 vaiorabbit <http://twitter.com/vaiorabbit>
20
-
21
- * libnanovg_gl2.dylib, libnanovg_gl3.dylib: Built with latest nanovg ( https://github.com/memononen/nanovg/tree/645e9147a8701c98f52240257af0c9d5fa640e86 )
22
- * nanovg_dll: Use CMake / Scripts are now M1 mac ready
23
- * demo: Reorganized directory structure / Added several codes to run hole_polygon.ry demo / Fixed qrc.rb for the latest RQRCoce library
24
-
25
- 2018-10-20 vaiorabbit <http://twitter.com/vaiorabbit>
26
-
27
- * nanovg.rb: Now compatible with the latest APIs (NanoVG Commit f4069e6a1ad5da430fb0a9c57476d5ddc2ff89b2 https://github.com/memononen/nanovg/commit/f4069e6a1ad5da430fb0a9c57476d5ddc2ff89b2 ).
28
-
29
- 2017-07-22 vaiorabbit <http://twitter.com/vaiorabbit>
30
-
31
- * nanovg.rb: Now compatible with the latest APIs (NanoVG Commit 30e1c98175b30bcfd8f979f0813a97333329dfe2 https://github.com/memononen/nanovg/commit/30e1c98175b30bcfd8f979f0813a97333329dfe2).
32
-
33
- 2017-03-21 vaiorabbit <http://twitter.com/vaiorabbit>
34
-
35
- * nanovg.rb: Now compatible with the latest APIs (NanoVG Commit c75fc0bfcf3a72fb61dcd46df0522a60b59c6cc2 https://github.com/memononen/nanovg/commit/c75fc0bfcf3a72fb61dcd46df0522a60b59c6cc2).
36
-
37
- 2016-12-03 vaiorabbit <http://twitter.com/vaiorabbit>
38
-
39
- * nanovg.rb, nanovg_dll: Now compatible with the latest APIs (NanoVG Commit cacb00b852079db23c180f2e6cbff41eef673783).
40
- * demo/emojifont.rb, etc.: Added.
41
-
42
- 2016-08-17 vaiorabbit <http://twitter.com/vaiorabbit>
43
-
44
- * nanovg.rb, nanovg_dll: Now compatible with the latest APIs (NanoVG Commit 09dc767e3f25ec97e7398c18eca6a4c6bb3763f5).
45
-
46
- 2015-09-07 vaiorabbit <http://twitter.com/vaiorabbit>
47
-
48
- * demo: Removed some uninformative samples.
49
-
50
- 2015-08-22 vaiorabbit
51
-
52
- * nanovg_dll.c: Fixed include file name for Mac OS X.
53
-
54
- 2015-07-16 vaiorabbit
55
-
56
- * demo/qrc.rb: Added.
57
-
58
- 2015-07-13 vaiorabbit
59
-
60
- * nanovg.rb, nanovg_dll.c (nvgSetupGL2, nvgSetupGL3): Minimal OpenGL proc-address setup function (mainly for Windows)
61
- * nanovg_dll (nanovg_gl2.def, nanovg_gl3.def): Module definition file to build DLLs on Visual Studio.
62
-
63
- 2015-07-12 vaiorabbit
64
-
65
- * First release.
1
+ 2022-04-29 vaiorabbit <http://twitter.com/vaiorabbit>
2
+
3
+ * Updated using the latest nanovg ( https://github.com/memononen/nanovg/commit/397f3300bc14bdb856ec429c71c345ab0340b0a6 )
4
+
5
+ 2022-01-08 vaiorabbit <http://twitter.com/vaiorabbit>
6
+
7
+ * Changed API
8
+
9
+ 2022-01-07 vaiorabbit <http://twitter.com/vaiorabbit>
10
+
11
+ * Use opengl-bindings2
12
+
13
+ 2022-01-01 vaiorabbit <http://twitter.com/vaiorabbit>
14
+
15
+ * nanovg-bindings.gemspec: Added
16
+
17
+ 2021-12-31 vaiorabbit <http://twitter.com/vaiorabbit>
18
+
19
+ * libnanovg_gl2.dll, libnanovg_gl3.dll: Added Windows binary
20
+ * demo/util: Added for automatic library loading
21
+ * nanovg_dll/nanovg.c: Fixed for Windows build
22
+
23
+ 2021-12-30 vaiorabbit <http://twitter.com/vaiorabbit>
24
+
25
+ * libnanovg_gl2.dylib, libnanovg_gl3.dylib: Built with latest nanovg ( https://github.com/memononen/nanovg/tree/645e9147a8701c98f52240257af0c9d5fa640e86 )
26
+ * nanovg_dll: Use CMake / Scripts are now M1 mac ready
27
+ * demo: Reorganized directory structure / Added several codes to run hole_polygon.ry demo / Fixed qrc.rb for the latest RQRCoce library
28
+
29
+ 2018-10-20 vaiorabbit <http://twitter.com/vaiorabbit>
30
+
31
+ * nanovg.rb: Now compatible with the latest APIs (NanoVG Commit f4069e6a1ad5da430fb0a9c57476d5ddc2ff89b2 https://github.com/memononen/nanovg/commit/f4069e6a1ad5da430fb0a9c57476d5ddc2ff89b2 ).
32
+
33
+ 2017-07-22 vaiorabbit <http://twitter.com/vaiorabbit>
34
+
35
+ * nanovg.rb: Now compatible with the latest APIs (NanoVG Commit 30e1c98175b30bcfd8f979f0813a97333329dfe2 https://github.com/memononen/nanovg/commit/30e1c98175b30bcfd8f979f0813a97333329dfe2).
36
+
37
+ 2017-03-21 vaiorabbit <http://twitter.com/vaiorabbit>
38
+
39
+ * nanovg.rb: Now compatible with the latest APIs (NanoVG Commit c75fc0bfcf3a72fb61dcd46df0522a60b59c6cc2 https://github.com/memononen/nanovg/commit/c75fc0bfcf3a72fb61dcd46df0522a60b59c6cc2).
40
+
41
+ 2016-12-03 vaiorabbit <http://twitter.com/vaiorabbit>
42
+
43
+ * nanovg.rb, nanovg_dll: Now compatible with the latest APIs (NanoVG Commit cacb00b852079db23c180f2e6cbff41eef673783).
44
+ * demo/emojifont.rb, etc.: Added.
45
+
46
+ 2016-08-17 vaiorabbit <http://twitter.com/vaiorabbit>
47
+
48
+ * nanovg.rb, nanovg_dll: Now compatible with the latest APIs (NanoVG Commit 09dc767e3f25ec97e7398c18eca6a4c6bb3763f5).
49
+
50
+ 2015-09-07 vaiorabbit <http://twitter.com/vaiorabbit>
51
+
52
+ * demo: Removed some uninformative samples.
53
+
54
+ 2015-08-22 vaiorabbit
55
+
56
+ * nanovg_dll.c: Fixed include file name for Mac OS X.
57
+
58
+ 2015-07-16 vaiorabbit
59
+
60
+ * demo/qrc.rb: Added.
61
+
62
+ 2015-07-13 vaiorabbit
63
+
64
+ * nanovg.rb, nanovg_dll.c (nvgSetupGL2, nvgSetupGL3): Minimal OpenGL proc-address setup function (mainly for Windows)
65
+ * nanovg_dll (nanovg_gl2.def, nanovg_gl3.def): Module definition file to build DLLs on Visual Studio.
66
+
67
+ 2015-07-12 vaiorabbit
68
+
69
+ * First release.
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
@@ -1,60 +1,60 @@
1
- # NanoVG-Bindings : A Ruby bindings of NanoVG #
2
-
3
- Provides NanoVG ( https://github.com/memononen/nanovg ) interfaces for ruby (MRI).
4
-
5
- * Created : 2015-07-12
6
- * Last modified : 2022-01-08
7
-
8
- <img src="https://raw.githubusercontent.com/vaiorabbit/nanovg-bindings/master/doc/example_rb.png" width="150"> <img src="https://raw.githubusercontent.com/vaiorabbit/nanovg-bindings/master/doc/emojifont_rb.png" width="150"> <img src="https://raw.githubusercontent.com/vaiorabbit/nanovg-bindings/master/doc/hex_gol_glider5_rb.png" width="150"> <img src="https://raw.githubusercontent.com/vaiorabbit/nanovg-bindings/master/doc/jpfont_rb.png" width="150"> <img src="https://raw.githubusercontent.com/vaiorabbit/nanovg-bindings/master/doc/mandelbrot_rb.png" width="150">
9
-
10
-
11
- ## Prerequisites ##
12
-
13
- * Ruby-FFI ( https://github.com/ffi/ffi )
14
- * $ gem install ffi
15
-
16
- * OpenGL context provider
17
- * ex.) glut.rb or glfw.rb in opengl-bindings ( https://github.com/vaiorabbit/ruby-opengl )
18
- * $ gem install opengl-bindings
19
-
20
- ## How to Use ##
21
-
22
- 1. Build NanoVG shared library
23
- * See nanovg_dll
24
-
25
- 2. Include nanovg.rb in your script.
26
- * ex.) require_relative 'nanovg'
27
-
28
- 3. Load shared library
29
- * ex.) NanoVG.load_dll('libnanovg_gl2.dylib', render_backend: :gl2)
30
-
31
- 4. Setup OpenGL
32
- * nvgSetupGL2() / nvgSetupGL3
33
-
34
- See demo/example.rb for details.
35
-
36
- ## License ##
37
-
38
- All source codes are available under the terms of the zlib/libpng license.
39
-
40
- NanoVG-Bindings : A Ruby bindings of NanoVG
41
- Copyright (c) 2015-2022 vaiorabbit
42
-
43
- This software is provided 'as-is', without any express or implied
44
- warranty. In no event will the authors be held liable for any damages
45
- arising from the use of this software.
46
-
47
- Permission is granted to anyone to use this software for any purpose,
48
- including commercial applications, and to alter it and redistribute it
49
- freely, subject to the following restrictions:
50
-
51
- 1. The origin of this software must not be misrepresented; you must not
52
- claim that you wrote the original software. If you use this software
53
- in a product, an acknowledgment in the product documentation would be
54
- appreciated but is not required.
55
-
56
- 2. Altered source versions must be plainly marked as such, and must not be
57
- misrepresented as being the original software.
58
-
59
- 3. This notice may not be removed or altered from any source
60
- distribution.
1
+ # NanoVG-Bindings : A Ruby bindings of NanoVG #
2
+
3
+ Provides NanoVG ( https://github.com/memononen/nanovg ) interfaces for ruby (MRI).
4
+
5
+ * Created : 2015-07-12
6
+ * Last modified : 2022-04-29
7
+
8
+ <img src="https://raw.githubusercontent.com/vaiorabbit/nanovg-bindings/master/doc/example_rb.png" width="150"> <img src="https://raw.githubusercontent.com/vaiorabbit/nanovg-bindings/master/doc/emojifont_rb.png" width="150"> <img src="https://raw.githubusercontent.com/vaiorabbit/nanovg-bindings/master/doc/hex_gol_glider5_rb.png" width="150"> <img src="https://raw.githubusercontent.com/vaiorabbit/nanovg-bindings/master/doc/jpfont_rb.png" width="150"> <img src="https://raw.githubusercontent.com/vaiorabbit/nanovg-bindings/master/doc/mandelbrot_rb.png" width="150">
9
+
10
+
11
+ ## Prerequisites ##
12
+
13
+ * Ruby-FFI ( https://github.com/ffi/ffi )
14
+ * $ gem install ffi
15
+
16
+ * OpenGL context provider
17
+ * ex.) glut.rb or glfw.rb in opengl-bindings ( https://github.com/vaiorabbit/ruby-opengl )
18
+ * $ gem install opengl-bindings
19
+
20
+ ## How to Use ##
21
+
22
+ 1. Build NanoVG shared library
23
+ * See nanovg_dll
24
+
25
+ 2. Include nanovg.rb in your script.
26
+ * ex.) require_relative 'nanovg'
27
+
28
+ 3. Load shared library
29
+ * ex.) NanoVG.load_dll('libnanovg_gl2.dylib', render_backend: :gl2)
30
+
31
+ 4. Setup OpenGL
32
+ * nvgSetupGL2() / nvgSetupGL3
33
+
34
+ See demo/example.rb for details.
35
+
36
+ ## License ##
37
+
38
+ All source codes are available under the terms of the zlib/libpng license.
39
+
40
+ NanoVG-Bindings : A Ruby bindings of NanoVG
41
+ Copyright (c) 2015-2022 vaiorabbit
42
+
43
+ This software is provided 'as-is', without any express or implied
44
+ warranty. In no event will the authors be held liable for any damages
45
+ arising from the use of this software.
46
+
47
+ Permission is granted to anyone to use this software for any purpose,
48
+ including commercial applications, and to alter it and redistribute it
49
+ freely, subject to the following restrictions:
50
+
51
+ 1. The origin of this software must not be misrepresented; you must not
52
+ claim that you wrote the original software. If you use this software
53
+ in a product, an acknowledgment in the product documentation would be
54
+ appreciated but is not required.
55
+
56
+ 2. Altered source versions must be plainly marked as such, and must not be
57
+ misrepresented as being the original software.
58
+
59
+ 3. This notice may not be removed or altered from any source
60
+ distribution.
Binary file
Binary file
Binary file
Binary file
data/lib/nanovg.rb CHANGED
@@ -1,295 +1,295 @@
1
- require 'ffi'
2
-
3
- module NVG
4
- extend FFI::Library
5
-
6
- #
7
- # define/enum
8
- #
9
-
10
- # NVGwinding
11
- CCW = 1
12
- CW = 2
13
-
14
- # NVGsolidity
15
- SOLID = 1
16
- HOLE = 2
17
-
18
- # NVGlineCap
19
- BUTT = 0
20
- ROUND = 1
21
- SQUARE = 2
22
- BEVEL = 3
23
- MITER = 4
24
-
25
- # NVGalign
26
- # Horizontal align
27
- ALIGN_LEFT = 1
28
- ALIGN_CENTER = 2
29
- ALIGN_RIGHT = 4
30
- # Vertical align
31
- ALIGN_TOP = 8
32
- ALIGN_MIDDLE = 16
33
- ALIGN_BOTTOM = 32
34
- ALIGN_BASELINE = 64
35
-
36
- # NVGblendFactor
37
- ZERO = 1 << 0
38
- ONE = 1 << 1
39
- SRC_COLOR = 1 << 2
40
- ONE_MINUS_SRC_COLOR = 1 << 3
41
- DST_COLOR = 1 << 4
42
- ONE_MINUS_DST_COLOR = 1 << 5
43
- SRC_ALPHA = 1 << 6
44
- ONE_MINUS_SRC_ALPHA = 1 << 7
45
- DST_ALPHA = 1 << 8
46
- ONE_MINUS_DST_ALPHA = 1 << 9
47
- SRC_ALPHA_SATURATE = 1 << 10
48
-
49
- # NVGcompositeOperation
50
- SOURCE_OVER = 0
51
- SOURCE_IN = 1
52
- SOURCE_OUT = 2
53
- ATOP = 3
54
- DESTINATION_OVER = 4
55
- DESTINATION_IN = 5
56
- DESTINATION_OUT = 6
57
- DESTINATION_ATOP = 7
58
- LIGHTER = 8
59
- COPY = 9
60
- XOR = 10
61
-
62
- # NVGimageFlags
63
- IMAGE_GENERATE_MIPMAPS = 1
64
- IMAGE_REPEATX = 2
65
- IMAGE_REPEATY = 4
66
- IMAGE_FLIPY = 8
67
- IMAGE_PREMULTIPLIED = 16
68
- IMAGE_NEAREST = 32
69
-
70
- # NVGcreateFlags
71
- ANTIALIAS = 1
72
- STENCIL_STROKES = 2
73
- DEBUG = 4
74
-
75
- #
76
- # struct
77
- #
78
-
79
- class Color < FFI::Struct
80
- layout(
81
- :rgba, [:float, 4]
82
- )
83
- end
84
-
85
- class Paint < FFI::Struct
86
- layout(
87
- :xform, [:float, 6],
88
- :extent, [:float, 2],
89
- :radius, :float,
90
- :feather, :float,
91
- :innerColor, Color,
92
- :outerColor, Color,
93
- :image, :int32
94
- )
95
- end
96
-
97
- class CompositeOperationState < FFI::Struct
98
- layout(
99
- :srcRGB, :int32,
100
- :dstRGB, :int32,
101
- :srcAlpha, :int32,
102
- :dstAlpha, :int32
103
- )
104
- end
105
-
106
- class GlyphPosition < FFI::Struct
107
- layout(
108
- :str, :pointer,
109
- :x, :float,
110
- :minx, :float,
111
- :maxx, :float
112
- )
113
- end
114
-
115
- class TextRow < FFI::Struct
116
- layout(
117
- :start, :pointer,
118
- :end, :pointer,
119
- :next, :pointer,
120
- :width, :float,
121
- :minx, :float,
122
- :maxx, :float
123
- )
124
- end
125
-
126
- #
127
- # Load native library.
128
- #
129
- @@nanovg_import_done = false
130
-
131
- def self.load_lib(libpath = './libnanovg.dylib', render_backend: :gl2)
132
- ffi_lib_flags :now, :global # to force FFI to access nvgCreateInternal from nvgCreateGL2
133
- ffi_lib libpath
134
- import_symbols(render_backend) unless @@nanovg_import_done
135
- end
136
-
137
- def self.import_symbols(render_backend)
138
- #
139
- # Common API
140
- #
141
- attach_function :BeginFrame, :nvgBeginFrame, [:pointer, :float, :float, :float], :void
142
- attach_function :CancelFrame, :nvgCancelFrame, [:pointer], :void
143
- attach_function :EndFrame, :nvgEndFrame, [:pointer], :void
144
-
145
- attach_function :GlobalCompositeOperation, :nvgGlobalCompositeOperation, [:pointer, :int32], :void
146
- attach_function :GlobalCompositeBlendFunc, :nvgGlobalCompositeBlendFunc, [:pointer, :int32, :int32], :void
147
- attach_function :GlobalCompositeBlendFuncSeparate, :nvgGlobalCompositeBlendFuncSeparate, [:pointer, :int32, :int32, :int32, :int32], :void
148
-
149
- attach_function :RGB, :nvgRGB, [:uint8, :uint8, :uint8], Color.by_value
150
- attach_function :RGBf, :nvgRGBf, [:float, :float, :float], Color.by_value
151
- attach_function :RGBA, :nvgRGBA, [:uint8, :uint8, :uint8, :uint8], Color.by_value
152
- attach_function :RGBAf, :nvgRGBAf, [:float, :float, :float, :float], Color.by_value
153
-
154
- attach_function :LerpRGBA, :nvgLerpRGBA, [Color.by_value, Color.by_value, :float], Color.by_value
155
- attach_function :TransRGBA, :nvgTransRGBA, [Color.by_value, :uint8], Color.by_value
156
- attach_function :TransRGBAf, :nvgTransRGBAf, [Color.by_value, :float], Color.by_value
157
- attach_function :HSL, :nvgHSL, [:float, :float, :float], Color.by_value
158
- attach_function :HSLA, :nvgHSLA, [:float, :float, :float, :uint8], Color.by_value
159
-
160
- attach_function :Save, :nvgSave, [:pointer], :void
161
- attach_function :Restore, :nvgRestore, [:pointer], :void
162
- attach_function :Reset, :nvgReset, [:pointer], :void
163
-
164
- attach_function :ShapeAntiAlias, :nvgShapeAntiAlias, [:pointer, Color.by_value], :void
165
- attach_function :StrokeColor, :nvgStrokeColor, [:pointer, Color.by_value], :void
166
- attach_function :StrokePaint, :nvgStrokePaint, [:pointer, Paint.by_value], :void
167
- attach_function :FillColor, :nvgFillColor, [:pointer, Color.by_value], :void
168
- attach_function :FillPaint, :nvgFillPaint, [:pointer, Paint.by_value], :void
169
- attach_function :MiterLimit, :nvgMiterLimit, [:pointer, :float], :void
170
- attach_function :StrokeWidth, :nvgStrokeWidth, [:pointer, :float], :void
171
- attach_function :LineCap, :nvgLineCap, [:pointer, :int32], :void
172
- attach_function :LineJoin, :nvgLineJoin, [:pointer, :int32], :void
173
- attach_function :GlobalAlpha, :nvgGlobalAlpha, [:pointer, :float], :void
174
-
175
- attach_function :ResetTransform, :nvgResetTransform, [:pointer], :void
176
- attach_function :Transform, :nvgTransform, [:pointer, :float, :float, :float, :float, :float, :float], :void
177
- attach_function :Translate, :nvgTranslate, [:pointer, :float, :float], :void
178
- attach_function :Rotate, :nvgRotate, [:pointer, :float], :void
179
- attach_function :SkewX, :nvgSkewX, [:pointer, :float], :void
180
- attach_function :SkewY, :nvgSkewY, [:pointer, :float], :void
181
- attach_function :Scale, :nvgScale, [:pointer, :float, :float], :void
182
- attach_function :CurrentTransform, :nvgCurrentTransform, [:pointer, :pointer], :void
183
-
184
- attach_function :TransformIdentity, :nvgTransformIdentity, [:pointer], :void
185
- attach_function :TransformTranslate, :nvgTransformTranslate, [:pointer, :float, :float], :void
186
- attach_function :TransformScale, :nvgTransformScale, [:pointer, :float, :float], :void
187
- attach_function :TransformRotate, :nvgTransformRotate, [:pointer, :float], :void
188
- attach_function :TransformSkewX, :nvgTransformSkewX, [:pointer, :float], :void
189
- attach_function :TransformSkewY, :nvgTransformSkewY, [:pointer, :float], :void
190
- attach_function :TransformMultiply, :nvgTransformMultiply, [:pointer, :pointer], :void
191
- attach_function :TransformPremultiply, :nvgTransformPremultiply, [:pointer, :pointer], :void
192
- attach_function :TransformInverse, :nvgTransformInverse, [:pointer, :pointer], :int32
193
- attach_function :TransformPoint, :nvgTransformPoint, [:pointer, :pointer, :pointer, :float, :float], :void
194
-
195
- attach_function :DegToRad, :nvgDegToRad, [:float], :float
196
- attach_function :RadToDeg, :nvgRadToDeg, [:float], :float
197
-
198
- attach_function :CreateImage, :nvgCreateImage, [:pointer, :pointer, :int32], :int32
199
- attach_function :CreateImageMem, :nvgCreateImageMem, [:pointer, :int32, :pointer, :int32], :int32
200
- attach_function :CreateImageRGBA, :nvgCreateImageRGBA, [:pointer, :int32, :int32, :int32, :pointer], :int32
201
- attach_function :UpdateImage, :nvgUpdateImage, [:pointer, :int32, :pointer], :void
202
- attach_function :ImageSize, :nvgImageSize, [:pointer, :int32, :pointer, :pointer], :void
203
- attach_function :DeleteImage, :nvgDeleteImage, [:pointer, :int32], :void
204
-
205
- attach_function :LinearGradient, :nvgLinearGradient, [:pointer, :float, :float, :float, :float, Color.by_value, Color.by_value], Paint.by_value
206
- attach_function :BoxGradient, :nvgBoxGradient, [:pointer, :float, :float, :float, :float, :float, :float, Color.by_value, Color.by_value], Paint.by_value
207
- attach_function :RadialGradient, :nvgRadialGradient, [:pointer, :float, :float, :float, :float, Color.by_value, Color.by_value], Paint.by_value
208
- attach_function :ImagePattern, :nvgImagePattern, [:pointer, :float, :float, :float, :float, :float, :int32, :float], Paint.by_value
209
-
210
- attach_function :Scissor, :nvgScissor, [:pointer, :float, :float, :float, :float], :void
211
- attach_function :IntersectScissor, :nvgIntersectScissor, [:pointer, :float, :float, :float, :float], :void
212
- attach_function :ResetScissor, :nvgResetScissor, [:pointer], :void
213
-
214
- attach_function :BeginPath, :nvgBeginPath, [:pointer], :void
215
- attach_function :MoveTo, :nvgMoveTo, [:pointer, :float, :float], :void
216
- attach_function :LineTo, :nvgLineTo, [:pointer, :float, :float], :void
217
- attach_function :BezierTo, :nvgBezierTo, [:pointer, :float, :float, :float, :float, :float, :float], :void
218
- attach_function :QuadTo, :nvgQuadTo, [:pointer, :float, :float, :float, :float], :void
219
- attach_function :ArcTo, :nvgArcTo, [:pointer, :float, :float, :float, :float, :float], :void
220
- attach_function :ClosePath, :nvgClosePath, [:pointer], :void
221
- attach_function :PathWinding, :nvgPathWinding, [:pointer, :int32], :void
222
- attach_function :Arc, :nvgArc, [:pointer, :float, :float, :float, :float, :float, :int32], :void
223
- attach_function :Rect, :nvgRect, [:pointer, :float, :float, :float, :float], :void
224
- attach_function :RoundedRect, :nvgRoundedRect, [:pointer, :float, :float, :float, :float, :float], :void
225
- attach_function :RoundedRectVarying, :nvgRoundedRectVarying, [:pointer, :float, :float, :float, :float, :float, :float, :float, :float], :void
226
- attach_function :Ellipse, :nvgEllipse, [:pointer, :float, :float, :float, :float], :void
227
- attach_function :Circle, :nvgCircle, [:pointer, :float, :float, :float], :void
228
- attach_function :Fill, :nvgFill, [:pointer], :void
229
- attach_function :Stroke, :nvgStroke, [:pointer], :void
230
-
231
- attach_function :CreateFont, :nvgCreateFont, [:pointer, :pointer, :pointer], :int32
232
- attach_function :CreateFontMem, :nvgCreateFontMem, [:pointer, :pointer, :pointer, :int32, :int32], :int32
233
- attach_function :FindFont, :nvgFindFont, [:pointer, :pointer], :int32
234
- attach_function :AddFallbackFontId, :nvgAddFallbackFontId, [:pointer, :int32, :int32], :int32
235
- attach_function :AddFallbackFont, :nvgAddFallbackFont, [:pointer, :pointer, :pointer], :int32
236
- attach_function :FontSize, :nvgFontSize, [:pointer, :float], :void
237
- attach_function :FontBlur, :nvgFontBlur, [:pointer, :float], :void
238
- attach_function :TextLetterSpacing, :nvgTextLetterSpacing, [:pointer, :float], :void
239
- attach_function :TextLineHeight, :nvgTextLineHeight, [:pointer, :float], :void
240
- attach_function :TextAlign, :nvgTextAlign, [:pointer, :int32], :void
241
- attach_function :FontFaceId, :nvgFontFaceId, [:pointer, :int32], :void
242
- attach_function :FontFace, :nvgFontFace, [:pointer, :pointer], :void
243
- attach_function :Text, :nvgText, [:pointer, :float, :float, :pointer, :pointer], :float
244
- attach_function :TextBox, :nvgTextBox, [:pointer, :float, :float, :float, :pointer, :pointer], :void
245
- attach_function :TextBounds, :nvgTextBounds, [:pointer, :float, :float, :pointer, :pointer, :pointer], :float
246
- attach_function :TextBoxBounds, :nvgTextBoxBounds, [:pointer, :float, :float, :float, :pointer, :pointer, :pointer], :void
247
- attach_function :TextGlyphPositions, :nvgTextGlyphPositions, [:pointer, :float, :float, :pointer, :pointer, :pointer, :int32], :int32
248
- attach_function :TextMetrics, :nvgTextMetrics, [:pointer, :pointer, :pointer, :pointer], :void
249
- attach_function :TextBreakLines, :nvgTextBreakLines, [:pointer, :pointer, :pointer, :float, :pointer, :int32], :int32
250
-
251
- #
252
- # GL2-specific API (nanovg_gl)
253
- #
254
- if render_backend == :gl2
255
- attach_function :CreateGL2, :nvgCreateGL2, [:int32], :pointer
256
- attach_function :DeleteGL2, :nvgDeleteGL2, [:pointer], :void
257
- attach_function :SetupGL2, :nvgSetupGL2, [], :void
258
- end
259
-
260
- #
261
- # GL3-specific API (nanovg_gl)
262
- #
263
- if render_backend == :gl3
264
- attach_function :CreateGL3, :nvgCreateGL3, [:int32], :pointer
265
- attach_function :DeleteGL3, :nvgDeleteGL3, [:pointer], :void
266
- attach_function :SetupGL3, :nvgSetupGL3, [], :void
267
- end
268
-
269
- @@nanovg_import_done = true
270
- end
271
- end
272
-
273
- =begin
274
- NanoVG-Bindings : A Ruby bindings of NanoVG
275
- Copyright (c) 2015-2022 vaiorabbit
276
-
277
- This software is provided 'as-is', without any express or implied
278
- warranty. In no event will the authors be held liable for any damages
279
- arising from the use of this software.
280
-
281
- Permission is granted to anyone to use this software for any purpose,
282
- including commercial applications, and to alter it and redistribute it
283
- freely, subject to the following restrictions:
284
-
285
- 1. The origin of this software must not be misrepresented; you must not
286
- claim that you wrote the original software. If you use this software
287
- in a product, an acknowledgment in the product documentation would be
288
- appreciated but is not required.
289
-
290
- 2. Altered source versions must be plainly marked as such, and must not be
291
- misrepresented as being the original software.
292
-
293
- 3. This notice may not be removed or altered from any source
294
- distribution.
295
- =end
1
+ require 'ffi'
2
+
3
+ module NVG
4
+ extend FFI::Library
5
+
6
+ #
7
+ # define/enum
8
+ #
9
+
10
+ # NVGwinding
11
+ CCW = 1
12
+ CW = 2
13
+
14
+ # NVGsolidity
15
+ SOLID = 1
16
+ HOLE = 2
17
+
18
+ # NVGlineCap
19
+ BUTT = 0
20
+ ROUND = 1
21
+ SQUARE = 2
22
+ BEVEL = 3
23
+ MITER = 4
24
+
25
+ # NVGalign
26
+ # Horizontal align
27
+ ALIGN_LEFT = 1
28
+ ALIGN_CENTER = 2
29
+ ALIGN_RIGHT = 4
30
+ # Vertical align
31
+ ALIGN_TOP = 8
32
+ ALIGN_MIDDLE = 16
33
+ ALIGN_BOTTOM = 32
34
+ ALIGN_BASELINE = 64
35
+
36
+ # NVGblendFactor
37
+ ZERO = 1 << 0
38
+ ONE = 1 << 1
39
+ SRC_COLOR = 1 << 2
40
+ ONE_MINUS_SRC_COLOR = 1 << 3
41
+ DST_COLOR = 1 << 4
42
+ ONE_MINUS_DST_COLOR = 1 << 5
43
+ SRC_ALPHA = 1 << 6
44
+ ONE_MINUS_SRC_ALPHA = 1 << 7
45
+ DST_ALPHA = 1 << 8
46
+ ONE_MINUS_DST_ALPHA = 1 << 9
47
+ SRC_ALPHA_SATURATE = 1 << 10
48
+
49
+ # NVGcompositeOperation
50
+ SOURCE_OVER = 0
51
+ SOURCE_IN = 1
52
+ SOURCE_OUT = 2
53
+ ATOP = 3
54
+ DESTINATION_OVER = 4
55
+ DESTINATION_IN = 5
56
+ DESTINATION_OUT = 6
57
+ DESTINATION_ATOP = 7
58
+ LIGHTER = 8
59
+ COPY = 9
60
+ XOR = 10
61
+
62
+ # NVGimageFlags
63
+ IMAGE_GENERATE_MIPMAPS = 1
64
+ IMAGE_REPEATX = 2
65
+ IMAGE_REPEATY = 4
66
+ IMAGE_FLIPY = 8
67
+ IMAGE_PREMULTIPLIED = 16
68
+ IMAGE_NEAREST = 32
69
+
70
+ # NVGcreateFlags
71
+ ANTIALIAS = 1
72
+ STENCIL_STROKES = 2
73
+ DEBUG = 4
74
+
75
+ #
76
+ # struct
77
+ #
78
+
79
+ class Color < FFI::Struct
80
+ layout(
81
+ :rgba, [:float, 4]
82
+ )
83
+ end
84
+
85
+ class Paint < FFI::Struct
86
+ layout(
87
+ :xform, [:float, 6],
88
+ :extent, [:float, 2],
89
+ :radius, :float,
90
+ :feather, :float,
91
+ :innerColor, Color,
92
+ :outerColor, Color,
93
+ :image, :int32
94
+ )
95
+ end
96
+
97
+ class CompositeOperationState < FFI::Struct
98
+ layout(
99
+ :srcRGB, :int32,
100
+ :dstRGB, :int32,
101
+ :srcAlpha, :int32,
102
+ :dstAlpha, :int32
103
+ )
104
+ end
105
+
106
+ class GlyphPosition < FFI::Struct
107
+ layout(
108
+ :str, :pointer,
109
+ :x, :float,
110
+ :minx, :float,
111
+ :maxx, :float
112
+ )
113
+ end
114
+
115
+ class TextRow < FFI::Struct
116
+ layout(
117
+ :start, :pointer,
118
+ :end, :pointer,
119
+ :next, :pointer,
120
+ :width, :float,
121
+ :minx, :float,
122
+ :maxx, :float
123
+ )
124
+ end
125
+
126
+ #
127
+ # Load native library.
128
+ #
129
+ @@nanovg_import_done = false
130
+
131
+ def self.load_lib(libpath = './libnanovg.dylib', render_backend: :gl2)
132
+ ffi_lib_flags :now, :global # to force FFI to access nvgCreateInternal from nvgCreateGL2
133
+ ffi_lib libpath
134
+ import_symbols(render_backend) unless @@nanovg_import_done
135
+ end
136
+
137
+ def self.import_symbols(render_backend)
138
+ #
139
+ # Common API
140
+ #
141
+ attach_function :BeginFrame, :nvgBeginFrame, [:pointer, :float, :float, :float], :void
142
+ attach_function :CancelFrame, :nvgCancelFrame, [:pointer], :void
143
+ attach_function :EndFrame, :nvgEndFrame, [:pointer], :void
144
+
145
+ attach_function :GlobalCompositeOperation, :nvgGlobalCompositeOperation, [:pointer, :int32], :void
146
+ attach_function :GlobalCompositeBlendFunc, :nvgGlobalCompositeBlendFunc, [:pointer, :int32, :int32], :void
147
+ attach_function :GlobalCompositeBlendFuncSeparate, :nvgGlobalCompositeBlendFuncSeparate, [:pointer, :int32, :int32, :int32, :int32], :void
148
+
149
+ attach_function :RGB, :nvgRGB, [:uint8, :uint8, :uint8], Color.by_value
150
+ attach_function :RGBf, :nvgRGBf, [:float, :float, :float], Color.by_value
151
+ attach_function :RGBA, :nvgRGBA, [:uint8, :uint8, :uint8, :uint8], Color.by_value
152
+ attach_function :RGBAf, :nvgRGBAf, [:float, :float, :float, :float], Color.by_value
153
+
154
+ attach_function :LerpRGBA, :nvgLerpRGBA, [Color.by_value, Color.by_value, :float], Color.by_value
155
+ attach_function :TransRGBA, :nvgTransRGBA, [Color.by_value, :uint8], Color.by_value
156
+ attach_function :TransRGBAf, :nvgTransRGBAf, [Color.by_value, :float], Color.by_value
157
+ attach_function :HSL, :nvgHSL, [:float, :float, :float], Color.by_value
158
+ attach_function :HSLA, :nvgHSLA, [:float, :float, :float, :uint8], Color.by_value
159
+
160
+ attach_function :Save, :nvgSave, [:pointer], :void
161
+ attach_function :Restore, :nvgRestore, [:pointer], :void
162
+ attach_function :Reset, :nvgReset, [:pointer], :void
163
+
164
+ attach_function :ShapeAntiAlias, :nvgShapeAntiAlias, [:pointer, Color.by_value], :void
165
+ attach_function :StrokeColor, :nvgStrokeColor, [:pointer, Color.by_value], :void
166
+ attach_function :StrokePaint, :nvgStrokePaint, [:pointer, Paint.by_value], :void
167
+ attach_function :FillColor, :nvgFillColor, [:pointer, Color.by_value], :void
168
+ attach_function :FillPaint, :nvgFillPaint, [:pointer, Paint.by_value], :void
169
+ attach_function :MiterLimit, :nvgMiterLimit, [:pointer, :float], :void
170
+ attach_function :StrokeWidth, :nvgStrokeWidth, [:pointer, :float], :void
171
+ attach_function :LineCap, :nvgLineCap, [:pointer, :int32], :void
172
+ attach_function :LineJoin, :nvgLineJoin, [:pointer, :int32], :void
173
+ attach_function :GlobalAlpha, :nvgGlobalAlpha, [:pointer, :float], :void
174
+
175
+ attach_function :ResetTransform, :nvgResetTransform, [:pointer], :void
176
+ attach_function :Transform, :nvgTransform, [:pointer, :float, :float, :float, :float, :float, :float], :void
177
+ attach_function :Translate, :nvgTranslate, [:pointer, :float, :float], :void
178
+ attach_function :Rotate, :nvgRotate, [:pointer, :float], :void
179
+ attach_function :SkewX, :nvgSkewX, [:pointer, :float], :void
180
+ attach_function :SkewY, :nvgSkewY, [:pointer, :float], :void
181
+ attach_function :Scale, :nvgScale, [:pointer, :float, :float], :void
182
+ attach_function :CurrentTransform, :nvgCurrentTransform, [:pointer, :pointer], :void
183
+
184
+ attach_function :TransformIdentity, :nvgTransformIdentity, [:pointer], :void
185
+ attach_function :TransformTranslate, :nvgTransformTranslate, [:pointer, :float, :float], :void
186
+ attach_function :TransformScale, :nvgTransformScale, [:pointer, :float, :float], :void
187
+ attach_function :TransformRotate, :nvgTransformRotate, [:pointer, :float], :void
188
+ attach_function :TransformSkewX, :nvgTransformSkewX, [:pointer, :float], :void
189
+ attach_function :TransformSkewY, :nvgTransformSkewY, [:pointer, :float], :void
190
+ attach_function :TransformMultiply, :nvgTransformMultiply, [:pointer, :pointer], :void
191
+ attach_function :TransformPremultiply, :nvgTransformPremultiply, [:pointer, :pointer], :void
192
+ attach_function :TransformInverse, :nvgTransformInverse, [:pointer, :pointer], :int32
193
+ attach_function :TransformPoint, :nvgTransformPoint, [:pointer, :pointer, :pointer, :float, :float], :void
194
+
195
+ attach_function :DegToRad, :nvgDegToRad, [:float], :float
196
+ attach_function :RadToDeg, :nvgRadToDeg, [:float], :float
197
+
198
+ attach_function :CreateImage, :nvgCreateImage, [:pointer, :pointer, :int32], :int32
199
+ attach_function :CreateImageMem, :nvgCreateImageMem, [:pointer, :int32, :pointer, :int32], :int32
200
+ attach_function :CreateImageRGBA, :nvgCreateImageRGBA, [:pointer, :int32, :int32, :int32, :pointer], :int32
201
+ attach_function :UpdateImage, :nvgUpdateImage, [:pointer, :int32, :pointer], :void
202
+ attach_function :ImageSize, :nvgImageSize, [:pointer, :int32, :pointer, :pointer], :void
203
+ attach_function :DeleteImage, :nvgDeleteImage, [:pointer, :int32], :void
204
+
205
+ attach_function :LinearGradient, :nvgLinearGradient, [:pointer, :float, :float, :float, :float, Color.by_value, Color.by_value], Paint.by_value
206
+ attach_function :BoxGradient, :nvgBoxGradient, [:pointer, :float, :float, :float, :float, :float, :float, Color.by_value, Color.by_value], Paint.by_value
207
+ attach_function :RadialGradient, :nvgRadialGradient, [:pointer, :float, :float, :float, :float, Color.by_value, Color.by_value], Paint.by_value
208
+ attach_function :ImagePattern, :nvgImagePattern, [:pointer, :float, :float, :float, :float, :float, :int32, :float], Paint.by_value
209
+
210
+ attach_function :Scissor, :nvgScissor, [:pointer, :float, :float, :float, :float], :void
211
+ attach_function :IntersectScissor, :nvgIntersectScissor, [:pointer, :float, :float, :float, :float], :void
212
+ attach_function :ResetScissor, :nvgResetScissor, [:pointer], :void
213
+
214
+ attach_function :BeginPath, :nvgBeginPath, [:pointer], :void
215
+ attach_function :MoveTo, :nvgMoveTo, [:pointer, :float, :float], :void
216
+ attach_function :LineTo, :nvgLineTo, [:pointer, :float, :float], :void
217
+ attach_function :BezierTo, :nvgBezierTo, [:pointer, :float, :float, :float, :float, :float, :float], :void
218
+ attach_function :QuadTo, :nvgQuadTo, [:pointer, :float, :float, :float, :float], :void
219
+ attach_function :ArcTo, :nvgArcTo, [:pointer, :float, :float, :float, :float, :float], :void
220
+ attach_function :ClosePath, :nvgClosePath, [:pointer], :void
221
+ attach_function :PathWinding, :nvgPathWinding, [:pointer, :int32], :void
222
+ attach_function :Arc, :nvgArc, [:pointer, :float, :float, :float, :float, :float, :int32], :void
223
+ attach_function :Rect, :nvgRect, [:pointer, :float, :float, :float, :float], :void
224
+ attach_function :RoundedRect, :nvgRoundedRect, [:pointer, :float, :float, :float, :float, :float], :void
225
+ attach_function :RoundedRectVarying, :nvgRoundedRectVarying, [:pointer, :float, :float, :float, :float, :float, :float, :float, :float], :void
226
+ attach_function :Ellipse, :nvgEllipse, [:pointer, :float, :float, :float, :float], :void
227
+ attach_function :Circle, :nvgCircle, [:pointer, :float, :float, :float], :void
228
+ attach_function :Fill, :nvgFill, [:pointer], :void
229
+ attach_function :Stroke, :nvgStroke, [:pointer], :void
230
+
231
+ attach_function :CreateFont, :nvgCreateFont, [:pointer, :pointer, :pointer], :int32
232
+ attach_function :CreateFontMem, :nvgCreateFontMem, [:pointer, :pointer, :pointer, :int32, :int32], :int32
233
+ attach_function :FindFont, :nvgFindFont, [:pointer, :pointer], :int32
234
+ attach_function :AddFallbackFontId, :nvgAddFallbackFontId, [:pointer, :int32, :int32], :int32
235
+ attach_function :AddFallbackFont, :nvgAddFallbackFont, [:pointer, :pointer, :pointer], :int32
236
+ attach_function :FontSize, :nvgFontSize, [:pointer, :float], :void
237
+ attach_function :FontBlur, :nvgFontBlur, [:pointer, :float], :void
238
+ attach_function :TextLetterSpacing, :nvgTextLetterSpacing, [:pointer, :float], :void
239
+ attach_function :TextLineHeight, :nvgTextLineHeight, [:pointer, :float], :void
240
+ attach_function :TextAlign, :nvgTextAlign, [:pointer, :int32], :void
241
+ attach_function :FontFaceId, :nvgFontFaceId, [:pointer, :int32], :void
242
+ attach_function :FontFace, :nvgFontFace, [:pointer, :pointer], :void
243
+ attach_function :Text, :nvgText, [:pointer, :float, :float, :pointer, :pointer], :float
244
+ attach_function :TextBox, :nvgTextBox, [:pointer, :float, :float, :float, :pointer, :pointer], :void
245
+ attach_function :TextBounds, :nvgTextBounds, [:pointer, :float, :float, :pointer, :pointer, :pointer], :float
246
+ attach_function :TextBoxBounds, :nvgTextBoxBounds, [:pointer, :float, :float, :float, :pointer, :pointer, :pointer], :void
247
+ attach_function :TextGlyphPositions, :nvgTextGlyphPositions, [:pointer, :float, :float, :pointer, :pointer, :pointer, :int32], :int32
248
+ attach_function :TextMetrics, :nvgTextMetrics, [:pointer, :pointer, :pointer, :pointer], :void
249
+ attach_function :TextBreakLines, :nvgTextBreakLines, [:pointer, :pointer, :pointer, :float, :pointer, :int32], :int32
250
+
251
+ #
252
+ # GL2-specific API (nanovg_gl)
253
+ #
254
+ if render_backend == :gl2
255
+ attach_function :CreateGL2, :nvgCreateGL2, [:int32], :pointer
256
+ attach_function :DeleteGL2, :nvgDeleteGL2, [:pointer], :void
257
+ attach_function :SetupGL2, :nvgSetupGL2, [], :void
258
+ end
259
+
260
+ #
261
+ # GL3-specific API (nanovg_gl)
262
+ #
263
+ if render_backend == :gl3
264
+ attach_function :CreateGL3, :nvgCreateGL3, [:int32], :pointer
265
+ attach_function :DeleteGL3, :nvgDeleteGL3, [:pointer], :void
266
+ attach_function :SetupGL3, :nvgSetupGL3, [], :void
267
+ end
268
+
269
+ @@nanovg_import_done = true
270
+ end
271
+ end
272
+
273
+ =begin
274
+ NanoVG-Bindings : A Ruby bindings of NanoVG
275
+ Copyright (c) 2015-2022 vaiorabbit
276
+
277
+ This software is provided 'as-is', without any express or implied
278
+ warranty. In no event will the authors be held liable for any damages
279
+ arising from the use of this software.
280
+
281
+ Permission is granted to anyone to use this software for any purpose,
282
+ including commercial applications, and to alter it and redistribute it
283
+ freely, subject to the following restrictions:
284
+
285
+ 1. The origin of this software must not be misrepresented; you must not
286
+ claim that you wrote the original software. If you use this software
287
+ in a product, an acknowledgment in the product documentation would be
288
+ appreciated but is not required.
289
+
290
+ 2. Altered source versions must be plainly marked as such, and must not be
291
+ misrepresented as being the original software.
292
+
293
+ 3. This notice may not be removed or altered from any source
294
+ distribution.
295
+ =end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanovg-bindings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - vaiorabbit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-09 00:00:00.000000000 Z
11
+ date: 2022-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi