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