Mercurial > fife-parpg
changeset 333:fee958103d58
* GuiImage now acts as Dummy Image if created without an argument.
* PyChan Image properties now allways return the GuiImage, annotated with a _source attribute.
* TwoButton.draw had a if branch that was never reached - fixed.
author | phoku@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 24 Aug 2009 14:41:52 +0000 |
parents | 457e626296ba |
children | a9482d3d989e |
files | engine/core/gui/base/gui_image.cpp engine/core/gui/widgets/twobutton.cpp engine/extensions/pychan/properties.py engine/extensions/pychan/widgets/icon.py |
diffstat | 4 files changed, 36 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/engine/core/gui/base/gui_image.cpp Mon Aug 24 13:23:03 2009 +0000 +++ b/engine/core/gui/base/gui_image.cpp Mon Aug 24 14:41:52 2009 +0000 @@ -51,10 +51,14 @@ } int GuiImage::getWidth() const { + if(m_poolid==Pool::INVALID_ID) + return 0; return m_pool->getImage(m_poolid).getWidth(); } int GuiImage::getHeight() const { + if(m_poolid==Pool::INVALID_ID) + return 0; return m_pool->getImage(m_poolid).getHeight(); } @@ -69,6 +73,6 @@ void GuiImage::convertToDisplayFormat() { // empty on purpose - // good idea? + // Since we don't need any conversions - this is just a proxy. } }
--- a/engine/core/gui/widgets/twobutton.cpp Mon Aug 24 13:23:03 2009 +0000 +++ b/engine/core/gui/widgets/twobutton.cpp Mon Aug 24 14:41:52 2009 +0000 @@ -54,7 +54,7 @@ } void TwoButton::draw(Graphics *graphics) { - Image* img = NULL; + Image* img = m_upImage; int xoffset = 0; int yoffset = 0; @@ -66,15 +66,10 @@ } } else if(mHasMouse) { if( m_hoverImage ) { - graphics->drawImage(m_hoverImage, 0, 0); - } - } else { - if( mHasMouse && m_hoverImage) { img = m_hoverImage; - } else if (m_upImage) { - img = m_upImage; } } + if (img) { graphics->drawImage(img, xoffset, yoffset); }
--- a/engine/extensions/pychan/properties.py Mon Aug 24 13:23:03 2009 +0000 +++ b/engine/extensions/pychan/properties.py Mon Aug 24 14:41:52 2009 +0000 @@ -69,11 +69,11 @@ color = self._getGetter(obj)() return fife.Color(color.r,color.g,color.b,color.a) -class DummyImage(object): - def getWidth(self): return 0 - def getHeight(self): return 0 - class ImageProperty(WrappedProperty): + """ + This unifies the way Images and Image attributes are handled + inside PyChan. + """ def __init__(self, name): super(ImageProperty, self).__init__(name) self.prop_name = "_prop_" + self.name.lower() @@ -81,7 +81,8 @@ image_info = getattr(obj, self.prop_name, {}) if not image: image_info["source"] = "" - image_info["image"] = DummyImage() + image_info["image"] = fife.GuiImage() + image_info["image"]._source = "" self._getSetter(obj)(None) elif isinstance(image, str): @@ -90,11 +91,17 @@ # we just let the NotFound exception trickle here. # depedning on complains we can catch and print a warning. image_info["image"] = get_manager().loadImage(image) + image_info["image"]._source = image self._getSetter(obj)(image_info["image"]) elif isinstance(image,fife.GuiImage): - image_info["source"] = None + # FIXME - this trickery with the hidden annotation + # with an _source attribute isn't really clean. + # Is it even necessary + image_info["source"] = getattr(image,"_source","") image_info["image"] = image + if image_info["source"]: + image_info["image"] = get_manager().loadImage(image) self._getSetter(obj)(image_info["image"]) else: attribute_name = "%s.%s" % (obj.__class__.__name__,self.name) @@ -104,5 +111,9 @@ setattr(obj, self.prop_name, image_info) def __get__(self, obj, objtype = None): - return getattr(obj, self.prop_name, {}).get("image",None) + d = getattr(obj, self.prop_name, {}) + image = d.get("image",None) + if not image: + image = fife.GuiImage() + return image
--- a/engine/extensions/pychan/widgets/icon.py Mon Aug 24 13:23:03 2009 +0000 +++ b/engine/extensions/pychan/widgets/icon.py Mon Aug 24 14:41:52 2009 +0000 @@ -24,6 +24,7 @@ from common import * from widget import Widget +from pychan.properties import ImageProperty class Icon(Widget): """ @@ -39,27 +40,20 @@ def __init__(self,image="",**kwargs): self.real_widget = fife.Icon(None) super(Icon,self).__init__(**kwargs) - self._source = self._image = None - if image: - self.image = image + self.image = image + + _image = ImageProperty("Image") def _setImage(self,source): - if isinstance(source,str): - self._source = source - self._image = get_manager().loadImage(source) - elif isinstance(source,fife.GuiImage): - self._source = None - self._image = source - else: - raise RuntimeError("Icon.image only accepts GuiImage and python strings, not '%s'" % repr(source)) - self.real_widget.setImage( self._image ) - - # Set minimum size accoriding to image + self._image = source + # This is a bit odd. + # ... not sure whether to leave the sizes alone, but that might + # break layouts. yikes. self.min_size = self.real_widget.getWidth(),self.real_widget.getHeight() - self.size = self.max_size = self.min_size + self.max_size = self.min_size + self.size = self.min_size + #print self._image, self.min_size, self.max_size def _getImage(self): - if self._source is not None: - return self._source return self._image image = property(_getImage,_setImage)