-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaint_station_gui_layer.py
153 lines (114 loc) · 6.55 KB
/
paint_station_gui_layer.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import pygame
from paint_station_layer import Layer
from paint_station_config import Config
from paint_station_button import Button
class GuiLayer(Layer):
def __init__(self, app, surface):
Layer.__init__(self, app, surface)
self._config = Config()
button_step_y = 40
self.__undo_button = Button(app, self._surface, (8, 20 + 0 * button_step_y, 35, 35), '撤销', self.undo, 'icons/undo.png')
self._buttons.append(self.__undo_button)
self.__redo_button = Button(app, self._surface, (48, 20 + 0 * button_step_y, 35, 35), '重做', self.redo, 'icons/redo.png')
self._buttons.append(self.__redo_button)
self.__pattern0_button = Button(app, self._surface, (3, 20 + 1 * button_step_y + 8, 27, 27), '0', self.pattern0, 'icons/pattern_0.png')
self._buttons.append(self.__pattern0_button)
self.__pattern1_button = Button(app, self._surface, (31, 20 + 1 * button_step_y + 8, 27, 27), '1', self.pattern1, 'icons/pattern_1.png')
self._buttons.append(self.__pattern1_button)
self.__pattern2_button = Button(app, self._surface, (60, 20 + 1 * button_step_y + 8, 27, 27), '2', self.pattern2, 'icons/pattern_2.png')
self._buttons.append(self.__pattern2_button)
self.__pattern3_button = Button(app, self._surface, (3, 20 + 2 * button_step_y + 0, 27, 27), '3', self.pattern3, 'icons/pattern_3.png')
self._buttons.append(self.__pattern3_button)
self.__pattern4_button = Button(app, self._surface, (31, 20 + 2 * button_step_y + 0, 27, 27), '4', self.pattern4, 'icons/pattern_4.png')
self._buttons.append(self.__pattern4_button)
self.__pattern5_button = Button(app, self._surface, (60, 20 + 2 * button_step_y + 0, 27, 27), '5', self.pattern5, 'icons/pattern_5.png')
self._buttons.append(self.__pattern5_button)
self.__opaque_button = Button(app, self._surface, (16, 20 + 3 * button_step_y - 4, 27, 27), '不透明', self.opaque, 'icons/opaque.png')
self._buttons.append(self.__opaque_button)
self.__transparent_button = Button(app, self._surface, (46, 20 + 3 * button_step_y - 4, 27, 27), '透明', self.transparent, 'icons/transparent.png')
self._buttons.append(self.__transparent_button)
self.__brush_button = Button(app, self._surface, (13, 20 + 4 * button_step_y - 8, 65, 35), '笔刷', self.brush, 'icons/brush.png')
self._buttons.append(self.__brush_button)
#self.__fill_black_button = Button(app, self._surface, (8, 20 + 3 * button_step_y, 35, 35), '填充', self.fill_black, 'icons/fill_black.png')
#self._buttons.append(self.__fill_black_button)
self.__fill_white_button = Button(app, self._surface, (3, 20 + 5 * button_step_y + 6, 27, 27), '填充', self.fill_white, 'icons/fill_white.png')
self._buttons.append(self.__fill_white_button)
self.__openfile_button = Button(app, self._surface, (31, 20 + 5 * button_step_y + 6, 27, 27), '打开', self.open, 'icons/open.png')
self._buttons.append(self.__openfile_button)
self.__savefile_button = Button(app, self._surface, (60, 20 + 5 * button_step_y + 6, 27, 27), '保存', self.save, 'icons/save.png')
self._buttons.append(self.__savefile_button)
self.__print_button = Button(app, self._surface, (13, 20 + 6 * button_step_y, 65, 35), '打印', self.print, 'icons/print.png')
if self._config.could_print:
self._buttons.append(self.__print_button)
self.__quit_button = Button(app, self._surface, (13, 300, 13, 13), '退出', app.quit, 'icons/quit_small.png')
self._buttons.append(self.__quit_button)
self.pattern0()
self.opaque()
def paint(self):
pygame.draw.rect(self._surface, self._config.gui_background_color,
(0, 0, self._config.paint_pos_x, self._config.win_height))
pygame.draw.rect(self._surface, self._config.gui_background_color,
(0, 0, self._config.win_width, self._config.paint_pos_y))
pygame.draw.rect(self._surface, self._config.gui_background_color,
(0, self._config.paint_pos_y + self._config.paint_height,
self._config.win_width, self._config.win_height - self._config.paint_height))
pygame.draw.rect(self._surface, self._config.gui_background_color,
(self._config.paint_pos_x + self._config.paint_width, self._config.paint_pos_y,
self._config.win_width - self._config.paint_pos_x - self._config.paint_width,
self._config.paint_height))
Layer.paint(self)
def undo(self):
self._app.undo()
def redo(self):
self._app.redo()
def _uncheck_all_pattern_buttons(self):
self.__pattern0_button.is_checked = False
self.__pattern1_button.is_checked = False
self.__pattern2_button.is_checked = False
self.__pattern3_button.is_checked = False
self.__pattern4_button.is_checked = False
self.__pattern5_button.is_checked = False
def pattern0(self):
self._app.brush.set_pattern(0)
self._uncheck_all_pattern_buttons()
self.__pattern0_button.is_checked = True
def pattern1(self):
self._app.brush.set_pattern(1)
self._uncheck_all_pattern_buttons()
self.__pattern1_button.is_checked = True
def pattern2(self):
self._app.brush.set_pattern(2)
self._uncheck_all_pattern_buttons()
self.__pattern2_button.is_checked = True
def pattern3(self):
self._app.brush.set_pattern(3)
self._uncheck_all_pattern_buttons()
self.__pattern3_button.is_checked = True
def pattern4(self):
self._app.brush.set_pattern(4)
self._uncheck_all_pattern_buttons()
self.__pattern4_button.is_checked = True
def pattern5(self):
self._app.brush.set_pattern(5)
self._uncheck_all_pattern_buttons()
self.__pattern5_button.is_checked = True
def opaque(self):
self.__opaque_button.is_checked = True
self.__transparent_button.is_checked = False
self._app.brush.set_opaque(True)
def transparent(self):
self.__opaque_button.is_checked = False
self.__transparent_button.is_checked = True
self._app.brush.set_opaque(False)
def fill_black(self):
self._app.fill_black()
def fill_white(self):
self._app.fill_white()
def brush(self):
self._app.show_brush_dialog()
def open(self):
self._app.open()
def save(self):
self._app.save()
def print(self):
self._app.print()