Skip to content

Commit 1ebed95

Browse files
Added borders to backgrounds and "x" button
1 parent 4f40feb commit 1ebed95

File tree

4 files changed

+54
-29
lines changed

4 files changed

+54
-29
lines changed

Button/remove.png

16.5 KB
Loading

Button/remove_hover.png

37 KB
Loading

UI/UI.py

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,6 @@ def display_options_button(window, screen_group, options_screen_group):
6161
# TODO: Crop image properly using Figma
6262
screen_group.add(Wrapper.Button((options_button_1, options_button_2), ((window.window.get_size()[0])-40, 40), display_options, window, False, Wrapper.Screen.NONE))
6363

64-
'''@args = options_group should be passed in first, then screen_group'''
65-
def display_options(window, options_group):
66-
# Constants
67-
OPTIONS_WIDTH = 300
68-
OPTIONS_HEIGHT = 300
69-
70-
# Switch on options
71-
window.options_screen = True
72-
options_group.empty()
73-
74-
# Draw everything
75-
options_group.add(Wrapper.Background((window.window.get_size()[0]/2, window.window.get_size()[1]/2), (OPTIONS_WIDTH, OPTIONS_HEIGHT), Wrapper.Colors.SMALL_BACKGROUND_COLOR))
76-
77-
# Where the text starts rendering
78-
text_start = window.window.get_size()[1]/2 - OPTIONS_HEIGHT/2 + 50
79-
80-
options_group.add(Wrapper.Text(Wrapper.DefaultText.text("Options", Wrapper.FontSizes.TITLE_SIZE), (window.window.get_size()[0]/2, text_start), window, False, Wrapper.Screen.NONE))
81-
close_options = Wrapper.add_args_to_func(OptionActions.close_options, window, options_group)
82-
press_main_menu = Wrapper.add_args_to_func(OptionActions.press_main_menu, window, options_group)
83-
options_group.add(Wrapper.TextButton(Wrapper.DefaultText.text("Return", Wrapper.FontSizes.BUTTON_SIZE), (window.window.get_size()[0]/2, text_start + 100), close_options, window, False, Wrapper.Screen.NONE))
84-
options_group.add(Wrapper.TextButton(Wrapper.DefaultText.text("Main Menu", Wrapper.FontSizes.BUTTON_SIZE), (window.window.get_size()[0]/2, text_start + 175), press_main_menu, window, False, Wrapper.Screen.NONE))
85-
8664
# Input (specifically buttons)
8765

8866
'''@args = options_group'''
@@ -102,6 +80,33 @@ def press_main_menu(window, options_group):
10280
window.screen_change = True
10381
window.options_screen = False
10482

83+
'''@args = options_group should be passed in first, then screen_group'''
84+
def display_options(window, options_group):
85+
# Constants
86+
OPTIONS_WIDTH = 300
87+
OPTIONS_HEIGHT = 300
88+
89+
# Switch on options
90+
window.options_screen = True
91+
options_group.empty()
92+
93+
# Draw everything
94+
options_group.add(Wrapper.Background((window.window.get_size()[0]/2, window.window.get_size()[1]/2), (OPTIONS_WIDTH, OPTIONS_HEIGHT), Wrapper.Colors.SMALL_BACKGROUND_COLOR, 3, window))
95+
96+
# Where the text starts rendering
97+
text_start = window.window.get_size()[1]/2 - OPTIONS_HEIGHT/2 + 50
98+
99+
exit_1 = pygame.image.load('Button/remove.png').convert_alpha()
100+
exit_1 = pygame.transform.rotozoom(exit_1, 0, 0.05)
101+
exit_2 = pygame.image.load('Button/remove_hover.png').convert_alpha()
102+
exit_2 = pygame.transform.rotozoom(exit_2, 0, 0.05)
103+
close_options = Wrapper.add_args_to_func(OptionActions.close_options, window, options_group)
104+
press_main_menu = Wrapper.add_args_to_func(OptionActions.press_main_menu, window, options_group)
105+
options_group.add(Wrapper.Button((exit_1, exit_2), (window.window.get_size()[0]/2 + OPTIONS_WIDTH/2 - 25, text_start - 25), close_options, window, False, Wrapper.Screen.NONE))
106+
107+
options_group.add(Wrapper.Text(Wrapper.DefaultText.text("Options", Wrapper.FontSizes.TITLE_SIZE), (window.window.get_size()[0]/2, text_start), window, False, Wrapper.Screen.NONE))
108+
options_group.add(Wrapper.TextButton(Wrapper.DefaultText.text("Main Menu", Wrapper.FontSizes.BUTTON_SIZE), (window.window.get_size()[0]/2, text_start + 75), press_main_menu, window, False, Wrapper.Screen.NONE))
109+
105110
'''TODO: These classes are inconsistent with being entirely static and being an instance based class. Make it consistent
106111
so initalization is consistent'''
107112
class SortingActions():
@@ -284,24 +289,31 @@ def toggle_aux_array(self):
284289
def show_advanced(self):
285290
# Constants
286291
OPTIONS_WIDTH = 300
287-
OPTIONS_HEIGHT = 400
292+
OPTIONS_HEIGHT = 300
288293

289294
# Switch on options
290295
self.window.options_screen = True
291296

292-
# Draw everything
293-
self.options_group.empty()
294-
self.options_group.add(Wrapper.Background((self.window.window.get_size()[0]/2, self.window.window.get_size()[1]/2), (OPTIONS_WIDTH, OPTIONS_HEIGHT), Wrapper.Colors.SMALL_BACKGROUND_COLOR))
295-
296297
# Where the text starts rendering
297298
text_start = self.window.window.get_size()[1]/2 - OPTIONS_HEIGHT/2 + 50
299+
300+
# Draw everything
301+
self.options_group.empty()
302+
self.options_group.add(Wrapper.Background((self.window.window.get_size()[0]/2, self.window.window.get_size()[1]/2), (OPTIONS_WIDTH, OPTIONS_HEIGHT), Wrapper.Colors.SMALL_BACKGROUND_COLOR, 3, self.window))
298303

304+
# Exit button
305+
exit_1 = pygame.image.load('Button/remove.png').convert_alpha()
306+
exit_1 = pygame.transform.rotozoom(exit_1, 0, 0.05)
307+
exit_2 = pygame.image.load('Button/remove_hover.png').convert_alpha()
308+
exit_2 = pygame.transform.rotozoom(exit_2, 0, 0.05)
309+
self.options_group.add(Wrapper.Button((exit_1, exit_2), (self.window.window.get_size()[0]/2 + OPTIONS_WIDTH/2 - 25, text_start - 25), self.close_window, self.window, False, Wrapper.Screen.NONE))
310+
299311
self.options_group.add(Wrapper.Text(Wrapper.DefaultText.text("Time Delay", Wrapper.FontSizes.SUB_TITLE_SIZE), (self.window.window.get_size()[0]/2, text_start), self.window, False, Wrapper.Screen.NONE))
300312
self.delay_textbox = Wrapper.TextBox(Wrapper.TextArgs(str(self.array.delay), Wrapper.Fonts(Wrapper.FontSizes.BUTTON_SIZE).UBUNTU_FONT, True, "#000000"), (self.window.window.get_size()[0]/2, text_start + 50), (200, 50), lambda a : self.array.change_delay(a), self.window, " secs", 1)
301313

302314
self.options_group.add(Wrapper.Text(Wrapper.DefaultText.text("Array Size", Wrapper.FontSizes.SUB_TITLE_SIZE), (self.window.window.get_size()[0]/2, text_start + 100), self.window, False, Wrapper.Screen.NONE))
303315
self.size_textbox = Wrapper.TextBox(Wrapper.TextArgs(str(self.array.size), Wrapper.Fonts(Wrapper.FontSizes.BUTTON_SIZE).UBUNTU_FONT, True, "#000000"), (self.window.window.get_size()[0]/2, text_start + 150), (200, 50), lambda a : self.array.change_size(a), self.window, "", 1)
304-
self.options_group.add(Wrapper.TextButton(Wrapper.DefaultText.text("Return", Wrapper.FontSizes.BUTTON_SIZE), (self.window.window.get_size()[0]/2, text_start + 210), self.close_window, self.window, False, Wrapper.Screen.NONE))
316+
305317
self.text_box_group.add(self.delay_textbox)
306318
self.text_box_group.add(self.size_textbox)
307319

@@ -321,6 +333,8 @@ def close_window(self):
321333
def custom_array(self):
322334
tkinter.Tk().withdraw() # prevents an empty tkinter window from appearing
323335
self.file = filedialog.askopenfilename()
336+
if (self.file == ''):
337+
return
324338
f = open(self.file, 'r')
325339
self.array_config.clear()
326340
self.list.clear()

UI/Wrapper.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Colors():
3535
TEXT_COLOR = "#E0E1DD"
3636
BACKGROUND_SCROLL_COLOR = BUTTON_COLOR
3737
SCROLLBAR_COLOR = TEXT_COLOR
38+
DEFAULT_BORDER_COLOR = TEXT_COLOR
3839

3940
class FontSizes():
4041
BUTTON_SIZE = 25
@@ -613,17 +614,27 @@ class Background(pygame.sprite.Sprite):
613614
@color = the color that the background will be in
614615
@coords = the coordinates where the rectangle will be centered at
615616
@dim = the dimensions of the rectangle
617+
@window = window class
616618
'''
617-
def __init__(self, coords, dim, color):
619+
def __init__(self, coords, dim, color, border_width = 0, window = None, border_color = Colors.DEFAULT_BORDER_COLOR):
618620
super().__init__()
619621
self.image = pygame.Surface(dim)
620622
self.color = color
621623
self.rect = self.image.get_rect(center = coords)
622624
self.coords = coords
623625
self.image.fill(color)
626+
self.border_width = border_width
627+
self.border_color = border_color
628+
self.window = window
624629

625630
def update(self):
626631
self.rect = self.image.get_rect(center = self.coords)
632+
top_left = self.rect.topleft
633+
if (self.border_width != 0):
634+
pygame.draw.rect(self.window.window, self.border_color, [top_left[0], top_left[1], self.rect.width, self.border_width])
635+
pygame.draw.rect(self.window.window, self.border_color, [top_left[0], top_left[1] + self.rect.height, self.rect.width, self.border_width])
636+
pygame.draw.rect(self.window.window, self.border_color, [top_left[0], top_left[1], self.border_width, self.rect.height])
637+
pygame.draw.rect(self.window.window, self.border_color, [top_left[0] + self.rect.width, top_left[1], self.border_width, self.rect.height + self.border_width])
627638

628639
def change_color(self, color):
629640
self.color = color

0 commit comments

Comments
 (0)