Example #1
0
def setMouseOffset(myCanvas, tiles, selectedTiles, mouseLoc, isDrag,
        selectedTile, grid, gridRes):
    # Only areas near the clicked tile are checked to see if they were
    # clicked on
    areasToCheck = getAreasToCheck(mouseLoc, grid, gridRes)
    for area in areasToCheck:
        for tile in area:
            # Part of this next block insures that only the tile on top
            # of other tiles is selected
            if (not isDrag and common.isInSquare(mouseLoc, tile.position,
                    tile.radius) and
                    common.getDistance(mouseLoc, tile.position) <
                    tile.radius and (selectedTile is None or
                    tiles.index(tile) > tiles.index(selectedTile))):
                selectedTile = tile
    # If there has been a left click, a single tile is selected.  If
    # there has been a right click, a group of snapped tiles is
    # selected.
    if selectedTile is not None:
        if myCanvas.isLDown:
            selectedTiles = [selectedTile]
        else:
            selectedTiles = []
            for tile in selectedTile.tileGroup:
                selectedTiles.append(tile)
        isDrag = True
        for tile in selectedTile.tileGroup:
            tile.mouseOffset = common.mySub(mouseLoc, tile.position)
            # The next two lines move all the tiles in a seleted group
            # of tiles to the top layer of the tiles
            tiles.remove(tile)
            tiles.append(tile)
    return selectedTiles, isDrag, selectedTile
Example #2
0
def checkPallet(myCanvas, tiles, mouseLoc, isDrag, selectedTile):
    for tile in myCanvas.tilePallet:
        if (not isDrag and common.isInSquare(mouseLoc, tile.position,
                tile.radius) and common.getDistance(mouseLoc, tile.position) <
                tile.radius):
            newTile = objects.Tile(myCanvas, tile.image)
            newTile.setPosition(tile.position)
            tiles.append(newTile)
            newTile.mouseOffset = common.mySub(mouseLoc, tile.position)
            selectedTile = newTile
            isDrag = True
    return isDrag, selectedTile
Example #3
0
def moveUnSnappable(myCanvas, mouseLoc, selectedTiles, selectedTile, isSnapped,
        sidesToSnap, snapdTile, tiles):
    # Checks each side of one of the tiles which is snapped but can
    # potentially still be unsnapped.  If the distance between this
    # tile and another tile is enough, the tiles unsnap
    for side in snapdTile.sides:
        if (side.adjSide is not None and common.getDistance(common.myAdd(
                common.mySub(mouseLoc, snapdTile.mouseOffset),
                side.corner.getOffset()), side.adjSide.corner.getPosition()) >
                objects.Canvas.SNAP_DISTANCE * objects.Canvas.scale + 1):
            isSnapped, sidesToSnap, snapdTile = moveUnSnap(myCanvas, mouseLoc,
                    selectedTiles, selectedTile, sidesToSnap, tiles)
            break
    return (isSnapped, sidesToSnap, snapdTile)
Example #4
0
def findMatch(sideA, sideB, minDistance, isMatch, snapdSide, adjSide):
    # This block only runs if the two sides are of the same color, and
    # also neither side is already snapped to another tile.
    if (sideA.color == sideB.color and
            common.isInSquare(sideA.corner.getPosition(),
            sideB.corner.getPosition(), minDistance) and not sideB.isSnapped):
        # When this code is run on different combinations of sides, this
        # code makes sure to only set the closest two compatible sides
        # as the sides to be used for snapping.
        distance = common.getDistance(sideA.corner.getPosition(),
                sideB.corner.getPosition())
        if distance < minDistance:
            minDistance = distance
            snapdSide = sideA
            adjSide = sideB
            isMatch = True
    return minDistance, isMatch, snapdSide, adjSide
Example #5
0
 def __init__(self, array, name, xbeginScale, xendScale, ybeginScale,
              yendScale, colScale, columnHeightList):
     self.numList = copy.deepcopy(array)
     self.name = name
     startX = int(width * xbeginScale)
     endX = int(width * (xendScale - 0.05))
     self.distance = getDistance(startX, endX, len(self.numList))
     self.columnWidth = int(self.distance * colScale)
     self.columnPosList = []
     for i in range(len(self.numList)):
         self.columnPosList.append(startX + self.distance * i)
     self.columnHeightList = copy.deepcopy(columnHeightList)
     self.yPos = int(yendScale * height)
     self.columnColorList = []
     for i in range(len(self.numList)):
         self.columnColorList.append(green)
     self.titleCenX, self.titleCenY = int(
         width * ((xendScale - 0.05 - xbeginScale) / 2 + xbeginScale)), int(
             height * ((ybeginScale - 0.025)))
     self.nameSurface, self.nameRect = getStrRect_Surface(
         self.name, self.titleCenX, self.titleCenY)