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.197 by root, Fri May 12 01:47:04 2006 UTC vs.
Revision 1.201 by root, Sat May 13 23:17:49 2006 UTC

252 my ($self) = @_; 252 my ($self) = @_;
253 253
254 $_->reconfigure 254 $_->reconfigure
255 for $self->children; 255 for $self->children;
256 256
257 $self->check_size; 257 $self->check_size (1);
258 $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $self->{w}, $self->{h}];
259 $self->update; 258 $self->update;
260} 259}
261 260
262sub set_max_size { 261sub set_max_size {
263 my ($self, $w, $h) = @_; 262 my ($self, $w, $h) = @_;
384sub set_parent { 383sub set_parent {
385 my ($self, $parent) = @_; 384 my ($self, $parent) = @_;
386 385
387 Scalar::Util::weaken ($self->{parent} = $parent); 386 Scalar::Util::weaken ($self->{parent} = $parent);
388 387
388 # TODO: req_w _does_change after ->reconfigure
389 $self->check_size 389 $self->check_size
390 unless exists $self->{req_w}; 390 unless exists $self->{req_w};
391} 391}
392 392
393sub check_size { 393sub check_size {
628} 628}
629 629
630sub update { 630sub update {
631 my ($self) = @_; 631 my ($self) = @_;
632 632
633 $ROOT->on_refresh ($self => sub { $self->render_child }); 633 $ROOT->on_post_alloc ($self => sub { $self->render_child });
634 $self->SUPER::update; 634 $self->SUPER::update;
635} 635}
636 636
637sub size_allocate { 637sub size_allocate {
638 my ($self, $w, $h) = @_; 638 my ($self, $w, $h) = @_;
776 $self->add ($self->{slider}); 776 $self->add ($self->{slider});
777 777
778 $self 778 $self
779} 779}
780 780
781#TODO# update range on size_allocate depeneing on child 781#TODO# update range on size_allocate depending on child
782# update viewport offset on scroll 782# update viewport offset on scroll
783 783
784############################################################################# 784#############################################################################
785 785
786package CFClient::UI::Frame; 786package CFClient::UI::Frame;
787 787
788our @ISA = CFClient::UI::Bin::; 788our @ISA = CFClient::UI::Bin::;
789 789
790use CFClient::OpenGL; 790use CFClient::OpenGL;
791
792sub new {
793 my $class = shift;
794
795 $class->SUPER::new (
796 bg => undef,
797 @_,
798 )
799}
800
801sub _draw {
802 my ($self) = @_;
803
804 if ($self->{bg}) {
805 my ($w, $h) = @$self{qw(w h)};
806
807 glEnable GL_BLEND;
808 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
809 glColor @{ $self->{bg} };
810
811 glBegin GL_QUADS;
812 glVertex 0 , 0;
813 glVertex 0 , $h;
814 glVertex $w, $h;
815 glVertex $w, 0;
816 glEnd;
817
818 glDisable GL_BLEND;
819 }
820
821 $self->SUPER::_draw;
822}
791 823
792############################################################################# 824#############################################################################
793 825
794package CFClient::UI::FancyFrame; 826package CFClient::UI::FancyFrame;
795 827
1448 my $sym = $ev->{sym}; 1480 my $sym = $ev->{sym};
1449 my $uni = $ev->{unicode}; 1481 my $uni = $ev->{unicode};
1450 1482
1451 my $text = $self->get_text; 1483 my $text = $self->get_text;
1452 1484
1453 if ($sym == 8) { 1485 if ($uni == 8) {
1454 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1486 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1455 } elsif ($sym == 127) { 1487 } elsif ($uni == 127) {
1456 substr $text, $self->{cursor}, 1, ""; 1488 substr $text, $self->{cursor}, 1, "";
1457 } elsif ($sym == CFClient::SDLK_LEFT) { 1489 } elsif ($sym == CFClient::SDLK_LEFT) {
1458 --$self->{cursor} if $self->{cursor}; 1490 --$self->{cursor} if $self->{cursor};
1459 } elsif ($sym == CFClient::SDLK_RIGHT) { 1491 } elsif ($sym == CFClient::SDLK_RIGHT) {
1460 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1492 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1461 } elsif ($sym == CFClient::SDLK_HOME) { 1493 } elsif ($sym == CFClient::SDLK_HOME) {
1462 $self->{cursor} = 0; 1494 $self->{cursor} = 0;
1463 } elsif ($sym == CFClient::SDLK_END) { 1495 } elsif ($sym == CFClient::SDLK_END) {
1464 $self->{cursor} = length $text; 1496 $self->{cursor} = length $text;
1465 } elsif ($sym == 27) { 1497 } elsif ($uni == 27) {
1466 $self->emit ('escape'); 1498 $self->emit ('escape');
1467 } elsif ($uni) { 1499 } elsif ($uni) {
1468 substr $text, $self->{cursor}++, 0, chr $uni; 1500 substr $text, $self->{cursor}++, 0, chr $uni;
1469 } 1501 }
1470 1502
2165 2197
2166 return unless $self->{h} > 0; 2198 return unless $self->{h} > 0;
2167 2199
2168 delete $self->{texture}; 2200 delete $self->{texture};
2169 2201
2170 $ROOT->on_refresh ($self, sub { 2202 $ROOT->on_post_alloc ($self, sub {
2171 if (delete $self->{need_reflow}) { 2203 if (delete $self->{need_reflow}) {
2172 my $height = 0; 2204 my $height = 0;
2173 2205
2174 $height += $_->[0] = $self->text_height ($_->[2]) 2206 $height += $_->[0] = $self->text_height ($_->[2])
2175 for @{$self->{par}}; 2207 for @{$self->{par}};
2506 my ($self, $items) = @_; 2538 my ($self, $items) = @_;
2507 2539
2508 $self->{scrolled}->clear; 2540 $self->{scrolled}->clear;
2509 return unless $items; 2541 return unless $items;
2510 2542
2511 my @items = sort { $a->{type} <=> $b->{type} } @$items; 2543 my @items = sort {
2544 ($a->{type} <=> $b->{type})
2545 or ($a->{name} cmp $b->{name})
2546 } @$items;
2512 2547
2513 $self->{real_items} = \@items; 2548 $self->{real_items} = \@items;
2514 2549
2515 for my $item (@items) { 2550 for my $item (@items) {
2516 my $desc = $item->{nrof} < 2 2551 my $desc = $item->{nrof} < 2
2517 ? $item->{name} 2552 ? $item->{name}
2518 : "$item->{nrof} $item->{name_pl}"; 2553 : "$item->{nrof} $item->{name_pl}";
2519 2554
2520 $self->{scrolled}->add ($item->{widget} ||= new CFClient::UI::InventoryItem item => $item); 2555 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2521 } 2556 }
2557
2558 $self->{scrolled}->add (@items);
2522 2559
2523# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2560# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2524} 2561}
2525 2562
2526sub size_request { 2563sub size_request {
2632 : $item->{text}; 2669 : $item->{text};
2633 2670
2634 for ($short) { 2671 for ($short) {
2635 s/^\s+//; 2672 s/^\s+//;
2636 s/\012.*/…/s; 2673 s/\012.*/…/s;
2637 my $len = int 30 / $item->{fontsize}; 2674 my $len = int 40 / $item->{fontsize};
2638 substr $_, $len, length, "…" if $len < length; 2675 substr $_, $len, length, "…" if $len < length;
2639 } 2676 }
2640 2677
2641 new CFClient::UI::Label 2678 new CFClient::UI::Label
2642 markup => $short, 2679 markup => $short,
2655} 2692}
2656 2693
2657sub add { 2694sub add {
2658 my ($self, $text, %arg) = @_; 2695 my ($self, $text, %arg) = @_;
2659 2696
2697 $text =~ s/^\s+//;
2698 $text =~ s/\s+$//;
2699
2660 my $timeout = time + ((delete $arg{timeout}) || 60); 2700 my $timeout = time + ((delete $arg{timeout}) || 60);
2661 2701
2662 my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; 2702 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
2663 2703
2664 if (my $item = $self->{item}{$group}) { 2704 if (my $item = $self->{item}{$group}) {
2666 $item->{count}++; 2706 $item->{count}++;
2667 } else { 2707 } else {
2668 $item->{count} = 1; 2708 $item->{count} = 1;
2669 $item->{text} = $item->{tooltip} = $text; 2709 $item->{text} = $item->{tooltip} = $text;
2670 } 2710 }
2711 $item->{id} = ++$self->{id};
2671 $item->{timeout} = $timeout; 2712 $item->{timeout} = $timeout;
2672 delete $item->{label}; 2713 delete $item->{label};
2673 } else { 2714 } else {
2674 $self->{item}{$group} = { 2715 $self->{item}{$group} = {
2675 id => ++$self->{id}, 2716 id => ++$self->{id},
2787 my ($self, $id, $cb) = @_; 2828 my ($self, $id, $cb) = @_;
2788 2829
2789 $self->{refresh_hook}{$id} = $cb; 2830 $self->{refresh_hook}{$id} = $cb;
2790} 2831}
2791 2832
2833sub on_post_alloc {
2834 my ($self, $id, $cb) = @_;
2835
2836 $self->{post_alloc_hook}{$id} = $cb;
2837}
2838
2792sub draw { 2839sub draw {
2793 my ($self) = @_; 2840 my ($self) = @_;
2841
2842 while ($self->{refresh_hook}) {
2843 $_->()
2844 for values %{delete $self->{refresh_hook}};
2845 }
2794 2846
2795 if ($self->{check_size}) { 2847 if ($self->{check_size}) {
2796 my @queue = ([], []); 2848 my @queue = ([], []);
2797 2849
2798 for (;;) { 2850 for (;;) {
2835 $widget->size_allocate ($w, $h); 2887 $widget->size_allocate ($w, $h);
2836 $widget->emit (size_allocate => $w, $h); 2888 $widget->emit (size_allocate => $w, $h);
2837 } 2889 }
2838 } 2890 }
2839 2891
2840 while ($self->{refresh_hook}) { 2892 while ($self->{post_alloc_hook}) {
2841 $_->() 2893 $_->()
2842 for values %{delete $self->{refresh_hook}}; 2894 for values %{delete $self->{post_alloc_hook}};
2843 } 2895 }
2844 2896
2845 glViewport 0, 0, $::WIDTH, $::HEIGHT; 2897 glViewport 0, 0, $::WIDTH, $::HEIGHT;
2846 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 2898 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2847 glClear GL_COLOR_BUFFER_BIT; 2899 glClear GL_COLOR_BUFFER_BIT;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines