+ self._baseRect = rect.copy()
+ self.coords = coords
+ imagePath = InstrumentTile._get_instrument_image(name)
+ self._img = pygame.image.load(imagePath)
+ self.update()
+
+
+ def update(self) :
+ innerWidth, innerHeight = [l-self.BORDER*2 for l in self.rect.size]
+ innerSize = innerWidth, innerHeight
+
+ border = pygame.Surface(self.rect.size)
+ border.fill((0,0,0,255))
+
+ bg = pygame.Surface(innerSize)
+ bg.fill((255,255,255,255))
+ bgRect = pygame.Rect((self.BORDER, self.BORDER), innerSize)
+
+ img = self._img
+ iWidth, iHeight = img.get_size()
+ imgRatio = float(iWidth) / iHeight
+
+ # adapts dimensions
+ iw = innerWidth
+ ih = int(round(innerWidth / imgRatio))
+
+ if ih > innerHeight:
+ ih = innerHeight
+ iw = int(round(innerHeight * imgRatio))
+
+ imgPosition = ((innerWidth - iw) / 2, (innerHeight - ih) / 2)
+ imgRect = pygame.Rect(imgPosition, (iw, ih))
+ img = pygame.transform.smoothscale(img, (iw, ih))
+
+ bg.blit(img, imgRect)
+ border.blit(bg, bgRect)
+ self.image = border
+
+
+ def inflate(self, refPoint) :
+ self.inflated = True
+ keep = {}
+ for name in REF_POINTS[refPoint] :
+ keep[name] = getattr(self.rect, name)
+
+ self.rect.inflate_ip(*[l*self.INFLATE_ZOOM for l in self.rect.size])
+
+ for k, v in keep.items() :
+ setattr(self.rect, k, v)
+
+ self.update()
+ self.dirty = 1
+
+
+ def deflate(self) :
+ self.inflated = False
+ self.rect = self._baseRect.copy()
+ self.update()
+ self.dirty = 1
+
+
+
+REF_POINTS = {
+ (0, 0) : ['top', 'left'],
+ (1, 0) : ['top'],
+ (2, 0) : ['top', 'right'],
+
+ (0, 1) : ['left'],
+ (1, 1) : [],
+ (2, 1) : ['right'],
+
+ (0, 2) : ['bottom', 'left'],
+ (1, 2) : ['bottom'],
+ (2, 2) : ['bottom', 'right']
+}
\ No newline at end of file