from .loader import loader
from .constants import FONTS
-from .transforms import NullTransform
+from .transforms import NullTransform, Multiply
class Button(object):
self._padding = padding
self.position = pos
self.name = name
+ self.enabled = True
+
+ def enable(self):
+ self.enabled = True
+
+ def disable(self):
+ self.enabled = False
@property
def position(self):
pass
def pressed(self, ev):
+ if not self.enabled:
+ return False
if self._pos is None:
# Unplaced buttons can't be pressed
return False
def __init__(self, text, colour, name=None, pos=None, padding=10):
font = loader.load_font(FONTS['sans'], size=24)
self._text = font.render(text, True, colour)
+ self._disabled_text = self._text.copy()
+ Multiply(colour=(80, 80, 80)).apply(self._disabled_text)
super(TextButton, self).__init__(self._text.get_size(), name,
pos, padding)
def render(self, surface):
- surface.blit(self._text, self._pos, None)
+ if self.enabled:
+ surface.blit(self._text, self._pos, None)
+ else:
+ surface.blit(self._disabled_text, self._pos, None)
class ImageButton(Button):
def update_image(self, *imgparts, **kwargs):
transform = kwargs.pop("transform", NullTransform())
self._img = loader.load_image(*imgparts, transform=transform)
+ Multiply((128, 128, 128)).apply(self._disabled_img)
def render(self, surface):
surface.blit(self._img, self._pos, None)