reflexion 0.1.1
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/ChangeLog +8 -0
- data/README +4 -0
- data/Rakefile +70 -0
- data/VERSION +1 -0
- data/examples/hello/Rakefile +41 -0
- data/examples/hello/main.cpp +18 -0
- data/examples/ruby/app.rb +13 -0
- data/examples/ruby/checker.rb +41 -0
- data/examples/ruby/fps.rb +49 -0
- data/examples/ruby/hello.rb +38 -0
- data/examples/ruby/key.rb +44 -0
- data/examples/ruby/shapes.rb +124 -0
- data/examples/ruby/text.rb +35 -0
- data/ext/reflex/application.cpp +151 -0
- data/ext/reflex/extconf.rb +57 -0
- data/ext/reflex/key.cpp +128 -0
- data/ext/reflex/native.cpp +22 -0
- data/ext/reflex/points.cpp +160 -0
- data/ext/reflex/reflex.cpp +83 -0
- data/ext/reflex/reflex.h +39 -0
- data/ext/reflex/window.cpp +357 -0
- data/include/reflex/application.h +50 -0
- data/include/reflex/defs.h +258 -0
- data/include/reflex/helpers.h +32 -0
- data/include/reflex/reflex.h +26 -0
- data/include/reflex/ruby/application.h +39 -0
- data/include/reflex/ruby/key.h +39 -0
- data/include/reflex/ruby/points.h +39 -0
- data/include/reflex/ruby/reflex.h +21 -0
- data/include/reflex/ruby/window.h +39 -0
- data/include/reflex/ruby.h +14 -0
- data/include/reflex/window.h +79 -0
- data/include/reflex.h +13 -0
- data/lib/reflex/application.rb +25 -0
- data/lib/reflex/autoinit.rb +11 -0
- data/lib/reflex/bounds.rb +133 -0
- data/lib/reflex/helpers.rb +52 -0
- data/lib/reflex/module.rb +30 -0
- data/lib/reflex/point.rb +69 -0
- data/lib/reflex/reflex.rb +21 -0
- data/lib/reflex/window.rb +65 -0
- data/lib/reflex.rb +11 -0
- data/reflex.gemspec +57 -0
- data/src/cocoa/application.mm +90 -0
- data/src/cocoa/applicationdata.h +51 -0
- data/src/cocoa/cocoaapplication.h +19 -0
- data/src/cocoa/cocoaapplication.mm +180 -0
- data/src/cocoa/cocoawindow.h +44 -0
- data/src/cocoa/cocoawindow.mm +171 -0
- data/src/cocoa/defs.h +34 -0
- data/src/cocoa/defs.mm +84 -0
- data/src/cocoa/openglview.h +17 -0
- data/src/cocoa/openglview.mm +186 -0
- data/src/cocoa/reflex.mm +68 -0
- data/src/cocoa/window.mm +118 -0
- data/src/cocoa/windowdata.h +51 -0
- data/src/defs.cpp +47 -0
- data/src/win32/defs.cpp +150 -0
- data/src/win32/opengl.cpp +95 -0
- data/src/win32/opengl.h +50 -0
- data/src/win32/reflex.cpp +65 -0
- data/src/win32/window.cpp +480 -0
- data/src/window.cpp +60 -0
- data/support.rb +56 -0
- data/task/ext.rake +42 -0
- data/task/gem.rake +33 -0
- data/task/git.rake +22 -0
- data/task/lib.rake +54 -0
- data/test/helpers.rb +15 -0
- data/test/test_bounds.rb +163 -0
- data/test/test_point.rb +81 -0
- data/test/test_reflex.rb +17 -0
- data/test/test_window.rb +39 -0
- metadata +173 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __REFLEX_RUBY_APPLICATION_H__
|
4
|
+
#define __REFLEX_RUBY_APPLICATION_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <rucy/rucy.h>
|
8
|
+
#include <rucy/class.h>
|
9
|
+
#include <reflex/application.h>
|
10
|
+
|
11
|
+
|
12
|
+
namespace Reflex
|
13
|
+
{
|
14
|
+
|
15
|
+
|
16
|
+
Rucy::Class application_class ();
|
17
|
+
// class Reflex::Application
|
18
|
+
|
19
|
+
|
20
|
+
}// Reflex
|
21
|
+
|
22
|
+
|
23
|
+
namespace Rucy
|
24
|
+
{
|
25
|
+
|
26
|
+
|
27
|
+
Value value (const Reflex::Application& application);
|
28
|
+
|
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
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
}// Rucy
|
37
|
+
|
38
|
+
|
39
|
+
#endif//EOH
|
@@ -0,0 +1,39 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __REFLEX_RUBY_KEY_H__
|
4
|
+
#define __REFLEX_RUBY_KEY_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <rucy/rucy.h>
|
8
|
+
#include <rucy/class.h>
|
9
|
+
#include <reflex/defs.h>
|
10
|
+
|
11
|
+
|
12
|
+
namespace Reflex
|
13
|
+
{
|
14
|
+
|
15
|
+
|
16
|
+
Rucy::Class key_class ();
|
17
|
+
// class Reflex::Key
|
18
|
+
|
19
|
+
|
20
|
+
}// Reflex
|
21
|
+
|
22
|
+
|
23
|
+
namespace Rucy
|
24
|
+
{
|
25
|
+
|
26
|
+
|
27
|
+
Value value (const Reflex::Key& key);
|
28
|
+
|
29
|
+
template <> inline Reflex::Key*
|
30
|
+
value_to<Reflex::Key*> (Value obj, bool convert)
|
31
|
+
{
|
32
|
+
return get_type<Reflex::Key>(obj, Reflex::key_class());
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
}// Rucy
|
37
|
+
|
38
|
+
|
39
|
+
#endif//EOH
|
@@ -0,0 +1,39 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __REFLEX_RUBY_POINTS_H__
|
4
|
+
#define __REFLEX_RUBY_POINTS_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <rucy/rucy.h>
|
8
|
+
#include <rucy/class.h>
|
9
|
+
#include <reflex/defs.h>
|
10
|
+
|
11
|
+
|
12
|
+
namespace Reflex
|
13
|
+
{
|
14
|
+
|
15
|
+
|
16
|
+
Rucy::Class points_class ();
|
17
|
+
// class Reflex::Points
|
18
|
+
|
19
|
+
|
20
|
+
}// Reflex
|
21
|
+
|
22
|
+
|
23
|
+
namespace Rucy
|
24
|
+
{
|
25
|
+
|
26
|
+
|
27
|
+
Value value (const Reflex::Points& points);
|
28
|
+
|
29
|
+
template <> inline Reflex::Points*
|
30
|
+
value_to<Reflex::Points*> (Value obj, bool convert)
|
31
|
+
{
|
32
|
+
return get_type<Reflex::Points>(obj, Reflex::points_class());
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
}// Rucy
|
37
|
+
|
38
|
+
|
39
|
+
#endif//EOH
|
@@ -0,0 +1,21 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __REFLEX_RUBY_REFLEX_H__
|
4
|
+
#define __REFLEX_RUBY_REFLEX_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <rucy/module.h>
|
8
|
+
|
9
|
+
|
10
|
+
namespace Reflex
|
11
|
+
{
|
12
|
+
|
13
|
+
|
14
|
+
Rucy::Module reflex_module ();
|
15
|
+
// module Reflex
|
16
|
+
|
17
|
+
|
18
|
+
}// Reflex
|
19
|
+
|
20
|
+
|
21
|
+
#endif//EOH
|
@@ -0,0 +1,39 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __REFLEX_RUBY_WINDOW_H__
|
4
|
+
#define __REFLEX_RUBY_WINDOW_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <rucy/rucy.h>
|
8
|
+
#include <rucy/class.h>
|
9
|
+
#include <reflex/window.h>
|
10
|
+
|
11
|
+
|
12
|
+
namespace Reflex
|
13
|
+
{
|
14
|
+
|
15
|
+
|
16
|
+
Rucy::Class window_class ();
|
17
|
+
// class Reflex::Window
|
18
|
+
|
19
|
+
|
20
|
+
}// Reflex
|
21
|
+
|
22
|
+
|
23
|
+
namespace Rucy
|
24
|
+
{
|
25
|
+
|
26
|
+
|
27
|
+
Value value (const Reflex::Window& window);
|
28
|
+
|
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
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
}// Rucy
|
37
|
+
|
38
|
+
|
39
|
+
#endif//EOH
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __REFLEX_RUBY_H__
|
4
|
+
#define __REFLEX_RUBY_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <reflex/ruby/reflex.h>
|
8
|
+
#include <reflex/ruby/application.h>
|
9
|
+
#include <reflex/ruby/window.h>
|
10
|
+
#include <reflex/ruby/key.h>
|
11
|
+
#include <reflex/ruby/points.h>
|
12
|
+
|
13
|
+
|
14
|
+
#endif//EOH
|
@@ -0,0 +1,79 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __REFLEX_WINDOW_H__
|
4
|
+
#define __REFLEX_WINDOW_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <reflex/defs.h>
|
8
|
+
#include <reflex/helpers.h>
|
9
|
+
|
10
|
+
|
11
|
+
namespace Reflex
|
12
|
+
{
|
13
|
+
|
14
|
+
|
15
|
+
class Window
|
16
|
+
{
|
17
|
+
|
18
|
+
public:
|
19
|
+
|
20
|
+
Window ();
|
21
|
+
|
22
|
+
virtual ~Window ();
|
23
|
+
|
24
|
+
virtual bool close ();
|
25
|
+
|
26
|
+
virtual bool show ();
|
27
|
+
|
28
|
+
virtual bool hide ();
|
29
|
+
|
30
|
+
virtual bool hidden () const;
|
31
|
+
|
32
|
+
virtual bool redraw ();
|
33
|
+
|
34
|
+
virtual bool get_title (String* title) const;
|
35
|
+
|
36
|
+
virtual bool set_title (const char* title);
|
37
|
+
|
38
|
+
virtual bool get_bounds (
|
39
|
+
coord* x,
|
40
|
+
coord* y = NULL,
|
41
|
+
coord* width = NULL,
|
42
|
+
coord* height = NULL);
|
43
|
+
|
44
|
+
virtual bool set_bounds (
|
45
|
+
coord x, coord y, coord width, coord height);
|
46
|
+
|
47
|
+
virtual void update ();
|
48
|
+
|
49
|
+
virtual void draw ();
|
50
|
+
|
51
|
+
virtual void moved (coord x, coord y);
|
52
|
+
|
53
|
+
virtual void resized (coord width, coord height);
|
54
|
+
|
55
|
+
virtual void key_down (const Key& key);
|
56
|
+
|
57
|
+
virtual void key_up (const Key& key);
|
58
|
+
|
59
|
+
virtual void points_down (const Points& points);
|
60
|
+
|
61
|
+
virtual void points_up (const Points& points);
|
62
|
+
|
63
|
+
virtual void points_moved (const Points& points);
|
64
|
+
|
65
|
+
operator bool () const;
|
66
|
+
|
67
|
+
bool operator ! () const;
|
68
|
+
|
69
|
+
struct Data;
|
70
|
+
|
71
|
+
Impl<Data> self;
|
72
|
+
|
73
|
+
};// Window
|
74
|
+
|
75
|
+
|
76
|
+
}// Reflex
|
77
|
+
|
78
|
+
|
79
|
+
#endif//EOH
|
data/include/reflex.h
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require 'reflex/native'
|
5
|
+
require 'reflex/helpers'
|
6
|
+
|
7
|
+
|
8
|
+
module Reflex
|
9
|
+
|
10
|
+
|
11
|
+
class Application
|
12
|
+
|
13
|
+
include Hookable
|
14
|
+
include Setter
|
15
|
+
|
16
|
+
def initialize (opts = {}, &block)
|
17
|
+
super
|
18
|
+
opts.each {|key, value| set key.intern, *value}
|
19
|
+
instance_eval &block if block
|
20
|
+
end
|
21
|
+
|
22
|
+
end# Application
|
23
|
+
|
24
|
+
|
25
|
+
end# Reflex
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require 'reflex/point'
|
5
|
+
|
6
|
+
|
7
|
+
module Reflex
|
8
|
+
|
9
|
+
|
10
|
+
class Bounds
|
11
|
+
|
12
|
+
include Comparable
|
13
|
+
|
14
|
+
attr_accessor :x, :y, :width, :height
|
15
|
+
|
16
|
+
def initialize (*args)
|
17
|
+
case args.size
|
18
|
+
when 0 then @x = @y = @width = @height = 0
|
19
|
+
when 1 then @x = @y = 0; @width = @height = args[0]
|
20
|
+
when 2 then @x = @y = 0; @width, @height = args
|
21
|
+
when 4 then @x, @y, @width, @height = args
|
22
|
+
else raise ArgumentError
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def right ()
|
27
|
+
@x + @width - 1
|
28
|
+
end
|
29
|
+
|
30
|
+
def right= (right)
|
31
|
+
@width = right + 1 - @x
|
32
|
+
end
|
33
|
+
|
34
|
+
def bottom ()
|
35
|
+
@y + @height - 1
|
36
|
+
end
|
37
|
+
|
38
|
+
def bottom= (bottom)
|
39
|
+
@height = bottom + 1 - @y
|
40
|
+
end
|
41
|
+
|
42
|
+
alias w width
|
43
|
+
alias w= width=
|
44
|
+
|
45
|
+
alias h height
|
46
|
+
alias h= height=
|
47
|
+
|
48
|
+
alias left x
|
49
|
+
alias left= x=
|
50
|
+
|
51
|
+
alias top y
|
52
|
+
alias top= y=
|
53
|
+
|
54
|
+
alias l left
|
55
|
+
alias l= left=
|
56
|
+
|
57
|
+
alias t top
|
58
|
+
alias t= top=
|
59
|
+
|
60
|
+
alias r right
|
61
|
+
alias r= right=
|
62
|
+
|
63
|
+
alias b bottom
|
64
|
+
alias b= bottom=
|
65
|
+
|
66
|
+
def offset_to! (*args)
|
67
|
+
@x, @y = case args.size
|
68
|
+
when 1 then args * 2
|
69
|
+
when 2 then args
|
70
|
+
else raise ArgumentError
|
71
|
+
end
|
72
|
+
self
|
73
|
+
end
|
74
|
+
|
75
|
+
def offset_to (*args)
|
76
|
+
dup.offset_to! *args
|
77
|
+
end
|
78
|
+
|
79
|
+
def offset_by! (*args)
|
80
|
+
dx, dy = case args.size
|
81
|
+
when 1 then args * 2
|
82
|
+
when 2 then args
|
83
|
+
else raise ArgumentError
|
84
|
+
end
|
85
|
+
@x += dx
|
86
|
+
@y += dy
|
87
|
+
self
|
88
|
+
end
|
89
|
+
|
90
|
+
def offset_by (*args)
|
91
|
+
dup.offset_by! *args
|
92
|
+
end
|
93
|
+
|
94
|
+
def inset_by! (*args)
|
95
|
+
dx, dy = case args.size
|
96
|
+
when 1 then args * 2
|
97
|
+
when 2 then args
|
98
|
+
else raise ArgumentError
|
99
|
+
end
|
100
|
+
@x += dx
|
101
|
+
@y += dy
|
102
|
+
@width -= dx * 2
|
103
|
+
@height -= dy * 2
|
104
|
+
self
|
105
|
+
end
|
106
|
+
|
107
|
+
def inset_by (*args)
|
108
|
+
dup.inset_by! *args
|
109
|
+
end
|
110
|
+
|
111
|
+
def to_a ()
|
112
|
+
[@x, @y, @width, @height]
|
113
|
+
end
|
114
|
+
|
115
|
+
def [] (index)
|
116
|
+
case index
|
117
|
+
when 0 then Point.new(left, top)
|
118
|
+
when 1 then Point.new(right, bottom)
|
119
|
+
else raise IndexError
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def <=> (o)
|
124
|
+
ret = @x <=> o.x; return ret if ret != 0
|
125
|
+
ret = @y <=> o.y; return ret if ret != 0
|
126
|
+
ret = right <=> o.right; return ret if ret != 0
|
127
|
+
bottom <=> o.bottom
|
128
|
+
end
|
129
|
+
|
130
|
+
end# Bounds
|
131
|
+
|
132
|
+
|
133
|
+
end# Reflex
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
module Reflex
|
5
|
+
|
6
|
+
|
7
|
+
module Hookable
|
8
|
+
|
9
|
+
def hook (name, &hookblock)
|
10
|
+
klass = class << self; self; end
|
11
|
+
original = klass.instance_method(name).bind self
|
12
|
+
obj = self
|
13
|
+
klass.__send__ :define_method, name do |*args, &methodblock|
|
14
|
+
hookblock.call self, original, *args, &methodblock
|
15
|
+
end
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def before (name, &beforeblock)
|
20
|
+
hook name do |obj, org, *args, &methodblock|
|
21
|
+
beforeblock.call(obj, *args, &methodblock)
|
22
|
+
org.call(*args, &methodblock)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def after (name, &afterblock)
|
27
|
+
hook name do |obj, org, *args, &methodblock|
|
28
|
+
ret = org.call(*args, &methodblock)
|
29
|
+
afterblock.call(obj, *args, &methodblock)
|
30
|
+
ret
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def on (name, &onblock)
|
35
|
+
hook name do |obj, org, *args, &methodblock|
|
36
|
+
onblock.call(obj, *args, &methodblock)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end# Hookable
|
41
|
+
|
42
|
+
|
43
|
+
module Setter
|
44
|
+
|
45
|
+
def set (name, *value)
|
46
|
+
__send__ name.to_s + '=', *value
|
47
|
+
end
|
48
|
+
|
49
|
+
end# Setter
|
50
|
+
|
51
|
+
|
52
|
+
end# Helpers
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
module Reflex
|
5
|
+
|
6
|
+
|
7
|
+
extend module ClassMethods
|
8
|
+
|
9
|
+
def root_dir ()
|
10
|
+
File.expand_path(File.join File.dirname(__FILE__), '..', '..')
|
11
|
+
end
|
12
|
+
|
13
|
+
def include_dirs ()
|
14
|
+
[File.join(root_dir, 'include')]
|
15
|
+
end
|
16
|
+
|
17
|
+
def library_dirs ()
|
18
|
+
[File.join(root_dir, 'lib')]
|
19
|
+
end
|
20
|
+
|
21
|
+
def version ()
|
22
|
+
open(File.join root_dir, 'VERSION') {|f| f.readline.chomp}
|
23
|
+
end
|
24
|
+
|
25
|
+
self
|
26
|
+
|
27
|
+
end# ClassMethods
|
28
|
+
|
29
|
+
|
30
|
+
end# Reflex
|
data/lib/reflex/point.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
module Reflex
|
5
|
+
|
6
|
+
|
7
|
+
class Point
|
8
|
+
|
9
|
+
include Comparable
|
10
|
+
|
11
|
+
attr_accessor :x, :y
|
12
|
+
|
13
|
+
def initialize (*args)
|
14
|
+
case args.size
|
15
|
+
when 0 then @x = @y = 0
|
16
|
+
when 1 then @x = @y = args[0]
|
17
|
+
when 2 then @x, @y = args
|
18
|
+
else raise ArgumentError
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def offset_to! (*args)
|
23
|
+
case args.size
|
24
|
+
when 1 then @x = @y = args[0]
|
25
|
+
when 2 then @x, @y = args
|
26
|
+
else raise ArgumentError
|
27
|
+
end
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def offset_to (*args)
|
32
|
+
dup.offset_to! *args
|
33
|
+
end
|
34
|
+
|
35
|
+
def offset_by! (*args)
|
36
|
+
case args.size
|
37
|
+
when 1 then @x += args[0]; @y += args[0]
|
38
|
+
when 2 then @x += args[0]; @y += args[1]
|
39
|
+
else raise ArgumentError
|
40
|
+
end
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def offset_by (*args)
|
45
|
+
dup.offset_by! *args
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_a ()
|
49
|
+
[@x, @y]
|
50
|
+
end
|
51
|
+
|
52
|
+
def [] (index)
|
53
|
+
case index
|
54
|
+
when 0 then @x
|
55
|
+
when 1 then @y
|
56
|
+
else raise IndexError
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def <=> (o)
|
61
|
+
ret = @x <=> o.x
|
62
|
+
return ret if ret != 0
|
63
|
+
@y <=> o.y
|
64
|
+
end
|
65
|
+
|
66
|
+
end# Point
|
67
|
+
|
68
|
+
|
69
|
+
end# Reflex
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require 'reflex/native'
|
5
|
+
require 'reflex/bounds'
|
6
|
+
require 'reflex/helpers'
|
7
|
+
require 'rays/painter'
|
8
|
+
|
9
|
+
|
10
|
+
module Reflex
|
11
|
+
|
12
|
+
|
13
|
+
class Window
|
14
|
+
|
15
|
+
include Hookable
|
16
|
+
include Setter
|
17
|
+
|
18
|
+
attr_reader :painter
|
19
|
+
|
20
|
+
def initialize (opts = {}, &block)
|
21
|
+
@painter = Rays::Painter.new.canvas 0, 0, 1, 1
|
22
|
+
opts.each {|key, value| set key.intern, *value}
|
23
|
+
instance_eval &block if block
|
24
|
+
end
|
25
|
+
|
26
|
+
def paint ()
|
27
|
+
@painter.begin
|
28
|
+
yield @painter if block_given?
|
29
|
+
@painter.end
|
30
|
+
end
|
31
|
+
|
32
|
+
def bounds (*args)
|
33
|
+
b = Bounds.new *get_bounds
|
34
|
+
b.offset_to! *args unless args.empty?
|
35
|
+
b
|
36
|
+
end
|
37
|
+
|
38
|
+
def bounds= (*args)
|
39
|
+
case args[0]
|
40
|
+
when Bounds
|
41
|
+
set_bounds *args[0].to_a
|
42
|
+
when Point
|
43
|
+
set_bounds *args.map{|p| p.to_a}.flatten
|
44
|
+
when Array
|
45
|
+
set_bounds *args[0]
|
46
|
+
when Integer, Float
|
47
|
+
set_bounds *args
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def draw ()
|
52
|
+
paint
|
53
|
+
end
|
54
|
+
|
55
|
+
alias org_resized resized
|
56
|
+
|
57
|
+
def resized (width, height)
|
58
|
+
@painter.canvas 0, 0, width, height
|
59
|
+
org_resized width, height
|
60
|
+
end
|
61
|
+
|
62
|
+
end# Window
|
63
|
+
|
64
|
+
|
65
|
+
end# Reflex
|
data/lib/reflex.rb
ADDED