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.121 by root, Mon Apr 17 19:21:00 2006 UTC vs.
Revision 1.133 by root, Tue Apr 18 21:39:31 2006 UTC

112 $self 112 $self
113} 113}
114 114
115sub move { 115sub move {
116 my ($self, $x, $y, $z) = @_; 116 my ($self, $x, $y, $z) = @_;
117
117 $self->{x} = int $x; 118 $self->{x} = int $x;
118 $self->{y} = int $y; 119 $self->{y} = int $y;
119 $self->{z} = $z if defined $z; 120 $self->{z} = $z if defined $z;
121
122 $self->update;
120} 123}
121 124
122sub needs_redraw { 125sub needs_redraw {
123 0 126 0
124} 127}
126sub size_request { 129sub size_request {
127 require Carp; 130 require Carp;
128 Carp::confess "size_request is abtract"; 131 Carp::confess "size_request is abtract";
129} 132}
130 133
131sub _size_allocate { 134sub configure {
132 my ($self, $x, $y, $w, $h) = @_; 135 my ($self, $x, $y, $w, $h) = @_;
133 136
134 $self->{x} = $x; 137 $self->{x} = $x;
135 $self->{y} = $y; 138 $self->{y} = $y;
136 139
137 return unless $self->{w} != $w || $self->{h} != $h; 140 return unless $self->{w} != $w || $self->{h} != $h;
138 141
139 $self->{w} = $w; 142 $self->{w} = $w;
140 $self->{h} = $h; 143 $self->{h} = $h;
141 144
142 1 145 $self->size_allocate ($w, $h);
143} 146}
144 147
145sub size_allocate { 148sub size_allocate {
146 my ($self, $x, $y, $w, $h) = @_; 149 # nothing to be done
147
148 $self->_size_allocate ($x, $y, $w, $h);
149} 150}
150 151
151# return top left coordinates 152# return top left coordinates
152sub _topleft { 153sub _topleft {
153 my ($self, $x, $y) = @_; 154 my ($self, $x, $y) = @_;
225 glPopMatrix; 226 glPopMatrix;
226 227
227 if ($self == $HOVER && $self->{can_hover}) { 228 if ($self == $HOVER && $self->{can_hover}) {
228 my ($x, $y) = @$self{qw(x y)}; 229 my ($x, $y) = @$self{qw(x y)};
229 230
230 glColor 0, 0, 1, 0.2; 231 glColor 1, 0.8, 0.5, 0.2;
231 glEnable GL_BLEND; 232 glEnable GL_BLEND;
232 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 233 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
233 glBegin GL_QUADS; 234 glBegin GL_QUADS;
234 glVertex $x , $y; 235 glVertex $x , $y;
235 glVertex $x + $self->{w}, $y; 236 glVertex $x + $self->{w}, $y;
260 my ($self, $parent) = @_; 261 my ($self, $parent) = @_;
261 262
262 Scalar::Util::weaken ($self->{parent} = $parent); 263 Scalar::Util::weaken ($self->{parent} = $parent);
263} 264}
264 265
266sub check_size {
267 my ($self) = @_;
268
269 my ($w, $h) = $self->size_request;
270
271 if ($w != $self->{req_w} || $h != $self->{req_h}) {
272 $self->{req_w} = $w;
273 $self->{req_h} = $h;
274
275 $self->{parent}->check_size
276 if $self->{parent};
277
278 $self->size_allocate ($w, $h);
279 $self->update;
280 }
281}
282
265sub update { 283sub update {
266 my ($self) = @_; 284 my ($self) = @_;
267 285
268 $self->{parent}->update 286 $self->{parent}->update
269 if $self->{parent}; 287 if $self->{parent};
270} 288}
271 289
272sub connect { 290sub connect {
273 my ($self, $signal, $cb) = @_; 291 my ($self, $signal, $cb) = @_;
274 292
275 push @{ $self->{cb}{$signal} }, $cb; 293 push @{ $self->{signal_cb}{$signal} }, $cb;
276} 294}
277 295
278sub emit { 296sub emit {
279 my ($self, $signal, @args) = @_; 297 my ($self, $signal, @args) = @_;
280 298
299 for my $cb (@{$self->{signal_cb}{$signal} || []}) {
281 $_->($self, @args) 300 $cb->($self, @args);
282 for @{$self->{cb}{$signal} || []}; 301 }
283} 302}
284 303
285sub DESTROY { 304sub DESTROY {
286 my ($self) = @_; 305 my ($self) = @_;
287 306
368 sort { $a->{z} <=> $b->{z} } 387 sort { $a->{z} <=> $b->{z} }
369 @{$self->{children}}, $child 388 @{$self->{children}}, $child
370 ]; 389 ];
371 390
372 $self->{w} = $self->{h} = -1; 391 $self->{w} = $self->{h} = -1;
373 $self->update; 392
393 $child->check_size;
374} 394}
375 395
376sub remove { 396sub remove {
377 my ($self, $widget) = @_; 397 my ($self, $widget) = @_;
378 398
379 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 399 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ];
380 400
381 $self->size_allocate (0, 0, $self->{w}, $self->{h}); 401 $self->check_size;
382} 402}
383 403
384sub find_widget { 404sub find_widget {
385 my ($self, $x, $y) = @_; 405 my ($self, $x, $y) = @_;
386 406
439sub size_request { 459sub size_request {
440 $_[0]{children}[0]->size_request 460 $_[0]{children}[0]->size_request
441} 461}
442 462
443sub size_allocate { 463sub size_allocate {
444 my ($self, $x, $y, $w, $h) = @_; 464 my ($self, $w, $h) = @_;
445 465
446 $self->_size_allocate ($x, $y, $w, $h) or return;
447
448 $self->{children}[0]->size_allocate (0, 0, $w, $h); 466 $self->{children}[0]->configure (0, 0, $w, $h);
449} 467}
450 468
451############################################################################# 469#############################################################################
452 470
453package CFClient::UI::Window; 471package CFClient::UI::Window;
479 $self->child->draw; 497 $self->child->draw;
480 }; 498 };
481} 499}
482 500
483sub size_allocate { 501sub size_allocate {
484 my ($self, $x, $y, $w, $h) = @_; 502 my ($self, $w, $h) = @_;
485 503
486 $self->_size_allocate ($x, $y, $w, $h) or return;
487
488 $self->child->size_allocate (0, 0, $w, $h); 504 $self->child->configure (0, 0, $w, $h);
489 505
490 $self->render_chld; 506 $self->render_chld;
491} 507}
492 508
493sub _draw { 509sub _draw {
509 glDisable GL_TEXTURE_2D; 525 glDisable GL_TEXTURE_2D;
510} 526}
511 527
512############################################################################# 528#############################################################################
513 529
530package CFClient::UI::ViewPort;
531
532our @ISA = CFClient::UI::Window::;
533
534sub new { die }
535
536sub size_request {
537 my ($self) = @_;
538
539 @$self{qw(child_w child_h)} = $self->child->size_request;
540 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
541
542 @$self{qw(child_w child_h)}
543}
544
545sub _draw {
546 my ($self) = @_;
547
548 $self->{children}[1]->draw;
549}
550
551
552#############################################################################
553
514package CFClient::UI::Frame; 554package CFClient::UI::Frame;
515 555
516our @ISA = CFClient::UI::Bin::; 556our @ISA = CFClient::UI::Bin::;
517 557
518use SDL::OpenGL; 558use SDL::OpenGL;
528} 568}
529 569
530sub size_allocate { 570sub size_allocate {
531 my ($self, $x, $y, $w, $h) = @_; 571 my ($self, $x, $y, $w, $h) = @_;
532 572
533 $self->_size_allocate ($x, $y, $w, $h) or return;
534
535 $self->child->size_allocate (2, 2, $w - 4, $h - 4); 573 $self->child->configure (2, 2, $w - 4, $h - 4);
536} 574}
537 575
538sub _draw { 576sub _draw {
539 my ($self) = @_; 577 my ($self) = @_;
540 578
590 $h + $self->{border} * 2, 628 $h + $self->{border} * 2,
591 ) 629 )
592} 630}
593 631
594sub size_allocate { 632sub size_allocate {
595 my ($self, $x, $y, $w, $h) = @_; 633 my ($self, $w, $h) = @_;
596
597 $self->_size_allocate ($x, $y, $w, $h) or return;
598 634
599 $h -= List::Util::max 0, $self->{border} * 2; 635 $h -= List::Util::max 0, $self->{border} * 2;
600 $w -= List::Util::max 0, $self->{border} * 2; 636 $w -= List::Util::max 0, $self->{border} * 2;
601 637
602 $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); 638 $self->child->configure ($self->{border}, $self->{border}, $w, $h);
603} 639}
604 640
605sub button_down { 641sub button_down {
606 my ($self, $ev, $x, $y) = @_; 642 my ($self, $ev, $x, $y) = @_;
607 643
616 652
617 ($x, $y) = ($ev->motion_x, $ev->motion_y); 653 ($x, $y) = ($ev->motion_x, $ev->motion_y);
618 654
619 $self->{user_w} = $bw + $x - $ox; 655 $self->{user_w} = $bw + $x - $ox;
620 $self->{user_h} = $bh + $y - $oy; 656 $self->{user_h} = $bh + $y - $oy;
621 $self->update; 657 $self->check_size;
622 }; 658 };
623 659
624 } elsif ($x >= 0 && $x < $self->{w} 660 } elsif ($x >= 0 && $x < $self->{w}
625 && $y >= 0 && $y < $self->{border}) { 661 && $y >= 0 && $y < $self->{border}) {
626 662
710 746
711 $child->set_parent ($self); 747 $child->set_parent ($self);
712 $self->{children}[$y][$x] = $child; 748 $self->{children}[$y][$x] = $child;
713 749
714 $self->{w} = $self->{h} = -1; 750 $self->{w} = $self->{h} = -1;
715 $self->update; 751
752 $child->check_size;
716} 753}
717 754
718# TODO: move to container class maybe? send childs a signal on removal? 755# TODO: move to container class maybe? send childs a signal on removal?
719sub clear { 756sub clear {
720 my ($self) = @_; 757 my ($self) = @_;
755 (sum @$hs), 792 (sum @$hs),
756 ) 793 )
757} 794}
758 795
759sub size_allocate { 796sub size_allocate {
760 my ($self, $x, $y, $w, $h) = @_; 797 my ($self, $w, $h) = @_;
761
762 $self->_size_allocate ($x, $y, $w, $h) or return;
763 798
764 my ($ws, $hs) = $self->get_wh; 799 my ($ws, $hs) = $self->get_wh;
765 800
766 my $req_w = sum @$ws; 801 my $req_w = sum @$ws;
767 my $req_h = sum @$hs; 802 my $req_h = sum @$hs;
789 824
790 for my $c (0 .. $#$row) { 825 for my $c (0 .. $#$row) {
791 my $col_w = $ws->[$c]; 826 my $col_w = $ws->[$c];
792 827
793 if (my $widget = $row->[$c]) { 828 if (my $widget = $row->[$c]) {
794 $widget->size_allocate ($x, $y, $col_w, $row_h); 829 $widget->configure ($x, $y, $col_w, $row_h);
795 } 830 }
796 831
797 $x += $col_w; 832 $x += $col_w;
798 } 833 }
799 834
844 (List::Util::max map $_->[1], @alloc), 879 (List::Util::max map $_->[1], @alloc),
845 ) 880 )
846} 881}
847 882
848sub size_allocate { 883sub size_allocate {
849 my ($self, $x, $y, $w, $h) = @_; 884 my ($self, $w, $h) = @_;
850
851 $self->_size_allocate ($x, $y, $w, $h);
852 885
853 ($h, $w) = ($w, $h); 886 ($h, $w) = ($w, $h);
854 887
855 my $children = $self->{children}; 888 my $children = $self->{children};
856 889
878 911
879 my $y = 0; 912 my $y = 0;
880 for (0 .. $#$children) { 913 for (0 .. $#$children) {
881 my $child = $children->[$_]; 914 my $child = $children->[$_];
882 my $h = $h[$_]; 915 my $h = $h[$_];
883 $child->size_allocate ($y, 0, $h, $w); 916 $child->configure ($y, 0, $h, $w);
884 917
885 $y += $h; 918 $y += $h;
886 } 919 }
920
921 1
887} 922}
888 923
889############################################################################# 924#############################################################################
890 925
891package CFClient::UI::VBox; 926package CFClient::UI::VBox;
904 (List::Util::sum map $_->[1], @alloc), 939 (List::Util::sum map $_->[1], @alloc),
905 ) 940 )
906} 941}
907 942
908sub size_allocate { 943sub size_allocate {
909 my ($self, $x, $y, $w, $h) = @_; 944 my ($self, $w, $h) = @_;
910
911 $self->_size_allocate ($x, $y, $w, $h);
912 945
913 my $children = $self->{children}; 946 my $children = $self->{children};
914 947
915 my @h = map +($_->size_request)[1], @$children; 948 my @h = map +($_->size_request)[1], @$children;
916 949
934 967
935 my $y = 0; 968 my $y = 0;
936 for (0 .. $#$children) { 969 for (0 .. $#$children) {
937 my $child = $children->[$_]; 970 my $child = $children->[$_];
938 my $h = $h[$_]; 971 my $h = $h[$_];
939 $child->size_allocate (0, $y, $w, $h); 972 $child->configure (0, $y, $w, $h);
940 973
941 $y += $h; 974 $y += $h;
942 } 975 }
976
977 1
943} 978}
944 979
945############################################################################# 980#############################################################################
946 981
947package CFClient::UI::Label; 982package CFClient::UI::Label;
1013 $h + $self->{padding} * 2, 1048 $h + $self->{padding} * 2,
1014 ) 1049 )
1015} 1050}
1016 1051
1017sub size_allocate { 1052sub size_allocate {
1018 my ($self, $x, $y, $w, $h) = @_; 1053 my ($self, $w, $h) = @_;
1019
1020 $self->_size_allocate ($x, $y, $w, $h) or return;
1021 1054
1022 delete $self->{texture}; 1055 delete $self->{texture};
1023} 1056}
1024 1057
1025sub update { 1058sub update {
1043 glEnable GL_TEXTURE_2D; 1076 glEnable GL_TEXTURE_2D;
1044 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1077 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1045 1078
1046 glColor @{$self->{fg}}; 1079 glColor @{$self->{fg}};
1047 1080
1048 my $x = 1081 $self->{ox} = int (
1049 $self->{align} < 0 ? $self->{padding} 1082 $self->{align} < 0 ? $self->{padding}
1050 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1083 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1051 : ($self->{w} - $tex->{w}) * 0.5; 1084 : ($self->{w} - $tex->{w}) * 0.5
1085 );
1052 1086
1053 my $y = 1087 $self->{oy} = int (
1054 $self->{valign} < 0 ? $self->{padding} 1088 $self->{valign} < 0 ? $self->{padding}
1055 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} 1089 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1056 : ($self->{h} - $tex->{h}) * 0.5; 1090 : ($self->{h} - $tex->{h}) * 0.5
1091 );
1057 1092
1058 $tex->draw_quad (int $x, int $y); 1093 $tex->draw_quad ($self->{ox}, $self->{oy});
1059 1094
1060 glDisable GL_TEXTURE_2D; 1095 glDisable GL_TEXTURE_2D;
1061 glDisable GL_BLEND; 1096 glDisable GL_BLEND;
1062} 1097}
1063 1098
1112 1147
1113 ($w + 1, $h) # add 1 for cursor 1148 ($w + 1, $h) # add 1 for cursor
1114} 1149}
1115 1150
1116sub size_allocate { 1151sub size_allocate {
1117 my ($self, $x, $y, $w, $h) = @_; 1152 my ($self, $w, $h) = @_;
1118
1119 $self->SUPER::size_allocate ($x, $y, $w, $h);
1120 1153
1121 $self->_set_text ($self->{text}); 1154 $self->_set_text ($self->{text});
1122} 1155}
1123 1156
1124sub set_text { 1157sub set_text {
1224 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) 1257 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text)
1225 } 1258 }
1226 1259
1227 glColor @{$self->{fg}}; 1260 glColor @{$self->{fg}};
1228 glBegin GL_LINES; 1261 glBegin GL_LINES;
1229 glVertex $self->{cur_x}, $self->{cur_y};
1230 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; 1262 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy};
1263 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
1231 glEnd; 1264 glEnd;
1232 } 1265 }
1233} 1266}
1234 1267
1235package CFClient::UI::Entry; 1268package CFClient::UI::Entry;
1272 1305
1273 $class->SUPER::new ( 1306 $class->SUPER::new (
1274 padding => 4, 1307 padding => 4,
1275 fg => [1, 1, 1], 1308 fg => [1, 1, 1],
1276 bg => [1, 1, 1, 0.2], 1309 bg => [1, 1, 1, 0.2],
1277 active_fg => [1, 1, 0], 1310 active_fg => [0, 0, 1],
1278 can_hover => 1, 1311 can_hover => 1,
1312 align => 0,
1313 valign => 0,
1279 @_ 1314 @_
1280 ) 1315 )
1281} 1316}
1282 1317
1283sub button_up { 1318sub button_up {
1342 my ($self) = @_; 1377 my ($self) = @_;
1343 1378
1344 ($self->{padding} * 2 + 6) x 2 1379 ($self->{padding} * 2 + 6) x 2
1345} 1380}
1346 1381
1347sub size_allocate {
1348 my ($self, $x, $y, $w, $h) = @_;
1349
1350 $self->_size_allocate ($x, $y, $w, $h);
1351}
1352
1353sub button_down { 1382sub button_down {
1354 my ($self, $ev, $x, $y) = @_; 1383 my ($self, $ev, $x, $y) = @_;
1355 1384
1356 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} 1385 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding}
1357 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { 1386 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) {
1379 1408
1380 $tex->draw_quad (0, 0, $s, $s); 1409 $tex->draw_quad (0, 0, $s, $s);
1381 1410
1382 glDisable GL_TEXTURE_2D; 1411 glDisable GL_TEXTURE_2D;
1383 glDisable GL_BLEND; 1412 glDisable GL_BLEND;
1413}
1414
1415#############################################################################
1416
1417package CFClient::UI::VGauge;
1418
1419our @ISA = CFClient::UI::Base::;
1420
1421use SDL::OpenGL;
1422
1423my %tex = (
1424 food => [
1425 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1426 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1427 ],
1428 grace => [
1429 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1430 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1431 ],
1432 hp => [
1433 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1434 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1435 ],
1436 mana => [
1437 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1438 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1439 ],
1440);
1441
1442# eg. VGauge->new (gauge => 'food'), default gauge: food
1443sub new {
1444 my $class = shift;
1445
1446 my $self = $class->SUPER::new (gauge => 'food', @_);
1447
1448 $self
1449}
1450
1451sub size_request {
1452 my ($self) = @_;
1453
1454 my $tex = $tex{$self->{gauge}}[0];
1455
1456 @$tex{qw(w h)}
1457}
1458
1459sub set_max {
1460 my ($self, $max) = @_;
1461
1462 $self->{max_val} = $max;
1463}
1464
1465sub set_value {
1466 my ($self, $val, $max) = @_;
1467
1468 $self->set_max ($max)
1469 if defined $max;
1470
1471 $max = $self->{max_val};
1472 $self->{val} = $val;
1473
1474 $self->update;
1475}
1476
1477sub _draw {
1478 my ($self) = @_;
1479
1480 my $tex = $tex{$self->{gauge}};
1481
1482 my ($w, $h) = ($self->{w}, $self->{h});
1483
1484 my $ycut = $self->{val} / ($self->{max_val} || 1);
1485 $ycut = 1 if $self->{val} > $self->{max_val};
1486
1487 my $t1 = $tex->[0];
1488 my $t2 = $tex->[1];
1489
1490 glEnable GL_BLEND;
1491 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1492 glEnable GL_TEXTURE_2D;
1493 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1494
1495 my $h1 = $self->{h} - $ycut * $self->{h};
1496 my $h2 = $ycut * $self->{h};
1497
1498 my $yp = 0;
1499
1500 glBindTexture GL_TEXTURE_2D, $t1->{name};
1501 glBegin GL_QUADS;
1502 glTexCoord 0 , 0; glVertex 0 , $yp;
1503 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1;
1504 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1;
1505 glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp;
1506 glEnd;
1507
1508 $yp += $h1;
1509
1510 glBindTexture GL_TEXTURE_2D, $t2->{name};
1511 glBegin GL_QUADS;
1512 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp;
1513 glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2;
1514 glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2;
1515 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp;
1516 glEnd;
1517
1518 glDisable GL_BLEND;
1519 glDisable GL_TEXTURE_2D;
1384} 1520}
1385 1521
1386############################################################################# 1522#############################################################################
1387 1523
1388package CFClient::UI::Slider; 1524package CFClient::UI::Slider;
1582 1718
1583 ($self->{req_w}, $self->{req_h}) 1719 ($self->{req_w}, $self->{req_h})
1584} 1720}
1585 1721
1586sub size_allocate { 1722sub size_allocate {
1587 my ($self, $x, $y, $w, $h) = @_; 1723 my ($self, $w, $h) = @_;
1588
1589 $self->SUPER::size_allocate ($x, $y, $w, $h);
1590 1724
1591 $self->{layout}->set_height ($self->{fontsize}); 1725 $self->{layout}->set_height ($self->{fontsize});
1592 $self->{layout}->set_width ($self->{w}); 1726 $self->{layout}->set_width ($self->{w});
1593 1727
1594 $self->reflow; 1728 $self->reflow;
1729 $self->update;
1595} 1730}
1596 1731
1597sub add_paragraph { 1732sub add_paragraph {
1598 my ($self, $color, $text) = @_; 1733 my ($self, $color, $text) = @_;
1599 1734
1779 glTranslate $sx0 - 32, $sy0 - 32, 0; 1914 glTranslate $sx0 - 32, $sy0 - 32, 0;
1780 1915
1781 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 1916 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
1782 1917
1783 if ($::CFG->{fow_enable}) { 1918 if ($::CFG->{fow_enable}) {
1784 if ($::CFG->{fow_smooth}) { # smooth fog of war 1919 if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war
1785 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; 1920 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
1786 glConvolutionFilter2D 1921 glConvolutionFilter2D (
1787 GL_CONVOLUTION_2D, 1922 GL_CONVOLUTION_2D,
1788 GL_ALPHA, 1923 GL_ALPHA,
1789 3, 3, 1924 3, 3,
1790 GL_ALPHA, GL_FLOAT, 1925 GL_ALPHA, GL_FLOAT,
1791 pack "f*", 1926 pack "f*",
1792 0.1, 0.1, 0.1, 1927 0.1, 0.1, 0.1,
1793 0.1, 0.2, 0.1, 1928 0.1, 0.2, 0.1,
1794 0.1, 0.1, 0.1, 1929 0.1, 0.1, 0.1,
1795 ; 1930 );
1796 glEnable GL_CONVOLUTION_2D; 1931 glEnable GL_CONVOLUTION_2D;
1797 } 1932 }
1798 1933
1799 $self->{fow_texture} = new CFClient::Texture 1934 $self->{fow_texture} = new CFClient::Texture
1800 w => $w, 1935 w => $w,
1830 $self->{mapmap_texture} = 1965 $self->{mapmap_texture} =
1831 new CFClient::Texture 1966 new CFClient::Texture
1832 w => $w, 1967 w => $w,
1833 h => $h, 1968 h => $h,
1834 data => $::MAP->mapmap ($w, $h), 1969 data => $::MAP->mapmap ($w, $h),
1835 type => GL_UNSIGNED_INT_8_8_8_8_REV; 1970 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
1836 1971
1837 $self->{mapmap_texture}->draw_quad (100, 100); 1972 $self->{mapmap_texture}->draw_quad (100, 100);
1838 1973
1839 glDisable GL_TEXTURE_2D; 1974 glDisable GL_TEXTURE_2D;
1840 glDisable GL_BLEND; 1975 glDisable GL_BLEND;
1884 2019
1885 my $mod = $ev->key_mod; 2020 my $mod = $ev->key_mod;
1886 my $sym = $ev->key_sym; 2021 my $sym = $ev->key_sym;
1887 2022
1888 if ($sym == SDLK_KP5) { 2023 if ($sym == SDLK_KP5) {
1889 $::CONN->user_send ("command stay fire"); 2024 $::CONN->user_send ("stay fire");
1890 } elsif ($sym == SDLK_a) { 2025 } elsif ($sym == SDLK_a) {
1891 $::CONN->user_send ("command apply"); 2026 $::CONN->user_send ("apply");
1892 } elsif ($sym == SDLK_QUOTE) { 2027 } elsif ($sym == SDLK_QUOTE) {
1893 $self->emit ('activate_console'); 2028 $self->emit ('activate_console');
1894 } elsif ($sym == SDLK_SLASH) { 2029 } elsif ($sym == SDLK_SLASH) {
1895 $self->emit ('activate_console' => '/'); 2030 $self->emit ('activate_console' => '/');
1896 } elsif (exists $DIR{$sym}) { 2031 } elsif (exists $DIR{$sym}) {
1897 if ($mod & KMOD_SHIFT) { 2032 if ($mod & KMOD_SHIFT) {
1898 $self->{shft}++; 2033 $self->{shft}++;
1899 $::CONN->user_send ("command fire $DIR{$sym}[0]"); 2034 $::CONN->user_send ("fire $DIR{$sym}[0]");
1900 } elsif ($mod & KMOD_CTRL) { 2035 } elsif ($mod & KMOD_CTRL) {
1901 $self->{ctrl}++; 2036 $self->{ctrl}++;
1902 $::CONN->user_send ("command run $DIR{$sym}[0]"); 2037 $::CONN->user_send ("run $DIR{$sym}[0]");
1903 } else { 2038 } else {
1904 $::CONN->user_send ("command $DIR{$sym}[1]"); 2039 $::CONN->user_send ("$DIR{$sym}[1]");
1905 } 2040 }
1906 } 2041 }
1907} 2042}
1908 2043
1909sub key_up { 2044sub key_up {
1911 2046
1912 my $mod = $ev->key_mod; 2047 my $mod = $ev->key_mod;
1913 my $sym = $ev->key_sym; 2048 my $sym = $ev->key_sym;
1914 2049
1915 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { 2050 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
1916 $::CONN->user_send ("command fire_stop"); 2051 $::CONN->user_send ("fire_stop");
1917 } 2052 }
1918 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { 2053 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
1919 $::CONN->user_send ("command run_stop"); 2054 $::CONN->user_send ("run_stop");
1920 } 2055 }
1921} 2056}
1922 2057
1923############################################################################# 2058#############################################################################
1924 2059
2007 2142
2008our @ISA = CFClient::UI::Container::; 2143our @ISA = CFClient::UI::Container::;
2009 2144
2010use SDL::OpenGL; 2145use SDL::OpenGL;
2011 2146
2147sub check_size {
2148 my ($self) = @_;
2149
2150 $self->configure (0, 0, $::WITH, $::HEIGHT);
2151}
2152
2012sub size_request { 2153sub size_request {
2013 ($::WIDTH, $::HEIGHT) 2154 ($::WIDTH, $::HEIGHT)
2014} 2155}
2015 2156
2016sub size_allocate { 2157sub configure {
2017 my ($self, $x, $y, $w, $h) = @_; 2158 my ($self, $x, $y, $w, $h) = @_;
2018 2159
2019 $self->_size_allocate ($x, $y, $w, $h); 2160 $self->SUPER::configure ($x, $y, $w, $h);
2020 2161
2021 $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) 2162 $_->configure ($_->{x}, $_->{y}, $_->size_request)
2022 for @{$self->{children}}; 2163 for @{$self->{children}};
2023} 2164}
2024 2165
2025sub _topleft { 2166sub _topleft {
2026 my ($self, $x, $y) = @_; 2167 my ($self, $x, $y) = @_;
2029} 2170}
2030 2171
2031sub update { 2172sub update {
2032 my ($self) = @_; 2173 my ($self) = @_;
2033 2174
2034 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); 2175 $self->check_size;
2035 ::refresh (); 2176 ::refresh ();
2036} 2177}
2037 2178
2038sub add { 2179sub add {
2039 my ($self, $widget) = @_; 2180 my ($self, $child) = @_;
2040 2181
2041 $self->SUPER::add ($widget); 2182 $self->SUPER::add ($child);
2042
2043 $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request);
2044} 2183}
2045 2184
2046sub on_refresh { 2185sub on_refresh {
2047 my ($self, $id, $cb) = @_; 2186 my ($self, $id, $cb) = @_;
2048 2187

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines