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.70 by root, Tue Apr 11 17:33:43 2006 UTC vs.
Revision 1.76 by root, Tue Apr 11 21:24:09 2006 UTC

1package CFClient::Widget; 1package CFClient::UI;
2 2
3use strict; 3use strict;
4 4
5use Scalar::Util; 5use Scalar::Util ();
6 6use List::Util ();
7use SDL::OpenGL;
8use SDL::OpenGL::Constants;
9 7
10use CFClient; 8use CFClient;
11 9
12our ($FOCUS, $HOVER, $GRAB); # various widgets 10our ($FOCUS, $HOVER, $GRAB); # various widgets
13 11
70 } 68 }
71 69
72 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; 70 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER;
73} 71}
74 72
73#############################################################################
74
75package CFClient::UI::Base;
76
77use strict;
78
79use SDL::OpenGL;
80
75sub new { 81sub new {
76 my $class = shift; 82 my $class = shift;
77 83
78 bless { 84 bless {
79 x => 0, 85 x => 0,
80 y => 0, 86 y => 0,
81 z => 0, 87 z => 0,
88 w => -1,
89 h => -1,
82 @_ 90 @_
83 }, $class 91 }, $class
84} 92}
85 93
86sub move { 94sub move {
97sub size_request { 105sub size_request {
98 require Carp; 106 require Carp;
99 Carp::confess "size_request is abtract"; 107 Carp::confess "size_request is abtract";
100} 108}
101 109
102sub size_allocate { 110sub _size_allocate {
103 my ($self, $w, $h) = @_; 111 my ($self, $x, $y, $w, $h) = @_;
112
113 $self->{x} = $x;
114 $self->{y} = $y;
115
116 return unless $self->{w} != $w || $self->{h} != $h;
104 117
105 $self->{w} = $w; 118 $self->{w} = $w;
106 $self->{h} = $h; 119 $self->{h} = $h;
120
121 1
122}
123
124sub size_allocate {
125 my ($self, $x, $y, $w, $h) = @_;
126
127 $self->_size_allocate ($x, $y, $w, $h);
107} 128}
108 129
109# translate global koordinates to local coordinate system 130# translate global koordinates to local coordinate system
110sub translate { 131sub translate {
111 my ($self, $x, $y) = @_; 132 my ($self, $x, $y) = @_;
155 return unless $self->{h} && $self->{w}; 176 return unless $self->{h} && $self->{w};
156 177
157 glPushMatrix; 178 glPushMatrix;
158 glTranslate $self->{x}, $self->{y}, 0; 179 glTranslate $self->{x}, $self->{y}, 0;
159 $self->_draw; 180 $self->_draw;
181 glPopMatrix;
182
160 if ($self == $HOVER) { 183 if ($self == $HOVER) {
161 glColor 1, 1, 1, 0.4; 184 my ($x, $y) = @$self{qw(x y)};
185
186 glColor 0, 0, 1, 0.2;
162 glEnable GL_BLEND; 187 glEnable GL_BLEND;
188 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
163 glBegin GL_QUADS; 189 glBegin GL_QUADS;
164 glVertex 0 , 0; 190 glVertex $x , $y;
165 glVertex $self->{w}, 0; 191 glVertex $x + $self->{w}, $y;
166 glVertex $self->{w}, $self->{h}; 192 glVertex $x + $self->{w}, $y + $self->{h};
167 glVertex 0 , $self->{h}; 193 glVertex $x , $y + $self->{h};
168 glEnd; 194 glEnd;
169 glDisable GL_BLEND; 195 glDisable GL_BLEND;
170 } 196 }
171 glPopMatrix;
172} 197}
173 198
174sub _draw { 199sub _draw {
175 my ($self) = @_; 200 my ($self) = @_;
176 201
216 241
217 $self->{parent}->update 242 $self->{parent}->update
218 if $self->{parent}; 243 if $self->{parent};
219} 244}
220 245
246sub connect {
247 my ($self, $signal, $cb) = @_;
248
249 push @{ $self->{cb}{$signal} }, $cb;
250}
251
252sub emit {
253 my ($self, $signal, @args) = @_;
254
255 $_->($self, @args)
256 for @{$self->{cb}{$signal} || []};
257}
258
221sub DESTROY { 259sub DESTROY {
222 my ($self) = @_; 260 my ($self) = @_;
223 261
224 #$self->deactivate; 262 #$self->deactivate;
225} 263}
226 264
227############################################################################# 265#############################################################################
228 266
229package CFClient::Widget::DrawBG; 267package CFClient::UI::DrawBG;
230 268
231our @ISA = CFClient::Widget::; 269our @ISA = CFClient::UI::Base::;
232 270
233use strict; 271use strict;
234use SDL::OpenGL; 272use SDL::OpenGL;
235 273
236sub new { 274sub new {
237 my $class = shift; 275 my $class = shift;
238 276
239 # range [value, low, high, page] 277 # range [value, low, high, page]
240 278
241 $class->SUPER::new ( 279 $class->SUPER::new (
242 bg => [0, 0, 0, 0.4], 280 bg => [0, 0, 0, 0.2],
243 active_bg => [1, 1, 1], 281 active_bg => [1, 1, 1],
244 @_ 282 @_
245 ) 283 )
246} 284}
247 285
248sub _draw { 286sub _draw {
249 my ($self) = @_; 287 my ($self) = @_;
250 288
251 my ($w, $h) = @$self{qw(w h)}; 289 my ($w, $h) = @$self{qw(w h)};
252 290
291 glEnable GL_BLEND;
292 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
253 glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} }; 293 glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} };
294
254 glBegin GL_QUADS; 295 glBegin GL_QUADS;
255 glVertex 0 , 0; 296 glVertex 0 , 0;
256 glVertex 0 , $h; 297 glVertex 0 , $h;
257 glVertex $w, $h; 298 glVertex $w, $h;
258 glVertex $w, 0; 299 glVertex $w, 0;
259 glEnd; 300 glEnd;
260}
261 301
262############################################################################# 302 glDisable GL_BLEND;
303}
263 304
305#############################################################################
306
264package CFClient::Widget::Empty; 307package CFClient::UI::Empty;
265 308
266our @ISA = CFClient::Widget::; 309our @ISA = CFClient::UI::Base::;
267 310
268sub size_request { 311sub size_request {
269 (0, 0) 312 (0, 0)
270} 313}
271 314
272sub draw { } 315sub draw { }
273 316
274############################################################################# 317#############################################################################
275 318
276package CFClient::Widget::Container; 319package CFClient::UI::Container;
277 320
278our @ISA = CFClient::Widget::; 321our @ISA = CFClient::UI::Base::;
279 322
280sub new { 323sub new {
281 my ($class, %arg) = @_; 324 my ($class, %arg) = @_;
282 325
283 my $children = delete $arg{children} || []; 326 my $children = delete $arg{children} || [];
297 $self->{children} = [ 340 $self->{children} = [
298 sort { $a->{z} <=> $b->{z} } 341 sort { $a->{z} <=> $b->{z} }
299 @{$self->{children}}, $chld 342 @{$self->{children}}, $chld
300 ]; 343 ];
301 344
302 $self->size_allocate ($self->{w}, $self->{h}) 345 $self->{w} = $self->{h} = -1;
303 if $self->{w}; #TODO: check for "realised state" 346 $self->update;
304} 347}
305 348
306sub remove { 349sub remove {
307 my ($self, $widget) = @_; 350 my ($self, $widget) = @_;
308 351
309 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 352 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ];
310 353
311 $self->size_allocate ($self->{w}, $self->{h}); 354 $self->size_allocate (0, 0, $self->{w}, $self->{h});
312} 355}
313 356
314sub find_widget { 357sub find_widget {
315 my ($self, $x, $y) = @_; 358 my ($self, $x, $y) = @_;
316 359
333 $_->draw for @{$self->{children}}; 376 $_->draw for @{$self->{children}};
334} 377}
335 378
336############################################################################# 379#############################################################################
337 380
338package CFClient::Widget::Bin; 381package CFClient::UI::Bin;
339 382
340our @ISA = CFClient::Widget::Container::; 383our @ISA = CFClient::UI::Container::;
341 384
342sub new { 385sub new {
343 my ($class, %arg) = @_; 386 my ($class, %arg) = @_;
344 387
345 my $child = (delete $arg{child}) || new CFClient::Widget::Empty::; 388 my $child = (delete $arg{child}) || new CFClient::UI::Empty::;
346 389
347 $class->SUPER::new (children => [$child], %arg) 390 $class->SUPER::new (children => [$child], %arg)
348} 391}
349 392
350sub add { 393sub add {
358sub remove { 401sub remove {
359 my ($self, $widget) = @_; 402 my ($self, $widget) = @_;
360 403
361 $self->SUPER::remove ($widget); 404 $self->SUPER::remove ($widget);
362 405
363 $self->{children} = [new CFClient::Widget::Empty] 406 $self->{children} = [new CFClient::UI::Empty]
364 unless @{$self->{children}}; 407 unless @{$self->{children}};
365} 408}
366 409
367sub child { $_[0]->{children}[0] } 410sub child { $_[0]->{children}[0] }
368 411
369sub size_request { 412sub size_request {
370 $_[0]{children}[0]->size_request 413 $_[0]{children}[0]->size_request
371} 414}
372 415
373sub size_allocate { 416sub size_allocate {
374 my ($self, $w, $h) = @_; 417 my ($self, $x, $y, $w, $h) = @_;
375 418
376 return unless $self->{w} != $w || $self->{h} != $h; 419 $self->_size_allocate ($x, $y, $w, $h) or return;
377 420
378 $self->SUPER::size_allocate ($w, $h);
379 $self->{children}[0]->size_allocate ($w, $h); 421 $self->{children}[0]->size_allocate (0, 0, $w, $h);
380} 422}
381 423
382############################################################################# 424#############################################################################
383 425
384package CFClient::Widget::Window; 426package CFClient::UI::Window;
385 427
386our @ISA = CFClient::Widget::Bin::; 428our @ISA = CFClient::UI::Bin::;
387 429
388use SDL::OpenGL; 430use SDL::OpenGL;
389 431
390sub new { 432sub new {
391 my ($class, %arg) = @_; 433 my ($class, %arg) = @_;
409 $self->{w}, $self->{h}, sub { $self->child->draw } 451 $self->{w}, $self->{h}, sub { $self->child->draw }
410 ); 452 );
411} 453}
412 454
413sub size_allocate { 455sub size_allocate {
414 my ($self, $w, $h) = @_; 456 my ($self, $x, $y, $w, $h) = @_;
415 457
416 return unless $self->{w} != $w || $self->{h} != $h; 458 $self->_size_allocate ($x, $y, $w, $h) or return;
417 459
418 $self->{w} = $w;
419 $self->{h} = $h;
420
421 $self->child->size_allocate ($w, $h); 460 $self->child->size_allocate (0, 0, $w, $h);
422 461
423 $self->render_chld; 462 $self->render_chld;
424} 463}
425 464
426sub _draw { 465sub _draw {
430 469
431 my $tex = $self->{texture} 470 my $tex = $self->{texture}
432 or return; 471 or return;
433 472
434 glEnable GL_BLEND; 473 glEnable GL_BLEND;
474 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
435 glEnable GL_TEXTURE_2D; 475 glEnable GL_TEXTURE_2D;
436 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 476 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
437 477
438 $tex->draw_quad (0, 0, $w, $h); 478 $tex->draw_quad (0, 0, $w, $h);
439 479
441 glDisable GL_TEXTURE_2D; 481 glDisable GL_TEXTURE_2D;
442} 482}
443 483
444############################################################################# 484#############################################################################
445 485
446package CFClient::Widget::Frame; 486package CFClient::UI::Frame;
447 487
448our @ISA = CFClient::Widget::Bin::; 488our @ISA = CFClient::UI::Bin::;
449 489
450use SDL::OpenGL; 490use SDL::OpenGL;
451 491
452sub size_request { 492sub size_request {
453 my ($self) = @_; 493 my ($self) = @_;
458 498
459 map { $_ + 4 } $chld->size_request; 499 map { $_ + 4 } $chld->size_request;
460} 500}
461 501
462sub size_allocate { 502sub size_allocate {
463 my ($self, $w, $h) = @_; 503 my ($self, $x, $y, $w, $h) = @_;
464 504
465 return unless $self->{w} != $w || $self->{h} != $h; 505 $self->_size_allocate ($x, $y, $w, $h) or return;
466 506
467 $self->{w} = $w;
468 $self->{h} = $h;
469
470 $self->child->size_allocate ($w - 4, $h - 4); 507 $self->child->size_allocate (2, 2, $w - 4, $h - 4);
471 $self->child->move (2, 2);
472} 508}
473 509
474sub _draw { 510sub _draw {
475 my ($self) = @_; 511 my ($self) = @_;
476 512
489 $chld->draw; 525 $chld->draw;
490} 526}
491 527
492############################################################################# 528#############################################################################
493 529
494package CFClient::Widget::FancyFrame; 530package CFClient::UI::FancyFrame;
495 531
496our @ISA = CFClient::Widget::Bin::; 532our @ISA = CFClient::UI::Bin::;
497 533
498use SDL::OpenGL; 534use SDL::OpenGL;
499 535
500my @tex = 536my @tex =
501 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 537 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
504sub size_request { 540sub size_request {
505 my ($self) = @_; 541 my ($self) = @_;
506 542
507 my ($w, $h) = $self->SUPER::size_request; 543 my ($w, $h) = $self->SUPER::size_request;
508 544
509 $h += $tex[1]->{height}; 545 $h += $tex[1]->{h};
510 $h += $tex[4]->{height}; 546 $h += $tex[4]->{h};
511 $w += $tex[2]->{width}; 547 $w += $tex[2]->{w};
512 $w += $tex[3]->{width}; 548 $w += $tex[3]->{w};
513 549
514 ($w, $h) 550 ($w, $h)
515} 551}
516 552
517sub size_allocate { 553sub size_allocate {
518 my ($self, $w, $h) = @_; 554 my ($self, $x, $y, $w, $h) = @_;
519 555
520 return unless $self->{w} != $w || $self->{h} != $h; 556 $self->_size_allocate ($x, $y, $w, $h) or return;
521 557
522 $self->SUPER::size_allocate ($w, $h);
523
524 $h -= $tex[1]->{height}; 558 $h -= $tex[1]->{h};
525 $h -= $tex[4]->{height}; 559 $h -= $tex[4]->{h};
526 $w -= $tex[2]->{width}; 560 $w -= $tex[2]->{w};
527 $w -= $tex[3]->{width}; 561 $w -= $tex[3]->{w};
528 562
529 $h = $h < 0 ? 0 : $h; 563 $h = $h < 0 ? 0 : $h;
530 $w = $w < 0 ? 0 : $w; 564 $w = $w < 0 ? 0 : $w;
531 565
532 my $child = $self->child; 566 my $child = $self->child;
533 567
534 $child->size_allocate ($w, $h); 568 $child->size_allocate ($tex[3]->{w}, $tex[1]->{h}, $w, $h);
535 $child->move ($tex[3]->{width}, $tex[1]->{height});
536} 569}
537 570
538sub _draw { 571sub _draw {
539 my ($self) = @_; 572 my ($self) = @_;
540 573
541 my ($w, $h) = ($self->{w}, $self->{h}); 574 my ($w, $h) = ($self->{w}, $self->{h});
542 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 575 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
543 576
544 glEnable GL_BLEND; 577 glEnable GL_BLEND;
578 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
545 glEnable GL_TEXTURE_2D; 579 glEnable GL_TEXTURE_2D;
546 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
547 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 580 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
548 581
549 my $top = $tex[1]; 582 my $top = $tex[1];
550 $top->draw_quad (0, 0, $w, $top->{height}); 583 $top->draw_quad (0, 0, $w, $top->{h});
551 584
552 my $left = $tex[3]; 585 my $left = $tex[3];
553 $left->draw_quad (0, $top->{height}, $left->{width}, $ch); 586 $left->draw_quad (0, $top->{h}, $left->{w}, $ch);
554 587
555 my $right = $tex[2]; 588 my $right = $tex[2];
556 $right->draw_quad ($w - $right->{width}, $top->{height}, $right->{width}, $ch); 589 $right->draw_quad ($w - $right->{w}, $top->{h}, $right->{w}, $ch);
557 590
558 my $bottom = $tex[4]; 591 my $bottom = $tex[4];
559 $bottom->draw_quad (0, $h - $bottom->{height}, $w, $bottom->{height}); 592 $bottom->draw_quad (0, $h - $bottom->{h}, $w, $bottom->{h});
560 593
561 my $bg = $tex[0]; 594 my $bg = $tex[0];
595
562 glBindTexture GL_TEXTURE_2D, $bg->{name}; 596 glBindTexture GL_TEXTURE_2D, $bg->{name};
563 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 597 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
564 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; 598 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT;
565 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; 599 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT;
566 600
567 my $rep_x = $cw / $bg->{width}; 601 my $rep_x = $cw / $bg->{w};
568 my $rep_y = $ch / $bg->{height}; 602 my $rep_y = $ch / $bg->{h};
569 603
570 $bg->draw_quad ($left->{width}, $top->{height}, $cw, $ch); 604 $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch);
571 605
606 glDisable GL_TEXTURE_2D;
572 glDisable GL_BLEND; 607 glDisable GL_BLEND;
573 glDisable GL_TEXTURE_2D;
574 608
575 $self->child->draw; 609 $self->child->draw;
576 610
577} 611}
578 612
579############################################################################# 613#############################################################################
580 614
581package CFClient::Widget::Table; 615package CFClient::UI::Table;
582 616
583our @ISA = CFClient::Widget::Bin::; 617our @ISA = CFClient::UI::Base::;
618
619use List::Util qw(max sum);
584 620
585use SDL::OpenGL; 621use SDL::OpenGL;
586 622
587sub add { 623sub add {
588 my ($self, $x, $y, $chld) = @_; 624 my ($self, $x, $y, $chld) = @_;
589 my $old_chld = $self->{children}[$y][$x];
590 625
591 $self->{children}[$y][$x] = $chld; 626 $self->{children}[$y][$x] = $chld;
592 $chld->set_parent ($self); 627 $chld->set_parent ($self);
628
629 $self->{w} = $self->{h} = -1;
593 $self->update; 630 $self->update;
594} 631}
595 632
596sub max_row_height { 633sub get_wh {
597 my ($self, $row) = @_; 634 my ($self) = @_;
598 635
599 my $hs = 0; 636 my (@w, @h);
600 for (my $xi = 0; $xi <= $#{$self->{children}->[$row] || []}; $xi++) { 637
638 for my $y (0 .. $#{$self->{children}}) {
601 my $c = $self->{children}->[$row]->[$xi]; 639 my $row = $self->{children}[$y]
602 if ($c) { 640 or next;
641
642 for my $x (0 .. $#$row) {
643 my $widget = $row->[$x]
644 or next;
603 my ($w, $h) = $c->size_request; 645 my ($w, $h) = $widget->size_request;
604 if ($hs < $h) { $hs = $h } 646
647 $w[$x] = max $w[$x], $w;
648 $h[$y] = max $h[$y], $h;
605 } 649 }
606 } 650 }
607 return $hs;
608}
609 651
610sub max_col_width { 652 (\@w, \@h)
653}
654
655sub size_request {
611 my ($self, $col) = @_; 656 my ($self) = @_;
612 657
658 my ($ws, $hs) = $self->get_wh;
659
660 (
661 (List::Util::sum @$ws),
662 (List::Util::sum @$hs),
663 )
664}
665
666sub size_allocate {
667 my ($self, $x, $y, $w, $h) = @_;
668
669 $self->_size_allocate ($x, $y, $w, $h) or return;
670
671 my ($ws, $hs) = $self->get_wh;
672
673 my $req_w = List::Util::sum @$ws;
674 my $req_h = List::Util::sum @$hs;
675
676 # linearly scale sizes
677 $_ *= $req_w / $w for @$ws;
678 $_ *= $req_h / $h for @$hs;
679
680 my $y;
681
682 for my $r (0 .. $#{$self->{children}}) {
683 my $row = $self->{children}[$r]
684 or next;
685
613 my $ws = 0; 686 my $x = 0;
614 for (my $yi = 0; $yi <= $#{$self->{children} || []}; $yi++) { 687 my $row_h = $hs->[$r];
615 my $c = ($self->{children}->[$yi] || [])->[$col]; 688
616 if ($c) { 689 for my $c (0 .. $#$row) {
617 my ($w, $h) = $c->size_request; 690 my $widget = $row->[$c]
618 if ($ws < $w) { $ws = $w } 691 or next;
692
693 my $col_w = $ws->[$c];
694
695 $widget->size_allocate ($x, $y, $col_w, $row_h);
696
697 $x += $col_w;
619 } 698 }
699
700 $y += $row_h;
620 } 701 }
621 return $ws; 702
622} 703}
704
705sub find_widget {
706 my ($self, $x, $y) = @_;
707
708 $x -= $self->{x};
709 $y -= $self->{y};
710
711 my $res;
712
713 for (grep $_, map @$_, grep $_, @{ $self->{children} }) {
714 $res = $_->find_widget ($x, $y)
715 and return $res;
716 }
717
718 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y})
719}
720
721sub _draw {
722 my ($self) = @_;
723
724 for (grep $_, @{$self->{children}}) {
725 $_->draw for grep $_, @$_;
726 }
727}
728
729#############################################################################
730
731package CFClient::UI::HBox;
732
733# TODO: wrap into common Box base class
734
735our @ISA = CFClient::UI::Container::;
623 736
624sub size_request { 737sub size_request {
625 my ($self) = @_; 738 my ($self) = @_;
626 739
627 my ($hs, $ws) = (0, 0);
628
629 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) {
630 $hs += $self->max_row_height ($yi);
631 }
632
633 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) {
634 my $wm = 0;
635 for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) {
636 $wm += $self->max_col_width ($xi)
637 }
638 if ($ws < $wm) { $ws = $wm }
639 }
640
641 return ($ws, $hs);
642}
643
644sub _draw {
645 my ($self) = @_;
646
647 my $y = 0;
648 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) {
649 my $x = 0;
650
651 for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) {
652
653 my $c = $self->{children}->[$yi]->[$xi];
654 if ($c) {
655 $c->move ($x, $y, 0); #TODO: Move to size_request
656 $c->draw if $c;
657 }
658
659 $x += $self->max_col_width ($xi);
660 }
661
662 $y += $self->max_row_height ($yi);
663 }
664}
665
666#############################################################################
667
668package CFClient::Widget::VBox;
669
670our @ISA = CFClient::Widget::Container::;
671
672use SDL::OpenGL;
673
674sub size_request {
675 my ($self) = @_;
676
677 my @alloc = map [$_->size_request], @{$self->{children}}; 740 my @alloc = map [$_->size_request], @{$self->{children}};
678 741
679 ( 742 (
680 (List::Util::max map $_->[0], @alloc),
681 (List::Util::sum map $_->[1], @alloc), 743 (List::Util::sum map $_->[0], @alloc),
744 (List::Util::max map $_->[1], @alloc),
682 ) 745 )
683} 746}
684 747
685sub size_allocate { 748sub size_allocate {
686 my ($self, $w, $h) = @_; 749 my ($self, $x, $y, $w, $h) = @_;
687 750
688 return unless $self->{w} != $w || $self->{h} != $h; 751 $self->_size_allocate ($x, $y, $w, $h) or return;
689 752
690 $self->{w} = $w;
691 $self->{h} = $h;
692
693 return unless $self->{h}; 753 return unless $self->{w};
754
755 ($h, $w) = ($w, $h);
694 756
695 my $children = $self->{children}; 757 my $children = $self->{children};
696 758
697 my @h = map +($_->size_request)[1], @$children; 759 my @h = map +($_->size_request)[0], @$children;
698 760
699 my $req_h = List::Util::sum @h; 761 my $req_h = List::Util::sum @h;
700 762
701 if ($req_h > $h) { 763 if ($req_h > $h) {
702 # ah well, not enough space 764 # ah well, not enough space
718 780
719 my $y = 0; 781 my $y = 0;
720 for (0 .. $#$children) { 782 for (0 .. $#$children) {
721 my $child = $children->[$_]; 783 my $child = $children->[$_];
722 my $h = $h[$_]; 784 my $h = $h[$_];
723 $child->move (0, $y);
724 $child->size_allocate ($w, $h); 785 $child->size_allocate ($y, 0, $h, $w);
725 786
726 $y += $h; 787 $y += $h;
727 } 788 }
728} 789}
729 790
730############################################################################# 791#############################################################################
731 792
793package CFClient::UI::VBox;
794
795# TODO: wrap into common Box base class
796
797our @ISA = CFClient::UI::Container::;
798
799sub size_request {
800 my ($self) = @_;
801
802 my @alloc = map [$_->size_request], @{$self->{children}};
803
804 (
805 (List::Util::max map $_->[0], @alloc),
806 (List::Util::sum map $_->[1], @alloc),
807 )
808}
809
810sub size_allocate {
811 my ($self, $x, $y, $w, $h) = @_;
812
813 $self->_size_allocate ($x, $y, $w, $h) or return;
814
815 return unless $self->{h};
816
817 my $children = $self->{children};
818
819 my @h = map +($_->size_request)[1], @$children;
820
821 my $req_h = List::Util::sum @h;
822
823 if ($req_h > $h) {
824 # ah well, not enough space
825 $_ = $h[$_] * $h / $req_h for @h;
826 } else {
827 my @exp = grep $_->{expand}, @$children;
828 @exp = @$children unless @exp;
829
830 my %exp = map +($_ => 1), @exp;
831
832 for (0 .. $#$children) {
833 my $child = $children->[$_];
834
835 my $alloc_h = $h[$_];
836 $alloc_h += ($h - $req_h) / @exp if $exp{$child};
837 $h[$_] = $alloc_h;
838 }
839 }
840
841 my $y = 0;
842 for (0 .. $#$children) {
843 my $child = $children->[$_];
844 my $h = $h[$_];
845 $child->size_allocate (0, $y, $w, $h);
846
847 $y += $h;
848 }
849}
850
851#############################################################################
852
732package CFClient::Widget::Label; 853package CFClient::UI::Label;
733 854
734our @ISA = CFClient::Widget::; 855our @ISA = CFClient::UI::Base::;
735 856
736use SDL::OpenGL; 857use SDL::OpenGL;
737 858
738sub new { 859sub new {
739 my ($class, %arg) = @_; 860 my ($class, %arg) = @_;
740 861
741 my $self = $class->SUPER::new ( 862 my $self = $class->SUPER::new (
742 fg => [1, 1, 1], 863 fg => [1, 1, 1],
743 height => $::FONTSIZE, 864 height => $::FONTSIZE,
744 text => "", 865 text => "",
866 align => -1,
867 padding => 2,
745 layout => new CFClient::Layout, 868 layout => new CFClient::Layout,
746 %arg 869 %arg
747 ); 870 );
748 871
749 $self->set_text ($self->{text}); 872 $self->set_text ($self->{text});
750 873
780sub size_request { 903sub size_request {
781 my ($self) = @_; 904 my ($self) = @_;
782 905
783 $self->{layout}->set_width; 906 $self->{layout}->set_width;
784 $self->{layout}->set_height ($self->{height}); 907 $self->{layout}->set_height ($self->{height});
785 $self->{layout}->size 908 my ($w, $h) = $self->{layout}->size;
786# if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack 909
787# ( 910 (
788# $self->{texture}{width}, 911 $w + $self->{padding} * 2,
789# $self->{texture}{height}, 912 $h + $self->{padding} * 2,
790# ) 913 )
791# } else {
792# my ($w, $h, $data) = CFClient::font_render "Yy", $self->{height};
793#
794# ($w, $h)
795# }
796} 914}
797 915
798sub size_allocate { 916sub size_allocate {
799 my ($self, $w, $h) = @_; 917 my ($self, $x, $y, $w, $h) = @_;
800 918
801 return unless $self->{w} != $w || $self->{h} != $h; 919 $self->_size_allocate ($x, $y, $w, $h) or return;
802 920
803 $self->SUPER::size_allocate ($w, $h);
804 delete $self->{texture}; 921 delete $self->{texture};
805} 922}
806 923
807sub update { 924sub update {
808 my ($self) = @_; 925 my ($self) = @_;
814sub _draw { 931sub _draw {
815 my ($self) = @_; 932 my ($self) = @_;
816 933
817 my $tex = $self->{texture} ||= do { 934 my $tex = $self->{texture} ||= do {
818 $self->{layout}->set_width ($self->{w}); 935 $self->{layout}->set_width ($self->{w});
819 new_from_layout CFClient::Texture $self->{layout}; 936 new_from_layout CFClient::Texture $self->{layout}
820 }; 937 };
821 938
822 glEnable GL_BLEND; 939 glEnable GL_BLEND;
940 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
823 glEnable GL_TEXTURE_2D; 941 glEnable GL_TEXTURE_2D;
824 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
825 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 942 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
826 943
827 glColor @{$self->{fg}}; 944 glColor @{$self->{fg}};
828 945
946 my $x =
947 $self->{align} < 0 ? $self->{padding}
948 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
949 : ($self->{w} - $tex->{w}) * 0.5;
950
829 $tex->draw_quad (0, 0); 951 $tex->draw_quad ($x, 0);
830 952
953 glDisable GL_TEXTURE_2D;
831 glDisable GL_BLEND; 954 glDisable GL_BLEND;
832 glDisable GL_TEXTURE_2D;
833} 955}
834 956
835############################################################################# 957#############################################################################
836 958
837package CFClient::Widget::Entry; 959package CFClient::UI::Entry;
838 960
839our @ISA = CFClient::Widget::Label::; 961our @ISA = CFClient::UI::Label::;
840 962
841use SDL; 963use SDL;
842use SDL::OpenGL; 964use SDL::OpenGL;
843 965
844sub new { 966sub new {
845 my $class = shift; 967 my $class = shift;
846 968
847 $class->SUPER::new ( 969 $class->SUPER::new (
848 fg => [1, 1, 1], 970 fg => [1, 1, 1],
849 bg => [0, 0, 0, 0.4], 971 bg => [0, 0, 0, 0.2],
850 active_bg => [1, 1, 1], 972 active_bg => [1, 1, 1],
851 active_fg => [0, 0, 0], 973 active_fg => [0, 0, 0],
852 @_ 974 @_
853 ) 975 )
854} 976}
858 980
859 $self->{last_activity} = $::NOW; 981 $self->{last_activity} = $::NOW;
860 982
861 $self->{text} = $text; 983 $self->{text} = $text;
862 $self->{layout}->set_width ($self->{w}); 984 $self->{layout}->set_width ($self->{w});
985
986 $text =~ s/./*/g if $self->{hidden};
987
863 $self->{layout}->set_markup ($self->escape_text ($text)); 988 $self->{layout}->set_markup ($self->escape_text ($text) . " ");
864 989
865 $text = substr $text, 0, $self->{cursor}; 990 $text = substr $text, 0, $self->{cursor};
866 utf8::encode $text; 991 utf8::encode $text;
867 992
868 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); 993 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
875 1000
876 ($w + 1, $h) # add 1 for cursor 1001 ($w + 1, $h) # add 1 for cursor
877} 1002}
878 1003
879sub size_allocate { 1004sub size_allocate {
880 my ($self, $w, $h) = @_; 1005 my ($self, $x, $y, $w, $h) = @_;
881 1006
882 return unless $self->{w} != $w || $self->{h} != $h;
883
884 $self->SUPER::size_allocate ($w, $h); 1007 $self->SUPER::size_allocate ($x, $y, $w, $h);
885 1008
886 $self->_set_text ($self->{text}); 1009 $self->_set_text ($self->{text});
887} 1010}
888 1011
889sub set_text { 1012sub set_text {
910 substr $text, $self->{cursor}, 1, ""; 1033 substr $text, $self->{cursor}, 1, "";
911 } elsif ($sym == SDLK_LEFT) { 1034 } elsif ($sym == SDLK_LEFT) {
912 --$self->{cursor} if $self->{cursor}; 1035 --$self->{cursor} if $self->{cursor};
913 } elsif ($sym == SDLK_RIGHT) { 1036 } elsif ($sym == SDLK_RIGHT) {
914 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1037 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1038 } elsif ($sym == SDLK_HOME) {
1039 $self->{cursor} = 0;
1040 } elsif ($sym == SDLK_END) {
1041 $self->{cursor} = length $text;
915 } elsif ($uni) { 1042 } elsif ($uni) {
916 substr $text, $self->{cursor}++, 0, chr $uni; 1043 substr $text, $self->{cursor}++, 0, chr $uni;
917 } 1044 }
918 1045
919 $self->_set_text ($text); 1046 $self->_set_text ($text);
934 $self->SUPER::button_down ($ev, $x, $y); 1061 $self->SUPER::button_down ($ev, $x, $y);
935 1062
936 my $idx = $self->{layout}->xy_to_index ($x, $y); 1063 my $idx = $self->{layout}->xy_to_index ($x, $y);
937 1064
938 # byte-index to char-index 1065 # byte-index to char-index
939 my $text = $self->{layout}; 1066 my $text = $self->{text};
940 utf8::encode $text; 1067 utf8::encode $text;
941 $self->{cursor} = length substr $text, 0, $idx; 1068 $self->{cursor} = length substr $text, 0, $idx;
942 1069
943 $self->_set_text ($self->{text}); 1070 $self->_set_text ($self->{text});
944 $self->update; 1071 $self->update;
959 $self->{fg} = $self->{active_fg}; 1086 $self->{fg} = $self->{active_fg};
960 } else { 1087 } else {
961 glColor @{$self->{bg}}; 1088 glColor @{$self->{bg}};
962 } 1089 }
963 1090
1091 glEnable GL_BLEND;
1092 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
964 glBegin GL_QUADS; 1093 glBegin GL_QUADS;
965 glVertex 0 , 0; 1094 glVertex 0 , 0;
966 glVertex 0 , $self->{h}; 1095 glVertex 0 , $self->{h};
967 glVertex $self->{w}, $self->{h}; 1096 glVertex $self->{w}, $self->{h};
968 glVertex $self->{w}, 0; 1097 glVertex $self->{w}, 0;
969 glEnd; 1098 glEnd;
1099 glDisable GL_BLEND;
970 1100
971 $self->SUPER::_draw; 1101 $self->SUPER::_draw;
972 1102
973 #TODO: force update every cursor change :( 1103 #TODO: force update every cursor change :(
974 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { 1104 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) {
980 } 1110 }
981} 1111}
982 1112
983############################################################################# 1113#############################################################################
984 1114
985package CFClient::Widget::Slider; 1115package CFClient::UI::Slider;
986 1116
987use strict; 1117use strict;
988 1118
989use SDL::OpenGL; 1119use SDL::OpenGL;
990use SDL::OpenGL::Constants;
991 1120
992our @ISA = CFClient::Widget::DrawBG::; 1121our @ISA = CFClient::UI::DrawBG::;
993
994sub size_request {
995 my ($self) = @_;
996
997 my $w = 20;
998 my $h = 10;
999
1000 $self->{vertical} ? ($h, $w) : ($w, $h)
1001}
1002 1122
1003sub new { 1123sub new {
1004 my $class = shift; 1124 my $class = shift;
1005 1125
1006 # range [value, low, high, page] 1126 # range [value, low, high, page]
1007 1127
1008 $class->SUPER::new ( 1128 my $self = $class->SUPER::new (
1009 fg => [1, 1, 1], 1129 fg => [1, 1, 1],
1010 active_fg => [0, 0, 0], 1130 active_fg => [0, 0, 0],
1011 range => [0, 0, 100, 10], 1131 range => [0, 0, 100, 10],
1132 req_w => 40,
1133 req_h => 10,
1012 vertical => 1, 1134 vertical => 0,
1013 @_ 1135 @_
1014 ) 1136 );
1137
1138 $self
1139}
1140
1141sub size_request {
1142 my ($self) = @_;
1143
1144 my $w = $self->{req_w};
1145 my $h = $self->{req_h};
1146
1147 $self->{vertical} ? ($h, $w) : ($w, $h)
1015} 1148}
1016 1149
1017sub button_down { 1150sub button_down {
1018 my ($self, $ev, $x, $y) = @_; 1151 my ($self, $ev, $x, $y) = @_;
1019 1152
1025 my ($self, $ev, $x, $y) = @_; 1158 my ($self, $ev, $x, $y) = @_;
1026 1159
1027 if ($GRAB == $self) { 1160 if ($GRAB == $self) {
1028 my ($value, $lo, $hi, $page) = @{$self->{range}}; 1161 my ($value, $lo, $hi, $page) = @{$self->{range}};
1029 1162
1163 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w});
1164
1030 $x = $x * ($hi - $lo) / $self->{w} + $lo; 1165 $x = $x * ($hi - $lo) / $w + $lo;
1031 $x = $lo if $x < $lo; 1166 $x = $lo if $x < $lo;
1032 $x = $hi - $page if $x > $hi - $page; 1167 $x = $hi - $page if $x > $hi - $page;
1033 $self->{range}[0] = $x; 1168 $self->{range}[0] = $x;
1034 1169
1035 $self->{changed}($x) if $self->{changed}; 1170 $self->emit (changed => $x);
1036 $self->update; 1171 $self->update;
1037 } 1172 }
1038} 1173}
1039 1174
1040sub _draw { 1175sub _draw {
1041 my ($self) = @_; 1176 my ($self) = @_;
1042 1177
1043 $self->SUPER::_draw (); 1178 $self->SUPER::_draw ();
1044
1045 glPushMatrix;
1046 1179
1047 my ($w, $h) = @$self{qw(w h)}; 1180 my ($w, $h) = @$self{qw(w h)};
1048 1181
1049 if ($self->{vertical}) { 1182 if ($self->{vertical}) {
1050 # draw a vertical slider like a rotated horizontal slider 1183 # draw a vertical slider like a rotated horizontal slider
1051 1184
1052 glTranslate 0, $self->{w};
1053 glRotate 90, 0, 0, 1; 1185 glRotate 90, 0, 0, 1;
1186 glTranslate 0, -$self->{w}, 0;
1054 1187
1055 ($w, $h) = ($h, $w); 1188 ($w, $h) = ($h, $w);
1056 } 1189 }
1057 1190
1058 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 1191 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
1090 glVertex $knob_a + 1, $h - 1; 1223 glVertex $knob_a + 1, $h - 1;
1091 glVertex $knob_b - 1, $h - 1; 1224 glVertex $knob_b - 1, $h - 1;
1092 glVertex $knob_b - 1, 1; 1225 glVertex $knob_b - 1, 1;
1093 } 1226 }
1094 glEnd; 1227 glEnd;
1095
1096 glPopMatrix;
1097} 1228}
1098 1229
1099############################################################################# 1230#############################################################################
1100 1231
1101package CFClient::Widget::MapWidget; 1232package CFClient::UI::MapWidget;
1102 1233
1103use strict; 1234use strict;
1104 1235
1105use List::Util qw(min max); 1236use List::Util qw(min max);
1106 1237
1107use SDL; 1238use SDL;
1108use SDL::OpenGL; 1239use SDL::OpenGL;
1109use SDL::OpenGL::Constants;
1110 1240
1111our @ISA = CFClient::Widget::; 1241our @ISA = CFClient::UI::Base::;
1112 1242
1113sub new { 1243sub new {
1114 my $class = shift; 1244 my $class = shift;
1115 1245
1116 $class->SUPER::new ( 1246 $class->SUPER::new (
1136 1266
1137sub update { 1267sub update {
1138 my ($self) = @_; 1268 my ($self) = @_;
1139 1269
1140 $self->{need_update} = 1; 1270 $self->{need_update} = 1;
1271 $self->SUPER::update;
1141} 1272}
1142 1273
1143sub _draw { 1274sub _draw {
1144 my ($self) = @_; 1275 my ($self) = @_;
1145 1276
1168 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; 1299 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs};
1169 } 1300 }
1170 1301
1171 glEnable GL_TEXTURE_2D; 1302 glEnable GL_TEXTURE_2D;
1172 glEnable GL_BLEND; 1303 glEnable GL_BLEND;
1304 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1173 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1305 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1174 1306
1175 my $sw4 = ($sw + 3) & ~3; 1307 my $sw4 = ($sw + 3) & ~3;
1176 my $darkness = "\x00" x ($sw4 * $sh); 1308 my $darkness = "\x00" x ($sw4 * $sh);
1177 1309
1190 } 1322 }
1191 1323
1192 for my $num (grep $_, @$cell[1,2,3]) { 1324 for my $num (grep $_, @$cell[1,2,3]) {
1193 my $tex = $::CONN->{face}[$num]{texture} || next; 1325 my $tex = $::CONN->{face}[$num]{texture} || next;
1194 1326
1195 my $w = $tex->{width}; 1327 my ($w, $h) = @$tex{qw(w h)};
1196 my $h = $tex->{height};
1197 1328
1198 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); 1329 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h);
1199 } 1330 }
1200 } 1331 }
1201 } 1332 }
1208# 1339#
1209# $lighting = $pb->get_pixels; 1340# $lighting = $pb->get_pixels;
1210# $lighting =~ s/(.)../$1/gs; 1341# $lighting =~ s/(.)../$1/gs;
1211# } 1342# }
1212 1343
1213 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1214 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1344 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1215 1345
1216 $darkness = new CFClient::Texture 1346 $darkness = new CFClient::Texture
1217 width => $sw4, 1347 w => $sw4,
1218 height => $sh, 1348 h => $sh,
1219 data => $darkness, 1349 data => $darkness,
1220 internalformat => GL_ALPHA, 1350 internalformat => GL_ALPHA,
1221 format => GL_ALPHA; 1351 format => GL_ALPHA;
1222 1352
1223 glColor 0.45, 0.45, 0.45, 1; 1353 glColor 0.45, 0.45, 0.45, 1;
1283 } 1413 }
1284} 1414}
1285 1415
1286############################################################################# 1416#############################################################################
1287 1417
1288package CFClient::Widget::Animator; 1418package CFClient::UI::Animator;
1289 1419
1290use SDL::OpenGL; 1420use SDL::OpenGL;
1291 1421
1292our @ISA = CFClient::Widget::Bin::; 1422our @ISA = CFClient::UI::Bin::;
1293 1423
1294sub moveto { 1424sub moveto {
1295 my ($self, $x, $y) = @_; 1425 my ($self, $x, $y) = @_;
1296 1426
1297 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 1427 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
1325 glPopMatrix; 1455 glPopMatrix;
1326} 1456}
1327 1457
1328############################################################################# 1458#############################################################################
1329 1459
1330package CFClient::Widget::Toplevel; 1460package CFClient::UI::Toplevel;
1331 1461
1332our @ISA = CFClient::Widget::Container::; 1462our @ISA = CFClient::UI::Container::;
1333 1463
1334sub size_request { 1464sub size_request {
1335 ($::WIDTH, $::HEIGHT) 1465 ($::WIDTH, $::HEIGHT)
1336} 1466}
1337 1467
1338sub size_allocate { 1468sub size_allocate {
1339 my ($self, $w, $h) = @_; 1469 my ($self, $x, $y, $w, $h) = @_;
1340 1470
1341 $self->SUPER::size_allocate ($w, $h); 1471 $self->_size_allocate ($x, $y, $w, $h);
1342 1472
1343 $_->size_allocate ($_->size_request) 1473 $_->size_allocate ($_->{x}, $_->{y}, $_->size_request)
1344 for @{$self->{children}}; 1474 for @{$self->{children}};
1345} 1475}
1346 1476
1347sub translate { 1477sub translate {
1348 my ($self, $x, $y) = @_; 1478 my ($self, $x, $y) = @_;
1351} 1481}
1352 1482
1353sub update { 1483sub update {
1354 my ($self) = @_; 1484 my ($self) = @_;
1355 1485
1356 $self->size_allocate ($self->size_request); 1486 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT);
1357 ::refresh (); 1487 ::refresh ();
1358} 1488}
1359 1489
1360sub add { 1490sub add {
1361 my ($self, $widget) = @_; 1491 my ($self, $widget) = @_;
1362 1492
1363 $self->SUPER::add ($widget); 1493 $self->SUPER::add ($widget);
1364 1494
1365 $widget->size_allocate ($widget->size_request); 1495 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request);
1366} 1496}
1367 1497
1368sub draw { 1498sub draw {
1369 my ($self) = @_; 1499 my ($self) = @_;
1370 1500
1371 $self->_draw; 1501 $self->_draw;
1372} 1502}
1373 1503
1374############################################################################# 1504#############################################################################
1375 1505
1376package CFClient::Widget; 1506package CFClient::UI;
1377 1507
1378$TOPLEVEL = new CFClient::Widget::Toplevel; 1508$TOPLEVEL = new CFClient::UI::Toplevel;
1379 1509
13801 15101
1381 1511

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines