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.137 by root, Wed Apr 19 21:38:05 2006 UTC

21 $FOCUS->key_up ($_[0]) if $FOCUS; 21 $FOCUS->key_up ($_[0]) if $FOCUS;
22} 22}
23 23
24sub feed_sdl_button_down_event { 24sub feed_sdl_button_down_event {
25 my ($ev) = @_; 25 my ($ev) = @_;
26 my ($x, $y) = ($ev->motion_x, $ev->motion_y); 26 my ($x, $y) = ($ev->{x}, $ev->{y});
27 27
28 if (!$BUTTON_STATE) { 28 if (!$BUTTON_STATE) {
29 my $widget = $ROOT->find_widget ($x, $y); 29 my $widget = $ROOT->find_widget ($x, $y);
30 30
31 $GRAB = $widget; 31 $GRAB = $widget;
32 $GRAB->update if $GRAB; 32 $GRAB->update if $GRAB;
33 } 33 }
34 34
35 $BUTTON_STATE |= 1 << ($ev->button - 1); 35 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
36 36
37 $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; 37 $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB;
38} 38}
39 39
40sub feed_sdl_button_up_event { 40sub feed_sdl_button_up_event {
41 my ($ev) = @_; 41 my ($ev) = @_;
42 my ($x, $y) = ($ev->motion_x, $ev->motion_y); 42 my ($x, $y) = ($ev->{x}, $ev->{y});
43 43
44 my $widget = $GRAB || $ROOT->find_widget ($x, $y); 44 my $widget = $GRAB || $ROOT->find_widget ($x, $y);
45 45
46 $BUTTON_STATE &= ~(1 << ($ev->button - 1)); 46 $BUTTON_STATE &= ~(1 << ($ev->{button} - 1));
47 47
48 $GRAB->button_up ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; 48 $GRAB->button_up ($ev, $GRAB->coord2local ($x, $y)) if $GRAB;
49 49
50 if (!$BUTTON_STATE) { 50 if (!$BUTTON_STATE) {
51 my $grab = $GRAB; undef $GRAB; 51 my $grab = $GRAB; undef $GRAB;
54 } 54 }
55} 55}
56 56
57sub feed_sdl_motion_event { 57sub feed_sdl_motion_event {
58 my ($ev) = @_; 58 my ($ev) = @_;
59 my ($x, $y) = ($ev->motion_x, $ev->motion_y); 59 my ($x, $y) = ($ev->{x}, $ev->{y});
60 60
61 my $widget = $GRAB || $ROOT->find_widget ($x, $y); 61 my $widget = $GRAB || $ROOT->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;
96 96
97 my $self = bless { 97 my $self = bless {
98 x => 0, 98 x => 0,
99 y => 0, 99 y => 0,
100 z => 0, 100 z => 0,
101 w => -1,
102 h => -1,
103 @_ 101 @_
104 }, $class; 102 }, $class;
105 103
106 for (keys %$self) { 104 for (keys %$self) {
107 if (/^connect_(.*)$/) { 105 if (/^connect_(.*)$/) {
110 } 108 }
111 109
112 $self 110 $self
113} 111}
114 112
113sub show {
114 my ($self) = @_;
115
116 return if $self->{parent};
117
118 $CFClient::UI::ROOT->add ($self);
119}
120
121sub hide {
122 my ($self) = @_;
123
124 return unless $self->{parent};
125
126 $self->{parent}->remove ($self);
127}
128
115sub move { 129sub move {
116 my ($self, $x, $y, $z) = @_; 130 my ($self, $x, $y, $z) = @_;
131
117 $self->{x} = int $x; 132 $self->{x} = int $x;
118 $self->{y} = int $y; 133 $self->{y} = int $y;
119 $self->{z} = $z if defined $z; 134 $self->{z} = $z if defined $z;
135
136 $self->update;
120} 137}
121 138
122sub needs_redraw { 139sub needs_redraw {
123 0 140 0
124} 141}
126sub size_request { 143sub size_request {
127 require Carp; 144 require Carp;
128 Carp::confess "size_request is abtract"; 145 Carp::confess "size_request is abtract";
129} 146}
130 147
131sub _size_allocate { 148sub configure {
132 my ($self, $x, $y, $w, $h) = @_; 149 my ($self, $x, $y, $w, $h) = @_;
133 150
134 $self->{x} = $x; 151 $self->{x} = $x;
135 $self->{y} = $y; 152 $self->{y} = $y;
136 153
137 return unless $self->{w} != $w || $self->{h} != $h; 154 return unless $self->{w} != $w || $self->{h} != $h;
138 155
139 $self->{w} = $w; 156 $self->{w} = $w;
140 $self->{h} = $h; 157 $self->{h} = $h;
141 158
142 1 159 $self->size_allocate ($w, $h);
160 $self->update;
143} 161}
144 162
145sub size_allocate { 163sub size_allocate {
146 my ($self, $x, $y, $w, $h) = @_; 164 # nothing to be done
147
148 $self->_size_allocate ($x, $y, $w, $h);
149} 165}
150 166
151# return top left coordinates 167# return top left coordinates
152sub _topleft { 168sub _topleft {
153 my ($self, $x, $y) = @_; 169 my ($self, $x, $y) = @_;
225 glPopMatrix; 241 glPopMatrix;
226 242
227 if ($self == $HOVER && $self->{can_hover}) { 243 if ($self == $HOVER && $self->{can_hover}) {
228 my ($x, $y) = @$self{qw(x y)}; 244 my ($x, $y) = @$self{qw(x y)};
229 245
230 glColor 0, 0, 1, 0.2; 246 glColor 1, 0.8, 0.5, 0.2;
231 glEnable GL_BLEND; 247 glEnable GL_BLEND;
232 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 248 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
233 glBegin GL_QUADS; 249 glBegin GL_QUADS;
234 glVertex $x , $y; 250 glVertex $x , $y;
235 glVertex $x + $self->{w}, $y; 251 glVertex $x + $self->{w}, $y;
260 my ($self, $parent) = @_; 276 my ($self, $parent) = @_;
261 277
262 Scalar::Util::weaken ($self->{parent} = $parent); 278 Scalar::Util::weaken ($self->{parent} = $parent);
263} 279}
264 280
281sub check_size {
282 my ($self) = @_;
283
284 my ($w, $h) = $self->size_request;
285
286 if ($w != $self->{req_w} || $h != $self->{req_h}) {
287 $self->{req_w} = $w;
288 $self->{req_h} = $h;
289
290 $self->{parent}->check_size
291 if $self->{parent};
292 }
293}
294
265sub update { 295sub update {
266 my ($self) = @_; 296 my ($self) = @_;
267 297
268 $self->{parent}->update 298 $self->{parent}->update
269 if $self->{parent}; 299 if $self->{parent};
270} 300}
271 301
272sub connect { 302sub connect {
273 my ($self, $signal, $cb) = @_; 303 my ($self, $signal, $cb) = @_;
274 304
275 push @{ $self->{cb}{$signal} }, $cb; 305 push @{ $self->{signal_cb}{$signal} }, $cb;
276} 306}
277 307
278sub emit { 308sub emit {
279 my ($self, $signal, @args) = @_; 309 my ($self, $signal, @args) = @_;
280 310
311 for my $cb (@{$self->{signal_cb}{$signal} || []}) {
281 $_->($self, @args) 312 $cb->($self, @args);
282 for @{$self->{cb}{$signal} || []}; 313 }
283} 314}
284 315
285sub DESTROY { 316sub DESTROY {
286 my ($self) = @_; 317 my ($self) = @_;
287 318
367 $self->{children} = [ 398 $self->{children} = [
368 sort { $a->{z} <=> $b->{z} } 399 sort { $a->{z} <=> $b->{z} }
369 @{$self->{children}}, $child 400 @{$self->{children}}, $child
370 ]; 401 ];
371 402
372 $self->{w} = $self->{h} = -1; 403 $child->check_size;
373 $self->update;
374} 404}
375 405
376sub remove { 406sub remove {
377 my ($self, $widget) = @_; 407 my ($self, $child) = @_;
378 408
409 delete $child->{parent};
410
379 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 411 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
380 412
381 $self->size_allocate (0, 0, $self->{w}, $self->{h}); 413 $self->check_size;
382} 414}
383 415
384sub find_widget { 416sub find_widget {
385 my ($self, $x, $y) = @_; 417 my ($self, $x, $y) = @_;
386 418
416 448
417 $class->SUPER::new (children => [$child], %arg) 449 $class->SUPER::new (children => [$child], %arg)
418} 450}
419 451
420sub add { 452sub add {
421 my ($self, $widget) = @_; 453 my ($self, $child) = @_;
422 454
423 $self->{children} = []; 455 $self->{children} = [];
424 456
425 $self->SUPER::add ($widget); 457 $self->SUPER::add ($child);
426} 458}
427 459
428sub remove { 460sub remove {
429 my ($self, $widget) = @_; 461 my ($self, $widget) = @_;
430 462
439sub size_request { 471sub size_request {
440 $_[0]{children}[0]->size_request 472 $_[0]{children}[0]->size_request
441} 473}
442 474
443sub size_allocate { 475sub size_allocate {
444 my ($self, $x, $y, $w, $h) = @_; 476 my ($self, $w, $h) = @_;
445 477
446 $self->_size_allocate ($x, $y, $w, $h) or return;
447
448 $self->{children}[0]->size_allocate (0, 0, $w, $h); 478 $self->{children}[0]->configure (0, 0, $w, $h);
449} 479}
450 480
451############################################################################# 481#############################################################################
452 482
453package CFClient::UI::Window; 483package CFClient::UI::Window;
479 $self->child->draw; 509 $self->child->draw;
480 }; 510 };
481} 511}
482 512
483sub size_allocate { 513sub size_allocate {
484 my ($self, $x, $y, $w, $h) = @_; 514 my ($self, $w, $h) = @_;
485 515
486 $self->_size_allocate ($x, $y, $w, $h) or return;
487
488 $self->child->size_allocate (0, 0, $w, $h); 516 $self->child->configure (0, 0, $w, $h);
489 517
490 $self->render_chld; 518 $self->render_chld;
491} 519}
492 520
493sub _draw { 521sub _draw {
509 glDisable GL_TEXTURE_2D; 537 glDisable GL_TEXTURE_2D;
510} 538}
511 539
512############################################################################# 540#############################################################################
513 541
542package CFClient::UI::ViewPort;
543
544our @ISA = CFClient::UI::Window::;
545
546sub new { die }
547
548sub size_request {
549 my ($self) = @_;
550
551 @$self{qw(child_w child_h)} = $self->child->size_request;
552 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
553
554 @$self{qw(child_w child_h)}
555}
556
557sub _draw {
558 my ($self) = @_;
559
560 $self->{children}[1]->draw;
561}
562
563
564#############################################################################
565
514package CFClient::UI::Frame; 566package CFClient::UI::Frame;
515 567
516our @ISA = CFClient::UI::Bin::; 568our @ISA = CFClient::UI::Bin::;
517 569
518use SDL::OpenGL; 570use SDL::OpenGL;
528} 580}
529 581
530sub size_allocate { 582sub size_allocate {
531 my ($self, $x, $y, $w, $h) = @_; 583 my ($self, $x, $y, $w, $h) = @_;
532 584
533 $self->_size_allocate ($x, $y, $w, $h) or return;
534
535 $self->child->size_allocate (2, 2, $w - 4, $h - 4); 585 $self->child->configure (2, 2, $w - 4, $h - 4);
536} 586}
537 587
538sub _draw { 588sub _draw {
539 my ($self) = @_; 589 my ($self) = @_;
540 590
571 # TODO: user_x, user_y, overwrite moveto? 621 # TODO: user_x, user_y, overwrite moveto?
572 622
573 $class->SUPER::new ( 623 $class->SUPER::new (
574 bg => [1, 1, 1, 1], 624 bg => [1, 1, 1, 1],
575 border_bg => [1, 1, 1, 1], 625 border_bg => [1, 1, 1, 1],
576 border => int $::FONTSIZE * 0.8, 626 border => 0.8,
577 @_ 627 @_
578 ) 628 )
579} 629}
580 630
631sub border {
632 int $_[0]{border} * $::FONTSIZE
633}
634
581sub size_request { 635sub size_request {
582 my ($self) = @_; 636 my ($self) = @_;
583 637
584 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; 638 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
585 639
586 my ($w, $h) = $self->SUPER::size_request; 640 my ($w, $h) = $self->SUPER::size_request;
587 641
588 ( 642 (
589 $w + $self->{border} * 2, 643 $w + $self->border * 2,
590 $h + $self->{border} * 2, 644 $h + $self->border * 2,
591 ) 645 )
592} 646}
593 647
594sub size_allocate { 648sub size_allocate {
595 my ($self, $x, $y, $w, $h) = @_; 649 my ($self, $w, $h) = @_;
596 650
597 $self->_size_allocate ($x, $y, $w, $h) or return;
598
599 $h -= List::Util::max 0, $self->{border} * 2; 651 $h -= List::Util::max 0, $self->border * 2;
600 $w -= List::Util::max 0, $self->{border} * 2; 652 $w -= List::Util::max 0, $self->border * 2;
601 653
602 $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); 654 $self->child->configure ($self->border, $self->border, $w, $h);
603} 655}
604 656
605sub button_down { 657sub button_down {
606 my ($self, $ev, $x, $y) = @_; 658 my ($self, $ev, $x, $y) = @_;
607 659
660 my $border = $self->border;
661
608 if ($x < $self->{w} && $x >= $self->{w} - $self->{border} 662 if ($x < $self->{w} && $x >= $self->{w} - $border
609 && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { 663 && $y < $self->{h} && $y >= $self->{h} - $border) {
610 664
611 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 665 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
612 my ($bw, $bh) = ($self->{w}, $self->{h}); 666 my ($bw, $bh) = ($self->{w}, $self->{h});
613 667
614 $self->{motion} = sub { 668 $self->{motion} = sub {
616 670
617 ($x, $y) = ($ev->motion_x, $ev->motion_y); 671 ($x, $y) = ($ev->motion_x, $ev->motion_y);
618 672
619 $self->{user_w} = $bw + $x - $ox; 673 $self->{user_w} = $bw + $x - $ox;
620 $self->{user_h} = $bh + $y - $oy; 674 $self->{user_h} = $bh + $y - $oy;
621 $self->update; 675 $self->check_size;
622 }; 676 };
623 677
624 } elsif ($x >= 0 && $x < $self->{w} 678 } elsif ($x >= 0 && $x < $self->{w}
625 && $y >= 0 && $y < $self->{border}) { 679 && $y >= 0 && $y < $border) {
626 680
627 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 681 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
628 my ($bx, $by) = ($self->{x}, $self->{y}); 682 my ($bx, $by) = ($self->{x}, $self->{y});
629 683
630 $self->{motion} = sub { 684 $self->{motion} = sub {
659 glEnable GL_BLEND; 713 glEnable GL_BLEND;
660 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 714 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
661 glEnable GL_TEXTURE_2D; 715 glEnable GL_TEXTURE_2D;
662 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 716 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
663 717
718 my $border = $self->border;
719
664 glColor @{ $self->{border_bg} }; 720 glColor @{ $self->{border_bg} };
665 $tex[1]->draw_quad (0, 0, $w, $self->{border}); 721 $tex[1]->draw_quad (0, 0, $w, $border);
666 $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); 722 $tex[3]->draw_quad (0, $border, $border, $ch);
667 $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); 723 $tex[2]->draw_quad ($w - $border, $border, $border, $ch);
668 $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); 724 $tex[4]->draw_quad (0, $h - $border, $w, $border);
669 725
670 my $bg = $tex[0]; 726 my $bg = $tex[0];
671 727
672 # TODO: repeat texture not scale 728 # TODO: repeat texture not scale
673 my $rep_x = $cw / $bg->{w}; 729 my $rep_x = $cw / $bg->{w};
676 glColor @{ $self->{bg} }; 732 glColor @{ $self->{bg} };
677 733
678 $bg->{s} = $rep_x; 734 $bg->{s} = $rep_x;
679 $bg->{t} = $rep_y; 735 $bg->{t} = $rep_y;
680 $bg->{wrap_mode} = 1; 736 $bg->{wrap_mode} = 1;
681 $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); 737 $bg->draw_quad ($border, $border, $cw, $ch);
682 738
683 glDisable GL_TEXTURE_2D; 739 glDisable GL_TEXTURE_2D;
684 glDisable GL_BLEND; 740 glDisable GL_BLEND;
685 741
686 $self->child->draw; 742 $self->child->draw;
709 my ($self, $x, $y, $child) = @_; 765 my ($self, $x, $y, $child) = @_;
710 766
711 $child->set_parent ($self); 767 $child->set_parent ($self);
712 $self->{children}[$y][$x] = $child; 768 $self->{children}[$y][$x] = $child;
713 769
714 $self->{w} = $self->{h} = -1; 770 $child->check_size;
715 $self->update;
716} 771}
717 772
718# TODO: move to container class maybe? send childs a signal on removal? 773# TODO: move to container class maybe? send childs a signal on removal?
719sub clear { 774sub clear {
720 my ($self) = @_; 775 my ($self) = @_;
755 (sum @$hs), 810 (sum @$hs),
756 ) 811 )
757} 812}
758 813
759sub size_allocate { 814sub size_allocate {
760 my ($self, $x, $y, $w, $h) = @_; 815 my ($self, $w, $h) = @_;
761
762 $self->_size_allocate ($x, $y, $w, $h) or return;
763 816
764 my ($ws, $hs) = $self->get_wh; 817 my ($ws, $hs) = $self->get_wh;
765 818
766 my $req_w = sum @$ws; 819 my $req_w = sum @$ws;
767 my $req_h = sum @$hs; 820 my $req_h = sum @$hs;
789 842
790 for my $c (0 .. $#$row) { 843 for my $c (0 .. $#$row) {
791 my $col_w = $ws->[$c]; 844 my $col_w = $ws->[$c];
792 845
793 if (my $widget = $row->[$c]) { 846 if (my $widget = $row->[$c]) {
794 $widget->size_allocate ($x, $y, $col_w, $row_h); 847 $widget->configure ($x, $y, $col_w, $row_h);
795 } 848 }
796 849
797 $x += $col_w; 850 $x += $col_w;
798 } 851 }
799 852
844 (List::Util::max map $_->[1], @alloc), 897 (List::Util::max map $_->[1], @alloc),
845 ) 898 )
846} 899}
847 900
848sub size_allocate { 901sub size_allocate {
849 my ($self, $x, $y, $w, $h) = @_; 902 my ($self, $w, $h) = @_;
850
851 $self->_size_allocate ($x, $y, $w, $h);
852 903
853 ($h, $w) = ($w, $h); 904 ($h, $w) = ($w, $h);
854 905
855 my $children = $self->{children}; 906 my $children = $self->{children};
856 907
878 929
879 my $y = 0; 930 my $y = 0;
880 for (0 .. $#$children) { 931 for (0 .. $#$children) {
881 my $child = $children->[$_]; 932 my $child = $children->[$_];
882 my $h = $h[$_]; 933 my $h = $h[$_];
883 $child->size_allocate ($y, 0, $h, $w); 934 $child->configure ($y, 0, $h, $w);
884 935
885 $y += $h; 936 $y += $h;
886 } 937 }
938
939 1
887} 940}
888 941
889############################################################################# 942#############################################################################
890 943
891package CFClient::UI::VBox; 944package CFClient::UI::VBox;
904 (List::Util::sum map $_->[1], @alloc), 957 (List::Util::sum map $_->[1], @alloc),
905 ) 958 )
906} 959}
907 960
908sub size_allocate { 961sub size_allocate {
909 my ($self, $x, $y, $w, $h) = @_; 962 my ($self, $w, $h) = @_;
910
911 $self->_size_allocate ($x, $y, $w, $h);
912 963
913 my $children = $self->{children}; 964 my $children = $self->{children};
914 965
915 my @h = map +($_->size_request)[1], @$children; 966 my @h = map +($_->size_request)[1], @$children;
916 967
934 985
935 my $y = 0; 986 my $y = 0;
936 for (0 .. $#$children) { 987 for (0 .. $#$children) {
937 my $child = $children->[$_]; 988 my $child = $children->[$_];
938 my $h = $h[$_]; 989 my $h = $h[$_];
939 $child->size_allocate (0, $y, $w, $h); 990 $child->configure (0, $y, $w, $h);
940 991
941 $y += $h; 992 $y += $h;
942 } 993 }
994
995 1
943} 996}
944 997
945############################################################################# 998#############################################################################
946 999
947package CFClient::UI::Label; 1000package CFClient::UI::Label;
953sub new { 1006sub new {
954 my ($class, %arg) = @_; 1007 my ($class, %arg) = @_;
955 1008
956 my $self = $class->SUPER::new ( 1009 my $self = $class->SUPER::new (
957 fg => [1, 1, 1], 1010 fg => [1, 1, 1],
958 fontsize => $::FONTSIZE, 1011 fontsize => 1,
959 text => "", 1012 text => "",
960 align => -1, 1013 align => -1,
961 valign => -1, 1014 valign => -1,
962 padding => 2, 1015 padding => 2,
963 layout => new CFClient::Layout, 1016 layout => new CFClient::Layout,
1002 1055
1003sub size_request { 1056sub size_request {
1004 my ($self) = @_; 1057 my ($self) = @_;
1005 1058
1006 $self->{layout}->set_width; 1059 $self->{layout}->set_width;
1007 $self->{layout}->set_height ($self->{fontsize}); 1060 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1008 1061
1009 my ($w, $h) = $self->{layout}->size; 1062 my ($w, $h) = $self->{layout}->size;
1010 1063
1011 ( 1064 (
1012 $w + $self->{padding} * 2, 1065 $w + $self->{padding} * 2,
1013 $h + $self->{padding} * 2, 1066 $h + $self->{padding} * 2,
1014 ) 1067 )
1015} 1068}
1016 1069
1017sub size_allocate { 1070sub size_allocate {
1018 my ($self, $x, $y, $w, $h) = @_; 1071 my ($self, $w, $h) = @_;
1019
1020 $self->_size_allocate ($x, $y, $w, $h) or return;
1021 1072
1022 delete $self->{texture}; 1073 delete $self->{texture};
1023}
1024
1025sub update {
1026 my ($self) = @_;
1027
1028 delete $self->{texture};
1029 $self->SUPER::update;
1030} 1074}
1031 1075
1032sub _draw { 1076sub _draw {
1033 my ($self) = @_; 1077 my ($self) = @_;
1034 1078
1035 my $tex = $self->{texture} ||= do { 1079 my $tex = $self->{texture} ||= do {
1036 $self->{layout}->set_width ($self->{w}); 1080 $self->{layout}->set_width ($self->{w});
1037 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize}); 1081 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1038 new_from_layout CFClient::Texture $self->{layout} 1082 new_from_layout CFClient::Texture $self->{layout}
1039 }; 1083 };
1040 1084
1041 glEnable GL_BLEND; 1085 glEnable GL_BLEND;
1042 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1086 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1043 glEnable GL_TEXTURE_2D; 1087 glEnable GL_TEXTURE_2D;
1044 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1088 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1045 1089
1046 glColor @{$self->{fg}}; 1090 glColor @{$self->{fg}};
1047 1091
1048 my $x = 1092 $self->{ox} = int (
1049 $self->{align} < 0 ? $self->{padding} 1093 $self->{align} < 0 ? $self->{padding}
1050 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1094 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1051 : ($self->{w} - $tex->{w}) * 0.5; 1095 : ($self->{w} - $tex->{w}) * 0.5
1096 );
1052 1097
1053 my $y = 1098 $self->{oy} = int (
1054 $self->{valign} < 0 ? $self->{padding} 1099 $self->{valign} < 0 ? $self->{padding}
1055 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} 1100 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1056 : ($self->{h} - $tex->{h}) * 0.5; 1101 : ($self->{h} - $tex->{h}) * 0.5
1102 );
1057 1103
1058 $tex->draw_quad (int $x, int $y); 1104 $tex->draw_quad ($self->{ox}, $self->{oy});
1059 1105
1060 glDisable GL_TEXTURE_2D; 1106 glDisable GL_TEXTURE_2D;
1061 glDisable GL_BLEND; 1107 glDisable GL_BLEND;
1062} 1108}
1063 1109
1065 1111
1066package CFClient::UI::EntryBase; 1112package CFClient::UI::EntryBase;
1067 1113
1068our @ISA = CFClient::UI::Label::; 1114our @ISA = CFClient::UI::Label::;
1069 1115
1070use SDL;
1071use SDL::OpenGL; 1116use SDL::OpenGL;
1072 1117
1073sub new { 1118sub new {
1074 my $class = shift; 1119 my $class = shift;
1075 1120
1090 1135
1091 delete $self->{cur_h}; 1136 delete $self->{cur_h};
1092 1137
1093 return if $self->{text} eq $text; 1138 return if $self->{text} eq $text;
1094 1139
1140 delete $self->{texture};
1141
1095 $self->{last_activity} = $::NOW; 1142 $self->{last_activity} = $::NOW;
1096 $self->{text} = $text; 1143 $self->{text} = $text;
1097 1144
1098 $text =~ s/./*/g if $self->{hidden}; 1145 $text =~ s/./*/g if $self->{hidden};
1099 $self->{layout}->set_text ("$text "); 1146 $self->{layout}->set_text ("$text ");
1112 1159
1113 ($w + 1, $h) # add 1 for cursor 1160 ($w + 1, $h) # add 1 for cursor
1114} 1161}
1115 1162
1116sub size_allocate { 1163sub size_allocate {
1117 my ($self, $x, $y, $w, $h) = @_; 1164 my ($self, $w, $h) = @_;
1118
1119 $self->SUPER::size_allocate ($x, $y, $w, $h);
1120 1165
1121 $self->_set_text ($self->{text}); 1166 $self->_set_text ($self->{text});
1122} 1167}
1123 1168
1124sub set_text { 1169sub set_text {
1130} 1175}
1131 1176
1132sub key_down { 1177sub key_down {
1133 my ($self, $ev) = @_; 1178 my ($self, $ev) = @_;
1134 1179
1135 my $mod = $ev->key_mod; 1180 my $mod = $ev->{mod};
1136 my $sym = $ev->key_sym; 1181 my $sym = $ev->{sym};
1137
1138 my $uni = $ev->key_unicode; 1182 my $uni = $ev->{unicode};
1139 1183
1140 my $text = $self->get_text; 1184 my $text = $self->get_text;
1141 1185
1142 if ($sym == SDLK_BACKSPACE) { 1186 if ($sym == 8) {
1143 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1187 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1144 } elsif ($sym == SDLK_DELETE) { 1188 } elsif ($sym == 127) {
1145 substr $text, $self->{cursor}, 1, ""; 1189 substr $text, $self->{cursor}, 1, "";
1146 } elsif ($sym == SDLK_LEFT) { 1190 } elsif ($sym == CFClient::SDLK_LEFT) {
1147 --$self->{cursor} if $self->{cursor}; 1191 --$self->{cursor} if $self->{cursor};
1148 } elsif ($sym == SDLK_RIGHT) { 1192 } elsif ($sym == CFClient::SDLK_RIGHT) {
1149 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1193 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1150 } elsif ($sym == SDLK_HOME) { 1194 } elsif ($sym == CFClient::SDLK_HOME) {
1151 $self->{cursor} = 0; 1195 $self->{cursor} = 0;
1152 } elsif ($sym == SDLK_END) { 1196 } elsif ($sym == CFClient::SDLK_END) {
1153 $self->{cursor} = length $text; 1197 $self->{cursor} = length $text;
1154 } elsif ($sym == SDLK_ESCAPE) { 1198 } elsif ($sym == 27) {
1155 $self->emit ('escape'); 1199 $self->emit ('escape');
1156 } elsif ($uni) { 1200 } elsif ($uni) {
1157 substr $text, $self->{cursor}++, 0, chr $uni; 1201 substr $text, $self->{cursor}++, 0, chr $uni;
1158 } 1202 }
1159 1203
1224 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) 1268 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text)
1225 } 1269 }
1226 1270
1227 glColor @{$self->{fg}}; 1271 glColor @{$self->{fg}};
1228 glBegin GL_LINES; 1272 glBegin GL_LINES;
1229 glVertex $self->{cur_x}, $self->{cur_y};
1230 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; 1273 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy};
1274 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
1231 glEnd; 1275 glEnd;
1232 } 1276 }
1233} 1277}
1234 1278
1235package CFClient::UI::Entry; 1279package CFClient::UI::Entry;
1236 1280
1237our @ISA = CFClient::UI::EntryBase::; 1281our @ISA = CFClient::UI::EntryBase::;
1238 1282
1239use SDL;
1240use SDL::OpenGL; 1283use SDL::OpenGL;
1241 1284
1242sub key_down { 1285sub key_down {
1243 my ($self, $ev) = @_; 1286 my ($self, $ev) = @_;
1244 1287
1245 my $sym = $ev->key_sym; 1288 my $sym = $ev->{sym};
1246 1289
1247 if ($sym == SDLK_RETURN) { 1290 if ($sym == 13) {
1248 $self->emit (activate => $self->get_text); 1291 $self->emit (activate => $self->get_text);
1249 $self->update; 1292 $self->update;
1250 1293
1251 } else { 1294 } else {
1252 $self->SUPER::key_down ($ev); 1295 $self->SUPER::key_down ($ev);
1258 1301
1259package CFClient::UI::Button; 1302package CFClient::UI::Button;
1260 1303
1261our @ISA = CFClient::UI::Label::; 1304our @ISA = CFClient::UI::Label::;
1262 1305
1263use SDL;
1264use SDL::OpenGL; 1306use SDL::OpenGL;
1265 1307
1266my @tex = 1308my @tex =
1267 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1309 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1268 qw(b1_button_active.png); 1310 qw(b1_button_active.png);
1272 1314
1273 $class->SUPER::new ( 1315 $class->SUPER::new (
1274 padding => 4, 1316 padding => 4,
1275 fg => [1, 1, 1], 1317 fg => [1, 1, 1],
1276 bg => [1, 1, 1, 0.2], 1318 bg => [1, 1, 1, 0.2],
1277 active_fg => [1, 1, 0], 1319 active_fg => [0, 0, 1],
1278 can_hover => 1, 1320 can_hover => 1,
1321 align => 0,
1322 valign => 0,
1279 @_ 1323 @_
1280 ) 1324 )
1281} 1325}
1282 1326
1283sub button_up { 1327sub button_up {
1320 1364
1321my @tex = 1365my @tex =
1322 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1366 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1323 qw(c1_checkbox_bg.png c1_checkbox_active.png); 1367 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1324 1368
1325use SDL;
1326use SDL::OpenGL; 1369use SDL::OpenGL;
1327 1370
1328sub new { 1371sub new {
1329 my $class = shift; 1372 my $class = shift;
1330 1373
1342 my ($self) = @_; 1385 my ($self) = @_;
1343 1386
1344 ($self->{padding} * 2 + 6) x 2 1387 ($self->{padding} * 2 + 6) x 2
1345} 1388}
1346 1389
1347sub size_allocate {
1348 my ($self, $x, $y, $w, $h) = @_;
1349
1350 $self->_size_allocate ($x, $y, $w, $h);
1351}
1352
1353sub button_down { 1390sub button_down {
1354 my ($self, $ev, $x, $y) = @_; 1391 my ($self, $ev, $x, $y) = @_;
1355 1392
1356 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} 1393 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding}
1357 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { 1394 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) {
1379 1416
1380 $tex->draw_quad (0, 0, $s, $s); 1417 $tex->draw_quad (0, 0, $s, $s);
1381 1418
1382 glDisable GL_TEXTURE_2D; 1419 glDisable GL_TEXTURE_2D;
1383 glDisable GL_BLEND; 1420 glDisable GL_BLEND;
1421}
1422
1423#############################################################################
1424
1425package CFClient::UI::VGauge;
1426
1427our @ISA = CFClient::UI::Base::;
1428
1429use SDL::OpenGL;
1430
1431my %tex = (
1432 food => [
1433 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1434 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1435 ],
1436 grace => [
1437 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1438 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1439 ],
1440 hp => [
1441 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1442 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1443 ],
1444 mana => [
1445 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1446 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1447 ],
1448);
1449
1450# eg. VGauge->new (gauge => 'food'), default gauge: food
1451sub new {
1452 my $class = shift;
1453
1454 my $self = $class->SUPER::new (gauge => 'food', @_);
1455
1456 $self
1457}
1458
1459sub size_request {
1460 my ($self) = @_;
1461
1462 my $tex = $tex{$self->{gauge}}[0];
1463
1464 @$tex{qw(w h)}
1465}
1466
1467sub set_max {
1468 my ($self, $max) = @_;
1469
1470 $self->{max_val} = $max;
1471}
1472
1473sub set_value {
1474 my ($self, $val, $max) = @_;
1475
1476 $self->set_max ($max)
1477 if defined $max;
1478
1479 $max = $self->{max_val};
1480 $self->{val} = $val;
1481
1482 $self->update;
1483}
1484
1485sub _draw {
1486 my ($self) = @_;
1487
1488 my $tex = $tex{$self->{gauge}};
1489
1490 my ($w, $h) = ($self->{w}, $self->{h});
1491
1492 my $ycut = $self->{val} / ($self->{max_val} || 1);
1493 $ycut = 1 if $self->{val} > $self->{max_val};
1494
1495 my $t1 = $tex->[0];
1496 my $t2 = $tex->[1];
1497
1498 glEnable GL_BLEND;
1499 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1500 glEnable GL_TEXTURE_2D;
1501 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1502
1503 my $h1 = $self->{h} - $ycut * $self->{h};
1504 my $h2 = $ycut * $self->{h};
1505
1506 my $yp = 0;
1507
1508 glBindTexture GL_TEXTURE_2D, $t1->{name};
1509 glBegin GL_QUADS;
1510 glTexCoord 0 , 0; glVertex 0 , $yp;
1511 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1;
1512 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1;
1513 glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp;
1514 glEnd;
1515
1516 $yp += $h1;
1517
1518 glBindTexture GL_TEXTURE_2D, $t2->{name};
1519 glBegin GL_QUADS;
1520 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp;
1521 glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2;
1522 glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2;
1523 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp;
1524 glEnd;
1525
1526 glDisable GL_BLEND;
1527 glDisable GL_TEXTURE_2D;
1384} 1528}
1385 1529
1386############################################################################# 1530#############################################################################
1387 1531
1388package CFClient::UI::Slider; 1532package CFClient::UI::Slider;
1407 # TODO: calculations are off 1551 # TODO: calculations are off
1408 my $self = $class->SUPER::new ( 1552 my $self = $class->SUPER::new (
1409 fg => [1, 1, 1], 1553 fg => [1, 1, 1],
1410 active_fg => [0, 0, 0], 1554 active_fg => [0, 0, 0],
1411 range => [0, 0, 100, 10], 1555 range => [0, 0, 100, 10],
1412 req_w => 40, 1556 req_w => 20,
1413 req_h => 13, 1557 req_h => 20,
1414 vertical => 0, 1558 vertical => 0,
1415 can_hover => 1, 1559 can_hover => 1,
1416 inner_pad => 5, 1560 inner_pad => 5,
1417 @_ 1561 @_
1418 ); 1562 );
1528 1672
1529sub new { 1673sub new {
1530 my $class = shift; 1674 my $class = shift;
1531 1675
1532 my $self = $class->SUPER::new ( 1676 my $self = $class->SUPER::new (
1533 req_w => $::WIDTH / 6,
1534 req_h => $::HEIGHT / 6,
1535 fontsize => $::FONTSIZE, 1677 fontsize => 1,
1536 @_, 1678 @_,
1537 1679
1538 layout => (new CFClient::Layout), 1680 layout => (new CFClient::Layout),
1539 par => [], 1681 par => [],
1540 height => 0, 1682 height => 0,
1561sub text_height { 1703sub text_height {
1562 my ($self, $text) = @_; 1704 my ($self, $text) = @_;
1563 1705
1564 my $layout = $self->{layout}; 1706 my $layout = $self->{layout};
1565 1707
1566 $layout->set_height ($self->{fontsize}); 1708 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
1567 $layout->set_width ($self->{w}); 1709 $layout->set_width ($self->{w});
1568 $layout->set_text ($text); 1710 $layout->set_text ($text);
1569 1711
1570 ($layout->size)[1] 1712 ($layout->size)[1]
1571} 1713}
1575 1717
1576 $self->{need_reflow}++; 1718 $self->{need_reflow}++;
1577 $self->update; 1719 $self->update;
1578} 1720}
1579 1721
1580sub size_request {
1581 my ($self) = @_;
1582
1583 ($self->{req_w}, $self->{req_h})
1584}
1585
1586sub size_allocate { 1722sub size_allocate {
1587 my ($self, $x, $y, $w, $h) = @_; 1723 my ($self, $w, $h) = @_;
1588 1724
1589 $self->SUPER::size_allocate ($x, $y, $w, $h); 1725 $self->SUPER::size_allocate ($w, $h);
1590 1726
1591 $self->{layout}->set_height ($self->{fontsize}); 1727 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1592 $self->{layout}->set_width ($self->{w}); 1728 $self->{layout}->set_width ($self->{children}[0]{w});
1593 1729
1594 $self->reflow; 1730 $self->reflow;
1595} 1731}
1596 1732
1597sub add_paragraph { 1733sub add_paragraph {
1680 glDisable GL_TEXTURE_2D; 1816 glDisable GL_TEXTURE_2D;
1681 } 1817 }
1682 1818
1683 $self->{children}[1]->draw; 1819 $self->{children}[1]->draw;
1684 1820
1685}
1686
1687#############################################################################
1688
1689package CFClient::UI::MapWidget;
1690
1691use strict;
1692
1693use List::Util qw(min max);
1694
1695use SDL;
1696use SDL::OpenGL;
1697
1698our @ISA = CFClient::UI::Base::;
1699
1700sub new {
1701 my $class = shift;
1702
1703 $class->SUPER::new (
1704 z => -1,
1705 can_focus => 1,
1706 list => (glGenLists 1),
1707 @_
1708 )
1709}
1710
1711sub key_down {
1712 print "MAPKEYDOWN\n";
1713}
1714
1715sub key_up {
1716}
1717
1718sub button_down {
1719 my ($self, $ev, $x, $y) = @_;
1720
1721 $self->focus_in;
1722
1723 if ($ev->button == 2) {
1724 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
1725 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
1726
1727 $self->{motion} = sub {
1728 my ($ev, $x, $y) = @_;
1729
1730 ($x, $y) = ($ev->motion_x, $ev->motion_y);
1731
1732 $::CFG->{map_shift_x} = $bw + $x - $ox;
1733 $::CFG->{map_shift_y} = $bh + $y - $oy;
1734
1735 $self->update;
1736 };
1737 }
1738}
1739
1740sub button_up {
1741 my ($self, $ev, $x, $y) = @_;
1742
1743 delete $self->{motion};
1744}
1745
1746sub mouse_motion {
1747 my ($self, $ev, $x, $y) = @_;
1748
1749 $self->{motion}->($ev, $x, $y) if $self->{motion};
1750}
1751
1752sub size_request {
1753 (
1754 1 + 32 * int $::WIDTH / 32,
1755 1 + 32 * int $::HEIGHT / 32,
1756 )
1757}
1758
1759sub update {
1760 my ($self) = @_;
1761
1762 $self->{need_update} = 1;
1763 $self->SUPER::update;
1764}
1765
1766sub draw {
1767 my ($self) = @_;
1768
1769 if (delete $self->{need_update}) {
1770 glNewList $self->{list}, GL_COMPILE;
1771
1772 if ($::MAP) {
1773 my $sw = int $::WIDTH / 32;
1774 my $sh = int $::HEIGHT / 32;
1775
1776 my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
1777 my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
1778
1779 glTranslate $sx0 - 32, $sy0 - 32, 0;
1780
1781 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
1782
1783 if ($::CFG->{fow_enable}) {
1784 if ($::CFG->{fow_smooth}) { # smooth fog of war
1785 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER;
1786 glConvolutionFilter2D
1787 GL_CONVOLUTION_2D,
1788 GL_ALPHA,
1789 3, 3,
1790 GL_ALPHA, GL_FLOAT,
1791 pack "f*",
1792 0.1, 0.1, 0.1,
1793 0.1, 0.2, 0.1,
1794 0.1, 0.1, 0.1,
1795 ;
1796 glEnable GL_CONVOLUTION_2D;
1797 }
1798
1799 $self->{fow_texture} = new CFClient::Texture
1800 w => $w,
1801 h => $h,
1802 data => $data,
1803 internalformat => GL_ALPHA,
1804 format => GL_ALPHA;
1805
1806 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
1807
1808 glEnable GL_BLEND;
1809 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1810 glEnable GL_TEXTURE_2D;
1811 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1812
1813 glColor +($::CFG->{fow_intensity}) x 3, 1;
1814 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
1815
1816 glDisable GL_TEXTURE_2D;
1817 glDisable GL_BLEND;
1818 }
1819
1820 # HACK BEGIN
1821 {
1822 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove
1823 my ($w, $h) = (250, 250);
1824
1825 glEnable GL_BLEND;
1826 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1827 glEnable GL_TEXTURE_2D;
1828 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1829
1830 $self->{mapmap_texture} =
1831 new CFClient::Texture
1832 w => $w,
1833 h => $h,
1834 data => $::MAP->mapmap ($w, $h),
1835 type => GL_UNSIGNED_INT_8_8_8_8_REV;
1836
1837 $self->{mapmap_texture}->draw_quad (100, 100);
1838
1839 glDisable GL_TEXTURE_2D;
1840 glDisable GL_BLEND;
1841 }
1842 # HACK END
1843 }
1844
1845 glEndList;
1846 }
1847
1848 glPushMatrix;
1849 glCallList $self->{list};
1850 glPopMatrix;
1851
1852 if ($FOCUS != $self) {
1853 glColor 64/255, 64/255, 64/255;
1854 glLogicOp GL_AND;
1855 glEnable GL_COLOR_LOGIC_OP;
1856 glBegin GL_QUADS;
1857 glVertex 0, 0;
1858 glVertex 0, $::HEIGHT;
1859 glVertex $::WIDTH, $::HEIGHT;
1860 glVertex $::WIDTH, 0;
1861 glEnd;
1862 glDisable GL_COLOR_LOGIC_OP;
1863 }
1864}
1865
1866my %DIR = (
1867 SDLK_KP8, [1, "north"],
1868 SDLK_KP9, [2, "northeast"],
1869 SDLK_KP6, [3, "east"],
1870 SDLK_KP3, [4, "southeast"],
1871 SDLK_KP2, [5, "south"],
1872 SDLK_KP1, [6, "southwest"],
1873 SDLK_KP4, [7, "west"],
1874 SDLK_KP7, [8, "northwest"],
1875
1876 SDLK_UP, [1, "north"],
1877 SDLK_RIGHT, [3, "east"],
1878 SDLK_DOWN, [5, "south"],
1879 SDLK_LEFT, [7, "west"],
1880);
1881
1882sub key_down {
1883 my ($self, $ev) = @_;
1884
1885 my $mod = $ev->key_mod;
1886 my $sym = $ev->key_sym;
1887
1888 if ($sym == SDLK_KP5) {
1889 $::CONN->user_send ("command stay fire");
1890 } elsif ($sym == SDLK_a) {
1891 $::CONN->user_send ("command apply");
1892 } elsif ($sym == SDLK_QUOTE) {
1893 $self->emit ('activate_console');
1894 } elsif ($sym == SDLK_SLASH) {
1895 $self->emit ('activate_console' => '/');
1896 } elsif (exists $DIR{$sym}) {
1897 if ($mod & KMOD_SHIFT) {
1898 $self->{shft}++;
1899 $::CONN->user_send ("command fire $DIR{$sym}[0]");
1900 } elsif ($mod & KMOD_CTRL) {
1901 $self->{ctrl}++;
1902 $::CONN->user_send ("command run $DIR{$sym}[0]");
1903 } else {
1904 $::CONN->user_send ("command $DIR{$sym}[1]");
1905 }
1906 }
1907}
1908
1909sub key_up {
1910 my ($self, $ev) = @_;
1911
1912 my $mod = $ev->key_mod;
1913 my $sym = $ev->key_sym;
1914
1915 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
1916 $::CONN->user_send ("command fire_stop");
1917 }
1918 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
1919 $::CONN->user_send ("command run_stop");
1920 }
1921} 1821}
1922 1822
1923############################################################################# 1823#############################################################################
1924 1824
1925package CFClient::UI::Animator; 1825package CFClient::UI::Animator;
2007 1907
2008our @ISA = CFClient::UI::Container::; 1908our @ISA = CFClient::UI::Container::;
2009 1909
2010use SDL::OpenGL; 1910use SDL::OpenGL;
2011 1911
1912sub check_size {
1913 my ($self) = @_;
1914
1915 $self->configure (0, 0, $::WITH, $::HEIGHT);
1916}
1917
2012sub size_request { 1918sub size_request {
2013 ($::WIDTH, $::HEIGHT) 1919 ($::WIDTH, $::HEIGHT)
2014} 1920}
2015 1921
2016sub size_allocate { 1922sub configure {
2017 my ($self, $x, $y, $w, $h) = @_; 1923 my ($self, $x, $y, $w, $h) = @_;
2018 1924
2019 $self->_size_allocate ($x, $y, $w, $h); 1925 $self->SUPER::configure ($x, $y, $w, $h);
2020 1926
2021 $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) 1927 $_->configure ($_->{x}, $_->{y}, $_->size_request)
2022 for @{$self->{children}}; 1928 for @{$self->{children}};
2023} 1929}
2024 1930
2025sub _topleft { 1931sub _topleft {
2026 my ($self, $x, $y) = @_; 1932 my ($self, $x, $y) = @_;
2029} 1935}
2030 1936
2031sub update { 1937sub update {
2032 my ($self) = @_; 1938 my ($self) = @_;
2033 1939
2034 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); 1940 $self->check_size;
2035 ::refresh (); 1941 ::refresh ();
2036} 1942}
2037 1943
2038sub add { 1944sub add {
2039 my ($self, $widget) = @_; 1945 my ($self, $child) = @_;
2040 1946
2041 $self->SUPER::add ($widget); 1947 $self->SUPER::add ($child);
2042
2043 $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request);
2044} 1948}
2045 1949
2046sub on_refresh { 1950sub on_refresh {
2047 my ($self, $id, $cb) = @_; 1951 my ($self, $id, $cb) = @_;
2048 1952

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines