1 | package CFClient::UI; |
1 | package CFClient::UI; |
2 | |
2 | |
|
|
3 | use utf8; |
3 | use strict; |
4 | use strict; |
4 | |
5 | |
5 | use Scalar::Util (); |
6 | use Scalar::Util (); |
6 | use List::Util (); |
7 | use List::Util (); |
7 | |
8 | |
… | |
… | |
23 | |
24 | |
24 | my $tip = $widget->{tooltip}; |
25 | my $tip = $widget->{tooltip}; |
25 | |
26 | |
26 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
27 | $tip = $tip->($widget) if CODE:: eq ref $tip; |
27 | |
28 | |
28 | $TOOLTIP->set_markup ($widget->{tooltip}); |
29 | $TOOLTIP->set_markup ($widget->{tooltip}, $widget->{tooltip_font}); |
29 | |
30 | |
30 | $TOOLTIP->show; |
31 | $TOOLTIP->show; |
31 | |
32 | |
32 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
33 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
33 | |
34 | |
… | |
… | |
666 | my ($w, $h) = ($self->w, $self->h); |
667 | my ($w, $h) = ($self->w, $self->h); |
667 | |
668 | |
668 | my $tex = $self->{texture} |
669 | my $tex = $self->{texture} |
669 | or return; |
670 | or return; |
670 | |
671 | |
671 | glEnable GL_BLEND; |
|
|
672 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
673 | glEnable GL_TEXTURE_2D; |
672 | glEnable GL_TEXTURE_2D; |
674 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
673 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
675 | glColor 0, 0, 0, 1; |
674 | glColor 0, 0, 0, 1; |
676 | |
675 | |
677 | $tex->draw_quad (0, 0, $w, $h); |
676 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
678 | |
677 | |
679 | glDisable GL_BLEND; |
|
|
680 | glDisable GL_TEXTURE_2D; |
678 | glDisable GL_TEXTURE_2D; |
681 | } |
679 | } |
682 | |
680 | |
683 | ############################################################################# |
681 | ############################################################################# |
684 | |
682 | |
… | |
… | |
1263 | my ($class, %arg) = @_; |
1261 | my ($class, %arg) = @_; |
1264 | |
1262 | |
1265 | my $self = $class->SUPER::new ( |
1263 | my $self = $class->SUPER::new ( |
1266 | fg => [1, 1, 1], |
1264 | fg => [1, 1, 1], |
1267 | #font => default_font |
1265 | #font => default_font |
|
|
1266 | #text => initial text |
|
|
1267 | #markup => initial narkup |
|
|
1268 | layout => (new CFClient::Layout), |
1268 | fontsize => 1, |
1269 | fontsize => 1, |
1269 | text => "", |
|
|
1270 | align => -1, |
1270 | align => -1, |
1271 | valign => -1, |
1271 | valign => -1, |
1272 | padding => 2, |
1272 | padding => 2, |
1273 | layout => new CFClient::Layout, |
|
|
1274 | can_events => 0, |
1273 | can_events => 0, |
1275 | %arg |
1274 | %arg |
1276 | ); |
1275 | ); |
1277 | |
1276 | |
1278 | if (exists $self->{template}) { |
1277 | if (exists $self->{template}) { |
1279 | my $layout = new CFClient::Layout; |
1278 | my $layout = new CFClient::Layout; |
1280 | $layout->set_text (delete $self->{template}); |
1279 | $layout->set_text (delete $self->{template}); |
1281 | $self->{template} = $layout; |
1280 | $self->{template} = $layout; |
1282 | } |
1281 | } |
1283 | |
1282 | |
1284 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1283 | if (exists $self->{markup}) { |
1285 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1284 | $self->set_markup (delete $self->{markup}); |
|
|
1285 | } else { |
|
|
1286 | $self->set_text (delete $self->{text}); |
|
|
1287 | } |
1286 | |
1288 | |
1287 | $self |
1289 | $self |
1288 | } |
1290 | } |
1289 | |
1291 | |
1290 | sub escape { |
1292 | sub escape { |
… | |
… | |
1308 | my ($self, $text) = @_; |
1310 | my ($self, $text) = @_; |
1309 | |
1311 | |
1310 | return if $self->{text} eq "T$text"; |
1312 | return if $self->{text} eq "T$text"; |
1311 | $self->{text} = "T$text"; |
1313 | $self->{text} = "T$text"; |
1312 | |
1314 | |
|
|
1315 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1313 | $self->{layout}->set_text ($text); |
1316 | $self->{layout}->set_text ($text); |
1314 | |
1317 | |
1315 | $self->update; |
1318 | $self->update; |
1316 | $self->check_size; |
1319 | $self->check_size; |
1317 | } |
1320 | } |
… | |
… | |
1320 | my ($self, $markup) = @_; |
1323 | my ($self, $markup) = @_; |
1321 | |
1324 | |
1322 | return if $self->{text} eq "M$markup"; |
1325 | return if $self->{text} eq "M$markup"; |
1323 | $self->{text} = "M$markup"; |
1326 | $self->{text} = "M$markup"; |
1324 | |
1327 | |
|
|
1328 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
|
|
1329 | |
|
|
1330 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
1325 | $self->{layout}->set_markup ($markup); |
1331 | $self->{layout}->set_markup ($markup); |
1326 | |
1332 | |
1327 | $self->update; |
1333 | $self->update; |
1328 | $self->check_size; |
1334 | $self->check_size; |
1329 | } |
1335 | } |
… | |
… | |
1371 | |
1377 | |
1372 | sub _draw { |
1378 | sub _draw { |
1373 | my ($self) = @_; |
1379 | my ($self) = @_; |
1374 | |
1380 | |
1375 | my $tex = $self->{texture} ||= do { |
1381 | my $tex = $self->{texture} ||= do { |
|
|
1382 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1376 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1383 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1377 | $self->{layout}->set_width ($self->{w}); |
1384 | $self->{layout}->set_width ($self->{w}); |
1378 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1385 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
|
|
1386 | |
1379 | new_from_layout CFClient::Texture $self->{layout} |
1387 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
|
|
1388 | |
|
|
1389 | $self->{ox} = int $self->{align} < 0 ? $self->{padding} |
|
|
1390 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
|
|
1391 | : ($self->{w} - $tex->{w}) * 0.5; |
|
|
1392 | |
|
|
1393 | $self->{oy} = int $self->{valign} < 0 ? $self->{padding} |
|
|
1394 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
|
|
1395 | : ($self->{h} - $tex->{h}) * 0.5; |
|
|
1396 | |
|
|
1397 | $tex |
1380 | }; |
1398 | }; |
1381 | |
1399 | |
1382 | glEnable GL_BLEND; |
|
|
1383 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1384 | glEnable GL_TEXTURE_2D; |
1400 | glEnable GL_TEXTURE_2D; |
1385 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1401 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1386 | |
1402 | |
|
|
1403 | if ($tex->{format} == GL_ALPHA) { |
1387 | glColor @{$self->{fg}}; |
1404 | glColor @{$self->{fg}}; |
1388 | |
|
|
1389 | $self->{ox} = int ( |
|
|
1390 | $self->{align} < 0 ? $self->{padding} |
|
|
1391 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
|
|
1392 | : ($self->{w} - $tex->{w}) * 0.5 |
|
|
1393 | ); |
|
|
1394 | |
|
|
1395 | $self->{oy} = int ( |
|
|
1396 | $self->{valign} < 0 ? $self->{padding} |
|
|
1397 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
|
|
1398 | : ($self->{h} - $tex->{h}) * 0.5 |
|
|
1399 | ); |
|
|
1400 | |
|
|
1401 | $tex->draw_quad ($self->{ox}, $self->{oy}); |
1405 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); |
|
|
1406 | } else { |
|
|
1407 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
|
|
1408 | } |
1402 | |
1409 | |
1403 | glDisable GL_TEXTURE_2D; |
1410 | glDisable GL_TEXTURE_2D; |
1404 | glDisable GL_BLEND; |
|
|
1405 | } |
1411 | } |
1406 | |
1412 | |
1407 | ############################################################################# |
1413 | ############################################################################# |
1408 | |
1414 | |
1409 | package CFClient::UI::EntryBase; |
1415 | package CFClient::UI::EntryBase; |
… | |
… | |
1444 | $self->{layout}->set_text ("$text "); |
1450 | $self->{layout}->set_text ("$text "); |
1445 | |
1451 | |
1446 | $self->emit (changed => $self->{text}); |
1452 | $self->emit (changed => $self->{text}); |
1447 | } |
1453 | } |
1448 | |
1454 | |
|
|
1455 | sub set_text { |
|
|
1456 | my ($self, $text) = @_; |
|
|
1457 | |
|
|
1458 | $self->{cursor} = length $text; |
|
|
1459 | $self->_set_text ($text); |
|
|
1460 | $self->check_size; |
|
|
1461 | $self->update; |
|
|
1462 | } |
|
|
1463 | |
1449 | sub get_text { |
1464 | sub get_text { |
1450 | $_[0]{text} |
1465 | $_[0]{text} |
1451 | } |
1466 | } |
1452 | |
1467 | |
1453 | sub size_request { |
1468 | sub size_request { |
… | |
… | |
1460 | |
1475 | |
1461 | sub size_allocate { |
1476 | sub size_allocate { |
1462 | my ($self, $w, $h) = @_; |
1477 | my ($self, $w, $h) = @_; |
1463 | |
1478 | |
1464 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
1479 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
1465 | } |
|
|
1466 | |
|
|
1467 | sub set_text { |
|
|
1468 | my ($self, $text) = @_; |
|
|
1469 | |
|
|
1470 | $self->{cursor} = length $text; |
|
|
1471 | $self->_set_text ($text); |
|
|
1472 | $self->update; |
|
|
1473 | } |
1480 | } |
1474 | |
1481 | |
1475 | sub key_down { |
1482 | sub key_down { |
1476 | my ($self, $ev) = @_; |
1483 | my ($self, $ev) = @_; |
1477 | |
1484 | |
… | |
… | |
1665 | |
1672 | |
1666 | if ($GRAB == $self) { |
1673 | if ($GRAB == $self) { |
1667 | $self->{fg} = $self->{active_fg}; |
1674 | $self->{fg} = $self->{active_fg}; |
1668 | } |
1675 | } |
1669 | |
1676 | |
1670 | glEnable GL_BLEND; |
|
|
1671 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1672 | glEnable GL_TEXTURE_2D; |
1677 | glEnable GL_TEXTURE_2D; |
1673 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1678 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1674 | glColor 0, 0, 0, 1; |
1679 | glColor 0, 0, 0, 1; |
1675 | |
1680 | |
1676 | $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h}); |
1681 | $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
1677 | |
1682 | |
1678 | glDisable GL_TEXTURE_2D; |
1683 | glDisable GL_TEXTURE_2D; |
1679 | glDisable GL_BLEND; |
|
|
1680 | |
1684 | |
1681 | $self->SUPER::_draw; |
1685 | $self->SUPER::_draw; |
1682 | } |
1686 | } |
1683 | |
1687 | |
1684 | ############################################################################# |
1688 | ############################################################################# |
… | |
… | |
1731 | |
1735 | |
1732 | my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; |
1736 | my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; |
1733 | |
1737 | |
1734 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1738 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1735 | |
1739 | |
1736 | glEnable GL_BLEND; |
|
|
1737 | glEnable GL_TEXTURE_2D; |
1740 | glEnable GL_TEXTURE_2D; |
1738 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1739 | |
1741 | |
1740 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
1742 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
1741 | |
1743 | |
1742 | $tex->draw_quad (0, 0, $s, $s); |
1744 | $tex->draw_quad_alpha (0, 0, $s, $s); |
1743 | |
1745 | |
1744 | glDisable GL_TEXTURE_2D; |
1746 | glDisable GL_TEXTURE_2D; |
1745 | glDisable GL_BLEND; |
|
|
1746 | } |
1747 | } |
1747 | |
1748 | |
1748 | ############################################################################# |
1749 | ############################################################################# |
1749 | |
1750 | |
1750 | package CFClient::UI::Image; |
1751 | package CFClient::UI::Image; |
… | |
… | |
1793 | glTranslate 0, -$self->{w}, 0; |
1794 | glTranslate 0, -$self->{w}, 0; |
1794 | |
1795 | |
1795 | ($w, $h) = ($h, $w); |
1796 | ($w, $h) = ($h, $w); |
1796 | } |
1797 | } |
1797 | |
1798 | |
1798 | glEnable GL_BLEND; |
|
|
1799 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1800 | glEnable GL_TEXTURE_2D; |
1799 | glEnable GL_TEXTURE_2D; |
1801 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1800 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1802 | |
1801 | |
1803 | $tex->draw_quad (0, 0, $w, $h); |
1802 | $tex->draw_quad_alpha (0, 0, $w, $h); |
1804 | |
1803 | |
1805 | glDisable GL_BLEND; |
|
|
1806 | glDisable GL_TEXTURE_2D; |
1804 | glDisable GL_TEXTURE_2D; |
1807 | } |
1805 | } |
1808 | |
1806 | |
1809 | ############################################################################# |
1807 | ############################################################################# |
1810 | |
1808 | |
… | |
… | |
2102 | $page ||= 2; |
2100 | $page ||= 2; |
2103 | |
2101 | |
2104 | my $knob_a = $inner_pad_px + ($value - $page * 0.5); |
2102 | my $knob_a = $inner_pad_px + ($value - $page * 0.5); |
2105 | my $knob_b = $inner_pad_px + ($value + $page * 0.5); |
2103 | my $knob_b = $inner_pad_px + ($value + $page * 0.5); |
2106 | |
2104 | |
2107 | glEnable GL_BLEND; |
|
|
2108 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2109 | glEnable GL_TEXTURE_2D; |
2105 | glEnable GL_TEXTURE_2D; |
2110 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2106 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2111 | |
2107 | |
2112 | # draw background |
2108 | # draw background |
2113 | $tex[1]->draw_quad (0, 0, $w, $h); |
2109 | $tex[1]->draw_quad_alpha (0, 0, $w, $h); |
2114 | |
2110 | |
2115 | # draw handle |
2111 | # draw handle |
2116 | $tex[0]->draw_quad ($knob_a, 0, $knob_b - $knob_a, $h); |
2112 | $tex[0]->draw_quad_alpha ($knob_a, 0, $knob_b - $knob_a, $h); |
2117 | |
2113 | |
2118 | glDisable GL_BLEND; |
|
|
2119 | glDisable GL_TEXTURE_2D; |
2114 | glDisable GL_TEXTURE_2D; |
2120 | } |
2115 | } |
2121 | |
2116 | |
2122 | ############################################################################# |
2117 | ############################################################################# |
2123 | |
2118 | |
… | |
… | |
2134 | fontsize => 1, |
2129 | fontsize => 1, |
2135 | can_events => 0, |
2130 | can_events => 0, |
2136 | #font => default_font |
2131 | #font => default_font |
2137 | @_, |
2132 | @_, |
2138 | |
2133 | |
2139 | layout => (new CFClient::Layout), |
2134 | layout => (new CFClient::Layout 1), |
2140 | par => [], |
2135 | par => [], |
2141 | height => 0, |
2136 | height => 0, |
2142 | children => [ |
2137 | children => [ |
2143 | (new CFClient::UI::Empty expand => 1), |
2138 | (new CFClient::UI::Empty expand => 1), |
2144 | (new CFClient::UI::Slider vertical => 1), |
2139 | (new CFClient::UI::Slider vertical => 1), |
… | |
… | |
2162 | |
2157 | |
2163 | my $layout = $self->{layout}; |
2158 | my $layout = $self->{layout}; |
2164 | |
2159 | |
2165 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2160 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2166 | $layout->set_width ($self->{children}[0]{w}); |
2161 | $layout->set_width ($self->{children}[0]{w}); |
2167 | $layout->set_text ($text); |
2162 | $layout->set_markup ($text); |
2168 | |
2163 | |
2169 | ($layout->size)[1] |
2164 | ($layout->size)[1] |
2170 | } |
2165 | } |
2171 | |
2166 | |
2172 | sub reflow { |
2167 | sub reflow { |
… | |
… | |
2228 | |
2223 | |
2229 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2224 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2230 | glClearColor 0, 0, 0, 0; |
2225 | glClearColor 0, 0, 0, 0; |
2231 | glClear GL_COLOR_BUFFER_BIT; |
2226 | glClear GL_COLOR_BUFFER_BIT; |
2232 | |
2227 | |
2233 | glEnable GL_BLEND; |
|
|
2234 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2235 | glEnable GL_TEXTURE_2D; |
2228 | glEnable GL_TEXTURE_2D; |
2236 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2229 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2237 | |
2230 | |
2238 | my $top = int $self->{children}[1]{range}[0]; |
2231 | my $top = int $self->{children}[1]{range}[0]; |
2239 | |
2232 | |
… | |
… | |
2248 | |
2241 | |
2249 | for my $par (@{$self->{par}}) { |
2242 | for my $par (@{$self->{par}}) { |
2250 | my $h = $par->[0]; |
2243 | my $h = $par->[0]; |
2251 | |
2244 | |
2252 | if ($y0 < $y + $h && $y < $y1) { |
2245 | if ($y0 < $y + $h && $y < $y1) { |
|
|
2246 | $layout->set_foreground (@{ $par->[1] }); |
2253 | $layout->set_text ($par->[2]); |
2247 | $layout->set_markup ($par->[2]); |
2254 | |
2248 | |
2255 | glColor @{ $par->[1] }; |
|
|
2256 | my ($W, $H) = $layout->size; |
2249 | my ($W, $H) = $layout->size; |
2257 | CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0); |
2250 | CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); |
2258 | } |
2251 | } |
2259 | |
2252 | |
2260 | $y += $h; |
2253 | $y += $h; |
2261 | } |
2254 | } |
2262 | |
2255 | |
2263 | glDisable GL_TEXTURE_2D; |
2256 | glDisable GL_TEXTURE_2D; |
2264 | glDisable GL_BLEND; |
|
|
2265 | }; |
2257 | }; |
2266 | }); |
2258 | }); |
2267 | } |
2259 | } |
2268 | |
2260 | |
2269 | sub _draw { |
2261 | sub _draw { |
2270 | my ($self) = @_; |
2262 | my ($self) = @_; |
2271 | |
2263 | |
2272 | glEnable GL_BLEND; |
|
|
2273 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2274 | glEnable GL_TEXTURE_2D; |
2264 | glEnable GL_TEXTURE_2D; |
2275 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2265 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2276 | glColor 1, 1, 1, 1; |
2266 | glColor 1, 1, 1, 1; |
2277 | $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2267 | $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2278 | glDisable GL_TEXTURE_2D; |
2268 | glDisable GL_TEXTURE_2D; |
2279 | glDisable GL_BLEND; |
|
|
2280 | |
2269 | |
2281 | $self->{children}[1]->draw; |
2270 | $self->{children}[1]->draw; |
2282 | |
2271 | |
2283 | } |
2272 | } |
2284 | |
2273 | |
… | |
… | |
2379 | can_events => 0, |
2368 | can_events => 0, |
2380 | ) |
2369 | ) |
2381 | } |
2370 | } |
2382 | |
2371 | |
2383 | sub set_markup { |
2372 | sub set_markup { |
2384 | my ($self, $text) = @_; |
2373 | my ($self, $text, $font) = @_; |
2385 | |
2374 | |
2386 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; |
2375 | $self->{label} = new CFClient::UI::Label |
|
|
2376 | fontsize => 0.8, |
|
|
2377 | fg => [0, 0, 0], |
|
|
2378 | font => ($font || $::FONT_PROP); |
|
|
2379 | |
|
|
2380 | $self->{label}->set_max_size ($::WIDTH * 0.3); |
2387 | $self->{label}->set_markup ($text); |
2381 | $self->{label}->set_markup ($text); |
2388 | $self->add ($self->{label}); |
2382 | $self->add ($self->{label}); |
2389 | } |
2383 | } |
2390 | |
2384 | |
2391 | sub size_request { |
2385 | sub size_request { |
2392 | my ($self) = @_; |
2386 | my ($self) = @_; |
2393 | |
|
|
2394 | $self->child->set_max_size ($::WIDTH * 0.3); |
|
|
2395 | |
2387 | |
2396 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
2388 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
2397 | |
2389 | |
2398 | ($w + 4, $h + 4) |
2390 | ($w + 4, $h + 4) |
2399 | } |
2391 | } |
… | |
… | |
2461 | return unless $::CONN;#d# manage and cache textures differently |
2453 | return unless $::CONN;#d# manage and cache textures differently |
2462 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2454 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2463 | |
2455 | |
2464 | # TODO animation |
2456 | # TODO animation |
2465 | if ($tex) { |
2457 | if ($tex) { |
2466 | glEnable GL_BLEND; |
|
|
2467 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2468 | glEnable GL_TEXTURE_2D; |
2458 | glEnable GL_TEXTURE_2D; |
2469 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2459 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2470 | glColor 1, 1, 1, 1; |
2460 | glColor 1, 1, 1, 1; |
2471 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
2461 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2472 | glDisable GL_TEXTURE_2D; |
2462 | glDisable GL_TEXTURE_2D; |
2473 | glDisable GL_BLEND; |
|
|
2474 | } |
2463 | } |
2475 | } |
2464 | } |
2476 | |
2465 | |
2477 | ############################################################################# |
2466 | ############################################################################# |
2478 | |
2467 | |
… | |
… | |
2655 | } |
2644 | } |
2656 | } |
2645 | } |
2657 | |
2646 | |
2658 | ############################################################################# |
2647 | ############################################################################# |
2659 | |
2648 | |
|
|
2649 | package CFClient::UI::Statusbox; |
|
|
2650 | |
|
|
2651 | our @ISA = CFClient::UI::VBox::; |
|
|
2652 | |
|
|
2653 | sub reorder { |
|
|
2654 | my ($self) = @_; |
|
|
2655 | my $NOW = time; |
|
|
2656 | |
|
|
2657 | while (my ($k, $v) = each %{ $self->{item} }) { |
|
|
2658 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
|
|
2659 | } |
|
|
2660 | |
|
|
2661 | my @widgets; |
|
|
2662 | my @items = sort { $a->{time} <=> $b->{time} } values %{ $self->{item} }; |
|
|
2663 | my $count = 10 + 1; |
|
|
2664 | for my $item (@items) { |
|
|
2665 | last unless --$count; |
|
|
2666 | |
|
|
2667 | push @widgets, $item->{label} ||= do { |
|
|
2668 | # TODO: doesn't handle markup well (read as: at all) |
|
|
2669 | my $short = delete $item->{text}; |
|
|
2670 | for ($short) { |
|
|
2671 | s/^\s+//; |
|
|
2672 | s/\012.*//s; |
|
|
2673 | my $len = int 30 / $item->{fontsize}; |
|
|
2674 | substr $_, $len, length, "…" if $len < length; |
|
|
2675 | } |
|
|
2676 | |
|
|
2677 | new CFClient::UI::Label |
|
|
2678 | markup => $short, |
|
|
2679 | tooltip => delete $item->{tooltip}, |
|
|
2680 | fontsize => delete $item->{fontsize}, |
|
|
2681 | color => delete $item->{color}, |
|
|
2682 | can_events => 1, |
|
|
2683 | can_hover => 1, |
|
|
2684 | }; |
|
|
2685 | } |
|
|
2686 | |
|
|
2687 | $self->clear; |
|
|
2688 | $self->SUPER::add (@widgets); |
|
|
2689 | } |
|
|
2690 | |
|
|
2691 | sub add { |
|
|
2692 | my ($self, $text, %arg) = @_; |
|
|
2693 | |
|
|
2694 | my $item = { |
|
|
2695 | time => time, |
|
|
2696 | text => $text, |
|
|
2697 | timeout => 60, |
|
|
2698 | tooltip => $text, |
|
|
2699 | fontsize => 0.8, |
|
|
2700 | color => [0.8, 0.8, 0.8, 0.8], |
|
|
2701 | %arg, |
|
|
2702 | }; |
|
|
2703 | |
|
|
2704 | $item->{timeout} += time; |
|
|
2705 | $item->{group} ||= $item+0; |
|
|
2706 | |
|
|
2707 | $item = $self->{item}{$item->{group}} ||= $item; |
|
|
2708 | |
|
|
2709 | $self->reorder; |
|
|
2710 | } |
|
|
2711 | |
|
|
2712 | ############################################################################# |
|
|
2713 | |
2660 | package CFClient::UI::Root; |
2714 | package CFClient::UI::Root; |
2661 | |
2715 | |
2662 | our @ISA = CFClient::UI::Container::; |
2716 | our @ISA = CFClient::UI::Container::; |
2663 | |
2717 | |
2664 | use CFClient::OpenGL; |
2718 | use CFClient::OpenGL; |