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.140 by root, Thu Apr 20 04:20:52 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
151 $self->{x} = $x;
152 $self->{y} = $y;
153
154 if ($self->{aspect}) { 151 if ($self->{aspect}) {
155 $w = List::Util::min $w, int $h * $self->{aspect}; 152 my $w2 = List::Util::min $w, int $h * $self->{aspect};
156 $h = List::Util::min $h, int $w / $self->{aspect}; 153 my $h2 = List::Util::min $h, int $w / $self->{aspect};
157 }
158 154
155 # use alignment to adjust x, y
156
157 $x += int +($w - $w2) * 0.5;
158 $y += int +($h - $h2) * 0.5;
159
160 ($w, $h) = ($w2, $h2);
161 }
162
163 if ($self->{x} != $x || $self->{y} != $y) {
164 $self->{x} = $x;
165 $self->{y} = $y;
166 $self->update;
167 }
168
159 return unless $self->{w} != $w || $self->{h} != $h; 169 if ($self->{w} != $w || $self->{h} != $h) {
160
161 $self->{w} = $w; 170 $self->{w} = $w;
162 $self->{h} = $h; 171 $self->{h} = $h;
163 172
164 $self->size_allocate ($w, $h); 173 $self->size_allocate ($w, $h);
165 $self->update; 174 $self->update;
175 }
166} 176}
167 177
168sub size_allocate { 178sub size_allocate {
169 # nothing to be done 179 # nothing to be done
170} 180}
284} 294}
285 295
286sub check_size { 296sub check_size {
287 my ($self) = @_; 297 my ($self) = @_;
288 298
299 return unless $self->{parent};
300
289 my ($w, $h) = $self->size_request; 301 my ($w, $h) = $self->size_request;
290 302
291 if ($w != $self->{req_w} || $h != $self->{req_h}) { 303 if ($w != $self->{req_w} || $h != $self->{req_h}) {
292 $self->{req_w} = $w; 304 $self->{req_w} = $w;
293 $self->{req_h} = $h; 305 $self->{req_h} = $h;
294 306
295 $self->{parent}->check_size 307 $self->{parent}->check_size;
296 if $self->{parent};
297 } 308 }
298} 309}
299 310
300sub update { 311sub update {
301 my ($self) = @_; 312 my ($self) = @_;
551sub new { die } 562sub new { die }
552 563
553sub size_request { 564sub size_request {
554 my ($self) = @_; 565 my ($self) = @_;
555 566
556 @$self{qw(child_w child_h)} = $self->child->size_request; 567 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)};
557 $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)});
558 569
559 @$self{qw(child_w child_h)} 570 @$self{qw(child_w child_h)}
560} 571}
561 572
571package CFClient::UI::Frame; 582package CFClient::UI::Frame;
572 583
573our @ISA = CFClient::UI::Bin::; 584our @ISA = CFClient::UI::Bin::;
574 585
575use CFClient::OpenGL; 586use CFClient::OpenGL;
576
577sub size_request {
578 my ($self) = @_;
579 my $chld = $self->child
580 or return (0, 0);
581
582 $chld->move (2, 2);
583
584 map { $_ + 4 } $chld->size_request;
585}
586
587sub size_allocate {
588 my ($self, $x, $y, $w, $h) = @_;
589
590 $self->child->configure (2, 2, $w - 4, $h - 4);
591}
592
593sub _draw {
594 my ($self) = @_;
595
596 my $chld = $self->child;
597
598 my ($w, $h) = $chld->size_request;
599
600 glBegin GL_QUADS;
601 glColor 0, 0, 0;
602 glVertex 0 , 0;
603 glVertex 0 , $h + 4;
604 glVertex $w + 4 , $h + 4;
605 glVertex $w + 4 , 0;
606 glEnd;
607
608 $chld->draw;
609}
610
611#############################################################################
612
613package CFClient::UI::FancyFrame;
614
615our @ISA = CFClient::UI::Bin::;
616
617use CFClient::OpenGL;
618
619my @tex =
620 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
621 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
622 587
623sub new { 588sub new {
624 my $class = shift; 589 my $class = shift;
625 590
626 # TODO: user_x, user_y, overwrite moveto?
627
628 $class->SUPER::new ( 591 my $self = $class->SUPER::new (
629 bg => [1, 1, 1, 1], 592 bg => [1, 1, 1, 1],
630 border_bg => [1, 1, 1, 1], 593 border_bg => [1, 1, 1, 1],
631 border => 0.8, 594 border => 0.8,
632 @_ 595 @_
633 ) 596 );
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
668 $self->{title} &&= new CFClient::UI::Label
669 align => 0,
670 valign => 1,
671 text => $self->{title},
672 fontsize => 1;
673
674 $self
634} 675}
635 676
636sub border { 677sub border {
637 int $_[0]{border} * $::FONTSIZE 678 int $_[0]{border} * $::FONTSIZE
638} 679}
653sub size_allocate { 694sub size_allocate {
654 my ($self, $w, $h) = @_; 695 my ($self, $w, $h) = @_;
655 696
656 $h -= List::Util::max 0, $self->border * 2; 697 $h -= List::Util::max 0, $self->border * 2;
657 $w -= List::Util::max 0, $self->border * 2; 698 $w -= List::Util::max 0, $self->border * 2;
699
700 $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2)
701 if $self->{title};
658 702
659 $self->child->configure ($self->border, $self->border, $w, $h); 703 $self->child->configure ($self->border, $self->border, $w, $h);
660} 704}
661 705
662sub button_down { 706sub button_down {
742 $bg->draw_quad ($border, $border, $cw, $ch); 786 $bg->draw_quad ($border, $border, $cw, $ch);
743 787
744 glDisable GL_TEXTURE_2D; 788 glDisable GL_TEXTURE_2D;
745 glDisable GL_BLEND; 789 glDisable GL_BLEND;
746 790
791 $self->{title}->draw if $self->{title};
747 $self->child->draw; 792 $self->child->draw;
748} 793}
749 794
750############################################################################# 795#############################################################################
751 796
793 or next; 838 or next;
794 839
795 for my $x (0 .. $#$row) { 840 for my $x (0 .. $#$row) {
796 my $widget = $row->[$x] 841 my $widget = $row->[$x]
797 or next; 842 or next;
798 my ($w, $h) = $widget->size_request; 843 my ($w, $h) = @$widget{qw(req_w req_h)};
799 844
800 $w[$x] = max $w[$x], $w; 845 $w[$x] = max $w[$x], $w;
801 $h[$y] = max $h[$y], $h; 846 $h[$y] = max $h[$y], $h;
802 } 847 }
803 } 848 }
908 953
909 ($h, $w) = ($w, $h); 954 ($h, $w) = ($w, $h);
910 955
911 my $children = $self->{children}; 956 my $children = $self->{children};
912 957
913 my @h = map +($_->size_request)[0], @$children; 958 my @h = map $_->{req_w}, @$children;
914 959
915 my $req_h = List::Util::sum @h; 960 my $req_h = List::Util::sum @h;
916 961
917 if ($req_h > $h) { 962 if ($req_h > $h) {
918 # ah well, not enough space 963 # ah well, not enough space
966sub size_allocate { 1011sub size_allocate {
967 my ($self, $w, $h) = @_; 1012 my ($self, $w, $h) = @_;
968 1013
969 my $children = $self->{children}; 1014 my $children = $self->{children};
970 1015
971 my @h = map +($_->size_request)[1], @$children; 1016 my @h = map $_->{req_h}, @$children;
972 1017
973 my $req_h = List::Util::sum @h; 1018 my $req_h = List::Util::sum @h;
974 1019
975 if ($req_h > $h) { 1020 if ($req_h > $h) {
976 # ah well, not enough space 1021 # ah well, not enough space
1020 padding => 2, 1065 padding => 2,
1021 layout => new CFClient::Layout, 1066 layout => new CFClient::Layout,
1022 %arg 1067 %arg
1023 ); 1068 );
1024 1069
1025 $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# 1070 if (exists $self->{template}) {
1071 my $layout = new CFClient::Layout;
1072 $layout->set_text (delete $self->{template});
1073 $self->{template} = $layout;
1074 }
1026 1075
1027 $self->set_text (delete $self->{text}) if exists $self->{text}; 1076 $self->set_text (delete $self->{text}) if exists $self->{text};
1028 $self->set_markup (delete $self->{markup}) if exists $self->{markup}; 1077 $self->set_markup (delete $self->{markup}) if exists $self->{markup};
1029 1078
1030 $self 1079 $self
1044 my ($self, $text) = @_; 1093 my ($self, $text) = @_;
1045 1094
1046 $self->{layout}->set_text ($text); 1095 $self->{layout}->set_text ($text);
1047 1096
1048 delete $self->{texture}; 1097 delete $self->{texture};
1098 $self->check_size;
1049 $self->update; 1099 $self->update;
1050} 1100}
1051 1101
1052sub set_markup { 1102sub set_markup {
1053 my ($self, $markup) = @_; 1103 my ($self, $markup) = @_;
1054 1104
1055 $self->{layout}->set_markup ($markup); 1105 $self->{layout}->set_markup ($markup);
1056 1106
1057 delete $self->{texture}; 1107 delete $self->{texture};
1108 $self->check_size;
1058 $self->update; 1109 $self->update;
1059} 1110}
1060 1111
1061sub size_request { 1112sub size_request {
1062 my ($self) = @_; 1113 my ($self) = @_;
1063 1114
1064 $self->{layout}->set_width; 1115 $self->{layout}->set_width;
1065 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1116 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1066 1117
1067 my ($w, $h) = $self->{layout}->size; 1118 my ($w, $h) = $self->{layout}->size;
1119
1120 if (exists $self->{template}) {
1121 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1122
1123 my ($w2, $h2) = $self->{template}->size;
1124
1125 $w = List::Util::max $w, $w2;
1126 $h = List::Util::max $h, $h2;
1127 }
1068 1128
1069 ( 1129 (
1070 $w + $self->{padding} * 2, 1130 $w + $self->{padding} * 2,
1071 $h + $self->{padding} * 2, 1131 $h + $self->{padding} * 2,
1072 ) 1132 )
1074 1134
1075sub size_allocate { 1135sub size_allocate {
1076 my ($self, $w, $h) = @_; 1136 my ($self, $w, $h) = @_;
1077 1137
1078 delete $self->{texture}; 1138 delete $self->{texture};
1139}
1140
1141sub set_fontsize {
1142 my ($self, $fontsize) = @_;
1143
1144 $self->{fontsize} = $fontsize;
1145 $self->check_size;
1079} 1146}
1080 1147
1081sub _draw { 1148sub _draw {
1082 my ($self) = @_; 1149 my ($self) = @_;
1083 1150
1166} 1233}
1167 1234
1168sub size_allocate { 1235sub size_allocate {
1169 my ($self, $w, $h) = @_; 1236 my ($self, $w, $h) = @_;
1170 1237
1171 $self->_set_text ($self->{text}); 1238 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text
1172} 1239}
1173 1240
1174sub set_text { 1241sub set_text {
1175 my ($self, $text) = @_; 1242 my ($self, $text) = @_;
1176 1243
1309our @ISA = CFClient::UI::Label::; 1376our @ISA = CFClient::UI::Label::;
1310 1377
1311use CFClient::OpenGL; 1378use CFClient::OpenGL;
1312 1379
1313my @tex = 1380my @tex =
1314 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1381 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1315 qw(b1_button_active.png); 1382 qw(b1_button_active.png);
1316 1383
1317sub new { 1384sub new {
1318 my $class = shift; 1385 my $class = shift;
1319 1386
1366package CFClient::UI::CheckBox; 1433package CFClient::UI::CheckBox;
1367 1434
1368our @ISA = CFClient::UI::DrawBG::; 1435our @ISA = CFClient::UI::DrawBG::;
1369 1436
1370my @tex = 1437my @tex =
1371 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1438 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1372 qw(c1_checkbox_bg.png c1_checkbox_active.png); 1439 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1373 1440
1374use CFClient::OpenGL; 1441use CFClient::OpenGL;
1375 1442
1376sub new { 1443sub new {
1425 glDisable GL_BLEND; 1492 glDisable GL_BLEND;
1426} 1493}
1427 1494
1428############################################################################# 1495#############################################################################
1429 1496
1430package CFClient::UI::VGauge; 1497package CFClient::UI::Image;
1431 1498
1432our @ISA = CFClient::UI::Base::; 1499our @ISA = CFClient::UI::Base::;
1433 1500
1434use CFClient::OpenGL; 1501use CFClient::OpenGL;
1502use Carp qw/confess/;
1435 1503
1436my %tex = ( 1504our %loaded_images;
1437 food => [
1438 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1439 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1440 ],
1441 grace => [
1442 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1443 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1444 ],
1445 hp => [
1446 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1447 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1448 ],
1449 mana => [
1450 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1451 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1452 ],
1453);
1454 1505
1455# eg. VGauge->new (gauge => 'food'), default gauge: food
1456sub new { 1506sub new {
1457 my $class = shift; 1507 my $class = shift;
1458 1508
1459 my $self = $class->SUPER::new ( 1509 my $self = $class->SUPER::new (@_);
1460 gauge => 'food',
1461 @_
1462 );
1463 1510
1464 $self->{aspect} = $tex{$self->{gauge}}[0]{w} / $tex{$self->{gauge}}[0]{h}; 1511 $self->{image} or confess "Image has 'image' not set. This is a fatal error!";
1512
1513 $loaded_images{$self->{image}} ||=
1514 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1515
1516 my $tex = $self->{tex} = $loaded_images{$self->{image}};
1517
1518 Scalar::Util::weaken $loaded_images{$self->{image}};
1519
1520 $self->{aspect} = $tex->{w} / $tex->{h};
1465 1521
1466 $self 1522 $self
1467} 1523}
1468 1524
1469sub size_request { 1525sub size_request {
1470 my ($self) = @_; 1526 my ($self) = @_;
1471 1527
1472 my $tex = $tex{$self->{gauge}}[0]; 1528 ($self->{tex}->{w}, $self->{tex}->{h})
1473
1474 @$tex{qw(w h)}
1475}
1476
1477sub set_max {
1478 my ($self, $max) = @_;
1479
1480 $self->{max_val} = $max;
1481}
1482
1483sub set_value {
1484 my ($self, $val, $max) = @_;
1485
1486 $self->set_max ($max)
1487 if defined $max;
1488
1489 $max = $self->{max_val};
1490 $self->{val} = $val;
1491
1492 $self->update;
1493} 1529}
1494 1530
1495sub _draw { 1531sub _draw {
1496 my ($self) = @_; 1532 my ($self) = @_;
1497 1533
1498 my $tex = $tex{$self->{gauge}}; 1534 my $tex = $self->{tex};
1499 1535
1500 my ($w, $h) = ($self->{w}, $self->{h}); 1536 my ($w, $h) = ($self->{w}, $self->{h});
1501 1537
1502 my $ycut = $self->{val} / ($self->{max_val} || 1); 1538 if ($self->{rot90}) {
1503 $ycut = 1 if $self->{val} > $self->{max_val}; 1539 glRotate 90, 0, 0, 1;
1540 glTranslate 0, -$self->{w}, 0;
1504 1541
1505 my $t1 = $tex->[0]; 1542 ($w, $h) = ($h, $w);
1506 my $t2 = $tex->[1]; 1543 }
1507 1544
1508 glEnable GL_BLEND; 1545 glEnable GL_BLEND;
1509 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1546 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1510 glEnable GL_TEXTURE_2D; 1547 glEnable GL_TEXTURE_2D;
1511 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1548 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1512 1549
1550 $tex->draw_quad (0, 0, $w, $h);
1551
1552 glDisable GL_BLEND;
1553 glDisable GL_TEXTURE_2D;
1554}
1555
1556#############################################################################
1557
1558package CFClient::UI::VGauge;
1559
1560our @ISA = CFClient::UI::Base::;
1561
1562use CFClient::OpenGL;
1563
1564my %tex = (
1565 food => [
1566 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1567 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1568 ],
1569 grace => [
1570 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1571 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1572 ],
1573 hp => [
1574 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1575 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1576 ],
1577 mana => [
1578 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1579 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1580 ],
1581);
1582
1583# eg. VGauge->new (gauge => 'food'), default gauge: food
1584sub new {
1585 my $class = shift;
1586
1587 my $self = $class->SUPER::new (
1588 type => 'food',
1589 @_
1590 );
1591
1592 $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h};
1593
1594 $self
1595}
1596
1597sub size_request {
1598 my ($self) = @_;
1599
1600 #my $tex = $tex{$self->{type}}[0];
1601 #@$tex{qw(w h)}
1602 (0, 0)
1603}
1604
1605sub set_max {
1606 my ($self, $max) = @_;
1607
1608 $self->{max_val} = $max;
1609}
1610
1611sub set_value {
1612 my ($self, $val, $max) = @_;
1613
1614 $self->set_max ($max)
1615 if defined $max;
1616
1617 $max = $self->{max_val};
1618 $self->{val} = $val;
1619
1620 $self->update;
1621}
1622
1623sub _draw {
1624 my ($self) = @_;
1625
1626 my $tex = $tex{$self->{type}};
1627
1628 my ($w, $h) = ($self->{w}, $self->{h});
1629
1630 if ($self->{vertical}) {
1631 glRotate 90, 0, 0, 1;
1632 glTranslate 0, -$self->{w}, 0;
1633
1634 ($w, $h) = ($h, $w);
1635 }
1636
1637 my $ycut = $self->{val} / ($self->{max_val} || 1);
1638 $ycut = 1 if $self->{val} > $self->{max_val};
1639
1640 my $t1 = $tex->[0];
1641 my $t2 = $tex->[1];
1642
1643 glEnable GL_BLEND;
1644 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1645 glEnable GL_TEXTURE_2D;
1646 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1647
1513 my $h1 = $self->{h} - $ycut * $self->{h}; 1648 my $h1 = $self->{h} - $ycut * $self->{h};
1514 my $h2 = $ycut * $self->{h}; 1649 my $h2 = $ycut * $self->{h};
1515 1650
1516 my $yp = 0;
1517
1518 glBindTexture GL_TEXTURE_2D, $t1->{name}; 1651 glBindTexture GL_TEXTURE_2D, $t1->{name};
1519 glBegin GL_QUADS; 1652 glBegin GL_QUADS;
1520 glTexCoord 0 , 0; glVertex 0 , $yp; 1653 glTexCoord 0 , 0; glVertex 0 , 0;
1521 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; 1654 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1;
1522 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; 1655 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1;
1523 glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; 1656 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1524 glEnd; 1657 glEnd;
1525
1526 $yp += $h1;
1527 1658
1528 glBindTexture GL_TEXTURE_2D, $t2->{name}; 1659 glBindTexture GL_TEXTURE_2D, $t2->{name};
1529 glBegin GL_QUADS; 1660 glBegin GL_QUADS;
1530 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; 1661 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1;
1531 glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; 1662 glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2;
1532 glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; 1663 glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2;
1533 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; 1664 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1;
1534 glEnd; 1665 glEnd;
1535 1666
1536 glDisable GL_BLEND; 1667 glDisable GL_BLEND;
1537 glDisable GL_TEXTURE_2D; 1668 glDisable GL_TEXTURE_2D;
1669}
1670
1671#############################################################################
1672
1673package CFClient::UI::Gauge;
1674
1675our @ISA = CFClient::UI::VBox::;
1676
1677sub new {
1678 my ($class, %arg) = shift;
1679
1680 my $self = $class->SUPER::new (
1681 @_,
1682 );
1683
1684 $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999");
1685 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1);
1686 $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999");
1687
1688 $self
1689}
1690
1691sub set_fontsize {
1692 my ($self, $fsize) = @_;
1693
1694 $self->{value}->set_fontsize ($fsize);
1695 $self->{max} ->set_fontsize ($fsize);
1696}
1697
1698sub set_value {
1699 my ($self, $val, $max) = @_;
1700
1701 $self->set_max ($max)
1702 if defined $max;
1703
1704 $self->{gauge}->set_value ($val, $max);
1705 $self->{value}->set_text ($val);
1706}
1707
1708sub set_max {
1709 my ($self, $max) = @_;
1710
1711 $self->{gauge}->set_max ($max);
1712 $self->{max}->set_text ($max);
1538} 1713}
1539 1714
1540############################################################################# 1715#############################################################################
1541 1716
1542package CFClient::UI::Slider; 1717package CFClient::UI::Slider;
1920use CFClient::OpenGL; 2095use CFClient::OpenGL;
1921 2096
1922sub check_size { 2097sub check_size {
1923 my ($self) = @_; 2098 my ($self) = @_;
1924 2099
1925 $self->configure (0, 0, $::WITH, $::HEIGHT); 2100 $self->configure (0, 0, $::WIDTH, $::HEIGHT);
1926} 2101}
1927 2102
1928sub size_request { 2103sub size_request {
1929 ($::WIDTH, $::HEIGHT) 2104 ($::WIDTH, $::HEIGHT)
1930} 2105}
1932sub configure { 2107sub configure {
1933 my ($self, $x, $y, $w, $h) = @_; 2108 my ($self, $x, $y, $w, $h) = @_;
1934 2109
1935 $self->SUPER::configure ($x, $y, $w, $h); 2110 $self->SUPER::configure ($x, $y, $w, $h);
1936 2111
1937 $_->configure ($_->{x}, $_->{y}, $_->size_request)
1938 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 }
1939} 2119}
1940 2120
1941sub _topleft { 2121sub _topleft {
1942 my ($self, $x, $y) = @_; 2122 my ($self, $x, $y) = @_;
1943 2123
1951 ::refresh (); 2131 ::refresh ();
1952} 2132}
1953 2133
1954sub add { 2134sub add {
1955 my ($self, $child) = @_; 2135 my ($self, $child) = @_;
2136
2137 # integerize window positions
2138 $child->{x} = int $child->{x};
2139 $child->{y} = int $child->{y};
1956 2140
1957 $self->SUPER::add ($child); 2141 $self->SUPER::add ($child);
1958} 2142}
1959 2143
1960sub on_refresh { 2144sub on_refresh {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines