Source

Fat x Fast / FatxFast / gui / border.py

# This file is part of FatxFast.
#
#    FatxFast is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    FatxFast is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with FatxFast.  If not, see <http://www.gnu.org/licenses/>.

# Versioning based on: 
# http://en.wikipedia.org/wiki/Versioning#Designating_development_stage
__author__ = "dryatu (c) 2013"
__version__ = "1.2.5"

import pygame
import math

class WidgetBorder(object):
    
    def __init__(self, width, color):
        self.width = width
        self.color = color

    def draw(self, surface, rect):
        if not self.width:
            return False

        even_correction = -1

        if self.width%2 != 0:
            even_correction = 0
        pygame.draw.line(surface, self.color, 
            (rect.left-self.width, rect.top), 
            (rect.right+self.width-1, rect.top), 
            self.width) 
        pygame.draw.line(surface, self.color, 
            (rect.left-self.width, rect.bottom), 
            (rect.right+self.width-1, rect.bottom), 
            self.width)
        pygame.draw.line(surface, self.color, 
            (rect.left-(self.width/2)-1, rect.top), 
            (rect.left-(self.width/2)-1, rect.bottom), 
            self.width)
        pygame.draw.line(surface, self.color, 
            (rect.right+(self.width/2)+even_correction, rect.top), 
            (rect.right+(self.width/2)+even_correction, rect.bottom), 
            self.width)