rubygoo 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +10 -0
- data/Manifest.txt +37 -0
- data/README.txt +81 -0
- data/Rakefile +35 -0
- data/TODO +10 -0
- data/docs/.DS_Store +0 -0
- data/docs/Picture 1.png +0 -0
- data/docs/ui/.DS_Store +0 -0
- data/docs/ui/UI.hpp +425 -0
- data/docs/ui/abutton.png +0 -0
- data/docs/ui/background.png +0 -0
- data/docs/ui/button.png +0 -0
- data/docs/ui/moveable.png +0 -0
- data/docs/ui/textbutton.png +0 -0
- data/lib/code_statistics.rb +107 -0
- data/lib/platform.rb +15 -0
- data/lib/rubygoo.rb +19 -0
- data/lib/rubygoo/adapters/adapter_factory.rb +14 -0
- data/lib/rubygoo/adapters/gosu_app_adapter.rb +50 -0
- data/lib/rubygoo/adapters/gosu_render_adapter.rb +53 -0
- data/lib/rubygoo/adapters/rubygame_app_adapter.rb +37 -0
- data/lib/rubygoo/adapters/rubygame_render_adapter.rb +51 -0
- data/lib/rubygoo/app.rb +80 -0
- data/lib/rubygoo/button.rb +53 -0
- data/lib/rubygoo/check_box.rb +74 -0
- data/lib/rubygoo/container.rb +130 -0
- data/lib/rubygoo/css_colors.rb +151 -0
- data/lib/rubygoo/dialog.rb +40 -0
- data/lib/rubygoo/goo_color.rb +8 -0
- data/lib/rubygoo/goo_event.rb +11 -0
- data/lib/rubygoo/label.rb +42 -0
- data/lib/rubygoo/text_field.rb +301 -0
- data/lib/rubygoo/widget.rb +144 -0
- data/samples/gosu_app.rb +102 -0
- data/samples/rubygame_app.rb +102 -0
- data/themes/default/Vera.ttf +0 -0
- data/themes/default/config.yml +20 -0
- metadata +121 -0
data/docs/ui/abutton.png
ADDED
Binary file
|
Binary file
|
data/docs/ui/button.png
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,107 @@
|
|
1
|
+
class CodeStatistics #:nodoc:
|
2
|
+
|
3
|
+
TEST_TYPES = %w(Units Functionals Unit\ tests Functional\ tests Integration\ tests)
|
4
|
+
|
5
|
+
def initialize(*pairs)
|
6
|
+
@pairs = pairs
|
7
|
+
@statistics = calculate_statistics
|
8
|
+
@total = calculate_total if pairs.length > 1
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
print_header
|
13
|
+
@pairs.each { |pair| print_line(pair.first, @statistics[pair.first]) }
|
14
|
+
print_splitter
|
15
|
+
|
16
|
+
if @total
|
17
|
+
print_line("Total", @total)
|
18
|
+
print_splitter
|
19
|
+
end
|
20
|
+
|
21
|
+
print_code_test_stats
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def calculate_statistics
|
26
|
+
@pairs.inject({}) { |stats, pair| stats[pair.first] = calculate_directory_statistics(pair.last); stats }
|
27
|
+
end
|
28
|
+
|
29
|
+
def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
|
30
|
+
stats = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
|
31
|
+
|
32
|
+
Dir.foreach(directory) do |file_name|
|
33
|
+
if File.stat(directory + "/" + file_name).directory? and (/^\./ !~ file_name)
|
34
|
+
newstats = calculate_directory_statistics(directory + "/" + file_name, pattern)
|
35
|
+
stats.each { |k, v| stats[k] += newstats[k] }
|
36
|
+
end
|
37
|
+
|
38
|
+
next unless file_name =~ pattern
|
39
|
+
|
40
|
+
f = File.open(directory + "/" + file_name)
|
41
|
+
|
42
|
+
while line = f.gets
|
43
|
+
stats["lines"] += 1
|
44
|
+
stats["classes"] += 1 if line =~ /class [A-Z]/
|
45
|
+
stats["methods"] += 1 if line =~ /def [a-z]/
|
46
|
+
stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
stats
|
51
|
+
end
|
52
|
+
|
53
|
+
def calculate_total
|
54
|
+
total = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
|
55
|
+
@statistics.each_value { |pair| pair.each { |k, v| total[k] += v } }
|
56
|
+
total
|
57
|
+
end
|
58
|
+
|
59
|
+
def calculate_code
|
60
|
+
code_loc = 0
|
61
|
+
@statistics.each { |k, v| code_loc += v['codelines'] unless TEST_TYPES.include? k }
|
62
|
+
code_loc
|
63
|
+
end
|
64
|
+
|
65
|
+
def calculate_tests
|
66
|
+
test_loc = 0
|
67
|
+
@statistics.each { |k, v| test_loc += v['codelines'] if TEST_TYPES.include? k }
|
68
|
+
test_loc
|
69
|
+
end
|
70
|
+
|
71
|
+
def print_header
|
72
|
+
print_splitter
|
73
|
+
puts "| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |"
|
74
|
+
print_splitter
|
75
|
+
end
|
76
|
+
|
77
|
+
def print_splitter
|
78
|
+
puts "+----------------------+-------+-------+---------+---------+-----+-------+"
|
79
|
+
end
|
80
|
+
|
81
|
+
def print_line(name, statistics)
|
82
|
+
m_over_c = (statistics["methods"] / statistics["classes"]) rescue m_over_c = 0
|
83
|
+
loc_over_m = (statistics["codelines"] / statistics["methods"]) - 2 rescue loc_over_m = 0
|
84
|
+
|
85
|
+
start = if TEST_TYPES.include? name
|
86
|
+
"| #{name.ljust(18)} "
|
87
|
+
else
|
88
|
+
"| #{name.ljust(20)} "
|
89
|
+
end
|
90
|
+
|
91
|
+
puts start +
|
92
|
+
"| #{statistics["lines"].to_s.rjust(5)} " +
|
93
|
+
"| #{statistics["codelines"].to_s.rjust(5)} " +
|
94
|
+
"| #{statistics["classes"].to_s.rjust(7)} " +
|
95
|
+
"| #{statistics["methods"].to_s.rjust(7)} " +
|
96
|
+
"| #{m_over_c.to_s.rjust(3)} " +
|
97
|
+
"| #{loc_over_m.to_s.rjust(5)} |"
|
98
|
+
end
|
99
|
+
|
100
|
+
def print_code_test_stats
|
101
|
+
code = calculate_code
|
102
|
+
tests = calculate_tests
|
103
|
+
|
104
|
+
puts " Code LOC: #{code} Test LOC: #{tests} Code to Test Ratio: 1:#{sprintf("%.1f", tests.to_f/code)}"
|
105
|
+
puts ""
|
106
|
+
end
|
107
|
+
end
|
data/lib/platform.rb
ADDED
data/lib/rubygoo.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$: << File.dirname(__FILE__)
|
2
|
+
$: << File.join(File.dirname(__FILE__),"rubygoo")
|
3
|
+
$: << File.join(File.dirname(__FILE__),"rubygoo","adapters")
|
4
|
+
class Rubygoo
|
5
|
+
VERSION = '0.0.3'
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'goo_event'
|
9
|
+
require 'goo_color'
|
10
|
+
require 'adapter_factory'
|
11
|
+
require 'yaml'
|
12
|
+
require 'widget'
|
13
|
+
require 'container'
|
14
|
+
require 'app'
|
15
|
+
require 'label'
|
16
|
+
require 'button'
|
17
|
+
require 'check_box'
|
18
|
+
require 'text_field'
|
19
|
+
require 'dialog'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class AdapterFactory
|
2
|
+
|
3
|
+
def app_for(platform,*args)
|
4
|
+
require "#{platform}_app_adapter"
|
5
|
+
ObjectSpace.const_get("#{platform.to_s.capitalize}AppAdapter").new *args
|
6
|
+
end
|
7
|
+
|
8
|
+
def renderer_for(platform,*args)
|
9
|
+
require "#{platform}_render_adapter"
|
10
|
+
ObjectSpace.const_get("#{platform.to_s.capitalize}RenderAdapter").new *args
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class GosuAppAdapter
|
2
|
+
|
3
|
+
def initialize(app,main_window)
|
4
|
+
@app = app
|
5
|
+
@main_window = main_window
|
6
|
+
end
|
7
|
+
|
8
|
+
def update(time)
|
9
|
+
@app.update time
|
10
|
+
end
|
11
|
+
|
12
|
+
def draw(target)
|
13
|
+
@app.draw target
|
14
|
+
end
|
15
|
+
|
16
|
+
# TODO convert keys?!?
|
17
|
+
def button_down(id)
|
18
|
+
case id
|
19
|
+
when MsLeft
|
20
|
+
@app.on_event GooEvent.new(:mouse_down, {
|
21
|
+
:x => @main_window.mouse_x, :y => @main_window.mouse_y,
|
22
|
+
:button => MOUSE_LEFT})
|
23
|
+
|
24
|
+
# gosu doens't track mouse motion?
|
25
|
+
when MouseMotionEvent
|
26
|
+
@app.on_event GooEvent.new(:mouse_motion, {
|
27
|
+
:x => event.pos[0], :y => event.pos[1]})
|
28
|
+
else
|
29
|
+
# assume it's a key
|
30
|
+
# where do I get the mods? ie shift,alt,ctrl
|
31
|
+
# where do I get the string rep of the char?
|
32
|
+
mods = []
|
33
|
+
mods << K_LALT if @main_window.button_down? KbLeftAlt
|
34
|
+
mods << K_RALT if @main_window.button_down? KbRightAlt
|
35
|
+
mods << K_LCTRL if @main_window.button_down? KbLeftControl
|
36
|
+
mods << K_RCTRL if @main_window.button_down? KbRightControl
|
37
|
+
mods << K_LSHIFT if @main_window.button_down? KbLeftShift
|
38
|
+
mods << K_RSHIFT if @main_window.button_down? KbRightShift
|
39
|
+
button_string = @main_window.button_id_to_char(id)
|
40
|
+
@app.on_event GooEvent.new(:key_pressed, {
|
41
|
+
:key => id, :mods => mods, :string => button_string})
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def button_up(id)
|
46
|
+
# TODO copy and tweak from above
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class GosuRenderAdapter
|
2
|
+
|
3
|
+
def initialize(window)
|
4
|
+
@window = window
|
5
|
+
end
|
6
|
+
|
7
|
+
def draw_box(x1,y1,x2,y2,color)
|
8
|
+
c = convert_color(color)
|
9
|
+
@window.draw_quad x1, y1, c, x2, y1, c, x1, y2, c, x2, y2, c
|
10
|
+
end
|
11
|
+
|
12
|
+
# fill in a rect with color or full screen if no color
|
13
|
+
def fill(color,rect=nil)
|
14
|
+
if rect.nil?
|
15
|
+
draw_box 0, 0, @window.width, @window.height, color
|
16
|
+
else
|
17
|
+
draw_box rect[0], rect[1], rect[2], rect[3], color
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# make static for now for migration ease of rendering fonts
|
22
|
+
def convert_color(goo_color)
|
23
|
+
Gosu::Color.new goo_color.a,goo_color.r,goo_color.g,goo_color.b
|
24
|
+
end
|
25
|
+
|
26
|
+
def start_drawing(); end
|
27
|
+
|
28
|
+
def finish_drawing(); end
|
29
|
+
|
30
|
+
def draw_image(img, x, y)
|
31
|
+
# z is unused here
|
32
|
+
img.draw x, y, 1
|
33
|
+
end
|
34
|
+
|
35
|
+
def size_text(text, font_file, font_size)
|
36
|
+
@font_cache ||= {}
|
37
|
+
@font_cache[font_file] ||= {}
|
38
|
+
font = @font_cache[font_file][font_size] ||= Font.new(@window, font_file, font_size)
|
39
|
+
|
40
|
+
return [font.text_width(text),font.height]
|
41
|
+
end
|
42
|
+
|
43
|
+
def render_text(text, font_file, font_size, color)
|
44
|
+
@font_cache ||= {}
|
45
|
+
@font_cache[font_file] ||= {}
|
46
|
+
font = @font_cache[font_file][font_size] ||= Font.new(@window, font_file, font_size)
|
47
|
+
|
48
|
+
# TODO how do you set the color here?
|
49
|
+
text_image = Image.from_text(@window, text, font_file, font_size, 2, 9999, :left)
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class RubygameAppAdapter
|
2
|
+
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def update(time)
|
8
|
+
@app.update time
|
9
|
+
end
|
10
|
+
|
11
|
+
def draw(target)
|
12
|
+
@app.draw target
|
13
|
+
end
|
14
|
+
|
15
|
+
# TODO convert keys?!?
|
16
|
+
def on_event(event)
|
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]})
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class RubygameRenderAdapter
|
2
|
+
|
3
|
+
def initialize(screen)
|
4
|
+
@screen = screen
|
5
|
+
TTF.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
def draw_box(x1,y1,x2,y2,color)
|
9
|
+
@screen.draw_box [x1,y1], [x2,y2], convert_color(color)
|
10
|
+
end
|
11
|
+
|
12
|
+
# fill in a rect with color or full screen if no color
|
13
|
+
def fill(color,rect=nil)
|
14
|
+
if rect.nil?
|
15
|
+
@screen.fill convert_color(color)
|
16
|
+
else
|
17
|
+
@screen.fill convert_color(color), rect
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def convert_color(goo_color)
|
22
|
+
[goo_color.r,goo_color.g,goo_color.b,goo_color.a]
|
23
|
+
end
|
24
|
+
|
25
|
+
def start_drawing(); end
|
26
|
+
|
27
|
+
def finish_drawing()
|
28
|
+
@screen.flip
|
29
|
+
end
|
30
|
+
|
31
|
+
def draw_image(img, x, y)
|
32
|
+
img.blit @screen, [x,y]
|
33
|
+
end
|
34
|
+
|
35
|
+
def size_text(text, font_file, font_size)
|
36
|
+
@font_cache ||= {}
|
37
|
+
@font_cache[font_file] ||= {}
|
38
|
+
font = @font_cache[font_file][font_size] ||= TTF.new(font_file, font_size)
|
39
|
+
|
40
|
+
font.size_text text
|
41
|
+
end
|
42
|
+
|
43
|
+
def render_text(text, font_file, font_size, color)
|
44
|
+
@font_cache ||= {}
|
45
|
+
@font_cache[font_file] ||= {}
|
46
|
+
font = @font_cache[font_file][font_size] ||= TTF.new(font_file, font_size)
|
47
|
+
|
48
|
+
text_image = font.render text, true, convert_color(color)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/lib/rubygoo/app.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
class App < Container
|
2
|
+
|
3
|
+
DEFAULT_PARAMS = {:theme=>'default',:x=>10,:y=>10,:width=>600,:height=>480,:data_dir=>File.join(File.dirname(__FILE__),"..","..","themes")}
|
4
|
+
attr_accessor :theme_name, :theme, :data_dir, :theme_dir, :renderer
|
5
|
+
|
6
|
+
def initialize(opts={})
|
7
|
+
merged_opts = DEFAULT_PARAMS.merge opts
|
8
|
+
@widgets = []
|
9
|
+
@tabbed_widgets = []
|
10
|
+
@focussed_widget = 0
|
11
|
+
theme_name = merged_opts[:theme]
|
12
|
+
@data_dir = merged_opts[:data_dir]
|
13
|
+
@theme_name = theme_name
|
14
|
+
@theme = load_theme theme_name
|
15
|
+
@renderer = merged_opts[:renderer]
|
16
|
+
super merged_opts
|
17
|
+
end
|
18
|
+
|
19
|
+
def app()
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def load_theme(theme_name)
|
24
|
+
@theme_dir = File.join(@data_dir,theme_name)
|
25
|
+
@theme = YAML::load_file(File.join(@theme_dir,"config.yml"))
|
26
|
+
end
|
27
|
+
|
28
|
+
def draw(screen)
|
29
|
+
screen.start_drawing
|
30
|
+
super screen
|
31
|
+
screen.finish_drawing
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_tabbed_widget(w)
|
35
|
+
w.focus_priority = @tabbed_widgets.size unless w.focus_priority
|
36
|
+
@focussed_widget = 1
|
37
|
+
w.focus if @tabbed_widgets.empty?
|
38
|
+
@tabbed_widgets << w
|
39
|
+
@tabbed_widgets.sort_by {|w| w.focus_priority}
|
40
|
+
end
|
41
|
+
|
42
|
+
def focus_back()
|
43
|
+
@tabbed_widgets[@focussed_widget].unfocus
|
44
|
+
@focussed_widget += 1
|
45
|
+
@focussed_widget %= @tabbed_widgets.size
|
46
|
+
@tabbed_widgets[@focussed_widget].focus
|
47
|
+
end
|
48
|
+
|
49
|
+
def focus_forward()
|
50
|
+
@tabbed_widgets[@focussed_widget].unfocus
|
51
|
+
@focussed_widget -= 1
|
52
|
+
@focussed_widget %= @tabbed_widgets.size
|
53
|
+
@tabbed_widgets[@focussed_widget].focus
|
54
|
+
end
|
55
|
+
|
56
|
+
# this is where all the rubygame to rubygoo event mapping will
|
57
|
+
# happen
|
58
|
+
def on_event(event)
|
59
|
+
case event.event_type
|
60
|
+
when :key_released
|
61
|
+
modal_keyboard_call :key_released, event
|
62
|
+
when :key_pressed
|
63
|
+
case event.data[:key]
|
64
|
+
when K_TAB
|
65
|
+
if event.data[:mods].include? K_LSHIFT or event.data[:mods].include? K_RSHIFT
|
66
|
+
focus_back
|
67
|
+
else
|
68
|
+
focus_forward
|
69
|
+
end
|
70
|
+
else
|
71
|
+
modal_keyboard_call :key_pressed, event
|
72
|
+
end
|
73
|
+
else
|
74
|
+
# ALL mouse events go here
|
75
|
+
modal_mouse_call event.event_type, event
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|