reflexion 0.1.40 → 0.1.42

Sign up to get free protection for your applications and to get access to all the features.
data/src/ios/screen.mm ADDED
@@ -0,0 +1,62 @@
1
+ // -*- mode: objc -*-
2
+ #include "screen.h"
3
+
4
+
5
+ #include "reflex/exception.h"
6
+
7
+
8
+ namespace Reflex
9
+ {
10
+
11
+
12
+ struct Screen::Data
13
+ {
14
+
15
+ UIScreen* screen = nil;
16
+
17
+ ~Data ()
18
+ {
19
+ if (screen) [screen release];
20
+ }
21
+
22
+ };// Screen::Data
23
+
24
+
25
+ void
26
+ Screen_initialize (Screen* pthis, UIScreen* screen)
27
+ {
28
+ pthis->self->screen = [screen retain];
29
+ }
30
+
31
+
32
+ Screen::Screen ()
33
+ {
34
+ }
35
+
36
+ Screen::~Screen ()
37
+ {
38
+ }
39
+
40
+ Bounds
41
+ Screen::frame () const
42
+ {
43
+ if (!*this)
44
+ invalid_state_error(__FILE__, __LINE__);
45
+
46
+ CGRect b = self->screen.bounds;
47
+ return Bounds(b.origin.x, b.origin.y, b.size.width, b.size.height);
48
+ }
49
+
50
+ Screen::operator bool () const
51
+ {
52
+ return self->screen;
53
+ }
54
+
55
+ bool
56
+ Screen::operator ! () const
57
+ {
58
+ return !operator bool();
59
+ }
60
+
61
+
62
+ }// Reflex
@@ -17,6 +17,8 @@
17
17
 
18
18
  - (void) stopTimer;
19
19
 
20
+ - (void) update;
21
+
20
22
  - (void) viewDidResize;
21
23
 
22
24
  - (void) titleDidChange;
@@ -293,6 +293,12 @@ ReflexViewController_get_show_fun ()
293
293
  [super viewDidDisappear: animated];
294
294
  }
295
295
 
296
+ - (void)viewDidLayoutSubviews
297
+ {
298
+ [super viewDidLayoutSubviews];
299
+ self.reflexView.frame = self.view.bounds;
300
+ }
301
+
296
302
  - (void) startTimer
297
303
  {
298
304
  [self startTimer: 60];
data/src/ios/window.h CHANGED
@@ -17,9 +17,7 @@ namespace Reflex
17
17
  struct WindowData : public Window::Data
18
18
  {
19
19
 
20
- ReflexViewController* view_controller;
21
-
22
- WindowData ();
20
+ ReflexViewController* view_controller = nil;
23
21
 
24
22
  bool is_valid () const
25
23
  {
data/src/ios/window.mm CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
 
5
5
  #include "reflex/exception.h"
6
+ #include "screen.h"
6
7
  #import "view_controller.h"
7
8
 
8
9
 
@@ -48,6 +49,12 @@ namespace Reflex
48
49
  return new WindowData();
49
50
  }
50
51
 
52
+ uint
53
+ Window_default_flags ()
54
+ {
55
+ return 0;
56
+ }
57
+
51
58
  void
52
59
  Window_initialize (Window* window)
53
60
  {
@@ -127,24 +134,44 @@ namespace Reflex
127
134
  Bounds
128
135
  Window_get_frame (const Window& window)
129
136
  {
130
- CGRect rect = get_vc(&window).reflexView.bounds;
131
- return Bounds(
132
- rect.origin.x,
133
- rect.origin.y,
134
- rect.size.width,
135
- rect.size.height);
137
+ CGRect b = get_vc(&window).reflexView.bounds;
138
+ return Bounds(b.origin.x, b.origin.y, b.size.width, b.size.height);
136
139
  }
137
140
 
138
141
  void
139
- Window_set_resizable (Window* window, bool state)
142
+ Window_set_flags (Window* window, uint flags)
140
143
  {
141
- //not_implemented_error(__FILE__, __LINE__);
144
+ if (Xot::has_flag(flags, Window::FLAG_CLOSABLE))
145
+ argument_error(__FILE__, __LINE__, "FLAG_CLOSABLE is not supported");
146
+
147
+ if (Xot::has_flag(flags, Window::FLAG_MINIMIZABLE))
148
+ argument_error(__FILE__, __LINE__, "FLAG_MINIMIZABLE is not supported");
149
+
150
+ if (Xot::has_flag(flags, Window::FLAG_RESIZABLE))
151
+ argument_error(__FILE__, __LINE__, "FLAG_RESIZABLE is not supported");
152
+ }
153
+
154
+ static UIScreen*
155
+ get_screen (const Window& window)
156
+ {
157
+ UIWindow* w = get_vc(&window).view.window;
158
+ if (@available(iOS 13.0, *))
159
+ {
160
+ return w.windowScene.screen;
161
+ }
162
+ else
163
+ {
164
+ return w.screen;
165
+ }
142
166
  }
143
167
 
144
- bool
145
- Window_is_resizable (const Window& window)
168
+ Screen
169
+ Window_get_screen (const Window& window)
146
170
  {
147
- return false;
171
+ Screen s;
172
+ UIScreen* screen = get_screen(window);
173
+ Screen_initialize(&s, screen ? screen : UIScreen.mainScreen);
174
+ return s;
148
175
  }
149
176
 
150
177
  float
@@ -154,10 +181,4 @@ namespace Reflex
154
181
  }
155
182
 
156
183
 
157
- WindowData::WindowData ()
158
- {
159
- view_controller = nil;
160
- }
161
-
162
-
163
184
  }// Reflex
@@ -12,13 +12,13 @@
12
12
  #import "opengl_view.h"
13
13
 
14
14
 
15
- static const NSUInteger WINDOW_STYLE_MASK =
16
- NSTitledWindowMask |
17
- NSClosableWindowMask |
18
- NSMiniaturizableWindowMask |
19
- NSResizableWindowMask |
20
- 0;//NSTexturedBackgroundWindowMask
21
-
15
+ static NSWindowStyleMask
16
+ default_style_mask ()
17
+ {
18
+ return Reflex::Window_make_style_mask(
19
+ Reflex::Window_default_flags(),
20
+ NSTitledWindowMask | NSTexturedBackgroundWindowMask);
21
+ }
22
22
 
23
23
  static int
24
24
  count_mouse_buttons (const Reflex::PointerEvent& e)
@@ -67,7 +67,7 @@ update_pixel_density (Reflex::Window* window)
67
67
  {
68
68
  self = [super
69
69
  initWithContentRect: NSMakeRect(0, 0, 0, 0)
70
- styleMask: WINDOW_STYLE_MASK
70
+ styleMask: default_style_mask()
71
71
  backing: NSBackingStoreBuffered
72
72
  defer: NO];
73
73
  if (!self) return nil;
@@ -368,7 +368,7 @@ update_pixel_density (Reflex::Window* window)
368
368
  if (clicking_count == 0)
369
369
  ++pointer_id;
370
370
  else if (clicking_count < 0)
371
- Reflex::invalid_state_error(__FILE__, __LINE__);
371
+ return;//Reflex::invalid_state_error(__FILE__, __LINE__);
372
372
 
373
373
  Window_call_pointer_event(win, &e);
374
374
  }
@@ -420,7 +420,7 @@ update_pixel_density (Reflex::Window* window)
420
420
  {
421
421
  return [NSWindow
422
422
  frameRectForContentRect: contentRect
423
- styleMask: WINDOW_STYLE_MASK];
423
+ styleMask: default_style_mask()];
424
424
  }
425
425
 
426
426
  @end// NativeWindow
data/src/osx/screen.h ADDED
@@ -0,0 +1,21 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_SRC_OSX_SCREEN_H__
4
+ #define __REFLEX_SRC_OSX_SCREEN_H__
5
+
6
+
7
+ #import <AppKit/NSScreen.h>
8
+ #include "reflex/screen.h"
9
+
10
+
11
+ namespace Reflex
12
+ {
13
+
14
+
15
+ void Screen_initialize (Screen* pthis, NSScreen* screen);
16
+
17
+
18
+ }// Reflex
19
+
20
+
21
+ #endif//EOH
data/src/osx/screen.mm ADDED
@@ -0,0 +1,62 @@
1
+ // -*- mode: objc -*-
2
+ #include "screen.h"
3
+
4
+
5
+ #include "reflex/exception.h"
6
+
7
+
8
+ namespace Reflex
9
+ {
10
+
11
+
12
+ struct Screen::Data
13
+ {
14
+
15
+ NSScreen* screen = nil;
16
+
17
+ ~Data ()
18
+ {
19
+ if (screen) [screen release];
20
+ }
21
+
22
+ };// Screen::Data
23
+
24
+
25
+ void
26
+ Screen_initialize (Screen* pthis, NSScreen* screen)
27
+ {
28
+ pthis->self->screen = [screen retain];
29
+ }
30
+
31
+
32
+ Screen::Screen ()
33
+ {
34
+ }
35
+
36
+ Screen::~Screen ()
37
+ {
38
+ }
39
+
40
+ Bounds
41
+ Screen::frame () const
42
+ {
43
+ if (!*this)
44
+ invalid_state_error(__FILE__, __LINE__);
45
+
46
+ NSRect f = self->screen.frame;
47
+ return Bounds(f.origin.x, f.origin.y, f.size.width, f.size.height);
48
+ }
49
+
50
+ Screen::operator bool () const
51
+ {
52
+ return self->screen;
53
+ }
54
+
55
+ bool
56
+ Screen::operator ! () const
57
+ {
58
+ return !operator bool();
59
+ }
60
+
61
+
62
+ }// Reflex
data/src/osx/window.h CHANGED
@@ -4,6 +4,7 @@
4
4
  #define __REFLEX_SRC_OSX_WINDOW_H__
