コード例 #1
0
    def update(self):
        super().update()

        self.cursor = input_handler.get_cursor()

        # Scrolling handler
        if self.offset > config.screen_y:  # Only scroll if page is longer than screen can fit
            if self.cursor.is_valid:
                deadband = scale(100)
                min_speed = scale(5)  # Minimum movement speed if moving
                feathering = scale(30)  # Lower = faster

                # Distance from center
                y_off = self.cursor.y_pos - config.screen_y / 2

                # Check if x and y are outside the deadband (center) range
                if y_off > deadband:
                    speed = min_speed + (y_off - deadband) / feathering
                    self.scroll -= speed
                elif y_off < -deadband:
                    speed = -min_speed + (y_off + deadband) / feathering
                    self.scroll -= speed

                # Make sure map doesn't go off the edge
                if self.scroll < -self.offset + config.screen_y:
                    self.scroll = -self.offset + config.screen_y
                elif self.scroll > 0:
                    self.scroll = 0

                self.scroll = int(self.scroll)
コード例 #2
0
 def __init__(self, background, x, y, width, height, target):
     global SCALE_FACTOR
     self.background = background
     parent = background.parent
     super().__init__(parent)
     self.base_x = scale(x, SCALE_FACTOR)
     self.base_y = scale(y, SCALE_FACTOR)
     self.box = pygame.Rect(self.base_x, self.base_y,
                            scale(width, SCALE_FACTOR),
                            scale(height, SCALE_FACTOR))
     self.is_selected = 0
     self.target = target
     self.master_window = parent.parent
     self.parent = parent
コード例 #3
0
 def __init__(self, master, text):
     super().__init__(master)
     master.increase_offset(master.margins)
     self.offset = master.go_next_clear()
     self.font = pygame.font.SysFont(master.heading_font,
                                     master.heading_size)
     self.display_text = self.font.render(text, True, (0, 0, 0))
     master.increase_offset(self.display_text.get_height())
     master.increase_offset(scale(15))
コード例 #4
0
    def update(self):
        self.cursor = input_handler.get_cursor()
        if self.cursor.is_valid:
            deadband = scale(100)
            min_speed = scale(5)  # Minimum movement speed if moving
            feathering = scale(30)  # Lower = faster

            # Distance from center
            x_off = scale(self.cursor.x_pos - config.screen_x / 2)
            y_off = scale(self.cursor.y_pos - config.screen_y / 2)

            # Check if x and y are outside the deadband (center) range
            if y_off > deadband:
                speed = min_speed + (y_off - deadband) / feathering
                self.y -= speed
            elif y_off < -deadband:
                speed = -min_speed + (y_off + deadband) / feathering
                self.y -= speed

            if x_off > deadband:
                speed = min_speed + (x_off - deadband) / feathering
                self.x -= speed
            elif x_off < -deadband:
                speed = -min_speed + (x_off + deadband) / feathering
                self.x -= speed

            # Make sure map doesn't go off the edge
            if self.x > self.x_max:
                self.x = self.x_max
            elif self.x < self.x_min:
                self.x = self.x_min

            if self.y > self.y_max:
                self.y = self.y_max
            elif self.y < self.y_min:
                self.y = self.y_min

            self.off_x = self.x - self.width / 2
            self.off_y = self.y - self.height / 2

        self.imagerect.center = (self.x, self.y)
コード例 #5
0
class Page(window_elements.Subwindow):
    priority = 127

    # Gap between text and side of the screen, also controls some other spacing
    margins = scale(30)

    # Style of the text in the title block
    title_size = scale(160)
    title_font = "cambria"
    title_color = (255, 255, 255)

    # Style of the heading text
    heading_size = scale(46)
    heading_font = "opensans"

    # Style of the regular text
    _font_size = 38
    font_size = scale(_font_size)
    font = "opensans"
    font_color = (51, 51, 51)
    font_spacing = scale(_font_size / 4)  # Spacing between lines
    font_indent = scale(
        15)  # Additional spacing beyond margin to indent regular text

    def __init__(self, master):
        super().__init__(master)
        self.cursor = input_handler.get_cursor(
        )  # TODO make this controlled by either the master window or subwindow

        master.register(self)

        self.offset = 0  # How far down the text goes
        self.scroll = 0  # How far down the user has scrolled

        # Spacing on the left and right, in addition to standard spacing (e.g an image taking up space)
        self.left_margin = 0
        self.right_margin = 0

        self.next_clear = 0  # How far down does image go, if one is currently being spaced

    def get_page(self):
        return self

    # Tell page that vertical space has been used
    def increase_offset(self, increase):
        if self.offset >= self.next_clear:  # If we are now clear of the image being spaced, reset margins
            self.next_clear += increase
            self.left_margin = 0
            self.right_margin = 0
        self.offset += increase

    # Draw white background
    def draw(self):
        self.screen.fill((255, 255, 255))
        super().draw()

    # Use up all space next to space occupied by image
    def go_next_clear(self):
        self.offset = self.next_clear
        return self.next_clear

    def update(self):
        super().update()

        self.cursor = input_handler.get_cursor()

        # Scrolling handler
        if self.offset > config.screen_y:  # Only scroll if page is longer than screen can fit
            if self.cursor.is_valid:
                deadband = scale(100)
                min_speed = scale(5)  # Minimum movement speed if moving
                feathering = scale(30)  # Lower = faster

                # Distance from center
                y_off = self.cursor.y_pos - config.screen_y / 2

                # Check if x and y are outside the deadband (center) range
                if y_off > deadband:
                    speed = min_speed + (y_off - deadband) / feathering
                    self.scroll -= speed
                elif y_off < -deadband:
                    speed = -min_speed + (y_off + deadband) / feathering
                    self.scroll -= speed

                # Make sure map doesn't go off the edge
                if self.scroll < -self.offset + config.screen_y:
                    self.scroll = -self.offset + config.screen_y
                elif self.scroll > 0:
                    self.scroll = 0

                self.scroll = int(self.scroll)