diff --git a/.gitignore b/.gitignore index b6e4761..39f5fce 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ __pycache__/ # Distribution / packaging .Python +.idea build/ develop-eggs/ dist/ diff --git a/UI/board.py b/UI/board.py new file mode 100644 index 0000000..a4f88db --- /dev/null +++ b/UI/board.py @@ -0,0 +1,40 @@ +import pygame.draw +from rounded_rect import draw_rounded_rect + + +class Board: + def __init__(self, size, bg_image): + self.fs = False + self.dp = [0, 0] + self.bg_image = bg_image + self.size = size + self.width = size[0] + self.height = size[1] + + self.width_fifth = self.width / 5 + self.small_size_fraction = sum(self.size) / 60 + self.mid_width = self.width - self.width_fifth - 2 * self.small_size_fraction + + self.height_sixth = self.height / 6 + + self.transparent_objects_color = (237, 237, 250) + + def draw_bg(self, display): + # drawing left rect + pygame.draw.rect(display, (49, 49, 54), pygame.Rect(0, 0, self.width_fifth, self.height)) + + # drawing bg image + display.blit(self.bg_image, [self.width_fifth, 0]) + + # drawing top and bottom rect + surf = pygame.Surface(self.size) + surf.fill((0, 0, 0)) + draw_rounded_rect(surf, pygame.Rect(self.width_fifth + self.small_size_fraction, + self.small_size_fraction, self.mid_width, + 100), + self.transparent_objects_color, int(self.height / 20)) + pygame.draw.rect(surf, self.transparent_objects_color, pygame.Rect(self.width_fifth, self.height - self.height_sixth, + self.width, self.height_sixth)) + surf.set_colorkey((0, 0, 0)) + surf.set_alpha(100) + display.blit(surf, [0, 0]) diff --git a/UI/board_bg.png b/UI/board_bg.png new file mode 100644 index 0000000..61cbe36 Binary files /dev/null and b/UI/board_bg.png differ diff --git a/UI/logo.png b/UI/logo.png new file mode 100644 index 0000000..623d0e5 Binary files /dev/null and b/UI/logo.png differ diff --git a/UI/main.py b/UI/main.py new file mode 100644 index 0000000..59c9667 --- /dev/null +++ b/UI/main.py @@ -0,0 +1,82 @@ +import pygame +from pygame.locals import * +import math +import numpy as np +import random +import time +import json +import os +import sys +import copy +from board import Board + + +# basic config +pygame.mixer.pre_init(48000, -16, 2, 512) +pygame.init() +pygame.mixer.set_num_channels(16) +available = pygame.font.get_fonts() +monitor_size = [pygame.display.Info().current_w, pygame.display.Info().current_h] + +font = pygame.font.SysFont('calibri', 60, True) +small_font = pygame.font.SysFont('calibri', 40, True) +tiny_font = pygame.font.SysFont('calibri', 20, True) + +Window_size = [1200, 800] +Default_size = Window_size +screen = pygame.display.set_mode(Window_size) +display = pygame.Surface(Window_size) +pygame.display.set_caption("School_board") +pygame.display.set_icon(pygame.image.load("logo.png").convert()) +clock = pygame.time.Clock() +Win_size = Window_size + + +alive = True +board = Board(Window_size, pygame.image.load("board_bg.png")) + +while alive: + + board.draw_bg(display) + + # event loop + + for event in pygame.event.get(): + if event.type == QUIT: + pygame.quit() + sys.exit(0) + + # keydown + elif event.type == KEYDOWN: + if event.key == K_ESCAPE: + pygame.quit() + sys.exit(0) + elif event.key == K_f: + board.fs = not board.fs + if board.fs is False: + Win_size = Default_size + screen = pygame.display.set_mode(Win_size) + board.dp = [0, 0] + else: + screen = pygame.display.set_mode(monitor_size, pygame.FULLSCREEN) + d = screen + ratio = [Default_size[1] / Default_size[0], Default_size[0] / Default_size[1]] + # u chose width or height here + + if Default_size[0] > Default_size[1]: + Win_size = [d.get_width(), int(d.get_width() * ratio[0])] + d = d.get_height() + dd = Win_size[1] + else: + Win_size = [int(d.get_height() * ratio[1]), d.get_height()] + d = pygame.display.get_surface().get_width() + dd = Win_size[0] + board.dp[0] = (d - dd) / 2 + + screen = screen + + # basic loop config + + screen.blit(pygame.transform.scale(display, Win_size), board.dp) + pygame.display.update() + clock.tick(10) diff --git a/UI/rounded_rect.py b/UI/rounded_rect.py new file mode 100644 index 0000000..58d8f3c --- /dev/null +++ b/UI/rounded_rect.py @@ -0,0 +1,52 @@ +import pygame.gfxdraw + + +def draw_rounded_rect(surface, rect, color, corner_radius): + if rect.width < 2 * corner_radius or rect.height < 2 * corner_radius: + raise ValueError(f"Both height (rect.height) and width (rect.width) must be > 2 * corner radius ({corner_radius})") + + # need to use anti aliasing circle drawing routines to smooth the corners + pygame.gfxdraw.aacircle(surface, rect.left+corner_radius, rect.top+corner_radius, corner_radius, color) + pygame.gfxdraw.aacircle(surface, rect.right-corner_radius-1, rect.top+corner_radius, corner_radius, color) + pygame.gfxdraw.aacircle(surface, rect.left+corner_radius, rect.bottom-corner_radius-1, corner_radius, color) + pygame.gfxdraw.aacircle(surface, rect.right-corner_radius-1, rect.bottom-corner_radius-1, corner_radius, color) + + pygame.gfxdraw.filled_circle(surface, rect.left+corner_radius, rect.top+corner_radius, corner_radius, color) + pygame.gfxdraw.filled_circle(surface, rect.right-corner_radius-1, rect.top+corner_radius, corner_radius, color) + pygame.gfxdraw.filled_circle(surface, rect.left+corner_radius, rect.bottom-corner_radius-1, corner_radius, color) + pygame.gfxdraw.filled_circle(surface, rect.right-corner_radius-1, rect.bottom-corner_radius-1, corner_radius, color) + + rect_tmp = pygame.Rect(rect) + + rect_tmp.width -= 2 * corner_radius + rect_tmp.center = rect.center + pygame.draw.rect(surface, color, rect_tmp) + + rect_tmp.width = rect.width + rect_tmp.height -= 2 * corner_radius + rect_tmp.center = rect.center + pygame.draw.rect(surface, color, rect_tmp) + + +def draw_bordered_rounded_rect(surface, rect, color, border_color, corner_radius, border_thickness): + if corner_radius < 0: + raise ValueError(f"border radius ({corner_radius}) must be >= 0") + + rect_tmp = pygame.Rect(rect) + center = rect_tmp.center + + if border_thickness: + if corner_radius <= 0: + pygame.draw.rect(surface, border_color, rect_tmp) + else: + draw_rounded_rect(surface, rect_tmp, border_color, corner_radius) + + rect_tmp.inflate_ip(-2*border_thickness, -2*border_thickness) + inner_radius = corner_radius - border_thickness + 1 + else: + inner_radius = corner_radius + + if inner_radius <= 0: + pygame.draw.rect(surface, color, rect_tmp) + else: + draw_rounded_rect(surface, rect_tmp, color, inner_radius) \ No newline at end of file