Permalink
Browse files

Added fill to shape

  • Loading branch information...
1 parent 7f420d1 commit cc61fc9a15d8f50617e3f6cffc4a593d7778b630 @wasnotrice wasnotrice committed Apr 24, 2012
Showing with 38 additions and 14 deletions.
  1. +2 −2 lib/shoes/element_methods.rb
  2. +5 −2 lib/swt_shoes/shape.rb
  3. +12 −4 spec/shoes/element_methods_spec.rb
  4. +19 −6 spec/swt_shoes/shape_spec.rb
@@ -88,8 +88,8 @@ def oval(*opts)
end
# Creates a new Shoes::Shape object
- def shape(style={}, &blk)
- Shoes::Shape.new(style, blk)
+ def shape(shape_style={}, &blk)
+ Shoes::Shape.new(style.merge(shape_style), blk)
end
# Creates a new Shoes::Color object
@@ -8,8 +8,8 @@ module SwtShoes
# @opts - options
#
module Shape
- attr_reader :gui_container
- attr_reader :gui_element
+ attr_reader :gui_container, :gui_element
+ attr_reader :gui_paint_callback
# The initialization hook for SwtShoes.
#
@@ -45,7 +45,10 @@ def gui_init
@gui_element = @gui_opts[:element] || Swt::Path.new(Shoes.display)
@gui_paint_callback = lambda do |event|
gc = event.gc
+ gc.set_background self.fill.to_native
+ gc.fill_path(@gui_element)
gc.set_antialias Swt::SWT::ON
+ gc.set_foreground self.stroke.to_native
gc.set_line_width self.style[:strokewidth]
gc.draw_path(@gui_element)
end
@@ -52,14 +52,22 @@ def initialize
end
describe "shape" do
- it "produces a Shoes::Shape" do
- shape = ElementMethodsShoeLaces.new.shape do
+ let(:app) { ElementMethodsShoeLaces.new }
+ subject {
+ app.shape {
move_to 400, 300
line_to 400, 200
line_to 100, 100
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
@@ -20,13 +20,9 @@ def initialize(opts = {}, blk = nil )
let(:args_with_element) { {container: gui_container, element: gui_element} }
let(:args_without_element) { {container: gui_container} }
- before :each do
- gui_container.should_receive(:add_paint_listener)
- end
-
shared_examples_for "Swt::Shape" do
before :each do
- gui_element.stub(:move_to)
+ gui_container.should_receive(:add_paint_listener)
end
it "uses Swt and not White Shoes" do
@@ -43,7 +39,6 @@ def initialize(opts = {}, blk = nil )
subject { ShapeShoeLaces.new gui: args_with_element }
it_behaves_like "Swt::Shape"
-
end
context "with gui container only" do
@@ -52,10 +47,28 @@ def initialize(opts = {}, blk = nil )
it_behaves_like "Swt::Shape"
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
gui_element.should_not_receive(:move_to)
subject
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

0 comments on commit cc61fc9

Please sign in to comment.