Commit 651be31c authored by Cyril Deguet's avatar Cyril Deguet

* added transparency in X11 skins

parent 035bbae4
......@@ -2,7 +2,7 @@
* x11_bitmap.cpp: X11 implementation of the Bitmap class
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_bitmap.cpp,v 1.3 2003/05/18 11:25:00 asmax Exp $
* $Id: x11_bitmap.cpp,v 1.4 2003/05/18 17:48:05 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
* Emmanuel Puig <karibu@via.ecp.fr>
......@@ -66,11 +66,13 @@ X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, string FileName, int AColor )
Width = 0;
Height = 0;
AlphaColor = AColor;
// TODO: check for endianness issues
AlphaColor = (AColor & 0xff) << 16 | (AColor & 0xff00) |
(AColor & 0xff0000) >> 16;
if( FileName != "" )
{
data = LoadFromFile( FileName, depth, Width, Height );
data = LoadFromFile( FileName, depth, AlphaColor, Width, Height );
}
// Create the image
......@@ -78,45 +80,6 @@ X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, string FileName, int AColor )
Height, 32, 4 * Width );
XInitImage( Bmp );
// Load the bitmap image
/* if( rc != BitmapSuccess )
{
if( FileName != "" )
msg_Warn( p_intf, "Couldn't load bitmap: %s", FileName.c_str() );
Width = 0;
Height = 0;
}*/
/* else
{
Width = gdk_pixbuf_get_width( Bmp );
Height = gdk_pixbuf_get_height( Bmp );
if( AColor != 0 )
{
// Change black pixels to another color to avoid transparency
int rowstride = gdk_pixbuf_get_rowstride( Bmp );
guchar *pixel = gdk_pixbuf_get_pixels( Bmp );
int pix_size = ( gdk_pixbuf_get_has_alpha( Bmp ) ? 4 : 3 );
for( int y = 0; y < Height; y++ )
{
for( int x = 0; x < Width; x++ )
{
guint32 r = pixel[0];
guint32 g = pixel[1]<<8;
guint32 b = pixel[2]<<16;
if( r+g+b == 0 )
{
pixel[2] = 10; // slight blue
}
pixel += pix_size;
}
}
}
Bmp = gdk_pixbuf_add_alpha( Bmp, TRUE, AColor & 0xff, (AColor>>8) & 0xff,
(AColor>>16) & 0xff );
}*/
}
//---------------------------------------------------------------------------
X11Bitmap::X11Bitmap( intf_thread_t *_p_intf, Graphics *from, int x, int y,
......@@ -178,6 +141,7 @@ bool X11Bitmap::Hit( int x, int y)
return false;
else
return true;*/
return true;
}
//---------------------------------------------------------------------------
int X11Bitmap::GetBmpPixel( int x, int y )
......@@ -207,7 +171,8 @@ void X11Bitmap::SetBmpPixel( int x, int y, int color )
// SetPixelV( bmpDC, x, y, color );
}
//---------------------------------------------------------------------------
char *X11Bitmap::LoadFromFile( string fileName, int depth, int &width, int &height )
char *X11Bitmap::LoadFromFile( string fileName, int depth, int AColor,
int &width, int &height )
{
// BMP header fields
uint32_t fileSize;
......@@ -241,7 +206,7 @@ char *X11Bitmap::LoadFromFile( string fileName, int depth, int &width, int &heig
dataSize = U32( headers + 34 );
nColors = U32( headers + 50 );
// fprintf(stderr,"image %d %d\n", width, height);
fprintf(stderr,"image %s %x\n", fileName.c_str(), AColor);
switch( bpp )
{
case 24:
......@@ -259,7 +224,17 @@ char *X11Bitmap::LoadFromFile( string fileName, int depth, int &width, int &heig
// Read a pixel
uint32_t pixel = 0;
fread( &pixel, 3, 1, file );
*(ptr++) = U32( &pixel );
pixel = U32( &pixel );
// Handle transparency
if( pixel == 0 && AColor != 0 )
{
pixel = 10; // slight blue
}
else if( pixel == AColor )
{
pixel = 0; // global alpha color is black
}
*(ptr++) = pixel;
}
fseek( file, pad, SEEK_CUR );
}
......
......@@ -2,7 +2,7 @@
* x11_bitmap.h: X11 implementation of the Bitmap class
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_bitmap.h,v 1.2 2003/05/18 11:25:00 asmax Exp $
* $Id: x11_bitmap.h,v 1.3 2003/05/18 17:48:05 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
......@@ -64,7 +64,8 @@ class X11Bitmap : public Bitmap
virtual void SetBmpPixel( int x, int y, int color );
protected:
char *LoadFromFile( string fileName, int depth, int &width, int &height);
char *LoadFromFile( string fileName, int depth, int AColor, int &width,
int &height);
};
//---------------------------------------------------------------------------
......
......@@ -2,7 +2,7 @@
* x11_font.cpp: X11 implementation of the Font class
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_font.cpp,v 1.1 2003/04/28 14:32:57 asmax Exp $
* $Id: x11_font.cpp,v 1.2 2003/05/18 17:48:05 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
* Emmanuel Puig <karibu@via.ecp.fr>
......@@ -91,6 +91,8 @@ void X11Font::AssignFont( Graphics *dest )
//---------------------------------------------------------------------------
void X11Font::GetSize( string text, int &w, int &h )
{
w = 0;
h = 0;
/* pango_layout_set_text( Layout, text.c_str(), text.length() );
pango_layout_get_pixel_size( Layout, &w, &h );*/
}
......
......@@ -2,7 +2,7 @@
* x11_graphics.cpp: X11 implementation of the Graphics and Region classes
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_graphics.cpp,v 1.2 2003/04/30 21:16:24 asmax Exp $
* $Id: x11_graphics.cpp,v 1.3 2003/05/18 17:48:05 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
* Emmanuel Puig <karibu@via.ecp.fr>
......@@ -69,13 +69,12 @@ X11Graphics::X11Graphics( intf_thread_t *p_intf, int w, int h,
}
// Set the background color to black
// gdk_draw_rectangle( Image, Gc, TRUE, 0, 0, w, h );
XFillRectangle( display, Image, Gc, 0, 0, w, h );
}
//---------------------------------------------------------------------------
X11Graphics::~X11Graphics()
{
/* g_object_unref( Gc );
g_object_unref( Image );*/
XFreePixmap( display, Image );
}
//---------------------------------------------------------------------------
void X11Graphics::CopyFrom( int dx, int dy, int dw, int dh, Graphics *Src,
......
......@@ -2,7 +2,7 @@
* x11_run.cpp:
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_run.cpp,v 1.4 2003/05/18 11:25:00 asmax Exp $
* $Id: x11_run.cpp,v 1.5 2003/05/18 17:48:05 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
......@@ -368,7 +368,7 @@ void OSRun( intf_thread_t *p_intf )
ProcessEvent( p_intf, proc, event );
// kludge: add timer
SkinManage( p_intf );
// SkinManage( p_intf );
}
}
......
......@@ -2,7 +2,7 @@
* x11_theme.cpp: X11 implementation of the Theme class
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_theme.cpp,v 1.1 2003/04/28 14:32:57 asmax Exp $
* $Id: x11_theme.cpp,v 1.2 2003/05/18 17:48:05 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
......@@ -165,17 +165,37 @@ void X11Theme::AddWindow( string name, int x, int y, bool visible,
gdk_window_show( gwnd );*/
// Create the window
Window root = DefaultRootWindow( display );
Window wnd = XCreateSimpleWindow( display, root, 0, 0, 200, 100, 0, 0, 0 );
Window wnd = XCreateSimpleWindow( display, root, 0, 0, 1, 1, 0, 0, 0 );
XSelectInput( display, wnd, ExposureMask|
KeyPressMask|KeyReleaseMask|ButtonPressMask|PointerMotionMask|
PointerMotionHintMask| EnterWindowMask|LeaveWindowMask);
// Changing decorations
struct {
unsigned long flags;
unsigned long functions;
unsigned long decorations;
long input_mode;
unsigned long status;
} motifWmHints;
Atom hints_atom = XInternAtom( display, "_MOTIF_WM_HINTS", False );
motifWmHints.flags = 2; // MWM_HINTS_DECORATIONS;
motifWmHints.decorations = 0;
XChangeProperty( display, wnd, hints_atom, hints_atom, 32,
PropModeReplace, (unsigned char *)&motifWmHints,
sizeof( motifWmHints ) / sizeof( long ) );
// Display the window
XMapRaised( display, wnd );
XFlush( display );
WindowList.push_back( (SkinWindow *)new OSWindow( p_intf, wnd, x, y, visible,
fadetime, alpha, movealpha, dragdrop, name ) ) ;
WindowList.push_back( (SkinWindow *)new OSWindow( p_intf, wnd, x, y,
visible, fadetime, alpha, movealpha, dragdrop, name ) ) ;
}
//---------------------------------------------------------------------------
void X11Theme::ChangeTray()
......
......@@ -2,7 +2,7 @@
* x11_window.cpp: X11 implementation of the Window class
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: x11_window.cpp,v 1.3 2003/05/18 11:25:00 asmax Exp $
* $Id: x11_window.cpp,v 1.4 2003/05/18 17:48:05 asmax Exp $
*
* Authors: Cyril Deguet <asmax@videolan.org>
*
......@@ -32,6 +32,7 @@
//--- X11 -------------------------------------------------------------------
#include <X11/Xlib.h>
#include <X11/extensions/shape.h>
//--- SKIN ------------------------------------------------------------------
#include "../os_api.h"
......@@ -276,51 +277,45 @@ void X11Window::SetTransparency( int Value )
//---------------------------------------------------------------------------
void X11Window::RefreshFromImage( int x, int y, int w, int h )
{
// Initialize painting
/* HDC DC = GetWindowDC( hWnd );
// Draw image on window
BitBlt( DC, x, y, w, h, ( (X11Graphics *)Image )->GetImageHandle(),
x, y, SRCCOPY );
// Release window device context
ReleaseDC( hWnd, DC );
*/
Drawable drawable = (( X11Graphics* )Image )->GetImage();
XCopyArea( display, drawable, Wnd, Gc, x, y, w, h, x, y );
XSync( display, 0);
/*
XImage *image = XGetImage( display, drawable, 0, 0, Width, Height,
AllPlanes, ZPixmap );
// Mask for transparency
GdkRegion *region = gdk_region_new();
Region region = XCreateRegion();
for( int line = 0; line < Height; line++ )
{
int start = 0, end = 0;
while( start < Width )
{
while( start < Width && gdk_image_get_pixel( image, start, line ) == 0 )
while( start < Width && XGetPixel( image, start, line ) == 0 )
{
start++;
}
end = start;
while( end < Width && gdk_image_get_pixel( image, end, line ) != 0)
while( end < Width && XGetPixel( image, end, line ) != 0)
{
end++;
}
GdkRectangle rect;
XRectangle rect;
rect.x = start;
rect.y = line;
rect.width = end - start + 1;
rect.height = 1;
GdkRegion *rectReg = gdk_region_rectangle( &rect );
gdk_region_union( region, rectReg );
gdk_region_destroy( rectReg );
Region newRegion = XCreateRegion();
XUnionRectWithRegion( &rect, region, newRegion );
XDestroyRegion( region );
region = newRegion;
start = end + 1;
}
}
gdk_window_shape_combine_region( gWnd, region, 0, 0 );
gdk_region_destroy( region );*/
XShapeCombineRegion( display, Wnd, ShapeBounding, 0, 0, region, ShapeSet );
XDestroyRegion( region );
XSync( display, 0);
}
//---------------------------------------------------------------------------
void X11Window::WindowManualMove()
......@@ -347,14 +342,15 @@ void X11Window::Move( int left, int top )
{
Left = left;
Top = top;
/* gdk_window_move( gWnd, left, top );*/
XMoveWindow( display, Wnd, left, top );
}
//---------------------------------------------------------------------------
void X11Window::Size( int width, int height )
{
Width = width;
Height = height;
/* gdk_window_resize( gWnd, width, height );*/
XResizeWindow( display, Wnd, width, height );
}
//---------------------------------------------------------------------------
void X11Window::ChangeToolTipText( string text )
......
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