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 | } |
… | |
… | |
380 | } |
382 | } |
381 | |
383 | |
382 | sub set_parent { |
384 | sub set_parent { |
383 | my ($self, $parent) = @_; |
385 | my ($self, $parent) = @_; |
384 | |
386 | |
385 | $self->{_tree_depth} = $parent->{_tree_depth} + 1; |
|
|
386 | Scalar::Util::weaken ($self->{parent} = $parent); |
387 | Scalar::Util::weaken ($self->{parent} = $parent); |
|
|
388 | |
|
|
389 | $self->check_size |
|
|
390 | unless exists $self->{req_w}; |
387 | } |
391 | } |
388 | |
392 | |
389 | sub check_size { |
393 | sub check_size { |
390 | my ($self) = @_; |
394 | my ($self, $forced) = @_; |
391 | |
395 | |
|
|
396 | $self->{force_alloc} = 1 if $forced; |
392 | $CFClient::UI::ROOT->{check_size}{$self} = $self; |
397 | $CFClient::UI::ROOT->{check_size}{$self} = $self; |
393 | } |
398 | } |
394 | |
399 | |
395 | sub update { |
400 | sub update { |
396 | my ($self) = @_; |
401 | my ($self) = @_; |
… | |
… | |
506 | $self->{children} = [ |
511 | $self->{children} = [ |
507 | sort { $a->{z} <=> $b->{z} } |
512 | sort { $a->{z} <=> $b->{z} } |
508 | @{$self->{children}}, @widgets |
513 | @{$self->{children}}, @widgets |
509 | ]; |
514 | ]; |
510 | |
515 | |
511 | $_->check_size |
516 | $self->check_size (1); |
512 | for @widgets; |
|
|
513 | |
|
|
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 | } |
… | |
… | |
1213 | } |
1173 | } |
1214 | |
1174 | |
1215 | sub size_allocate { |
1175 | sub size_allocate { |
1216 | my ($self, $w, $h) = @_; |
1176 | my ($self, $w, $h) = @_; |
1217 | |
1177 | |
|
|
1178 | Carp::confess "negative size" if $w < 0 || $h < 0;#d# |
|
|
1179 | |
1218 | my $children = $self->{children}; |
1180 | my $children = $self->{children}; |
1219 | |
1181 | |
1220 | my @h = map $_->{req_h}, @$children; |
1182 | my @h = map $_->{req_h}, @$children; |
1221 | |
1183 | |
1222 | my $req_h = List::Util::sum @h; |
1184 | my $req_h = List::Util::sum @h; |
… | |
… | |
1261 | my ($class, %arg) = @_; |
1223 | my ($class, %arg) = @_; |
1262 | |
1224 | |
1263 | my $self = $class->SUPER::new ( |
1225 | my $self = $class->SUPER::new ( |
1264 | fg => [1, 1, 1], |
1226 | fg => [1, 1, 1], |
1265 | #font => default_font |
1227 | #font => default_font |
|
|
1228 | #text => initial text |
|
|
1229 | #markup => initial narkup |
|
|
1230 | layout => (new CFClient::Layout), |
1266 | fontsize => 1, |
1231 | fontsize => 1, |
1267 | text => "", |
|
|
1268 | align => -1, |
1232 | align => -1, |
1269 | valign => -1, |
1233 | valign => -1, |
1270 | padding => 2, |
1234 | padding => 2, |
1271 | layout => new CFClient::Layout, |
|
|
1272 | can_events => 0, |
1235 | can_events => 0, |
1273 | %arg |
1236 | %arg |
1274 | ); |
1237 | ); |
1275 | |
1238 | |
1276 | if (exists $self->{template}) { |
1239 | if (exists $self->{template}) { |
1277 | my $layout = new CFClient::Layout; |
1240 | my $layout = new CFClient::Layout; |
1278 | $layout->set_text (delete $self->{template}); |
1241 | $layout->set_text (delete $self->{template}); |
1279 | $self->{template} = $layout; |
1242 | $self->{template} = $layout; |
1280 | } |
1243 | } |
1281 | |
1244 | |
1282 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1245 | if (exists $self->{markup}) { |
1283 | $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 | } |
1284 | |
1250 | |
1285 | $self |
1251 | $self |
1286 | } |
1252 | } |
1287 | |
1253 | |
1288 | sub escape { |
1254 | sub escape { |
… | |
… | |
1306 | my ($self, $text) = @_; |
1272 | my ($self, $text) = @_; |
1307 | |
1273 | |
1308 | return if $self->{text} eq "T$text"; |
1274 | return if $self->{text} eq "T$text"; |
1309 | $self->{text} = "T$text"; |
1275 | $self->{text} = "T$text"; |
1310 | |
1276 | |
|
|
1277 | $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; |
1311 | $self->{layout}->set_text ($text); |
1278 | $self->{layout}->set_text ($text); |
1312 | |
1279 | |
1313 | $self->update; |
1280 | $self->update; |
1314 | $self->check_size; |
1281 | $self->check_size; |
1315 | } |
1282 | } |
… | |
… | |
1318 | my ($self, $markup) = @_; |
1285 | my ($self, $markup) = @_; |
1319 | |
1286 | |
1320 | return if $self->{text} eq "M$markup"; |
1287 | return if $self->{text} eq "M$markup"; |
1321 | $self->{text} = "M$markup"; |
1288 | $self->{text} = "M$markup"; |
1322 | |
1289 | |
|
|
1290 | my $rgba = $markup =~ /span.*(?:foreground|background)/; |
|
|
1291 | |
|
|
1292 | $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; |
1323 | $self->{layout}->set_markup ($markup); |
1293 | $self->{layout}->set_markup ($markup); |
1324 | |
1294 | |
1325 | $self->update; |
1295 | $self->update; |
1326 | $self->check_size; |
1296 | $self->check_size; |
1327 | } |
1297 | } |
… | |
… | |
1369 | |
1339 | |
1370 | sub _draw { |
1340 | sub _draw { |
1371 | my ($self) = @_; |
1341 | my ($self) = @_; |
1372 | |
1342 | |
1373 | my $tex = $self->{texture} ||= do { |
1343 | my $tex = $self->{texture} ||= do { |
|
|
1344 | $self->{layout}->set_foreground (@{$self->{fg}}); |
1374 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1345 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1375 | $self->{layout}->set_width ($self->{w}); |
1346 | $self->{layout}->set_width ($self->{w}); |
1376 | $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 | |
1377 | 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 |
1378 | }; |
1360 | }; |
1379 | |
1361 | |
1380 | glEnable GL_BLEND; |
|
|
1381 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1382 | glEnable GL_TEXTURE_2D; |
1362 | glEnable GL_TEXTURE_2D; |
1383 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1363 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1384 | |
1364 | |
|
|
1365 | if ($tex->{format} == GL_ALPHA) { |
1385 | glColor @{$self->{fg}}; |
1366 | glColor @{$self->{fg}}; |
1386 | |
|
|
1387 | $self->{ox} = int ( |
|
|
1388 | $self->{align} < 0 ? $self->{padding} |
|
|
1389 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
|
|
1390 | : ($self->{w} - $tex->{w}) * 0.5 |
|
|
1391 | ); |
|
|
1392 | |
|
|
1393 | $self->{oy} = int ( |
|
|
1394 | $self->{valign} < 0 ? $self->{padding} |
|
|
1395 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
|
|
1396 | : ($self->{h} - $tex->{h}) * 0.5 |
|
|
1397 | ); |
|
|
1398 | |
|
|
1399 | $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 | } |
1400 | |
1371 | |
1401 | glDisable GL_TEXTURE_2D; |
1372 | glDisable GL_TEXTURE_2D; |
1402 | glDisable GL_BLEND; |
|
|
1403 | } |
1373 | } |
1404 | |
1374 | |
1405 | ############################################################################# |
1375 | ############################################################################# |
1406 | |
1376 | |
1407 | package CFClient::UI::EntryBase; |
1377 | package CFClient::UI::EntryBase; |
… | |
… | |
1442 | $self->{layout}->set_text ("$text "); |
1412 | $self->{layout}->set_text ("$text "); |
1443 | |
1413 | |
1444 | $self->emit (changed => $self->{text}); |
1414 | $self->emit (changed => $self->{text}); |
1445 | } |
1415 | } |
1446 | |
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 | |
1447 | sub get_text { |
1426 | sub get_text { |
1448 | $_[0]{text} |
1427 | $_[0]{text} |
1449 | } |
1428 | } |
1450 | |
1429 | |
1451 | sub size_request { |
1430 | sub size_request { |
… | |
… | |
1458 | |
1437 | |
1459 | sub size_allocate { |
1438 | sub size_allocate { |
1460 | my ($self, $w, $h) = @_; |
1439 | my ($self, $w, $h) = @_; |
1461 | |
1440 | |
1462 | $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 |
1463 | } |
|
|
1464 | |
|
|
1465 | sub set_text { |
|
|
1466 | my ($self, $text) = @_; |
|
|
1467 | |
|
|
1468 | $self->{cursor} = length $text; |
|
|
1469 | $self->_set_text ($text); |
|
|
1470 | $self->update; |
|
|
1471 | } |
1442 | } |
1472 | |
1443 | |
1473 | sub key_down { |
1444 | sub key_down { |
1474 | my ($self, $ev) = @_; |
1445 | my ($self, $ev) = @_; |
1475 | |
1446 | |
… | |
… | |
1663 | |
1634 | |
1664 | if ($GRAB == $self) { |
1635 | if ($GRAB == $self) { |
1665 | $self->{fg} = $self->{active_fg}; |
1636 | $self->{fg} = $self->{active_fg}; |
1666 | } |
1637 | } |
1667 | |
1638 | |
1668 | glEnable GL_BLEND; |
|
|
1669 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1670 | glEnable GL_TEXTURE_2D; |
1639 | glEnable GL_TEXTURE_2D; |
1671 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1640 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1672 | glColor 0, 0, 0, 1; |
1641 | glColor 0, 0, 0, 1; |
1673 | |
1642 | |
1674 | $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h}); |
1643 | $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
1675 | |
1644 | |
1676 | glDisable GL_TEXTURE_2D; |
1645 | glDisable GL_TEXTURE_2D; |
1677 | glDisable GL_BLEND; |
|
|
1678 | |
1646 | |
1679 | $self->SUPER::_draw; |
1647 | $self->SUPER::_draw; |
1680 | } |
1648 | } |
1681 | |
1649 | |
1682 | ############################################################################# |
1650 | ############################################################################# |
… | |
… | |
1729 | |
1697 | |
1730 | 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; |
1731 | |
1699 | |
1732 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1700 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1733 | |
1701 | |
1734 | glEnable GL_BLEND; |
1702 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
|
|
1703 | |
1735 | glEnable GL_TEXTURE_2D; |
1704 | glEnable GL_TEXTURE_2D; |
1736 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1737 | |
|
|
1738 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
|
|
1739 | |
|
|
1740 | $tex->draw_quad (0, 0, $s, $s); |
1705 | $tex->draw_quad_alpha (0, 0, $s, $s); |
1741 | |
|
|
1742 | glDisable GL_TEXTURE_2D; |
1706 | glDisable GL_TEXTURE_2D; |
1743 | glDisable GL_BLEND; |
|
|
1744 | } |
1707 | } |
1745 | |
1708 | |
1746 | ############################################################################# |
1709 | ############################################################################# |
1747 | |
1710 | |
1748 | package CFClient::UI::Image; |
1711 | package CFClient::UI::Image; |
… | |
… | |
1791 | glTranslate 0, -$self->{w}, 0; |
1754 | glTranslate 0, -$self->{w}, 0; |
1792 | |
1755 | |
1793 | ($w, $h) = ($h, $w); |
1756 | ($w, $h) = ($h, $w); |
1794 | } |
1757 | } |
1795 | |
1758 | |
1796 | glEnable GL_BLEND; |
|
|
1797 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1798 | glEnable GL_TEXTURE_2D; |
1759 | glEnable GL_TEXTURE_2D; |
1799 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1760 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1800 | |
1761 | |
1801 | $tex->draw_quad (0, 0, $w, $h); |
1762 | $tex->draw_quad_alpha (0, 0, $w, $h); |
1802 | |
1763 | |
1803 | glDisable GL_BLEND; |
|
|
1804 | glDisable GL_TEXTURE_2D; |
1764 | glDisable GL_TEXTURE_2D; |
1805 | } |
1765 | } |
1806 | |
1766 | |
1807 | ############################################################################# |
1767 | ############################################################################# |
1808 | |
1768 | |
… | |
… | |
2100 | $page ||= 2; |
2060 | $page ||= 2; |
2101 | |
2061 | |
2102 | my $knob_a = $inner_pad_px + ($value - $page * 0.5); |
2062 | my $knob_a = $inner_pad_px + ($value - $page * 0.5); |
2103 | my $knob_b = $inner_pad_px + ($value + $page * 0.5); |
2063 | my $knob_b = $inner_pad_px + ($value + $page * 0.5); |
2104 | |
2064 | |
2105 | glEnable GL_BLEND; |
|
|
2106 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2107 | glEnable GL_TEXTURE_2D; |
2065 | glEnable GL_TEXTURE_2D; |
2108 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2066 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2109 | |
2067 | |
2110 | # draw background |
2068 | # draw background |
2111 | $tex[1]->draw_quad (0, 0, $w, $h); |
2069 | $tex[1]->draw_quad_alpha (0, 0, $w, $h); |
2112 | |
2070 | |
2113 | # draw handle |
2071 | # draw handle |
2114 | $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); |
2115 | |
2073 | |
2116 | glDisable GL_BLEND; |
|
|
2117 | glDisable GL_TEXTURE_2D; |
2074 | glDisable GL_TEXTURE_2D; |
2118 | } |
2075 | } |
2119 | |
2076 | |
2120 | ############################################################################# |
2077 | ############################################################################# |
2121 | |
2078 | |
… | |
… | |
2132 | fontsize => 1, |
2089 | fontsize => 1, |
2133 | can_events => 0, |
2090 | can_events => 0, |
2134 | #font => default_font |
2091 | #font => default_font |
2135 | @_, |
2092 | @_, |
2136 | |
2093 | |
2137 | layout => (new CFClient::Layout), |
2094 | layout => (new CFClient::Layout 1), |
2138 | par => [], |
2095 | par => [], |
2139 | height => 0, |
2096 | height => 0, |
2140 | children => [ |
2097 | children => [ |
2141 | (new CFClient::UI::Empty expand => 1), |
2098 | (new CFClient::UI::Empty expand => 1), |
2142 | (new CFClient::UI::Slider vertical => 1), |
2099 | (new CFClient::UI::Slider vertical => 1), |
… | |
… | |
2160 | |
2117 | |
2161 | my $layout = $self->{layout}; |
2118 | my $layout = $self->{layout}; |
2162 | |
2119 | |
2163 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2120 | $layout->set_height ($self->{fontsize} * $::FONTSIZE); |
2164 | $layout->set_width ($self->{children}[0]{w}); |
2121 | $layout->set_width ($self->{children}[0]{w}); |
2165 | $layout->set_text ($text); |
2122 | $layout->set_markup ($text); |
2166 | |
2123 | |
2167 | ($layout->size)[1] |
2124 | ($layout->size)[1] |
2168 | } |
2125 | } |
2169 | |
2126 | |
2170 | sub reflow { |
2127 | sub reflow { |
… | |
… | |
2226 | |
2183 | |
2227 | $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 { |
2228 | glClearColor 0, 0, 0, 0; |
2185 | glClearColor 0, 0, 0, 0; |
2229 | glClear GL_COLOR_BUFFER_BIT; |
2186 | glClear GL_COLOR_BUFFER_BIT; |
2230 | |
2187 | |
2231 | glEnable GL_BLEND; |
|
|
2232 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2233 | glEnable GL_TEXTURE_2D; |
2188 | glEnable GL_TEXTURE_2D; |
2234 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2189 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2235 | |
2190 | |
2236 | my $top = int $self->{children}[1]{range}[0]; |
2191 | my $top = int $self->{children}[1]{range}[0]; |
2237 | |
2192 | |
… | |
… | |
2246 | |
2201 | |
2247 | for my $par (@{$self->{par}}) { |
2202 | for my $par (@{$self->{par}}) { |
2248 | my $h = $par->[0]; |
2203 | my $h = $par->[0]; |
2249 | |
2204 | |
2250 | if ($y0 < $y + $h && $y < $y1) { |
2205 | if ($y0 < $y + $h && $y < $y1) { |
|
|
2206 | $layout->set_foreground (@{ $par->[1] }); |
2251 | $layout->set_text ($par->[2]); |
2207 | $layout->set_markup ($par->[2]); |
2252 | |
2208 | |
2253 | glColor @{ $par->[1] }; |
|
|
2254 | my ($W, $H) = $layout->size; |
2209 | my ($W, $H) = $layout->size; |
2255 | 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); |
2256 | } |
2211 | } |
2257 | |
2212 | |
2258 | $y += $h; |
2213 | $y += $h; |
2259 | } |
2214 | } |
2260 | |
2215 | |
2261 | glDisable GL_TEXTURE_2D; |
2216 | glDisable GL_TEXTURE_2D; |
2262 | glDisable GL_BLEND; |
|
|
2263 | }; |
2217 | }; |
2264 | }); |
2218 | }); |
2265 | } |
2219 | } |
2266 | |
2220 | |
2267 | sub _draw { |
2221 | sub _draw { |
2268 | my ($self) = @_; |
2222 | my ($self) = @_; |
2269 | |
2223 | |
2270 | glEnable GL_BLEND; |
|
|
2271 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2272 | glEnable GL_TEXTURE_2D; |
2224 | glEnable GL_TEXTURE_2D; |
2273 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2225 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2274 | glColor 1, 1, 1, 1; |
2226 | glColor 1, 1, 1, 1; |
2275 | $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}); |
2276 | glDisable GL_TEXTURE_2D; |
2228 | glDisable GL_TEXTURE_2D; |
2277 | glDisable GL_BLEND; |
|
|
2278 | |
2229 | |
2279 | $self->{children}[1]->draw; |
2230 | $self->{children}[1]->draw; |
2280 | |
2231 | |
2281 | } |
2232 | } |
2282 | |
2233 | |
… | |
… | |
2376 | @_, |
2327 | @_, |
2377 | can_events => 0, |
2328 | can_events => 0, |
2378 | ) |
2329 | ) |
2379 | } |
2330 | } |
2380 | |
2331 | |
2381 | sub set_markup { |
2332 | sub set_tooltip_from { |
2382 | my ($self, $text) = @_; |
2333 | my ($self, $widget) = @_; |
2383 | |
2334 | |
2384 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; |
2335 | $self->add (new CFClient::UI::Label |
2385 | $self->{label}->set_markup ($text); |
2336 | markup => $widget->{tooltip}, |
2386 | $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 | ); |
2387 | } |
2342 | } |
2388 | |
2343 | |
2389 | sub size_request { |
2344 | sub size_request { |
2390 | my ($self) = @_; |
2345 | my ($self) = @_; |
2391 | |
|
|
2392 | $self->child->set_max_size ($::WIDTH * 0.3); |
|
|
2393 | |
2346 | |
2394 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
2347 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
2395 | |
2348 | |
2396 | ($w + 4, $h + 4) |
2349 | ($w + 4, $h + 4) |
2397 | } |
2350 | } |
… | |
… | |
2403 | } |
2356 | } |
2404 | |
2357 | |
2405 | sub _draw { |
2358 | sub _draw { |
2406 | my ($self) = @_; |
2359 | my ($self) = @_; |
2407 | |
2360 | |
2408 | glPushMatrix; |
|
|
2409 | glTranslate 0.375, 0.375; |
2361 | glTranslate 0.375, 0.375; |
2410 | |
2362 | |
2411 | my ($w, $h) = @$self{qw(w h)}; |
2363 | my ($w, $h) = @$self{qw(w h)}; |
2412 | |
2364 | |
2413 | glColor 1, 0.8, 0.4; |
2365 | glColor 1, 0.8, 0.4; |
… | |
… | |
2424 | glVertex 0 , $h; |
2376 | glVertex 0 , $h; |
2425 | glVertex $w, $h; |
2377 | glVertex $w, $h; |
2426 | glVertex $w, 0; |
2378 | glVertex $w, 0; |
2427 | glEnd; |
2379 | glEnd; |
2428 | |
2380 | |
2429 | glPopMatrix; |
2381 | glTranslate 2 - 0.375, 2 - 0.375; |
2430 | |
|
|
2431 | glTranslate 2, 2; |
|
|
2432 | $self->SUPER::_draw; |
2382 | $self->SUPER::_draw; |
2433 | } |
2383 | } |
2434 | |
2384 | |
2435 | ############################################################################# |
2385 | ############################################################################# |
2436 | |
2386 | |
… | |
… | |
2459 | return unless $::CONN;#d# manage and cache textures differently |
2409 | return unless $::CONN;#d# manage and cache textures differently |
2460 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2410 | my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; |
2461 | |
2411 | |
2462 | # TODO animation |
2412 | # TODO animation |
2463 | if ($tex) { |
2413 | if ($tex) { |
2464 | glEnable GL_BLEND; |
|
|
2465 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2466 | glEnable GL_TEXTURE_2D; |
2414 | glEnable GL_TEXTURE_2D; |
2467 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2415 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2468 | glColor 1, 1, 1, 1; |
2416 | glColor 1, 1, 1, 1; |
2469 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
2417 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2470 | glDisable GL_TEXTURE_2D; |
2418 | glDisable GL_TEXTURE_2D; |
2471 | glDisable GL_BLEND; |
|
|
2472 | } |
2419 | } |
2473 | } |
2420 | } |
2474 | |
2421 | |
2475 | ############################################################################# |
2422 | ############################################################################# |
2476 | |
2423 | |
… | |
… | |
2653 | } |
2600 | } |
2654 | } |
2601 | } |
2655 | |
2602 | |
2656 | ############################################################################# |
2603 | ############################################################################# |
2657 | |
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 | |
2658 | package CFClient::UI::Root; |
2692 | package CFClient::UI::Root; |
2659 | |
2693 | |
2660 | our @ISA = CFClient::UI::Container::; |
2694 | our @ISA = CFClient::UI::Container::; |
2661 | |
2695 | |
2662 | use CFClient::OpenGL; |
2696 | use CFClient::OpenGL; |
… | |
… | |
2772 | |
2806 | |
2773 | my ($w, $h) = $widget->{user_w} && $widget->{user_h} |
2807 | my ($w, $h) = $widget->{user_w} && $widget->{user_h} |
2774 | ? @$widget{qw(user_w user_h)} |
2808 | ? @$widget{qw(user_w user_h)} |
2775 | : $widget->size_request; |
2809 | : $widget->size_request; |
2776 | |
2810 | |
|
|
2811 | if (delete $widget->{force_alloc} |
2777 | if ($w != $widget->{req_w} || $h != $widget->{req_h}) { |
2812 | or $w != $widget->{req_w} or $h != $widget->{req_h}) { |
|
|
2813 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
|
|
2814 | |
2778 | $widget->{req_w} = $w; |
2815 | $widget->{req_w} = $w; |
2779 | $widget->{req_h} = $h; |
2816 | $widget->{req_h} = $h; |
2780 | |
2817 | |
2781 | $self->{size_alloc}{$widget} = [$widget, $widget->{w}, $widget->{h}]; |
2818 | $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h]; |
2782 | |
2819 | |
2783 | $widget->{parent}->check_size |
2820 | $widget->{parent}->check_size |
2784 | if $widget->{parent}; |
2821 | if $widget->{parent}; |
2785 | } |
2822 | } |
2786 | } |
2823 | } |
2787 | } |
2824 | } |
2788 | |
2825 | |
2789 | while ($self->{size_alloc}) { |
2826 | while ($self->{size_alloc}) { |
2790 | for (values %{delete $self->{size_alloc}}) { |
2827 | for (values %{delete $self->{size_alloc}}) { |
2791 | my ($widget, $w, $h) = @$_; |
2828 | my ($widget, $w, $h) = @$_; |
|
|
2829 | |
|
|
2830 | $w = 0 if $w < 0; |
|
|
2831 | $h = 0 if $h < 0; |
2792 | |
2832 | |
2793 | $widget->{w} = $w; |
2833 | $widget->{w} = $w; |
2794 | $widget->{h} = $h; |
2834 | $widget->{h} = $h; |
2795 | $widget->size_allocate ($w, $h); |
2835 | $widget->size_allocate ($w, $h); |
2796 | $widget->emit (size_allocate => $w, $h); |
2836 | $widget->emit (size_allocate => $w, $h); |