Skip to content

Commit

Permalink
Added fill to shape
Browse files Browse the repository at this point in the history
  • Loading branch information
wasnotrice committed Apr 24, 2012
1 parent 7f420d1 commit cc61fc9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/shoes/element_methods.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def oval(*opts)
end end


# Creates a new Shoes::Shape object # Creates a new Shoes::Shape object
def shape(style={}, &blk) def shape(shape_style={}, &blk)
Shoes::Shape.new(style, blk) Shoes::Shape.new(style.merge(shape_style), blk)
end end


# Creates a new Shoes::Color object # Creates a new Shoes::Color object
Expand Down
7 changes: 5 additions & 2 deletions lib/swt_shoes/shape.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module SwtShoes
# @opts - options # @opts - options
# #
module Shape module Shape
attr_reader :gui_container attr_reader :gui_container, :gui_element
attr_reader :gui_element attr_reader :gui_paint_callback


# The initialization hook for SwtShoes. # The initialization hook for SwtShoes.
# #
Expand Down Expand Up @@ -45,7 +45,10 @@ def gui_init
@gui_element = @gui_opts[:element] || Swt::Path.new(Shoes.display) @gui_element = @gui_opts[:element] || Swt::Path.new(Shoes.display)
@gui_paint_callback = lambda do |event| @gui_paint_callback = lambda do |event|
gc = event.gc gc = event.gc
gc.set_background self.fill.to_native
gc.fill_path(@gui_element)
gc.set_antialias Swt::SWT::ON gc.set_antialias Swt::SWT::ON
gc.set_foreground self.stroke.to_native
gc.set_line_width self.style[:strokewidth] gc.set_line_width self.style[:strokewidth]
gc.draw_path(@gui_element) gc.draw_path(@gui_element)
end end
Expand Down
16 changes: 12 additions & 4 deletions spec/shoes/element_methods_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -52,14 +52,22 @@ def initialize
end end


describe "shape" do describe "shape" do
it "produces a Shoes::Shape" do let(:app) { ElementMethodsShoeLaces.new }
shape = ElementMethodsShoeLaces.new.shape do subject {
app.shape {
move_to 400, 300 move_to 400, 300
line_to 400, 200 line_to 400, 200
line_to 100, 100 line_to 100, 100
line_to 400, 300 line_to 400, 300
end }
shape.should be_an_instance_of(Shoes::Shape) }

it { should be_an_instance_of(Shoes::Shape) }

it "receives style from app" do
green = Shoes::COLORS.fetch :green
app.style[:stroke] = green
subject.stroke.should eq(green)
end end
end end


Expand Down
25 changes: 19 additions & 6 deletions spec/swt_shoes/shape_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@ def initialize(opts = {}, blk = nil )
let(:args_with_element) { {container: gui_container, element: gui_element} } let(:args_with_element) { {container: gui_container, element: gui_element} }
let(:args_without_element) { {container: gui_container} } let(:args_without_element) { {container: gui_container} }


before :each do
gui_container.should_receive(:add_paint_listener)
end

shared_examples_for "Swt::Shape" do shared_examples_for "Swt::Shape" do
before :each do before :each do
gui_element.stub(:move_to) gui_container.should_receive(:add_paint_listener)
end end


it "uses Swt and not White Shoes" do it "uses Swt and not White Shoes" do
Expand All @@ -43,7 +39,6 @@ def initialize(opts = {}, blk = nil )
subject { ShapeShoeLaces.new gui: args_with_element } subject { ShapeShoeLaces.new gui: args_with_element }


it_behaves_like "Swt::Shape" it_behaves_like "Swt::Shape"

end end


context "with gui container only" do context "with gui container only" do
Expand All @@ -52,10 +47,28 @@ def initialize(opts = {}, blk = nil )
it_behaves_like "Swt::Shape" it_behaves_like "Swt::Shape"


describe "gui_init" do describe "gui_init" do
before :each do
gui_container.should_receive(:add_paint_listener)
end

it "should not set current point on gui element" do it "should not set current point on gui element" do
gui_element.should_not_receive(:move_to) gui_element.should_not_receive(:move_to)
subject subject
end end
end end
end end

context "basic" do
subject {
Shoes::Shape.new(gui: args_without_element) {
move_to 150, 150
line_to 300, 300
line_to 0, 300
line to 150, 350
}
}

it_behaves_like "Swt object with stroke"
it_behaves_like "Swt object with fill"
end
end end

0 comments on commit cc61fc9

Please sign in to comment.