gosu 0.7.19 → 0.7.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (281) hide show
  1. data/Gosu/Input.hpp +12 -8
  2. data/Gosu/Math.hpp +13 -0
  3. data/Gosu/TextInput.hpp +5 -0
  4. data/Gosu/Version.hpp +2 -2
  5. data/GosuImpl/Graphics/TextUnix.cpp +253 -0
  6. data/GosuImpl/InputMac.mm +4 -4
  7. data/GosuImpl/InputWin.cpp +4 -4
  8. data/GosuImpl/InputX.cpp +15 -15
  9. data/GosuImpl/Math.cpp +28 -4
  10. data/GosuImpl/RubyGosu.swg +14 -3
  11. data/GosuImpl/RubyGosuStub.mm +8 -15
  12. data/GosuImpl/RubyGosu_wrap.cxx +113 -6
  13. data/GosuImpl/TextInputMac.mm +10 -1
  14. data/GosuImpl/TextInputWin.cpp +10 -0
  15. data/GosuImpl/TextInputX.cpp +10 -0
  16. data/GosuImpl/WindowMac.mm +15 -4
  17. data/GosuImpl/WindowWin.cpp +16 -7
  18. data/examples/TextInput.rb +15 -0
  19. data/lib/gosu.rb +5 -8
  20. data/linux/extconf.rb +34 -9
  21. metadata +13 -272
  22. data/GosuImpl/Graphics/TextPangoFT.cpp +0 -186
  23. data/Rakefile +0 -314
  24. data/examples/TextInput.cpp +0 -192
  25. data/examples/Tutorial.cpp +0 -215
  26. data/linux/Makefile.in +0 -99
  27. data/linux/configure +0 -5850
  28. data/linux/configure.ac +0 -110
  29. data/reference/cpp/_audio_8hpp-source.html +0 -178
  30. data/reference/cpp/_audio_8hpp.html +0 -100
  31. data/reference/cpp/_audio_8hpp_source.html +0 -170
  32. data/reference/cpp/_auto_link_8hpp-source.html +0 -85
  33. data/reference/cpp/_auto_link_8hpp.html +0 -84
  34. data/reference/cpp/_auto_link_8hpp_source.html +0 -85
  35. data/reference/cpp/_bitmap_8hpp-source.html +0 -131
  36. data/reference/cpp/_bitmap_8hpp.html +0 -114
  37. data/reference/cpp/_bitmap_8hpp_source.html +0 -131
  38. data/reference/cpp/_buttons_mac_8hpp-source.html +0 -206
  39. data/reference/cpp/_buttons_mac_8hpp.html +0 -240
  40. data/reference/cpp/_buttons_mac_8hpp_source.html +0 -206
  41. data/reference/cpp/_color_8hpp-source.html +0 -216
  42. data/reference/cpp/_color_8hpp.html +0 -130
  43. data/reference/cpp/_color_8hpp_source.html +0 -232
  44. data/reference/cpp/_directories_8hpp-source.html +0 -89
  45. data/reference/cpp/_directories_8hpp.html +0 -103
  46. data/reference/cpp/_directories_8hpp_source.html +0 -89
  47. data/reference/cpp/_font_8hpp-source.html +0 -116
  48. data/reference/cpp/_font_8hpp.html +0 -94
  49. data/reference/cpp/_font_8hpp_source.html +0 -116
  50. data/reference/cpp/_fwd_8hpp-source.html +0 -99
  51. data/reference/cpp/_fwd_8hpp.html +0 -90
  52. data/reference/cpp/_fwd_8hpp_source.html +0 -99
  53. data/reference/cpp/_gosu_8hpp-source.html +0 -97
  54. data/reference/cpp/_gosu_8hpp.html +0 -84
  55. data/reference/cpp/_gosu_8hpp_source.html +0 -97
  56. data/reference/cpp/_graphics_8hpp-source.html +0 -135
  57. data/reference/cpp/_graphics_8hpp.html +0 -101
  58. data/reference/cpp/_graphics_8hpp_source.html +0 -144
  59. data/reference/cpp/_graphics_base_8hpp-source.html +0 -116
  60. data/reference/cpp/_graphics_base_8hpp.html +0 -128
  61. data/reference/cpp/_graphics_base_8hpp_source.html +0 -117
  62. data/reference/cpp/_i_o_8hpp-source.html +0 -302
  63. data/reference/cpp/_i_o_8hpp.html +0 -129
  64. data/reference/cpp/_i_o_8hpp_source.html +0 -295
  65. data/reference/cpp/_image_8hpp-source.html +0 -173
  66. data/reference/cpp/_image_8hpp.html +0 -103
  67. data/reference/cpp/_image_8hpp_source.html +0 -176
  68. data/reference/cpp/_image_data_8hpp-source.html +0 -109
  69. data/reference/cpp/_image_data_8hpp.html +0 -97
  70. data/reference/cpp/_image_data_8hpp_source.html +0 -109
  71. data/reference/cpp/_input_8hpp-source.html +0 -183
  72. data/reference/cpp/_input_8hpp.html +0 -109
  73. data/reference/cpp/_input_8hpp_source.html +0 -183
  74. data/reference/cpp/_math_8hpp-source.html +0 -157
  75. data/reference/cpp/_math_8hpp.html +0 -152
  76. data/reference/cpp/_math_8hpp_source.html +0 -157
  77. data/reference/cpp/_platform_8hpp-source.html +0 -134
  78. data/reference/cpp/_platform_8hpp.html +0 -162
  79. data/reference/cpp/_platform_8hpp_source.html +0 -134
  80. data/reference/cpp/_rot_flip_8hpp-source.html +0 -185
  81. data/reference/cpp/_rot_flip_8hpp.html +0 -130
  82. data/reference/cpp/_rot_flip_8hpp_source.html +0 -185
  83. data/reference/cpp/_sockets_8hpp-source.html +0 -175
  84. data/reference/cpp/_sockets_8hpp.html +0 -124
  85. data/reference/cpp/_sockets_8hpp_source.html +0 -175
  86. data/reference/cpp/_text_8hpp-source.html +0 -103
  87. data/reference/cpp/_text_8hpp.html +0 -106
  88. data/reference/cpp/_text_8hpp_source.html +0 -103
  89. data/reference/cpp/_text_input_8hpp-source.html +0 -111
  90. data/reference/cpp/_text_input_8hpp.html +0 -94
  91. data/reference/cpp/_text_input_8hpp_source.html +0 -116
  92. data/reference/cpp/_timing_8hpp-source.html +0 -83
  93. data/reference/cpp/_timing_8hpp.html +0 -97
  94. data/reference/cpp/_timing_8hpp_source.html +0 -83
  95. data/reference/cpp/_utility_8hpp-source.html +0 -90
  96. data/reference/cpp/_utility_8hpp.html +0 -103
  97. data/reference/cpp/_utility_8hpp_source.html +0 -90
  98. data/reference/cpp/_version_8hpp-source.html +0 -78
  99. data/reference/cpp/_version_8hpp.html +0 -154
  100. data/reference/cpp/_version_8hpp_source.html +0 -78
  101. data/reference/cpp/_win_utility_8hpp-source.html +0 -126
  102. data/reference/cpp/_win_utility_8hpp.html +0 -128
  103. data/reference/cpp/_win_utility_8hpp_source.html +0 -126
  104. data/reference/cpp/_window_8hpp-source.html +0 -158
  105. data/reference/cpp/_window_8hpp.html +0 -94
  106. data/reference/cpp/_window_8hpp_source.html +0 -159
  107. data/reference/cpp/annotated.html +0 -98
  108. data/reference/cpp/class_gosu_1_1_audio-members.html +0 -76
  109. data/reference/cpp/class_gosu_1_1_audio.html +0 -155
  110. data/reference/cpp/class_gosu_1_1_bitmap-members.html +0 -86
  111. data/reference/cpp/class_gosu_1_1_bitmap.html +0 -506
  112. data/reference/cpp/class_gosu_1_1_buffer-members.html +0 -85
  113. data/reference/cpp/class_gosu_1_1_buffer.html +0 -341
  114. data/reference/cpp/class_gosu_1_1_buffer.png +0 -0
  115. data/reference/cpp/class_gosu_1_1_button-members.html +0 -77
  116. data/reference/cpp/class_gosu_1_1_button.html +0 -198
  117. data/reference/cpp/class_gosu_1_1_color-members.html +0 -108
  118. data/reference/cpp/class_gosu_1_1_color.html +0 -972
  119. data/reference/cpp/class_gosu_1_1_comm_socket-members.html +0 -91
  120. data/reference/cpp/class_gosu_1_1_comm_socket.html +0 -506
  121. data/reference/cpp/class_gosu_1_1_file-members.html +0 -82
  122. data/reference/cpp/class_gosu_1_1_file.html +0 -276
  123. data/reference/cpp/class_gosu_1_1_file.png +0 -0
  124. data/reference/cpp/class_gosu_1_1_font-members.html +0 -82
  125. data/reference/cpp/class_gosu_1_1_font.html +0 -506
  126. data/reference/cpp/class_gosu_1_1_graphics-members.html +0 -93
  127. data/reference/cpp/class_gosu_1_1_graphics.html +0 -817
  128. data/reference/cpp/class_gosu_1_1_image-members.html +0 -87
  129. data/reference/cpp/class_gosu_1_1_image.html +0 -797
  130. data/reference/cpp/class_gosu_1_1_image_data-members.html +0 -78
  131. data/reference/cpp/class_gosu_1_1_image_data.html +0 -282
  132. data/reference/cpp/class_gosu_1_1_input-members.html +0 -86
  133. data/reference/cpp/class_gosu_1_1_input.html +0 -418
  134. data/reference/cpp/class_gosu_1_1_listener_socket-members.html +0 -79
  135. data/reference/cpp/class_gosu_1_1_listener_socket.html +0 -222
  136. data/reference/cpp/class_gosu_1_1_message_socket-members.html +0 -81
  137. data/reference/cpp/class_gosu_1_1_message_socket.html +0 -306
  138. data/reference/cpp/class_gosu_1_1_reader-members.html +0 -81
  139. data/reference/cpp/class_gosu_1_1_reader.html +0 -323
  140. data/reference/cpp/class_gosu_1_1_resource-members.html +0 -80
  141. data/reference/cpp/class_gosu_1_1_resource.html +0 -306
  142. data/reference/cpp/class_gosu_1_1_resource.png +0 -0
  143. data/reference/cpp/class_gosu_1_1_rot_flip-members.html +0 -84
  144. data/reference/cpp/class_gosu_1_1_rot_flip.html +0 -352
  145. data/reference/cpp/class_gosu_1_1_sample-members.html +0 -80
  146. data/reference/cpp/class_gosu_1_1_sample.html +0 -324
  147. data/reference/cpp/class_gosu_1_1_sample_instance-members.html +0 -82
  148. data/reference/cpp/class_gosu_1_1_sample_instance.html +0 -318
  149. data/reference/cpp/class_gosu_1_1_song-members.html +0 -90
  150. data/reference/cpp/class_gosu_1_1_song.html +0 -493
  151. data/reference/cpp/class_gosu_1_1_text_input-members.html +0 -80
  152. data/reference/cpp/class_gosu_1_1_text_input.html +0 -255
  153. data/reference/cpp/class_gosu_1_1_window-members.html +0 -91
  154. data/reference/cpp/class_gosu_1_1_window.html +0 -534
  155. data/reference/cpp/class_gosu_1_1_writer-members.html +0 -80
  156. data/reference/cpp/class_gosu_1_1_writer.html +0 -293
  157. data/reference/cpp/classes.html +0 -86
  158. data/reference/cpp/closed.gif +0 -0
  159. data/reference/cpp/cpp.css +0 -155
  160. data/reference/cpp/doxygen.png +0 -0
  161. data/reference/cpp/files.html +0 -99
  162. data/reference/cpp/functions.html +0 -128
  163. data/reference/cpp/functions_0x62.html +0 -144
  164. data/reference/cpp/functions_0x63.html +0 -143
  165. data/reference/cpp/functions_0x64.html +0 -143
  166. data/reference/cpp/functions_0x65.html +0 -122
  167. data/reference/cpp/functions_0x66.html +0 -144
  168. data/reference/cpp/functions_0x67.html +0 -136
  169. data/reference/cpp/functions_0x68.html +0 -122
  170. data/reference/cpp/functions_0x69.html +0 -124
  171. data/reference/cpp/functions_0x6b.html +0 -116
  172. data/reference/cpp/functions_0x6c.html +0 -118
  173. data/reference/cpp/functions_0x6d.html +0 -126
  174. data/reference/cpp/functions_0x6e.html +0 -121
  175. data/reference/cpp/functions_0x6f.html +0 -127
  176. data/reference/cpp/functions_0x70.html +0 -137
  177. data/reference/cpp/functions_0x72.html +0 -157
  178. data/reference/cpp/functions_0x73.html +0 -180
  179. data/reference/cpp/functions_0x74.html +0 -128
  180. data/reference/cpp/functions_0x75.html +0 -123
  181. data/reference/cpp/functions_0x76.html +0 -118
  182. data/reference/cpp/functions_0x77.html +0 -132
  183. data/reference/cpp/functions_0x78.html +0 -116
  184. data/reference/cpp/functions_0x79.html +0 -118
  185. data/reference/cpp/functions_0x7e.html +0 -142
  186. data/reference/cpp/functions_enum.html +0 -88
  187. data/reference/cpp/functions_eval.html +0 -90
  188. data/reference/cpp/functions_func.html +0 -124
  189. data/reference/cpp/functions_func_0x62.html +0 -136
  190. data/reference/cpp/functions_func_0x63.html +0 -137
  191. data/reference/cpp/functions_func_0x64.html +0 -141
  192. data/reference/cpp/functions_func_0x65.html +0 -120
  193. data/reference/cpp/functions_func_0x66.html +0 -140
  194. data/reference/cpp/functions_func_0x67.html +0 -130
  195. data/reference/cpp/functions_func_0x68.html +0 -120
  196. data/reference/cpp/functions_func_0x69.html +0 -120
  197. data/reference/cpp/functions_func_0x6b.html +0 -114
  198. data/reference/cpp/functions_func_0x6c.html +0 -114
  199. data/reference/cpp/functions_func_0x6d.html +0 -124
  200. data/reference/cpp/functions_func_0x6e.html +0 -117
  201. data/reference/cpp/functions_func_0x6f.html +0 -114
  202. data/reference/cpp/functions_func_0x70.html +0 -135
  203. data/reference/cpp/functions_func_0x72.html +0 -151
  204. data/reference/cpp/functions_func_0x73.html +0 -174
  205. data/reference/cpp/functions_func_0x74.html +0 -120
  206. data/reference/cpp/functions_func_0x75.html +0 -121
  207. data/reference/cpp/functions_func_0x76.html +0 -116
  208. data/reference/cpp/functions_func_0x77.html +0 -128
  209. data/reference/cpp/functions_func_0x7e.html +0 -140
  210. data/reference/cpp/functions_type.html +0 -88
  211. data/reference/cpp/functions_vars.html +0 -135
  212. data/reference/cpp/globals.html +0 -95
  213. data/reference/cpp/globals_defs.html +0 -95
  214. data/reference/cpp/hierarchy.html +0 -100
  215. data/reference/cpp/index.html +0 -67
  216. data/reference/cpp/namespace_gosu.html +0 -3311
  217. data/reference/cpp/namespace_gosu_1_1_colors.html +0 -287
  218. data/reference/cpp/namespace_gosu_1_1_win.html +0 -354
  219. data/reference/cpp/namespacemembers.html +0 -139
  220. data/reference/cpp/namespacemembers_0x62.html +0 -143
  221. data/reference/cpp/namespacemembers_0x63.html +0 -125
  222. data/reference/cpp/namespacemembers_0x64.html +0 -121
  223. data/reference/cpp/namespacemembers_0x66.html +0 -129
  224. data/reference/cpp/namespacemembers_0x67.html +0 -163
  225. data/reference/cpp/namespacemembers_0x68.html +0 -113
  226. data/reference/cpp/namespacemembers_0x69.html +0 -117
  227. data/reference/cpp/namespacemembers_0x6b.html +0 -289
  228. data/reference/cpp/namespacemembers_0x6c.html +0 -119
  229. data/reference/cpp/namespacemembers_0x6d.html +0 -131
  230. data/reference/cpp/namespacemembers_0x6e.html +0 -127
  231. data/reference/cpp/namespacemembers_0x6f.html +0 -121
  232. data/reference/cpp/namespacemembers_0x70.html +0 -115
  233. data/reference/cpp/namespacemembers_0x71.html +0 -113
  234. data/reference/cpp/namespacemembers_0x72.html +0 -165
  235. data/reference/cpp/namespacemembers_0x73.html +0 -135
  236. data/reference/cpp/namespacemembers_0x74.html +0 -129
  237. data/reference/cpp/namespacemembers_0x75.html +0 -117
  238. data/reference/cpp/namespacemembers_0x77.html +0 -117
  239. data/reference/cpp/namespacemembers_0x79.html +0 -113
  240. data/reference/cpp/namespacemembers_0x7a.html +0 -115
  241. data/reference/cpp/namespacemembers_enum.html +0 -103
  242. data/reference/cpp/namespacemembers_eval.html +0 -445
  243. data/reference/cpp/namespacemembers_func.html +0 -269
  244. data/reference/cpp/namespacemembers_type.html +0 -93
  245. data/reference/cpp/namespacemembers_vars.html +0 -117
  246. data/reference/cpp/namespaces.html +0 -76
  247. data/reference/cpp/open.gif +0 -0
  248. data/reference/cpp/struct_gosu_1_1_g_l_tex_info-members.html +0 -78
  249. data/reference/cpp/struct_gosu_1_1_g_l_tex_info.html +0 -186
  250. data/reference/cpp/struct_gosu_1_1_touch-members.html +0 -76
  251. data/reference/cpp/struct_gosu_1_1_touch.html +0 -154
  252. data/reference/cpp/tab_b.gif +0 -0
  253. data/reference/cpp/tab_l.gif +0 -0
  254. data/reference/cpp/tab_r.gif +0 -0
  255. data/reference/cpp/tabs.css +0 -105
  256. data/reference/rdoc/classes/Gosu.html +0 -1546
  257. data/reference/rdoc/classes/Gosu/Color.html +0 -660
  258. data/reference/rdoc/classes/Gosu/Font.html +0 -545
  259. data/reference/rdoc/classes/Gosu/GLTexInfo.html +0 -412
  260. data/reference/rdoc/classes/Gosu/Image.html +0 -706
  261. data/reference/rdoc/classes/Gosu/Sample.html +0 -476
  262. data/reference/rdoc/classes/Gosu/SampleInstance.html +0 -523
  263. data/reference/rdoc/classes/Gosu/Song.html +0 -568
  264. data/reference/rdoc/classes/Gosu/TextInput.html +0 -444
  265. data/reference/rdoc/classes/Gosu/Window.html +0 -911
  266. data/reference/rdoc/classes/Numeric.html +0 -479
  267. data/reference/rdoc/created.rid +0 -1
  268. data/reference/rdoc/files/COPYING_txt.html +0 -391
  269. data/reference/rdoc/files/README_txt.html +0 -387
  270. data/reference/rdoc/files/reference/Deployment on OS X_rdoc.html +0 -381
  271. data/reference/rdoc/files/reference/Deployment on Windows_rdoc.html +0 -385
  272. data/reference/rdoc/files/reference/Drawing with Colors_rdoc.html +0 -363
  273. data/reference/rdoc/files/reference/Order of Corners_rdoc.html +0 -358
  274. data/reference/rdoc/files/reference/Tileability_rdoc.html +0 -374
  275. data/reference/rdoc/files/reference/Z Ordering_rdoc.html +0 -361
  276. data/reference/rdoc/files/reference/gosu_rb.html +0 -348
  277. data/reference/rdoc/fr_class_index.html +0 -12
  278. data/reference/rdoc/fr_file_index.html +0 -10
  279. data/reference/rdoc/fr_method_index.html +0 -66
  280. data/reference/rdoc/index.html +0 -1
  281. data/reference/rdoc/rdoc-style.css +0 -320
@@ -34,21 +34,21 @@ namespace Gosu
34
34
  //! Very lightweight class that identifies a button (keyboard, mouse or other device).
35
35
  class Button
36
36
  {
37
- unsigned id;
37
+ unsigned id_;
38
38
 
39
39
  public:
40
40
  //! For internal use.
41
- explicit Button(unsigned id) : id(id) {}
41
+ explicit Button(unsigned id) : id_(id) {}
42
42
  //! For internal use.
43
- unsigned getId() const { return id; }
43
+ unsigned id() const { return id_; }
44
44
 
45
45
  //! Default constructor; == noButton.
46
- Button() : id(noButton) {}
46
+ Button() : id_(noButton) {}
47
47
 
48
48
  //! Conversion from ButtonName constants.
49
- Button(ButtonName name) : id(name) {}
49
+ Button(ButtonName name) : id_(name) {}
50
50
  };
51
-
51
+
52
52
  // Available even on non-iPhone platforms to make it easier to compile the
53
53
  // same source for multiple platforms.
54
54
 
@@ -62,16 +62,20 @@ namespace Gosu
62
62
  double x, y;
63
63
  };
64
64
  typedef std::vector<Touch> Touches;
65
-
65
+
66
66
  //! Tests whether two Buttons identify the same physical button.
67
67
  inline bool operator==(Button lhs, Button rhs)
68
68
  {
69
- return lhs.getId() == rhs.getId();
69
+ return lhs.id() == rhs.id();
70
70
  }
71
71
  inline bool operator!=(Button lhs, Button rhs)
72
72
  {
73
73
  return !(lhs == rhs);
74
74
  }
75
+ inline bool operator<(Button lhs, Button rhs)
76
+ {
77
+ return lhs.id() < rhs.id();
78
+ }
75
79
 
76
80
  //! Manages initialization and shutdown of the input system. Only one Input
77
81
  //! instance can exist per application.
@@ -101,6 +101,19 @@ namespace Gosu
101
101
  return clamp(value, min, max);
102
102
  }
103
103
 
104
+ //! Returns (value-min) % (max-min) + min, where % always has a positive
105
+ //! result for max > min. The results are undefined for max <= min.
106
+ //! Note: This means that max is exclusive.
107
+ int wrap(int value, int min, int max);
108
+ //! Returns (value-min) % (max-min) + min, where % always has a positive
109
+ //! result for max > min. The results are undefined for max <= min.
110
+ //! Note: This means that max is exclusive.
111
+ float wrap(float value, float min, float max);
112
+ //! Returns (value-min) % (max-min) + min, where % always has a positive
113
+ //! result for max > min. The results are undefined for max <= min.
114
+ //! Note: This means that max is exclusive.
115
+ double wrap(double value, double min, double max);
116
+
104
117
  //! Returns the square of the distance between two points.
105
118
  inline double distanceSqr(double x1, double y1, double x2, double y2)
106
119
  {
@@ -37,11 +37,16 @@ namespace Gosu
37
37
 
38
38
  //! Position of the caret as the index of the character that it's left to.
39
39
  unsigned caretPos() const;
40
+ //! Sets the caret position as returned by caretPos.
41
+ //! You usually also want to use setSelectionStart.
42
+ void setCaretPos(unsigned pos);
40
43
 
41
44
  //! If there is a selection, the selectionStart() member yields its beginning,
42
45
  //! using the same indexing scheme as caretPos. If there is no selection,
43
46
  //! selectionStart() is equal to caretPos().
44
47
  unsigned selectionStart() const;
48
+ //! Sets the start of the selection as returned by selectionStart.
49
+ void setSelectionStart(unsigned pos);
45
50
 
46
51
  // Platform-specific communication with Gosu::Input.
47
52
  #if defined(GOSU_IS_MAC)
@@ -3,7 +3,7 @@
3
3
 
4
4
  #define GOSU_MAJOR_VERSION 0
5
5
  #define GOSU_MINOR_VERSION 7
6
- #define GOSU_POINT_VERSION 19
7
- #define GOSU_VERSION "0.7.19"
6
+ #define GOSU_POINT_VERSION 20
7
+ #define GOSU_VERSION "0.7.20"
8
8
 
9
9
  #endif
@@ -0,0 +1,253 @@
1
+ #include <Gosu/Text.hpp>
2
+ #include <Gosu/Bitmap.hpp>
3
+ #include <Gosu/Utility.hpp>
4
+
5
+ #include <pango/pango.h>
6
+ #include <pango/pangoft2.h>
7
+ #include <glib.h>
8
+ #include <SDL/SDL_ttf.h>
9
+
10
+ #include <boost/utility.hpp>
11
+ #include <string>
12
+ #include <cstring>
13
+ #include <stdexcept>
14
+
15
+ std::wstring Gosu::defaultFontName()
16
+ {
17
+ return L"sans";
18
+ }
19
+
20
+ namespace Gosu
21
+ {
22
+ // Used for system fonts
23
+ // Adapted from original version by Jan Lücker
24
+ class PangoRenderer : boost::noncopyable
25
+ {
26
+ int width, height;
27
+
28
+ PangoContext* context;
29
+ PangoLayout* layout;
30
+ PangoFontDescription *font_description;
31
+ PangoAttribute* attr;
32
+ PangoAttrList* attrList;
33
+
34
+ public:
35
+ PangoRenderer()
36
+ {
37
+ font_description = NULL;
38
+ attr = NULL;
39
+ attrList = NULL;
40
+ }
41
+ ~PangoRenderer()
42
+ {
43
+ g_object_unref(context);
44
+ g_object_unref(layout);
45
+
46
+ if(font_description)
47
+ pango_font_description_free(font_description);
48
+ if(attr)
49
+ pango_attribute_destroy(attr);
50
+ }
51
+ unsigned textWidth(const std::wstring& text,
52
+ const std::wstring& fontFace, unsigned fontHeight,
53
+ unsigned fontFlags)
54
+ {
55
+ g_type_init();
56
+
57
+ int dpi_x = 100, dpi_y = 100;
58
+
59
+ context = pango_ft2_get_context(dpi_x, dpi_y);
60
+
61
+ pango_context_set_language(context, pango_language_from_string ("en_US"));
62
+ PangoDirection init_dir = PANGO_DIRECTION_LTR;
63
+ pango_context_set_base_dir(context, init_dir);
64
+
65
+ font_description = pango_font_description_new();
66
+
67
+ pango_font_description_set_family(font_description,
68
+ g_strdup(narrow(fontFace).c_str()));
69
+ pango_font_description_set_style(font_description,
70
+ (fontFlags & ffItalic) ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL);
71
+ pango_font_description_set_variant(font_description, PANGO_VARIANT_NORMAL);
72
+ pango_font_description_set_weight(font_description,
73
+ (fontFlags & ffBold) ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL);
74
+ pango_font_description_set_stretch(font_description, PANGO_STRETCH_NORMAL);
75
+ int init_scale = int(fontHeight/2.0 + 0.5);
76
+ pango_font_description_set_size(font_description, init_scale * PANGO_SCALE);
77
+
78
+ pango_context_set_font_description(context, font_description);
79
+
80
+
81
+ layout = pango_layout_new(context);
82
+
83
+
84
+ if(fontFlags & ffUnderline)
85
+ {
86
+ // PangoAttribute *attr;
87
+ attr = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
88
+ attr->start_index = 0;
89
+ attr->end_index = text.length();
90
+ // PangoAttrList* attrList;
91
+ attrList = pango_attr_list_new();
92
+ pango_attr_list_insert(attrList, attr);
93
+ pango_layout_set_attributes(layout, attrList);
94
+ pango_attr_list_unref(attrList);
95
+ }
96
+
97
+
98
+ // IMPR: Catch errors? (Last NULL-Pointer)
99
+ gchar* utf8Str = g_ucs4_to_utf8((gunichar*)text.c_str(), text.length(), NULL, NULL, NULL);
100
+ pango_layout_set_text(layout, utf8Str, -1);
101
+ g_free(utf8Str);
102
+
103
+ PangoDirection base_dir = pango_context_get_base_dir(context);
104
+ pango_layout_set_alignment(layout,
105
+ base_dir == PANGO_DIRECTION_LTR ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT);
106
+
107
+ pango_layout_set_width(layout, -1);
108
+
109
+ PangoRectangle logical_rect;
110
+
111
+ pango_layout_get_pixel_extents(layout, NULL, &logical_rect);
112
+ height = logical_rect.height;
113
+ width = logical_rect.width;
114
+
115
+ return width;
116
+ }
117
+ void drawText(Bitmap& bitmap, const std::wstring& text, int x, int y,
118
+ Color c, const std::wstring& fontFace, unsigned fontHeight,
119
+ unsigned fontFlags)
120
+ {
121
+ textWidth(text, fontFace, fontHeight, fontFlags);
122
+
123
+ FT_Bitmap ft_bitmap;
124
+
125
+ guchar* buf = new guchar[width * height];
126
+ std::fill(buf, buf + width * height, 0x00);
127
+
128
+ ft_bitmap.rows = height;
129
+ ft_bitmap.width = width;
130
+ ft_bitmap.pitch = ft_bitmap.width;
131
+ ft_bitmap.buffer = buf;
132
+ ft_bitmap.num_grays = 256;
133
+ ft_bitmap.pixel_mode = ft_pixel_mode_grays;
134
+
135
+ int x_start = 0;
136
+ pango_ft2_render_layout(&ft_bitmap, layout, x_start, 0);
137
+
138
+
139
+ int min_height = height;
140
+ if((unsigned)height > fontHeight) min_height = fontHeight;
141
+
142
+ for(int y2 = 0; y2 < min_height; y2++)
143
+ {
144
+ if (y + y2 < 0 || y + y2 >= bitmap.height())
145
+ break;
146
+
147
+ for(int x2 = 0; x2 < width; x2++)
148
+ {
149
+ if (x + x2 < 0 || x + x2 >= bitmap.width())
150
+ break;
151
+ unsigned val = ft_bitmap.buffer[y2*width+x2];
152
+ Color color = c;
153
+ color.setAlpha(val);
154
+ bitmap.setPixel(x2 + x, y2 + y, color);
155
+ }
156
+ }
157
+
158
+ delete[] buf;
159
+ }
160
+ };
161
+
162
+
163
+ // Used for custom TTF files
164
+ // Adapted from customFont class by José Tomás Tocino García (TheOm3ga)
165
+ class SDLTTFRenderer : boost::noncopyable
166
+ {
167
+ TTF_Font* font;
168
+
169
+ class SDLSurface : boost::noncopyable
170
+ {
171
+ SDL_Surface* surface;
172
+
173
+ public:
174
+ SDLSurface(TTF_Font* font, const std::wstring& text, Gosu::Color c)
175
+ {
176
+ SDL_Color color = { c.red(), c.green(), c.blue() };
177
+ surface = TTF_RenderUTF8_Blended(font, Gosu::wstringToUTF8(text).c_str(), color);
178
+ if (!surface)
179
+ throw std::runtime_error("Could not render text " + Gosu::wstringToUTF8(text));
180
+ }
181
+
182
+ ~SDLSurface()
183
+ {
184
+ SDL_FreeSurface(surface);
185
+ }
186
+
187
+ unsigned height() const
188
+ {
189
+ return surface->h;
190
+ }
191
+
192
+ unsigned width() const
193
+ {
194
+ return surface->w;
195
+ }
196
+
197
+ const void* data() const
198
+ {
199
+ return surface->pixels;
200
+ }
201
+ };
202
+
203
+ public:
204
+ SDLTTFRenderer(const std::wstring& fontName, unsigned fontHeight)
205
+ {
206
+ static int initResult = TTF_Init();
207
+ if (initResult < 0)
208
+ throw std::runtime_error("Could not initialize SDL_TTF");
209
+
210
+ // Try to open the font at the given path
211
+ font = TTF_OpenFont(Gosu::wstringToUTF8(fontName).c_str(), fontHeight);
212
+ if (!font)
213
+ throw std::runtime_error("Could not open TTF file " + Gosu::wstringToUTF8(fontName));
214
+ }
215
+
216
+ ~SDLTTFRenderer()
217
+ {
218
+ TTF_CloseFont(font);
219
+ }
220
+
221
+ unsigned textWidth(const std::wstring& text){
222
+ return SDLSurface(font, text, 0xffffff).width();
223
+ }
224
+
225
+ void drawText(Bitmap& bmp, const std::wstring& text, int x, int y, Gosu::Color c) {
226
+ SDLSurface surf(font, text, c);
227
+ Gosu::Bitmap temp;
228
+ temp.resize(surf.width(), surf.height());
229
+ std::memcpy(temp.data(), surf.data(), temp.width() * temp.height() * 4);
230
+ bmp.insert(temp, x, y);
231
+ }
232
+ };
233
+ }
234
+
235
+ unsigned Gosu::textWidth(const std::wstring& text,
236
+ const std::wstring& fontName, unsigned fontHeight,
237
+ unsigned fontFlags)
238
+ {
239
+ if (fontName.find(L"/") == std::wstring::npos)
240
+ return PangoRenderer().textWidth(text, fontName, fontHeight, fontFlags);
241
+ else
242
+ return SDLTTFRenderer(fontName, fontHeight).textWidth(text);
243
+ }
244
+
245
+ void Gosu::drawText(Bitmap& bitmap, const std::wstring& text, int x, int y,
246
+ Color c, const std::wstring& fontName, unsigned fontHeight,
247
+ unsigned fontFlags)
248
+ {
249
+ if (fontName.find(L"/") == std::wstring::npos)
250
+ PangoRenderer().drawText(bitmap, text, x, y, c, fontName, fontHeight, fontFlags);
251
+ else
252
+ SDLTTFRenderer(fontName, fontHeight).drawText(bitmap, text, x, y, c);
253
+ }
@@ -606,8 +606,8 @@ bool Gosu::Input::feedNSEvent(void* event)
606
606
 
607
607
  wchar_t Gosu::Input::idToChar(Button btn)
608
608
  {
609
- if (btn.getId() < numScancodes)
610
- return idChars[btn.getId()];
609
+ if (btn.id() < numScancodes)
610
+ return idChars[btn.id()];
611
611
  else
612
612
  return 0;
613
613
  }
@@ -625,7 +625,7 @@ bool Gosu::Input::down(Gosu::Button btn) const
625
625
  if (btn == noButton)
626
626
  return false;
627
627
 
628
- return buttonStates.at(btn.getId());
628
+ return buttonStates.at(btn.id());
629
629
  }
630
630
 
631
631
  double Gosu::Input::mouseX() const
@@ -667,7 +667,7 @@ void Gosu::Input::update()
667
667
  for (unsigned i = 0; i < pimpl->queue.size(); ++i)
668
668
  {
669
669
  Impl::WaitingButton& wb = pimpl->queue[i];
670
- buttonStates.at(wb.btn.getId()) = wb.down;
670
+ buttonStates.at(wb.btn.id()) = wb.down;
671
671
  if (wb.down && onButtonDown)
672
672
  onButtonDown(wb.btn);
673
673
  else if (!wb.down && onButtonUp)
@@ -383,17 +383,17 @@ Gosu::Button Gosu::Input::charToId(wchar_t ch)
383
383
  wchar_t Gosu::Input::idToChar(Gosu::Button btn)
384
384
  {
385
385
  // Only translate keyboard ids.
386
- if (btn.getId() > 255)
386
+ if (btn.id() > 255)
387
387
  return 0;
388
388
 
389
389
  // Special case...?
390
- if (btn.getId() == kbSpace)
390
+ if (btn.id() == kbSpace)
391
391
  return L' ';
392
392
 
393
393
  // Try to get the key name.
394
394
  // (Three elements so too-long names will make GKNT return 3 and we'll know.)
395
395
  wchar_t buf[3];
396
- if (::GetKeyNameText(btn.getId() << 16, buf, 3) == 1)
396
+ if (::GetKeyNameText(btn.id() << 16, buf, 3) == 1)
397
397
  return /*std::*/towlower(buf[0]);
398
398
 
399
399
  return 0;
@@ -405,7 +405,7 @@ bool Gosu::Input::down(Button btn) const
405
405
  if (btn == noButton)
406
406
  return false;
407
407
 
408
- return buttons.at(btn.getId());
408
+ return buttons.at(btn.id());
409
409
  }
410
410
 
411
411
  double Gosu::Input::mouseX() const
@@ -53,7 +53,7 @@ bool Gosu::Input::down(Gosu::Button btn) const
53
53
  return false;
54
54
 
55
55
  // Will default to false for unknown indices (good).
56
- return pimpl->keyMap[btn.getId()];
56
+ return pimpl->keyMap[btn.id()];
57
57
  }
