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
@@ -4,22 +4,25 @@
4
4
  #define __REFLEX_APPLICATION_H__
5
5
 
6
6
 
7
+ #include <xot/ref.h>
8
+ #include <xot/pimpl.h>
7
9
  #include <reflex/defs.h>
8
- #include <reflex/helpers.h>
9
10
 
10
11
 
11
12
  namespace Reflex
12
13
  {
13
14
 
14
15
 
15
- class Application
16
+ class Application : public Xot::RefCountable<>
16
17
  {
17
18
 
19
+ typedef Application This;
20
+
18
21
  public:
19
22
 
20
- Application ();
23
+ typedef Xot::Ref<This> Ref;
21
24
 
22
- virtual ~Application ();
25
+ Application ();
23
26
 
24
27
  virtual bool run ();
25
28
 
@@ -29,9 +32,9 @@ namespace Reflex
29
32
 
30
33
  virtual bool about ();
31
34
 
32
- virtual bool get_name (String* name) const;
35
+ virtual bool set_name (const char* name);
33
36
 
34
- virtual bool set_name (const char* name);
37
+ virtual const char* name () const;
35
38
 
36
39
  operator bool () const;
37
40
 
@@ -39,7 +42,11 @@ namespace Reflex
39
42
 
40
43
  struct Data;
41
44
 
42
- Impl<Data> self;
45
+ Xot::PImpl<Data, true> self;
46
+
47
+ protected:
48
+
49
+ virtual ~Application ();
43
50
 
44
51
  };// Application
45
52
 
@@ -4,20 +4,22 @@
4
4
  #define __REFLEX_DEFS_H__
5
5
 
6
6
 
7
- #include <xot/defs.h>
8
- #include <xot/string.h>
7
+ #include <rays/defs.h>
9
8
 
10
9
 
11
- namespace Reflex
10
+ namespace Rucy
12
11
  {
13
12
 
13
+ class Value;
14
+
15
+ }// Rucy
14
16
 
15
- using namespace Xot::Types;
16
17
 
17
- using Xot::String;
18
+ namespace Reflex
19
+ {
18
20
 
19
21
 
20
- typedef float coord;
22
+ using namespace Rays;
21
23
 
22
24
 
23
25
  enum KeyCodes
@@ -32,7 +32,7 @@ namespace Reflex
32
32
  };// ReflexException
33
33
 
34
34
 
35
- void error (const char* format = NULL, ...);
35
+ void reflex_error (const char* format = NULL, ...);
36
36
 
37
37
 
38
38
  }// Reflex
@@ -6,6 +6,7 @@
6
6
 
7
7
  #include <rucy/rucy.h>
8
8
  #include <rucy/class.h>
9
+ #include <rucy/extension.h>
9
10
  #include <reflex/application.h>
10
11
 
11
12
 
@@ -17,23 +18,43 @@ namespace Reflex
17
18
  // class Reflex::Application
18
19
 
19
20
 
20
- }// Reflex
21
+ template <typename T>
22
+ class RubyApplication : public Rucy::ClassWrapper<T>
23
+ {
21
24
 
25
+ public:
22
26
 
23
- namespace Rucy
24
- {
27
+ virtual bool run ()
28
+ {
29
+ SYM(run);
30
+ return this->value.call(run);
31
+ }
25
32
 
33
+ virtual bool quit ()
34
+ {
35
+ SYM(quit);
36
+ return this->value.call(quit);
37
+ }
26
38
 
27
- Value value (const Reflex::Application& application);
39
+ virtual bool preference ()
40
+ {
41
+ SYM(preference);
42
+ return this->value.call(preference);
43
+ }
28
44
 
29
- template <> inline Reflex::Application*
30
- value_to<Reflex::Application*> (Value obj, bool convert)
31
- {
32
- return get_type<Reflex::Application>(obj, Reflex::application_class());
33
- }
45
+ virtual bool about ()
46
+ {
47
+ SYM(about);
48
+ return this->value.call(about);
49
+ }
50
+
51
+ };// RubyApplication
52
+
53
+
54
+ }// Reflex
34
55
 
35
56
 
36
- }// Rucy
57
+ RUCY_WRAPPER_VALUE_FROM_TO(Reflex::Application, Reflex::application_class())
37
58
 
38
59
 
39
60
  #endif//EOH
@@ -24,12 +24,12 @@ namespace Rucy
24
24
  {
25
25
 
26
26
 
27
- Value value (const Reflex::Key& key);
27
+ Value value (const Reflex::Key& obj);
28
28
 
29
29
  template <> inline Reflex::Key*
30
- value_to<Reflex::Key*> (Value obj, bool convert)
30
+ value_to<Reflex::Key*> (Value val, bool)
31
31
  {
32
- return get_type<Reflex::Key>(obj, Reflex::key_class());
32
+ return get_type_ptr<Reflex::Key>(val, Reflex::key_class());
33
33
  }
34
34
 
35
35
 
@@ -24,12 +24,12 @@ namespace Rucy
24
24
  {
25
25
 
26
26
 
27
- Value value (const Reflex::Points& points);
27
+ Value value (const Reflex::Points& obj);
28
28
 
29
29
  template <> inline Reflex::Points*
30
- value_to<Reflex::Points*> (Value obj, bool convert)
30
+ value_to<Reflex::Points*> (Value val, bool)
31
31
  {
32
- return get_type<Reflex::Points>(obj, Reflex::points_class());
32
+ return get_type_ptr<Reflex::Points>(val, Reflex::points_class());
33
33
  }
34
34
 
35
35
 
@@ -0,0 +1,106 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_RUBY_VIEW_H__
4
+ #define __REFLEX_RUBY_VIEW_H__
5
+
6
+
7
+ #include <rucy/rucy.h>
8
+ #include <rucy/class.h>
9
+ #include <rucy/extension.h>
10
+ #include <rays/ruby/bounds.h>
11
+ #include <rays/ruby/painter.h>
12
+ #include <reflex/view.h>
13
+ #include <reflex/ruby/key.h>
14
+ #include <reflex/ruby/points.h>
15
+
16
+
17
+ namespace Reflex
18
+ {
19
+
20
+
21
+ Rucy::Class view_class ();
22
+ // class Reflex::View
23
+
24
+
25
+ template <typename T>
26
+ class RubyView : public Rucy::ClassWrapper<T>
27
+ {
28
+
29
+ public:
30
+
31
+ virtual bool show ()
32
+ {
33
+ SYM(show);
34
+ return this->value.call(show);
35
+ }
36
+
37
+ virtual bool hide ()
38
+ {
39
+ SYM(hide);
40
+ return this->value.call(hide);
41
+ }
42
+
43
+ virtual void update (float dt)
44
+ {
45
+ SYM(update);
46
+ this->value.call(update, dt);
47
+ }
48
+
49
+ virtual void draw (Painter* p, const Bounds& b)
50
+ {
51
+ SYM(draw);
52
+ this->value.call(draw, Rucy::value(p), Rucy::value(b));
53
+ }
54
+
55
+ virtual void moved (coord dx, coord dy)
56
+ {
57
+ SYM(moved);
58
+ this->value.call(moved, dx, dy);
59
+ }
60
+
61
+ virtual void resized (coord dwidth, coord dheight)
62
+ {
63
+ SYM(resized);
64
+ this->value.call(resized, dwidth, dheight);
65
+ }
66
+
67
+ virtual void key_down (const Key& key)
68
+ {
69
+ SYM(key_down);
70
+ this->value.call(key_down, Rucy::value(key));
71
+ }
72
+
73
+ virtual void key_up (const Key& key)
74
+ {
75
+ SYM(key_up);
76
+ this->value.call(key_up, Rucy::value(key));
77
+ }
78
+
79
+ virtual void points_down (const Points& points)
80
+ {
81
+ SYM(points_down);
82
+ this->value.call(points_down, Rucy::value(points));
83
+ }
84
+
85
+ virtual void points_up (const Points& points)
86
+ {
87
+ SYM(points_up);
88
+ this->value.call(points_up, Rucy::value(points));
89
+ }
90
+
91
+ virtual void points_moved (const Points& points)
92
+ {
93
+ SYM(points_moved);
94
+ this->value.call(points_moved, Rucy::value(points));
95
+ }
96
+
97
+ };// RubyView
98
+
99
+
100
+ }// Reflex
101
+
102
+
103
+ RUCY_WRAPPER_VALUE_FROM_TO(Reflex::View, Reflex::view_class())
104
+
105
+
106
+ #endif//EOH
@@ -6,7 +6,10 @@
6
6
 
7
7
  #include <rucy/rucy.h>
8
8
  #include <rucy/class.h>
9
+ #include <rucy/extension.h>
9
10
  #include <reflex/window.h>
11
+ #include <reflex/ruby/key.h>
12
+ #include <reflex/ruby/points.h>
10
13
 
11
14
 
12
15
  namespace Reflex
@@ -17,23 +20,91 @@ namespace Reflex
17
20
  // class Reflex::Window
18
21
 
19
22
 
20
- }// Reflex
21
-
22
-
23
- namespace Rucy
24
- {
23
+ template <typename T>
24
+ class RubyWindow : public Rucy::ClassWrapper<T>
25
+ {
25
26
 
27
+ public:
28
+
29
+ virtual bool show ()
30
+ {
31
+ SYM(show);
32
+ return this->value.call(show);
33
+ }
34
+
35
+ virtual bool hide ()
36
+ {
37
+ SYM(hide);
38
+ return this->value.call(hide);
39
+ }
40
+
41
+ virtual bool close ()
42
+ {
43
+ SYM(close);
44
+ return this->value.call(close);
45
+ }
46
+
47
+ virtual void update (float dt)
48
+ {
49
+ SYM(update);
50
+ this->value.call(update, dt);
51
+ }
52
+
53
+ virtual void draw ()
54
+ {
55
+ SYM(draw);
56
+ this->value.call(draw);
57
+ }
58
+
59
+ virtual void moved (coord x, coord y)
60
+ {
61
+ SYM(moved);
62
+ this->value.call(moved, x, y);
63
+ }
64
+
65
+ virtual void resized (coord width, coord height)
66
+ {
67
+ SYM(resized);
68
+ this->value.call(resized, width, height);
69
+ }
70
+
71
+ virtual void key_down (const Key& key)
72
+ {
73
+ SYM(key_down);
74
+ this->value.call(key_down, Rucy::value(key));
75
+ }
76
+
77
+ virtual void key_up (const Key& key)
78
+ {
79
+ SYM(key_up);
80
+ this->value.call(key_up, Rucy::value(key));
81
+ }
82
+
83
+ virtual void points_down (const Points& points)
84
+ {
85
+ SYM(points_down);
86
+ this->value.call(points_down, Rucy::value(points));
87
+ }
88
+
89
+ virtual void points_up (const Points& points)
90
+ {
91
+ SYM(points_up);
92
+ this->value.call(points_up, Rucy::value(points));
93
+ }
94
+
95
+ virtual void points_moved (const Points& points)
96
+ {
97
+ SYM(points_moved);
98
+ this->value.call(points_moved, Rucy::value(points));
99
+ }
100
+
101
+ };// RubyWindow
26
102
 
27
- Value value (const Reflex::Window& window);
28
103
 
29
- template <> inline Reflex::Window*
30
- value_to<Reflex::Window*> (Value obj, bool convert)
31
- {
32
- return get_type<Reflex::Window>(obj, Reflex::window_class());
33
- }
104
+ }// Reflex
34
105
 
35
106
 
36
- }// Rucy
107
+ RUCY_WRAPPER_VALUE_FROM_TO(Reflex::Window, Reflex::window_class())
37
108
 
38
109
 
39
110
  #endif//EOH
@@ -5,10 +5,11 @@
5
5
 
6
6
 
7
7
  #include <reflex/ruby/reflex.h>
8
- #include <reflex/ruby/application.h>
9
- #include <reflex/ruby/window.h>
10
8
  #include <reflex/ruby/key.h>
11
9
  #include <reflex/ruby/points.h>
10
+ #include <reflex/ruby/application.h>
11
+ #include <reflex/ruby/window.h>
12
+ #include <reflex/ruby/view.h>
12
13
 
13
14
 
14
15
  #endif//EOH
@@ -0,0 +1,103 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __REFLEX_VIEW_H__
4
+ #define __REFLEX_VIEW_H__
5
+
6
+
7
+ #include <vector>
8
+ #include <xot/ref.h>
9
+ #include <xot/pimpl.h>
10
+ #include <reflex/defs.h>
11
+
12
+
13
+ namespace Rays
14
+ {
15
+
16
+ struct Bounds;
17
+
18
+ class Painter;
19
+
20
+ };// Rays
21
+
22
+
23
+ namespace Reflex
24
+ {
25
+
26
+
27
+ class Window;
28
+
29
+
30
+ class View : public Xot::RefCountable<>
31
+ {
32
+
33
+ typedef View This;
34
+
35
+ public:
36
+
37
+ typedef Xot::Ref<This> Ref;
38
+
39
+ View ();
40
+
41
+ virtual bool show ();
42
+
43
+ virtual bool hide ();
44
+
45
+ virtual bool redraw ();
46
+
47
+ virtual bool add_child (View* child);
48
+
49
+ virtual bool remove_child (View* child);
50
+
51
+ virtual View* find_child (
52
+ const char* name, size_t index = 0, bool recursive = false);
53
+
54
+ virtual const View* find_child (
55
+ const char* name, size_t index = 0, bool recursive = false) const;
56
+
57
+ virtual bool set_name (const char* name);
58
+
59
+ virtual const char* name () const;
60
+
61
+ virtual bool set_bounds (coord x, coord y, coord width, coord height);
62
+
63
+ virtual bool set_bounds (const Bounds& bounds);
64
+
65
+ virtual const Bounds& bounds () const;
66
+
67
+ virtual bool hidden () const;
68
+
69
+ virtual View* parent ();
70
+
71
+ virtual const View* parent () const;
72
+
73
+ virtual Window* window ();
74
+
75
+ virtual const Window* window () const;
76
+
77
+ virtual void update (float dt);
78
+
79
+ virtual void draw (Painter* p, const Bounds& b);
80
+
81
+ virtual void moved (coord dx, coord dy);
82
+
83
+ virtual void resized (coord dwidth, coord dheight);
84
+
85
+ virtual operator bool () const;
86
+
87
+ virtual bool operator ! () const;
88
+
89
+ struct Data;
90
+
91
+ Xot::PImpl<Data> self;
92
+
93
+ protected:
94
+
95
+ virtual ~View ();
96
+
97
+ };// View
98
+
99
+
100
+ }// Reflex
101
+
102
+
103
+ #endif//EOH
@@ -4,47 +4,68 @@
4
4
  #define __REFLEX_WINDOW_H__
5
5
 
6
6
 
7
+ #include <xot/ref.h>
8
+ #include <xot/pimpl.h>
7
9
  #include <reflex/defs.h>
8
- #include <reflex/helpers.h>
10
+
11
+
12
+ namespace Rays
13
+ {
14
+
15
+ class Bounds;
16
+
17
+ class Painter;
18
+
19
+ }// Rays
9
20
 
10
21
 
11
22
  namespace Reflex
12
23
  {
13
24
 
14
25
 
15
- class Window
26
+ class View;
27
+
28
+
29
+ class Window : public Xot::RefCountable<>
16
30
  {
17
31
 
18
- public:
32
+ typedef Window This;
19
33
 
20
- Window ();
34
+ public:
21
35
 
22
- virtual ~Window ();
36
+ typedef Xot::Ref<This> Ref;
23
37
 
24
- virtual bool close ();
38
+ Window ();
25
39
 
26
40
  virtual bool show ();
27
41
 
28
42
  virtual bool hide ();
29
43
 
30
- virtual bool hidden () const;
44
+ virtual bool close ();
31
45
 
32
46
  virtual bool redraw ();
33
47
 
34
- virtual bool get_title (String* title) const;
48
+ virtual bool set_title (const char* title);
49
+
50
+ virtual const char* title () const;
35
51
 
36
- virtual bool set_title (const char* title);
52
+ virtual bool set_bounds (coord x, coord y, coord width, coord height);
37
53
 
38
- virtual bool get_bounds (
39
- coord* x,
40
- coord* y = NULL,
41
- coord* width = NULL,
42
- coord* height = NULL);
54
+ virtual bool set_bounds (const Bounds& bounds);
55
+
56
+ virtual Bounds bounds () const;
57
+
58
+ virtual bool hidden () const;
43
59
 
44
- virtual bool set_bounds (
45
- coord x, coord y, coord width, coord height);
60
+ virtual View* root ();
46
61
 
47
- virtual void update ();
62
+ virtual const View* root () const;
63
+
64
+ virtual Painter* painter ();
65
+
66
+ virtual const Painter* painter () const;
67
+
68
+ virtual void update (float dt);
48
69
 
49
70
  virtual void draw ();
50
71
 
@@ -68,7 +89,11 @@ namespace Reflex
68
89
 
69
90
  struct Data;
70
91
 
71
- Impl<Data> self;
92
+ Xot::PImpl<Data, true> self;
93
+
94
+ protected:
95
+
96
+ virtual ~Window ();
72
97
 
73
98
  };// Window
74
99
 
data/include/reflex.h CHANGED
@@ -7,8 +7,9 @@
7
7
  #include <reflex/defs.h>
8
8
  #include <reflex/reflex.h>
9
9
  #include <reflex/exception.h>
10
+ #include <reflex/application.h>
10
11
  #include <reflex/window.h>
11
- #include <reflex/helpers.h>
12
+ #include <reflex/view.h>
12
13
 
13
14
 
14
15
  #endif//EOH
@@ -1,8 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- require 'reflex/native'
5
- require 'reflex/helpers'
4
+ require 'xot/hookable'
5
+ require 'xot/setter'
6
+ require 'reflex/ext'
6
7
 
7
8
 
8
9
  module Reflex
@@ -10,13 +11,13 @@ module Reflex
10
11
 
11
12
  class Application
12
13
 
13
- include Hookable
14
- include Setter
14
+ include Xot::Hookable
15
+ include Xot::Setter
15
16
 
16
- def initialize (opts = {}, &block)
17
- super
17
+ def initialize (opts = {})
18
+ super()
18
19
  opts.each {|key, value| set key.intern, *value}
19
- instance_eval &block if block
20
+ yield self if block_given?
20
21
  end
21
22
 
22
23
  end# Application
@@ -1,8 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- require 'reflex/native'
5
4
  require 'rays/autoinit'
5
+ require 'reflex/ext'
6
6
 
7
7
 
8
8
  unless $REFLEX_NOAUTOINIT
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/bitmap'
5
+
6
+
7
+ module Reflex
8
+
9
+
10
+ Bitmap = Rays::Bitmap
11
+
12
+
13
+ end# Reflex