Example #1
0
    def redrawguidelines(self):
        numberDivisionsX = self.numberHorizontalRects
        numberDivisionsY = self.numberVerticalRects

        xLength = self.myRect.width
        xSpacing = xLength / numberDivisionsX
        for i in range(1, numberDivisionsX):
            gl = GuideLine(int(i * xSpacing + self.myRect.topLeftX),
                           self.myRect.topLeftY, "vertical", self.myRect,
                           self.screen, self.myRect.drawablesController, True)

        yLength = self.myRect.height
        ySpacing = yLength / numberDivisionsY
        for i in range(1, numberDivisionsY):
            gl = GuideLine(self.myRect.topLeftX,
                           int(i * ySpacing + self.myRect.topLeftY),
                           "horizontal", self.myRect, self.screen,
                           self.myRect.drawablesController, True)
 def divideHorizontal(self):
     yLength = self.myRect.height
     ySpacing = yLength / self.horizontalGuidelinesCount
     for i in range(1, self.horizontalGuidelinesCount):
         yPosition = int(ySpacing * i + self.myRect.topLeftY)
         gl = GuideLine(self.myRect.topLeftX, yPosition, "horizontal",
                        self.myRect, self.myRect.screen,
                        self.myRect.drawablesController, True)
         self.horizontalCutList.append(gl)
 def divideVertical(self):
     xLength = self.myRect.width
     xSpacing = xLength / self.verticalGuidelinesCount
     for i in range(1, self.verticalGuidelinesCount):
         xPosition = int(xSpacing * i + self.myRect.topLeftX)
         gl = GuideLine(xPosition, self.myRect.topLeftY, "vertical",
                        self.myRect, self.myRect.screen,
                        self.myRect.drawablesController, True)
         self.verticalCutList.append(gl)
Example #4
0
    def update(self):
        if self.state == CUTTINGVERTICAL and self.myRect.isCollidingWithPoint(
                self.myRect.mouse.mx, self.myRect.mouse.my
        ) and self.myRect.mouse.leftMouseReleasedThisFrame == True:
            gl = GuideLine(self.myRect.mouse.mx, self.myRect.topLeftY,
                           "vertical", self.myRect, self.screen,
                           self.myRect.drawablesController, False)
            self.guidelines.append(gl)
            self.numberHorizontalRects += 1
            self.lastLine = (gl, "vertical")
            self.lineList.append(self.lastLine)

        elif self.state == CUTTINGHORIZONTAL and self.myRect.isCollidingWithPoint(
                self.myRect.mouse.mx, self.myRect.mouse.my
        ) and self.myRect.mouse.leftMouseReleasedThisFrame == True:
            gl = GuideLine(self.myRect.topLeftX, self.myRect.mouse.my,
                           "horizontal", self.myRect, self.screen,
                           self.myRect.drawablesController, False)
            self.guidelines.append(gl)
            self.numberVerticalRects += 1
            self.lastLine = (gl, "horizontal")
            self.lineList.append(self.lastLine)

        if self.state == CUTTINGVERTICAL and self.buttonPressed == True:
            self.state = CUTTINGHORIZONTAL
            self.buttonPressed = False

        if self.state == CUTTINGHORIZONTAL and self.buttonPressed == True:
            self.state = TRYSUBDIVIDE
            self.buttonPressed = False

        if self.state == TRYSUBDIVIDE:
            #first remove guidelines
            for gl in self.guidelines:
                for glInDc in self.myRect.drawablesController.guidelines:
                    if gl == glInDc:
                        self.myRect.drawablesController.guidelines.remove(
                            glInDc)
            #next re-add guidelines in right places
            self.redrawguidelines()
            self.myRect.numberVerticalRects = self.numberVerticalRects
            self.myRect.numberHorizontalRects = self.numberHorizontalRects
            self.isReadyForSubdivide = True
Example #5
0
    def update(self, isClick):
        # decide if close enough to mouse to draw guiding line or not
        mousePos = pg.mouse.get_pos()
        distToMouse = math.sqrt((self.xPosition - mousePos[0])**2 +
                                (self.yPosition - mousePos[1])**2)
        if distToMouse < self.radius:
            self.isTouchingMouse = True
        else:
            self.isTouchingMouse = False

        if distToMouse < self.radius and isClick == True:
            if self.type == "vertical":
                gl = GuideLine(self.xPosition, self.yPosition + self.offset,
                               self.type, self.myRect, self.screen,
                               self.drawablesController, True)
            elif self.type == "horizontal":
                gl = GuideLine(self.xPosition + self.offset, self.yPosition,
                               self.type, self.myRect, self.screen,
                               self.drawablesController, True)
            self.drawablesController.cutmarkers.remove(self)
    def autoCut(self, hCuts, vCuts):
        self.verticalGuidelinesCount = vCuts
        xLength = self.myRect.width
        xSpacing = xLength / self.verticalGuidelinesCount
        for i in range(1, self.verticalGuidelinesCount):
            xPosition = int(xSpacing * i + self.myRect.topLeftX)
            gl = GuideLine(xPosition, self.myRect.topLeftY, "vertical",
                           self.myRect, self.myRect.screen,
                           self.myRect.drawablesController, True)
        self.myRect.numberHorizontalRects = self.verticalGuidelinesCount
        self.myRect.cutSquareVertical()

        self.horizontalGuidelinesCount = hCuts
        yLength = self.myRect.height
        ySpacing = yLength / self.horizontalGuidelinesCount
        for i in range(1, self.horizontalGuidelinesCount):
            yPosition = int(ySpacing * i + self.myRect.topLeftY)
            gl = GuideLine(self.myRect.topLeftX, yPosition, "horizontal",
                           self.myRect, self.myRect.screen,
                           self.myRect.drawablesController, True)
        self.myRect.numberVerticalRects = self.horizontalGuidelinesCount
        self.myRect.finalCut()
    def setupGuides(self):
        x = 0
        y = 20

        self.qtGuide1 = GuideCircle(QtCore.QRectF(x, y, 260, 260), -36, 342)
        GuideLine(QtCore.QPointF(x + 240, y + 268), self.qtGuide1)
        GuideLine(QtCore.QPointF(x + 265, y + 246), self.qtGuide1)
        GuideLine(QtCore.QPointF(x + 158, y + 134), self.qtGuide1)
        GuideLine(QtCore.QPointF(x + 184, y + 109), self.qtGuide1)
        GuideLine(QtCore.QPointF(x + 160, y +  82), self.qtGuide1)
        GuideLine(QtCore.QPointF(x +  77, y + 163), self.qtGuide1)
        GuideLine(QtCore.QPointF(x + 100, y + 190), self.qtGuide1)
        GuideLine(QtCore.QPointF(x + 132, y + 159), self.qtGuide1)
        GuideLine(QtCore.QPointF(x + 188, y + 211), self.qtGuide1)
        GuideCircle(QtCore.QRectF(x + 30, y + 30, 200, 200), -30, 336, GuideCircle.CW, self.qtGuide1)
        GuideLine(QtCore.QPointF(x + 238, y + 201), self.qtGuide1)

        y = 30
        self.qtGuide2 = GuideCircle(QtCore.QRectF(x + 30, y + 30, 200, 200), 135, 270, GuideCircle.CCW)
        GuideLine(QtCore.QPointF(x + 222, y + 38), self.qtGuide2)
        GuideCircle(QtCore.QRectF(x, y, 260, 260), 135, 270, GuideCircle.CW, self.qtGuide2)
        GuideLine(QtCore.QPointF(x + 59, y + 59), self.qtGuide2)

        x = 115
        y = 10
        self.qtGuide3 = GuideLine(QtCore.QLineF(x, y, x + 30, y))
        GuideLine(QtCore.QPointF(x + 30, y + 170), self.qtGuide3)
        GuideLine(QtCore.QPointF(x, y + 170), self.qtGuide3)
        GuideLine(QtCore.QPointF(x, y), self.qtGuide3)

        self.qtGuide1.setFence(QtCore.QRectF(0, 0, 800, 600))
        self.qtGuide2.setFence(QtCore.QRectF(0, 0, 800, 600))
        self.qtGuide3.setFence(QtCore.QRectF(0, 0, 800, 600))
class ItemCircleAnimation(DemoItem):
    sscene = None

    def __init__(self, scene=None, parent=None):
        super(ItemCircleAnimation, self).__init__(scene, parent)

        ItemCircleAnimation.sscene = scene
        self.letterList = []
        self.letterCount = Colors.tickerLetterCount
        self.scale = 1.0
        self.showCount = -1
        self.tickOnPaint = False
        self.paused = False
        self.doIntroTransitions = True
        self.setAcceptsHoverEvents(True)
        self.setCursor(QtCore.Qt.OpenHandCursor)
        self.setupGuides()
        self.setupLetters()
        self.useGuideQt()
        self.effect = None

        self.mouseMoveLastPosition = QtCore.QPointF()
        self.tickTimer = QtCore.QTime()

    def createLetter(self, c):
        letter = LetterItem(c, ItemCircleAnimation.sscene, self)
        self.letterList.append(letter)

    def setupLetters(self):
        self.letterList = []

        s = Colors.tickerText
        tlen = len(s)
        room = self.letterCount
        while room >= tlen:
            for c in s:
                self.createLetter(c)

            room -= tlen

        # Fill in with blanks.
        while room > 0:
            self.createLetter(' ')
            room -= 1

    def setupGuides(self):
        x = 0
        y = 20

        self.qtGuide1 = GuideCircle(QtCore.QRectF(x, y, 260, 260), -36, 342)
        GuideLine(QtCore.QPointF(x + 240, y + 268), self.qtGuide1)
        GuideLine(QtCore.QPointF(x + 265, y + 246), self.qtGuide1)
        GuideLine(QtCore.QPointF(x + 158, y + 134), self.qtGuide1)
        GuideLine(QtCore.QPointF(x + 184, y + 109), self.qtGuide1)
        GuideLine(QtCore.QPointF(x + 160, y +  82), self.qtGuide1)
        GuideLine(QtCore.QPointF(x +  77, y + 163), self.qtGuide1)
        GuideLine(QtCore.QPointF(x + 100, y + 190), self.qtGuide1)
        GuideLine(QtCore.QPointF(x + 132, y + 159), self.qtGuide1)
        GuideLine(QtCore.QPointF(x + 188, y + 211), self.qtGuide1)
        GuideCircle(QtCore.QRectF(x + 30, y + 30, 200, 200), -30, 336, GuideCircle.CW, self.qtGuide1)
        GuideLine(QtCore.QPointF(x + 238, y + 201), self.qtGuide1)

        y = 30
        self.qtGuide2 = GuideCircle(QtCore.QRectF(x + 30, y + 30, 200, 200), 135, 270, GuideCircle.CCW)
        GuideLine(QtCore.QPointF(x + 222, y + 38), self.qtGuide2)
        GuideCircle(QtCore.QRectF(x, y, 260, 260), 135, 270, GuideCircle.CW, self.qtGuide2)
        GuideLine(QtCore.QPointF(x + 59, y + 59), self.qtGuide2)

        x = 115
        y = 10
        self.qtGuide3 = GuideLine(QtCore.QLineF(x, y, x + 30, y))
        GuideLine(QtCore.QPointF(x + 30, y + 170), self.qtGuide3)
        GuideLine(QtCore.QPointF(x, y + 170), self.qtGuide3)
        GuideLine(QtCore.QPointF(x, y), self.qtGuide3)

        self.qtGuide1.setFence(QtCore.QRectF(0, 0, 800, 600))
        self.qtGuide2.setFence(QtCore.QRectF(0, 0, 800, 600))
        self.qtGuide3.setFence(QtCore.QRectF(0, 0, 800, 600))

    def useGuide(self, guide, firstLetter, lastLetter):
        padding = guide.lengthAll() / float(lastLetter - firstLetter)

        for i, letter in enumerate(self.letterList[firstLetter:lastLetter]):
            letter.useGuide(guide, i * padding)

    def useGuideQt(self):
        if self.currGuide is not self.qtGuide1:
            self.useGuide(self.qtGuide1, 0, self.letterCount)
            self.currGuide = self.qtGuide1

    def useGuideTt(self):
        if self.currGuide is not self.qtGuide2:
            split = int(self.letterCount * 5.0 / 7.0)
            self.useGuide(self.qtGuide2, 0, split)
            self.useGuide(self.qtGuide3, split, self.letterCount)
            self.currGuide = self.qtGuide2

    def boundingRect(self):
        return QtCore.QRectF(0, 0, 300, 320)

    def prepare(self):
        pass

    def switchToNextEffect(self):
        self.showCount += 1

        if self.showCount == 1:
            self.effect = EffectSnake(self.letterList)
        elif self.showCount == 2:
            self.effect = EffectLine(self.letterList)
            self.effect.setPostEffect(PostRotateXYTwist(0.01, 0.0, 0.003, 0.0))
        elif self.showCount == 3:
            self.effect = EffectRaindrops(self.letterList)
            self.effect.setPostEffect(PostRotateXYTwist(0.01, 0.005, 0.003, 0.003))
        elif self.showCount == 4:
            self.effect = EffectScan(self.letterList)
            self.effect.normalMoveSpeed = 0
            self.effect.setPostEffect(PostRotateXY(0.008, 0.0, 0.005, 0.0))
        else:
            self.showCount = 0
            self.effect = EffectWhirlWind(self.letterList)

    def animationStarted(self, id):
        if id == DemoItemAnimation.ANIM_IN:
            if self.doIntroTransitions:
                # Make all letters disappear.
                for letter in self.letterList:
                    letter.setPos(1000, 0)

                self.switchToNextEffect()
                self.useGuideQt()
                self.scale = 1.0

                # The first time we run, we have a rather large delay to
                # perform benchmark before the ticker shows.  But now, since we
                # are showing, use a more appropriate value.
                self.currentAnimation.startDelay = 1500
        elif self.effect is not None:
            self.effect.useSheepDog = False

        self.tickTimer = QtCore.QTime.currentTime()

    def animationStopped(self, _):
        pass

    def swapModel(self):
        if self.currGuide is self.qtGuide2:
            self.useGuideQt()
        else:
            self.useGuideTt()

    def hoverEnterEvent(self, event):
        # Skip swap here to enhance ticker dragging.
        pass

    def hoverLeaveEvent(self, event):
        self.swapModel()

    def setTickerScale(self, s):
        self.scale = s
        self.qtGuide1.setScale(self.scale, self.scale)
        self.qtGuide2.setScale(self.scale, self.scale)
        self.qtGuide3.setScale(self.scale, self.scale)

    def mousePressEvent(self, event):
        self.mouseMoveLastPosition = event.scenePos();

        if event.button() == QtCore.Qt.LeftButton:
            self.setCursor(QtCore.Qt.ClosedHandCursor)
        else:
            self.switchToNextEffect()

    def mouseReleaseEvent(self, event):
        if event.button() == QtCore.Qt.LeftButton:
            self.setCursor(QtCore.Qt.OpenHandCursor)

    def mouseMoveEvent(self, event):
        newPosition = event.scenePos()
        self.setPosUsingSheepDog(self.pos() + newPosition - self.mouseMoveLastPosition, QtCore.QRectF(-260, -280, 1350, 1160))
        self.mouseMoveLastPosition = newPosition

    def wheelEvent(self, event):
        if event.delta() > 0:
            self.effect.moveSpeed -= 0.20
        else:
            self.effect.moveSpeed += 0.20

        if self.effect.moveSpeed < 0:
            self.effect.moveSpeed = 0.0

    def pause(self, on):
        self.paused = on
        self.tickTimer = QtCore.QTime.currentTime()

    def tick(self):
        if self.paused or not self.effect:
            return

        t = self.tickTimer.msecsTo(QtCore.QTime.currentTime())
        self.tickTimer = QtCore.QTime.currentTime()
        self.effect.tick(t / 10.0)

    def paint(self, painter, opt, widget):
        if self.tickOnPaint:
            self.tick()
    def __init__(self, xx, yy, w, h, screen, drawablesController,
                 isOriginalSquare, mouse, stateManager, ownerID):
        # the xPosition and yPosition refer to the middle point of the rectangle
        # include a origin point
        self.xPosition = xx
        self.yPosition = yy
        self.width = w
        self.height = h
        self.screen = screen
        self.drawablesController = drawablesController
        self.drawablesController.rectangles.append(self)
        self.xOrigin = xx
        self.yOrigin = yy
        self.address = self
        self.willBeDivided = True
        self.myPointCollider = None

        # Keeps track of which original rectangle it is a part of for shading in division
        # 0 if original test rect, 1 for first (left) rectangle, 2 for second (right), doesn't apply to multiplication
        self.ownerID = ownerID

        self.stateManager = stateManager

        #mouse var needed to pass to cutting
        self.mouse = mouse

        # these member variables may be useful for rectangle collisions
        self.topLeftX = int(self.xPosition - self.width / 2)
        self.topLeftY = int(self.yPosition - self.height / 2)
        self.bottomRightX = int(self.xPosition + self.width / 2)
        self.bottomRightY = int(self.yPosition + self.height / 2)
        self.topRightX = self.topLeftX + self.width
        self.bottomLeftX = self.bottomRightX - self.width

        # boolean var to decide if rectangle should be subdivided when all cutmarkers removed
        self.isOriginalSquare = isOriginalSquare

        # vars used to cut up rectangles if is original square
        self.numberHorizontalRects = -1
        self.numberVerticalRects = -1

        # show random color to display cutting working
        if self.isOriginalSquare == True:
            self.color = colors.WHITE
        else:
            # possColors = (colors.GREEN,colors.RED,colors.DARKBLUE)
            self.color = colors.WHITE
        self.isShaded = False  # boolean used for toggling off/on shading
        # booleans used for cross-hatch shading
        self.isShadedV = False
        self.isShadedH = False
        self.isShadedB = False
        self.colorHatch = colors.WHITE

        self.vColor = None  # for subtraction right now
        self.hColor = None  # just for subtr right now

        self.isTrash = False
        self.isMarked = False

        # draw outer guidelines and bg square only if rectangle is original square
        if self.isOriginalSquare == True:
            GuideLine(self.topLeftX, self.topLeftY, "vertical", self,
                      self.screen, self.drawablesController, True)
            GuideLine(self.topLeftX, self.topLeftY, "horizontal", self,
                      self.screen, self.drawablesController, True)
            GuideLine(self.topLeftX + self.width, self.topLeftY, "vertical",
                      self, self.screen, self.drawablesController, True)
            GuideLine(self.topLeftX, self.topLeftY + self.height, "horizontal",
                      self, self.screen, self.drawablesController, True)
            BgSquare(self.topLeftX, self.topLeftY, self.width, self.height,
                     self.screen, self.drawablesController)

        # cutting behavior
        self.myCutter = None
        if self.isOriginalSquare == True:
            if self.stateManager.cuttingType == self.stateManager.VARCUTTING:
                self.myCutter = CutterVariable(self)
            elif self.stateManager.cuttingType == self.stateManager.CMCUTTING:
                self.myCutter = CutterCutmarkers(self)
            elif self.stateManager.cuttingType == self.stateManager.FRACTIONCUTTING:
                self.myCutter = CutterFraction(self)