1 /*****************************************************************************
2 * x11_graphics.cpp: X11 implementation of the Graphics and Region classes
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: x11_graphics.cpp,v 1.8 2003/06/09 12:33:16 asmax Exp $
7 * Authors: Cyril Deguet <asmax@videolan.org>
8 * Emmanuel Puig <karibu@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
24 *****************************************************************************/
28 //--- X11 -----------------------------------------------------------------
31 //--- VLC -----------------------------------------------------------------
34 //--- SKIN ------------------------------------------------------------------
35 #include "../src/graphics.h"
36 #include "../src/window.h"
37 #include "../os_window.h"
38 #include "../src/theme.h"
39 #include "../os_theme.h"
40 #include "x11_graphics.h"
41 #include "../src/skin_common.h"
46 //---------------------------------------------------------------------------
48 //---------------------------------------------------------------------------
49 X11Graphics::X11Graphics( intf_thread_t *p_intf, int w, int h,
50 SkinWindow *from ) : Graphics( w, h )
52 display = p_intf->p_sys->display;
53 int screen = DefaultScreen( display );
57 Window fromWnd = ( (X11Window *)from )->GetHandle();
59 XWindowAttributes attr;
61 XGetWindowAttributes( display, fromWnd, &attr);
62 Image = XCreatePixmap( display, fromWnd, w, h, attr.depth );
64 Gc = DefaultGC( display, screen );
68 Window root = DefaultRootWindow( display );
70 Image = XCreatePixmap( display, root, w, h,
71 DefaultDepth( display, screen ) );
73 Gc = DefaultGC( display, screen );
76 // Set the background color to black
77 DrawRect( 0, 0, w, h, 0 );
79 //---------------------------------------------------------------------------
80 X11Graphics::~X11Graphics()
83 XFreePixmap( display, Image );
86 //---------------------------------------------------------------------------
87 void X11Graphics::CopyFrom( int dx, int dy, int dw, int dh, Graphics *Src,
88 int sx, int sy, int Flag )
91 XCopyArea( display, (( X11Graphics* )Src )->GetImage(), Image, Gc,
92 sx, sy, dw, dh, dx, dy );
95 //---------------------------------------------------------------------------
96 void X11Graphics::DrawRect( int x, int y, int w, int h, int color )
99 gcVal.foreground = color;
101 XChangeGC( display, Gc, GCForeground, &gcVal );
102 XFillRectangle( display, Image, Gc, x, y, w, h );
105 //---------------------------------------------------------------------------
106 void X11Graphics::SetClipRegion( SkinRegion *rgn )
108 /* gdk_gc_set_clip_region( Gc, ( (X11Region *)rgn )->GetHandle() );*/
110 //---------------------------------------------------------------------------
111 void X11Graphics::ResetClipRegion()
113 /* GdkRectangle rect;
117 rect.height = Height;
118 GdkRegion *rgn = gdk_region_rectangle( &rect );
119 gdk_gc_set_clip_region( Gc, rgn );
120 gdk_region_destroy( rgn );*/
122 //---------------------------------------------------------------------------
126 //---------------------------------------------------------------------------
128 //---------------------------------------------------------------------------
129 X11Region::X11Region()
131 RefPoint.x = RefPoint.y = 0;
133 //---------------------------------------------------------------------------
134 X11Region::X11Region( int x, int y, int w, int h )
136 RefPoint.x = RefPoint.y = 0;
137 AddRectangle( x, y, w, h );
139 //---------------------------------------------------------------------------
140 X11Region::~X11Region()
143 //---------------------------------------------------------------------------
144 void X11Region::AddPoint( int x, int y )
146 AddRectangle( x, y, 1, 1 );
148 //---------------------------------------------------------------------------
149 void X11Region::AddRectangle( int x, int y, int w, int h )
151 CoordsRectangle coords;
152 coords.x = x - RefPoint.x; coords.y = y - RefPoint.y;
153 coords.w = w; coords.h = h;
154 RectanglesList.push_back( coords );
156 //---------------------------------------------------------------------------
157 void X11Region::AddElipse( int x, int y, int w, int h )
160 coords.x = x - RefPoint.x; coords.y = y - RefPoint.y;
161 coords.w = w; coords.h = h;
162 ElipsesList.push_back( coords );
164 //---------------------------------------------------------------------------
165 void X11Region::Move( int x, int y )
170 //---------------------------------------------------------------------------
171 bool X11Region::Hit( int x, int y )
178 // Check our rectangles list first
179 for( i = 0; i < RectanglesList.size(); i++ )
181 if( x >= RectanglesList[i].x &&
182 x <= RectanglesList[i].x + RectanglesList[i].w &&
183 y >= RectanglesList[i].y &&
184 y <= RectanglesList[i].y + RectanglesList[i].h )
190 // Check our elipses list
191 for( i = 0; i < ElipsesList.size(); i++ )
194 if( x >= ElipsesList[i].x &&
195 x <= ElipsesList[i].x + ElipsesList[i].w &&
196 y >= ElipsesList[i].y &&
197 y <= ElipsesList[i].y + ElipsesList[i].h )
205 //---------------------------------------------------------------------------