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.133 by root, Tue Apr 18 21:39:31 2006 UTC vs.
Revision 1.134 by root, Wed Apr 19 06:06:45 2006 UTC

96 96
97 my $self = bless { 97 my $self = bless {
98 x => 0, 98 x => 0,
99 y => 0, 99 y => 0,
100 z => 0, 100 z => 0,
101 w => -1,
102 h => -1,
103 @_ 101 @_
104 }, $class; 102 }, $class;
105 103
106 for (keys %$self) { 104 for (keys %$self) {
107 if (/^connect_(.*)$/) { 105 if (/^connect_(.*)$/) {
110 } 108 }
111 109
112 $self 110 $self
113} 111}
114 112
113sub show {
114 my ($self) = @_;
115
116 return if $self->{parent};
117
118 $CFClient::UI::ROOT->add ($self);
119}
120
121sub hide {
122 my ($self) = @_;
123
124 return unless $self->{parent};
125
126 $self->{parent}->remove ($self);
127}
128
115sub move { 129sub move {
116 my ($self, $x, $y, $z) = @_; 130 my ($self, $x, $y, $z) = @_;
117 131
118 $self->{x} = int $x; 132 $self->{x} = int $x;
119 $self->{y} = int $y; 133 $self->{y} = int $y;
141 155
142 $self->{w} = $w; 156 $self->{w} = $w;
143 $self->{h} = $h; 157 $self->{h} = $h;
144 158
145 $self->size_allocate ($w, $h); 159 $self->size_allocate ($w, $h);
160 $self->update;
146} 161}
147 162
148sub size_allocate { 163sub size_allocate {
149 # nothing to be done 164 # nothing to be done
150} 165}
272 $self->{req_w} = $w; 287 $self->{req_w} = $w;
273 $self->{req_h} = $h; 288 $self->{req_h} = $h;
274 289
275 $self->{parent}->check_size 290 $self->{parent}->check_size
276 if $self->{parent}; 291 if $self->{parent};
277
278 $self->size_allocate ($w, $h);
279 $self->update;
280 } 292 }
281} 293}
282 294
283sub update { 295sub update {
284 my ($self) = @_; 296 my ($self) = @_;
386 $self->{children} = [ 398 $self->{children} = [
387 sort { $a->{z} <=> $b->{z} } 399 sort { $a->{z} <=> $b->{z} }
388 @{$self->{children}}, $child 400 @{$self->{children}}, $child
389 ]; 401 ];
390 402
391 $self->{w} = $self->{h} = -1;
392
393 $child->check_size; 403 $child->check_size;
394} 404}
395 405
396sub remove { 406sub remove {
397 my ($self, $widget) = @_; 407 my ($self, $child) = @_;
398 408
409 delete $child->{parent};
410
399 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 411 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
400 412
401 $self->check_size; 413 $self->check_size;
402} 414}
403 415
404sub find_widget { 416sub find_widget {
436 448
437 $class->SUPER::new (children => [$child], %arg) 449 $class->SUPER::new (children => [$child], %arg)
438} 450}
439 451
440sub add { 452sub add {
441 my ($self, $widget) = @_; 453 my ($self, $child) = @_;
442 454
443 $self->{children} = []; 455 $self->{children} = [];
444 456
445 $self->SUPER::add ($widget); 457 $self->SUPER::add ($child);
446} 458}
447 459
448sub remove { 460sub remove {
449 my ($self, $widget) = @_; 461 my ($self, $widget) = @_;
450 462
609 # TODO: user_x, user_y, overwrite moveto? 621 # TODO: user_x, user_y, overwrite moveto?
610 622
611 $class->SUPER::new ( 623 $class->SUPER::new (
612 bg => [1, 1, 1, 1], 624 bg => [1, 1, 1, 1],
613 border_bg => [1, 1, 1, 1], 625 border_bg => [1, 1, 1, 1],
614 border => int $::FONTSIZE * 0.8, 626 border => 0.8,
615 @_ 627 @_
616 ) 628 )
617} 629}
618 630
631sub border {
632 int $_[0]{border} * $::FONTSIZE
633}
634
619sub size_request { 635sub size_request {
620 my ($self) = @_; 636 my ($self) = @_;
621 637
622 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; 638 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
623 639
624 my ($w, $h) = $self->SUPER::size_request; 640 my ($w, $h) = $self->SUPER::size_request;
625 641
626 ( 642 (
627 $w + $self->{border} * 2, 643 $w + $self->border * 2,
628 $h + $self->{border} * 2, 644 $h + $self->border * 2,
629 ) 645 )
630} 646}
631 647
632sub size_allocate { 648sub size_allocate {
633 my ($self, $w, $h) = @_; 649 my ($self, $w, $h) = @_;
634 650
635 $h -= List::Util::max 0, $self->{border} * 2; 651 $h -= List::Util::max 0, $self->border * 2;
636 $w -= List::Util::max 0, $self->{border} * 2; 652 $w -= List::Util::max 0, $self->border * 2;
637 653
638 $self->child->configure ($self->{border}, $self->{border}, $w, $h); 654 $self->child->configure ($self->border, $self->border, $w, $h);
639} 655}
640 656
641sub button_down { 657sub button_down {
642 my ($self, $ev, $x, $y) = @_; 658 my ($self, $ev, $x, $y) = @_;
643 659
660 my $border = $self->border;
661
644 if ($x < $self->{w} && $x >= $self->{w} - $self->{border} 662 if ($x < $self->{w} && $x >= $self->{w} - $border
645 && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { 663 && $y < $self->{h} && $y >= $self->{h} - $border) {
646 664
647 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 665 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
648 my ($bw, $bh) = ($self->{w}, $self->{h}); 666 my ($bw, $bh) = ($self->{w}, $self->{h});
649 667
650 $self->{motion} = sub { 668 $self->{motion} = sub {
656 $self->{user_h} = $bh + $y - $oy; 674 $self->{user_h} = $bh + $y - $oy;
657 $self->check_size; 675 $self->check_size;
658 }; 676 };
659 677
660 } elsif ($x >= 0 && $x < $self->{w} 678 } elsif ($x >= 0 && $x < $self->{w}
661 && $y >= 0 && $y < $self->{border}) { 679 && $y >= 0 && $y < $border) {
662 680
663 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 681 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
664 my ($bx, $by) = ($self->{x}, $self->{y}); 682 my ($bx, $by) = ($self->{x}, $self->{y});
665 683
666 $self->{motion} = sub { 684 $self->{motion} = sub {
695 glEnable GL_BLEND; 713 glEnable GL_BLEND;
696 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 714 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
697 glEnable GL_TEXTURE_2D; 715 glEnable GL_TEXTURE_2D;
698 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 716 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
699 717
718 my $border = $self->border;
719
700 glColor @{ $self->{border_bg} }; 720 glColor @{ $self->{border_bg} };
701 $tex[1]->draw_quad (0, 0, $w, $self->{border}); 721 $tex[1]->draw_quad (0, 0, $w, $border);
702 $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); 722 $tex[3]->draw_quad (0, $border, $border, $ch);
703 $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); 723 $tex[2]->draw_quad ($w - $border, $border, $border, $ch);
704 $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); 724 $tex[4]->draw_quad (0, $h - $border, $w, $border);
705 725
706 my $bg = $tex[0]; 726 my $bg = $tex[0];
707 727
708 # TODO: repeat texture not scale 728 # TODO: repeat texture not scale
709 my $rep_x = $cw / $bg->{w}; 729 my $rep_x = $cw / $bg->{w};
712 glColor @{ $self->{bg} }; 732 glColor @{ $self->{bg} };
713 733
714 $bg->{s} = $rep_x; 734 $bg->{s} = $rep_x;
715 $bg->{t} = $rep_y; 735 $bg->{t} = $rep_y;
716 $bg->{wrap_mode} = 1; 736 $bg->{wrap_mode} = 1;
717 $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); 737 $bg->draw_quad ($border, $border, $cw, $ch);
718 738
719 glDisable GL_TEXTURE_2D; 739 glDisable GL_TEXTURE_2D;
720 glDisable GL_BLEND; 740 glDisable GL_BLEND;
721 741
722 $self->child->draw; 742 $self->child->draw;
744sub add { 764sub add {
745 my ($self, $x, $y, $child) = @_; 765 my ($self, $x, $y, $child) = @_;
746 766
747 $child->set_parent ($self); 767 $child->set_parent ($self);
748 $self->{children}[$y][$x] = $child; 768 $self->{children}[$y][$x] = $child;
749
750 $self->{w} = $self->{h} = -1;
751 769
752 $child->check_size; 770 $child->check_size;
753} 771}
754 772
755# TODO: move to container class maybe? send childs a signal on removal? 773# TODO: move to container class maybe? send childs a signal on removal?
988sub new { 1006sub new {
989 my ($class, %arg) = @_; 1007 my ($class, %arg) = @_;
990 1008
991 my $self = $class->SUPER::new ( 1009 my $self = $class->SUPER::new (
992 fg => [1, 1, 1], 1010 fg => [1, 1, 1],
993 fontsize => $::FONTSIZE, 1011 fontsize => 1,
994 text => "", 1012 text => "",
995 align => -1, 1013 align => -1,
996 valign => -1, 1014 valign => -1,
997 padding => 2, 1015 padding => 2,
998 layout => new CFClient::Layout, 1016 layout => new CFClient::Layout,
1037 1055
1038sub size_request { 1056sub size_request {
1039 my ($self) = @_; 1057 my ($self) = @_;
1040 1058
1041 $self->{layout}->set_width; 1059 $self->{layout}->set_width;
1042 $self->{layout}->set_height ($self->{fontsize}); 1060 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1043 1061
1044 my ($w, $h) = $self->{layout}->size; 1062 my ($w, $h) = $self->{layout}->size;
1045 1063
1046 ( 1064 (
1047 $w + $self->{padding} * 2, 1065 $w + $self->{padding} * 2,
1053 my ($self, $w, $h) = @_; 1071 my ($self, $w, $h) = @_;
1054 1072
1055 delete $self->{texture}; 1073 delete $self->{texture};
1056} 1074}
1057 1075
1058sub update {
1059 my ($self) = @_;
1060
1061 delete $self->{texture};
1062 $self->SUPER::update;
1063}
1064
1065sub _draw { 1076sub _draw {
1066 my ($self) = @_; 1077 my ($self) = @_;
1067 1078
1068 my $tex = $self->{texture} ||= do { 1079 my $tex = $self->{texture} ||= do {
1069 $self->{layout}->set_width ($self->{w}); 1080 $self->{layout}->set_width ($self->{w});
1070 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize}); 1081 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1071 new_from_layout CFClient::Texture $self->{layout} 1082 new_from_layout CFClient::Texture $self->{layout}
1072 }; 1083 };
1073 1084
1074 glEnable GL_BLEND; 1085 glEnable GL_BLEND;
1075 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1086 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1124 my ($self, $text) = @_; 1135 my ($self, $text) = @_;
1125 1136
1126 delete $self->{cur_h}; 1137 delete $self->{cur_h};
1127 1138
1128 return if $self->{text} eq $text; 1139 return if $self->{text} eq $text;
1140
1141 delete $self->{texture};
1129 1142
1130 $self->{last_activity} = $::NOW; 1143 $self->{last_activity} = $::NOW;
1131 $self->{text} = $text; 1144 $self->{text} = $text;
1132 1145
1133 $text =~ s/./*/g if $self->{hidden}; 1146 $text =~ s/./*/g if $self->{hidden};
1543 # TODO: calculations are off 1556 # TODO: calculations are off
1544 my $self = $class->SUPER::new ( 1557 my $self = $class->SUPER::new (
1545 fg => [1, 1, 1], 1558 fg => [1, 1, 1],
1546 active_fg => [0, 0, 0], 1559 active_fg => [0, 0, 0],
1547 range => [0, 0, 100, 10], 1560 range => [0, 0, 100, 10],
1548 req_w => 40, 1561 req_w => 20,
1549 req_h => 13, 1562 req_h => 20,
1550 vertical => 0, 1563 vertical => 0,
1551 can_hover => 1, 1564 can_hover => 1,
1552 inner_pad => 5, 1565 inner_pad => 5,
1553 @_ 1566 @_
1554 ); 1567 );
1664 1677
1665sub new { 1678sub new {
1666 my $class = shift; 1679 my $class = shift;
1667 1680
1668 my $self = $class->SUPER::new ( 1681 my $self = $class->SUPER::new (
1669 req_w => $::WIDTH / 6,
1670 req_h => $::HEIGHT / 6,
1671 fontsize => $::FONTSIZE, 1682 fontsize => 1,
1672 @_, 1683 @_,
1673 1684
1674 layout => (new CFClient::Layout), 1685 layout => (new CFClient::Layout),
1675 par => [], 1686 par => [],
1676 height => 0, 1687 height => 0,
1697sub text_height { 1708sub text_height {
1698 my ($self, $text) = @_; 1709 my ($self, $text) = @_;
1699 1710
1700 my $layout = $self->{layout}; 1711 my $layout = $self->{layout};
1701 1712
1702 $layout->set_height ($self->{fontsize}); 1713 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
1703 $layout->set_width ($self->{w}); 1714 $layout->set_width ($self->{w});
1704 $layout->set_text ($text); 1715 $layout->set_text ($text);
1705 1716
1706 ($layout->size)[1] 1717 ($layout->size)[1]
1707} 1718}
1711 1722
1712 $self->{need_reflow}++; 1723 $self->{need_reflow}++;
1713 $self->update; 1724 $self->update;
1714} 1725}
1715 1726
1716sub size_request {
1717 my ($self) = @_;
1718
1719 ($self->{req_w}, $self->{req_h})
1720}
1721
1722sub size_allocate { 1727sub size_allocate {
1723 my ($self, $w, $h) = @_; 1728 my ($self, $w, $h) = @_;
1724 1729
1730 $self->SUPER::size_allocate ($w, $h);
1731
1725 $self->{layout}->set_height ($self->{fontsize}); 1732 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1726 $self->{layout}->set_width ($self->{w}); 1733 $self->{layout}->set_width ($self->{children}[0]{w});
1727 1734
1728 $self->reflow; 1735 $self->reflow;
1729 $self->update;
1730} 1736}
1731 1737
1732sub add_paragraph { 1738sub add_paragraph {
1733 my ($self, $color, $text) = @_; 1739 my ($self, $color, $text) = @_;
1734 1740

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines