reflexion 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.doc/ext/reflex/application.cpp +37 -6
- data/.doc/ext/reflex/capture_event.cpp +1 -1
- data/.doc/ext/reflex/chase_constraint.cpp +1 -1
- data/.doc/ext/reflex/clipboard.cpp +1 -1
- data/.doc/ext/reflex/color_event.cpp +76 -0
- data/.doc/ext/reflex/color_picker.cpp +113 -0
- data/.doc/ext/reflex/constraint.cpp +1 -1
- data/.doc/ext/reflex/contact_event.cpp +1 -1
- data/.doc/ext/reflex/control_change_event.cpp +1 -1
- data/.doc/ext/reflex/device.cpp +1 -1
- data/.doc/ext/reflex/device_event.cpp +1 -1
- data/.doc/ext/reflex/draw_event.cpp +1 -1
- data/.doc/ext/reflex/ellipse_shape.cpp +1 -1
- data/.doc/ext/reflex/event.cpp +1 -1
- data/.doc/ext/reflex/file_dialog.cpp +181 -0
- data/.doc/ext/reflex/file_event.cpp +103 -0
- data/.doc/ext/reflex/filter.cpp +1 -1
- data/.doc/ext/reflex/focus_event.cpp +1 -1
- data/.doc/ext/reflex/frame_event.cpp +1 -1
- data/.doc/ext/reflex/gamepad.cpp +48 -0
- data/.doc/ext/reflex/image_view.cpp +1 -1
- data/.doc/ext/reflex/key_event.cpp +1 -274
- data/.doc/ext/reflex/line_shape.cpp +1 -1
- data/.doc/ext/reflex/link_constraint.cpp +1 -1
- data/.doc/ext/reflex/menu.cpp +6 -5
- data/.doc/ext/reflex/midi.cpp +9 -2
- data/.doc/ext/reflex/midi_event.cpp +1 -1
- data/.doc/ext/reflex/motion_event.cpp +1 -1
- data/.doc/ext/reflex/native.cpp +18 -6
- data/.doc/ext/reflex/note_event.cpp +1 -1
- data/.doc/ext/reflex/pin.cpp +1 -1
- data/.doc/ext/reflex/pointer.cpp +1 -1
- data/.doc/ext/reflex/pointer_event.cpp +2 -2
- data/.doc/ext/reflex/polygon_shape.cpp +1 -1
- data/.doc/ext/reflex/rect_shape.cpp +1 -1
- data/.doc/ext/reflex/reflex.cpp +566 -232
- data/.doc/ext/reflex/screen.cpp +27 -1
- data/.doc/ext/reflex/scroll_event.cpp +1 -1
- data/.doc/ext/reflex/selector.cpp +1 -1
- data/.doc/ext/reflex/shape.cpp +1 -1
- data/.doc/ext/reflex/snap_constraint.cpp +1 -1
- data/.doc/ext/reflex/style.cpp +1 -1
- data/.doc/ext/reflex/style_length.cpp +1 -1
- data/.doc/ext/reflex/text_event.cpp +104 -0
- data/.doc/ext/reflex/timer.cpp +1 -1
- data/.doc/ext/reflex/timer_event.cpp +1 -1
- data/.doc/ext/reflex/update_event.cpp +1 -1
- data/.doc/ext/reflex/view.cpp +110 -56
- data/.doc/ext/reflex/wheel_constraint.cpp +1 -1
- data/.doc/ext/reflex/wheel_event.cpp +1 -1
- data/.doc/ext/reflex/window.cpp +226 -17
- data/.github/workflows/release-gem.yml +2 -49
- data/.github/workflows/tag.yml +5 -28
- data/.github/workflows/test.yml +1 -37
- data/ChangeLog.md +54 -0
- data/Gemfile.lock +13 -8
- data/Rakefile +13 -2
- data/Reflex.podspec +2 -2
- data/VERSION +1 -1
- data/ext/reflex/application.cpp +41 -6
- data/ext/reflex/capture_event.cpp +1 -1
- data/ext/reflex/chase_constraint.cpp +1 -1
- data/ext/reflex/clipboard.cpp +1 -1
- data/ext/reflex/color_event.cpp +80 -0
- data/ext/reflex/color_picker.cpp +121 -0
- data/ext/reflex/constraint.cpp +1 -1
- data/ext/reflex/contact_event.cpp +1 -1
- data/ext/reflex/control_change_event.cpp +1 -1
- data/ext/reflex/device.cpp +1 -1
- data/ext/reflex/device_event.cpp +1 -1
- data/ext/reflex/draw_event.cpp +1 -1
- data/ext/reflex/ellipse_shape.cpp +1 -1
- data/ext/reflex/event.cpp +1 -1
- data/ext/reflex/extconf.rb +4 -2
- data/ext/reflex/file_dialog.cpp +194 -0
- data/ext/reflex/file_event.cpp +108 -0
- data/ext/reflex/filter.cpp +1 -1
- data/ext/reflex/focus_event.cpp +1 -1
- data/ext/reflex/frame_event.cpp +1 -1
- data/ext/reflex/gamepad.cpp +50 -0
- data/ext/reflex/image_view.cpp +1 -1
- data/ext/reflex/key_event.cpp +1 -275
- data/ext/reflex/line_shape.cpp +1 -1
- data/ext/reflex/link_constraint.cpp +1 -1
- data/ext/reflex/menu.cpp +8 -7
- data/ext/reflex/midi.cpp +11 -3
- data/ext/reflex/midi_event.cpp +1 -1
- data/ext/reflex/motion_event.cpp +1 -1
- data/ext/reflex/native.cpp +18 -6
- data/ext/reflex/note_event.cpp +1 -1
- data/ext/reflex/pin.cpp +1 -1
- data/ext/reflex/pointer.cpp +1 -1
- data/ext/reflex/pointer_event.cpp +2 -2
- data/ext/reflex/polygon_shape.cpp +1 -1
- data/ext/reflex/rect_shape.cpp +1 -1
- data/ext/reflex/reflex.cpp +568 -232
- data/ext/reflex/screen.cpp +31 -2
- data/ext/reflex/scroll_event.cpp +1 -1
- data/ext/reflex/selector.cpp +1 -1
- data/ext/reflex/selector.h +9 -9
- data/ext/reflex/shape.cpp +1 -1
- data/ext/reflex/snap_constraint.cpp +1 -1
- data/ext/reflex/style.cpp +1 -1
- data/ext/reflex/style_length.cpp +1 -1
- data/ext/reflex/text_event.cpp +111 -0
- data/ext/reflex/timer.cpp +1 -1
- data/ext/reflex/timer_event.cpp +1 -1
- data/ext/reflex/update_event.cpp +1 -1
- data/ext/reflex/view.cpp +121 -61
- data/ext/reflex/wheel_constraint.cpp +1 -1
- data/ext/reflex/wheel_event.cpp +1 -1
- data/ext/reflex/window.cpp +256 -25
- data/include/reflex/application.h +10 -0
- data/include/reflex/color_picker.h +65 -0
- data/include/reflex/event.h +178 -88
- data/include/reflex/file_dialog.h +73 -0
- data/include/reflex/gamepad.h +3 -0
- data/include/reflex/menu.h +3 -3
- data/include/reflex/midi.h +3 -0
- data/include/reflex/reflex.h +2 -0
- data/include/reflex/ruby/application.h +6 -1
- data/include/reflex/ruby/color_picker.h +89 -0
- data/include/reflex/ruby/event.h +62 -29
- data/include/reflex/ruby/file_dialog.h +89 -0
- data/include/reflex/ruby/gamepad.h +46 -0
- data/include/reflex/ruby/reflex.h +3 -0
- data/include/reflex/ruby/view.h +92 -44
- data/include/reflex/ruby/window.h +60 -1
- data/include/reflex/ruby.h +3 -0
- data/include/reflex/screen.h +11 -2
- data/include/reflex/view.h +28 -16
- data/include/reflex/window.h +40 -8
- data/include/reflex.h +3 -0
- data/lib/reflex/application.rb +5 -5
- data/lib/reflex/autoinit.rb +3 -1
- data/lib/reflex/button.rb +3 -3
- data/lib/reflex/color_event.rb +16 -0
- data/lib/reflex/color_picker.rb +45 -0
- data/lib/reflex/control_change_event.rb +17 -0
- data/lib/reflex/file_dialog.rb +70 -0
- data/lib/reflex/file_event.rb +37 -0
- data/lib/reflex/helper.rb +58 -7
- data/lib/reflex/key_event.rb +9 -4
- data/lib/reflex/menu.rb +17 -1
- data/lib/reflex/model.rb +19 -19
- data/lib/reflex/note_event.rb +1 -1
- data/lib/reflex/pointer.rb +14 -3
- data/lib/reflex/pointer_event.rb +12 -1
- data/lib/reflex/reflex.rb +5 -0
- data/lib/reflex/shape.rb +14 -14
- data/lib/reflex/style.rb +16 -16
- data/lib/reflex/text_event.rb +40 -0
- data/lib/reflex/timer.rb +3 -3
- data/lib/reflex/view.rb +29 -14
- data/lib/reflex/wheel_event.rb +12 -3
- data/lib/reflex/window.rb +25 -13
- data/lib/reflex.rb +8 -2
- data/reflex.gemspec +4 -4
- data/samples/ime.rb +100 -0
- data/samples/ios/hello/hello.xcodeproj/project.pbxproj +236 -224
- data/samples/menu.rb +4 -1
- data/samples/model.rb +3 -3
- data/samples/test/alert.rb +93 -0
- data/samples/test/always_on.rb +76 -0
- data/samples/test/app_background.rb +51 -0
- data/samples/test/boundary.rb +75 -0
- data/samples/test/callback_exception.rb +101 -0
- data/samples/test/cancel.rb +53 -0
- data/samples/test/color_picker.rb +63 -0
- data/samples/test/file_dialog.rb +102 -0
- data/samples/window_style.rb +156 -0
- data/src/application.cpp +159 -18
- data/src/application.h +92 -7
- data/src/color_picker.cpp +113 -0
- data/src/color_picker.h +36 -0
- data/src/event.cpp +410 -252
- data/src/event.h +12 -0
- data/src/file_dialog.cpp +163 -0
- data/src/file_dialog.h +52 -0
- data/src/gamepad.cpp +42 -5
- data/src/gamepad.h +4 -0
- data/src/ios/app_delegate.mm +5 -3
- data/src/ios/application.mm +24 -0
- data/src/ios/color_picker.mm +19 -0
- data/src/ios/file_dialog.mm +21 -0
- data/src/ios/gamepad.mm +4 -4
- data/src/ios/menu.mm +5 -0
- data/src/ios/reflex.mm +8 -0
- data/src/ios/screen.mm +26 -0
- data/src/ios/view_controller.mm +2 -30
- data/src/ios/window.mm +38 -9
- data/src/menu.cpp +66 -4
- data/src/menu.h +17 -1
- data/src/midi.cpp +61 -31
- data/src/osx/app_delegate.h +4 -0
- data/src/osx/app_delegate.mm +102 -22
- data/src/osx/application.mm +88 -6
- data/src/osx/color_picker.mm +112 -0
- data/src/osx/event.h +10 -0
- data/src/osx/event.mm +84 -30
- data/src/osx/file_dialog.mm +168 -0
- data/src/osx/gamepad.mm +2 -2
- data/src/osx/gamepad_hid.mm +1 -1
- data/src/osx/menu.mm +177 -33
- data/src/osx/native_window.h +16 -2
- data/src/osx/native_window.mm +114 -57
- data/src/osx/opengl_view.h +2 -1
- data/src/osx/opengl_view.mm +184 -43
- data/src/osx/reflex.mm +38 -0
- data/src/osx/screen.mm +36 -0
- data/src/osx/window.mm +106 -24
- data/src/pointer.cpp +13 -4
- data/src/pointer.h +4 -0
- data/src/rays.h +46 -0
- data/src/sdl/application.cpp +68 -8
- data/src/sdl/color_picker.cpp +18 -0
- data/src/sdl/event.cpp +24 -3
- data/src/sdl/event.h +12 -0
- data/src/sdl/file_dialog.cpp +20 -0
- data/src/sdl/gamepad.cpp +3 -7
- data/src/sdl/menu.cpp +5 -0
- data/src/sdl/reflex.cpp +20 -0
- data/src/sdl/screen.cpp +36 -0
- data/src/sdl/window.cpp +142 -29
- data/src/shape.cpp +15 -10
- data/src/view.cpp +287 -198
- data/src/view.h +4 -2
- data/src/vk.h +416 -0
- data/src/win32/application.cpp +162 -12
- data/src/win32/application.h +20 -0
- data/src/win32/color_picker.cpp +82 -0
- data/src/win32/event.cpp +114 -12
- data/src/win32/event.h +21 -4
- data/src/win32/file_dialog.cpp +226 -0
- data/src/win32/gamepad.cpp +9 -2
- data/src/win32/menu.cpp +191 -53
- data/src/win32/menu.h +9 -1
- data/src/win32/opengl.cpp +2 -9
- data/src/win32/reflex.cpp +44 -3
- data/src/win32/screen.cpp +164 -3
- data/src/win32/screen.h +8 -0
- data/src/win32/tray.cpp +191 -0
- data/src/win32/tray.h +22 -0
- data/src/win32/vk.cpp +11 -0
- data/src/win32/window.cpp +809 -148
- data/src/win32/window.h +6 -0
- data/src/window.cpp +718 -185
- data/src/window.h +66 -33
- data/src/world.cpp +9 -1
- data/test/helper.rb +17 -0
- data/test/test_application.rb +90 -1
- data/test/test_chase_constraint.rb +1 -3
- data/test/test_color_event.rb +36 -0
- data/test/test_color_picker.rb +62 -0
- data/test/test_constraint.rb +2 -4
- data/test/test_event.rb +1 -1
- data/test/test_file_dialog.rb +48 -0
- data/test/test_file_event.rb +43 -0
- data/test/test_has_text_preedit.rb +54 -0
- data/test/test_key_event.rb +20 -5
- data/test/test_link_constraint.rb +1 -3
- data/test/test_menu.rb +40 -10
- data/test/test_pointer.rb +33 -23
- data/test/test_pointer_event.rb +24 -9
- data/test/test_reflex.rb +36 -0
- data/test/test_screen.rb +24 -2
- data/test/test_snap_constraint.rb +1 -3
- data/test/test_text_event.rb +54 -0
- data/test/test_view.rb +41 -4
- data/test/test_wheel_constraint.rb +1 -3
- data/test/test_wheel_event.rb +13 -5
- data/test/test_window.rb +196 -44
- metadata +80 -10
- data/.github/workflows/utils.rb +0 -127
data/src/osx/application.mm
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
#include "application.h"
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
#import <AppKit/
|
|
5
|
+
#import <AppKit/AppKit.h>
|
|
6
6
|
#include "reflex/exception.h"
|
|
7
7
|
#include "reflex/debug.h"
|
|
8
|
-
#include "menu.h"
|
|
9
8
|
#include "window.h"
|
|
9
|
+
#include "menu.h"
|
|
10
10
|
#import "native_window.h"
|
|
11
11
|
#import "app_delegate.h"
|
|
12
12
|
|
|
@@ -21,6 +21,16 @@ namespace Reflex
|
|
|
21
21
|
return new ApplicationData();
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
String
|
|
25
|
+
Application_get_default_name ()
|
|
26
|
+
{
|
|
27
|
+
NSBundle* bundle = NSBundle.mainBundle;
|
|
28
|
+
NSString* name = [bundle objectForInfoDictionaryKey: @"CFBundleDisplayName"];
|
|
29
|
+
if (!name) name = [bundle objectForInfoDictionaryKey: @"CFBundleName"];
|
|
30
|
+
if (!name) name = NSProcessInfo.processInfo.processName;
|
|
31
|
+
return name ? name.UTF8String : "";
|
|
32
|
+
}
|
|
33
|
+
|
|
24
34
|
ApplicationData&
|
|
25
35
|
Application_get_data (Application* app)
|
|
26
36
|
{
|
|
@@ -36,9 +46,31 @@ namespace Reflex
|
|
|
36
46
|
return Application_get_data(const_cast<Application*>(app));
|
|
37
47
|
}
|
|
38
48
|
|
|
49
|
+
|
|
50
|
+
static void
|
|
51
|
+
update_status_item (Application* app)
|
|
52
|
+
{
|
|
53
|
+
[Application_get_data(app).delegate updateStatusItem];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
void
|
|
57
|
+
Application_stop (Application* app)
|
|
58
|
+
{
|
|
59
|
+
[NSApp stop: nil];
|
|
60
|
+
|
|
61
|
+
// stop: takes effect only after an event is handled, so post one
|
|
62
|
+
NSEvent* e = [NSEvent
|
|
63
|
+
otherEventWithType: NSEventTypeApplicationDefined
|
|
64
|
+
location: NSZeroPoint modifierFlags: 0 timestamp: 0
|
|
65
|
+
windowNumber: 0 context: nil subtype: 0 data1: 0 data2: 0];
|
|
66
|
+
[NSApp postEvent: e atStart: YES];
|
|
67
|
+
}
|
|
68
|
+
|
|
39
69
|
void
|
|
40
70
|
Application_set_menu (Application* app, Menu* menu)
|
|
41
71
|
{
|
|
72
|
+
update_status_item(app);
|
|
73
|
+
|
|
42
74
|
for (auto it = app->window_begin(), end = app->window_end(); it != end; ++it)
|
|
43
75
|
{
|
|
44
76
|
Window* win = it->get();
|
|
@@ -49,6 +81,25 @@ namespace Reflex
|
|
|
49
81
|
Menu_apply_to_main_menu(menu);
|
|
50
82
|
}
|
|
51
83
|
|
|
84
|
+
void
|
|
85
|
+
Application_set_background (Application* app, bool state)
|
|
86
|
+
{
|
|
87
|
+
[NSApp setActivationPolicy: state
|
|
88
|
+
? NSApplicationActivationPolicyAccessory
|
|
89
|
+
: NSApplicationActivationPolicyRegular];
|
|
90
|
+
|
|
91
|
+
if (!state)
|
|
92
|
+
[NSApp activateIgnoringOtherApps: YES];
|
|
93
|
+
|
|
94
|
+
update_status_item(app);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
void
|
|
98
|
+
Application_set_background_menu (Application* app, Menu* menu)
|
|
99
|
+
{
|
|
100
|
+
update_status_item(app);
|
|
101
|
+
}
|
|
102
|
+
|
|
52
103
|
|
|
53
104
|
ApplicationData::ApplicationData ()
|
|
54
105
|
: delegate(nil)
|
|
@@ -79,16 +130,47 @@ namespace Reflex
|
|
|
79
130
|
ReflexAppDelegate* delegate = setup_app_delegate(app);
|
|
80
131
|
[delegate bind: this];
|
|
81
132
|
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
133
|
+
if (app.isRunning)
|
|
134
|
+
{
|
|
135
|
+
// the host app runs the event loop
|
|
85
136
|
[delegate callOnStart];
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (delegate.isLaunched)
|
|
141
|
+
{
|
|
142
|
+
// the app is launched only once, so the later runs start by themselves
|
|
143
|
+
[delegate performSelector: @selector(callOnStart) withObject: nil afterDelay: 0];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
self->started = false;
|
|
147
|
+
self->quitting = false;
|
|
148
|
+
self->running = true;
|
|
149
|
+
[app run];
|
|
150
|
+
self->running = false;
|
|
151
|
+
|
|
152
|
+
Application_cleanup(this);
|
|
153
|
+
[delegate unbind];
|
|
154
|
+
|
|
155
|
+
Application_throw_exception(this);
|
|
86
156
|
}
|
|
87
157
|
|
|
88
158
|
void
|
|
89
159
|
Application::quit ()
|
|
90
160
|
{
|
|
91
|
-
|
|
161
|
+
// terminate exits the process even before run, which would take down
|
|
162
|
+
// irb or a test process
|
|
163
|
+
if (!NSApp.isRunning)
|
|
164
|
+
invalid_state_error(__FILE__, __LINE__, "the application is not running.");
|
|
165
|
+
|
|
166
|
+
Event e;
|
|
167
|
+
Application_call_quit_event(this, &e);
|
|
168
|
+
if (e.is_blocked()) return;
|
|
169
|
+
|
|
170
|
+
if (self->running)
|
|
171
|
+
Application_stop(this);
|
|
172
|
+
else
|
|
173
|
+
[NSApp terminate: nil];
|
|
92
174
|
}
|
|
93
175
|
|
|
94
176
|
void
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// -*- objc -*-
|
|
2
|
+
#include "../color_picker.h"
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
#import <AppKit/AppKit.h>
|
|
6
|
+
#include "reflex/exception.h"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@interface ReflexColorPanelTarget : NSObject
|
|
10
|
+
|
|
11
|
+
- (void) setCurrentPicker: (Reflex::ColorPicker*) picker;
|
|
12
|
+
|
|
13
|
+
@end
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@implementation ReflexColorPanelTarget
|
|
17
|
+
|
|
18
|
+
{
|
|
19
|
+
// not a static, that would be released at exit after the ruby vm is gone
|
|
20
|
+
Reflex::ColorPicker::Ref current;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
- (void) setCurrentPicker: (Reflex::ColorPicker*) picker
|
|
24
|
+
{
|
|
25
|
+
if (current && current != picker)
|
|
26
|
+
[self closeCurrent];
|
|
27
|
+
|
|
28
|
+
current = picker;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
- (void) closeCurrent
|
|
32
|
+
{
|
|
33
|
+
if (!current) return;
|
|
34
|
+
|
|
35
|
+
Reflex::ColorPicker::Ref picker = current;
|
|
36
|
+
current = NULL;
|
|
37
|
+
|
|
38
|
+
Reflex::Event e;
|
|
39
|
+
Reflex::ColorPicker_call_close_event(picker, &e);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
- (void) colorChanged: (NSColorPanel*) panel
|
|
43
|
+
{
|
|
44
|
+
if (!current) return;
|
|
45
|
+
|
|
46
|
+
NSColor* color = [panel.color colorUsingColorSpace: NSColorSpace.sRGBColorSpace];
|
|
47
|
+
if (!color) return;
|
|
48
|
+
|
|
49
|
+
Reflex::ColorEvent e(Reflex::Color(
|
|
50
|
+
color.redComponent,
|
|
51
|
+
color.greenComponent,
|
|
52
|
+
color.blueComponent,
|
|
53
|
+
color.alphaComponent));
|
|
54
|
+
Reflex::ColorPicker_call_color_event(current, &e);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
- (void) panelWillClose: (NSNotification*) notification
|
|
58
|
+
{
|
|
59
|
+
[self closeCurrent];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@end
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
namespace Reflex
|
|
66
|
+
{
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
static ReflexColorPanelTarget*
|
|
70
|
+
get_target (NSColorPanel* panel)
|
|
71
|
+
{
|
|
72
|
+
static ReflexColorPanelTarget* target = nil;
|
|
73
|
+
if (!target)
|
|
74
|
+
{
|
|
75
|
+
target = [[ReflexColorPanelTarget alloc] init];
|
|
76
|
+
[NSNotificationCenter.defaultCenter
|
|
77
|
+
addObserver: target
|
|
78
|
+
selector: @selector(panelWillClose:)
|
|
79
|
+
name: NSWindowWillCloseNotification
|
|
80
|
+
object: panel];
|
|
81
|
+
}
|
|
82
|
+
return target;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
void
|
|
86
|
+
ColorPicker_show (ColorPicker* picker, const Color* initial)
|
|
87
|
+
{
|
|
88
|
+
if (!picker)
|
|
89
|
+
argument_error(__FILE__, __LINE__);
|
|
90
|
+
|
|
91
|
+
NSColorPanel* panel = NSColorPanel.sharedColorPanel;
|
|
92
|
+
ReflexColorPanelTarget* target = get_target(panel);
|
|
93
|
+
[target setCurrentPicker: picker];
|
|
94
|
+
|
|
95
|
+
panel.showsAlpha = picker->alpha();
|
|
96
|
+
panel.continuous = YES;
|
|
97
|
+
panel.target = target;
|
|
98
|
+
panel.action = @selector(colorChanged:);
|
|
99
|
+
if (initial)
|
|
100
|
+
{
|
|
101
|
+
panel.color = [NSColor
|
|
102
|
+
colorWithSRGBRed: initial->red
|
|
103
|
+
green: initial->green
|
|
104
|
+
blue: initial->blue
|
|
105
|
+
alpha: initial->alpha];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
[panel makeKeyAndOrderFront: nil];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
}// Reflex
|
data/src/osx/event.h
CHANGED
|
@@ -32,6 +32,16 @@ namespace Reflex
|
|
|
32
32
|
};// NativeFlagKeyEvent
|
|
33
33
|
|
|
34
34
|
|
|
35
|
+
class NativeTextEvent : public TextEvent
|
|
36
|
+
{
|
|
37
|
+
|
|
38
|
+
public:
|
|
39
|
+
|
|
40
|
+
NativeTextEvent (Action action, NSString* text, NSRange selection);
|
|
41
|
+
|
|
42
|
+
};// NativeTextEvent
|
|
43
|
+
|
|
44
|
+
|
|
35
45
|
class NativePointerEvent : public PointerEvent
|
|
36
46
|
{
|
|
37
47
|
|
data/src/osx/event.mm
CHANGED
|
@@ -18,14 +18,14 @@ namespace Reflex
|
|
|
18
18
|
{
|
|
19
19
|
NSUInteger flags = event ? event.modifierFlags : NSEvent.modifierFlags;
|
|
20
20
|
return
|
|
21
|
-
(flags &
|
|
22
|
-
(flags &
|
|
23
|
-
(flags &
|
|
24
|
-
(flags &
|
|
25
|
-
(flags &
|
|
26
|
-
(flags &
|
|
27
|
-
(flags &
|
|
28
|
-
(flags &
|
|
21
|
+
(flags & NSEventModifierFlagCapsLock ? MOD_CAPS : 0) |
|
|
22
|
+
(flags & NSEventModifierFlagShift ? MOD_SHIFT : 0) |
|
|
23
|
+
(flags & NSEventModifierFlagControl ? MOD_CONTROL : 0) |
|
|
24
|
+
(flags & NSEventModifierFlagOption ? MOD_OPTION : 0) |
|
|
25
|
+
(flags & NSEventModifierFlagCommand ? MOD_COMMAND : 0) |
|
|
26
|
+
(flags & NSEventModifierFlagNumericPad ? MOD_NUMPAD : 0) |
|
|
27
|
+
(flags & NSEventModifierFlagHelp ? MOD_HELP : 0) |
|
|
28
|
+
(flags & NSEventModifierFlagFunction ? MOD_FUNCTION : 0);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
static Point
|
|
@@ -73,15 +73,15 @@ namespace Reflex
|
|
|
73
73
|
switch ([e keyCode])
|
|
74
74
|
{
|
|
75
75
|
case kVK_Shift:
|
|
76
|
-
case kVK_RightShift: return
|
|
76
|
+
case kVK_RightShift: return NSEventModifierFlagShift;
|
|
77
77
|
case kVK_Control:
|
|
78
|
-
case kVK_RightControl: return
|
|
78
|
+
case kVK_RightControl: return NSEventModifierFlagControl;
|
|
79
79
|
case kVK_Option:
|
|
80
|
-
case kVK_RightOption: return
|
|
80
|
+
case kVK_RightOption: return NSEventModifierFlagOption;
|
|
81
81
|
case kVK_Command:
|
|
82
|
-
case kVK_RightCommand: return
|
|
83
|
-
case kVK_CapsLock: return
|
|
84
|
-
case kVK_Function: return
|
|
82
|
+
case kVK_RightCommand: return NSEventModifierFlagCommand;
|
|
83
|
+
case kVK_CapsLock: return NSEventModifierFlagCapsLock;
|
|
84
|
+
case kVK_Function: return NSEventModifierFlagFunction;
|
|
85
85
|
}
|
|
86
86
|
return 0;
|
|
87
87
|
}
|
|
@@ -105,13 +105,56 @@ namespace Reflex
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
|
|
108
|
+
static int
|
|
109
|
+
to_char_index (NSString* str, NSUInteger utf16_index)
|
|
110
|
+
{
|
|
111
|
+
if (utf16_index > str.length) utf16_index = str.length;
|
|
112
|
+
|
|
113
|
+
int index = 0;
|
|
114
|
+
for (NSUInteger i = 0; i < utf16_index; ++i, ++index)
|
|
115
|
+
{
|
|
116
|
+
unichar c = [str characterAtIndex: i];
|
|
117
|
+
if (!CFStringIsSurrogateHighCharacter(c) || i + 1 >= str.length)
|
|
118
|
+
continue;
|
|
119
|
+
|
|
120
|
+
if (CFStringIsSurrogateLowCharacter([str characterAtIndex: i + 1]))
|
|
121
|
+
++i;
|
|
122
|
+
}
|
|
123
|
+
return index;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static int
|
|
127
|
+
get_selection_offset (NSString* str, NSRange selection)
|
|
128
|
+
{
|
|
129
|
+
if (selection.location == NSNotFound) return -1;
|
|
130
|
+
return to_char_index(str, selection.location);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static int
|
|
134
|
+
get_selection_size (NSString* str, NSRange selection)
|
|
135
|
+
{
|
|
136
|
+
if (selection.location == NSNotFound) return 0;
|
|
137
|
+
return
|
|
138
|
+
to_char_index(str, selection.location + selection.length) -
|
|
139
|
+
to_char_index(str, selection.location);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
NativeTextEvent::NativeTextEvent (
|
|
143
|
+
Action action, NSString* text, NSRange selection)
|
|
144
|
+
: TextEvent(
|
|
145
|
+
action, text.UTF8String,
|
|
146
|
+
get_selection_offset(text, selection), get_selection_size(text, selection))
|
|
147
|
+
{
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
|
|
108
151
|
static bool
|
|
109
152
|
is_pointer_dragging (NSEvent* e)
|
|
110
153
|
{
|
|
111
154
|
return
|
|
112
|
-
[e type] ==
|
|
113
|
-
[e type] ==
|
|
114
|
-
[e type] ==
|
|
155
|
+
[e type] == NSEventTypeLeftMouseDragged ||
|
|
156
|
+
[e type] == NSEventTypeRightMouseDragged ||
|
|
157
|
+
[e type] == NSEventTypeOtherMouseDragged;
|
|
115
158
|
}
|
|
116
159
|
|
|
117
160
|
static uint
|
|
@@ -130,24 +173,24 @@ namespace Reflex
|
|
|
130
173
|
{
|
|
131
174
|
switch ([e type])
|
|
132
175
|
{
|
|
133
|
-
case
|
|
134
|
-
case
|
|
135
|
-
case
|
|
176
|
+
case NSEventTypeLeftMouseDown:
|
|
177
|
+
case NSEventTypeLeftMouseUp:
|
|
178
|
+
case NSEventTypeLeftMouseDragged:
|
|
136
179
|
return Reflex::Pointer::MOUSE | Reflex::Pointer::MOUSE_LEFT;
|
|
137
180
|
|
|
138
|
-
case
|
|
139
|
-
case
|
|
140
|
-
case
|
|
181
|
+
case NSEventTypeRightMouseDown:
|
|
182
|
+
case NSEventTypeRightMouseUp:
|
|
183
|
+
case NSEventTypeRightMouseDragged:
|
|
141
184
|
return Reflex::Pointer::MOUSE | Reflex::Pointer::MOUSE_RIGHT;
|
|
142
185
|
|
|
143
|
-
case
|
|
144
|
-
case
|
|
145
|
-
case
|
|
186
|
+
case NSEventTypeOtherMouseDown:
|
|
187
|
+
case NSEventTypeOtherMouseUp:
|
|
188
|
+
case NSEventTypeOtherMouseDragged:
|
|
146
189
|
return Reflex::Pointer::MOUSE | Reflex::Pointer::MOUSE_MIDDLE;
|
|
147
190
|
|
|
148
|
-
case
|
|
149
|
-
case
|
|
150
|
-
case
|
|
191
|
+
case NSEventTypeMouseMoved:
|
|
192
|
+
case NSEventTypeMouseEntered:
|
|
193
|
+
case NSEventTypeMouseExited:
|
|
151
194
|
return Reflex::Pointer::MOUSE | get_current_pointer_type();
|
|
152
195
|
|
|
153
196
|
default:
|
|
@@ -190,8 +233,19 @@ namespace Reflex
|
|
|
190
233
|
}
|
|
191
234
|
|
|
192
235
|
|
|
236
|
+
static coord
|
|
237
|
+
to_wheel_pixels (NSEvent* e, CGFloat delta)
|
|
238
|
+
{
|
|
239
|
+
return delta * (e.hasPreciseScrollingDeltas ? 1 : WHEEL_PIXELS_PER_LINE);
|
|
240
|
+
}
|
|
241
|
+
|
|
193
242
|
NativeWheelEvent::NativeWheelEvent (NSEvent* e, NSView* view)
|
|
194
|
-
: WheelEvent(
|
|
243
|
+
: WheelEvent(
|
|
244
|
+
0, 0, 0,
|
|
245
|
+
to_wheel_pixels(e, e.scrollingDeltaX),
|
|
246
|
+
to_wheel_pixels(e, -e.scrollingDeltaY),
|
|
247
|
+
0,
|
|
248
|
+
get_modifiers(e))
|
|
195
249
|
{
|
|
196
250
|
WheelEvent_set_position(this, get_pointer_position(e, view));
|
|
197
251
|
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// -*- objc -*-
|
|
2
|
+
#include "../file_dialog.h"
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
#import <AppKit/AppKit.h>
|
|
6
|
+
#include "reflex/exception.h"
|
|
7
|
+
#include "window.h"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@interface ReflexOpenSavePanelDelegate : NSObject <NSOpenSavePanelDelegate>
|
|
11
|
+
@end
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@implementation ReflexOpenSavePanelDelegate
|
|
15
|
+
|
|
16
|
+
{
|
|
17
|
+
NSArray<NSString*>* suffixes;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
- (id) initWithExtensions: (const Reflex::StringList&) extensions
|
|
21
|
+
{
|
|
22
|
+
self = [super init];
|
|
23
|
+
if (!self) return nil;
|
|
24
|
+
|
|
25
|
+
NSMutableArray* array = [NSMutableArray arrayWithCapacity: extensions.size()];
|
|
26
|
+
for (const auto& extension : extensions)
|
|
27
|
+
{
|
|
28
|
+
NSString* str = [NSString stringWithUTF8String: ("." + extension).c_str()];
|
|
29
|
+
if (!str)
|
|
30
|
+
Reflex::argument_error(__FILE__, __LINE__);
|
|
31
|
+
|
|
32
|
+
[array addObject: str];
|
|
33
|
+
}
|
|
34
|
+
suffixes = [array retain];
|
|
35
|
+
|
|
36
|
+
return self;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
- (void) dealloc
|
|
40
|
+
{
|
|
41
|
+
[suffixes release];
|
|
42
|
+
|
|
43
|
+
[super dealloc];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
- (BOOL) panel: (id) sender shouldEnableURL: (NSURL*) url
|
|
47
|
+
{
|
|
48
|
+
NSNumber* directory = nil;
|
|
49
|
+
if (![url getResourceValue: &directory forKey: NSURLIsDirectoryKey error: NULL])
|
|
50
|
+
return YES;// what cannot be classified is better shown than hidden
|
|
51
|
+
|
|
52
|
+
if (directory.boolValue)
|
|
53
|
+
return YES;
|
|
54
|
+
|
|
55
|
+
NSString* name = url.lastPathComponent.lowercaseString;
|
|
56
|
+
for (NSString* suffix in suffixes)
|
|
57
|
+
{
|
|
58
|
+
if ([name hasSuffix: suffix.lowercaseString])
|
|
59
|
+
return YES;
|
|
60
|
+
}
|
|
61
|
+
return NO;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@end
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
namespace Reflex
|
|
68
|
+
{
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
static NSOpenPanel*
|
|
72
|
+
create_open_panel (FileDialog* dialog, FileDialog::Data::Mode mode)
|
|
73
|
+
{
|
|
74
|
+
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
|
75
|
+
panel.canChooseFiles = mode != FileDialog::Data::OPEN_DIRECTORY;
|
|
76
|
+
panel.canChooseDirectories = mode == FileDialog::Data::OPEN_DIRECTORY;
|
|
77
|
+
panel.allowsMultipleSelection = mode == FileDialog::Data::OPEN_FILES;
|
|
78
|
+
|
|
79
|
+
const StringList& extensions = dialog->extensions();
|
|
80
|
+
if (mode != FileDialog::Data::OPEN_DIRECTORY && !extensions.empty())
|
|
81
|
+
{
|
|
82
|
+
panel.delegate = [[[ReflexOpenSavePanelDelegate alloc]
|
|
83
|
+
initWithExtensions: extensions]
|
|
84
|
+
autorelease];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return panel;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static NSSavePanel*
|
|
91
|
+
create_save_panel (const char* name)
|
|
92
|
+
{
|
|
93
|
+
NSSavePanel* panel = [NSSavePanel savePanel];
|
|
94
|
+
|
|
95
|
+
if (name && *name)
|
|
96
|
+
panel.nameFieldStringValue = [NSString stringWithUTF8String: name];
|
|
97
|
+
|
|
98
|
+
return panel;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
void
|
|
102
|
+
FileDialog_show (
|
|
103
|
+
FileDialog* dialog, FileDialog::Data::Mode mode,
|
|
104
|
+
const char* dir, const char* name)
|
|
105
|
+
{
|
|
106
|
+
if (!dialog)
|
|
107
|
+
argument_error(__FILE__, __LINE__);
|
|
108
|
+
|
|
109
|
+
bool save = mode == FileDialog::Data::SAVE_FILE;
|
|
110
|
+
NSSavePanel* panel = save
|
|
111
|
+
? create_save_panel(name)
|
|
112
|
+
: create_open_panel(dialog, mode);
|
|
113
|
+
|
|
114
|
+
const char* title = dialog->title();
|
|
115
|
+
if (*title)
|
|
116
|
+
panel.message = [NSString stringWithUTF8String: title];
|
|
117
|
+
|
|
118
|
+
if (dir && *dir)
|
|
119
|
+
{
|
|
120
|
+
NSString* nsdir = [NSString stringWithUTF8String: dir];
|
|
121
|
+
panel.directoryURL = [NSURL fileURLWithPath: nsdir isDirectory: YES];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
FileDialog::Ref dialog_ref = dialog;
|
|
125
|
+
id delegate = panel.delegate;
|
|
126
|
+
void (^completion)(NSModalResponse) = ^(NSModalResponse result)
|
|
127
|
+
{
|
|
128
|
+
(void) delegate;// panel.delegate is weak ref, so capture it here
|
|
129
|
+
|
|
130
|
+
FileDialog* pdialog = const_cast<FileDialog*>(dialog_ref.get());
|
|
131
|
+
|
|
132
|
+
if (result == NSModalResponseOK)
|
|
133
|
+
{
|
|
134
|
+
StringList paths;
|
|
135
|
+
if (save)
|
|
136
|
+
{
|
|
137
|
+
const char* path = panel.URL.path.UTF8String;
|
|
138
|
+
if (path) paths.emplace_back(path);
|
|
139
|
+
}
|
|
140
|
+
else
|
|
141
|
+
{
|
|
142
|
+
for (NSURL* url in ((NSOpenPanel*) panel).URLs)
|
|
143
|
+
{
|
|
144
|
+
const char* path = url.path.UTF8String;
|
|
145
|
+
if (path) paths.emplace_back(path);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
FileEvent e(save ? FileEvent::SAVE : FileEvent::OPEN, paths);
|
|
150
|
+
FileDialog_call_file_event(pdialog, &e);
|
|
151
|
+
}
|
|
152
|
+
else
|
|
153
|
+
{
|
|
154
|
+
Event e;
|
|
155
|
+
FileDialog_call_cancel_event(pdialog, &e);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
Window* owner = dialog->owner();
|
|
160
|
+
NSWindow* nswindow = owner ? (NSWindow*) Window_get_data(owner).native : nil;
|
|
161
|
+
if (nswindow)
|
|
162
|
+
[panel beginSheetModalForWindow: nswindow completionHandler: completion];
|
|
163
|
+
else
|
|
164
|
+
[panel beginWithCompletionHandler: completion];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
}// Reflex
|
data/src/osx/gamepad.mm
CHANGED
|
@@ -21,14 +21,14 @@ namespace Reflex
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
void
|
|
24
|
-
|
|
24
|
+
Gamepad_init_native (Application* app)
|
|
25
25
|
{
|
|
26
26
|
init_gc_gamepads(app);
|
|
27
27
|
init_hid_gamepads(app);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
void
|
|
31
|
-
|
|
31
|
+
Gamepad_fin_native (Application* app)
|
|
32
32
|
{
|
|
33
33
|
fin_gc_gamepads(app);
|
|
34
34
|
fin_hid_gamepads(app);
|
data/src/osx/gamepad_hid.mm
CHANGED
|
@@ -567,7 +567,7 @@ namespace Reflex
|
|
|
567
567
|
|
|
568
568
|
CFIndex count = CFSetGetCount(set.get());
|
|
569
569
|
std::vector<IOHIDDeviceRef> devices(count, NULL);
|
|
570
|
-
CFSetGetValues(set.get(), (const void**)
|
|
570
|
+
CFSetGetValues(set.get(), (const void**) devices.data());
|
|
571
571
|
|
|
572
572
|
for (CFIndex i = 0; i < count; ++i)
|
|
573
573
|
handle_connect_event(app, kIOReturnSuccess, manager, devices[i]);
|