4671d62dabde06d4fc2762467438559eb013c67a
[ruby-esmart.git] / src / esmart_trans_x11 / rb_esmart_trans_x11.c
1 /*
2  * $Id: rb_esmart_trans_x11.c 52 2004-08-01 10:19:14Z tilman $
3  *
4  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
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 <Esmart/Esmart_Trans_X11.h>
24 #include <evas/rb_evas.h>
25 #include <evas/rb_evas_object.h>
26 #include <ecore/rb_window.h>
27
28 #include "../rb_esmart.h"
29
30 static void c_free (RbEvasObject *e)
31 {
32         c_evas_object_free (e, true);
33 }
34
35 static VALUE c_new (VALUE klass, VALUE evas)
36 {
37         VALUE self, argv[1];
38         RbEvasObject *trans;
39
40         CHECK_CLASS (evas, cEvas);
41         GET_OBJ (evas, RbEvas, e);
42
43         self = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark,
44                                  c_free, trans);
45         trans->real = esmart_trans_x11_new (e->real);
46
47         argv[0] = evas;
48         rb_obj_call_init (self, 1, argv);
49
50         return self;
51 }
52
53 static VALUE c_type_get (VALUE self)
54 {
55         GET_OBJ (self, RbEvasObject, e);
56
57         return INT2FIX (esmart_trans_x11_type_get (e->real));
58 }
59
60 static VALUE c_type_set (VALUE self, VALUE val)
61 {
62         GET_OBJ (self, RbEvasObject, e);
63
64         Check_Type (val, T_FIXNUM);
65
66         esmart_trans_x11_type_set (e->real, FIX2INT (val));
67
68         return Qnil;
69 }
70
71 static VALUE c_window_set (VALUE self, VALUE window)
72 {
73         GET_OBJ (self, RbEvasObject, e);
74
75         CHECK_CLASS (window, cWindow);
76         GET_OBJ (window, RbWindow, w);
77
78         esmart_trans_x11_window_set (e->real, w->real);
79
80         return Qnil;
81 }
82
83 static VALUE c_freshen (VALUE self, VALUE x, VALUE y, VALUE w, VALUE h)
84 {
85         GET_OBJ (self, RbEvasObject, e);
86
87         Check_Type (x, T_FIXNUM);
88         Check_Type (y, T_FIXNUM);
89         Check_Type (w, T_FIXNUM);
90         Check_Type (h, T_FIXNUM);
91
92         esmart_trans_x11_freshen (e->real, FIX2INT (x), FIX2INT (y),
93                                   FIX2INT (w), FIX2INT (h));
94
95         return Qnil;
96 }
97
98 void Init_esmart_trans_x11 (void)
99 {
100         VALUE c;
101
102         rb_require ("esmart");
103         rb_require ("ecore_x");
104
105         c = rb_define_class_under (mEsmart, "TransX11", cEvasObject);
106
107         rb_define_singleton_method (c, "new", c_new, 1);
108         rb_define_method (c, "type", c_type_get, 0);
109         rb_define_method (c, "type=", c_type_set, 1);
110         rb_define_method (c, "window=", c_window_set, 1);
111         rb_define_method (c, "freshen", c_freshen, 4);
112
113         rb_define_const (c, "BACKGROUND",
114                          INT2FIX (Esmart_Trans_X11_Type_Background));
115         rb_define_const (c, "SCREENGRAB",
116                          INT2FIX (Esmart_Trans_X11_Type_Screengrab));
117 }