ruby2d 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/assets/README.md +7 -8
  3. data/assets/Rakefile +85 -0
  4. data/assets/include/SDL2/SDL.h +4 -1
  5. data/assets/include/SDL2/SDL_assert.h +3 -1
  6. data/assets/include/SDL2/SDL_atomic.h +20 -2
  7. data/assets/include/SDL2/SDL_audio.h +47 -14
  8. data/assets/include/SDL2/SDL_bits.h +10 -1
  9. data/assets/include/SDL2/SDL_blendmode.h +10 -7
  10. data/assets/include/SDL2/SDL_clipboard.h +1 -1
  11. data/assets/include/SDL2/SDL_config.h +24 -390
  12. data/assets/include/SDL2/SDL_config_android.h +182 -0
  13. data/assets/include/SDL2/SDL_config_iphoneos.h +207 -0
  14. data/assets/include/SDL2/SDL_config_macosx.h +266 -0
  15. data/assets/include/SDL2/SDL_config_minimal.h +85 -0
  16. data/assets/include/SDL2/SDL_config_os2.h +188 -0
  17. data/assets/include/SDL2/SDL_config_pandora.h +135 -0
  18. data/assets/include/SDL2/SDL_config_psp.h +165 -0
  19. data/assets/include/SDL2/SDL_config_windows.h +288 -0
  20. data/assets/include/SDL2/SDL_config_winrt.h +243 -0
  21. data/assets/include/SDL2/SDL_config_wiz.h +149 -0
  22. data/assets/include/SDL2/SDL_copying.h +20 -0
  23. data/assets/include/SDL2/SDL_cpuinfo.h +119 -8
  24. data/assets/include/SDL2/SDL_egl.h +4 -1
  25. data/assets/include/SDL2/SDL_endian.h +6 -3
  26. data/assets/include/SDL2/SDL_error.h +38 -2
  27. data/assets/include/SDL2/SDL_events.h +67 -28
  28. data/assets/include/SDL2/SDL_filesystem.h +1 -1
  29. data/assets/include/SDL2/SDL_gamecontroller.h +160 -9
  30. data/assets/include/SDL2/SDL_gesture.h +1 -1
  31. data/assets/include/SDL2/SDL_haptic.h +10 -1
  32. data/assets/include/SDL2/SDL_hints.h +460 -17
  33. data/assets/include/SDL2/SDL_image.h +2 -2
  34. data/assets/include/SDL2/SDL_joystick.h +115 -24
  35. data/assets/include/SDL2/SDL_keyboard.h +1 -1
  36. data/assets/include/SDL2/SDL_keycode.h +11 -9
  37. data/assets/include/SDL2/SDL_loadso.h +1 -1
  38. data/assets/include/SDL2/SDL_locale.h +101 -0
  39. data/assets/include/SDL2/SDL_log.h +3 -3
  40. data/assets/include/SDL2/SDL_main.h +28 -16
  41. data/assets/include/SDL2/SDL_messagebox.h +6 -4
  42. data/assets/include/SDL2/SDL_metal.h +117 -0
  43. data/assets/include/SDL2/SDL_misc.h +75 -0
  44. data/assets/include/SDL2/SDL_mouse.h +1 -1
  45. data/assets/include/SDL2/SDL_mutex.h +1 -1
  46. data/assets/include/SDL2/SDL_name.h +1 -1
  47. data/assets/include/SDL2/SDL_opengl.h +1 -1
  48. data/assets/include/SDL2/SDL_opengl_glext.h +3 -0
  49. data/assets/include/SDL2/SDL_opengles.h +1 -1
  50. data/assets/include/SDL2/SDL_opengles2.h +1 -1
  51. data/assets/include/SDL2/SDL_pixels.h +27 -18
  52. data/assets/include/SDL2/SDL_platform.h +1 -1
  53. data/assets/include/SDL2/SDL_power.h +1 -1
  54. data/assets/include/SDL2/SDL_quit.h +1 -1
  55. data/assets/include/SDL2/SDL_rect.h +29 -3
  56. data/assets/include/SDL2/SDL_render.h +230 -3
  57. data/assets/include/SDL2/SDL_revision.h +2 -2
  58. data/assets/include/SDL2/SDL_rwops.h +51 -22
  59. data/assets/include/SDL2/SDL_scancode.h +2 -2
  60. data/assets/include/SDL2/SDL_sensor.h +28 -12
  61. data/assets/include/SDL2/SDL_shape.h +1 -1
  62. data/assets/include/SDL2/SDL_stdinc.h +44 -4
  63. data/assets/include/SDL2/SDL_surface.h +12 -2
  64. data/assets/include/SDL2/SDL_system.h +50 -4
  65. data/assets/include/SDL2/SDL_syswm.h +39 -9
  66. data/assets/include/SDL2/SDL_test.h +1 -1
  67. data/assets/include/SDL2/SDL_test_assert.h +1 -1
  68. data/assets/include/SDL2/SDL_test_common.h +32 -2
  69. data/assets/include/SDL2/SDL_test_compare.h +1 -1
  70. data/assets/include/SDL2/SDL_test_crc32.h +1 -1
  71. data/assets/include/SDL2/SDL_test_font.h +1 -1
  72. data/assets/include/SDL2/SDL_test_fuzzer.h +1 -1
  73. data/assets/include/SDL2/SDL_test_harness.h +1 -1
  74. data/assets/include/SDL2/SDL_test_images.h +1 -1
  75. data/assets/include/SDL2/SDL_test_log.h +1 -1
  76. data/assets/include/SDL2/SDL_test_md5.h +1 -1
  77. data/assets/include/SDL2/SDL_test_memory.h +3 -3
  78. data/assets/include/SDL2/SDL_test_random.h +1 -1
  79. data/assets/include/SDL2/SDL_thread.h +34 -11
  80. data/assets/include/SDL2/SDL_timer.h +1 -1
  81. data/assets/include/SDL2/SDL_touch.h +17 -1
  82. data/assets/include/SDL2/SDL_types.h +1 -1
  83. data/assets/include/SDL2/SDL_version.h +2 -2
  84. data/assets/include/SDL2/SDL_video.h +11 -5
  85. data/assets/include/SDL2/SDL_vulkan.h +9 -11
  86. data/assets/include/SDL2/begin_code.h +8 -9
  87. data/assets/include/SDL2/close_code.h +4 -1
  88. data/assets/macos/lib/libFLAC.a +0 -0
  89. data/assets/macos/lib/libSDL2.a +0 -0
  90. data/assets/macos/lib/libSDL2_image.a +0 -0
  91. data/assets/macos/lib/libSDL2_mixer.a +0 -0
  92. data/assets/macos/lib/libSDL2_ttf.a +0 -0
  93. data/assets/macos/lib/libfreetype.a +0 -0
  94. data/assets/macos/lib/libjpeg.a +0 -0
  95. data/assets/macos/lib/libmpg123.a +0 -0
  96. data/assets/macos/lib/libogg.a +0 -0
  97. data/assets/macos/lib/libpng16.a +0 -0
  98. data/assets/macos/lib/libtiff.a +0 -0
  99. data/assets/macos/lib/libvorbis.a +0 -0
  100. data/assets/macos/lib/libvorbisfile.a +0 -0
  101. data/assets/macos/lib/libwebp.a +0 -0
  102. data/assets/mingw/bin/SDL2.dll +0 -0
  103. data/assets/mingw/bin/SDL2_image.dll +0 -0
  104. data/assets/mingw/bin/libpng16-16.dll +0 -0
  105. data/assets/mingw/bin/libtiff-5.dll +0 -0
  106. data/assets/mingw/bin/libwebp-7.dll +0 -0
  107. data/assets/mingw/lib/libSDL2.a +0 -0
  108. data/assets/mingw/lib/libSDL2.dll.a +0 -0
  109. data/assets/mingw/lib/libSDL2_image.a +0 -0
  110. data/assets/mingw/lib/libSDL2_image.dll.a +0 -0
  111. data/assets/mingw/lib/libSDL2_test.a +0 -0
  112. data/assets/mingw/lib/libSDL2main.a +0 -0
  113. data/bin/ruby2d +2 -1
  114. data/{assets/linux/simple2d/src/simple2d.c → ext/ruby2d/common.c} +32 -32
  115. data/{assets/linux/simple2d/src → ext/ruby2d}/controllers.c +17 -17
  116. data/ext/ruby2d/extconf.rb +6 -36
  117. data/{assets/linux/simple2d/src → ext/ruby2d}/gl.c +106 -85
  118. data/{assets/linux/simple2d/src → ext/ruby2d}/gl2.c +35 -20
  119. data/{assets/linux/simple2d/src → ext/ruby2d}/gl3.c +146 -58
  120. data/{assets/linux/simple2d/src → ext/ruby2d}/gles.c +41 -26
  121. data/{assets/linux/simple2d/src → ext/ruby2d}/image.c +16 -16
  122. data/{assets/linux/simple2d/src → ext/ruby2d}/input.c +8 -8
  123. data/{assets/linux/simple2d/src → ext/ruby2d}/music.c +30 -17
  124. data/ext/ruby2d/ruby2d.c +427 -290
  125. data/ext/ruby2d/ruby2d.h +789 -0
  126. data/{assets/linux/simple2d/src → ext/ruby2d}/shapes.c +18 -18
  127. data/ext/ruby2d/sound.c +118 -0
  128. data/{assets/linux/simple2d/src → ext/ruby2d}/sprite.c +16 -16
  129. data/{assets/linux/simple2d/src → ext/ruby2d}/text.c +22 -22
  130. data/ext/ruby2d/tileset.c +30 -0
  131. data/{assets/linux/simple2d/src → ext/ruby2d}/window.c +71 -60
  132. data/lib/ruby2d.rb +5 -2
  133. data/lib/ruby2d/circle.rb +18 -2
  134. data/lib/ruby2d/cli/build.rb +3 -8
  135. data/lib/ruby2d/cli/colorize.rb +10 -0
  136. data/lib/ruby2d/dsl.rb +16 -9
  137. data/lib/ruby2d/entity.rb +17 -0
  138. data/lib/ruby2d/font.rb +4 -3
  139. data/lib/ruby2d/image.rb +24 -1
  140. data/lib/ruby2d/line.rb +20 -0
  141. data/lib/ruby2d/music.rb +5 -0
  142. data/lib/ruby2d/pixel.rb +17 -0
  143. data/lib/ruby2d/quad.rb +18 -0
  144. data/lib/ruby2d/rectangle.rb +11 -2
  145. data/lib/ruby2d/renderable.rb +4 -8
  146. data/lib/ruby2d/sound.rb +5 -0
  147. data/lib/ruby2d/sprite.rb +35 -3
  148. data/lib/ruby2d/square.rb +9 -0
  149. data/lib/ruby2d/text.rb +22 -1
  150. data/lib/ruby2d/tileset.rb +69 -0
  151. data/lib/ruby2d/triangle.rb +16 -0
  152. data/lib/ruby2d/version.rb +1 -1
  153. data/lib/ruby2d/window.rb +249 -22
  154. metadata +41 -27
  155. data/assets/include/simple2d.h +0 -735
  156. data/assets/linux/simple2d/Makefile +0 -250
  157. data/assets/linux/simple2d/bin/simple2d.sh +0 -1249
  158. data/assets/linux/simple2d/include/simple2d.h +0 -735
  159. data/assets/linux/simple2d/src/sound.c +0 -56
  160. data/assets/macos/lib/libsimple2d.a +0 -0
  161. data/assets/mingw/lib/libsimple2d.a +0 -0
  162. data/lib/ruby2d/colorize.rb +0 -10
@@ -1,6 +1,6 @@
1
1
  // shapes.c
2
2
 
3
- #include "../include/simple2d.h"
3
+ #include "ruby2d.h"
4
4
 
5
5
 
6
6
  /*
@@ -11,7 +11,7 @@
11
11
  * rx The x coordinate to rotate around
12
12
  * ry The y coordinate to rotate around
13
13
  */
14
- S2D_GL_Point S2D_RotatePoint(S2D_GL_Point p, GLfloat angle, GLfloat rx, GLfloat ry) {
14
+ R2D_GL_Point R2D_RotatePoint(R2D_GL_Point p, GLfloat angle, GLfloat rx, GLfloat ry) {
15
15
 
16
16
  // Convert from degrees to radians
17
17
  angle = angle * M_PI / 180.0;
@@ -39,28 +39,28 @@ S2D_GL_Point S2D_RotatePoint(S2D_GL_Point p, GLfloat angle, GLfloat rx, GLfloat
39
39
  /*
40
40
  * Get the point to be rotated around given a position in a rectangle
41
41
  */
42
- S2D_GL_Point S2D_GetRectRotationPoint(int x, int y, int w, int h, int position) {
42
+ R2D_GL_Point R2D_GetRectRotationPoint(int x, int y, int w, int h, int position) {
43
43
 
44
- S2D_GL_Point p;
44
+ R2D_GL_Point p;
45
45
 
46
46
  switch (position) {
47
- case S2D_CENTER:
47
+ case R2D_CENTER:
48
48
  p.x = x + (w / 2.0);
49
49
  p.y = y + (h / 2.0);
50
50
  break;
51
- case S2D_TOP_LEFT:
51
+ case R2D_TOP_LEFT:
52
52
  p.x = x;
53
53
  p.y = y;
54
54
  break;
55
- case S2D_TOP_RIGHT:
55
+ case R2D_TOP_RIGHT:
56
56
  p.x = x + w;
57
57
  p.y = y;
58
58
  break;
59
- case S2D_BOTTOM_LEFT:
59
+ case R2D_BOTTOM_LEFT:
60
60
  p.x = x;
61
61
  p.y = y + h;
62
62
  break;
63
- case S2D_BOTTOM_RIGHT:
63
+ case R2D_BOTTOM_RIGHT:
64
64
  p.x = x + w;
65
65
  p.y = y + h;
66
66
  break;
@@ -73,14 +73,14 @@ S2D_GL_Point S2D_GetRectRotationPoint(int x, int y, int w, int h, int position)
73
73
  /*
74
74
  * Draw a triangle
75
75
  */
76
- void S2D_DrawTriangle(GLfloat x1, GLfloat y1,
76
+ void R2D_DrawTriangle(GLfloat x1, GLfloat y1,
77
77
  GLfloat r1, GLfloat g1, GLfloat b1, GLfloat a1,
78
78
  GLfloat x2, GLfloat y2,
79
79
  GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
80
80
  GLfloat x3, GLfloat y3,
81
81
  GLfloat r3, GLfloat g3, GLfloat b3, GLfloat a3) {
82
82
 
83
- S2D_GL_DrawTriangle(x1, y1, r1, g1, b1, a1,
83
+ R2D_GL_DrawTriangle(x1, y1, r1, g1, b1, a1,
84
84
  x2, y2, r2, g2, b2, a2,
85
85
  x3, y3, r3, g3, b3, a3);
86
86
  }
@@ -89,7 +89,7 @@ void S2D_DrawTriangle(GLfloat x1, GLfloat y1,
89
89
  /*
90
90
  * Draw a quad, using two triangles
91
91
  */
92
- void S2D_DrawQuad(GLfloat x1, GLfloat y1,
92
+ void R2D_DrawQuad(GLfloat x1, GLfloat y1,
93
93
  GLfloat r1, GLfloat g1, GLfloat b1, GLfloat a1,
94
94
  GLfloat x2, GLfloat y2,
95
95
  GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
@@ -98,11 +98,11 @@ void S2D_DrawQuad(GLfloat x1, GLfloat y1,
98
98
  GLfloat x4, GLfloat y4,
99
99
  GLfloat r4, GLfloat g4, GLfloat b4, GLfloat a4) {
100
100
 
101
- S2D_GL_DrawTriangle(x1, y1, r1, g1, b1, a1,
101
+ R2D_GL_DrawTriangle(x1, y1, r1, g1, b1, a1,
102
102
  x2, y2, r2, g2, b2, a2,
103
103
  x3, y3, r3, g3, b3, a3);
104
104
 
105
- S2D_GL_DrawTriangle(x3, y3, r3, g3, b3, a3,
105
+ R2D_GL_DrawTriangle(x3, y3, r3, g3, b3, a3,
106
106
  x4, y4, r4, g4, b4, a4,
107
107
  x1, y1, r1, g1, b1, a1);
108
108
  };
@@ -111,7 +111,7 @@ void S2D_DrawQuad(GLfloat x1, GLfloat y1,
111
111
  /*
112
112
  * Draw a line from a quad
113
113
  */
114
- void S2D_DrawLine(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2,
114
+ void R2D_DrawLine(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2,
115
115
  GLfloat width,
116
116
  GLfloat r1, GLfloat g1, GLfloat b1, GLfloat a1,
117
117
  GLfloat r2, GLfloat g2, GLfloat b2, GLfloat a2,
@@ -122,7 +122,7 @@ void S2D_DrawLine(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2,
122
122
  double x = ((x2 - x1) / length) * width / 2;
123
123
  double y = ((y2 - y1) / length) * width / 2;
124
124
 
125
- S2D_DrawQuad(
125
+ R2D_DrawQuad(
126
126
  x1 - y, y1 + x, r1, g1, b1, a1,
127
127
  x1 + y, y1 - x, r2, g2, b2, a2,
128
128
  x2 + y, y2 - x, r3, g3, b3, a3,
@@ -134,7 +134,7 @@ void S2D_DrawLine(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2,
134
134
  /*
135
135
  * Draw a circle from triangles
136
136
  */
137
- void S2D_DrawCircle(GLfloat x, GLfloat y, GLfloat radius, int sectors,
137
+ void R2D_DrawCircle(GLfloat x, GLfloat y, GLfloat radius, int sectors,
138
138
  GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
139
139
 
140
140
  double angle = 2 * M_PI / sectors;
@@ -147,7 +147,7 @@ void S2D_DrawCircle(GLfloat x, GLfloat y, GLfloat radius, int sectors,
147
147
  GLfloat x2 = x + radius * cos((i - 1) * angle);
148
148
  GLfloat y2 = y + radius * sin((i - 1) * angle);
149
149
 
150
- S2D_GL_DrawTriangle( x, y, r, g, b, a,
150
+ R2D_GL_DrawTriangle( x, y, r, g, b, a,
151
151
  x1, y1, r, g, b, a,
152
152
  x2, y2, r, g, b, a);
153
153
  }
@@ -0,0 +1,118 @@
1
+ // sound.c
2
+
3
+ #include "ruby2d.h"
4
+
5
+
6
+ /*
7
+ * Create a sound, given an audio file path
8
+ */
9
+ R2D_Sound *R2D_CreateSound(const char *path) {
10
+ R2D_Init();
11
+
12
+ // Check if sound file exists
13
+ if (!R2D_FileExists(path)) {
14
+ R2D_Error("R2D_CreateSound", "Sound file `%s` not found", path);
15
+ return NULL;
16
+ }
17
+
18
+ // Allocate the sound structure
19
+ R2D_Sound *snd = (R2D_Sound *) malloc(sizeof(R2D_Sound));
20
+ if (!snd) {
21
+ R2D_Error("R2D_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
+ R2D_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 R2D_PlaySound(R2D_Sound *snd) {
44
+ if (!snd) return;
45
+ Mix_PlayChannel(-1, snd->data, 0);
46
+ }
47
+
48
+
49
+ /*
50
+ * Get the sound's length in seconds
51
+ */
52
+ int R2D_GetSoundLength(R2D_Sound *snd) {
53
+ float points = 0;
54
+ float frames = 0;
55
+ int frequency = 0;
56
+ Uint16 format = 0;
57
+ int channels = 0;
58
+
59
+ // Populate the frequency, format and channel variables
60
+ if (!Mix_QuerySpec(&frequency, &format, &channels)) return -1; // Querying audio deails failed
61
+ if (!snd) return -1;
62
+
63
+ // points = bytes / samplesize
64
+ points = (snd->data->alen / ((format & 0xFF) / 8));
65
+
66
+ // frames = sample points / channels
67
+ frames = (points / channels);
68
+
69
+ // frames / frequency is seconds of audio
70
+ return ceil(frames / frequency);
71
+ }
72
+
73
+
74
+ /*
75
+ * Get the sound's volume
76
+ */
77
+ int R2D_GetSoundVolume(R2D_Sound *snd) {
78
+ if (!snd) return -1;
79
+ return ceil(Mix_VolumeChunk(snd->data, -1) * (100.0 / MIX_MAX_VOLUME));
80
+ }
81
+
82
+
83
+ /*
84
+ * Set the sound's volume a given percentage
85
+ */
86
+ void R2D_SetSoundVolume(R2D_Sound *snd, int volume) {
87
+ if (!snd) return;
88
+ // Set volume to be a percentage of the maximum mix volume
89
+ Mix_VolumeChunk(snd->data, (volume / 100.0) * MIX_MAX_VOLUME);
90
+ }
91
+
92
+
93
+ /*
94
+ * Get the sound mixer volume
95
+ */
96
+ int R2D_GetSoundMixVolume() {
97
+ return ceil(Mix_Volume(-1, -1) * (100.0 / MIX_MAX_VOLUME));
98
+ }
99
+
100
+
101
+ /*
102
+ * Set the sound mixer volume a given percentage
103
+ */
104
+ void R2D_SetSoundMixVolume(int volume) {
105
+ // This sets the volume value across all channels
106
+ // Set volume to be a percentage of the maximum mix volume
107
+ Mix_Volume(-1, (volume / 100.0) * MIX_MAX_VOLUME);
108
+ }
109
+
110
+
111
+ /*
112
+ * Free the sound
113
+ */
114
+ void R2D_FreeSound(R2D_Sound *snd) {
115
+ if (!snd) return;
116
+ Mix_FreeChunk(snd->data);
117
+ free(snd);
118
+ }
@@ -1,30 +1,30 @@
1
1
  // sprite.c
2
2
 
3
- #include "../include/simple2d.h"
3
+ #include "ruby2d.h"
4
4
 
5
5
 
6
6
  /*
7
7
  * Create a sprite, given an image file path
8
8
  */
9
- S2D_Sprite *S2D_CreateSprite(const char *path) {
9
+ R2D_Sprite *R2D_CreateSprite(const char *path) {
10
10
 
11
11
  // Check if image file exists
12
- if (!S2D_FileExists(path)) {
13
- S2D_Error("S2D_CreateSprite", "Sprite image file `%s` not found", path);
12
+ if (!R2D_FileExists(path)) {
13
+ R2D_Error("R2D_CreateSprite", "Sprite image file `%s` not found", path);
14
14
  return NULL;
15
15
  }
16
16
 
17
17
  // Allocate the sprite structure
18
- S2D_Sprite *spr = (S2D_Sprite *) malloc(sizeof(S2D_Sprite));
18
+ R2D_Sprite *spr = (R2D_Sprite *) malloc(sizeof(R2D_Sprite));
19
19
  if (!spr) {
20
- S2D_Error("S2D_CreateSprite", "Out of memory!");
20
+ R2D_Error("R2D_CreateSprite", "Out of memory!");
21
21
  return NULL;
22
22
  }
23
23
 
24
24
  // Load the sprite image file
25
- spr->img = S2D_CreateImage(path);
25
+ spr->img = R2D_CreateImage(path);
26
26
  if (!spr->img) {
27
- S2D_Error("S2D_CreateSprite", "Cannot create sprite image `%s`", path);
27
+ R2D_Error("R2D_CreateSprite", "Cannot create sprite image `%s`", path);
28
28
  free(spr);
29
29
  return NULL;
30
30
  }
@@ -60,7 +60,7 @@ S2D_Sprite *S2D_CreateSprite(const char *path) {
60
60
  /*
61
61
  * Clip a sprite
62
62
  */
63
- void S2D_ClipSprite(S2D_Sprite *spr, int x, int y, int w, int h) {
63
+ void R2D_ClipSprite(R2D_Sprite *spr, int x, int y, int w, int h) {
64
64
  if (!spr) return;
65
65
 
66
66
  // Calculate ratios
@@ -108,9 +108,9 @@ void S2D_ClipSprite(S2D_Sprite *spr, int x, int y, int w, int h) {
108
108
  /*
109
109
  * Rotate a sprite
110
110
  */
111
- void S2D_RotateSprite(S2D_Sprite *spr, GLfloat angle, int position) {
111
+ void R2D_RotateSprite(R2D_Sprite *spr, GLfloat angle, int position) {
112
112
 
113
- S2D_GL_Point p = S2D_GetRectRotationPoint(
113
+ R2D_GL_Point p = R2D_GetRectRotationPoint(
114
114
  spr->x, spr->y, spr->width, spr->height, position
115
115
  );
116
116
 
@@ -123,25 +123,25 @@ void S2D_RotateSprite(S2D_Sprite *spr, GLfloat angle, int position) {
123
123
  /*
124
124
  * Draw a sprite
125
125
  */
126
- void S2D_DrawSprite(S2D_Sprite *spr) {
126
+ void R2D_DrawSprite(R2D_Sprite *spr) {
127
127
  if (!spr) return;
128
128
 
129
129
  if (spr->img->texture_id == 0) {
130
- S2D_GL_CreateTexture(&spr->img->texture_id, spr->img->format,
130
+ R2D_GL_CreateTexture(&spr->img->texture_id, spr->img->format,
131
131
  spr->img->width, spr->img->height,
132
132
  spr->img->surface->pixels, GL_NEAREST);
133
133
  SDL_FreeSurface(spr->img->surface);
134
134
  }
135
135
 
136
- S2D_GL_DrawSprite(spr);
136
+ R2D_GL_DrawSprite(spr);
137
137
  }
138
138
 
139
139
 
140
140
  /*
141
141
  * Free a sprite
142
142
  */
143
- void S2D_FreeSprite(S2D_Sprite *spr) {
143
+ void R2D_FreeSprite(R2D_Sprite *spr) {
144
144
  if (!spr) return;
145
- S2D_FreeImage(spr->img);
145
+ R2D_FreeImage(spr->img);
146
146
  free(spr);
147
147
  }
@@ -1,17 +1,17 @@
1
1
  // text.c
2
2
 
3
- #include "../include/simple2d.h"
3
+ #include "ruby2d.h"
4
4
 
5
5
 
6
6
  /*
7
7
  * Create text, given a font file path, the message, and size
8
8
  */
9
- S2D_Text *S2D_CreateText(const char *font, const char *msg, int size) {
10
- S2D_Init();
9
+ R2D_Text *R2D_CreateText(const char *font, const char *msg, int size) {
10
+ R2D_Init();
11
11
 
12
12
  // Check if font file exists
13
- if (!S2D_FileExists(font)) {
14
- S2D_Error("S2D_CreateText", "Font file `%s` not found", font);
13
+ if (!R2D_FileExists(font)) {
14
+ R2D_Error("R2D_CreateText", "Font file `%s` not found", font);
15
15
  return NULL;
16
16
  }
17
17
 
@@ -19,16 +19,16 @@ S2D_Text *S2D_CreateText(const char *font, const char *msg, int size) {
19
19
  if (msg == NULL || strlen(msg) == 0) msg = " ";
20
20
 
21
21
  // Allocate the text structure
22
- S2D_Text *txt = (S2D_Text *) malloc(sizeof(S2D_Text));
22
+ R2D_Text *txt = (R2D_Text *) malloc(sizeof(R2D_Text));
23
23
  if (!txt) {
24
- S2D_Error("S2D_CreateText", "Out of memory!");
24
+ R2D_Error("R2D_CreateText", "Out of memory!");
25
25
  return NULL;
26
26
  }
27
27
 
28
28
  // Open the font
29
29
  txt->font_data = TTF_OpenFont(font, size);
30
30
  if (!txt->font_data) {
31
- S2D_Error("TTF_OpenFont", TTF_GetError());
31
+ R2D_Error("TTF_OpenFont", TTF_GetError());
32
32
  free(txt);
33
33
  return NULL;
34
34
  }
@@ -49,7 +49,7 @@ S2D_Text *S2D_CreateText(const char *font, const char *msg, int size) {
49
49
  txt->texture_id = 0;
50
50
 
51
51
  // Save the width and height of the text
52
- TTF_SizeText(txt->font_data, txt->msg, &txt->width, &txt->height);
52
+ TTF_SizeUTF8(txt->font_data, txt->msg, &txt->width, &txt->height);
53
53
 
54
54
  return txt;
55
55
  }
@@ -58,10 +58,10 @@ S2D_Text *S2D_CreateText(const char *font, const char *msg, int size) {
58
58
  /*
59
59
  * Set the text message
60
60
  */
61
- void S2D_SetText(S2D_Text *txt, const char *msg, ...) {
61
+ void R2D_SetText(R2D_Text *txt, const char *msg, ...) {
62
62
  if (!txt) return;
63
63
 
64
- // `msg` cannot be an empty string or NULL for TTF_SizeText
64
+ // `msg` cannot be an empty string or NULL for TTF_SizeUTF8
65
65
  if (msg == NULL || strlen(msg) == 0) msg = " ";
66
66
 
67
67
  // Format and store new text string
@@ -72,19 +72,19 @@ void S2D_SetText(S2D_Text *txt, const char *msg, ...) {
72
72
  va_end(args);
73
73
 
74
74
  // Save the width and height of the text
75
- TTF_SizeText(txt->font_data, txt->msg, &txt->width, &txt->height);
75
+ TTF_SizeUTF8(txt->font_data, txt->msg, &txt->width, &txt->height);
76
76
 
77
77
  // Delete the current texture so a new one can be generated
78
- S2D_GL_FreeTexture(&txt->texture_id);
78
+ R2D_GL_FreeTexture(&txt->texture_id);
79
79
  }
80
80
 
81
81
 
82
82
  /*
83
83
  * Rotate text
84
84
  */
85
- void S2D_RotateText(S2D_Text *txt, GLfloat angle, int position) {
85
+ void R2D_RotateText(R2D_Text *txt, GLfloat angle, int position) {
86
86
 
87
- S2D_GL_Point p = S2D_GetRectRotationPoint(
87
+ R2D_GL_Point p = R2D_GetRectRotationPoint(
88
88
  txt->x, txt->y, txt->width, txt->height, position
89
89
  );
90
90
 
@@ -97,33 +97,33 @@ void S2D_RotateText(S2D_Text *txt, GLfloat angle, int position) {
97
97
  /*
98
98
  * Draw text
99
99
  */
100
- void S2D_DrawText(S2D_Text *txt) {
100
+ void R2D_DrawText(R2D_Text *txt) {
101
101
  if (!txt) return;
102
102
 
103
103
  if (txt->texture_id == 0) {
104
104
  SDL_Color color = { 255, 255, 255 };
105
- txt->surface = TTF_RenderText_Blended(txt->font_data, txt->msg, color);
105
+ txt->surface = TTF_RenderUTF8_Blended(txt->font_data, txt->msg, color);
106
106
  if (!txt->surface) {
107
- S2D_Error("TTF_RenderText_Blended", TTF_GetError());
107
+ R2D_Error("TTF_RenderUTF8_Blended", TTF_GetError());
108
108
  return;
109
109
  }
110
- S2D_GL_CreateTexture(&txt->texture_id, GL_RGBA,
110
+ R2D_GL_CreateTexture(&txt->texture_id, GL_RGBA,
111
111
  txt->width, txt->height,
112
112
  txt->surface->pixels, GL_NEAREST);
113
113
  SDL_FreeSurface(txt->surface);
114
114
  }
115
115
 
116
- S2D_GL_DrawText(txt);
116
+ R2D_GL_DrawText(txt);
117
117
  }
118
118
 
119
119
 
120
120
  /*
121
121
  * Free the text
122
122
  */
123
- void S2D_FreeText(S2D_Text *txt) {
123
+ void R2D_FreeText(R2D_Text *txt) {
124
124
  if (!txt) return;
125
125
  free(txt->msg);
126
- S2D_GL_FreeTexture(&txt->texture_id);
126
+ R2D_GL_FreeTexture(&txt->texture_id);
127
127
  TTF_CloseFont(txt->font_data);
128
128
  free(txt);
129
129
  }