rubygoo 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,3 +37,12 @@
37
37
  * added mouse_enter/exit events and hover states for button/checkboxes
38
38
  * new color theme from nedric
39
39
  * bug fixes
40
+
41
+ === 0.0.8 / 2009-2-9
42
+
43
+ * Getting closer to a 1.0 release
44
+ * Ruby 1.9.1 support
45
+ * bug fixes
46
+ * added clear method to containers to remove all children
47
+ * added readers for some widgets
48
+ * added draw_line to adapter
@@ -3,14 +3,9 @@ Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
5
  TODO
6
- docs/Picture 1.png
7
- docs/ui/UI.hpp
8
- docs/ui/abutton.png
9
- docs/ui/background.png
10
- docs/ui/button.png
11
- docs/ui/moveable.png
12
- docs/ui/textbutton.png
13
6
  lib/code_statistics.rb
7
+ lib/inflections.rb
8
+ lib/inflector.rb
14
9
  lib/platform.rb
15
10
  lib/rubygoo.rb
16
11
  lib/rubygoo/adapters/adapter_factory.rb
data/README.txt CHANGED
@@ -11,7 +11,7 @@ Rubygoo is a theme-able gui framework for use with rubygame and soon gosu. It ha
11
11
  * theme-able gui widgets
12
12
  * named css colors
13
13
  * works with rubygame and gosu
14
- * containers, labels, buttons, checkboxes, radio buttons, radio groups
14
+ * containers, labels, buttons, checkboxes, radio buttons, radio groups, icons
15
15
  * tabbing focus of widgets
16
16
  * modal dialogs
17
17
 
@@ -84,13 +84,6 @@ Rubygoo is a theme-able gui framework for use with rubygame and soon gosu. It ha
84
84
  app.add text_field, label, button, modal_button, grp
85
85
  app.add check
86
86
 
87
- # pulldown = Pulldown.new {:x=>70, :y=>80}
88
- # pulldown.on :changed do |*opts|
89
- # label.set_text(opts.first)
90
- # end
91
- #
92
- # app.add pulldown
93
-
94
87
  app_adapter = factory.app_for :rubygame, app
95
88
 
96
89
  # rubygame standard stuff below here
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rubygems'
4
4
  require 'hoe'
5
5
 
6
6
  module Rubygoo
7
- VERSION = '0.0.7'
7
+ VERSION = '0.0.8'
8
8
  end
9
9
  Hoe.new('rubygoo', Rubygoo::VERSION) do |p|
10
10
  p.developer('Shawn Anderson', 'shawn42@gmail.com')
@@ -13,7 +13,7 @@ Hoe.new('rubygoo', Rubygoo::VERSION) do |p|
13
13
  p.email = 'shawn42@gmail.com'
14
14
  p.summary = "Easy to use gui library for Rubygame or Gosu."
15
15
  p.url = "http://rubygoo.googlecode.com"
16
- p.changes = p.paragraphs_of('History.txt', 8..8).join("\n\n")
16
+ p.changes = p.paragraphs_of('History.txt', 10..11).join("\n\n")
17
17
  p.remote_rdoc_dir = '' # Release to root
18
18
  p.extra_deps << ['constructor']
19
19
  p.extra_deps << ['publisher']
@@ -37,29 +37,12 @@ task :stats do
37
37
  end
38
38
 
39
39
  begin
40
+ require 'rake'
40
41
  require 'spec/rake/spectask'
41
42
 
42
- desc "Run all specs (tests)"
43
- Spec::Rake::SpecTask.new do |t|
44
- t.spec_files = FileList['test/*_spec.rb']
45
- t.spec_opts = ["--format", "specdoc"]
46
- end
47
-
48
- rule(/spec:.+/) do |t|
49
- name = t.name.gsub("spec:","")
50
-
51
- path = File.join( File.dirname(__FILE__),'test','%s_spec.rb'%name )
52
-
53
- if File.exist? path
54
- Spec::Rake::SpecTask.new(name) do |t|
55
- t.spec_files = [path]
56
- end
57
-
58
- puts "\nRunning spec/%s_spec.rb"%[name]
59
- Rake::Task[name].invoke
60
- else
61
- puts "File does not exist: %s"%path
62
- end
43
+ desc "Run all specs"
44
+ Spec::Rake::SpecTask.new('specs') do |t|
45
+ t.spec_files = FileList['test/*_spec.rb']
63
46
  end
64
47
 
65
48
  rescue LoadError
data/TODO CHANGED
@@ -1,4 +1,6 @@
1
1
  TODO
2
+ - change contructor chaining to a setup callback (setup, that can be overridden in subclasses)
3
+ - write some unit tests!
2
4
  - enabled?/disabled? effect on tabbing?
3
5
  - add show/hide effect on tabbing?
4
6
  - tool tips
@@ -0,0 +1,52 @@
1
+ Inflector.inflections do |inflect|
2
+ inflect.plural(/$/, 's')
3
+ inflect.plural(/s$/i, 's')
4
+ inflect.plural(/(ax|test)is$/i, '\1es')
5
+ inflect.plural(/(octop|vir)us$/i, '\1i')
6
+ inflect.plural(/(alias|status)$/i, '\1es')
7
+ inflect.plural(/(bu)s$/i, '\1ses')
8
+ inflect.plural(/(buffal|tomat)o$/i, '\1oes')
9
+ inflect.plural(/([ti])um$/i, '\1a')
10
+ inflect.plural(/sis$/i, 'ses')
11
+ inflect.plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves')
12
+ inflect.plural(/(hive)$/i, '\1s')
13
+ inflect.plural(/([^aeiouy]|qu)y$/i, '\1ies')
14
+ inflect.plural(/(x|ch|ss|sh)$/i, '\1es')
15
+ inflect.plural(/(matr|vert|ind)ix|ex$/i, '\1ices')
16
+ inflect.plural(/([m|l])ouse$/i, '\1ice')
17
+ inflect.plural(/^(ox)$/i, '\1en')
18
+ inflect.plural(/(quiz)$/i, '\1zes')
19
+
20
+ inflect.singular(/s$/i, '')
21
+ inflect.singular(/(n)ews$/i, '\1ews')
22
+ inflect.singular(/([ti])a$/i, '\1um')
23
+ inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '\1\2sis')
24
+ inflect.singular(/(^analy)ses$/i, '\1sis')
25
+ inflect.singular(/([^f])ves$/i, '\1fe')
26
+ inflect.singular(/(hive)s$/i, '\1')
27
+ inflect.singular(/(tive)s$/i, '\1')
28
+ inflect.singular(/([lr])ves$/i, '\1f')
29
+ inflect.singular(/([^aeiouy]|qu)ies$/i, '\1y')
30
+ inflect.singular(/(s)eries$/i, '\1eries')
31
+ inflect.singular(/(m)ovies$/i, '\1ovie')
32
+ inflect.singular(/(x|ch|ss|sh)es$/i, '\1')
33
+ inflect.singular(/([m|l])ice$/i, '\1ouse')
34
+ inflect.singular(/(bus)es$/i, '\1')
35
+ inflect.singular(/(o)es$/i, '\1')
36
+ inflect.singular(/(shoe)s$/i, '\1')
37
+ inflect.singular(/(cris|ax|test)es$/i, '\1is')
38
+ inflect.singular(/(octop|vir)i$/i, '\1us')
39
+ inflect.singular(/(alias|status)es$/i, '\1')
40
+ inflect.singular(/^(ox)en/i, '\1')
41
+ inflect.singular(/(vert|ind)ices$/i, '\1ex')
42
+ inflect.singular(/(matr)ices$/i, '\1ix')
43
+ inflect.singular(/(quiz)zes$/i, '\1')
44
+
45
+ inflect.irregular('person', 'people')
46
+ inflect.irregular('man', 'men')
47
+ inflect.irregular('child', 'children')
48
+ inflect.irregular('sex', 'sexes')
49
+ inflect.irregular('move', 'moves')
50
+
51
+ inflect.uncountable(%w(equipment information rice money species series fish sheep))
52
+ end
@@ -0,0 +1,279 @@
1
+ require 'singleton'
2
+
3
+ # The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without,
4
+ # and class names to foreign keys. The default inflections for pluralization, singularization, and uncountable words are kept
5
+ # in inflections.rb.
6
+ module Inflector
7
+ # A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
8
+ # inflection rules. Examples:
9
+ #
10
+ # Inflector.inflections do |inflect|
11
+ # inflect.plural /^(ox)$/i, '\1\2en'
12
+ # inflect.singular /^(ox)en/i, '\1'
13
+ #
14
+ # inflect.irregular 'octopus', 'octopi'
15
+ #
16
+ # inflect.uncountable "equipment"
17
+ # end
18
+ #
19
+ # New rules are added at the top. So in the example above, the irregular rule for octopus will now be the first of the
20
+ # pluralization and singularization rules that is runs. This guarantees that your rules run before any of the rules that may
21
+ # already have been loaded.
22
+ class Inflections
23
+ include Singleton
24
+
25
+ attr_reader :plurals, :singulars, :uncountables
26
+
27
+ def initialize
28
+ @plurals, @singulars, @uncountables = [], [], []
29
+ end
30
+
31
+ # Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
32
+ # The replacement should always be a string that may include references to the matched data from the rule.
33
+ def plural(rule, replacement)
34
+ @plurals.insert(0, [rule, replacement])
35
+ end
36
+
37
+ # Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
38
+ # The replacement should always be a string that may include references to the matched data from the rule.
39
+ def singular(rule, replacement)
40
+ @singulars.insert(0, [rule, replacement])
41
+ end
42
+
43
+ # Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
44
+ # for strings, not regular expressions. You simply pass the irregular in singular and plural form.
45
+ #
46
+ # Examples:
47
+ # irregular 'octopus', 'octopi'
48
+ # irregular 'person', 'people'
49
+ def irregular(singular, plural)
50
+ plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1])
51
+ singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1])
52
+ end
53
+
54
+ # Add uncountable words that shouldn't be attempted inflected.
55
+ #
56
+ # Examples:
57
+ # uncountable "money"
58
+ # uncountable "money", "information"
59
+ # uncountable %w( money information rice )
60
+ def uncountable(*words)
61
+ (@uncountables << words).flatten!
62
+ end
63
+
64
+ # Clears the loaded inflections within a given scope (default is :all). Give the scope as a symbol of the inflection type,
65
+ # the options are: :plurals, :singulars, :uncountables
66
+ #
67
+ # Examples:
68
+ # clear :all
69
+ # clear :plurals
70
+ def clear(scope = :all)
71
+ case scope
72
+ when :all
73
+ @plurals, @singulars, @uncountables = [], [], []
74
+ else
75
+ instance_variable_set "@#{scope}", []
76
+ end
77
+ end
78
+ end
79
+
80
+ extend self
81
+
82
+ def inflections
83
+ if block_given?
84
+ yield Inflections.instance
85
+ else
86
+ Inflections.instance
87
+ end
88
+ end
89
+
90
+ # Returns the plural form of the word in the string.
91
+ #
92
+ # Examples
93
+ # "post".pluralize #=> "posts"
94
+ # "octopus".pluralize #=> "octopi"
95
+ # "sheep".pluralize #=> "sheep"
96
+ # "words".pluralize #=> "words"
97
+ # "the blue mailman".pluralize #=> "the blue mailmen"
98
+ # "CamelOctopus".pluralize #=> "CamelOctopi"
99
+ def pluralize(word)
100
+ result = word.to_s.dup
101
+
102
+ if inflections.uncountables.include?(result.downcase)
103
+ result
104
+ else
105
+ inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
106
+ result
107
+ end
108
+ end
109
+
110
+ # The reverse of pluralize, returns the singular form of a word in a string.
111
+ #
112
+ # Examples
113
+ # "posts".singularize #=> "post"
114
+ # "octopi".singularize #=> "octopus"
115
+ # "sheep".singluarize #=> "sheep"
116
+ # "word".singluarize #=> "word"
117
+ # "the blue mailmen".singularize #=> "the blue mailman"
118
+ # "CamelOctopi".singularize #=> "CamelOctopus"
119
+ def singularize(word)
120
+ result = word.to_s.dup
121
+
122
+ if inflections.uncountables.include?(result.downcase)
123
+ result
124
+ else
125
+ inflections.singulars.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
126
+ result
127
+ end
128
+ end
129
+
130
+ # By default, camelize converts strings to UpperCamelCase. If the argument to camelize
131
+ # is set to ":lower" then camelize produces lowerCamelCase.
132
+ #
133
+ # camelize will also convert '/' to '::' which is useful for converting paths to namespaces
134
+ #
135
+ # Examples
136
+ # "active_record".camelize #=> "ActiveRecord"
137
+ # "active_record".camelize(:lower) #=> "activeRecord"
138
+ # "active_record/errors".camelize #=> "ActiveRecord::Errors"
139
+ # "active_record/errors".camelize(:lower) #=> "activeRecord::Errors"
140
+ def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
141
+ if first_letter_in_uppercase
142
+ lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
143
+ else
144
+ lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
145
+ end
146
+ end
147
+
148
+ # Capitalizes all the words and replaces some characters in the string to create
149
+ # a nicer looking title. Titleize is meant for creating pretty output. It is not
150
+ # used in the Rails internals.
151
+ #
152
+ # titleize is also aliased as as titlecase
153
+ #
154
+ # Examples
155
+ # "man from the boondocks".titleize #=> "Man From The Boondocks"
156
+ # "x-men: the last stand".titleize #=> "X Men: The Last Stand"
157
+ def titleize(word)
158
+ humanize(underscore(word)).gsub(/\b([a-z])/) { $1.capitalize }
159
+ end
160
+
161
+ # The reverse of +camelize+. Makes an underscored form from the expression in the string.
162
+ #
163
+ # Changes '::' to '/' to convert namespaces to paths.
164
+ #
165
+ # Examples
166
+ # "ActiveRecord".underscore #=> "active_record"
167
+ # "ActiveRecord::Errors".underscore #=> active_record/errors
168
+ def underscore(camel_cased_word)
169
+ camel_cased_word.to_s.gsub(/::/, '/').
170
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
171
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
172
+ tr("-", "_").
173
+ downcase
174
+ end
175
+
176
+ # Replaces underscores with dashes in the string.
177
+ #
178
+ # Example
179
+ # "puni_puni" #=> "puni-puni"
180
+ def dasherize(underscored_word)
181
+ underscored_word.gsub(/_/, '-')
182
+ end
183
+
184
+ # Capitalizes the first word and turns underscores into spaces and strips _id.
185
+ # Like titleize, this is meant for creating pretty output.
186
+ #
187
+ # Examples
188
+ # "employee_salary" #=> "Employee salary"
189
+ # "author_id" #=> "Author"
190
+ def humanize(lower_case_and_underscored_word)
191
+ lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
192
+ end
193
+
194
+ # Removes the module part from the expression in the string
195
+ #
196
+ # Examples
197
+ # "ActiveRecord::CoreExtensions::String::Inflections".demodulize #=> "Inflections"
198
+ # "Inflections".demodulize #=> "Inflections"
199
+ def demodulize(class_name_in_module)
200
+ class_name_in_module.to_s.gsub(/^.*::/, '')
201
+ end
202
+
203
+ # Create the name of a table like Rails does for models to table names. This method
204
+ # uses the pluralize method on the last word in the string.
205
+ #
206
+ # Examples
207
+ # "RawScaledScorer".tableize #=> "raw_scaled_scorers"
208
+ # "egg_and_ham".tableize #=> "egg_and_hams"
209
+ # "fancyCategory".tableize #=> "fancy_categories"
210
+ def tableize(class_name)
211
+ pluralize(underscore(class_name))
212
+ end
213
+
214
+ # Create a class name from a table name like Rails does for table names to models.
215
+ # Note that this returns a string and not a Class. (To convert to an actual class
216
+ # follow classify with constantize.)
217
+ #
218
+ # Examples
219
+ # "egg_and_hams".classify #=> "EggAndHam"
220
+ # "post".classify #=> "Post"
221
+ def classify(table_name)
222
+ # strip out any leading schema name
223
+ camelize(singularize(table_name.to_s.sub(/.*\./, '')))
224
+ end
225
+
226
+ # Creates a foreign key name from a class name.
227
+ # +separate_class_name_and_id_with_underscore+ sets whether
228
+ # the method should put '_' between the name and 'id'.
229
+ #
230
+ # Examples
231
+ # "Message".foreign_key #=> "message_id"
232
+ # "Message".foreign_key(false) #=> "messageid"
233
+ # "Admin::Post".foreign_key #=> "post_id"
234
+ def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
235
+ underscore(demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id")
236
+ end
237
+
238
+ # Constantize tries to find a declared constant with the name specified
239
+ # in the string. It raises a NameError when the name is not in CamelCase
240
+ # or is not initialized.
241
+ #
242
+ # Examples
243
+ # "Module".constantize #=> Module
244
+ # "Class".constantize #=> Class
245
+ def constantize(camel_cased_word)
246
+ unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word
247
+ raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!"
248
+ end
249
+
250
+ Object.module_eval("::#{$1}", __FILE__, __LINE__)
251
+ end
252
+
253
+ # Ordinalize turns a number into an ordinal string used to denote the
254
+ # position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
255
+ #
256
+ # Examples
257
+ # ordinalize(1) # => "1st"
258
+ # ordinalize(2) # => "2nd"
259
+ # ordinalize(1002) # => "1002nd"
260
+ # ordinalize(1003) # => "1003rd"
261
+ def ordinalize(number)
262
+ if (11..13).include?(number.to_i % 100)
263
+ "#{number}th"
264
+ else
265
+ case number.to_i % 10
266
+ when 1
267
+ "#{number}st"
268
+ when 2
269
+ "#{number}nd"
270
+ when 3
271
+ "#{number}rd"
272
+ else
273
+ "#{number}th"
274
+ end
275
+ end
276
+ end
277
+ end
278
+
279
+ require 'inflections'
@@ -26,6 +26,11 @@ module Rubygoo
26
26
  @window.draw_line x1, y2, c, x1, y1, c
27
27
  end
28
28
 
29
+ def draw_line(x1,y1,x2,y2,color)
30
+ c = convert_color(color)
31
+ @window.draw_line x1, y1, c, x1, y2, c
32
+ end
33
+
29
34
  CIRCLE_STEP = 10
30
35
  def draw_circle(cx,cy,r,color)
31
36
  c_color = convert_color(color)
@@ -72,6 +77,23 @@ module Rubygoo
72
77
  end
73
78
  end
74
79
 
80
+ # untested in Gosu
81
+ def draw_partial_image(img, to_x, to_y,
82
+ from_x=nil,from_y=nil,from_w=nil,from_h=nil, color=nil)
83
+
84
+ if from_x
85
+ if from_w
86
+ from = [from_x,from_y,from_w,from_h]
87
+ image = Image.new @screen, img, false, from
88
+ else
89
+ raise "not supported in gosu"
90
+ end
91
+ image.draw x, y, 0
92
+ else
93
+ draw_image img,to_x,to_y,color
94
+ end
95
+ end
96
+
75
97
  def size_text(text, font_file, font_size)
76
98
  @font_cache ||= {}
77
99
  @font_cache[font_file] ||= {}