Class: PREP::Core::Rectangle

Inherits:
Drawable show all
Defined in:
lib/core/rectangle.rb

Overview

矩形描画構成要素クラス

Direct Known Subclasses

ArcRectangle

Constant Summary collapse

STYLES =
{
  :solid => "solid",
}
FILL_PATTERNS =
{
  :flat => "flat",
}
@@default_values =
{
  :line_color      => { :red => 0, :green => 0, :blue => 0 },
  :line_width      => 1,
  :line_style      => STYLES[:solid],
  :fill_pattern    => FILL_PATTERNS[:flat],
  :fill_color      => { :red => 1, :green => 1, :blue => 1 },
  :layer           => 1,
  :expand          => false,
  :control_visible => false,
}

Instance Attribute Summary collapse

Attributes inherited from Drawable

#identifier, #layer

Instance Method Summary collapse

Methods inherited from Drawable

#<=>, #calculate_pos, #key_string_to_symbol, #rewind_current_page, #visible?

Constructor Details

#initialize(identifier, values = { }) ⇒ Rectangle

Returns a new instance of Rectangle.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/core/rectangle.rb', line 37

def initialize(identifier, values = { })
  values = @@default_values.merge(key_string_to_symbol(values))
  super(identifier, values[:layer])

  @region = Region.new(values[:region][:x].mm2pixcel,
                       values[:region][:y].mm2pixcel,
                       values[:region][:width].mm2pixcel,
                       values[:region][:height].mm2pixcel)
  @line_color = Color.new(values[:line_color][:red],
                          values[:line_color][:green],
                          values[:line_color][:blue])
  self.line_style = values[:line_style]
  self.fill_pattern = values[:fill_pattern]
  @fill_color = Color.new(values[:fill_color][:red],
                          values[:fill_color][:green],
                          values[:fill_color][:blue])
  self.line_width = values[:line_width]
  @expand = values[:expand]
  @control_visible = values[:control_visible]
end

Instance Attribute Details

#expandObject (readonly)

Returns the value of attribute expand.



35
36
37
# File 'lib/core/rectangle.rb', line 35

def expand
  @expand
end

#fill_colorObject (readonly)

Returns the value of attribute fill_color.



35
36
37
# File 'lib/core/rectangle.rb', line 35

def fill_color
  @fill_color
end

#fill_patternObject

Returns the value of attribute fill_pattern.



35
36
37
# File 'lib/core/rectangle.rb', line 35

def fill_pattern
  @fill_pattern
end

#line_colorObject (readonly)

Returns the value of attribute line_color.



35
36
37
# File 'lib/core/rectangle.rb', line 35

def line_color
  @line_color
end

#line_styleObject

Returns the value of attribute line_style.



35
36
37
# File 'lib/core/rectangle.rb', line 35

def line_style
  @line_style
end

#line_widthObject

Returns the value of attribute line_width.



35
36
37
# File 'lib/core/rectangle.rb', line 35

def line_width
  @line_width
end

#regionObject (readonly)

Returns the value of attribute region.



35
36
37
# File 'lib/core/rectangle.rb', line 35

def region
  @region
end

Instance Method Details

#calculate_region(prep, region, value, stop_on_drawable = nil) ⇒ Object



90
91
92
93
94
95
96
97
98
99
# File 'lib/core/rectangle.rb', line 90

def calculate_region(prep, region, value, stop_on_drawable = nil)
  if self === stop_on_drawable
    raise ReRenderJump.new(region)
  end
  puts "Calculate region for #{self.class}: #{self.identifier} region: #{region}" if ENV["DEBUG"]
  ret_region = Region.new(0, 0,
                          region.width - (@region.x + @region.width),
                          region.height - (@region.y + @region.height))
  return @region.x + @region.width, @region.y + @region.height
end

#draw(prep, region, values, stop_on_drawable = nil) ⇒ Object

矩形の描画



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/core/rectangle.rb', line 102

def draw(prep, region, values, stop_on_drawable = nil)
  if self === stop_on_drawable
    raise ReRenderJump.new(region)
  end
  STDERR.puts("Draw on #{self.class} #{self.identifier}") if ENV['DEBUG']
  # 領域判定
  calculate_region(prep, region, values)

  if visible?(values)
    prep.current_page.set_line_width(@line_width.to_f)
    unless @line_color.white?
      prep.current_page.set_rgb_stroke(@line_color.red.to_f,
                                       @line_color.green.to_f,
                                       @line_color.blue.to_f)
    end
    unless @fill_color.white?
      prep.current_page.set_rgb_fill(@fill_color.red.to_f,
                                     @fill_color.green.to_f,
                                     @fill_color.blue.to_f)
    end
  end

  region_backup = @region.dup
  if @expand_region
    @region = @expand_region.dup
    @expand_region = nil
  end
  pos_x, pos_y = calculate_pos(prep.current_page, region, @region.x, @region.y)

  if visible?(values)
    prep.current_page.rectangle(pos_x, pos_y - @region.height, @region.width, @region.height)
    fill_and_or_stroke(prep)
  end

  @region = region_backup
  prep.current_page.drawed = true
end

#expand_region(setting) ⇒ Object



58
59
60
61
62
# File 'lib/core/rectangle.rb', line 58

def expand_region(setting)
  @expand_region = @region.dup
  @expand_region.width = setting[:width] if setting[:width]
  @expand_region.height = setting[:height] if setting[:height]
end