Exemplo n.º 1
0
    def center_text(self, text, color=None):
        if not color:
            color = self.display.color_scheme.highlight

        center = self.display.get_content_center()
        render_text_centered(self.display, self.display.fonts.normal, text,
                             center[0],
                             center[1] - (self.display.fonts.normal.size / 2),
                             color)
Exemplo n.º 2
0
    def render(self, display, color, pos, half_size):
        """
        Renders the icon to the display
        :param display: The display manager
        :param color: The color
        :param pos: The center point of the shape
        :param half_size: Half the size of the shape
        """

        icon = get_condition_icon(self.code)
        size = display.fonts.weather.measure(icon)
        render_text_centered(display, display.fonts.weather, icon, pos[0], pos[1] - (size[1] / 2.0), color)
Exemplo n.º 3
0
    def render(self):

        if self.panel:
            rect = self.panel.render()
        else:
            rect = super(MFDPage, self).render()

        # Calculate number of whole pages
        self.num_pages_y = rect.height / self.page_size_y

        # Advance to the next whole page if first page or non-trivial content on last page
        if self.num_pages_y == 0 or rect.height % self.page_size_y > 16:
            self.num_pages_y += 1

        # Smart-Constrain Page
        self.constrain_pages()

        # Render Overflow indicators if off screen
        if self.auto_scroll:

            paging_color = self.display.color_scheme.foreground

            # If we have already paged, show MORE link at the top
            if self.page_y > 1:
                arrow_pos = [self.display.bounds.right - 18, self.min_y]
                render_triangle_up(self.display, paging_color, arrow_pos, 8)
                render_text_centered(self.display, self.display.fonts.small,
                                     "MORE", arrow_pos[0], arrow_pos[1] + 3,
                                     paging_color)

            # If we have more pages, show a MORE link at the bottom
            if self.page_y < self.num_pages_y:
                arrow_pos = [self.display.bounds.right - 18, self.max_y]
                render_triangle_down(self.display, paging_color, arrow_pos, 8)
                render_text_centered(
                    self.display, self.display.fonts.small, "MORE",
                    arrow_pos[0],
                    arrow_pos[1] - 3 - self.display.fonts.small.size,
                    paging_color)

        return rect
Exemplo n.º 4
0
    def render(self, display, map_context):
        """
        Renders the symbol to the screen.
        :param display: The display manager
        """

        # In general symbols will be composed of the following components
        #
        # Main Shape
        # Square - Amenities
        # Circle - Government / Services / Public
        #   Diamond - Shops
        #   Square w. Diamond Top - Residential
        #
        # Text
        # Right Text - Specialization
        #   Bottom Text - Name
        #   Inner Text - Symbol Code
        #   Left Text - Augmented Data for current map mode

        shape_width = 1
        shape_size = 20

        # Set shape. Python 2.7 doesn't have enum support so I'm using a placeholder class for that.
        shape = SymbolBackShape()
        style = shape.circle

        shape_shop = shape.diamond
        shape_service = shape.square
        shape_public = shape.circle

        icons = list()

        font = display.fonts.small

        pos = (int(self.x), int(self.y))

        # Grab name, preferring short_name if present, otherwise abbreviating
        display_name = self.get_display_name()

        app_data = None
        extra_data = None
        inner_text = None

        if map_context.cursor_context is self:
            app_data = 'CUR'

        if map_context.target is self:
            app_data = 'TGT'

        shop = self.get_tag_value('shop')
        amenity = self.get_tag_value('amenity')

        hide_shape_if_has_building = True

        # Modify our display parameters based on what our context is

        if self.has_tag('highway'):

            # Don't display names for roads at the moment
            display_name = None

            highway = self.get_tag_value('highway')
            if highway == 'traffic_signals':
                style = shape.traffic_stop
                hide_shape_if_has_building = False

            elif highway == 'street_lamp':
                style = shape.circle
                shape_width = 0
                shape_size = 1
                hide_shape_if_has_building = False

            elif highway == 'motorway_junction':
                style = shape.diamond
                hide_shape_if_has_building = False

            elif highway == 'crossing':
                style = shape.diamond
                hide_shape_if_has_building = False
                shape_width = 0
                shape_size = 6

        elif amenity:

            style = shape_shop

            if amenity == 'pharmacy':
                style = shape.none
                icons.append(PillIcon())

            elif amenity == 'fuel':
                inner_text = 'GAS'

            elif amenity == 'school':
                style = shape_public  # Though this could be service if private school
                inner_text = 'EDU'

            elif amenity == 'veterinary':
                style = shape_service
                inner_text = 'VET'

            elif amenity == 'place_of_worship':

                # Plug in the denomination or religion
                extra_data = self.get_tag_value('denomination')
                if extra_data is None:
                    extra_data = self.get_tag_value('religion')

                style = shape_service
                inner_text = 'REL'

            elif amenity in ('restaurant', 'pub'):

                # Plug in the cuisine
                extra_data = self.get_tag_value('cuisine')

                style = shape_service  # Service since we eat in

                icons.append(FoodIcon())  # TODO: Render by cuisine

            elif amenity in ('fast_food', 'food_court'):

                # Plug in the cuisine
                extra_data = self.get_tag_value('cuisine')

                icons.append(FoodIcon())  # TODO: Render by cuisine

            elif amenity == 'cafe':
                inner_text = 'caf'

            elif amenity == 'bbq':
                inner_text = 'bbq'

            elif amenity in ('biergarten', 'bar'):
                inner_text = 'bar'

            elif amenity == 'drinking_water':
                inner_text = 'H2O'

            elif amenity == 'ice_cream':
                inner_text = 'ice'  # Icon should come here - this one isn't intuitive on abbrv.

            elif amenity in ('college', 'university'):
                inner_text = 'EDU'

            elif amenity == 'kindergarten':
                inner_text = 'pre'

            elif amenity == 'library':
                inner_text = 'lib'

            elif amenity == 'school':
                inner_text = 'sch'

            elif amenity == 'public_bookcase':
                inner_text = 'cas'

            elif amenity in ('bicycle_parking', 'bicycle_repair_station', 'bicycle_rental'):
                inner_text = 'bik'

            elif amenity == 'boat_sharing':
                inner_text = 'boa'

            elif amenity == 'bus_station':
                inner_text = 'bus'

        elif shop:

            style = shape_shop

            if shop == 'car_repair':
                style = shape_service
                inner_text = 'CAR'

            elif shop == 'furniture':
                icons.append(ChairIcon())

            elif shop == 'sports':
                inner_text = 'ATH'

            elif shop == 'free_flying':
                inner_text = 'FLY'

            elif shop == 'shoes':
                inner_text = 'WLK'

            elif shop == 'supermarket':
                icons.append(FoodIcon())

            elif shop == 'optician':
                style = shape.none
                icons.append(EyeIcon())

            elif shop == 'beauty':
                style = shape_service
                inner_text = 'SPA'

        elif self.has_tag('tourism'):

            # No added styling needed so far
            pass

        elif self.has_tag('building'):

            # No added styling needed so far
            pass

        elif self.has_tag('leisure'):

            # No added styling needed so far
            pass

        elif self.has_tag('power'):

            power = self.get_tag_value('power')

            if power == 'tower':
                style = shape.triangle
                shape_size = 6

            elif power == 'pole':
                style = shape.circle
                shape_size = 3

        elif self.has_tag('barrier'):
            shape_size = 3

        elif self.has_tag_value('footway', 'crossing'):
            style = shape.diamond
            shape_width = 0
            shape_size = 6

        elif self.has_tag('surveillance'):
            style = shape.none
            icons.append(EyeIcon())

        elif self.has_tag('weather'):
            style = shape.none
            icons.append(WeatherIcon(self.get_tag_value('weather')))

            if self.has_tag('wind:speed') and self.has_tag('wind:direction_cardinal'):
                extra_data = self.get_tag_value('wind:speed') + ' ' + self.get_tag_value('wind:direction_cardinal')

            display_name = self.get_tag_value('temperature') + "'F"

        elif self.has_tag('man_made'):

            man_made = self.get_tag_value('man_made')

            if man_made == 'tower':
                style = shape.triangle

            elif man_made == 'surveillance':
                style = shape.none
                icons.append(EyeIcon())

        elif self.has_tag('actor'):

            actor = self.get_tag_value('actor')

            if actor == 'cursor':
                style = shape.cursor
                shape_width = 3
                extra_data = self.get_tag_value('owner')
                display_name = '{}, {}'.format(self.lat, self.lng)
                if map_context.cursor_context:
                    app_data = map_context.cursor_context.name
            else:
                style = shape.double_circle

        elif self.has_tag('incident'):
            style = shape.diamond

            end = self.get_tag_value('end_date')
            extra_data = end

            shape_width = 2
            
        elif self.has_tag('location'):
            style = shape.bullseye
            shape_width = 5

        half_size = shape_size / 2

        right_text = extra_data
        left_text = app_data
        bottom_text = display_name

        color = self.get_color(display.color_scheme, map_context)

        # Render the shape of the item
        if (not hide_shape_if_has_building or not self.has_lines) and map_context.should_show_shapes(self):

            if style == shape.circle:
                render_circle(display, color, pos, half_size + 2, shape_width)

            elif style == shape.square:
                render_rectangle(display, color, Rect(self.x - half_size, self.y - half_size, shape_size, shape_size),
                                 shape_width)

            elif style == shape.diamond:
                render_diamond(display, color, pos, half_size + 2, shape_width)

            elif style == shape.triangle:
                render_triangle_up(display, color, pos, half_size + 2, shape_width)

            elif style == shape.bullseye:
                render_circle(display, color, pos, half_size * 2, 1)
                render_circle(display, color, pos, half_size, 1)
                draw_horizontal_line(display, color, pos[0] - (half_size * 3), pos[0] + (half_size * 3), pos[1])
                draw_vertical_line(display, color, pos[0], pos[1] - (half_size * 3), pos[1] + (half_size * 3))

            elif style == shape.double_circle:
                render_circle(display, color, pos, half_size + 2, shape_width)
                render_circle(display, color, pos, half_size, shape_width)

            elif style == shape.traffic_stop:
                render_circle(display, display.color_scheme.red, pos, 4, 0)
                render_circle(display, display.color_scheme.yellow, pos, 3, 0)
                render_circle(display, display.color_scheme.green, pos, 1, 0)

            elif style == shape.cursor:
                draw_vertical_line(display, display.color_scheme.highlight, pos[0], pos[1] - shape_width,
                                   pos[1] + shape_width)
                draw_horizontal_line(display, display.color_scheme.highlight, pos[0] - shape_width,
                                     pos[0] + shape_width, pos[1])

        # Render adornment icons
        if map_context.should_show_icons(self):
            for icon in icons:
                icon.render(display, color, pos, half_size)

        # Render text labels
        if inner_text and map_context.should_show_shapes(self):
            render_text_centered(display,
                                 font,
                                 inner_text.upper(),
                                 self.x,
                                 self.y - (font.measure(inner_text)[1] / 2.0),
                                 color)

        if right_text and map_context.should_show_right_text(self):
            render_text(display,
                        font,
                        right_text.upper(),
                        self.x + half_size + 3,
                        self.y - (font.measure(right_text)[1] / 2.0),
                        color)

        if left_text and map_context.should_show_left_text(self):
            render_text(display,
                        font,
                        left_text.upper(),
                        self.x - font.measure(left_text)[0] - 12,
                        self.y - (font.measure(left_text)[1] / 2.0),
                        display.color_scheme.highlight)

        if bottom_text and map_context.should_show_bottom_text(self):
            render_text_centered(display,
                                 font,
                                 bottom_text.upper(),
                                 self.x,
                                 self.y + half_size + 3,
                                 color)
Exemplo n.º 5
0
    def render(self, display, x_start, x_end, y, is_top):
        """
        Renders the button with its current state.
        :type display: The PiMFD.DisplayManager.DisplayManager that manages display settings
        :param x_start: The leftmost side of the button's bounds
        :param x_end: The rightmost side of the button's bounds
        :type is_top: bool True if this button is on the top of the screen, False if on the bottom.
        """

        if self.enabled:
            font_color = display.color_scheme.foreground
        else:
            font_color = display.color_scheme.disabled

        # Figure out background color - sometimes we'll want to render it on top of other content
        background = None
        if self.always_render_background:
            background = display.color_scheme.background

        label = self.text

        # If it's selected, use inverted colors
        if self.selected:
            background = font_color
            font_color = display.color_scheme.background
            label = ' ' + label + ' '  # Pad out the display so it appears wider with a background

        midpoint = ((x_end - x_start) / 2) + x_start

        pos = render_text_centered(display, display.fonts.normal, label, midpoint, y, font_color, background=background)

        if self.enabled:
            # Render tick marks
            line_length = 5
            if is_top:
                draw_vertical_line(display,
                                   display.color_scheme.foreground,
                                   midpoint,
                                   y - 2,
                                   y - 2 - line_length)

                top = y - 2 - line_length
                bottom = pos.bottom
            else:
                draw_vertical_line(display,
                                   display.color_scheme.foreground,
                                   midpoint,
                                   y + pos.height - 2,
                                   y + pos.height + line_length - 2)

                top = pos.top
                bottom = y + pos.height + line_length - 2
        else:
            top = pos.top
            bottom = pos.bottom

        # Update the bounds of the button for collision detection later
        self.bounds = Rect(x_start, top, x_end - x_start, bottom - top)

        # Render the bounds of the rectangle
        if self.draw_border:
            render_rectangle(display, display.color_scheme.foreground, self.bounds)