| 1 |
|
| 2 |
|
| 3 |
)\ |
| 4 |
|
| 5 |
require 'environment' |
| 6 |
require 'mui/gtk_web_image_loader' |
| 7 |
require 'serialthread' |
| 8 |
require 'skin' |
| 9 |
|
| 10 |
require 'gtk3' |
| 11 |
require 'observer' |
| 12 |
|
| 13 |
レンダリングできる。 |
| 14 |
イメージが表示され、ロードが終了したら指定された画像が表示される。 |
| 15 |
、ストレージキャッシュがついてる。 |
| 16 |
module Gtk |
| 17 |
class WebIcon < Image |
| 18 |
DEFAULT_RECTANGLE = Gdk::Rectangle.new(0, 0, 48, 48) |
| 19 |
|
| 20 |
include Observable |
| 21 |
|
| 22 |
|
| 23 |
くはパス(String) |
| 24 |
le) または幅(px) |
| 25 |
高さ(px) |
| 26 |
def initialize(url, rect = DEFAULT_RECTANGLE, height = nil) |
| 27 |
rect = Gdk::Rectangle.new(0, 0, rect, height) if height |
| 28 |
case url |
| 29 |
when Diva::Model |
| 30 |
super(pixbuf: load_model(url, rect, set_loading_image: false)) |
| 31 |
when GdkPixbuf::Pixbuf |
| 32 |
super(pixbuf: url) |
| 33 |
else |
| 34 |
photo = Plugin.collect(:photo_filter, url, Pluggaloid::COLLECT).first |
| 35 |
super(pixbuf: load_model(photo || Skin[:notfound], rect, set_loading_image: false)) |
| 36 |
end |
| 37 |
end |
| 38 |
|
| 39 |
def load_model(photo, rect, set_loading_image: true) |
| 40 |
loading = photo.load_pixbuf(width: Gdk.scale(rect.width), height: Gdk.scale(rect.height)) do |pb| |
| 41 |
update_pixbuf(pb) |
| 42 |
end |
| 43 |
if set_loading_image |
| 44 |
self.pixbuf = loading |
| 45 |
end |
| 46 |
loading |
| 47 |
end |
| 48 |
|
| 49 |
def update_pixbuf(pixbuf) |
| 50 |
unless destroyed? |
| 51 |
self.pixbuf = pixbuf |
| 52 |
changed |
| 53 |
notify_observers |
| 54 |
end |
| 55 |
end |
| 56 |
end |
| 57 |
end |