… | |
… | |
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 | |
23 | |
24 | my $tip = $widget->{tooltip}; |
24 | my $tip = $widget->{tooltip}; |
25 | |
25 | |
26 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
26 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
27 | |
27 | |
28 | $TOOLTIP->set_text ($widget->{tooltip}); |
28 | $TOOLTIP->set_markup ($widget->{tooltip}); |
29 | $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0)); |
29 | $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0)); |
30 | $TOOLTIP->show; |
30 | $TOOLTIP->show; |
31 | } |
31 | } |
32 | |
32 | |
33 | return; |
33 | return; |
… | |
… | |
140 | $self->connect ($1 => delete $self->{$_}); |
140 | $self->connect ($1 => delete $self->{$_}); |
141 | } |
141 | } |
142 | } |
142 | } |
143 | |
143 | |
144 | $self |
144 | $self |
|
|
145 | } |
|
|
146 | |
|
|
147 | sub destroy { |
|
|
148 | my ($self) = @_; |
|
|
149 | |
|
|
150 | $self->hide; |
|
|
151 | %$self = (); |
145 | } |
152 | } |
146 | |
153 | |
147 | sub show { |
154 | sub show { |
148 | my ($self) = @_; |
155 | my ($self) = @_; |
149 | |
156 | |
… | |
… | |
313 | glVertex $x + $self->{w}, $y + $self->{h}; |
320 | glVertex $x + $self->{w}, $y + $self->{h}; |
314 | glVertex $x , $y + $self->{h}; |
321 | glVertex $x , $y + $self->{h}; |
315 | glEnd; |
322 | glEnd; |
316 | glDisable GL_BLEND; |
323 | glDisable GL_BLEND; |
317 | } |
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 | } |
318 | } |
339 | } |
319 | |
340 | |
320 | sub _draw { |
341 | sub _draw { |
321 | my ($self) = @_; |
342 | my ($self) = @_; |
322 | |
343 | |
… | |
… | |
490 | |
511 | |
491 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
512 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
492 | |
513 | |
493 | $self->check_size; |
514 | $self->check_size; |
494 | $self->update; |
515 | $self->update; |
|
|
516 | } |
|
|
517 | |
|
|
518 | sub clear { |
|
|
519 | my ($self) = @_; |
|
|
520 | |
|
|
521 | delete $_->{parent} |
|
|
522 | for @{ delete $self->{children} }; |
|
|
523 | |
|
|
524 | $self->{children} = []; |
495 | } |
525 | } |
496 | |
526 | |
497 | sub find_widget { |
527 | sub find_widget { |
498 | my ($self, $x, $y) = @_; |
528 | my ($self, $x, $y) = @_; |
499 | |
529 | |
… | |
… | |
1124 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1154 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1125 | |
1155 | |
1126 | $self |
1156 | $self |
1127 | } |
1157 | } |
1128 | |
1158 | |
1129 | sub escape_text { |
1159 | sub escape { |
1130 | local $_ = $_[1]; |
1160 | local $_ = $_[1]; |
1131 | |
1161 | |
1132 | s/&/&/g; |
1162 | s/&/&/g; |
1133 | s/>/>/g; |
1163 | s/>/>/g; |
1134 | s/</</g; |
1164 | s/</</g; |
… | |
… | |
1744 | sub new { |
1774 | sub new { |
1745 | my ($class, %arg) = @_; |
1775 | my ($class, %arg) = @_; |
1746 | |
1776 | |
1747 | my $self = $class->SUPER::new ( |
1777 | my $self = $class->SUPER::new ( |
1748 | tooltip => $arg{type}, |
1778 | tooltip => $arg{type}, |
|
|
1779 | can_events => 1, |
|
|
1780 | can_hover => 1, |
1749 | %arg, |
1781 | %arg, |
1750 | ); |
1782 | ); |
1751 | |
1783 | |
1752 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999", can_events => 1, can_hover => 1); |
1784 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); |
1753 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_events => 1, can_hover => 1); |
1785 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); |
1754 | $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999", can_events => 1, can_hover => 1); |
1786 | $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999"); |
1755 | |
1787 | |
1756 | $self |
1788 | $self |
1757 | } |
1789 | } |
1758 | |
1790 | |
1759 | sub set_fontsize { |
1791 | sub set_fontsize { |
… | |
… | |
2174 | @_, |
2206 | @_, |
2175 | can_events => 0, |
2207 | can_events => 0, |
2176 | ) |
2208 | ) |
2177 | } |
2209 | } |
2178 | |
2210 | |
2179 | sub set_text { |
2211 | sub set_markup { |
2180 | my ($self, $text) = @_; |
2212 | my ($self, $text) = @_; |
2181 | |
2213 | |
2182 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; |
2214 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; |
2183 | $self->{label}->set_text ($text); |
2215 | $self->{label}->set_markup ($text); |
2184 | $self->add ($self->{label}); |
2216 | $self->add ($self->{label}); |
2185 | } |
2217 | } |
2186 | |
2218 | |
2187 | sub size_request { |
2219 | sub size_request { |
2188 | my ($self) = @_; |
2220 | my ($self) = @_; |
2189 | |
2221 | |
2190 | $self->child->set_max_size ($::WIDTH * 0.2); |
2222 | $self->child->set_max_size ($::WIDTH * 0.3); |
2191 | |
2223 | |
2192 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
2224 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
2193 | |
2225 | |
2194 | ($w + 4, $h + 4) |
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); |
2195 | } |
2233 | } |
2196 | |
2234 | |
2197 | sub _draw { |
2235 | sub _draw { |
2198 | my ($self) = @_; |
2236 | my ($self) = @_; |
2199 | |
2237 | |
… | |
… | |
2224 | $self->SUPER::_draw; |
2262 | $self->SUPER::_draw; |
2225 | } |
2263 | } |
2226 | |
2264 | |
2227 | ############################################################################# |
2265 | ############################################################################# |
2228 | |
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 | |
2229 | package CFClient::UI::Root; |
2305 | package CFClient::UI::Root; |
2230 | |
2306 | |
2231 | our @ISA = CFClient::UI::Container::; |
2307 | our @ISA = CFClient::UI::Container::; |
2232 | |
2308 | |
2233 | use CFClient::OpenGL; |
2309 | use CFClient::OpenGL; |