+from GUI.RectangleWidget import RectangleWidget
import json
from dataclasses import dataclass
-import GUI.ImageWidget as ImageWidget
-import GUI.BasicButtonWidget as BasicButtonWidget
+from GUI.ImageWidget import ImageWidget
+from GUI.BasicButtonWidget import BasicButtonWidget
@dataclass
class Event:
props["fontSize"],
tuple(map(int, props["colour"].split(', ')))
)
+ elif widget["type"] == "Rectangle" :
+ props = widget["props"]
+ self.createRectangleWidget(
+ props["x"],
+ props["y"],
+ props["w"],
+ props["h"],
+ tuple(map(int, props["fillColour"].split(', '))),
+ props["opacity"],
+ props["border"],
+ props["borderThickness"],
+ tuple(map(int, props["borderColour"].split(', ')))
+ )
def createImageWidget(self, x, y, w, h, path, fit) -> None:
- self.widgetList.append(ImageWidget.ImageWidget(self, x, y, w, h, path, fit))
+ self.widgetList.append(ImageWidget(self, x, y, w, h, path, fit))
def createBasicButtonWidget(self, x, y, w, h, event, text, font, fontSize, colour) -> None:
- self.widgetList.append(BasicButtonWidget.BasicButtonWidget(self, x, y, w, h, event, text, font, fontSize, colour))
+ self.widgetList.append(BasicButtonWidget(self, x, y, w, h, event, text, font, fontSize, colour))
+
+ def createRectangleWidget(self, x, y, w, h, fillColour, opacity, border, borderThickness, borderColour):
+ self.widgetList.append(RectangleWidget(self, x, y, w, h, fillColour, opacity, border, borderThickness, borderColour))
def handleMouseEvent(self, mouseX, mouseY, mouseDown) -> None:
for widget in self.widgetList:
--- /dev/null
+import GUI.Widget as Widget
+import pygame
+
+class RectangleWidget(Widget.Widget):
+ def __init__(self, gui, x, y, w, h, fillColour, opacity, border,
+ borderThickness, borderColour) -> None:
+ super().__init__(gui)
+
+ self.screenX = x
+ self.screenY = y
+ self.screenW = w
+ self.screenH = h
+
+ self.fillColour = fillColour
+ self.opacity = opacity
+ self.border = border
+ self.borderThickness = borderThickness
+ self.borderColour = borderColour
+
+
+ self.surface = pygame.Surface((self.screenW, self.screenH))
+ self.surface.set_alpha(256 * self.opacity)
+ self.surface.fill(self.fillColour)
+
+ if self.border:
+ borderSurf = pygame.Surface((self.screenW, self.borderThickness))
+ borderSurf.fill(self.borderColour)
+ self.surface.blit(borderSurf, (0, 0))
+
+ borderSurf = pygame.Surface((self.screenW, self.borderThickness))
+ borderSurf.fill(self.borderColour)
+ self.surface.blit(borderSurf, (0, self.screenH - self.borderThickness))
+
+ borderSurf = pygame.Surface((self.borderThickness, self.screenH))
+ borderSurf.fill(self.borderColour)
+ self.surface.blit(borderSurf, (0, 0))
+
+ borderSurf = pygame.Surface((self.borderThickness, self.screenH))
+ borderSurf.fill(self.borderColour)
+ self.surface.blit(borderSurf, (self.screenW - self.borderThickness, 0))
\ No newline at end of file