mardi 4 octobre 2016

How to make 2 contradictory methods work in drawRect?

I'm stuck with my code: I need to use three pairs of 2 different methods inside drawRect. To be precise, three methods for drawing triangle and three methods for drawing rectangle.

Even having if-statement these methods work incorrectly. I have bugs. Because all these methods are called at the same time.

Help me find a solution, please. Is there a workaround?

override func drawRect(dirtyRect: NSRect) {
    super.drawRect(dirtyRect)

    drawBG()
    GraphicsState { self.drawMyPoints() }

    if makeRectangle.state == 1 {
        buildRectPath()
        drawRectPath()
        drawRectFill()
    }

    if makeTriangle.state == 1 {
        buildTriPath()
        drawTriPath()
        drawTriFill()
    }

    drawBorder()
}

How I expect it to work:

I have two buttons in my UI: makeRectangle and makeTriangle. Pressing the first one I get rectangle with path stroke and its body filled with color. The same principle applied to triangle.

How it works:

Due to the fact that these methods are called at the same time I get rectangle filled like triangle and triangle without a path.

Aucun commentaire:

Enregistrer un commentaire