Commit 28373226 authored by Gildas Bazin's avatar Gildas Bazin

* modules/gui/skins/x11/*: fixed transparency problem. XShapeCombineRegion() needs to be called before the window is mapped.
parent 0a3fa2c8
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* x11_bitmap.cpp: X11 implementation of the Bitmap class * x11_bitmap.cpp: X11 implementation of the Bitmap class
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: x11_bitmap.cpp,v 1.9 2003/06/01 22:11:24 asmax Exp $ * $Id: x11_bitmap.cpp,v 1.10 2003/06/08 12:45:13 gbazin Exp $
* *
* Authors: Cyril Deguet <asmax@videolan.org> * Authors: Cyril Deguet <asmax@videolan.org>
* *
...@@ -55,7 +55,7 @@ X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, string FileName, int AColor ) ...@@ -55,7 +55,7 @@ X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, string FileName, int AColor )
: Bitmap( p_intf, FileName, AColor ) : Bitmap( p_intf, FileName, AColor )
{ {
p_intf = _p_intf; p_intf = _p_intf;
// Find the display // Find the display
display = p_intf->p_sys->display; display = p_intf->p_sys->display;
int screen = DefaultScreen( display ); int screen = DefaultScreen( display );
...@@ -70,10 +70,10 @@ X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, string FileName, int AColor ) ...@@ -70,10 +70,10 @@ X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, string FileName, int AColor )
{ {
return; return;
} }
AlphaColor = (AColor & 0xff) << 16 | (AColor & 0xff00) | AlphaColor = (AColor & 0xff) << 16 | (AColor & 0xff00) |
(AColor & 0xff0000) >> 16; (AColor & 0xff0000) >> 16;
XLOCK; XLOCK;
imlib_context_set_display( display ); imlib_context_set_display( display );
imlib_context_set_visual( visual ); imlib_context_set_visual( visual );
...@@ -85,7 +85,7 @@ X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, string FileName, int AColor ) ...@@ -85,7 +85,7 @@ X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, string FileName, int AColor )
imlib_context_set_image( Img ); imlib_context_set_image( Img );
Width = imlib_image_get_width(); Width = imlib_image_get_width();
Height = imlib_image_get_height(); Height = imlib_image_get_height();
// Add an alpha layer // Add an alpha layer
DATA32 *data = imlib_image_get_data(); DATA32 *data = imlib_image_get_data();
DATA32 *ptr = data; DATA32 *ptr = data;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* x11_timer.h: helper class to implement timers * x11_timer.h: helper class to implement timers
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: x11_timer.h,v 1.3 2003/06/08 11:33:14 asmax Exp $ * $Id: x11_timer.h,v 1.4 2003/06/08 12:45:13 gbazin Exp $
* *
* Authors: Cyril Deguet <asmax@videolan.org> * Authors: Cyril Deguet <asmax@videolan.org>
* *
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
#ifndef VLC_SKIN_X11_TIMER #ifndef VLC_SKIN_X11_TIMER
#define VLC_SKIN_X11_TIMER #define VLC_SKIN_X11_TIMER
#include <list.h> #include <list>
using namespace std;
typedef struct typedef struct
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* x11_window.cpp: X11 implementation of the Window class * x11_window.cpp: X11 implementation of the Window class
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: x11_window.cpp,v 1.14 2003/06/08 11:33:14 asmax Exp $ * $Id: x11_window.cpp,v 1.15 2003/06/08 12:45:13 gbazin Exp $
* *
* Authors: Cyril Deguet <asmax@videolan.org> * Authors: Cyril Deguet <asmax@videolan.org>
* *
...@@ -63,26 +63,23 @@ X11Window::X11Window( intf_thread_t *p_intf, Window wnd, int x, int y, ...@@ -63,26 +63,23 @@ X11Window::X11Window( intf_thread_t *p_intf, Window wnd, int x, int y,
dragdrop ) dragdrop )
{ {
// Set handles // Set handles
Wnd = wnd; Wnd = wnd;
display = p_intf->p_sys->display;
display = p_intf->p_sys->display; int screen = DefaultScreen( display );
int screen = DefaultScreen( display );
Gc = DefaultGC( display, screen );
Name = name; Name = name;
LButtonDown = false; LButtonDown = false;
RButtonDown = false; RButtonDown = false;
// Creation of a graphic context that doesn't generate a GraphicsExpose
// event when using functions like XCopyArea
XGCValues gcVal;
gcVal.graphics_exposures = False;
XLOCK;
Gc = XCreateGC( display, wnd, GCGraphicsExposures, &gcVal );
XUNLOCK;
// Removing fading effect // Removing fading effect
Transition = 0; Transition = 0;
/*
// Set position parameters
CursorPos = new POINT;
WindowPos = new POINT;
*/
if( DragDrop ) if( DragDrop )
{ {
...@@ -104,10 +101,11 @@ X11Window::X11Window( intf_thread_t *p_intf, Window wnd, int x, int y, ...@@ -104,10 +101,11 @@ X11Window::X11Window( intf_thread_t *p_intf, Window wnd, int x, int y,
XSetWindowAttributes attr; XSetWindowAttributes attr;
attr.background_pixel = color.pixel; attr.background_pixel = color.pixel;
attr.override_redirect = True; attr.override_redirect = True;
ToolTip.window = XCreateWindow( display, root, 0, 0, 1, 1, 1, 0, InputOutput, ToolTip.window = XCreateWindow( display, root, 0, 0, 1, 1, 1, 0,
CopyFromParent, CWBackPixel|CWOverrideRedirect, &attr ); InputOutput, CopyFromParent,
XGCValues gcVal; CWBackPixel|CWOverrideRedirect, &attr );
ToolTip.font = XLoadFont( display, "-*-helvetica-bold-r-*-*-*-80-*-*-*-*-*-*" ); ToolTip.font = XLoadFont( display,
"-*-helvetica-bold-r-*-*-*-80-*-*-*-*-*-*" );
gcVal.font = ToolTip.font; gcVal.font = ToolTip.font;
gcVal.foreground = 0; gcVal.foreground = 0;
gcVal.background = color.pixel; gcVal.background = color.pixel;
...@@ -138,7 +136,10 @@ X11Window::~X11Window() ...@@ -138,7 +136,10 @@ X11Window::~X11Window()
{ {
DestroyWindow( hWnd ); DestroyWindow( hWnd );
}*/ }*/
XFreeGC( display, Gc );
XDestroyWindow( display, ToolTip.window ); XDestroyWindow( display, ToolTip.window );
/* /*
if( DragDrop ) if( DragDrop )
{ {
...@@ -148,17 +149,62 @@ X11Window::~X11Window() ...@@ -148,17 +149,62 @@ X11Window::~X11Window()
// Uninitialize the OLE library // Uninitialize the OLE library
OleUninitialize(); OleUninitialize();
}*/ }*/
/* if( gWnd )
{
gdk_window_destroy( gWnd );
}*/
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void X11Window::OSShow( bool show ) void X11Window::OSShow( bool show )
{ {
if( show ) if( show )
{ {
// We do the call to XShapeCombineRegion() here because the window
// must be unmapped for this to work.
Drawable drawable = (( X11Graphics* )Image )->GetImage();
XLOCK; XLOCK;
XImage *image = XGetImage( display, drawable, 0, 0, Width, Height,
AllPlanes, ZPixmap );
if( image )
{
// Mask for transparency
Region region = XCreateRegion();
region = XCreateRegion();
for( int line = 0; line < Height; line++ )
{
int start = 0, end = 0;
while( start < Width )
{
while( start < Width && XGetPixel( image, start, line )
== 0 )
{
start++;
}
end = start;
while( end < Width && XGetPixel( image, end, line ) != 0)
{
end++;
}
XRectangle rect;
rect.x = start;
rect.y = line;
rect.width = end - start + 1;
rect.height = 1;
Region newRegion = XCreateRegion();
XUnionRectWithRegion( &rect, region, newRegion );
XDestroyRegion( region );
region = newRegion;
start = end + 1;
}
}
XShapeCombineRegion( display, Wnd, ShapeBounding, 0, 0, region,
ShapeSet );
XDestroyRegion( region );
}
else
{
msg_Err( p_intf, "X11Window::OSShow XShapeCombineRegion() failed");
}
XMapWindow( display, Wnd ); XMapWindow( display, Wnd );
XMoveWindow( display, Wnd, Left, Top ); XMoveWindow( display, Wnd, Left, Top );
XUNLOCK; XUNLOCK;
...@@ -262,14 +308,14 @@ bool X11Window::ProcessOSEvent( Event *evt ) ...@@ -262,14 +308,14 @@ bool X11Window::ProcessOSEvent( Event *evt )
MouseUp( (int)( (XButtonEvent *)p2 )->x, MouseUp( (int)( (XButtonEvent *)p2 )->x,
(int)( (XButtonEvent *)p2 )->y, 2 ); (int)( (XButtonEvent *)p2 )->y, 2 );
break; break;
case 4: case 4:
// Scroll up // Scroll up
MouseScroll( (int)( (XButtonEvent *)p2 )->x, MouseScroll( (int)( (XButtonEvent *)p2 )->x,
(int)( (XButtonEvent *)p2 )->y, (int)( (XButtonEvent *)p2 )->y,
MOUSE_SCROLL_UP); MOUSE_SCROLL_UP);
break; break;
case 5: case 5:
// Scroll down // Scroll down
MouseScroll( (int)( (XButtonEvent *)p2 )->x, MouseScroll( (int)( (XButtonEvent *)p2 )->x,
...@@ -306,48 +352,9 @@ void X11Window::SetTransparency( int Value ) ...@@ -306,48 +352,9 @@ void X11Window::SetTransparency( int Value )
void X11Window::RefreshFromImage( int x, int y, int w, int h ) void X11Window::RefreshFromImage( int x, int y, int w, int h )
{ {
Drawable drawable = (( X11Graphics* )Image )->GetImage(); Drawable drawable = (( X11Graphics* )Image )->GetImage();
XLOCK; XLOCK;
XCopyArea( display, drawable, Wnd, Gc, x, y, w, h, x, y ); XCopyArea( display, drawable, Wnd, Gc, x, y, w, h, x, y );
XImage *image = XGetImage( display, drawable, 0, 0, Width, Height,
AllPlanes, ZPixmap );
if( !image )
{
msg_Err( p_intf, "X11Window::RefreshFromImage failed");
}
// Mask for transparency
Region region = XCreateRegion();
for( int line = 0; line < Height; line++ )
{
int start = 0, end = 0;
while( start < Width )
{
while( start < Width && XGetPixel( image, start, line ) == 0 )
{
start++;
}
end = start;
while( end < Width && XGetPixel( image, end, line ) != 0)
{
end++;
}
XRectangle rect;
rect.x = start;
rect.y = line;
rect.width = end - start + 1;
rect.height = 1;
Region newRegion = XCreateRegion();
XUnionRectWithRegion( &rect, region, newRegion );
XDestroyRegion( region );
region = newRegion;
start = end + 1;
}
}
XShapeCombineRegion( display, Wnd, ShapeBounding, 0, 0, region, ShapeSet );
XDestroyRegion( region );
XSync( display, 0); XSync( display, 0);
XUNLOCK; XUNLOCK;
} }
......
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