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.398 by root, Sat Jul 21 14:32:10 2007 UTC vs.
Revision 1.408 by root, Sun Jul 22 15:26:01 2007 UTC

593 593
594# using global variables seems a bit hacky, but passing through all drawing 594# using global variables seems a bit hacky, but passing through all drawing
595# functions seems pointless. 595# functions seems pointless.
596our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn 596our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn
597 597
598sub draw { 598#sub draw {
599 my ($self) = @_; 599#CFPlus.xs
600
601 return unless $self->{h} && $self->{w};
602
603 # update screen rectangle
604 local $draw_x = $draw_x + $self->{x};
605 local $draw_y = $draw_y + $self->{y};
606
607 # skip widgets that are entirely outside the drawing area
608 return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w)
609 || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h);
610
611 glPushMatrix;
612 glTranslate $self->{x}, $self->{y}, 0;
613
614 if ($self == $HOVER && $self->{can_hover}) {
615 glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2;
616 glEnable GL_BLEND;
617 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
618 glBegin GL_QUADS;
619 glVertex 0 , 0;
620 glVertex $self->{w}, 0;
621 glVertex $self->{w}, $self->{h};
622 glVertex 0 , $self->{h};
623 glEnd;
624 glDisable GL_BLEND;
625 }
626
627 if ($ENV{CFPLUS_DEBUG} & 1) {
628 glPushMatrix;
629 glColor 1, 1, 0, 1;
630 glTranslate 0.375, 0.375;
631 glBegin GL_LINE_LOOP;
632 glVertex 0 , 0;
633 glVertex $self->{w} - 1, 0;
634 glVertex $self->{w} - 1, $self->{h} - 1;
635 glVertex 0 , $self->{h} - 1;
636 glEnd;
637 glPopMatrix;
638 #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
639 }
640
641 $self->_draw;
642 glPopMatrix;
643}
644 600
645sub _draw { 601sub _draw {
646 my ($self) = @_; 602 my ($self) = @_;
647 603
648 warn "no draw defined for $self\n"; 604 warn "no draw defined for $self\n";
649} 605}
650 606
651my $cntx;#d#
652sub DESTROY { 607sub DESTROY {
653 my ($self) = @_; 608 my ($self) = @_;
654 609
655 return if CFPlus::in_destruct; 610 return if CFPlus::in_destruct;
656 611
769 sort { $a->{z} <=> $b->{z} } 724 sort { $a->{z} <=> $b->{z} }
770 @{$self->{children}}, @widgets 725 @{$self->{children}}, @widgets
771 ]; 726 ];
772 727
773 $self->realloc; 728 $self->realloc;
729
730 map $_+0, @widgets
774} 731}
775 732
776sub children { 733sub children {
777 @{ $_[0]{children} } 734 @{ $_[0]{children} }
778} 735}
1093 $vp->{parent}{hslider}->set_value ($x); 1050 $vp->{parent}{hslider}->set_value ($x);
1094 $vp->{parent}{vslider}->set_value ($y); 1051 $vp->{parent}{vslider}->set_value ($y);
1095 1052
1096 0 1053 0
1097 }, 1054 },
1055 on_size_allocate => sub {
1056 my ($vp, $w, $h) = @_;
1057 $vp->{parent}->update_slider;
1058 0
1059 },
1098 ; 1060 ;
1099 1061
1100 $self->SUPER::add ($self->{vp}); 1062 $self->SUPER::add ($self->{vp});
1101 1063
1102 $self->add ($child) if $child; 1064 $self->add ($child) if $child;
1113sub update_slider { 1075sub update_slider {
1114 my ($self) = @_; 1076 my ($self) = @_;
1115 1077
1116 my $child = ($self->{vp} or return)->child; 1078 my $child = ($self->{vp} or return)->child;
1117 1079
1080 if ($self->{scroll_x}) {
1118 my ($w1, $w2) = ($child->{w}, $self->{vp}{w}); 1081 my ($w1, $w2) = ($child->{req_w}, $self->{vp}{w});
1119 $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); 1082 $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]);
1120 1083
1121 my $visible = $w1 > $w2; 1084 my $visible = $w1 > $w2;
1122 if ($visible != $self->{hslider_visible}) { 1085 if ($visible != $self->{hslider_visible}) {
1123 $self->{hslider_visible} = $visible; 1086 $self->{hslider_visible} = $visible;
1124 $visible ? $self->SUPER::add ($self->{hslider}) 1087 $visible ? $self->SUPER::add ($self->{hslider})
1125 : $self->SUPER::remove ($self->{hslider}); 1088 : $self->SUPER::remove ($self->{hslider});
1089 }
1126 } 1090 }
1127 1091
1092 if ($self->{scroll_y}) {
1128 my ($h1, $h2) = ($child->{h}, $self->{vp}{h}); 1093 my ($h1, $h2) = ($child->{req_h}, $self->{vp}{h});
1129 $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); 1094 $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]);
1130 1095
1131 my $visible = $h1 > $h2; 1096 my $visible = $h1 > $h2;
1132 if ($visible != $self->{vslider_visible}) { 1097 if ($visible != $self->{vslider_visible}) {
1133 $self->{vslider_visible} = $visible; 1098 $self->{vslider_visible} = $visible;
1134 $visible ? $self->SUPER::add ($self->{vslider}) 1099 $visible ? $self->SUPER::add ($self->{vslider})
1135 : $self->SUPER::remove ($self->{vslider}); 1100 : $self->SUPER::remove ($self->{vslider});
1101 }
1136 } 1102 }
1137} 1103}
1138 1104
1139sub start_dragging { 1105sub start_dragging {
1140 my ($self, $ev) = @_; 1106 my ($self, $ev) = @_;
1720 1686
1721use List::Util qw(min max); 1687use List::Util qw(min max);
1722 1688
1723our @ISA = CFPlus::UI::Container::; 1689our @ISA = CFPlus::UI::Container::;
1724 1690
1725sub add { 1691sub add_fixed {
1726 my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; 1692 my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_;
1727 1693
1728 $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; 1694 $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h];
1729 $self->SUPER::add ($child); 1695 $self->SUPER::add ($child);
1730} 1696}
1785 for my $child ($self->visible_children) { 1751 for my $child ($self->visible_children) {
1786 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; 1752 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} };
1787 1753
1788 $x = _scale $pos, $x, $W; 1754 $x = _scale $pos, $x, $W;
1789 $y = _scale $pos, $x, $H; 1755 $y = _scale $pos, $x, $H;
1790 $w = _scale $size, $w, $child->{req_w}; 1756 $w = _scale $size, $w, $W;
1791 $h = _scale $size, $h, $child->{req_h}; 1757 $h = _scale $size, $h, $H;
1792 1758
1793 $child->configure ($x, $y, $w, $h); 1759 $child->configure ($x, $y, $w, $h);
1794 } 1760 }
1795 1761
1796 1 1762 1
2061 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} 2027 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
2062 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} 2028 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y}
2063 : ($self->{h} - $size->[1]) * 0.5); 2029 : ($self->{h} - $size->[1]) * 0.5);
2064 }; 2030 };
2065 2031
2066 my $w = List::Util::min $self->{w} + 4, $size->[0]; 2032# unless ($self->{list}) {
2067 my $h = List::Util::min $self->{h} + 2, $size->[1]; 2033# $self->{list} = CFPlus::OpenGL::glGenList;
2034# CFPlus::OpenGL::glNewList $self->{list};
2035# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2036# CFPlus::OpenGL::glEndList;
2037# }
2038#
2039# CFPlus::OpenGL::glCallList $self->{list};
2068 2040
2069 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2041 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2070} 2042}
2043
2044#sub destroy {
2045# my ($self) = @_;
2046#
2047# CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list};
2048#
2049# $self->SUPER::destroy;
2050#}
2071 2051
2072############################################################################# 2052#############################################################################
2073 2053
2074package CFPlus::UI::EntryBase; 2054package CFPlus::UI::EntryBase;
2075 2055
3473 3453
3474 if ($self->{anim} && $self->{animspeed}) { 3454 if ($self->{anim} && $self->{animspeed}) {
3475 CFPlus::weaken (my $widget = $self); 3455 CFPlus::weaken (my $widget = $self);
3476 3456
3477 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; 3457 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3478 $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed}; 3458 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed};
3479 $self->{timer} = Event->timer ( 3459 $self->{timer} = Event->timer (
3480 parked => 1, 3460 parked => 1,
3481 cb => sub { 3461 cb => sub {
3482 return unless $::CONN && $widget; 3462 return unless $::CONN && $widget;
3483 3463
3520 3500
3521 if (my $anim = $::CONN->{anim}[$self->{anim}]) { 3501 if (my $anim = $::CONN->{anim}[$self->{anim}]) {
3522 if ($anim && @$anim) { 3502 if ($anim && @$anim) {
3523 delete $self->{wait_face}; 3503 delete $self->{wait_face};
3524 $self->{face} = $anim->[ $self->{frame} % @$anim ]; 3504 $self->{face} = $anim->[ $self->{frame} % @$anim ];
3505 $self->{tex} = $::CONN->{texture}[ $::CONN->{faceid}[$self->{face}] ];
3525 } 3506 }
3526 } 3507 }
3527} 3508}
3528 3509
3529sub size_request { 3510sub size_request {
3530 my ($self) = @_; 3511 my ($self) = @_;
3531 3512
3532 if ($::CONN) { 3513 if ($::CONN) {
3533 if (my $faceid = $::CONN->{faceid}[$self->{face}]) { 3514 if (my $faceid = $::CONN->{faceid}[$self->{face}]) {
3534 if (my $tex = $::CONN->{texture}[$faceid]) { 3515 if (my $tex = $::CONN->{texture}[$faceid]) {
3516 $self->{tex} = $tex;
3535 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); 3517 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h});
3536 } else { 3518 } else {
3537 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { 3519 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub {
3538 $self->realloc; 3520 $self->realloc;
3539 }); 3521 });
3561} 3543}
3562 3544
3563sub _draw { 3545sub _draw {
3564 my ($self) = @_; 3546 my ($self) = @_;
3565 3547
3566 return unless $::CONN;
3567
3568 $self->SUPER::_draw; 3548 $self->SUPER::_draw;
3569 3549
3570 my $faceid = $::CONN->{faceid}[$self->{face}] 3550 if (my $tex = $self->{tex}) {
3571 or return;
3572
3573 my $tex = $::CONN->{texture}[$faceid];
3574
3575 if ($tex) {
3576 glEnable GL_TEXTURE_2D; 3551 glEnable GL_TEXTURE_2D;
3577 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 3552 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
3578 glColor 0, 0, 0, 1; 3553 glColor 0, 0, 0, 1;
3579 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 3554 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
3580 glDisable GL_TEXTURE_2D; 3555 glDisable GL_TEXTURE_2D;
3790sub add { 3765sub add {
3791 my ($self, $title, $widget, $tooltip) = @_; 3766 my ($self, $title, $widget, $tooltip) = @_;
3792 3767
3793 CFPlus::weaken $self; 3768 CFPlus::weaken $self;
3794 3769
3795 $self->{buttonbar}->add (new CFPlus::UI::Button 3770 unless (ref $title) {
3771 $title = new CFPlus::UI::Button
3796 markup => $title, 3772 markup => $title,
3797 tooltip => $tooltip, 3773 tooltip => $tooltip,
3774 );
3775 }
3776
3798 on_activate => sub { $self->set_current_page ($widget) }, 3777 $title->connect (activate => sub { $self->set_current_page ($widget) });
3799 ); 3778 $self->{buttonbar}->add ($title);
3800 3779
3801 $self->{multiplexer}->add ($widget); 3780 $self->{multiplexer}->add ($widget);
3802} 3781}
3803 3782
3804sub get_current_page { 3783sub get_current_page {
4136 while ($self->{refresh_hook}) { 4115 while ($self->{refresh_hook}) {
4137 $_->() 4116 $_->()
4138 for values %{delete $self->{refresh_hook}}; 4117 for values %{delete $self->{refresh_hook}};
4139 } 4118 }
4140 4119
4141 if ($self->{realloc}) { 4120 while ($self->{realloc}) {
4142 my %queue; 4121 my %queue;
4143 my @queue; 4122 my @queue;
4144 my $widget; 4123 my $widget;
4145 4124
4146 outer: 4125 outer:
4193 } 4172 }
4194 } 4173 }
4195 4174
4196 delete $self->{realloc}{$widget+0}; 4175 delete $self->{realloc}{$widget+0};
4197 } 4176 }
4198 }
4199 4177
4200 while (my $size_alloc = delete $self->{size_alloc}) { 4178 while (my $size_alloc = delete $self->{size_alloc}) {
4201 my @queue = sort { $b->{visible} <=> $a->{visible} } 4179 my @queue = sort { $a->{visible} <=> $b->{visible} }
4202 values %$size_alloc; 4180 values %$size_alloc;
4203 4181
4204 while () { 4182 while () {
4205 my $widget = pop @queue || last; 4183 my $widget = pop @queue || last;
4206 4184
4207 my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; 4185 my ($w, $h) = @$widget{qw(alloc_w alloc_h)};
4208 4186
4209 $w = 0 if $w < 0;
4210 $h = 0 if $h < 0;
4211
4212 $w = max $widget->{min_w}, $w; 4187 $w = max $widget->{min_w}, $w;
4213 $h = max $widget->{min_h}, $h; 4188 $h = max $widget->{min_h}, $h;
4214 4189
4215# $w = min $self->{w} - $widget->{x}, $w if $self->{w}; 4190# $w = min $self->{w} - $widget->{x}, $w if $self->{w};
4216# $h = min $self->{h} - $widget->{y}, $h if $self->{h}; 4191# $h = min $self->{h} - $widget->{y}, $h if $self->{h};
4217 4192
4218 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 4193 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
4219 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 4194 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
4220 4195
4221 $w = int $w + 0.5; 4196 $w = int $w + 0.5;
4222 $h = int $h + 0.5; 4197 $h = int $h + 0.5;
4223 4198
4224 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { 4199 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) {
4225 $widget->{old_w} = $widget->{w}; 4200 $widget->{old_w} = $widget->{w};
4226 $widget->{old_h} = $widget->{h}; 4201 $widget->{old_h} = $widget->{h};
4227 4202
4228 $widget->{w} = $w; 4203 $widget->{w} = $w;
4229 $widget->{h} = $h; 4204 $widget->{h} = $h;
4230 4205
4231 $widget->emit (size_allocate => $w, $h); 4206 $widget->emit (size_allocate => $w, $h);
4207 }
4232 } 4208 }
4233 } 4209 }
4234 } 4210 }
4235 4211
4236 while ($self->{post_alloc_hook}) { 4212 while ($self->{post_alloc_hook}) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines