1 /*****************************************************************************
2 * wrappers.cpp: Wrappers around C++ objects
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: wrappers.cpp,v 1.13 2003/10/22 19:12:56 ipkiss 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, char *playondrop )
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 ),
91 ConvertBoolean( playondrop ) );
93 //---------------------------------------------------------------------------
97 //---------------------------------------------------------------------------
98 void StartTheme( char *magnet )
100 g_pIntf->p_sys->p_theme->StartTheme( atoi( magnet ) );
102 //---------------------------------------------------------------------------
106 //---------------------------------------------------------------------------
107 void StartControlGroup( char *x, char *y )
109 g_pIntf->p_sys->p_theme->OffBank->PushOffSet( atoi( x ), atoi( y ) );
111 //---------------------------------------------------------------------------
112 void EndControlGroup()
114 g_pIntf->p_sys->p_theme->OffBank->PopOffSet();
117 //---------------------------------------------------------------------------
118 void AddAnchor( char *x, char *y, char *len, char *priority )
121 SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
123 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
125 vlcWin->AnchorList.push_back( new Anchor( g_pIntf, atoi( x ) + XOff,
126 atoi( y ) + YOff, atoi( len ),
127 atoi( priority ), vlcWin ) );
129 //---------------------------------------------------------------------------
134 //---------------------------------------------------------------------------
136 //---------------------------------------------------------------------------
137 void AddImage( char *id, char *visible, char *x, char *y, char *image,
138 char *event, char *help )
141 SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
143 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
145 vlcWin->ControlList.push_back( new ControlImage( id,
146 ConvertBoolean( visible ), atoi( x ) + XOff,
147 atoi( y ) + YOff, image, event, help, vlcWin ) );
149 //---------------------------------------------------------------------------
150 void AddRectangle( char *id, char *visible, char *x, char *y, char *w, char *h,
151 char *color, char *event, char *help )
154 SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
156 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
158 vlcWin->ControlList.push_back( new ControlRectangle( id,
159 ConvertBoolean( visible ), atoi( x ) + XOff, atoi( y ) + YOff,
160 atoi( w ), atoi( h ), ConvertColor( color ), event, help, vlcWin ) );
162 //---------------------------------------------------------------------------
167 char *up, char *down, char *disabled,
168 char *onclick, char *onmouseover, char *onmouseout,
169 char *tooltiptext, char *help )
172 SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
174 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
176 vlcWin->ControlList.push_back( new ControlButton(
178 ConvertBoolean( visible ),
179 atoi( x ) + XOff, atoi( y ) + YOff,
181 onclick, onmouseover, onmouseout,
185 //---------------------------------------------------------------------------
190 char *img1, char *img2,
191 char *clickimg1, char *clickimg2, char *disabled1, char *disabled2,
192 char *onclick1, char *onclick2, char *onmouseover1, char *onmouseout1,
193 char *onmouseover2, char *onmouseout2,
194 char *tooltiptext1, char *tooltiptext2, char *help )
197 SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
199 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
201 vlcWin->ControlList.push_back( new ControlCheckBox(
203 ConvertBoolean( visible ),
204 atoi( x ) + XOff, atoi( y ) + YOff,
205 img1, img2, clickimg1, clickimg2, disabled1, disabled2,
206 onclick1, onclick2, onmouseover1, onmouseout1, onmouseover2,
208 tooltiptext1, tooltiptext2, help, vlcWin ) );
210 //---------------------------------------------------------------------------
211 void AddSlider( char *id, char *visible, char *x, char *y, char *type, char *up,
212 char *down, char *abs, char *ord, char *tooltiptext, char *help )
215 int res1 = CheckCoords( abs );
216 int res2 = CheckCoords( ord );
217 if( res1 < 2 || res2 < 2 )
219 msg_Warn( g_pIntf, "Cannot add slider: not enough points" );
224 msg_Warn( g_pIntf, "Cannot add slider: invalid list of points" );
229 double *p_abs, *p_ord;
230 p_abs = new double[res1];
231 p_ord = new double[res1];
232 ConvertCoords( abs, p_abs );
233 ConvertCoords( ord, p_ord );
235 SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
238 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
239 for( i = 0; i < res1; i++ )
241 p_abs[i] += XOff + atoi(x);
242 p_ord[i] += YOff + atoi(y);
246 if( g_pIntf->p_sys->p_theme->ConstructPlaylist )
248 GenericControl *playlist = vlcWin->ControlList.back();
249 ( (ControlPlayList *)playlist )->InitSliderCurve( p_abs, p_ord, res1,
254 vlcWin->ControlList.push_back( new ControlSlider( id,
255 ConvertBoolean( visible ), type, up, down, p_abs, p_ord, res1,
256 tooltiptext, help, vlcWin ) );
262 //---------------------------------------------------------------------------
263 void AddPlayList( char *id, char *visible, char *x, char *y, char *width,
264 char *infowidth, char *font, char *playfont, char *selcolor, char *abs,
265 char *ord, char *longfilename, char *help )
267 g_pIntf->p_sys->p_theme->ConstructPlaylist = true;
270 int res1 = CheckCoords( abs );
271 int res2 = CheckCoords( ord );
272 if( res1 < 2 || res2 < 2 )
274 msg_Warn( g_pIntf, "Cannot add slider: not enough points" );
279 msg_Warn( g_pIntf, "Cannot add slider: invalid list of points" );
284 double *p_abs, *p_ord;
285 p_abs = new double[res1];
286 p_ord = new double[res1];
287 ConvertCoords( abs, p_abs );
288 ConvertCoords( ord, p_ord );
290 SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
293 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
294 for( i = 0; i < res1; i++ )
296 p_abs[i] += XOff + atoi(x);
297 p_ord[i] += YOff + atoi(y);
301 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
303 vlcWin->ControlList.push_back( new ControlPlayList( id,
304 ConvertBoolean( visible ), atoi( width ), atoi( infowidth ), font,
305 playfont, ConvertColor( selcolor ), p_abs, p_ord, res1,
306 ConvertBoolean( longfilename ), help, vlcWin ) );
312 //---------------------------------------------------------------------------
313 void AddPlayListEnd()
315 g_pIntf->p_sys->p_theme->ConstructPlaylist = false;
317 //---------------------------------------------------------------------------
318 void AddText( char *id, char *visible, char *x, char *y, char *text, char *font,
319 char *align, char *width, char *display, char *scroll, char *scrollspace,
323 SkinWindow *vlcWin = g_pIntf->p_sys->p_theme->WindowList.back();
325 g_pIntf->p_sys->p_theme->OffBank->GetOffSet( XOff, YOff );
327 vlcWin->ControlList.push_back( new ControlText( id,
328 ConvertBoolean( visible ), atoi( x ) + XOff,
329 atoi( y ) + YOff, text, font, ConvertAlign( align ), atoi( width ),
330 display, ConvertBoolean( scroll ), atoi( scrollspace ), help,
333 //---------------------------------------------------------------------------
338 //---------------------------------------------------------------------------
340 //---------------------------------------------------------------------------
341 static bool ConvertBoolean( const char *value )
343 return strcmp( value, "true" ) == 0;
345 //---------------------------------------------------------------------------
346 static int ConvertColor( const char *transcolor )
348 int iRed, iGreen, iBlue;
349 iRed = iGreen = iBlue = 0;
350 sscanf( transcolor, "#%2X%2X%2X", &iRed, &iGreen, &iBlue );
351 return ( 65536 * iBlue + 256 * iGreen + iRed );
353 //---------------------------------------------------------------------------
354 // Check that abs and ord contain the same number of comas
355 static int CheckCoords( const char *coord )
358 while( coord && *coord )
366 //---------------------------------------------------------------------------
367 static void ConvertCoords( char *coord, double *p_coord )
372 while( coord && *coord )
377 p_coord[i] = atof( ptr );
383 p_coord[i] = atof( ptr );
385 //---------------------------------------------------------------------------
386 static int ConvertAlign( char *align )
388 if( strcmp( align, "left" ) == 0 )
389 return VLC_FONT_ALIGN_LEFT;
390 else if( strcmp( align, "right" ) == 0 )
391 return VLC_FONT_ALIGN_RIGHT;
392 else if( strcmp( align, "center" ) == 0 )
393 return VLC_FONT_ALIGN_CENTER;
395 return VLC_FONT_ALIGN_LEFT;
397 //---------------------------------------------------------------------------