-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquadHandler.py
More file actions
86 lines (67 loc) · 3.08 KB
/
Copy pathquadHandler.py
File metadata and controls
86 lines (67 loc) · 3.08 KB
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
from OpenGL.GL import glDeleteTextures
from glm import vec2
import extra
import texture
from VBOHandler import VBOImage
class Quad:
def __init__(self,
shader,
corners,
colour,
texture):
self.corners = corners
self.colours = [colour] * len(self.corners)
self.texture = texture
self.textureCorners = [(0, 0), (1, 0), (1, 1), (0, 1)]
self.VBO = VBOImage(shader, self.corners, self.colours, self.textureCorners, self.texture)
def edit(self, corners, colour):
self.corners = corners
self.colours = [colour] * len(self.corners)
self.VBO.vertices = self.corners
self.VBO.colours = self.colours
self.VBO.update()
def changeTexture(self, newTexture):
self.texture = newTexture
self.VBO.texture = newTexture
def draw(self):
self.VBO.draw()
class TextQuad:
def __init__(self, shader, text, fontPath, topLeft, height, displayV, colour, isTopRight=False):
self.height = height
self.displayV = displayV
self.fontPath = fontPath
self.colour = colour
self.topLeft = topLeft
self.isTopRight = isTopRight
self.text = text
self.textTexture, textSize = texture.GenTextTextureSize(text,
height,
displayV,
fontPath,
customColour=colour
)
self.quad = Quad(shader,
extra.generateRectangleCoordsTopLeft(topLeft, textSize)
if not self.isTopRight else
extra.generateRectangleCoordsTopLeft(self.topLeft - vec2(textSize.x, 0), textSize),
colour,
self.textTexture
)
def changeText(self, newText):
if newText != self.text:
self.text = newText
self.textTexture, textSize = texture.GenTextTextureSize(self.text,
self.height,
self.displayV,
self.fontPath,
customColour=self.colour
)
oldTexture = self.quad.texture
glDeleteTextures(1, [oldTexture])
self.quad.changeTexture(self.textTexture)
self.quad.edit(extra.generateRectangleCoordsTopLeft(self.topLeft, textSize)
if not self.isTopRight else
extra.generateRectangleCoordsTopLeft(self.topLeft-vec2(textSize.x, 0), textSize),
self.colour)
def draw(self):
self.quad.draw()