gosu 0.8.0.pre3 → 0.8.0.pre4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gosu/Buttons.hpp +13 -11
- data/{linux → ext/gosu}/extconf.rb +25 -47
- data/{GosuImpl/RubyGosu_wrap.cxx → ext/gosu/gosu_wrap.cxx} +3 -2
- data/{GosuImpl/RubyGosu_wrap.h → ext/gosu/gosu_wrap.h} +0 -0
- data/lib/gosu.rb +6 -7
- data/lib/gosu/zen.rb +12 -0
- data/{GosuImpl → src}/Audio/ALChannelManagement.hpp +0 -0
- data/{GosuImpl → src}/Audio/AudioFile.hpp +0 -0
- data/{GosuImpl → src}/Audio/AudioOpenAL.cpp +0 -0
- data/{GosuImpl → src}/Audio/AudioOpenAL.mm +0 -0
- data/{GosuImpl → src}/Audio/AudioToolboxFile.hpp +0 -0
- data/{GosuImpl → src}/Audio/OggFile.hpp +0 -0
- data/{GosuImpl → src}/Audio/SndFile.hpp +0 -0
- data/{GosuImpl/Graphics → src/Bitmap}/Bitmap.cpp +2 -0
- data/{GosuImpl/Graphics → src/Bitmap}/BitmapApple.mm +0 -0
- data/{GosuImpl/Graphics → src/Bitmap}/BitmapBMP.cpp +0 -0
- data/{GosuImpl/Graphics → src/Bitmap}/BitmapColorKey.cpp +0 -0
- data/{GosuImpl/Graphics → src/Bitmap}/BitmapFreeImage.cpp +0 -0
- data/{GosuImpl/Graphics → src/Bitmap}/BitmapGDIplus.cpp +0 -0
- data/{GosuImpl/Graphics → src/Bitmap}/BitmapUtils.cpp +0 -0
- data/{GosuImpl → src}/DirectoriesMac.mm +0 -0
- data/{GosuImpl → src}/DirectoriesTouch.mm +0 -0
- data/{GosuImpl → src}/DirectoriesUnix.cpp +0 -0
- data/{GosuImpl → src}/DirectoriesWin.cpp +0 -0
- data/{GosuImpl → src}/FileUnix.cpp +0 -0
- data/{GosuImpl → src}/FileWin.cpp +0 -0
- data/{GosuImpl/Graphics → src}/GosuView.hpp +0 -0
- data/{GosuImpl/Graphics → src}/GosuView.mm +0 -0
- data/{GosuImpl → src}/Graphics/BlockAllocator.cpp +0 -0
- data/{GosuImpl → src}/Graphics/BlockAllocator.hpp +0 -0
- data/{GosuImpl → src}/Graphics/ClipRectStack.hpp +0 -0
- data/{GosuImpl → src}/Graphics/Color.cpp +0 -0
- data/{GosuImpl → src}/Graphics/Common.hpp +0 -0
- data/{GosuImpl → src}/Graphics/DrawOp.hpp +0 -0
- data/{GosuImpl → src}/Graphics/DrawOpQueue.hpp +0 -0
- data/{GosuImpl → src}/Graphics/Graphics.cpp +0 -0
- data/{GosuImpl → src}/Graphics/Image.cpp +0 -0
- data/{GosuImpl → src}/Graphics/LargeImageData.cpp +0 -0
- data/{GosuImpl → src}/Graphics/LargeImageData.hpp +0 -0
- data/{GosuImpl → src}/Graphics/Macro.hpp +0 -0
- data/{GosuImpl → src}/Graphics/RenderState.hpp +0 -0
- data/{GosuImpl → src}/Graphics/TexChunk.cpp +0 -0
- data/{GosuImpl → src}/Graphics/TexChunk.hpp +0 -0
- data/{GosuImpl → src}/Graphics/Texture.cpp +0 -0
- data/{GosuImpl → src}/Graphics/Texture.hpp +0 -0
- data/{GosuImpl → src}/Graphics/Transform.cpp +0 -0
- data/{GosuImpl → src}/Graphics/TransformStack.hpp +0 -0
- data/{GosuImpl → src}/IO.cpp +0 -0
- data/{GosuImpl → src}/Iconv.hpp +0 -0
- data/{GosuImpl → src}/Input/AccelerometerReader.hpp +0 -0
- data/{GosuImpl → src}/Input/AccelerometerReader.mm +0 -0
- data/{GosuImpl → src/Input}/Input.cpp +0 -0
- data/{GosuImpl → src/Input}/InputTouch.mm +0 -0
- data/{GosuImpl → src/Input}/TextInput.cpp +0 -0
- data/{GosuImpl → src/Input}/TextInputMac.mm +0 -0
- data/{GosuImpl → src}/Inspection.cpp +0 -0
- data/{GosuImpl → src}/MacUtility.hpp +0 -0
- data/{GosuImpl → src}/Math.cpp +0 -0
- data/{GosuImpl → src}/Sockets/CommSocket.cpp +0 -0
- data/{GosuImpl → src}/Sockets/ListenerSocket.cpp +0 -0
- data/{GosuImpl → src}/Sockets/MessageSocket.cpp +0 -0
- data/{GosuImpl → src}/Sockets/Socket.cpp +0 -0
- data/{GosuImpl → src}/Sockets/Socket.hpp +0 -0
- data/{GosuImpl/Graphics → src/Text}/Font.cpp +1 -1
- data/{GosuImpl/Graphics → src/Text}/FormattedString.hpp +0 -0
- data/{GosuImpl/Graphics → src/Text}/Text.cpp +1 -1
- data/{GosuImpl/Graphics/TextTouch.mm → src/Text/TextApple.mm} +0 -0
- data/{GosuImpl/Graphics → src/Text}/TextMac.cpp +1 -1
- data/{GosuImpl/Graphics → src/Text}/TextTTFWin.cpp +0 -0
- data/{GosuImpl/Graphics → src/Text}/TextUnix.cpp +0 -0
- data/{GosuImpl/Graphics → src/Text}/TextWin.cpp +0 -0
- data/{GosuImpl → src}/TimingApple.cpp +0 -0
- data/{GosuImpl → src}/TimingUnix.cpp +0 -0
- data/{GosuImpl → src}/TimingWin.cpp +0 -0
- data/{GosuImpl → src}/Utility.cpp +0 -0
- data/{GosuImpl → src}/UtilityApple.mm +0 -0
- data/{GosuImpl → src}/UtilityWin.cpp +0 -0
- data/{GosuImpl → src}/WinMain.cpp +0 -0
- data/{GosuImpl → src}/WinUtility.cpp +0 -0
- data/{GosuImpl → src}/Window.cpp +0 -0
- data/{GosuImpl → src}/WindowTouch.mm +0 -0
- data/{GosuImpl → src}/X11vroot.h +0 -0
- metadata +97 -193
- data/.yardopts +0 -1
- data/COPYING +0 -29
- data/GosuImpl/InputMac.mm +0 -733
- data/GosuImpl/InputWin.cpp +0 -483
- data/GosuImpl/InputX.cpp +0 -243
- data/GosuImpl/RubyGosu.swg +0 -821
- data/GosuImpl/RubyGosu_SWIG_GC_PATCH.patch +0 -126
- data/GosuImpl/RubyGosu_SWIG_RENAME_PATCH.patch +0 -62
- data/GosuImpl/TextInputWin.cpp +0 -211
- data/GosuImpl/TextInputX.cpp +0 -217
- data/GosuImpl/WindowWin.cpp +0 -534
- data/GosuImpl/WindowX.cpp +0 -458
- data/README.txt +0 -25
- data/dependencies/libogg/AUTHORS +0 -4
- data/dependencies/libogg/CHANGES +0 -70
- data/dependencies/libogg/COPYING +0 -28
- data/dependencies/libogg/include/ogg/ogg.h +0 -209
- data/dependencies/libogg/include/ogg/os_types.h +0 -147
- data/dependencies/libogg/src/bitwise.c +0 -857
- data/dependencies/libogg/src/framing.c +0 -2089
- data/dependencies/libvorbis/AUTHORS +0 -3
- data/dependencies/libvorbis/CHANGES +0 -126
- data/dependencies/libvorbis/COPYING +0 -28
- data/dependencies/libvorbis/include/vorbis/codec.h +0 -243
- data/dependencies/libvorbis/include/vorbis/vorbisenc.h +0 -436
- data/dependencies/libvorbis/include/vorbis/vorbisfile.h +0 -206
- data/dependencies/libvorbis/lib/analysis.c +0 -120
- data/dependencies/libvorbis/lib/backends.h +0 -144
- data/dependencies/libvorbis/lib/barkmel.c +0 -64
- data/dependencies/libvorbis/lib/bitrate.c +0 -253
- data/dependencies/libvorbis/lib/bitrate.h +0 -59
- data/dependencies/libvorbis/lib/block.c +0 -1046
- data/dependencies/libvorbis/lib/books/coupled/res_books_51.h +0 -12257
- data/dependencies/libvorbis/lib/books/coupled/res_books_stereo.h +0 -15783
- data/dependencies/libvorbis/lib/books/floor/floor_books.h +0 -1547
- data/dependencies/libvorbis/lib/books/uncoupled/res_books_uncoupled.h +0 -7758
- data/dependencies/libvorbis/lib/codebook.c +0 -479
- data/dependencies/libvorbis/lib/codebook.h +0 -119
- data/dependencies/libvorbis/lib/codec_internal.h +0 -167
- data/dependencies/libvorbis/lib/envelope.c +0 -375
- data/dependencies/libvorbis/lib/envelope.h +0 -80
- data/dependencies/libvorbis/lib/floor0.c +0 -222
- data/dependencies/libvorbis/lib/floor1.c +0 -1099
- data/dependencies/libvorbis/lib/highlevel.h +0 -58
- data/dependencies/libvorbis/lib/info.c +0 -664
- data/dependencies/libvorbis/lib/lookup.c +0 -94
- data/dependencies/libvorbis/lib/lookup.h +0 -32
- data/dependencies/libvorbis/lib/lookup_data.h +0 -192
- data/dependencies/libvorbis/lib/lpc.c +0 -160
- data/dependencies/libvorbis/lib/lpc.h +0 -29
- data/dependencies/libvorbis/lib/lsp.c +0 -456
- data/dependencies/libvorbis/lib/lsp.h +0 -28
- data/dependencies/libvorbis/lib/mapping0.c +0 -816
- data/dependencies/libvorbis/lib/masking.h +0 -785
- data/dependencies/libvorbis/lib/mdct.c +0 -563
- data/dependencies/libvorbis/lib/mdct.h +0 -71
- data/dependencies/libvorbis/lib/misc.h +0 -57
- data/dependencies/libvorbis/lib/modes/floor_all.h +0 -260
- data/dependencies/libvorbis/lib/modes/psych_11.h +0 -51
- data/dependencies/libvorbis/lib/modes/psych_16.h +0 -133
- data/dependencies/libvorbis/lib/modes/psych_44.h +0 -642
- data/dependencies/libvorbis/lib/modes/psych_8.h +0 -101
- data/dependencies/libvorbis/lib/modes/residue_16.h +0 -163
- data/dependencies/libvorbis/lib/modes/residue_44.h +0 -292
- data/dependencies/libvorbis/lib/modes/residue_44p51.h +0 -451
- data/dependencies/libvorbis/lib/modes/residue_44u.h +0 -318
- data/dependencies/libvorbis/lib/modes/residue_8.h +0 -109
- data/dependencies/libvorbis/lib/modes/setup_11.h +0 -143
- data/dependencies/libvorbis/lib/modes/setup_16.h +0 -153
- data/dependencies/libvorbis/lib/modes/setup_22.h +0 -128
- data/dependencies/libvorbis/lib/modes/setup_32.h +0 -132
- data/dependencies/libvorbis/lib/modes/setup_44.h +0 -117
- data/dependencies/libvorbis/lib/modes/setup_44p51.h +0 -74
- data/dependencies/libvorbis/lib/modes/setup_44u.h +0 -74
- data/dependencies/libvorbis/lib/modes/setup_8.h +0 -149
- data/dependencies/libvorbis/lib/modes/setup_X.h +0 -225
- data/dependencies/libvorbis/lib/os.h +0 -186
- data/dependencies/libvorbis/lib/psy.c +0 -1203
- data/dependencies/libvorbis/lib/psy.h +0 -154
- data/dependencies/libvorbis/lib/psytune.c +0 -524
- data/dependencies/libvorbis/lib/registry.c +0 -45
- data/dependencies/libvorbis/lib/registry.h +0 -32
- data/dependencies/libvorbis/lib/res0.c +0 -889
- data/dependencies/libvorbis/lib/scales.h +0 -90
- data/dependencies/libvorbis/lib/sharedbook.c +0 -579
- data/dependencies/libvorbis/lib/smallft.c +0 -1255
- data/dependencies/libvorbis/lib/smallft.h +0 -34
- data/dependencies/libvorbis/lib/synthesis.c +0 -184
- data/dependencies/libvorbis/lib/tone.c +0 -54
- data/dependencies/libvorbis/lib/vorbisenc.c +0 -1215
- data/dependencies/libvorbis/lib/vorbisfile.c +0 -2337
- data/dependencies/libvorbis/lib/window.c +0 -2135
- data/dependencies/libvorbis/lib/window.h +0 -26
- data/dependencies/ogg_vorbis.license +0 -28
- data/reference/gosu.rb +0 -1284
@@ -1,126 +0,0 @@
|
|
1
|
-
Index: GosuImpl/RubyGosu_wrap.cxx
|
2
|
-
===================================================================
|
3
|
-
--- GosuImpl/RubyGosu_wrap.cxx (Revision 993)
|
4
|
-
+++ GosuImpl/RubyGosu_wrap.cxx (Arbeitskopie)
|
5
|
-
@@ -8,6 +8,10 @@
|
6
|
-
* interface file instead.
|
7
|
-
* ----------------------------------------------------------------------------- */
|
8
|
-
|
9
|
-
+// This file was afterwards patched using the following instructions:
|
10
|
-
+// http://sourceforge.net/tracker/index.php?func=detail&aid=2034216&group_id=1645&atid=101645
|
11
|
-
+// (Many thanks to Kevin Burge for that.)
|
12
|
-
+
|
13
|
-
#define SWIGRUBY
|
14
|
-
#define SWIG_DIRECTORS
|
15
|
-
|
16
|
-
@@ -855,6 +859,7 @@
|
17
|
-
|
18
|
-
|
19
|
-
#include <ruby.h>
|
20
|
-
+#include <map>
|
21
|
-
|
22
|
-
/* Remove global macros defined in Ruby's win32.h */
|
23
|
-
#ifdef write
|
24
|
-
@@ -1183,7 +1188,7 @@
|
25
|
-
/* Global Ruby hash table to store Trackings from C/C++
|
26
|
-
structs to Ruby Objects.
|
27
|
-
*/
|
28
|
-
-static VALUE swig_ruby_trackings = Qnil;
|
29
|
-
+static std::map<void*, VALUE> swig_ruby_trackings;
|
30
|
-
|
31
|
-
/* Global variable that stores a reference to the ruby
|
32
|
-
hash table delete function. */
|
33
|
-
@@ -1200,34 +1205,18 @@
|
34
|
-
This is done to allow multiple DSOs to share the same
|
35
|
-
tracking table.
|
36
|
-
*/
|
37
|
-
- ID trackings_id = rb_intern( "@__trackings__" );
|
38
|
-
VALUE verbose = rb_gv_get("VERBOSE");
|
39
|
-
rb_gv_set("VERBOSE", Qfalse);
|
40
|
-
- swig_ruby_trackings = rb_ivar_get( _mSWIG, trackings_id );
|
41
|
-
rb_gv_set("VERBOSE", verbose);
|
42
|
-
|
43
|
-
/* No, it hasn't. Create one ourselves */
|
44
|
-
- if ( swig_ruby_trackings == Qnil )
|
45
|
-
- {
|
46
|
-
- swig_ruby_trackings = rb_hash_new();
|
47
|
-
- rb_ivar_set( _mSWIG, trackings_id, swig_ruby_trackings );
|
48
|
-
- }
|
49
|
-
+ swig_ruby_trackings.clear();
|
50
|
-
|
51
|
-
/* Now store a reference to the hash table delete function
|
52
|
-
so that we only have to look it up once.*/
|
53
|
-
swig_ruby_hash_delete = rb_intern("delete");
|
54
|
-
}
|
55
|
-
|
56
|
-
-/* Get a Ruby number to reference a pointer */
|
57
|
-
-SWIGRUNTIME VALUE SWIG_RubyPtrToReference(void* ptr) {
|
58
|
-
- /* We cast the pointer to an unsigned long
|
59
|
-
- and then store a reference to it using
|
60
|
-
- a Ruby number object. */
|
61
|
-
-
|
62
|
-
- /* Convert the pointer to a Ruby number */
|
63
|
-
- return SWIG2NUM(ptr);
|
64
|
-
-}
|
65
|
-
-
|
66
|
-
/* Get a Ruby number to reference an object */
|
67
|
-
SWIGRUNTIME VALUE SWIG_RubyObjectToReference(VALUE object) {
|
68
|
-
/* We cast the object to an unsigned long
|
69
|
-
@@ -1249,39 +1238,16 @@
|
70
|
-
|
71
|
-
/* Add a Tracking from a C/C++ struct to a Ruby object */
|
72
|
-
SWIGRUNTIME void SWIG_RubyAddTracking(void* ptr, VALUE object) {
|
73
|
-
- /* In a Ruby hash table we store the pointer and
|
74
|
-
- the associated Ruby object. The trick here is
|
75
|
-
- that we cannot store the Ruby object directly - if
|
76
|
-
- we do then it cannot be garbage collected. So
|
77
|
-
- instead we typecast it as a unsigned long and
|
78
|
-
- convert it to a Ruby number object.*/
|
79
|
-
-
|
80
|
-
- /* Get a reference to the pointer as a Ruby number */
|
81
|
-
- VALUE key = SWIG_RubyPtrToReference(ptr);
|
82
|
-
-
|
83
|
-
- /* Get a reference to the Ruby object as a Ruby number */
|
84
|
-
- VALUE value = SWIG_RubyObjectToReference(object);
|
85
|
-
-
|
86
|
-
/* Store the mapping to the global hash table. */
|
87
|
-
- rb_hash_aset(swig_ruby_trackings, key, value);
|
88
|
-
+ swig_ruby_trackings[ptr] = object;
|
89
|
-
}
|
90
|
-
|
91
|
-
/* Get the Ruby object that owns the specified C/C++ struct */
|
92
|
-
SWIGRUNTIME VALUE SWIG_RubyInstanceFor(void* ptr) {
|
93
|
-
- /* Get a reference to the pointer as a Ruby number */
|
94
|
-
- VALUE key = SWIG_RubyPtrToReference(ptr);
|
95
|
-
-
|
96
|
-
- /* Now lookup the value stored in the global hash table */
|
97
|
-
- VALUE value = rb_hash_aref(swig_ruby_trackings, key);
|
98
|
-
-
|
99
|
-
- if (value == Qnil) {
|
100
|
-
- /* No object exists - return nil. */
|
101
|
-
+ if (swig_ruby_trackings.count(ptr) == 0)
|
102
|
-
return Qnil;
|
103
|
-
- }
|
104
|
-
- else {
|
105
|
-
- /* Convert this value to Ruby object */
|
106
|
-
- return SWIG_RubyReferenceToObject(value);
|
107
|
-
- }
|
108
|
-
+ else
|
109
|
-
+ return swig_ruby_trackings[ptr];
|
110
|
-
}
|
111
|
-
|
112
|
-
/* Remove a Tracking from a C/C++ struct to a Ruby object. It
|
113
|
-
@@ -1289,12 +1255,7 @@
|
114
|
-
since the same memory address may be reused later to create
|
115
|
-
a new object. */
|
116
|
-
SWIGRUNTIME void SWIG_RubyRemoveTracking(void* ptr) {
|
117
|
-
- /* Get a reference to the pointer as a Ruby number */
|
118
|
-
- VALUE key = SWIG_RubyPtrToReference(ptr);
|
119
|
-
-
|
120
|
-
- /* Delete the object from the hash table by calling Ruby's
|
121
|
-
- do this we need to call the Hash.delete method.*/
|
122
|
-
- rb_funcall(swig_ruby_trackings, swig_ruby_hash_delete, 1, key);
|
123
|
-
+ swig_ruby_trackings.erase(ptr);
|
124
|
-
}
|
125
|
-
|
126
|
-
/* This is a helper method that unlinks a Ruby object from its
|
@@ -1,62 +0,0 @@
|
|
1
|
-
--- GosuImpl/RubyGosu_wrap.cxx
|
2
|
-
+++ GosuImpl/RubyGosu_wrap.cxx
|
3
|
-
@@ -2912,14 +2912,14 @@ SwigDirector_Window::~SwigDirector_Window() {
|
4
|
-
void SwigDirector_Window::update() {
|
5
|
-
VALUE result;
|
6
|
-
|
7
|
-
- result = rb_funcall(swig_get_self(), rb_intern("update"), 0, NULL);
|
8
|
-
+ result = rb_funcall(swig_get_self(), rb_intern("protected_update"), 0, NULL);
|
9
|
-
}
|
10
|
-
|
11
|
-
|
12
|
-
void SwigDirector_Window::draw() {
|
13
|
-
VALUE result;
|
14
|
-
|
15
|
-
- result = rb_funcall(swig_get_self(), rb_intern("draw"), 0, NULL);
|
16
|
-
+ result = rb_funcall(swig_get_self(), rb_intern("protected_draw_2"), 0, NULL);
|
17
|
-
}
|
18
|
-
|
19
|
-
|
20
|
-
@@ -2927,7 +2927,7 @@ bool SwigDirector_Window::needsRedraw() const {
|
21
|
-
bool c_result ;
|
22
|
-
VALUE result;
|
23
|
-
|
24
|
-
- result = rb_funcall(swig_get_self(), rb_intern("needs_redraw?"), 0, NULL);
|
25
|
-
+ result = rb_funcall(swig_get_self(), rb_intern("protected_needs_redraw?"), 0, NULL);
|
26
|
-
bool swig_val;
|
27
|
-
int swig_res = SWIG_AsVal_bool(result, &swig_val);
|
28
|
-
if (!SWIG_IsOK(swig_res)) {
|
29
|
-
@@ -2942,7 +2942,7 @@ bool SwigDirector_Window::needsCursor() const {
|
30
|
-
bool c_result ;
|
31
|
-
VALUE result;
|
32
|
-
|
33
|
-
- result = rb_funcall(swig_get_self(), rb_intern("needs_cursor?"), 0, NULL);
|
34
|
-
+ result = rb_funcall(swig_get_self(), rb_intern("protected_needs_cursor?"), 0, NULL);
|
35
|
-
bool swig_val;
|
36
|
-
int swig_res = SWIG_AsVal_bool(result, &swig_val);
|
37
|
-
if (!SWIG_IsOK(swig_res)) {
|
38
|
-
@@ -2956,7 +2956,7 @@ bool SwigDirector_Window::needsCursor() const {
|
39
|
-
void SwigDirector_Window::loseFocus() {
|
40
|
-
VALUE result;
|
41
|
-
|
42
|
-
- result = rb_funcall(swig_get_self(), rb_intern("lose_focus"), 0, NULL);
|
43
|
-
+ result = rb_funcall(swig_get_self(), rb_intern("protected_lose_focus"), 0, NULL);
|
44
|
-
}
|
45
|
-
|
46
|
-
|
47
|
-
@@ -2977,7 +2977,7 @@ void SwigDirector_Window::buttonDown(Gosu::Button arg0) {
|
48
|
-
else
|
49
|
-
obj0 = LONG2NUM((&arg0)->id());
|
50
|
-
}
|
51
|
-
- result = rb_funcall(swig_get_self(), rb_intern("button_down"), 1,obj0);
|
52
|
-
+ result = rb_funcall(swig_get_self(), rb_intern("protected_button_down"), 1,obj0);
|
53
|
-
}
|
54
|
-
|
55
|
-
|
56
|
-
@@ -2991,7 +2991,7 @@ void SwigDirector_Window::buttonUp(Gosu::Button arg0) {
|
57
|
-
else
|
58
|
-
obj0 = LONG2NUM((&arg0)->id());
|
59
|
-
}
|
60
|
-
- result = rb_funcall(swig_get_self(), rb_intern("button_up"), 1,obj0);
|
61
|
-
+ result = rb_funcall(swig_get_self(), rb_intern("protected_button_up"), 1,obj0);
|
62
|
-
}
|
data/GosuImpl/TextInputWin.cpp
DELETED
@@ -1,211 +0,0 @@
|
|
1
|
-
#include <Gosu/TextInput.hpp>
|
2
|
-
#include <Gosu/Buttons.hpp>
|
3
|
-
#include <algorithm>
|
4
|
-
#include <vector>
|
5
|
-
#include <wctype.h>
|
6
|
-
|
7
|
-
// OPT-IN, have you heard of it?!
|
8
|
-
#ifndef NOMINMAX
|
9
|
-
#define NOMINMAX
|
10
|
-
#endif
|
11
|
-
#include <windows.h>
|
12
|
-
|
13
|
-
struct Gosu::TextInput::Impl
|
14
|
-
{
|
15
|
-
std::wstring text;
|
16
|
-
unsigned caretPos, selectionStart;
|
17
|
-
Impl() : caretPos(0), selectionStart(0) {}
|
18
|
-
};
|
19
|
-
|
20
|
-
Gosu::TextInput::TextInput()
|
21
|
-
: pimpl(new Impl)
|
22
|
-
{
|
23
|
-
}
|
24
|
-
|
25
|
-
Gosu::TextInput::~TextInput()
|
26
|
-
{
|
27
|
-
}
|
28
|
-
|
29
|
-
std::wstring Gosu::TextInput::text() const
|
30
|
-
{
|
31
|
-
return pimpl->text;
|
32
|
-
}
|
33
|
-
|
34
|
-
void Gosu::TextInput::setText(const std::wstring& text)
|
35
|
-
{
|
36
|
-
pimpl->text = text;
|
37
|
-
pimpl->caretPos = pimpl->selectionStart = text.length();
|
38
|
-
}
|
39
|
-
|
40
|
-
unsigned Gosu::TextInput::caretPos() const
|
41
|
-
{
|
42
|
-
return pimpl->caretPos;
|
43
|
-
}
|
44
|
-
|
45
|
-
void Gosu::TextInput::setCaretPos(unsigned pos)
|
46
|
-
{
|
47
|
-
pimpl->caretPos = pos;
|
48
|
-
}
|
49
|
-
|
50
|
-
unsigned Gosu::TextInput::selectionStart() const
|
51
|
-
{
|
52
|
-
return pimpl->selectionStart;
|
53
|
-
}
|
54
|
-
|
55
|
-
void Gosu::TextInput::setSelectionStart(unsigned pos)
|
56
|
-
{
|
57
|
-
pimpl->selectionStart = pos;
|
58
|
-
}
|
59
|
-
|
60
|
-
#define CARET_POS (pimpl->caretPos)
|
61
|
-
#define SEL_START (pimpl->selectionStart)
|
62
|
-
|
63
|
-
bool Gosu::TextInput::feedMessage(unsigned long message, unsigned long wparam, unsigned long lparam)
|
64
|
-
{
|
65
|
-
if (message == WM_CHAR && wparam >= 32 && wparam != 127)
|
66
|
-
{
|
67
|
-
// Delete (overwrite) previous selection.
|
68
|
-
if (CARET_POS != SEL_START)
|
69
|
-
{
|
70
|
-
unsigned min = std::min(CARET_POS, SEL_START);
|
71
|
-
unsigned max = std::max(CARET_POS, SEL_START);
|
72
|
-
pimpl->text.erase(pimpl->text.begin() + min, pimpl->text.begin() + max);
|
73
|
-
CARET_POS = SEL_START = min;
|
74
|
-
}
|
75
|
-
|
76
|
-
wchar_t text[] = { static_cast<wchar_t>(wparam), 0 };
|
77
|
-
std::wstring filteredText = filter(text);
|
78
|
-
pimpl->text.insert(pimpl->text.begin() + CARET_POS, filteredText.begin(), filteredText.end());
|
79
|
-
CARET_POS += filteredText.length();
|
80
|
-
SEL_START = CARET_POS;
|
81
|
-
return true;
|
82
|
-
}
|
83
|
-
|
84
|
-
bool ctrlDown = (GetKeyState(VK_CONTROL) < 0);
|
85
|
-
bool shiftDown = (GetKeyState(VK_SHIFT) < 0);
|
86
|
-
|
87
|
-
// Char left
|
88
|
-
if (message == WM_KEYDOWN && wparam == VK_LEFT && !ctrlDown)
|
89
|
-
{
|
90
|
-
if (CARET_POS > 0)
|
91
|
-
CARET_POS -= 1;
|
92
|
-
|
93
|
-
if (!shiftDown)
|
94
|
-
SEL_START = CARET_POS;
|
95
|
-
|
96
|
-
return true;
|
97
|
-
}
|
98
|
-
|
99
|
-
// Char right
|
100
|
-
if (message == WM_KEYDOWN && wparam == VK_RIGHT && !ctrlDown)
|
101
|
-
{
|
102
|
-
if (CARET_POS < pimpl->text.length())
|
103
|
-
CARET_POS += 1;
|
104
|
-
|
105
|
-
if (!shiftDown)
|
106
|
-
SEL_START = CARET_POS;
|
107
|
-
|
108
|
-
return true;
|
109
|
-
}
|
110
|
-
|
111
|
-
// Home
|
112
|
-
if (message == WM_KEYDOWN && wparam == VK_HOME)
|
113
|
-
{
|
114
|
-
CARET_POS = 0;
|
115
|
-
|
116
|
-
if (!shiftDown)
|
117
|
-
SEL_START = CARET_POS;
|
118
|
-
|
119
|
-
return true;
|
120
|
-
}
|
121
|
-
|
122
|
-
// End
|
123
|
-
if (message == WM_KEYDOWN && wparam == VK_END)
|
124
|
-
{
|
125
|
-
CARET_POS = pimpl->text.length();
|
126
|
-
|
127
|
-
if (!shiftDown)
|
128
|
-
SEL_START = CARET_POS;
|
129
|
-
|
130
|
-
return true;
|
131
|
-
}
|
132
|
-
|
133
|
-
// Word left
|
134
|
-
if (message == WM_KEYDOWN && wparam == VK_LEFT && ctrlDown)
|
135
|
-
{
|
136
|
-
if (CARET_POS == pimpl->text.length())
|
137
|
-
--CARET_POS;
|
138
|
-
|
139
|
-
while (CARET_POS > 0 && iswspace(pimpl->text.at(CARET_POS - 1)))
|
140
|
-
--CARET_POS;
|
141
|
-
|
142
|
-
while (CARET_POS > 0 && !iswspace(pimpl->text.at(CARET_POS - 1)))
|
143
|
-
--CARET_POS;
|
144
|
-
|
145
|
-
if (!shiftDown)
|
146
|
-
SEL_START = CARET_POS;
|
147
|
-
|
148
|
-
return true;
|
149
|
-
}
|
150
|
-
|
151
|
-
// Word right
|
152
|
-
if (message == WM_KEYDOWN && wparam == VK_RIGHT && ctrlDown)
|
153
|
-
{
|
154
|
-
while (CARET_POS < pimpl->text.length() && iswspace(pimpl->text.at(CARET_POS)))
|
155
|
-
++CARET_POS;
|
156
|
-
|
157
|
-
while (CARET_POS < pimpl->text.length() && !iswspace(pimpl->text.at(CARET_POS)))
|
158
|
-
++CARET_POS;
|
159
|
-
|
160
|
-
if (!shiftDown)
|
161
|
-
SEL_START = CARET_POS;
|
162
|
-
|
163
|
-
return true;
|
164
|
-
}
|
165
|
-
|
166
|
-
// Delete existant selection
|
167
|
-
if (message == WM_KEYDOWN && wparam == VK_BACK)
|
168
|
-
{
|
169
|
-
if (SEL_START != CARET_POS)
|
170
|
-
{
|
171
|
-
unsigned min = std::min(CARET_POS, SEL_START);
|
172
|
-
unsigned max = std::max(CARET_POS, SEL_START);
|
173
|
-
pimpl->text.erase(pimpl->text.begin() + min, pimpl->text.begin() + max);
|
174
|
-
SEL_START = CARET_POS = min;
|
175
|
-
}
|
176
|
-
else
|
177
|
-
{
|
178
|
-
unsigned oldCaret = CARET_POS;
|
179
|
-
// Move left - either char or word
|
180
|
-
feedMessage(WM_KEYDOWN, VK_LEFT, lparam);
|
181
|
-
pimpl->text.erase(pimpl->text.begin() + CARET_POS, pimpl->text.begin() + oldCaret);
|
182
|
-
SEL_START = CARET_POS;
|
183
|
-
}
|
184
|
-
|
185
|
-
return true;
|
186
|
-
}
|
187
|
-
|
188
|
-
// Delete existant selection
|
189
|
-
if (message == WM_KEYDOWN && wparam == VK_DELETE)
|
190
|
-
{
|
191
|
-
if (SEL_START != CARET_POS)
|
192
|
-
{
|
193
|
-
unsigned min = std::min(CARET_POS, SEL_START);
|
194
|
-
unsigned max = std::max(CARET_POS, SEL_START);
|
195
|
-
pimpl->text.erase(pimpl->text.begin() + min, pimpl->text.begin() + max);
|
196
|
-
SEL_START = CARET_POS = min;
|
197
|
-
}
|
198
|
-
else
|
199
|
-
{
|
200
|
-
unsigned oldCaret = CARET_POS;
|
201
|
-
// Move right - either char or word
|
202
|
-
feedMessage(WM_KEYDOWN, VK_RIGHT, lparam);
|
203
|
-
pimpl->text.erase(pimpl->text.begin() + oldCaret, pimpl->text.begin() + CARET_POS);
|
204
|
-
SEL_START = CARET_POS = oldCaret;
|
205
|
-
}
|
206
|
-
|
207
|
-
return true;
|
208
|
-
}
|
209
|
-
|
210
|
-
return false;
|
211
|
-
}
|
data/GosuImpl/TextInputX.cpp
DELETED
@@ -1,217 +0,0 @@
|
|
1
|
-
#include <Gosu/TextInput.hpp>
|
2
|
-
#include <Gosu/Input.hpp>
|
3
|
-
#include <algorithm>
|
4
|
-
#include <vector>
|
5
|
-
#include <wctype.h>
|
6
|
-
|
7
|
-
struct Gosu::TextInput::Impl
|
8
|
-
{
|
9
|
-
std::wstring text;
|
10
|
-
unsigned caretPos, selectionStart;
|
11
|
-
Impl() : caretPos(0), selectionStart(0) {}
|
12
|
-
};
|
13
|
-
|
14
|
-
Gosu::TextInput::TextInput()
|
15
|
-
: pimpl(new Impl)
|
16
|
-
{
|
17
|
-
}
|
18
|
-
|
19
|
-
Gosu::TextInput::~TextInput()
|
20
|
-
{
|
21
|
-
}
|
22
|
-
|
23
|
-
std::wstring Gosu::TextInput::text() const
|
24
|
-
{
|
25
|
-
return pimpl->text;
|
26
|
-
}
|
27
|
-
|
28
|
-
void Gosu::TextInput::setText(const std::wstring& text)
|
29
|
-
{
|
30
|
-
pimpl->text = text;
|
31
|
-
pimpl->caretPos = pimpl->selectionStart = text.length();
|
32
|
-
}
|
33
|
-
|
34
|
-
unsigned Gosu::TextInput::caretPos() const
|
35
|
-
{
|
36
|
-
return pimpl->caretPos;
|
37
|
-
}
|
38
|
-
|
39
|
-
void Gosu::TextInput::setCaretPos(unsigned pos)
|
40
|
-
{
|
41
|
-
pimpl->caretPos = pos;
|
42
|
-
}
|
43
|
-
|
44
|
-
unsigned Gosu::TextInput::selectionStart() const
|
45
|
-
{
|
46
|
-
return pimpl->selectionStart;
|
47
|
-
}
|
48
|
-
|
49
|
-
void Gosu::TextInput::setSelectionStart(unsigned pos)
|
50
|
-
{
|
51
|
-
pimpl->selectionStart = pos;
|
52
|
-
}
|
53
|
-
|
54
|
-
#define CARET_POS (pimpl->caretPos)
|
55
|
-
#define SEL_START (pimpl->selectionStart)
|
56
|
-
|
57
|
-
bool Gosu::TextInput::feedXEvent(void* display, void* event)
|
58
|
-
{
|
59
|
-
XEvent* ev = static_cast<XEvent*>(event);
|
60
|
-
|
61
|
-
if (ev->type != KeyPress)
|
62
|
-
return false;
|
63
|
-
|
64
|
-
bool ctrlDown = (ev->xkey.state & ControlMask);
|
65
|
-
bool shiftDown = (ev->xkey.state & ShiftMask);
|
66
|
-
|
67
|
-
KeySym lower, upper;
|
68
|
-
int keysyms_per_keycode_return;
|
69
|
-
KeySym keysym = *XGetKeyboardMapping((Display*)display, ev->xkey.keycode, 1, &keysyms_per_keycode_return);
|
70
|
-
XConvertCase(keysym, &lower, &upper);
|
71
|
-
|
72
|
-
wchar_t ch = static_cast<wchar_t>(shiftDown ? upper : lower);
|
73
|
-
|
74
|
-
if (ch >= 32 && ch != 127 && ch <= 255)
|
75
|
-
{
|
76
|
-
// Delete (overwrite) previous selection.
|
77
|
-
if (CARET_POS != SEL_START)
|
78
|
-
{
|
79
|
-
unsigned min = std::min(CARET_POS, SEL_START);
|
80
|
-
unsigned max = std::max(CARET_POS, SEL_START);
|
81
|
-
pimpl->text.erase(pimpl->text.begin() + min, pimpl->text.begin() + max);
|
82
|
-
CARET_POS = SEL_START = min;
|
83
|
-
}
|
84
|
-
|
85
|
-
wchar_t text[] = { ch, 0 };
|
86
|
-
std::wstring filteredText = filter(text);
|
87
|
-
pimpl->text.insert(pimpl->text.begin() + CARET_POS, filteredText.begin(), filteredText.end());
|
88
|
-
CARET_POS += filteredText.length();
|
89
|
-
SEL_START = CARET_POS;
|
90
|
-
return true;
|
91
|
-
}
|
92
|
-
|
93
|
-
Button btn(ev->xkey.keycode-8);
|
94
|
-
|
95
|
-
// Char left
|
96
|
-
if (btn == kbLeft && !ctrlDown)
|
97
|
-
{
|
98
|
-
if (CARET_POS > 0)
|
99
|
-
CARET_POS -= 1;
|
100
|
-
|
101
|
-
if (!shiftDown)
|
102
|
-
SEL_START = CARET_POS;
|
103
|
-
|
104
|
-
return true;
|
105
|
-
}
|
106
|
-
|
107
|
-
// Char right
|
108
|
-
if (btn == kbRight && !ctrlDown)
|
109
|
-
{
|
110
|
-
if (CARET_POS < pimpl->text.length())
|
111
|
-
CARET_POS += 1;
|
112
|
-
|
113
|
-
if (!shiftDown)
|
114
|
-
SEL_START = CARET_POS;
|
115
|
-
|
116
|
-
return true;
|
117
|
-
}
|
118
|
-
|
119
|
-
// Home
|
120
|
-
if (btn == kbHome)
|
121
|
-
{
|
122
|
-
CARET_POS = 0;
|
123
|
-
|
124
|
-
if (!shiftDown)
|
125
|
-
SEL_START = CARET_POS;
|
126
|
-
|
127
|
-
return true;
|
128
|
-
}
|
129
|
-
|
130
|
-
// End
|
131
|
-
if (btn == kbEnd)
|
132
|
-
{
|
133
|
-
CARET_POS = pimpl->text.length();
|
134
|
-
|
135
|
-
if (!shiftDown)
|
136
|
-
SEL_START = CARET_POS;
|
137
|
-
|
138
|
-
return true;
|
139
|
-
}
|
140
|
-
|
141
|
-
// Word left
|
142
|
-
if (btn == kbLeft && ctrlDown)
|
143
|
-
{
|
144
|
-
if (CARET_POS == pimpl->text.length())
|
145
|
-
--CARET_POS;
|
146
|
-
|
147
|
-
while (CARET_POS > 0 && iswspace(pimpl->text.at(CARET_POS - 1)))
|
148
|
-
--CARET_POS;
|
149
|
-
|
150
|
-
while (CARET_POS > 0 && !iswspace(pimpl->text.at(CARET_POS - 1)))
|
151
|
-
--CARET_POS;
|
152
|
-
|
153
|
-
if (!shiftDown)
|
154
|
-
SEL_START = CARET_POS;
|
155
|
-
|
156
|
-
return true;
|
157
|
-
}
|
158
|
-
|
159
|
-
// Word right
|
160
|
-
if (btn == kbRight && ctrlDown)
|
161
|
-
{
|
162
|
-
while (CARET_POS < pimpl->text.length() && iswspace(pimpl->text.at(CARET_POS)))
|
163
|
-
++CARET_POS;
|
164
|
-
|
165
|
-
while (CARET_POS < pimpl->text.length() && !iswspace(pimpl->text.at(CARET_POS)))
|
166
|
-
++CARET_POS;
|
167
|
-
|
168
|
-
if (!shiftDown)
|
169
|
-
SEL_START = CARET_POS;
|
170
|
-
|
171
|
-
return true;
|
172
|
-
}
|
173
|
-
|
174
|
-
// Delete existant selection
|
175
|
-
if (btn == kbBackspace)
|
176
|
-
{
|
177
|
-
if (SEL_START != CARET_POS)
|
178
|
-
{
|
179
|
-
unsigned min = std::min(CARET_POS, SEL_START);
|
180
|
-
unsigned max = std::max(CARET_POS, SEL_START);
|
181
|
-
pimpl->text.erase(pimpl->text.begin() + min, pimpl->text.begin() + max);
|
182
|
-
SEL_START = CARET_POS = min;
|
183
|
-
}
|
184
|
-
else if (CARET_POS > 0)
|
185
|
-
{
|
186
|
-
unsigned oldCaret = CARET_POS;
|
187
|
-
CARET_POS -= 1;
|
188
|
-
pimpl->text.erase(pimpl->text.begin() + CARET_POS, pimpl->text.begin() + oldCaret);
|
189
|
-
SEL_START = CARET_POS;
|
190
|
-
}
|
191
|
-
|
192
|
-
return true;
|
193
|
-
}
|
194
|
-
|
195
|
-
// Delete existant selection
|
196
|
-
if (btn == kbDelete)
|
197
|
-
{
|
198
|
-
if (SEL_START != CARET_POS)
|
199
|
-
{
|
200
|
-
unsigned min = std::min(CARET_POS, SEL_START);
|
201
|
-
unsigned max = std::max(CARET_POS, SEL_START);
|
202
|
-
pimpl->text.erase(pimpl->text.begin() + min, pimpl->text.begin() + max);
|
203
|
-
SEL_START = CARET_POS = min;
|
204
|
-
}
|
205
|
-
else if (CARET_POS < pimpl->text.length())
|
206
|
-
{
|
207
|
-
unsigned oldCaret = CARET_POS;
|
208
|
-
CARET_POS += 1;
|
209
|
-
pimpl->text.erase(pimpl->text.begin() + oldCaret, pimpl->text.begin() + CARET_POS);
|
210
|
-
SEL_START = CARET_POS = oldCaret;
|
211
|
-
}
|
212
|
-
|
213
|
-
return true;
|
214
|
-
}
|
215
|
-
|
216
|
-
return false;
|
217
|
-
}
|