(プログラムを実行したところ)
(画像一覧で画像を選択するとウィンドウ全体に表示される。再度クリックすると、
一覧表示に戻る。)
GNOME Developer Platform Demos にある clutter を利用したサンプル photo-wall.c をGenieで書き直してみました。
Genieで使い易いように、以下の箇所を変更しています。
・ファイルの読み込みには、gio libaryのGLib.FileとGLib.FileInfoを使用している。
・ファイルパスリストには、gee libraryのlistを使用している。
・imageの表示には、Clutter.ImageとGdk.Pixbufを使用している。
(写真は、「フリー写真素材 Futta.NET」の写真を利用しています。)
## image-viewer-gs.gs
uses
Clutter
stage : Stage
filename : string
image : Image
STAGE_WIDTH : int = 800
STAGE_HEIGHT : int = 600
THUMBNAIL_SIZE : int = 200
is_focused : bool = false
orig_x : float = 0.0f
orig_y : float = 0.0f
init
var IMAGE_DIR_PATH = "./images/"
if Clutter.init(ref args) != InitError.SUCCESS
print "Clutter init error"
stage = new Stage ()
stage.title = "ImageView"
stage.set_size (STAGE_WIDTH, STAGE_HEIGHT)
stage.set_user_resizable (true)
stage.destroy.connect(Clutter.main_quit)
var img_path_list = new list of string
try
var directory = File.new_for_path (IMAGE_DIR_PATH)
var enumerator = directory.enumerate_children (FileAttribute.STANDARD_NAME, 0)
file_info : FileInfo
while (file_info = enumerator.next_file ()) != null
filename = file_info.get_name ()
//stdout.printf ("%s\n", file_info.get_name ());
stdout.printf ("%s\n", filename)
img_path_list.add (filename)
except e:Error
print "Message: %s", e.message
//stdout.printf ("%s\n", filename)
print ""
for s in img_path_list
print s
var row_count = STAGE_WIDTH / THUMBNAIL_SIZE
var col_count = STAGE_HEIGHT / THUMBNAIL_SIZE
for var row = 0 to (row_count - 1)
for var col = 0 to (col_count - 1)
var s = img_path_list[row * col_count + col]
try
var pixbuf = new Gdk.Pixbuf.from_file (IMAGE_DIR_PATH + s)
image = new Image ()
image.set_data (pixbuf.get_pixels (),
pixbuf.has_alpha ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888,
pixbuf.width,
pixbuf.height,
pixbuf.rowstride)
except e:Error
print "Message: %s", e.message
var actor = new Actor ()
actor.content = image
actor.set_size (THUMBNAIL_SIZE, THUMBNAIL_SIZE)
actor.set_position (row * THUMBNAIL_SIZE, col * THUMBNAIL_SIZE)
actor.reactive = true
actor.button_press_event.connect (actor_clicked_cb)
stage.add_child (actor);
stage.show()
Clutter.main()
def actor_clicked_cb (actor:Actor, evt:ButtonEvent) : bool
print "Clicked"
print "x: %d", (int)actor.x
print "y: %d", (int)actor.y
print "z: %d", (int)actor.z_position
stage.remove_child (actor)
stage.add_child (actor)
if is_focused == false
orig_x = actor.x
orig_y = actor.y
print "orig_x: %d", (int)orig_x
print "orig_y: %d", (int)orig_y
if is_focused == false
actor.x = 0
actor.y = 0
actor.z_position = 10.0f
actor.reactive = true
actor.width = STAGE_WIDTH
actor.height = STAGE_HEIGHT
else
actor.x = orig_x
actor.y = orig_y
actor.z_position = 0.0f
actor.reactive = true
actor.width = THUMBNAIL_SIZE
actor.height = THUMBNAIL_SIZE
is_focused = !is_focused
return true
ビルド
valac --pkg clutter-1.0 --pkg gee-0.8 image-viewer-gs.gs