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.72 by root, Tue Apr 11 18:00:45 2006 UTC vs.
Revision 1.77 by root, Tue Apr 11 22:14:13 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
45 43
46 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); 44 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y);
47 45
48 $BUTTON_STATE &= ~(1 << ($ev->button - 1)); 46 $BUTTON_STATE &= ~(1 << ($ev->button - 1));
49 47
50 $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB; 48 $GRAB->button_up ($ev, $GRAB->translate ($x, $y)) if $GRAB;
51 49
52 if (!$BUTTON_STATE) { 50 if (!$BUTTON_STATE) {
53 my $grab = $GRAB; undef $GRAB; 51 my $grab = $GRAB; undef $GRAB;
54 $grab->update if $grab; 52 $grab->update if $grab;
55 $GRAB->update if $GRAB; 53 $GRAB->update if $GRAB;
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) = @_;
158 glTranslate $self->{x}, $self->{y}, 0; 179 glTranslate $self->{x}, $self->{y}, 0;
159 $self->_draw; 180 $self->_draw;
160 glPopMatrix; 181 glPopMatrix;
161 182
162 if ($self == $HOVER) { 183 if ($self == $HOVER) {
163 my ($x, $y) = @$self->{qw(x y)}; 184 my ($x, $y) = @$self{qw(x y)};
164 185
165 glColor 1, 1, 1, 0.1; 186 glColor 0, 0, 1, 0.2;
166 glEnable GL_BLEND; 187 glEnable GL_BLEND;
188 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
167 glBegin GL_QUADS; 189 glBegin GL_QUADS;
168 glVertex $x , $y; 190 glVertex $x , $y;
169 glVertex $x + $self->{w}, $y; 191 glVertex $x + $self->{w}, $y;
170 glVertex $x + $self->{w}, $y + $self->{h}; 192 glVertex $x + $self->{w}, $y + $self->{h};
171 glVertex $x , $y + $self->{h}; 193 glVertex $x , $y + $self->{h};
240 #$self->deactivate; 262 #$self->deactivate;
241} 263}
242 264
243############################################################################# 265#############################################################################
244 266
245package CFClient::Widget::DrawBG; 267package CFClient::UI::DrawBG;
246 268
247our @ISA = CFClient::Widget::; 269our @ISA = CFClient::UI::Base::;
248 270
249use strict; 271use strict;
250use SDL::OpenGL; 272use SDL::OpenGL;
251 273
252sub new { 274sub new {
253 my $class = shift; 275 my $class = shift;
254 276
255 # range [value, low, high, page] 277 # range [value, low, high, page]
256 278
257 $class->SUPER::new ( 279 $class->SUPER::new (
258 bg => [0, 0, 0, 0.4], 280 bg => [0, 0, 0, 0.2],
259 active_bg => [1, 1, 1], 281 active_bg => [1, 1, 1],
260 @_ 282 @_
261 ) 283 )
262} 284}
263 285
264sub _draw { 286sub _draw {
265 my ($self) = @_; 287 my ($self) = @_;
266 288
267 my ($w, $h) = @$self{qw(w h)}; 289 my ($w, $h) = @$self{qw(w h)};
268 290
291 glEnable GL_BLEND;
292 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
269 glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} }; 293 glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} };
294
270 glBegin GL_QUADS; 295 glBegin GL_QUADS;
271 glVertex 0 , 0; 296 glVertex 0 , 0;
272 glVertex 0 , $h; 297 glVertex 0 , $h;
273 glVertex $w, $h; 298 glVertex $w, $h;
274 glVertex $w, 0; 299 glVertex $w, 0;
275 glEnd; 300 glEnd;
276}
277 301
278############################################################################# 302 glDisable GL_BLEND;
303}
279 304
305#############################################################################
306
280package CFClient::Widget::Empty; 307package CFClient::UI::Empty;
281 308
282our @ISA = CFClient::Widget::; 309our @ISA = CFClient::UI::Base::;
283 310
284sub size_request { 311sub size_request {
285 (0, 0) 312 (0, 0)
286} 313}
287 314
288sub draw { } 315sub draw { }
289 316
290############################################################################# 317#############################################################################
291 318
292package CFClient::Widget::Container; 319package CFClient::UI::Container;
293 320
294our @ISA = CFClient::Widget::; 321our @ISA = CFClient::UI::Base::;
295 322
296sub new { 323sub new {
297 my ($class, %arg) = @_; 324 my ($class, %arg) = @_;
298 325
299 my $children = delete $arg{children} || []; 326 my $children = delete $arg{children} || [];
303 330
304 $self 331 $self
305} 332}
306 333
307sub add { 334sub add {
308 my ($self, $chld, $expand) = @_; 335 my ($self, $chld) = @_;
309 336
310 $chld->{expand} = $expand;
311 $chld->set_parent ($self); 337 $chld->set_parent ($self);
312 338
313 $self->{children} = [ 339 $self->{children} = [
314 sort { $a->{z} <=> $b->{z} } 340 sort { $a->{z} <=> $b->{z} }
315 @{$self->{children}}, $chld 341 @{$self->{children}}, $chld
316 ]; 342 ];
317 343
318 $self->size_allocate ($self->{w}, $self->{h}) 344 $self->{w} = $self->{h} = -1;
319 if $self->{w}; #TODO: check for "realised state" 345 $self->update;
320} 346}
321 347
322sub remove { 348sub remove {
323 my ($self, $widget) = @_; 349 my ($self, $widget) = @_;
324 350
325 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 351 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ];
326 352
327 $self->size_allocate ($self->{w}, $self->{h}); 353 $self->size_allocate (0, 0, $self->{w}, $self->{h});
328} 354}
329 355
330sub find_widget { 356sub find_widget {
331 my ($self, $x, $y) = @_; 357 my ($self, $x, $y) = @_;
332 358
349 $_->draw for @{$self->{children}}; 375 $_->draw for @{$self->{children}};
350} 376}
351 377
352############################################################################# 378#############################################################################
353 379
354package CFClient::Widget::Bin; 380package CFClient::UI::Bin;
355 381
356our @ISA = CFClient::Widget::Container::; 382our @ISA = CFClient::UI::Container::;
357 383
358sub new { 384sub new {
359 my ($class, %arg) = @_; 385 my ($class, %arg) = @_;
360 386
361 my $child = (delete $arg{child}) || new CFClient::Widget::Empty::; 387 my $child = (delete $arg{child}) || new CFClient::UI::Empty::;
362 388
363 $class->SUPER::new (children => [$child], %arg) 389 $class->SUPER::new (children => [$child], %arg)
364} 390}
365 391
366sub add { 392sub add {
374sub remove { 400sub remove {
375 my ($self, $widget) = @_; 401 my ($self, $widget) = @_;
376 402
377 $self->SUPER::remove ($widget); 403 $self->SUPER::remove ($widget);
378 404
379 $self->{children} = [new CFClient::Widget::Empty] 405 $self->{children} = [new CFClient::UI::Empty]
380 unless @{$self->{children}}; 406 unless @{$self->{children}};
381} 407}
382 408
383sub child { $_[0]->{children}[0] } 409sub child { $_[0]->{children}[0] }
384 410
385sub size_request { 411sub size_request {
386 $_[0]{children}[0]->size_request 412 $_[0]{children}[0]->size_request
387} 413}
388 414
389sub size_allocate { 415sub size_allocate {
390 my ($self, $w, $h) = @_; 416 my ($self, $x, $y, $w, $h) = @_;
391 417
392 return unless $self->{w} != $w || $self->{h} != $h; 418 $self->_size_allocate ($x, $y, $w, $h) or return;
393 419
394 $self->SUPER::size_allocate ($w, $h);
395 $self->{children}[0]->size_allocate ($w, $h); 420 $self->{children}[0]->size_allocate (0, 0, $w, $h);
396} 421}
397 422
398############################################################################# 423#############################################################################
399 424
400package CFClient::Widget::Window; 425package CFClient::UI::Window;
401 426
402our @ISA = CFClient::Widget::Bin::; 427our @ISA = CFClient::UI::Bin::;
403 428
404use SDL::OpenGL; 429use SDL::OpenGL;
405 430
406sub new { 431sub new {
407 my ($class, %arg) = @_; 432 my ($class, %arg) = @_;
425 $self->{w}, $self->{h}, sub { $self->child->draw } 450 $self->{w}, $self->{h}, sub { $self->child->draw }
426 ); 451 );
427} 452}
428 453
429sub size_allocate { 454sub size_allocate {
430 my ($self, $w, $h) = @_; 455 my ($self, $x, $y, $w, $h) = @_;
431 456
432 return unless $self->{w} != $w || $self->{h} != $h; 457 $self->_size_allocate ($x, $y, $w, $h) or return;
433 458
434 $self->{w} = $w;
435 $self->{h} = $h;
436
437 $self->child->size_allocate ($w, $h); 459 $self->child->size_allocate (0, 0, $w, $h);
438 460
439 $self->render_chld; 461 $self->render_chld;
440} 462}
441 463
442sub _draw { 464sub _draw {
446 468
447 my $tex = $self->{texture} 469 my $tex = $self->{texture}
448 or return; 470 or return;
449 471
450 glEnable GL_BLEND; 472 glEnable GL_BLEND;
473 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
451 glEnable GL_TEXTURE_2D; 474 glEnable GL_TEXTURE_2D;
452 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 475 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
453 476
454 $tex->draw_quad (0, 0, $w, $h); 477 $tex->draw_quad (0, 0, $w, $h);
455 478
457 glDisable GL_TEXTURE_2D; 480 glDisable GL_TEXTURE_2D;
458} 481}
459 482
460############################################################################# 483#############################################################################
461 484
462package CFClient::Widget::Frame; 485package CFClient::UI::Frame;
463 486
464our @ISA = CFClient::Widget::Bin::; 487our @ISA = CFClient::UI::Bin::;
465 488
466use SDL::OpenGL; 489use SDL::OpenGL;
467 490
468sub size_request { 491sub size_request {
469 my ($self) = @_; 492 my ($self) = @_;
474 497
475 map { $_ + 4 } $chld->size_request; 498 map { $_ + 4 } $chld->size_request;
476} 499}
477 500
478sub size_allocate { 501sub size_allocate {
479 my ($self, $w, $h) = @_; 502 my ($self, $x, $y, $w, $h) = @_;
480 503
481 return unless $self->{w} != $w || $self->{h} != $h; 504 $self->_size_allocate ($x, $y, $w, $h) or return;
482 505
483 $self->{w} = $w;
484 $self->{h} = $h;
485
486 $self->child->size_allocate ($w - 4, $h - 4); 506 $self->child->size_allocate (2, 2, $w - 4, $h - 4);
487 $self->child->move (2, 2);
488} 507}
489 508
490sub _draw { 509sub _draw {
491 my ($self) = @_; 510 my ($self) = @_;
492 511
505 $chld->draw; 524 $chld->draw;
506} 525}
507 526
508############################################################################# 527#############################################################################
509 528
510package CFClient::Widget::FancyFrame; 529package CFClient::UI::FancyFrame;
511 530
512our @ISA = CFClient::Widget::Bin::; 531our @ISA = CFClient::UI::Bin::;
513 532
514use SDL::OpenGL; 533use SDL::OpenGL;
515 534
516my @tex = 535my @tex =
517 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 536 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
518 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 537 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
519 538
520sub size_request { 539sub size_request {
521 my ($self) = @_; 540 my ($self) = @_;
522 541
542 my ($w, $h) =
543 $self->{user_w} && $self->{user_h}
544 ? ($self->{user_w}, $self->{user_h})
523 my ($w, $h) = $self->SUPER::size_request; 545 : ($self->SUPER::size_request);
524 546
525 $h += $tex[1]->{h}; 547 $h += $tex[1]->{h};
526 $h += $tex[4]->{h}; 548 $h += $tex[4]->{h};
527 $w += $tex[2]->{w}; 549 $w += $tex[2]->{w};
528 $w += $tex[3]->{w}; 550 $w += $tex[3]->{w};
529 551
530 ($w, $h) 552 ($w, $h)
531} 553}
532 554
533sub size_allocate { 555sub size_allocate {
534 my ($self, $w, $h) = @_; 556 my ($self, $x, $y, $w, $h) = @_;
535 557
536 return unless $self->{w} != $w || $self->{h} != $h; 558 $self->_size_allocate ($x, $y, $w, $h) or return;
537 559
538 $self->SUPER::size_allocate ($w, $h);
539
540 $h -= $tex[1]->{h}; 560 $h -= $tex[1]{h};
541 $h -= $tex[4]->{h}; 561 $h -= $tex[4]{h};
542 $w -= $tex[2]->{w}; 562 $w -= $tex[2]{w};
543 $w -= $tex[3]->{w}; 563 $w -= $tex[3]{w};
544 564
545 $h = $h < 0 ? 0 : $h; 565 $h = $h < 0 ? 0 : $h;
546 $w = $w < 0 ? 0 : $w; 566 $w = $w < 0 ? 0 : $w;
547 567
548 my $child = $self->child; 568 my $child = $self->child;
549 569
550 $child->size_allocate ($w, $h);
551 $child->move ($tex[3]->{w}, $tex[1]->{h}); 570 $child->size_allocate ($tex[3]->{w}, $tex[1]->{h}, $w, $h);
571}
572
573sub button_down {
574 my ($self, $ev, $x, $y) = @_;
575
576 if ($x < $self->{w} && $x >= $self->{w} - $tex[2]{w}
577 && $y < $self->{h} && $y >= $self->{h} - $tex[4]{h}) {
578
579 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
580 my ($bw, $bh) = ($self->{w}, $self->{h});
581
582 $self->{motion} = sub {
583 my ($ev, $x, $y) = @_;
584
585 ($x, $y) = ($ev->motion_x, $ev->motion_y);
586
587 $self->{user_w} = $bw + $x - $ox;
588 $self->{user_h} = $bh + $y - $oy;
589 $self->update;
590 };
591
592 } elsif ($x >= 0 && $x < $self->{w}
593 && $y >= 0 && $y < $tex[1]{h}) {
594
595 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
596 my ($bx, $by) = ($self->{x}, $self->{y});
597
598 $self->{motion} = sub {
599 my ($ev, $x, $y) = @_;
600
601 ($x, $y) = ($ev->motion_x, $ev->motion_y);
602
603 $self->move ($bx + $x - $ox, $by + $y - $oy);
604 $self->update;
605 };
606 }
607}
608
609sub button_up {
610 my ($self, $ev, $x, $y) = @_;
611
612 delete $self->{motion};
613}
614
615sub mouse_motion {
616 my ($self, $ev, $x, $y) = @_;
617
618 $self->{motion}->($ev, $x, $y) if $self->{motion};
552} 619}
553 620
554sub _draw { 621sub _draw {
555 my ($self) = @_; 622 my ($self) = @_;
556 623
557 my ($w, $h) = ($self->{w}, $self->{h}); 624 my ($w, $h) = ($self->{w}, $self->{h});
558 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 625 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
559 626
560 glEnable GL_BLEND; 627 glEnable GL_BLEND;
628 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
561 glEnable GL_TEXTURE_2D; 629 glEnable GL_TEXTURE_2D;
562 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
563 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 630 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
564 631
565 my $top = $tex[1]; 632 my $top = $tex[1];
566 $top->draw_quad (0, 0, $w, $top->{h}); 633 $top->draw_quad (0, 0, $w, $top->{h});
567 634
573 640
574 my $bottom = $tex[4]; 641 my $bottom = $tex[4];
575 $bottom->draw_quad (0, $h - $bottom->{h}, $w, $bottom->{h}); 642 $bottom->draw_quad (0, $h - $bottom->{h}, $w, $bottom->{h});
576 643
577 my $bg = $tex[0]; 644 my $bg = $tex[0];
645
578 glBindTexture GL_TEXTURE_2D, $bg->{name}; 646 glBindTexture GL_TEXTURE_2D, $bg->{name};
579 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 647 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
580 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; 648 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT;
581 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; 649 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT;
582 650
583 my $rep_x = $cw / $bg->{w}; 651 my $rep_x = $cw / $bg->{w};
584 my $rep_y = $ch / $bg->{h}; 652 my $rep_y = $ch / $bg->{h};
585 653
586 $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); 654 $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch);
587 655
656 glDisable GL_TEXTURE_2D;
588 glDisable GL_BLEND; 657 glDisable GL_BLEND;
589 glDisable GL_TEXTURE_2D;
590 658
591 $self->child->draw; 659 $self->child->draw;
592 660
593} 661}
594 662
595############################################################################# 663#############################################################################
596 664
597package CFClient::Widget::Table; 665package CFClient::UI::Table;
598 666
599our @ISA = CFClient::Widget::; 667our @ISA = CFClient::UI::Base::;
668
669use List::Util qw(max sum);
600 670
601use SDL::OpenGL; 671use SDL::OpenGL;
602 672
603sub add { 673sub add {
604 my ($self, $x, $y, $chld) = @_; 674 my ($self, $x, $y, $chld) = @_;
605 my $old_chld = $self->{children}[$y][$x];
606 675
607 $self->{children}[$y][$x] = $chld; 676 $self->{children}[$y][$x] = $chld;
608 $chld->set_parent ($self); 677 $chld->set_parent ($self);
678
679 $self->{w} = $self->{h} = -1;
609 $self->update; 680 $self->update;
610} 681}
611 682
612sub max_row_height { 683sub get_wh {
613 my ($self, $row) = @_; 684 my ($self) = @_;
614 685
615 my $hs = 0; 686 my (@w, @h);
616 for (my $xi = 0; $xi <= $#{$self->{children}->[$row] || []}; $xi++) { 687
688 for my $y (0 .. $#{$self->{children}}) {
617 my $c = $self->{children}->[$row]->[$xi]; 689 my $row = $self->{children}[$y]
618 if ($c) { 690 or next;
691
692 for my $x (0 .. $#$row) {
693 my $widget = $row->[$x]
694 or next;
619 my ($w, $h) = $c->size_request; 695 my ($w, $h) = $widget->size_request;
620 if ($hs < $h) { $hs = $h } 696
697 $w[$x] = max $w[$x], $w;
698 $h[$y] = max $h[$y], $h;
621 } 699 }
622 } 700 }
623 return $hs;
624}
625 701
626sub max_col_width { 702 (\@w, \@h)
703}
704
705sub size_request {
627 my ($self, $col) = @_; 706 my ($self) = @_;
628 707
708 my ($ws, $hs) = $self->get_wh;
709
710 (
711 (List::Util::sum @$ws),
712 (List::Util::sum @$hs),
713 )
714}
715
716sub size_allocate {
717 my ($self, $x, $y, $w, $h) = @_;
718
719 $self->_size_allocate ($x, $y, $w, $h) or return;
720
721 my ($ws, $hs) = $self->get_wh;
722
723 my $req_w = List::Util::sum @$ws;
724 my $req_h = List::Util::sum @$hs;
725
726 # linearly scale sizes
727 $_ *= $w / $req_w for @$ws;
728 $_ *= $h / $req_h for @$hs;
729
730 my $y;
731
732 for my $r (0 .. $#{$self->{children}}) {
733 my $row = $self->{children}[$r]
734 or next;
735
629 my $ws = 0; 736 my $x = 0;
630 for (my $yi = 0; $yi <= $#{$self->{children} || []}; $yi++) { 737 my $row_h = $hs->[$r];
631 my $c = ($self->{children}->[$yi] || [])->[$col]; 738
632 if ($c) { 739 for my $c (0 .. $#$row) {
633 my ($w, $h) = $c->size_request; 740 my $widget = $row->[$c]
634 if ($ws < $w) { $ws = $w } 741 or next;
742
743 my $col_w = $ws->[$c];
744
745 $widget->size_allocate ($x, $y, $col_w, $row_h);
746
747 $x += $col_w;
635 } 748 }
749
750 $y += $row_h;
636 } 751 }
637 return $ws; 752
638} 753}
754
755sub find_widget {
756 my ($self, $x, $y) = @_;
757
758 $x -= $self->{x};
759 $y -= $self->{y};
760
761 my $res;
762
763 for (grep $_, map @$_, grep $_, @{ $self->{children} }) {
764 $res = $_->find_widget ($x, $y)
765 and return $res;
766 }
767
768 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y})
769}
770
771sub _draw {
772 my ($self) = @_;
773
774 for (grep $_, @{$self->{children}}) {
775 $_->draw for grep $_, @$_;
776 }
777}
778
779#############################################################################
780
781package CFClient::UI::HBox;
782
783# TODO: wrap into common Box base class
784
785our @ISA = CFClient::UI::Container::;
639 786
640sub size_request { 787sub size_request {
641 my ($self) = @_; 788 my ($self) = @_;
642 789
790 my @alloc = map [$_->size_request], @{$self->{children}};
791
792 (
793 (List::Util::sum map $_->[0], @alloc),
794 (List::Util::max map $_->[1], @alloc),
795 )
796}
797
798sub size_allocate {
799 my ($self, $x, $y, $w, $h) = @_;
800
801 $self->_size_allocate ($x, $y, $w, $h) or return;
802
803 return unless $self->{w};
804
643 my ($hs, $ws) = (0, 0); 805 ($h, $w) = ($w, $h);
644 806
645 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { 807 my $children = $self->{children};
646 $hs += $self->max_row_height ($yi);
647 }
648 808
649 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { 809 my @h = map +($_->size_request)[0], @$children;
650 my $wm = 0; 810
651 for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) { 811 my $req_h = List::Util::sum @h;
652 $wm += $self->max_col_width ($xi) 812
813 if ($req_h > $h) {
814 # ah well, not enough space
815 $_ = $h[$_] * $h / $req_h for @h;
816 } else {
817 my $exp = List::Util::sum map $_->{expand}, @$children;
818 $exp ||= 1;
819
820 for (0 .. $#$children) {
821 my $child = $children->[$_];
822
823 my $alloc_h = $h[$_];
824 $alloc_h += ($h - $req_h) * $child->{expand} / $exp;
825 $h[$_] = $alloc_h;
653 } 826 }
654 if ($ws < $wm) { $ws = $wm }
655 } 827 }
656
657 return ($ws, $hs);
658}
659
660sub _draw {
661 my ($self) = @_;
662 828
663 my $y = 0; 829 my $y = 0;
664 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { 830 for (0 .. $#$children) {
831 my $child = $children->[$_];
665 my $x = 0; 832 my $h = $h[$_];
833 $child->size_allocate ($y, 0, $h, $w);
666 834
667 for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) { 835 $y += $h;
668
669 my $c = $self->{children}->[$yi]->[$xi];
670 if ($c) {
671 $c->move ($x, $y, 0); #TODO: Move to size_request
672 $c->draw if $c;
673 }
674
675 $x += $self->max_col_width ($xi);
676 }
677
678 $y += $self->max_row_height ($yi);
679 } 836 }
680} 837}
681 838
682############################################################################# 839#############################################################################
683 840
684package CFClient::Widget::VBox; 841package CFClient::UI::VBox;
685 842
843# TODO: wrap into common Box base class
844
686our @ISA = CFClient::Widget::Container::; 845our @ISA = CFClient::UI::Container::;
687
688use SDL::OpenGL;
689 846
690sub size_request { 847sub size_request {
691 my ($self) = @_; 848 my ($self) = @_;
692 849
693 my @alloc = map [$_->size_request], @{$self->{children}}; 850 my @alloc = map [$_->size_request], @{$self->{children}};
697 (List::Util::sum map $_->[1], @alloc), 854 (List::Util::sum map $_->[1], @alloc),
698 ) 855 )
699} 856}
700 857
701sub size_allocate { 858sub size_allocate {
702 my ($self, $w, $h) = @_; 859 my ($self, $x, $y, $w, $h) = @_;
703 860
704 return unless $self->{w} != $w || $self->{h} != $h; 861 $self->_size_allocate ($x, $y, $w, $h) or return;
705
706 $self->{w} = $w;
707 $self->{h} = $h;
708 862
709 return unless $self->{h}; 863 return unless $self->{h};
710 864
711 my $children = $self->{children}; 865 my $children = $self->{children};
712 866
716 870
717 if ($req_h > $h) { 871 if ($req_h > $h) {
718 # ah well, not enough space 872 # ah well, not enough space
719 $_ = $h[$_] * $h / $req_h for @h; 873 $_ = $h[$_] * $h / $req_h for @h;
720 } else { 874 } else {
721 my @exp = grep $_->{expand}, @$children; 875 my $exp = List::Util::sum map $_->{expand}, @$children;
722 @exp = @$children unless @exp; 876 $exp ||= 1;
723 877
724 my %exp = map +($_ => 1), @exp;
725
726 for (0 .. $#$children) { 878 for (0 .. $#$children) {
727 my $child = $children->[$_]; 879 my $child = $children->[$_];
728 880
729 my $alloc_h = $h[$_]; 881 $h[$_] += ($h - $req_h) * $child->{expand} / $exp;
730 $alloc_h += ($h - $req_h) / @exp if $exp{$child};
731 $h[$_] = $alloc_h;
732 } 882 }
733 } 883 }
734 884
735 my $y = 0; 885 my $y = 0;
736 for (0 .. $#$children) { 886 for (0 .. $#$children) {
737 my $child = $children->[$_]; 887 my $child = $children->[$_];
738 my $h = $h[$_]; 888 my $h = $h[$_];
739 $child->move (0, $y);
740 $child->size_allocate ($w, $h); 889 $child->size_allocate (0, $y, $w, $h);
741 890
742 $y += $h; 891 $y += $h;
743 } 892 }
744} 893}
745 894
746############################################################################# 895#############################################################################
747 896
748package CFClient::Widget::Label; 897package CFClient::UI::Label;
749 898
750our @ISA = CFClient::Widget::; 899our @ISA = CFClient::UI::Base::;
751 900
752use SDL::OpenGL; 901use SDL::OpenGL;
753 902
754sub new { 903sub new {
755 my ($class, %arg) = @_; 904 my ($class, %arg) = @_;
756 905
757 my $self = $class->SUPER::new ( 906 my $self = $class->SUPER::new (
758 fg => [1, 1, 1], 907 fg => [1, 1, 1],
759 height => $::FONTSIZE, 908 height => $::FONTSIZE,
760 text => "", 909 text => "",
761 align => -1, 910 align => -1,
911 padding => 2,
762 layout => new CFClient::Layout, 912 layout => new CFClient::Layout,
763 %arg 913 %arg
764 ); 914 );
765 915
766 $self->set_text ($self->{text}); 916 $self->set_text ($self->{text});
767 917
797sub size_request { 947sub size_request {
798 my ($self) = @_; 948 my ($self) = @_;
799 949
800 $self->{layout}->set_width; 950 $self->{layout}->set_width;
801 $self->{layout}->set_height ($self->{height}); 951 $self->{layout}->set_height ($self->{height});
802 $self->{layout}->size 952 my ($w, $h) = $self->{layout}->size;
803# if ($self->{texture}{w} > 1 && $self->{texture}{height} > 1) { #TODO: hack 953
804# ( 954 (
805# $self->{texture}{w}, 955 $w + $self->{padding} * 2,
806# $self->{texture}{h}, 956 $h + $self->{padding} * 2,
807# ) 957 )
808# } else {
809# my ($w, $h, $data) = CFClient::font_render "Yy", $self->{h};
810#
811# ($w, $h)
812# }
813} 958}
814 959
815sub size_allocate { 960sub size_allocate {
816 my ($self, $w, $h) = @_; 961 my ($self, $x, $y, $w, $h) = @_;
817 962
818 return unless $self->{w} != $w || $self->{h} != $h; 963 $self->_size_allocate ($x, $y, $w, $h) or return;
819 964
820 $self->SUPER::size_allocate ($w, $h);
821 delete $self->{texture}; 965 delete $self->{texture};
822} 966}
823 967
824sub update { 968sub update {
825 my ($self) = @_; 969 my ($self) = @_;
831sub _draw { 975sub _draw {
832 my ($self) = @_; 976 my ($self) = @_;
833 977
834 my $tex = $self->{texture} ||= do { 978 my $tex = $self->{texture} ||= do {
835 $self->{layout}->set_width ($self->{w}); 979 $self->{layout}->set_width ($self->{w});
836 new_from_layout CFClient::Texture $self->{layout}; 980 new_from_layout CFClient::Texture $self->{layout}
837 }; 981 };
838 982
839 glEnable GL_BLEND; 983 glEnable GL_BLEND;
984 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
840 glEnable GL_TEXTURE_2D; 985 glEnable GL_TEXTURE_2D;
841 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
842 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 986 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
843 987
844 glColor @{$self->{fg}}; 988 glColor @{$self->{fg}};
845 989
846 my $x = 990 my $x =
847 $self->{align} < 0 ? 0 991 $self->{align} < 0 ? $self->{padding}
848 : $self->{align} > 0 ? $self->{w} - $self->{texture}{w} 992 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
849 : ($self->{w} + $self->{texture}{w}) * 0.5; 993 : ($self->{w} - $tex->{w}) * 0.5;
850 994
851 $tex->draw_quad ($x, 0); 995 $tex->draw_quad ($x, $self->{padding});
852 996
997 glDisable GL_TEXTURE_2D;
853 glDisable GL_BLEND; 998 glDisable GL_BLEND;
854 glDisable GL_TEXTURE_2D;
855} 999}
856 1000
857############################################################################# 1001#############################################################################
858 1002
859package CFClient::Widget::Entry; 1003package CFClient::UI::Entry;
860 1004
861our @ISA = CFClient::Widget::Label::; 1005our @ISA = CFClient::UI::Label::;
862 1006
863use SDL; 1007use SDL;
864use SDL::OpenGL; 1008use SDL::OpenGL;
865 1009
866sub new { 1010sub new {
867 my $class = shift; 1011 my $class = shift;
868 1012
869 $class->SUPER::new ( 1013 $class->SUPER::new (
870 fg => [1, 1, 1], 1014 fg => [1, 1, 1],
871 bg => [0, 0, 0, 0.4], 1015 bg => [0, 0, 0, 0.2],
872 active_bg => [1, 1, 1], 1016 active_bg => [1, 1, 1],
873 active_fg => [0, 0, 0], 1017 active_fg => [0, 0, 0],
874 @_ 1018 @_
875 ) 1019 )
876} 1020}
883 $self->{text} = $text; 1027 $self->{text} = $text;
884 $self->{layout}->set_width ($self->{w}); 1028 $self->{layout}->set_width ($self->{w});
885 1029
886 $text =~ s/./*/g if $self->{hidden}; 1030 $text =~ s/./*/g if $self->{hidden};
887 1031
888
889 $self->{layout}->set_markup ($self->escape_text ($text)); 1032 $self->{layout}->set_markup ($self->escape_text ($text) . " ");
890 1033
891 $text = substr $text, 0, $self->{cursor}; 1034 $text = substr $text, 0, $self->{cursor};
892 utf8::encode $text; 1035 utf8::encode $text;
893 1036
894 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); 1037 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
901 1044
902 ($w + 1, $h) # add 1 for cursor 1045 ($w + 1, $h) # add 1 for cursor
903} 1046}
904 1047
905sub size_allocate { 1048sub size_allocate {
906 my ($self, $w, $h) = @_; 1049 my ($self, $x, $y, $w, $h) = @_;
907 1050
908 return unless $self->{w} != $w || $self->{h} != $h;
909
910 $self->SUPER::size_allocate ($w, $h); 1051 $self->SUPER::size_allocate ($x, $y, $w, $h);
911 1052
912 $self->_set_text ($self->{text}); 1053 $self->_set_text ($self->{text});
913} 1054}
914 1055
915sub set_text { 1056sub set_text {
936 substr $text, $self->{cursor}, 1, ""; 1077 substr $text, $self->{cursor}, 1, "";
937 } elsif ($sym == SDLK_LEFT) { 1078 } elsif ($sym == SDLK_LEFT) {
938 --$self->{cursor} if $self->{cursor}; 1079 --$self->{cursor} if $self->{cursor};
939 } elsif ($sym == SDLK_RIGHT) { 1080 } elsif ($sym == SDLK_RIGHT) {
940 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1081 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1082 } elsif ($sym == SDLK_HOME) {
1083 $self->{cursor} = 0;
1084 } elsif ($sym == SDLK_END) {
1085 $self->{cursor} = length $text;
941 } elsif ($uni) { 1086 } elsif ($uni) {
942 substr $text, $self->{cursor}++, 0, chr $uni; 1087 substr $text, $self->{cursor}++, 0, chr $uni;
943 } 1088 }
944 1089
945 $self->_set_text ($text); 1090 $self->_set_text ($text);
960 $self->SUPER::button_down ($ev, $x, $y); 1105 $self->SUPER::button_down ($ev, $x, $y);
961 1106
962 my $idx = $self->{layout}->xy_to_index ($x, $y); 1107 my $idx = $self->{layout}->xy_to_index ($x, $y);
963 1108
964 # byte-index to char-index 1109 # byte-index to char-index
965 my $text = $self->{layout}; 1110 my $text = $self->{text};
966 utf8::encode $text; 1111 utf8::encode $text;
967 $self->{cursor} = length substr $text, 0, $idx; 1112 $self->{cursor} = length substr $text, 0, $idx;
968 1113
969 $self->_set_text ($self->{text}); 1114 $self->_set_text ($self->{text});
970 $self->update; 1115 $self->update;
985 $self->{fg} = $self->{active_fg}; 1130 $self->{fg} = $self->{active_fg};
986 } else { 1131 } else {
987 glColor @{$self->{bg}}; 1132 glColor @{$self->{bg}};
988 } 1133 }
989 1134
1135 glEnable GL_BLEND;
1136 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
990 glBegin GL_QUADS; 1137 glBegin GL_QUADS;
991 glVertex 0 , 0; 1138 glVertex 0 , 0;
992 glVertex 0 , $self->{h}; 1139 glVertex 0 , $self->{h};
993 glVertex $self->{w}, $self->{h}; 1140 glVertex $self->{w}, $self->{h};
994 glVertex $self->{w}, 0; 1141 glVertex $self->{w}, 0;
995 glEnd; 1142 glEnd;
1143 glDisable GL_BLEND;
996 1144
997 $self->SUPER::_draw; 1145 $self->SUPER::_draw;
998 1146
999 #TODO: force update every cursor change :( 1147 #TODO: force update every cursor change :(
1000 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { 1148 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) {
1006 } 1154 }
1007} 1155}
1008 1156
1009############################################################################# 1157#############################################################################
1010 1158
1011package CFClient::Widget::Slider; 1159package CFClient::UI::Slider;
1012 1160
1013use strict; 1161use strict;
1014 1162
1015use SDL::OpenGL; 1163use SDL::OpenGL;
1016use SDL::OpenGL::Constants;
1017 1164
1018our @ISA = CFClient::Widget::DrawBG::; 1165our @ISA = CFClient::UI::DrawBG::;
1019
1020sub size_request {
1021 my ($self) = @_;
1022
1023 my $w = 50;
1024 my $h = 10;
1025
1026 $self->{vertical} ? ($h, $w) : ($w, $h)
1027}
1028 1166
1029sub new { 1167sub new {
1030 my $class = shift; 1168 my $class = shift;
1031 1169
1032 # range [value, low, high, page] 1170 # range [value, low, high, page]
1033 1171
1034 $class->SUPER::new ( 1172 my $self = $class->SUPER::new (
1035 fg => [1, 1, 1], 1173 fg => [1, 1, 1],
1036 active_fg => [0, 0, 0], 1174 active_fg => [0, 0, 0],
1037 range => [0, 0, 100, 10], 1175 range => [0, 0, 100, 10],
1176 req_w => 40,
1177 req_h => 10,
1038 vertical => 1, 1178 vertical => 0,
1039 @_ 1179 @_
1040 ) 1180 );
1181
1182 $self
1183}
1184
1185sub size_request {
1186 my ($self) = @_;
1187
1188 my $w = $self->{req_w};
1189 my $h = $self->{req_h};
1190
1191 $self->{vertical} ? ($h, $w) : ($w, $h)
1041} 1192}
1042 1193
1043sub button_down { 1194sub button_down {
1044 my ($self, $ev, $x, $y) = @_; 1195 my ($self, $ev, $x, $y) = @_;
1045 1196
1120 glEnd; 1271 glEnd;
1121} 1272}
1122 1273
1123############################################################################# 1274#############################################################################
1124 1275
1125package CFClient::Widget::MapWidget; 1276package CFClient::UI::MapWidget;
1126 1277
1127use strict; 1278use strict;
1128 1279
1129use List::Util qw(min max); 1280use List::Util qw(min max);
1130 1281
1131use SDL; 1282use SDL;
1132use SDL::OpenGL; 1283use SDL::OpenGL;
1133use SDL::OpenGL::Constants;
1134 1284
1135our @ISA = CFClient::Widget::; 1285our @ISA = CFClient::UI::Base::;
1136 1286
1137sub new { 1287sub new {
1138 my $class = shift; 1288 my $class = shift;
1139 1289
1140 $class->SUPER::new ( 1290 $class->SUPER::new (
1151sub key_up { 1301sub key_up {
1152} 1302}
1153 1303
1154sub size_request { 1304sub size_request {
1155 ( 1305 (
1156 1 + int $::WIDTH / 32, 1306 1 + 32 * int $::WIDTH / 32,
1157 1 + int $::HEIGHT / 32, 1307 1 + 32 * int $::HEIGHT / 32,
1158 ) 1308 )
1159} 1309}
1160 1310
1161sub update { 1311sub update {
1162 my ($self) = @_; 1312 my ($self) = @_;
1163 1313
1164 $self->{need_update} = 1; 1314 $self->{need_update} = 1;
1315 $self->SUPER::update;
1165} 1316}
1166 1317
1167sub _draw { 1318sub draw {
1168 my ($self) = @_; 1319 my ($self) = @_;
1169 1320
1170 if (delete $self->{need_update}) { 1321 if (delete $self->{need_update}) {
1171 glNewList $self->{list}, GL_COMPILE; 1322 glNewList $self->{list}, GL_COMPILE;
1172 1323
1192 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; 1343 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs};
1193 } 1344 }
1194 1345
1195 glEnable GL_TEXTURE_2D; 1346 glEnable GL_TEXTURE_2D;
1196 glEnable GL_BLEND; 1347 glEnable GL_BLEND;
1348 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1197 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1349 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1198 1350
1199 my $sw4 = ($sw + 3) & ~3; 1351 my $sw4 = ($sw + 3) & ~3;
1200 my $darkness = "\x00" x ($sw4 * $sh); 1352 my $darkness = "\x00" x ($sw4 * $sh);
1201 1353
1231# 1383#
1232# $lighting = $pb->get_pixels; 1384# $lighting = $pb->get_pixels;
1233# $lighting =~ s/(.)../$1/gs; 1385# $lighting =~ s/(.)../$1/gs;
1234# } 1386# }
1235 1387
1236 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1237 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1388 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1238 1389
1239 $darkness = new CFClient::Texture 1390 $darkness = new CFClient::Texture
1240 width => $sw4, 1391 w => $sw4,
1241 height => $sh, 1392 h => $sh,
1242 data => $darkness, 1393 data => $darkness,
1243 internalformat => GL_ALPHA, 1394 internalformat => GL_ALPHA,
1244 format => GL_ALPHA; 1395 format => GL_ALPHA;
1245 1396
1246 glColor 0.45, 0.45, 0.45, 1; 1397 glColor 0.45, 0.45, 0.45, 1;
1306 } 1457 }
1307} 1458}
1308 1459
1309############################################################################# 1460#############################################################################
1310 1461
1311package CFClient::Widget::Animator; 1462package CFClient::UI::Animator;
1312 1463
1313use SDL::OpenGL; 1464use SDL::OpenGL;
1314 1465
1315our @ISA = CFClient::Widget::Bin::; 1466our @ISA = CFClient::UI::Bin::;
1316 1467
1317sub moveto { 1468sub moveto {
1318 my ($self, $x, $y) = @_; 1469 my ($self, $x, $y) = @_;
1319 1470
1320 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 1471 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
1348 glPopMatrix; 1499 glPopMatrix;
1349} 1500}
1350 1501
1351############################################################################# 1502#############################################################################
1352 1503
1353package CFClient::Widget::Toplevel; 1504package CFClient::UI::Toplevel;
1354 1505
1355our @ISA = CFClient::Widget::Container::; 1506our @ISA = CFClient::UI::Container::;
1356 1507
1357sub size_request { 1508sub size_request {
1358 ($::WIDTH, $::HEIGHT) 1509 ($::WIDTH, $::HEIGHT)
1359} 1510}
1360 1511
1361sub size_allocate { 1512sub size_allocate {
1362 my ($self, $w, $h) = @_; 1513 my ($self, $x, $y, $w, $h) = @_;
1363 1514
1364 $self->SUPER::size_allocate ($w, $h); 1515 $self->_size_allocate ($x, $y, $w, $h);
1365 1516
1366 $_->size_allocate ($_->size_request) 1517 $_->size_allocate ($_->{x}, $_->{y}, $_->size_request)
1367 for @{$self->{children}}; 1518 for @{$self->{children}};
1368} 1519}
1369 1520
1370sub translate { 1521sub translate {
1371 my ($self, $x, $y) = @_; 1522 my ($self, $x, $y) = @_;
1374} 1525}
1375 1526
1376sub update { 1527sub update {
1377 my ($self) = @_; 1528 my ($self) = @_;
1378 1529
1379 $self->size_allocate ($self->size_request); 1530 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT);
1380 ::refresh (); 1531 ::refresh ();
1381} 1532}
1382 1533
1383sub add { 1534sub add {
1384 my ($self, $widget) = @_; 1535 my ($self, $widget) = @_;
1385 1536
1386 $self->SUPER::add ($widget); 1537 $self->SUPER::add ($widget);
1387 1538
1388 $widget->size_allocate ($widget->size_request); 1539 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request);
1389} 1540}
1390 1541
1391sub draw { 1542sub draw {
1392 my ($self) = @_; 1543 my ($self) = @_;
1393 1544
1394 $self->_draw; 1545 $self->_draw;
1395} 1546}
1396 1547
1397############################################################################# 1548#############################################################################
1398 1549
1399package CFClient::Widget; 1550package CFClient::UI;
1400 1551
1401$TOPLEVEL = new CFClient::Widget::Toplevel; 1552$TOPLEVEL = new CFClient::UI::Toplevel;
1402 1553
14031 15541
1404 1555

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines