]> git.sesse.net Git - vlc/blob - modules/gui/skins/src/banks.cpp
* Added use of channel server for skins: still experimental
[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.2 2003/04/14 10:00:38 karibu 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         return Bank[DEFAULT_BITMAP_NAME];
82     }
83
84     return Bank[Id];
85 }
86 //---------------------------------------------------------------------------
87
88
89 //---------------------------------------------------------------------------
90 //  Font Bank
91 //---------------------------------------------------------------------------
92 FontBank::FontBank( intf_thread_t *_p_intf )
93 {
94     p_intf = _p_intf;
95
96     // Create default font
97     Add( DEFAULT_FONT_NAME, "arial", 12, 0, 400, false, false );
98 }
99 //---------------------------------------------------------------------------
100 FontBank::~FontBank()
101 {
102     for( map<string,Font *>::iterator iter = Bank.begin();
103          iter != Bank.end(); iter++ )
104     {
105         delete (OSFont *)iter->second;
106     }
107 }
108 //---------------------------------------------------------------------------
109 bool FontBank::Add( string name, string fontname, int size,
110                     int color, int weight, bool italic, bool underline )
111 {
112     if( Bank[name] != NULL )
113     {
114         msg_Warn( p_intf, "Font name already exists: %s", name.c_str() );
115         return false;
116     }
117
118     Bank[name] = (Font *)new OSFont( p_intf, fontname, size, color,
119                                      weight, italic, underline );
120     return true;
121 }
122 //---------------------------------------------------------------------------
123 Font * FontBank::Get( string Id )
124 {
125     // If the specified font doesn't exist, use the default one
126     if( Bank[Id] == NULL )
127     {
128         msg_Warn( p_intf, "Unknown font name '%s', using default one",
129                   Id.c_str() );
130         return Bank[DEFAULT_FONT_NAME];
131     }
132
133     return Bank[Id];
134 }
135 //---------------------------------------------------------------------------
136
137
138 //---------------------------------------------------------------------------
139 //  Event Bank
140 //---------------------------------------------------------------------------
141 EventBank::EventBank( intf_thread_t *_p_intf )
142 {
143     p_intf = _p_intf;
144
145     // Create default event
146     Add( DEFAULT_EVENT_NAME, "VLC_NOTHING",             "none" );
147
148     Add( "none",             "VLC_NOTHING",             "none" );
149     Add( "time",             "VLC_STREAMPOS",           "none" );
150     Add( "left_time",        "VLC_ENDSTREAMPOS",        "none" );
151     Add( "total_time",       "VLC_TOTALSTREAMPOS",      "none" );
152     Add( "file_name",        "VLC_STREAMNAME",          "none" );
153     Add( "help",             "VLC_HELP_TEXT",           "none" );
154
155     Add( "tray",             "VLC_CHANGE_TRAY",         "CTRL+T" );
156     Add( "taskbar",          "VLC_CHANGE_TASKBAR",      "CTRL+B" );
157
158     Add( "playlist_refresh", "CTRL_PLAYLIST",           "none" );
159     Add( "play",             "VLC_PLAY",                "X" );
160     Add( "pause",            "VLC_PAUSE",               "C" );
161     Add( "stop",             "VLC_STOP",                "V" );
162     Add( "next",             "VLC_NEXT",                "B" );
163     Add( "prev",             "VLC_PREV",                "Z" );
164     Add( "fullscreen",       "VLC_FULLSCREEN",          "F" );
165
166     // Volume control
167     Add( "mute",             "VLC_VOLUME_CHANGE(MUTE)", "none" );
168     Add( "volume_up",        "VLC_VOLUME_CHANGE(UP)",   "none" );
169     Add( "volume_down",      "VLC_VOLUME_CHANGE(DOWN)", "none" );
170     Add( "volume_refresh",   "VLC_VOLUME_CHANGE(SET)",  "none" );
171
172     // Log events
173     Add( "show_log",         "VLC_LOG_SHOW(TRUE)",      "none" );
174     Add( "hide_log",         "VLC_LOG_SHOW(FALSE)",     "none" );
175     Add( "clear_log",        "VLC_LOG_CLEAR",           "none" );
176
177     Add( "quit",             "VLC_HIDE(VLC_QUIT)",      "CTRL+C" );
178     Add( "open",             "VLC_OPEN",                "CTRL+O" );
179     Add( "add_file",         "VLC_PLAYLIST_ADD_FILE",   "CTRL+A" );
180     Add( "load_skin",        "VLC_LOAD_SKIN",           "CTRL+S" );
181
182 }
183 //---------------------------------------------------------------------------
184 EventBank::~EventBank()
185 {
186     for( map<string,Event *>::iterator iter = Bank.begin();
187          iter != Bank.end(); iter++ )
188     {
189         iter->second->DestructParameters( true );
190         delete (OSEvent *)iter->second;
191     }
192 }
193 //---------------------------------------------------------------------------
194 bool EventBank::Add( string Name, string EventDesc, string shortcut )
195 {
196     if( Bank[Name] != NULL )
197     {
198         msg_Warn( p_intf, "Event name already exists: %s", Name.c_str() );
199         return false;
200     }
201
202     Bank[Name] = (Event *)new OSEvent( p_intf, EventDesc, shortcut );
203     return true;
204 }
205 //---------------------------------------------------------------------------
206 void EventBank::TestShortcut( int key, int mod )
207 {
208     for( map<string,Event *>::iterator iter = Bank.begin();
209          iter != Bank.end(); iter++ )
210     {
211         // If key and modifier match to event shortcut, send event
212         if( iter->second->MatchShortcut( key, mod ) )
213             iter->second->SendEvent();
214     }
215 }
216 //---------------------------------------------------------------------------
217 Event * EventBank::Get( string Id )
218 {
219     // If the specified font doesn't exist, use the default one
220     if( Bank[Id] == NULL )
221     {
222         msg_Warn( p_intf, "Unknown event name '%s', using default one",
223                   Id.c_str() );
224         return Bank[DEFAULT_EVENT_NAME];
225     }
226
227     return Bank[Id];
228 }
229 //---------------------------------------------------------------------------
230 void EventBank::Init()
231 {
232     for( map<string,Event *>::iterator iter = Bank.begin();
233          iter != Bank.end(); iter++ )
234     {
235         iter->second->CreateEvent();
236     }
237 }
238 //---------------------------------------------------------------------------
239
240
241 //---------------------------------------------------------------------------
242 //  Offset Bank
243 //---------------------------------------------------------------------------
244 OffSetBank::OffSetBank( intf_thread_t *_p_intf )
245 {
246     p_intf = _p_intf;
247     XOff = 0;
248     YOff = 0;
249 }
250 //---------------------------------------------------------------------------
251 OffSetBank::~OffSetBank()
252 {
253     if( !XList.empty() )
254         msg_Warn( p_intf, "At least one offset remains" );
255 }
256 //---------------------------------------------------------------------------
257 void OffSetBank::PushOffSet( int X, int Y )
258 {
259     XList.push_front( X );
260     YList.push_front( Y );
261     XOff += X;
262     YOff += Y;
263 }
264 //---------------------------------------------------------------------------
265 void OffSetBank::PopOffSet()
266 {
267     if( XList.empty() )
268     {
269         msg_Warn( p_intf, "No offset to pop" );
270         return;
271     }
272
273     XOff -= XList.front();
274     YOff -= YList.front();
275     XList.pop_front();
276     YList.pop_front();
277 }
278 //---------------------------------------------------------------------------
279 void OffSetBank::GetOffSet( int &X, int &Y )
280 {
281     X = XOff;
282     Y = YOff;
283 }
284 //---------------------------------------------------------------------------
285