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.403 by root, Sat Jul 21 21:25:23 2007 UTC vs.
Revision 1.411 by root, Sun Jul 22 19:34:59 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";
1730 1686
1731use List::Util qw(min max); 1687use List::Util qw(min max);
1732 1688
1733our @ISA = CFPlus::UI::Container::; 1689our @ISA = CFPlus::UI::Container::;
1734 1690
1735sub add_fixed {
1736 my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_;
1737
1738 $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h];
1739 $self->SUPER::add ($child);
1740}
1741
1742sub _scale($$$) { 1691sub _scale($$$) {
1743 my ($mode, $val, $max) = @_; 1692 my ($rel, $val, $max) = @_;
1744 1693
1745 $mode eq "abs" ? $val 1694 $rel ? $val * $max : $val
1746 : $mode eq "rel" ? $val * $max
1747 : 0
1748} 1695}
1749 1696
1750sub size_request { 1697sub size_request {
1751 my ($self) = @_; 1698 my ($self) = @_;
1752 1699
1753 my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); 1700 my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0);
1754 1701
1755 # determine overall size by querying abs widgets 1702 # determine overall size by querying abs widgets
1756 for my $child ($self->visible_children) { 1703 for my $child ($self->visible_children) {
1757 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; 1704 unless ($child->{c_rel}) {
1705 my $x = $child->{c_x};
1706 my $y = $child->{c_y};
1758 1707
1759 if ($pos eq "abs") {
1760 $w = _scale $size, $w, $child->{req_w};
1761 $h = _scale $size, $h, $child->{req_h};
1762
1763 $x1 = min $x1, $x; $x2 = max $x2, $x + $w; 1708 $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w};
1764 $y1 = min $y1, $y; $y2 = max $y2, $y + $h; 1709 $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h};
1765 } 1710 }
1766 } 1711 }
1767 1712
1768 my $W = $x2 - $x1; 1713 my $W = $x2 - $x1;
1769 my $H = $y2 - $y1; 1714 my $H = $y2 - $y1;
1770 1715
1771 # now layout remaining widgets 1716 # now layout remaining widgets
1772 for my $child ($self->visible_children) { 1717 for my $child ($self->visible_children) {
1773 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; 1718 if ($child->{c_rel}) {
1719 my $x = _scale $child->{c_rel}, $child->{c_x}, $W;
1720 my $y = _scale $child->{c_rel}, $child->{c_y}, $H;
1774 1721
1775 if ($pos ne "abs") {
1776 $x = _scale $pos, $x, $W;
1777 $y = _scale $pos, $x, $H;
1778 $w = _scale $size, $w, $child->{req_w};
1779 $h = _scale $size, $h, $child->{req_h};
1780
1781 $x1 = min $x1, $x; $x2 = max $x2, $x + $w; 1722 $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w};
1782 $y1 = min $y1, $y; $y2 = max $y2, $y + $h; 1723 $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h};
1783 } 1724 }
1784 } 1725 }
1785 1726
1786 my $W = $x2 - $x1; 1727 my $W = $x2 - $x1;
1787 my $H = $y2 - $y1; 1728 my $H = $y2 - $y1;
1791 1732
1792sub invoke_size_allocate { 1733sub invoke_size_allocate {
1793 my ($self, $W, $H) = @_; 1734 my ($self, $W, $H) = @_;
1794 1735
1795 for my $child ($self->visible_children) { 1736 for my $child ($self->visible_children) {
1796 my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; 1737 my $x = _scale $child->{c_rel}, $child->{c_x}, $W;
1738 my $y = _scale $child->{c_rel}, $child->{c_y}, $H;
1797 1739
1798 $x = _scale $pos, $x, $W; 1740 $x += $child->{c_halign} * $child->{req_w};
1799 $y = _scale $pos, $x, $H; 1741 $y += $child->{c_valign} * $child->{req_h};
1800 $w = _scale $size, $w, $W;
1801 $h = _scale $size, $h, $H;
1802 1742
1803 $child->configure ($x, $y, $w, $h); 1743 $child->configure ($x, $y, $child->{req_w}, $child->{req_h});
1804 } 1744 }
1805 1745
1806 1 1746 1
1807} 1747}
1808 1748
2071 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} 2011 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
2072 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} 2012 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y}
2073 : ($self->{h} - $size->[1]) * 0.5); 2013 : ($self->{h} - $size->[1]) * 0.5);
2074 }; 2014 };
2075 2015
2076 my $w = List::Util::min $self->{w} + 4, $size->[0]; 2016# unless ($self->{list}) {
2077 my $h = List::Util::min $self->{h} + 2, $size->[1]; 2017# $self->{list} = CFPlus::OpenGL::glGenList;
2018# CFPlus::OpenGL::glNewList $self->{list};
2019# $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2020# CFPlus::OpenGL::glEndList;
2021# }
2022#
2023# CFPlus::OpenGL::glCallList $self->{list};
2078 2024
2079 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2025 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2080} 2026}
2027
2028#sub destroy {
2029# my ($self) = @_;
2030#
2031# CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list};
2032#
2033# $self->SUPER::destroy;
2034#}
2081 2035
2082############################################################################# 2036#############################################################################
2083 2037
2084package CFPlus::UI::EntryBase; 2038package CFPlus::UI::EntryBase;
2085 2039
2870 2824
2871 $self->SUPER::invoke_button_down ($ev, $x, $y); 2825 $self->SUPER::invoke_button_down ($ev, $x, $y);
2872 2826
2873 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; 2827 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x];
2874 2828
2875 $self->invoke_mouse_motion ($ev, $x, $y) 2829 $self->invoke_mouse_motion ($ev, $x, $y);
2830
2831 1
2876} 2832}
2877 2833
2878sub invoke_mouse_motion { 2834sub invoke_mouse_motion {
2879 my ($self, $ev, $x, $y) = @_; 2835 my ($self, $ev, $x, $y) = @_;
2880 2836
2900 2856
2901 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; 2857 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2;
2902 2858
2903 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); 2859 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
2904 2860
2905 ! ! $delta 2861 1
2906} 2862}
2907 2863
2908sub update { 2864sub update {
2909 my ($self) = @_; 2865 my ($self) = @_;
2910 2866
3483 3439
3484 if ($self->{anim} && $self->{animspeed}) { 3440 if ($self->{anim} && $self->{animspeed}) {
3485 CFPlus::weaken (my $widget = $self); 3441 CFPlus::weaken (my $widget = $self);
3486 3442
3487 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; 3443 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3488 $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed}; 3444 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed};
3489 $self->{timer} = Event->timer ( 3445 $self->{timer} = Event->timer (
3490 parked => 1, 3446 parked => 1,
3491 cb => sub { 3447 cb => sub {
3492 return unless $::CONN && $widget; 3448 return unless $::CONN && $widget;
3493 3449
3795sub add { 3751sub add {
3796 my ($self, $title, $widget, $tooltip) = @_; 3752 my ($self, $title, $widget, $tooltip) = @_;
3797 3753
3798 CFPlus::weaken $self; 3754 CFPlus::weaken $self;
3799 3755
3800 $self->{buttonbar}->add (new CFPlus::UI::Button 3756 unless (ref $title) {
3757 $title = new CFPlus::UI::Button
3801 markup => $title, 3758 markup => $title,
3802 tooltip => $tooltip, 3759 tooltip => $tooltip,
3760 ;
3761 }
3762
3803 on_activate => sub { $self->set_current_page ($widget) }, 3763 $title->connect (activate => sub { $self->set_current_page ($widget) });
3804 ); 3764 $self->{buttonbar}->add ($title);
3805 3765
3806 $self->{multiplexer}->add ($widget); 3766 $self->{multiplexer}->add ($widget);
3807} 3767}
3808 3768
3809sub get_current_page { 3769sub get_current_page {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines