ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.37 by root, Sun Apr 9 21:05:50 2006 UTC vs.
Revision 1.65 by root, Tue Apr 11 14:04:27 2006 UTC

1package Crossfire::Client::Widget; 1package CFClient::Widget;
2 2
3use strict; 3use strict;
4 4
5use Scalar::Util; 5use Scalar::Util;
6 6
7use SDL::OpenGL; 7use SDL::OpenGL;
8use SDL::OpenGL::Constants; 8use SDL::OpenGL::Constants;
9 9
10our $FOCUS; # the widget with current focus 10use CFClient;
11
12our ($FOCUS, $HOVER, $GRAB); # various widgets
13
14our $TOPLEVEL;
15our $BUTTON_STATE;
11 16
12# class methods for events 17# class methods for events
13sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } 18sub feed_sdl_key_down_event {
14sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } 19 $FOCUS->key_down ($_[0]) if $FOCUS;
20}
21
22sub feed_sdl_key_up_event {
23 $FOCUS->key_up ($_[0]) if $FOCUS;
24}
25
15sub feed_sdl_button_down_event { } 26sub feed_sdl_button_down_event {
27 my ($ev) = @_;
28 my ($x, $y) = ($ev->motion_x, $ev->motion_y);
29
30 if (!$BUTTON_STATE) {
31 my $widget = $TOPLEVEL->find_widget ($x, $y);
32
33 $GRAB = $widget;
34 $GRAB->update if $GRAB;
35 }
36
37 $BUTTON_STATE |= 1 << ($ev->button - 1);
38
39 $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB;
40}
41
16sub feed_sdl_button_up_event { } 42sub feed_sdl_button_up_event {
43 my ($ev) = @_;
44 my ($x, $y) = ($ev->motion_x, $ev->motion_y);
45
46 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y);
47
48 $BUTTON_STATE &= ~(1 << ($ev->button - 1));
49
50 $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB;
51
52 if (!$BUTTON_STATE) {
53 my $grab = $GRAB; undef $GRAB;
54 $grab->update if $grab;
55 $GRAB->update if $GRAB;
56 }
57}
58
59sub feed_sdl_motion_event {
60 my ($ev) = @_;
61 my ($x, $y) = ($ev->motion_x, $ev->motion_y);
62
63 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y);
64
65 if ($widget != $HOVER) {
66 my $hover = $HOVER; $HOVER = $widget;
67
68 $hover->update if $hover;
69 $HOVER->update if $HOVER;
70 }
71
72 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER;
73}
17 74
18sub new { 75sub new {
19 my $class = shift; 76 my $class = shift;
20 77
21 bless { @_ }, $class 78 bless {
79 x => 0,
80 y => 0,
81 z => 0,
82 @_
83 }, $class
22} 84}
23 85
24sub move { 86sub move {
25 my ($self, $x, $y, $z) = @_; 87 my ($self, $x, $y, $z) = @_;
26 $self->{x} = $x; 88 $self->{x} = $x;
37 Carp::confess "size_request is abtract"; 99 Carp::confess "size_request is abtract";
38} 100}
39 101
40sub size_allocate { 102sub size_allocate {
41 my ($self, $w, $h) = @_; 103 my ($self, $w, $h) = @_;
104
42 $self->w ($w); 105 $self->{w} = $w;
43 $self->h ($h); 106 $self->{h} = $h;
107}
108
109# translate global koordinates to local coordinate system
110sub translate {
111 my ($self, $x, $y) = @_;
112
113 $self->{parent}->translate ($x - $self->{x}, $y - $self->{y});
44} 114}
45 115
46sub focus_in { 116sub focus_in {
47 my ($widget) = @_; 117 my ($self) = @_;
48 $FOCUS = $widget; 118
119 my $focus = $FOCUS; $FOCUS = $self;
120 $focus->update if $focus;
121 $FOCUS->update;
49} 122}
50 123
51sub focus_out { 124sub focus_out {
52 my ($widget) = @_; 125 my ($self) = @_;
53}
54 126
55sub key_down { 127 return unless $FOCUS == $self;
56 my ($widget, $sdlev) = @_;
57}
58 128
59sub key_up { 129 my $focus = $FOCUS; undef $FOCUS;
60 my ($widget, $sdlev) = @_; 130 $focus->update if $focus; #?
61} 131}
62 132
133sub mouse_motion { }
134sub button_up { }
63sub button_down { 135sub button_down { }
64 my ($widget, $sdlev) = @_; 136sub key_down { }
65} 137sub key_up { }
66 138
67sub button_up {
68 my ($widget, $sdlev) = @_;
69}
70
71sub w { $_[0]->{w} = $_[1] if $_[1]; $_[0]->{w} } 139sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} }
72sub h { $_[0]->{h} = $_[1] if $_[1]; $_[0]->{h} } 140sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} }
73sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} } 141sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} }
74sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} } 142sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} }
75sub z { $_[0]->{z} = $_[1] if $_[1]; $_[0]->{z} } 143sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} }
76 144
77sub draw { 145sub draw {
78 my ($self) = @_; 146 my ($self) = @_;
79 147
80 glPushMatrix; 148 glPushMatrix;
81 glTranslate $self->{x}, $self->{y}, 0; 149 glTranslate $self->{x}, $self->{y}, 0;
82 $self->_draw; 150 $self->_draw;
151 if ($self == $HOVER) {
152 glColor 1, 1, 1, 0.4;
153 glEnable GL_BLEND;
154 glBegin GL_QUADS;
155 glVertex 0 , 0;
156 glVertex $self->{w}, 0;
157 glVertex $self->{w}, $self->{h};
158 glVertex 0 , $self->{h};
159 glEnd;
160 glDisable GL_BLEND;
161 }
83 glPopMatrix; 162 glPopMatrix;
84} 163}
85 164
86sub _draw { 165sub _draw {
87 my ($widget) = @_; 166 my ($self) = @_;
167
168 warn "no draw defined for $self\n";
88} 169}
89 170
90sub bbox { 171sub bbox {
91 my ($self) = @_; 172 my ($self) = @_;
92 my ($w, $h) = $self->size_request; 173 my ($w, $h) = $self->size_request;
96 $self->{x} = $w, 177 $self->{x} = $w,
97 $self->{y} = $h 178 $self->{y} = $h
98 ) 179 )
99} 180}
100 181
182sub find_widget {
183 my ($self, $x, $y) = @_;
184
185 return $self
186 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
187 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
188
189 ()
190}
191
101sub del_parent { $_[0]->{parent} = undef } 192sub del_parent { $_[0]->{parent} = undef }
102 193
103sub set_parent { 194sub set_parent {
104 my ($self, $par) = @_; 195 my ($self, $par) = @_;
105 196
122 my ($self) = @_; 213 my ($self) = @_;
123 214
124 #$self->deactivate; 215 #$self->deactivate;
125} 216}
126 217
127package Crossfire::Client::Widget::Bin; 218#############################################################################
128 219
220package CFClient::Widget::Container;
221
129our @ISA = Crossfire::Client::Widget::; 222our @ISA = CFClient::Widget::;
130 223
131sub add { $_[0]->{child} = $_[1]; $_[1]->set_parent ($_[0]); $_[1]->{expand} = $_[2] } 224sub new {
132sub get { $_[0]->{child} } 225 my ($class, %arg) = @_;
226
227 my $children = delete $arg{children} || [];
228
229 my $self = $class->SUPER::new (children => [], %arg);
230 $self->add ($_) for @$children;
231
232 $self
233}
234
235sub add {
236 my ($self, $chld, $expand) = @_;
237
238 $chld->{expand} = $expand;
239 $chld->set_parent ($self);
240
241 @{$self->{children}} =
242 sort { $a->{z} <=> $b->{z} }
243 @{$self->{children}}, $chld;
244
245 $self->size_allocate ($self->{w}, $self->{h})
246 if $self->{w}; #TODO: check for "realised state"
247}
133 248
134sub remove { 249sub remove {
135 my ($self, $chld) = @_; 250 my ($self, $widget) = @_;
136 delete $self->{child} 251
137 if $self->{child} == $chld; 252 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ];
253
254 $self->size_allocate ($self->{w}, $self->{h});
138} 255}
256
257sub find_widget {
258 my ($self, $x, $y) = @_;
259
260 $x -= $self->{x};
261 $y -= $self->{y};
262
263 my $res;
264
265 for (reverse @{ $self->{children} }) {
266 $res = $_->find_widget ($x, $y)
267 and return $res;
268 }
269
270 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y})
271}
272
273sub _draw {
274 my ($self) = @_;
275
276 $_->draw for @{$self->{children}};
277}
278
279#############################################################################
280
281package CFClient::Widget::Bin;
282
283our @ISA = CFClient::Widget::Container::;
284
285sub child { $_[0]->{children}[0] }
139 286
140sub size_request { 287sub size_request {
141 $_[0]->{child}->size_request if $_[0]->{child} 288 $_[0]{children}[0]->size_request if $_[0]{children}[0];
142} 289}
290
143sub size_allocate { 291sub size_allocate {
144 my ($self, $w, $h) = @_; 292 my ($self, $w, $h) = @_;
293
145 $self->SUPER::size_allocate ($w, $h); 294 $self->SUPER::size_allocate ($w, $h);
146 $self->{child}->size_allocate ($w, $h) 295 $self->{children}[0]->size_allocate ($w, $h)
147 if $self->{child} 296 if $self->{children}[0]
148} 297}
149 298
150sub _draw { 299#############################################################################
151 my ($self) = @_;
152 300
153 $self->{child}->draw; 301package CFClient::Widget::Window;
154}
155 302
156package Crossfire::Client::Widget::Toplevel;
157
158our @ISA = Crossfire::Client::Widget::; 303our @ISA = CFClient::Widget::Bin::;
159 304
160use SDL::OpenGL; 305use SDL::OpenGL;
161 306
162sub add { 307sub new {
163 my ($self, $chld) = @_; 308 my ($class, %arg) = @_;
164 309
165 push @{$self->{childs}}, $chld; 310 my $self = $class->SUPER::new (%arg);
166 @{$self->{childs}} =
167 sort { $a->{z} <=> $b->{z} }
168 @{$self->{childs}};
169
170 $chld->set_parent ($self);
171 $chld->size_allocate ($chld->size_request);
172}
173
174sub remove {
175 my ($self, $chld) = @_;
176 @{$self->{childs}} =
177 sort { $a->{z} <=> $b->{z} }
178 grep { $_ && $_ != $_[0] }
179 @{$self->{childs}}
180} 311}
181 312
182sub update { 313sub update {
183 my ($self) = @_; 314 my ($self) = @_;
184 ::refresh ();
185}
186 315
187sub _draw { 316 # we want to do this delayed...
188 my ($self) = @_;
189
190 $_->draw for @{$self->{childs}};
191}
192
193package Crossfire::Client::Widget::Window;
194
195our @ISA = Crossfire::Client::Widget::Bin::;
196
197use SDL::OpenGL;
198
199sub add {
200 my ($self, $chld) = @_;
201 warn "ADD $chld\n";
202 $self->SUPER::add ($chld);
203 $chld->set_parent ($self);
204}
205
206sub remove {
207 my ($self) = @_;
208 # TODO FIXME: removing a child from a window will crash, see render_chld
209 # $self->update;
210}
211
212sub update {
213 my ($self) = @_;
214 $self->render_chld; 317 $self->render_chld;
318 $self->SUPER::update;
215} 319}
216 320
217sub render_chld { 321sub render_chld {
218 my ($self) = @_; 322 my ($self) = @_;
219 my $chld = $self->get;
220 my ($w, $h) = $self->size_request;
221 323
222 require Carp;
223 Carp::cluck "RENDERCHI $w $h";
224 warn "RENDERCHI $w $h\n";
225 $self->{texture} = 324 $self->{texture} =
226 Crossfire::Client::Texture->new_from_opengl ( 325 CFClient::Texture->new_from_opengl (
227 $w, $h, sub { $chld->draw } 326 $self->{w}, $self->{h}, sub { $self->child->draw }
228 ); 327 );
229 $self->{texture}->upload;
230}
231
232sub size_request {
233 my ($self) = @_;
234 ($self->w, $self->h)
235} 328}
236 329
237sub size_allocate { 330sub size_allocate {
238 my ($self, $w, $h) = @_; 331 my ($self, $w, $h) = @_;
239 332
240 $self->w ($w); 333 $self->{w} = $w;
241 $self->h ($h); 334 $self->{h} = $h;
335
242 $self->get->size_allocate ($w, $h); 336 $self->child->size_allocate ($w, $h);
243 337
244 $self->update; #TODO: Move this to the size_request event propably? 338 $self->render_chld;
245} 339}
246 340
247sub _draw { 341sub _draw {
248 my ($self) = @_; 342 my ($self) = @_;
249 343
253 or return; 347 or return;
254 348
255 glEnable GL_BLEND; 349 glEnable GL_BLEND;
256 glEnable GL_TEXTURE_2D; 350 glEnable GL_TEXTURE_2D;
257 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 351 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
258 glBindTexture GL_TEXTURE_2D, $tex->{name};
259 352
260 glBegin GL_QUADS; 353 $tex->draw_quad (0, 0, $w, $h);
261 glTexCoord 0, 0; glVertex 0, 0;
262 glTexCoord 0, 1; glVertex 0, $h;
263 glTexCoord 1, 1; glVertex $w, $h;
264 glTexCoord 1, 0; glVertex $w, 0;
265 glEnd;
266 354
267 glDisable GL_BLEND; 355 glDisable GL_BLEND;
268 glDisable GL_TEXTURE_2D; 356 glDisable GL_TEXTURE_2D;
269} 357}
270 358
359#############################################################################
360
271package Crossfire::Client::Widget::Frame; 361package CFClient::Widget::Frame;
272 362
273our @ISA = Crossfire::Client::Widget::Bin::; 363our @ISA = CFClient::Widget::Bin::;
274 364
275use SDL::OpenGL; 365use SDL::OpenGL;
276 366
277sub size_request { 367sub size_request {
278 my ($self) = @_; 368 my ($self) = @_;
279 my $chld = $self->get 369 my $chld = $self->child
280 or return (0, 0); 370 or return (0, 0);
281 371
282 $chld->move (2, 2); 372 $chld->move (2, 2);
283 373
284 map { $_ + 4 } $chld->size_request; 374 map { $_ + 4 } $chld->size_request;
285} 375}
286 376
287sub size_allocate { 377sub size_allocate {
288 my ($self, $w, $h) = @_; 378 my ($self, $w, $h) = @_;
289 379
290 $self->w ($w); 380 $self->{w} = $w;
291 $self->h ($h); 381 $self->{h} = $h;
292 382
293 $self->get->size_allocate ($w - 4, $h - 4); 383 $self->child->size_allocate ($w - 4, $h - 4);
294 $self->get->move (2, 2); 384 $self->child->move (2, 2);
295} 385}
296 386
297sub _draw { 387sub _draw {
298 my ($self) = @_; 388 my ($self) = @_;
299 389
300 my $chld = $self->get; 390 my $chld = $self->child;
301 391
302 my ($w, $h) = $chld->size_request; 392 my ($w, $h) = $chld->size_request;
303 393
304 glBegin GL_QUADS; 394 glBegin GL_QUADS;
305 glColor 0, 0, 0; 395 glColor 0, 0, 0;
306 glTexCoord 0, 0; glVertex 0 , 0; 396 glVertex 0 , 0;
307 glTexCoord 0, 1; glVertex 0 , $h + 4; 397 glVertex 0 , $h + 4;
308 glTexCoord 1, 1; glVertex $w + 4 , $h + 4; 398 glVertex $w + 4 , $h + 4;
309 glTexCoord 1, 0; glVertex $w + 4 , 0; 399 glVertex $w + 4 , 0;
310 glEnd; 400 glEnd;
311 401
312 $chld->draw; 402 $chld->draw;
313} 403}
314 404
405#############################################################################
406
315package Crossfire::Client::Widget::FancyFrame; 407package CFClient::Widget::FancyFrame;
316 408
317our @ISA = Crossfire::Client::Widget::Frame::; 409our @ISA = CFClient::Widget::Bin::;
318 410
319use SDL::OpenGL; 411use SDL::OpenGL;
320 412
321sub new { 413my @tex =
322 my ($self, $theme) = @_;
323 $self = $self->SUPER::new;
324
325 $self->{txts} = [
326 map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } 414 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
327 qw/d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png/ 415 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
328 ];
329 $self
330}
331 416
332sub size_request { 417sub size_request {
333 my ($self) = @_; 418 my ($self) = @_;
419
334 my ($w, $h) = $self->get->size_request; 420 my ($w, $h) = $self->SUPER::size_request;
335 421
336 $h += $self->{txts}->[1]->{height}; 422 $h += $tex[1]->{height};
337 $h += $self->{txts}->[4]->{height}; 423 $h += $tex[4]->{height};
338 $w += $self->{txts}->[2]->{width}; 424 $w += $tex[2]->{width};
339 $w += $self->{txts}->[3]->{width}; 425 $w += $tex[3]->{width};
340 426
341 ($w, $h) 427 ($w, $h)
342} 428}
343 429
344sub size_allocate { 430sub size_allocate {
345 my ($self, $w, $h) = @_; 431 my ($self, $w, $h) = @_;
346 432
347 $self->w ($w); 433 $self->SUPER::size_allocate ($w, $h);
348 $self->h ($h); 434
349 $h -= $self->{txts}->[1]->{height}; 435 $h -= $tex[1]->{height};
350 $h -= $self->{txts}->[4]->{height}; 436 $h -= $tex[4]->{height};
351 $w -= $self->{txts}->[2]->{width}; 437 $w -= $tex[2]->{width};
352 $w -= $self->{txts}->[3]->{width}; 438 $w -= $tex[3]->{width};
353 439
354 $h = $h < 0 ? 0 : $h; 440 $h = $h < 0 ? 0 : $h;
355 $w = $w < 0 ? 0 : $w; 441 $w = $w < 0 ? 0 : $w;
356 warn "CHILD:$w $h\n"; 442
357 $self->get->size_allocate ($w, $h); 443 $self->child->size_allocate ($w, $h);
358 $self->get->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); 444 $self->child->move ($tex[3]->{width}, $tex[1]->{height});
359} 445}
360 446
361sub _draw { 447sub _draw {
362 my ($self) = @_; 448 my ($self) = @_;
363 449
364 my ($w, $h) = ($self->w, $self->h); 450 my ($w, $h) = ($self->{w}, $self->{h});
365 my ($cw, $ch) = ($self->get->w, $self->get->h); 451 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
366 452
367 glEnable GL_BLEND; 453 glEnable GL_BLEND;
368 glEnable GL_TEXTURE_2D; 454 glEnable GL_TEXTURE_2D;
369 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 455 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
370 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 456 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
371 457
372 my $top = $self->{txts}->[1]; 458 my $top = $tex[1];
373 glBindTexture GL_TEXTURE_2D, $top->{name}; 459 $top->draw_quad (0, 0, $w, $top->{height});
374 460
375 glBegin GL_QUADS;
376 glTexCoord 0, 0; glVertex 0 , 0;
377 glTexCoord 0, 1; glVertex 0 , $top->{height};
378 glTexCoord 1, 1; glVertex $w , $top->{height};
379 glTexCoord 1, 0; glVertex $w , 0;
380 glEnd;
381
382 my $left = $self->{txts}->[3]; 461 my $left = $tex[3];
383 glBindTexture GL_TEXTURE_2D, $left->{name}; 462 $left->draw_quad (0, $top->{height}, $left->{width}, $ch);
384 463
385 glBegin GL_QUADS;
386 glTexCoord 0, 0; glVertex 0 , $top->{height};
387 glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch;
388 glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch;
389 glTexCoord 1, 0; glVertex $left->{width}, $top->{height};
390 glEnd;
391
392 my $right = $self->{txts}->[2]; 464 my $right = $tex[2];
393 glBindTexture GL_TEXTURE_2D, $right->{name}; 465 $right->draw_quad ($w - $right->{width}, $top->{height}, $right->{width}, $ch);
394 466
395 glBegin GL_QUADS;
396 glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height};
397 glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch;
398 glTexCoord 1, 1; glVertex $w , $top->{height} + $ch;
399 glTexCoord 1, 0; glVertex $w , $top->{height};
400 glEnd;
401
402 my $bottom = $self->{txts}->[4]; 467 my $bottom = $tex[4];
403 glBindTexture GL_TEXTURE_2D, $bottom->{name}; 468 $bottom->draw_quad (0, $h - $bottom->{height}, $w, $bottom->{height});
404 469
405 glBegin GL_QUADS; 470 my $bg = $tex[0];
406 glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height};
407 glTexCoord 0, 1; glVertex 0 , $h;
408 glTexCoord 1, 1; glVertex $w , $h;
409 glTexCoord 1, 0; glVertex $w , $h - $bottom->{height};
410 glEnd;
411
412 my $bg = $self->{txts}->[0];
413 glBindTexture GL_TEXTURE_2D, $bg->{name}; 471 glBindTexture GL_TEXTURE_2D, $bg->{name};
414 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 472 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
415 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; 473 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT;
416 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; 474 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT;
417 475
418 my $rep_x = $cw / $bg->{width}; 476 my $rep_x = $cw / $bg->{width};
419 my $rep_y = $ch / $bg->{height}; 477 my $rep_y = $ch / $bg->{height};
420 478
421 glBegin GL_QUADS; 479 $bg->draw_quad ($left->{width}, $top->{height}, $cw, $ch);
422 glTexCoord 0, 0; glVertex $left->{width}, $top->{height};
423 glTexCoord 0, $rep_y; glVertex $left->{width}, $top->{height} + $ch;
424 glTexCoord $rep_x, $rep_y; glVertex $left->{width} + $cw , $top->{height} + $ch;
425 glTexCoord $rep_x, 0; glVertex $left->{width} + $cw , $top->{height};
426 glEnd;
427 480
428 glDisable GL_BLEND; 481 glDisable GL_BLEND;
429 glDisable GL_TEXTURE_2D; 482 glDisable GL_TEXTURE_2D;
430 483
431 $self->get->draw; 484 $self->child->draw;
432 485
433} 486}
434 487
488#############################################################################
489
435package Crossfire::Client::Widget::Table; 490package CFClient::Widget::Table;
436 491
437our @ISA = Crossfire::Client::Widget::Bin::; 492our @ISA = CFClient::Widget::Bin::;
438 493
439use SDL::OpenGL; 494use SDL::OpenGL;
440 495
441sub add { 496sub add {
442 my ($self, $x, $y, $chld) = @_; 497 my ($self, $x, $y, $chld) = @_;
443 my $old_chld = $self->{childs}[$y][$x]; 498 my $old_chld = $self->{children}[$y][$x];
444 499
445 $self->{childs}[$y][$x] = $chld; 500 $self->{children}[$y][$x] = $chld;
446 $chld->set_parent ($self); 501 $chld->set_parent ($self);
447 $self->update; 502 $self->update;
448} 503}
449 504
450sub max_row_height { 505sub max_row_height {
451 my ($self, $row) = @_; 506 my ($self, $row) = @_;
452 507
453 my $hs = 0; 508 my $hs = 0;
454 for (my $xi = 0; $xi <= $#{$self->{childs}->[$row] || []}; $xi++) { 509 for (my $xi = 0; $xi <= $#{$self->{children}->[$row] || []}; $xi++) {
455 my $c = $self->{childs}->[$row]->[$xi]; 510 my $c = $self->{children}->[$row]->[$xi];
456 if ($c) { 511 if ($c) {
457 my ($w, $h) = $c->size_request; 512 my ($w, $h) = $c->size_request;
458 if ($hs < $h) { $hs = $h } 513 if ($hs < $h) { $hs = $h }
459 } 514 }
460 } 515 }
463 518
464sub max_col_width { 519sub max_col_width {
465 my ($self, $col) = @_; 520 my ($self, $col) = @_;
466 521
467 my $ws = 0; 522 my $ws = 0;
468 for (my $yi = 0; $yi <= $#{$self->{childs} || []}; $yi++) { 523 for (my $yi = 0; $yi <= $#{$self->{children} || []}; $yi++) {
469 my $c = ($self->{childs}->[$yi] || [])->[$col]; 524 my $c = ($self->{children}->[$yi] || [])->[$col];
470 if ($c) { 525 if ($c) {
471 my ($w, $h) = $c->size_request; 526 my ($w, $h) = $c->size_request;
472 if ($ws < $w) { $ws = $w } 527 if ($ws < $w) { $ws = $w }
473 } 528 }
474 } 529 }
478sub size_request { 533sub size_request {
479 my ($self) = @_; 534 my ($self) = @_;
480 535
481 my ($hs, $ws) = (0, 0); 536 my ($hs, $ws) = (0, 0);
482 537
483 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 538 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) {
484 $hs += $self->max_row_height ($yi); 539 $hs += $self->max_row_height ($yi);
485 } 540 }
486 541
487 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 542 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) {
488 my $wm = 0; 543 my $wm = 0;
489 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { 544 for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) {
490 $wm += $self->max_col_width ($xi) 545 $wm += $self->max_col_width ($xi)
491 } 546 }
492 if ($ws < $wm) { $ws = $wm } 547 if ($ws < $wm) { $ws = $wm }
493 } 548 }
494 549
497 552
498sub _draw { 553sub _draw {
499 my ($self) = @_; 554 my ($self) = @_;
500 555
501 my $y = 0; 556 my $y = 0;
502 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 557 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) {
503 my $x = 0; 558 my $x = 0;
504 559
505 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { 560 for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) {
506 561
507 my $c = $self->{childs}->[$yi]->[$xi]; 562 my $c = $self->{children}->[$yi]->[$xi];
508 if ($c) { 563 if ($c) {
509 $c->move ($x, $y, 0); #TODO: Move to size_request 564 $c->move ($x, $y, 0); #TODO: Move to size_request
510 $c->draw if $c; 565 $c->draw if $c;
511 } 566 }
512 567
515 570
516 $y += $self->max_row_height ($yi); 571 $y += $self->max_row_height ($yi);
517 } 572 }
518} 573}
519 574
575#############################################################################
576
520package Crossfire::Client::Widget::VBox; 577package CFClient::Widget::VBox;
521 578
522our @ISA = Crossfire::Client::Widget::Bin::; 579our @ISA = CFClient::Widget::Container::;
523 580
524use SDL::OpenGL; 581use SDL::OpenGL;
525 582
526sub add {
527 my ($self, $chld, $expand) = @_;
528 push @{$self->{childs}}, $chld;
529 $chld->{expand} = $expand;
530 $chld->set_parent ($self);
531 $self->update;
532}
533
534sub size_request { 583sub size_request {
535 my ($self) = @_; 584 my ($self) = @_;
536 585
537 my ($hs, $ws) = (0, 0); 586 my @alloc = map [$_->size_request], @{$self->{children}};
538 for (@{$self->{childs} || []}) { 587
539 my ($w, $h) = $_->size_request;
540 $hs += $h;
541 if ($ws < $w) { $ws = $w }
542 } 588 (
543 589 (List::Util::max map $_->[0], @alloc),
544 return ($ws, $hs); 590 (List::Util::sum map $_->[1], @alloc),
591 )
545} 592}
546 593
547sub size_allocate { 594sub size_allocate {
548 my ($self, $w, $h) = @_; 595 my ($self, $w, $h) = @_;
549 596
551 $self->h ($h); 598 $self->h ($h);
552 599
553 my $exp; 600 my $exp;
554 my @oth; 601 my @oth;
555 # find expand widget 602 # find expand widget
556 for (@{$self->{childs}}) { 603 for (@{$self->{children}}) {
557 if ($_->{expand}) { 604 if ($_->{expand}) {
558 $exp = $_; 605 $exp = $_;
559 last; 606 last;
560 } 607 }
561 push @oth, $_; 608 push @oth, $_;
569 $oh += $h; 616 $oh += $h;
570 if ($ow < $w) { $ow = $w } 617 if ($ow < $w) { $ow = $w }
571 } 618 }
572 619
573 my $y = 0; 620 my $y = 0;
574 for (@{$self->{childs}}) { 621 for (@{$self->{children}}) {
575 $_->move (0, $y); 622 $_->move (0, $y);
576 623
577 if ($_ == $exp) { 624 if ($_ == $exp) {
578 $_->size_allocate ($w, $h - $oh); 625 $_->size_allocate ($w, $h - $oh);
579 $y += $h - $oh; 626 $y += $h - $oh;
583 $y += $h; 630 $y += $h;
584 } 631 }
585 } 632 }
586} 633}
587 634
588sub _draw { 635#############################################################################
589 my ($self) = @_;
590 636
591 my ($x, $y);
592 for (@{$self->{childs} || []}) {
593 $_->draw;
594 $y += $_->h;
595 }
596}
597
598package Crossfire::Client::Widget::Label; 637package CFClient::Widget::Label;
599 638
600our @ISA = Crossfire::Client::Widget::; 639our @ISA = CFClient::Widget::;
601 640
602use SDL::OpenGL; 641use SDL::OpenGL;
603 642
604sub new { 643sub new {
605 my ($class, $x, $y, $z, $height, $text) = @_; 644 my ($class, %arg) = @_;
606 645
607 # TODO: color, and make height, xyz etc. optional 646 # TODO: color, and make height, xyz etc. optional
608 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); 647 my $self = $class->SUPER::new (
648 color => [1, 1, 1],
649 height => $::FONTSIZE,
650 text => "",
651 layout => new CFClient::Layout,
652 %arg
653 );
609 654
610 $self->set_text ($text); 655 $self->set_text ($self->{text});
611 656
612 $self 657 $self
613} 658}
614 659
615sub set_text { 660sub set_text {
616 my ($self, $text) = @_; 661 my ($self, $text) = @_;
617 662
618 $self->{text} = $text; 663 $self->{text} = $text;
619 $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; 664 $self->{layout}->set_markup ($text);
620 665
621 $self->update; 666 delete $self->{texture};
622} 667}
623 668
624sub get_text { 669sub get_text {
625 my ($self, $text) = @_; 670 my ($self, $text) = @_;
626 671
628} 673}
629 674
630sub size_request { 675sub size_request {
631 my ($self) = @_; 676 my ($self) = @_;
632 677
633 ( 678 $self->{layout}->set_width;
679 $self->{layout}->set_height ($self->{height});
680 $self->{layout}->size
681# if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack
682# (
634 $self->{texture}{width}, 683# $self->{texture}{width},
635 $self->{texture}{height}, 684# $self->{texture}{height},
636 ) 685# )
686# } else {
687# my ($w, $h, $data) = CFClient::font_render "Yy", $self->{height};
688#
689# ($w, $h)
690# }
691}
692
693sub size_allocate {
694 my ($self, $w, $h) = @_;
695
696 $self->SUPER::size_allocate ($w, $h);
697 delete $self->{texture};
637} 698}
638 699
639sub _draw { 700sub _draw {
640 my ($self) = @_; 701 my ($self) = @_;
641 702
642 my $tex = $self->{texture}; 703 my $tex = $self->{texture} ||= do {
704 $self->{layout}->set_width ($self->{w});
705 new_from_layout CFClient::Texture $self->{layout};
706 };
643 707
644 glEnable GL_BLEND; 708 glEnable GL_BLEND;
645 glEnable GL_TEXTURE_2D; 709 glEnable GL_TEXTURE_2D;
646 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 710 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
647 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 711 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
648 glBindTexture GL_TEXTURE_2D, $tex->{name};
649 712
650 glColor 1, 0, 0, 1; # TODO color 713 glColor @{$self->{color}};
651 714
652 glBegin GL_QUADS; 715 $tex->draw_quad (0, 0);
653 glTexCoord 0, 0; glVertex 0 , 0;
654 glTexCoord 0, 1; glVertex 0 , $tex->{height};
655 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
656 glTexCoord 1, 0; glVertex $tex->{width}, 0;
657 glEnd;
658 716
659 glDisable GL_BLEND; 717 glDisable GL_BLEND;
660 glDisable GL_TEXTURE_2D; 718 glDisable GL_TEXTURE_2D;
661} 719}
662 720
721#############################################################################
722
663package Crossfire::Client::Widget::TextEntry; 723package CFClient::Widget::Entry;
664 724
665our @ISA = Crossfire::Client::Widget::Label::; 725our @ISA = CFClient::Widget::Label::;
666 726
667use SDL; 727use SDL;
668use SDL::OpenGL; 728use SDL::OpenGL;
669 729
670sub key_down { 730sub key_down {
671 my ($self, $ev) = @_; 731 my ($self, $ev) = @_;
672 732
673 my $mod = $ev->key_mod; 733 my $mod = $ev->key_mod;
674 my $sym = $ev->key_sym; 734 my $sym = $ev->key_sym;
675 735
676 $ev->set_unicode (1);
677 my $uni = $ev->key_unicode; 736 my $uni = $ev->key_unicode;
678 737
679 my $text = $self->get_text; 738 my $text = $self->get_text;
680 739
681 if ($sym == SDLK_BACKSPACE) { 740 if ($sym == SDLK_BACKSPACE) {
682 substr $text, -1, 1, ''; 741 substr $text, -1, 1, '';
683
684 } elsif ($uni) { 742 } elsif ($uni) {
685 $text .= chr $uni; 743 $text .= chr $uni;
686 } 744 }
745
687 $self->set_text ($text); 746 $self->set_text ($text);
688} 747}
689 748
749sub button_down {
750 my ($self, $ev) = @_;
751
752 $self->focus_in;
753}
754
755sub mouse_motion {
756 my ($self, $ev, $x, $y) = @_;
757 printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d#
758}
759
760sub _draw {
761 my ($self) = @_;
762
763 if ($FOCUS == $self) {
764 glColor 1, 1, 1;
765 } else {
766 glColor 0.7, 0.7, 0.7;
767 }
768
769 glBegin GL_QUADS;
770 glVertex 0 , 0;
771 glVertex 0 , $self->{h} - 1;
772 glVertex $self->{w} - 1, $self->{h} - 1;
773 glVertex $self->{w} - 1, 0;
774 glEnd;
775
776 $self->SUPER::_draw;
777}
778
779#############################################################################
780
690package Crossfire::Client::Widget::MapWidget; 781package CFClient::Widget::MapWidget;
691 782
692use strict; 783use strict;
693 784
694use List::Util qw(min max); 785use List::Util qw(min max);
695 786
696use SDL; 787use SDL;
697use SDL::OpenGL; 788use SDL::OpenGL;
698use SDL::OpenGL::Constants; 789use SDL::OpenGL::Constants;
699 790
700our @ISA = Crossfire::Client::Widget::; 791our @ISA = CFClient::Widget::;
792
793sub new {
794 my $class = shift;
795
796 $class->SUPER::new (
797 z => -1,
798 list => (glGenLists 1),
799 @_
800 )
801}
701 802
702sub key_down { 803sub key_down {
703 print "MAPKEYDOWN\n"; 804 print "MAPKEYDOWN\n";
704} 805}
705 806
706sub key_up { 807sub key_up {
707} 808}
708 809
709sub size_request { 810sub size_request {
710 811 (
812 1 + int $::WIDTH / 32,
813 1 + int $::HEIGHT / 32,
814 )
711} 815}
712 816
713sub size_allocate { 817sub update {
818 my ($self) = @_;
819
820 $self->{need_update} = 1;
714} 821}
715 822
716sub _draw { 823sub _draw {
717 my ($self) = @_; 824 my ($self) = @_;
718 825
826 if (delete $self->{need_update}) {
827 glNewList $self->{list}, GL_COMPILE;
828
719 my $mx = $::CONN->{mapx}; 829 my $mx = $::CONN->{mapx};
720 my $my = $::CONN->{mapy}; 830 my $my = $::CONN->{mapy};
721 831
722 my $map = $::CONN->{map}; 832 my $map = $::CONN->{map};
723 833
724 my ($xofs, $yofs); 834 my ($xofs, $yofs);
725 835
726 my $sw = 1 + int $::WIDTH / 32; 836 my $sw = 1 + int $::WIDTH / 32;
727 my $sh = 1 + int $::HEIGHT / 32; 837 my $sh = 1 + int $::HEIGHT / 32;
728 838
729 if ($::CONN->{mapw} > $sw) { 839 if ($::CONN->{mapw} > $sw) {
730 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; 840 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5;
731 } else { 841 } else {
732 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; 842 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs};
733 } 843 }
734 844
735 if ($::CONN->{maph} > $sh) { 845 if ($::CONN->{maph} > $sh) {
736 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; 846 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5;
737 } else { 847 } else {
738 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; 848 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs};
739 } 849 }
740 850
741 glEnable GL_TEXTURE_2D; 851 glEnable GL_TEXTURE_2D;
742 glEnable GL_BLEND; 852 glEnable GL_BLEND;
743 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 853 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
744 854
745 my $sw4 = ($sw + 3) & ~3; 855 my $sw4 = ($sw + 3) & ~3;
746 my $lighting = "\x00" x ($sw4 * $sh); 856 my $darkness = "\x00" x ($sw4 * $sh);
747 857
748 for my $x (0 .. $sw - 1) { 858 for my $x (0 .. $sw - 1) {
859 my $row = $map->[$x + $xofs];
749 for my $y (0 .. $sh - 1) { 860 for my $y (0 .. $sh - 1) {
750 861
751 my $cell = $map->[$x + $xofs][$y + $yofs] 862 my $cell = $row->[$y + $yofs]
752 or next; 863 or next;
753 864
754 my $darkness = $cell->[0] * (1 / 255); 865 my $dark = $cell->[0];
755 if ($darkness < 0) { 866 if ($dark < 0) {
756 $darkness = 0.15; 867 substr $darkness, $y * $sw4 + $x, 1, chr 224;
868 } else {
869 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark;
757 } 870 }
758 substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255;
759 871
760 for my $num (grep $_, @$cell[1,2,3]) { 872 for my $num (grep $_, @$cell[1,2,3]) {
761 my $tex = $::CONN->{face}[$num]{texture} || next; 873 my $tex = $::CONN->{face}[$num]{texture} || next;
762 874
763 glBindTexture GL_TEXTURE_2D, $tex->{name};
764
765 my $w = $tex->{width}; 875 my $w = $tex->{width};
766 my $h = $tex->{height}; 876 my $h = $tex->{height};
767 877
768 my $px = ($x + 1) * 32 - $w; 878 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h);
769 my $py = ($y + 1) * 32 - $h;
770
771 glBegin GL_QUADS;
772 glTexCoord 0, 0; glVertex $px , $py;
773 glTexCoord 0, 1; glVertex $px , $py + $h;
774 glTexCoord 1, 1; glVertex $px + $w, $py + $h;
775 glTexCoord 1, 0; glVertex $px + $w, $py;
776 glEnd; 879 }
777 } 880 }
778 } 881 }
779 }
780 882
781# if (1) { # higher quality darkness 883# if (1) { # higher quality darkness
782# $lighting =~ s/(.)/$1$1$1/gs; 884# $lighting =~ s/(.)/$1$1$1/gs;
783# my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; 885# my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3;
784# 886#
786# 888#
787# $lighting = $pb->get_pixels; 889# $lighting = $pb->get_pixels;
788# $lighting =~ s/(.)../$1/gs; 890# $lighting =~ s/(.)../$1/gs;
789# } 891# }
790 892
791 $lighting = new Crossfire::Client::Texture
792 width => $sw4,
793 height => $sh,
794 data => $lighting,
795 internalformat => GL_ALPHA4,
796 format => GL_ALPHA;
797
798 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 893 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
799 glColor 0, 0, 0, 0.75;
800 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 894 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
801 glBindTexture GL_TEXTURE_2D, $lighting->{name};
802 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
803 glBegin GL_QUADS;
804 glTexCoord 0, 0; glVertex 0 , 0;
805 glTexCoord 0, 1; glVertex 0 , $sh * 32;
806 glTexCoord 1, 1; glVertex $sw4 * 32, $sh * 32;
807 glTexCoord 1, 0; glVertex $sw4 * 32, 0;
808 glEnd;
809 895
896 $darkness = new CFClient::Texture
897 width => $sw4,
898 height => $sh,
899 data => $darkness,
900 internalformat => GL_ALPHA,
901 format => GL_ALPHA;
902
903 glColor 0.45, 0.45, 0.45, 1;
904 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32);
905
810 glDisable GL_TEXTURE_2D; 906 glDisable GL_TEXTURE_2D;
811 glDisable GL_BLEND; 907 glDisable GL_BLEND;
908
909 glEndList;
910 }
911
912 glCallList $self->{list};
812} 913}
813 914
814my %DIR = ( 915my %DIR = (
815 SDLK_KP8, [1, "north"], 916 SDLK_KP8, [1, "north"],
816 SDLK_KP9, [2, "northeast"], 917 SDLK_KP9, [2, "northeast"],
860 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { 961 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
861 $::CONN->send ("command run_stop"); 962 $::CONN->send ("command run_stop");
862 } 963 }
863} 964}
864 965
966#############################################################################
967
865package Crossfire::Client::Widget::Animator; 968package CFClient::Widget::Animator;
866 969
867use SDL::OpenGL; 970use SDL::OpenGL;
868 971
869our @ISA = Crossfire::Client::Widget::Bin::; 972our @ISA = CFClient::Widget::Bin::;
870 973
871sub moveto { 974sub moveto {
872 my ($self, $x, $y) = @_; 975 my ($self, $x, $y) = @_;
873 976
874 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 977 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
875 $self->{speed} = 0.2; 978 $self->{speed} = 0.001;
876 $self->{time} = 1; 979 $self->{time} = 1;
877 980
878 ::animation_start $self; 981 ::animation_start $self;
879} 982}
880 983
895 998
896sub _draw { 999sub _draw {
897 my ($self) = @_; 1000 my ($self) = @_;
898 1001
899 glPushMatrix; 1002 glPushMatrix;
900 glRotate $self->{time} * 10000, 0, 1, 0; 1003 glRotate $self->{time} * 1000, 0, 1, 0;
901 $self->{child}->draw; 1004 $self->{children}[0]->draw;
902 glPopMatrix; 1005 glPopMatrix;
903} 1006}
904 1007
9051; 1008#############################################################################
906 1009
1010package CFClient::Widget::Toplevel;
1011
1012our @ISA = CFClient::Widget::Container::;
1013
1014sub size_request {
1015 ($::WIDTH, $::HEIGHT)
1016}
1017
1018sub size_allocate {
1019 my ($self, $w, $h) = @_;
1020
1021 $self->SUPER::size_allocate ($w, $h);
1022
1023 $_->size_allocate ($_->size_request)
1024 for @{$self->{children}};
1025}
1026
1027sub translate {
1028 my ($self, $x, $y) = @_;
1029
1030 ($x, $y)
1031}
1032
1033sub update {
1034 my ($self) = @_;
1035
1036 $self->size_allocate ($self->size_request);
1037 ::refresh ();
1038}
1039
1040sub add {
1041 my ($self, $widget) = @_;
1042
1043 $self->SUPER::add ($widget);
1044
1045 $widget->size_allocate ($widget->size_request);
1046}
1047
1048sub draw {
1049 my ($self) = @_;
1050
1051 $self->_draw;
1052}
1053
1054#############################################################################
1055
1056package CFClient::Widget;
1057
1058$TOPLEVEL = new CFClient::Widget::Toplevel;
1059
10601
1061

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines