gosu 1.0.0 → 1.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,168 +0,0 @@
1
- #include <Gosu/Gosu.hpp>
2
- #include <stdio.h>
3
- #include <cstring>
4
-
5
- extern "C" {
6
- #include <Gosu/Image.h>
7
-
8
- // Constructors
9
- Gosu_Image *Gosu_Image_create(const char *filename, unsigned image_flags)
10
- {
11
- return reinterpret_cast<Gosu_Image *>(new Gosu::Image(filename, image_flags));
12
- };
13
-
14
- Gosu_Image *Gosu_Image_create_from_markup(const char *markup, const char *font, double font_height,
15
- int width, double spacing, unsigned align, unsigned font_flags, unsigned image_flags)
16
- {
17
- Gosu::Bitmap bitmap = Gosu::layout_markup(markup, font, font_height, spacing, width,
18
- (Gosu::Alignment)align, font_flags);
19
- return reinterpret_cast<Gosu_Image *>(new Gosu::Image(bitmap, image_flags));
20
- }
21
-
22
- Gosu_Image *Gosu_Image_create_from_text(const char *text, const char *font, double font_height,
23
- int width, double spacing, unsigned align, unsigned font_flags, unsigned image_flags)
24
- {
25
- Gosu::Bitmap bitmap = Gosu::layout_text(text, font, font_height, spacing, width,
26
- (Gosu::Alignment)align, font_flags);
27
- return reinterpret_cast<Gosu_Image *>(new Gosu::Image(bitmap, image_flags));
28
- }
29
-
30
- Gosu_Image *Gosu_Image_create_from_blob(unsigned char *blob, int byte_count, int columns, int rows, unsigned image_flags)
31
- {
32
- std::size_t size = columns * rows * 4;
33
- Gosu::Bitmap bitmap(columns, rows, Gosu::Color::NONE);
34
-
35
- if (byte_count == size) {
36
- // 32 bit per pixel, assume R8G8B8A8
37
- std::memcpy(bitmap.data(), blob, size);
38
- }
39
- else if (byte_count == size * sizeof(float)) {
40
- // 128 bit per channel, assume float/float/float/float
41
- const float *in = reinterpret_cast<const float *>(blob);
42
- Gosu::Color::Channel *out = reinterpret_cast<Gosu::Color::Channel *>(bitmap.data());
43
- for (int i = size; i > 0; --i) {
44
- *(out++) = static_cast<Gosu::Color::Channel>(*(in++) * 255);
45
- }
46
- }
47
- else {
48
- return nullptr; // abort?
49
- }
50
-
51
- return reinterpret_cast<Gosu_Image *>(new Gosu::Image(bitmap, image_flags));
52
- }
53
-
54
- Gosu_Image *Gosu_Image_create_from_subimage(Gosu_Image *image, int left, int top, int width, int height)
55
- {
56
- Gosu::Image *gosu_image = reinterpret_cast<Gosu::Image *>(image);
57
- std::unique_ptr<Gosu::ImageData> image_data = gosu_image->data().subimage(left, top, width, height);
58
-
59
- return reinterpret_cast<Gosu_Image *>(image_data.get() ? new Gosu::Image(std::move(image_data)) : nullptr);
60
- }
61
-
62
- void Gosu_Image_create_from_tiles(const char *source, int tile_width, int tile_height, void function(void *data, Gosu_Image *image), void *data, unsigned image_flags)
63
- {
64
- std::vector<Gosu::Image> gosu_images = Gosu::load_tiles(source, tile_width, tile_height, image_flags);
65
-
66
- for (Gosu::Image &img : gosu_images) {
67
- function(data, reinterpret_cast<Gosu_Image *>(new Gosu::Image(img)));
68
- }
69
- }
70
-
71
- void Gosu_Image_create_tiles_from_image(Gosu_Image *image, int tile_width, int tile_height, void function(void *data, Gosu_Image *image), void *data, unsigned image_flags)
72
- {
73
- std::vector<Gosu::Image> gosu_images = Gosu::load_tiles(reinterpret_cast<Gosu::Image *>(image)->data().to_bitmap(), tile_width, tile_height, image_flags);
74
-
75
- for (Gosu::Image &img : gosu_images) {
76
- function(data, reinterpret_cast<Gosu_Image *>(new Gosu::Image(img)));
77
- }
78
- }
79
-
80
- // Properties
81
- unsigned Gosu_Image_width(Gosu_Image *image)
82
- {
83
- return reinterpret_cast<Gosu::Image *>(image)->width();
84
- }
85
-
86
- unsigned Gosu_Image_height(Gosu_Image *image)
87
- {
88
- return reinterpret_cast<Gosu::Image *>(image)->height();
89
- }
90
-
91
- Gosu_GLTexInfo *Gosu_Image_gl_tex_info_create(Gosu_Image *image)
92
- {
93
- Gosu::Image *gosu_image = reinterpret_cast<Gosu::Image *>(image);
94
- Gosu::GLTexInfo *gosu_texture_info = new Gosu::GLTexInfo(*gosu_image->data().gl_tex_info());
95
- if (gosu_texture_info) {
96
- return reinterpret_cast<Gosu_GLTexInfo *>(gosu_texture_info);
97
- }
98
- else {
99
- return nullptr;
100
- }
101
- }
102
-
103
- void Gosu_Image_gl_tex_info_destroy(Gosu_GLTexInfo *gl_tex_info)
104
- {
105
- delete (reinterpret_cast<Gosu::GLTexInfo *>(gl_tex_info));
106
- }
107
-
108
- // Rendering
109
- void Gosu_Image_draw(Gosu_Image *image, double x, double y, double z, double scale_x, double scale_y, unsigned color, unsigned mode)
110
- {
111
- reinterpret_cast<Gosu::Image *>(image)->draw(x, y, z, scale_x, scale_y, color, (Gosu::AlphaMode)mode);
112
- }
113
-
114
- void Gosu_Image_draw_rot(Gosu_Image *image, double x, double y, double z,
115
- double angle, double center_x, double center_y,
116
- double scale_x, double scale_y, unsigned color, unsigned mode)
117
- {
118
- reinterpret_cast<Gosu::Image *>(image)->draw_rot(x, y, z,
119
- angle, center_x, center_y,
120
- scale_x, scale_y,
121
- color, (Gosu::AlphaMode)mode);
122
- }
123
-
124
- void Gosu_Image_draw_as_quad(Gosu_Image *image,
125
- double x1, double y1, unsigned color1,
126
- double x2, double y2, unsigned color2,
127
- double x3, double y3, unsigned color3,
128
- double x4, double y4, unsigned color4,
129
- double z, unsigned mode)
130
- {
131
- Gosu::Image *gosu_image = reinterpret_cast<Gosu::Image *>(image);
132
- gosu_image->data().draw(
133
- x1, y1, color1,
134
- x2, y2, color2,
135
- x3, y3, color3,
136
- x4, y4, color4,
137
- z, (Gosu::AlphaMode)mode);
138
- }
139
-
140
- // Image operations
141
- void Gosu_Image_insert(Gosu_Image *image, Gosu_Image *source, int x, int y)
142
- {
143
- Gosu::Bitmap bmp;
144
- bmp = reinterpret_cast<Gosu::Image *>(source)->data().to_bitmap();
145
- reinterpret_cast<Gosu::Image *>(image)->data().insert(bmp, x, y);
146
- }
147
-
148
- unsigned char *Gosu_Image_to_blob(Gosu_Image *image)
149
- {
150
- Gosu::Image *gosu_image = reinterpret_cast<Gosu::Image *>(image);
151
- static thread_local Gosu::Bitmap bitmap;
152
- bitmap = gosu_image->data().to_bitmap();
153
-
154
- return reinterpret_cast<unsigned char *>(bitmap.data());
155
- }
156
-
157
- void Gosu_Image_save(Gosu_Image *image, const char *filename)
158
- {
159
- Gosu::save_image_file(reinterpret_cast<Gosu::Image *>(image)->data().to_bitmap(), filename);
160
- }
161
-
162
- // Destructor
163
- void Gosu_Image_destroy(Gosu_Image *image)
164
- {
165
- delete (reinterpret_cast<Gosu::Image *>(image));
166
- }
167
-
168
- }
@@ -1,90 +0,0 @@
1
- #pragma once
2
-
3
- #include "AudioFile.hpp"
4
- #include <Gosu/IO.hpp>
5
- #include <algorithm>
6
- #include <stdexcept>
7
- #include <string>
8
-
9
- #include <mpg123.h>
10
-
11
- namespace Gosu
12
- {
13
- class MPEGFile : public AudioFile
14
- {
15
- Gosu::Buffer contents_;
16
- off_t position_ = 0;
17
- mpg123_handle* handle_;
18
-
19
- enum {
20
- SAMPLE_RATE = 44100,
21
- INPUT_SIZE = 16384
22
- };
23
-
24
- public:
25
- MPEGFile(Gosu::Reader reader)
26
- {
27
- contents_.resize(reader.resource().size() - reader.position());
28
- reader.read(contents_.data(), contents_.size());
29
-
30
- static int init_error = mpg123_init();
31
- if (init_error != MPG123_OK) {
32
- throw std::runtime_error("Cannot initialize mpg123: " +
33
- std::string(mpg123_plain_strerror(init_error)));
34
- }
35
-
36
- int new_error;
37
- handle_ = mpg123_new(nullptr, &new_error);
38
- if (handle_ == nullptr) {
39
- throw std::runtime_error("Cannot initialize mpg123 decoder: " +
40
- std::string(mpg123_plain_strerror(new_error)));
41
- }
42
-
43
- mpg123_param(handle_, MPG123_FORCE_RATE, SAMPLE_RATE, 0);
44
- mpg123_param(handle_, MPG123_FLAGS, MPG123_FORCE_STEREO, 0);
45
-
46
- mpg123_open_feed(handle_);
47
- }
48
-
49
- ~MPEGFile() override
50
- {
51
- mpg123_delete(handle_);
52
- }
53
-
54
- ALenum format() const override
55
- {
56
- return AL_FORMAT_STEREO16;
57
- }
58
-
59
- ALuint sample_rate() const override
60
- {
61
- return SAMPLE_RATE;
62
- }
63
-
64
- std::size_t read_data(void* dest, std::size_t length) override
65
- {
66
- std::size_t written = 0;
67
- int error = 0;
68
-
69
- error = mpg123_read(handle_, static_cast<unsigned char*>(dest), length, &written);
70
- while (written == 0
71
- && (error == MPG123_NEED_MORE || error == MPG123_NEW_FORMAT)
72
- && position_ != contents_.size()) {
73
- auto bytes = std::min<std::size_t>(contents_.size() - position_, INPUT_SIZE);
74
- // (Not sure what to do about the return value of mpg123_feed here.)
75
- mpg123_feed(handle_, static_cast<unsigned char*>(contents_.data()) + position_,
76
- bytes);
77
- position_ += bytes;
78
- error = mpg123_read(handle_, static_cast<unsigned char*>(dest), length, &written);
79
- }
80
-
81
- return written;
82
- }
83
-
84
- void rewind() override
85
- {
86
- mpg123_feedseek(handle_, 0, SEEK_SET, &position_);
87
- assert (position_ >= 0 && position_ <= contents_.size());
88
- }
89
- };
90
- }
@@ -1,30 +0,0 @@
1
- #include <Gosu/Audio.hpp>
2
- #include <Gosu/Sample.h>
3
-
4
- extern "C" {
5
-
6
- Gosu_Sample *Gosu_Sample_create(const char *filename)
7
- {
8
- return reinterpret_cast<Gosu_Sample *>( new Gosu::Sample(filename) );
9
- }
10
-
11
- void Gosu_Sample_destroy(Gosu_Sample *sample)
12
- {
13
- delete( reinterpret_cast<Gosu::Sample *>( sample ) );
14
- }
15
-
16
- Gosu_Channel *Gosu_Sample_play(Gosu_Sample *sample, double volume, double speed, bool looping)
17
- {
18
- Gosu::Channel channel = reinterpret_cast<Gosu::Sample *>( sample )->play(volume, speed, looping);
19
-
20
- return reinterpret_cast<Gosu_Channel *>( new Gosu::Channel(channel) );
21
- }
22
-
23
- Gosu_Channel *Gosu_Sample_play_pan(Gosu_Sample *sample, double pan, double volume, double speed, bool looping)
24
- {
25
- Gosu::Channel channel = reinterpret_cast<Gosu::Sample *>( sample )->play_pan(pan, volume, speed, looping);
26
-
27
- return reinterpret_cast<Gosu_Channel *>( new Gosu::Channel(channel) );
28
- }
29
-
30
- }
@@ -1,52 +0,0 @@
1
- #include <Gosu/Audio.hpp>
2
- #include <Gosu/Song.h>
3
-
4
- extern "C" {
5
- Gosu_Song* Gosu_Song_create(const char* filename)
6
- {
7
- return reinterpret_cast<Gosu_Song*>( new Gosu::Song(filename) );
8
- }
9
-
10
- void Gosu_Song_destroy(Gosu_Song* song)
11
- {
12
- delete( reinterpret_cast<Gosu::Song*>( song ));
13
- }
14
-
15
- void Gosu_Song_play(Gosu_Song* song, bool looping)
16
- {
17
- reinterpret_cast<Gosu::Song*>( song )->play(looping);
18
- }
19
-
20
- bool Gosu_Song_playing(Gosu_Song* song)
21
- {
22
- return reinterpret_cast<Gosu::Song*>( song )->playing();
23
- }
24
-
25
- void Gosu_Song_pause(Gosu_Song* song)
26
- {
27
- reinterpret_cast<Gosu::Song*>( song )->pause();
28
- }
29
-
30
- bool Gosu_Song_paused(Gosu_Song* song)
31
- {
32
- return reinterpret_cast<Gosu::Song*>( song )->paused();
33
- }
34
-
35
- void Gosu_Song_stop(Gosu_Song* song)
36
- {
37
- reinterpret_cast<Gosu::Song*>( song )->stop();
38
- }
39
-
40
- double Gosu_Song_volume(Gosu_Song* song){
41
- return reinterpret_cast<Gosu::Song*>( song )->volume();
42
- }
43
-
44
- void Gosu_Song_set_volume(Gosu_Song* song, double volume){
45
- return reinterpret_cast<Gosu::Song*>( song )->set_volume(volume);
46
- }
47
-
48
- Gosu_Song* Gosu_Song_current_song()
49
- {
50
- return reinterpret_cast<Gosu_Song*>(Gosu::Song::current_song());
51
- }
52
- }
@@ -1,101 +0,0 @@
1
- #include <Gosu/Gosu.hpp>
2
-
3
- namespace Gosu
4
- {
5
- class TextInputForWrapper : public Gosu::TextInput
6
- {
7
- public:
8
- TextInputForWrapper();
9
- std::string filter(std::string text) const override;
10
- std::function<void (const char *text)> filter_callback;
11
- std::string filter_result = "";
12
- };
13
- } // namespace Gosu
14
-
15
- Gosu::TextInputForWrapper::TextInputForWrapper() : Gosu::TextInput()
16
- {
17
- }
18
-
19
- std::string Gosu::TextInputForWrapper::filter(std::string text) const
20
- {
21
- if (filter_callback != nullptr) {
22
- filter_callback(text.c_str());
23
- return filter_result;
24
- }
25
- else {
26
- return text;
27
- }
28
- }
29
-
30
- extern "C" {
31
- #include <Gosu/TextInput.h>
32
-
33
- Gosu_TextInput *Gosu_TextInput_create()
34
- {
35
- return reinterpret_cast<Gosu_TextInput *>(new Gosu::TextInputForWrapper());
36
- }
37
-
38
- const char *Gosu_TextInput_text(Gosu_TextInput *text_input)
39
- {
40
- thread_local std::string string;
41
- string = reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->text();
42
-
43
- return string.c_str();
44
- }
45
-
46
- void Gosu_TextInput_set_text(Gosu_TextInput *text_input, const char *text)
47
- {
48
- reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->set_text(text);
49
- }
50
-
51
- unsigned Gosu_TextInput_caret_pos(Gosu_TextInput *text_input)
52
- {
53
- return reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->caret_pos();
54
- }
55
-
56
- void Gosu_TextInput_set_caret_pos(Gosu_TextInput *text_input, unsigned pos)
57
- {
58
- return reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->set_caret_pos(pos);
59
- }
60
-
61
- unsigned Gosu_TextInput_selection_start(Gosu_TextInput *text_input)
62
- {
63
- return reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->selection_start();
64
- }
65
-
66
- void Gosu_TextInput_set_selection_start(Gosu_TextInput *text_input, unsigned pos)
67
- {
68
- return reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->set_selection_start(pos);
69
- }
70
-
71
- void Gosu_TextInput_set_filter(Gosu_TextInput *text_input, void function(void *data, const char *text), void *data)
72
- {
73
- reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->filter_callback = [=](const char *text) { function(data, text); };
74
- }
75
-
76
- void Gosu_TextInput_set_filter_result(Gosu_TextInput *text_input, const char *result)
77
- {
78
- reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->filter_result = result;
79
- }
80
-
81
- void Gosu_TextInput_insert_text(Gosu_TextInput *text_input, const char *text)
82
- {
83
- reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->insert_text(text);
84
- }
85
-
86
- void Gosu_TextInput_delete_backward(Gosu_TextInput *text_input)
87
- {
88
- reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->delete_backward();
89
- }
90
-
91
- void Gosu_TextInput_delete_forward(Gosu_TextInput *text_input)
92
- {
93
- reinterpret_cast<Gosu::TextInputForWrapper *>(text_input)->delete_forward();
94
- }
95
-
96
- void Gosu_TextInput_destroy(Gosu_TextInput *text_input)
97
- {
98
- delete (reinterpret_cast<Gosu::TextInputForWrapper *>(text_input));
99
- }
100
-
101
- }
@@ -1,317 +0,0 @@
1
- #include <Gosu/Gosu.hpp>
2
-
3
- namespace Gosu
4
- {
5
- class WindowForWrapper : public Gosu::Window
6
- {
7
- public:
8
- WindowForWrapper(int width, int height, bool fullscreen, double update_interval, bool resizable);
9
- void update() override;
10
- void draw() override;
11
- void default_button_down(unsigned btn); // Enables fullscreen toggle
12
- void button_down(Gosu::Button btn) override;
13
- void button_up(Gosu::Button btn) override;
14
- void gamepad_connected(int id) override;
15
- void gamepad_disconnected(int id) override;
16
- void drop(const std::string &filename) override;
17
- bool needs_redraw() const override;
18
- bool needs_cursor() const override;
19
- void close() override;
20
-
21
- void close_immediately();
22
-
23
- std::function<void ()> update_callback;
24
- std::function<void ()> draw_callback;
25
- std::function<void (unsigned btn)> button_down_callback;
26
- std::function<void (unsigned btn)> button_up_callback;
27
- std::function<void (int id)> gamepad_connected_callback;
28
- std::function<void (int id)> gamepad_disconnected_callback;
29
- std::function<void (const char *filename)> drop_callback;
30
- std::function<bool ()> needs_redraw_callback;
31
- std::function<bool ()> needs_cursor_callback;
32
- std::function<void ()> close_callback;
33
- };
34
- } // namespace Gosu
35
-
36
- Gosu::WindowForWrapper::WindowForWrapper(int width, int height, bool fullscreen,
37
- double update_interval, bool resizable)
38
- : Gosu::Window(width, height, fullscreen, update_interval, resizable)
39
- {
40
- }
41
-
42
- void Gosu::WindowForWrapper::update()
43
- {
44
- if (update_callback != nullptr) {
45
- update_callback();
46
- }
47
- }
48
-
49
- void Gosu::WindowForWrapper::draw()
50
- {
51
- if (draw_callback != nullptr) {
52
- draw_callback();
53
- }
54
- }
55
-
56
- void Gosu::WindowForWrapper::default_button_down(unsigned btn)
57
- {
58
- Gosu::Window::button_down(Gosu::Button(btn));
59
- }
60
-
61
- void Gosu::WindowForWrapper::button_down(Gosu::Button btn)
62
- {
63
- if (button_down_callback != nullptr) {
64
- button_down_callback(btn);
65
- }
66
- }
67
-
68
- void Gosu::WindowForWrapper::button_up(Gosu::Button btn)
69
- {
70
- if (button_up_callback != nullptr) {
71
- button_up_callback(btn);
72
- }
73
- }
74
-
75
- void Gosu::WindowForWrapper::gamepad_connected(int id)
76
- {
77
- if (gamepad_connected_callback != nullptr) {
78
- gamepad_connected_callback(id);
79
- }
80
- }
81
-
82
- void Gosu::WindowForWrapper::gamepad_disconnected(int id)
83
- {
84
- if (gamepad_disconnected_callback != nullptr) {
85
- gamepad_disconnected_callback(id);
86
- }
87
- }
88
-
89
- void Gosu::WindowForWrapper::drop(const std::string &filename)
90
- {
91
- if (drop_callback != nullptr) {
92
- drop_callback(filename.c_str());
93
- }
94
- }
95
-
96
- bool Gosu::WindowForWrapper::needs_redraw() const
97
- {
98
- if (needs_redraw_callback != nullptr) {
99
- return needs_redraw_callback();
100
- }
101
- else {
102
- return true;
103
- }
104
- }
105
-
106
- bool Gosu::WindowForWrapper::needs_cursor() const
107
- {
108
- if (needs_cursor_callback != nullptr) {
109
- return needs_cursor_callback();
110
- }
111
- else {
112
- return false;
113
- }
114
- }
115
-
116
- void Gosu::WindowForWrapper::close()
117
- {
118
- if (close_callback != nullptr) {
119
- close_callback();
120
- }
121
- else {
122
- Gosu::Window::close();
123
- }
124
- }
125
-
126
- void Gosu::WindowForWrapper::close_immediately()
127
- {
128
- Gosu::Window::close();
129
- }
130
-
131
- extern "C" {
132
- #include <Gosu/Window.h>
133
- #include <Gosu/TextInput.h>
134
-
135
- // Constructor
136
- Gosu_Window *Gosu_Window_create(int width, int height, bool fullscreen, double update_interval, bool resizable)
137
- {
138
- return reinterpret_cast<Gosu_Window *>(new Gosu::WindowForWrapper(width, height, fullscreen, update_interval, resizable));
139
- };
140
-
141
- // Callbacks
142
- void Gosu_Window_set_draw(Gosu_Window *window, void function(void *data), void *data)
143
- {
144
- reinterpret_cast<Gosu::WindowForWrapper *>(window)->draw_callback = [=]() { function(data); };
145
- }
146
-
147
- void Gosu_Window_set_update(Gosu_Window *window, void function(void *data), void *data)
148
- {
149
- reinterpret_cast<Gosu::WindowForWrapper *>(window)->update_callback = [=]() { function(data); };
150
- }
151
-
152
- void Gosu_Window_set_button_down(Gosu_Window *window, void function(void *data, unsigned btn), void *data)
153
- {
154
- reinterpret_cast<Gosu::WindowForWrapper *>(window)->button_down_callback = [=](unsigned btn) { function(data, btn); };
155
- }
156
-
157
- void Gosu_Window_default_button_down(Gosu_Window *window, unsigned btn)
158
- {
159
- reinterpret_cast<Gosu::WindowForWrapper *>(window)->default_button_down(btn);
160
- }
161
-
162
- void Gosu_Window_set_button_up(Gosu_Window *window, void function(void *data, unsigned btn), void *data)
163
- {
164
- reinterpret_cast<Gosu::WindowForWrapper *>(window)->button_up_callback = [=](unsigned btn) { function(data, btn); };
165
- }
166
-
167
- void Gosu_Window_set_gamepad_connected(Gosu_Window *window, void function(void *data, int id), void *data)
168
- {
169
- reinterpret_cast<Gosu::WindowForWrapper *>(window)->gamepad_connected_callback = [=](int id) { function(data, id); };
170
- }
171
-
172
- void Gosu_Window_set_gamepad_disconnected(Gosu_Window *window, void function(void *data, int id), void *data)
173
- {
174
- reinterpret_cast<Gosu::WindowForWrapper *>(window)->gamepad_disconnected_callback = [=](int id) { function(data, id); };
175
- }
176
-
177
- void Gosu_Window_set_drop(Gosu_Window *window, void function(void *data, const char *filename), void *data)
178
- {
179
- reinterpret_cast<Gosu::WindowForWrapper *>(window)->drop_callback = [=](const char *filename) { function(data, filename); };
180
- }
181
-
182
- void Gosu_Window_set_needs_redraw(Gosu_Window *window, bool function(void *data), void *data)
183
- {
184
- reinterpret_cast<Gosu::WindowForWrapper *>(window)->needs_redraw_callback = [=]() -> bool { return function(data); };
185
- }
186
-
187
- void Gosu_Window_set_needs_cursor(Gosu_Window *window, bool function(void *data), void *data)
188
- {
189
- reinterpret_cast<Gosu::WindowForWrapper *>(window)->needs_cursor_callback = [=]() -> bool { return function(data); };
190
- }
191
-
192
- void Gosu_Window_set_close(Gosu_Window *window, void function(void *data), void *data)
193
- {
194
- reinterpret_cast<Gosu::WindowForWrapper *>(window)->close_callback = [=]() { function(data); };
195
- }
196
-
197
- Gosu_TextInput *Gosu_Window_text_input(Gosu_Window *window)
198
- {
199
- Gosu::Window *gosu_window = reinterpret_cast<Gosu::WindowForWrapper *>(window);
200
- return reinterpret_cast<Gosu_TextInput *>(gosu_window->input().text_input());
201
- }
202
-
203
- void Gosu_Window_set_text_input(Gosu_Window *window, Gosu_TextInput *text_input)
204
- {
205
- Gosu::Window *gosu_window = reinterpret_cast<Gosu::WindowForWrapper *>(window);
206
- gosu_window->input().set_text_input(reinterpret_cast<Gosu::TextInput *>(text_input));
207
- }
208
-
209
- void Gosu_Window_show(Gosu_Window *window)
210
- {
211
- reinterpret_cast<Gosu::WindowForWrapper *>(window)->show();
212
- }
213
-
214
- bool Gosu_Window_tick(Gosu_Window *window)
215
- {
216
- return reinterpret_cast<Gosu::WindowForWrapper *>(window)->tick();
217
- }
218
-
219
- void Gosu_Window_close_immediately(Gosu_Window *window)
220
- {
221
- reinterpret_cast<Gosu::WindowForWrapper *>(window)->close_immediately();
222
- }
223
-
224
- bool Gosu_Window_is_fullscreen(Gosu_Window *window)
225
- {
226
- return reinterpret_cast<Gosu::WindowForWrapper *>(window)->fullscreen();
227
- }
228
-
229
- bool Gosu_Window_is_resizable(Gosu_Window *window)
230
- {
231
- return reinterpret_cast<Gosu::WindowForWrapper *>(window)->resizable();
232
- }
233
-
234
- const char *Gosu_Window_caption(Gosu_Window *window)
235
- {
236
- static thread_local std::string caption;
237
- caption = reinterpret_cast<Gosu::WindowForWrapper *>(window)->caption();
238
-
239
- return caption.c_str();
240
- }
241
-
242
- void Gosu_Window_set_caption(Gosu_Window *window, const char *caption)
243
- {
244
- reinterpret_cast<Gosu::WindowForWrapper *>(window)->set_caption(caption);
245
- }
246
-
247
- double Gosu_Window_update_interval(Gosu_Window *window)
248
- {
249
- return reinterpret_cast<Gosu::WindowForWrapper *>(window)->update_interval();
250
- }
251
-
252
- void Gosu_Window_set_update_interval(Gosu_Window *window, double update_interval)
253
- {
254
- reinterpret_cast<Gosu::WindowForWrapper *>(window)->set_update_interval(update_interval);
255
- }
256
-
257
- void Gosu_Window_set_mouse_x(Gosu_Window *window, double x)
258
- {
259
- Gosu::Window *gosu_window = reinterpret_cast<Gosu::WindowForWrapper *>(window);
260
- gosu_window->input().set_mouse_position(x, gosu_window->input().mouse_x());
261
- }
262
-
263
- void Gosu_Window_set_mouse_y(Gosu_Window *window, double y)
264
- {
265
- Gosu::Window *gosu_window = reinterpret_cast<Gosu::WindowForWrapper *>(window);
266
- gosu_window->input().set_mouse_position(gosu_window->input().mouse_x(), y);
267
- }
268
-
269
- double Gosu_Window_mouse_x(Gosu_Window *window)
270
- {
271
- return reinterpret_cast<Gosu::WindowForWrapper *>(window)->input().mouse_x();
272
- }
273
-
274
- double Gosu_Window_mouse_y(Gosu_Window *window)
275
- {
276
- return reinterpret_cast<Gosu::WindowForWrapper *>(window)->input().mouse_y();
277
- }
278
-
279
- int Gosu_Window_width(Gosu_Window *window)
280
- {
281
- return reinterpret_cast<Gosu::WindowForWrapper *>(window)->width();
282
- }
283
-
284
- void Gosu_Window_set_width(Gosu_Window *window, int width)
285
- {
286
- Gosu::Window *gosu_window = reinterpret_cast<Gosu::WindowForWrapper *>(window);
287
- gosu_window->resize(width, gosu_window->height(), gosu_window->fullscreen());
288
- }
289
-
290
- int Gosu_Window_height(Gosu_Window *window)
291
- {
292
- return reinterpret_cast<Gosu::WindowForWrapper *>(window)->height();
293
- }
294
-
295
- void Gosu_Window_set_height(Gosu_Window *window, int height)
296
- {
297
- Gosu::Window *gosu_window = reinterpret_cast<Gosu::WindowForWrapper *>(window);
298
- gosu_window->resize(gosu_window->width(), height, gosu_window->fullscreen());
299
- }
300
-
301
- void Gosu_Window_resize(Gosu_Window *window, int width, int height, bool fullscreen)
302
- {
303
- reinterpret_cast<Gosu::WindowForWrapper *>(window)->resize(width, height, fullscreen);
304
- }
305
-
306
- int Gosu_Window_is_button_down(Gosu_Window *window, unsigned btn)
307
- {
308
- return reinterpret_cast<Gosu::WindowForWrapper *>(window)->input().down(Gosu::Button(btn));
309
- }
310
-
311
- // Destructor
312
- void Gosu_Window_destroy(Gosu_Window *window)
313
- {
314
- delete (reinterpret_cast<Gosu::WindowForWrapper *>(window));
315
- }
316
-
317
- }