… | |
… | |
8 | use CFClient; |
8 | use CFClient; |
9 | |
9 | |
10 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
10 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
11 | |
11 | |
12 | our $ROOT; |
12 | our $ROOT; |
|
|
13 | our $TOOLTIP; |
13 | our $BUTTON_STATE; |
14 | our $BUTTON_STATE; |
|
|
15 | |
|
|
16 | sub check_tooltip { |
|
|
17 | if (!$GRAB) { |
|
|
18 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
|
|
19 | if (length $widget->{tooltip}) { |
|
|
20 | |
|
|
21 | if ($TOOLTIP->{owner} != $widget) { |
|
|
22 | $TOOLTIP->{owner} = $widget; |
|
|
23 | |
|
|
24 | my $tip = $widget->{tooltip}; |
|
|
25 | |
|
|
26 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
|
|
27 | |
|
|
28 | $TOOLTIP->set_text ($widget->{tooltip}); |
|
|
29 | $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0)); |
|
|
30 | $TOOLTIP->show; |
|
|
31 | } |
|
|
32 | |
|
|
33 | return; |
|
|
34 | } |
|
|
35 | } |
|
|
36 | } |
|
|
37 | |
|
|
38 | $TOOLTIP->hide; |
|
|
39 | delete $TOOLTIP->{owner}; |
|
|
40 | } |
14 | |
41 | |
15 | # class methods for events |
42 | # class methods for events |
16 | sub feed_sdl_key_down_event { |
43 | sub feed_sdl_key_down_event { |
17 | $FOCUS->key_down ($_[0]) if $FOCUS; |
44 | $FOCUS->key_down ($_[0]) if $FOCUS; |
18 | } |
45 | } |
… | |
… | |
28 | if (!$BUTTON_STATE) { |
55 | if (!$BUTTON_STATE) { |
29 | my $widget = $ROOT->find_widget ($x, $y); |
56 | my $widget = $ROOT->find_widget ($x, $y); |
30 | |
57 | |
31 | $GRAB = $widget; |
58 | $GRAB = $widget; |
32 | $GRAB->update if $GRAB; |
59 | $GRAB->update if $GRAB; |
|
|
60 | |
|
|
61 | check_tooltip; |
33 | } |
62 | } |
34 | |
63 | |
35 | $BUTTON_STATE |= 1 << ($ev->{button} - 1); |
64 | $BUTTON_STATE |= 1 << ($ev->{button} - 1); |
36 | |
65 | |
37 | $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
66 | $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
… | |
… | |
49 | |
78 | |
50 | if (!$BUTTON_STATE) { |
79 | if (!$BUTTON_STATE) { |
51 | my $grab = $GRAB; undef $GRAB; |
80 | my $grab = $GRAB; undef $GRAB; |
52 | $grab->update if $grab; |
81 | $grab->update if $grab; |
53 | $GRAB->update if $GRAB; |
82 | $GRAB->update if $GRAB; |
|
|
83 | |
|
|
84 | check_tooltip; |
54 | } |
85 | } |
55 | } |
86 | } |
56 | |
87 | |
57 | sub feed_sdl_motion_event { |
88 | sub feed_sdl_motion_event { |
58 | my ($ev) = @_; |
89 | my ($ev) = @_; |
… | |
… | |
63 | if ($widget != $HOVER) { |
94 | if ($widget != $HOVER) { |
64 | my $hover = $HOVER; $HOVER = $widget; |
95 | my $hover = $HOVER; $HOVER = $widget; |
65 | |
96 | |
66 | $hover->update if $hover && $hover->{can_hover}; |
97 | $hover->update if $hover && $hover->{can_hover}; |
67 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
98 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
|
|
99 | |
|
|
100 | check_tooltip; |
68 | } |
101 | } |
69 | |
102 | |
70 | $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; |
103 | $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; |
71 | } |
104 | } |
72 | |
105 | |
… | |
… | |
109 | } |
142 | } |
110 | |
143 | |
111 | $self |
144 | $self |
112 | } |
145 | } |
113 | |
146 | |
|
|
147 | sub destroy { |
|
|
148 | my ($self) = @_; |
|
|
149 | |
|
|
150 | $self->hide; |
|
|
151 | %$self = (); |
|
|
152 | } |
|
|
153 | |
114 | sub show { |
154 | sub show { |
115 | my ($self) = @_; |
155 | my ($self) = @_; |
116 | |
156 | |
117 | return if $self->{parent}; |
157 | return if $self->{parent}; |
118 | |
158 | |
… | |
… | |
135 | $self->{z} = $z if defined $z; |
175 | $self->{z} = $z if defined $z; |
136 | |
176 | |
137 | $self->update; |
177 | $self->update; |
138 | } |
178 | } |
139 | |
179 | |
140 | sub needs_redraw { |
180 | sub set_size { |
141 | 0 |
181 | my ($self, $w, $h) = @_; |
|
|
182 | |
|
|
183 | $self->{user_w} = $w; |
|
|
184 | $self->{user_h} = $h; |
|
|
185 | |
|
|
186 | $self->check_size; |
142 | } |
187 | } |
143 | |
188 | |
144 | sub size_request { |
189 | sub size_request { |
145 | require Carp; |
190 | require Carp; |
146 | Carp::confess "size_request is abstract"; |
191 | Carp::confess "size_request is abstract"; |
… | |
… | |
176 | } |
221 | } |
177 | } |
222 | } |
178 | |
223 | |
179 | sub size_allocate { |
224 | sub size_allocate { |
180 | # 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; |
181 | } |
233 | } |
182 | |
234 | |
183 | # return top left coordinates |
235 | # return top left coordinates |
184 | sub _topleft { |
236 | sub _topleft { |
185 | my ($self, $x, $y) = @_; |
237 | my ($self, $x, $y) = @_; |
… | |
… | |
297 | } |
349 | } |
298 | |
350 | |
299 | sub check_size { |
351 | sub check_size { |
300 | my ($self) = @_; |
352 | my ($self) = @_; |
301 | |
353 | |
302 | return unless $self->{parent}; |
354 | $self->{parent} |
|
|
355 | or return 1; |
303 | |
356 | |
304 | my ($w, $h) = $self->size_request; |
357 | my ($w, $h) = $self->{user_w} && $self->{user_h} |
|
|
358 | ? @$self{qw(user_w user_h)} |
|
|
359 | : $self->size_request; |
305 | |
360 | |
306 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
361 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
307 | $self->{req_w} = $w; |
362 | $self->{req_w} = $w; |
308 | $self->{req_h} = $h; |
363 | $self->{req_h} = $h; |
309 | |
364 | |
310 | $self->{parent}->check_size; |
365 | $self->{parent}->check_size |
|
|
366 | or $self->size_allocate ( |
|
|
367 | (List::Util::max $self->{w}, $w), |
|
|
368 | (List::Util::max $self->{h}, $h), |
|
|
369 | ); |
|
|
370 | |
|
|
371 | 1 |
|
|
372 | } else { |
|
|
373 | 0 |
311 | } |
374 | } |
312 | } |
375 | } |
313 | |
376 | |
314 | sub update { |
377 | sub update { |
315 | my ($self) = @_; |
378 | my ($self) = @_; |
… | |
… | |
433 | delete $child->{parent}; |
496 | delete $child->{parent}; |
434 | |
497 | |
435 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
498 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
436 | |
499 | |
437 | $self->check_size; |
500 | $self->check_size; |
|
|
501 | $self->update; |
438 | } |
502 | } |
439 | |
503 | |
440 | sub find_widget { |
504 | sub find_widget { |
441 | my ($self, $x, $y) = @_; |
505 | my ($self, $x, $y) = @_; |
442 | |
506 | |
… | |
… | |
602 | border => 0.8, |
666 | border => 0.8, |
603 | @_ |
667 | @_ |
604 | ); |
668 | ); |
605 | |
669 | |
606 | $self |
670 | $self |
607 | } |
|
|
608 | |
|
|
609 | sub set_size { |
|
|
610 | my ($self, $w, $h) = @_; |
|
|
611 | $self->{req_w} = $w; |
|
|
612 | $self->{req_h} = $h; |
|
|
613 | $self->check_size; |
|
|
614 | } |
|
|
615 | |
|
|
616 | sub size_request { |
|
|
617 | my ($self) = @_; |
|
|
618 | ($self->{req_w}, $self->{req_h}) |
|
|
619 | } |
|
|
620 | |
|
|
621 | sub size_allocate { |
|
|
622 | my ($self, $w, $h) = @_; |
|
|
623 | $self->{w} = $w; |
|
|
624 | $self->{h} = $h; |
|
|
625 | $self->child->configure (0, 0, $w, $h); |
|
|
626 | } |
671 | } |
627 | |
672 | |
628 | sub _draw { |
673 | sub _draw { |
629 | my ($self) = @_; |
674 | my ($self) = @_; |
630 | |
675 | |
… | |
… | |
687 | int $_[0]{border} * $::FONTSIZE |
732 | int $_[0]{border} * $::FONTSIZE |
688 | } |
733 | } |
689 | |
734 | |
690 | sub size_request { |
735 | sub size_request { |
691 | my ($self) = @_; |
736 | my ($self) = @_; |
692 | |
|
|
693 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
|
|
694 | |
737 | |
695 | my ($w, $h) = $self->SUPER::size_request; |
738 | my ($w, $h) = $self->SUPER::size_request; |
696 | |
739 | |
697 | ( |
740 | ( |
698 | $w + $self->border * 2, |
741 | $w + $self->border * 2, |
… | |
… | |
1065 | sub new { |
1108 | sub new { |
1066 | my ($class, %arg) = @_; |
1109 | my ($class, %arg) = @_; |
1067 | |
1110 | |
1068 | my $self = $class->SUPER::new ( |
1111 | my $self = $class->SUPER::new ( |
1069 | fg => [1, 1, 1], |
1112 | fg => [1, 1, 1], |
|
|
1113 | #font => default_font |
1070 | fontsize => 1, |
1114 | fontsize => 1, |
1071 | text => "", |
1115 | text => "", |
1072 | align => -1, |
1116 | align => -1, |
1073 | valign => -1, |
1117 | valign => -1, |
1074 | padding => 2, |
1118 | padding => 2, |
… | |
… | |
1120 | } |
1164 | } |
1121 | |
1165 | |
1122 | sub size_request { |
1166 | sub size_request { |
1123 | my ($self) = @_; |
1167 | my ($self) = @_; |
1124 | |
1168 | |
1125 | $self->{layout}->set_width; |
1169 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
|
|
1170 | $self->{layout}->set_width ($self->{max_w} || -1); |
1126 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1171 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1127 | |
1172 | |
1128 | my ($w, $h) = $self->{layout}->size; |
1173 | my ($w, $h) = $self->{layout}->size; |
1129 | |
1174 | |
1130 | if (exists $self->{template}) { |
1175 | if (exists $self->{template}) { |
|
|
1176 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
1131 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1177 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1132 | |
1178 | |
1133 | my ($w2, $h2) = $self->{template}->size; |
1179 | my ($w2, $h2) = $self->{template}->size; |
1134 | |
1180 | |
1135 | $w = List::Util::max $w, $w2; |
1181 | $w = List::Util::max $w, $w2; |
… | |
… | |
1150 | |
1196 | |
1151 | sub set_fontsize { |
1197 | sub set_fontsize { |
1152 | my ($self, $fontsize) = @_; |
1198 | my ($self, $fontsize) = @_; |
1153 | |
1199 | |
1154 | $self->{fontsize} = $fontsize; |
1200 | $self->{fontsize} = $fontsize; |
|
|
1201 | delete $self->{texture}; |
1155 | $self->check_size; |
1202 | $self->check_size; |
|
|
1203 | $self->update; |
1156 | } |
1204 | } |
1157 | |
1205 | |
1158 | sub _draw { |
1206 | sub _draw { |
1159 | my ($self) = @_; |
1207 | my ($self) = @_; |
1160 | |
1208 | |
1161 | my $tex = $self->{texture} ||= do { |
1209 | my $tex = $self->{texture} ||= do { |
|
|
1210 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1162 | $self->{layout}->set_width ($self->{w}); |
1211 | $self->{layout}->set_width ($self->{w}); |
1163 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1212 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1164 | new_from_layout CFClient::Texture $self->{layout} |
1213 | new_from_layout CFClient::Texture $self->{layout} |
1165 | }; |
1214 | }; |
1166 | |
1215 | |
… | |
… | |
1569 | |
1618 | |
1570 | package CFClient::UI::VGauge; |
1619 | package CFClient::UI::VGauge; |
1571 | |
1620 | |
1572 | our @ISA = CFClient::UI::Base::; |
1621 | our @ISA = CFClient::UI::Base::; |
1573 | |
1622 | |
|
|
1623 | use List::Util qw(min max); |
|
|
1624 | |
1574 | use CFClient::OpenGL; |
1625 | use CFClient::OpenGL; |
1575 | |
1626 | |
1576 | my %tex = ( |
1627 | my %tex = ( |
1577 | food => [ |
1628 | food => [ |
1578 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1629 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1579 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
1630 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
1580 | ], |
1631 | ], |
1581 | grace => [ |
1632 | grace => [ |
1582 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1633 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1583 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
1634 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ |
1584 | ], |
1635 | ], |
1585 | hp => [ |
1636 | hp => [ |
1586 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1637 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1587 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
1638 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
1588 | ], |
1639 | ], |
1589 | mana => [ |
1640 | mana => [ |
1590 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1641 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1591 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
1642 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ |
1592 | ], |
1643 | ], |
1593 | ); |
1644 | ); |
1594 | |
1645 | |
1595 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
1646 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
1596 | sub new { |
1647 | sub new { |
… | |
… | |
1634 | |
1685 | |
1635 | sub _draw { |
1686 | sub _draw { |
1636 | my ($self) = @_; |
1687 | my ($self) = @_; |
1637 | |
1688 | |
1638 | my $tex = $tex{$self->{type}}; |
1689 | my $tex = $tex{$self->{type}}; |
|
|
1690 | my ($t1, $t2, $t3) = @$tex; |
1639 | |
1691 | |
1640 | my ($w, $h) = ($self->{w}, $self->{h}); |
1692 | my ($w, $h) = ($self->{w}, $self->{h}); |
1641 | |
1693 | |
1642 | if ($self->{vertical}) { |
1694 | if ($self->{vertical}) { |
1643 | glRotate 90, 0, 0, 1; |
1695 | glRotate 90, 0, 0, 1; |
… | |
… | |
1645 | |
1697 | |
1646 | ($w, $h) = ($h, $w); |
1698 | ($w, $h) = ($h, $w); |
1647 | } |
1699 | } |
1648 | |
1700 | |
1649 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1701 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1650 | $ycut = 1 if $self->{val} > $self->{max_val}; |
|
|
1651 | |
1702 | |
1652 | my $t1 = $tex->[0]; |
1703 | my $ycut1 = max 0, min 1, $ycut; |
1653 | my $t2 = $tex->[1]; |
1704 | my $ycut2 = max 0, min 1, $ycut - 1; |
|
|
1705 | |
|
|
1706 | my $h1 = $self->{h} * (1 - $ycut1); |
|
|
1707 | my $h2 = $self->{h} * (1 - $ycut2); |
1654 | |
1708 | |
1655 | glEnable GL_BLEND; |
1709 | glEnable GL_BLEND; |
1656 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1710 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1657 | glEnable GL_TEXTURE_2D; |
1711 | glEnable GL_TEXTURE_2D; |
1658 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1712 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1659 | |
1713 | |
1660 | my $h1 = $self->{h} - $ycut * $self->{h}; |
|
|
1661 | my $h2 = $ycut * $self->{h}; |
|
|
1662 | |
|
|
1663 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1714 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1664 | glBegin GL_QUADS; |
1715 | glBegin GL_QUADS; |
1665 | glTexCoord 0 , 0; glVertex 0 , 0; |
1716 | glTexCoord 0 , 0; glVertex 0 , 0; |
1666 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; |
1717 | glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1; |
1667 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; |
1718 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1; |
1668 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1719 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1669 | glEnd; |
1720 | glEnd; |
1670 | |
1721 | |
|
|
1722 | my $ycut1 = List::Util::min 1, $ycut; |
1671 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1723 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1672 | glBegin GL_QUADS; |
1724 | glBegin GL_QUADS; |
1673 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; |
1725 | glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1; |
1674 | glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; |
1726 | glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2; |
1675 | glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; |
1727 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2; |
1676 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; |
1728 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1; |
1677 | glEnd; |
1729 | glEnd; |
|
|
1730 | |
|
|
1731 | if ($t3) { |
|
|
1732 | glBindTexture GL_TEXTURE_2D, $t3->{name}; |
|
|
1733 | glBegin GL_QUADS; |
|
|
1734 | glTexCoord 0 , $t3->{t} * (1 - $ycut2); glVertex 0 , $h2; |
|
|
1735 | glTexCoord 0 , $t3->{t}; glVertex 0 , $self->{h}; |
|
|
1736 | glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $self->{h}; |
|
|
1737 | glTexCoord $t3->{s}, $t3->{t} * (1 - $ycut2); glVertex $w, $h2; |
|
|
1738 | glEnd; |
|
|
1739 | } |
1678 | |
1740 | |
1679 | glDisable GL_BLEND; |
1741 | glDisable GL_BLEND; |
1680 | glDisable GL_TEXTURE_2D; |
1742 | glDisable GL_TEXTURE_2D; |
1681 | } |
1743 | } |
1682 | |
1744 | |
… | |
… | |
1685 | package CFClient::UI::Gauge; |
1747 | package CFClient::UI::Gauge; |
1686 | |
1748 | |
1687 | our @ISA = CFClient::UI::VBox::; |
1749 | our @ISA = CFClient::UI::VBox::; |
1688 | |
1750 | |
1689 | sub new { |
1751 | sub new { |
1690 | my ($class, %arg) = shift; |
1752 | my ($class, %arg) = @_; |
1691 | |
1753 | |
1692 | my $self = $class->SUPER::new ( |
1754 | my $self = $class->SUPER::new ( |
1693 | @_, |
1755 | tooltip => $arg{type}, |
|
|
1756 | %arg, |
1694 | ); |
1757 | ); |
1695 | |
1758 | |
1696 | $self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"; |
1759 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999", can_events => 1, can_hover => 1); |
1697 | $self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"; |
|
|
1698 | $self->add ($self->{value}); |
|
|
1699 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); |
1760 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_events => 1, can_hover => 1); |
1700 | $self->add ($self->{max}); |
1761 | $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999", can_events => 1, can_hover => 1); |
1701 | |
1762 | |
1702 | $self |
1763 | $self |
1703 | } |
|
|
1704 | |
|
|
1705 | sub size_request { |
|
|
1706 | my ($self) = @_; |
|
|
1707 | (($self->{max}->size_request)[0], 0) |
|
|
1708 | } |
1764 | } |
1709 | |
1765 | |
1710 | sub set_fontsize { |
1766 | sub set_fontsize { |
1711 | my ($self, $fsize) = @_; |
1767 | my ($self, $fsize) = @_; |
1712 | |
1768 | |
… | |
… | |
1877 | sub new { |
1933 | sub new { |
1878 | my $class = shift; |
1934 | my $class = shift; |
1879 | |
1935 | |
1880 | my $self = $class->SUPER::new ( |
1936 | my $self = $class->SUPER::new ( |
1881 | fontsize => 1, |
1937 | fontsize => 1, |
|
|
1938 | #font => default_font |
1882 | @_, |
1939 | @_, |
1883 | |
1940 | |
1884 | layout => (new CFClient::Layout), |
1941 | layout => (new CFClient::Layout), |
1885 | par => [], |
1942 | par => [], |
1886 | height => 0, |
1943 | height => 0, |
… | |
… | |
1926 | sub size_allocate { |
1983 | sub size_allocate { |
1927 | my ($self, $w, $h) = @_; |
1984 | my ($self, $w, $h) = @_; |
1928 | |
1985 | |
1929 | $self->SUPER::size_allocate ($w, $h); |
1986 | $self->SUPER::size_allocate ($w, $h); |
1930 | |
1987 | |
|
|
1988 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1931 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1989 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1932 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1990 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1933 | |
1991 | |
1934 | $self->reflow; |
1992 | $self->reflow; |
1935 | } |
1993 | } |
… | |
… | |
1987 | my $y1 = $top + $self->{h}; |
2045 | my $y1 = $top + $self->{h}; |
1988 | |
2046 | |
1989 | my $y = 0; |
2047 | my $y = 0; |
1990 | |
2048 | |
1991 | my $layout = $self->{layout}; |
2049 | my $layout = $self->{layout}; |
|
|
2050 | |
|
|
2051 | $layout->set_font ($self->{font}) if $self->{font}; |
1992 | |
2052 | |
1993 | for my $par (@{$self->{par}}) { |
2053 | for my $par (@{$self->{par}}) { |
1994 | my $h = $par->[0]; |
2054 | my $h = $par->[0]; |
1995 | |
2055 | |
1996 | if ($y0 < $y + $h && $y < $y1) { |
2056 | if ($y0 < $y + $h && $y < $y1) { |
… | |
… | |
2106 | $self->emit (changed => $self->{state}); |
2166 | $self->emit (changed => $self->{state}); |
2107 | } |
2167 | } |
2108 | |
2168 | |
2109 | ############################################################################# |
2169 | ############################################################################# |
2110 | |
2170 | |
|
|
2171 | package CFClient::UI::Tooltip; |
|
|
2172 | |
|
|
2173 | our @ISA = CFClient::UI::Bin::; |
|
|
2174 | |
|
|
2175 | use CFClient::OpenGL; |
|
|
2176 | |
|
|
2177 | sub new { |
|
|
2178 | my $class = shift; |
|
|
2179 | |
|
|
2180 | $class->SUPER::new ( |
|
|
2181 | @_, |
|
|
2182 | can_events => 0, |
|
|
2183 | ) |
|
|
2184 | } |
|
|
2185 | |
|
|
2186 | sub set_text { |
|
|
2187 | my ($self, $text) = @_; |
|
|
2188 | |
|
|
2189 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; |
|
|
2190 | $self->{label}->set_text ($text); |
|
|
2191 | $self->add ($self->{label}); |
|
|
2192 | } |
|
|
2193 | |
|
|
2194 | sub size_request { |
|
|
2195 | my ($self) = @_; |
|
|
2196 | |
|
|
2197 | $self->child->set_max_size ($::WIDTH * 0.3); |
|
|
2198 | |
|
|
2199 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
|
|
2200 | |
|
|
2201 | ($w + 4, $h + 4) |
|
|
2202 | } |
|
|
2203 | |
|
|
2204 | sub _draw { |
|
|
2205 | my ($self) = @_; |
|
|
2206 | |
|
|
2207 | glPushMatrix; |
|
|
2208 | glTranslate 0.375, 0.375; |
|
|
2209 | |
|
|
2210 | my ($w, $h) = @$self{qw(w h)}; |
|
|
2211 | |
|
|
2212 | glColor 1, 0.8, 0.4; |
|
|
2213 | glBegin GL_QUADS; |
|
|
2214 | glVertex 0 , 0; |
|
|
2215 | glVertex 0 , $h; |
|
|
2216 | glVertex $w, $h; |
|
|
2217 | glVertex $w, 0; |
|
|
2218 | glEnd; |
|
|
2219 | |
|
|
2220 | glColor 0, 0, 0; |
|
|
2221 | glBegin GL_LINE_LOOP; |
|
|
2222 | glVertex 0 , 0; |
|
|
2223 | glVertex 0 , $h; |
|
|
2224 | glVertex $w, $h; |
|
|
2225 | glVertex $w, 0; |
|
|
2226 | glEnd; |
|
|
2227 | |
|
|
2228 | glPopMatrix; |
|
|
2229 | |
|
|
2230 | glTranslate 2, 2; |
|
|
2231 | $self->SUPER::_draw; |
|
|
2232 | } |
|
|
2233 | |
|
|
2234 | ############################################################################# |
|
|
2235 | |
2111 | package CFClient::UI::Root; |
2236 | package CFClient::UI::Root; |
2112 | |
2237 | |
2113 | our @ISA = CFClient::UI::Container::; |
2238 | our @ISA = CFClient::UI::Container::; |
2114 | |
2239 | |
2115 | use CFClient::OpenGL; |
2240 | use CFClient::OpenGL; |
… | |
… | |
2190 | ############################################################################# |
2315 | ############################################################################# |
2191 | |
2316 | |
2192 | package CFClient::UI; |
2317 | package CFClient::UI; |
2193 | |
2318 | |
2194 | $ROOT = new CFClient::UI::Root; |
2319 | $ROOT = new CFClient::UI::Root; |
|
|
2320 | $TOOLTIP = new CFClient::UI::Tooltip; |
2195 | |
2321 | |
2196 | 1 |
2322 | 1 |
2197 | |
2323 | |