Module: WindowPositionAndResizeActions
- Included in:
- GenericApplication
- Defined in:
- lib/generic_application.rb
Instance Method Summary collapse
- #absolutize_size(size, width_or_height) ⇒ Object
- #current_bounds ⇒ Object
- #height ⇒ Object
- #position(cardinal_point, opts = {}) ⇒ Object
- #position_top_left_corner_at(x, y, opts = {}) ⇒ Object
- #resize(w, h, opts = {}) ⇒ Object
- #transition_to_bounds(start_bounds, end_bounds) ⇒ Object
- #width ⇒ Object
Instance Method Details
#absolutize_size(size, width_or_height) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/generic_application.rb', line 106 def absolutize_size(size, width_or_height) if size.to_s[-1].chr == "%" OSX.send("desktop_#{width_or_height}") * (size.to_f / 100) else size end end |
#current_bounds ⇒ Object
37 38 39 |
# File 'lib/generic_application.rb', line 37 def current_bounds app.windows[0].bounds.get end |
#height ⇒ Object
74 75 76 77 |
# File 'lib/generic_application.rb', line 74 def height b = current_bounds b[3] - b[1] end |
#position(cardinal_point, opts = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/generic_application.rb', line 41 def position(cardinal_point, opts={}) x, y = nil, nil case cardinal_point when :north_east x = OSX.desktop_width - width y = 0 when :south_east x = OSX.desktop_width - width y = OSX.desktop_height - height when :north_west x, y = 0, 0 when :south_west x = 0 y = OSX.desktop_height - height end position_top_left_corner_at(x, y, opts) end |
#position_top_left_corner_at(x, y, opts = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/generic_application.rb', line 59 def position_top_left_corner_at(x, y, opts={}) b = current_bounds end_bounds = [x, y, x + width, y + height] if opts[:animate] transition_to_bounds(b, end_bounds) else app.windows[0].bounds.set(end_bounds) end end |
#resize(w, h, opts = {}) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/generic_application.rb', line 79 def resize(w, h, opts={}) b = current_bounds w = absolutize_size(w, :width) h = absolutize_size(h, :height) end_bounds = [ b[0], b[1], b[0] + w, b[1] + h ] if opts[:animate] transition_to_bounds(b, end_bounds) else app.windows[0].bounds.set(end_bounds) end end |
#transition_to_bounds(start_bounds, end_bounds) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/generic_application.rb', line 91 def transition_to_bounds(start_bounds, end_bounds) # puts "From #{start_bounds.inspect} to #{end_bounds.inspect}" steps = 50 factor = 100 / steps 1.upto(steps) do |step| frac = step.to_f * factor / 100 step_bounds = [] 0.upto(3) do |x| step_bounds[x] = start_bounds[x] + ((end_bounds[x] - start_bounds[x]) * frac) end # puts "bounds: #{step_bounds.inspect}" app.windows[0].bounds.set(step_bounds) end end |
#width ⇒ Object
69 70 71 72 |
# File 'lib/generic_application.rb', line 69 def width b = current_bounds b[2] - b[0] end |