reflexion 0.3.14 → 0.3.15

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.
data/src/osx/device.mm CHANGED
@@ -9,11 +9,14 @@ namespace Reflex
9
9
  {
10
10
 
11
11
 
12
+ #pragma GCC diagnostic push
13
+ #pragma GCC diagnostic ignored "-Wmissing-noreturn"
12
14
  void
13
15
  vibrate ()
14
16
  {
15
17
  not_implemented_error(__FILE__, __LINE__);
16
18
  }
19
+ #pragma GCC diagnostic pop
17
20
 
18
21
 
19
22
  }// Reflex
@@ -2,6 +2,9 @@
2
2
 
3
3
 
4
4
  #include <SDL.h>
5
+ #ifdef WASM
6
+ #include <emscripten.h>
7
+ #endif
5
8
  #include <xot/time.h>
6
9
  #include "reflex/exception.h"
7
10
  #include "reflex/debug.h"
@@ -51,8 +54,8 @@ namespace Reflex
51
54
  return Window_dispatch_event(win, event);
52
55
  }
53
56
 
54
- static bool
55
- dispatch_events ()
57
+ static void
58
+ dispatch_events (Application* app)
56
59
  {
57
60
  SDL_Event event;
58
61
  while (SDL_PollEvent(&event))
@@ -60,13 +63,9 @@ namespace Reflex
60
63
  if (dispatch_window_event(event))
61
64
  continue;
62
65
 
63
- switch (event.type)
64
- {
65
- case SDL_QUIT: return false;
66
- }
66
+ if (event.type == SDL_QUIT)
67
+ app->quit();
67
68
  }
68
-
69
- return true;
70
69
  }
71
70
 
72
71
  static void
@@ -76,18 +75,15 @@ namespace Reflex
76
75
  Window_update(it->get());
77
76
  }
78
77
 
79
- void
80
- Application::start ()
78
+ static void
79
+ main_loop (Application* app)
81
80
  {
82
- Event e;
83
- Application_call_start(this, &e);
84
-
85
- ApplicationData* self = get_data(this);
81
+ ApplicationData* self = get_data(app);
86
82
 
87
83
  double prev = Xot::time();
88
84
  while (!self->quit)
89
85
  {
90
- if (!dispatch_events()) break;
86
+ dispatch_events(app);
91
87
 
92
88
  static const double INTERVAL = 1.0 / 60.0;
93
89
  static const double SLEEPABLE = INTERVAL * 0.9;
@@ -100,11 +96,39 @@ namespace Reflex
100
96
  continue;
101
97
  }
102
98
 
103
- update_all_windows(this);
99
+ update_all_windows(app);
104
100
  prev = now;
105
101
  }
106
102
  }
107
103
 
104
+ #ifdef WASM
105
+ static void
106
+ emscripten_main_loop (void* arg)
107
+ {
108
+ Application* app = (Application*) arg;
109
+
110
+ dispatch_events(app);
111
+
112
+ if (get_data(app)->quit)
113
+ emscripten_cancel_main_loop();
114
+ else
115
+ update_all_windows(app);
116
+ }
117
+ #endif
118
+
119
+ void
120
+ Application::start ()
121
+ {
122
+ Event e;
123
+ Application_call_start(this, &e);
124
+
125
+ #ifdef WASM
126
+ emscripten_set_main_loop_arg(emscripten_main_loop, this, 0, true);
127
+ #else
128
+ main_loop(this);
129
+ #endif
130
+ }
131
+
108
132
  void
109
133
  Application::quit ()
