hornetseye-xorg 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +1 -0
- data/COPYING +679 -0
- data/README.md +4 -0
- data/Rakefile +183 -0
- data/ext/error.hh +50 -0
- data/ext/frame.cc +69 -0
- data/ext/frame.hh +41 -0
- data/ext/init.cc +48 -0
- data/ext/rubyinc.hh +54 -0
- data/ext/rubytools.hh +33 -0
- data/ext/rubytools.tcc +32 -0
- data/ext/timer.cc +40 -0
- data/ext/timer.hh +37 -0
- data/ext/x11display.cc +269 -0
- data/ext/x11display.hh +64 -0
- data/ext/x11output.cc +92 -0
- data/ext/x11output.hh +45 -0
- data/ext/x11painter.hh +45 -0
- data/ext/x11window.cc +528 -0
- data/ext/x11window.hh +79 -0
- data/ext/ximagepainter.cc +152 -0
- data/ext/ximagepainter.hh +43 -0
- data/ext/xvideoimagepainter.cc +439 -0
- data/ext/xvideoimagepainter.hh +57 -0
- data/lib/hornetseye-xorg/frame.rb +29 -0
- data/lib/hornetseye-xorg/node.rb +29 -0
- data/lib/hornetseye-xorg/x11display.rb +95 -0
- data/lib/hornetseye-xorg/ximageoutput.rb +32 -0
- data/lib/hornetseye_xorg_ext.rb +22 -0
- metadata +147 -0
data/ext/x11output.cc
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
/* HornetsEye - Computer Vision with Ruby
|
2
|
+
Copyright (C) 2006, 2007, 2008, 2009 Jan Wedekind
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program 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
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
16
|
+
#include "x11output.hh"
|
17
|
+
#include "x11window.hh"
|
18
|
+
|
19
|
+
using namespace std;
|
20
|
+
|
21
|
+
VALUE X11Output::cRubyClass = Qnil;
|
22
|
+
|
23
|
+
X11Output::X11Output( X11PainterPtr painter ):
|
24
|
+
m_painter(painter)
|
25
|
+
{
|
26
|
+
m_painter->registerImageSource( this );
|
27
|
+
}
|
28
|
+
|
29
|
+
X11Output::~X11Output(void)
|
30
|
+
{
|
31
|
+
m_painter->unregisterImageSource();
|
32
|
+
}
|
33
|
+
|
34
|
+
void X11Output::write( FramePtr frame ) throw (Error)
|
35
|
+
{
|
36
|
+
m_frame = frame;
|
37
|
+
X11Window *window = m_painter->window();
|
38
|
+
if ( window ) window->repaint();
|
39
|
+
}
|
40
|
+
|
41
|
+
bool X11Output::status(void) const
|
42
|
+
{
|
43
|
+
bool retVal;
|
44
|
+
if ( m_painter->window() != NULL ) {
|
45
|
+
if ( m_painter->window()->display()->quit() )
|
46
|
+
retVal = false;
|
47
|
+
else
|
48
|
+
retVal = true;
|
49
|
+
} else
|
50
|
+
retVal = false;
|
51
|
+
return retVal;
|
52
|
+
}
|
53
|
+
|
54
|
+
VALUE X11Output::registerRubyClass( VALUE module )
|
55
|
+
{
|
56
|
+
cRubyClass = rb_define_class_under( module, "X11Output", rb_cObject );
|
57
|
+
rb_define_method( cRubyClass, "status?",
|
58
|
+
RUBY_METHOD_FUNC( wrapStatus ), 0 );
|
59
|
+
rb_define_method( cRubyClass, "write",
|
60
|
+
RUBY_METHOD_FUNC( wrapWrite ), 1 );
|
61
|
+
return cRubyClass;
|
62
|
+
}
|
63
|
+
|
64
|
+
void X11Output::deleteRubyObject( void *ptr )
|
65
|
+
{
|
66
|
+
delete (X11OutputPtr *)ptr;
|
67
|
+
}
|
68
|
+
|
69
|
+
void X11Output::markRubyObject( void *ptr )
|
70
|
+
{
|
71
|
+
FramePtr frame( (*(X11OutputPtr *)ptr)->frame() );
|
72
|
+
if ( frame ) frame->markRubyMember();
|
73
|
+
}
|
74
|
+
|
75
|
+
VALUE X11Output::wrapStatus( VALUE rbSelf )
|
76
|
+
{
|
77
|
+
X11OutputPtr *self; Data_Get_Struct( rbSelf, X11OutputPtr, self );
|
78
|
+
return (*self)->status() ? Qtrue : Qfalse;
|
79
|
+
}
|
80
|
+
|
81
|
+
VALUE X11Output::wrapWrite( VALUE rbSelf, VALUE rbFrame )
|
82
|
+
{
|
83
|
+
try {
|
84
|
+
X11OutputPtr *self; Data_Get_Struct( rbSelf, X11OutputPtr, self );
|
85
|
+
FramePtr frame( new Frame( rbFrame ) );
|
86
|
+
(*self)->write( frame );
|
87
|
+
} catch ( std::exception &e ) {
|
88
|
+
rb_raise( rb_eRuntimeError, "%s", e.what() );
|
89
|
+
}
|
90
|
+
return rbFrame;
|
91
|
+
}
|
92
|
+
|
data/ext/x11output.hh
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
/* HornetsEye - Computer Vision with Ruby
|
2
|
+
Copyright (C) 2006, 2007, 2008, 2009 Jan Wedekind
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program 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
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
16
|
+
#ifndef HORNETSEYE_X11OUTPUT_HH
|
17
|
+
#define HORNETSEYE_X11OUTPUT_HH
|
18
|
+
|
19
|
+
#include "frame.hh"
|
20
|
+
#include "x11painter.hh"
|
21
|
+
|
22
|
+
class X11Output
|
23
|
+
{
|
24
|
+
public:
|
25
|
+
X11Output( X11PainterPtr painter );
|
26
|
+
virtual ~X11Output(void);
|
27
|
+
virtual void write( FramePtr frame ) throw (Error);
|
28
|
+
virtual bool status(void) const;
|
29
|
+
X11PainterPtr painter(void) { return m_painter; }
|
30
|
+
FramePtr frame(void) { return m_frame; }
|
31
|
+
static VALUE cRubyClass;
|
32
|
+
static VALUE registerRubyClass( VALUE module );
|
33
|
+
static void deleteRubyObject( void *ptr );
|
34
|
+
static void markRubyObject( void *ptr );
|
35
|
+
static VALUE wrapStatus( VALUE rbSelf );
|
36
|
+
static VALUE wrapWrite( VALUE rbSelf, VALUE rbFrame );
|
37
|
+
protected:
|
38
|
+
FramePtr m_frame;
|
39
|
+
X11PainterPtr m_painter;
|
40
|
+
};
|
41
|
+
|
42
|
+
typedef boost::shared_ptr< X11Output > X11OutputPtr;
|
43
|
+
|
44
|
+
#endif
|
45
|
+
|
data/ext/x11painter.hh
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
/* HornetsEye - Computer Vision with Ruby
|
2
|
+
Copyright (C) 2006, 2007, 2008, 2009 Jan Wedekind
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program 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
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
16
|
+
#ifndef HORNETSEYE_X11PAINTER_HH
|
17
|
+
#define HORNETSEYE_X11PAINTER_HH
|
18
|
+
|
19
|
+
#include <X11/Xutil.h>
|
20
|
+
#include "x11display.hh"
|
21
|
+
|
22
|
+
class X11Window;
|
23
|
+
class X11Output;
|
24
|
+
|
25
|
+
class X11Painter {
|
26
|
+
public:
|
27
|
+
X11Painter(void): m_imageSource(NULL), m_window(NULL) {}
|
28
|
+
virtual ~X11Painter(void) {}
|
29
|
+
virtual void paint( bool x11Event ) throw (Error) = 0;
|
30
|
+
X11Window *window(void) { return m_window; }
|
31
|
+
void registerWindow( X11Window *window ) { m_window = window; }
|
32
|
+
virtual void unregisterWindow(void) { m_window = NULL; }
|
33
|
+
void registerImageSource( X11Output *imageSource )
|
34
|
+
{ m_imageSource = imageSource; }
|
35
|
+
void unregisterImageSource(void) { m_imageSource = NULL; }
|
36
|
+
virtual XVisualInfo *visualInfo( X11DisplayPtr display ) throw (Error) = 0;
|
37
|
+
protected:
|
38
|
+
X11Output *m_imageSource;
|
39
|
+
X11Window *m_window;
|
40
|
+
};
|
41
|
+
|
42
|
+
typedef boost::shared_ptr< X11Painter > X11PainterPtr;
|
43
|
+
|
44
|
+
#endif
|
45
|
+
|
data/ext/x11window.cc
ADDED
@@ -0,0 +1,528 @@
|
|
1
|
+
/* HornetsEye - Computer Vision with Ruby
|
2
|
+
Copyright (C) 2006, 2007, 2008, 2009 Jan Wedekind
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program 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
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
16
|
+
#ifndef NDEBUG
|
17
|
+
#include <iostream>
|
18
|
+
#endif
|
19
|
+
#include <X11/keysym.h>
|
20
|
+
#include <X11/xpm.h>
|
21
|
+
#include <stdint.h>
|
22
|
+
#include "rubytools.hh"
|
23
|
+
#include "x11display.hh"
|
24
|
+
#include "x11output.hh"
|
25
|
+
#include "x11window.hh"
|
26
|
+
|
27
|
+
using namespace std;
|
28
|
+
|
29
|
+
// created from favicon.ico
|
30
|
+
static const char *hornetseye_xpm[] = {
|
31
|
+
"16 16 152 2",
|
32
|
+
" c black",
|
33
|
+
". c #6FB062",
|
34
|
+
"X c #2DD1B8",
|
35
|
+
"o c #37D7C6",
|
36
|
+
"O c #5B9091",
|
37
|
+
"+ c #5A9092",
|
38
|
+
"@ c #5A9192",
|
39
|
+
"# c #5A9290",
|
40
|
+
"$ c #5C9192",
|
41
|
+
"% c #5D9393",
|
42
|
+
"& c #659187",
|
43
|
+
"* c #7FBF86",
|
44
|
+
"= c #40C8A6",
|
45
|
+
"- c #46D4BE",
|
46
|
+
"; c #59CDAB",
|
47
|
+
": c #7BC79F",
|
48
|
+
"> c #64CAA2",
|
49
|
+
", c #64CCA8",
|
50
|
+
"< c #67CDAA",
|
51
|
+
"1 c #6ACEA9",
|
52
|
+
"2 c #69D1B3",
|
53
|
+
"3 c #5DDFD5",
|
54
|
+
"4 c #4CE4DF",
|
55
|
+
"5 c #66DEC9",
|
56
|
+
"6 c #73DBC6",
|
57
|
+
"7 c #79E5DC",
|
58
|
+
"8 c #6CE8EA",
|
59
|
+
"9 c #79EBED",
|
60
|
+
"0 c #87B35F",
|
61
|
+
"q c #89B258",
|
62
|
+
"w c #8ABE7A",
|
63
|
+
"e c #AFBB5D",
|
64
|
+
"r c #AFBA62",
|
65
|
+
"t c #BEC062",
|
66
|
+
"y c #B8C36F",
|
67
|
+
"u c #B8F149",
|
68
|
+
"i c #B9F24A",
|
69
|
+
"p c #B8F04C",
|
70
|
+
"a c #B9F14D",
|
71
|
+
"s c #BDF04E",
|
72
|
+
"d c #FF962F",
|
73
|
+
"f c #FF9B39",
|
74
|
+
"g c #DCB642",
|
75
|
+
"h c #DABA48",
|
76
|
+
"j c #E3BD55",
|
77
|
+
"k c #E4BE58",
|
78
|
+
"l c #FFB369",
|
79
|
+
"z c #C1C268",
|
80
|
+
"x c #D6C774",
|
81
|
+
"c c #D1C879",
|
82
|
+
"v c #E7C363",
|
83
|
+
"b c #EAC86C",
|
84
|
+
"n c #8ACA9B",
|
85
|
+
"m c #96C587",
|
86
|
+
"M c #99C589",
|
87
|
+
"N c #81CFA6",
|
88
|
+
"B c #8CCEA3",
|
89
|
+
"V c #80D0A9",
|
90
|
+
"C c #9CD6B5",
|
91
|
+
"Z c #A5C787",
|
92
|
+
"A c #A4C890",
|
93
|
+
"S c #A8C0B8",
|
94
|
+
"D c #84E0D0",
|
95
|
+
"F c #8FE3D2",
|
96
|
+
"G c #90E0C8",
|
97
|
+
"H c #99E5D7",
|
98
|
+
"J c #9EE4D4",
|
99
|
+
"K c #85E9E1",
|
100
|
+
"L c #86EEEB",
|
101
|
+
"P c #86EDEE",
|
102
|
+
"I c #8BEEEF",
|
103
|
+
"U c #8FEDEC",
|
104
|
+
"Y c #96EAE1",
|
105
|
+
"T c #95EFEE",
|
106
|
+
"R c #94EFF0",
|
107
|
+
"E c #98EFF0",
|
108
|
+
"W c #90F0EF",
|
109
|
+
"Q c #95F1F0",
|
110
|
+
"! c #A0C0C0",
|
111
|
+
"~ c #A1C1C1",
|
112
|
+
"^ c #A3C1C1",
|
113
|
+
"/ c #A2C2C0",
|
114
|
+
"( c #B0E0C8",
|
115
|
+
") c #B5E1CA",
|
116
|
+
"_ c #B0EADB",
|
117
|
+
"` c #B3EBDE",
|
118
|
+
"' c #AAF2EF",
|
119
|
+
"] c #B5F4F5",
|
120
|
+
"[ c #B5F5F5",
|
121
|
+
"{ c #DDCD81",
|
122
|
+
"} c #D9D18D",
|
123
|
+
"| c #C4DCB4",
|
124
|
+
" . c #D1DCB2",
|
125
|
+
".. c #D1DFBB",
|
126
|
+
"X. c #D6F698",
|
127
|
+
"o. c #D7F69A",
|
128
|
+
"O. c #D9F797",
|
129
|
+
"+. c #D8F79B",
|
130
|
+
"@. c #D9F69A",
|
131
|
+
"#. c #E4CC82",
|
132
|
+
"$. c #EAD99E",
|
133
|
+
"%. c #EBDA9F",
|
134
|
+
"&. c #EDD99D",
|
135
|
+
"*. c #FFC083",
|
136
|
+
"=. c #FFC68F",
|
137
|
+
"-. c #FFC995",
|
138
|
+
";. c #EBDBA3",
|
139
|
+
":. c #F1DEA9",
|
140
|
+
">. c #F2DFAE",
|
141
|
+
",. c #FFDFBF",
|
142
|
+
"<. c #EEE1B2",
|
143
|
+
"1. c #EEE4B8",
|
144
|
+
"2. c #F4E1B2",
|
145
|
+
"3. c #FFE0BF",
|
146
|
+
"4. c #D3DFDF",
|
147
|
+
"5. c #D7DFDB",
|
148
|
+
"6. c #D3DFE1",
|
149
|
+
"7. c #D8E5C3",
|
150
|
+
"8. c #DAE6C8",
|
151
|
+
"9. c #CDF9F7",
|
152
|
+
"0. c #CDF8F9",
|
153
|
+
"q. c #D3E1E1",
|
154
|
+
"w. c #D2E0E2",
|
155
|
+
"e. c #D2E2E2",
|
156
|
+
"r. c #D4E2E2",
|
157
|
+
"t. c #D0F8F5",
|
158
|
+
"y. c #D2FAF7",
|
159
|
+
"u. c #D5F8F9",
|
160
|
+
"i. c #D6FAF8",
|
161
|
+
"p. c #D9F9F9",
|
162
|
+
"a. c #ECFBCF",
|
163
|
+
"s. c #EDFACE",
|
164
|
+
"d. c #EDFBCF",
|
165
|
+
"f. c #ECFAD2",
|
166
|
+
"g. c #F7E9C7",
|
167
|
+
"h. c #F7EDCF",
|
168
|
+
"j. c #F8EAC8",
|
169
|
+
"k. c #FAEED2",
|
170
|
+
"l. c #FAF0D6",
|
171
|
+
"z. c #FAF1DA",
|
172
|
+
"x. c #E3FBFB",
|
173
|
+
"c. c #E7FBFB",
|
174
|
+
"v. c #E4FCFA",
|
175
|
+
"b. c #ECFBFC",
|
176
|
+
"n. c #EDFCFD",
|
177
|
+
"m. c #F5FDFD",
|
178
|
+
"M. c #FAFEFE",
|
179
|
+
"N. c #FBFFFF",
|
180
|
+
"B. c #FFFDFB",
|
181
|
+
"V. c #FEFEFE",
|
182
|
+
"C. c gray100",
|
183
|
+
"Z. c None",
|
184
|
+
"Z.Z.,.,.,.,.,.,.,.a.a.a.a.f.s.a.",
|
185
|
+
"Z.-.*.*.*.*.*.*.*.X.@.@.@.+.O.X.",
|
186
|
+
"=.l f d d d d d d i i a s s i i ",
|
187
|
+
"5.S & 7.8._ 1.V.V.V.v.) ...J } ",
|
188
|
+
"r.^ % p.i.' &.V.V.V.v.C t.9.T { ",
|
189
|
+
"e.^ % V.V.x.( >.V.V.H <.V.V.n.F ",
|
190
|
+
"e.^ + V.V.V.E B n N A z.V.V.V.Q ",
|
191
|
+
"e.^ + V.V.m.: h.V.N.K b V.V.V.2 ",
|
192
|
+
"4.! O ;.;.D c V.V.V.[ Z #.;.G r ",
|
193
|
+
"4.! # Q I 3 k V.V.V.c.= L L 4 h ",
|
194
|
+
"r.^ % V.V.[ M :.V.V.7 x V.V.t.V ",
|
195
|
+
"r.^ % V.V.V.8 0 w * . l.V.V.V.9 ",
|
196
|
+
"e.^ + V.V.V.; | i.9.6 v V.V.V.5 ",
|
197
|
+
"e.! + g.h.Y e V.V.V.W z 2.h.` q ",
|
198
|
+
"4.! + < < - j V.V.V.n.X > , o g ",
|
199
|
+
"e.^ % V.V.Q y j.V.V.U t V.V.[ M "
|
200
|
+
};
|
201
|
+
|
202
|
+
VALUE X11Window::cRubyClass = Qnil;
|
203
|
+
|
204
|
+
X11Window::X11Window( X11DisplayPtr display, X11PainterPtr painter,
|
205
|
+
int width, int height, Window parent ):
|
206
|
+
m_display(display), m_painter(painter), m_width(width), m_height(height)
|
207
|
+
{
|
208
|
+
// state = true;
|
209
|
+
ERRORMACRO( width > 0 && height > 0, Error, ,
|
210
|
+
width << 'x' << height << " is an illegal window size." );
|
211
|
+
|
212
|
+
m_visualInfo = painter->visualInfo( display );
|
213
|
+
/* // Request true-colour X11 visual.
|
214
|
+
if ( !XMatchVisualInfo( display->get(),
|
215
|
+
DefaultScreen( display->get() ),
|
216
|
+
24, TrueColor, &m_visualInfo) ) {
|
217
|
+
if ( !XMatchVisualInfo( display->get(),
|
218
|
+
DefaultScreen( display->get() ),
|
219
|
+
16, TrueColor, &m_visualInfo ) ) {
|
220
|
+
if ( !XMatchVisualInfo( display->get(),
|
221
|
+
DefaultScreen( display->get() ),
|
222
|
+
15, TrueColor, &m_visualInfo ) ) {
|
223
|
+
ERRORMACRO( false, Error, ,
|
224
|
+
"Could not get X11 visual for true-colour display." );
|
225
|
+
};
|
226
|
+
};
|
227
|
+
}; */
|
228
|
+
|
229
|
+
// Create a color map.
|
230
|
+
m_colourMap = XCreateColormap( m_display->get(),
|
231
|
+
DefaultRootWindow( display->get() ),
|
232
|
+
m_visualInfo->visual, AllocNone );
|
233
|
+
ERRORMACRO( m_colourMap != 0, Error, ,
|
234
|
+
"Couldn't allocate X11 colormap." );
|
235
|
+
|
236
|
+
try {
|
237
|
+
|
238
|
+
// http://space-out.net/readarticle.php?article=1
|
239
|
+
XSetWindowAttributes attributes;
|
240
|
+
attributes.colormap = m_colourMap;
|
241
|
+
attributes.event_mask = KeyPressMask | ExposureMask | StructureNotifyMask;
|
242
|
+
|
243
|
+
#ifndef NDEBUG
|
244
|
+
cerr << "Creating window of size " << width << 'x' << height << endl;
|
245
|
+
#endif
|
246
|
+
|
247
|
+
if ( parent == 0 )
|
248
|
+
parent = RootWindow( display->get(),
|
249
|
+
m_visualInfo->screen );
|
250
|
+
|
251
|
+
m_window = XCreateWindow( display->get(),
|
252
|
+
parent,
|
253
|
+
0, 0, width, height,
|
254
|
+
0, m_visualInfo->depth, InputOutput,
|
255
|
+
m_visualInfo->visual,
|
256
|
+
CWColormap | CWEventMask,
|
257
|
+
&attributes );
|
258
|
+
ERRORMACRO( m_window != 0, Error, , "Error creating X11 window." );
|
259
|
+
|
260
|
+
wmProtocols = XInternAtom( display->get(), "WM_PROTOCOLS", False );
|
261
|
+
wmDeleteWindow = XInternAtom( display->get(), "WM_DELETE_WINDOW", False );
|
262
|
+
XSetWMProtocols( display->get(), m_window, &wmDeleteWindow, 1 );
|
263
|
+
#ifdef HAVE_XPM
|
264
|
+
XWMHints wmHints;
|
265
|
+
XpmCreatePixmapFromData( display->get(), m_window,
|
266
|
+
(char **)hornetseye_xpm,
|
267
|
+
&wmHints.icon_pixmap,
|
268
|
+
&wmHints.icon_mask,
|
269
|
+
0 );
|
270
|
+
wmHints.flags = IconPixmapHint | IconMaskHint;
|
271
|
+
XSetWMHints( display->get(), m_window, &wmHints );
|
272
|
+
#endif
|
273
|
+
|
274
|
+
try {
|
275
|
+
|
276
|
+
painter->registerWindow( this );
|
277
|
+
|
278
|
+
// Add window to list of display-class.
|
279
|
+
display->addWindow( this );
|
280
|
+
|
281
|
+
// Create graphics context.
|
282
|
+
XGCValues xgcv;
|
283
|
+
m_gc = XCreateGC( display->get(), m_window, 0L, &xgcv );
|
284
|
+
|
285
|
+
} catch ( Error &e ) {
|
286
|
+
|
287
|
+
display->removeWindow( this );
|
288
|
+
XDestroyWindow( display->get(), m_window );
|
289
|
+
painter->unregisterWindow();
|
290
|
+
throw e;
|
291
|
+
|
292
|
+
};
|
293
|
+
|
294
|
+
} catch ( Error &e ) {
|
295
|
+
|
296
|
+
XFreeColormap( display->get(), m_colourMap );
|
297
|
+
throw e;
|
298
|
+
|
299
|
+
};
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
X11Window::~X11Window(void)
|
304
|
+
{
|
305
|
+
#ifndef NDEBUG
|
306
|
+
cerr << "Destroying X11-window." << endl;
|
307
|
+
#endif
|
308
|
+
XFreeGC( m_display->get(), m_gc );
|
309
|
+
m_display->removeWindow( this );
|
310
|
+
XDestroyWindow( m_display->get(), m_window );
|
311
|
+
m_painter->unregisterWindow();
|
312
|
+
XFreeColormap( m_display->get(), m_colourMap );
|
313
|
+
}
|
314
|
+
|
315
|
+
void X11Window::show(void) throw (Error)
|
316
|
+
{
|
317
|
+
XEvent event;
|
318
|
+
XMapWindow( m_display->get(), m_window );
|
319
|
+
// Wait for X-server.
|
320
|
+
XIfEvent( m_display->get(), &event, waitForNotify, (char *)m_window );
|
321
|
+
repaint( true );
|
322
|
+
}
|
323
|
+
|
324
|
+
void X11Window::close(void)
|
325
|
+
{
|
326
|
+
XEvent event;
|
327
|
+
XUnmapWindow( m_display->get(), m_window );
|
328
|
+
// Wait for X-server.
|
329
|
+
XIfEvent( m_display->get(), &event, waitForNotify, (char *)m_window );
|
330
|
+
}
|
331
|
+
|
332
|
+
void X11Window::setTitle( const char *_title )
|
333
|
+
{
|
334
|
+
char *title = strdup( _title );
|
335
|
+
XStoreName( m_display->get(), m_window, title );
|
336
|
+
free( title );
|
337
|
+
}
|
338
|
+
|
339
|
+
Bool X11Window::waitForNotify( Display *, XEvent *e, char *arg )
|
340
|
+
{
|
341
|
+
return ( e->type == MapNotify || e->type == UnmapNotify ) &&
|
342
|
+
( e->xmap.window == (Window)arg );
|
343
|
+
}
|
344
|
+
|
345
|
+
void X11Window::resize( int width, int height ) throw (Error)
|
346
|
+
{
|
347
|
+
ERRORMACRO( width > 0 && height > 0, Error, ,
|
348
|
+
"Cannot resize window to " << width << 'x' << height );
|
349
|
+
if ( m_width != width || m_height != height ) {
|
350
|
+
#ifndef NDEBUG
|
351
|
+
cerr << "Resizing to " << width << "x" << height << endl;
|
352
|
+
#endif
|
353
|
+
XResizeWindow( m_display->get(), m_window, width, height );
|
354
|
+
m_width = width;
|
355
|
+
m_height = height;
|
356
|
+
XFlush( m_display->get() );
|
357
|
+
};
|
358
|
+
}
|
359
|
+
|
360
|
+
void X11Window::repaint( bool x11Event ) throw (Error)
|
361
|
+
{
|
362
|
+
paintEvent( x11Event );
|
363
|
+
}
|
364
|
+
|
365
|
+
void X11Window::handleEvent( XEvent &event ) throw (Error)
|
366
|
+
{
|
367
|
+
#ifndef NDEBUG
|
368
|
+
cerr << "X11Window::handleEvent()" << endl;
|
369
|
+
#endif
|
370
|
+
switch ( event.type ) {
|
371
|
+
case ConfigureNotify:
|
372
|
+
#ifndef NDEBUG
|
373
|
+
cerr << "ConfigureNotify event" << endl;
|
374
|
+
#endif
|
375
|
+
while ( XCheckTypedWindowEvent( m_display->get(), m_window,
|
376
|
+
ConfigureNotify, &event ) );
|
377
|
+
m_width = event.xconfigure.width;
|
378
|
+
m_height = event.xconfigure.height;
|
379
|
+
paintEvent( true );
|
380
|
+
break;
|
381
|
+
case ClientMessage:
|
382
|
+
if ( ( event.xclient.message_type == wmProtocols ) &&
|
383
|
+
( (Atom)event.xclient.data.l[0] == wmDeleteWindow ) ) {
|
384
|
+
#ifndef NDEBUG
|
385
|
+
cerr << "Delete message" << endl;
|
386
|
+
#endif
|
387
|
+
m_display->setQuit( true );
|
388
|
+
};
|
389
|
+
break;
|
390
|
+
case Expose:
|
391
|
+
#ifndef NDEBUG
|
392
|
+
cerr << "Expose event" << endl;
|
393
|
+
#endif
|
394
|
+
while ( XCheckTypedWindowEvent( m_display->get(), m_window,
|
395
|
+
Expose, &event ) );
|
396
|
+
paintEvent( true );
|
397
|
+
break;
|
398
|
+
case KeyPress:
|
399
|
+
#ifndef NDEBUG
|
400
|
+
cerr << "Key event" << endl;
|
401
|
+
#endif
|
402
|
+
keyEvent( event.xkey );
|
403
|
+
break;
|
404
|
+
default:
|
405
|
+
break;
|
406
|
+
};
|
407
|
+
}
|
408
|
+
|
409
|
+
void X11Window::paintEvent( bool x11Event ) throw (Error)
|
410
|
+
{
|
411
|
+
#ifndef NDEBUG
|
412
|
+
cerr << "X11Window::paintEvent( " << x11Event << " )" << endl;
|
413
|
+
#endif
|
414
|
+
m_painter->paint( x11Event );
|
415
|
+
}
|
416
|
+
|
417
|
+
void X11Window::keyEvent( XKeyEvent &xkey ) throw (Error)
|
418
|
+
{
|
419
|
+
switch ( xkey.keycode ) {
|
420
|
+
case 0x09: // escape
|
421
|
+
case 0x41: // space
|
422
|
+
#ifndef NDEBUG
|
423
|
+
cerr << "Escape/Space -> Quit!" << endl;
|
424
|
+
#endif
|
425
|
+
m_display->setQuit( true );
|
426
|
+
break;
|
427
|
+
default:
|
428
|
+
break;
|
429
|
+
};
|
430
|
+
}
|
431
|
+
|
432
|
+
VALUE X11Window::registerRubyClass( VALUE module )
|
433
|
+
{
|
434
|
+
cRubyClass = rb_define_class_under( module, "X11Window", rb_cObject );
|
435
|
+
rb_define_singleton_method( cRubyClass, "new",
|
436
|
+
RUBY_METHOD_FUNC( wrapNew ), 4 );
|
437
|
+
rb_define_method( cRubyClass, "title=",
|
438
|
+
RUBY_METHOD_FUNC( wrapSetTitle ), 1 );
|
439
|
+
rb_define_method( cRubyClass, "width",
|
440
|
+
RUBY_METHOD_FUNC( wrapWidth ), 0 );
|
441
|
+
rb_define_method( cRubyClass, "height",
|
442
|
+
RUBY_METHOD_FUNC( wrapHeight ), 0 );
|
443
|
+
rb_define_method( cRubyClass, "resize",
|
444
|
+
RUBY_METHOD_FUNC( wrapResize ), 2 );
|
445
|
+
rb_define_method( cRubyClass, "show",
|
446
|
+
RUBY_METHOD_FUNC( wrapShow ), 0 );
|
447
|
+
rb_define_method( cRubyClass, "close",
|
448
|
+
RUBY_METHOD_FUNC( wrapClose ), 0 );
|
449
|
+
return cRubyClass;
|
450
|
+
}
|
451
|
+
|
452
|
+
void X11Window::deleteRubyObject( void *ptr )
|
453
|
+
{
|
454
|
+
delete (X11WindowPtr *)ptr;
|
455
|
+
}
|
456
|
+
|
457
|
+
VALUE X11Window::wrapNew( VALUE rbClass, VALUE rbDisplay, VALUE rbX11Output,
|
458
|
+
VALUE rbWidth, VALUE rbHeight )
|
459
|
+
{
|
460
|
+
VALUE retVal = Qnil;
|
461
|
+
try {
|
462
|
+
checkStruct( rbDisplay, X11Display::cRubyClass );
|
463
|
+
X11DisplayPtr *display;
|
464
|
+
dataGetStruct( rbDisplay, X11Display::cRubyClass, X11DisplayPtr,
|
465
|
+
display );
|
466
|
+
checkStruct( rbX11Output, X11Output::cRubyClass );
|
467
|
+
X11OutputPtr *x11Output;
|
468
|
+
dataGetStruct( rbX11Output, X11Output::cRubyClass, X11OutputPtr,
|
469
|
+
x11Output );
|
470
|
+
X11WindowPtr ptr
|
471
|
+
( new X11Window( *display, (*x11Output)->painter(),
|
472
|
+
NUM2INT( rbWidth ), NUM2INT( rbHeight ) ) );
|
473
|
+
retVal = Data_Wrap_Struct( rbClass, 0, X11Window::deleteRubyObject,
|
474
|
+
new X11WindowPtr( ptr ) );
|
475
|
+
} catch ( std::exception &e ) {
|
476
|
+
rb_raise( rb_eRuntimeError, "%s", e.what() );
|
477
|
+
};
|
478
|
+
return retVal;
|
479
|
+
}
|
480
|
+
|
481
|
+
VALUE X11Window::wrapSetTitle( VALUE rbSelf, VALUE rbTitle )
|
482
|
+
{
|
483
|
+
X11WindowPtr *self; Data_Get_Struct( rbSelf, X11WindowPtr, self );
|
484
|
+
(*self)->setTitle( StringValuePtr( rbTitle ) );
|
485
|
+
return rbTitle;
|
486
|
+
}
|
487
|
+
|
488
|
+
VALUE X11Window::wrapWidth( VALUE rbSelf )
|
489
|
+
{
|
490
|
+
X11WindowPtr *self; Data_Get_Struct( rbSelf, X11WindowPtr, self );
|
491
|
+
return INT2NUM( (*self)->width() );
|
492
|
+
}
|
493
|
+
|
494
|
+
VALUE X11Window::wrapHeight( VALUE rbSelf )
|
495
|
+
{
|
496
|
+
X11WindowPtr *self; Data_Get_Struct( rbSelf, X11WindowPtr, self );
|
497
|
+
return INT2NUM( (*self)->height() );
|
498
|
+
}
|
499
|
+
|
500
|
+
VALUE X11Window::wrapResize( VALUE rbSelf, VALUE rbWidth, VALUE rbHeight )
|
501
|
+
{
|
502
|
+
try {
|
503
|
+
X11WindowPtr *self; Data_Get_Struct( rbSelf, X11WindowPtr, self );
|
504
|
+
(*self)->resize( NUM2INT( rbWidth ), NUM2INT( rbHeight ) );
|
505
|
+
} catch ( std::exception &e ) {
|
506
|
+
rb_raise( rb_eRuntimeError, "%s", e.what() );
|
507
|
+
};
|
508
|
+
return rbSelf;
|
509
|
+
}
|
510
|
+
|
511
|
+
VALUE X11Window::wrapShow( VALUE rbSelf )
|
512
|
+
{
|
513
|
+
try {
|
514
|
+
X11WindowPtr *self; Data_Get_Struct( rbSelf, X11WindowPtr, self );
|
515
|
+
(*self)->show();
|
516
|
+
} catch ( std::exception &e ) {
|
517
|
+
rb_raise( rb_eRuntimeError, "%s", e.what() );
|
518
|
+
};
|
519
|
+
return rbSelf;
|
520
|
+
}
|
521
|
+
|
522
|
+
VALUE X11Window::wrapClose( VALUE rbSelf )
|
523
|
+
{
|
524
|
+
X11WindowPtr *self; Data_Get_Struct( rbSelf, X11WindowPtr, self );
|
525
|
+
(*self)->close();
|
526
|
+
return rbSelf;
|
527
|
+
}
|
528
|
+
|