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.399 by root, Sat Jul 21 16:07:53 2007 UTC vs.
Revision 1.406 by root, Sat Jul 21 23:17:35 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
1095 $vp->{parent}{hslider}->set_value ($x); 1050 $vp->{parent}{hslider}->set_value ($x);
1096 $vp->{parent}{vslider}->set_value ($y); 1051 $vp->{parent}{vslider}->set_value ($y);
1097 1052
1098 0 1053 0
1099 }, 1054 },
1055 on_size_allocate => sub {
1056 my ($vp, $w, $h) = @_;
1057 $vp->{parent}->update_slider;
1058 0
1059 },
1100 ; 1060 ;
1101 1061
1102 $self->SUPER::add ($self->{vp}); 1062 $self->SUPER::add ($self->{vp});
1103 1063
1104 $self->add ($child) if $child; 1064 $self->add ($child) if $child;
1115sub update_slider { 1075sub update_slider {
1116 my ($self) = @_; 1076 my ($self) = @_;
1117 1077
1118 my $child = ($self->{vp} or return)->child; 1078 my $child = ($self->{vp} or return)->child;
1119 1079
1080 if ($self->{scroll_x}) {
1120 my ($w1, $w2) = ($child->{w}, $self->{vp}{w}); 1081 my ($w1, $w2) = ($child->{req_w}, $self->{vp}{w});
1121 $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]);
1122 1083
1123 my $visible = $w1 > $w2; 1084 my $visible = $w1 > $w2;
1124 if ($visible != $self->{hslider_visible}) { 1085 if ($visible != $self->{hslider_visible}) {
1125 $self->{hslider_visible} = $visible; 1086 $self->{hslider_visible} = $visible;
1126 $visible ? $self->SUPER::add ($self->{hslider}) 1087 $visible ? $self->SUPER::add ($self->{hslider})
1127 : $self->SUPER::remove ($self->{hslider}); 1088 : $self->SUPER::remove ($self->{hslider});
1089 }
1128 } 1090 }
1129 1091
1092 if ($self->{scroll_y}) {
1130 my ($h1, $h2) = ($child->{h}, $self->{vp}{h}); 1093 my ($h1, $h2) = ($child->{req_h}, $self->{vp}{h});
1131 $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]);
1132 1095
1133 my $visible = $h1 > $h2; 1096 my $visible = $h1 > $h2;
1134 if ($visible != $self->{vslider_visible}) { 1097 if ($visible != $self->{vslider_visible}) {
1135 $self->{vslider_visible} = $visible; 1098 $self->{vslider_visible} = $visible;
1136 $visible ? $self->SUPER::add ($self->{vslider}) 1099 $visible ? $self->SUPER::add ($self->{vslider})
1137 : $self->SUPER::remove ($self->{vslider}); 1100 : $self->SUPER::remove ($self->{vslider});
1101 }
1138 } 1102 }
1139} 1103}
1140 1104
1141sub start_dragging { 1105sub start_dragging {
1142 my ($self, $ev) = @_; 1106 my ($self, $ev) = @_;
1722 1686
1723use List::Util qw(min max); 1687use List::Util qw(min max);
1724 1688
1725our @ISA = CFPlus::UI::Container::; 1689our @ISA = CFPlus::UI::Container::;
1726 1690
1727sub add { 1691sub add_fixed {
1728 my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; 1692 my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_;
1729 1693
1730 $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; 1694 $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h];
1731 $self->SUPER::add ($child); 1695 $self->SUPER::add ($child);
1732} 1696}
1787 for my $child ($self->visible_children) { 1751 for my $child ($self->visible_children) {
1788 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; 1752 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} };
1789 1753
1790 $x = _scale $pos, $x, $W; 1754 $x = _scale $pos, $x, $W;
1791 $y = _scale $pos, $x, $H; 1755 $y = _scale $pos, $x, $H;
1792 $w = _scale $size, $w, $child->{req_w}; 1756 $w = _scale $size, $w, $W;
1793 $h = _scale $size, $h, $child->{req_h}; 1757 $h = _scale $size, $h, $H;
1794 1758
1795 $child->configure ($x, $y, $w, $h); 1759 $child->configure ($x, $y, $w, $h);
1796 } 1760 }
1797 1761
1798 1 1762 1
2062 2026
2063 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} 2027 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
2064 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} 2028 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y}
2065 : ($self->{h} - $size->[1]) * 0.5); 2029 : ($self->{h} - $size->[1]) * 0.5);
2066 }; 2030 };
2067
2068 my $w = List::Util::min $self->{w} + 4, $size->[0];
2069 my $h = List::Util::min $self->{h} + 2, $size->[1];
2070 2031
2071 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2032 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2072} 2033}
2073 2034
2074############################################################################# 2035#############################################################################
3475 3436
3476 if ($self->{anim} && $self->{animspeed}) { 3437 if ($self->{anim} && $self->{animspeed}) {
3477 CFPlus::weaken (my $widget = $self); 3438 CFPlus::weaken (my $widget = $self);
3478 3439
3479 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; 3440 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3480 $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed}; 3441 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed};
3481 $self->{timer} = Event->timer ( 3442 $self->{timer} = Event->timer (
3482 parked => 1, 3443 parked => 1,
3483 cb => sub { 3444 cb => sub {
3484 return unless $::CONN && $widget; 3445 return unless $::CONN && $widget;
3485 3446
3522 3483
3523 if (my $anim = $::CONN->{anim}[$self->{anim}]) { 3484 if (my $anim = $::CONN->{anim}[$self->{anim}]) {
3524 if ($anim && @$anim) { 3485 if ($anim && @$anim) {
3525 delete $self->{wait_face}; 3486 delete $self->{wait_face};
3526 $self->{face} = $anim->[ $self->{frame} % @$anim ]; 3487 $self->{face} = $anim->[ $self->{frame} % @$anim ];
3488 $self->{tex} = $::CONN->{texture}[ $::CONN->{faceid}[$self->{face}] ];
3527 } 3489 }
3528 } 3490 }
3529} 3491}
3530 3492
3531sub size_request { 3493sub size_request {
3532 my ($self) = @_; 3494 my ($self) = @_;
3533 3495
3534 if ($::CONN) { 3496 if ($::CONN) {
3535 if (my $faceid = $::CONN->{faceid}[$self->{face}]) { 3497 if (my $faceid = $::CONN->{faceid}[$self->{face}]) {
3536 if (my $tex = $::CONN->{texture}[$faceid]) { 3498 if (my $tex = $::CONN->{texture}[$faceid]) {
3499 $self->{tex} = $tex;
3537 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); 3500 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h});
3538 } else { 3501 } else {
3539 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { 3502 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub {
3540 $self->realloc; 3503 $self->realloc;
3541 }); 3504 });
3563} 3526}
3564 3527
3565sub _draw { 3528sub _draw {
3566 my ($self) = @_; 3529 my ($self) = @_;
3567 3530
3568 return unless $::CONN;
3569
3570 $self->SUPER::_draw; 3531 $self->SUPER::_draw;
3571 3532
3572 my $faceid = $::CONN->{faceid}[$self->{face}] 3533 if (my $tex = $self->{tex}) {
3573 or return;
3574
3575 my $tex = $::CONN->{texture}[$faceid];
3576
3577 if ($tex) {
3578 glEnable GL_TEXTURE_2D; 3534 glEnable GL_TEXTURE_2D;
3579 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 3535 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
3580 glColor 0, 0, 0, 1; 3536 glColor 0, 0, 0, 1;
3581 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 3537 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
3582 glDisable GL_TEXTURE_2D; 3538 glDisable GL_TEXTURE_2D;
4138 while ($self->{refresh_hook}) { 4094 while ($self->{refresh_hook}) {
4139 $_->() 4095 $_->()
4140 for values %{delete $self->{refresh_hook}}; 4096 for values %{delete $self->{refresh_hook}};
4141 } 4097 }
4142 4098
4143 if ($self->{realloc}) { 4099 while ($self->{realloc}) {
4144 my %queue; 4100 my %queue;
4145 my @queue; 4101 my @queue;
4146 my $widget; 4102 my $widget;
4147 4103
4148 outer: 4104 outer:
4195 } 4151 }
4196 } 4152 }
4197 4153
4198 delete $self->{realloc}{$widget+0}; 4154 delete $self->{realloc}{$widget+0};
4199 } 4155 }
4200 }
4201 4156
4202 while (my $size_alloc = delete $self->{size_alloc}) { 4157 while (my $size_alloc = delete $self->{size_alloc}) {
4203 my @queue = sort { $b->{visible} <=> $a->{visible} } 4158 my @queue = sort { $a->{visible} <=> $b->{visible} }
4204 values %$size_alloc; 4159 values %$size_alloc;
4205 4160
4206 while () { 4161 while () {
4207 my $widget = pop @queue || last; 4162 my $widget = pop @queue || last;
4208 4163
4209 my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; 4164 my ($w, $h) = @$widget{qw(alloc_w alloc_h)};
4210 4165
4211 $w = 0 if $w < 0;
4212 $h = 0 if $h < 0;
4213
4214 $w = max $widget->{min_w}, $w; 4166 $w = max $widget->{min_w}, $w;
4215 $h = max $widget->{min_h}, $h; 4167 $h = max $widget->{min_h}, $h;
4216 4168
4217# $w = min $self->{w} - $widget->{x}, $w if $self->{w}; 4169# $w = min $self->{w} - $widget->{x}, $w if $self->{w};
4218# $h = min $self->{h} - $widget->{y}, $h if $self->{h}; 4170# $h = min $self->{h} - $widget->{y}, $h if $self->{h};
4219 4171
4220 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 4172 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
4221 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 4173 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
4222 4174
4223 $w = int $w + 0.5; 4175 $w = int $w + 0.5;
4224 $h = int $h + 0.5; 4176 $h = int $h + 0.5;
4225 4177
4226 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { 4178 if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) {
4227 $widget->{old_w} = $widget->{w}; 4179 $widget->{old_w} = $widget->{w};
4228 $widget->{old_h} = $widget->{h}; 4180 $widget->{old_h} = $widget->{h};
4229 4181
4230 $widget->{w} = $w; 4182 $widget->{w} = $w;
4231 $widget->{h} = $h; 4183 $widget->{h} = $h;
4232 4184
4233 $widget->emit (size_allocate => $w, $h); 4185 $widget->emit (size_allocate => $w, $h);
4186 }
4234 } 4187 }
4235 } 4188 }
4236 } 4189 }
4237 4190
4238 while ($self->{post_alloc_hook}) { 4191 while ($self->{post_alloc_hook}) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines