reflexion 0.1.3 → 0.1.4

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.
Files changed (88) hide show
  1. data/.doc/ext/reflex/application.cpp +35 -76
  2. data/.doc/ext/reflex/defs.cpp +8 -0
  3. data/.doc/ext/reflex/key.cpp +38 -43
  4. data/.doc/ext/reflex/native.cpp +6 -4
  5. data/.doc/ext/reflex/points.cpp +47 -52
  6. data/.doc/ext/reflex/reflex.cpp +12 -13
  7. data/.doc/ext/reflex/view.cpp +242 -0
  8. data/.doc/ext/reflex/window.cpp +87 -178
  9. data/.gitignore +14 -0
  10. data/Rakefile +6 -31
  11. data/VERSION +1 -1
  12. data/examples/hello/.gitignore +2 -0
  13. data/examples/ruby/app.rb +2 -2
  14. data/examples/ruby/checker.rb +3 -3
  15. data/examples/ruby/fps.rb +14 -14
  16. data/examples/ruby/grid.rb +65 -0
  17. data/examples/ruby/hello.rb +19 -7
  18. data/examples/ruby/key.rb +4 -4
  19. data/examples/ruby/shapes.rb +6 -6
  20. data/examples/ruby/text.rb +20 -17
  21. data/examples/ruby/views.rb +88 -0
  22. data/examples/ruby/visuals.rb +27 -0
  23. data/ext/reflex/application.cpp +36 -76
  24. data/ext/reflex/defs.cpp +8 -0
  25. data/ext/reflex/defs.h +1 -18
  26. data/ext/reflex/extconf.rb +16 -8
  27. data/ext/reflex/key.cpp +39 -43
  28. data/ext/reflex/native.cpp +6 -4
  29. data/ext/reflex/points.cpp +48 -52
  30. data/ext/reflex/reflex.cpp +12 -13
  31. data/ext/reflex/view.cpp +260 -0
  32. data/ext/reflex/window.cpp +89 -178
  33. data/include/reflex/application.h +14 -7
  34. data/include/reflex/defs.h +8 -6
  35. data/include/reflex/exception.h +1 -1
  36. data/include/reflex/ruby/application.h +31 -10
  37. data/include/reflex/ruby/key.h +3 -3
  38. data/include/reflex/ruby/points.h +3 -3
  39. data/include/reflex/ruby/view.h +106 -0
  40. data/include/reflex/ruby/window.h +83 -12
  41. data/include/reflex/ruby.h +3 -2
  42. data/include/reflex/view.h +103 -0
  43. data/include/reflex/window.h +43 -18
  44. data/include/reflex.h +2 -1
  45. data/lib/reflex/application.rb +8 -7
  46. data/lib/reflex/autoinit.rb +1 -1
  47. data/lib/reflex/bitmap.rb +13 -0
  48. data/lib/reflex/bounds.rb +2 -122
  49. data/lib/reflex/ext.rb +5 -0
  50. data/lib/reflex/helpers.rb +36 -31
  51. data/lib/reflex/image.rb +13 -0
  52. data/lib/reflex/module.rb +9 -2
  53. data/lib/reflex/painter.rb +13 -0
  54. data/lib/reflex/point.rb +3 -59
  55. data/lib/reflex/reflex.rb +1 -1
  56. data/lib/reflex/texture.rb +13 -0
  57. data/lib/reflex/view.rb +33 -0
  58. data/lib/reflex/visuals/string.rb +53 -0
  59. data/lib/reflex/window.rb +18 -43
  60. data/lib/reflex.rb +3 -3
  61. data/reflex.gemspec +16 -42
  62. data/src/cocoa/application.mm +17 -23
  63. data/src/cocoa/applicationdata.h +3 -9
  64. data/src/cocoa/cocoaapplication.h +6 -4
  65. data/src/cocoa/cocoaapplication.mm +61 -19
  66. data/src/cocoa/cocoawindow.h +7 -5
  67. data/src/cocoa/cocoawindow.mm +109 -50
  68. data/src/cocoa/defs.mm +5 -2
  69. data/src/cocoa/window.mm +71 -41
  70. data/src/cocoa/windowdata.h +14 -9
  71. data/src/defs.cpp +1 -1
  72. data/src/exception.cpp +3 -18
  73. data/src/helpers.h +12 -0
  74. data/src/reflex.cpp +11 -5
  75. data/src/view.cpp +326 -0
  76. data/src/win32/application.cpp +7 -8
  77. data/src/win32/defs.h +1 -1
  78. data/src/win32/window.cpp +137 -41
  79. data/src/window.cpp +38 -1
  80. data/test/helpers.rb +2 -5
  81. data/test/test_application.rb +17 -0
  82. data/test/test_reflex.rb +4 -2
  83. data/test/test_view.rb +74 -0
  84. data/test/test_window.rb +33 -2
  85. metadata +157 -97
  86. data/include/reflex/helpers.h +0 -32
  87. data/test/test_bounds.rb +0 -163
  88. data/test/test_point.rb +0 -81
data/src/win32/window.cpp CHANGED
@@ -1,10 +1,13 @@
1
1
  #include "reflex/window.h"
2
2
 
3
3
 
4
+ #define NOMINMAX
4
5
  #include <windows.h>
5
6
  #include <boost/shared_ptr.hpp>
6
7
  #include <boost/scoped_array.hpp>
8
+ #include <rays/painter.h>
7
9
  #include "reflex/reflex.h"
10
+ #include "reflex/view.h"
8
11
  #include "opengl.h"
9
12
 
10
13
 
@@ -21,11 +24,52 @@ namespace Reflex
21
24
 
22
25
  int hidecount;
23
26
 
27
+ bool redraw;
28
+
29
+ Painter painter;
30
+
31
+ View::Ref root;
32
+
33
+ String title_tmp;
34
+
24
35
  OpenGL opengl;
25
36
 
26
37
  Data ()
27
- : this_(NULL), hwnd(NULL), hidecount(1)
38
+ : this_(NULL), hwnd(NULL), hidecount(1), redraw(true), root(new View)
39
+ {
40
+ root->set_name("root");
41
+ }
42
+
43
+ ~Data ()
44
+ {
45
+ unbind();
46
+ }
47
+
48
+ void bind_reflex (Window* obj)
49
+ {
50
+ if (!obj) return;
51
+
52
+ this_ = obj;
53
+ }
54
+
55
+ void unbind_reflex ()
56
+ {
57
+ this_ = NULL;
58
+ }
59
+
60
+ void unbind ()
61
+ {
62
+ unbind_reflex();
63
+ }
64
+
65
+ operator bool () const
66
+ {
67
+ return this_ && hwnd && IsWindow(hwnd);
68
+ }
69
+
70
+ bool operator ! () const
28
71
  {
72
+ return !operator bool();
29
73
  }
30
74
 
31
75
  };// Window::Data
@@ -198,7 +242,7 @@ namespace Reflex
198
242
  case WM_TIMER:
199
243
  {
200
244
  if (wp == UPDATE_TIMER_ID)
201
- win->update();
245
+ win->update(1);
202
246
  return 0;
203
247
  }
204
248
 
@@ -291,24 +335,18 @@ namespace Reflex
291
335
 
292
336
  Window::Window ()
293
337
  {
294
- self->this_ = this;
338
+ self->bind_reflex(this);
295
339
 
296
340
  create_window(this);
341
+
342
+ self->painter.canvas(0, 0, 1, 1);
297
343
  }
298
344
 
299
345
  Window::~Window ()
300
346
  {
301
347
  close();
302
- self->this_ = NULL;
303
- }
304
-
305
- bool
306
- Window::close ()
307
- {
308
- if (!self->hwnd || !IsWindow(self->hwnd))
309
- return false;
310
348
 
311
- return DestroyWindow(self->hwnd) != FALSE;
349
+ self->unbind_reflex();
312
350
  }
313
351
 
314
352
  static bool
@@ -361,11 +399,12 @@ namespace Reflex
361
399
  }
362
400
 
363
401
  bool
364
- Window::hidden () const
402
+ Window::close ()
365
403
  {
366
- if (!*this) return true;
404
+ if (!self->hwnd || !IsWindow(self->hwnd))
405
+ return false;
367
406
 
368
- return self->hidecount > 0;
407
+ return DestroyWindow(self->hwnd) != FALSE;
369
408
  }
370
409
 
371
410
  bool
@@ -374,6 +413,9 @@ namespace Reflex
374
413
  if (!*this) return false;
375
414
 
376
415
  #if 1
416
+ self->redraw = true;
417
+ return true;
418
+ #elif 1
377
419
  InvalidateRect(self->hwnd, NULL, FALSE);
378
420
  return true;
379
421
  #else
@@ -383,45 +425,66 @@ namespace Reflex
383
425
  }
384
426
 
385
427
  bool
386
- Window::get_title (String* title) const
428
+ Window::set_title (const char* title)
387
429
  {
388
430
  if (!*this || !title) return false;
389
431
 
390
- *title = "";
432
+ return SetWindowText(self->hwnd, title) != FALSE;
433
+ }
434
+
435
+ const char*
436
+ Window::title () const
437
+ {
438
+ if (!*this) return "";
391
439
 
392
440
  int size = GetWindowTextLength(self->hwnd);
393
- if (size <= 0) return true;
441
+ if (size <= 0) return "";
394
442
 
395
443
  boost::scoped_array<char> buf(new char[size + 1]);
396
444
  if (GetWindowText(self->hwnd, &buf[0], size + 1) != size)
397
- return false;
445
+ return "";
398
446
 
399
- *title = &buf[0];
400
- return true;
401
- }
402
-
403
- bool
404
- Window::set_title (const char* title)
405
- {
406
- if (!*this || !title) return false;
407
-
408
- return SetWindowText(self->hwnd, title) != FALSE;
447
+ self->title_tmp = &buf[0];
448
+ return self->title_tmp.c_str();
409
449
  }
410
450
 
411
- bool
412
- Window::get_bounds (coord* x, coord* y, coord* width, coord* height)
451
+ static bool
452
+ get_window_bounds (
453
+ HWND hwnd, coord* x, coord* y, coord* width, coord* height,
454
+ coord* nonclient_width = NULL, coord* nonclient_height = NULL)
413
455
  {
414
- if (!*this || (!x && !y && !width && !height))
456
+ if (
457
+ !hwnd ||
458
+ (!x && !y && !width && !height) ||
459
+ !!nonclient_width != !!nonclient_height)
460
+ {
415
461
  return false;
462
+ }
416
463
 
417
- RECT rect;
418
- if (!GetWindowRect(self->hwnd, &rect))
464
+ RECT window, client;
465
+ if (
466
+ !GetWindowRect(hwnd, &window) ||
467
+ !GetClientRect(hwnd, &client))
468
+ {
419
469
  return false;
470
+ }
471
+
472
+ if (x) *x = window.left;
473
+ if (y) *y = window.top;
474
+ if (width) *width = client.right - client.left;
475
+ if (height) *height = client.bottom - client.top;
476
+
477
+ if (nonclient_width || nonclient_height)
478
+ {
479
+ coord ww = window.right - window.left;
480
+ coord wh = window.bottom - window.top;
481
+ coord cw = client.right - client.left;
482
+ coord ch = client.bottom - client.top;
483
+
484
+ *nonclient_width = ww - cw;
485
+ *nonclient_height = wh - ch;
486
+ }
420
487
 
421
- if (x) *x = rect.left;
422
- if (y) *y = rect.top;
423
- if (width) *width = rect.right - rect.left + 1;
424
- if (height) *height = rect.bottom - rect.top + 1;
425
488
  return true;
426
489
  }
427
490
 
@@ -430,9 +493,16 @@ namespace Reflex
430
493
  {
431
494
  if (!*this) return false;
432
495
 
433
- coord xx, yy, ww, hh;
434
- if (!get_bounds(&xx, &yy, &ww, &hh))
496
+ coord xx, yy, ww, hh, nonclient_w, nonclient_h;
497
+ if (
498
+ !get_window_bounds(
499
+ self->hwnd, &xx, &yy, &ww, &hh, &nonclient_w, &nonclient_h))
500
+ {
435
501
  return false;
502
+ }
503
+
504
+ width += nonclient_w;
505
+ height += nonclient_h;
436
506
 
437
507
  UINT flags = 0;
438
508
  if (x == xx && y == yy) flags |= SWP_NOMOVE;
@@ -445,9 +515,35 @@ namespace Reflex
445
515
  flags | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
446
516
  }
