1 /*****************************************************************************
2 * wrappers.cpp: Wrappers around C++ objects
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: wrappers.cpp,v 1.10 2003/04/21 21:51:16 asmax Exp $
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8 * Emmanuel Puig <karibu@via.ecp.fr>
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.
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.
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,
24 *****************************************************************************/
27 //--- GENERAL ---------------------------------------------------------------
32 //--- VLC -------------------------------------------------------------------
34 extern intf_thread_t *g_pIntf;
36 //--- SKIN ------------------------------------------------------------------
37 #include "../src/anchor.h"
38 #include "../src/banks.h"
39 #include "../controls/controls.h"
40 #include "../src/font.h"
41 #include "../os_font.h"
42 #include "../src/window.h"
43 #include "../src/theme.h"
44 #include "../src/skin_common.h"
48 //---------------------------------------------------------------------------
50 //---------------------------------------------------------------------------
51 static bool ConvertBoolean( const char *value );
52 static int ConvertColor( const char *transcolor );
53 static int CheckCoords( const char *coord );
54 static void ConvertCoords( char *coord, double *p_coord );
55 static int ConvertAlign( char *align );
57 //---------------------------------------------------------------------------
59 //---------------------------------------------------------------------------
60 void AddBitmap( char *name, char *file, char *transcolor )
62 g_pIntf->p_sys->p_theme->BmpBank->Add( name, file,
63 ConvertColor( transcolor ) );
65 //---------------------------------------------------------------------------
66 void AddEvent( char *name, char *event, char *key )
68 g_pIntf->p_sys->p_theme->EvtBank->Add( name, event, key );
70 //---------------------------------------------------------------------------
71 void AddFont( char *name, char *font, char *size, char *color,
72 char *weight, char *italic, char *underline )
74 g_pIntf->p_sys->p_theme->FntBank->Add(
75 name, font, atoi( size ), ConvertColor( color ), atoi( weight ),
76 ConvertBoolean( italic ), ConvertBoolean( underline ) );
78 //---------------------------------------------------------------------------
79 void AddThemeInfo( char *name, char *author, char *email, char *webpage )
81 g_pIntf->p_sys->p_theme->ChangeClientWindowName(
82 "VLC Media Player - " + (string)name );
84 //---------------------------------------------------------------------------
85 void StartWindow( char *name, char *x, char *y, char *visible, char *fadetime,
86 char *alpha, char *movealpha, char *dragdrop )
88 g_pIntf->p_sys->p_theme->AddWindow( name, atoi( x ), atoi( y ),
89 ConvertBoolean( visible ), atoi( fadetime ), atoi( alpha ),
90 atoi( movealpha ), ConvertBoolean( dragdrop ) );
92 //---------------------------------------------------------------------------
96 //---------------------------------------------------------------------------
97 void StartTheme( char *magnet )
99 g_pIntf->p_sys->p_theme->StartTheme( atoi( magnet ) );
101 //---------------------------------------------------------------------------
105 //---------------------------------------------------------------------------
106 void StartControlGroup( char *x, char *y )
108 g_pIntf->p_sys->p_theme->OffBank->PushOffSet( atoi( x ), atoi( y ) );
110 //---------------------------------------------------------------------------
111 void EndControlGroup()
113 g_pIntf->p_sys->p_theme->OffBank->PopOffSet();
116 //---------------------------------------------------------------------------
117 void AddAnchor( char *x, char *y, char *len, char *priority )
120 SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
122 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
124 vlcWin->AnchorList.push_back( new Anchor( g_pIntf, atoi( x ) + XOff,
125 atoi( y ) + YOff, atoi( len ),
126 atoi( priority ), vlcWin ) );
128 //---------------------------------------------------------------------------
133 //---------------------------------------------------------------------------
135 //---------------------------------------------------------------------------
136 void AddImage( char *id, char *visible, char *x, char *y, char *image,
137 char *event, char *help )
140 SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
142 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
144 vlcWin->ControlList.push_back( new ControlImage( id,
145 ConvertBoolean( visible ), atoi( x ) + XOff,
146 atoi( y ) + YOff, image, event, help, vlcWin ) );
148 //---------------------------------------------------------------------------
149 void AddRectangle( char *id, char *visible, char *x, char *y, char *w, char *h,
150 char *color, char *event, char *help )
153 SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
155 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
157 vlcWin->ControlList.push_back( new ControlRectangle( id,
158 ConvertBoolean( visible ), atoi( x ) + XOff, atoi( y ) + YOff,
159 atoi( w ), atoi( h ), ConvertColor( color ), event, help, vlcWin ) );
161 //---------------------------------------------------------------------------
166 char *up, char *down, char *disabled,
167 char *onclick, char *onmouseover, char *onmouseout,
168 char *tooltiptext, char *help )
171 SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
173 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
175 vlcWin->ControlList.push_back( new ControlButton(
177 ConvertBoolean( visible ),
178 atoi( x ) + XOff, atoi( y ) + YOff,
180 onclick, onmouseover, onmouseout,
184 //---------------------------------------------------------------------------
189 char *img1, char *img2,
190 char *clickimg1, char *clickimg2, char *disabled1, char *disabled2,
191 char *onclick1, char *onclick2, char *onmouseover1, char *onmouseout1,
192 char *onmouseover2, char *onmouseout2,
193 char *tooltiptext1, char *tooltiptext2, char *help )
196 SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
198 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
200 vlcWin->ControlList.push_back( new ControlCheckBox(
202 ConvertBoolean( visible ),
203 atoi( x ) + XOff, atoi( y ) + YOff,
204 img1, img2, clickimg1, clickimg2, disabled1, disabled2,
205 onclick1, onclick2, onmouseover1, onmouseout1, onmouseover2,
207 tooltiptext1, tooltiptext2, help, vlcWin ) );
209 //---------------------------------------------------------------------------
210 void AddSlider( char *id, char *visible, char *x, char *y, char *type, char *up,
211 char *down, char *abs, char *ord, char *tooltiptext, char *help )
214 int res1 = CheckCoords( abs );
215 int res2 = CheckCoords( ord );
216 if( res1 < 2 || res2 < 2 )
218 msg_Warn( g_pIntf, "Cannot add slider: not enough points" );
223 msg_Warn( g_pIntf, "Cannot add slider: invalid list of points" );
228 double *p_abs, *p_ord;
229 p_abs = new double[res1];
230 p_ord = new double[res1];
231 ConvertCoords( abs, p_abs );
232 ConvertCoords( ord, p_ord );
234 SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
237 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
238 for( i = 0; i < res1; i++ )
240 p_abs[i] += XOff + atoi(x);
241 p_ord[i] += YOff + atoi(y);
245 if( g_pIntf->p_sys->p_theme->ConstructPlaylist )
247 GenericControl *playlist = vlcWin->ControlList.back();
248 ( (ControlPlayList *)playlist )->InitSliderCurve( p_abs, p_ord, res1,
253 vlcWin->ControlList.push_back( new ControlSlider( id,
254 ConvertBoolean( visible ), type, up, down, p_abs, p_ord, res1,
255 tooltiptext, help, vlcWin ) );
261 //---------------------------------------------------------------------------
262 void AddPlayList( char *id, char *visible, char *x, char *y, char *width,
263 char *infowidth, char *font, char *playfont, char *selcolor, char *abs,
264 char *ord, char *longfilename, char *help )
266 g_pIntf->p_sys->p_theme->ConstructPlaylist = true;
269 int res1 = CheckCoords( abs );
270 int res2 = CheckCoords( ord );
271 if( res1 < 2 || res2 < 2 )
273 msg_Warn( g_pIntf, "Cannot add slider: not enough points" );
278 msg_Warn( g_pIntf, "Cannot add slider: invalid list of points" );
283 double *p_abs, *p_ord;
284 p_abs = new double[res1];
285 p_ord = new double[res1];
286 ConvertCoords( abs, p_abs );
287 ConvertCoords( ord, p_ord );
289 SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
292 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
293 for( i = 0; i < res1; i++ )
295 p_abs[i] += XOff + atoi(x);
296 p_ord[i] += YOff + atoi(y);
300 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
302 vlcWin->ControlList.push_back( new ControlPlayList( id,
303 ConvertBoolean( visible ), atoi( width ), atoi( infowidth ), font,
304 playfont, ConvertColor( selcolor ), p_abs, p_ord, res1,
305 ConvertBoolean( longfilename ), help, vlcWin ) );
311 //---------------------------------------------------------------------------
312 void AddPlayListEnd()
314 g_pIntf->p_sys->p_theme->ConstructPlaylist = false;
316 //---------------------------------------------------------------------------
317 void AddText( char *id, char *visible, char *x, char *y, char *text, char *font,
318 char *align, char *width, char *display, char *scroll, char *scrollspace,
322 SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
324 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
326 vlcWin->ControlList.push_back( new ControlText( id,
327 ConvertBoolean( visible ), atoi( x ) + XOff,
328 atoi( y ) + YOff, text, font, ConvertAlign( align ), atoi( width ),
329 display, ConvertBoolean( scroll ), atoi( scrollspace ), help,
332 //---------------------------------------------------------------------------
337 //---------------------------------------------------------------------------
339 //---------------------------------------------------------------------------
340 static bool ConvertBoolean( const char *value )
342 return strcmp( value, "true" ) == 0;
344 //---------------------------------------------------------------------------
345 static int ConvertColor( const char *transcolor )
347 int iRed, iGreen, iBlue;
348 iRed = iGreen = iBlue = 0;
349 sscanf( transcolor, "#%2X%2X%2X", &iRed, &iGreen, &iBlue );
350 return ( 65536 * iBlue + 256 * iGreen + iRed );
352 //---------------------------------------------------------------------------
353 // Check that abs and ord contain the same number of comas
354 static int CheckCoords( const char *coord )
357 while( coord && *coord )
365 //---------------------------------------------------------------------------
366 static void ConvertCoords( char *coord, double *p_coord )
371 while( coord && *coord )
376 p_coord[i] = atof( ptr );
382 p_coord[i] = atof( ptr );
384 //---------------------------------------------------------------------------
385 static int ConvertAlign( char *align )
387 if( strcmp( align, "left" ) == 0 )
388 return VLC_FONT_ALIGN_LEFT;
389 else if( strcmp( align, "right" ) == 0 )
390 return VLC_FONT_ALIGN_RIGHT;
391 else if( strcmp( align, "center" ) == 0 )
392 return VLC_FONT_ALIGN_CENTER;
394 return VLC_FONT_ALIGN_LEFT;
396 //---------------------------------------------------------------------------