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.401 by root, Sat Jul 21 20:05:37 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";
1795 for my $child ($self->visible_children) { 1751 for my $child ($self->visible_children) {
1796 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; 1752 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} };
1797 1753
1798 $x = _scale $pos, $x, $W; 1754 $x = _scale $pos, $x, $W;
1799 $y = _scale $pos, $x, $H; 1755 $y = _scale $pos, $x, $H;
1800 $w = _scale $size, $w, $child->{req_w}; 1756 $w = _scale $size, $w, $W;
1801 $h = _scale $size, $h, $child->{req_h}; 1757 $h = _scale $size, $h, $H;
1802 1758
1803 $child->configure ($x, $y, $w, $h); 1759 $child->configure ($x, $y, $w, $h);
1804 } 1760 }
1805 1761
1806 1 1762 1
2070 2026
2071 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} 2027 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
2072 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} 2028 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y}
2073 : ($self->{h} - $size->[1]) * 0.5); 2029 : ($self->{h} - $size->[1]) * 0.5);
2074 }; 2030 };
2075
2076 my $w = List::Util::min $self->{w} + 4, $size->[0];
2077 my $h = List::Util::min $self->{h} + 2, $size->[1];
2078 2031
2079 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2032 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2080} 2033}
2081 2034
2082############################################################################# 2035#############################################################################
3483 3436
3484 if ($self->{anim} && $self->{animspeed}) { 3437 if ($self->{anim} && $self->{animspeed}) {
3485 CFPlus::weaken (my $widget = $self); 3438 CFPlus::weaken (my $widget = $self);
3486 3439
3487 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; 3440 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3488 $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed}; 3441 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed};
3489 $self->{timer} = Event->timer ( 3442 $self->{timer} = Event->timer (
3490 parked => 1, 3443 parked => 1,
3491 cb => sub { 3444 cb => sub {
3492 return unless $::CONN && $widget; 3445 return unless $::CONN && $widget;
3493 3446
3530 3483
3531 if (my $anim = $::CONN->{anim}[$self->{anim}]) { 3484 if (my $anim = $::CONN->{anim}[$self->{anim}]) {
3532 if ($anim && @$anim) { 3485 if ($anim && @$anim) {
3533 delete $self->{wait_face}; 3486 delete $self->{wait_face};
3534 $self->{face} = $anim->[ $self->{frame} % @$anim ]; 3487 $self->{face} = $anim->[ $self->{frame} % @$anim ];
3488 $self->{tex} = $::CONN->{texture}[ $::CONN->{faceid}[$self->{face}] ];
3535 } 3489 }
3536 } 3490 }
3537} 3491}
3538 3492
3539sub size_request { 3493sub size_request {
3540 my ($self) = @_; 3494 my ($self) = @_;
3541 3495
3542 if ($::CONN) { 3496 if ($::CONN) {
3543 if (my $faceid = $::CONN->{faceid}[$self->{face}]) { 3497 if (my $faceid = $::CONN->{faceid}[$self->{face}]) {
3544 if (my $tex = $::CONN->{texture}[$faceid]) { 3498 if (my $tex = $::CONN->{texture}[$faceid]) {
3499 $self->{tex} = $tex;
3545 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); 3500 return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h});
3546 } else { 3501 } else {
3547 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { 3502 $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub {
3548 $self->realloc; 3503 $self->realloc;
3549 }); 3504 });
3571} 3526}
3572 3527
3573sub _draw { 3528sub _draw {
3574 my ($self) = @_; 3529 my ($self) = @_;
3575 3530
3576 return unless $::CONN;
3577
3578 $self->SUPER::_draw; 3531 $self->SUPER::_draw;
3579 3532
3580 my $faceid = $::CONN->{faceid}[$self->{face}] 3533 if (my $tex = $self->{tex}) {
3581 or return;
3582
3583 my $tex = $::CONN->{texture}[$faceid];
3584
3585 if ($tex) {
3586 glEnable GL_TEXTURE_2D; 3534 glEnable GL_TEXTURE_2D;
3587 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 3535 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
3588 glColor 0, 0, 0, 1; 3536 glColor 0, 0, 0, 1;
3589 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 3537 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
3590 glDisable GL_TEXTURE_2D; 3538 glDisable GL_TEXTURE_2D;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines