Class: Shoes::Swt::ImagePattern

Inherits:
Object
  • Object
show all
Includes:
Common::ImageHandling, Common::Remove
Defined in:
shoes-swt/lib/shoes/swt/image_pattern.rb

Instance Method Summary collapse

Methods included from Common::ImageHandling

#cleanup_temporary_files, #load_file_image_data

Methods included from Common::Remove

#dispose_held_resources, #remove

Constructor Details

#initialize(dsl) ⇒ ImagePattern

Returns a new instance of ImagePattern.



9
10
11
# File 'shoes-swt/lib/shoes/swt/image_pattern.rb', line 9

def initialize(dsl)
  @dsl = dsl
end

Instance Method Details

#apply_as_fill(gc, _dsl) ⇒ Object



28
29
30
# File 'shoes-swt/lib/shoes/swt/image_pattern.rb', line 28

def apply_as_fill(gc, _dsl)
  gc.set_background_pattern pattern
end

#apply_as_stroke(gc, _dsl) ⇒ Object



32
33
34
# File 'shoes-swt/lib/shoes/swt/image_pattern.rb', line 32

def apply_as_stroke(gc, _dsl)
  gc.set_foreground_pattern pattern
end

#disposeObject



13
14
15
16
# File 'shoes-swt/lib/shoes/swt/image_pattern.rb', line 13

def dispose
  @image&.dispose
  @pattern&.dispose
end

#patternObject

Since colors are bound up (at least in specs) with image patterns, we can’t safely touch images during initialize, so lazily load them.



20
21
22
23
24
25
26
# File 'shoes-swt/lib/shoes/swt/image_pattern.rb', line 20

def pattern
  @image   ||= ::Swt::Image.new(Shoes.display, load_file_image_data(@dsl.path))
  @pattern ||= ::Swt::Pattern.new(Shoes.display, @image)
  cleanup_temporary_files

  @pattern
end