def deleteLine(self, at=None): todo('optimize deleteLine with glBufferSubData()') if at is None: at = self.focusLoc.asGL(*self.s) #* If there's a bound there, don't delete all the lines under it as well removedBound = False # You can't change the size of a set while iterating through it for some reason # Hence, copy(). for i in self.bounds.copy(): if i == at: self.bounds.remove(i) removedBound = True if not removedBound: #* This should not be nessicarry, I have no idea why the 3 lines don't work by themselves. linesStillAtFocus = True while linesStillAtFocus: linesStillAtFocus = False for i in self.lines: if i.start == at or i.end == at: self.lines.remove(i) for i in self.lines: if i.start == at or i.end == at: linesStillAtFocus = True self.currentLine = None self.resetLineVbo() self.update()
def drawBackground(self): # self.qp.begin(self) # self.qp.setPen(QColor(255, 0, 0, 255)) # self.qp.drawEllipse(*self.centerPoint.asTL().data(), 6, 6) # debug(self.background) if type(self.background) is tuple: # self.qp.fillRect(0, 0, self.width, self.height, QColor(*self.background)) # return glColor(*clampColor(*self.background)) glBegin(GL_QUADS) glVertex2f(1,1) glVertex2f(1,-1) glVertex2f(-1,-1) glVertex2f(-1,1) glEnd() elif type(self.background) is str: # if not self._image: # self._image = QLabel(self) # self._image.setPixmap(QPixmap(self.background)) # self._image.setPixmap(QPixmap(QColor(255, 255, 255, 0))) # pixmap = QPixmap(self.background) #, 'Format_ARGB32_Premultiplied') image = QImage(self.background).mirrored() #, 'Format_ARGB32_Premultiplied') texture = QOpenGLTexture(image) texture.bind() glDrawArrays(GL_TRIANGLE_FAN, 0, 4) # texture.bind() # for k, v in kwparams.items(): # gl.glTexParameteri(gl.GL_TEXTURE_2D, getattr(gl, k), v) # texture.release() # qp = QPainter(pixmap) # qp.fillRect(pixmap.rect(), QColor(0, 0, 0, 150)) # qp.end() # pixmap.transformed(QTransform()) # self.window()._image.setPixmap(pixmap) # else: # self._image.show() # self.imageimage = QImage(self.background) # QPainter painter(this) # self.qp.drawPixmap(0, 0, pixmap) elif type(self.background) is QGradient: todo('Drawing QGradient') elif type(self.background) is QImage: self.qp.drawImage(0, 0, self.background)
def undo(self): todo('undo') if self.currentLine == None and len(self.lines) > 0: del self.lines[-1] if self.mirroringStates[self.currentMirrorState] >= 2 and len(self.lines) > 0: self.lines.pop() if self.mirroringStates[self.currentMirrorState] >= 4 and len(self.lines) > 0: self.lines.pop() if len(self.lines) > 1: self.lines.pop() elif self.currentLine != None: self.currentLine = None
def drawMirroring(self): todo('mirroring') #* Add mirroring for i in self.lineBuffer: #* Check if there's already a line there (so it doesn't get bolder (because of anti-aliasing)) dontDraw = False for k in self.lines: if i == k or (i.start == k.end and i.end == k.start): dontDraw = True #* Check if the start and end are the same (no line would be drawn) if i.start != i.end and not dontDraw: self.lines.append(i) if self.mirroringStates[self.currentMirrorState] in [1, 4]: starty = self.startingPoint.y + (self.startingPoint.y - i.start.y) + 2 endy = self.startingPoint.y + (self.startingPoint.y - i.end.y) + 2 vertStart = Pointi(i.start.x, starty) vertEnd = Pointi(i.end.x, endy) self.lines.append(Line(vertStart, vertEnd, i.color)) if self.mirroringStates[self.currentMirrorState] >= 2: # self.startingPoint = Point(min(self.dots, key=lambda i:abs(i.x - (self.width / 2))).x + 1, min(self.dots, key=lambda i:abs(i.y - (self.height / 2))).y + 1) startx = self.startingPoint.x + (self.startingPoint.x - i.start.x) + 2 endx = self.startingPoint.x + (self.startingPoint.x - i.end.x) + 2 horStart = Pointi(startx, i.start.y) horEnd = Pointi(endx, i.end.y) self.lines.append(Line(horStart, horEnd, i.color)) if self.mirroringStates[self.currentMirrorState] >= 4: corStart = Pointi(startx, starty) corEnd = Pointi(endx, endy) self.lines.append(Line(corStart, corEnd, i.color)) self.lineBuffer = [] #* Add mirrored current line if self.currentLine is not None and self.mirroringStates[self.currentMirrorState] in [1, 4]: curStarty = self.startingPoint.y + (self.startingPoint.y - self.currentLine.start.y) + 2 curEndy = self.startingPoint.y + (self.startingPoint.y - self.currentLine.end.y) + 2 Line(Pointi(self.currentLine.start.x, curStarty), Pointi(self.currentLine.end.x, curEndy), self.currentLine.color).draw(self.mainSurface) if self.currentLine is not None and self.mirroringStates[self.currentMirrorState] >= 2: curStartx = self.startingPoint.x + (self.startingPoint.x - self.currentLine.start.x) + 2 curEndx = self.startingPoint.x + (self.startingPoint.x - self.currentLine.end.x) + 2 Line(Pointi(curStartx, self.currentLine.start.y), Pointi(curEndx, self.currentLine.end.y), self.currentLine.color).draw(self.mainSurface) if self.currentLine is not None and self.mirroringStates[self.currentMirrorState] >= 4: Line(Pointi(curStartx, curStarty), Pointi(curEndx, curEndy), self.currentLine.color).draw(self.mainSurface)
def specificErase(self): todo('specificErase') # If there's nothing there, don't do anything if self.focusLoc in [i.end for i in self.lines] + [i.start for i in self.lines]: if self.specificEraseBuffer == None: self.specificEraseBuffer = self.focusLoc else: assert(type(self.specificEraseBuffer) == Pointi) for index, i in enumerate(self.lines): if (i.start == self.focusLoc and i.end == self.specificEraseBuffer) or \ (i.start == self.specificEraseBuffer and i.end == self.focusLoc): del self.lines[index] self.specificEraseBuffer = None else: self.specificEraseBuffer = None
def setBackground(selector): debug(selector) if selector == "Color": self.paper.background = self.optionsMenu.backgroundColor.getColor( ) elif selector == "Pattern": todo('figure out how to select a pattern/gradient') self.paper.background = self.optionsMenu.backgroundColor.getColor( ) elif selector == "Image": self.paper.background = self.optionsMenu.backgroundPath.file elif selector == "Map Image": todo('get an image from the map') self.paper.background = (255, 160, 100, 255) else: raise UserWarning( "Something has gone horribly, horribly wrong.")
def redo(self): todo('redo')
def new_(self): todo('_new')
def saveAs(self): todo('saveAs')
def toggleFullscreen(self): todo('toggleFullscreen')
def setShortcut(): todo('custom shortcuts')
def restoreDefaults(): todo('set defaults')