-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpclass.py
171 lines (127 loc) · 7.7 KB
/
pclass.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# ************************************************************************************************#
# ************************************************************************************************#
# Directory Structure
# ************************************************************************************************#
# ************************************************************************************************#
# /photonmain.py # primary program
# /pgvar.py # global variable declarations
# /pgui.py # photon gui elements and buttons
# /pfunc.py # functions
# /pclass.py # button processing class that handles drawing / displaying UI
# /pbproc.py # processing sticky, group, dropdown etc button actions
# /photon_ref.py # references, dev notes, style guide, modification instructions
# pclass.py
moduleName = "pclass.py"
# ************************************************************************************************#
# ************************************************************************************************#
# Import Modules
# ************************************************************************************************#
# ************************************************************************************************#
# # public python modules
import pygame
import random
import math
import sys
import time # for FPS functions
import inspect # for displaying the line number of the code in print commands
# # unique modules for this app
import pgvar
#import pfunc
import pgui
#import pclass
#import pbproc
# ************************************************************************************************#
# ************************************************************************************************#
# initialize variables
# ************************************************************************************************#
# ************************************************************************************************#
screen = pygame.display.set_mode((pgvar.pygame_window_width, pgvar.pygame_window_height))
myfont = pgvar.myfont
# ************************************************************************************************************************
# ************************************************************************************************************************
# Classes #
# ************************************************************************************************************************
# ************************************************************************************************************************
class Button:
def __init__ (self, (x,y), button_name, x_width, y_height, button_label_txt, buttonType, buttonEnabled, buttonColor, buttonVisible):
self.button_name = button_name
self.x = x
self.x_width = x_width
self.y = y
self.y_height = y_height
self.color = buttonColor
self.thickness = 0
self.button_label_txt = button_label_txt
self.colorBorder = pgvar.UI_button_border_color
self.buttonType = buttonType
self.buttonEnabled = buttonEnabled
self.buttonVisible = buttonVisible
# # displays buttons
def display(self):
# render "pushy" type buttons
if self.buttonType == "pushy":
pygame.draw.rect(screen, self.color, (self.x, self.y, self.x_width, self.y_height)) #button
pygame.draw.rect(screen, self.colorBorder, (self.x, self.y, self.x_width, self.y_height), 3) #border
label = myfont.render(str(self.button_label_txt), 0, pgvar.UI_button_txt_color)
screen.blit(label, (self.x + 5, self.y))
# render "sticky" type buttons
elif self.buttonType == "sticky":
pygame.draw.rect(screen, self.color, (self.x, self.y, self.x_width, self.y_height)) #button
pygame.draw.rect(screen, self.colorBorder, (self.x, self.y, self.x_width, self.y_height), 3) #border
label = myfont.render(str(self.button_label_txt), 0, pgvar.UI_button_txt_color)
screen.blit(label, (self.x + 5, self.y))
# render "label" type buttons
elif self.buttonType == "label":
self.color = pgvar.UI_label_color # since self.color = buttonColor by default, this overwrites that for labels
pygame.draw.rect(screen, self.color, (self.x, self.y, self.x_width, self.y_height)) #button
label = myfont.render(str(self.button_label_txt), 0, pgvar.UI_button_txt_color)
screen.blit(label, (self.x + 5, self.y))
# render "group" type buttons
elif self.buttonType == "group":
pygame.draw.rect(screen, self.color, (self.x, self.y, self.x_width, self.y_height)) #button
pygame.draw.rect(screen, self.colorBorder, (self.x, self.y, self.x_width, self.y_height), 3) #border
label = myfont.render(str(self.button_label_txt), 0, pgvar.UI_button_txt_color)
screen.blit(label, (self.x + 5, self.y))
# render "dropdown" type buttons
elif self.buttonType == "dropdown":
if self.buttonVisible == True:
#print lineNum(), "rendering dropdown type buttons, button: ", self.button_name, "buttonVisible?:", self.buttonVisible
pygame.draw.rect(screen, self.color, (self.x, self.y, self.x_width, self.y_height)) #button
pygame.draw.rect(screen, self.colorBorder, (self.x, self.y, self.x_width, self.y_height), 3) #border
label = myfont.render(str(self.button_label_txt), 0, pgvar.UI_button_txt_color) # set label
screen.blit(label, (self.x + 5, self.y)) # draw label
# render "Menu" type buttons
elif self.buttonType == "menu":
if self.buttonVisible == True:
pygame.draw.rect(screen, self.color, (self.x, self.y, self.x_width, self.y_height)) #button
pygame.draw.rect(screen, self.colorBorder, (self.x, self.y, self.x_width, self.y_height), 3) #border
label = myfont.render(str(self.button_label_txt), 0, pgvar.UI_button_txt_color)
screen.blit(label, (self.x + 5, self.y))
elif self.buttonType == "textEntry":
pygame.draw.rect(screen, self.color, (self.x, self.y, self.x_width, self.y_height)) #button
pygame.draw.rect(screen, self.colorBorder, (self.x, self.y, self.x_width, self.y_height), 3) #border
label = myfont.render(str(self.button_label_txt), 0, pgvar.UI_button_txt_color)
screen.blit(label, (self.x + 5, self.y))
# render "popup" type buttons
elif self.buttonType == "popup":
if self.buttonVisible == True:
pygame.draw.rect(screen, self.color, (self.x, self.y, self.x_width, self.y_height)) #button
pygame.draw.rect(screen, self.colorBorder, (self.x, self.y, self.x_width, self.y_height), 3) #border
label = myfont.render(str(self.button_label_txt), 0, pgvar.UI_button_txt_color)
screen.blit(label, (self.x + 5, self.y))
elif self.buttonType == "popup_element":
if self.button_name == "menu02popup01element03":
self.buttonVisible = pgui.menu02popup01element03["visible"]
if self.button_name == "menu02popup01element06":
self.buttonVisible = pgui.menu02popup01element06["visible"]
if self.buttonVisible == True:
pygame.draw.rect(screen, self.color, (self.x, self.y, self.x_width, self.y_height)) #button
#pygame.draw.rect(screen, self.colorBorder, (self.x, self.y, self.x_width, self.y_height), 3) #border
label = myfont.render(str(self.button_label_txt), 0, pgvar.UI_button_txt_color)
screen.blit(label, (self.x + 5, self.y))
elif self.buttonType == "popup_element_button":
if self.buttonVisible == True:
pygame.draw.rect(screen, self.color, (self.x, self.y, self.x_width, self.y_height)) #button
pygame.draw.rect(screen, self.colorBorder, (self.x, self.y, self.x_width, self.y_height), 1) #border
label = myfont.render(str(self.button_label_txt), 0, pgvar.UI_button_txt_color)
screen.blit(label, (self.x + 5, self.y))