Class: Rubygoo::App
- Extended by:
- Publisher
- Defined in:
- lib/rubygoo/app.rb
Constant Summary collapse
- DEFAULT_PARAMS =
{:theme=>'default',:x=>10,:y=>10,:data_dir=>File.join(File.dirname(__FILE__),"..","..","themes"),:mouse_cursor => true}
Instance Attribute Summary collapse
-
#data_dir ⇒ Object
Returns the value of attribute data_dir.
-
#mouse ⇒ Object
Returns the value of attribute mouse.
-
#renderer ⇒ Object
Returns the value of attribute renderer.
-
#tab_groups ⇒ Object
Returns the value of attribute tab_groups.
-
#theme ⇒ Object
Returns the value of attribute theme.
-
#theme_dir ⇒ Object
Returns the value of attribute theme_dir.
-
#theme_name ⇒ Object
Returns the value of attribute theme_name.
Attributes inherited from Container
#bg_color, #queued_widgets, #rect, #widgets
Attributes inherited from Widget
#container, #enabled, #focus_priority, #focussed, #goo_id, #h, #mouse_over, #opts, #padding_left, #padding_top, #parent, #relative, #visible, #w, #x, #y
Instance Method Summary collapse
-
#add_modal(widget) ⇒ Object
redirects all events to this widget.
- #add_tab_group(tg) ⇒ Object
- #add_tabbed_widget(w) ⇒ Object
- #app ⇒ Object
- #draw(screen) ⇒ Object
- #focus(w) ⇒ Object
- #focus_back ⇒ Object
- #focus_forward ⇒ Object
-
#initialize(opts = {}, &block) ⇒ App
constructor
A new instance of App.
- #load_theme(theme_name) ⇒ Object
-
#modal_keyboard_call(meth, event) ⇒ Object
distribute our keyboard events to our modals first.
-
#modal_mouse_call(meth, event) ⇒ Object
distribute our mouse events to our modals first.
- #on_event(event) ⇒ Object
- #pop_tab_group ⇒ Object
- #remove_modal(widget) ⇒ Object
- #update(time) ⇒ Object
Methods inherited from Container
#_draw, #_key_pressed, #_key_released, #_mouse_down, #_mouse_drag, #_mouse_dragging, #_mouse_motion, #_mouse_up, #_update, #add, #added, #clear, #get, #remove, #resize, #tab_to?
Methods inherited from Widget
#_draw, #_focus, #_key_pressed, #_key_released, #_mouse_down, #_mouse_drag, #_mouse_dragging, #_mouse_motion, #_mouse_up, #_unfocus, #_update, #added, #contains?, #disable, #enable, #enabled?, #focussed?, #get, #get_color, goo_prop, #hide, inherited, #key_pressed, #key_released, #modal?, #mouse_down, #mouse_drag, #mouse_dragging, #mouse_enter, #mouse_exit, #mouse_motion, #mouse_over?, #mouse_up, #removed, #show, #tab_to?, #theme_property, #unfocus, #update_rect, #visible?
Methods included from Inflector
#camelize, #classify, #constantize, #dasherize, #demodulize, #foreign_key, #humanize, #inflections, #ordinalize, #pluralize, #singularize, #tableize, #titleize, #underscore
Constructor Details
#initialize(opts = {}, &block) ⇒ App
Returns a new instance of App.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rubygoo/app.rb', line 12 def initialize(opts={}, &block) merged_opts = DEFAULT_PARAMS.merge opts @widgets = [] @tab_groups = [] @tab_groups << TabGroup.new theme_name = merged_opts[:theme] @data_dir = merged_opts[:data_dir] @theme_name = theme_name @theme = load_theme theme_name @renderer = merged_opts[:renderer] # should this go here? @mouse_cursor = merged_opts[:mouse_cursor] if @mouse_cursor @mouse = MouseCursor.new @mouse.parent = self @mouse.app = self.app @mouse.added end @mouse_dragging = false super merged_opts, &block end |
Instance Attribute Details
#data_dir ⇒ Object
Returns the value of attribute data_dir.
10 11 12 |
# File 'lib/rubygoo/app.rb', line 10 def data_dir @data_dir end |
#mouse ⇒ Object
Returns the value of attribute mouse.
10 11 12 |
# File 'lib/rubygoo/app.rb', line 10 def mouse @mouse end |
#renderer ⇒ Object
Returns the value of attribute renderer.
10 11 12 |
# File 'lib/rubygoo/app.rb', line 10 def renderer @renderer end |
#tab_groups ⇒ Object
Returns the value of attribute tab_groups.
10 11 12 |
# File 'lib/rubygoo/app.rb', line 10 def tab_groups @tab_groups end |
#theme ⇒ Object
Returns the value of attribute theme.
10 11 12 |
# File 'lib/rubygoo/app.rb', line 10 def theme @theme end |
#theme_dir ⇒ Object
Returns the value of attribute theme_dir.
10 11 12 |
# File 'lib/rubygoo/app.rb', line 10 def theme_dir @theme_dir end |
#theme_name ⇒ Object
Returns the value of attribute theme_name.
10 11 12 |
# File 'lib/rubygoo/app.rb', line 10 def theme_name @theme_name end |
Instance Method Details
#add_modal(widget) ⇒ Object
redirects all events to this widget
122 123 124 125 126 127 128 |
# File 'lib/rubygoo/app.rb', line 122 def add_modal() @modal_widgets << tg = TabGroup.new tg.add() self.app.add_tab_group tg add end |
#add_tab_group(tg) ⇒ Object
61 62 63 |
# File 'lib/rubygoo/app.rb', line 61 def add_tab_group(tg) @tab_groups << tg end |
#add_tabbed_widget(w) ⇒ Object
57 58 59 |
# File 'lib/rubygoo/app.rb', line 57 def (w) @tab_groups[0].add w end |
#app ⇒ Object
37 38 39 |
# File 'lib/rubygoo/app.rb', line 37 def app() self end |
#draw(screen) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/rubygoo/app.rb', line 46 def draw(screen) @renderer.start_drawing _draw @renderer @mouse._draw @renderer if @mouse @renderer.finish_drawing end |
#focus(w) ⇒ Object
53 54 55 |
# File 'lib/rubygoo/app.rb', line 53 def focus(w) @tab_groups.last.focus w end |
#focus_back ⇒ Object
65 66 67 |
# File 'lib/rubygoo/app.rb', line 65 def focus_back() @tab_groups.last.previous end |
#focus_forward ⇒ Object
69 70 71 |
# File 'lib/rubygoo/app.rb', line 69 def focus_forward() @tab_groups.last.next end |
#load_theme(theme_name) ⇒ Object
41 42 43 44 |
# File 'lib/rubygoo/app.rb', line 41 def load_theme(theme_name) @theme_dir = File.join(@data_dir,theme_name) @theme = YAML::load_file(File.join(@theme_dir,"config.yml")) end |
#modal_keyboard_call(meth, event) ⇒ Object
distribute our keyboard events to our modals first
151 152 153 154 155 156 157 158 159 |
# File 'lib/rubygoo/app.rb', line 151 def modal_keyboard_call(meth, event) if @modal_widgets.empty? @widgets.select{|w|w.enabled? and w.focussed?}.each do |w| w.send meth, event end else @modal_widgets.last.send meth, event end end |
#modal_mouse_call(meth, event) ⇒ Object
distribute our mouse events to our modals first
140 141 142 143 144 145 146 147 148 |
# File 'lib/rubygoo/app.rb', line 140 def modal_mouse_call(meth, event) if @modal_widgets.empty? @widgets.select{|w|w.enabled? and (w.contains? event.data[:x],event.data[:y] or meth == :_mouse_motion) }.each do |w| w.send meth, event end else @modal_widgets.last.send meth, event end end |
#on_event(event) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/rubygoo/app.rb', line 73 def on_event(event) fire :evented, event case event.event_type when :key_released modal_keyboard_call :_key_released, event when :key_pressed case event.data[:key] when K_TAB if event.data[:mods].include? K_LSHIFT or event.data[:mods].include? K_RSHIFT focus_back else focus_forward end else modal_keyboard_call :_key_pressed, event end when :mouse_down modal_mouse_call :_mouse_down, event # TODO: I know this is simplistic and doesn't account for which button # is being pressed/released @mouse_start_x = event.data[:x] @mouse_start_y = event.data[:y] when :mouse_up x = event.data[:x] y = event.data[:y] if @mouse_start_x == x and @mouse_start_y == y modal_mouse_call :_mouse_up, event else event.data[:start_x] = @mouse_start_x event.data[:start_y] = @mouse_start_y modal_mouse_call :_mouse_drag, event end @mouse_start_x = nil @mouse_start_y = nil when :mouse_motion x = event.data[:x] y = event.data[:y] if @mouse_start_x event.data[:start_x] = @mouse_start_x event.data[:start_y] = @mouse_start_y modal_mouse_call :_mouse_dragging, event else modal_mouse_call :_mouse_motion, event end @mouse._mouse_motion event if @mouse end end |
#pop_tab_group ⇒ Object
135 136 137 |
# File 'lib/rubygoo/app.rb', line 135 def pop_tab_group() @tab_groups.pop end |
#remove_modal(widget) ⇒ Object
130 131 132 133 |
# File 'lib/rubygoo/app.rb', line 130 def remove_modal() self.app.pop_tab_group remove end |
#update(time) ⇒ Object
161 162 163 |
# File 'lib/rubygoo/app.rb', line 161 def update(time) _update(time) end |