… | |
… | |
14 | our $BUTTON_STATE; |
14 | our $BUTTON_STATE; |
15 | |
15 | |
16 | sub check_tooltip { |
16 | sub check_tooltip { |
17 | if (!$GRAB) { |
17 | if (!$GRAB) { |
18 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
18 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
19 | if (exists $widget->{tooltip}) { |
19 | if (length $widget->{tooltip}) { |
20 | |
20 | |
21 | if ($TOOLTIP->{owner} != $widget) { |
21 | if ($TOOLTIP->{owner} != $widget) { |
22 | $TOOLTIP->{owner} = $widget; |
22 | $TOOLTIP->{owner} = $widget; |
|
|
23 | |
|
|
24 | my $tip = $widget->{tooltip}; |
|
|
25 | |
|
|
26 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
|
|
27 | |
23 | $TOOLTIP->set_text ($widget->{tooltip}); |
28 | $TOOLTIP->set_markup ($widget->{tooltip}); |
24 | $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0)); |
29 | $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0)); |
25 | $TOOLTIP->show; |
30 | $TOOLTIP->show; |
26 | } |
31 | } |
27 | |
32 | |
28 | return; |
33 | return; |
… | |
… | |
137 | } |
142 | } |
138 | |
143 | |
139 | $self |
144 | $self |
140 | } |
145 | } |
141 | |
146 | |
|
|
147 | sub destroy { |
|
|
148 | my ($self) = @_; |
|
|
149 | |
|
|
150 | $self->hide; |
|
|
151 | %$self = (); |
|
|
152 | } |
|
|
153 | |
142 | sub show { |
154 | sub show { |
143 | my ($self) = @_; |
155 | my ($self) = @_; |
144 | |
156 | |
145 | return if $self->{parent}; |
157 | return if $self->{parent}; |
146 | |
158 | |
… | |
… | |
163 | $self->{z} = $z if defined $z; |
175 | $self->{z} = $z if defined $z; |
164 | |
176 | |
165 | $self->update; |
177 | $self->update; |
166 | } |
178 | } |
167 | |
179 | |
168 | sub needs_redraw { |
180 | sub set_size { |
169 | 0 |
181 | my ($self, $w, $h) = @_; |
|
|
182 | |
|
|
183 | $self->{user_w} = $w; |
|
|
184 | $self->{user_h} = $h; |
|
|
185 | |
|
|
186 | $self->check_size; |
170 | } |
187 | } |
171 | |
188 | |
172 | sub size_request { |
189 | sub size_request { |
173 | require Carp; |
190 | require Carp; |
174 | Carp::confess "size_request is abstract"; |
191 | Carp::confess "size_request is abstract"; |
… | |
… | |
204 | } |
221 | } |
205 | } |
222 | } |
206 | |
223 | |
207 | sub size_allocate { |
224 | sub size_allocate { |
208 | # nothing to be done |
225 | # nothing to be done |
|
|
226 | } |
|
|
227 | |
|
|
228 | sub set_max_size { |
|
|
229 | my ($self, $w, $h) = @_; |
|
|
230 | |
|
|
231 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
|
|
232 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
209 | } |
233 | } |
210 | |
234 | |
211 | # return top left coordinates |
235 | # return top left coordinates |
212 | sub _topleft { |
236 | sub _topleft { |
213 | my ($self, $x, $y) = @_; |
237 | my ($self, $x, $y) = @_; |
… | |
… | |
296 | glVertex $x + $self->{w}, $y + $self->{h}; |
320 | glVertex $x + $self->{w}, $y + $self->{h}; |
297 | glVertex $x , $y + $self->{h}; |
321 | glVertex $x , $y + $self->{h}; |
298 | glEnd; |
322 | glEnd; |
299 | glDisable GL_BLEND; |
323 | glDisable GL_BLEND; |
300 | } |
324 | } |
|
|
325 | |
|
|
326 | if ($ENV{PCLIENT_DEBUG}) { |
|
|
327 | glPushMatrix; |
|
|
328 | glColor 1, 1, 0, 1; |
|
|
329 | glTranslate $self->{x} + 0.375, $self->{y} + 0.375; |
|
|
330 | glBegin GL_LINE_LOOP; |
|
|
331 | glVertex 0 , 0; |
|
|
332 | glVertex $self->{w}, 0; |
|
|
333 | glVertex $self->{w}, $self->{h}; |
|
|
334 | glVertex 0 , $self->{h}; |
|
|
335 | glEnd; |
|
|
336 | glPopMatrix; |
|
|
337 | CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
338 | } |
301 | } |
339 | } |
302 | |
340 | |
303 | sub _draw { |
341 | sub _draw { |
304 | my ($self) = @_; |
342 | my ($self) = @_; |
305 | |
343 | |
… | |
… | |
325 | } |
363 | } |
326 | |
364 | |
327 | sub check_size { |
365 | sub check_size { |
328 | my ($self) = @_; |
366 | my ($self) = @_; |
329 | |
367 | |
330 | return unless $self->{parent}; |
368 | $self->{parent} |
|
|
369 | or return 1; |
331 | |
370 | |
332 | my ($w, $h) = $self->size_request; |
371 | my ($w, $h) = $self->{user_w} && $self->{user_h} |
|
|
372 | ? @$self{qw(user_w user_h)} |
|
|
373 | : $self->size_request; |
333 | |
374 | |
334 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
375 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
335 | $self->{req_w} = $w; |
376 | $self->{req_w} = $w; |
336 | $self->{req_h} = $h; |
377 | $self->{req_h} = $h; |
337 | |
378 | |
338 | $self->{parent}->check_size; |
379 | $self->{parent}->check_size |
|
|
380 | or $self->size_allocate ( |
|
|
381 | (List::Util::max $self->{w}, $w), |
|
|
382 | (List::Util::max $self->{h}, $h), |
|
|
383 | ); |
|
|
384 | |
|
|
385 | 1 |
|
|
386 | } else { |
|
|
387 | 0 |
339 | } |
388 | } |
340 | } |
389 | } |
341 | |
390 | |
342 | sub update { |
391 | sub update { |
343 | my ($self) = @_; |
392 | my ($self) = @_; |
… | |
… | |
464 | |
513 | |
465 | $self->check_size; |
514 | $self->check_size; |
466 | $self->update; |
515 | $self->update; |
467 | } |
516 | } |
468 | |
517 | |
|
|
518 | sub clear { |
|
|
519 | my ($self) = @_; |
|
|
520 | |
|
|
521 | delete $_->{parent} |
|
|
522 | for @{ delete $self->{children} }; |
|
|
523 | |
|
|
524 | $self->{children} = []; |
|
|
525 | } |
|
|
526 | |
469 | sub find_widget { |
527 | sub find_widget { |
470 | my ($self, $x, $y) = @_; |
528 | my ($self, $x, $y) = @_; |
471 | |
529 | |
472 | $x -= $self->{x}; |
530 | $x -= $self->{x}; |
473 | $y -= $self->{y}; |
531 | $y -= $self->{y}; |
… | |
… | |
631 | border => 0.8, |
689 | border => 0.8, |
632 | @_ |
690 | @_ |
633 | ); |
691 | ); |
634 | |
692 | |
635 | $self |
693 | $self |
636 | } |
|
|
637 | |
|
|
638 | sub set_size { |
|
|
639 | my ($self, $w, $h) = @_; |
|
|
640 | $self->{req_w} = $w; |
|
|
641 | $self->{req_h} = $h; |
|
|
642 | $self->check_size; |
|
|
643 | } |
|
|
644 | |
|
|
645 | sub size_request { |
|
|
646 | my ($self) = @_; |
|
|
647 | ($self->{req_w}, $self->{req_h}) |
|
|
648 | } |
|
|
649 | |
|
|
650 | sub size_allocate { |
|
|
651 | my ($self, $w, $h) = @_; |
|
|
652 | $self->{w} = $w; |
|
|
653 | $self->{h} = $h; |
|
|
654 | $self->child->configure (0, 0, $w, $h); |
|
|
655 | } |
694 | } |
656 | |
695 | |
657 | sub _draw { |
696 | sub _draw { |
658 | my ($self) = @_; |
697 | my ($self) = @_; |
659 | |
698 | |
… | |
… | |
716 | int $_[0]{border} * $::FONTSIZE |
755 | int $_[0]{border} * $::FONTSIZE |
717 | } |
756 | } |
718 | |
757 | |
719 | sub size_request { |
758 | sub size_request { |
720 | my ($self) = @_; |
759 | my ($self) = @_; |
721 | |
|
|
722 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
|
|
723 | |
760 | |
724 | my ($w, $h) = $self->SUPER::size_request; |
761 | my ($w, $h) = $self->SUPER::size_request; |
725 | |
762 | |
726 | ( |
763 | ( |
727 | $w + $self->border * 2, |
764 | $w + $self->border * 2, |
… | |
… | |
1094 | sub new { |
1131 | sub new { |
1095 | my ($class, %arg) = @_; |
1132 | my ($class, %arg) = @_; |
1096 | |
1133 | |
1097 | my $self = $class->SUPER::new ( |
1134 | my $self = $class->SUPER::new ( |
1098 | fg => [1, 1, 1], |
1135 | fg => [1, 1, 1], |
|
|
1136 | #font => default_font |
1099 | fontsize => 1, |
1137 | fontsize => 1, |
1100 | text => "", |
1138 | text => "", |
1101 | align => -1, |
1139 | align => -1, |
1102 | valign => -1, |
1140 | valign => -1, |
1103 | padding => 2, |
1141 | padding => 2, |
… | |
… | |
1116 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1154 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1117 | |
1155 | |
1118 | $self |
1156 | $self |
1119 | } |
1157 | } |
1120 | |
1158 | |
1121 | sub escape_text { |
1159 | sub escape { |
1122 | local $_ = $_[1]; |
1160 | local $_ = $_[1]; |
1123 | |
1161 | |
1124 | s/&/&/g; |
1162 | s/&/&/g; |
1125 | s/>/>/g; |
1163 | s/>/>/g; |
1126 | s/</</g; |
1164 | s/</</g; |
… | |
… | |
1149 | } |
1187 | } |
1150 | |
1188 | |
1151 | sub size_request { |
1189 | sub size_request { |
1152 | my ($self) = @_; |
1190 | my ($self) = @_; |
1153 | |
1191 | |
1154 | $self->{layout}->set_width; |
1192 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
|
|
1193 | $self->{layout}->set_width ($self->{max_w} || -1); |
1155 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1194 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1156 | |
1195 | |
1157 | my ($w, $h) = $self->{layout}->size; |
1196 | my ($w, $h) = $self->{layout}->size; |
1158 | |
1197 | |
1159 | if (exists $self->{template}) { |
1198 | if (exists $self->{template}) { |
|
|
1199 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
1160 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1200 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1161 | |
1201 | |
1162 | my ($w2, $h2) = $self->{template}->size; |
1202 | my ($w2, $h2) = $self->{template}->size; |
1163 | |
1203 | |
1164 | $w = List::Util::max $w, $w2; |
1204 | $w = List::Util::max $w, $w2; |
… | |
… | |
1179 | |
1219 | |
1180 | sub set_fontsize { |
1220 | sub set_fontsize { |
1181 | my ($self, $fontsize) = @_; |
1221 | my ($self, $fontsize) = @_; |
1182 | |
1222 | |
1183 | $self->{fontsize} = $fontsize; |
1223 | $self->{fontsize} = $fontsize; |
|
|
1224 | delete $self->{texture}; |
1184 | $self->check_size; |
1225 | $self->check_size; |
|
|
1226 | $self->update; |
1185 | } |
1227 | } |
1186 | |
1228 | |
1187 | sub _draw { |
1229 | sub _draw { |
1188 | my ($self) = @_; |
1230 | my ($self) = @_; |
1189 | |
1231 | |
1190 | my $tex = $self->{texture} ||= do { |
1232 | my $tex = $self->{texture} ||= do { |
|
|
1233 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1191 | $self->{layout}->set_width ($self->{w}); |
1234 | $self->{layout}->set_width ($self->{w}); |
1192 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1235 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1193 | new_from_layout CFClient::Texture $self->{layout} |
1236 | new_from_layout CFClient::Texture $self->{layout} |
1194 | }; |
1237 | }; |
1195 | |
1238 | |
… | |
… | |
1598 | |
1641 | |
1599 | package CFClient::UI::VGauge; |
1642 | package CFClient::UI::VGauge; |
1600 | |
1643 | |
1601 | our @ISA = CFClient::UI::Base::; |
1644 | our @ISA = CFClient::UI::Base::; |
1602 | |
1645 | |
|
|
1646 | use List::Util qw(min max); |
|
|
1647 | |
1603 | use CFClient::OpenGL; |
1648 | use CFClient::OpenGL; |
1604 | |
1649 | |
1605 | my %tex = ( |
1650 | my %tex = ( |
1606 | food => [ |
1651 | food => [ |
1607 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1652 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1608 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
1653 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
1609 | ], |
1654 | ], |
1610 | grace => [ |
1655 | grace => [ |
1611 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1656 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1612 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
1657 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ |
1613 | ], |
1658 | ], |
1614 | hp => [ |
1659 | hp => [ |
1615 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1660 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1616 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
1661 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
1617 | ], |
1662 | ], |
1618 | mana => [ |
1663 | mana => [ |
1619 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1664 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1620 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
1665 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ |
1621 | ], |
1666 | ], |
1622 | ); |
1667 | ); |
1623 | |
1668 | |
1624 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
1669 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
1625 | sub new { |
1670 | sub new { |
… | |
… | |
1663 | |
1708 | |
1664 | sub _draw { |
1709 | sub _draw { |
1665 | my ($self) = @_; |
1710 | my ($self) = @_; |
1666 | |
1711 | |
1667 | my $tex = $tex{$self->{type}}; |
1712 | my $tex = $tex{$self->{type}}; |
|
|
1713 | my ($t1, $t2, $t3) = @$tex; |
1668 | |
1714 | |
1669 | my ($w, $h) = ($self->{w}, $self->{h}); |
1715 | my ($w, $h) = ($self->{w}, $self->{h}); |
1670 | |
1716 | |
1671 | if ($self->{vertical}) { |
1717 | if ($self->{vertical}) { |
1672 | glRotate 90, 0, 0, 1; |
1718 | glRotate 90, 0, 0, 1; |
… | |
… | |
1674 | |
1720 | |
1675 | ($w, $h) = ($h, $w); |
1721 | ($w, $h) = ($h, $w); |
1676 | } |
1722 | } |
1677 | |
1723 | |
1678 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1724 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1679 | $ycut = 1 if $self->{val} > $self->{max_val}; |
|
|
1680 | |
1725 | |
1681 | my $t1 = $tex->[0]; |
1726 | my $ycut1 = max 0, min 1, $ycut; |
1682 | my $t2 = $tex->[1]; |
1727 | my $ycut2 = max 0, min 1, $ycut - 1; |
|
|
1728 | |
|
|
1729 | my $h1 = $self->{h} * (1 - $ycut1); |
|
|
1730 | my $h2 = $self->{h} * (1 - $ycut2); |
1683 | |
1731 | |
1684 | glEnable GL_BLEND; |
1732 | glEnable GL_BLEND; |
1685 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1733 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1686 | glEnable GL_TEXTURE_2D; |
1734 | glEnable GL_TEXTURE_2D; |
1687 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1735 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1688 | |
1736 | |
1689 | my $h1 = $self->{h} - $ycut * $self->{h}; |
|
|
1690 | my $h2 = $ycut * $self->{h}; |
|
|
1691 | |
|
|
1692 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1737 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1693 | glBegin GL_QUADS; |
1738 | glBegin GL_QUADS; |
1694 | glTexCoord 0 , 0; glVertex 0 , 0; |
1739 | glTexCoord 0 , 0; glVertex 0 , 0; |
1695 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; |
1740 | glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1; |
1696 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; |
1741 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1; |
1697 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1742 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1698 | glEnd; |
1743 | glEnd; |
1699 | |
1744 | |
|
|
1745 | my $ycut1 = List::Util::min 1, $ycut; |
1700 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1746 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1701 | glBegin GL_QUADS; |
1747 | glBegin GL_QUADS; |
1702 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; |
1748 | glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1; |
1703 | glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; |
1749 | glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2; |
1704 | glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; |
1750 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2; |
1705 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; |
1751 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1; |
1706 | glEnd; |
1752 | glEnd; |
|
|
1753 | |
|
|
1754 | if ($t3) { |
|
|
1755 | glBindTexture GL_TEXTURE_2D, $t3->{name}; |
|
|
1756 | glBegin GL_QUADS; |
|
|
1757 | glTexCoord 0 , $t3->{t} * (1 - $ycut2); glVertex 0 , $h2; |
|
|
1758 | glTexCoord 0 , $t3->{t}; glVertex 0 , $self->{h}; |
|
|
1759 | glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $self->{h}; |
|
|
1760 | glTexCoord $t3->{s}, $t3->{t} * (1 - $ycut2); glVertex $w, $h2; |
|
|
1761 | glEnd; |
|
|
1762 | } |
1707 | |
1763 | |
1708 | glDisable GL_BLEND; |
1764 | glDisable GL_BLEND; |
1709 | glDisable GL_TEXTURE_2D; |
1765 | glDisable GL_TEXTURE_2D; |
1710 | } |
1766 | } |
1711 | |
1767 | |
… | |
… | |
1718 | sub new { |
1774 | sub new { |
1719 | my ($class, %arg) = @_; |
1775 | my ($class, %arg) = @_; |
1720 | |
1776 | |
1721 | my $self = $class->SUPER::new ( |
1777 | my $self = $class->SUPER::new ( |
1722 | tooltip => $arg{type}, |
1778 | tooltip => $arg{type}, |
|
|
1779 | can_events => 1, |
|
|
1780 | can_hover => 1, |
1723 | %arg, |
1781 | %arg, |
1724 | ); |
1782 | ); |
1725 | |
1783 | |
1726 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
1784 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
1727 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); |
1785 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
1728 | $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999"); |
1786 | $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999"); |
1729 | |
1787 | |
1730 | $self |
1788 | $self |
1731 | } |
1789 | } |
1732 | |
1790 | |
… | |
… | |
1900 | sub new { |
1958 | sub new { |
1901 | my $class = shift; |
1959 | my $class = shift; |
1902 | |
1960 | |
1903 | my $self = $class->SUPER::new ( |
1961 | my $self = $class->SUPER::new ( |
1904 | fontsize => 1, |
1962 | fontsize => 1, |
|
|
1963 | #font => default_font |
1905 | @_, |
1964 | @_, |
1906 | |
1965 | |
1907 | layout => (new CFClient::Layout), |
1966 | layout => (new CFClient::Layout), |
1908 | par => [], |
1967 | par => [], |
1909 | height => 0, |
1968 | height => 0, |
… | |
… | |
1949 | sub size_allocate { |
2008 | sub size_allocate { |
1950 | my ($self, $w, $h) = @_; |
2009 | my ($self, $w, $h) = @_; |
1951 | |
2010 | |
1952 | $self->SUPER::size_allocate ($w, $h); |
2011 | $self->SUPER::size_allocate ($w, $h); |
1953 | |
2012 | |
|
|
2013 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1954 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
2014 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1955 | $self->{layout}->set_width ($self->{children}[0]{w}); |
2015 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1956 | |
2016 | |
1957 | $self->reflow; |
2017 | $self->reflow; |
1958 | } |
2018 | } |
… | |
… | |
2010 | my $y1 = $top + $self->{h}; |
2070 | my $y1 = $top + $self->{h}; |
2011 | |
2071 | |
2012 | my $y = 0; |
2072 | my $y = 0; |
2013 | |
2073 | |
2014 | my $layout = $self->{layout}; |
2074 | my $layout = $self->{layout}; |
|
|
2075 | |
|
|
2076 | $layout->set_font ($self->{font}) if $self->{font}; |
2015 | |
2077 | |
2016 | for my $par (@{$self->{par}}) { |
2078 | for my $par (@{$self->{par}}) { |
2017 | my $h = $par->[0]; |
2079 | my $h = $par->[0]; |
2018 | |
2080 | |
2019 | if ($y0 < $y + $h && $y < $y1) { |
2081 | if ($y0 < $y + $h && $y < $y1) { |
… | |
… | |
2129 | $self->emit (changed => $self->{state}); |
2191 | $self->emit (changed => $self->{state}); |
2130 | } |
2192 | } |
2131 | |
2193 | |
2132 | ############################################################################# |
2194 | ############################################################################# |
2133 | |
2195 | |
|
|
2196 | package CFClient::UI::Tooltip; |
|
|
2197 | |
|
|
2198 | our @ISA = CFClient::UI::Bin::; |
|
|
2199 | |
|
|
2200 | use CFClient::OpenGL; |
|
|
2201 | |
|
|
2202 | sub new { |
|
|
2203 | my $class = shift; |
|
|
2204 | |
|
|
2205 | $class->SUPER::new ( |
|
|
2206 | @_, |
|
|
2207 | can_events => 0, |
|
|
2208 | ) |
|
|
2209 | } |
|
|
2210 | |
|
|
2211 | sub set_markup { |
|
|
2212 | my ($self, $text) = @_; |
|
|
2213 | |
|
|
2214 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; |
|
|
2215 | $self->{label}->set_markup ($text); |
|
|
2216 | $self->add ($self->{label}); |
|
|
2217 | } |
|
|
2218 | |
|
|
2219 | sub size_request { |
|
|
2220 | my ($self) = @_; |
|
|
2221 | |
|
|
2222 | $self->child->set_max_size ($::WIDTH * 0.3); |
|
|
2223 | |
|
|
2224 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
|
|
2225 | |
|
|
2226 | ($w + 4, $h + 4) |
|
|
2227 | } |
|
|
2228 | |
|
|
2229 | sub size_allocate { |
|
|
2230 | my ($self, $w, $h) = @_; |
|
|
2231 | |
|
|
2232 | $self->SUPER::size_allocate ($w - 4, $h - 4); |
|
|
2233 | } |
|
|
2234 | |
|
|
2235 | sub _draw { |
|
|
2236 | my ($self) = @_; |
|
|
2237 | |
|
|
2238 | glPushMatrix; |
|
|
2239 | glTranslate 0.375, 0.375; |
|
|
2240 | |
|
|
2241 | my ($w, $h) = @$self{qw(w h)}; |
|
|
2242 | |
|
|
2243 | glColor 1, 0.8, 0.4; |
|
|
2244 | glBegin GL_QUADS; |
|
|
2245 | glVertex 0 , 0; |
|
|
2246 | glVertex 0 , $h; |
|
|
2247 | glVertex $w, $h; |
|
|
2248 | glVertex $w, 0; |
|
|
2249 | glEnd; |
|
|
2250 | |
|
|
2251 | glColor 0, 0, 0; |
|
|
2252 | glBegin GL_LINE_LOOP; |
|
|
2253 | glVertex 0 , 0; |
|
|
2254 | glVertex 0 , $h; |
|
|
2255 | glVertex $w, $h; |
|
|
2256 | glVertex $w, 0; |
|
|
2257 | glEnd; |
|
|
2258 | |
|
|
2259 | glPopMatrix; |
|
|
2260 | |
|
|
2261 | glTranslate 2, 2; |
|
|
2262 | $self->SUPER::_draw; |
|
|
2263 | } |
|
|
2264 | |
|
|
2265 | ############################################################################# |
|
|
2266 | |
|
|
2267 | package CFClient::UI::Face; |
|
|
2268 | |
|
|
2269 | our @ISA = CFClient::UI::Base::; |
|
|
2270 | |
|
|
2271 | use CFClient::OpenGL; |
|
|
2272 | |
|
|
2273 | sub new { |
|
|
2274 | my $class = shift; |
|
|
2275 | |
|
|
2276 | $class->SUPER::new ( |
|
|
2277 | aspect => 1, |
|
|
2278 | @_, |
|
|
2279 | ) |
|
|
2280 | } |
|
|
2281 | |
|
|
2282 | sub size_request { |
|
|
2283 | (32, 8) |
|
|
2284 | } |
|
|
2285 | |
|
|
2286 | sub draw { |
|
|
2287 | my ($self) = @_; |
|
|
2288 | |
|
|
2289 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
|
|
2290 | |
|
|
2291 | if ($tex) { |
|
|
2292 | glEnable GL_BLEND; |
|
|
2293 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2294 | glEnable GL_TEXTURE_2D; |
|
|
2295 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2296 | glColor 1, 1, 1, 1; |
|
|
2297 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
|
|
2298 | glDisable GL_TEXTURE_2D; |
|
|
2299 | glDisable GL_BLEND; |
|
|
2300 | } |
|
|
2301 | } |
|
|
2302 | |
|
|
2303 | ############################################################################# |
|
|
2304 | |
2134 | package CFClient::UI::Root; |
2305 | package CFClient::UI::Root; |
2135 | |
2306 | |
2136 | our @ISA = CFClient::UI::Container::; |
2307 | our @ISA = CFClient::UI::Container::; |
2137 | |
2308 | |
2138 | use CFClient::OpenGL; |
2309 | use CFClient::OpenGL; |
… | |
… | |
2213 | ############################################################################# |
2384 | ############################################################################# |
2214 | |
2385 | |
2215 | package CFClient::UI; |
2386 | package CFClient::UI; |
2216 | |
2387 | |
2217 | $ROOT = new CFClient::UI::Root; |
2388 | $ROOT = new CFClient::UI::Root; |
2218 | $TOOLTIP = new CFClient::UI::Label fontsize => 0.8, can_events => 0; |
2389 | $TOOLTIP = new CFClient::UI::Tooltip; |
2219 | |
2390 | |
2220 | 1 |
2391 | 1 |
2221 | |
2392 | |