reflexion 0.1.39 → 0.1.41

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,6 +11,7 @@
11
11
  #include <rays/painter.h>
12
12
  #include <reflex/defs.h>
13
13
  #include <reflex/event.h>
14
+ #include <reflex/screen.h>
14
15
 
15
16
 
16
17
  namespace Reflex
@@ -29,12 +30,27 @@ namespace Reflex
29
30
 
30
31
  typedef Xot::Ref<This> Ref;
31
32
 
33
+ enum Flag
34
+ {
35
+
36
+ FLAG_CLOSABLE = Xot::bit(0),
37
+
38
+ FLAG_MINIMIZABLE = Xot::bit(1),
39
+
40
+ FLAG_RESIZABLE = Xot::bit(2),
41
+
42
+ FLAG_LAST = FLAG_RESIZABLE
43
+
44
+ };// Flag
45
+
32
46
  Window ();
33
47
 
34
48
  virtual void show ();
35
49
 
36
50
  virtual void hide ();
37
51
 
52
+ virtual bool hidden () const;
53
+
38
54
  virtual void close (bool force = false);
39
55
 
40
56
  virtual void redraw ();
@@ -53,11 +69,13 @@ namespace Reflex
53
69
 
54
70
  virtual Bounds frame () const;
55
71
 
56
- virtual void set_resizable (bool state = true);
72
+ virtual void add_flag (uint flags);
57
73
 
58
- virtual bool is_resizable () const;
74
+ virtual void remove_flag (uint flags);
59
75
 
60
- virtual bool hidden () const;
76
+ virtual bool has_flag (uint flags) const;
77
+
78
+ virtual Screen screen () const;
61
79
 
62
80
  virtual View* root ();
63
81
 
@@ -24,7 +24,7 @@ module Reflex
24
24
  end
25
25
 
26
26
  def inspect()
27
- "#<Reflex::ContactEvent type:#{type} shape:#{shape} view:#{view}>"
27
+ "#<Reflex::ContactEvent #{action} shape:#{shape} view:#{view}>"
28
28
  end
29
29
 
30
30
  end# ContactEvent
@@ -0,0 +1,21 @@
1
+ require 'forwardable'
2
+
3
+
4
+ module Reflex
5
+
6
+
7
+ class Screen
8
+
9
+ extend Forwardable
10
+
11
+ def_delegators :frame,
12
+ :x, :y, :z, :w, :h, :d, :width, :height, :depth,
13
+ :left, :top, :back, :right, :bottom, :front,
14
+ :left_top, :right_top, :left_bottom, :right_bottom,
15
+ :lt, :lr, :lb, :rb,
16
+ :position, :pos, :size, :center
17
+
18
+ end# Screen
19
+
20
+
21
+ end# Reflex
data/lib/reflex/view.rb CHANGED
@@ -120,14 +120,15 @@ module Reflex
120
120
  cache: {reader: :cache?},
121
121
  resize_to_fit: {reader: :resize_to_fit?},
122
122
  scroll_to_fit: {reader: :scroll_to_fit?},
123
+ fix_angle: {reader: :fix_angle?},
123
124
  static: {reader: :static?},
124
125
  dynamic: {reader: :dynamic?},
125
126
  sensor: {reader: :sensor?},
126
127
  debug: {reader: :debug?}
127
128
 
128
- alias add add_child
129
+ alias add add_child
129
130
  alias remove remove_child
130
- alias find find_child
131
+ alias find find_child
131
132
 
132
133
  alias apply_impulse apply_linear_impulse
133
134
  alias velocity= linear_velocity=
data/lib/reflex/window.rb CHANGED
@@ -62,7 +62,9 @@ module Reflex
62
62
  :restitution=, :restitution
63
63
 
64
64
  universal_accessor :title, :frame,
65
- resizable: {reader: :resizable?}
65
+ closable: {reader: :closable?},
66
+ minimizable: {reader: :minimizable?},
67
+ resizable: {reader: :resizable?}
66
68
 
67
69
  def initialize(options = nil, &block)
68
70
  super()
data/lib/reflex.rb CHANGED
@@ -47,6 +47,7 @@ require 'reflex/model'
47
47
  require 'reflex/model_owner'
48
48
 
49
49
  require 'reflex/application'
50
+ require 'reflex/screen'
50
51
  require 'reflex/window'
51
52
  require 'reflex/view'
52
53
 
data/reflex.gemspec CHANGED
@@ -1,10 +1,7 @@
1
1
  # -*- mode: ruby -*-
2
2
 
3
3
 
4
- File.expand_path('lib', __dir__)
5
- .tap {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
6
-
7
- require 'reflex/extension'
4
+ require_relative 'lib/reflex/extension'
8
5
 
9
6
 
10
7
  Gem::Specification.new do |s|
@@ -17,21 +14,21 @@ Gem::Specification.new do |s|
17
14
  rdocs = glob.call *%w[README .doc/ext/**/*.cpp]
18
15
 
19
16
  s.name = "#{name}ion"
17
+ s.version = ext.version
18
+ s.license = 'MIT'
20
19
  s.summary = 'A Graphical User Interface Tool Kit.'
21
20
  s.description = 'This library helps you to develop interactive graphical user interface.'
22
- s.version = ext.version
23
-
24
- s.authors = %w[xordog]
25
- s.email = 'xordog@gmail.com'
26
- s.homepage = "https://github.com/xord/reflex"
21
+ s.authors = %w[xordog]
22
+ s.email = 'xordog@gmail.com'
23
+ s.homepage = "https://github.com/xord/reflex"
27
24
 
28
25
  s.platform = Gem::Platform::RUBY
29
- s.required_ruby_version = '>= 2.7.0'
26
+ s.required_ruby_version = '>= 3.0.0'
30
27
 
31
- s.add_runtime_dependency 'xot', '~> 0.1.36'
32
- s.add_runtime_dependency 'rucy', '~> 0.1.36'
33
- s.add_runtime_dependency 'beeps', '~> 0.1.37'
34
- s.add_runtime_dependency 'rays', '~> 0.1.37'
28
+ s.add_runtime_dependency 'xot', '~> 0.1.38'
29
+ s.add_runtime_dependency 'rucy', '~> 0.1.38'
30
+ s.add_runtime_dependency 'beeps', '~> 0.1.39'
31
+ s.add_runtime_dependency 'rays', '~> 0.1.39'
35
32
 
36
33
  s.add_development_dependency 'rake'
37
34
  s.add_development_dependency 'test-unit'
data/src/body.cpp CHANGED
@@ -247,6 +247,20 @@ namespace Reflex
247
247
  return Xot::rad2deg(self->b2body->GetAngularVelocity());
248
248
  }
249
249
 
250
+ void
251
+ Body::fix_rotation (bool state)
252
+ {
253
+ validate(this);
254
+
255
+ self->b2body->SetFixedRotation(state);
256
+ }
257
+
258
+ bool
259
+ Body::is_rotation_fixed () const
260
+ {
261
+ return self->b2body->IsFixedRotation();
262
+ }
263
+
250
264
  void
251
265
  Body::set_gravity_scale (float scale)
252
266
  {
data/src/body.h CHANGED
@@ -67,6 +67,10 @@ namespace Reflex
67
67
 
68
68
  float angular_velocity () const;
69
69
 
70
+ void fix_rotation (bool state = true);
71
+
72
+ bool is_rotation_fixed () const;
73
+
70
74
  void set_gravity_scale (float scale);
71
75
 
72
76
  float gravity_scale () const;
@@ -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 Window_make_style_mask(
19
+ Reflex::Window::Data::FLAG_DEFAULT,
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,58 @@
1
+ // -*- mode: objc -*-
2
+ #include "screen.h"
3
+
4
+
5
+ namespace Reflex
6
+ {
7
+
8
+
9
+ struct Screen::Data
10
+ {
11
+
12
+ NSScreen* screen = nil;
13
+
14
+ ~Data ()
15
+ {
16
+ if (screen) [screen release];
17
+ }
18
+
19
+ };// Screen::Data
20
+
21
+
22
+ void
23
+ Screen_initialize (Screen* pthis, NSScreen* screen)
24
+ {
25
+ pthis->self->screen = [screen retain];
26
+ }
27
+
28
+
29
+ Screen::Screen ()
30
+ {
31
+ }
32
+
33
+ Screen::~Screen ()
34
+ {
35
+ }
36
+
37
+ Bounds
38
+ Screen::frame () const
39
+ {
40
+ NSRect frame = self->screen.frame;
41
+ return Bounds(
42
+ frame.origin.x, frame.origin.y,
43
+ frame.size.width, frame.size.height);
44
+ }
45
+
46
+ Screen::operator bool () const
47
+ {
48
+ return self->screen;
49
+ }
50
+
51
+ bool
52
+ Screen::operator ! () const
53
+ {
54
+ return !operator bool();
55
+ }
56
+
57
+
58
+ }// 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
 
@@ -35,6 +36,9 @@ namespace Reflex
35
36
 
36
37
  const WindowData& Window_get_data (const Window* window);
37
38
 
39
+ NSWindowStyleMask Window_make_style_mask (
40
+ uint flags, NSWindowStyleMask styleMask = 0);
41
+
38
42
 
39
43
  }// Reflex
40
44
 
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
  {
@@ -113,19 +135,23 @@ namespace Reflex
113
135
  }
114
136
 
115
137
  void
116
- Window_set_resizable (Window* window, bool state)
138
+ Window_set_flags (Window* window, uint flags)
117
139
  {
118
- NativeWindow* native = get_native(window);
119
- if (state)
120
- native.styleMask |= NSResizableWindowMask;
121
- else
122
- native.styleMask &= ~NSResizableWindowMask;
140
+ NativeWindow* native = get_native(window);
141
+ NSWindowStyleMask styleMask =
142
+ Window_make_style_mask(window->self->flags, native.styleMask);
143
+
144
+ if (styleMask != native.styleMask)
145
+ native.styleMask = styleMask;
123
146
  }
124
147
 
125
- bool
126
- Window_is_resizable (const Window& window)
148
+ Screen
149
+ Window_get_screen (const Window& window)
127
150
  {
128
- return get_native(&window).styleMask & NSResizableWindowMask;
151
+ Screen s;
152
+ NativeWindow* native = get_native(&window);
153
+ if (native && native.screen) Screen_initialize(&s, native.screen);
154
+ return s;
129
155
  }
130
156
 
131
157
  float
data/src/view.cpp CHANGED
@@ -216,6 +216,7 @@ namespace Reflex
216
216
 
217
217
  pbody.reset(b);
218
218
  update_body_frame();
219
+ update_body_states();
219
220
  }
220
221
  return *pbody;
221
222
  }
@@ -235,6 +236,12 @@ namespace Reflex
235
236
  pbody->set_transform(frame.x, frame.y, angle);
236
237
  }
237
238
 
239
+ void update_body_states ()
240
+ {
241
+ if (pbody && pbody->is_rotation_fixed() != has_flag(View::FLAG_FIX_ANGLE))
242
+ pbody->fix_rotation(has_flag(View::FLAG_FIX_ANGLE));
243
+ }
244
+
238
245
  void
239
246
  get_view2body_matrix (Matrix* m)
240
247
  {
@@ -261,7 +268,7 @@ namespace Reflex
261
268
  .translate(-pivot);
262
269
  }
263
270
 
264
- void update_body_and_shapes ()
271
+ void setup_body_and_shapes ()
265
272
  {
266
273
  std::unique_ptr<Body> old_body;
267
274
  if (pbody)
@@ -718,7 +725,7 @@ namespace Reflex
718
725
  }
719
726
 
720
727
  view->self->window = window;
721
- view->self->update_body_and_shapes();
728
+ view->self->setup_body_and_shapes();
722
729
 
723
730
  View::ChildList* children = view->self->children();
724
731
  if (children)
@@ -2364,12 +2371,16 @@ namespace Reflex
2364
2371
  View::add_flag (uint flags)
2365
2372
  {
2366
2373
  self->add_flag(flags);
2374
+
2375
+ self->update_body_states();
2367
2376
  }
2368
2377
 
2369
2378
  void
2370
2379
  View::remove_flag (uint flags)
2371
2380
  {
2372
2381
  self->remove_flag(flags);
2382
+
2383
+ self->update_body_states();
2373
2384
  }
2374
2385
 
2375
2386
  bool
data/src/window.cpp CHANGED
@@ -450,6 +450,12 @@ namespace Reflex
450
450
  self->hide_count = new_count;
451
451
  }
452
452
 
453
+ bool
454
+ Window::hidden () const
455
+ {
456
+ return self->hide_count > 0;
457
+ }
458
+
453
459
  void
454
460
  Window::close (bool force)
455
461
  {
@@ -512,21 +518,31 @@ namespace Reflex
512
518
  }
513
519
 
514
520
  void
515
- Window::set_resizable (bool state)
521
+ Window::add_flag (uint flags)
516
522
  {
517
- Window_set_resizable(this, state);
523
+ Xot::add_flag(&self->flags, flags);
524
+
525
+ Window_set_flags(this, self->flags);
518
526
  }
519
527
 
520
- bool
521
- Window::is_resizable () const
528
+ void
529
+ Window::remove_flag (uint flags)
522
530
  {
523
- return Window_is_resizable(*this);
531
+ Xot::remove_flag(&self->flags, flags);
532
+
533
+ Window_set_flags(this, self->flags);
524
534
  }
525
535
 
526
536
  bool
527
- Window::hidden () const
537
+ Window::has_flag (uint flags) const
528
538
  {
529
- return self->hide_count > 0;
539
+ return Xot::has_flag(self->flags, flags);
540
+ }
541
+
542
+ Screen
543
+ Window::screen () const
544
+ {
545
+ return Window_get_screen(*this);
530
546
  }
531
547
 
532
548
  View*
data/src/window.h CHANGED
@@ -37,6 +37,8 @@ namespace Reflex
37
37
 
38
38
  typedef std::map<View::Ref, TargetPointerMap> CaptureMap;
39
39
 
40
+ enum {FLAG_DEFAULT = FLAG_CLOSABLE | FLAG_MINIMIZABLE | FLAG_RESIZABLE};
41
+
40
42
  int hide_count = 1;
41
43
 
42
44
  bool redraw = true;
@@ -51,6 +53,8 @@ namespace Reflex
51
53
 
52
54
  CaptureMap captures;
53
55
 
56
+ uint flags = FLAG_DEFAULT;
57
+
54
58
  Data ()
55
59
  {
56
60
  prev_time_update = prev_time_draw = Xot::time();
@@ -94,9 +98,9 @@ namespace Reflex
94
98
 
95
99
  Bounds Window_get_frame (const Window& window);
96
100
 
97
- void Window_set_resizable (Window* window, bool state);
101
+ Screen Window_get_screen (const Window& window);
98
102
 
99
- bool Window_is_resizable (const Window& window);
103
+ void Window_set_flags (Window* window, uint flags);
100
104
 
101
105
  void Window_set_focus (Window* window, View* view);
102
106
 
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()
@@ -275,6 +275,20 @@ class TestView < Test::Unit::TestCase
275
275
  assert_equal 361, v.angle
276
276
  end
277
277
 
278
+ def test_fix_angle()
279
+ v = view
280
+ assert_false v.fix_angle?
281
+ assert_false v.fix_angle
282
+
283
+ v.fix_angle = true
284
+ assert_true v.fix_angle?
285
+ assert_true v.fix_angle
286
+
287
+ v.fix_angle false
288
+ assert_false v.fix_angle?
289
+ assert_false v.fix_angle
290
+ end
291
+
278
292
  def test_pivot()
279
293
  v = view
280
294
  assert_each_in_epsilon [0, 0, 0], v.pivot.to_a(3)