Source

Fat x Fast / FatxFast / graphics.py

Full commit
# 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.4"

import pygame
import os
from FatxFast.resource import resource_manager
from FatxFast import config

os.environ['SDL_VIDEO_CENTERED'] = '1'

SCREENSIZE = (960, 640)

class Graphics(object):

    def __init__(self, reso=SCREENSIZE, config=config.Config()):
        self.reso = reso
        self.config = config
        flags = 0
        if self.config.fullscreen:
            flags = flags | pygame.FULLSCREEN
        self.screen = pygame.display.set_mode(reso, flags)
        self.icon_image = resource_manager.load_image("ico.gif")
        pygame.display.set_icon(self.icon_image)
        self.set_background((50,50,50))
        self.fill_background()
        self.fullscreen = False
        self.caption = "WINDOW NAME UNDEFINED"

    def fill_background(self):
        self.screen.fill(self.bgcolor)

    def get_screen(self):
        return self.screen
    
    def set_background(self, color):
        self.bgcolor = color

    def set_title(self, title):
        self.caption = title
        pygame.display.set_caption(title)

    def toggle_fullscreen(self):
        pygame.display.quit()
        pygame.display.init()
        if self.fullscreen:
            self.fullscreen = False
            flags = 0
        else:
            self.fullscreen = True
            flags = pygame.FULLSCREEN
        self.screen = pygame.display.set_mode(self.reso, flags)
        self.set_title(self.caption)

    def update(self):
        pygame.display.flip()