1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
9 ShadowData = Struct.new(:radius, :color, :grow, :offset)
11 ShadowData.new(7.0, Qt::Color.new(0x40, 0x40, 0x50), 5, Qt::PointF.new(6, 4))
13 def with_shadow(loader, data = DEFAULT_SHADOW_DATA)
14 lambda do |piece, size|
15 isz = size * 100 / (100 + data.grow) + Qt::Point.new(0.5, 0.5)
17 data.offset.x * isz.x / 200.0,
18 data.offset.y * isz.x / 200.0)
19 img = loader[piece, isz]
20 scaled_data = ShadowData.new(data.radius * isz.x / 100.0,
24 s = shadow(img, scaled_data)
25 Qt::Painter.new(s).paint do |p|
26 dst = Qt::Rect.new((size.x - isz.x) / 2 - off.x,
27 (size.y - isz.y) / 2 - off.y,
29 p.draw_image(dst, img, Qt::Rect.new(Qt::Point.new(0, 0), isz))
38 img = Qt::Image.painted(Qt::Point.new(img.width + data.grow,
39 img.height + data.grow)) do |p|
40 px = (data.grow * 0.5 + data.offset.x).to_i
41 py = (data.grow * 0.5 + data.offset.y).to_i
43 p.composition_mode = Qt::Painter::CompositionMode_Source
44 p.fill_rect Qt::Rect.new(px, py, img.width, img.height), data.color
45 p.composition_mode = Qt::Painter::CompositionMode_DestinationAtop
46 p.draw_image Qt::Point.new(px, py), img
48 img.exp_blur(data.radius)