File: gui_theme.c

package info (click to toggle)
lbreakout2 2.5.2-2.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 6,040 kB
  • ctags: 2,374
  • sloc: ansic: 20,911; sh: 2,891; makefile: 374
file content (149 lines) | stat: -rw-r--r-- 5,757 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/***************************************************************************
                          gui_theme.c  -  description
                             -------------------
    begin                : Fri Oct 11 2002
    copyright            : (C) 2002 by Michael Speck
    email                : kulkanie@gmx.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "gui_theme.h"

#define ABORT( msg ) { fprintf( stderr, "%s\n", msg ); exit(1); }

GuiTheme *gui_theme = 0;

/*
====================================================================
Load a theme from a theme directory. The surface path set by
stk_surface_set_path() is prepended.
====================================================================
*/

GuiTheme* gui_theme_load( char *name )
{
    GuiTheme *theme = calloc( 1, sizeof( GuiTheme ) );
    if ( theme == 0 ) ABORT( "Out Of Memory" )

    theme->box_wallpaper = 
        stk_surface_load( SDL_SWSURFACE, 
            "%s/box_wallpaper.png", name );
    theme->widget_wallpaper = 
        stk_surface_load( SDL_SWSURFACE, 
            "%s/widget_wallpaper.png", name );
    theme->box_frame = 
        stk_surface_load( SDL_SWSURFACE, 
            "%s/box_frame.png", name );
    theme->widget_frame = 
        stk_surface_load( SDL_SWSURFACE, 
            "%s/widget_frame.png", name );
    theme->button_frame_normal = 
        stk_surface_load( SDL_SWSURFACE, 
            "%s/button_frame_normal.png", name );
    theme->button_frame_clicked = 
        stk_surface_load( SDL_SWSURFACE, 
            "%s/button_frame_clicked.png", name );
    theme->button_wallpaper_normal = 
        stk_surface_load( SDL_SWSURFACE, 
            "%s/button_wallpaper_normal.png", name );
    theme->button_wallpaper_focused = 
        stk_surface_load( SDL_SWSURFACE, 
            "%s/button_wallpaper_focused.png", name );
    theme->scrollbar_arrows = 
        stk_surface_load( SDL_SWSURFACE, 
            "%s/scrollbar_arrows.png", name );
    theme->scrollbar_arrow_size =
        theme->scrollbar_arrows->h;
    theme->checkbox = 
        stk_surface_load( SDL_SWSURFACE, 
            "%s/checkbox.png", name );
    theme->checkbox_size = theme->checkbox->h;
    theme->progress_high = 
        stk_surface_load( SDL_SWSURFACE, 
            "%s/progress_high.png", name );
    theme->progress_medium = 
        stk_surface_load( SDL_SWSURFACE, 
            "%s/progress_medium.png", name );
    theme->progress_low = 
        stk_surface_load( SDL_SWSURFACE, 
            "%s/progress_low.png", name );
    theme->list_item_color = 
        stk_surface_load( SDL_SWSURFACE, 
            "%s/list_item_color.png", name );
    theme->spinbutton_arrows = 
        stk_surface_load( SDL_SWSURFACE, 
            "%s/spinbutton_arrows.png", name );
    theme->spinbutton_arrow_size = 
        theme->spinbutton_arrows->h;

    theme->font =
        stk_font_load( SDL_SWSURFACE, "%s/font.png", name );
    theme->edit_font =
        stk_font_load( SDL_SWSURFACE, "%s/font.png", name );
    theme->label_font =
        stk_font_load( SDL_SWSURFACE, "%s/font.png", name );
    theme->button_font = theme->font;
    theme->progressbar_font = theme->font;
    
    theme->click_sound = 
        stk_sound_load( -1, "%s/click.wav", name );
    theme->type_sound = 
        stk_sound_load( -1, "%s/edit.wav", name );
    
    return theme;
}

/*
====================================================================
Free the memory of a surface if not NULL and reset the pointer
to NULL.
====================================================================
*/
void gui_theme_delete( GuiTheme **theme )
{
    if ( *theme ) {
        stk_surface_free( &(*theme)->box_wallpaper );
        stk_surface_free( &(*theme)->widget_wallpaper );
        stk_surface_free( &(*theme)->box_frame );
        stk_surface_free( &(*theme)->widget_frame );
        stk_surface_free( &(*theme)->button_frame_normal );
        stk_surface_free( &(*theme)->button_frame_clicked );
        stk_surface_free( &(*theme)->button_wallpaper_normal );
        stk_surface_free( &(*theme)->button_wallpaper_focused );
        stk_surface_free( &(*theme)->scrollbar_arrows );
        stk_surface_free( &(*theme)->checkbox );
        stk_surface_free( &(*theme)->progress_high );
        stk_surface_free( &(*theme)->progress_medium );
        stk_surface_free( &(*theme)->progress_low );
        stk_surface_free( &(*theme)->list_item_color );
        stk_surface_free( &(*theme)->spinbutton_arrows );
        stk_font_free( &(*theme)->font );
        stk_font_free( &(*theme)->edit_font );
        stk_font_free( &(*theme)->label_font );
        stk_sound_free( &(*theme)->click_sound );
        stk_sound_free( &(*theme)->type_sound );
        free( *theme ); *theme = 0;
    }
}

/*
====================================================================
Select the current theme. New widgets will use its graphics.
====================================================================
*/
void gui_theme_select( GuiTheme *theme )
{
    gui_theme = theme;
}