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.137 by root, Wed Apr 19 21:38:05 2006 UTC vs.
Revision 1.148 by elmex, Sat Apr 22 12:14:45 2006 UTC

87 87
88package CFClient::UI::Base; 88package CFClient::UI::Base;
89 89
90use strict; 90use strict;
91 91
92use SDL::OpenGL; 92use CFClient::OpenGL;
93 93
94sub new { 94sub new {
95 my $class = shift; 95 my $class = shift;
96 96
97 my $self = bless { 97 my $self = bless {
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 if ($self->{aspect}) {
152 my $w2 = List::Util::min $w, int $h * $self->{aspect};
153 my $h2 = List::Util::min $h, int $w / $self->{aspect};
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) {
151 $self->{x} = $x; 164 $self->{x} = $x;
152 $self->{y} = $y; 165 $self->{y} = $y;
166 $self->update;
167 }
153 168
154 return unless $self->{w} != $w || $self->{h} != $h; 169 if ($self->{w} != $w || $self->{h} != $h) {
155
156 $self->{w} = $w; 170 $self->{w} = $w;
157 $self->{h} = $h; 171 $self->{h} = $h;
158 172
159 $self->size_allocate ($w, $h); 173 $self->size_allocate ($w, $h);
160 $self->update; 174 $self->update;
175 }
161} 176}
162 177
163sub size_allocate { 178sub size_allocate {
164 # nothing to be done 179 # nothing to be done
165} 180}
324package CFClient::UI::DrawBG; 339package CFClient::UI::DrawBG;
325 340
326our @ISA = CFClient::UI::Base::; 341our @ISA = CFClient::UI::Base::;
327 342
328use strict; 343use strict;
329use SDL::OpenGL; 344use CFClient::OpenGL;
330 345
331sub new { 346sub new {
332 my $class = shift; 347 my $class = shift;
333 348
334 # range [value, low, high, page] 349 # range [value, low, high, page]
482 497
483package CFClient::UI::Window; 498package CFClient::UI::Window;
484 499
485our @ISA = CFClient::UI::Bin::; 500our @ISA = CFClient::UI::Bin::;
486 501
487use SDL::OpenGL; 502use CFClient::OpenGL;
488 503
489sub new { 504sub new {
490 my ($class, %arg) = @_; 505 my ($class, %arg) = @_;
491 506
492 my $self = $class->SUPER::new (%arg); 507 my $self = $class->SUPER::new (%arg);
565 580
566package CFClient::UI::Frame; 581package CFClient::UI::Frame;
567 582
568our @ISA = CFClient::UI::Bin::; 583our @ISA = CFClient::UI::Bin::;
569 584
570use SDL::OpenGL; 585use CFClient::OpenGL;
571
572sub size_request {
573 my ($self) = @_;
574 my $chld = $self->child
575 or return (0, 0);
576
577 $chld->move (2, 2);
578
579 map { $_ + 4 } $chld->size_request;
580}
581
582sub size_allocate {
583 my ($self, $x, $y, $w, $h) = @_;
584
585 $self->child->configure (2, 2, $w - 4, $h - 4);
586}
587
588sub _draw {
589 my ($self) = @_;
590
591 my $chld = $self->child;
592
593 my ($w, $h) = $chld->size_request;
594
595 glBegin GL_QUADS;
596 glColor 0, 0, 0;
597 glVertex 0 , 0;
598 glVertex 0 , $h + 4;
599 glVertex $w + 4 , $h + 4;
600 glVertex $w + 4 , 0;
601 glEnd;
602
603 $chld->draw;
604}
605
606#############################################################################
607
608package CFClient::UI::FancyFrame;
609
610our @ISA = CFClient::UI::Bin::;
611
612use SDL::OpenGL;
613
614my @tex =
615 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
616 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
617 586
618sub new { 587sub new {
619 my $class = shift; 588 my $class = shift;
620 589
621 # TODO: user_x, user_y, overwrite moveto?
622
623 $class->SUPER::new ( 590 my $self = $class->SUPER::new (
624 bg => [1, 1, 1, 1], 591 bg => [1, 1, 1, 1],
625 border_bg => [1, 1, 1, 1], 592 border_bg => [1, 1, 1, 1],
626 border => 0.8, 593 border => 0.8,
627 @_ 594 @_
628 ) 595 );
596
597 $self
598}
599
600sub set_size {
601 my ($self, $w, $h) = @_;
602 $self->{req_w} = $w;
603 $self->{req_h} = $h;
604 $self->check_size;
605}
606
607sub size_request {
608 my ($self) = @_;
609 ($self->{req_w}, $self->{req_h})
610}
611
612sub size_allocate {
613 my ($self, $w, $h) = @_;
614 $self->{w} = $w;
615 $self->{h} = $h;
616 $self->child->configure (0, 0, $w, $h);
617}
618
619sub _draw {
620 my ($self) = @_;
621
622 my ($w, $h) = ($self->{w}, $self->{h});
623
624 glEnable GL_BLEND;
625 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
626 glEnable GL_TEXTURE_2D;
627 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
628
629# glBegin GL_QUADS;
630# glColor 0, 0, 0, 0;
631# glVertex 0 , 0;
632# glVertex 0 , $h;
633# glVertex $w, $h;
634# glVertex $w, 0;
635# glEnd;
636
637
638 $self->child->draw;
639 glDisable GL_BLEND;
640 glDisable GL_TEXTURE_2D;
641}
642
643#############################################################################
644
645package CFClient::UI::FancyFrame;
646
647our @ISA = CFClient::UI::Bin::;
648
649use CFClient::OpenGL;
650
651my @tex =
652 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
653 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
654
655sub new {
656 my $class = shift;
657
658 # TODO: user_x, user_y, overwrite moveto?
659
660 my $self = $class->SUPER::new (
661 bg => [1, 1, 1, 1],
662 border_bg => [1, 1, 1, 1],
663 border => 0.8,
664 @_
665 );
666
667 $self->{title} &&= new CFClient::UI::Label
668 align => 0,
669 valign => 1,
670 text => $self->{title},
671 fontsize => 1;
672
673 $self
629} 674}
630 675
631sub border { 676sub border {
632 int $_[0]{border} * $::FONTSIZE 677 int $_[0]{border} * $::FONTSIZE
633} 678}
649 my ($self, $w, $h) = @_; 694 my ($self, $w, $h) = @_;
650 695
651 $h -= List::Util::max 0, $self->border * 2; 696 $h -= List::Util::max 0, $self->border * 2;
652 $w -= List::Util::max 0, $self->border * 2; 697 $w -= List::Util::max 0, $self->border * 2;
653 698
699 $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2)
700 if $self->{title};
701
654 $self->child->configure ($self->border, $self->border, $w, $h); 702 $self->child->configure ($self->border, $self->border, $w, $h);
655} 703}
656 704
657sub button_down { 705sub button_down {
658 my ($self, $ev, $x, $y) = @_; 706 my ($self, $ev, $x, $y) = @_;
660 my $border = $self->border; 708 my $border = $self->border;
661 709
662 if ($x < $self->{w} && $x >= $self->{w} - $border 710 if ($x < $self->{w} && $x >= $self->{w} - $border
663 && $y < $self->{h} && $y >= $self->{h} - $border) { 711 && $y < $self->{h} && $y >= $self->{h} - $border) {
664 712
665 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 713 my ($ox, $oy) = ($ev->{x}, $ev->{y});
666 my ($bw, $bh) = ($self->{w}, $self->{h}); 714 my ($bw, $bh) = ($self->{w}, $self->{h});
667 715
668 $self->{motion} = sub { 716 $self->{motion} = sub {
669 my ($ev, $x, $y) = @_; 717 my ($ev, $x, $y) = @_;
670 718
671 ($x, $y) = ($ev->motion_x, $ev->motion_y); 719 ($x, $y) = ($ev->{x}, $ev->{y});
672 720
673 $self->{user_w} = $bw + $x - $ox; 721 $self->{user_w} = $bw + $x - $ox;
674 $self->{user_h} = $bh + $y - $oy; 722 $self->{user_h} = $bh + $y - $oy;
675 $self->check_size; 723 $self->check_size;
676 }; 724 };
677 725
678 } elsif ($x >= 0 && $x < $self->{w} 726 } elsif ($x >= 0 && $x < $self->{w}
679 && $y >= 0 && $y < $border) { 727 && $y >= 0 && $y < $border) {
680 728
681 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 729 my ($ox, $oy) = ($ev->{x}, $ev->{y});
682 my ($bx, $by) = ($self->{x}, $self->{y}); 730 my ($bx, $by) = ($self->{x}, $self->{y});
683 731
684 $self->{motion} = sub { 732 $self->{motion} = sub {
685 my ($ev, $x, $y) = @_; 733 my ($ev, $x, $y) = @_;
686 734
687 ($x, $y) = ($ev->motion_x, $ev->motion_y); 735 ($x, $y) = ($ev->{x}, $ev->{y});
688 736
689 $self->move ($bx + $x - $ox, $by + $y - $oy); 737 $self->move ($bx + $x - $ox, $by + $y - $oy);
690 $self->update; 738 $self->update;
691 }; 739 };
692 } 740 }
737 $bg->draw_quad ($border, $border, $cw, $ch); 785 $bg->draw_quad ($border, $border, $cw, $ch);
738 786
739 glDisable GL_TEXTURE_2D; 787 glDisable GL_TEXTURE_2D;
740 glDisable GL_BLEND; 788 glDisable GL_BLEND;
741 789
790 $self->{title}->draw if $self->{title};
742 $self->child->draw; 791 $self->child->draw;
743} 792}
744 793
745############################################################################# 794#############################################################################
746 795
748 797
749our @ISA = CFClient::UI::Base::; 798our @ISA = CFClient::UI::Base::;
750 799
751use List::Util qw(max sum); 800use List::Util qw(max sum);
752 801
753use SDL::OpenGL; 802use CFClient::OpenGL;
754 803
755sub new { 804sub new {
756 my $class = shift; 805 my $class = shift;
757 806
758 $class->SUPER::new ( 807 $class->SUPER::new (
999 1048
1000package CFClient::UI::Label; 1049package CFClient::UI::Label;
1001 1050
1002our @ISA = CFClient::UI::Base::; 1051our @ISA = CFClient::UI::Base::;
1003 1052
1004use SDL::OpenGL; 1053use CFClient::OpenGL;
1005 1054
1006sub new { 1055sub new {
1007 my ($class, %arg) = @_; 1056 my ($class, %arg) = @_;
1008 1057
1009 my $self = $class->SUPER::new ( 1058 my $self = $class->SUPER::new (
1015 padding => 2, 1064 padding => 2,
1016 layout => new CFClient::Layout, 1065 layout => new CFClient::Layout,
1017 %arg 1066 %arg
1018 ); 1067 );
1019 1068
1020 $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# 1069 if (exists $self->{template}) {
1070 my $layout = new CFClient::Layout;
1071 $layout->set_text (delete $self->{template});
1072 $self->{template} = $layout;
1073 }
1021 1074
1022 $self->set_text (delete $self->{text}) if exists $self->{text}; 1075 $self->set_text (delete $self->{text}) if exists $self->{text};
1023 $self->set_markup (delete $self->{markup}) if exists $self->{markup}; 1076 $self->set_markup (delete $self->{markup}) if exists $self->{markup};
1024 1077
1025 $self 1078 $self
1058 1111
1059 $self->{layout}->set_width; 1112 $self->{layout}->set_width;
1060 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1113 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1061 1114
1062 my ($w, $h) = $self->{layout}->size; 1115 my ($w, $h) = $self->{layout}->size;
1116
1117 if (exists $self->{template}) {
1118 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1119
1120 my ($w2, $h2) = $self->{template}->size;
1121
1122 $w = List::Util::max $w, $w2;
1123 $h = List::Util::max $h, $h2;
1124 }
1063 1125
1064 ( 1126 (
1065 $w + $self->{padding} * 2, 1127 $w + $self->{padding} * 2,
1066 $h + $self->{padding} * 2, 1128 $h + $self->{padding} * 2,
1067 ) 1129 )
1069 1131
1070sub size_allocate { 1132sub size_allocate {
1071 my ($self, $w, $h) = @_; 1133 my ($self, $w, $h) = @_;
1072 1134
1073 delete $self->{texture}; 1135 delete $self->{texture};
1136}
1137
1138sub set_fontsize {
1139 my ($self, $fontsize) = @_;
1140
1141 $self->{fontsize} = $fontsize;
1142 $self->check_size;
1074} 1143}
1075 1144
1076sub _draw { 1145sub _draw {
1077 my ($self) = @_; 1146 my ($self) = @_;
1078 1147
1111 1180
1112package CFClient::UI::EntryBase; 1181package CFClient::UI::EntryBase;
1113 1182
1114our @ISA = CFClient::UI::Label::; 1183our @ISA = CFClient::UI::Label::;
1115 1184
1116use SDL::OpenGL; 1185use CFClient::OpenGL;
1117 1186
1118sub new { 1187sub new {
1119 my $class = shift; 1188 my $class = shift;
1120 1189
1121 $class->SUPER::new ( 1190 $class->SUPER::new (
1278 1347
1279package CFClient::UI::Entry; 1348package CFClient::UI::Entry;
1280 1349
1281our @ISA = CFClient::UI::EntryBase::; 1350our @ISA = CFClient::UI::EntryBase::;
1282 1351
1283use SDL::OpenGL; 1352use CFClient::OpenGL;
1284 1353
1285sub key_down { 1354sub key_down {
1286 my ($self, $ev) = @_; 1355 my ($self, $ev) = @_;
1287 1356
1288 my $sym = $ev->{sym}; 1357 my $sym = $ev->{sym};
1301 1370
1302package CFClient::UI::Button; 1371package CFClient::UI::Button;
1303 1372
1304our @ISA = CFClient::UI::Label::; 1373our @ISA = CFClient::UI::Label::;
1305 1374
1306use SDL::OpenGL; 1375use CFClient::OpenGL;
1307 1376
1308my @tex = 1377my @tex =
1309 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1378 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1310 qw(b1_button_active.png); 1379 qw(b1_button_active.png);
1311 1380
1312sub new { 1381sub new {
1313 my $class = shift; 1382 my $class = shift;
1314 1383
1361package CFClient::UI::CheckBox; 1430package CFClient::UI::CheckBox;
1362 1431
1363our @ISA = CFClient::UI::DrawBG::; 1432our @ISA = CFClient::UI::DrawBG::;
1364 1433
1365my @tex = 1434my @tex =
1366 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1435 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1367 qw(c1_checkbox_bg.png c1_checkbox_active.png); 1436 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1368 1437
1369use SDL::OpenGL; 1438use CFClient::OpenGL;
1370 1439
1371sub new { 1440sub new {
1372 my $class = shift; 1441 my $class = shift;
1373 1442
1374 $class->SUPER::new ( 1443 $class->SUPER::new (
1420 glDisable GL_BLEND; 1489 glDisable GL_BLEND;
1421} 1490}
1422 1491
1423############################################################################# 1492#############################################################################
1424 1493
1425package CFClient::UI::VGauge; 1494package CFClient::UI::Image;
1426 1495
1427our @ISA = CFClient::UI::Base::; 1496our @ISA = CFClient::UI::Base::;
1428 1497
1429use SDL::OpenGL; 1498use CFClient::OpenGL;
1499use Carp qw/confess/;
1430 1500
1431my %tex = ( 1501our %loaded_images;
1432 food => [
1433 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1434 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1435 ],
1436 grace => [
1437 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1438 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1439 ],
1440 hp => [
1441 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1442 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1443 ],
1444 mana => [
1445 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1446 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1447 ],
1448);
1449 1502
1450# eg. VGauge->new (gauge => 'food'), default gauge: food
1451sub new { 1503sub new {
1452 my $class = shift; 1504 my $class = shift;
1453 1505
1454 my $self = $class->SUPER::new (gauge => 'food', @_); 1506 my $self = $class->SUPER::new (@_);
1507
1508 $self->{image} or confess "Image has 'image' not set. This is a fatal error!";
1509
1510 $loaded_images{$self->{image}} ||=
1511 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1512
1513 my $tex = $self->{tex} = $loaded_images{$self->{image}};
1514
1515 Scalar::Util::weaken $loaded_images{$self->{image}};
1516
1517 $self->{aspect} = $tex->{w} / $tex->{h};
1455 1518
1456 $self 1519 $self
1457} 1520}
1458 1521
1459sub size_request { 1522sub size_request {
1460 my ($self) = @_; 1523 my ($self) = @_;
1461 1524
1462 my $tex = $tex{$self->{gauge}}[0]; 1525 ($self->{tex}->{w}, $self->{tex}->{h})
1463
1464 @$tex{qw(w h)}
1465}
1466
1467sub set_max {
1468 my ($self, $max) = @_;
1469
1470 $self->{max_val} = $max;
1471}
1472
1473sub set_value {
1474 my ($self, $val, $max) = @_;
1475
1476 $self->set_max ($max)
1477 if defined $max;
1478
1479 $max = $self->{max_val};
1480 $self->{val} = $val;
1481
1482 $self->update;
1483} 1526}
1484 1527
1485sub _draw { 1528sub _draw {
1486 my ($self) = @_; 1529 my ($self) = @_;
1487 1530
1488 my $tex = $tex{$self->{gauge}}; 1531 my $tex = $self->{tex};
1489 1532
1490 my ($w, $h) = ($self->{w}, $self->{h}); 1533 my ($w, $h) = ($self->{w}, $self->{h});
1491 1534
1492 my $ycut = $self->{val} / ($self->{max_val} || 1); 1535 if ($self->{rot90}) {
1493 $ycut = 1 if $self->{val} > $self->{max_val}; 1536 glRotate 90, 0, 0, 1;
1537 glTranslate 0, -$self->{w}, 0;
1494 1538
1495 my $t1 = $tex->[0]; 1539 ($w, $h) = ($h, $w);
1496 my $t2 = $tex->[1]; 1540 }
1497 1541
1498 glEnable GL_BLEND; 1542 glEnable GL_BLEND;
1499 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1543 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1500 glEnable GL_TEXTURE_2D; 1544 glEnable GL_TEXTURE_2D;
1501 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1545 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1502 1546
1547 $tex->draw_quad (0, 0, $w, $h);
1548
1549 glDisable GL_BLEND;
1550 glDisable GL_TEXTURE_2D;
1551}
1552
1553#############################################################################
1554
1555package CFClient::UI::VGauge;
1556
1557our @ISA = CFClient::UI::Base::;
1558
1559use CFClient::OpenGL;
1560
1561my %tex = (
1562 food => [
1563 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1564 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1565 ],
1566 grace => [
1567 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1568 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1569 ],
1570 hp => [
1571 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1572 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1573 ],
1574 mana => [
1575 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1576 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1577 ],
1578);
1579
1580# eg. VGauge->new (gauge => 'food'), default gauge: food
1581sub new {
1582 my $class = shift;
1583
1584 my $self = $class->SUPER::new (
1585 type => 'food',
1586 @_
1587 );
1588
1589 $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h};
1590
1591 $self
1592}
1593
1594sub size_request {
1595 my ($self) = @_;
1596
1597 #my $tex = $tex{$self->{type}}[0];
1598 #@$tex{qw(w h)}
1599 (0, 0)
1600}
1601
1602sub set_max {
1603 my ($self, $max) = @_;
1604
1605 $self->{max_val} = $max;
1606}
1607
1608sub set_value {
1609 my ($self, $val, $max) = @_;
1610
1611 $self->set_max ($max)
1612 if defined $max;
1613
1614 $max = $self->{max_val};
1615 $self->{val} = $val;
1616
1617 $self->update;
1618}
1619
1620sub _draw {
1621 my ($self) = @_;
1622
1623 my $tex = $tex{$self->{type}};
1624
1625 my ($w, $h) = ($self->{w}, $self->{h});
1626
1627 if ($self->{vertical}) {
1628 glRotate 90, 0, 0, 1;
1629 glTranslate 0, -$self->{w}, 0;
1630
1631 ($w, $h) = ($h, $w);
1632 }
1633
1634 my $ycut = $self->{val} / ($self->{max_val} || 1);
1635 $ycut = 1 if $self->{val} > $self->{max_val};
1636
1637 my $t1 = $tex->[0];
1638 my $t2 = $tex->[1];
1639
1640 glEnable GL_BLEND;
1641 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1642 glEnable GL_TEXTURE_2D;
1643 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1644
1503 my $h1 = $self->{h} - $ycut * $self->{h}; 1645 my $h1 = $self->{h} - $ycut * $self->{h};
1504 my $h2 = $ycut * $self->{h}; 1646 my $h2 = $ycut * $self->{h};
1505 1647
1506 my $yp = 0;
1507
1508 glBindTexture GL_TEXTURE_2D, $t1->{name}; 1648 glBindTexture GL_TEXTURE_2D, $t1->{name};
1509 glBegin GL_QUADS; 1649 glBegin GL_QUADS;
1510 glTexCoord 0 , 0; glVertex 0 , $yp; 1650 glTexCoord 0 , 0; glVertex 0 , 0;
1511 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; 1651 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1;
1512 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; 1652 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1;
1513 glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; 1653 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1514 glEnd; 1654 glEnd;
1515
1516 $yp += $h1;
1517 1655
1518 glBindTexture GL_TEXTURE_2D, $t2->{name}; 1656 glBindTexture GL_TEXTURE_2D, $t2->{name};
1519 glBegin GL_QUADS; 1657 glBegin GL_QUADS;
1520 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; 1658 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1;
1521 glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; 1659 glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2;
1522 glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; 1660 glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2;
1523 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; 1661 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1;
1524 glEnd; 1662 glEnd;
1525 1663
1526 glDisable GL_BLEND; 1664 glDisable GL_BLEND;
1527 glDisable GL_TEXTURE_2D; 1665 glDisable GL_TEXTURE_2D;
1528} 1666}
1529 1667
1530############################################################################# 1668#############################################################################
1531 1669
1670package CFClient::UI::Gauge;
1671
1672our @ISA = CFClient::UI::VBox::;
1673
1674sub new {
1675 my ($class, %arg) = shift;
1676
1677 my $self = $class->SUPER::new (
1678 @_,
1679 );
1680
1681 $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999");
1682 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1);
1683 $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999");
1684
1685 $self
1686}
1687
1688sub set_fontsize {
1689 my ($self, $fsize) = @_;
1690
1691 $self->{value}->set_fontsize ($fsize);
1692 $self->{max} ->set_fontsize ($fsize);
1693}
1694
1695sub set_value {
1696 my ($self, $val, $max) = @_;
1697
1698 $self->set_max ($max)
1699 if defined $max;
1700
1701 $self->{gauge}->set_value ($val, $max);
1702 $self->{value}->set_text ($val);
1703}
1704
1705sub set_max {
1706 my ($self, $max) = @_;
1707
1708 $self->{gauge}->set_max ($max);
1709 $self->{max}->set_text ($max);
1710}
1711
1712#############################################################################
1713
1532package CFClient::UI::Slider; 1714package CFClient::UI::Slider;
1533 1715
1534use strict; 1716use strict;
1535 1717
1536use SDL::OpenGL; 1718use CFClient::OpenGL;
1537 1719
1538our @ISA = CFClient::UI::DrawBG::; 1720our @ISA = CFClient::UI::DrawBG::;
1539 1721
1540my @tex = 1722my @tex =
1541 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1723 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1666 1848
1667package CFClient::UI::TextView; 1849package CFClient::UI::TextView;
1668 1850
1669our @ISA = CFClient::UI::HBox::; 1851our @ISA = CFClient::UI::HBox::;
1670 1852
1671use SDL::OpenGL; 1853use CFClient::OpenGL;
1672 1854
1673sub new { 1855sub new {
1674 my $class = shift; 1856 my $class = shift;
1675 1857
1676 my $self = $class->SUPER::new ( 1858 my $self = $class->SUPER::new (
1822 2004
1823############################################################################# 2005#############################################################################
1824 2006
1825package CFClient::UI::Animator; 2007package CFClient::UI::Animator;
1826 2008
1827use SDL::OpenGL; 2009use CFClient::OpenGL;
1828 2010
1829our @ISA = CFClient::UI::Bin::; 2011our @ISA = CFClient::UI::Bin::;
1830 2012
1831sub moveto { 2013sub moveto {
1832 my ($self, $x, $y) = @_; 2014 my ($self, $x, $y) = @_;
1905 2087
1906package CFClient::UI::Root; 2088package CFClient::UI::Root;
1907 2089
1908our @ISA = CFClient::UI::Container::; 2090our @ISA = CFClient::UI::Container::;
1909 2091
1910use SDL::OpenGL; 2092use CFClient::OpenGL;
1911 2093
1912sub check_size { 2094sub check_size {
1913 my ($self) = @_; 2095 my ($self) = @_;
1914 2096
1915 $self->configure (0, 0, $::WITH, $::HEIGHT); 2097 $self->configure (0, 0, $::WITH, $::HEIGHT);
1941 ::refresh (); 2123 ::refresh ();
1942} 2124}
1943 2125
1944sub add { 2126sub add {
1945 my ($self, $child) = @_; 2127 my ($self, $child) = @_;
2128
2129 # integerize window positions
2130 $child->{x} = int $child->{x};
2131 $child->{y} = int $child->{y};
1946 2132
1947 $self->SUPER::add ($child); 2133 $self->SUPER::add ($child);
1948} 2134}
1949 2135
1950sub on_refresh { 2136sub on_refresh {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines