]> git.sesse.net Git - vlc/blob - modules/gui/skins/x11/x11_graphics.cpp
* x11_timer.cpp: compilation fix
[vlc] / modules / gui / skins / x11 / x11_graphics.cpp
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 $
6  *
7  * Authors: Cyril Deguet     <asmax@videolan.org>
8  *          Emmanuel Puig    <karibu@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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,
23  * USA.
24  *****************************************************************************/
25
26 #ifdef X11_SKINS
27
28 //--- X11 -----------------------------------------------------------------
29 #include <X11/Xlib.h>
30
31 //--- VLC -----------------------------------------------------------------
32 #include <vlc/intf.h>
33
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"
42
43 #include <stdio.h>
44 #include <math.h>
45
46 //---------------------------------------------------------------------------
47 // X11 GRAPHICS
48 //---------------------------------------------------------------------------
49 X11Graphics::X11Graphics( intf_thread_t *p_intf, int w, int h,
50                           SkinWindow *from ) : Graphics( w, h )
51 {
52     display = p_intf->p_sys->display;
53     int screen = DefaultScreen( display );
54
55     if( from != NULL )
56     {
57         Window fromWnd = ( (X11Window *)from )->GetHandle();
58
59         XWindowAttributes attr;
60         XLOCK;
61         XGetWindowAttributes( display, fromWnd, &attr);
62         Image = XCreatePixmap( display, fromWnd, w, h, attr.depth );
63         XUNLOCK;
64         Gc = DefaultGC( display, screen );
65     }
66     else
67     {
68         Window root = DefaultRootWindow( display );
69         XLOCK;
70         Image = XCreatePixmap( display, root, w, h,
71                                DefaultDepth( display, screen ) );
72         XUNLOCK;
73         Gc = DefaultGC( display, screen );
74     }
75
76     // Set the background color to black
77     DrawRect( 0, 0, w, h, 0 );
78 }
79 //---------------------------------------------------------------------------
80 X11Graphics::~X11Graphics()
81 {
82     XLOCK;
83     XFreePixmap( display, Image );
84     XUNLOCK;
85 }
86 //---------------------------------------------------------------------------
87 void X11Graphics::CopyFrom( int dx, int dy, int dw, int dh, Graphics *Src,
88                               int sx, int sy, int Flag )
89 {
90     XLOCK;
91     XCopyArea( display, (( X11Graphics* )Src )->GetImage(), Image, Gc, 
92                sx, sy, dw, dh, dx, dy );
93     XUNLOCK;
94 }
95 //---------------------------------------------------------------------------
96 void X11Graphics::DrawRect( int x, int y, int w, int h, int color )
97 {
98     XGCValues gcVal;
99     gcVal.foreground = color;
100     XLOCK;
101     XChangeGC( display, Gc, GCForeground,  &gcVal );
102     XFillRectangle( display, Image, Gc, x, y, w, h );    
103     XUNLOCK;
104 }
105 //---------------------------------------------------------------------------
106 void X11Graphics::SetClipRegion( SkinRegion *rgn )
107 {
108 /*    gdk_gc_set_clip_region( Gc, ( (X11Region *)rgn )->GetHandle() );*/
109 }
110 //---------------------------------------------------------------------------
111 void X11Graphics::ResetClipRegion()
112 {
113 /*    GdkRectangle rect;
114     rect.x = 0;
115     rect.y = 0;
116     rect.width = Width;
117     rect.height = Height;
118     GdkRegion *rgn = gdk_region_rectangle( &rect );
119     gdk_gc_set_clip_region( Gc, rgn );
120     gdk_region_destroy( rgn );*/
121 }
122 //---------------------------------------------------------------------------
123
124
125
126 //---------------------------------------------------------------------------
127 // X11 REGION
128 //---------------------------------------------------------------------------
129 X11Region::X11Region()
130 {
131     RefPoint.x = RefPoint.y = 0;
132 }
133 //---------------------------------------------------------------------------
134 X11Region::X11Region( int x, int y, int w, int h )
135 {
136     RefPoint.x = RefPoint.y = 0;
137     AddRectangle( x, y, w, h );
138 }
139 //---------------------------------------------------------------------------
140 X11Region::~X11Region()
141 {
142 }
143 //---------------------------------------------------------------------------
144 void X11Region::AddPoint( int x, int y )
145 {
146     AddRectangle( x, y, 1, 1 );
147 }
148 //---------------------------------------------------------------------------
149 void X11Region::AddRectangle( int x, int y, int w, int h )
150 {
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 );
155 }
156 //---------------------------------------------------------------------------
157 void X11Region::AddElipse( int x, int y, int w, int h )
158 {
159     CoordsElipse coords;
160     coords.x = x - RefPoint.x; coords.y = y - RefPoint.y;
161     coords.w = w; coords.h = h;
162     ElipsesList.push_back( coords );
163 }
164 //---------------------------------------------------------------------------
165 void X11Region::Move( int x, int y )
166 {
167     RefPoint.x += x;
168     RefPoint.y += y;
169 }
170 //---------------------------------------------------------------------------
171 bool X11Region::Hit( int x, int y )
172 {
173     unsigned int i;
174
175     x -= RefPoint.x;
176     y -= RefPoint.y;
177
178     // Check our rectangles list first
179     for( i = 0; i < RectanglesList.size(); i++ )
180     {
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 )
185         {
186             return true;
187         }
188     }
189
190     // Check our elipses list
191     for( i = 0; i < ElipsesList.size(); i++ )
192     {
193         // FIXME!!
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 )
198         {
199             return true;
200         }
201     }
202
203     return false;
204 }
205 //---------------------------------------------------------------------------
206
207 #endif