1 /*****************************************************************************
2 * gtk2_bitmap.cpp: GTK2 implementation of the Bitmap class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: gtk2_bitmap.cpp,v 1.9 2003/04/15 20:33:58 karibu Exp $
7 * Authors: Cyril Deguet <asmax@videolan.org>
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111,
23 *****************************************************************************/
27 //--- GTK2 -----------------------------------------------------------------
28 #include <gdk-pixbuf/gdk-pixbuf.h>
31 //--- VLC -------------------------------------------------------------------
34 //--- SKIN ------------------------------------------------------------------
37 #include "gtk2_graphics.h"
39 #include "gtk2_bitmap.h"
40 #include "skin_common.h"
43 //---------------------------------------------------------------------------
45 //---------------------------------------------------------------------------
46 GTK2Bitmap::GTK2Bitmap( intf_thread_t *p_intf, string FileName, int AColor )
47 : Bitmap( p_intf, FileName, AColor )
55 // Create image from file if it exists
56 HBitmap = (HBITMAP) LoadImage( NULL, FileName.c_str(), IMAGE_BITMAP,
57 0, 0, LR_LOADFROMFILE );
61 msg_Warn( p_intf, "Couldn't load bitmap: %s", FileName.c_str() );
63 HBitmap = CreateBitmap( 0, 0, 1, 32, NULL );
66 // Create device context
67 bmpDC = CreateCompatibleDC( NULL );
68 SelectObject( bmpDC, HBitmap );
71 GetObject( HBitmap, sizeof( Bmp ), &Bmp );
73 Height = Bmp.bmHeight;
75 // If alpha color is not 0, then change 0 colors to non black color to avoid
76 // window transparency
77 if( (int)AlphaColor != OSAPI_GetNonTransparentColor( 0 ) )
79 bufDC = CreateCompatibleDC( bmpDC );
80 HBuf = CreateCompatibleBitmap( bmpDC, Width, Height );
81 SelectObject( bufDC, HBuf );
84 HBRUSH Brush = CreateSolidBrush( OSAPI_GetNonTransparentColor( 0 ) );
89 FillRect( bufDC, r, Brush );
90 DeleteObject( Brush );
93 TransparentBlt( bufDC, 0, 0, Width, Height, bmpDC, 0, 0, Width, Height, 0 );
94 BitBlt( bmpDC, 0, 0, Width, Height, bufDC, 0, 0, SRCCOPY );
100 DeleteObject( HBitmap );*/
102 // Load the bitmap image
103 Bmp = gdk_pixbuf_new_from_file( FileName.c_str(), NULL );
107 msg_Warn( p_intf, "Couldn't load bitmap: %s", FileName.c_str() );
109 // Bmp = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE, 8, 1, 1);
113 Width = gdk_pixbuf_get_width( Bmp );
114 Height = gdk_pixbuf_get_height( Bmp );
116 //---------------------------------------------------------------------------
117 GTK2Bitmap::GTK2Bitmap( intf_thread_t *p_intf, Graphics *from, int x, int y,
118 int w, int h, int AColor ) : Bitmap( p_intf, from, x, y, w, h, AColor )
124 HDC fromDC = ( (GTK2Graphics *)from )->GetImageHandle();
127 bmpDC = CreateCompatibleDC( fromDC );
128 HBmp = CreateCompatibleBitmap( fromDC, Width, Height );
129 SelectObject( bmpDC, HBmp );
130 DeleteObject( HBmp );
131 BitBlt( bmpDC, 0, 0, Width, Height, fromDC, x, y, SRCCOPY );*/
133 //---------------------------------------------------------------------------
134 GTK2Bitmap::GTK2Bitmap( intf_thread_t *p_intf, Bitmap *c )
135 : Bitmap( p_intf, c )
140 c->GetSize( Width, Height );
141 AlphaColor = c->GetAlphaColor();
144 bmpDC = CreateCompatibleDC( NULL );
145 HBuf = CreateCompatibleBitmap( bmpDC, Width, Height );
146 SelectObject( bmpDC, HBuf );
148 BitBlt( bmpDC, 0, 0, Width, Height, ( (GTK2Bitmap *)c )->GetBmpDC(),
150 DeleteObject( HBuf );*/
152 //---------------------------------------------------------------------------
153 GTK2Bitmap::~GTK2Bitmap()
155 /* DeleteDC( bmpDC );*/
157 //---------------------------------------------------------------------------
158 void GTK2Bitmap::DrawBitmap( int x, int y, int w, int h, int xRef, int yRef,
161 /* HDC destDC = ( (GTK2Graphics *)dest )->GetImageHandle();
163 // New method, not available in win95
164 TransparentBlt( destDC, xRef, yRef, w, h, bmpDC, x, y, w, h, AlphaColor );
166 GdkDrawable *destImg = ( (GTK2Graphics *)dest )->GetImage();
167 GdkGC *destGC = ( (GTK2Graphics *)dest )->GetGC();
169 gdk_pixbuf_render_to_drawable( Bmp, destImg, destGC, x, y, xRef, yRef,
170 w, h, GDK_RGB_DITHER_NONE, 0, 0);
172 //---------------------------------------------------------------------------
173 bool GTK2Bitmap::Hit( int x, int y)
175 if( x < 0 || x >= Width || y < 0 || y >= Height )
179 int rowstride, offset;
182 rowstride = gdk_pixbuf_get_rowstride( Bmp );
183 pixels = gdk_pixbuf_get_pixels( Bmp );
184 has_alpha = gdk_pixbuf_get_has_alpha( Bmp );
186 offset = y * rowstride + ( x * (has_alpha ? 4 : 3) );
188 int r = pixels [offset];
189 int g = pixels [offset + 1];
190 int b = pixels [offset + 2];
191 unsigned int c = r + g * 256 + b * 65536;
192 /* If has_alpha == TRUE, then the alpha component is in
193 pixels [offset + 3] */
195 if( c == AlphaColor )
200 //---------------------------------------------------------------------------
201 int GTK2Bitmap::GetBmpPixel( int x, int y )
203 // return GetPixel( bmpDC, x, y );
205 //---------------------------------------------------------------------------
206 void GTK2Bitmap::SetBmpPixel( int x, int y, int color )
208 // SetPixelV( bmpDC, x, y, color );
210 //---------------------------------------------------------------------------