]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/art_bitmap.cpp
skins2: implement art display in image controls
[vlc] / modules / gui / skins2 / src / art_bitmap.cpp
1 /*****************************************************************************
2  * art_bitmap.cpp
3  *****************************************************************************
4  * Copyright (C) 2010 the VideoLAN team
5  * $Id$
6  *
7  * Author: Erwan Tulou      <erwan10@vidoelan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include "art_bitmap.hpp"
29 #include <vlc_image.h>
30
31
32 // static variables
33 intf_thread_t*    ArtBitmap::m_pIntf = NULL;
34 image_handler_t*  ArtBitmap::m_pImageHandler = NULL;
35 list<ArtBitmap*>  ArtBitmap::m_listBitmap;
36
37 ArtBitmap::ArtBitmap( string uriName ):
38     FileBitmap( m_pIntf, m_pImageHandler, uriName, -1 ), m_uriName( uriName )
39 {
40 }
41
42 void ArtBitmap::initArtBitmap( intf_thread_t* pIntf )
43 {
44     if( m_pIntf )
45         return;
46
47     // retain reference to skins interface
48     m_pIntf = pIntf;
49
50     // initialize handler
51     m_pImageHandler = image_HandlerCreate( pIntf );
52
53     if( !m_pImageHandler )
54         msg_Err( m_pIntf, "initialization of art bitmaps failed" );
55 }
56
57
58 ArtBitmap* ArtBitmap::getArtBitmap( string uriName )
59 {
60     if( !m_pImageHandler )
61         return NULL;
62
63     // check whether art is already loaded
64     list<ArtBitmap*>::const_iterator it;
65     for( it = m_listBitmap.begin(); it != m_listBitmap.end(); ++it )
66     {
67         if( (*it)->getUriName() == uriName )
68             return *it;
69     }
70
71     // create and retain a new ArtBitmap since uri if not yet known
72     ArtBitmap* pArt = new ArtBitmap( uriName );
73     if( pArt && pArt->getWidth() && pArt->getHeight() )
74     {
75         m_listBitmap.push_back( pArt );
76         return pArt;
77     }
78     else
79     {
80         delete pArt;
81         return NULL;
82     }
83 }
84
85 void ArtBitmap::freeArtBitmap( )
86 {
87     m_pIntf = NULL;
88
89     if( m_pImageHandler )
90     {
91         image_HandlerDelete( m_pImageHandler );
92         m_pImageHandler = NULL;
93     }
94
95     m_listBitmap.clear();
96 }