gosu 0.7.19 → 0.7.20
Sign up to get free protection for your applications and to get access to all the features.
- data/Gosu/Input.hpp +12 -8
- data/Gosu/Math.hpp +13 -0
- data/Gosu/TextInput.hpp +5 -0
- data/Gosu/Version.hpp +2 -2
- data/GosuImpl/Graphics/TextUnix.cpp +253 -0
- data/GosuImpl/InputMac.mm +4 -4
- data/GosuImpl/InputWin.cpp +4 -4
- data/GosuImpl/InputX.cpp +15 -15
- data/GosuImpl/Math.cpp +28 -4
- data/GosuImpl/RubyGosu.swg +14 -3
- data/GosuImpl/RubyGosuStub.mm +8 -15
- data/GosuImpl/RubyGosu_wrap.cxx +113 -6
- data/GosuImpl/TextInputMac.mm +10 -1
- data/GosuImpl/TextInputWin.cpp +10 -0
- data/GosuImpl/TextInputX.cpp +10 -0
- data/GosuImpl/WindowMac.mm +15 -4
- data/GosuImpl/WindowWin.cpp +16 -7
- data/examples/TextInput.rb +15 -0
- data/lib/gosu.rb +5 -8
- data/linux/extconf.rb +34 -9
- metadata +13 -272
- data/GosuImpl/Graphics/TextPangoFT.cpp +0 -186
- data/Rakefile +0 -314
- data/examples/TextInput.cpp +0 -192
- data/examples/Tutorial.cpp +0 -215
- data/linux/Makefile.in +0 -99
- data/linux/configure +0 -5850
- data/linux/configure.ac +0 -110
- data/reference/cpp/_audio_8hpp-source.html +0 -178
- data/reference/cpp/_audio_8hpp.html +0 -100
- data/reference/cpp/_audio_8hpp_source.html +0 -170
- data/reference/cpp/_auto_link_8hpp-source.html +0 -85
- data/reference/cpp/_auto_link_8hpp.html +0 -84
- data/reference/cpp/_auto_link_8hpp_source.html +0 -85
- data/reference/cpp/_bitmap_8hpp-source.html +0 -131
- data/reference/cpp/_bitmap_8hpp.html +0 -114
- data/reference/cpp/_bitmap_8hpp_source.html +0 -131
- data/reference/cpp/_buttons_mac_8hpp-source.html +0 -206
- data/reference/cpp/_buttons_mac_8hpp.html +0 -240
- data/reference/cpp/_buttons_mac_8hpp_source.html +0 -206
- data/reference/cpp/_color_8hpp-source.html +0 -216
- data/reference/cpp/_color_8hpp.html +0 -130
- data/reference/cpp/_color_8hpp_source.html +0 -232
- data/reference/cpp/_directories_8hpp-source.html +0 -89
- data/reference/cpp/_directories_8hpp.html +0 -103
- data/reference/cpp/_directories_8hpp_source.html +0 -89
- data/reference/cpp/_font_8hpp-source.html +0 -116
- data/reference/cpp/_font_8hpp.html +0 -94
- data/reference/cpp/_font_8hpp_source.html +0 -116
- data/reference/cpp/_fwd_8hpp-source.html +0 -99
- data/reference/cpp/_fwd_8hpp.html +0 -90
- data/reference/cpp/_fwd_8hpp_source.html +0 -99
- data/reference/cpp/_gosu_8hpp-source.html +0 -97
- data/reference/cpp/_gosu_8hpp.html +0 -84
- data/reference/cpp/_gosu_8hpp_source.html +0 -97
- data/reference/cpp/_graphics_8hpp-source.html +0 -135
- data/reference/cpp/_graphics_8hpp.html +0 -101
- data/reference/cpp/_graphics_8hpp_source.html +0 -144
- data/reference/cpp/_graphics_base_8hpp-source.html +0 -116
- data/reference/cpp/_graphics_base_8hpp.html +0 -128
- data/reference/cpp/_graphics_base_8hpp_source.html +0 -117
- data/reference/cpp/_i_o_8hpp-source.html +0 -302
- data/reference/cpp/_i_o_8hpp.html +0 -129
- data/reference/cpp/_i_o_8hpp_source.html +0 -295
- data/reference/cpp/_image_8hpp-source.html +0 -173
- data/reference/cpp/_image_8hpp.html +0 -103
- data/reference/cpp/_image_8hpp_source.html +0 -176
- data/reference/cpp/_image_data_8hpp-source.html +0 -109
- data/reference/cpp/_image_data_8hpp.html +0 -97
- data/reference/cpp/_image_data_8hpp_source.html +0 -109
- data/reference/cpp/_input_8hpp-source.html +0 -183
- data/reference/cpp/_input_8hpp.html +0 -109
- data/reference/cpp/_input_8hpp_source.html +0 -183
- data/reference/cpp/_math_8hpp-source.html +0 -157
- data/reference/cpp/_math_8hpp.html +0 -152
- data/reference/cpp/_math_8hpp_source.html +0 -157
- data/reference/cpp/_platform_8hpp-source.html +0 -134
- data/reference/cpp/_platform_8hpp.html +0 -162
- data/reference/cpp/_platform_8hpp_source.html +0 -134
- data/reference/cpp/_rot_flip_8hpp-source.html +0 -185
- data/reference/cpp/_rot_flip_8hpp.html +0 -130
- data/reference/cpp/_rot_flip_8hpp_source.html +0 -185
- data/reference/cpp/_sockets_8hpp-source.html +0 -175
- data/reference/cpp/_sockets_8hpp.html +0 -124
- data/reference/cpp/_sockets_8hpp_source.html +0 -175
- data/reference/cpp/_text_8hpp-source.html +0 -103
- data/reference/cpp/_text_8hpp.html +0 -106
- data/reference/cpp/_text_8hpp_source.html +0 -103
- data/reference/cpp/_text_input_8hpp-source.html +0 -111
- data/reference/cpp/_text_input_8hpp.html +0 -94
- data/reference/cpp/_text_input_8hpp_source.html +0 -116
- data/reference/cpp/_timing_8hpp-source.html +0 -83
- data/reference/cpp/_timing_8hpp.html +0 -97
- data/reference/cpp/_timing_8hpp_source.html +0 -83
- data/reference/cpp/_utility_8hpp-source.html +0 -90
- data/reference/cpp/_utility_8hpp.html +0 -103
- data/reference/cpp/_utility_8hpp_source.html +0 -90
- data/reference/cpp/_version_8hpp-source.html +0 -78
- data/reference/cpp/_version_8hpp.html +0 -154
- data/reference/cpp/_version_8hpp_source.html +0 -78
- data/reference/cpp/_win_utility_8hpp-source.html +0 -126
- data/reference/cpp/_win_utility_8hpp.html +0 -128
- data/reference/cpp/_win_utility_8hpp_source.html +0 -126
- data/reference/cpp/_window_8hpp-source.html +0 -158
- data/reference/cpp/_window_8hpp.html +0 -94
- data/reference/cpp/_window_8hpp_source.html +0 -159
- data/reference/cpp/annotated.html +0 -98
- data/reference/cpp/class_gosu_1_1_audio-members.html +0 -76
- data/reference/cpp/class_gosu_1_1_audio.html +0 -155
- data/reference/cpp/class_gosu_1_1_bitmap-members.html +0 -86
- data/reference/cpp/class_gosu_1_1_bitmap.html +0 -506
- data/reference/cpp/class_gosu_1_1_buffer-members.html +0 -85
- data/reference/cpp/class_gosu_1_1_buffer.html +0 -341
- data/reference/cpp/class_gosu_1_1_buffer.png +0 -0
- data/reference/cpp/class_gosu_1_1_button-members.html +0 -77
- data/reference/cpp/class_gosu_1_1_button.html +0 -198
- data/reference/cpp/class_gosu_1_1_color-members.html +0 -108
- data/reference/cpp/class_gosu_1_1_color.html +0 -972
- data/reference/cpp/class_gosu_1_1_comm_socket-members.html +0 -91
- data/reference/cpp/class_gosu_1_1_comm_socket.html +0 -506
- data/reference/cpp/class_gosu_1_1_file-members.html +0 -82
- data/reference/cpp/class_gosu_1_1_file.html +0 -276
- data/reference/cpp/class_gosu_1_1_file.png +0 -0
- data/reference/cpp/class_gosu_1_1_font-members.html +0 -82
- data/reference/cpp/class_gosu_1_1_font.html +0 -506
- data/reference/cpp/class_gosu_1_1_graphics-members.html +0 -93
- data/reference/cpp/class_gosu_1_1_graphics.html +0 -817
- data/reference/cpp/class_gosu_1_1_image-members.html +0 -87
- data/reference/cpp/class_gosu_1_1_image.html +0 -797
- data/reference/cpp/class_gosu_1_1_image_data-members.html +0 -78
- data/reference/cpp/class_gosu_1_1_image_data.html +0 -282
- data/reference/cpp/class_gosu_1_1_input-members.html +0 -86
- data/reference/cpp/class_gosu_1_1_input.html +0 -418
- data/reference/cpp/class_gosu_1_1_listener_socket-members.html +0 -79
- data/reference/cpp/class_gosu_1_1_listener_socket.html +0 -222
- data/reference/cpp/class_gosu_1_1_message_socket-members.html +0 -81
- data/reference/cpp/class_gosu_1_1_message_socket.html +0 -306
- data/reference/cpp/class_gosu_1_1_reader-members.html +0 -81
- data/reference/cpp/class_gosu_1_1_reader.html +0 -323
- data/reference/cpp/class_gosu_1_1_resource-members.html +0 -80
- data/reference/cpp/class_gosu_1_1_resource.html +0 -306
- data/reference/cpp/class_gosu_1_1_resource.png +0 -0
- data/reference/cpp/class_gosu_1_1_rot_flip-members.html +0 -84
- data/reference/cpp/class_gosu_1_1_rot_flip.html +0 -352
- data/reference/cpp/class_gosu_1_1_sample-members.html +0 -80
- data/reference/cpp/class_gosu_1_1_sample.html +0 -324
- data/reference/cpp/class_gosu_1_1_sample_instance-members.html +0 -82
- data/reference/cpp/class_gosu_1_1_sample_instance.html +0 -318
- data/reference/cpp/class_gosu_1_1_song-members.html +0 -90
- data/reference/cpp/class_gosu_1_1_song.html +0 -493
- data/reference/cpp/class_gosu_1_1_text_input-members.html +0 -80
- data/reference/cpp/class_gosu_1_1_text_input.html +0 -255
- data/reference/cpp/class_gosu_1_1_window-members.html +0 -91
- data/reference/cpp/class_gosu_1_1_window.html +0 -534
- data/reference/cpp/class_gosu_1_1_writer-members.html +0 -80
- data/reference/cpp/class_gosu_1_1_writer.html +0 -293
- data/reference/cpp/classes.html +0 -86
- data/reference/cpp/closed.gif +0 -0
- data/reference/cpp/cpp.css +0 -155
- data/reference/cpp/doxygen.png +0 -0
- data/reference/cpp/files.html +0 -99
- data/reference/cpp/functions.html +0 -128
- data/reference/cpp/functions_0x62.html +0 -144
- data/reference/cpp/functions_0x63.html +0 -143
- data/reference/cpp/functions_0x64.html +0 -143
- data/reference/cpp/functions_0x65.html +0 -122
- data/reference/cpp/functions_0x66.html +0 -144
- data/reference/cpp/functions_0x67.html +0 -136
- data/reference/cpp/functions_0x68.html +0 -122
- data/reference/cpp/functions_0x69.html +0 -124
- data/reference/cpp/functions_0x6b.html +0 -116
- data/reference/cpp/functions_0x6c.html +0 -118
- data/reference/cpp/functions_0x6d.html +0 -126
- data/reference/cpp/functions_0x6e.html +0 -121
- data/reference/cpp/functions_0x6f.html +0 -127
- data/reference/cpp/functions_0x70.html +0 -137
- data/reference/cpp/functions_0x72.html +0 -157
- data/reference/cpp/functions_0x73.html +0 -180
- data/reference/cpp/functions_0x74.html +0 -128
- data/reference/cpp/functions_0x75.html +0 -123
- data/reference/cpp/functions_0x76.html +0 -118
- data/reference/cpp/functions_0x77.html +0 -132
- data/reference/cpp/functions_0x78.html +0 -116
- data/reference/cpp/functions_0x79.html +0 -118
- data/reference/cpp/functions_0x7e.html +0 -142
- data/reference/cpp/functions_enum.html +0 -88
- data/reference/cpp/functions_eval.html +0 -90
- data/reference/cpp/functions_func.html +0 -124
- data/reference/cpp/functions_func_0x62.html +0 -136
- data/reference/cpp/functions_func_0x63.html +0 -137
- data/reference/cpp/functions_func_0x64.html +0 -141
- data/reference/cpp/functions_func_0x65.html +0 -120
- data/reference/cpp/functions_func_0x66.html +0 -140
- data/reference/cpp/functions_func_0x67.html +0 -130
- data/reference/cpp/functions_func_0x68.html +0 -120
- data/reference/cpp/functions_func_0x69.html +0 -120
- data/reference/cpp/functions_func_0x6b.html +0 -114
- data/reference/cpp/functions_func_0x6c.html +0 -114
- data/reference/cpp/functions_func_0x6d.html +0 -124
- data/reference/cpp/functions_func_0x6e.html +0 -117
- data/reference/cpp/functions_func_0x6f.html +0 -114
- data/reference/cpp/functions_func_0x70.html +0 -135
- data/reference/cpp/functions_func_0x72.html +0 -151
- data/reference/cpp/functions_func_0x73.html +0 -174
- data/reference/cpp/functions_func_0x74.html +0 -120
- data/reference/cpp/functions_func_0x75.html +0 -121
- data/reference/cpp/functions_func_0x76.html +0 -116
- data/reference/cpp/functions_func_0x77.html +0 -128
- data/reference/cpp/functions_func_0x7e.html +0 -140
- data/reference/cpp/functions_type.html +0 -88
- data/reference/cpp/functions_vars.html +0 -135
- data/reference/cpp/globals.html +0 -95
- data/reference/cpp/globals_defs.html +0 -95
- data/reference/cpp/hierarchy.html +0 -100
- data/reference/cpp/index.html +0 -67
- data/reference/cpp/namespace_gosu.html +0 -3311
- data/reference/cpp/namespace_gosu_1_1_colors.html +0 -287
- data/reference/cpp/namespace_gosu_1_1_win.html +0 -354
- data/reference/cpp/namespacemembers.html +0 -139
- data/reference/cpp/namespacemembers_0x62.html +0 -143
- data/reference/cpp/namespacemembers_0x63.html +0 -125
- data/reference/cpp/namespacemembers_0x64.html +0 -121
- data/reference/cpp/namespacemembers_0x66.html +0 -129
- data/reference/cpp/namespacemembers_0x67.html +0 -163
- data/reference/cpp/namespacemembers_0x68.html +0 -113
- data/reference/cpp/namespacemembers_0x69.html +0 -117
- data/reference/cpp/namespacemembers_0x6b.html +0 -289
- data/reference/cpp/namespacemembers_0x6c.html +0 -119
- data/reference/cpp/namespacemembers_0x6d.html +0 -131
- data/reference/cpp/namespacemembers_0x6e.html +0 -127
- data/reference/cpp/namespacemembers_0x6f.html +0 -121
- data/reference/cpp/namespacemembers_0x70.html +0 -115
- data/reference/cpp/namespacemembers_0x71.html +0 -113
- data/reference/cpp/namespacemembers_0x72.html +0 -165
- data/reference/cpp/namespacemembers_0x73.html +0 -135
- data/reference/cpp/namespacemembers_0x74.html +0 -129
- data/reference/cpp/namespacemembers_0x75.html +0 -117
- data/reference/cpp/namespacemembers_0x77.html +0 -117
- data/reference/cpp/namespacemembers_0x79.html +0 -113
- data/reference/cpp/namespacemembers_0x7a.html +0 -115
- data/reference/cpp/namespacemembers_enum.html +0 -103
- data/reference/cpp/namespacemembers_eval.html +0 -445
- data/reference/cpp/namespacemembers_func.html +0 -269
- data/reference/cpp/namespacemembers_type.html +0 -93
- data/reference/cpp/namespacemembers_vars.html +0 -117
- data/reference/cpp/namespaces.html +0 -76
- data/reference/cpp/open.gif +0 -0
- data/reference/cpp/struct_gosu_1_1_g_l_tex_info-members.html +0 -78
- data/reference/cpp/struct_gosu_1_1_g_l_tex_info.html +0 -186
- data/reference/cpp/struct_gosu_1_1_touch-members.html +0 -76
- data/reference/cpp/struct_gosu_1_1_touch.html +0 -154
- data/reference/cpp/tab_b.gif +0 -0
- data/reference/cpp/tab_l.gif +0 -0
- data/reference/cpp/tab_r.gif +0 -0
- data/reference/cpp/tabs.css +0 -105
- data/reference/rdoc/classes/Gosu.html +0 -1546
- data/reference/rdoc/classes/Gosu/Color.html +0 -660
- data/reference/rdoc/classes/Gosu/Font.html +0 -545
- data/reference/rdoc/classes/Gosu/GLTexInfo.html +0 -412
- data/reference/rdoc/classes/Gosu/Image.html +0 -706
- data/reference/rdoc/classes/Gosu/Sample.html +0 -476
- data/reference/rdoc/classes/Gosu/SampleInstance.html +0 -523
- data/reference/rdoc/classes/Gosu/Song.html +0 -568
- data/reference/rdoc/classes/Gosu/TextInput.html +0 -444
- data/reference/rdoc/classes/Gosu/Window.html +0 -911
- data/reference/rdoc/classes/Numeric.html +0 -479
- data/reference/rdoc/created.rid +0 -1
- data/reference/rdoc/files/COPYING_txt.html +0 -391
- data/reference/rdoc/files/README_txt.html +0 -387
- data/reference/rdoc/files/reference/Deployment on OS X_rdoc.html +0 -381
- data/reference/rdoc/files/reference/Deployment on Windows_rdoc.html +0 -385
- data/reference/rdoc/files/reference/Drawing with Colors_rdoc.html +0 -363
- data/reference/rdoc/files/reference/Order of Corners_rdoc.html +0 -358
- data/reference/rdoc/files/reference/Tileability_rdoc.html +0 -374
- data/reference/rdoc/files/reference/Z Ordering_rdoc.html +0 -361
- data/reference/rdoc/files/reference/gosu_rb.html +0 -348
- data/reference/rdoc/fr_class_index.html +0 -12
- data/reference/rdoc/fr_file_index.html +0 -10
- data/reference/rdoc/fr_method_index.html +0 -66
- data/reference/rdoc/index.html +0 -1
- data/reference/rdoc/rdoc-style.css +0 -320
data/Gosu/Input.hpp
CHANGED
@@ -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
|
37
|
+
unsigned id_;
|
38
38
|
|
39
39
|
public:
|
40
40
|
//! For internal use.
|
41
|
-
explicit Button(unsigned id) :
|
41
|
+
explicit Button(unsigned id) : id_(id) {}
|
42
42
|
//! For internal use.
|
43
|
-
unsigned
|
43
|
+
unsigned id() const { return id_; }
|
44
44
|
|
45
45
|
//! Default constructor; == noButton.
|
46
|
-
Button() :
|
46
|
+
Button() : id_(noButton) {}
|
47
47
|
|
48
48
|
//! Conversion from ButtonName constants.
|
49
|
-
Button(ButtonName 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.
|
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.
|
data/Gosu/Math.hpp
CHANGED
@@ -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
|
{
|
data/Gosu/TextInput.hpp
CHANGED
@@ -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)
|
data/Gosu/Version.hpp
CHANGED
@@ -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
|
+
}
|
data/GosuImpl/InputMac.mm
CHANGED
@@ -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.
|
610
|
-
return idChars[btn.
|
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.
|
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.
|
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)
|
data/GosuImpl/InputWin.cpp
CHANGED
@@ -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.
|
386
|
+
if (btn.id() > 255)
|
387
387
|
return 0;
|
388
388
|
|
389
389
|
// Special case...?
|
390
|
-
if (btn.
|
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.
|
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.
|
408
|
+
return buttons.at(btn.id());
|
409
409
|
}
|
410
410
|
|
411
411
|
double Gosu::Input::mouseX() const
|
data/GosuImpl/InputX.cpp
CHANGED
@@ -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.
|
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.
|
78
|
-
return btn.
|
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.
|
84
|
+
//if ((btn.id() >> 8) == 0)
|
85
85
|
//{
|
86
|
-
// unsigned char in[] = { btn.
|
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
|