58
58
 
59
59
  Gosu::Button Gosu::Input::charToId(wchar_t ch)
@@ -74,16 +74,16 @@ namespace
74
74
  wchar_t Gosu::Input::idToChar(Button btn)
75
75
  {
76
76
  // ASCII chars
77
- if (btn.getId() >= 32 && btn.getId() <= 255)
78
- return btn.getId();
77
+ if (btn.id() >= 32 && btn.id() <= 255)
78
+ return btn.id();
79
79
 
80
80
  // Looking at SDL source suggests that this is to be interpreted depending on the third byte.
81
81
  // Should find solid literature on that if it exists.
82
82
  // Commented out: This is pretty pointless since LATIN-1 maps to Unicode directly...
83
83
  // BUT could serve as a basis for more?!
84
- //if ((btn.getId() >> 8) == 0)
84
+ //if ((btn.id() >> 8) == 0)
85
85
  //{
86
- // unsigned char in[] = { btn.getId() & 0xff, 0 };
86
+ // unsigned char in[] = { btn.id() & 0xff, 0 };
87
87
  // std::wstring converted = iconvert<std::wstring, UCS_4_INTERNAL, LATIN>(std::string(reinterpret_cast<char*>(in)));
88
88
  // return converted.at(0);
89
89
  //}
@@ -167,8 +167,8 @@ void Gosu::Input::update()
167
167
  pimpl->keyMap[id] = true;
168
168
  // TODO: Here, above, below, who came up with that cast? Uh :)
169
169
  if (onButtonDown)
170
- onButtonDown(Button(id));
171
- if (onButtonUp and id == msWheelUp or id == msWheelDown)
170
+ onButtonDown(Button(id));
171
+ if (onButtonUp and id == msWheelUp or id == msWheelDown)
172
172
  onButtonUp(Button(id));
173
173
  }
174
174
  else if (event.type == ButtonRelease)
@@ -189,12 +189,12 @@ void Gosu::Input::update()
189
189
  {
190
190
  pimpl->mouseX = event.xbutton.x;
191
191
  pimpl->mouseY = event.xbutton.y;
192
- }
193
- else if (event.type == EnterNotify || event.type == LeaveNotify)
192
+ }
193
+ else if (event.type == EnterNotify || event.type == LeaveNotify)
194
194
  {
195
195
  pimpl->mouseX = event.xcrossing.x;
196
196
  pimpl->mouseY = event.xcrossing.y;
197
- }
197
+ }
198
198
  }
199
199
  pimpl->eventList.clear();
200
200
  }
@@ -202,11 +202,11 @@ void Gosu::Input::update()
202
202
  void Gosu::Input::setMousePosition(double x, double y)
203
203
  {
204
204
  ::XWarpPointer(pimpl->display, None, pimpl->window, 0, 0, 0, 0,
205
- x / pimpl->mouseFactorX, y / pimpl->mouseFactorY);
206
- ::XSync(pimpl->display, False);
207
- // Couldn't find a way to fetch the current mouse position. These
208
- // values may not be correct if the cursor was grabbed, for example.
209
- pimpl->mouseX = x, pimpl->mouseY = y;
205
+ x / pimpl->mouseFactorX, y / pimpl->mouseFactorY);
206
+ ::XSync(pimpl->display, False);
207
+ // Couldn't find a way to fetch the current mouse position. These
208
+ // values may not be correct if the cursor was grabbed, for example.
209
+ pimpl->mouseX = x, pimpl->mouseY = y;
210
210
  }
211
211
 
212
212
  Gosu::TextInput* Gosu::Input::textInput() const