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_tooltip_from ($widget); |
29 | |
|
|
30 | $TOOLTIP->show; |
30 | $TOOLTIP->show; |
31 | |
31 | |
32 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
32 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
33 | |
33 | |
34 | if ($x + $TOOLTIP->{w} > $::WIDTH) { |
34 | if ($x + $TOOLTIP->{w} > $::WIDTH) { |
35 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); |
35 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); |
36 | } |
36 | } |
37 | |
37 | |
38 | $TOOLTIP->move ($x, $y); |
38 | $TOOLTIP->move ($x, $y); |
|
|
39 | $TOOLTIP->check_size; |
|
|
40 | $TOOLTIP->update; |
39 | } |
41 | } |
40 | |
42 | |
41 | return; |
43 | return; |
42 | } |
44 | } |
43 | } |
45 | } |
… | |
… | |
387 | $self->check_size |
389 | $self->check_size |
388 | unless exists $self->{req_w}; |
390 | unless exists $self->{req_w}; |
389 | } |
391 | } |
390 | |
392 | |
391 | sub check_size { |
393 | sub check_size { |
392 | my ($self) = @_; |
394 | my ($self, $forced) = @_; |
393 | |
395 | |
|
|
396 | $self->{force_alloc} = 1 if $forced; |
394 | $CFClient::UI::ROOT->{check_size}{$self} = $self; |
397 | $CFClient::UI::ROOT->{check_size}{$self} = $self; |
395 | } |
398 | } |
396 | |
399 | |
397 | sub update { |
400 | sub update { |
398 | my ($self) = @_; |
401 | my ($self) = @_; |
… | |
… | |
508 | $self->{children} = [ |
511 | $self->{children} = [ |
509 | sort { $a->{z} <=> $b->{z} } |
512 | sort { $a->{z} <=> $b->{z} } |
510 | @{$self->{children}}, @widgets |
513 | @{$self->{children}}, @widgets |
511 | ]; |
514 | ]; |
512 | |
515 | |
513 | $self->check_size; |
516 | $self->check_size (1); |
514 | $self->update; |
517 | $self->update; |
515 | } |
518 | } |
516 | |
519 | |
517 | sub children { |
520 | sub children { |
518 | @{ $_[0]{children} } |
521 | @{ $_[0]{children} } |
… | |
… | |
666 | my ($w, $h) = ($self->w, $self->h); |
669 | my ($w, $h) = ($self->w, $self->h); |
667 | |
670 | |
668 | my $tex = $self->{texture} |
671 | my $tex = $self->{texture} |
669 | or return; |
672 | or return; |
670 | |
673 | |
671 | glEnable GL_BLEND; |
|
|
672 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
673 | glEnable GL_TEXTURE_2D; |
674 | glEnable GL_TEXTURE_2D; |
674 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
675 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
675 | glColor 0, 0, 0, 1; |
676 | glColor 0, 0, 0, 1; |
676 | |
677 | |
677 | $tex->draw_quad (0, 0, $w, $h); |
678 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
678 | |
679 | |
679 | glDisable GL_BLEND; |
|
|
680 | glDisable GL_TEXTURE_2D; |
680 | glDisable GL_TEXTURE_2D; |
681 | } |
681 | } |
682 | |
682 | |
683 | ############################################################################# |
683 | ############################################################################# |
684 | |
684 | |
… | |
… | |
787 | |
787 | |
788 | our @ISA = CFClient::UI::Bin::; |
788 | our @ISA = CFClient::UI::Bin::; |
789 | |
789 | |
790 | use CFClient::OpenGL; |
790 | use CFClient::OpenGL; |
791 | |
791 | |
792 | sub new { |
|
|
793 | my $class = shift; |
|
|
794 | |
|
|
795 | my $self = $class->SUPER::new ( |
|
|
796 | bg => [1, 1, 1, 1], |
|
|
797 | border_bg => [1, 1, 1, 1], |
|
|
798 | border => 0.8, |
|
|
799 | @_ |
|
|
800 | ); |
|
|
801 | |
|
|
802 | $self |
|
|
803 | } |
|
|
804 | |
|
|
805 | sub _draw { |
|
|
806 | my ($self) = @_; |
|
|
807 | |
|
|
808 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
809 | |
|
|
810 | glEnable GL_BLEND; |
|
|
811 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
812 | glEnable GL_TEXTURE_2D; |
|
|
813 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
814 | |
|
|
815 | # glBegin GL_QUADS; |
|
|
816 | # glColor 0, 0, 0, 0; |
|
|
817 | # glVertex 0 , 0; |
|
|
818 | # glVertex 0 , $h; |
|
|
819 | # glVertex $w, $h; |
|
|
820 | # glVertex $w, 0; |
|
|
821 | # glEnd; |
|
|
822 | |
|
|
823 | |
|
|
824 | $self->child->draw; |
|
|
825 | glDisable GL_BLEND; |
|
|
826 | glDisable GL_TEXTURE_2D; |
|
|
827 | } |
|
|
828 | |
|
|
829 | ############################################################################# |
792 | ############################################################################# |
830 | |
793 | |
831 | package CFClient::UI::FancyFrame; |
794 | package CFClient::UI::FancyFrame; |
832 | |
795 | |
833 | our @ISA = CFClient::UI::Bin::; |
796 | our @ISA = CFClient::UI::Bin::; |
… | |
… | |
947 | my ($self) = @_; |
910 | my ($self) = @_; |
948 | |
911 | |
949 | my ($w, $h ) = ($self->{w}, $self->{h}); |
912 | my ($w, $h ) = ($self->{w}, $self->{h}); |
950 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
913 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
951 | |
914 | |
952 | glEnable GL_BLEND; |
|
|
953 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
954 | glEnable GL_TEXTURE_2D; |
915 | glEnable GL_TEXTURE_2D; |
955 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
916 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
956 | |
917 | |
957 | my $border = $self->border; |
918 | my $border = $self->border; |
958 | |
919 | |
959 | glColor @{ $self->{border_bg} }; |
920 | glColor @{ $self->{border_bg} }; |
960 | $tex[1]->draw_quad (0, 0, $w, $border); |
921 | $tex[1]->draw_quad_alpha (0, 0, $w, $border); |
961 | $tex[3]->draw_quad (0, $border, $border, $ch); |
922 | $tex[3]->draw_quad_alpha (0, $border, $border, $ch); |
962 | $tex[2]->draw_quad ($w - $border, $border, $border, $ch); |
923 | $tex[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
963 | $tex[4]->draw_quad (0, $h - $border, $w, $border); |
924 | $tex[4]->draw_quad_alpha (0, $h - $border, $w, $border); |
964 | |
925 | |
965 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
926 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
966 | my $bg = $tex[0]; |
927 | my $bg = $tex[0]; |
967 | |
928 | |
968 | # TODO: repeat texture not scale |
929 | # TODO: repeat texture not scale |
… | |
… | |
972 | glColor @{ $self->{bg} }; |
933 | glColor @{ $self->{bg} }; |
973 | |
934 | |
974 | $bg->{s} = $rep_x; |
935 | $bg->{s} = $rep_x; |
975 | $bg->{t} = $rep_y; |
936 | $bg->{t} = $rep_y; |
976 | $bg->{wrap_mode} = 1; |
937 | $bg->{wrap_mode} = 1; |
977 | $bg->draw_quad ($border, $border, $cw, $ch); |
938 | $bg->draw_quad_alpha ($border, $border, $cw, $ch); |
|
|
939 | } |
978 | |
940 | |
979 | glDisable GL_TEXTURE_2D; |
941 | glDisable GL_TEXTURE_2D; |
980 | glDisable GL_BLEND; |
|
|
981 | } |
|
|
982 | |
942 | |
983 | $self->{title}->draw if $self->{title}; |
943 | $self->{title}->draw if $self->{title}; |
984 | |
944 | |
985 | $self->child->draw; |
945 | $self->child->draw; |
986 | } |
946 | } |
… | |
… | |
1263 | my ($class, %arg) = @_; |
1223 | my ($class, %arg) = @_; |
1264 | |
1224 | |
1265 | my $self = $class->SUPER::new ( |
1225 | my $self = $class->SUPER::new ( |
1266 | fg => [1, 1, 1], |
1226 | fg => [1, 1, 1], |
1267 | #font => default_font |
1227 | #font => default_font |
|
|
1228 | #text => initial text |
|
|
1229 | #markup => initial narkup |
|
|
1230 | layout => (new CFClient::Layout), |
1268 | fontsize => 1, |
1231 | fontsize => 1, |
1269 | text => "", |
|
|
1270 | align => -1, |
1232 | align => -1, |
1271 | valign => -1, |
1233 | valign => -1, |
1272 | padding => 2, |
1234 | padding => 2, |
1273 | layout => new CFClient::Layout, |
|
|
1274 | can_events => 0, |
1235 | can_events => 0, |
1275 | %arg |
1236 | %arg |
1276 | ); |
1237 | ); |
1277 | |
1238 | |
1278 | if (exists $self->{template}) { |
1239 | if (exists $self->{template}) { |
1279 | my $layout = new CFClient::Layout; |
1240 | my $layout = new CFClient::Layout; |
1280 | $layout->set_text (delete $self->{template}); |
1241 | $layout->set_text (delete $self->{template}); |
1281 | $self->{template} = $layout; |
1242 | $self->{template} = $layout; |
1282 | } |
1243 | } |
1283 | |
1244 | |
1284 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1245 | if (exists $self->{markup}) { |
1285 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1246 | $self->set_markup (delete $self->{markup}); |
|
|
1247 | } else { |
|
|
1248 | $self->set_text (delete $self->{text}); |
|
|
1249 | } |
1286 | |
1250 | |
1287 | $self |
1251 | $self |
1288 | } |
1252 | } |
1289 | |
1253 | |
1290 | sub escape { |
1254 | sub escape { |
… | |
… | |
1308 | my ($self, $text) = @_; |
1272 | my ($self, $text) = @_; |
1309 | |
1273 | |
1310 | return if $self->{text} eq "T$text"; |
1274 | return if $self->{text} eq "T$text"; |
1311 | $self->{text} = "T$text"; |
1275 | $self->{text} = "T$text"; |
1312 | |
1276 | |
|
|
1277 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1313 | $self->{layout}->set_text ($text); |
1278 | $self->{layout}->set_text ($text); |
1314 | |
1279 | |
1315 | $self->update; |
1280 | $self->update; |
1316 | $self->check_size; |
1281 | $self->check_size; |
1317 | } |
1282 | } |
… | |
… | |
1320 | my ($self, $markup) = @_; |
1285 | my ($self, $markup) = @_; |
1321 | |
1286 | |
1322 | return if $self->{text} eq "M$markup"; |
1287 | return if $self->{text} eq "M$markup"; |
1323 | $self->{text} = "M$markup"; |
1288 | $self->{text} = "M$markup"; |
1324 | |
1289 | |
|
|
1290 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
|
|
1291 | |
|
|
1292 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
1325 | $self->{layout}->set_markup ($markup); |
1293 | $self->{layout}->set_markup ($markup); |
1326 | |
1294 | |
1327 | $self->update; |
1295 | $self->update; |
1328 | $self->check_size; |
1296 | $self->check_size; |
1329 | } |
1297 | } |
… | |
… | |
1371 | |
1339 | |
1372 | sub _draw { |
1340 | sub _draw { |
1373 | my ($self) = @_; |
1341 | my ($self) = @_; |
1374 | |
1342 | |
1375 | my $tex = $self->{texture} ||= do { |
1343 | my $tex = $self->{texture} ||= do { |
|
|
1344 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1376 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1345 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1377 | $self->{layout}->set_width ($self->{w}); |
1346 | $self->{layout}->set_width ($self->{w}); |
1378 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1347 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
|
|
1348 | |
1379 | new_from_layout CFClient::Texture $self->{layout} |
1349 | my $tex = new_from_layout CFClient::Texture $self->{layout}; |
|
|
1350 | |
|
|
1351 | $self->{ox} = int $self->{align} < 0 ? $self->{padding} |
|
|
1352 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
|
|
1353 | : ($self->{w} - $tex->{w}) * 0.5; |
|
|
1354 | |
|
|
1355 | $self->{oy} = int $self->{valign} < 0 ? $self->{padding} |
|
|
1356 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
|
|
1357 | : ($self->{h} - $tex->{h}) * 0.5; |
|
|
1358 | |
|
|
1359 | $tex |
1380 | }; |
1360 | }; |
1381 | |
1361 | |
1382 | glEnable GL_BLEND; |
|
|
1383 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1384 | glEnable GL_TEXTURE_2D; |
1362 | glEnable GL_TEXTURE_2D; |
1385 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1363 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1386 | |
1364 | |
|
|
1365 | if ($tex->{format} == GL_ALPHA) { |
1387 | glColor @{$self->{fg}}; |
1366 | 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}); |
1367 | $tex->draw_quad_alpha ($self->{ox}, $self->{oy}); |
|
|
1368 | } else { |
|
|
1369 | $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy}); |
|
|
1370 | } |
1402 | |
1371 | |
1403 | glDisable GL_TEXTURE_2D; |
1372 | glDisable GL_TEXTURE_2D; |
1404 | glDisable GL_BLEND; |
|
|
1405 | } |
1373 | } |
1406 | |
1374 | |
1407 | ############################################################################# |
1375 | ############################################################################# |
1408 | |
1376 | |
1409 | package CFClient::UI::EntryBase; |
1377 | package CFClient::UI::EntryBase; |
… | |
… | |
1444 | $self->{layout}->set_text ("$text "); |
1412 | $self->{layout}->set_text ("$text "); |
1445 | |
1413 | |
1446 | $self->emit (changed => $self->{text}); |
1414 | $self->emit (changed => $self->{text}); |
1447 | } |
1415 | } |
1448 | |
1416 | |
|
|
1417 | sub set_text { |
|
|
1418 | my ($self, $text) = @_; |
|
|
1419 | |
|
|
1420 | $self->{cursor} = length $text; |
|
|
1421 | $self->_set_text ($text); |
|
|
1422 | $self->check_size; |
|
|
1423 | $self->update; |
|
|
1424 | } |
|
|
1425 | |
1449 | sub get_text { |
1426 | sub get_text { |
1450 | $_[0]{text} |
1427 | $_[0]{text} |
1451 | } |
1428 | } |
1452 | |
1429 | |
1453 | sub size_request { |
1430 | sub size_request { |
… | |
… | |
1460 | |
1437 | |
1461 | sub size_allocate { |
1438 | sub size_allocate { |
1462 | my ($self, $w, $h) = @_; |
1439 | my ($self, $w, $h) = @_; |
1463 | |
1440 | |
1464 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
1441 | $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 | } |
1442 | } |
1474 | |
1443 | |
1475 | sub key_down { |
1444 | sub key_down { |
1476 | my ($self, $ev) = @_; |
1445 | my ($self, $ev) = @_; |
1477 | |
1446 | |
… | |
… | |
1665 | |
1634 | |
1666 | if ($GRAB == $self) { |
1635 | if ($GRAB == $self) { |
1667 | $self->{fg} = $self->{active_fg}; |
1636 | $self->{fg} = $self->{active_fg}; |
1668 | } |
1637 | } |
1669 | |
1638 | |
1670 | glEnable GL_BLEND; |
|
|
1671 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1672 | glEnable GL_TEXTURE_2D; |
1639 | glEnable GL_TEXTURE_2D; |
1673 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1640 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1674 | glColor 0, 0, 0, 1; |
1641 | glColor 0, 0, 0, 1; |
1675 | |
1642 | |
1676 | $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h}); |
1643 | $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
1677 | |
1644 | |
1678 | glDisable GL_TEXTURE_2D; |
1645 | glDisable GL_TEXTURE_2D; |
1679 | glDisable GL_BLEND; |
|
|
1680 | |
1646 | |
1681 | $self->SUPER::_draw; |
1647 | $self->SUPER::_draw; |
1682 | } |
1648 | } |
1683 | |
1649 | |
1684 | ############################################################################# |
1650 | ############################################################################# |
… | |
… | |
1731 | |
1697 | |
1732 | my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; |
1698 | my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; |
1733 | |
1699 | |
1734 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1700 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1735 | |
1701 | |
1736 | glEnable GL_BLEND; |
1702 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
|
|
1703 | |
1737 | glEnable GL_TEXTURE_2D; |
1704 | glEnable GL_TEXTURE_2D; |
1738 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1739 | |
|
|
1740 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
|
|
1741 | |
|
|
1742 | $tex->draw_quad (0, 0, $s, $s); |
1705 | $tex->draw_quad_alpha (0, 0, $s, $s); |
1743 | |
|
|
1744 | glDisable GL_TEXTURE_2D; |
1706 | glDisable GL_TEXTURE_2D; |
1745 | glDisable GL_BLEND; |
|
|
1746 | } |
1707 | } |
1747 | |
1708 | |
1748 | ############################################################################# |
1709 | ############################################################################# |
1749 | |
1710 | |
1750 | package CFClient::UI::Image; |
1711 | package CFClient::UI::Image; |
… | |
… | |
1793 | glTranslate 0, -$self->{w}, 0; |
1754 | glTranslate 0, -$self->{w}, 0; |
1794 | |
1755 | |
1795 | ($w, $h) = ($h, $w); |
1756 | ($w, $h) = ($h, $w); |
1796 | } |
1757 | } |
1797 | |
1758 | |
1798 | glEnable GL_BLEND; |
|
|
1799 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1800 | glEnable GL_TEXTURE_2D; |
1759 | glEnable GL_TEXTURE_2D; |
1801 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1760 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1802 | |
1761 | |
1803 | $tex->draw_quad (0, 0, $w, $h); |
1762 | $tex->draw_quad_alpha (0, 0, $w, $h); |
1804 | |
1763 | |
1805 | glDisable GL_BLEND; |
|
|
1806 | glDisable GL_TEXTURE_2D; |
1764 | glDisable GL_TEXTURE_2D; |
1807 | } |
1765 | } |
1808 | |
1766 | |
1809 | ############################################################################# |
1767 | ############################################################################# |
1810 | |
1768 | |
… | |
… | |
2102 | $page ||= 2; |
2060 | $page ||= 2; |
2103 | |
2061 | |
2104 | my $knob_a = $inner_pad_px + ($value - $page * 0.5); |
2062 | my $knob_a = $inner_pad_px + ($value - $page * 0.5); |
2105 | my $knob_b = $inner_pad_px + ($value + $page * 0.5); |
2063 | my $knob_b = $inner_pad_px + ($value + $page * 0.5); |
2106 | |
2064 | |
2107 | glEnable GL_BLEND; |
|
|
2108 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2109 | glEnable GL_TEXTURE_2D; |
2065 | glEnable GL_TEXTURE_2D; |
2110 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2066 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2111 | |
2067 | |
2112 | # draw background |
2068 | # draw background |
2113 | $tex[1]->draw_quad (0, 0, $w, $h); |
2069 | $tex[1]->draw_quad_alpha (0, 0, $w, $h); |
2114 | |
2070 | |
2115 | # draw handle |
2071 | # draw handle |
2116 | $tex[0]->draw_quad ($knob_a, 0, $knob_b - $knob_a, $h); |
2072 | $tex[0]->draw_quad_alpha ($knob_a, 0, $knob_b - $knob_a, $h); |
2117 | |
2073 | |
2118 | glDisable GL_BLEND; |
|
|
2119 | glDisable GL_TEXTURE_2D; |
2074 | glDisable GL_TEXTURE_2D; |
2120 | } |
2075 | } |
2121 | |
2076 | |
2122 | ############################################################################# |
2077 | ############################################################################# |
2123 | |
2078 | |
… | |
… | |
2134 | fontsize => 1, |
2089 | fontsize => 1, |
2135 | can_events => 0, |
2090 | can_events => 0, |
2136 | #font => default_font |
2091 | #font => default_font |
2137 | @_, |
2092 | @_, |
2138 | |
2093 | |
2139 | layout => (new CFClient::Layout), |
2094 | layout => (new CFClient::Layout 1), |
2140 | par => [], |
2095 | par => [], |
2141 | height => 0, |
2096 | height => 0, |
2142 | children => [ |
2097 | children => [ |
2143 | (new CFClient::UI::Empty expand => 1), |
2098 | (new CFClient::UI::Empty expand => 1), |
2144 | (new CFClient::UI::Slider vertical => 1), |
2099 | (new CFClient::UI::Slider vertical => 1), |
… | |
… | |
2162 | |
2117 | |
2163 | my $layout = $self->{layout}; |
2118 | my $layout = $self->{layout}; |
2164 | |
2119 | |
2165 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2120 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2166 | $layout->set_width ($self->{children}[0]{w}); |
2121 | $layout->set_width ($self->{children}[0]{w}); |
2167 | $layout->set_text ($text); |
2122 | $layout->set_markup ($text); |
2168 | |
2123 | |
2169 | ($layout->size)[1] |
2124 | ($layout->size)[1] |
2170 | } |
2125 | } |
2171 | |
2126 | |
2172 | sub reflow { |
2127 | sub reflow { |
… | |
… | |
2228 | |
2183 | |
2229 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2184 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { |
2230 | glClearColor 0, 0, 0, 0; |
2185 | glClearColor 0, 0, 0, 0; |
2231 | glClear GL_COLOR_BUFFER_BIT; |
2186 | glClear GL_COLOR_BUFFER_BIT; |
2232 | |
2187 | |
2233 | glEnable GL_BLEND; |
|
|
2234 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2235 | glEnable GL_TEXTURE_2D; |
2188 | glEnable GL_TEXTURE_2D; |
2236 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2189 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2237 | |
2190 | |
2238 | my $top = int $self->{children}[1]{range}[0]; |
2191 | my $top = int $self->{children}[1]{range}[0]; |
2239 | |
2192 | |
… | |
… | |
2248 | |
2201 | |
2249 | for my $par (@{$self->{par}}) { |
2202 | for my $par (@{$self->{par}}) { |
2250 | my $h = $par->[0]; |
2203 | my $h = $par->[0]; |
2251 | |
2204 | |
2252 | if ($y0 < $y + $h && $y < $y1) { |
2205 | if ($y0 < $y + $h && $y < $y1) { |
|
|
2206 | $layout->set_foreground (@{ $par->[1] }); |
2253 | $layout->set_text ($par->[2]); |
2207 | $layout->set_markup ($par->[2]); |
2254 | |
2208 | |
2255 | glColor @{ $par->[1] }; |
|
|
2256 | my ($W, $H) = $layout->size; |
2209 | my ($W, $H) = $layout->size; |
2257 | CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0); |
2210 | CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); |
2258 | } |
2211 | } |
2259 | |
2212 | |
2260 | $y += $h; |
2213 | $y += $h; |
2261 | } |
2214 | } |
2262 | |
2215 | |
2263 | glDisable GL_TEXTURE_2D; |
2216 | glDisable GL_TEXTURE_2D; |
2264 | glDisable GL_BLEND; |
|
|
2265 | }; |
2217 | }; |
2266 | }); |
2218 | }); |
2267 | } |
2219 | } |
2268 | |
2220 | |
2269 | sub _draw { |
2221 | sub _draw { |
2270 | my ($self) = @_; |
2222 | my ($self) = @_; |
2271 | |
2223 | |
2272 | glEnable GL_BLEND; |
|
|
2273 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2274 | glEnable GL_TEXTURE_2D; |
2224 | glEnable GL_TEXTURE_2D; |
2275 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2225 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2276 | glColor 1, 1, 1, 1; |
2226 | glColor 1, 1, 1, 1; |
2277 | $self->{texture}->draw_quad (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2227 | $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); |
2278 | glDisable GL_TEXTURE_2D; |
2228 | glDisable GL_TEXTURE_2D; |
2279 | glDisable GL_BLEND; |
|
|
2280 | |
2229 | |
2281 | $self->{children}[1]->draw; |
2230 | $self->{children}[1]->draw; |
2282 | |
2231 | |
2283 | } |
2232 | } |
2284 | |
2233 | |
… | |
… | |
2378 | @_, |
2327 | @_, |
2379 | can_events => 0, |
2328 | can_events => 0, |
2380 | ) |
2329 | ) |
2381 | } |
2330 | } |
2382 | |
2331 | |
2383 | sub set_markup { |
2332 | sub set_tooltip_from { |
2384 | my ($self, $text) = @_; |
2333 | my ($self, $widget) = @_; |
2385 | |
2334 | |
2386 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; |
2335 | $self->add (new CFClient::UI::Label |
2387 | $self->{label}->set_markup ($text); |
2336 | markup => $widget->{tooltip}, |
2388 | $self->add ($self->{label}); |
2337 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
|
|
2338 | fontsize => 0.8, |
|
|
2339 | fg => [0, 0, 0, 1], |
|
|
2340 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
|
|
2341 | ); |
2389 | } |
2342 | } |
2390 | |
2343 | |
2391 | sub size_request { |
2344 | sub size_request { |
2392 | my ($self) = @_; |
2345 | my ($self) = @_; |
2393 | |
|
|
2394 | $self->child->set_max_size ($::WIDTH * 0.3); |
|
|
2395 | |
2346 | |
2396 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
2347 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
2397 | |
2348 | |
2398 | ($w + 4, $h + 4) |
2349 | ($w + 4, $h + 4) |
2399 | } |
2350 | } |
… | |
… | |
2405 | } |
2356 | } |
2406 | |
2357 | |
2407 | sub _draw { |
2358 | sub _draw { |
2408 | my ($self) = @_; |
2359 | my ($self) = @_; |
2409 | |
2360 | |
2410 | glPushMatrix; |
|
|
2411 | glTranslate 0.375, 0.375; |
2361 | glTranslate 0.375, 0.375; |
2412 | |
2362 | |
2413 | my ($w, $h) = @$self{qw(w h)}; |
2363 | my ($w, $h) = @$self{qw(w h)}; |
2414 | |
2364 | |
2415 | glColor 1, 0.8, 0.4; |
2365 | glColor 1, 0.8, 0.4; |
… | |
… | |
2426 | glVertex 0 , $h; |
2376 | glVertex 0 , $h; |
2427 | glVertex $w, $h; |
2377 | glVertex $w, $h; |
2428 | glVertex $w, 0; |
2378 | glVertex $w, 0; |
2429 | glEnd; |
2379 | glEnd; |
2430 | |
2380 | |
2431 | glPopMatrix; |
2381 | glTranslate 2 - 0.375, 2 - 0.375; |
2432 | |
|
|
2433 | glTranslate 2, 2; |
|
|
2434 | $self->SUPER::_draw; |
2382 | $self->SUPER::_draw; |
2435 | } |
2383 | } |
2436 | |
2384 | |
2437 | ############################################################################# |
2385 | ############################################################################# |
2438 | |
2386 | |
… | |
… | |
2461 | return unless $::CONN;#d# manage and cache textures differently |
2409 | return unless $::CONN;#d# manage and cache textures differently |
2462 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2410 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2463 | |
2411 | |
2464 | # TODO animation |
2412 | # TODO animation |
2465 | if ($tex) { |
2413 | if ($tex) { |
2466 | glEnable GL_BLEND; |
|
|
2467 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2468 | glEnable GL_TEXTURE_2D; |
2414 | glEnable GL_TEXTURE_2D; |
2469 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2415 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2470 | glColor 1, 1, 1, 1; |
2416 | glColor 1, 1, 1, 1; |
2471 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
2417 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2472 | glDisable GL_TEXTURE_2D; |
2418 | glDisable GL_TEXTURE_2D; |
2473 | glDisable GL_BLEND; |
|
|
2474 | } |
2419 | } |
2475 | } |
2420 | } |
2476 | |
2421 | |
2477 | ############################################################################# |
2422 | ############################################################################# |
2478 | |
2423 | |
… | |
… | |
2655 | } |
2600 | } |
2656 | } |
2601 | } |
2657 | |
2602 | |
2658 | ############################################################################# |
2603 | ############################################################################# |
2659 | |
2604 | |
|
|
2605 | package CFClient::UI::Statusbox; |
|
|
2606 | |
|
|
2607 | our @ISA = CFClient::UI::VBox::; |
|
|
2608 | |
|
|
2609 | sub reorder { |
|
|
2610 | my ($self) = @_; |
|
|
2611 | my $NOW = time; |
|
|
2612 | |
|
|
2613 | while (my ($k, $v) = each %{ $self->{item} }) { |
|
|
2614 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
|
|
2615 | } |
|
|
2616 | |
|
|
2617 | my @widgets; |
|
|
2618 | |
|
|
2619 | my @items = sort { |
|
|
2620 | $a->{pri} <=> $b->{pri} |
|
|
2621 | or $b->{id} <=> $a->{id} |
|
|
2622 | } values %{ $self->{item} }; |
|
|
2623 | |
|
|
2624 | my $count = 10 + 1; |
|
|
2625 | for my $item (@items) { |
|
|
2626 | last unless --$count; |
|
|
2627 | |
|
|
2628 | push @widgets, $item->{label} ||= do { |
|
|
2629 | # TODO: doesn't handle markup well (read as: at all) |
|
|
2630 | my $short = $item->{count} > 1 |
|
|
2631 | ? "<b>$item->{count} ×</b> $item->{text}" |
|
|
2632 | : $item->{text}; |
|
|
2633 | |
|
|
2634 | for ($short) { |
|
|
2635 | s/^\s+//; |
|
|
2636 | s/\012.*/…/s; |
|
|
2637 | my $len = int 30 / $item->{fontsize}; |
|
|
2638 | substr $_, $len, length, "…" if $len < length; |
|
|
2639 | } |
|
|
2640 | |
|
|
2641 | new CFClient::UI::Label |
|
|
2642 | markup => $short, |
|
|
2643 | tooltip => $item->{tooltip}, |
|
|
2644 | tooltip_font => $::FONT_PROP, |
|
|
2645 | tooltip_width => 0.67, |
|
|
2646 | fontsize => $item->{fontsize}, |
|
|
2647 | color => $item->{color}, |
|
|
2648 | can_events => 1, |
|
|
2649 | can_hover => 1 |
|
|
2650 | }; |
|
|
2651 | } |
|
|
2652 | |
|
|
2653 | $self->clear; |
|
|
2654 | $self->SUPER::add (reverse @widgets); |
|
|
2655 | } |
|
|
2656 | |
|
|
2657 | sub add { |
|
|
2658 | my ($self, $text, %arg) = @_; |
|
|
2659 | |
|
|
2660 | my $timeout = time + ((delete $arg{timeout}) || 60); |
|
|
2661 | |
|
|
2662 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
|
|
2663 | |
|
|
2664 | if (my $item = $self->{item}{$group}) { |
|
|
2665 | if ($item->{text} eq $text) { |
|
|
2666 | $item->{count}++; |
|
|
2667 | } else { |
|
|
2668 | $item->{count} = 1; |
|
|
2669 | $item->{text} = $item->{tooltip} = $text; |
|
|
2670 | } |
|
|
2671 | $item->{timeout} = $timeout; |
|
|
2672 | delete $item->{label}; |
|
|
2673 | } else { |
|
|
2674 | $self->{item}{$group} = { |
|
|
2675 | id => ++$self->{id}, |
|
|
2676 | text => $text, |
|
|
2677 | timeout => $timeout, |
|
|
2678 | tooltip => $text, |
|
|
2679 | fontsize => 0.8, |
|
|
2680 | color => [0.8, 0.8, 0.8, 0.8], |
|
|
2681 | pri => 0, |
|
|
2682 | count => 1, |
|
|
2683 | %arg, |
|
|
2684 | }; |
|
|
2685 | } |
|
|
2686 | |
|
|
2687 | $self->reorder; |
|
|
2688 | } |
|
|
2689 | |
|
|
2690 | ############################################################################# |
|
|
2691 | |
2660 | package CFClient::UI::Root; |
2692 | package CFClient::UI::Root; |
2661 | |
2693 | |
2662 | our @ISA = CFClient::UI::Container::; |
2694 | our @ISA = CFClient::UI::Container::; |
2663 | |
2695 | |
2664 | use CFClient::OpenGL; |
2696 | use CFClient::OpenGL; |
… | |
… | |
2774 | |
2806 | |
2775 | my ($w, $h) = $widget->{user_w} && $widget->{user_h} |
2807 | my ($w, $h) = $widget->{user_w} && $widget->{user_h} |
2776 | ? @$widget{qw(user_w user_h)} |
2808 | ? @$widget{qw(user_w user_h)} |
2777 | : $widget->size_request; |
2809 | : $widget->size_request; |
2778 | |
2810 | |
|
|
2811 | if (delete $widget->{force_alloc} |
2779 | if ($w != $widget->{req_w} || $h != $widget->{req_h}) { |
2812 | or $w != $widget->{req_w} or $h != $widget->{req_h}) { |
2780 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
2813 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
2781 | |
2814 | |
2782 | $widget->{req_w} = $w; |
2815 | $widget->{req_w} = $w; |
2783 | $widget->{req_h} = $h; |
2816 | $widget->{req_h} = $h; |
2784 | |
2817 | |
2785 | $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}]; |
2818 | $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h]; |
2786 | |
2819 | |
2787 | $widget->{parent}->check_size |
2820 | $widget->{parent}->check_size |
2788 | if $widget->{parent}; |
2821 | if $widget->{parent}; |
2789 | } |
2822 | } |
2790 | } |
2823 | } |