ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.98 by root, Fri Apr 14 02:06:22 2006 UTC vs.
Revision 1.108 by root, Fri Apr 14 23:32:29 2006 UTC

61 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); 61 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y);
62 62
63 if ($widget != $HOVER) { 63 if ($widget != $HOVER) {
64 my $hover = $HOVER; $HOVER = $widget; 64 my $hover = $HOVER; $HOVER = $widget;
65 65
66 $hover->update if $hover; 66 $hover->update if $hover && $hover->{can_hover};
67 $HOVER->update if $HOVER; 67 $HOVER->update if $HOVER && $HOVER->{can_hover};
68 } 68 }
69 69
70 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; 70 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER;
71} 71}
72 72
439} 439}
440 440
441sub render_chld { 441sub render_chld {
442 my ($self) = @_; 442 my ($self) = @_;
443 443
444 $self->{texture} = 444 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
445 CFClient::Texture->new_from_opengl ( 445 glClearColor 0, 0, 0, 1;
446 $self->{w}, $self->{h}, sub { $self->child->draw } 446 glClear GL_COLOR_BUFFER_BIT;
447 ); 447 $self->child->draw;
448 };
448} 449}
449 450
450sub size_allocate { 451sub size_allocate {
451 my ($self, $x, $y, $w, $h) = @_; 452 my ($self, $x, $y, $w, $h) = @_;
452 453
639 # TODO: repeat texture not scale 640 # TODO: repeat texture not scale
640 my $rep_x = $cw / $bg->{w}; 641 my $rep_x = $cw / $bg->{w};
641 my $rep_y = $ch / $bg->{h}; 642 my $rep_y = $ch / $bg->{h};
642 643
643 glColor @{ $self->{bg} }; 644 glColor @{ $self->{bg} };
645
646 $bg->{s} = $rep_x;
647 $bg->{t} = $rep_y;
648 $bg->{wrap_mode} = 1;
644 $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); 649 $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch);
645 650
646 glDisable GL_TEXTURE_2D; 651 glDisable GL_TEXTURE_2D;
647 glDisable GL_BLEND; 652 glDisable GL_BLEND;
648 653
727 my $col_expand = (sum @col_expand) || 1; 732 my $col_expand = (sum @col_expand) || 1;
728 733
729 # linearly scale sizes 734 # linearly scale sizes
730 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 735 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
731 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; 736 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
737
738 $_ = int $_ for @$ws; #TODO: avoid rounding problems
739 $_ = int $_ for @$hs; #TODO: avoid rounding problems
732 740
733 my $y; 741 my $y;
734 742
735 for my $r (0 .. $#{$self->{children}}) { 743 for my $r (0 .. $#{$self->{children}}) {
736 my $row = $self->{children}[$r] 744 my $row = $self->{children}[$r]
827 } 835 }
828 836
829 my $y = 0; 837 my $y = 0;
830 for (0 .. $#$children) { 838 for (0 .. $#$children) {
831 my $child = $children->[$_]; 839 my $child = $children->[$_];
832 my $h = $h[$_]; 840 my $h = int $h[$_];
833 $child->size_allocate ($y, 0, $h, $w); 841 $child->size_allocate ($y, 0, $h, $w);
834 842
835 $y += $h; 843 $y += $h;
836 } 844 }
837} 845}
881 } 889 }
882 890
883 my $y = 0; 891 my $y = 0;
884 for (0 .. $#$children) { 892 for (0 .. $#$children) {
885 my $child = $children->[$_]; 893 my $child = $children->[$_];
886 my $h = $h[$_]; 894 my $h = int $h[$_];
887 $child->size_allocate (0, $y, $w, $h); 895 $child->size_allocate (0, $y, $w, $h);
888 896
889 $y += $h; 897 $y += $h;
890 } 898 }
891} 899}
900 908
901sub new { 909sub new {
902 my ($class, %arg) = @_; 910 my ($class, %arg) = @_;
903 911
904 my $self = $class->SUPER::new ( 912 my $self = $class->SUPER::new (
905 fg => [1, 1, 1], 913 fg => [1, 1, 1],
906 height => $::FONTSIZE, 914 fontsize => $::FONTSIZE,
907 text => "", 915 text => "",
908 align => -1, 916 align => -1,
909 padding => 2, 917 padding => 2,
910 layout => new CFClient::Layout, 918 layout => new CFClient::Layout,
911 %arg 919 %arg
912 ); 920 );
913 921
914 $self->set_text ($self->{text}); 922 $self->set_text ($self->{text});
915 923
945 953
946sub size_request { 954sub size_request {
947 my ($self) = @_; 955 my ($self) = @_;
948 956
949 $self->{layout}->set_width; 957 $self->{layout}->set_width;
950 $self->{layout}->set_height ($self->{height}); 958 $self->{layout}->set_height ($self->{fontsize});
951 my ($w, $h) = $self->{layout}->size; 959 my ($w, $h) = $self->{layout}->size;
952 960
953 ( 961 (
954 $w + $self->{padding} * 2, 962 $w + $self->{padding} * 2,
955 $h + $self->{padding} * 2, 963 $h + $self->{padding} * 2,
974sub _draw { 982sub _draw {
975 my ($self) = @_; 983 my ($self) = @_;
976 984
977 my $tex = $self->{texture} ||= do { 985 my $tex = $self->{texture} ||= do {
978 $self->{layout}->set_width ($self->{w}); 986 $self->{layout}->set_width ($self->{w});
979 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); 987 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize});
980 new_from_layout CFClient::Texture $self->{layout} 988 new_from_layout CFClient::Texture $self->{layout}
981 }; 989 };
982 990
983 glEnable GL_BLEND; 991 glEnable GL_BLEND;
984 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 992 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
985 glEnable GL_TEXTURE_2D; 993 glEnable GL_TEXTURE_2D;
986 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 994 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
987 995
988 glColor @{$self->{fg}}; 996 glColor @{$self->{fg}};
989 997
990 my $x = 998 my $x =
991 $self->{align} < 0 ? $self->{padding} 999 $self->{align} < 0 ? $self->{padding}
992 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1000 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
993 : ($self->{w} - $tex->{w}) * 0.5; 1001 : ($self->{w} - $tex->{w}) * 0.5;
994 1002
995 glTranslate int $x, int +($self->{h} - $tex->{h}) * 0.5, 0; 1003 $tex->draw_quad (int $x, int +($self->{h} - $tex->{h}) * 0.5);
996 $tex->draw_quad (0, 0);
997 1004
998 glDisable GL_TEXTURE_2D; 1005 glDisable GL_TEXTURE_2D;
999 glDisable GL_BLEND; 1006 glDisable GL_BLEND;
1000} 1007}
1001 1008
1023} 1030}
1024 1031
1025sub _set_text { 1032sub _set_text {
1026 my ($self, $text) = @_; 1033 my ($self, $text) = @_;
1027 1034
1035 my $old_text = $self->{text};
1036
1028 $self->{last_activity} = $::NOW; 1037 $self->{last_activity} = $::NOW;
1029 1038
1030 $self->{text} = $text; 1039 $self->{text} = $text;
1031 $self->{layout}->set_width ($self->{w}); 1040 $self->{layout}->set_width ($self->{w});
1032 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); 1041 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize});
1033 1042
1034 $text =~ s/./*/g if $self->{hidden}; 1043 $text =~ s/./*/g if $self->{hidden};
1035 1044
1036 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1045 $self->{layout}->set_markup ($self->escape_text ($text) . " ");
1037 1046
1038 $text = substr $text, 0, $self->{cursor}; 1047 $text = substr $text, 0, $self->{cursor};
1039 utf8::encode $text; 1048 utf8::encode $text;
1040 1049
1041 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); 1050 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
1051
1052 $self->emit (changed => $self->{text}) # XXX: is this the right place to do this?
1053 if $old_text ne $self->{text};
1042} 1054}
1043 1055
1044sub size_request { 1056sub size_request {
1045 my ($self) = @_; 1057 my ($self) = @_;
1046 1058
1085 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1097 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1086 } elsif ($sym == SDLK_HOME) { 1098 } elsif ($sym == SDLK_HOME) {
1087 $self->{cursor} = 0; 1099 $self->{cursor} = 0;
1088 } elsif ($sym == SDLK_END) { 1100 } elsif ($sym == SDLK_END) {
1089 $self->{cursor} = length $text; 1101 $self->{cursor} = length $text;
1102 } elsif ($sym == SDLK_ESCAPE) {
1103 $self->emit ('escape');
1090 } elsif ($uni) { 1104 } elsif ($uni) {
1091 substr $text, $self->{cursor}++, 0, chr $uni; 1105 substr $text, $self->{cursor}++, 0, chr $uni;
1092 } 1106 }
1093 1107
1094 $self->_set_text ($text); 1108 $self->_set_text ($text);
1156 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; 1170 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h};
1157 glEnd; 1171 glEnd;
1158 } 1172 }
1159} 1173}
1160 1174
1175package CFClient::UI::LineEntry;
1176
1177our @ISA = CFClient::UI::Entry::;
1178
1179use SDL;
1180use SDL::OpenGL;
1181
1182sub key_down {
1183 my ($self, $ev) = @_;
1184
1185 my $sym = $ev->key_sym;
1186
1187 if ($sym == SDLK_RETURN) {
1188 $self->emit (activate => $self->get_text);
1189 $self->update;
1190
1191 } else {
1192 $self->SUPER::key_down ($ev);
1193 }
1194
1195}
1196
1161############################################################################# 1197#############################################################################
1162 1198
1163package CFClient::UI::Button; 1199package CFClient::UI::Button;
1164 1200
1165our @ISA = CFClient::UI::Label::; 1201our @ISA = CFClient::UI::Label::;
1222 1258
1223package CFClient::UI::CheckBox; 1259package CFClient::UI::CheckBox;
1224 1260
1225our @ISA = CFClient::UI::DrawBG::; 1261our @ISA = CFClient::UI::DrawBG::;
1226 1262
1263my @tex =
1264 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1265 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1266
1227use SDL; 1267use SDL;
1228use SDL::OpenGL; 1268use SDL::OpenGL;
1229 1269
1230sub new { 1270sub new {
1231 my $class = shift; 1271 my $class = shift;
1268 $self->SUPER::_draw; 1308 $self->SUPER::_draw;
1269 1309
1270 glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0; 1310 glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0;
1271 1311
1272 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; 1312 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2;
1273 1313
1274 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; 1314 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
1275 1315
1276 glBegin GL_LINE_LOOP; 1316 glEnable GL_BLEND;
1277 glVertex 0 , 0; 1317 glEnable GL_TEXTURE_2D;
1278 glVertex 0 , $s; 1318 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1279 glVertex $s, $s;
1280 glVertex $s, 0;
1281 glEnd;
1282 1319
1283 if ($self->{state}) { 1320 my $tex = $self->{state} ? $tex[1] : $tex[0];
1284 glBegin GL_LINES; 1321
1285 glVertex 0 , 0; 1322 $tex->draw_quad (0, 0, $s, $s);
1286 glVertex $s, $s; 1323
1287 glVertex $s, 0; 1324 glDisable GL_TEXTURE_2D;
1288 glVertex 0 , $s; 1325 glDisable GL_BLEND;
1289 glEnd;
1290 }
1291} 1326}
1292 1327
1293############################################################################# 1328#############################################################################
1294 1329
1295package CFClient::UI::Slider; 1330package CFClient::UI::Slider;
1297use strict; 1332use strict;
1298 1333
1299use SDL::OpenGL; 1334use SDL::OpenGL;
1300 1335
1301our @ISA = CFClient::UI::DrawBG::; 1336our @ISA = CFClient::UI::DrawBG::;
1337
1338my @tex =
1339 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1340 qw(s1_slider.png s1_slider_bg.png);
1302 1341
1303sub new { 1342sub new {
1304 my $class = shift; 1343 my $class = shift;
1305 1344
1306 # range [value, low, high, page] 1345 # range [value, low, high, page]
1314 range => [0, 0, 100, 10], 1353 range => [0, 0, 100, 10],
1315 req_w => 40, 1354 req_w => 40,
1316 req_h => 13, 1355 req_h => 13,
1317 vertical => 0, 1356 vertical => 0,
1318 can_hover => 1, 1357 can_hover => 1,
1358 inner_pad => 5,
1319 @_ 1359 @_
1320 ); 1360 );
1321 1361
1322 $self 1362 $self
1323} 1363}
1344 if ($GRAB == $self) { 1384 if ($GRAB == $self) {
1345 my ($value, $lo, $hi, $page) = @{$self->{range}}; 1385 my ($value, $lo, $hi, $page) = @{$self->{range}};
1346 1386
1347 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); 1387 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w});
1348 1388
1389 my $inner_pad_px = $self->_calc_inner_pad_px ($w);
1390 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
1391
1392 $x -= $inner_pad_px; # substract the padding
1349 $x = $x * ($hi - $lo) / $w + $lo; 1393 $x = $x * ($hi - $lo) / $inner_w + $lo;
1350 $x = $lo if $x < $lo; 1394 $x = $lo if $x < $lo;
1351 $x = $hi - $page if $x > $hi - $page; 1395 $x = $hi - $page if $x > $hi - $page;
1352 $self->{range}[0] = $x; 1396 $self->{range}[0] = $x;
1353 1397
1354 $self->emit (changed => $x); 1398 $self->emit (changed => $x);
1355 $self->update; 1399 $self->update;
1356 } 1400 }
1401}
1402
1403# the inner_* stuff is for generating a padding for the slider handle,
1404# so that the handle doesn't leave the texture. This calculation isn't 100%
1405# correct propably, but it does the job for now
1406sub _calc_inner_pad_px {
1407 my ($self, $w) = @_;
1408 ($w / 100) * $self->{inner_pad} # % to pixels
1357} 1409}
1358 1410
1359sub _draw { 1411sub _draw {
1360 my ($self) = @_; 1412 my ($self) = @_;
1361 1413
1375 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 1427 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
1376 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 1428 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
1377 1429
1378 my ($value, $lo, $hi, $page) = @{$self->{range}}; 1430 my ($value, $lo, $hi, $page) = @{$self->{range}};
1379 1431
1432 $hi = $value + 1 if $lo == $hi;
1433
1434 my $inner_pad_px = $self->_calc_inner_pad_px ($w);
1435 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
1436
1380 $page = int $page * $w / ($hi - $lo); 1437 $page = int $page * $inner_w / ($hi - $lo);
1381 $value = int +($value - $lo) * $w / ($hi - $lo); 1438 $value = int +($value - $lo) * $inner_w / ($hi - $lo);
1382 1439
1383 $w -= $page; 1440 $w -= $page;
1384 $page &= ~1; 1441 $page &= ~1;
1385 glTranslate $page * 0.5, 0, 0; 1442 glTranslate $page * 0.5, 0, 0;
1386 $page ||= 2; 1443 $page ||= 2;
1387 1444
1388 glColor @$fg;
1389 glBegin GL_LINES;
1390 glVertex 0, 0; glVertex 0, $h;
1391 glVertex $w - 1, 0; glVertex $w - 1, $h;
1392 glVertex 0, $h * 0.5; glVertex $w, $h * 0.5;
1393 glEnd;
1394
1395 my $knob_a = $value - $page * 0.5; 1445 my $knob_a = $inner_pad_px + ($value - $page * 0.5);
1396 my $knob_b = $value + $page * 0.5; 1446 my $knob_b = $inner_pad_px + ($value + $page * 0.5);
1397 1447
1398 glBegin GL_QUADS; 1448 glEnable GL_BLEND;
1399 glColor @$fg; 1449 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1400 glVertex $knob_a, 0; 1450 glEnable GL_TEXTURE_2D;
1401 glVertex $knob_a, $h; 1451 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1402 glVertex $knob_b, $h;
1403 glVertex $knob_b, 0;
1404 1452
1405 if ($knob_a < $knob_b - 2) { 1453 # draw background
1406 glColor @$bg; 1454 $tex[1]->draw_quad (0, 0, $w, $h);
1407 glVertex $knob_a + 1, 1; 1455
1408 glVertex $knob_a + 1, $h - 1; 1456 # draw handle
1409 glVertex $knob_b - 1, $h - 1; 1457 $tex[0]->draw_quad ($knob_a, 0, $knob_b - $knob_a, $h);
1410 glVertex $knob_b - 1, 1; 1458
1411 } 1459 glDisable GL_BLEND;
1412 glEnd; 1460 glDisable GL_TEXTURE_2D;
1413} 1461}
1414 1462
1415############################################################################# 1463#############################################################################
1416 1464
1417package CFClient::UI::TextView; 1465package CFClient::UI::TextView;
1422 1470
1423sub new { 1471sub new {
1424 my $class = shift; 1472 my $class = shift;
1425 1473
1426 my $self = $class->SUPER::new ( 1474 my $self = $class->SUPER::new (
1475 req_w => $::WIDTH / 6,
1476 req_h => $::HEIGHT / 6,
1477 fontsize => $::FONTSIZE,
1478 @_,
1479
1480 layout => (new CFClient::Layout),
1427 par => [], 1481 par => [],
1428 @_, 1482 height => 0,
1429 children => [ 1483 children => [
1430 (new CFClient::UI::Empty expand => 1), 1484 (new CFClient::UI::Empty expand => 1),
1431 (new CFClient::UI::Slider vertical => 1), 1485 (new CFClient::UI::Slider vertical => 1),
1432 ], 1486 ],
1433 ); 1487 );
1434 1488
1489 $self->{children}[1]->connect (changed => sub {
1490 $self->update;
1491 });
1492
1435 $self 1493 $self
1494}
1495
1496sub set_fontsize {
1497 my ($self, $fontsize) = @_;
1498
1499 $self->{fontsize} = $fontsize;
1500 $self->reflow;
1501}
1502
1503sub text_height {
1504 my ($self, $text) = @_;
1505
1506 my $layout = $self->{layout};
1507
1508 $layout->set_height ($self->{fontsize});
1509 $layout->set_width ($self->{w});
1510 $layout->set_text ($text);
1511
1512 ($layout->size)[1]
1513}
1514
1515sub reflow {
1516 my ($self) = @_;
1517
1518 $self->{need_reflow}++;
1519 $self->update;
1520}
1521
1522sub size_request {
1523 my ($self) = @_;
1524
1525 ($self->{req_w}, $self->{req_h})
1526}
1527
1528sub size_allocate {
1529 my ($self, $x, $y, $w, $h) = @_;
1530
1531 $self->SUPER::size_allocate ($x, $y, $w, $h);
1532
1533 $self->{layout}->set_height ($self->{fontsize});
1534 $self->{layout}->set_width ($self->{w});
1535
1536 $self->reflow;
1436} 1537}
1437 1538
1438sub add_paragraph { 1539sub add_paragraph {
1439 my ($self, $color, $text) = @_; 1540 my ($self, $color, $text) = @_;
1440 1541
1542 #TODO: intelligently "reformat" paragraph
1543
1544 my $height = $self->text_height ($text);
1545
1546 $self->{height} += $height;
1547
1441 push @{$self->{par}}, [$color, $text]; 1548 push @{$self->{par}}, [$height, $color, $text];
1442 my $count = scalar @{$self->{par}}; 1549
1443 $self->{children}[1]{range} = [$count - 1, 0, $count, 1]; 1550 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}];
1444 $self->{children}[1]->update; 1551 $self->{children}[1]->update;
1445} 1552}
1446 1553
1554sub update {
1555 my ($self) = @_;
1556
1557 $self->SUPER::update;
1558
1559 return unless $self->{h} > 0;
1560
1561 delete $self->{texture};
1562
1563 $TOPLEVEL->on_refresh ($self, sub {
1564 if (delete $self->{need_reflow}) {
1565 my $height = 0;
1566
1567 $height += $_->[0] = $self->text_height ($_->[2])
1568 for @{$self->{par}};
1569
1570 $self->{height} = $height;
1571
1572 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
1573
1574 delete $self->{texture};
1575 }
1576
1577 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
1578 glClearColor 0, 0, 0, 1;
1579 glClear GL_COLOR_BUFFER_BIT;
1580
1581 glEnable GL_BLEND;
1582 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1583 glEnable GL_TEXTURE_2D;
1584 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1585
1586 my $top = int $self->{children}[1]{range}[0];
1587
1588 my $y0 = $top;
1589 my $y1 = $top + $self->{h};
1590
1591 my $y = 0;
1592
1593 my $layout = $self->{layout};
1594
1595 for my $par (@{$self->{par}}) {
1596 my $h = $par->[0];
1597
1598 if ($y0 < $y + $h && $y < $y1) {
1599 $layout->set_text ($par->[2]);
1600
1601 glColor @{ $par->[1] };
1602 my ($W, $H) = $layout->size;
1603 CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0);
1604 }
1605
1606 $y += $h;
1607 }
1608
1609 glDisable GL_TEXTURE_2D;
1610 glDisable GL_BLEND;
1611 };
1612 });
1613}
1614
1447sub _draw { 1615sub _draw {
1448 my ($self) = @_; 1616 my ($self) = @_;
1449 1617
1450 my $par = $self->{par}; 1618 if ($self->{texture}) {
1451
1452 my $bottom = (scalar @$par) - 1;
1453
1454 my $w = $self->{children}[0]{w};
1455 my $y = $self->{h};
1456
1457 glEnable GL_BLEND;
1458 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1459 glEnable GL_TEXTURE_2D; 1619 glEnable GL_TEXTURE_2D;
1460 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1620 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1461 1621 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h});
1462 # TODO: everything!
1463 while ($y > 0 && $bottom >= 0) {
1464 my $par = $par->[$bottom--];
1465
1466 my $layout = new CFClient::Layout;
1467
1468 $layout->set_height ($::FONTSIZE);
1469 $layout->set_width ($w);
1470 $layout->set_text ($par->[1]);
1471 my $tex = new_from_layout CFClient::Texture $layout;
1472 $y -= $tex->{h};
1473
1474 glColor @{ $par->[0] };
1475 $tex->draw_quad (0, $y);
1476 }
1477
1478 glDisable GL_TEXTURE_2D; 1622 glDisable GL_TEXTURE_2D;
1479 glDisable GL_BLEND; 1623 }
1624
1625 $self->{children}[1]->draw;
1626
1480} 1627}
1481 1628
1482############################################################################# 1629#############################################################################
1483 1630
1484package CFClient::UI::MapWidget; 1631package CFClient::UI::MapWidget;
1508} 1655}
1509 1656
1510sub key_up { 1657sub key_up {
1511} 1658}
1512 1659
1660sub button_down {
1661 my ($self, $ev, $x, $y) = @_;
1662
1663 $self->focus_in;
1664
1665 if ($ev->button == 2) {
1666 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
1667 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
1668
1669 $self->{motion} = sub {
1670 my ($ev, $x, $y) = @_;
1671
1672 ($x, $y) = ($ev->motion_x, $ev->motion_y);
1673
1674 $::CFG->{map_shift_x} = $bw + $x - $ox;
1675 $::CFG->{map_shift_y} = $bh + $y - $oy;
1676
1677 $self->update;
1678 };
1679 }
1680}
1681
1682sub button_up {
1683 my ($self, $ev, $x, $y) = @_;
1684
1685 delete $self->{motion};
1686}
1687
1688sub mouse_motion {
1689 my ($self, $ev, $x, $y) = @_;
1690
1691 $self->{motion}->($ev, $x, $y) if $self->{motion};
1692}
1693
1513sub size_request { 1694sub size_request {
1514 ( 1695 (
1515 1 + 32 * int $::WIDTH / 32, 1696 1 + 32 * int $::WIDTH / 32,
1516 1 + 32 * int $::HEIGHT / 32, 1697 1 + 32 * int $::HEIGHT / 32,
1517 ) 1698 )
1525} 1706}
1526 1707
1527sub draw { 1708sub draw {
1528 my ($self) = @_; 1709 my ($self) = @_;
1529 1710
1530 $self->{need_update}++;#d#
1531 if (delete $self->{need_update}) { 1711 if (delete $self->{need_update}) {
1532 glNewList $self->{list}, GL_COMPILE; 1712 glNewList $self->{list}, GL_COMPILE;
1533 1713
1534 my $sw = int $::WIDTH / 32; 1714 my $sw = int $::WIDTH / 32;
1535 my $sh = int $::HEIGHT / 32; 1715 my $sh = int $::HEIGHT / 32;
1536 1716
1537 if ($::MAP) { 1717 if ($::MAP) {
1718 my $sx = $::CFG->{map_shift_x};
1719 my $sy = $::CFG->{map_shift_y};
1720
1721 glTranslate +($sx & 31) - 32, ($sy & 31) - 32, 0;
1722
1538 my ($w, $h, $data) = $::MAP->draw (0, 0, $sw, $sh); 1723 my ($w, $h, $data) = $::MAP->draw ($sx >> 5, $sy >> 5, 0, 0, $sw + 1, $sh + 1);
1539 1724
1540 if ($::CFG->{fow_enable}) { 1725 if ($::CFG->{fow_enable}) {
1541 if ($::CFG->{fow_smooth}) { # smooth fog of war 1726 if ($::CFG->{fow_smooth}) { # smooth fog of war
1542 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; 1727 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER;
1543 glConvolutionFilter2D 1728 glConvolutionFilter2D
1575 } 1760 }
1576 1761
1577 glEndList; 1762 glEndList;
1578 } 1763 }
1579 1764
1765 glPushMatrix;
1580 glCallList $self->{list}; 1766 glCallList $self->{list};
1767 glPopMatrix;
1581 1768
1582 if ($FOCUS != $self) { 1769 if ($FOCUS != $self) {
1583 glColor 64/255, 64/255, 64/255; 1770 glColor 64/255, 64/255, 64/255;
1584 glLogicOp GL_AND; 1771 glLogicOp GL_AND;
1585 glEnable GL_COLOR_LOGIC_OP; 1772 glEnable GL_COLOR_LOGIC_OP;
1617 1804
1618 if ($sym == SDLK_KP5) { 1805 if ($sym == SDLK_KP5) {
1619 $::CONN->user_send ("command stay fire"); 1806 $::CONN->user_send ("command stay fire");
1620 } elsif ($sym == SDLK_a) { 1807 } elsif ($sym == SDLK_a) {
1621 $::CONN->user_send ("command apply"); 1808 $::CONN->user_send ("command apply");
1809 } elsif ($sym == SDLK_QUOTE) {
1810 $self->emit ('activate_console');
1811 } elsif ($sym == SDLK_SLASH) {
1812 $self->emit ('activate_console' => '/');
1622 } elsif (exists $DIR{$sym}) { 1813 } elsif (exists $DIR{$sym}) {
1623 if ($mod & KMOD_SHIFT) { 1814 if ($mod & KMOD_SHIFT) {
1624 $self->{shft}++; 1815 $self->{shft}++;
1625 $::CONN->user_send ("command fire $DIR{$sym}[0]"); 1816 $::CONN->user_send ("command fire $DIR{$sym}[0]");
1626 } elsif ($mod & KMOD_CTRL) { 1817 } elsif ($mod & KMOD_CTRL) {
1730 1921
1731package CFClient::UI::Toplevel; 1922package CFClient::UI::Toplevel;
1732 1923
1733our @ISA = CFClient::UI::Container::; 1924our @ISA = CFClient::UI::Container::;
1734 1925
1926use SDL::OpenGL;
1927
1735sub size_request { 1928sub size_request {
1736 ($::WIDTH, $::HEIGHT) 1929 ($::WIDTH, $::HEIGHT)
1737} 1930}
1738 1931
1739sub size_allocate { 1932sub size_allocate {
1764 $self->SUPER::add ($widget); 1957 $self->SUPER::add ($widget);
1765 1958
1766 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); 1959 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request);
1767} 1960}
1768 1961
1962sub on_refresh {
1963 my ($self, $id, $cb) = @_;
1964
1965 $self->{refresh_hook}{$id} = $cb;
1966}
1967
1769sub draw { 1968sub draw {
1770 my ($self) = @_; 1969 my ($self) = @_;
1771 1970
1971 while (my $rcb = delete $self->{refresh_hook}) {
1972 $_->() for values %$rcb;
1973 }
1974
1975 glViewport 0, 0, $::WIDTH, $::HEIGHT;
1976 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
1977 glClear GL_COLOR_BUFFER_BIT;
1978
1979 glMatrixMode GL_PROJECTION;
1980 glLoadIdentity;
1981 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000;
1982 glMatrixMode GL_MODELVIEW;
1983 glLoadIdentity;
1984
1772 $self->_draw; 1985 $self->_draw;
1773} 1986}
1774 1987
1775############################################################################# 1988#############################################################################
1776 1989

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines