Skip to content

Commit

Permalink
Initial work for releasing colors on fill/stroke
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrclark committed May 8, 2014
1 parent a546688 commit f6ac67e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/shoes/swt/color.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def initialize(color)
@real = ::Swt::Graphics::Color.new(Shoes.display, @dsl.red, @dsl.green, @dsl.blue)
end

def dispose
@real.dispose unless @real.disposed?
end

attr_reader :dsl

# @return [Integer] the alpha value, from 0 (transparent) to 255 (opaque)
Expand Down
13 changes: 13 additions & 0 deletions lib/shoes/swt/common/clear.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@ def clear
app.remove_paint_listener @painter
remove_click_listeners
@real.dispose unless @real.nil? || @real.disposed?
dispose_held_resources
dispose
end

def mark_to_dispose(resource)
@to_dispose ||= []
@to_dispose << resource
end

def dispose_held_resources
return unless @to_dispose

@to_dispose.each(&:dispose)
@to_dispose.clear
end

# Classes should override to dispose of any Swt resources they create
def dispose
end
Expand Down
4 changes: 3 additions & 1 deletion lib/shoes/swt/common/fill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ module Fill
#
# @return [Swt::Graphics::Color] The Swt representation of this object's fill color
def fill
dsl.fill ? ::Shoes.configuration.backend_for(dsl.fill) : nil
fill_color = dsl.fill ? ::Shoes.configuration.backend_for(dsl.fill) : nil
mark_to_dispose(fill_color)
fill_color
end

# This object's fill alpha value
Expand Down
4 changes: 3 additions & 1 deletion lib/shoes/swt/common/stroke.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ module Stroke
#
# @return [Swt::Graphics::Color] The Swt representation of this object's stroke color
def stroke
dsl.stroke ? ::Shoes.configuration.backend_for(dsl.stroke) : nil
stroke_color = dsl.stroke ? ::Shoes.configuration.backend_for(dsl.stroke) : nil
mark_to_dispose(stroke_color)
stroke_color
end

# This object's stroke alpha value
Expand Down

0 comments on commit f6ac67e

Please sign in to comment.