-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbox.py
99 lines (79 loc) · 2.76 KB
/
box.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import flags
import pygame
from ops import *
from surface import Surface
from text import Text
class Box(Surface):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.button_bar = Surface(
parent=self,
position=(0, self.height - flags.square_size),
size=(flags.bar_size, flags.square_size)
)
self.body = Page(self)
self.buttons = []
for i in range(flags.bar_squares):
self.buttons.append(
Button(parent=self.button_bar, position=(i*flags.square_size, 0))
)
def initialize(self):
self.body.initialize()
for button in self.buttons:
button.print()
self.button_bar.print()
self.print()
def mouse(self, coords, pressed=False):
for button in self.buttons:
if button.contains(coords):
button.mouse(pressed=pressed)
elif button.is_hovered or button.is_pressed:
button.clear()
class Button(Surface):
def __init__(self, **kwargs):
if 'shape' not in kwargs:
kwargs['shape'] = [[1] + [0]*(flags.pixels_per_square - 1)]*(flags.pixels_per_square - 1) + \
[[1]*flags.pixels_per_square]
super().__init__(**kwargs)
self.is_hovered = False
self.is_pressed = False
def mouse(self, pressed=False):
self.is_hovered = not pressed
self.is_pressed = pressed
shape = [[0]*flags.pixels_per_square for _ in range(flags.pixels_per_square)]
for i in range(len(shape)):
for j in range(len(shape[i])):
val = self.shape[i][j]
shape[i][j] = val if val else (flags.dark_grey if pressed else flags.grey)
self.load_pixels(shape)
self.render()
def clear(self):
self.is_hovered = False
self.is_pressed = False
self.load_pixels(self.shape)
self.render()
class Page(Surface):
def __init__(self, parent=None, title='Page'):
super().__init__(
parent=parent,
size=(flags.bar_size, flags.box_size - flags.square_size),
)
self.title = title
self.title_block = Text(
parent=self,
font=flags.title_font,
)
self.body_block = Text(
parent=self,
justify_under=self.title_block,
no_margin='top',
margin=20
)
def initialize(self):
self.fill(flags.white)
self.title_block.print_text(self.title)
self.body_block.print_text(self.body)
self.print()
@property
def body(self):
return 'body '*50