110
134
  {
data/src/sdl/event.cpp ADDED
@@ -0,0 +1,176 @@
1
+ // -*- c++ -*-
2
+ #include "event.h"
3
+
4
+
5
+ #include "reflex/exception.h"
6
+ #include "reflex/debug.h"
7
+
8
+
9
+ namespace Reflex
10
+ {
11
+
12
+
13
+ static uint
14
+ get_modifiers (SDL_Keymod mod)
15
+ {
16
+ uint ret = 0;
17
+ if (mod & KMOD_CAPS) ret |= MOD_CAPS;
18
+ if (mod & KMOD_SHIFT) ret |= MOD_SHIFT;
19
+ if (mod & KMOD_CTRL) ret |= MOD_CONTROL;
20
+ if (mod & KMOD_ALT) ret |= MOD_ALT;
21
+ if (mod & KMOD_GUI) ret |= MOD_WIN;
22
+ if (mod & KMOD_NUM) ret |= MOD_NUMPAD;
23
+ if (mod & KMOD_SCROLL) ret |= MOD_SCROLL;
24
+ return ret;
25
+ }
26
+
27
+ uint
28
+ KeyEvent_get_modifiers ()
29
+ {
30
+ return get_modifiers(SDL_GetModState());
31
+ }
32
+
33
+
34
+ static const char*
35
+ get_chars (const SDL_KeyboardEvent& e)
36
+ {
37
+ static char buf[2] = {0};
38
+
39
+ const char* name = SDL_GetKeyName(e.keysym.sym);
40
+ if (name && strlen(name) == 1)
41
+ {
42
+ if (e.keysym.mod & KMOD_SHIFT)
43
+ buf[0] = name[0];
44
+ else
45
+ buf[0] = tolower(name[0]);
46
+ return buf;
47
+ }
48
+
49
+ switch (e.keysym.sym)
50
+ {
51
+ case SDLK_RETURN: buf[0] = '\r'; break;
52
+ case SDLK_TAB: buf[0] = '\t'; break;
53
+ case SDLK_BACKSPACE: buf[0] = '\b'; break;
54
+ case SDLK_DELETE: buf[0] = 0x7f; break;
55
+ case SDLK_ESCAPE: buf[0] = 0x1b; break;
56
+ case SDLK_SPACE: buf[0] = ' '; break;
57
+ default: buf[0] = '\0'; break;
58
+ }
59
+ return buf;
60
+ }
61
+
62
+ NativeKeyEvent::NativeKeyEvent (const SDL_KeyboardEvent& e, Action action)
63
+ : KeyEvent(
64
+ action,
65
+ get_chars(e),
66
+ (KeyCode) e.keysym.scancode,
67
+ get_modifiers((SDL_Keymod) e.keysym.mod),
68
+ e.repeat ? 1 : 0)
69
+ {
70
+ }
71
+
72
+
73
+ static uint
74
+ get_pointer_type (Uint8 button)
75
+ {
76
+ uint type = Pointer::MOUSE;
77
+ switch (button)
78
+ {
79
+ case SDL_BUTTON_LEFT: type |= Pointer::MOUSE_LEFT; break;
80
+ case SDL_BUTTON_RIGHT: type |= Pointer::MOUSE_RIGHT; break;
81
+ case SDL_BUTTON_MIDDLE: type |= Pointer::MOUSE_MIDDLE; break;
82
+ }
83
+ return type;
84
+ }
85
+
86
+ static uint
87
+ get_current_pointer_type (Uint32 state)
88
+ {
89
+ uint type = Pointer::MOUSE;
90
+ if (state & SDL_BUTTON_LMASK) type |= Pointer::MOUSE_LEFT;
91
+ if (state & SDL_BUTTON_RMASK) type |= Pointer::MOUSE_RIGHT;
92
+ if (state & SDL_BUTTON_MMASK) type |= Pointer::MOUSE_MIDDLE;
93
+ return type;
94
+ }
95
+
96
+ NativePointerEvent::NativePointerEvent (
97
+ const SDL_MouseButtonEvent& e, SDL_Window* window, Pointer::Action action)
98
+ {
99
+ PointerEvent_add_pointer(this, Pointer(
100
+ 0,
101
+ get_pointer_type(e.button),
102
+ action,
103
+ Point(e.x, e.y),
104
+ get_modifiers(SDL_GetModState()),
105
+ (uint) e.clicks,
106
+ false,
107
+ time()));
108
+ }
109
+
110
+ NativePointerEvent::NativePointerEvent (
111
+ const SDL_MouseMotionEvent& e, SDL_Window* window)
112
+ {
113
+ PointerEvent_add_pointer(this, Pointer(
114
+ 0,
115
+ get_current_pointer_type(e.state),
116
+ Pointer::MOVE,
117
+ Point(e.x, e.y),
118
+ get_modifiers(SDL_GetModState()),
119
+ 0,
120
+ e.state & (SDL_BUTTON_LMASK | SDL_BUTTON_RMASK | SDL_BUTTON_MMASK),
121
+ time()));
122
+ }
123
+
124
+ NativePointerEvent::NativePointerEvent (
125
+ const SDL_TouchFingerEvent& e, SDL_Window* window, Pointer::Action action)
126
+ {
127
+ uint mods = get_modifiers(SDL_GetModState());
128
+ double t = time();
129
+
130
+ int w = 0, h = 0;
131
+ if (window) SDL_GetWindowSize(window, &w, &h);
132
+
133
+ PointerEvent_add_pointer(this, Pointer(
134
+ (uint) e.fingerId,
135
+ Pointer::TOUCH,
136
+ action,
137
+ Point(e.x * w, e.y * h),
138
+ mods,
139
+ 0,
140
+ action == Pointer::MOVE,
141
+ t));
142
+
143
+ int size = SDL_GetNumTouchFingers(e.touchId);
144
+ for (int i = 0; i < size; ++i)
145
+ {
146
+ SDL_Finger* finger = SDL_GetTouchFinger(e.touchId, i);
147
+ if (!finger || finger->id == e.fingerId) continue;
148
+ PointerEvent_add_pointer(this, Pointer(
149
+ (uint) finger->id,
150
+ Pointer::TOUCH,
151
+ Pointer::STAY,
152
+ Point(finger->x * w, finger->y * h),
153
+ mods,
154
+ 0,
155
+ true,
156
+ t));
157
+ }
158
+ }
159
+
160
+
161
+ NativeWheelEvent::NativeWheelEvent (
162
+ const SDL_MouseWheelEvent& e, SDL_Window* window)
163
+ : WheelEvent(
164
+ 0, 0, 0,
165
+ e.direction == SDL_MOUSEWHEEL_FLIPPED ? -e.preciseX : e.preciseX,
166
+ e.direction == SDL_MOUSEWHEEL_FLIPPED ? -e.preciseY : e.preciseY,
167
+ 0,
168
+ get_modifiers(SDL_GetModState()))
169
+ {
170
+ int mx, my;
171
+ SDL_GetMouseState(&mx, &my);
172
+ WheelEvent_set_position(this, Point(mx, my));
173
+ }
174
+
175
+
176
+ }// Reflex
data/src/sdl/event.h ADDED
@@ -0,0 +1,58 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_SRC_SDL_EVENT_H__
4
+ #define __REFLEX_SRC_SDL_EVENT_H__
5
+
6
+
7
+ #include <SDL.h>
8
+ #include "../event.h"
9
+
10
+
11
+ namespace Reflex
12
+ {
13
+
14
+
15
+ class NativeKeyEvent : public KeyEvent
16
+ {
17
+
18
+ public:
19
+
20
+ NativeKeyEvent (const SDL_KeyboardEvent& event, Action action);
21
+
22
+ };// NativeKeyEvent
23
+
24
+
25
+ class NativePointerEvent : public PointerEvent
26
+ {
27
+
28
+ public:
29
+
30
+ NativePointerEvent (
31
+ const SDL_MouseButtonEvent& event, SDL_Window* window,
32
+ Pointer::Action action);
33
+
34
+ NativePointerEvent (
35
+ const SDL_MouseMotionEvent& event, SDL_Window* window);
36
+
37
+ NativePointerEvent (
38
+ const SDL_TouchFingerEvent& event, SDL_Window* window,
39
+ Pointer::Action action);
40
+
41
+ };// NativePointerEvent
42
+
43
+
44
+ class NativeWheelEvent : public WheelEvent
45
+ {
46
+
47
+ public:
48
+
49
+ NativeWheelEvent (
50
+ const SDL_MouseWheelEvent& event, SDL_Window* window);
51
+
52
+ };// NativeWheelEvent
53
+
54
+
55
+ }// Reflex
56
+
57
+
58
+ #endif//EOH
data/src/sdl/window.cpp CHANGED
@@ -5,6 +5,7 @@
5
5
  #include "reflex/debug.h"
6
6
  #include "reflex/screen.h"
7
7
  #include "../view.h"
8
+ #include "event.h"
8
9
  #include "screen.h"
9
10
  #include "opengl.h"
10
11
 
@@ -68,7 +69,7 @@ namespace Reflex
68
69
 
69
70
  Uint32 to_sdl_flags (uint flags)
70
71
  {
71
- Uint32 sdl_flags = SDL_WINDOW_OPENGL;
72
+ Uint32 sdl_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI;
72
73
 
73
74
  if (Xot::has_flag(flags, Window::FLAG_RESIZABLE))
74
75
  sdl_flags |= SDL_WINDOW_RESIZABLE;
@@ -298,15 +299,16 @@ namespace Reflex
298
299
  return 1;
299
300
 
300
301
  SDL_Window* native = get_native(const_cast<Window*>(&win));
301
- int display_index = SDL_GetWindowDisplayIndex(native);
302
- if (display_index < 0)
302
+ if (!native)
303
303
  return 1;
304
304
 
305
- float dpi = 0;
306
- if (SDL_GetDisplayDPI(display_index, &dpi, NULL, NULL) != 0)
305
+ int win_w = 0, draw_w = 0;
306
+ SDL_GetWindowSize( native, &win_w, NULL);
307
+ SDL_GL_GetDrawableSize(native, &draw_w, NULL);
308
+ if (win_w <= 0 || draw_w <= 0)
307
309
  return 1;
308
310
 
309
- return dpi / 96.f;
311
+ return (float) draw_w / (float) win_w;
310
312
  }
311
313
 
312
314
  Window*
@@ -318,32 +320,111 @@ namespace Reflex
318
320
  bool
319
321
  Window_dispatch_event (Window* win, const SDL_Event& event)
320
322
  {
321
- if (event.type != SDL_WINDOWEVENT) return true;
322
-
323
323
  WindowData* self = get_data(win);
324
324
 
325
- switch (event.window.event)
325
+ switch (event.type)
326
326
  {
327
- case SDL_WINDOWEVENT_CLOSE:
328
- Window_close(win);
327
+ case SDL_WINDOWEVENT:
328
+ {
329
+ switch (event.window.event)
330
+ {
331
+ case SDL_WINDOWEVENT_CLOSE:
332
+ Window_close(win);
333
+ break;
334
+
335
+ case SDL_WINDOWEVENT_EXPOSED:
336
+ self->context.make_current();
337
+ draw(win);
338
+ self->context.swap_buffers();
339
+ break;
340
+
341
+ case SDL_WINDOWEVENT_MOVED:
342
+ case SDL_WINDOWEVENT_RESIZED:
343
+ case SDL_WINDOWEVENT_SIZE_CHANGED:
344
+ case SDL_WINDOWEVENT_RESTORED:
345
+ case SDL_WINDOWEVENT_MAXIMIZED:
346
+ case SDL_WINDOWEVENT_MINIMIZED:
347
+ frame_changed(win);
348
+ break;
349
+
350
+ case SDL_WINDOWEVENT_FOCUS_GAINED:
351
+ Window_call_activate_event(win);
352
+ break;
353
+
354
+ case SDL_WINDOWEVENT_FOCUS_LOST:
355
+ Window_call_deactivate_event(win);
356
+ break;
357
+ }
329
358
  break;
359
+ }
360
+
361
+ case SDL_KEYDOWN:
362
+ {
363
+ NativeKeyEvent e(event.key, KeyEvent::DOWN);
364
+ Window_call_key_event(win, &e);
365
+ break;
366
+ }
330
367
 
331
- case SDL_WINDOWEVENT_EXPOSED:
368
+ case SDL_KEYUP:
332
369
  {
333
- self->context.make_current();
334
- draw(win);
335
- self->context.swap_buffers();
370
+ NativeKeyEvent e(event.key, KeyEvent::UP);
371
+ Window_call_key_event(win, &e);
336
372
  break;
337
373
  }
338
374
 
339
- case SDL_WINDOWEVENT_MOVED:
340
- case SDL_WINDOWEVENT_RESIZED:
341
- case SDL_WINDOWEVENT_SIZE_CHANGED:
342
- case SDL_WINDOWEVENT_RESTORED:
343
- case SDL_WINDOWEVENT_MAXIMIZED:
344
- case SDL_WINDOWEVENT_MINIMIZED:
345
- frame_changed(win);
375
+ case SDL_MOUSEBUTTONDOWN:
376
+ {
377
+ NativePointerEvent e(
378
+ event.button, self->native, Pointer::DOWN);
379
+ Window_call_pointer_event(win, &e);
380
+ break;
381
+ }
382
+
383
+ case SDL_MOUSEBUTTONUP:
384
+ {
385
+ NativePointerEvent e(
386
+ event.button, self->native, Pointer::UP);
387
+ Window_call_pointer_event(win, &e);
388
+ break;
389
+ }
390
+
391
+ case SDL_MOUSEMOTION:
392
+ {
393
+ NativePointerEvent e(event.motion, self->native);
394
+ Window_call_pointer_event(win, &e);
346
395
  break;
396
+ }
397
+
398
+ case SDL_MOUSEWHEEL:
399
+ {
400
+ NativeWheelEvent e(event.wheel, self->native);
401
+ Window_call_wheel_event(win, &e);
402
+ break;
403
+ }
404
+
405
+ case SDL_FINGERDOWN:
406
+ {
407
+ NativePointerEvent e(event.tfinger, self->native, Pointer::DOWN);
408
+ Window_call_pointer_event(win, &e);
409
+ break;
410
+ }
411
+
412
+ case SDL_FINGERUP:
413
+ {
414
+ NativePointerEvent e(event.tfinger, self->native, Pointer::UP);
415
+ Window_call_pointer_event(win, &e);
416
+ break;
417
+ }
418
+
419
+ case SDL_FINGERMOTION:
420
+ {
421
+ NativePointerEvent e(event.tfinger, self->native, Pointer::MOVE);
422
+ Window_call_pointer_event(win, &e);
423
+ break;
424
+ }
425
+
426
+ default:
427
+ return false;
347
428
  }
348
429
 
349
430
  return true;
data/src/shape.cpp CHANGED
@@ -852,7 +852,7 @@ namespace Reflex
852
852
  b2points[i] = to_b2vec2(polyline[i], ppm);
853
853
 
854
854
  b2PolygonShape b2shape;
855
- b2shape.Set(&b2points[0], polyline.size());
855
+ b2shape.Set(&b2points[0], (int32) polyline.size());
856
856
 
857
857
  return FixtureBuilder(shape, &b2shape).fixtures();
858
858
  }
@@ -1213,12 +1213,6 @@ namespace Reflex
1213
1213
  return (WallShapeData&) *shape.self;
1214
1214
  }
1215
1215
 
1216
- static const WallShapeData&
1217
- get_data (const WallShape& shape)
1218
- {
1219
- return get_data(const_cast<WallShape&>(shape));
1220
- }
1221
-
1222
1216
 
1223
1217
  WallShape::WallShape (uint positions, coord thickness)
1224
1218
  : Super(new WallShapeData)
data/src/style.cpp CHANGED
@@ -321,7 +321,7 @@ namespace Reflex
321
321
 
322
322
  bool set_flow (Flow main, Flow sub)
323
323
  {
324
- return flow.set((main & FLOW_MASK) | ((sub & FLOW_MASK) << FLOW_SHIFT));
324
+ return flow.set(((int) main & FLOW_MASK) | (((int) sub & FLOW_MASK) << FLOW_SHIFT));
325
325
  }
326
326
 
327
327
  Flow flow_main () const
data/src/timer.cpp CHANGED
@@ -268,6 +268,8 @@ namespace Reflex
268
268
  timers.pop_front();
269
269
  }
270
270
 
271
+ #pragma GCC diagnostic push
272
+ #pragma GCC diagnostic ignored "-Wmissing-noreturn"
271
273
  void
272
274
  Timers::find_timers (
273
275
  TimerList* result, const Selector& selector, bool recursive) const
@@ -277,6 +279,7 @@ namespace Reflex
277
279
 
278
280
  not_implemented_error(__FILE__, __LINE__);
279
281
  }
282
+ #pragma GCC diagnostic pop
280
283
 
281
284
 
282
285
  }// Reflex
data/src/win32/event.cpp CHANGED
@@ -42,7 +42,6 @@ namespace Reflex
42
42
  }
43
43
 
44
44
 
45
-
46
45
  static uint
47
46
  get_mouse_type (UINT msg, WPARAM wp)
48
47
  {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reflexion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.3.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-17 00:00:00.000000000 Z
11
+ date: 2026-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xot
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.11
19
+ version: 0.3.12
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.3.11
26
+ version: 0.3.12
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rucy
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.11
33
+ version: 0.3.12
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.3.11
40
+ version: 0.3.12
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rays
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.3.11
47
+ version: 0.3.12
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.3.11
54
+ version: 0.3.12
55
55
  description: This library helps you to develop interactive graphical user interface.
56
56
  email: xordog@gmail.com
57
57
  executables: []
@@ -383,6 +383,8 @@ files:
383
383
  - src/reflex.cpp
384
384
  - src/sdl/application.cpp
385
385
  - src/sdl/device.cpp
386
+ - src/sdl/event.cpp
387
+ - src/sdl/event.h
386
388
  - src/sdl/gamepad.cpp
387
389
  - src/sdl/opengl.cpp
388
390
  - src/sdl/opengl.h