Class: CTioga2::Graphics::Types::GridLayout
- Inherits:
-
Object
- Object
- CTioga2::Graphics::Types::GridLayout
- Defined in:
- lib/ctioga2/graphics/types/grid.rb
Overview
This class provides a grid-like layout through the use of a grid setup command and a grid box specification.
Instance Attribute Summary collapse
-
#delta_x ⇒ Object
The X offset to go from the right-hand side of one element to the left-hand-side of the next.
-
#delta_y ⇒ Object
The Y offset to go from the bottom of one element to the top of the next.
-
#hscales ⇒ Object
Horizontal scales.
-
#nup ⇒ Object
The nup: an array nb horizontal, nb vertical.
-
#outer_margins ⇒ Object
The margins (left, right, top, bottom) around the whole grid.
-
#vscales ⇒ Object
Vertical scales.
Class Method Summary collapse
Instance Method Summary collapse
-
#frame_coordinates(t, x, y) ⇒ Object
Compute the frame coordinates fo the x,y element of the grid.
-
#initialize(nup = "2x2") ⇒ GridLayout
constructor
A new instance of GridLayout.
Constructor Details
#initialize(nup = "2x2") ⇒ GridLayout
Returns a new instance of GridLayout.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/ctioga2/graphics/types/grid.rb', line 128 def initialize(nup = "2x2") if nup.respond_to?(:split) if nup =~ /,/ @hscales, @vscales = nup.split(/\s*x\s*/).map { |x| x.split(/\s*,\s*/).map { |y| y.to_f } } if @hscales.size == 1 @hscales = [1] * @hscales[0].to_i elsif @vscales.size == 1 @vscales = [1] * @vscales[0].to_i end @nup = [@hscales.size, @vscales.size] else @nup = nup.split(/\s*x\s*/).map { |s| s.to_i } end else @nup = nup.dup end # Initialize with the given @outer_margins = { 'left' => Dimension.new(:dy, 2.5, :x), 'right' => Dimension.new(:bp, 6, :x), 'bottom' => Dimension.new(:dy, 2.5, :y), 'top' => Dimension.new(:dy, 2.5, :y) } @delta_x = Dimension.new(:dy, 2.5, :x) @delta_y = Dimension.new(:dy, 2.5, :y) @hscales ||= [1] * @nup[0] @vscales ||= [1] * @nup[1] end |
Instance Attribute Details
#delta_x ⇒ Object
The X offset to go from the right-hand side of one element to the left-hand-side of the next
113 114 115 |
# File 'lib/ctioga2/graphics/types/grid.rb', line 113 def delta_x @delta_x end |
#delta_y ⇒ Object
The Y offset to go from the bottom of one element to the top of the next.
117 118 119 |
# File 'lib/ctioga2/graphics/types/grid.rb', line 117 def delta_y @delta_y end |
#hscales ⇒ Object
Horizontal scales
123 124 125 |
# File 'lib/ctioga2/graphics/types/grid.rb', line 123 def hscales @hscales end |
#nup ⇒ Object
The nup: an array nb horizontal, nb vertical
120 121 122 |
# File 'lib/ctioga2/graphics/types/grid.rb', line 120 def nup @nup end |
#outer_margins ⇒ Object
The margins (left, right, top, bottom) around the whole grid
109 110 111 |
# File 'lib/ctioga2/graphics/types/grid.rb', line 109 def outer_margins @outer_margins end |
#vscales ⇒ Object
Vertical scales
126 127 128 |
# File 'lib/ctioga2/graphics/types/grid.rb', line 126 def vscales @vscales end |
Class Method Details
.current_grid ⇒ Object
168 169 170 |
# File 'lib/ctioga2/graphics/types/grid.rb', line 168 def self.current_grid return @current_grid end |
.current_grid=(grid) ⇒ Object
164 165 166 |
# File 'lib/ctioga2/graphics/types/grid.rb', line 164 def self.current_grid=(grid) @current_grid = grid end |
Instance Method Details
#frame_coordinates(t, x, y) ⇒ Object
Compute the frame coordinates fo the x,y element of the grid. They are numbered from the top,left element.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/ctioga2/graphics/types/grid.rb', line 174 def frame_coordinates(t, x, y) compute_lengths(t) xo = if x > 0 @hscales[0..(x-1)].inject(0,:+) * @wbase else 0 end xl = @outer_margins['left'].to_frame(t, :x) + xo + x * @delta_x.to_frame(t, :x) yo = if y > 0 @vscales[0..(y-1)].inject(0,:+) * @hbase else 0 end yt = 1 - (@outer_margins['top'].to_frame(t, :y) + yo + y * @delta_y.to_frame(t, :y)) return [xl, yt, xl + @wbase * @hscales[x], yt - @hbase * @vscales[y]] end |