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.146 by elmex, Fri Apr 21 15:03:46 2006 UTC vs.
Revision 1.149 by root, Sat Apr 22 23:11:32 2006 UTC

140 0 140 0
141} 141}
142 142
143sub size_request { 143sub size_request {
144 require Carp; 144 require Carp;
145 Carp::confess "size_request is abtract"; 145 Carp::confess "size_request is abstract";
146} 146}
147 147
148sub configure { 148sub configure {
149 my ($self, $x, $y, $w, $h) = @_; 149 my ($self, $x, $y, $w, $h) = @_;
150 150
152 my $w2 = List::Util::min $w, int $h * $self->{aspect}; 152 my $w2 = List::Util::min $w, int $h * $self->{aspect};
153 my $h2 = List::Util::min $h, int $w / $self->{aspect}; 153 my $h2 = List::Util::min $h, int $w / $self->{aspect};
154 154
155 # use alignment to adjust x, y 155 # use alignment to adjust x, y
156 156
157 $x += ($w - $w2) * 0.5; 157 $x += int +($w - $w2) * 0.5;
158 $y += ($h - $h2) * 0.5; 158 $y += int +($h - $h2) * 0.5;
159 159
160 ($w, $h) = ($w2, $h2); 160 ($w, $h) = ($w2, $h2);
161 } 161 }
162 162
163 if ($self->{x} != $x || $self->{y} != $y) { 163 if ($self->{x} != $x || $self->{y} != $y) {
294} 294}
295 295
296sub check_size { 296sub check_size {
297 my ($self) = @_; 297 my ($self) = @_;
298 298
299 return unless $self->{parent};
300
299 my ($w, $h) = $self->size_request; 301 my ($w, $h) = $self->size_request;
300 302
301 if ($w != $self->{req_w} || $h != $self->{req_h}) { 303 if ($w != $self->{req_w} || $h != $self->{req_h}) {
302 $self->{req_w} = $w; 304 $self->{req_w} = $w;
303 $self->{req_h} = $h; 305 $self->{req_h} = $h;
304 306
305 $self->{parent}->check_size 307 $self->{parent}->check_size;
306 if $self->{parent};
307 } 308 }
308} 309}
309 310
310sub update { 311sub update {
311 my ($self) = @_; 312 my ($self) = @_;
561sub new { die } 562sub new { die }
562 563
563sub size_request { 564sub size_request {
564 my ($self) = @_; 565 my ($self) = @_;
565 566
566 @$self{qw(child_w child_h)} = $self->child->size_request; 567 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)};
567 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); 568 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
568 569
569 @$self{qw(child_w child_h)} 570 @$self{qw(child_w child_h)}
570} 571}
571 572
581package CFClient::UI::Frame; 582package CFClient::UI::Frame;
582 583
583our @ISA = CFClient::UI::Bin::; 584our @ISA = CFClient::UI::Bin::;
584 585
585use CFClient::OpenGL; 586use CFClient::OpenGL;
586
587sub size_request {
588 my ($self) = @_;
589 my $chld = $self->child
590 or return (0, 0);
591
592 $chld->move (2, 2);
593
594 map { $_ + 4 } $chld->size_request;
595}
596
597sub size_allocate {
598 my ($self, $x, $y, $w, $h) = @_;
599
600 $self->child->configure (2, 2, $w - 4, $h - 4);
601}
602
603sub _draw {
604 my ($self) = @_;
605
606 my $chld = $self->child;
607
608 my ($w, $h) = $chld->size_request;
609
610 glBegin GL_QUADS;
611 glColor 0, 0, 0;
612 glVertex 0 , 0;
613 glVertex 0 , $h + 4;
614 glVertex $w + 4 , $h + 4;
615 glVertex $w + 4 , 0;
616 glEnd;
617
618 $chld->draw;
619}
620
621#############################################################################
622
623package CFClient::UI::FancyFrame;
624
625our @ISA = CFClient::UI::Bin::;
626
627use CFClient::OpenGL;
628
629my @tex =
630 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
631 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
632 587
633sub new { 588sub new {
634 my $class = shift; 589 my $class = shift;
635
636 # TODO: user_x, user_y, overwrite moveto?
637 590
638 my $self = $class->SUPER::new ( 591 my $self = $class->SUPER::new (
639 bg => [1, 1, 1, 1], 592 bg => [1, 1, 1, 1],
640 border_bg => [1, 1, 1, 1], 593 border_bg => [1, 1, 1, 1],
641 border => 0.8, 594 border => 0.8,
642 @_ 595 @_
643 ); 596 );
644 597
598 $self
599}
600
601sub set_size {
602 my ($self, $w, $h) = @_;
603 $self->{req_w} = $w;
604 $self->{req_h} = $h;
605 $self->check_size;
606}
607
608sub size_request {
609 my ($self) = @_;
610 ($self->{req_w}, $self->{req_h})
611}
612
613sub size_allocate {
614 my ($self, $w, $h) = @_;
615 $self->{w} = $w;
616 $self->{h} = $h;
617 $self->child->configure (0, 0, $w, $h);
618}
619
620sub _draw {
621 my ($self) = @_;
622
623 my ($w, $h) = ($self->{w}, $self->{h});
624
625 glEnable GL_BLEND;
626 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
627 glEnable GL_TEXTURE_2D;
628 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
629
630# glBegin GL_QUADS;
631# glColor 0, 0, 0, 0;
632# glVertex 0 , 0;
633# glVertex 0 , $h;
634# glVertex $w, $h;
635# glVertex $w, 0;
636# glEnd;
637
638
639 $self->child->draw;
640 glDisable GL_BLEND;
641 glDisable GL_TEXTURE_2D;
642}
643
644#############################################################################
645
646package CFClient::UI::FancyFrame;
647
648our @ISA = CFClient::UI::Bin::;
649
650use CFClient::OpenGL;
651
652my @tex =
653 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
654 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
655
656sub new {
657 my $class = shift;
658
659 # TODO: user_x, user_y, overwrite moveto?
660
661 my $self = $class->SUPER::new (
662 bg => [1, 1, 1, 1],
663 border_bg => [1, 1, 1, 1],
664 border => 0.8,
665 @_
666 );
667
645 $self->{title} &&= new CFClient::UI::Label 668 $self->{title} &&= new CFClient::UI::Label
646 align => 0, 669 align => 0,
647 valign => 1, 670 valign => 1,
648 text => $self->{title}, 671 text => $self->{title},
649 fontsize => 1; 672 fontsize => 1;
815 or next; 838 or next;
816 839
817 for my $x (0 .. $#$row) { 840 for my $x (0 .. $#$row) {
818 my $widget = $row->[$x] 841 my $widget = $row->[$x]
819 or next; 842 or next;
820 my ($w, $h) = $widget->size_request; 843 my ($w, $h) = @$widget{qw(req_w req_h)};
821 844
822 $w[$x] = max $w[$x], $w; 845 $w[$x] = max $w[$x], $w;
823 $h[$y] = max $h[$y], $h; 846 $h[$y] = max $h[$y], $h;
824 } 847 }
825 } 848 }
930 953
931 ($h, $w) = ($w, $h); 954 ($h, $w) = ($w, $h);
932 955
933 my $children = $self->{children}; 956 my $children = $self->{children};
934 957
935 my @h = map +($_->size_request)[0], @$children; 958 my @h = map $_->{req_w}, @$children;
936 959
937 my $req_h = List::Util::sum @h; 960 my $req_h = List::Util::sum @h;
938 961
939 if ($req_h > $h) { 962 if ($req_h > $h) {
940 # ah well, not enough space 963 # ah well, not enough space
988sub size_allocate { 1011sub size_allocate {
989 my ($self, $w, $h) = @_; 1012 my ($self, $w, $h) = @_;
990 1013
991 my $children = $self->{children}; 1014 my $children = $self->{children};
992 1015
993 my @h = map +($_->size_request)[1], @$children; 1016 my @h = map $_->{req_h}, @$children;
994 1017
995 my $req_h = List::Util::sum @h; 1018 my $req_h = List::Util::sum @h;
996 1019
997 if ($req_h > $h) { 1020 if ($req_h > $h) {
998 # ah well, not enough space 1021 # ah well, not enough space
1070 my ($self, $text) = @_; 1093 my ($self, $text) = @_;
1071 1094
1072 $self->{layout}->set_text ($text); 1095 $self->{layout}->set_text ($text);
1073 1096
1074 delete $self->{texture}; 1097 delete $self->{texture};
1098 $self->check_size;
1075 $self->update; 1099 $self->update;
1076} 1100}
1077 1101
1078sub set_markup { 1102sub set_markup {
1079 my ($self, $markup) = @_; 1103 my ($self, $markup) = @_;
1080 1104
1081 $self->{layout}->set_markup ($markup); 1105 $self->{layout}->set_markup ($markup);
1082 1106
1083 delete $self->{texture}; 1107 delete $self->{texture};
1108 $self->check_size;
1084 $self->update; 1109 $self->update;
1085} 1110}
1086 1111
1087sub size_request { 1112sub size_request {
1088 my ($self) = @_; 1113 my ($self) = @_;
1115 1140
1116sub set_fontsize { 1141sub set_fontsize {
1117 my ($self, $fontsize) = @_; 1142 my ($self, $fontsize) = @_;
1118 1143
1119 $self->{fontsize} = $fontsize; 1144 $self->{fontsize} = $fontsize;
1120 $self->update; 1145 $self->check_size;
1121} 1146}
1122 1147
1123sub _draw { 1148sub _draw {
1124 my ($self) = @_; 1149 my ($self) = @_;
1125 1150
1208} 1233}
1209 1234
1210sub size_allocate { 1235sub size_allocate {
1211 my ($self, $w, $h) = @_; 1236 my ($self, $w, $h) = @_;
1212 1237
1213 $self->_set_text ($self->{text}); 1238 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text
1214} 1239}
1215 1240
1216sub set_text { 1241sub set_text {
1217 my ($self, $text) = @_; 1242 my ($self, $text) = @_;
1218 1243
1487 1512
1488 $loaded_images{$self->{image}} ||= 1513 $loaded_images{$self->{image}} ||=
1489 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; 1514 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1490 1515
1491 my $tex = $self->{tex} = $loaded_images{$self->{image}}; 1516 my $tex = $self->{tex} = $loaded_images{$self->{image}};
1517
1518 Scalar::Util::weaken $loaded_images{$self->{image}};
1492 1519
1493 $self->{aspect} = $tex->{w} / $tex->{h}; 1520 $self->{aspect} = $tex->{w} / $tex->{h};
1494 1521
1495 $self 1522 $self
1496} 1523}
1664sub set_fontsize { 1691sub set_fontsize {
1665 my ($self, $fsize) = @_; 1692 my ($self, $fsize) = @_;
1666 1693
1667 $self->{value}->set_fontsize ($fsize); 1694 $self->{value}->set_fontsize ($fsize);
1668 $self->{max} ->set_fontsize ($fsize); 1695 $self->{max} ->set_fontsize ($fsize);
1669 $self->update;
1670} 1696}
1671 1697
1672sub set_value { 1698sub set_value {
1673 my ($self, $val, $max) = @_; 1699 my ($self, $val, $max) = @_;
1674 1700
2069use CFClient::OpenGL; 2095use CFClient::OpenGL;
2070 2096
2071sub check_size { 2097sub check_size {
2072 my ($self) = @_; 2098 my ($self) = @_;
2073 2099
2074 $self->configure (0, 0, $::WITH, $::HEIGHT); 2100 $self->configure (0, 0, $::WIDTH, $::HEIGHT);
2075} 2101}
2076 2102
2077sub size_request { 2103sub size_request {
2078 ($::WIDTH, $::HEIGHT) 2104 ($::WIDTH, $::HEIGHT)
2079} 2105}
2081sub configure { 2107sub configure {
2082 my ($self, $x, $y, $w, $h) = @_; 2108 my ($self, $x, $y, $w, $h) = @_;
2083 2109
2084 $self->SUPER::configure ($x, $y, $w, $h); 2110 $self->SUPER::configure ($x, $y, $w, $h);
2085 2111
2086 $_->configure ($_->{x}, $_->{y}, $_->size_request)
2087 for @{$self->{children}}; 2112 for my $child (@{$self->{children}}) {
2113 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2114
2115 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2116 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2117 $child->configure ($X, $Y, $W,$H);
2118 }
2088} 2119}
2089 2120
2090sub _topleft { 2121sub _topleft {
2091 my ($self, $x, $y) = @_; 2122 my ($self, $x, $y) = @_;
2092 2123

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines