rubygoo 0.0.3 → 0.0.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.
- 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
    
        data/lib/rubygoo/widget.rb
    CHANGED
    
    | @@ -1,144 +1,152 @@ | |
| 1 1 | 
             
            require 'publisher'
         | 
| 2 2 | 
             
            require 'css_colors'
         | 
| 3 3 | 
             
            require 'goo_color'
         | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 6 | 
            -
               | 
| 7 | 
            -
             | 
| 8 | 
            -
                 | 
| 9 | 
            -
                : | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
                 | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
                 | 
| 21 | 
            -
                 | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 4 | 
            +
            require 'rect'
         | 
| 5 | 
            +
            module Rubygoo
         | 
| 6 | 
            +
              class Widget
         | 
| 7 | 
            +
                extend Publisher
         | 
| 8 | 
            +
                can_fire :clicked
         | 
| 9 | 
            +
                attr_accessor :enabled, :parent, :container, 
         | 
| 10 | 
            +
                  :x, :y, :w, :h, :app, :x_pad, :y_pad, :focussed,
         | 
| 11 | 
            +
                  :focus_priority
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                DEFAULT_PARAMS = {
         | 
| 14 | 
            +
                  :x => 0,
         | 
| 15 | 
            +
                  :y => 0,
         | 
| 16 | 
            +
                  :w => 1,
         | 
| 17 | 
            +
                  :h => 1,
         | 
| 18 | 
            +
                  :x_pad => 2,
         | 
| 19 | 
            +
                  :y_pad => 2,
         | 
| 20 | 
            +
                }
         | 
| 21 | 
            +
                def initialize(opts={})
         | 
| 22 | 
            +
                  merged_opts = DEFAULT_PARAMS.merge opts
         | 
| 23 | 
            +
                  @x = merged_opts[:x]
         | 
| 24 | 
            +
                  @y = merged_opts[:y]
         | 
| 25 | 
            +
                  @x_pad = merged_opts[:x_pad]
         | 
| 26 | 
            +
                  @y_pad = merged_opts[:y_pad]
         | 
| 27 | 
            +
                  @w = merged_opts[:w]
         | 
| 28 | 
            +
                  @h = merged_opts[:h]
         | 
| 29 | 
            +
                  update_rect
         | 
| 30 | 
            +
                end
         | 
| 29 31 |  | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 32 | 
            +
                def update_rect()
         | 
| 33 | 
            +
                  @rect = Rect.new [@x,@y,@w+@x_pad,@h+@y_pad]
         | 
| 34 | 
            +
                end
         | 
| 33 35 |  | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 36 | 
            +
                # called when the widget is added to a container
         | 
| 37 | 
            +
                def added()
         | 
| 38 | 
            +
                end
         | 
| 37 39 |  | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 40 | 
            +
                # called when the widget is removed from a container
         | 
| 41 | 
            +
                def removed()
         | 
| 42 | 
            +
                end
         | 
| 41 43 |  | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 44 | 
            +
                def contains?(pos)
         | 
| 45 | 
            +
                  @rect.collide_point? pos[0], pos[1]
         | 
| 46 | 
            +
                end
         | 
| 45 47 |  | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 48 | 
            +
                def enabled?()
         | 
| 49 | 
            +
                  @enabled
         | 
| 50 | 
            +
                end
         | 
| 49 51 |  | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            +
                def update(millis)
         | 
| 53 | 
            +
                end
         | 
| 52 54 |  | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 55 | 
            +
                # draw ourself on the screen
         | 
| 56 | 
            +
                def draw(screen)
         | 
| 57 | 
            +
                end
         | 
| 56 58 |  | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 59 | 
            +
                # called when there is a mouse click
         | 
| 60 | 
            +
                def mouse_down(event)
         | 
| 61 | 
            +
                end
         | 
| 60 62 |  | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 63 | 
            +
                # called when there is a mouse motion
         | 
| 64 | 
            +
                def mouse_motion(event)
         | 
| 65 | 
            +
                end
         | 
| 64 66 |  | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 67 | 
            +
                # called when there is a mouse release
         | 
| 68 | 
            +
                def mouse_up(event)
         | 
| 69 | 
            +
                end
         | 
| 68 70 |  | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 71 | 
            +
                # called when a key press is sent to us
         | 
| 72 | 
            +
                def key_pressed(event)
         | 
| 73 | 
            +
                end
         | 
| 72 74 |  | 
| 73 | 
            -
             | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 75 | 
            +
                # called when a key release is sent to us
         | 
| 76 | 
            +
                def key_released(event)
         | 
| 77 | 
            +
                end
         | 
| 76 78 |  | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 79 | 
            +
                # called when the widget receives focus
         | 
| 80 | 
            +
                def on_focus()
         | 
| 81 | 
            +
                end
         | 
| 80 82 |  | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 83 | 
            +
                def focus()
         | 
| 84 | 
            +
                  @focussed = true
         | 
| 85 | 
            +
                  on_focus
         | 
| 86 | 
            +
                end
         | 
| 85 87 |  | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 88 | 
            +
                # called when the widget loses focus
         | 
| 89 | 
            +
                def on_unfocus()
         | 
| 90 | 
            +
                end
         | 
| 89 91 |  | 
| 90 | 
            -
             | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 95 | 
            -
             | 
| 96 | 
            -
             | 
| 97 | 
            -
             | 
| 92 | 
            +
                def unfocus()
         | 
| 93 | 
            +
                  @focussed = false
         | 
| 94 | 
            +
                  on_unfocus
         | 
| 95 | 
            +
                end
         | 
| 96 | 
            +
                
         | 
| 97 | 
            +
                def focussed?()
         | 
| 98 | 
            +
                  @focussed
         | 
| 99 | 
            +
                end
         | 
| 98 100 |  | 
| 99 | 
            -
             | 
| 100 | 
            -
             | 
| 101 | 
            -
             | 
| 102 | 
            -
             | 
| 103 | 
            -
             | 
| 104 | 
            -
             | 
| 105 | 
            -
             | 
| 106 | 
            -
             | 
| 107 | 
            -
             | 
| 108 | 
            -
             | 
| 109 | 
            -
             | 
| 110 | 
            -
             | 
| 101 | 
            +
                # gets the property for the class asking for it.
         | 
| 102 | 
            +
                # it will walk up the object hierarchy if needed
         | 
| 103 | 
            +
                def theme_property(prop_key)
         | 
| 104 | 
            +
                  prop = nil
         | 
| 105 | 
            +
                  parent = self.class
         | 
| 106 | 
            +
                  until parent == Object
         | 
| 107 | 
            +
                    class_theme = app.theme[parent.to_s]
         | 
| 108 | 
            +
                    if class_theme
         | 
| 109 | 
            +
                      class_prop = class_theme[prop_key]
         | 
| 110 | 
            +
                      if class_prop
         | 
| 111 | 
            +
                        prop = class_prop
         | 
| 112 | 
            +
                        break
         | 
| 113 | 
            +
                      end
         | 
| 111 114 | 
             
                    end
         | 
| 115 | 
            +
                    parent = parent.superclass
         | 
| 116 | 
            +
                  end
         | 
| 117 | 
            +
                  if prop_key.to_s.match /color/i
         | 
| 118 | 
            +
                    get_color prop
         | 
| 119 | 
            +
                  else
         | 
| 120 | 
            +
                    prop
         | 
| 112 121 | 
             
                  end
         | 
| 113 | 
            -
                  parent = parent.superclass
         | 
| 114 | 
            -
                end
         | 
| 115 | 
            -
                if prop_key.to_s.match /color/i
         | 
| 116 | 
            -
                  get_color prop
         | 
| 117 | 
            -
                else
         | 
| 118 | 
            -
                  prop
         | 
| 119 122 | 
             
                end
         | 
| 120 | 
            -
              end
         | 
| 121 123 |  | 
| 122 | 
            -
             | 
| 123 | 
            -
             | 
| 124 | 
            -
             | 
| 125 | 
            -
             | 
| 126 | 
            -
             | 
| 127 | 
            -
             | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
             | 
| 124 | 
            +
                def get_color(color)
         | 
| 125 | 
            +
                  new_color = nil
         | 
| 126 | 
            +
                  if color.is_a? Array
         | 
| 127 | 
            +
                    if color.size > 3
         | 
| 128 | 
            +
                      new_color = color
         | 
| 129 | 
            +
                    else
         | 
| 130 | 
            +
                      # fill in zeros for all other colors
         | 
| 131 | 
            +
                      3-color.size.times do
         | 
| 132 | 
            +
                        color << 0
         | 
| 133 | 
            +
                      end
         | 
| 134 | 
            +
                      # fill in alpha as 255
         | 
| 135 | 
            +
                      color << 255
         | 
| 131 136 | 
             
                    end
         | 
| 132 | 
            -
             | 
| 133 | 
            -
                     | 
| 137 | 
            +
                  elsif color.is_a? Symbol
         | 
| 138 | 
            +
                    new_color = CSS_COLORS[color]
         | 
| 139 | 
            +
                  else
         | 
| 140 | 
            +
                    raise "invalid color"
         | 
| 134 141 | 
             
                  end
         | 
| 135 | 
            -
             | 
| 136 | 
            -
                  new_color  | 
| 137 | 
            -
                 | 
| 138 | 
            -
             | 
| 142 | 
            +
             | 
| 143 | 
            +
                  GooColor.new *new_color 
         | 
| 144 | 
            +
                end
         | 
| 145 | 
            +
                
         | 
| 146 | 
            +
                # called each update cycle with the amount of time that has passed.  useful
         | 
| 147 | 
            +
                # for animations, etc
         | 
| 148 | 
            +
                def update(time)
         | 
| 139 149 | 
             
                end
         | 
| 140 150 |  | 
| 141 | 
            -
                GooColor.new *new_color 
         | 
| 142 151 | 
             
              end
         | 
| 143 | 
            -
             | 
| 144 152 | 
             
            end
         | 
    
        data/samples/gosu_app.rb
    CHANGED
    
    | @@ -3,13 +3,20 @@ $: << './lib' | |
| 3 3 | 
             
            require 'rubygoo'
         | 
| 4 4 |  | 
| 5 5 | 
             
            require 'gosu'
         | 
| 6 | 
            -
            require 'rubygame'
         | 
| 7 6 | 
             
            include Gosu
         | 
| 8 | 
            -
            include  | 
| 7 | 
            +
            include Rubygoo
         | 
| 9 8 |  | 
| 10 | 
            -
            class  | 
| 9 | 
            +
            class RubygooWindow < Window
         | 
| 11 10 | 
             
              def initialize()
         | 
| 11 | 
            +
             | 
| 12 12 | 
             
                super(640, 480, false)
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                # TODO, how can I do this cleaner?
         | 
| 15 | 
            +
                %w{a b c d e f g h i j k l m n o p q r s t u v w x y z}.each do |letter|
         | 
| 16 | 
            +
                  eval "::Kb#{letter.upcase} = #{self.char_to_button_id(letter)}"
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
                # how do I get rid of this?
         | 
| 19 | 
            +
                require 'gosu_app_adapter'
         | 
| 13 20 | 
             
                factory = AdapterFactory.new
         | 
| 14 21 | 
             
                @render_adapter = factory.renderer_for :gosu, self
         | 
| 15 22 | 
             
                app = create_gui(@render_adapter)
         | 
| @@ -96,7 +103,7 @@ end | |
| 96 103 |  | 
| 97 104 | 
             
            if $0 == __FILE__
         | 
| 98 105 |  | 
| 99 | 
            -
              window =  | 
| 106 | 
            +
              window = RubygooWindow.new 
         | 
| 100 107 | 
             
              window.show
         | 
| 101 108 |  | 
| 102 109 | 
             
            end
         | 
    
        data/samples/rubygame_app.rb
    CHANGED
    
    | @@ -3,6 +3,7 @@ $: << './lib' | |
| 3 3 | 
             
            require 'rubygoo'
         | 
| 4 4 | 
             
            require 'rubygame'
         | 
| 5 5 | 
             
            include Rubygame
         | 
| 6 | 
            +
            include Rubygoo
         | 
| 6 7 |  | 
| 7 8 | 
             
            def create_gui(renderer)
         | 
| 8 9 | 
             
              app = App.new :renderer => renderer
         | 
| @@ -62,6 +63,7 @@ end | |
| 62 63 | 
             
            if $0 == __FILE__
         | 
| 63 64 |  | 
| 64 65 | 
             
              screen = Screen.new [600,480]
         | 
| 66 | 
            +
              screen.show_cursor = false
         | 
| 65 67 |  | 
| 66 68 | 
             
              factory = AdapterFactory.new
         | 
| 67 69 | 
             
              render_adapter = factory.renderer_for :rubygame, screen
         | 
    
        data/themes/default/config.yml
    CHANGED
    
    | @@ -1,20 +1,23 @@ | |
| 1 1 | 
             
            --- 
         | 
| 2 | 
            -
            App: 
         | 
| 2 | 
            +
            Rubygoo::App: 
         | 
| 3 3 | 
             
              :bg_color: :Black
         | 
| 4 | 
            -
            Widget: 
         | 
| 4 | 
            +
            Rubygoo::Widget: 
         | 
| 5 5 | 
             
              :font: Vera.ttf
         | 
| 6 6 | 
             
              :font_size: 20
         | 
| 7 7 | 
             
              :color: :Black
         | 
| 8 8 | 
             
              :focus_color: :FireBrick
         | 
| 9 9 | 
             
              :bg_color: :Gray
         | 
| 10 10 | 
             
              :border_color: :FireBrick
         | 
| 11 | 
            -
            Button: 
         | 
| 11 | 
            +
            Rubygoo::Button: 
         | 
| 12 12 | 
             
              :bg_color: :DimGray
         | 
| 13 | 
            -
            CheckBox:
         | 
| 13 | 
            +
            Rubygoo::CheckBox:
         | 
| 14 14 | 
             
              :checked_color: :FireBrick
         | 
| 15 | 
            -
            TextField:
         | 
| 15 | 
            +
            Rubygoo::TextField:
         | 
| 16 16 | 
             
              :fg_color: :FireBrick
         | 
| 17 17 | 
             
              :bg_color: :Gray
         | 
| 18 18 | 
             
              :bg_select_color: :FireBrick
         | 
| 19 19 | 
             
              :fg_select_color: :Snow
         | 
| 20 20 | 
             
              :border_color: :Black
         | 
| 21 | 
            +
            Rubygoo::MouseCursor:
         | 
| 22 | 
            +
              :color: :Snow
         | 
| 23 | 
            +
              :mouse_cursor: cursor.png
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: rubygoo
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - Shawn Anderson
         | 
| @@ -9,7 +9,7 @@ autorequire: | |
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 11 |  | 
| 12 | 
            -
            date: 2008- | 
| 12 | 
            +
            date: 2008-10-13 00:00:00 -07:00
         | 
| 13 13 | 
             
            default_executable: 
         | 
| 14 14 | 
             
            dependencies: 
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| @@ -84,6 +84,8 @@ files: | |
| 84 84 | 
             
            - lib/rubygoo/goo_color.rb
         | 
| 85 85 | 
             
            - lib/rubygoo/goo_event.rb
         | 
| 86 86 | 
             
            - lib/rubygoo/label.rb
         | 
| 87 | 
            +
            - lib/rubygoo/mouse_cursor.rb
         | 
| 88 | 
            +
            - lib/rubygoo/rect.rb
         | 
| 87 89 | 
             
            - lib/rubygoo/text_field.rb
         | 
| 88 90 | 
             
            - lib/rubygoo/widget.rb
         | 
| 89 91 | 
             
            - samples/gosu_app.rb
         |