Source code for usf.screens.display
################################################################################
# copyright 2009 Gabriel Pettier <gabriel.pettier@gmail.com> #
# #
# This file is part of Ultimate Smash Friends. #
# #
# Ultimate Smash Friends 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. #
# #
# Ultimate Smash Friends 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 #
# Ultimate Smash Friends. If not, see <http://www.gnu.org/licenses/>. #
################################################################################
'''
This module profide the display configuration screen (resolution,
fullscreen, display fps...)
'''
from usf.screens.screen import Screen
from usf.widgets.box import VBox
from usf.widgets.label import Label
from usf.widgets.checkbox_text import TextCheckBox
from usf.widgets.spinner import Spinner
from usf.widgets.slider import Slider
from usf.widgets.button import Button
from usf.translation import _
from usf import CONFIG
import pygame
[docs]class Display(Screen):
[docs] def init(self):
self.add(VBox())
self.name = _("Display Options")
modes = []
for resolution in pygame.display.list_modes():
if resolution[0] >= 800:
modes.append(str(resolution[0]) + "x" + str(resolution[1]))
modes.reverse()
self.resolution = Spinner(modes, 170)
self.resolution.set_value(str(CONFIG.general.WIDTH) + 'x'
+ str(CONFIG.general.HEIGHT))
self.widget.add(Label(_('Screen resolution (requires a restart):')))
self.widget.add(self.resolution)
self.fullscreen = TextCheckBox(_('Fullscreen:'))
self.fullscreen.set_value(CONFIG.display.FULLSCREEN)
self.widget.add(self.fullscreen)
self.widget.add(Label(_('Zoom sharpness:')), margin=25)
zoom = Slider('zoom_sharpness')
self.widget.add(zoom, margin=10, size=(220, 30))
zoom.set_value(CONFIG.general.ZOOM_SHARPNESS/5)
self.fps = TextCheckBox(_('Show FPS:'))
self.fps.set_value(CONFIG.display.SHOW_FPS)
self.widget.add(self.fps, margin=25)
self.widget.add(Button(_('Back')), margin=30)
[docs] def callback(self, action):
if action == self.resolution:
value = action.get_value()
CONFIG.general.WIDTH = int(value.split('x')[0])
CONFIG.general.HEIGHT = int(value.split('x')[1])
if action == self.fullscreen:
pygame.display.toggle_fullscreen()
if CONFIG.display.FULLSCREEN:
CONFIG.display.FULLSCREEN = False
else:
CONFIG.display.FULLSCREEN = True
if action == self.fps:
if CONFIG.display.SHOW_FPS:
CONFIG.display.SHOW_FPS = False
else:
CONFIG.display.SHOW_FPS = True
if action.text == 'zoom_sharpness':
CONFIG.general.ZOOM_SHARPNESS = (action.get_value()+1)*5
if action.text == _('Back'):
return {'goto': 'back'}
CONFIG.write()