Module Theme
[hide private]
[frames] | no frames]

Source Code for Module Theme

 1  #####################################################################
 
 2  # -*- coding: iso-8859-1 -*-                                        #
 
 3  #                                                                   #
 
 4  # Frets on Fire                                                     #
 
 5  # Copyright (C) 2006 Sami Kyöstilä                                  #
 
 6  #                                                                   #
 
 7  # This program is free software; you can redistribute it and/or     #
 
 8  # modify it under the terms of the GNU General Public License       #
 
 9  # as published by the Free Software Foundation; either version 2    #
 
10  # of the License, or (at your option) any later version.            #
 
11  #                                                                   #
 
12  # This program is distributed in the hope that it will be useful,   #
 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of    #
 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     #
 
15  # GNU General Public License for more details.                      #
 
16  #                                                                   #
 
17  # You should have received a copy of the GNU General Public License #
 
18  # along with this program; if not, write to the Free Software       #
 
19  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,        #
 
20  # MA  02110-1301, USA.                                              #
 
21  #####################################################################
 
22  
 
23  from OpenGL.GL import * 
24  import Config 
25  
 
26  # read the color scheme from the config file
 
27  Config.define("theme", "background_color",  str, "#330000") 
28  Config.define("theme", "base_color",        str, "#FFFF80") 
29  Config.define("theme", "selected_color",    str, "#FFBF00") 
30  Config.define("theme", "fret0_color",       str, "#22FF22") 
31  Config.define("theme", "fret1_color",       str, "#FF2222") 
32  Config.define("theme", "fret2_color",       str, "#FFFF22") 
33  Config.define("theme", "fret3_color",       str, "#3333FF") 
34  Config.define("theme", "fret4_color",       str, "#FF22FF") 
35  
 
36 -def hexToColor(color):
37 if color[0] == "#": 38 color = color[1:] 39 if len(color) == 3: 40 return (int(color[0], 16) / 15.0, int(color[1], 16) / 15.0, int(color[2], 16) / 15.0) 41 return (int(color[0:2], 16) / 255.0, int(color[2:4], 16) / 255.0, int(color[4:6], 16) / 255.0) 42 return (0, 0, 0)
43
44 -def colorToHex(color):
45 return "#" + ("".join(["%02x" % int(c * 255) for c in color]))
46 47 backgroundColor = None 48 baseColor = None 49 selectedColor = None 50 fretColors = None 51
52 -def open(config):
53 global backgroundColor, baseColor, selectedColor, fretColors 54 backgroundColor = hexToColor(config.get("theme", "background_color")) 55 baseColor = hexToColor(config.get("theme", "base_color")) 56 selectedColor = hexToColor(config.get("theme", "selected_color")) 57 fretColors = [hexToColor(config.get("theme", "fret%d_color" % i)) for i in range(5)]
58
59 -def setSelectedColor(alpha = 1.0):
60 glColor4f(*(selectedColor + (alpha,)))
61
62 -def setBaseColor(alpha = 1.0):
63 glColor4f(*(baseColor + (alpha,)))
64