Commit 60c63d39 authored by Olivier Teulière's avatar Olivier Teulière

* skins2: Other attempt at supporting transparency on Windows (win2k, winxp).

   As it is not perfect yet, a new config option allows to disable transparency
   effects.
parent 1dcec75f
...@@ -88,15 +88,15 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -88,15 +88,15 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
else if( rName == "Bitmap" ) else if( rName == "Bitmap" )
{ {
const BuilderData::Bitmap bitmap( attr["id"] , const BuilderData::Bitmap bitmap( attr["id"] ,
ConvertFileName( attr["file"] ), convertFileName( attr["file"] ),
ConvertColor( attr["alphacolor"] ) ); convertColor( attr["alphacolor"] ) );
m_data.m_listBitmap.push_back( bitmap ); m_data.m_listBitmap.push_back( bitmap );
} }
else if( rName == "BitmapFont" ) else if( rName == "BitmapFont" )
{ {
const BuilderData::BitmapFont font( attr["id"], const BuilderData::BitmapFont font( attr["id"],
ConvertFileName( attr["file"] ), convertFileName( attr["file"] ),
attr["type"] ); attr["type"] );
m_data.m_listBitmapFont.push_back( font ); m_data.m_listBitmapFont.push_back( font );
} }
...@@ -128,7 +128,7 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -128,7 +128,7 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
else if( rName == "Font" ) else if( rName == "Font" )
{ {
const BuilderData::Font fontData( attr["id"], const BuilderData::Font fontData( attr["id"],
ConvertFileName( attr["file"] ), convertFileName( attr["file"] ),
atoi( attr["size"] ) ); atoi( attr["size"] ) );
m_data.m_listFont.push_back( fontData ); m_data.m_listFont.push_back( fontData );
} }
...@@ -170,11 +170,11 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -170,11 +170,11 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
m_xOffset, atoi( attr["y"] ) + m_yOffset, attr["visible"], m_xOffset, atoi( attr["y"] ) + m_yOffset, attr["visible"],
atoi( attr["width"]), atoi( attr["height"] ), atoi( attr["width"]), atoi( attr["height"] ),
attr["lefttop"], attr["rightbottom"], attr["lefttop"], attr["rightbottom"],
attr["font"], attr["var"], ConvertColor( attr["fgcolor"] ), attr["font"], attr["var"], convertColor( attr["fgcolor"] ),
ConvertColor( attr["playcolor"] ), convertColor( attr["playcolor"] ),
ConvertColor( attr["bgcolor1"] ), convertColor( attr["bgcolor1"] ),
ConvertColor( attr["bgcolor2"] ), convertColor( attr["bgcolor2"] ),
ConvertColor( attr["selcolor"] ), attr["help"], convertColor( attr["selcolor"] ), attr["help"],
m_curLayer, m_curWindowId, m_curLayoutId ); m_curLayer, m_curWindowId, m_curLayoutId );
m_curLayer++; m_curLayer++;
m_data.m_listList.push_back( listData ); m_data.m_listList.push_back( listData );
...@@ -219,7 +219,7 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -219,7 +219,7 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset, atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
attr["visible"], attr["font"], attr["visible"], attr["font"],
attr["text"], atoi( attr["width"] ), attr["text"], atoi( attr["width"] ),
ConvertColor( attr["color"] ), attr["help"], m_curLayer, convertColor( attr["color"] ), attr["help"], m_curLayer,
m_curWindowId, m_curLayoutId ); m_curWindowId, m_curLayoutId );
m_curLayer++; m_curLayer++;
m_data.m_listText.push_back( textData ); m_data.m_listText.push_back( textData );
...@@ -236,14 +236,16 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -236,14 +236,16 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
return; return;
} }
const BuilderData::Theme theme( attr["tooltipfont"], const BuilderData::Theme theme( attr["tooltipfont"],
atoi( attr["magnet"] ), atoi( attr["alpha"] ), atoi( attr["magnet"] ),
atoi( attr["movealpha"] ), atoi( attr["fadetime"] ) ); convertInRange( attr["alpha"], 1, 255, "alpha" ),
convertInRange( attr["movealpha"], 1, 255, "movealpha" ),
atoi( attr["fadetime"] ) );
m_data.m_listTheme.push_back( theme ); m_data.m_listTheme.push_back( theme );
} }
else if( rName == "ThemeInfo" ) else if( rName == "ThemeInfo" )
{ {
msg_Warn( getIntf(), "skin: %s author: %s", attr["name"], msg_Info( getIntf(), "skin: %s author: %s", attr["name"],
attr["author"] ); attr["author"] );
} }
...@@ -264,9 +266,9 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -264,9 +266,9 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
m_curWindowId = uniqueId( attr["id"] ); m_curWindowId = uniqueId( attr["id"] );
const BuilderData::Window window( m_curWindowId, const BuilderData::Window window( m_curWindowId,
atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset, atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
ConvertBoolean( attr["visible"] ), convertBoolean( attr["visible"] ),
ConvertBoolean( attr["dragdrop"] ), convertBoolean( attr["dragdrop"] ),
ConvertBoolean( attr["playondrop"] ) ); convertBoolean( attr["playondrop"] ) );
m_data.m_listWindow.push_back( window ); m_data.m_listWindow.push_back( window );
} }
} }
...@@ -289,13 +291,13 @@ void SkinParser::handleEndElement( const string &rName ) ...@@ -289,13 +291,13 @@ void SkinParser::handleEndElement( const string &rName )
} }
bool SkinParser::ConvertBoolean( const char *value ) const bool SkinParser::convertBoolean( const char *value ) const
{ {
return strcmp( value, "true" ) == 0; return strcmp( value, "true" ) == 0;
} }
int SkinParser::ConvertColor( const char *transcolor ) const int SkinParser::convertColor( const char *transcolor ) const
{ {
unsigned long iRed, iGreen, iBlue; unsigned long iRed, iGreen, iBlue;
iRed = iGreen = iBlue = 0; iRed = iGreen = iBlue = 0;
...@@ -303,11 +305,39 @@ int SkinParser::ConvertColor( const char *transcolor ) const ...@@ -303,11 +305,39 @@ int SkinParser::ConvertColor( const char *transcolor ) const
return ( iRed << 16 | iGreen << 8 | iBlue ); return ( iRed << 16 | iGreen << 8 | iBlue );
} }
string SkinParser::ConvertFileName( const char *fileName ) const
string SkinParser::convertFileName( const char *fileName ) const
{ {
return m_path + string( fileName ); return m_path + string( fileName );
} }
int SkinParser::convertInRange( const char *value, int minValue, int maxValue,
const string &rAttribute ) const
{
int intValue = atoi( value );
if( intValue < minValue )
{
msg_Warn( getIntf(), "Value of \"%s\" attribute (%i) is out of the "
"expected range [%i, %i], using %i instead",
rAttribute.c_str(), intValue, minValue, maxValue, minValue );
return minValue;
}
else if( intValue > maxValue )
{
msg_Warn( getIntf(), "Value of \"%s\" attribute (%i) is out of the "
"expected range [%i, %i], using %i instead",
rAttribute.c_str(), intValue, minValue, maxValue, maxValue );
return maxValue;
}
else
{
return intValue;
}
}
const string SkinParser::generateId() const const string SkinParser::generateId() const
{ {
static int i = 1; static int i = 1;
......
...@@ -64,9 +64,15 @@ class SkinParser: public XMLParser ...@@ -64,9 +64,15 @@ class SkinParser: public XMLParser
virtual void handleEndElement( const string &rName ); virtual void handleEndElement( const string &rName );
/// Helper functions /// Helper functions
bool ConvertBoolean( const char *value ) const; //@{
int ConvertColor( const char *transcolor ) const; bool convertBoolean( const char *value ) const;
string ConvertFileName( const char *fileName ) const; int convertColor( const char *transcolor ) const;
string convertFileName( const char *fileName ) const;
/// Transform to int, and check that it is in the given range (if not,
/// the closest range boundary will be used)
int convertInRange( const char *value, int minValue, int maxValue,
const string &rAttribute ) const;
//@}
/// Generate a new id /// Generate a new id
const string generateId() const; const string generateId() const;
......
...@@ -223,16 +223,24 @@ static void Run( intf_thread_t *p_intf ) ...@@ -223,16 +223,24 @@ static void Run( intf_thread_t *p_intf )
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Module descriptor // Module descriptor
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#define DEFAULT_SKIN N_("Last skin used") #define SKINS2_LAST N_("Last skin used")
#define DEFAULT_SKIN_LONG N_("Select the path to the last skin used.") #define SKINS2_LAST_LONG N_("Select the path to the last skin used.")
#define SKIN_CONFIG N_("Config of last used skin") #define SKINS2_CONFIG N_("Config of last used skin")
#define SKIN_CONFIG_LONG N_("Config of last used skin.") #define SKINS2_CONFIG_LONG N_("Config of last used skin.")
#define SKINS2_TRANSPARENCY N_("Enable transparency effects")
#define SKINS2_TRANSPARENCY_LONG N_("You can disable all transparency effects" \
" if you want. This is mainly useful when moving windows does not behave" \
" correctly.")
vlc_module_begin(); vlc_module_begin();
add_string( "skins2-last", "", NULL, DEFAULT_SKIN, DEFAULT_SKIN_LONG, add_string( "skins2-last", "", NULL, SKINS2_LAST, SKINS2_LAST_LONG,
VLC_TRUE ); VLC_TRUE );
add_string( "skins2-config", "", NULL, SKIN_CONFIG, SKIN_CONFIG_LONG, add_string( "skins2-config", "", NULL, SKINS2_CONFIG, SKINS2_CONFIG_LONG,
VLC_TRUE ); VLC_TRUE );
#ifdef WIN32
add_bool( "skins2-transparency", VLC_TRUE, NULL, SKINS2_TRANSPARENCY,
SKINS2_TRANSPARENCY_LONG, VLC_FALSE );
#endif
set_description( _("Skinnable Interface") ); set_description( _("Skinnable Interface") );
set_capability( "interface", 30 ); set_capability( "interface", 30 );
set_callbacks( Open, Close ); set_callbacks( Open, Close );
......
...@@ -65,11 +65,22 @@ void WindowManager::startMove( TopWindow &rWindow ) ...@@ -65,11 +65,22 @@ void WindowManager::startMove( TopWindow &rWindow )
m_movingWindows.clear(); m_movingWindows.clear();
buildDependSet( m_movingWindows, &rWindow ); buildDependSet( m_movingWindows, &rWindow );
// Change the opacity of the moving windows if( config_GetInt( getIntf(), "skins2-transparency" ) )
WinSet_t::const_iterator it;
for( it = m_movingWindows.begin(); it != m_movingWindows.end(); it++ )
{ {
(*it)->setOpacity( m_moveAlpha ); // Change the opacity of the moving windows
WinSet_t::const_iterator it;
for( it = m_movingWindows.begin(); it != m_movingWindows.end(); it++ )
{
(*it)->setOpacity( m_moveAlpha );
}
// FIXME: We need to refresh the windows, because if 2 windows overlap
// and one of them becomes transparent, the other one is not refreshed
// automatically. I don't know why... -- Ipkiss
for( it = m_allWindows.begin(); it != m_allWindows.end(); it++ )
{
(*it)->refresh( 0, 0, (*it)->getWidth(), (*it)->getHeight() );
}
} }
} }
...@@ -79,11 +90,14 @@ void WindowManager::stopMove() ...@@ -79,11 +90,14 @@ void WindowManager::stopMove()
WinSet_t::const_iterator itWin1, itWin2; WinSet_t::const_iterator itWin1, itWin2;
AncList_t::const_iterator itAnc1, itAnc2; AncList_t::const_iterator itAnc1, itAnc2;
// Restore the opacity of the moving windows if( config_GetInt( getIntf(), "skins2-transparency" ) )
WinSet_t::const_iterator it;
for( it = m_movingWindows.begin(); it != m_movingWindows.end(); it++ )
{ {
(*it)->setOpacity( m_alpha ); // Restore the opacity of the moving windows
WinSet_t::const_iterator it;
for( it = m_movingWindows.begin(); it != m_movingWindows.end(); it++ )
{
(*it)->setOpacity( m_alpha );
}
} }
// Delete the dependencies // Delete the dependencies
......
...@@ -41,7 +41,7 @@ Win32Window::Win32Window( intf_thread_t *pIntf, GenericWindow &rWindow, ...@@ -41,7 +41,7 @@ Win32Window::Win32Window( intf_thread_t *pIntf, GenericWindow &rWindow,
HINSTANCE hInst, HWND hParentWindow, HINSTANCE hInst, HWND hParentWindow,
bool dragDrop, bool playOnDrop, bool dragDrop, bool playOnDrop,
Win32Window *pParentWindow ): Win32Window *pParentWindow ):
OSWindow( pIntf ), m_dragDrop( dragDrop ) OSWindow( pIntf ), m_dragDrop( dragDrop ), m_isLayered( false )
{ {
// Create the window // Create the window
if( pParentWindow ) if( pParentWindow )
...@@ -66,11 +66,6 @@ Win32Window::Win32Window( intf_thread_t *pIntf, GenericWindow &rWindow, ...@@ -66,11 +66,6 @@ Win32Window::Win32Window( intf_thread_t *pIntf, GenericWindow &rWindow,
return; return;
} }
// We do it this way otherwise CreateWindowEx will fail if WS_EX_LAYERED
// is not supported
// SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
// GetWindowLong( m_hWnd, GWL_EXSTYLE ) | WS_EX_LAYERED );
// Store a pointer to the GenericWindow in a map // Store a pointer to the GenericWindow in a map
Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() ); Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
pFactory->m_windowMap[m_hWnd] = &rWindow; pFactory->m_windowMap[m_hWnd] = &rWindow;
...@@ -138,37 +133,49 @@ void Win32Window::raise() const ...@@ -138,37 +133,49 @@ void Win32Window::raise() const
void Win32Window::setOpacity( uint8_t value ) const void Win32Window::setOpacity( uint8_t value ) const
{ {
#if 0
Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() ); Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
if( value == 255 ) if( value == 255 )
{ {
// If the window is opaque, we remove the WS_EX_LAYERED attribute // If the window is opaque, we remove the WS_EX_LAYERED attribute
// which slows resizing for nothing // which slows down resizing for nothing
SetWindowLongPtr( m_hWnd, GWL_EXSTYLE, if( m_isLayered )
GetWindowLong( m_hWnd, GWL_EXSTYLE ) & !WS_EX_LAYERED ); {
SetWindowPos( m_hWnd, HWND_TOP, 0, 0, 0, 0, SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED ); GetWindowLong( m_hWnd, GWL_EXSTYLE ) & ~WS_EX_LAYERED );
// Redraw the window, otherwise we may end up with a grey rectangle
// for some strange reason
RedrawWindow(m_hWnd, NULL, NULL,
RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
m_isLayered = false;
}
} }
else else
{ {
if( pFactory->SetLayeredWindowAttributes ) if( pFactory->SetLayeredWindowAttributes )
{ {
// (Re)Add the WS_EX_LAYERED attribute. if( ! m_isLayered )
// Resizing will be very slow, now :) {
SetWindowLongPtr( m_hWnd, GWL_EXSTYLE, // (Re)Add the WS_EX_LAYERED attribute.
GetWindowLong( m_hWnd, GWL_EXSTYLE ) | WS_EX_LAYERED ); // Resizing will be very slow, now :)
SetWindowPos( m_hWnd, HWND_TOP, 0, 0, 0, 0, SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED ); GetWindowLong( m_hWnd, GWL_EXSTYLE ) | WS_EX_LAYERED );
// Redraw the window, otherwise we may end up with a grey
// rectangle for some strange reason
RedrawWindow(m_hWnd, NULL, NULL,
RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
m_isLayered = true;
}
// Change the opacity // Change the opacity
pFactory->SetLayeredWindowAttributes( pFactory->SetLayeredWindowAttributes(
m_hWnd, 0, value, LWA_ALPHA|LWA_COLORKEY ); m_hWnd, 0, value, LWA_ALPHA|LWA_COLORKEY );
} }
} }
UpdateWindow( m_hWnd );
#endif
} }
......
...@@ -69,6 +69,8 @@ class Win32Window: public OSWindow ...@@ -69,6 +69,8 @@ class Win32Window: public OSWindow
bool m_dragDrop; bool m_dragDrop;
/// Drop target /// Drop target
LPDROPTARGET m_pDropTarget; LPDROPTARGET m_pDropTarget;
/// Indicates whether the window is layered
mutable bool m_isLayered;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment