class AbstractorBox(Box): def __init__(self, x, y): self.topline = None self.rightline = None self.bottomline = None self.color = (1.0, 0.4, 0.8) Box.__init__(self, x, y) def get_vertices(self, centerx, centery): left = centerx-self.s2 right = centerx+self.s1 bottom = centery-self.s2 top = centery+self.s1 return vec2(right, bottom), vec2(right, top), vec2(left, top) def update(self, x, y): Box.update(self, x, y) self.a, self.b, self.c = a, b, c = self.get_vertices(x, y) pos = vec2(x, y) self.leftattach = (b.x, y) self.bottomattach = (x, b.y) self.rightattach = (x+self.s1, y+self.s1) self.right_triangle = Triangle(a, b, pos, self.color, self.batch) self.top_triangle = Triangle(b, c, pos, self.color, self.batch) self.bottom_triangle = Triangle(c, a, pos, self.color, self.batch) self.glow = self.batch.add_indexed(6, pyglet.gl.GL_TRIANGLES, None, [0, 1, 3, 1, 4, 3, 1, 2, 4, 2, 5, 4, 2, 0, 5, 0, 3, 5], ('v2f', (a.x+255, a.y-512 , b.x+255, b.y+255, c.x-512, c.y+255, a.x, a.y, b.x, b.y, c.x, c.y)), ('c4f', (self.color+(0.0,))*3+(self.color+(1.0,))*3) ) self.topattach = (x, a.y) self.bottomattach = (x-self.s1, y-self.s1) self.rightattach = (a.x, y) def draw(self): self.batch.draw() def gethover(self, x, y): hovered = False if self.top_triangle.gethover(vec2(x, y)): hovered = self, self.leftattach if self.bottom_triangle.gethover(vec2(x, y)): hovered = self, self.bottomattach if self.right_triangle.gethover(vec2(x, y)): hovered = self, self.rightattach return hovered def drag_end(self, x, y): pass
class ApplicatorBox(Box): def __init__(self, x, y): self.leftline = None self.rightline = None self.bottomline = None self.color = (0.4, 1.0, 0.8) Box.__init__(self, x, y) def get_vertices(self, centerx, centery): left = centerx-self.s1 right = centerx+self.s2 bottom = centery-self.s1 top = centery+self.s2 return vec2(left, top), vec2(left, bottom), vec2(right, bottom) def update(self, x, y): Box.update(self, x, y) pos = vec2(x, y) self.a, self.b, self.c = a, b, c = self.get_vertices(x, y) self.left_triangle = Triangle(a, b, pos, self.color, self.batch) self.bottom_triangle = Triangle(b, c, pos, self.color, self.batch) self.right_triangle = Triangle(c, a, pos, self.color, self.batch) self.glow = self.batch.add_indexed(6, pyglet.gl.GL_TRIANGLES, None, [0, 1, 3, 1, 4, 3, 1, 2, 4, 2, 5, 4, 2, 0, 5, 0, 3, 5], ('v2f', (a.x-255, a.y+512 , b.x-255, b.y-255, c.x+512, c.y-255, a.x, a.y, b.x, b.y, c.x, c.y)), ('c4f', (self.color+(0.0,))*3+(self.color+(1.0,))*3) ) self.leftattach = (b.x, y) self.bottomattach = (x, b.y) self.rightattach = (x+self.s1, y+self.s1) def draw(self): self.batch.draw() if self.rightline: self.rightline.draw() if self.leftline: self.leftline.draw() def gethover(self, x, y): hovered = False if x > self.a.x and x < self.c.x and y > self.b.y and y < self.a.y: #bounding box check if self.left_triangle.gethover(vec2(x, y)): hovered = self, self.leftattach if self.bottom_triangle.gethover(vec2(x, y)): hovered = self, self.bottomattach if self.right_triangle.gethover(vec2(x, y)): hovered = self, self.rightattach else: self.left_triangle.highlight(False) self.bottom_triangle.highlight(False) self.right_triangle.highlight(False) return hovered def gethover_recursive(self, x, y): hovered = self.gethover(x, y) if hovered: return hovered else: if self.rightline: rightline_hover = self.rightline.gethover_recursive(x, y) if rightline_hover: return rightline_hover else: if self.leftline: leftline_hover = self.leftline.gethover_recursive(x, y) if leftline_hover: return leftline_hover else: return False def drag_end(self, x, y): pass