Class: Shortcut::Screen

Inherits:
Object
  • Object
show all
Defined in:
lib/shortcut/screen.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Screen

Returns a new instance of Screen.



10
11
12
13
14
15
16
17
# File 'lib/shortcut/screen.rb', line 10

def initialize(opts = {})
  dim = Toolkit.get_default_toolkit.get_screen_size
  opts = {:x => 0, :y => 0, :width => dim.get_width, :height => dim.get_height}.merge(opts)
  rectangle = Rectangle.new(opts[:x], opts[:y], opts[:width], opts[:height])

  @robot = Robot.new
  @image = @robot.create_screen_capture(rectangle)
end

Instance Method Details

#find_template(template) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/shortcut/screen.rb', line 33

def find_template(template)
  for x in 0...(@image.getWidth - template.getWidth)
    for y in 0...(@image.getHeight - template.getHeight)
      if loop_through_template(template, x, y)
        return Point.new(x, y)
      end
    end
  end

  return false
end

#get_color(x, y) ⇒ Object



24
25
26
# File 'lib/shortcut/screen.rb', line 24

def get_color(x, y)
  @image.getRGB(x, y)
end

#get_color_hex(x, y) ⇒ Object



28
29
30
31
# File 'lib/shortcut/screen.rb', line 28

def get_color_hex(x, y)
  color = get_color(x, y)
  sprintf("%02X%02X%02X", (color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF)
end

#save_image(pathname) ⇒ Object



19
20
21
22
# File 'lib/shortcut/screen.rb', line 19

def save_image(pathname)
  file = java::io::File.new(pathname)
  ImageIO.write(@image, "PNG", file)
end