ruby2d 0.9.3 → 0.11.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.
- checksums.yaml +4 -4
- data/assets/README.md +7 -9
- data/assets/Rakefile +85 -0
- data/assets/include/SDL2/SDL.h +4 -1
- data/assets/include/SDL2/SDL_assert.h +3 -1
- data/assets/include/SDL2/SDL_atomic.h +20 -2
- data/assets/include/SDL2/SDL_audio.h +47 -14
- data/assets/include/SDL2/SDL_bits.h +10 -1
- data/assets/include/SDL2/SDL_blendmode.h +10 -7
- data/assets/include/SDL2/SDL_clipboard.h +1 -1
- data/assets/include/SDL2/SDL_config.h +24 -390
- data/assets/include/SDL2/SDL_config_android.h +182 -0
- data/assets/include/SDL2/SDL_config_iphoneos.h +207 -0
- data/assets/include/SDL2/SDL_config_macosx.h +266 -0
- data/assets/include/SDL2/SDL_config_minimal.h +85 -0
- data/assets/include/SDL2/SDL_config_os2.h +188 -0
- data/assets/include/SDL2/SDL_config_pandora.h +135 -0
- data/assets/include/SDL2/SDL_config_psp.h +165 -0
- data/assets/include/SDL2/SDL_config_windows.h +288 -0
- data/assets/include/SDL2/SDL_config_winrt.h +243 -0
- data/assets/include/SDL2/SDL_config_wiz.h +149 -0
- data/assets/include/SDL2/SDL_copying.h +20 -0
- data/assets/include/SDL2/SDL_cpuinfo.h +119 -8
- data/assets/include/SDL2/SDL_egl.h +4 -1
- data/assets/include/SDL2/SDL_endian.h +6 -3
- data/assets/include/SDL2/SDL_error.h +38 -2
- data/assets/include/SDL2/SDL_events.h +67 -28
- data/assets/include/SDL2/SDL_filesystem.h +1 -1
- data/assets/include/SDL2/SDL_gamecontroller.h +160 -9
- data/assets/include/SDL2/SDL_gesture.h +1 -1
- data/assets/include/SDL2/SDL_haptic.h +10 -1
- data/assets/include/SDL2/SDL_hints.h +460 -17
- data/assets/include/SDL2/SDL_image.h +2 -2
- data/assets/include/SDL2/SDL_joystick.h +115 -24
- data/assets/include/SDL2/SDL_keyboard.h +1 -1
- data/assets/include/SDL2/SDL_keycode.h +11 -9
- data/assets/include/SDL2/SDL_loadso.h +1 -1
- data/assets/include/SDL2/SDL_locale.h +101 -0
- data/assets/include/SDL2/SDL_log.h +3 -3
- data/assets/include/SDL2/SDL_main.h +28 -16
- data/assets/include/SDL2/SDL_messagebox.h +6 -4
- data/assets/include/SDL2/SDL_metal.h +117 -0
- data/assets/include/SDL2/SDL_misc.h +75 -0
- data/assets/include/SDL2/SDL_mouse.h +1 -1
- data/assets/include/SDL2/SDL_mutex.h +1 -1
- data/assets/include/SDL2/SDL_name.h +1 -1
- data/assets/include/SDL2/SDL_opengl.h +1 -1
- data/assets/include/SDL2/SDL_opengl_glext.h +3 -0
- data/assets/include/SDL2/SDL_opengles.h +1 -1
- data/assets/include/SDL2/SDL_opengles2.h +1 -1
- data/assets/include/SDL2/SDL_pixels.h +27 -18
- data/assets/include/SDL2/SDL_platform.h +1 -1
- data/assets/include/SDL2/SDL_power.h +1 -1
- data/assets/include/SDL2/SDL_quit.h +1 -1
- data/assets/include/SDL2/SDL_rect.h +29 -3
- data/assets/include/SDL2/SDL_render.h +230 -3
- data/assets/include/SDL2/SDL_revision.h +2 -2
- data/assets/include/SDL2/SDL_rwops.h +51 -22
- data/assets/include/SDL2/SDL_scancode.h +2 -2
- data/assets/include/SDL2/SDL_sensor.h +28 -12
- data/assets/include/SDL2/SDL_shape.h +1 -1
- data/assets/include/SDL2/SDL_stdinc.h +44 -4
- data/assets/include/SDL2/SDL_surface.h +12 -2
- data/assets/include/SDL2/SDL_system.h +50 -4
- data/assets/include/SDL2/SDL_syswm.h +39 -9
- data/assets/include/SDL2/SDL_test.h +1 -1
- data/assets/include/SDL2/SDL_test_assert.h +1 -1
- data/assets/include/SDL2/SDL_test_common.h +32 -2
- data/assets/include/SDL2/SDL_test_compare.h +1 -1
- data/assets/include/SDL2/SDL_test_crc32.h +1 -1
- data/assets/include/SDL2/SDL_test_font.h +1 -1
- data/assets/include/SDL2/SDL_test_fuzzer.h +1 -1
- data/assets/include/SDL2/SDL_test_harness.h +1 -1
- data/assets/include/SDL2/SDL_test_images.h +1 -1
- data/assets/include/SDL2/SDL_test_log.h +1 -1
- data/assets/include/SDL2/SDL_test_md5.h +1 -1
- data/assets/include/SDL2/SDL_test_memory.h +3 -3
- data/assets/include/SDL2/SDL_test_random.h +1 -1
- data/assets/include/SDL2/SDL_thread.h +34 -11
- data/assets/include/SDL2/SDL_timer.h +1 -1
- data/assets/include/SDL2/SDL_touch.h +17 -1
- data/assets/include/SDL2/SDL_types.h +1 -1
- data/assets/include/SDL2/SDL_version.h +2 -2
- data/assets/include/SDL2/SDL_video.h +11 -5
- data/assets/include/SDL2/SDL_vulkan.h +9 -11
- data/assets/include/SDL2/begin_code.h +8 -9
- data/assets/include/SDL2/close_code.h +4 -1
- data/assets/macos/lib/libFLAC.a +0 -0
- data/assets/macos/lib/libSDL2.a +0 -0
- data/assets/macos/lib/libSDL2_image.a +0 -0
- data/assets/macos/lib/libSDL2_mixer.a +0 -0
- data/assets/macos/lib/libSDL2_ttf.a +0 -0
- data/assets/macos/lib/libfreetype.a +0 -0
- data/assets/macos/lib/libjpeg.a +0 -0
- data/assets/macos/lib/libmpg123.a +0 -0
- data/assets/macos/lib/libogg.a +0 -0
- data/assets/macos/lib/libpng16.a +0 -0
- data/assets/macos/lib/libtiff.a +0 -0
- data/assets/macos/lib/libvorbis.a +0 -0
- data/assets/macos/lib/libvorbisfile.a +0 -0
- data/assets/macos/lib/libwebp.a +0 -0
- data/assets/mingw/bin/SDL2.dll +0 -0
- data/assets/mingw/bin/SDL2_image.dll +0 -0
- data/assets/mingw/bin/libpng16-16.dll +0 -0
- data/assets/mingw/bin/libtiff-5.dll +0 -0
- data/assets/mingw/bin/libwebp-7.dll +0 -0
- data/assets/mingw/lib/libSDL2.a +0 -0
- data/assets/mingw/lib/libSDL2.dll.a +0 -0
- data/assets/mingw/lib/libSDL2_image.a +0 -0
- data/assets/mingw/lib/libSDL2_image.dll.a +0 -0
- data/assets/mingw/lib/libSDL2_test.a +0 -0
- data/assets/mingw/lib/libSDL2main.a +0 -0
- data/bin/ruby2d +1 -0
- data/{assets/linux/simple2d/src/simple2d.c → ext/ruby2d/common.c} +32 -32
- data/{assets/linux/simple2d/src → ext/ruby2d}/controllers.c +17 -17
- data/ext/ruby2d/extconf.rb +36 -58
- data/ext/ruby2d/font.c +35 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/gl.c +72 -100
- data/ext/ruby2d/gl2.c +86 -0
- data/ext/ruby2d/gl3.c +305 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/gles.c +22 -81
- data/ext/ruby2d/image.c +58 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/input.c +8 -8
- data/{assets/linux/simple2d/src → ext/ruby2d}/music.c +30 -17
- data/ext/ruby2d/ruby2d.c +449 -439
- data/ext/ruby2d/ruby2d.h +652 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/shapes.c +18 -18
- data/ext/ruby2d/sound.c +118 -0
- data/ext/ruby2d/text.c +22 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/window.c +73 -62
- data/lib/ruby2d/circle.rb +21 -3
- data/lib/ruby2d/cli/build.rb +4 -7
- data/lib/ruby2d/dsl.rb +16 -9
- data/lib/ruby2d/entity.rb +17 -0
- data/lib/ruby2d/font.rb +23 -3
- data/lib/ruby2d/image.rb +35 -7
- data/lib/ruby2d/line.rb +23 -1
- data/lib/ruby2d/music.rb +5 -0
- data/lib/ruby2d/pixel.rb +17 -0
- data/lib/ruby2d/quad.rb +21 -1
- data/lib/ruby2d/rectangle.rb +12 -3
- data/lib/ruby2d/renderable.rb +4 -20
- data/lib/ruby2d/sound.rb +30 -0
- data/lib/ruby2d/sprite.rb +57 -75
- data/lib/ruby2d/square.rb +10 -1
- data/lib/ruby2d/text.rb +55 -12
- data/lib/ruby2d/texture.rb +28 -0
- data/lib/ruby2d/tileset.rb +87 -0
- data/lib/ruby2d/triangle.rb +19 -1
- data/lib/ruby2d/version.rb +1 -1
- data/lib/ruby2d/vertices.rb +84 -0
- data/lib/ruby2d/window.rb +259 -22
- data/lib/ruby2d.rb +6 -1
- metadata +41 -26
- data/assets/include/simple2d.h +0 -735
- data/assets/linux/simple2d/Makefile +0 -257
- data/assets/linux/simple2d/bin/simple2d.sh +0 -1312
- data/assets/linux/simple2d/include/simple2d.h +0 -735
- data/assets/linux/simple2d/src/gl2.c +0 -146
- data/assets/linux/simple2d/src/gl3.c +0 -275
- data/assets/linux/simple2d/src/image.c +0 -138
- data/assets/linux/simple2d/src/sound.c +0 -56
- data/assets/linux/simple2d/src/sprite.c +0 -147
- data/assets/linux/simple2d/src/text.c +0 -129
- data/assets/macos/lib/libsimple2d.a +0 -0
- data/assets/mingw/lib/libsimple2d.a +0 -0
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// sound.c
|
|
2
|
-
|
|
3
|
-
#include "../include/simple2d.h"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
* Create a sound, given an audio file path
|
|
8
|
-
*/
|
|
9
|
-
S2D_Sound *S2D_CreateSound(const char *path) {
|
|
10
|
-
S2D_Init();
|
|
11
|
-
|
|
12
|
-
// Check if sound file exists
|
|
13
|
-
if (!S2D_FileExists(path)) {
|
|
14
|
-
S2D_Error("S2D_CreateSound", "Sound file `%s` not found", path);
|
|
15
|
-
return NULL;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Allocate the sound structure
|
|
19
|
-
S2D_Sound *snd = (S2D_Sound *) malloc(sizeof(S2D_Sound));
|
|
20
|
-
if (!snd) {
|
|
21
|
-
S2D_Error("S2D_CreateSound", "Out of memory!");
|
|
22
|
-
return NULL;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Load the sound data from file
|
|
26
|
-
snd->data = Mix_LoadWAV(path);
|
|
27
|
-
if (!snd->data) {
|
|
28
|
-
S2D_Error("Mix_LoadWAV", Mix_GetError());
|
|
29
|
-
free(snd);
|
|
30
|
-
return NULL;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Initialize values
|
|
34
|
-
snd->path = path;
|
|
35
|
-
|
|
36
|
-
return snd;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
/*
|
|
41
|
-
* Play the sound
|
|
42
|
-
*/
|
|
43
|
-
void S2D_PlaySound(S2D_Sound *snd) {
|
|
44
|
-
if (!snd) return;
|
|
45
|
-
Mix_PlayChannel(-1, snd->data, 0);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/*
|
|
50
|
-
* Free the sound
|
|
51
|
-
*/
|
|
52
|
-
void S2D_FreeSound(S2D_Sound *snd) {
|
|
53
|
-
if (!snd) return;
|
|
54
|
-
Mix_FreeChunk(snd->data);
|
|
55
|
-
free(snd);
|
|
56
|
-
}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
// sprite.c
|
|
2
|
-
|
|
3
|
-
#include "../include/simple2d.h"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
* Create a sprite, given an image file path
|
|
8
|
-
*/
|
|
9
|
-
S2D_Sprite *S2D_CreateSprite(const char *path) {
|
|
10
|
-
|
|
11
|
-
// Check if image file exists
|
|
12
|
-
if (!S2D_FileExists(path)) {
|
|
13
|
-
S2D_Error("S2D_CreateSprite", "Sprite image file `%s` not found", path);
|
|
14
|
-
return NULL;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Allocate the sprite structure
|
|
18
|
-
S2D_Sprite *spr = (S2D_Sprite *) malloc(sizeof(S2D_Sprite));
|
|
19
|
-
if (!spr) {
|
|
20
|
-
S2D_Error("S2D_CreateSprite", "Out of memory!");
|
|
21
|
-
return NULL;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Load the sprite image file
|
|
25
|
-
spr->img = S2D_CreateImage(path);
|
|
26
|
-
if (!spr->img) {
|
|
27
|
-
S2D_Error("S2D_CreateSprite", "Cannot create sprite image `%s`", path);
|
|
28
|
-
free(spr);
|
|
29
|
-
return NULL;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Initialize values
|
|
33
|
-
spr->path = path;
|
|
34
|
-
spr->x = 0;
|
|
35
|
-
spr->y = 0;
|
|
36
|
-
spr->color.r = 1.f;
|
|
37
|
-
spr->color.g = 1.f;
|
|
38
|
-
spr->color.b = 1.f;
|
|
39
|
-
spr->color.a = 1.f;
|
|
40
|
-
spr->width = spr->img->width;
|
|
41
|
-
spr->height = spr->img->height;
|
|
42
|
-
spr->clip_width = spr->img->width;
|
|
43
|
-
spr->clip_height = spr->img->height;
|
|
44
|
-
spr->rotate = 0;
|
|
45
|
-
spr->rx = 0;
|
|
46
|
-
spr->ry = 0;
|
|
47
|
-
spr->tx1 = 0.f;
|
|
48
|
-
spr->ty1 = 0.f;
|
|
49
|
-
spr->tx2 = 1.f;
|
|
50
|
-
spr->ty2 = 0.f;
|
|
51
|
-
spr->tx3 = 1.f;
|
|
52
|
-
spr->ty3 = 1.f;
|
|
53
|
-
spr->tx4 = 0.f;
|
|
54
|
-
spr->ty4 = 1.f;
|
|
55
|
-
|
|
56
|
-
return spr;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/*
|
|
61
|
-
* Clip a sprite
|
|
62
|
-
*/
|
|
63
|
-
void S2D_ClipSprite(S2D_Sprite *spr, int x, int y, int w, int h) {
|
|
64
|
-
if (!spr) return;
|
|
65
|
-
|
|
66
|
-
// Calculate ratios
|
|
67
|
-
// rw = ratio width; rh = ratio height
|
|
68
|
-
double rw = w / (double)spr->img->width;
|
|
69
|
-
double rh = h / (double)spr->img->height;
|
|
70
|
-
|
|
71
|
-
// Apply ratios to x, y coordinates
|
|
72
|
-
// cx = crop x coord; cy = crop y coord
|
|
73
|
-
double cx = x * rw;
|
|
74
|
-
double cy = y * rh;
|
|
75
|
-
|
|
76
|
-
// Convert given width, height to doubles
|
|
77
|
-
// cw = crop width; ch = crop height
|
|
78
|
-
double cw = (double)w;
|
|
79
|
-
double ch = (double)h;
|
|
80
|
-
|
|
81
|
-
// Apply ratio to texture width and height
|
|
82
|
-
// tw = texture width; th = texture height
|
|
83
|
-
double tw = rw * w;
|
|
84
|
-
double th = rh * h;
|
|
85
|
-
|
|
86
|
-
// Calculate and store sprite texture values
|
|
87
|
-
|
|
88
|
-
spr->tx1 = cx / cw;
|
|
89
|
-
spr->ty1 = cy / ch;
|
|
90
|
-
|
|
91
|
-
spr->tx2 = (cx + tw) / cw;
|
|
92
|
-
spr->ty2 = cy / ch;
|
|
93
|
-
|
|
94
|
-
spr->tx3 = (cx + tw) / cw;
|
|
95
|
-
spr->ty3 = (cy + th) / ch;
|
|
96
|
-
|
|
97
|
-
spr->tx4 = cx / cw;
|
|
98
|
-
spr->ty4 = (cy + th) / ch;
|
|
99
|
-
|
|
100
|
-
// Store the sprite dimensions
|
|
101
|
-
spr->width = (spr->width / (double)spr->clip_width ) * w;
|
|
102
|
-
spr->height = (spr->height / (double)spr->clip_height) * h;
|
|
103
|
-
spr->clip_width = w;
|
|
104
|
-
spr->clip_height = h;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
/*
|
|
109
|
-
* Rotate a sprite
|
|
110
|
-
*/
|
|
111
|
-
void S2D_RotateSprite(S2D_Sprite *spr, GLfloat angle, int position) {
|
|
112
|
-
|
|
113
|
-
S2D_GL_Point p = S2D_GetRectRotationPoint(
|
|
114
|
-
spr->x, spr->y, spr->width, spr->height, position
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
spr->rotate = angle;
|
|
118
|
-
spr->rx = p.x;
|
|
119
|
-
spr->ry = p.y;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
/*
|
|
124
|
-
* Draw a sprite
|
|
125
|
-
*/
|
|
126
|
-
void S2D_DrawSprite(S2D_Sprite *spr) {
|
|
127
|
-
if (!spr) return;
|
|
128
|
-
|
|
129
|
-
if (spr->img->texture_id == 0) {
|
|
130
|
-
S2D_GL_CreateTexture(&spr->img->texture_id, spr->img->format,
|
|
131
|
-
spr->img->width, spr->img->height,
|
|
132
|
-
spr->img->surface->pixels, GL_NEAREST);
|
|
133
|
-
SDL_FreeSurface(spr->img->surface);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
S2D_GL_DrawSprite(spr);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
/*
|
|
141
|
-
* Free a sprite
|
|
142
|
-
*/
|
|
143
|
-
void S2D_FreeSprite(S2D_Sprite *spr) {
|
|
144
|
-
if (!spr) return;
|
|
145
|
-
S2D_FreeImage(spr->img);
|
|
146
|
-
free(spr);
|
|
147
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
// text.c
|
|
2
|
-
|
|
3
|
-
#include "../include/simple2d.h"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
* Create text, given a font file path, the message, and size
|
|
8
|
-
*/
|
|
9
|
-
S2D_Text *S2D_CreateText(const char *font, const char *msg, int size) {
|
|
10
|
-
S2D_Init();
|
|
11
|
-
|
|
12
|
-
// Check if font file exists
|
|
13
|
-
if (!S2D_FileExists(font)) {
|
|
14
|
-
S2D_Error("S2D_CreateText", "Font file `%s` not found", font);
|
|
15
|
-
return NULL;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// `msg` cannot be an empty string or NULL for TTF_SizeText
|
|
19
|
-
if (msg == NULL || strlen(msg) == 0) msg = " ";
|
|
20
|
-
|
|
21
|
-
// Allocate the text structure
|
|
22
|
-
S2D_Text *txt = (S2D_Text *) malloc(sizeof(S2D_Text));
|
|
23
|
-
if (!txt) {
|
|
24
|
-
S2D_Error("S2D_CreateText", "Out of memory!");
|
|
25
|
-
return NULL;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Open the font
|
|
29
|
-
txt->font_data = TTF_OpenFont(font, size);
|
|
30
|
-
if (!txt->font_data) {
|
|
31
|
-
S2D_Error("TTF_OpenFont", TTF_GetError());
|
|
32
|
-
free(txt);
|
|
33
|
-
return NULL;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Initialize values
|
|
37
|
-
txt->font = font;
|
|
38
|
-
txt->msg = (char *) malloc(strlen(msg) + 1 * sizeof(char));
|
|
39
|
-
strcpy(txt->msg, msg);
|
|
40
|
-
txt->x = 0;
|
|
41
|
-
txt->y = 0;
|
|
42
|
-
txt->color.r = 1.f;
|
|
43
|
-
txt->color.g = 1.f;
|
|
44
|
-
txt->color.b = 1.f;
|
|
45
|
-
txt->color.a = 1.f;
|
|
46
|
-
txt->rotate = 0;
|
|
47
|
-
txt->rx = 0;
|
|
48
|
-
txt->ry = 0;
|
|
49
|
-
txt->texture_id = 0;
|
|
50
|
-
|
|
51
|
-
// Save the width and height of the text
|
|
52
|
-
TTF_SizeText(txt->font_data, txt->msg, &txt->width, &txt->height);
|
|
53
|
-
|
|
54
|
-
return txt;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
/*
|
|
59
|
-
* Set the text message
|
|
60
|
-
*/
|
|
61
|
-
void S2D_SetText(S2D_Text *txt, const char *msg, ...) {
|
|
62
|
-
if (!txt) return;
|
|
63
|
-
|
|
64
|
-
// `msg` cannot be an empty string or NULL for TTF_SizeText
|
|
65
|
-
if (msg == NULL || strlen(msg) == 0) msg = " ";
|
|
66
|
-
|
|
67
|
-
// Format and store new text string
|
|
68
|
-
va_list args;
|
|
69
|
-
va_start(args, msg);
|
|
70
|
-
free(txt->msg);
|
|
71
|
-
vasprintf(&txt->msg, msg, args);
|
|
72
|
-
va_end(args);
|
|
73
|
-
|
|
74
|
-
// Save the width and height of the text
|
|
75
|
-
TTF_SizeText(txt->font_data, txt->msg, &txt->width, &txt->height);
|
|
76
|
-
|
|
77
|
-
// Delete the current texture so a new one can be generated
|
|
78
|
-
S2D_GL_FreeTexture(&txt->texture_id);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
/*
|
|
83
|
-
* Rotate text
|
|
84
|
-
*/
|
|
85
|
-
void S2D_RotateText(S2D_Text *txt, GLfloat angle, int position) {
|
|
86
|
-
|
|
87
|
-
S2D_GL_Point p = S2D_GetRectRotationPoint(
|
|
88
|
-
txt->x, txt->y, txt->width, txt->height, position
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
txt->rotate = angle;
|
|
92
|
-
txt->rx = p.x;
|
|
93
|
-
txt->ry = p.y;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
/*
|
|
98
|
-
* Draw text
|
|
99
|
-
*/
|
|
100
|
-
void S2D_DrawText(S2D_Text *txt) {
|
|
101
|
-
if (!txt) return;
|
|
102
|
-
|
|
103
|
-
if (txt->texture_id == 0) {
|
|
104
|
-
SDL_Color color = { 255, 255, 255 };
|
|
105
|
-
txt->surface = TTF_RenderText_Blended(txt->font_data, txt->msg, color);
|
|
106
|
-
if (!txt->surface) {
|
|
107
|
-
S2D_Error("TTF_RenderText_Blended", TTF_GetError());
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
S2D_GL_CreateTexture(&txt->texture_id, GL_RGBA,
|
|
111
|
-
txt->width, txt->height,
|
|
112
|
-
txt->surface->pixels, GL_NEAREST);
|
|
113
|
-
SDL_FreeSurface(txt->surface);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
S2D_GL_DrawText(txt);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
/*
|
|
121
|
-
* Free the text
|
|
122
|
-
*/
|
|
123
|
-
void S2D_FreeText(S2D_Text *txt) {
|
|
124
|
-
if (!txt) return;
|
|
125
|
-
free(txt->msg);
|
|
126
|
-
S2D_GL_FreeTexture(&txt->texture_id);
|
|
127
|
-
TTF_CloseFont(txt->font_data);
|
|
128
|
-
free(txt);
|
|
129
|
-
}
|
|
Binary file
|
|
Binary file
|