Class: Shoes::Image

Inherits:
Basic show all
Defined in:
lib/shoes/basic.rb

Instance Attribute Summary collapse

Attributes inherited from Basic

#args, #cleared, #hided, #initials, #parent, #shows

Attributes included from Mod

#click_proc, #hover_proc, #hovered, #leave_proc, #margin_bottom, #margin_left, #margin_right, #margin_top, #release_proc

Instance Method Summary collapse

Methods inherited from Basic

#clear, #fix_size, #hide, #move, #move2, #move3, #positioning, #remove, #show, #style, #toggle

Methods included from Mod

#click, #hover, #leave, #release, #set_margin

Constructor Details

#initialize(args) ⇒ Image



145
146
147
148
149
# File 'lib/shoes/basic.rb', line 145

def initialize args
  @path = args[:path]
  args.delete :path
  super args      
end

Instance Attribute Details

#pathObject

Returns the value of attribute path



151
152
153
# File 'lib/shoes/basic.rb', line 151

def path
  @path
end

Instance Method Details

#rotate(angle) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/shoes/basic.rb', line 161

def rotate angle
  (@real_orig, @first_time = @real, true) unless @real_orig
  len = Math.sqrt @width**2 + @height**2
  surface = Cairo::ImageSurface.new Cairo::FORMAT_ARGB32, len, len
  context = Cairo::Context.new surface
  hlen, dleft, dtop = len/2.0, (len-width)/2.0, (len-height)/2.0
  context.save do
    pixbuf = @real_orig.pixbuf
    context.translate hlen, hlen
    context.rotate angle * Math::PI / 180
    context.translate -hlen, -hlen
    context.set_source_pixbuf pixbuf, dleft, dtop
    context.paint
  end
  remove
  @real = app.create_tmp_png surface
  app.canvas.put @real, 0, 0
  @real.show_now
  (@left -= dleft; @top -= dtop; @first_time = false) if @first_time
  move @left, @top
end