Class: GTK::Grid

Inherits:
Object show all
Includes:
Serialize
Defined in:
dragon/grid.rb

Constant Summary collapse

SCREEN_Y_DIRECTION =
-1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime) ⇒ Grid

Returns a new instance of Grid.


63
64
65
66
67
# File 'dragon/grid.rb', line 63

def initialize runtime
  @runtime = runtime
  @ffi_draw = runtime.ffi_draw
  origin_bottom_left!
end

Instance Attribute Details

#bottomFloat

Returns the “x” coordinate indicating the bottom of the screen.

Returns:


19
20
21
# File 'dragon/grid.rb', line 19

def bottom
  @bottom
end

#bottom_marginObject

Returns the value of attribute bottom_margin


61
62
63
# File 'dragon/grid.rb', line 61

def bottom_margin
  @bottom_margin
end

#center_xFloat

Returns the “x” coordinate indicating the center of the screen.

Returns:


39
40
41
# File 'dragon/grid.rb', line 39

def center_x
  @center_x
end

#center_yFloat

Returns the “y” coordinate indicating the center of the screen.

Returns:


44
45
46
# File 'dragon/grid.rb', line 44

def center_y
  @center_y
end

#leftFloat

Returns the “y” coordinate indicating the left of the screen.

Returns:


29
30
31
# File 'dragon/grid.rb', line 29

def left
  @left
end

#left_marginObject

Returns the value of attribute left_margin


61
62
63
# File 'dragon/grid.rb', line 61

def left_margin
  @left_margin
end

#nameSymbol

The coordinate system currently in use.

Returns:

  • (Symbol)

    `:bottom_left` or `:center`


14
15
16
# File 'dragon/grid.rb', line 14

def name
  @name
end

#origin_xFloat

Returns the “x” coordinate of the origin.

Returns:


54
55
56
# File 'dragon/grid.rb', line 54

def origin_x
  @origin_x
end

#origin_yFloat

Returns the “y” coordinate of the origin.

Returns:


59
60
61
# File 'dragon/grid.rb', line 59

def origin_y
  @origin_y
end

#rect[Float, Float, Float, Float]

Returns the bottom left and top right coordinates in a single list.

Returns:


49
50
51
# File 'dragon/grid.rb', line 49

def rect
  @rect
end

#rightFloat

Returns the “y” coordinate indicating the right of the screen.

Returns:


34
35
36
# File 'dragon/grid.rb', line 34

def right
  @right
end

#topFloat

Returns the “x” coordinate indicating the top of the screen.

Returns:


24
25
26
# File 'dragon/grid.rb', line 24

def top
  @top
end

Instance Method Details

#bottom_right[Float, Float]

Returns the coordinates indicating the bottom right of the screen.

Returns:


185
186
187
# File 'dragon/grid.rb', line 185

def bottom_right
  [@right, @bottom].point
end

#center[Float, Float]

Returns the coordinates indicating the center of the screen.

Returns:


178
179
180
# File 'dragon/grid.rb', line 178

def center
  @center
end

#ffi_drawObject


97
98
99
# File 'dragon/grid.rb', line 97

def ffi_draw
  @ffi_draw
end

#ffi_draw=(value) ⇒ Object


101
102
103
# File 'dragon/grid.rb', line 101

def ffi_draw= value
  @ffi_draw = value
end

#hFloat

The logical height used for rendering.

Returns:


164
165
166
# File 'dragon/grid.rb', line 164

def h
  @runtime.logical_height
end

#h_halfFloat

Half the logical height used for rendering.

Returns:


171
172
173
# File 'dragon/grid.rb', line 171

def h_half
  h.half
end

#origin_bottom_left!void

This method returns an undefined value.

Sets the rendering coordinate system to have its origin in the bottom left.


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'dragon/grid.rb', line 109

def origin_bottom_left!
  return if @name == :bottom_left
  @name = :bottom_left
  @origin_x = 0.0
  @origin_y = @runtime.logical_height
  @left   = 0.0
  @right  = @runtime.logical_width
  @top    = @runtime.logical_height
  @bottom = 0.0
  @left_margin = 0.0
  @bottom_margin = 0.0
  @center_x = @runtime.logical_width.half
  @center_y = @runtime.logical_height.half
  @rect   = [@left, @bottom, @runtime.logical_width, @runtime.logical_height].rect
  @center = [@center_x, @center_y].point
  @ffi_draw.set_grid @origin_x, @origin_y, SCREEN_Y_DIRECTION
end

#origin_center!void

This method returns an undefined value.

Sets the rendering coordinate system to have its origin in the center.


131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'dragon/grid.rb', line 131

def origin_center!
  return if @name == :center
  @name = :center
  @origin_x = @runtime.logical_width.half
  @origin_y = @runtime.logical_height.half
  @left   =  -@runtime.logical_width.half
  @right  =   @runtime.logical_width.half
  @top    =   @runtime.logical_height.half
  @bottom =  -@runtime.logical_height.half
  @center_x = 0.0
  @center_y = 0.0
  @rect   = [@left, @bottom, @runtime.logical_width, @runtime.logical_height].rect
  @center = [@center_x, @center_y].point
  @ffi_draw.set_grid @origin_x, @origin_y, SCREEN_Y_DIRECTION
end

#transform_x(x) ⇒ Float

Returns `x` plus the origin “x”.

Returns:


72
73
74
# File 'dragon/grid.rb', line 72

def transform_x x
  @origin_x + x
end

#transform_y(y) ⇒ Float

Returns `y` plus the origin “y”.

Returns:


86
87
88
# File 'dragon/grid.rb', line 86

def transform_y y
  @origin_y + y * SCREEN_Y_DIRECTION
end

#untransform_x(x) ⇒ Float

Returns `x` minus the origin “x”.

Returns:


79
80
81
# File 'dragon/grid.rb', line 79

def untransform_x x
  x - @origin_x
end

#untransform_y(y) ⇒ Float

Returns `y` minus the origin “y”.

Returns:


93
94
95
# File 'dragon/grid.rb', line 93

def untransform_y y
  @origin_y + y * SCREEN_Y_DIRECTION
end

#wFloat

The logical width used for rendering.

Returns:


150
151
152
# File 'dragon/grid.rb', line 150

def w
  @runtime.logical_width
end

#w_halfFloat

Half the logical width used for rendering.

Returns:


157
158
159
# File 'dragon/grid.rb', line 157

def w_half
  w.half
end