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.146 by elmex, Fri Apr 21 15:03:46 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 {
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 += ($w - $w2) * 0.5;
158 $y += ($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 586
572sub size_request { 587sub size_request {
573 my ($self) = @_; 588 my ($self) = @_;
574 my $chld = $self->child 589 my $chld = $self->child
575 or return (0, 0); 590 or return (0, 0);
607 622
608package CFClient::UI::FancyFrame; 623package CFClient::UI::FancyFrame;
609 624
610our @ISA = CFClient::UI::Bin::; 625our @ISA = CFClient::UI::Bin::;
611 626
612use SDL::OpenGL; 627use CFClient::OpenGL;
613 628
614my @tex = 629my @tex =
615 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 630 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
616 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 631 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
617 632
618sub new { 633sub new {
619 my $class = shift; 634 my $class = shift;
620 635
621 # TODO: user_x, user_y, overwrite moveto? 636 # TODO: user_x, user_y, overwrite moveto?
622 637
623 $class->SUPER::new ( 638 my $self = $class->SUPER::new (
624 bg => [1, 1, 1, 1], 639 bg => [1, 1, 1, 1],
625 border_bg => [1, 1, 1, 1], 640 border_bg => [1, 1, 1, 1],
626 border => 0.8, 641 border => 0.8,
627 @_ 642 @_
628 ) 643 );
644
645 $self->{title} &&= new CFClient::UI::Label
646 align => 0,
647 valign => 1,
648 text => $self->{title},
649 fontsize => 1;
650
651 $self
629} 652}
630 653
631sub border { 654sub border {
632 int $_[0]{border} * $::FONTSIZE 655 int $_[0]{border} * $::FONTSIZE
633} 656}
649 my ($self, $w, $h) = @_; 672 my ($self, $w, $h) = @_;
650 673
651 $h -= List::Util::max 0, $self->border * 2; 674 $h -= List::Util::max 0, $self->border * 2;
652 $w -= List::Util::max 0, $self->border * 2; 675 $w -= List::Util::max 0, $self->border * 2;
653 676
677 $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2)
678 if $self->{title};
679
654 $self->child->configure ($self->border, $self->border, $w, $h); 680 $self->child->configure ($self->border, $self->border, $w, $h);
655} 681}
656 682
657sub button_down { 683sub button_down {
658 my ($self, $ev, $x, $y) = @_; 684 my ($self, $ev, $x, $y) = @_;
660 my $border = $self->border; 686 my $border = $self->border;
661 687
662 if ($x < $self->{w} && $x >= $self->{w} - $border 688 if ($x < $self->{w} && $x >= $self->{w} - $border
663 && $y < $self->{h} && $y >= $self->{h} - $border) { 689 && $y < $self->{h} && $y >= $self->{h} - $border) {
664 690
665 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 691 my ($ox, $oy) = ($ev->{x}, $ev->{y});
666 my ($bw, $bh) = ($self->{w}, $self->{h}); 692 my ($bw, $bh) = ($self->{w}, $self->{h});
667 693
668 $self->{motion} = sub { 694 $self->{motion} = sub {
669 my ($ev, $x, $y) = @_; 695 my ($ev, $x, $y) = @_;
670 696
671 ($x, $y) = ($ev->motion_x, $ev->motion_y); 697 ($x, $y) = ($ev->{x}, $ev->{y});
672 698
673 $self->{user_w} = $bw + $x - $ox; 699 $self->{user_w} = $bw + $x - $ox;
674 $self->{user_h} = $bh + $y - $oy; 700 $self->{user_h} = $bh + $y - $oy;
675 $self->check_size; 701 $self->check_size;
676 }; 702 };
677 703
678 } elsif ($x >= 0 && $x < $self->{w} 704 } elsif ($x >= 0 && $x < $self->{w}
679 && $y >= 0 && $y < $border) { 705 && $y >= 0 && $y < $border) {
680 706
681 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 707 my ($ox, $oy) = ($ev->{x}, $ev->{y});
682 my ($bx, $by) = ($self->{x}, $self->{y}); 708 my ($bx, $by) = ($self->{x}, $self->{y});
683 709
684 $self->{motion} = sub { 710 $self->{motion} = sub {
685 my ($ev, $x, $y) = @_; 711 my ($ev, $x, $y) = @_;
686 712
687 ($x, $y) = ($ev->motion_x, $ev->motion_y); 713 ($x, $y) = ($ev->{x}, $ev->{y});
688 714
689 $self->move ($bx + $x - $ox, $by + $y - $oy); 715 $self->move ($bx + $x - $ox, $by + $y - $oy);
690 $self->update; 716 $self->update;
691 }; 717 };
692 } 718 }
737 $bg->draw_quad ($border, $border, $cw, $ch); 763 $bg->draw_quad ($border, $border, $cw, $ch);
738 764
739 glDisable GL_TEXTURE_2D; 765 glDisable GL_TEXTURE_2D;
740 glDisable GL_BLEND; 766 glDisable GL_BLEND;
741 767
768 $self->{title}->draw if $self->{title};
742 $self->child->draw; 769 $self->child->draw;
743} 770}
744 771
745############################################################################# 772#############################################################################
746 773
748 775
749our @ISA = CFClient::UI::Base::; 776our @ISA = CFClient::UI::Base::;
750 777
751use List::Util qw(max sum); 778use List::Util qw(max sum);
752 779
753use SDL::OpenGL; 780use CFClient::OpenGL;
754 781
755sub new { 782sub new {
756 my $class = shift; 783 my $class = shift;
757 784
758 $class->SUPER::new ( 785 $class->SUPER::new (
999 1026
1000package CFClient::UI::Label; 1027package CFClient::UI::Label;
1001 1028
1002our @ISA = CFClient::UI::Base::; 1029our @ISA = CFClient::UI::Base::;
1003 1030
1004use SDL::OpenGL; 1031use CFClient::OpenGL;
1005 1032
1006sub new { 1033sub new {
1007 my ($class, %arg) = @_; 1034 my ($class, %arg) = @_;
1008 1035
1009 my $self = $class->SUPER::new ( 1036 my $self = $class->SUPER::new (
1015 padding => 2, 1042 padding => 2,
1016 layout => new CFClient::Layout, 1043 layout => new CFClient::Layout,
1017 %arg 1044 %arg
1018 ); 1045 );
1019 1046
1020 $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# 1047 if (exists $self->{template}) {
1048 my $layout = new CFClient::Layout;
1049 $layout->set_text (delete $self->{template});
1050 $self->{template} = $layout;
1051 }
1021 1052
1022 $self->set_text (delete $self->{text}) if exists $self->{text}; 1053 $self->set_text (delete $self->{text}) if exists $self->{text};
1023 $self->set_markup (delete $self->{markup}) if exists $self->{markup}; 1054 $self->set_markup (delete $self->{markup}) if exists $self->{markup};
1024 1055
1025 $self 1056 $self
1058 1089
1059 $self->{layout}->set_width; 1090 $self->{layout}->set_width;
1060 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1091 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1061 1092
1062 my ($w, $h) = $self->{layout}->size; 1093 my ($w, $h) = $self->{layout}->size;
1094
1095 if (exists $self->{template}) {
1096 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1097
1098 my ($w2, $h2) = $self->{template}->size;
1099
1100 $w = List::Util::max $w, $w2;
1101 $h = List::Util::max $h, $h2;
1102 }
1063 1103
1064 ( 1104 (
1065 $w + $self->{padding} * 2, 1105 $w + $self->{padding} * 2,
1066 $h + $self->{padding} * 2, 1106 $h + $self->{padding} * 2,
1067 ) 1107 )
1069 1109
1070sub size_allocate { 1110sub size_allocate {
1071 my ($self, $w, $h) = @_; 1111 my ($self, $w, $h) = @_;
1072 1112
1073 delete $self->{texture}; 1113 delete $self->{texture};
1114}
1115
1116sub set_fontsize {
1117 my ($self, $fontsize) = @_;
1118
1119 $self->{fontsize} = $fontsize;
1120 $self->update;
1074} 1121}
1075 1122
1076sub _draw { 1123sub _draw {
1077 my ($self) = @_; 1124 my ($self) = @_;
1078 1125
1111 1158
1112package CFClient::UI::EntryBase; 1159package CFClient::UI::EntryBase;
1113 1160
1114our @ISA = CFClient::UI::Label::; 1161our @ISA = CFClient::UI::Label::;
1115 1162
1116use SDL::OpenGL; 1163use CFClient::OpenGL;
1117 1164
1118sub new { 1165sub new {
1119 my $class = shift; 1166 my $class = shift;
1120 1167
1121 $class->SUPER::new ( 1168 $class->SUPER::new (
1278 1325
1279package CFClient::UI::Entry; 1326package CFClient::UI::Entry;
1280 1327
1281our @ISA = CFClient::UI::EntryBase::; 1328our @ISA = CFClient::UI::EntryBase::;
1282 1329
1283use SDL::OpenGL; 1330use CFClient::OpenGL;
1284 1331
1285sub key_down { 1332sub key_down {
1286 my ($self, $ev) = @_; 1333 my ($self, $ev) = @_;
1287 1334
1288 my $sym = $ev->{sym}; 1335 my $sym = $ev->{sym};
1301 1348
1302package CFClient::UI::Button; 1349package CFClient::UI::Button;
1303 1350
1304our @ISA = CFClient::UI::Label::; 1351our @ISA = CFClient::UI::Label::;
1305 1352
1306use SDL::OpenGL; 1353use CFClient::OpenGL;
1307 1354
1308my @tex = 1355my @tex =
1309 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1356 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1310 qw(b1_button_active.png); 1357 qw(b1_button_active.png);
1311 1358
1312sub new { 1359sub new {
1313 my $class = shift; 1360 my $class = shift;
1314 1361
1361package CFClient::UI::CheckBox; 1408package CFClient::UI::CheckBox;
1362 1409
1363our @ISA = CFClient::UI::DrawBG::; 1410our @ISA = CFClient::UI::DrawBG::;
1364 1411
1365my @tex = 1412my @tex =
1366 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1413 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1367 qw(c1_checkbox_bg.png c1_checkbox_active.png); 1414 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1368 1415
1369use SDL::OpenGL; 1416use CFClient::OpenGL;
1370 1417
1371sub new { 1418sub new {
1372 my $class = shift; 1419 my $class = shift;
1373 1420
1374 $class->SUPER::new ( 1421 $class->SUPER::new (
1420 glDisable GL_BLEND; 1467 glDisable GL_BLEND;
1421} 1468}
1422 1469
1423############################################################################# 1470#############################################################################
1424 1471
1425package CFClient::UI::VGauge; 1472package CFClient::UI::Image;
1426 1473
1427our @ISA = CFClient::UI::Base::; 1474our @ISA = CFClient::UI::Base::;
1428 1475
1429use SDL::OpenGL; 1476use CFClient::OpenGL;
1477use Carp qw/confess/;
1430 1478
1431my %tex = ( 1479our %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 1480
1450# eg. VGauge->new (gauge => 'food'), default gauge: food
1451sub new { 1481sub new {
1452 my $class = shift; 1482 my $class = shift;
1453 1483
1454 my $self = $class->SUPER::new (gauge => 'food', @_); 1484 my $self = $class->SUPER::new (@_);
1485
1486 $self->{image} or confess "Image has 'image' not set. This is a fatal error!";
1487
1488 $loaded_images{$self->{image}} ||=
1489 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1490
1491 my $tex = $self->{tex} = $loaded_images{$self->{image}};
1492
1493 $self->{aspect} = $tex->{w} / $tex->{h};
1455 1494
1456 $self 1495 $self
1457} 1496}
1458 1497
1459sub size_request { 1498sub size_request {
1460 my ($self) = @_; 1499 my ($self) = @_;
1461 1500
1462 my $tex = $tex{$self->{gauge}}[0]; 1501 ($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} 1502}
1484 1503
1485sub _draw { 1504sub _draw {
1486 my ($self) = @_; 1505 my ($self) = @_;
1487 1506
1488 my $tex = $tex{$self->{gauge}}; 1507 my $tex = $self->{tex};
1489 1508
1490 my ($w, $h) = ($self->{w}, $self->{h}); 1509 my ($w, $h) = ($self->{w}, $self->{h});
1491 1510
1492 my $ycut = $self->{val} / ($self->{max_val} || 1); 1511 if ($self->{rot90}) {
1493 $ycut = 1 if $self->{val} > $self->{max_val}; 1512 glRotate 90, 0, 0, 1;
1513 glTranslate 0, -$self->{w}, 0;
1494 1514
1495 my $t1 = $tex->[0]; 1515 ($w, $h) = ($h, $w);
1496 my $t2 = $tex->[1]; 1516 }
1497 1517
1498 glEnable GL_BLEND; 1518 glEnable GL_BLEND;
1499 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1519 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1500 glEnable GL_TEXTURE_2D; 1520 glEnable GL_TEXTURE_2D;
1501 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1521 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1502 1522
1523 $tex->draw_quad (0, 0, $w, $h);
1524
1525 glDisable GL_BLEND;
1526 glDisable GL_TEXTURE_2D;
1527}
1528
1529#############################################################################
1530
1531package CFClient::UI::VGauge;
1532
1533our @ISA = CFClient::UI::Base::;
1534
1535use CFClient::OpenGL;
1536
1537my %tex = (
1538 food => [
1539 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1540 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1541 ],
1542 grace => [
1543 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1544 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1545 ],
1546 hp => [
1547 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1548 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1549 ],
1550 mana => [
1551 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1552 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1553 ],
1554);
1555
1556# eg. VGauge->new (gauge => 'food'), default gauge: food
1557sub new {
1558 my $class = shift;
1559
1560 my $self = $class->SUPER::new (
1561 type => 'food',
1562 @_
1563 );
1564
1565 $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h};
1566
1567 $self
1568}
1569
1570sub size_request {
1571 my ($self) = @_;
1572
1573 #my $tex = $tex{$self->{type}}[0];
1574 #@$tex{qw(w h)}
1575 (0, 0)
1576}
1577
1578sub set_max {
1579 my ($self, $max) = @_;
1580
1581 $self->{max_val} = $max;
1582}
1583
1584sub set_value {
1585 my ($self, $val, $max) = @_;
1586
1587 $self->set_max ($max)
1588 if defined $max;
1589
1590 $max = $self->{max_val};
1591 $self->{val} = $val;
1592
1593 $self->update;
1594}
1595
1596sub _draw {
1597 my ($self) = @_;
1598
1599 my $tex = $tex{$self->{type}};
1600
1601 my ($w, $h) = ($self->{w}, $self->{h});
1602
1603 if ($self->{vertical}) {
1604 glRotate 90, 0, 0, 1;
1605 glTranslate 0, -$self->{w}, 0;
1606
1607 ($w, $h) = ($h, $w);
1608 }
1609
1610 my $ycut = $self->{val} / ($self->{max_val} || 1);
1611 $ycut = 1 if $self->{val} > $self->{max_val};
1612
1613 my $t1 = $tex->[0];
1614 my $t2 = $tex->[1];
1615
1616 glEnable GL_BLEND;
1617 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1618 glEnable GL_TEXTURE_2D;
1619 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1620
1503 my $h1 = $self->{h} - $ycut * $self->{h}; 1621 my $h1 = $self->{h} - $ycut * $self->{h};
1504 my $h2 = $ycut * $self->{h}; 1622 my $h2 = $ycut * $self->{h};
1505 1623
1506 my $yp = 0;
1507
1508 glBindTexture GL_TEXTURE_2D, $t1->{name}; 1624 glBindTexture GL_TEXTURE_2D, $t1->{name};
1509 glBegin GL_QUADS; 1625 glBegin GL_QUADS;
1510 glTexCoord 0 , 0; glVertex 0 , $yp; 1626 glTexCoord 0 , 0; glVertex 0 , 0;
1511 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; 1627 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1;
1512 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; 1628 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1;
1513 glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; 1629 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1514 glEnd; 1630 glEnd;
1515
1516 $yp += $h1;
1517 1631
1518 glBindTexture GL_TEXTURE_2D, $t2->{name}; 1632 glBindTexture GL_TEXTURE_2D, $t2->{name};
1519 glBegin GL_QUADS; 1633 glBegin GL_QUADS;
1520 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; 1634 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1;
1521 glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; 1635 glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2;
1522 glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; 1636 glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2;
1523 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; 1637 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1;
1524 glEnd; 1638 glEnd;
1525 1639
1526 glDisable GL_BLEND; 1640 glDisable GL_BLEND;
1527 glDisable GL_TEXTURE_2D; 1641 glDisable GL_TEXTURE_2D;
1528} 1642}
1529 1643
1530############################################################################# 1644#############################################################################
1531 1645
1646package CFClient::UI::Gauge;
1647
1648our @ISA = CFClient::UI::VBox::;
1649
1650sub new {
1651 my ($class, %arg) = shift;
1652
1653 my $self = $class->SUPER::new (
1654 @_,
1655 );
1656
1657 $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999");
1658 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1);
1659 $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999");
1660
1661 $self
1662}
1663
1664sub set_fontsize {
1665 my ($self, $fsize) = @_;
1666
1667 $self->{value}->set_fontsize ($fsize);
1668 $self->{max} ->set_fontsize ($fsize);
1669 $self->update;
1670}
1671
1672sub set_value {
1673 my ($self, $val, $max) = @_;
1674
1675 $self->set_max ($max)
1676 if defined $max;
1677
1678 $self->{gauge}->set_value ($val, $max);
1679 $self->{value}->set_text ($val);
1680}
1681
1682sub set_max {
1683 my ($self, $max) = @_;
1684
1685 $self->{gauge}->set_max ($max);
1686 $self->{max}->set_text ($max);
1687}
1688
1689#############################################################################
1690
1532package CFClient::UI::Slider; 1691package CFClient::UI::Slider;
1533 1692
1534use strict; 1693use strict;
1535 1694
1536use SDL::OpenGL; 1695use CFClient::OpenGL;
1537 1696
1538our @ISA = CFClient::UI::DrawBG::; 1697our @ISA = CFClient::UI::DrawBG::;
1539 1698
1540my @tex = 1699my @tex =
1541 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1700 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1666 1825
1667package CFClient::UI::TextView; 1826package CFClient::UI::TextView;
1668 1827
1669our @ISA = CFClient::UI::HBox::; 1828our @ISA = CFClient::UI::HBox::;
1670 1829
1671use SDL::OpenGL; 1830use CFClient::OpenGL;
1672 1831
1673sub new { 1832sub new {
1674 my $class = shift; 1833 my $class = shift;
1675 1834
1676 my $self = $class->SUPER::new ( 1835 my $self = $class->SUPER::new (
1822 1981
1823############################################################################# 1982#############################################################################
1824 1983
1825package CFClient::UI::Animator; 1984package CFClient::UI::Animator;
1826 1985
1827use SDL::OpenGL; 1986use CFClient::OpenGL;
1828 1987
1829our @ISA = CFClient::UI::Bin::; 1988our @ISA = CFClient::UI::Bin::;
1830 1989
1831sub moveto { 1990sub moveto {
1832 my ($self, $x, $y) = @_; 1991 my ($self, $x, $y) = @_;
1905 2064
1906package CFClient::UI::Root; 2065package CFClient::UI::Root;
1907 2066
1908our @ISA = CFClient::UI::Container::; 2067our @ISA = CFClient::UI::Container::;
1909 2068
1910use SDL::OpenGL; 2069use CFClient::OpenGL;
1911 2070
1912sub check_size { 2071sub check_size {
1913 my ($self) = @_; 2072 my ($self) = @_;
1914 2073
1915 $self->configure (0, 0, $::WITH, $::HEIGHT); 2074 $self->configure (0, 0, $::WITH, $::HEIGHT);
1941 ::refresh (); 2100 ::refresh ();
1942} 2101}
1943 2102
1944sub add { 2103sub add {
1945 my ($self, $child) = @_; 2104 my ($self, $child) = @_;
2105
2106 # integerize window positions
2107 $child->{x} = int $child->{x};
2108 $child->{y} = int $child->{y};
1946 2109
1947 $self->SUPER::add ($child); 2110 $self->SUPER::add ($child);
1948} 2111}
1949 2112
1950sub on_refresh { 2113sub on_refresh {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines