… | |
… | |
146 | } |
146 | } |
147 | |
147 | |
148 | sub configure { |
148 | sub 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 += ($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) { |
|
|
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 | |
168 | sub size_allocate { |
178 | sub size_allocate { |
169 | # nothing to be done |
179 | # nothing to be done |
170 | } |
180 | } |
… | |
… | |
623 | sub new { |
633 | sub new { |
624 | my $class = shift; |
634 | my $class = shift; |
625 | |
635 | |
626 | # TODO: user_x, user_y, overwrite moveto? |
636 | # TODO: user_x, user_y, overwrite moveto? |
627 | |
637 | |
628 | $class->SUPER::new ( |
638 | my $self = $class->SUPER::new ( |
629 | bg => [1, 1, 1, 1], |
639 | bg => [1, 1, 1, 1], |
630 | border_bg => [1, 1, 1, 1], |
640 | border_bg => [1, 1, 1, 1], |
631 | border => 0.8, |
641 | border => 0.8, |
632 | @_ |
642 | @_ |
633 | ) |
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 |
634 | } |
652 | } |
635 | |
653 | |
636 | sub border { |
654 | sub border { |
637 | int $_[0]{border} * $::FONTSIZE |
655 | int $_[0]{border} * $::FONTSIZE |
638 | } |
656 | } |
… | |
… | |
653 | sub size_allocate { |
671 | sub size_allocate { |
654 | my ($self, $w, $h) = @_; |
672 | my ($self, $w, $h) = @_; |
655 | |
673 | |
656 | $h -= List::Util::max 0, $self->border * 2; |
674 | $h -= List::Util::max 0, $self->border * 2; |
657 | $w -= List::Util::max 0, $self->border * 2; |
675 | $w -= List::Util::max 0, $self->border * 2; |
|
|
676 | |
|
|
677 | $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) |
|
|
678 | if $self->{title}; |
658 | |
679 | |
659 | $self->child->configure ($self->border, $self->border, $w, $h); |
680 | $self->child->configure ($self->border, $self->border, $w, $h); |
660 | } |
681 | } |
661 | |
682 | |
662 | sub button_down { |
683 | sub button_down { |
… | |
… | |
742 | $bg->draw_quad ($border, $border, $cw, $ch); |
763 | $bg->draw_quad ($border, $border, $cw, $ch); |
743 | |
764 | |
744 | glDisable GL_TEXTURE_2D; |
765 | glDisable GL_TEXTURE_2D; |
745 | glDisable GL_BLEND; |
766 | glDisable GL_BLEND; |
746 | |
767 | |
|
|
768 | $self->{title}->draw if $self->{title}; |
747 | $self->child->draw; |
769 | $self->child->draw; |
748 | } |
770 | } |
749 | |
771 | |
750 | ############################################################################# |
772 | ############################################################################# |
751 | |
773 | |
… | |
… | |
1020 | padding => 2, |
1042 | padding => 2, |
1021 | layout => new CFClient::Layout, |
1043 | layout => new CFClient::Layout, |
1022 | %arg |
1044 | %arg |
1023 | ); |
1045 | ); |
1024 | |
1046 | |
1025 | $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 | } |
1026 | |
1052 | |
1027 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1053 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1028 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1054 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1029 | |
1055 | |
1030 | $self |
1056 | $self |
… | |
… | |
1063 | |
1089 | |
1064 | $self->{layout}->set_width; |
1090 | $self->{layout}->set_width; |
1065 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1091 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1066 | |
1092 | |
1067 | 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 | } |
1068 | |
1103 | |
1069 | ( |
1104 | ( |
1070 | $w + $self->{padding} * 2, |
1105 | $w + $self->{padding} * 2, |
1071 | $h + $self->{padding} * 2, |
1106 | $h + $self->{padding} * 2, |
1072 | ) |
1107 | ) |
… | |
… | |
1455 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
1490 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
1456 | sub new { |
1491 | sub new { |
1457 | my $class = shift; |
1492 | my $class = shift; |
1458 | |
1493 | |
1459 | my $self = $class->SUPER::new ( |
1494 | my $self = $class->SUPER::new ( |
1460 | gauge => 'food', |
1495 | type => 'food', |
1461 | @_ |
1496 | @_ |
1462 | ); |
1497 | ); |
1463 | |
1498 | |
1464 | $self->{aspect} = $tex{$self->{gauge}}[0]{w} / $tex{$self->{gauge}}[0]{h}; |
1499 | $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h}; |
1465 | |
1500 | |
1466 | $self |
1501 | $self |
1467 | } |
1502 | } |
1468 | |
1503 | |
1469 | sub size_request { |
1504 | sub size_request { |
1470 | my ($self) = @_; |
1505 | my ($self) = @_; |
1471 | |
1506 | |
1472 | my $tex = $tex{$self->{gauge}}[0]; |
1507 | my $tex = $tex{$self->{type}}[0]; |
1473 | |
1508 | |
1474 | @$tex{qw(w h)} |
1509 | @$tex{qw(w h)} |
1475 | } |
1510 | } |
1476 | |
1511 | |
1477 | sub set_max { |
1512 | sub set_max { |
… | |
… | |
1493 | } |
1528 | } |
1494 | |
1529 | |
1495 | sub _draw { |
1530 | sub _draw { |
1496 | my ($self) = @_; |
1531 | my ($self) = @_; |
1497 | |
1532 | |
1498 | my $tex = $tex{$self->{gauge}}; |
1533 | my $tex = $tex{$self->{type}}; |
1499 | |
1534 | |
1500 | my ($w, $h) = ($self->{w}, $self->{h}); |
1535 | my ($w, $h) = ($self->{w}, $self->{h}); |
1501 | |
1536 | |
1502 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1537 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1503 | $ycut = 1 if $self->{val} > $self->{max_val}; |
1538 | $ycut = 1 if $self->{val} > $self->{max_val}; |
… | |
… | |
1511 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1546 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1512 | |
1547 | |
1513 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1548 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1514 | my $h2 = $ycut * $self->{h}; |
1549 | my $h2 = $ycut * $self->{h}; |
1515 | |
1550 | |
1516 | my $yp = 0; |
|
|
1517 | |
|
|
1518 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1551 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1519 | glBegin GL_QUADS; |
1552 | glBegin GL_QUADS; |
1520 | glTexCoord 0 , 0; glVertex 0 , $yp; |
1553 | glTexCoord 0 , 0; glVertex 0 , 0; |
1521 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; |
1554 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; |
1522 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; |
1555 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; |
1523 | glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; |
1556 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1524 | glEnd; |
1557 | glEnd; |
1525 | |
|
|
1526 | $yp += $h1; |
|
|
1527 | |
1558 | |
1528 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1559 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1529 | glBegin GL_QUADS; |
1560 | glBegin GL_QUADS; |
1530 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; |
1561 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; |
1531 | glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; |
1562 | glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; |
1532 | glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; |
1563 | glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; |
1533 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; |
1564 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; |
1534 | glEnd; |
1565 | glEnd; |
1535 | |
1566 | |
1536 | glDisable GL_BLEND; |
1567 | glDisable GL_BLEND; |
1537 | glDisable GL_TEXTURE_2D; |
1568 | glDisable GL_TEXTURE_2D; |
|
|
1569 | } |
|
|
1570 | |
|
|
1571 | ############################################################################# |
|
|
1572 | |
|
|
1573 | package CFClient::UI::Gauge; |
|
|
1574 | |
|
|
1575 | our @ISA = CFClient::UI::VBox::; |
|
|
1576 | |
|
|
1577 | sub new { |
|
|
1578 | my ($class, %arg) = shift; |
|
|
1579 | |
|
|
1580 | my $self = $class->SUPER::new ( |
|
|
1581 | @_, |
|
|
1582 | ); |
|
|
1583 | |
|
|
1584 | $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
|
|
1585 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); |
|
|
1586 | $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
|
|
1587 | |
|
|
1588 | $self |
|
|
1589 | } |
|
|
1590 | |
|
|
1591 | sub set_value { |
|
|
1592 | my ($self, $val, $max) = @_; |
|
|
1593 | |
|
|
1594 | $self->set_max ($max) |
|
|
1595 | if defined $max; |
|
|
1596 | |
|
|
1597 | $self->{gauge}->set_value ($val, $max); |
|
|
1598 | $self->{value}->set_text ($val); |
|
|
1599 | } |
|
|
1600 | |
|
|
1601 | sub set_max { |
|
|
1602 | my ($self, $max) = @_; |
|
|
1603 | |
|
|
1604 | $self->{gauge}->set_max ($max); |
|
|
1605 | $self->{max}->set_text ($max); |
1538 | } |
1606 | } |
1539 | |
1607 | |
1540 | ############################################################################# |
1608 | ############################################################################# |
1541 | |
1609 | |
1542 | package CFClient::UI::Slider; |
1610 | package CFClient::UI::Slider; |