447
517
 
518
+ bool
519
+ Window::get_bounds (coord* x, coord* y, coord* width, coord* height)
520
+ {
521
+ return *this && get_window_bounds(self->hwnd, x, y, width, height);
522
+ }
523
+
524
+ bool
525
+ Window::hidden () const
526
+ {
527
+ if (!*this) return true;
528
+
529
+ return self->hidecount > 0;
530
+ }
531
+
532
+ View*
533
+ Window::root ()
534
+ {
535
+ return self->root.get();
536
+ }
537
+
538
+ Painter*
539
+ Window::painter ()
540
+ {
541
+ return &self->painter;
542
+ }
543
+
448
544
  Window::operator bool () const
449
545
  {
450
- return self && self->this_ && self->hwnd && IsWindow(self->hwnd);
546
+ return self && *self;
451
547
  }
452
548
 
453
549
 
data/src/window.cpp CHANGED
@@ -1,18 +1,50 @@
1
1
  #include "reflex/window.h"
2
2
 
3
3
 
4
+ #include <rays/bounds.h>
5
+ #include <rays/painter.h>
6
+ #include <reflex/view.h>
7
+
8
+
4
9
  namespace Reflex
5
10
  {
6
11
 
7
12
 
13
+ void update_view_tree (View* v, float dt);
14
+
15
+ void draw_view_tree (View* v, Painter* p, coord left, coord top);
16
+
17
+
18
+ const View*
19
+ Window::root () const
20
+ {
21
+ return const_cast<Window*>(this)->root();
22
+ }
23
+
24
+ const Painter*
25
+ Window::painter () const
26
+ {
27
+ return const_cast<Window*>(this)->painter();
28
+ }
29
+
8
30
  void
9
- Window::update ()
31
+ Window::update (float dt)
10
32
  {
33
+ update_view_tree(root(), dt);
11
34
  }
12
35
 
13
36
  void
14
37
  Window::draw ()
15
38
  {
39
+ Painter* p = painter();
40
+ if (!p) return;
41
+
42
+ View* v = root();
43
+ if (!v) return;
44
+
45
+ if (!p->begin()) return;
46
+ draw_view_tree(v, p, 0, 0);
47
+ p->end();
16
48
  }
17
49
 
18
50
  void
@@ -23,6 +55,11 @@ namespace Reflex
23
55
  void
24
56
  Window::resized (coord width, coord height)
25
57
  {
58
+ Painter* p = painter();
59
+ if (p) p->canvas(0, 0, width, height);
60
+
61
+ View* v = root();
62
+ if (v) v->set_bounds(0, 0, width, height);
26
63
  }
27
64
 
28
65
  void
data/test/helpers.rb CHANGED
@@ -1,11 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
- require 'test/unit'
3
2
 
4
3
 
5
- %w[rays reflex].product(%w[ext lib]).each do |paths|
6
- paths = %w[.. ..] + paths
7
- $: << File.expand_path(File.join File.dirname(__FILE__), *paths)
8
- end
4
+ require 'bundler/setup'
5
+ require 'test/unit'
9
6
  require 'reflex'
10
7
 
11
8
 
@@ -0,0 +1,17 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require_relative 'helpers'
5
+
6
+
7
+ class TestApplication < Test::Unit::TestCase
8
+
9
+ @@app = Reflex::Application.new
10
+
11
+ def test_name ()
12
+ assert_equal '', @@app.name
13
+ @@app.name = 'AppName'
14
+ assert_equal 'AppName', @@app.name
15
+ end
16
+
17
+ end# TestApplication
data/test/test_reflex.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  # -*- coding: utf-8 -*-
2
- $: << File.dirname(__FILE__)
2
+
3
+
3
4
  $RAYS_NOAUTOINIT = true
4
5
  $REFLEX_NOAUTOINIT = true
5
- require 'helpers'
6
+
7
+ require_relative 'helpers'
6
8
 
7
9
 
8
10
  class TestReflex < Test::Unit::TestCase
data/test/test_view.rb ADDED
@@ -0,0 +1,74 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require_relative 'helpers'
5
+
6
+
7
+ class TestView < Test::Unit::TestCase
8
+
9
+ def view (*args)
10
+ Reflex::View.new *args
11
+ end
12
+
13
+ def test_initialize ()
14
+ assert_equal '', view.name
15
+ assert_equal 'Test', view(:name => 'Test').name
16
+ end
17
+
18
+ def test_hidden ()
19
+ v = view
20
+ assert_equal false, v.hidden
21
+ v.hide
22
+ assert_equal true, v.hidden
23
+ v.show
24
+ assert_equal false, v.hidden
25
+ end
26
+
27
+ def test_hidden_count ()
28
+ v = view
29
+ v.show
30
+ assert_equal false, v.hidden
31
+ v.hide
32
+ assert_equal false, v.hidden
33
+ v.hide
34
+ assert_equal true, v.hidden
35
+ end
36
+
37
+ def test_add_child ()
38
+ assert_raise(ArgumentError) {view.add_child}
39
+ assert_raise(ArgumentError) {view.add_child nil}
40
+ assert_raise(ArgumentError) {view.add_child 1}
41
+ assert_nothing_raised {view.add_child view}
42
+ end
43
+
44
+ def test_remove_child ()
45
+ assert_raise(ArgumentError) {view.remove_child}
46
+ assert_raise(ArgumentError) {view.remove_child nil}
47
+ assert_raise(ArgumentError) {view.remove_child 1}
48
+ assert_raise(Rucy::NativeError) {view.remove_child view}
49
+ v = view
50
+ v.add_child child = view
51
+ assert_nothing_raised {v.remove_child child}
52
+ end
53
+
54
+ def test_find_child ()
55
+ v = view
56
+ v.add_child child = view(:name => :Test)
57
+ assert_equal child, v.find_child(:Test)
58
+ end
59
+
60
+ def test_parent ()
61
+ parent, child = view, view
62
+ parent.add_child child
63
+ assert_nil parent.parent
64
+ assert_equal parent, child.parent
65
+ end
66
+
67
+ def test_name ()
68
+ v = view
69
+ assert_equal '', v.name
70
+ v.name = 'Test'
71
+ assert_equal 'Test', v.name
72
+ end
73
+
74
+ end# TestView
data/test/test_window.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
- $: << File.dirname(__FILE__)
3
- require 'helpers'
2
+
3
+
4
+ require_relative 'helpers'
4
5
 
5
6
 
6
7
  class TestWindow < Test::Unit::TestCase
@@ -36,4 +37,34 @@ class TestWindow < Test::Unit::TestCase
36
37
  assert_equal 'test title', @w.title
37
38
  end
38
39
 
40
+ def test_root ()
41
+ assert_not_nil @w.root
42
+ assert_nil @w.root.parent
43
+ assert_equal 'root', @w.root.name
44
+ end
45
+
46
+ def test_window ()
47
+ assert_equal @w, @w.root.window
48
+ end
49
+
50
+ def test_move ()
51
+ b = @w.bounds.to_a
52
+ @w.move_to 100, 100
53
+ assert_equal [100, 100], @w.bounds.pos.to_a
54
+ @w.move_by 5, 5
55
+ assert_equal [105, 105], @w.bounds.pos.to_a
56
+ @w.move_by -1, -1
57
+ assert_equal [104, 104], @w.bounds.pos.to_a
58
+ end
59
+
60
+ def test_resize ()
61
+ b = @w.bounds.to_a
62
+ @w.resize_to 200, 200
63
+ assert_equal [200, 200], @w.bounds.size.to_a
64
+ @w.resize_by 5, 5
65
+ assert_equal [205, 205], @w.bounds.size.to_a
66
+ @w.resize_by -1, -1
67
+ assert_equal [204, 204], @w.bounds.size.to_a
68
+ end
69
+
39
70
  end# TestWindow