Class: Rabbit::ImageManipulable::Base
- Inherits:
-
Object
- Object
- Rabbit::ImageManipulable::Base
show all
- Extended by:
- ModuleLoader
- Defined in:
- lib/rabbit/image/base.rb
Constant Summary
ModuleLoader::LOADERS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
extend_object, find_loader, loaders, push_loader, unshift_loader
Constructor Details
#initialize(filename, props, canvas: nil) ⇒ Base
Returns a new instance of Base.
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/rabbit/image/base.rb', line 57
def initialize(filename, props, canvas: nil)
@filename = filename
@properties = Properties.new(props)
@canvas = canvas
initialize_keep_ratio
@animation = nil
@animation_iterator = nil
@animation_timeout = nil
update_size
@original_width = @width
@original_height = @height
end
|
Instance Attribute Details
#animation ⇒ Object
Returns the value of attribute animation.
55
56
57
|
# File 'lib/rabbit/image/base.rb', line 55
def animation
@animation
end
|
#filename ⇒ Object
Returns the value of attribute filename.
51
52
53
|
# File 'lib/rabbit/image/base.rb', line 51
def filename
@filename
end
|
#original_height ⇒ Object
Returns the value of attribute original_height.
54
55
56
|
# File 'lib/rabbit/image/base.rb', line 54
def original_height
@original_height
end
|
#original_width ⇒ Object
Returns the value of attribute original_width.
53
54
55
|
# File 'lib/rabbit/image/base.rb', line 53
def original_width
@original_width
end
|
#properties ⇒ Object
Returns the value of attribute properties.
52
53
54
|
# File 'lib/rabbit/image/base.rb', line 52
def properties
@properties
end
|
Class Method Details
.delegate ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/rabbit/image/base.rb', line 31
def delegate
extend Forwardable
def_delegators(:@delegated_loader,
:draw,
:ensure_resize,
:height,
:internal_pixbuf,
:keep_ratio,
:keep_ratio=,
:keep_ratio?,
:original_height,
:original_width,
:pixbuf,
:resize,
:update_size,
:width)
end
|
Instance Method Details
#[](key) ⇒ Object
70
71
72
|
# File 'lib/rabbit/image/base.rb', line 70
def [](key)
@properties[key]
end
|
#[]=(key, value) ⇒ Object
74
75
76
|
# File 'lib/rabbit/image/base.rb', line 74
def []=(key, value)
@properties[key] = value
end
|
#draw(canvas, x, y, params = {}) ⇒ Object
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/rabbit/image/base.rb', line 139
def draw(canvas, x, y, params={})
default_params = default_draw_params(x, y)
target_pixbuf = pixbuf
if @animation_iterator
@animation_iterator.advance
target_pixbuf = @animation_iterator.pixbuf
update_animation_timeout(canvas)
end
canvas.draw_pixbuf(target_pixbuf, x, y, default_params.merge(params))
end
|
#height ⇒ Object
97
98
99
100
|
# File 'lib/rabbit/image/base.rb', line 97
def height
(relative_clip_height&.resolve(@height) || @height) -
(relative_clip_y&.resolve(@height) || 0)
end
|
#keep_ratio=(value) ⇒ Object
84
85
86
|
# File 'lib/rabbit/image/base.rb', line 84
def keep_ratio=(value)
@properties.keep_ratio = value
end
|
#keep_ratio? ⇒ Boolean
Also known as:
keep_ratio
78
79
80
|
# File 'lib/rabbit/image/base.rb', line 78
def keep_ratio?
@properties.keep_ratio
end
|
#pixbuf ⇒ Object
88
89
90
|
# File 'lib/rabbit/image/base.rb', line 88
def pixbuf
@pixbuf
end
|
#relative_clip_height ⇒ Object
114
115
116
|
# File 'lib/rabbit/image/base.rb', line 114
def relative_clip_height
@properties.get_relative_size("relative_clip_height", @filename)
end
|
#relative_clip_width ⇒ Object
110
111
112
|
# File 'lib/rabbit/image/base.rb', line 110
def relative_clip_width
@properties.get_relative_size("relative_clip_width", @filename)
end
|
#relative_clip_x ⇒ Object
102
103
104
|
# File 'lib/rabbit/image/base.rb', line 102
def relative_clip_x
@properties.get_relative_size("relative_clip_x", @filename)
end
|
#relative_clip_y ⇒ Object
106
107
108
|
# File 'lib/rabbit/image/base.rb', line 106
def relative_clip_y
@properties.get_relative_size("relative_clip_y", @filename)
end
|
#resize(w, h) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/rabbit/image/base.rb', line 118
def resize(w, h)
if w.nil? and h.nil?
return
elsif keep_ratio?
if w and h.nil?
h = (original_height * w.to_f / original_width).ceil
elsif w.nil? and h
w = (original_width * h.to_f / original_height).ceil
end
else
w ||= width
h ||= height
end
w = w.ceil if w
h = h.ceil if h
if w and w > 0 and h and h > 0 and [w, h] != [width, height]
@width = w
@height = h
end
end
|
#width ⇒ Object
92
93
94
95
|
# File 'lib/rabbit/image/base.rb', line 92
def width
(relative_clip_width&.resolve(@width) || @width) -
(relative_clip_x&.resolve(@width) || 0)
end
|