rbsdl3 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/rbsdl3/ttf.rb ADDED
@@ -0,0 +1,254 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../rbsdl3"
3
+ require_relative "sdl"
4
+
5
+ module SDL3
6
+ using BindingsRefinement
7
+ SDL_ttf = proc {
8
+ # Ruby wrappers for SDL_ttf macros
9
+ #
10
+ const_set :SDL_TTF_MAJOR_VERSION, 3
11
+ const_set :SDL_TTF_MINOR_VERSION, 2
12
+ const_set :SDL_TTF_MICRO_VERSION, 2
13
+ const_set :SDL_TTF_VERSION, SDL_VERSIONNUM(SDL_TTF_MAJOR_VERSION, SDL_TTF_MINOR_VERSION, SDL_TTF_MICRO_VERSION)
14
+ module_function def SDL_TTF_VERSION_ATLEAST(x, y, z) = ((SDL_TTF_MAJOR_VERSION >= x) && (SDL_TTF_MAJOR_VERSION > x || SDL_TTF_MINOR_VERSION >= y) && (SDL_TTF_MAJOR_VERSION > x || SDL_TTF_MINOR_VERSION > y || SDL_TTF_MICRO_VERSION >= z))
15
+
16
+ # Fiddle declarations for SDL_ttf functions, structs, and enums
17
+ #
18
+ extern "int TTF_Version(void)"
19
+ extern "void TTF_GetFreeTypeVersion(int *, int *, int *)"
20
+ extern "void TTF_GetHarfBuzzVersion(int *, int *, int *)"
21
+ extern "bool TTF_Init(void)"
22
+ extern "TTF_Font * TTF_OpenFont(char *, float)"
23
+ extern "TTF_Font * TTF_OpenFontIO(SDL_IOStream *, bool, float)"
24
+ extern "TTF_Font * TTF_OpenFontWithProperties(SDL_PropertiesID)"
25
+ extern "TTF_Font * TTF_CopyFont(TTF_Font *)"
26
+ extern "SDL_PropertiesID TTF_GetFontProperties(TTF_Font *)"
27
+ extern "Uint32 TTF_GetFontGeneration(TTF_Font *)"
28
+ extern "bool TTF_AddFallbackFont(TTF_Font *, TTF_Font *)"
29
+ extern "void TTF_RemoveFallbackFont(TTF_Font *, TTF_Font *)"
30
+ extern "void TTF_ClearFallbackFonts(TTF_Font *)"
31
+ extern "bool TTF_SetFontSize(TTF_Font *, float)"
32
+ extern "bool TTF_SetFontSizeDPI(TTF_Font *, float, int, int)"
33
+ extern "float TTF_GetFontSize(TTF_Font *)"
34
+ extern "bool TTF_GetFontDPI(TTF_Font *, int *, int *)"
35
+ typealias "TTF_FontStyleFlags", "Uint32"
36
+ extern "void TTF_SetFontStyle(TTF_Font *, TTF_FontStyleFlags)"
37
+ extern "TTF_FontStyleFlags TTF_GetFontStyle(TTF_Font *)"
38
+ extern "bool TTF_SetFontOutline(TTF_Font *, int)"
39
+ extern "int TTF_GetFontOutline(TTF_Font *)"
40
+ const_set :TTF_HINTING_INVALID, 4294967295
41
+ const_set :TTF_HINTING_NORMAL, 0
42
+ const_set :TTF_HINTING_LIGHT, 1
43
+ const_set :TTF_HINTING_MONO, 2
44
+ const_set :TTF_HINTING_NONE, 3
45
+ const_set :TTF_HINTING_LIGHT_SUBPIXEL, 4
46
+ typealias "TTF_HintingFlags", "enum"
47
+ extern "void TTF_SetFontHinting(TTF_Font *, TTF_HintingFlags)"
48
+ extern "int TTF_GetNumFontFaces(TTF_Font *)"
49
+ extern "TTF_HintingFlags TTF_GetFontHinting(TTF_Font *)"
50
+ extern "bool TTF_SetFontSDF(TTF_Font *, bool)"
51
+ extern "bool TTF_GetFontSDF(TTF_Font *)"
52
+ extern "int TTF_GetFontWeight(TTF_Font *)"
53
+ const_set :TTF_HORIZONTAL_ALIGN_INVALID, 4294967295
54
+ const_set :TTF_HORIZONTAL_ALIGN_LEFT, 0
55
+ const_set :TTF_HORIZONTAL_ALIGN_CENTER, 1
56
+ const_set :TTF_HORIZONTAL_ALIGN_RIGHT, 2
57
+ typealias "TTF_HorizontalAlignment", "enum"
58
+ extern "void TTF_SetFontWrapAlignment(TTF_Font *, TTF_HorizontalAlignment)"
59
+ extern "TTF_HorizontalAlignment TTF_GetFontWrapAlignment(TTF_Font *)"
60
+ extern "int TTF_GetFontHeight(TTF_Font *)"
61
+ extern "int TTF_GetFontAscent(TTF_Font *)"
62
+ extern "int TTF_GetFontDescent(TTF_Font *)"
63
+ extern "void TTF_SetFontLineSkip(TTF_Font *, int)"
64
+ extern "int TTF_GetFontLineSkip(TTF_Font *)"
65
+ extern "void TTF_SetFontKerning(TTF_Font *, bool)"
66
+ extern "bool TTF_GetFontKerning(TTF_Font *)"
67
+ extern "bool TTF_FontIsFixedWidth(TTF_Font *)"
68
+ extern "bool TTF_FontIsScalable(TTF_Font *)"
69
+ extern "char * TTF_GetFontFamilyName(TTF_Font *)"
70
+ extern "char * TTF_GetFontStyleName(TTF_Font *)"
71
+ const_set :TTF_DIRECTION_INVALID, 0
72
+ const_set :TTF_DIRECTION_LTR, 4
73
+ const_set :TTF_DIRECTION_RTL, 5
74
+ const_set :TTF_DIRECTION_TTB, 6
75
+ const_set :TTF_DIRECTION_BTT, 7
76
+ typealias "TTF_Direction", "enum"
77
+ extern "bool TTF_SetFontDirection(TTF_Font *, TTF_Direction)"
78
+ extern "TTF_Direction TTF_GetFontDirection(TTF_Font *)"
79
+ extern "Uint32 TTF_StringToTag(char *)"
80
+ extern "void TTF_TagToString(Uint32, char *, size_t)"
81
+ extern "bool TTF_SetFontScript(TTF_Font *, Uint32)"
82
+ extern "Uint32 TTF_GetFontScript(TTF_Font *)"
83
+ extern "Uint32 TTF_GetGlyphScript(Uint32)"
84
+ extern "bool TTF_SetFontLanguage(TTF_Font *, char *)"
85
+ extern "bool TTF_FontHasGlyph(TTF_Font *, Uint32)"
86
+ const_set :TTF_IMAGE_INVALID, 0
87
+ const_set :TTF_IMAGE_ALPHA, 1
88
+ const_set :TTF_IMAGE_COLOR, 2
89
+ const_set :TTF_IMAGE_SDF, 3
90
+ typealias "TTF_ImageType", "enum"
91
+ extern "SDL_Surface * TTF_GetGlyphImage(TTF_Font *, Uint32, TTF_ImageType *)"
92
+ extern "SDL_Surface * TTF_GetGlyphImageForIndex(TTF_Font *, Uint32, TTF_ImageType *)"
93
+ extern "bool TTF_GetGlyphMetrics(TTF_Font *, Uint32, int *, int *, int *, int *, int *)"
94
+ extern "bool TTF_GetGlyphKerning(TTF_Font *, Uint32, Uint32, int *)"
95
+ extern "bool TTF_GetStringSize(TTF_Font *, char *, size_t, int *, int *)"
96
+ extern "bool TTF_GetStringSizeWrapped(TTF_Font *, char *, size_t, int, int *, int *)"
97
+ extern "bool TTF_MeasureString(TTF_Font *, char *, size_t, int, int *, size_t *)"
98
+ extern "SDL_Surface * TTF_RenderText_Solid(TTF_Font *, char *, size_t, SDL_Color)", unsupported: "SDL function unsupported by Fiddle: TTF_RenderText_Solid()"
99
+ extern "SDL_Surface * TTF_RenderText_Solid_Wrapped(TTF_Font *, char *, size_t, SDL_Color, int)", unsupported: "SDL function unsupported by Fiddle: TTF_RenderText_Solid_Wrapped()"
100
+ extern "SDL_Surface * TTF_RenderGlyph_Solid(TTF_Font *, Uint32, SDL_Color)", unsupported: "SDL function unsupported by Fiddle: TTF_RenderGlyph_Solid()"
101
+ extern "SDL_Surface * TTF_RenderText_Shaded(TTF_Font *, char *, size_t, SDL_Color, SDL_Color)", unsupported: "SDL function unsupported by Fiddle: TTF_RenderText_Shaded()"
102
+ extern "SDL_Surface * TTF_RenderText_Shaded_Wrapped(TTF_Font *, char *, size_t, SDL_Color, SDL_Color, int)", unsupported: "SDL function unsupported by Fiddle: TTF_RenderText_Shaded_Wrapped()"
103
+ extern "SDL_Surface * TTF_RenderGlyph_Shaded(TTF_Font *, Uint32, SDL_Color, SDL_Color)", unsupported: "SDL function unsupported by Fiddle: TTF_RenderGlyph_Shaded()"
104
+ extern "SDL_Surface * TTF_RenderText_Blended(TTF_Font *, char *, size_t, SDL_Color)", unsupported: "SDL function unsupported by Fiddle: TTF_RenderText_Blended()"
105
+ extern "SDL_Surface * TTF_RenderText_Blended_Wrapped(TTF_Font *, char *, size_t, SDL_Color, int)", unsupported: "SDL function unsupported by Fiddle: TTF_RenderText_Blended_Wrapped()"
106
+ extern "SDL_Surface * TTF_RenderGlyph_Blended(TTF_Font *, Uint32, SDL_Color)", unsupported: "SDL function unsupported by Fiddle: TTF_RenderGlyph_Blended()"
107
+ extern "SDL_Surface * TTF_RenderText_LCD(TTF_Font *, char *, size_t, SDL_Color, SDL_Color)", unsupported: "SDL function unsupported by Fiddle: TTF_RenderText_LCD()"
108
+ extern "SDL_Surface * TTF_RenderText_LCD_Wrapped(TTF_Font *, char *, size_t, SDL_Color, SDL_Color, int)", unsupported: "SDL function unsupported by Fiddle: TTF_RenderText_LCD_Wrapped()"
109
+ extern "SDL_Surface * TTF_RenderGlyph_LCD(TTF_Font *, Uint32, SDL_Color, SDL_Color)", unsupported: "SDL function unsupported by Fiddle: TTF_RenderGlyph_LCD()"
110
+ const_set :TTF_Text, struct(
111
+ [
112
+ "char *text",
113
+ "int num_lines",
114
+ "int refcount",
115
+ "TTF_TextData *internal",
116
+ ]
117
+ )
118
+ extern "TTF_TextEngine * TTF_CreateSurfaceTextEngine(void)"
119
+ extern "bool TTF_DrawSurfaceText(TTF_Text *, int, int, SDL_Surface *)"
120
+ extern "void TTF_DestroySurfaceTextEngine(TTF_TextEngine *)"
121
+ extern "TTF_TextEngine * TTF_CreateRendererTextEngine(SDL_Renderer *)"
122
+ extern "TTF_TextEngine * TTF_CreateRendererTextEngineWithProperties(SDL_PropertiesID)"
123
+ extern "bool TTF_DrawRendererText(TTF_Text *, float, float)"
124
+ extern "void TTF_DestroyRendererTextEngine(TTF_TextEngine *)"
125
+ extern "TTF_TextEngine * TTF_CreateGPUTextEngine(SDL_GPUDevice *)"
126
+ extern "TTF_TextEngine * TTF_CreateGPUTextEngineWithProperties(SDL_PropertiesID)"
127
+ const_set :TTF_GPUAtlasDrawSequence, struct(
128
+ [
129
+ "SDL_GPUTexture *atlas_texture",
130
+ "SDL_FPoint *xy",
131
+ "SDL_FPoint *uv",
132
+ "int num_vertices",
133
+ "int *indices",
134
+ "int num_indices",
135
+ "TTF_ImageType image_type",
136
+ "TTF_GPUAtlasDrawSequence *next",
137
+ ]
138
+ )
139
+ extern "TTF_GPUAtlasDrawSequence * TTF_GetGPUTextDrawData(TTF_Text *)"
140
+ extern "void TTF_DestroyGPUTextEngine(TTF_TextEngine *)"
141
+ const_set :TTF_GPU_TEXTENGINE_WINDING_INVALID, 4294967295
142
+ const_set :TTF_GPU_TEXTENGINE_WINDING_CLOCKWISE, 0
143
+ const_set :TTF_GPU_TEXTENGINE_WINDING_COUNTER_CLOCKWISE, 1
144
+ typealias "TTF_GPUTextEngineWinding", "enum"
145
+ extern "void TTF_SetGPUTextEngineWinding(TTF_TextEngine *, TTF_GPUTextEngineWinding)"
146
+ extern "TTF_GPUTextEngineWinding TTF_GetGPUTextEngineWinding(TTF_TextEngine *)"
147
+ extern "TTF_Text * TTF_CreateText(TTF_TextEngine *, TTF_Font *, char *, size_t)"
148
+ extern "SDL_PropertiesID TTF_GetTextProperties(TTF_Text *)"
149
+ extern "bool TTF_SetTextEngine(TTF_Text *, TTF_TextEngine *)"
150
+ extern "TTF_TextEngine * TTF_GetTextEngine(TTF_Text *)"
151
+ extern "bool TTF_SetTextFont(TTF_Text *, TTF_Font *)"
152
+ extern "TTF_Font * TTF_GetTextFont(TTF_Text *)"
153
+ extern "bool TTF_SetTextDirection(TTF_Text *, TTF_Direction)"
154
+ extern "TTF_Direction TTF_GetTextDirection(TTF_Text *)"
155
+ extern "bool TTF_SetTextScript(TTF_Text *, Uint32)"
156
+ extern "Uint32 TTF_GetTextScript(TTF_Text *)"
157
+ extern "bool TTF_SetTextColor(TTF_Text *, Uint8, Uint8, Uint8, Uint8)"
158
+ extern "bool TTF_SetTextColorFloat(TTF_Text *, float, float, float, float)"
159
+ extern "bool TTF_GetTextColor(TTF_Text *, Uint8 *, Uint8 *, Uint8 *, Uint8 *)"
160
+ extern "bool TTF_GetTextColorFloat(TTF_Text *, float *, float *, float *, float *)"
161
+ extern "bool TTF_SetTextPosition(TTF_Text *, int, int)"
162
+ extern "bool TTF_GetTextPosition(TTF_Text *, int *, int *)"
163
+ extern "bool TTF_SetTextWrapWidth(TTF_Text *, int)"
164
+ extern "bool TTF_GetTextWrapWidth(TTF_Text *, int *)"
165
+ extern "bool TTF_SetTextWrapWhitespaceVisible(TTF_Text *, bool)"
166
+ extern "bool TTF_TextWrapWhitespaceVisible(TTF_Text *)"
167
+ extern "bool TTF_SetTextString(TTF_Text *, char *, size_t)"
168
+ extern "bool TTF_InsertTextString(TTF_Text *, int, char *, size_t)"
169
+ extern "bool TTF_AppendTextString(TTF_Text *, char *, size_t)"
170
+ extern "bool TTF_DeleteTextString(TTF_Text *, int, int)"
171
+ extern "bool TTF_GetTextSize(TTF_Text *, int *, int *)"
172
+ typealias "TTF_SubStringFlags", "Uint32"
173
+ const_set :TTF_SubString, struct(
174
+ [
175
+ "TTF_SubStringFlags flags",
176
+ "int offset",
177
+ "int length",
178
+ "int line_index",
179
+ "int cluster_index",
180
+ { "rect": SDL_Rect },
181
+ ]
182
+ )
183
+ extern "bool TTF_GetTextSubString(TTF_Text *, int, TTF_SubString *)"
184
+ extern "bool TTF_GetTextSubStringForLine(TTF_Text *, int, TTF_SubString *)"
185
+ extern "TTF_SubString ** TTF_GetTextSubStringsForRange(TTF_Text *, int, int, int *)"
186
+ extern "bool TTF_GetTextSubStringForPoint(TTF_Text *, int, int, TTF_SubString *)"
187
+ extern "bool TTF_GetPreviousTextSubString(TTF_Text *, TTF_SubString *, TTF_SubString *)"
188
+ extern "bool TTF_GetNextTextSubString(TTF_Text *, TTF_SubString *, TTF_SubString *)"
189
+ extern "bool TTF_UpdateText(TTF_Text *)"
190
+ extern "void TTF_DestroyText(TTF_Text *)"
191
+ extern "void TTF_CloseFont(TTF_Font *)"
192
+ extern "void TTF_Quit(void)"
193
+ extern "int TTF_WasInit(void)"
194
+ const_set :TTF_DRAW_COMMAND_NOOP, 0
195
+ const_set :TTF_DRAW_COMMAND_FILL, 1
196
+ const_set :TTF_DRAW_COMMAND_COPY, 2
197
+ typealias "TTF_DrawCommand", "enum"
198
+ const_set :TTF_FillOperation, struct(
199
+ [
200
+ "TTF_DrawCommand cmd",
201
+ { "rect": SDL_Rect },
202
+ ]
203
+ )
204
+ const_set :TTF_CopyOperation, struct(
205
+ [
206
+ "TTF_DrawCommand cmd",
207
+ "int text_offset",
208
+ "TTF_Font *glyph_font",
209
+ "Uint32 glyph_index",
210
+ { "src": SDL_Rect },
211
+ { "dst": SDL_Rect },
212
+ "void *reserved",
213
+ ]
214
+ )
215
+ const_set :TTF_DrawOperation, union(
216
+ [
217
+ "TTF_DrawCommand cmd",
218
+ { "fill": TTF_FillOperation },
219
+ { "copy": TTF_CopyOperation },
220
+ ]
221
+ )
222
+ const_set :TTF_TextData, struct(
223
+ [
224
+ "TTF_Font *font",
225
+ { "color": SDL_FColor },
226
+ "bool needs_layout_update",
227
+ "TTF_TextLayout *layout",
228
+ "int x",
229
+ "int y",
230
+ "int w",
231
+ "int h",
232
+ "int num_ops",
233
+ "TTF_DrawOperation *ops",
234
+ "int num_clusters",
235
+ "TTF_SubString *clusters",
236
+ "SDL_PropertiesID props",
237
+ "bool needs_engine_update",
238
+ "TTF_TextEngine *engine",
239
+ "void *engine_text",
240
+ ]
241
+ )
242
+ const_set :TTF_TextEngine, struct(
243
+ [
244
+ "Uint32 version",
245
+ "void *userdata",
246
+ "function (*CreateText)()",
247
+ "function (*DestroyText)()",
248
+ ]
249
+ )
250
+ }
251
+ private_constant :SDL_ttf
252
+
253
+ SDL_ttf.call
254
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SDL3
4
+ VERSION = "0.1.0"
5
+ end
data/lib/rbsdl3.rb ADDED
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+ require "fiddle/import"
3
+ require_relative "rbsdl3/version"
4
+
5
+ module SDL3
6
+ module BindingsRefinement
7
+ refine Fiddle::Importer do
8
+ def extern(signature, *opts, unsupported: nil)
9
+ return unless (h = handler rescue nil) && !h.handlers.empty?
10
+ return if unsupported&.tap { |msg|
11
+ name = signature[/(\w+)\(/, 1]
12
+ define_method(name) { raise NotImplementedError, msg, caller(1) }
13
+ module_function(name)
14
+ }
15
+ begin
16
+ f = super
17
+ rescue Fiddle::DLError => e
18
+ # Re-trigger type-resolution DLErrors here, limiting the stubbing path
19
+ # to symbol-resolution failures.
20
+ name, = begin
21
+ parse_signature(signature, type_alias)
22
+ rescue Fiddle::DLError
23
+ raise e
24
+ end
25
+ module_eval(<<-EOS, __FILE__, __LINE__+1)
26
+ def #{name}(...)
27
+ e = ::NotImplementedError.new("SDL symbol not found: #{name}()")
28
+ e.set_backtrace(caller(1))
29
+ ::Kernel.raise(e)
30
+ end
31
+ EOS
32
+ module_function(name)
33
+ else
34
+ name = f.name
35
+ module_eval("private def #{name}(...) = ::SDL3.#{name}(...)")
36
+ end
37
+ f
38
+ end
39
+ end
40
+
41
+ refine Module do
42
+ def const_set(name, value)
43
+ const_defined?(name, false) ? value : super
44
+ end
45
+ end
46
+ end
47
+
48
+ extend Fiddle::Importer
49
+
50
+ DLLOAD_TARGETS = %i[SDL SDL_image SDL_ttf].freeze
51
+ private_constant :DLLOAD_TARGETS
52
+
53
+ def self.dlload(*libs)
54
+ super
55
+
56
+ # Map C 'enum' to an int-compatible type (mirrors common ABI layouts)
57
+ typealias "enum", "int"
58
+
59
+ DLLOAD_TARGETS.each do |m|
60
+ const_get(m, false).call if const_defined?(m, false)
61
+ end
62
+ end
63
+
64
+ dlload
65
+ end
66
+ require_relative "rbsdl3/sdl"
data/sig/sdl3.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module SDL3
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbsdl3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - shinokaro
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: fiddle
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 1.1.7
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: 1.1.7
26
+ description: 'rbsdl3 is a Ruby binding to SDL3 that links against an SDL dynamic library
27
+ chosen at runtime.
28
+
29
+ '
30
+ email:
31
+ - shinokaro@hotmail.co.jp
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - CHANGELOG.md
37
+ - LICENSE
38
+ - README.md
39
+ - lib/rbsdl3.rb
40
+ - lib/rbsdl3/image.rb
41
+ - lib/rbsdl3/sdl.rb
42
+ - lib/rbsdl3/ttf.rb
43
+ - lib/rbsdl3/version.rb
44
+ - sig/sdl3.rbs
45
+ homepage: https://github.com/shinokaro/rbsdl3
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ homepage_uri: https://github.com/shinokaro/rbsdl3
50
+ source_code_uri: https://github.com/shinokaro/rbsdl3
51
+ changelog_uri: https://github.com/shinokaro/rbsdl3/CHANGELOG.md
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 3.1.0
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 4.0.3
67
+ specification_version: 4
68
+ summary: rbsdl3 is an SDL3 binding for Ruby implemented using Fiddle.
69
+ test_files: []