banks.cpp 9.79 KB
Newer Older
ipkiss's avatar
ipkiss committed
1
/*****************************************************************************
2
 * banks.cpp: Bitmap bank, Event bank, Font bank and OffSet bank
ipkiss's avatar
ipkiss committed
3
4
 *****************************************************************************
 * Copyright (C) 2003 VideoLAN
5
 * $Id: banks.cpp,v 1.11 2003/10/17 20:21:59 ipkiss Exp $
ipkiss's avatar
ipkiss committed
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
 *
 * Authors: Olivier Teulire <ipkiss@via.ecp.fr>
 *          Emmanuel Puig    <karibu@via.ecp.fr>
 *
 * 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.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111,
 * USA.
 *****************************************************************************/


//--- VLC -------------------------------------------------------------------
#include <vlc/intf.h>

//--- SKIN ------------------------------------------------------------------
#include "bitmap.h"
32
#include "../os_bitmap.h"
ipkiss's avatar
ipkiss committed
33
#include "event.h"
34
#include "../os_event.h"
ipkiss's avatar
ipkiss committed
35
#include "font.h"
36
#include "../os_font.h"
ipkiss's avatar
ipkiss committed
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
#include "banks.h"
#include "skin_common.h"



//---------------------------------------------------------------------------
//  Bitmap Bank
//---------------------------------------------------------------------------
BitmapBank::BitmapBank( intf_thread_t *_p_intf )
{
    p_intf = _p_intf;

    // Create default bitmap
    Add( DEFAULT_BITMAP_NAME, "", 0 );
}
//---------------------------------------------------------------------------
BitmapBank::~BitmapBank()
{
    for( map<string,Bitmap *>::iterator iter = Bank.begin();
         iter != Bank.end(); iter++ )
    {
        delete (OSBitmap *)iter->second;
    }
}
//---------------------------------------------------------------------------
bool BitmapBank::Add( string Id, string FileName, int AColor )
{
    if( Bank[Id] != NULL )
    {
        msg_Warn( p_intf, "Bitmap name already exists: %s", Id.c_str() );
        return false;
    }

    Bank[Id] = (Bitmap *)new OSBitmap( p_intf, FileName, AColor );
    return true;
}
//---------------------------------------------------------------------------
Bitmap * BitmapBank::Get( string Id )
{
    // If the specified bitmap doesn't exist, use the default one
    if( Bank[Id] == NULL )
    {
        msg_Warn( p_intf, "Unknown bitmap name '%s', using default one",
                  Id.c_str() );
81
        Bank.erase( Id );
ipkiss's avatar
ipkiss committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
        return Bank[DEFAULT_BITMAP_NAME];
    }

    return Bank[Id];
}
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
//  Font Bank
//---------------------------------------------------------------------------
FontBank::FontBank( intf_thread_t *_p_intf )
{
    p_intf = _p_intf;

    // Create default font
    Add( DEFAULT_FONT_NAME, "arial", 12, 0, 400, false, false );
}
//---------------------------------------------------------------------------
FontBank::~FontBank()
{
103
    for( map<string,SkinFont *>::iterator iter = Bank.begin();
ipkiss's avatar
ipkiss committed
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
         iter != Bank.end(); iter++ )
    {
        delete (OSFont *)iter->second;
    }
}
//---------------------------------------------------------------------------
bool FontBank::Add( string name, string fontname, int size,
                    int color, int weight, bool italic, bool underline )
{
    if( Bank[name] != NULL )
    {
        msg_Warn( p_intf, "Font name already exists: %s", name.c_str() );
        return false;
    }

119
    Bank[name] = (SkinFont *)new OSFont( p_intf, fontname, size, color,
ipkiss's avatar
ipkiss committed
120
121
122
123
                                     weight, italic, underline );
    return true;
}
//---------------------------------------------------------------------------
124
SkinFont * FontBank::Get( string Id )
ipkiss's avatar
ipkiss committed
125
126
127
128
129
130
{
    // If the specified font doesn't exist, use the default one
    if( Bank[Id] == NULL )
    {
        msg_Warn( p_intf, "Unknown font name '%s', using default one",
                  Id.c_str() );
131
        Bank.erase( Id );
ipkiss's avatar
ipkiss committed
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
        return Bank[DEFAULT_FONT_NAME];
    }

    return Bank[Id];
}
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
//  Event Bank
//---------------------------------------------------------------------------
EventBank::EventBank( intf_thread_t *_p_intf )
{
    p_intf = _p_intf;

    // Create default event
    Add( DEFAULT_EVENT_NAME, "VLC_NOTHING",             "none" );

    Add( "none",             "VLC_NOTHING",             "none" );
    Add( "time",             "VLC_STREAMPOS",           "none" );
    Add( "left_time",        "VLC_ENDSTREAMPOS",        "none" );
    Add( "total_time",       "VLC_TOTALSTREAMPOS",      "none" );
154
155
    Add( "file_name",        "VLC_STREAM_NAME",         "none" );
    Add( "title",            "VLC_STREAM_TITLE",        "none" );
ipkiss's avatar
ipkiss committed
156
157
    Add( "help",             "VLC_HELP_TEXT",           "none" );

158
    Add( "tray",             "VLC_CHANGE_TRAY",         "none" );
ipkiss's avatar
ipkiss committed
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
    Add( "taskbar",          "VLC_CHANGE_TASKBAR",      "CTRL+B" );

    Add( "playlist_refresh", "CTRL_PLAYLIST",           "none" );
    Add( "play",             "VLC_PLAY",                "X" );
    Add( "pause",            "VLC_PAUSE",               "C" );
    Add( "stop",             "VLC_STOP",                "V" );
    Add( "next",             "VLC_NEXT",                "B" );
    Add( "prev",             "VLC_PREV",                "Z" );
    Add( "fullscreen",       "VLC_FULLSCREEN",          "F" );

    // Volume control
    Add( "mute",             "VLC_VOLUME_CHANGE(MUTE)", "none" );
    Add( "volume_up",        "VLC_VOLUME_CHANGE(UP)",   "none" );
    Add( "volume_down",      "VLC_VOLUME_CHANGE(DOWN)", "none" );
    Add( "volume_refresh",   "VLC_VOLUME_CHANGE(SET)",  "none" );

175
    // Dialogs events
ipkiss's avatar
ipkiss committed
176
177
    Add( "show_log",         "VLC_LOG_SHOW(TRUE)",      "none" );
    Add( "hide_log",         "VLC_LOG_SHOW(FALSE)",     "none" );
178
179
    Add( "show_prefs",       "VLC_PREFS_SHOW",          "none" );
    Add( "show_info",        "VLC_INFO_SHOW",           "none" );
ipkiss's avatar
ipkiss committed
180
181
182

    Add( "quit",             "VLC_HIDE(VLC_QUIT)",      "CTRL+C" );
    Add( "open",             "VLC_OPEN",                "CTRL+O" );
183
    Add( "net",              "VLC_NET",                 "CTRL+N" );
ipkiss's avatar
ipkiss committed
184
185
    Add( "add_file",         "VLC_PLAYLIST_ADD_FILE",   "CTRL+A" );
    Add( "load_skin",        "VLC_LOAD_SKIN",           "CTRL+S" );
ipkiss's avatar
ipkiss committed
186
    Add( "on_top",           "VLC_ON_TOP",              "CTRL+T" );
ipkiss's avatar
ipkiss committed
187
188
189
190
191
192
193
}
//---------------------------------------------------------------------------
EventBank::~EventBank()
{
    for( map<string,Event *>::iterator iter = Bank.begin();
         iter != Bank.end(); iter++ )
    {
194
        iter->second->DestructParameters( true );
ipkiss's avatar
ipkiss committed
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
        delete (OSEvent *)iter->second;
    }
}
//---------------------------------------------------------------------------
bool EventBank::Add( string Name, string EventDesc, string shortcut )
{
    if( Bank[Name] != NULL )
    {
        msg_Warn( p_intf, "Event name already exists: %s", Name.c_str() );
        return false;
    }

    Bank[Name] = (Event *)new OSEvent( p_intf, EventDesc, shortcut );
    return true;
}
//---------------------------------------------------------------------------
void EventBank::TestShortcut( int key, int mod )
{
    for( map<string,Event *>::iterator iter = Bank.begin();
         iter != Bank.end(); iter++ )
    {
        // If key and modifier match to event shortcut, send event
        if( iter->second->MatchShortcut( key, mod ) )
            iter->second->SendEvent();
    }
}
//---------------------------------------------------------------------------
Event * EventBank::Get( string Id )
{
224
    // If the specified event doesn't exist, use the default one
ipkiss's avatar
ipkiss committed
225
226
227
228
    if( Bank[Id] == NULL )
    {
        msg_Warn( p_intf, "Unknown event name '%s', using default one",
                  Id.c_str() );
229
        Bank.erase( Id );
ipkiss's avatar
ipkiss committed
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
        return Bank[DEFAULT_EVENT_NAME];
    }

    return Bank[Id];
}
//---------------------------------------------------------------------------
void EventBank::Init()
{
    for( map<string,Event *>::iterator iter = Bank.begin();
         iter != Bank.end(); iter++ )
    {
        iter->second->CreateEvent();
    }
}
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
//  Offset Bank
//---------------------------------------------------------------------------
OffSetBank::OffSetBank( intf_thread_t *_p_intf )
{
    p_intf = _p_intf;
    XOff = 0;
    YOff = 0;
}
//---------------------------------------------------------------------------
OffSetBank::~OffSetBank()
{
    if( !XList.empty() )
        msg_Warn( p_intf, "At least one offset remains" );
}
//---------------------------------------------------------------------------
void OffSetBank::PushOffSet( int X, int Y )
{
    XList.push_front( X );
    YList.push_front( Y );
    XOff += X;
    YOff += Y;
}
//---------------------------------------------------------------------------
void OffSetBank::PopOffSet()
{
    if( XList.empty() )
    {
        msg_Warn( p_intf, "No offset to pop" );
        return;
    }

    XOff -= XList.front();
    YOff -= YList.front();
    XList.pop_front();
    YList.pop_front();
}
//---------------------------------------------------------------------------
void OffSetBank::GetOffSet( int &X, int &Y )
{
    X = XOff;
    Y = YOff;
}
//---------------------------------------------------------------------------