Logo Search packages:      
Sourcecode: ocempgui version File versions  Download package

def themes::default::DefaultEngine::DefaultEngine::draw_border (   self,
  surface,
  state,
  cls = None,
  style = None,
  bordertype = BORDER_FLAT,
  rect = None,
  space = 0 
)

D.draw_border (...) -> None

Draws a border on the passed using a specific border type.

Dependant on the border type, this method will draw a rectangle
border on the passed surface.

The 'rect' argument indicates the drawing area at which's edges
the border will be drawn. This can differ from the real surface
rect. A None value (the default) will draw the border around the
surface.

'space' denotes, how many pixels will be left between each
border pixel before drawing the next one. A value of 0 thus
causes the method to draw a solid border while other values will
draw dashed borders.

The BORDER_RAISED, BORDER_SUNKEN, BORDER_ETCHED_IN and
BORDER_ETCHED_OUT border types use the 'lightcolor', 'darkcolor'
and 'shadow' style entries for drawing, BORDER_FLAT uses the
'bordercolor' entry.

If no style is passed, the method will try to retrieve a style
using the get_style() method.

Raises a ValueError, if the passed bordertype argument is
not a value of the BORDER_TYPES tuple.

Definition at line 81 of file DefaultEngine.py.

                                                                :
        """D.draw_border (...) -> None

        Draws a border on the passed using a specific border type.

        Dependant on the border type, this method will draw a rectangle
        border on the passed surface.

        The 'rect' argument indicates the drawing area at which's edges
        the border will be drawn. This can differ from the real surface
        rect. A None value (the default) will draw the border around the
        surface.
        
        'space' denotes, how many pixels will be left between each
        border pixel before drawing the next one. A value of 0 thus
        causes the method to draw a solid border while other values will
        draw dashed borders.

        The BORDER_RAISED, BORDER_SUNKEN, BORDER_ETCHED_IN and
        BORDER_ETCHED_OUT border types use the 'lightcolor', 'darkcolor'
        and 'shadow' style entries for drawing, BORDER_FLAT uses the
        'bordercolor' entry.
        
        If no style is passed, the method will try to retrieve a style
        using the get_style() method.
        
        Raises a ValueError, if the passed bordertype argument is
        not a value of the BORDER_TYPES tuple.
        """
        if bordertype not in BORDER_TYPES:
            raise ValueError ("bordertype must be a value from BORDER_TYPES")
        # Do nothing in case, that the border type is none.
        if bordertype == BORDER_NONE:
            return surface
        self_style = self.style

        if not style:
            style = self_style.get_style (cls)

        # The spacing for the lines. space == 0 actually means a solid line,
        # spacing == 1 a dashed one with 1px spaces, etc.
        # Add one pixel for the slicing later on. 
        space += 1
        
        # Maybe pixel3d should be used here, but it does not support 24
        # bit color depths.
        array = pygame.surfarray.array3d (surface)

        # Create the area, the border should surround.
        # We will use the passed padding for it.
        r = rect
        if r == None:
            r = surface.get_rect ()

        # Dependant on the border style, we will care about the used
        # colors. 3D effect such as sunken or raised make use of the
        # light/darkcolor style keys, the flat one uses the fgcolor. If
        # it is a 3D effect, we are going to use the shadow key to
        # determine, how many lines the distinction shall have.
        # 
        # The drawing is done as follows:
        # * First fill the upper row of the (n,m) matrix with the given
        #   color and color only every wanted pixel.
        # * The color the bottom row of the matrix in the same way.
        # * The left column will be colored as well.
        # * The same again with the right column.
        
        if bordertype == BORDER_FLAT:
            color = self_style.get_style_entry (cls, style, "bordercolor",
                                                state)
            array[r.left:r.right:space, r.top] = color
            array[r.left:r.right:space, r.bottom - 1] = color
            array[r.left, r.top:r.bottom:space] = color
            array[r.right - 1, r.top:r.bottom:space] = color

        elif bordertype in (BORDER_SUNKEN, BORDER_RAISED):
            shadow = self_style.get_style_entry (cls, style, "shadow")
            if shadow < 1:
                return surface # No shadow wanted.

            # Create the colors.
            color1 = self_style.get_style_entry (cls, style, "lightcolor",
                                                 state)
            color2 = self_style.get_style_entry (cls, style, "darkcolor",
                                                 state)

            if bordertype == BORDER_SUNKEN:
                color1, color2 = color2, color1

            # By default we will create bevel edges, for which the
            # topleft colors take the most place. Thus the bottomleft
            # array slices will be reduced continously.
            for i in xrange (shadow):
                array[r.left + i:r.right - i:space, r.top + i] = color1
                array[r.left + i:r.right - i:space,
                      r.bottom - (i + 1)] = color2
                array[r.left + i, r.top + i:r.bottom - i:space] = color1
                array[r.right - (i + 1),
                      r.top + i + 1:r.bottom - i:space] = color2

        elif bordertype in (BORDER_ETCHED_IN, BORDER_ETCHED_OUT):
            shadow = self_style.get_style_entry (cls, style, "shadow")
            if shadow < 1:
                return surface # No shadow wanted.
            color1 = self_style.get_style_entry (cls, style, "lightcolor",
                                                 state)
            color2 = self_style.get_style_entry (cls, style, "darkcolor",
                                                 state)
            if bordertype == BORDER_ETCHED_OUT:
                color1, color2 = color2, color1
            s = shadow
            # First (inner) rectangle.
            array[r.left + s:r.right:space, r.top + s:r.top + 2 * s] = color1
            array[r.left + s:r.right:space,r.bottom - s:r.bottom] = color1
            array[r.left + s:r.left + 2 * s, r.top + s:r.bottom:space] = color1
            array[r.right - s:r.right, r.top + s:r.bottom:space] = color1
            # Second (outer) rectangle.
            array[r.left:r.right - s:space, r.top:r.top + s] = color2
            array[r.left:r.right - s:space,
                  r.bottom - 2*s:r.bottom - s] = color2
            array[r.left:r.left + s, r.top:r.bottom - s:space] = color2
            array[r.right - 2 * s:r.right - s,
                  r.top:r.bottom - s:space] = color2

        # Blit the new surface.
        pygame.surfarray.blit_array (surface, array)

    def draw_dropshadow (self, surface, cls=None, style=None):


Generated by  Doxygen 1.6.0   Back to index