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.147 by root, Sat Apr 22 03:50:25 2006 UTC vs.
Revision 1.150 by elmex, Sun Apr 23 00:08:29 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 can_events => 1,
101 @_ 102 @_
102 }, $class; 103 }, $class;
103 104
104 for (keys %$self) { 105 for (keys %$self) {
105 if (/^connect_(.*)$/) { 106 if (/^connect_(.*)$/) {
278} 279}
279 280
280sub find_widget { 281sub find_widget {
281 my ($self, $x, $y) = @_; 282 my ($self, $x, $y) = @_;
282 283
284 return () unless $self->{can_events};
285
283 return $self 286 return $self
284 if $x >= $self->{x} && $x < $self->{x} + $self->{w} 287 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
285 && $y >= $self->{y} && $y < $self->{y} + $self->{h}; 288 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
286 289
287 () 290 ()
294} 297}
295 298
296sub check_size { 299sub check_size {
297 my ($self) = @_; 300 my ($self) = @_;
298 301
302 return unless $self->{parent};
303
299 my ($w, $h) = $self->size_request; 304 my ($w, $h) = $self->size_request;
300 305
301 if ($w != $self->{req_w} || $h != $self->{req_h}) { 306 if ($w != $self->{req_w} || $h != $self->{req_h}) {
302 $self->{req_w} = $w; 307 $self->{req_w} = $w;
303 $self->{req_h} = $h; 308 $self->{req_h} = $h;
304 309
305 $self->{parent}->check_size 310 $self->{parent}->check_size;
306 if $self->{parent};
307 } 311 }
308} 312}
309 313
310sub update { 314sub update {
311 my ($self) = @_; 315 my ($self) = @_;
378 382
379package CFClient::UI::Empty; 383package CFClient::UI::Empty;
380 384
381our @ISA = CFClient::UI::Base::; 385our @ISA = CFClient::UI::Base::;
382 386
387sub new {
388 my ($class, %arg) = @_;
389 $class->SUPER::new (can_events => 0, %arg);
390}
391
383sub size_request { 392sub size_request {
384 (0, 0) 393 (0, 0)
385} 394}
386 395
387sub draw { } 396sub draw { }
395sub new { 404sub new {
396 my ($class, %arg) = @_; 405 my ($class, %arg) = @_;
397 406
398 my $children = delete $arg{children} || []; 407 my $children = delete $arg{children} || [];
399 408
400 my $self = $class->SUPER::new (children => [], %arg); 409 my $self = $class->SUPER::new (children => [], can_events => 0, %arg);
401 $self->add ($_) for @$children; 410 $self->add ($_) for @$children;
402 411
403 $self 412 $self
404} 413}
405 414
561sub new { die } 570sub new { die }
562 571
563sub size_request { 572sub size_request {
564 my ($self) = @_; 573 my ($self) = @_;
565 574
566 @$self{qw(child_w child_h)} = $self->child->size_request; 575 @$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)}); 576 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
568 577
569 @$self{qw(child_w child_h)} 578 @$self{qw(child_w child_h)}
570} 579}
571 580
581package CFClient::UI::Frame; 590package CFClient::UI::Frame;
582 591
583our @ISA = CFClient::UI::Bin::; 592our @ISA = CFClient::UI::Bin::;
584 593
585use CFClient::OpenGL; 594use 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 595
633sub new { 596sub new {
634 my $class = shift; 597 my $class = shift;
635
636 # TODO: user_x, user_y, overwrite moveto?
637 598
638 my $self = $class->SUPER::new ( 599 my $self = $class->SUPER::new (
639 bg => [1, 1, 1, 1], 600 bg => [1, 1, 1, 1],
640 border_bg => [1, 1, 1, 1], 601 border_bg => [1, 1, 1, 1],
641 border => 0.8, 602 border => 0.8,
642 @_ 603 @_
643 ); 604 );
644 605
606 $self
607}
608
609sub set_size {
610 my ($self, $w, $h) = @_;
611 $self->{req_w} = $w;
612 $self->{req_h} = $h;
613 $self->check_size;
614}
615
616sub size_request {
617 my ($self) = @_;
618 ($self->{req_w}, $self->{req_h})
619}
620
621sub size_allocate {
622 my ($self, $w, $h) = @_;
623 $self->{w} = $w;
624 $self->{h} = $h;
625 $self->child->configure (0, 0, $w, $h);
626}
627
628sub _draw {
629 my ($self) = @_;
630
631 my ($w, $h) = ($self->{w}, $self->{h});
632
633 glEnable GL_BLEND;
634 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
635 glEnable GL_TEXTURE_2D;
636 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
637
638# glBegin GL_QUADS;
639# glColor 0, 0, 0, 0;
640# glVertex 0 , 0;
641# glVertex 0 , $h;
642# glVertex $w, $h;
643# glVertex $w, 0;
644# glEnd;
645
646
647 $self->child->draw;
648 glDisable GL_BLEND;
649 glDisable GL_TEXTURE_2D;
650}
651
652#############################################################################
653
654package CFClient::UI::FancyFrame;
655
656our @ISA = CFClient::UI::Bin::;
657
658use CFClient::OpenGL;
659
660my @tex =
661 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
662 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
663
664sub new {
665 my $class = shift;
666
667 # TODO: user_x, user_y, overwrite moveto?
668
669 my $self = $class->SUPER::new (
670 bg => [1, 1, 1, 1],
671 border_bg => [1, 1, 1, 1],
672 border => 0.8,
673 can_events => 1,
674 @_
675 );
676
645 $self->{title} &&= new CFClient::UI::Label 677 $self->{title} &&= new CFClient::UI::Label
646 align => 0, 678 align => 0,
647 valign => 1, 679 valign => 1,
648 text => $self->{title}, 680 text => $self->{title},
649 fontsize => 1; 681 fontsize => 1;
815 or next; 847 or next;
816 848
817 for my $x (0 .. $#$row) { 849 for my $x (0 .. $#$row) {
818 my $widget = $row->[$x] 850 my $widget = $row->[$x]
819 or next; 851 or next;
820 my ($w, $h) = $widget->size_request; 852 my ($w, $h) = @$widget{qw(req_w req_h)};
821 853
822 $w[$x] = max $w[$x], $w; 854 $w[$x] = max $w[$x], $w;
823 $h[$y] = max $h[$y], $h; 855 $h[$y] = max $h[$y], $h;
824 } 856 }
825 } 857 }
930 962
931 ($h, $w) = ($w, $h); 963 ($h, $w) = ($w, $h);
932 964
933 my $children = $self->{children}; 965 my $children = $self->{children};
934 966
935 my @h = map +($_->size_request)[0], @$children; 967 my @h = map $_->{req_w}, @$children;
936 968
937 my $req_h = List::Util::sum @h; 969 my $req_h = List::Util::sum @h;
938 970
939 if ($req_h > $h) { 971 if ($req_h > $h) {
940 # ah well, not enough space 972 # ah well, not enough space
988sub size_allocate { 1020sub size_allocate {
989 my ($self, $w, $h) = @_; 1021 my ($self, $w, $h) = @_;
990 1022
991 my $children = $self->{children}; 1023 my $children = $self->{children};
992 1024
993 my @h = map +($_->size_request)[1], @$children; 1025 my @h = map $_->{req_h}, @$children;
994 1026
995 my $req_h = List::Util::sum @h; 1027 my $req_h = List::Util::sum @h;
996 1028
997 if ($req_h > $h) { 1029 if ($req_h > $h) {
998 # ah well, not enough space 1030 # ah well, not enough space
1039 text => "", 1071 text => "",
1040 align => -1, 1072 align => -1,
1041 valign => -1, 1073 valign => -1,
1042 padding => 2, 1074 padding => 2,
1043 layout => new CFClient::Layout, 1075 layout => new CFClient::Layout,
1076 can_events => 0,
1044 %arg 1077 %arg
1045 ); 1078 );
1046 1079
1047 if (exists $self->{template}) { 1080 if (exists $self->{template}) {
1048 my $layout = new CFClient::Layout; 1081 my $layout = new CFClient::Layout;
1070 my ($self, $text) = @_; 1103 my ($self, $text) = @_;
1071 1104
1072 $self->{layout}->set_text ($text); 1105 $self->{layout}->set_text ($text);
1073 1106
1074 delete $self->{texture}; 1107 delete $self->{texture};
1108 $self->check_size;
1075 $self->update; 1109 $self->update;
1076} 1110}
1077 1111
1078sub set_markup { 1112sub set_markup {
1079 my ($self, $markup) = @_; 1113 my ($self, $markup) = @_;
1080 1114
1081 $self->{layout}->set_markup ($markup); 1115 $self->{layout}->set_markup ($markup);
1082 1116
1083 delete $self->{texture}; 1117 delete $self->{texture};
1118 $self->check_size;
1084 $self->update; 1119 $self->update;
1085} 1120}
1086 1121
1087sub size_request { 1122sub size_request {
1088 my ($self) = @_; 1123 my ($self) = @_;
1171 active_bg => [1, 1, 1, 0.5], 1206 active_bg => [1, 1, 1, 0.5],
1172 active_fg => [0, 0, 0], 1207 active_fg => [0, 0, 0],
1173 can_hover => 1, 1208 can_hover => 1,
1174 can_focus => 1, 1209 can_focus => 1,
1175 valign => 0, 1210 valign => 0,
1211 can_events => 1,
1176 @_ 1212 @_
1177 ) 1213 )
1178} 1214}
1179 1215
1180sub _set_text { 1216sub _set_text {
1208} 1244}
1209 1245
1210sub size_allocate { 1246sub size_allocate {
1211 my ($self, $w, $h) = @_; 1247 my ($self, $w, $h) = @_;
1212 1248
1213 $self->_set_text ($self->{text}); 1249 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text
1214} 1250}
1215 1251
1216sub set_text { 1252sub set_text {
1217 my ($self, $text) = @_; 1253 my ($self, $text) = @_;
1218 1254
1365 bg => [1, 1, 1, 0.2], 1401 bg => [1, 1, 1, 0.2],
1366 active_fg => [0, 0, 1], 1402 active_fg => [0, 0, 1],
1367 can_hover => 1, 1403 can_hover => 1,
1368 align => 0, 1404 align => 0,
1369 valign => 0, 1405 valign => 0,
1406 can_events => 1,
1370 @_ 1407 @_
1371 ) 1408 )
1372} 1409}
1373 1410
1374sub button_up { 1411sub button_up {
1479our %loaded_images; 1516our %loaded_images;
1480 1517
1481sub new { 1518sub new {
1482 my $class = shift; 1519 my $class = shift;
1483 1520
1484 my $self = $class->SUPER::new (@_); 1521 my $self = $class->SUPER::new (can_events => 0, @_);
1485 1522
1486 $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; 1523 $self->{image} or confess "Image has 'image' not set. This is a fatal error!";
1487 1524
1488 $loaded_images{$self->{image}} ||= 1525 $loaded_images{$self->{image}} ||=
1489 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; 1526 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1654 1691
1655 my $self = $class->SUPER::new ( 1692 my $self = $class->SUPER::new (
1656 @_, 1693 @_,
1657 ); 1694 );
1658 1695
1659 $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1696 $self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999";
1697 $self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999";
1698 $self->add ($self->{value});
1660 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); 1699 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1);
1661 $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1700 $self->add ($self->{max});
1662 1701
1663 $self 1702 $self
1703}
1704
1705sub size_request {
1706 my ($self) = @_;
1707 (($self->{max}->size_request)[0], 0)
1664} 1708}
1665 1709
1666sub set_fontsize { 1710sub set_fontsize {
1667 my ($self, $fsize) = @_; 1711 my ($self, $fsize) = @_;
1668 1712
2032 my $class = shift; 2076 my $class = shift;
2033 2077
2034 my $self = $class->SUPER::new ( 2078 my $self = $class->SUPER::new (
2035 state => 0, 2079 state => 0,
2036 connect_activate => \&toggle_flopper, 2080 connect_activate => \&toggle_flopper,
2081 can_events => 1,
2037 @_ 2082 @_
2038 ); 2083 );
2039 2084
2040 if ($self->{state}) { 2085 if ($self->{state}) {
2041 $self->{state} = 0; 2086 $self->{state} = 0;
2070use CFClient::OpenGL; 2115use CFClient::OpenGL;
2071 2116
2072sub check_size { 2117sub check_size {
2073 my ($self) = @_; 2118 my ($self) = @_;
2074 2119
2075 $self->configure (0, 0, $::WITH, $::HEIGHT); 2120 $self->configure (0, 0, $::WIDTH, $::HEIGHT);
2076} 2121}
2077 2122
2078sub size_request { 2123sub size_request {
2079 ($::WIDTH, $::HEIGHT) 2124 ($::WIDTH, $::HEIGHT)
2080} 2125}
2082sub configure { 2127sub configure {
2083 my ($self, $x, $y, $w, $h) = @_; 2128 my ($self, $x, $y, $w, $h) = @_;
2084 2129
2085 $self->SUPER::configure ($x, $y, $w, $h); 2130 $self->SUPER::configure ($x, $y, $w, $h);
2086 2131
2087 $_->configure ($_->{x}, $_->{y}, $_->size_request)
2088 for @{$self->{children}}; 2132 for my $child (@{$self->{children}}) {
2133 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2134
2135 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2136 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2137 $child->configure ($X, $Y, $W,$H);
2138 }
2089} 2139}
2090 2140
2091sub _topleft { 2141sub _topleft {
2092 my ($self, $x, $y) = @_; 2142 my ($self, $x, $y) = @_;
2093 2143

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines