Esempio n. 1
0
    def render(self):
        """
        Renders the widget to the screen
        :return: The rect of the control as it was rendered
        """

        # Standardize our dimensions
        self.rect = Rect(self.pos[0], self.pos[1], self.width, self.height)
        self.set_dimensions_from_rect(self.rect)

        color = self.get_color()

        # Draw the basic skeleton of the control
        render_rectangle(self.display, color, self.rect)

        # We need to do a bit of math to figure out how to position items
        range_increment = self.width / float(self.range_high - self.range_low)

        # Draw the box of the control - unless we're below or at min-val
        if self.value > self.range_low:
            x = (min(self.value, self.range_high) -
                 self.range_low) * range_increment
            chart_rect = Rect(self.left, self.top, x, self.height)
            render_rectangle(self.display, color, chart_rect, width=0)

        # Return our dimensions
        return self.rect
Esempio n. 2
0
    def render(self):
        """
        Renders the glyph and returns its dimensions
        :return: The dimensions of the glyph
        """

        # Size Constants
        rect_size = self.display.fonts.normal.size + self.check_pad

        self.rect = Rect(self.pos[0], self.pos[1], self.desired_size[0],
                         self.desired_size[1])

        focus_color = self.display.color_scheme.get_focus_color(
            self.render_focus)

        # Draw the border
        render_rectangle(self.display, focus_color, self.rect)

        # Draw checkmark (if checked)
        if self.checked:
            checked_rect = Rect(self.pos[0] + self.check_pad,
                                self.pos[1] + self.check_pad,
                                rect_size - (self.check_pad * 2),
                                rect_size - (self.check_pad * 2))

            render_rectangle(self.display, focus_color, checked_rect, width=0)

        # Update and return our dimensions
        return self.set_dimensions_from_rect(self.rect)
Esempio n. 3
0
    def render(self):
        """
        Renders the widget to the screen
        :return: The rect of the control as it was rendered
        """

        # Standardize our dimensions
        self.rect = Rect(self.pos[0], self.pos[1], self.width, self.height)
        self.set_dimensions_from_rect(self.rect)

        color = self.get_color()

        if self.is_highlighted:
            highlight = self.display.color_scheme.highlight
        else:
            highlight = color

        # Draw the basic skeleton of the control
        draw_vertical_line(self.display, color, self.left, self.top,
                           self.bottom)
        draw_vertical_line(self.display, color, self.right, self.top,
                           self.bottom)
        draw_horizontal_line(self.display, color, self.left, self.right,
                             self.top + 4)

        # We need to do a bit of math to figure out how to position items
        range_increment = self.width / float(self.range_high - self.range_low)

        # Draw any tick marks present
        for tick in self.ticks:
            tick_offset = (tick - self.range_low) * range_increment
            draw_vertical_line(self.display, color, self.left + tick_offset,
                               self.top, self.bottom)

        # Draw the box of the control
        if self.box_width >= 0:
            low_x = (self.value_low - self.range_low) * range_increment
            high_x = (self.value_high - self.range_low) * range_increment
            chart_rect = Rect(self.left + low_x, self.top + 2, high_x - low_x,
                              self.height - 3)
            render_rectangle(self.display,
                             highlight,
                             chart_rect,
                             width=self.box_width)

        # If we have a value, render it
        if self.value_current:
            x = (self.value_current - self.range_low) * range_increment
            draw_vertical_line(self.display,
                               self.display.color_scheme.highlight,
                               self.left + x, self.top, self.bottom)

    # Return our dimensions
        return self.rect
Esempio n. 4
0
    def render(self):
        """
        Renders the glyph and returns its dimensions
        :return: The dimensions of the glyph
        """

        # Size Constants
        self.rect = Rect(self.pos[0], self.pos[1], self.desired_size[0], self.desired_size[1])

        # Draw the border
        focus_color = self.display.color_scheme.get_focus_color(self.render_focus)
        render_rectangle(self.display, focus_color, self.rect)

        # Draw the text
        display = self.display
        render_text(display, display.fonts.normal, self.text, self.pos[0] + self.pad_x, self.pos[1] + self.pad_y,
                    focus_color)

        # Update and return our dimensions
        return self.set_dimensions_from_rect(self.rect)
Esempio n. 5
0
    def render(self):

        # Colorize as needed
        color = self.get_color()
        self.lbl_title.color = self.get_title_color()

        # Render an outline around the entire control
        rect = Rect(self.pos[0], self.pos[1], self.desired_size[0],
                    self.desired_size[1])

        # Some statuses need custom backgrounds
        if self.status == DashboardStatus.Caution:
            render_rectangle(self.display,
                             self.display.color_scheme.caution_bg,
                             rect,
                             width=0)
        elif self.status == DashboardStatus.Critical:
            render_rectangle(self.display,
                             self.display.color_scheme.critical_bg,
                             rect,
                             width=0)

        # Render the outline
        render_rectangle(self.display, color, rect)

        # Render the base content with some padding
        pos = self.pos[0] + self.padding, self.pos[1] + self.padding
        self.panel.render_at(pos)

        # Assume the width of the outer outline
        return self.set_dimensions_from_rect(rect)
Esempio n. 6
0
    def render(self, display, surface):
        """
        Renders an interlaced effect over everything
        :param display: The DisplayManager
        :param surface: The overlay graphical surface to render to
        """

        if not self.options.enable_shadow_effect:
            return

        color = (0, 0, 0, self.alpha)

        rect_top = Rect(display.bounds.left, display.bounds.top, display.bounds.width, self.size)
        rect_left = Rect(display.bounds.left, self.size, self.size, display.bounds.right - self.size)
        rect_right = Rect(display.bounds.right - self.size, self.size, self.size, display.bounds.height - self.size)

        render_rectangle(display, color, rect_top, width=0, surface=surface)
        render_rectangle(display, color, rect_left, width=0, surface=surface)
        render_rectangle(display, color, rect_right, width=0, surface=surface)
Esempio n. 7
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)
Esempio n. 8
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)