ruby2d 0.9.4 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/assets/include/SDL2/SDL.h +4 -1
  3. data/assets/include/SDL2/SDL_assert.h +3 -1
  4. data/assets/include/SDL2/SDL_atomic.h +1 -1
  5. data/assets/include/SDL2/SDL_audio.h +1 -1
  6. data/assets/include/SDL2/SDL_bits.h +1 -1
  7. data/assets/include/SDL2/SDL_blendmode.h +4 -1
  8. data/assets/include/SDL2/SDL_clipboard.h +1 -1
  9. data/assets/include/SDL2/SDL_config.h +1 -1
  10. data/assets/include/SDL2/SDL_config_android.h +7 -3
  11. data/assets/include/SDL2/SDL_config_iphoneos.h +16 -10
  12. data/assets/include/SDL2/SDL_config_macosx.h +40 -14
  13. data/assets/include/SDL2/SDL_config_minimal.h +1 -1
  14. data/assets/include/SDL2/SDL_config_os2.h +26 -8
  15. data/assets/include/SDL2/SDL_config_pandora.h +4 -2
  16. data/assets/include/SDL2/SDL_config_psp.h +2 -1
  17. data/assets/include/SDL2/SDL_config_windows.h +40 -9
  18. data/assets/include/SDL2/SDL_config_winrt.h +5 -2
  19. data/assets/include/SDL2/SDL_config_wiz.h +5 -2
  20. data/assets/include/SDL2/SDL_copying.h +1 -1
  21. data/assets/include/SDL2/SDL_cpuinfo.h +32 -3
  22. data/assets/include/SDL2/SDL_egl.h +4 -1
  23. data/assets/include/SDL2/SDL_endian.h +6 -3
  24. data/assets/include/SDL2/SDL_error.h +38 -2
  25. data/assets/include/SDL2/SDL_events.h +64 -28
  26. data/assets/include/SDL2/SDL_filesystem.h +1 -1
  27. data/assets/include/SDL2/SDL_gamecontroller.h +160 -9
  28. data/assets/include/SDL2/SDL_gesture.h +1 -1
  29. data/assets/include/SDL2/SDL_haptic.h +10 -1
  30. data/assets/include/SDL2/SDL_hints.h +316 -4
  31. data/assets/include/SDL2/SDL_joystick.h +115 -24
  32. data/assets/include/SDL2/SDL_keyboard.h +1 -1
  33. data/assets/include/SDL2/SDL_keycode.h +11 -9
  34. data/assets/include/SDL2/SDL_loadso.h +1 -1
  35. data/assets/include/SDL2/SDL_locale.h +101 -0
  36. data/assets/include/SDL2/SDL_log.h +3 -3
  37. data/assets/include/SDL2/SDL_main.h +1 -1
  38. data/assets/include/SDL2/SDL_messagebox.h +6 -4
  39. data/assets/include/SDL2/SDL_metal.h +117 -0
  40. data/assets/include/SDL2/SDL_misc.h +75 -0
  41. data/assets/include/SDL2/SDL_mouse.h +1 -1
  42. data/assets/include/SDL2/SDL_mutex.h +1 -1
  43. data/assets/include/SDL2/SDL_name.h +1 -1
  44. data/assets/include/SDL2/SDL_opengl.h +1 -1
  45. data/assets/include/SDL2/SDL_opengl_glext.h +3 -0
  46. data/assets/include/SDL2/SDL_opengles.h +1 -1
  47. data/assets/include/SDL2/SDL_opengles2.h +1 -1
  48. data/assets/include/SDL2/SDL_pixels.h +25 -16
  49. data/assets/include/SDL2/SDL_platform.h +1 -1
  50. data/assets/include/SDL2/SDL_power.h +1 -1
  51. data/assets/include/SDL2/SDL_quit.h +1 -1
  52. data/assets/include/SDL2/SDL_rect.h +1 -1
  53. data/assets/include/SDL2/SDL_render.h +63 -3
  54. data/assets/include/SDL2/SDL_revision.h +2 -2
  55. data/assets/include/SDL2/SDL_rwops.h +2 -10
  56. data/assets/include/SDL2/SDL_scancode.h +1 -1
  57. data/assets/include/SDL2/SDL_sensor.h +25 -9
  58. data/assets/include/SDL2/SDL_shape.h +1 -1
  59. data/assets/include/SDL2/SDL_stdinc.h +44 -4
  60. data/assets/include/SDL2/SDL_surface.h +11 -2
  61. data/assets/include/SDL2/SDL_system.h +50 -4
  62. data/assets/include/SDL2/SDL_syswm.h +29 -2
  63. data/assets/include/SDL2/SDL_test.h +1 -1
  64. data/assets/include/SDL2/SDL_test_assert.h +1 -1
  65. data/assets/include/SDL2/SDL_test_common.h +14 -1
  66. data/assets/include/SDL2/SDL_test_compare.h +1 -1
  67. data/assets/include/SDL2/SDL_test_crc32.h +1 -1
  68. data/assets/include/SDL2/SDL_test_font.h +1 -1
  69. data/assets/include/SDL2/SDL_test_fuzzer.h +1 -1
  70. data/assets/include/SDL2/SDL_test_harness.h +1 -1
  71. data/assets/include/SDL2/SDL_test_images.h +1 -1
  72. data/assets/include/SDL2/SDL_test_log.h +1 -1
  73. data/assets/include/SDL2/SDL_test_md5.h +1 -1
  74. data/assets/include/SDL2/SDL_test_memory.h +1 -1
  75. data/assets/include/SDL2/SDL_test_random.h +1 -1
  76. data/assets/include/SDL2/SDL_thread.h +34 -11
  77. data/assets/include/SDL2/SDL_timer.h +1 -1
  78. data/assets/include/SDL2/SDL_touch.h +1 -1
  79. data/assets/include/SDL2/SDL_types.h +1 -1
  80. data/assets/include/SDL2/SDL_version.h +2 -2
  81. data/assets/include/SDL2/SDL_video.h +11 -5
  82. data/assets/include/SDL2/SDL_vulkan.h +6 -8
  83. data/assets/include/SDL2/begin_code.h +5 -9
  84. data/assets/include/SDL2/close_code.h +1 -1
  85. data/assets/macos/lib/libFLAC.a +0 -0
  86. data/assets/macos/lib/libSDL2.a +0 -0
  87. data/assets/macos/lib/libSDL2_image.a +0 -0
  88. data/assets/macos/lib/libSDL2_mixer.a +0 -0
  89. data/assets/macos/lib/libSDL2_ttf.a +0 -0
  90. data/assets/macos/lib/libfreetype.a +0 -0
  91. data/assets/macos/lib/libjpeg.a +0 -0
  92. data/assets/macos/lib/libmodplug.a +0 -0
  93. data/assets/macos/lib/libmpg123.a +0 -0
  94. data/assets/macos/lib/libogg.a +0 -0
  95. data/assets/macos/lib/libpng16.a +0 -0
  96. data/assets/macos/lib/libtiff.a +0 -0
  97. data/assets/macos/lib/libvorbis.a +0 -0
  98. data/assets/macos/lib/libvorbisfile.a +0 -0
  99. data/assets/macos/lib/libwebp.a +0 -0
  100. data/assets/mingw/bin/SDL2.dll +0 -0
  101. data/assets/mingw/lib/libSDL2.a +0 -0
  102. data/assets/mingw/lib/libSDL2.dll.a +0 -0
  103. data/assets/mingw/lib/libSDL2_test.a +0 -0
  104. data/assets/mingw/lib/libSDL2main.a +0 -0
  105. data/bin/ruby2d +1 -0
  106. data/{assets/linux/simple2d/src/simple2d.c → ext/ruby2d/common.c} +32 -32
  107. data/{assets/linux/simple2d/src → ext/ruby2d}/controllers.c +17 -17
  108. data/ext/ruby2d/extconf.rb +37 -59
  109. data/ext/ruby2d/font.c +35 -0
  110. data/{assets/linux/simple2d/src → ext/ruby2d}/gl.c +66 -98
  111. data/ext/ruby2d/gl2.c +86 -0
  112. data/{assets/linux/simple2d/src → ext/ruby2d}/gl3.c +69 -112
  113. data/{assets/linux/simple2d/src → ext/ruby2d}/gles.c +22 -81
  114. data/ext/ruby2d/image.c +58 -0
  115. data/{assets/linux/simple2d/src → ext/ruby2d}/input.c +8 -8
  116. data/{assets/linux/simple2d/src → ext/ruby2d}/music.c +30 -17
  117. data/ext/ruby2d/ruby2d.c +449 -439
  118. data/ext/ruby2d/ruby2d.h +652 -0
  119. data/{assets/linux/simple2d/src → ext/ruby2d}/shapes.c +18 -18
  120. data/{assets/linux/simple2d/src → ext/ruby2d}/sound.c +39 -14
  121. data/ext/ruby2d/text.c +22 -0
  122. data/{assets/linux/simple2d/src → ext/ruby2d}/window.c +63 -63
  123. data/lib/ruby2d/circle.rb +21 -3
  124. data/lib/ruby2d/cli/build.rb +4 -7
  125. data/lib/ruby2d/dsl.rb +16 -9
  126. data/lib/ruby2d/entity.rb +17 -0
  127. data/lib/ruby2d/font.rb +23 -3
  128. data/lib/ruby2d/image.rb +35 -7
  129. data/lib/ruby2d/line.rb +23 -1
  130. data/lib/ruby2d/music.rb +5 -0
  131. data/lib/ruby2d/pixel.rb +17 -0
  132. data/lib/ruby2d/quad.rb +21 -1
  133. data/lib/ruby2d/rectangle.rb +12 -3
  134. data/lib/ruby2d/renderable.rb +4 -20
  135. data/lib/ruby2d/sound.rb +30 -0
  136. data/lib/ruby2d/sprite.rb +57 -75
  137. data/lib/ruby2d/square.rb +10 -1
  138. data/lib/ruby2d/text.rb +55 -12
  139. data/lib/ruby2d/texture.rb +28 -0
  140. data/lib/ruby2d/tileset.rb +87 -0
  141. data/lib/ruby2d/triangle.rb +19 -1
  142. data/lib/ruby2d/version.rb +1 -1
  143. data/lib/ruby2d/vertices.rb +84 -0
  144. data/lib/ruby2d/window.rb +259 -22
  145. data/lib/ruby2d.rb +6 -1
  146. metadata +30 -26
  147. data/assets/include/simple2d.h +0 -757
  148. data/assets/linux/simple2d/Makefile +0 -260
  149. data/assets/linux/simple2d/bin/simple2d.sh +0 -1318
  150. data/assets/linux/simple2d/include/simple2d.h +0 -757
  151. data/assets/linux/simple2d/src/gl2.c +0 -146
  152. data/assets/linux/simple2d/src/image.c +0 -138
  153. data/assets/linux/simple2d/src/sprite.c +0 -147
  154. data/assets/linux/simple2d/src/text.c +0 -129
  155. data/assets/macos/lib/libsimple2d.a +0 -0
  156. data/assets/mingw/lib/libsimple2d.a +0 -0
Binary file
Binary file
Binary file
Binary file
data/bin/ruby2d CHANGED
@@ -115,6 +115,7 @@ when 'launch'
115
115
  else
116
116
  puts usage_launch
117
117
  end
118
+ # TODO: Need add this functionality to the gem
118
119
  when 'simulator'
119
120
  case ARGV[1]
120
121
  when '--list'
@@ -1,11 +1,11 @@
1
- // Simple 2D Shared functions and data
1
+ // Ruby 2D Shared functions and data
2
2
 
3
- #include "../include/simple2d.h"
3
+ #include "ruby2d.h"
4
4
 
5
- // Initalize S2D shared data
6
- bool S2D_diagnostics = false;
5
+ // Initalize shared data
6
+ bool R2D_diagnostics = false;
7
7
 
8
- // S2D initialization status
8
+ // Initialization status
9
9
  static bool initted = false;
10
10
 
11
11
 
@@ -30,7 +30,7 @@ int vasprintf(char **strp, const char *fmt, va_list ap) {
30
30
  /*
31
31
  * Checks if a file exists and can be accessed
32
32
  */
33
- bool S2D_FileExists(const char *path) {
33
+ bool R2D_FileExists(const char *path) {
34
34
  if (!path) return false;
35
35
 
36
36
  if (access(path, F_OK) != -1) {
@@ -44,22 +44,22 @@ bool S2D_FileExists(const char *path) {
44
44
  /*
45
45
  * Logs standard messages to the console
46
46
  */
47
- void S2D_Log(int type, const char *msg, ...) {
47
+ void R2D_Log(int type, const char *msg, ...) {
48
48
 
49
49
  // Always log if diagnostics set, or if a warning or error message
50
- if (S2D_diagnostics || type != S2D_INFO) {
50
+ if (R2D_diagnostics || type != R2D_INFO) {
51
51
 
52
52
  va_list args;
53
53
  va_start(args, msg);
54
54
 
55
55
  switch (type) {
56
- case S2D_INFO:
56
+ case R2D_INFO:
57
57
  printf("\033[1;36mInfo:\033[0m ");
58
58
  break;
59
- case S2D_WARN:
59
+ case R2D_WARN:
60
60
  printf("\033[1;33mWarning:\033[0m ");
61
61
  break;
62
- case S2D_ERROR:
62
+ case R2D_ERROR:
63
63
  printf("\033[1;31mError:\033[0m ");
64
64
  break;
65
65
  }
@@ -72,14 +72,14 @@ void S2D_Log(int type, const char *msg, ...) {
72
72
 
73
73
 
74
74
  /*
75
- * Logs Simple 2D errors to the console, with caller and message body
75
+ * Logs Ruby 2D errors to the console, with caller and message body
76
76
  */
77
- void S2D_Error(const char *caller, const char *msg, ...) {
77
+ void R2D_Error(const char *caller, const char *msg, ...) {
78
78
  va_list args;
79
79
  va_start(args, msg);
80
80
  char *fmsg;
81
81
  vasprintf(&fmsg, msg, args);
82
- S2D_Log(S2D_ERROR, "(%s) %s", caller, fmsg);
82
+ R2D_Log(R2D_ERROR, "(%s) %s", caller, fmsg);
83
83
  free(fmsg);
84
84
  va_end(args);
85
85
  }
@@ -88,15 +88,15 @@ void S2D_Error(const char *caller, const char *msg, ...) {
88
88
  /*
89
89
  * Enable/disable logging of diagnostics
90
90
  */
91
- void S2D_Diagnostics(bool status) {
92
- S2D_diagnostics = status;
91
+ void R2D_Diagnostics(bool status) {
92
+ R2D_diagnostics = status;
93
93
  }
94
94
 
95
95
 
96
96
  /*
97
97
  * Enable terminal colors in Windows
98
98
  */
99
- void S2D_Windows_EnableTerminalColors() {
99
+ void R2D_Windows_EnableTerminalColors() {
100
100
  #if WINDOWS
101
101
  HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
102
102
  DWORD dwMode = 0;
@@ -108,25 +108,25 @@ void S2D_Windows_EnableTerminalColors() {
108
108
 
109
109
 
110
110
  /*
111
- * Initialize Simple 2D subsystems
111
+ * Initialize Ruby 2D subsystems
112
112
  */
113
- bool S2D_Init() {
113
+ bool R2D_Init() {
114
114
  if (initted) return true;
115
115
 
116
116
  // Enable terminal colors in Windows
117
- S2D_Windows_EnableTerminalColors();
117
+ R2D_Windows_EnableTerminalColors();
118
118
 
119
- S2D_Log(S2D_INFO, "Initializing Simple 2D");
119
+ R2D_Log(R2D_INFO, "Initializing Ruby 2D");
120
120
 
121
121
  // Initialize SDL
122
122
  if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
123
- S2D_Error("SDL_Init", SDL_GetError());
123
+ R2D_Error("SDL_Init", SDL_GetError());
124
124
  return false;
125
125
  }
126
126
 
127
127
  // Initialize SDL_ttf
128
128
  if (TTF_Init() != 0) {
129
- S2D_Error("TTF_Init", TTF_GetError());
129
+ R2D_Error("TTF_Init", TTF_GetError());
130
130
  return false;
131
131
  }
132
132
 
@@ -142,17 +142,17 @@ bool S2D_Init() {
142
142
  // It's version 2.0.2, don't check for Mix_Init errors
143
143
  } else {
144
144
  if ((mix_initted&mix_flags) != mix_flags) {
145
- S2D_Error("Mix_Init", Mix_GetError());
145
+ R2D_Error("Mix_Init", Mix_GetError());
146
146
  }
147
147
  }
148
148
 
149
149
  if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) != 0) {
150
- S2D_Error("Mix_OpenAudio", Mix_GetError());
150
+ R2D_Error("Mix_OpenAudio", Mix_GetError());
151
151
  return false;
152
152
  }
153
153
 
154
- // Call `S2D_Quit` at program exit
155
- atexit(S2D_Quit);
154
+ // Call `R2D_Quit` at program exit
155
+ atexit(R2D_Quit);
156
156
 
157
157
  // All subsystems initted
158
158
  initted = true;
@@ -161,10 +161,10 @@ bool S2D_Init() {
161
161
 
162
162
 
163
163
  /*
164
- * Gets the primary display's dimentions
164
+ * Gets the primary display's dimensions
165
165
  */
166
- void S2D_GetDisplayDimensions(int *w, int *h) {
167
- S2D_Init();
166
+ void R2D_GetDisplayDimensions(int *w, int *h) {
167
+ R2D_Init();
168
168
  SDL_DisplayMode dm;
169
169
  SDL_GetCurrentDisplayMode(0, &dm);
170
170
  *w = dm.w;
@@ -173,9 +173,9 @@ void S2D_GetDisplayDimensions(int *w, int *h) {
173
173
 
174
174
 
175
175
  /*
176
- * Quits Simple 2D subsystems
176
+ * Quits Ruby 2D subsystems
177
177
  */
178
- void S2D_Quit() {
178
+ void R2D_Quit() {
179
179
  IMG_Quit();
180
180
  Mix_CloseAudio();
181
181
  Mix_Quit();
@@ -1,6 +1,6 @@
1
1
  // controllers.c
2
2
 
3
- #include "../include/simple2d.h"
3
+ #include "ruby2d.h"
4
4
 
5
5
  // Stores the last joystick instance ID seen by the system. These instance IDs
6
6
  // are unique and increment with each new joystick connected.
@@ -10,7 +10,7 @@ static int last_intance_id = -1;
10
10
  /*
11
11
  * Add controller mapping from string
12
12
  */
13
- void S2D_AddControllerMapping(const char *map) {
13
+ void R2D_AddControllerMapping(const char *map) {
14
14
  int result = SDL_GameControllerAddMapping(map);
15
15
 
16
16
  char guid[33];
@@ -18,13 +18,13 @@ void S2D_AddControllerMapping(const char *map) {
18
18
 
19
19
  switch (result) {
20
20
  case 1:
21
- S2D_Log(S2D_INFO, "Mapping added for GUID: %s", guid);
21
+ R2D_Log(R2D_INFO, "Mapping added for GUID: %s", guid);
22
22
  break;
23
23
  case 0:
24
- S2D_Log(S2D_INFO, "Mapping updated for GUID: %s", guid);
24
+ R2D_Log(R2D_INFO, "Mapping updated for GUID: %s", guid);
25
25
  break;
26
26
  case -1:
27
- S2D_Error("SDL_GameControllerAddMapping", SDL_GetError());
27
+ R2D_Error("SDL_GameControllerAddMapping", SDL_GetError());
28
28
  break;
29
29
  }
30
30
  }
@@ -33,17 +33,17 @@ void S2D_AddControllerMapping(const char *map) {
33
33
  /*
34
34
  * Add controller mappings from the specified file
35
35
  */
36
- void S2D_AddControllerMappingsFromFile(const char *path) {
37
- if (!S2D_FileExists(path)) {
38
- S2D_Log(S2D_WARN, "Controller mappings file not found: %s", path);
36
+ void R2D_AddControllerMappingsFromFile(const char *path) {
37
+ if (!R2D_FileExists(path)) {
38
+ R2D_Log(R2D_WARN, "Controller mappings file not found: %s", path);
39
39
  return;
40
40
  }
41
41
 
42
42
  int mappings_added = SDL_GameControllerAddMappingsFromFile(path);
43
43
  if (mappings_added == -1) {
44
- S2D_Error("SDL_GameControllerAddMappingsFromFile", SDL_GetError());
44
+ R2D_Error("SDL_GameControllerAddMappingsFromFile", SDL_GetError());
45
45
  } else {
46
- S2D_Log(S2D_INFO, "Added %i controller mapping(s)", mappings_added);
46
+ R2D_Log(R2D_INFO, "Added %i controller mapping(s)", mappings_added);
47
47
  }
48
48
  }
49
49
 
@@ -51,7 +51,7 @@ void S2D_AddControllerMappingsFromFile(const char *path) {
51
51
  /*
52
52
  * Check if joystick is a controller
53
53
  */
54
- bool S2D_IsController(SDL_JoystickID id) {
54
+ bool R2D_IsController(SDL_JoystickID id) {
55
55
  return SDL_GameControllerFromInstanceID(id) == NULL ? false : true;
56
56
  }
57
57
 
@@ -59,7 +59,7 @@ bool S2D_IsController(SDL_JoystickID id) {
59
59
  /*
60
60
  * Open controllers and joysticks
61
61
  */
62
- void S2D_OpenControllers() {
62
+ void R2D_OpenControllers() {
63
63
 
64
64
  char guid_str[33];
65
65
 
@@ -78,9 +78,9 @@ void S2D_OpenControllers() {
78
78
 
79
79
  if (intance_id > last_intance_id) {
80
80
  if (controller) {
81
- S2D_Log(S2D_INFO, "Controller #%i: %s\n GUID: %s", intance_id, SDL_GameControllerName(controller), guid_str);
81
+ R2D_Log(R2D_INFO, "Controller #%i: %s\n GUID: %s", intance_id, SDL_GameControllerName(controller), guid_str);
82
82
  } else {
83
- S2D_Log(S2D_ERROR, "Could not open controller #%i: %s", intance_id, SDL_GetError());
83
+ R2D_Log(R2D_ERROR, "Could not open controller #%i: %s", intance_id, SDL_GetError());
84
84
  }
85
85
  last_intance_id = intance_id;
86
86
  }
@@ -91,18 +91,18 @@ void S2D_OpenControllers() {
91
91
  SDL_JoystickID intance_id = SDL_JoystickInstanceID(joy);
92
92
 
93
93
  if (!joy) {
94
- S2D_Log(S2D_ERROR, "Could not open controller");
94
+ R2D_Log(R2D_ERROR, "Could not open controller");
95
95
  } else if(intance_id > last_intance_id) {
96
96
  SDL_JoystickGetGUIDString(
97
97
  SDL_JoystickGetGUID(joy),
98
98
  guid_str, 33
99
99
  );
100
- S2D_Log(S2D_INFO,
100
+ R2D_Log(R2D_INFO,
101
101
  "Controller #%i: %s\n GUID: %s\n Axes: %d\n Buttons: %d\n Balls: %d",
102
102
  intance_id, SDL_JoystickName(joy), guid_str, SDL_JoystickNumAxes(joy),
103
103
  SDL_JoystickNumButtons(joy), SDL_JoystickNumBalls(joy)
104
104
  );
105
- S2D_Log(S2D_WARN, "Controller #%i does not have a mapping available", intance_id);
105
+ R2D_Log(R2D_WARN, "Controller #%i does not have a mapping available", intance_id);
106
106
  last_intance_id = intance_id;
107
107
  }
108
108
  }
@@ -1,7 +1,6 @@
1
1
  require 'mkmf'
2
2
  require_relative '../../lib/ruby2d/cli/colorize'
3
3
 
4
- S2D_VERSION = '1.2.0' # Simple 2D minimum version required
5
4
  $errors = [] # Holds errors
6
5
 
7
6
  # Set the OS platform
@@ -13,6 +12,8 @@ when /linux/
13
12
  if `cat /etc/os-release` =~ /raspbian/
14
13
  $platform = :linux_rpi
15
14
  end
15
+ when /bsd/
16
+ $platform = :bsd
16
17
  when /mingw/
17
18
  $platform = :windows
18
19
  else
@@ -31,27 +32,6 @@ def print_errors
31
32
  end
32
33
 
33
34
 
34
- # Check that Simple 2D is installed and meets minimum version requirements
35
- def check_s2d
36
-
37
- # Simple 2D not installed
38
- if `which simple2d`.empty?
39
- $errors << "Ruby 2D uses a native library called Simple 2D, which was not found." <<
40
- "To install, follow the instructions at #{"ruby2d.com".bold}"
41
- print_errors; exit
42
-
43
- # Simple 2D installed, checking version
44
- else
45
- unless Gem::Version.new(`bash simple2d --version`) >= Gem::Version.new(S2D_VERSION)
46
- $errors << "Simple 2D needs to be updated for this version of Ruby 2D." <<
47
- "Run the following, then try reinstalling this gem:\n" <<
48
- " simple2d update".bold
49
- print_errors; exit
50
- end
51
- end
52
- end
53
-
54
-
55
35
  # Add compiler and linker flags
56
36
  def add_flags(type, flags)
57
37
  case type
@@ -63,32 +43,38 @@ def add_flags(type, flags)
63
43
  end
64
44
 
65
45
 
66
- # Check SDL libraries on Linux
67
- def check_sdl_linux
46
+ # Check for SDL libraries
47
+ def check_sdl
68
48
  unless have_library('SDL2') && have_library('SDL2_image') && have_library('SDL2_mixer') && have_library('SDL2_ttf')
69
49
 
70
50
  $errors << "Couldn't find packages needed by Ruby 2D."
71
51
 
72
- # Fedora and CentOS
73
- if system('which yum')
74
- $errors << "Install the following packages using `yum` (or `dnf`) and try again:\n" <<
75
- " SDL2-devel SDL2_image-devel SDL2_mixer-devel SDL2_ttf-devel".bold
76
-
77
- # Arch
78
- elsif system('which pacman')
79
- $errors << "Install the following packages using `pacman` and try again:\n" <<
52
+ case $platform
53
+ when :linux, :linux_rpi
54
+ # Fedora and CentOS
55
+ if system('which yum')
56
+ $errors << "Install the following packages using `yum` (or `dnf`) and try again:\n" <<
57
+ " SDL2-devel SDL2_image-devel SDL2_mixer-devel SDL2_ttf-devel".bold
58
+
59
+ # Arch
60
+ elsif system('which pacman')
61
+ $errors << "Install the following packages using `pacman` and try again:\n" <<
62
+ " sdl2 sdl2_image sdl2_mixer sdl2_ttf".bold
63
+
64
+ # openSUSE
65
+ elsif system('which zypper')
66
+ $errors << "Install the following packages using `zypper` and try again:\n" <<
67
+ " libSDL2-devel libSDL2_image-devel libSDL2_mixer-devel libSDL2_ttf-devel".bold
68
+
69
+ # Ubuntu, Debian, and Mint
70
+ # `apt` must be last because openSUSE has it aliased to `zypper`
71
+ elsif system('which apt')
72
+ $errors << "Install the following packages using `apt` and try again:\n" <<
73
+ " libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev".bold
74
+ end
75
+ when :bsd
76
+ $errors << "Install the following packages using `pkg` and try again:\n" <<
80
77
  " sdl2 sdl2_image sdl2_mixer sdl2_ttf".bold
81
-
82
- # openSUSE
83
- elsif system('which zypper')
84
- $errors << "Install the following packages using `zypper` and try again:\n" <<
85
- " libSDL2-devel libSDL2_image-devel libSDL2_mixer-devel libSDL2_ttf-devel".bold
86
-
87
- # Ubuntu, Debian, and Mint
88
- # `apt` must be last because openSUSE has it aliased to `zypper`
89
- elsif system('which apt')
90
- $errors << "Install the following packages using `apt` and try again:\n" <<
91
- " libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev".bold
92
78
  end
93
79
 
94
80
  $errors << "" << "See #{"ruby2d.com".bold} for additional help."
@@ -106,14 +92,11 @@ def set_rpi_flags
106
92
  end
107
93
 
108
94
 
109
- # Use the Simple 2D, SDL, and other libraries installed by the user (not those bundled with the gem)
95
+ # Use SDL and other libraries installed by the user (not those bundled with the gem)
110
96
  def use_usr_libs
111
- check_s2d
112
-
113
97
  # Add flags
114
98
  set_rpi_flags
115
99
  add_flags(:c, '-I/usr/local/include')
116
- add_flags(:ld, `bash simple2d --libs`)
117
100
  end
118
101
 
119
102
 
@@ -134,27 +117,22 @@ else
134
117
  add_flags(:c, '-I../../assets/include')
135
118
  ldir = "#{Dir.pwd}/../../assets/macos/lib"
136
119
 
137
- add_flags(:ld, "#{ldir}/libsimple2d.a")
138
120
  add_flags(:ld, "#{ldir}/libSDL2.a #{ldir}/libSDL2_image.a #{ldir}/libSDL2_mixer.a #{ldir}/libSDL2_ttf.a")
139
121
  add_flags(:ld, "#{ldir}/libjpeg.a #{ldir}/libpng16.a #{ldir}/libtiff.a #{ldir}/libwebp.a")
140
122
  add_flags(:ld, "#{ldir}/libmpg123.a #{ldir}/libogg.a #{ldir}/libFLAC.a #{ldir}/libvorbis.a #{ldir}/libvorbisfile.a")
141
- add_flags(:ld, "#{ldir}/libfreetype.a")
142
- add_flags(:ld, "-Wl,-framework,Cocoa -Wl,-framework,ForceFeedback")
143
-
144
- when :linux, :linux_rpi
145
- check_sdl_linux
146
- simple2d_dir = "#{Dir.pwd}/../../assets/linux/simple2d"
123
+ add_flags(:ld, "#{ldir}/libfreetype.a #{ldir}/libmodplug.a")
124
+ add_flags(:ld, "-Wl,-framework,Cocoa -Wl,-framework,GameController -Wl,-framework,ForceFeedback")
147
125
 
148
- `(cd #{simple2d_dir} && make)`
126
+ when :linux, :linux_rpi, :bsd
127
+ check_sdl
149
128
 
150
129
  set_rpi_flags
151
- add_flags(:c, "-I#{simple2d_dir}/include")
152
- add_flags(:ld, "#{simple2d_dir}/build/libsimple2d.a -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lm")
130
+ add_flags(:ld, "-lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lm")
153
131
  if $platform == :linux then add_flags(:ld, '-lGL') end
154
132
 
155
133
  when :windows
156
134
  add_flags(:c, '-I../../assets/include')
157
- add_flags(:ld, '-L../../assets/mingw/lib -lsimple2d -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf')
135
+ add_flags(:ld, '-L../../assets/mingw/lib -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf')
158
136
  add_flags(:ld, '-lmingw32 -lopengl32 -lglew32')
159
137
 
160
138
  # If can't detect the platform, use libraries installed by the user
@@ -165,5 +143,5 @@ end
165
143
 
166
144
  $LDFLAGS.gsub!(/\n/, ' ') # remove newlines in flags, they can cause problems
167
145
 
168
- # Create the Makefile
146
+ # Create Makefile
169
147
  create_makefile('ruby2d/ruby2d')
data/ext/ruby2d/font.c ADDED
@@ -0,0 +1,35 @@
1
+ // font.c
2
+
3
+ #include "ruby2d.h"
4
+
5
+
6
+ /*
7
+ * Create a TTF_Font object given a path to a font and a size
8
+ */
9
+ TTF_Font *R2D_FontCreateTTFFont(const char *path, int size, const char *style) {
10
+
11
+ // Check if font file exists
12
+ if (!R2D_FileExists(path)) {
13
+ R2D_Error("R2D_FontCreateTTFFont", "Font file `%s` not found", path);
14
+ return NULL;
15
+ }
16
+
17
+ TTF_Font *font = TTF_OpenFont(path, size);
18
+
19
+ if (!font) {
20
+ R2D_Error("TTF_OpenFont", TTF_GetError());
21
+ return NULL;
22
+ }
23
+
24
+ if(strncmp(style, "bold", 4) == 0) {
25
+ TTF_SetFontStyle(font, TTF_STYLE_BOLD);
26
+ } else if(strncmp(style, "italic", 6) == 0) {
27
+ TTF_SetFontStyle(font, TTF_STYLE_ITALIC);
28
+ } else if(strncmp(style, "underline", 9) == 0) {
29
+ TTF_SetFontStyle(font, TTF_STYLE_UNDERLINE);
30
+ } else if(strncmp(style, "strikethrough", 13) == 0) {
31
+ TTF_SetFontStyle(font, TTF_STYLE_STRIKETHROUGH);
32
+ }
33
+
34
+ return font;
35
+ }