5
5
 
6
6
 
7
+ #import <AppKit/NSWindow.h>
7
8
  #include "../window.h"
8
9
 
9
10
 
@@ -17,12 +18,10 @@ namespace Reflex
17
18
  struct WindowData : public Window::Data
18
19
  {
19
20
 
20
- NativeWindow* native;
21
+ NativeWindow* native = nil;
21
22
 
22
23
  mutable String title_tmp;
23
24
 
24
- WindowData ();
25
-
26
25
  bool is_valid () const
27
26
  {
28
27
  return native;
@@ -35,6 +34,9 @@ namespace Reflex
35
34
 
36
35
  const WindowData& Window_get_data (const Window* window);
37
36
 
37
+ NSWindowStyleMask Window_make_style_mask (
38
+ uint flags, NSWindowStyleMask styleMask = 0);
39
+
38
40
 
39
41
  }// Reflex
40
42
 
data/src/osx/window.mm CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  #import <Cocoa/Cocoa.h>
6
6
  #include "reflex/exception.h"
7
+ #include "screen.h"
7
8
  #import "native_window.h"
8
9
 
9
10
 
@@ -31,6 +32,27 @@ namespace Reflex
31
32
  return Window_get_data(const_cast<Window*>(window));
32
33
  }
33
34
 
35
+ NSWindowStyleMask
36
+ Window_make_style_mask (uint flags, NSWindowStyleMask styleMask)
37
+ {
38
+ if (Xot::has_flag(flags, Window::FLAG_CLOSABLE))
39
+ styleMask |= NSWindowStyleMaskClosable;
40
+ else
41
+ styleMask &= ~NSWindowStyleMaskClosable;
42
+
43
+ if (Xot::has_flag(flags, Window::FLAG_MINIMIZABLE))
44
+ styleMask |= NSWindowStyleMaskMiniaturizable;
45
+ else
46
+ styleMask &= ~NSWindowStyleMaskMiniaturizable;
47
+
48
+ if (Xot::has_flag(flags, Window::FLAG_RESIZABLE))
49
+ styleMask |= NSWindowStyleMaskResizable;
50
+ else
51
+ styleMask &= ~NSWindowStyleMaskResizable;
52
+
53
+ return styleMask;
54
+ }
55
+
34
56
  static NativeWindow*
35
57
  get_native (const Window* window)
36
58
  {
@@ -48,6 +70,15 @@ namespace Reflex
48
70
  return new WindowData();
49
71
  }
50
72
 
73
+ uint
74
+ Window_default_flags ()
75
+ {
76
+ return
77
+ Window::FLAG_CLOSABLE |
78
+ Window::FLAG_MINIMIZABLE |
79
+ Window::FLAG_RESIZABLE;
80
+ }
81
+
51
82
  void
52
83
  Window_initialize (Window* window)
53
84
  {
@@ -104,28 +135,28 @@ namespace Reflex
104
135
  Window_get_frame (const Window& window)
105
136
  {
106
137
  NativeWindow* native = get_native(&window);
107
- NSRect rect = [native contentRectForFrameRect: [native frame]];
108
- return Bounds(
109
- rect.origin.x,
110
- rect.origin.y,
111
- rect.size.width,
112
- rect.size.height);
138
+ NSRect r = [native contentRectForFrameRect: [native frame]];
139
+ return Bounds(r.origin.x, r.origin.y, r.size.width, r.size.height);
113
140
  }
114
141
 
115
142
  void
116
- Window_set_resizable (Window* window, bool state)
143
+ Window_set_flags (Window* window, uint flags)
117
144
  {
118
- NativeWindow* native = get_native(window);
119
- if (state)
120
- native.styleMask |= NSResizableWindowMask;
121
- else
122
- native.styleMask &= ~NSResizableWindowMask;
145
+ NativeWindow* native = get_native(window);
146
+ NSWindowStyleMask styleMask =
147
+ Window_make_style_mask(window->self->flags, native.styleMask);
148
+
149
+ if (styleMask != native.styleMask)
150
+ native.styleMask = styleMask;
123
151
  }
124
152
 
125
- bool
126
- Window_is_resizable (const Window& window)
153
+ Screen
154
+ Window_get_screen (const Window& window)
127
155
  {
128
- return get_native(&window).styleMask & NSResizableWindowMask;
156
+ Screen s;
157
+ NSScreen* screen = get_native(&window).screen;
158
+ if (screen) Screen_initialize(&s, screen);
159
+ return s;
129
160
  }
130
161
 
131
162
  float
@@ -135,10 +166,4 @@ namespace Reflex
135
166
  }
136
167
 
137
168
 
138
- WindowData::WindowData ()
139
- {
140
- native = nil;
141
- }
142
-
143
-
144
169
  }// Reflex
data/src/window.cpp CHANGED
@@ -22,6 +22,17 @@ namespace Reflex
22
22
  using TargetPointerMap = Window::Data::TargetPointerMap;
23
23
 
24
24
 
25
+ Window::Data::Data ()
26
+ : flags(Window_default_flags())
27
+ {
28
+ prev_time_update = prev_time_draw = Xot::time();
29
+ }
30
+
31
+ Window::Data::~Data ()
32
+ {
33
+ }
34
+
35
+
25
36
  Window::Data::PointerData::PointerData (uint view_index)
26
37
  : view_index(view_index)
27
38
  {
@@ -450,6 +461,12 @@ namespace Reflex
450
461
  self->hide_count = new_count;
451
462
  }
452
463
 
464
+ bool
465
+ Window::hidden () const
466
+ {
467
+ return self->hide_count > 0;
468
+ }
469
+
453
470
  void
454
471
  Window::close (bool force)
455
472
  {
@@ -512,21 +529,37 @@ namespace Reflex
512
529
  }
513
530
 
514
531
  void
515
- Window::set_resizable (bool state)
532
+ Window::add_flag (uint flags)
516
533
  {
517
- Window_set_resizable(this, state);
534
+ uint value = self->flags;
535
+ Xot::add_flag(&value, flags);
536
+
537
+ Window_set_flags(this, value);
538
+
539
+ self->flags = value;
518
540
  }
519
541
 
520
- bool
521
- Window::is_resizable () const
542
+ void
543
+ Window::remove_flag (uint flags)
522
544
  {
523
- return Window_is_resizable(*this);
545
+ uint value = self->flags;
546
+ Xot::remove_flag(&value, flags);
547
+
548
+ Window_set_flags(this, value);
549
+
550
+ self->flags = value;
524
551
  }
525
552
 
526
553
  bool
527
- Window::hidden () const
554
+ Window::has_flag (uint flags) const
528
555
  {
529
- return self->hide_count > 0;
556
+ return Xot::has_flag(self->flags, flags);
557
+ }
558
+
559
+ Screen
560
+ Window::screen () const
561
+ {
562
+ return Window_get_screen(*this);
530
563
  }
531
564
 
532
565
  View*
data/src/window.h CHANGED
@@ -51,14 +51,11 @@ namespace Reflex
51
51
 
52
52
  CaptureMap captures;
53
53
 
54
- Data ()
55
- {
56
- prev_time_update = prev_time_draw = Xot::time();
57
- }
54
+ uint flags;
58
55
 
59
- virtual ~Data ()
60
- {
61
- }
56
+ Data ();
57
+
58
+ virtual ~Data ();
62
59
 
63
60
  virtual bool is_valid () const = 0;
64
61
 
@@ -77,6 +74,8 @@ namespace Reflex
77
74
 
78
75
  Window::Data* Window_create_data ();
79
76
 
77
+ uint Window_default_flags ();
78
+
80
79
  void Window_initialize (Window* window);
81
80
 
82
81
  void Window_show (Window* window);
@@ -94,9 +93,9 @@ namespace Reflex
94
93
 
95
94
  Bounds Window_get_frame (const Window& window);
96
95
 
97
- void Window_set_resizable (Window* window, bool state);
96
+ Screen Window_get_screen (const Window& window);
98
97
 
99
- bool Window_is_resizable (const Window& window);
98
+ void Window_set_flags (Window* window, uint flags);
100
99
 
101
100
  void Window_set_focus (Window* window, View* view);
