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-05-04 06:07:36 -07:00
|
|
|
orig_pixbuf = None
|
2008-03-10 04:56:40 -07:00
|
|
|
|
2008-05-04 06:07:36 -07:00
|
|
|
def __init__(self, pixbuf, img_size, use_reflection = False, quality = QUALITY_NORMAL, anchor = None):
|
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-05-04 06:07:36 -07:00
|
|
|
self.orig_pixbuf = pixbuf
|
|
|
|
|
2008-03-10 04:56:40 -07:00
|
|
|
|
|
|
|
self.main_pic = clutter.Texture()
|
2008-04-22 07:56:02 -07:00
|
|
|
self.reflection = None
|
|
|
|
#self.reflection = Texture_Reflection(self.main_pic)
|
2008-03-10 04:56:40 -07:00
|
|
|
|
2008-06-04 06:16:12 -07:00
|
|
|
self.set_pixbuf(pixbuf)
|
2008-03-20 17:08:38 -07:00
|
|
|
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
|
2008-06-04 06:16:12 -07:00
|
|
|
|
|
|
|
#Check to see whether the dimensions are already within 10% of the new ones
|
|
|
|
"""
|
|
|
|
height_max = int(pixbuf.get_height() * 1.1)
|
|
|
|
height_min = int(pixbuf.get_height() * 0.9)
|
|
|
|
width_max = int(pixbuf.get_width() * 1.1)
|
|
|
|
width_min = int(pixbuf.get_width() * 0.9)
|
|
|
|
#If not, perform the resize
|
|
|
|
if ((height < height_max) and (height > height_min)) or ((width < width_max) and (width > width_min)):
|
|
|
|
#Changed my mind, it has to be the exact right size
|
|
|
|
"""
|
|
|
|
if (height == pixbuf.get_height()) or (width == pixbuf.get_width()):
|
|
|
|
return pixbuf
|
|
|
|
else:
|
|
|
|
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):
|
2008-06-12 03:32:21 -07:00
|
|
|
self.orig_pixbuf = pixbuf
|
2008-03-30 04:58:56 -07:00
|
|
|
if pixbuf is None:
|
|
|
|
self.main_pic.hide()
|
|
|
|
if not self.reflection is None: self.reflection.hide()
|
|
|
|
return
|
|
|
|
else:
|
2008-06-04 06:16:12 -07:00
|
|
|
self.pixbuf = self.resize_pixbuf(pixbuf)
|
|
|
|
self.main_pic.set_pixbuf(self.pixbuf)
|
2008-03-30 04:58:56 -07:00
|
|
|
self.main_pic.set_position(self.x, self.y)
|
|
|
|
self.main_pic.show()
|
2008-03-26 15:31:52 -07:00
|
|
|
|
2008-03-30 04:58:56 -07:00
|
|
|
#For the most part the Reflection texture automatically takes car of pixbuf changes
|
|
|
|
#So we only need to set the flection the first time arouns (ie self.reflection is None)
|
2008-03-26 15:31:52 -07:00
|
|
|
if self.use_reflection:
|
2008-05-04 06:07:36 -07:00
|
|
|
self.set_reflection(True)
|
2008-03-26 15:31:52 -07:00
|
|
|
else:
|
2008-06-22 04:31:12 -07:00
|
|
|
self.reflection = None
|
2008-05-04 06:07:36 -07:00
|
|
|
|
|
|
|
#Turns reflections on and off
|
|
|
|
def set_reflection(self, toggle):
|
|
|
|
#If the current state is the requested state, do nothing
|
|
|
|
if self.reflection == toggle:
|
|
|
|
return
|
|
|
|
|
2008-06-15 05:29:44 -07:00
|
|
|
self.use_reflection = toggle
|
2008-06-22 04:31:12 -07:00
|
|
|
if self.use_reflection:
|
|
|
|
if not self.reflection is None:
|
|
|
|
self.remove(self.reflection)
|
|
|
|
self.reflection = None
|
|
|
|
self.reflection = Texture_Reflection(self.main_pic)
|
|
|
|
self.add(self.reflection)
|
|
|
|
self.reflection.show()
|
|
|
|
else:
|
2008-05-04 06:07:36 -07:00
|
|
|
self.remove(self.reflection)
|
|
|
|
self.reflection = None
|
|
|
|
|
2008-05-01 07:04:34 -07:00
|
|
|
def get_texture(self):
|
2008-05-04 06:07:36 -07:00
|
|
|
return self.main_pic
|
|
|
|
|
|
|
|
def get_width(self):
|
|
|
|
return self.img_size
|
|
|
|
def get_height(self):
|
|
|
|
return self.img_size
|