2004-05-25 22:13:04 -04:00
|
|
|
|
# -*- coding: iso-8859-1 -*-
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
# Name: bmpshape.py
|
|
|
|
|
# Purpose: Bitmap shape
|
|
|
|
|
#
|
|
|
|
|
# Author: Pierre Hj<48>lm (from C++ original by Julian Smart)
|
|
|
|
|
#
|
2004-06-02 16:49:09 -04:00
|
|
|
|
# Created: 2004-05-08
|
|
|
|
|
# RCS-ID: $Id$
|
2004-05-25 22:13:04 -04:00
|
|
|
|
# Copyright: (c) 2004 Pierre Hj<48>lm - 1998 Julian Smart
|
|
|
|
|
# Licence: wxWindows license
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
2004-06-04 16:12:01 -04:00
|
|
|
|
from _basic import RectangleShape
|
2004-05-25 22:13:04 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BitmapShape(RectangleShape):
|
|
|
|
|
"""Draws a bitmap (non-resizable)."""
|
|
|
|
|
def __init__(self):
|
|
|
|
|
RectangleShape.__init__(self, 100, 50)
|
2004-06-18 12:32:03 -04:00
|
|
|
|
self._filename = ""
|
2004-05-25 22:13:04 -04:00
|
|
|
|
|
|
|
|
|
def OnDraw(self, dc):
|
|
|
|
|
if not self._bitmap.Ok():
|
|
|
|
|
return
|
|
|
|
|
|
2004-06-18 12:32:03 -04:00
|
|
|
|
x = self._xpos - self._bitmap.GetWidth() / 2.0
|
|
|
|
|
y = self._ypos - self._bitmap.GetHeight() / 2.0
|
2004-05-25 22:13:04 -04:00
|
|
|
|
dc.DrawBitmap(self._bitmap, x, y, True)
|
|
|
|
|
|
|
|
|
|
def SetSize(self, w, h, recursive = True):
|
|
|
|
|
if self._bitmap.Ok():
|
|
|
|
|
w = self._bitmap.GetWidth()
|
|
|
|
|
h = self._bitmap.GetHeight()
|
|
|
|
|
|
|
|
|
|
self.SetAttachmentSize(w, h)
|
|
|
|
|
|
|
|
|
|
self._width = w
|
|
|
|
|
self._height = h
|
|
|
|
|
|
|
|
|
|
self.SetDefaultRegionSize()
|
|
|
|
|
|
|
|
|
|
def GetBitmap(self):
|
|
|
|
|
"""Return a the bitmap associated with this shape."""
|
|
|
|
|
return self._bitmap
|
|
|
|
|
|
|
|
|
|
def SetBitmap(self, bitmap):
|
|
|
|
|
"""Set the bitmap associated with this shape.
|
|
|
|
|
|
|
|
|
|
You can delete the bitmap from the calling application, since
|
|
|
|
|
reference counting will take care of holding on to the internal bitmap
|
|
|
|
|
data.
|
|
|
|
|
"""
|
|
|
|
|
self._bitmap = bitmap
|
|
|
|
|
if self._bitmap.Ok():
|
|
|
|
|
self.SetSize(self._bitmap.GetWidth(), self._bitmap.GetHeight())
|
|
|
|
|
|
|
|
|
|
def SetFilename(self, f):
|
|
|
|
|
"""Set the bitmap filename."""
|
|
|
|
|
self._filename = f
|
|
|
|
|
|
|
|
|
|
def GetFilename(self):
|
|
|
|
|
"""Return the bitmap filename."""
|
|
|
|
|
return self._filename
|