diff options
author | Alan Aguiar <alanjas@hotmail.com> | 2012-10-17 01:10:23 (GMT) |
---|---|---|
committer | Alan Aguiar <alanjas@hotmail.com> | 2012-10-17 01:10:23 (GMT) |
commit | ba6da3f4e9665e8bb8f6be64f09f40698980861a (patch) | |
tree | 5689f406a65a1b9185781a62b705ea5f38542d3e /gui.py |
add all files of version 1
Diffstat (limited to 'gui.py')
-rw-r--r-- | gui.py | 128 |
1 files changed, 128 insertions, 0 deletions
@@ -0,0 +1,128 @@ +#!/usr/bin/env python2.5 +############################################################################ +# Copyright (C) 2007 by kawk # +# kawk@theprogrammingsite.com # +# # +# This file is a generic GUI library for the FiftyTwo card game set. # +# FiftyTwo is a set of card games for the OLPC XO laptop. # +# # +# This program 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. # +# # +# This program 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 this program; if not, write to the # +# Free Software Foundation, Inc., # +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # +############################################################################ + +import pygame +from pygame.locals import * +import olpcgames +import olpcgames.pausescreen +import fiftytwo + +class widget(pygame.sprite.Sprite): + def __init__(self, position, size): + pygame.sprite.Sprite.__init__(self) + self.visible = 0 + self.rect = Rect(((0, 0), (0, 0))) + self.rect.move_ip(position) + self.rect.w = size[0] + self.rect.h = size[1] + self.special = 0 + + def detect_click(self, mouseposition): + if mouseposition[0] > self.rect.left and mouseposition[0] < self.rect.right: + if mouseposition[1] > self.rect.top and mouseposition[1] < self.rect.bottom: + print self.rect + print mouseposition + return True + + return False + +class container(pygame.sprite.OrderedUpdates): + def __init__(self, widgets, position, size): + pygame.sprite.OrderedUpdates.__init__(self, widgets) + self.rect = Rect((position, size)) + + def draw(self, surface, mouseposition): + for s in self.sprites(): + if s.special and mouseposition[0] > s.rect.left and mouseposition[0] < s.rect.right \ + and mouseposition[1] > s.rect.top and mouseposition[1] < s.rect.bottom: + if mouseposition[2] is not 0: + surface.blit(s.clickimage, s.rect) + else: + surface.blit(s.hoverimage, s.rect) + else: + surface.blit(s.image, s.rect) + +class label(widget): + def __init__(self, position, size, title, color, textsize=38): + widget.__init__(self, position, size) + font = pygame.font.Font(None, textsize) + self.image = font.render(title, 1, color) + self.image = self.image.convert_alpha() + self.rect = self.image.get_rect() + self.rect.x = position[0] + self.rect.y = position[1] + + +class image(widget): + def __init__(self, position, size, file, trans=None): + widget.__init__(self, position, size) + self.image, self.rect = fiftytwo.load_image(file, trans) + self.rect.x = position[0] + self.rect.y = position[1] + +class button(widget): + def __init__(self, position, size, title): + widget.__init__(self, position, size) + self.special = 1 + self.label = label(position, size, title, (255, 255, 255)) + self.image = pygame.Surface(size) + self.hoverimage = pygame.Surface(size) + self.clickimage = pygame.Surface(size) + leftrect = self.image.get_rect() + leftrect.x = 0 + leftrect.y = 0 + leftrect.w = 32 + leftrect.h = size[1] + pygame.draw.ellipse(self.image, (128, 128, 128), leftrect) + pygame.draw.ellipse(self.hoverimage, (176, 176, 176), leftrect) + pygame.draw.ellipse(self.clickimage, (208, 208, 208), leftrect) + leftrect.x = size[0]-32 + pygame.draw.ellipse(self.image, (128, 128, 128), leftrect) + pygame.draw.ellipse(self.hoverimage, (176, 176, 176), leftrect) + pygame.draw.ellipse(self.clickimage, (208, 208, 208), leftrect) + self.image.fill((128, 128, 128), ((16, 0), (size[0]-32, size[1]))) + self.hoverimage.fill((176, 176, 176), ((16, 0), (size[0]-32, size[1]))) + self.clickimage.fill((208, 208, 208), ((16, 0), (size[0]-32, size[1]))) + self.image.blit(self.label.image, (10, 4)) + self.hoverimage.blit(self.label.image, (10, 4)) + self.clickimage.blit(self.label.image, (10, 4)) + self.image.set_colorkey((0, 0, 0), pygame.RLEACCEL) + self.hoverimage.set_colorkey((0, 0, 0), pygame.RLEACCEL) + self.clickimage.set_colorkey((0, 0, 0), pygame.RLEACCEL) + +class frame(container): + def __init__(self, widgets, position, size): + container.__init__(self, widgets, position, size) + + def draw(self, surface, mouseposition): + container.draw(self, surface, mouseposition) + pygame.draw.rect(surface, (32, 32, 32), self.rect, 5) + +class popup(frame): + def __init__(self, widgets, position, size): + frame.__init__(self, widgets, position, size) + + def draw(self, surface, mouseposition): + surface.fill((48, 48, 48), self.rect) + frame.draw(self, surface, mouseposition) |