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.138 by root, Wed Apr 19 23:37:49 2006 UTC vs.
Revision 1.143 by root, Thu Apr 20 21:28:51 2006 UTC

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}
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
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 )
1449 1489
1450# eg. VGauge->new (gauge => 'food'), default gauge: food 1490# eg. VGauge->new (gauge => 'food'), default gauge: food
1451sub new { 1491sub new {
1452 my $class = shift; 1492 my $class = shift;
1453 1493
1454 my $self = $class->SUPER::new (gauge => 'food', @_); 1494 my $self = $class->SUPER::new (
1495 type => 'food',
1496 @_
1497 );
1498
1499 $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h};
1455 1500
1456 $self 1501 $self
1457} 1502}
1458 1503
1459sub size_request { 1504sub size_request {
1460 my ($self) = @_; 1505 my ($self) = @_;
1461 1506
1462 my $tex = $tex{$self->{gauge}}[0]; 1507 #my $tex = $tex{$self->{type}}[0];
1463
1464 @$tex{qw(w h)} 1508 #@$tex{qw(w h)}
1509 (0, 0)
1465} 1510}
1466 1511
1467sub set_max { 1512sub set_max {
1468 my ($self, $max) = @_; 1513 my ($self, $max) = @_;
1469 1514
1483} 1528}
1484 1529
1485sub _draw { 1530sub _draw {
1486 my ($self) = @_; 1531 my ($self) = @_;
1487 1532
1488 my $tex = $tex{$self->{gauge}}; 1533 my $tex = $tex{$self->{type}};
1489 1534
1490 my ($w, $h) = ($self->{w}, $self->{h}); 1535 my ($w, $h) = ($self->{w}, $self->{h});
1536
1537 if ($self->{vertical}) {
1538 glRotate 90, 0, 0, 1;
1539 glTranslate 0, -$self->{w}, 0;
1540
1541 ($w, $h) = ($h, $w);
1542 }
1491 1543
1492 my $ycut = $self->{val} / ($self->{max_val} || 1); 1544 my $ycut = $self->{val} / ($self->{max_val} || 1);
1493 $ycut = 1 if $self->{val} > $self->{max_val}; 1545 $ycut = 1 if $self->{val} > $self->{max_val};
1494 1546
1495 my $t1 = $tex->[0]; 1547 my $t1 = $tex->[0];
1501 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1553 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1502 1554
1503 my $h1 = $self->{h} - $ycut * $self->{h}; 1555 my $h1 = $self->{h} - $ycut * $self->{h};
1504 my $h2 = $ycut * $self->{h}; 1556 my $h2 = $ycut * $self->{h};
1505 1557
1506 my $yp = 0;
1507
1508 glBindTexture GL_TEXTURE_2D, $t1->{name}; 1558 glBindTexture GL_TEXTURE_2D, $t1->{name};
1509 glBegin GL_QUADS; 1559 glBegin GL_QUADS;
1510 glTexCoord 0 , 0; glVertex 0 , $yp; 1560 glTexCoord 0 , 0; glVertex 0 , 0;
1511 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; 1561 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1;
1512 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; 1562 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1;
1513 glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; 1563 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1514 glEnd; 1564 glEnd;
1515
1516 $yp += $h1;
1517 1565
1518 glBindTexture GL_TEXTURE_2D, $t2->{name}; 1566 glBindTexture GL_TEXTURE_2D, $t2->{name};
1519 glBegin GL_QUADS; 1567 glBegin GL_QUADS;
1520 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; 1568 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1;
1521 glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; 1569 glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2;
1522 glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; 1570 glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2;
1523 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; 1571 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1;
1524 glEnd; 1572 glEnd;
1525 1573
1526 glDisable GL_BLEND; 1574 glDisable GL_BLEND;
1527 glDisable GL_TEXTURE_2D; 1575 glDisable GL_TEXTURE_2D;
1576}
1577
1578#############################################################################
1579
1580package CFClient::UI::Gauge;
1581
1582our @ISA = CFClient::UI::VBox::;
1583
1584sub new {
1585 my ($class, %arg) = shift;
1586
1587 my $self = $class->SUPER::new (
1588 @_,
1589 );
1590
1591 $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999");
1592 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1);
1593 $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999");
1594
1595 $self
1596}
1597
1598sub set_value {
1599 my ($self, $val, $max) = @_;
1600
1601 $self->set_max ($max)
1602 if defined $max;
1603
1604 $self->{gauge}->set_value ($val, $max);
1605 $self->{value}->set_text ($val);
1606}
1607
1608sub set_max {
1609 my ($self, $max) = @_;
1610
1611 $self->{gauge}->set_max ($max);
1612 $self->{max}->set_text ($max);
1528} 1613}
1529 1614
1530############################################################################# 1615#############################################################################
1531 1616
1532package CFClient::UI::Slider; 1617package CFClient::UI::Slider;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines