Beispiel #1
0
	def _PositionWidgets(self):

		# Retrieve the screen.

		screen = GetScreen()
		screenDimensions = GetDimensions(screen)

		# Calculate the positions of texts and buttons.

		titleDimensions = self._titleLabel.GetDimensions()
		messageDimensions = self._messageLabel.GetDimensions()
		continueButtonDimensions = self._continueButton.GetDimensions()

		titleAndMessageBundleHeight = titleDimensions.Y + messageDimensions.Y

		self._titleLabel.SetPosition(Vector(
			(screenDimensions.X - titleDimensions.X) / 2,
			(screenDimensions.Y - Parameters.Margin - continueButtonDimensions.Y - titleAndMessageBundleHeight) / 2,
		))

		self._messageLabel.SetPosition(Vector(
			(screenDimensions.X - messageDimensions.X) / 2,
			self._titleLabel.GetPosition().Y + titleDimensions.Y,
		))

		self._continueButton.SetPosition(Vector(
			(screenDimensions.X - continueButtonDimensions.X) / 2,
			screenDimensions.Y - Parameters.Margin - continueButtonDimensions.Y,
		))
def SpreadHorizontally(destinationSurface,
                       widgets,
                       verticalPosition,
                       margin=None):

    destinationDimensions = GetDimensions(destinationSurface)
    if margin:
        destinationDimensions.X -= 2 * margin

    widgetDimensions = [x.GetDimensions() for x in widgets]

    totalWidth = sum([x.X for x in widgetDimensions])

    spaceCount = len(widgets) - 1
    spaceWidth = (destinationDimensions.X - totalWidth) / spaceCount

    sumOfWidths = 0
    numberOfSpaces = 0

    for index in range(len(widgets)):

        currentPosition = (0 if not margin else
                           margin) + sumOfWidths + numberOfSpaces * spaceWidth
        position = Vector(currentPosition, verticalPosition)

        widgets[index].SetPosition(position)

        sumOfWidths += widgetDimensions[index].X
        numberOfSpaces += 1
Beispiel #3
0
    def _GenerateSprites(self):

        # Render the text itself.

        textSurface = RenderText(self._text, self._font, self._textColor)
        textSurfaceDimensions = GetDimensions(textSurface)

        # Create both surfaces.

        surfaceDimensions = textSurfaceDimensions + (Padding * 2)
        if self._minimumWidth:
            surfaceDimensions.X = max(self._minimumWidth, surfaceDimensions.X)

        self._activeSurface = Surface(tuple(surfaceDimensions), SRCALPHA)
        self._inactiveSurface = self._activeSurface.copy()

        RenderRoundedRectangle(self._activeSurface, Vector(),
                               surfaceDimensions, (50, 50, 255, 255))
        RenderRoundedRectangle(self._inactiveSurface, Vector(),
                               surfaceDimensions, (50, 50, 255, 32))

        # Draw text on both surfaces.

        textPosition = Vector(
            (surfaceDimensions.X - textSurfaceDimensions.X) / 2, Padding.Y)

        Blit(self._activeSurface, textSurface, textPosition)
        Blit(self._inactiveSurface, textSurface, textPosition)

        # Set the inactive surface as the current surface.

        self.SetSurface(self._inactiveSurface)
def InterpolateToScale(surface, scale):

    dimensions = GetDimensions(surface) * scale

    dimensions.X = int(dimensions.X)
    dimensions.Y = int(dimensions.Y)

    return InterpolateToDimensions(surface, dimensions)
def MoveToTheBottom(destinationSurface, widgets, margin=None):

    destinationDimensions = GetDimensions(destinationSurface)

    for widget in widgets:

        position = widget.GetPosition()
        dimensions = widget.GetDimensions()

        position.Y = destinationDimensions.Y - (margin if margin else
                                                0) - dimensions.Y

        widget.SetPosition(position)
Beispiel #6
0
    def _GenerateSurface(self):

        if not self._text:

            self.SetSurface(None)

            return

        # Render the text.

        textSurface = RenderText(self._text, self._font, self._textColor)
        textSurfaceDimensions = GetDimensions(textSurface)

        # Set the text surface as the current surface.

        self.SetSurface(textSurface)
Beispiel #7
0
    def _PositionWidgets(self):

        # Retrieve the screen and its dimensions.

        screen = GetScreen()
        screenDimensions = GetDimensions(screen)

        # Position the top labels.

        labels = [self._creator, self._version]

        SpreadHorizontally(screen, labels, Parameters.Margin,
                           Parameters.Margin)

        # Position the buttons.

        buttons = [self._newGameButton, self._quitButton]

        SpreadHorizontally(screen, buttons, 0, Parameters.Margin)
        MoveToTheBottom(screen, buttons, Parameters.Margin)

        # Position the title.

        labelsPartHeight = Parameters.Margin + max(
            [x.GetDimensions().Y for x in labels])
        buttonsPartHeight = Parameters.Margin + max(
            [x.GetDimensions().Y for x in buttons])

        titleDimensions = self._title.GetDimensions()

        self._title.SetPosition(
            Vector(
                (screenDimensions - titleDimensions).X / 2,
                labelsPartHeight + (screenDimensions.Y - titleDimensions.Y -
                                    labelsPartHeight - buttonsPartHeight) / 2,
            ))
Beispiel #8
0
    def SetSurface(self, surface):

        self._surface = surface
        self._dimensions = GetDimensions(self._surface)
Beispiel #9
0
	def GetDimensions(self):

		return GetDimensions(self._surfaces[0])