102
101
 
data/test/test_event.rb CHANGED
@@ -7,6 +7,10 @@ class TestEvent < Test::Unit::TestCase
7
7
  Reflex::UpdateEvent.new 0, 0
8
8
  end
9
9
 
10
+ def test_initialize()
11
+ assert_raise(Reflex::ReflexError) {Reflex::Event.new}
12
+ end
13
+
10
14
  def test_dup()
11
15
  e1 = event
12
16
  e2 = e1.dup
@@ -0,0 +1,18 @@
1
+ require_relative 'helper'
2
+
3
+
4
+ class TestScreen < Test::Unit::TestCase
5
+
6
+ def screen()
7
+ Reflex::Window.new.screen
8
+ end
9
+
10
+ def test_initialize()
11
+ assert_raise(Reflex::ReflexError) {Reflex::Screen.new}
12
+ end
13
+
14
+ def test_frame()
15
+ assert_raise(Rucy::InvalidObjectError) {screen.frame}
16
+ end
17
+
18
+ end# TestScreen
data/test/test_view.rb CHANGED
@@ -28,21 +28,21 @@ class TestView < Test::Unit::TestCase
28
28
 
29
29
  def test_show_hide_hidden()
30
30
  v = view
31
- assert_equal false, v.hidden?
31
+ assert_false v.hidden?
32
32
  v.hide
33
- assert_equal true, v.hidden?
33
+ assert_true v.hidden?
34
34
  v.show
35
- assert_equal false, v.hidden?
35
+ assert_false v.hidden?
36
36
  end
37
37
 
38
38
  def test_hidden_count()
39
39
  v = view
40
40
  v.show
41
- assert_equal false, v.hidden?
41
+ assert_false v.hidden?
42
42
  v.hide
43
- assert_equal false, v.hidden?
43
+ assert_false v.hidden?
44
44
  v.hide
45
- assert_equal true, v.hidden?
45
+ assert_true v.hidden?
46
46
  end
47
47
 
48
48
  def test_coord_conversion()
data/test/test_window.rb CHANGED
@@ -12,17 +12,21 @@ class TestWindow < Test::Unit::TestCase
12
12
 
13
13
  def test_show_hide_hidden()
14
14
  w = win
15
- assert_equal true, w.hidden
15
+ assert_true w.hidden
16
16
  w.show
17
- assert_equal false, w.hidden
17
+ assert_false w.hidden
18
18
  w.hide
19
- assert_equal true, w.hidden
19
+ assert_true w.hidden
20
+ end
21
+
22
+ def test_hidden_count()
23
+ w = win
20
24
  w.hide
21
- assert_equal true, w.hidden
25
+ assert_true w.hidden
22
26
  w.show
23
- assert_equal true, w.hidden
27
+ assert_true w.hidden
24
28
  w.show
25
- assert_equal false, w.hidden
29
+ assert_false w.hidden
26
30
  end
27
31
 
28
32
  def test_coord_conversion()
@@ -66,6 +70,40 @@ class TestWindow < Test::Unit::TestCase
66
70
  w.frame = [bounds(1, 2, 3, 4, 5, 6)]; assert_equal [1, 2, 0, 4, 5, 0], w.frame.to_a(3)
67
71
  end
68
72
 
73
+ def test_closable?()
74
+ w = win
75
+ assert_true w.closable?
76
+
77
+ w.closable = false
78
+ assert_false w.closable?
79
+
80
+ w.closable = true
81
+ assert_true w.closable?
82
+
83
+ w.closable false
84
+ assert_false w.closable?
85
+
86
+ w.closable true
87
+ assert_true w.closable?
88
+ end
89
+
90
+ def test_minimizable?()
91
+ w = win
92
+ assert_true w.minimizable?
93
+
94
+ w.minimizable = false
95
+ assert_false w.minimizable?
96
+
97
+ w.minimizable = true
98
+ assert_true w.minimizable?
99
+
100
+ w.minimizable false
101
+ assert_false w.minimizable?
102
+
103
+ w.minimizable true
104
+ assert_true w.minimizable?
105
+ end
106
+
69
107
  def test_resizable?()
70
108
  w = win
71
109
  assert_true w.resizable?
@@ -83,6 +121,10 @@ class TestWindow < Test::Unit::TestCase
83
121
  assert_true w.resizable?
84
122
  end
85
123
 
124
+ def test_screen()
125
+ assert_not_nil win.screen
126
+ end
127
+
86
128
  def test_root()
87
129
  w = win
88
130
  assert_not_nil w.root