"""An SDL gui interface"""
"""Adventures on Planet Zephulor by Aaron Hachez. 

   All code, artwork, and sound copyright 2003, Aaron Hachez.

   ----------------------------------------------------------------------------------------

   This file is part of "Adventures on Planet Zephulor".

   A copy of the GNU General Public License should be included with any
   redistribution of this program in a file named "COPYING.txt".

   "Adventures on Planet Zephulor" 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 2 of the License, or
   (at your option) any later version.

   "Adventures on Planet Zephulor" 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 "Adventures on Planet Zephulor"; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

   ----------------------------------------------------------------------------------------

   "Adventures on Planet Zephulor" uses the following libraries:

   PyGame
   SDL

   Both are at the time of this writing, licensed under the GNU LGPL. Please see
   the included file LGPL for details 
"""

import pygame

class base_object:
    """This is the basic object. 
    It has basic data: width, height, x/y, isactive, 
    and functions: getclick, activate, deactivate, move, resize"""

    width = 0
    height = 0
    x = 0
    y = 0
    isactive = 0

    def __init__(self, width=0, height=0, x=0, y=0):
        """Initialize object, no arguments required"""

        self.width = width
        self.height = height
        self.x = x
        self.y = y

    def getclick(self, src):
        """Find out whether or not object has been clicked. Returns non-zero on click"""

        if src.screenrect[0] < self.x:
            return
        if src.screenrect[1] < self.y:
            return
        if src.screenrect[0] > (self.x + self.width):
            return
        if src.screenrect[1] > (self.y + self.height):
            return
        else:
            return(1)

    def activate(self):
        """Activate if deactivated, returns nonzero on success"""

        if self.isactive = 0:
            self.isactive = 1
            return(1)
        else:
            return

    def deactivate(self):
        """Deactivate if activated, returns nonzero on success"""

        if self.isactive = 1:
            self.isactive = 0
            return(1)
        else:
            return

    def move(self, x=None, y=None):
        """Move object by x and y values, return nonzero on success, 1 if move in one direction, 2 if both."""

        retval = 0

        if x != None:
            self.x += x
            retval += 1
        if y != None:
            self.y += y
            retval += 1

        return(retval)
    
    def resize(self, width, height):
        """Resize object to width and height, returns non-zero on success, 1 if resize in one direction, 2 if both"""

        retval = 0

        if width != None:
            self.width = width
            retval += 1
        if height != None:
            self.height = height
            retval += 1

        return(retval)


class base_text(base_object):
    """A basic text object"""

    text = None
    size = 36

    def write(self, text, screen):
        """Print text to screen"""
        if pygame.font:
            font = pygame.font.Font(None, self.size)
            text = font.render(text, 1, (210, 210, 210))
            srcrect = (0, 0, self.width, self.height)
            #textpos.centerx = background.get_rect().centerx
            #background.fill((0, 0, 0))
            screen.blit(text, (self.x, self.y), srcrect)

            # Copy text for later use
            self.text = text

    def setsize(self, size):
        """Set the font size, return non-zero on success"""

        if size != None:
            self.size = size
            return(1)
        else:
            return








