2008-03-10 04:56:40 -07:00
|
|
|
import pygtk
|
|
|
|
import gtk
|
|
|
|
import pango
|
|
|
|
import clutter
|
|
|
|
import os
|
2008-03-19 14:41:47 -07:00
|
|
|
from ui_elements.ReflectionTexture import Texture_Reflection
|
2008-03-10 04:56:40 -07:00
|
|
|
|
|
|
|
class ImageFrame(clutter.Group):
|
2008-03-20 17:08:38 -07:00
|
|
|
QUALITY_FAST, QUALITY_NORMAL, QUALITY_SLOW = range(3)
|
|
|
|
quality = QUALITY_NORMAL
|
2008-03-10 04:56:40 -07:00
|
|
|
|
2008-03-20 17:08:38 -07:00
|
|
|
def __init__(self, pixbuf, img_size, use_reflection = False, quality = QUALITY_NORMAL):
|
2008-03-10 04:56:40 -07:00
|
|
|
clutter.Group.__init__(self)
|
|
|
|
self.width = img_size
|
|
|
|
self.height = img_size
|
2008-03-20 17:08:38 -07:00
|
|
|
self.img_size = img_size
|
|
|
|
self.use_reflection = use_reflection
|
|
|
|
self.quality = quality
|
2008-03-10 04:56:40 -07:00
|
|
|
|
|
|
|
self.main_pic = clutter.Texture()
|
|
|
|
|
2008-03-20 17:08:38 -07:00
|
|
|
#If a reflection is desired, add it on
|
|
|
|
|
|
|
|
|
|
|
|
#pixbuf can be None, it just means that nothing appears initially
|
|
|
|
if pixbuf is None:
|
|
|
|
self.add(self.main_pic)
|
|
|
|
|
|
|
|
if use_reflection:
|
|
|
|
self.reflection = Texture_Reflection(self.main_pic)
|
|
|
|
self.add(self.reflection)
|
|
|
|
self.reflection.show()
|
|
|
|
else:
|
|
|
|
self.reflection = None
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
pixbuf = self.resize_pixbuf(pixbuf)
|
|
|
|
|
|
|
|
self.main_pic.set_pixbuf(pixbuf)
|
|
|
|
self.main_pic.set_position(self.x, self.y)
|
|
|
|
self.main_pic.show()
|
|
|
|
|
|
|
|
if use_reflection:
|
|
|
|
self.reflection = Texture_Reflection(self.main_pic)
|
|
|
|
self.add(self.reflection)
|
|
|
|
self.reflection.show()
|
|
|
|
else:
|
|
|
|
self.reflection = None
|
|
|
|
|
|
|
|
self.add(self.main_pic)
|
|
|
|
|
|
|
|
def resize_pixbuf(self, pixbuf):
|
2008-03-10 04:56:40 -07:00
|
|
|
#New method of resizing changes size of pixbuf rather than texture.... MUCH better performance :)
|
2008-03-20 17:08:38 -07:00
|
|
|
(self.x, self.y) = (0, 0)
|
2008-03-10 04:56:40 -07:00
|
|
|
if pixbuf.get_height() > pixbuf.get_width():
|
|
|
|
xy_ratio = float(pixbuf.get_width()) / pixbuf.get_height()
|
2008-03-20 17:08:38 -07:00
|
|
|
height = self.img_size
|
|
|
|
width = int(self.img_size * xy_ratio)
|
|
|
|
self.x = (self.img_size - width)/2
|
2008-03-10 04:56:40 -07:00
|
|
|
#x = int(cover_size / 2)
|
|
|
|
#x = x + (cover_size - width)
|
|
|
|
else:
|
|
|
|
xy_ratio = float(pixbuf.get_height()) / float(pixbuf.get_width())
|
2008-03-20 17:08:38 -07:00
|
|
|
width = self.img_size
|
|
|
|
height = int(self.img_size * xy_ratio)
|
|
|
|
self.y = (self.img_size - height)/2
|
2008-03-10 04:56:40 -07:00
|
|
|
#y = y + (cover_size - height)
|
|
|
|
|
2008-03-20 17:08:38 -07:00
|
|
|
#Set the conversion mode / quality
|
|
|
|
if self.quality == self.QUALITY_FAST: conversion_mode = gtk.gdk.INTERP_NEAREST #gtk.gdk.INTERP_TILES
|
|
|
|
elif self.quality == self.QUALITY_NORMAL: conversion_mode = gtk.gdk.INTERP_BILINEAR
|
|
|
|
elif self.quality == self.QUALITY_SLOW: conversion_mode = gtk.gdk.INTERP_HYPER
|
|
|
|
pixbuf = pixbuf.scale_simple(width, height, conversion_mode)
|
2008-03-10 04:56:40 -07:00
|
|
|
|
2008-03-20 17:08:38 -07:00
|
|
|
return pixbuf
|
|
|
|
|
|
|
|
def set_pixbuf(self, pixbuf):
|
|
|
|
pixbuf = self.resize_pixbuf(pixbuf)
|
|
|
|
self.main_pic.set_pixbuf(pixbuf)
|
|
|
|
self.main_pic.set_position(self.x, self.y)
|
|
|
|
self.main_pic.show()
|