c0e5136f4e3e2f66627ef5e98c605a05ae8d90f5
[ruby-ecore.git] / src / ecore_evas / rb_gl_x11.c
1 /*
2  * $Id: rb_gl_x11.c 351 2006-02-10 15:25:40Z tilman $
3  *
4  * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <ruby.h>
22
23 #include <Ecore.h>
24 #include <Ecore_Evas.h>
25
26 #include "../ecore/rb_ecore.h"
27 #include "../ecore_x/rb_window.h"
28 #include "rb_ecore_evas_main.h"
29 #include "rb_ecore_evas.h"
30
31 typedef struct {
32         RbEcoreEvas ee;
33         VALUE parent_window;
34         VALUE window;
35 } RbEcoreEvasGlX11;
36
37 static void c_mark (RbEcoreEvasGlX11 *ee)
38 {
39         c_ecore_evas_mark (&ee->ee);
40
41         if (!NIL_P (ee->parent_window))
42                 rb_gc_mark (ee->parent_window);
43
44         if (!NIL_P (ee->window))
45                 rb_gc_mark (ee->window);
46 }
47
48 static void c_free (RbEcoreEvasGlX11 *ee)
49 {
50         c_ecore_evas_free (&ee->ee, false);
51
52         free (ee);
53 }
54
55 static VALUE c_alloc (VALUE klass)
56 {
57         RbEcoreEvasGlX11 *ee = NULL;
58
59         ecore_init ();
60         ecore_evas_init ();
61
62         return Data_Make_Struct (klass, RbEcoreEvasGlX11,
63                                  c_mark, c_free, ee);
64 }
65
66 /*
67  * call-seq:
68  *  Ecore::Evas::GlX11.new([display, parent, x, y, w, h]) => glx11
69  *
70  * Creates an Ecore::Evas::GlX11 object.
71  */
72 static VALUE c_init (int argc, VALUE *argv, VALUE self)
73 {
74         VALUE disp, parent, geom[4];
75         RbWindow *win = NULL;
76         char *cdisp = NULL;
77         int i, igeom[4] = {0, 0, 0, 0};
78
79         GET_OBJ (self, RbEcoreEvasGlX11, ee);
80
81         rb_scan_args (argc, argv, "06", &disp, &parent,
82                       &geom[0], &geom[1], &geom[2], &geom[3]);
83
84         if (!NIL_P (disp)) {
85                 Check_Type (disp, T_STRING);
86                 cdisp = StringValuePtr (disp);
87         }
88
89         if (!NIL_P (parent)) {
90                 CHECK_CLASS (parent, cWindow);
91                 Data_Get_Struct (parent, RbWindow, win);
92         }
93
94         for (i = 0; i < 4; i++)
95                 if (!NIL_P (geom[i])) {
96                         Check_Type (geom[i], T_FIXNUM);
97                         igeom[i] = FIX2INT (geom[i]);
98                 }
99
100         ee->ee.real = ecore_evas_gl_x11_new (cdisp,
101                                              win ? win->real : 0,
102                                              igeom[0], igeom[1],
103                                              igeom[2], igeom[3]);
104         ee->parent_window = parent;
105         ee->window = Qnil;
106
107         rb_call_super (argc, argv);
108
109         return self;
110 }
111
112 /*
113  * call-seq:
114  *  glx11.window => window
115  *
116  * Returns the <code>Ecore::X::Window</code> object for <i>glx11</i>.
117  */
118 static VALUE c_window_get (VALUE self)
119 {
120         Ecore_X_Window w;
121
122         GET_OBJ (self, RbEcoreEvasGlX11, ee);
123
124         if (NIL_P (ee->window)) {
125                 w = ecore_evas_gl_x11_window_get (ee->ee.real);
126                 ee->window = TO_ECORE_X_WINDOW (self, w);
127         }
128
129         return ee->window;
130 }
131
132 void Init_GlX11 (void)
133 {
134         VALUE c;
135
136         rb_require ("ecore_x");
137
138         c = rb_define_class_under (mEvas, "GlX11", cEcoreEvas);
139
140         rb_define_alloc_func (c, c_alloc);
141         rb_define_method (c, "initialize", c_init, -1);
142         rb_define_method (c, "window", c_window_get, 0);
143 }