rubygoo 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +2 -0
- data/TODO +1 -4
- data/lib/rubygoo.rb +14 -13
- data/lib/rubygoo/adapters/adapter_factory.rb +12 -9
- data/lib/rubygoo/adapters/gosu_app_adapter.rb +510 -7
- data/lib/rubygoo/adapters/gosu_render_adapter.rb +52 -38
- data/lib/rubygoo/adapters/rubygame_app_adapter.rb +36 -29
- data/lib/rubygoo/adapters/rubygame_render_adapter.rb +39 -37
- data/lib/rubygoo/app.rb +77 -64
- data/lib/rubygoo/button.rb +43 -41
- data/lib/rubygoo/check_box.rb +58 -56
- data/lib/rubygoo/container.rb +106 -96
- data/lib/rubygoo/css_colors.rb +152 -150
- data/lib/rubygoo/dialog.rb +35 -36
- data/lib/rubygoo/goo_color.rb +14 -6
- data/lib/rubygoo/goo_event.rb +10 -8
- data/lib/rubygoo/label.rb +36 -34
- data/lib/rubygoo/mouse_cursor.rb +21 -0
- data/lib/rubygoo/rect.rb +602 -0
- data/lib/rubygoo/text_field.rb +244 -243
- data/lib/rubygoo/widget.rb +122 -114
- data/samples/gosu_app.rb +11 -4
- data/samples/rubygame_app.rb +2 -0
- data/themes/default/config.yml +8 -5
- metadata +4 -2
@@ -1,53 +1,67 @@
|
|
1
|
-
|
1
|
+
module Rubygoo
|
2
|
+
class GosuRenderAdapter
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
def initialize(window)
|
5
|
+
@window = window
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
def draw_box_filled(x1,y1,x2,y2,color)
|
9
|
+
c = convert_color(color)
|
10
|
+
@window.draw_quad x1, y1, c, x2, y1, c, x1, y2, c, x2, y2, c
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
def draw_box(x1,y1,x2,y2,color)
|
14
|
+
c = convert_color(color)
|
15
|
+
@window.draw_line x1, y1, c, x2, y1, c
|
16
|
+
@window.draw_line x2, y1, c, x2, y2, c
|
17
|
+
@window.draw_line x2, y2, c, x1, y2, c
|
18
|
+
@window.draw_line x1, y2, c, x1, y1, c
|
18
19
|
end
|
19
|
-
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
# fill in a rect with color or full screen if no color
|
22
|
+
def fill(color,rect=nil)
|
23
|
+
if rect.nil?
|
24
|
+
draw_box_filled 0, 0, @window.width, @window.height, color
|
25
|
+
else
|
26
|
+
draw_box_filled rect[0], rect[1], rect[2]+rect[0], rect[3]+rect[1], color
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# make static for now for migration ease of rendering fonts
|
31
|
+
def convert_color(goo_color)
|
32
|
+
Gosu::Color.new goo_color.a,goo_color.r,goo_color.g,goo_color.b
|
33
|
+
end
|
25
34
|
|
26
|
-
|
35
|
+
def start_drawing(); end
|
27
36
|
|
28
|
-
|
37
|
+
def finish_drawing(); end
|
29
38
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
39
|
+
def draw_image(img, x, y, color=nil)
|
40
|
+
# z is unused here
|
41
|
+
if color
|
42
|
+
img.draw x, y, 1,1,1,convert_color(color)
|
43
|
+
else
|
44
|
+
img.draw x, y, 1
|
45
|
+
end
|
46
|
+
end
|
34
47
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
48
|
+
def size_text(text, font_file, font_size)
|
49
|
+
@font_cache ||= {}
|
50
|
+
@font_cache[font_file] ||= {}
|
51
|
+
font = @font_cache[font_file][font_size] ||= Font.new(@window, font_file, font_size)
|
39
52
|
|
40
|
-
|
41
|
-
|
53
|
+
return [font.text_width(text),font.height]
|
54
|
+
end
|
42
55
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
56
|
+
def render_text(text, font_file, font_size, color)
|
57
|
+
@font_cache ||= {}
|
58
|
+
@font_cache[font_file] ||= {}
|
59
|
+
font = @font_cache[font_file][font_size] ||= Font.new(@window, font_file, font_size)
|
47
60
|
|
48
|
-
|
49
|
-
|
50
|
-
|
61
|
+
# TODO how do you set the color here?
|
62
|
+
text_image = Image.from_text(@window, text, font_file, font_size, 2, font.text_width(text).ceil+text.length*2, :left)
|
63
|
+
end
|
51
64
|
|
52
65
|
|
66
|
+
end
|
53
67
|
end
|
@@ -1,37 +1,44 @@
|
|
1
|
-
|
1
|
+
require 'rubygame'
|
2
|
+
include Rubygame
|
3
|
+
include Mouse
|
4
|
+
include Key
|
2
5
|
|
3
|
-
|
4
|
-
@app = app
|
5
|
-
end
|
6
|
+
module Rubygoo
|
6
7
|
|
7
|
-
|
8
|
-
@app.update time
|
9
|
-
end
|
8
|
+
class RubygameAppAdapter
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def initialize(app)
|
11
|
+
@app = app
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
case event
|
18
|
-
when KeyUpEvent
|
19
|
-
@app.on_event GooEvent.new(:key_released, {
|
20
|
-
:key => event.key, :mods => event.mods, :string => event.string})
|
21
|
-
when KeyDownEvent
|
22
|
-
@app.on_event GooEvent.new(:key_pressed, {
|
23
|
-
:key => event.key, :mods => event.mods, :string => event.string})
|
24
|
-
when MouseUpEvent
|
25
|
-
@app.on_event GooEvent.new(:mouse_up, {
|
26
|
-
:x => event.pos[0], :y => event.pos[1], :button => event.button})
|
27
|
-
when MouseDownEvent
|
28
|
-
@app.on_event GooEvent.new(:mouse_down, {
|
29
|
-
:x => event.pos[0], :y => event.pos[1], :button => event.button})
|
30
|
-
when MouseMotionEvent
|
31
|
-
@app.on_event GooEvent.new(:mouse_motion, {
|
32
|
-
:x => event.pos[0], :y => event.pos[1]})
|
14
|
+
def update(time)
|
15
|
+
@app.update time
|
33
16
|
end
|
34
|
-
end
|
35
17
|
|
18
|
+
def draw(target)
|
19
|
+
@app.draw target
|
20
|
+
end
|
21
|
+
|
22
|
+
# TODO convert keys?!?
|
23
|
+
def on_event(event)
|
24
|
+
case event
|
25
|
+
when KeyUpEvent
|
26
|
+
@app.on_event GooEvent.new(:key_released, {
|
27
|
+
:key => event.key, :mods => event.mods, :string => event.string})
|
28
|
+
when KeyDownEvent
|
29
|
+
@app.on_event GooEvent.new(:key_pressed, {
|
30
|
+
:key => event.key, :mods => event.mods, :string => event.string})
|
31
|
+
when MouseUpEvent
|
32
|
+
@app.on_event GooEvent.new(:mouse_up, {
|
33
|
+
:x => event.pos[0], :y => event.pos[1], :button => event.button})
|
34
|
+
when MouseDownEvent
|
35
|
+
@app.on_event GooEvent.new(:mouse_down, {
|
36
|
+
:x => event.pos[0], :y => event.pos[1], :button => event.button})
|
37
|
+
when MouseMotionEvent
|
38
|
+
@app.on_event GooEvent.new(:mouse_motion, {
|
39
|
+
:x => event.pos[0], :y => event.pos[1]})
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
36
43
|
|
37
44
|
end
|
@@ -1,51 +1,53 @@
|
|
1
|
-
|
1
|
+
module Rubygoo
|
2
|
+
class RubygameRenderAdapter
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
def initialize(screen)
|
5
|
+
@screen = screen
|
6
|
+
TTF.setup
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def draw_box(x1,y1,x2,y2,color)
|
10
|
+
@screen.draw_box [x1,y1], [x2,y2], convert_color(color)
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
# fill in a rect with color or full screen if no color
|
14
|
+
def fill(color,rect=nil)
|
15
|
+
if rect.nil?
|
16
|
+
@screen.fill convert_color(color)
|
17
|
+
else
|
18
|
+
@screen.fill convert_color(color), rect
|
19
|
+
end
|
18
20
|
end
|
19
|
-
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
def convert_color(goo_color)
|
23
|
+
[goo_color.r,goo_color.g,goo_color.b,goo_color.a]
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
+
def start_drawing(); end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def finish_drawing()
|
29
|
+
@screen.flip
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
def draw_image(img, x, y, color=nil)
|
33
|
+
img.blit @screen, [x,y]
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
def size_text(text, font_file, font_size)
|
37
|
+
@font_cache ||= {}
|
38
|
+
@font_cache[font_file] ||= {}
|
39
|
+
font = @font_cache[font_file][font_size] ||= TTF.new(font_file, font_size)
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
font.size_text text
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
def render_text(text, font_file, font_size, color)
|
45
|
+
@font_cache ||= {}
|
46
|
+
@font_cache[font_file] ||= {}
|
47
|
+
font = @font_cache[font_file][font_size] ||= TTF.new(font_file, font_size)
|
47
48
|
|
48
|
-
|
49
|
-
|
49
|
+
text_image = font.render text, true, convert_color(color)
|
50
|
+
end
|
50
51
|
|
52
|
+
end
|
51
53
|
end
|
data/lib/rubygoo/app.rb
CHANGED
@@ -1,80 +1,93 @@
|
|
1
|
-
|
1
|
+
module Rubygoo
|
2
|
+
class App < Container
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
DEFAULT_PARAMS = {:theme=>'default',:x=>10,:y=>10,:width=>600,:height=>480,:data_dir=>File.join(File.dirname(__FILE__),"..","..","themes"),:mouse_cursor => true}
|
5
|
+
attr_accessor :theme_name, :theme, :data_dir, :theme_dir, :renderer
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
7
|
+
def initialize(opts={})
|
8
|
+
merged_opts = DEFAULT_PARAMS.merge opts
|
9
|
+
@widgets = []
|
10
|
+
@tabbed_widgets = []
|
11
|
+
@focussed_widget = 0
|
12
|
+
theme_name = merged_opts[:theme]
|
13
|
+
@data_dir = merged_opts[:data_dir]
|
14
|
+
@theme_name = theme_name
|
15
|
+
@theme = load_theme theme_name
|
16
|
+
@renderer = merged_opts[:renderer]
|
17
|
+
super merged_opts
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
# should this go here?
|
20
|
+
@mouse_opt = merged_opts[:mouse_cursor]
|
21
|
+
if @mouse_opt
|
22
|
+
@mouse = MouseCursor.new
|
23
|
+
@mouse.parent = self
|
24
|
+
@mouse.app = self.app
|
25
|
+
@mouse.added
|
26
|
+
end
|
27
|
+
end
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
29
|
+
def app()
|
30
|
+
self
|
31
|
+
end
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
+
def load_theme(theme_name)
|
34
|
+
@theme_dir = File.join(@data_dir,theme_name)
|
35
|
+
@theme = YAML::load_file(File.join(@theme_dir,"config.yml"))
|
36
|
+
end
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
38
|
+
def draw(screen)
|
39
|
+
@renderer.start_drawing
|
40
|
+
super @renderer
|
41
|
+
@mouse.draw @renderer if @mouse_opt
|
42
|
+
@renderer.finish_drawing
|
43
|
+
end
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
def add_tabbed_widget(w)
|
46
|
+
w.focus_priority = @tabbed_widgets.size unless w.focus_priority
|
47
|
+
@focussed_widget = 1
|
48
|
+
w.focus if @tabbed_widgets.empty?
|
49
|
+
@tabbed_widgets << w
|
50
|
+
@tabbed_widgets.sort_by {|w| w.focus_priority}
|
51
|
+
end
|
48
52
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
def focus_back()
|
54
|
+
@tabbed_widgets[@focussed_widget].unfocus
|
55
|
+
@focussed_widget += 1
|
56
|
+
@focussed_widget %= @tabbed_widgets.size
|
57
|
+
@tabbed_widgets[@focussed_widget].focus
|
58
|
+
end
|
59
|
+
|
60
|
+
def focus_forward()
|
61
|
+
@tabbed_widgets[@focussed_widget].unfocus
|
62
|
+
@focussed_widget -= 1
|
63
|
+
@focussed_widget %= @tabbed_widgets.size
|
64
|
+
@tabbed_widgets[@focussed_widget].focus
|
65
|
+
end
|
55
66
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
+
def on_event(event)
|
68
|
+
case event.event_type
|
69
|
+
when :key_released
|
70
|
+
modal_keyboard_call :key_released, event
|
71
|
+
when :key_pressed
|
72
|
+
case event.data[:key]
|
73
|
+
when K_TAB
|
74
|
+
if event.data[:mods].include? K_LSHIFT or event.data[:mods].include? K_RSHIFT
|
75
|
+
focus_back
|
76
|
+
else
|
77
|
+
focus_forward
|
78
|
+
end
|
67
79
|
else
|
68
|
-
|
80
|
+
modal_keyboard_call :key_pressed, event
|
69
81
|
end
|
70
82
|
else
|
71
|
-
|
83
|
+
# ALL mouse events go here
|
84
|
+
modal_mouse_call event.event_type, event
|
85
|
+
|
86
|
+
if event.event_type == :mouse_motion
|
87
|
+
@mouse.mouse_motion event if @mouse_opt
|
88
|
+
end
|
72
89
|
end
|
73
|
-
else
|
74
|
-
# ALL mouse events go here
|
75
|
-
modal_mouse_call event.event_type, event
|
76
90
|
end
|
77
|
-
end
|
78
91
|
|
92
|
+
end
|
79
93
|
end
|
80
|
-
|
data/lib/rubygoo/button.rb
CHANGED
@@ -1,53 +1,55 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def added()
|
9
|
-
font = theme_property :font
|
10
|
-
@font_size = theme_property :font_size
|
11
|
-
@color = theme_property :color
|
12
|
-
@bg_color = theme_property :bg_color
|
13
|
-
@border_color = theme_property :border_color
|
14
|
-
@focus_color = theme_property :focus_color
|
15
|
-
@font_file = File.join(@app.theme_dir,font)
|
16
|
-
|
17
|
-
@rendered_text ||= @app.renderer.render_text @text, @font_file, @font_size, @color
|
18
|
-
@rect = Rect.new [@x-@x_pad,@y-@y_pad,@rendered_text.width+2*@x_pad,@rendered_text.height+2*@y_pad]
|
19
|
-
end
|
1
|
+
module Rubygoo
|
2
|
+
class Button < Widget
|
3
|
+
can_fire :pressed
|
4
|
+
def initialize(text, opts={})
|
5
|
+
super opts
|
6
|
+
@text = text
|
7
|
+
end
|
20
8
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
9
|
+
def added()
|
10
|
+
font = theme_property :font
|
11
|
+
@font_size = theme_property :font_size
|
12
|
+
@color = theme_property :color
|
13
|
+
@bg_color = theme_property :bg_color
|
14
|
+
@border_color = theme_property :border_color
|
15
|
+
@focus_color = theme_property :focus_color
|
16
|
+
@font_file = File.join(@app.theme_dir,font)
|
17
|
+
|
18
|
+
@rendered_text ||= @app.renderer.render_text @text, @font_file, @font_size, @color
|
19
|
+
@rect = Rect.new [@x-@x_pad,@y-@y_pad,@rendered_text.width+2*@x_pad,@rendered_text.height+2*@y_pad]
|
20
|
+
end
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
case event.data[:key]
|
29
|
-
when K_SPACE
|
22
|
+
# called when there is a mouse click
|
23
|
+
def mouse_up(event)
|
30
24
|
fire :pressed, event
|
31
25
|
end
|
32
|
-
end
|
33
26
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
if @border_color
|
41
|
-
x1 = @rect[0]
|
42
|
-
y1 = @rect[1]
|
43
|
-
x2 = @rect[2] + x1
|
44
|
-
y2 = @rect[3] + y1
|
45
|
-
adapter.draw_box x1, y1, x2, y2, @border_color
|
27
|
+
# called when a key press is sent to us
|
28
|
+
def key_pressed(event)
|
29
|
+
case event.data[:key]
|
30
|
+
when K_SPACE
|
31
|
+
fire :pressed, event
|
32
|
+
end
|
46
33
|
end
|
47
34
|
|
35
|
+
def draw(adapter)
|
36
|
+
if @focussed
|
37
|
+
adapter.fill @focus_color, @rect
|
38
|
+
elsif @bg_color
|
39
|
+
adapter.fill @bg_color, @rect
|
40
|
+
end
|
41
|
+
if @border_color
|
42
|
+
x1 = @rect[0]
|
43
|
+
y1 = @rect[1]
|
44
|
+
x2 = @rect[2] + x1
|
45
|
+
y2 = @rect[3] + y1
|
46
|
+
adapter.draw_box x1, y1, x2, y2, @border_color
|
47
|
+
end
|
48
48
|
|
49
|
-
adapter.draw_image @rendered_text, @x, @y
|
50
49
|
|
50
|
+
adapter.draw_image @rendered_text, @x, @y, @color
|
51
|
+
|
52
|
+
end
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|