]> git.sesse.net Git - vlc/blob - modules/gui/skins/src/banks.cpp
* modules/gui/skins/*:
[vlc] / modules / gui / skins / src / banks.cpp
1 /*****************************************************************************
2  * banks.cpp: Bitmap bank, Event bank, Font bank and OffSet bank
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: banks.cpp,v 1.12 2004/02/15 18:58:38 ipkiss Exp $
6  *
7  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8  *          Emmanuel Puig    <karibu@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111,
23  * USA.
24  *****************************************************************************/
25
26
27 //--- VLC -------------------------------------------------------------------
28 #include <vlc/intf.h>
29
30 //--- SKIN ------------------------------------------------------------------
31 #include "bitmap.h"
32 #include "../os_bitmap.h"
33 #include "event.h"
34 #include "../os_event.h"
35 #include "font.h"
36 #include "../os_font.h"
37 #include "banks.h"
38 #include "skin_common.h"
39
40
41
42 //---------------------------------------------------------------------------
43 //  Bitmap Bank
44 //---------------------------------------------------------------------------
45 BitmapBank::BitmapBank( intf_thread_t *_p_intf )
46 {
47     p_intf = _p_intf;
48
49     // Create default bitmap
50     Add( DEFAULT_BITMAP_NAME, "", 0 );
51 }
52 //---------------------------------------------------------------------------
53 BitmapBank::~BitmapBank()
54 {
55     for( map<string,Bitmap *>::iterator iter = Bank.begin();
56          iter != Bank.end(); iter++ )
57     {
58         delete (OSBitmap *)iter->second;
59     }
60 }
61 //---------------------------------------------------------------------------
62 bool BitmapBank::Add( string Id, string FileName, int AColor )
63 {
64     if( Bank[Id] != NULL )
65     {
66         msg_Warn( p_intf, "Bitmap name already exists: %s", Id.c_str() );
67         return false;
68     }
69
70     Bank[Id] = (Bitmap *)new OSBitmap( p_intf, FileName, AColor );
71     return true;
72 }
73 //---------------------------------------------------------------------------
74 Bitmap * BitmapBank::Get( string Id )
75 {
76     // If the specified bitmap doesn't exist, use the default one
77     if( Bank[Id] == NULL )
78     {
79         msg_Warn( p_intf, "Unknown bitmap name '%s', using default one",
80                   Id.c_str() );
81         Bank.erase( Id );
82         return Bank[DEFAULT_BITMAP_NAME];
83     }
84
85     return Bank[Id];
86 }
87 //---------------------------------------------------------------------------
88
89
90 //---------------------------------------------------------------------------
91 //  Font Bank
92 //---------------------------------------------------------------------------
93 FontBank::FontBank( intf_thread_t *_p_intf )
94 {
95     p_intf = _p_intf;
96
97     // Create default font
98     Add( DEFAULT_FONT_NAME, "arial", 12, 0, 400, false, false );
99 }
100 //---------------------------------------------------------------------------
101 FontBank::~FontBank()
102 {
103     for( map<string,SkinFont *>::iterator iter = Bank.begin();
104          iter != Bank.end(); iter++ )
105     {
106         delete (OSFont *)iter->second;
107     }
108 }
109 //---------------------------------------------------------------------------
110 bool FontBank::Add( string name, string fontname, int size,
111                     int color, int weight, bool italic, bool underline )
112 {
113     if( Bank[name] != NULL )
114     {
115         msg_Warn( p_intf, "Font name already exists: %s", name.c_str() );
116         return false;
117     }
118
119     Bank[name] = (SkinFont *)new OSFont( p_intf, fontname, size, color,
120                                      weight, italic, underline );
121     return true;
122 }
123 //---------------------------------------------------------------------------
124 SkinFont * FontBank::Get( string Id )
125 {
126     // If the specified font doesn't exist, use the default one
127     if( Bank[Id] == NULL )
128     {
129         msg_Warn( p_intf, "Unknown font name '%s', using default one",
130                   Id.c_str() );
131         Bank.erase( Id );
132         return Bank[DEFAULT_FONT_NAME];
133     }
134
135     return Bank[Id];
136 }
137 //---------------------------------------------------------------------------
138
139
140 //---------------------------------------------------------------------------
141 //  Event Bank
142 //---------------------------------------------------------------------------
143 EventBank::EventBank( intf_thread_t *_p_intf )
144 {
145     p_intf = _p_intf;
146
147     // Create default event
148     Add( DEFAULT_EVENT_NAME, "VLC_NOTHING",             "none" );
149
150     Add( "none",             "VLC_NOTHING",             "none" );
151     Add( "time",             "VLC_STREAMPOS",           "none" );
152     Add( "left_time",        "VLC_ENDSTREAMPOS",        "none" );
153     Add( "total_time",       "VLC_TOTALSTREAMPOS",      "none" );
154     Add( "file_name",        "VLC_STREAM_NAME",         "none" );
155     Add( "title",            "VLC_STREAM_TITLE",        "none" );
156     Add( "help",             "VLC_HELP_TEXT",           "none" );
157
158     Add( "tray",             "VLC_CHANGE_TRAY",         "none" );
159     Add( "taskbar",          "VLC_CHANGE_TASKBAR",      "CTRL+B" );
160
161     Add( "playlist_refresh", "CTRL_PLAYLIST",           "none" );
162     Add( "play",             "VLC_PLAY",                "X" );
163     Add( "pause",            "VLC_PAUSE",               "C" );
164     Add( "stop",             "VLC_STOP",                "V" );
165     Add( "next",             "VLC_NEXT",                "B" );
166     Add( "prev",             "VLC_PREV",                "Z" );
167     Add( "slow",             "VLC_SLOWER",              "none" );
168     Add( "fast",             "VLC_FASTER",              "none" );
169     Add( "fullscreen",       "VLC_FULLSCREEN",          "F" );
170
171     // Volume control
172     Add( "mute",             "VLC_VOLUME_CHANGE(MUTE)", "none" );
173     Add( "volume_up",        "VLC_VOLUME_CHANGE(UP)",   "none" );
174     Add( "volume_down",      "VLC_VOLUME_CHANGE(DOWN)", "none" );
175     Add( "volume_refresh",   "VLC_VOLUME_CHANGE(SET)",  "none" );
176
177     // Dialogs events
178     Add( "show_log",         "VLC_LOG_SHOW(TRUE)",      "none" );
179     Add( "hide_log",         "VLC_LOG_SHOW(FALSE)",     "none" );
180     Add( "show_prefs",       "VLC_PREFS_SHOW",          "none" );
181     Add( "show_info",        "VLC_INFO_SHOW",           "none" );
182
183     Add( "quit",             "VLC_HIDE(VLC_QUIT)",      "CTRL+C" );
184     Add( "open",             "VLC_OPEN",                "CTRL+O" );
185     Add( "net",              "VLC_NET",                 "CTRL+N" );
186     Add( "add_file",         "VLC_PLAYLIST_ADD_FILE",   "CTRL+A" );
187     Add( "load_skin",        "VLC_LOAD_SKIN",           "CTRL+S" );
188     Add( "on_top",           "VLC_ON_TOP",              "CTRL+T" );
189 }
190 //---------------------------------------------------------------------------
191 EventBank::~EventBank()
192 {
193     for( map<string,Event *>::iterator iter = Bank.begin();
194          iter != Bank.end(); iter++ )
195     {
196         iter->second->DestructParameters( true );
197         delete (OSEvent *)iter->second;
198     }
199 }
200 //---------------------------------------------------------------------------
201 bool EventBank::Add( string Name, string EventDesc, string shortcut )
202 {
203     if( Bank[Name] != NULL )
204     {
205         msg_Warn( p_intf, "Event name already exists: %s", Name.c_str() );
206         return false;
207     }
208
209     Bank[Name] = (Event *)new OSEvent( p_intf, EventDesc, shortcut );
210     return true;
211 }
212 //---------------------------------------------------------------------------
213 void EventBank::TestShortcut( int key, int mod )
214 {
215     for( map<string,Event *>::iterator iter = Bank.begin();
216          iter != Bank.end(); iter++ )
217     {
218         // If key and modifier match to event shortcut, send event
219         if( iter->second->MatchShortcut( key, mod ) )
220             iter->second->SendEvent();
221     }
222 }
223 //---------------------------------------------------------------------------
224 Event * EventBank::Get( string Id )
225 {
226     // If the specified event doesn't exist, use the default one
227     if( Bank[Id] == NULL )
228     {
229         msg_Warn( p_intf, "Unknown event name '%s', using default one",
230                   Id.c_str() );
231         Bank.erase( Id );
232         return Bank[DEFAULT_EVENT_NAME];
233     }
234
235     return Bank[Id];
236 }
237 //---------------------------------------------------------------------------
238 void EventBank::Init()
239 {
240     for( map<string,Event *>::iterator iter = Bank.begin();
241          iter != Bank.end(); iter++ )
242     {
243         iter->second->CreateEvent();
244     }
245 }
246 //---------------------------------------------------------------------------
247
248
249 //---------------------------------------------------------------------------
250 //  Offset Bank
251 //---------------------------------------------------------------------------
252 OffSetBank::OffSetBank( intf_thread_t *_p_intf )
253 {
254     p_intf = _p_intf;
255     XOff = 0;
256     YOff = 0;
257 }
258 //---------------------------------------------------------------------------
259 OffSetBank::~OffSetBank()
260 {
261     if( !XList.empty() )
262         msg_Warn( p_intf, "At least one offset remains" );
263 }
264 //---------------------------------------------------------------------------
265 void OffSetBank::PushOffSet( int X, int Y )
266 {
267     XList.push_front( X );
268     YList.push_front( Y );
269     XOff += X;
270     YOff += Y;
271 }
272 //---------------------------------------------------------------------------
273 void OffSetBank::PopOffSet()
274 {
275     if( XList.empty() )
276     {
277         msg_Warn( p_intf, "No offset to pop" );
278         return;
279     }
280
281     XOff -= XList.front();
282     YOff -= YList.front();
283     XList.pop_front();
284     YList.pop_front();
285 }
286 //---------------------------------------------------------------------------
287 void OffSetBank::GetOffSet( int &X, int &Y )
288 {
289     X = XOff;
290     Y = YOff;
291 }
292 //---------------------------------------------------------------------------
293