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.125 by root, Mon Apr 17 20:52:15 2006 UTC vs.
Revision 1.140 by root, Thu Apr 20 04:20:52 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;
87 87
88package CFClient::UI::Base; 88package CFClient::UI::Base;
89 89
90use strict; 90use strict;
91 91
92use SDL::OpenGL; 92use CFClient::OpenGL;
93 93
94sub new { 94sub new {
95 my $class = shift; 95 my $class = shift;
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
154 if ($self->{aspect}) {
155 $w = List::Util::min $w, int $h * $self->{aspect};
156 $h = List::Util::min $h, int $w / $self->{aspect};
157 }
158
137 return unless $self->{w} != $w || $self->{h} != $h; 159 return unless $self->{w} != $w || $self->{h} != $h;
138 160
139 $self->{w} = $w; 161 $self->{w} = $w;
140 $self->{h} = $h; 162 $self->{h} = $h;
141 163
142 1 164 $self->size_allocate ($w, $h);
165 $self->update;
143} 166}
144 167
145sub size_allocate { 168sub size_allocate {
146 my ($self, $x, $y, $w, $h) = @_; 169 # nothing to be done
147
148 $self->_size_allocate ($x, $y, $w, $h);
149} 170}
150 171
151# return top left coordinates 172# return top left coordinates
152sub _topleft { 173sub _topleft {
153 my ($self, $x, $y) = @_; 174 my ($self, $x, $y) = @_;
284} 305}
285 306
286sub connect { 307sub connect {
287 my ($self, $signal, $cb) = @_; 308 my ($self, $signal, $cb) = @_;
288 309
289 push @{ $self->{cb}{$signal} }, $cb; 310 push @{ $self->{signal_cb}{$signal} }, $cb;
290} 311}
291 312
292sub emit { 313sub emit {
293 my ($self, $signal, @args) = @_; 314 my ($self, $signal, @args) = @_;
294 315
316 for my $cb (@{$self->{signal_cb}{$signal} || []}) {
295 $_->($self, @args) 317 $cb->($self, @args);
296 for @{$self->{cb}{$signal} || []}; 318 }
297} 319}
298 320
299sub DESTROY { 321sub DESTROY {
300 my ($self) = @_; 322 my ($self) = @_;
301 323
307package CFClient::UI::DrawBG; 329package CFClient::UI::DrawBG;
308 330
309our @ISA = CFClient::UI::Base::; 331our @ISA = CFClient::UI::Base::;
310 332
311use strict; 333use strict;
312use SDL::OpenGL; 334use CFClient::OpenGL;
313 335
314sub new { 336sub new {
315 my $class = shift; 337 my $class = shift;
316 338
317 # range [value, low, high, page] 339 # range [value, low, high, page]
381 $self->{children} = [ 403 $self->{children} = [
382 sort { $a->{z} <=> $b->{z} } 404 sort { $a->{z} <=> $b->{z} }
383 @{$self->{children}}, $child 405 @{$self->{children}}, $child
384 ]; 406 ];
385 407
386 $self->{w} = $self->{h} = -1; 408 $child->check_size;
387 $self->update;
388} 409}
389 410
390sub remove { 411sub remove {
391 my ($self, $widget) = @_; 412 my ($self, $child) = @_;
392 413
414 delete $child->{parent};
415
393 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 416 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
394 417
395 $self->check_size; 418 $self->check_size;
396} 419}
397 420
398sub find_widget { 421sub find_widget {
430 453
431 $class->SUPER::new (children => [$child], %arg) 454 $class->SUPER::new (children => [$child], %arg)
432} 455}
433 456
434sub add { 457sub add {
435 my ($self, $widget) = @_; 458 my ($self, $child) = @_;
436 459
437 $self->{children} = []; 460 $self->{children} = [];
438 461
439 $self->SUPER::add ($widget); 462 $self->SUPER::add ($child);
440} 463}
441 464
442sub remove { 465sub remove {
443 my ($self, $widget) = @_; 466 my ($self, $widget) = @_;
444 467
453sub size_request { 476sub size_request {
454 $_[0]{children}[0]->size_request 477 $_[0]{children}[0]->size_request
455} 478}
456 479
457sub size_allocate { 480sub size_allocate {
458 my ($self, $x, $y, $w, $h) = @_; 481 my ($self, $w, $h) = @_;
459 482
460 $self->_size_allocate ($x, $y, $w, $h) or return;
461
462 $self->{children}[0]->size_allocate (0, 0, $w, $h); 483 $self->{children}[0]->configure (0, 0, $w, $h);
463} 484}
464 485
465############################################################################# 486#############################################################################
466 487
467package CFClient::UI::Window; 488package CFClient::UI::Window;
468 489
469our @ISA = CFClient::UI::Bin::; 490our @ISA = CFClient::UI::Bin::;
470 491
471use SDL::OpenGL; 492use CFClient::OpenGL;
472 493
473sub new { 494sub new {
474 my ($class, %arg) = @_; 495 my ($class, %arg) = @_;
475 496
476 my $self = $class->SUPER::new (%arg); 497 my $self = $class->SUPER::new (%arg);
493 $self->child->draw; 514 $self->child->draw;
494 }; 515 };
495} 516}
496 517
497sub size_allocate { 518sub size_allocate {
498 my ($self, $x, $y, $w, $h) = @_; 519 my ($self, $w, $h) = @_;
499 520
500 $self->_size_allocate ($x, $y, $w, $h) or return;
501
502 $self->child->size_allocate (0, 0, $w, $h); 521 $self->child->configure (0, 0, $w, $h);
503 522
504 $self->render_chld; 523 $self->render_chld;
505} 524}
506 525
507sub _draw { 526sub _draw {
538 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); 557 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
539 558
540 @$self{qw(child_w child_h)} 559 @$self{qw(child_w child_h)}
541} 560}
542 561
543sub size_allocate {
544 my ($self, $x, $y, $w, $h) = @_;
545
546 $self->_size_allocate ($x, $y, $w, $h) or return;
547}
548
549sub _draw { 562sub _draw {
550 my ($self) = @_; 563 my ($self) = @_;
551 564
552 $self->{children}[1]->draw; 565 $self->{children}[1]->draw;
553} 566}
557 570
558package CFClient::UI::Frame; 571package CFClient::UI::Frame;
559 572
560our @ISA = CFClient::UI::Bin::; 573our @ISA = CFClient::UI::Bin::;
561 574
562use SDL::OpenGL; 575use CFClient::OpenGL;
563 576
564sub size_request { 577sub size_request {
565 my ($self) = @_; 578 my ($self) = @_;
566 my $chld = $self->child 579 my $chld = $self->child
567 or return (0, 0); 580 or return (0, 0);
572} 585}
573 586
574sub size_allocate { 587sub size_allocate {
575 my ($self, $x, $y, $w, $h) = @_; 588 my ($self, $x, $y, $w, $h) = @_;
576 589
577 $self->_size_allocate ($x, $y, $w, $h) or return;
578
579 $self->child->size_allocate (2, 2, $w - 4, $h - 4); 590 $self->child->configure (2, 2, $w - 4, $h - 4);
580} 591}
581 592
582sub _draw { 593sub _draw {
583 my ($self) = @_; 594 my ($self) = @_;
584 595
601 612
602package CFClient::UI::FancyFrame; 613package CFClient::UI::FancyFrame;
603 614
604our @ISA = CFClient::UI::Bin::; 615our @ISA = CFClient::UI::Bin::;
605 616
606use SDL::OpenGL; 617use CFClient::OpenGL;
607 618
608my @tex = 619my @tex =
609 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 620 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
610 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 621 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
611 622
615 # TODO: user_x, user_y, overwrite moveto? 626 # TODO: user_x, user_y, overwrite moveto?
616 627
617 $class->SUPER::new ( 628 $class->SUPER::new (
618 bg => [1, 1, 1, 1], 629 bg => [1, 1, 1, 1],
619 border_bg => [1, 1, 1, 1], 630 border_bg => [1, 1, 1, 1],
620 border => int $::FONTSIZE * 0.8, 631 border => 0.8,
621 @_ 632 @_
622 ) 633 )
623} 634}
624 635
636sub border {
637 int $_[0]{border} * $::FONTSIZE
638}
639
625sub size_request { 640sub size_request {
626 my ($self) = @_; 641 my ($self) = @_;
627 642
628 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; 643 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
629 644
630 my ($w, $h) = $self->SUPER::size_request; 645 my ($w, $h) = $self->SUPER::size_request;
631 646
632 ( 647 (
633 $w + $self->{border} * 2, 648 $w + $self->border * 2,
634 $h + $self->{border} * 2, 649 $h + $self->border * 2,
635 ) 650 )
636} 651}
637 652
638sub size_allocate { 653sub size_allocate {
639 my ($self, $x, $y, $w, $h) = @_; 654 my ($self, $w, $h) = @_;
640 655
641 $self->_size_allocate ($x, $y, $w, $h) or return;
642
643 $h -= List::Util::max 0, $self->{border} * 2; 656 $h -= List::Util::max 0, $self->border * 2;
644 $w -= List::Util::max 0, $self->{border} * 2; 657 $w -= List::Util::max 0, $self->border * 2;
645 658
646 $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); 659 $self->child->configure ($self->border, $self->border, $w, $h);
647} 660}
648 661
649sub button_down { 662sub button_down {
650 my ($self, $ev, $x, $y) = @_; 663 my ($self, $ev, $x, $y) = @_;
651 664
665 my $border = $self->border;
666
652 if ($x < $self->{w} && $x >= $self->{w} - $self->{border} 667 if ($x < $self->{w} && $x >= $self->{w} - $border
653 && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { 668 && $y < $self->{h} && $y >= $self->{h} - $border) {
654 669
655 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 670 my ($ox, $oy) = ($ev->{x}, $ev->{y});
656 my ($bw, $bh) = ($self->{w}, $self->{h}); 671 my ($bw, $bh) = ($self->{w}, $self->{h});
657 672
658 $self->{motion} = sub { 673 $self->{motion} = sub {
659 my ($ev, $x, $y) = @_; 674 my ($ev, $x, $y) = @_;
660 675
661 ($x, $y) = ($ev->motion_x, $ev->motion_y); 676 ($x, $y) = ($ev->{x}, $ev->{y});
662 677
663 $self->{user_w} = $bw + $x - $ox; 678 $self->{user_w} = $bw + $x - $ox;
664 $self->{user_h} = $bh + $y - $oy; 679 $self->{user_h} = $bh + $y - $oy;
665 $self->update; 680 $self->check_size;
666 }; 681 };
667 682
668 } elsif ($x >= 0 && $x < $self->{w} 683 } elsif ($x >= 0 && $x < $self->{w}
669 && $y >= 0 && $y < $self->{border}) { 684 && $y >= 0 && $y < $border) {
670 685
671 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 686 my ($ox, $oy) = ($ev->{x}, $ev->{y});
672 my ($bx, $by) = ($self->{x}, $self->{y}); 687 my ($bx, $by) = ($self->{x}, $self->{y});
673 688
674 $self->{motion} = sub { 689 $self->{motion} = sub {
675 my ($ev, $x, $y) = @_; 690 my ($ev, $x, $y) = @_;
676 691
677 ($x, $y) = ($ev->motion_x, $ev->motion_y); 692 ($x, $y) = ($ev->{x}, $ev->{y});
678 693
679 $self->move ($bx + $x - $ox, $by + $y - $oy); 694 $self->move ($bx + $x - $ox, $by + $y - $oy);
680 $self->update; 695 $self->update;
681 }; 696 };
682 } 697 }
703 glEnable GL_BLEND; 718 glEnable GL_BLEND;
704 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 719 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
705 glEnable GL_TEXTURE_2D; 720 glEnable GL_TEXTURE_2D;
706 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 721 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
707 722
723 my $border = $self->border;
724
708 glColor @{ $self->{border_bg} }; 725 glColor @{ $self->{border_bg} };
709 $tex[1]->draw_quad (0, 0, $w, $self->{border}); 726 $tex[1]->draw_quad (0, 0, $w, $border);
710 $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); 727 $tex[3]->draw_quad (0, $border, $border, $ch);
711 $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); 728 $tex[2]->draw_quad ($w - $border, $border, $border, $ch);
712 $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); 729 $tex[4]->draw_quad (0, $h - $border, $w, $border);
713 730
714 my $bg = $tex[0]; 731 my $bg = $tex[0];
715 732
716 # TODO: repeat texture not scale 733 # TODO: repeat texture not scale
717 my $rep_x = $cw / $bg->{w}; 734 my $rep_x = $cw / $bg->{w};
720 glColor @{ $self->{bg} }; 737 glColor @{ $self->{bg} };
721 738
722 $bg->{s} = $rep_x; 739 $bg->{s} = $rep_x;
723 $bg->{t} = $rep_y; 740 $bg->{t} = $rep_y;
724 $bg->{wrap_mode} = 1; 741 $bg->{wrap_mode} = 1;
725 $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); 742 $bg->draw_quad ($border, $border, $cw, $ch);
726 743
727 glDisable GL_TEXTURE_2D; 744 glDisable GL_TEXTURE_2D;
728 glDisable GL_BLEND; 745 glDisable GL_BLEND;
729 746
730 $self->child->draw; 747 $self->child->draw;
736 753
737our @ISA = CFClient::UI::Base::; 754our @ISA = CFClient::UI::Base::;
738 755
739use List::Util qw(max sum); 756use List::Util qw(max sum);
740 757
741use SDL::OpenGL; 758use CFClient::OpenGL;
742 759
743sub new { 760sub new {
744 my $class = shift; 761 my $class = shift;
745 762
746 $class->SUPER::new ( 763 $class->SUPER::new (
753 my ($self, $x, $y, $child) = @_; 770 my ($self, $x, $y, $child) = @_;
754 771
755 $child->set_parent ($self); 772 $child->set_parent ($self);
756 $self->{children}[$y][$x] = $child; 773 $self->{children}[$y][$x] = $child;
757 774
758 $self->{w} = $self->{h} = -1; 775 $child->check_size;
759 $self->update;
760} 776}
761 777
762# TODO: move to container class maybe? send childs a signal on removal? 778# TODO: move to container class maybe? send childs a signal on removal?
763sub clear { 779sub clear {
764 my ($self) = @_; 780 my ($self) = @_;
799 (sum @$hs), 815 (sum @$hs),
800 ) 816 )
801} 817}
802 818
803sub size_allocate { 819sub size_allocate {
804 my ($self, $x, $y, $w, $h) = @_; 820 my ($self, $w, $h) = @_;
805
806 $self->_size_allocate ($x, $y, $w, $h) or return;
807 821
808 my ($ws, $hs) = $self->get_wh; 822 my ($ws, $hs) = $self->get_wh;
809 823
810 my $req_w = sum @$ws; 824 my $req_w = sum @$ws;
811 my $req_h = sum @$hs; 825 my $req_h = sum @$hs;
833 847
834 for my $c (0 .. $#$row) { 848 for my $c (0 .. $#$row) {
835 my $col_w = $ws->[$c]; 849 my $col_w = $ws->[$c];
836 850
837 if (my $widget = $row->[$c]) { 851 if (my $widget = $row->[$c]) {
838 $widget->size_allocate ($x, $y, $col_w, $row_h); 852 $widget->configure ($x, $y, $col_w, $row_h);
839 } 853 }
840 854
841 $x += $col_w; 855 $x += $col_w;
842 } 856 }
843 857
888 (List::Util::max map $_->[1], @alloc), 902 (List::Util::max map $_->[1], @alloc),
889 ) 903 )
890} 904}
891 905
892sub size_allocate { 906sub size_allocate {
893 my ($self, $x, $y, $w, $h) = @_; 907 my ($self, $w, $h) = @_;
894
895 $self->_size_allocate ($x, $y, $w, $h) or return;
896 908
897 ($h, $w) = ($w, $h); 909 ($h, $w) = ($w, $h);
898 910
899 my $children = $self->{children}; 911 my $children = $self->{children};
900 912
922 934
923 my $y = 0; 935 my $y = 0;
924 for (0 .. $#$children) { 936 for (0 .. $#$children) {
925 my $child = $children->[$_]; 937 my $child = $children->[$_];
926 my $h = $h[$_]; 938 my $h = $h[$_];
927 $child->size_allocate ($y, 0, $h, $w); 939 $child->configure ($y, 0, $h, $w);
928 940
929 $y += $h; 941 $y += $h;
930 } 942 }
931 943
932 1 944 1
950 (List::Util::sum map $_->[1], @alloc), 962 (List::Util::sum map $_->[1], @alloc),
951 ) 963 )
952} 964}
953 965
954sub size_allocate { 966sub size_allocate {
955 my ($self, $x, $y, $w, $h) = @_; 967 my ($self, $w, $h) = @_;
956
957 $self->_size_allocate ($x, $y, $w, $h) or return;
958 968
959 my $children = $self->{children}; 969 my $children = $self->{children};
960 970
961 my @h = map +($_->size_request)[1], @$children; 971 my @h = map +($_->size_request)[1], @$children;
962 972
980 990
981 my $y = 0; 991 my $y = 0;
982 for (0 .. $#$children) { 992 for (0 .. $#$children) {
983 my $child = $children->[$_]; 993 my $child = $children->[$_];
984 my $h = $h[$_]; 994 my $h = $h[$_];
985 $child->size_allocate (0, $y, $w, $h); 995 $child->configure (0, $y, $w, $h);
986 996
987 $y += $h; 997 $y += $h;
988 } 998 }
989 999
990 1 1000 1
994 1004
995package CFClient::UI::Label; 1005package CFClient::UI::Label;
996 1006
997our @ISA = CFClient::UI::Base::; 1007our @ISA = CFClient::UI::Base::;
998 1008
999use SDL::OpenGL; 1009use CFClient::OpenGL;
1000 1010
1001sub new { 1011sub new {
1002 my ($class, %arg) = @_; 1012 my ($class, %arg) = @_;
1003 1013
1004 my $self = $class->SUPER::new ( 1014 my $self = $class->SUPER::new (
1005 fg => [1, 1, 1], 1015 fg => [1, 1, 1],
1006 fontsize => $::FONTSIZE, 1016 fontsize => 1,
1007 text => "", 1017 text => "",
1008 align => -1, 1018 align => -1,
1009 valign => -1, 1019 valign => -1,
1010 padding => 2, 1020 padding => 2,
1011 layout => new CFClient::Layout, 1021 layout => new CFClient::Layout,
1050 1060
1051sub size_request { 1061sub size_request {
1052 my ($self) = @_; 1062 my ($self) = @_;
1053 1063
1054 $self->{layout}->set_width; 1064 $self->{layout}->set_width;
1055 $self->{layout}->set_height ($self->{fontsize}); 1065 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1056 1066
1057 my ($w, $h) = $self->{layout}->size; 1067 my ($w, $h) = $self->{layout}->size;
1058 1068
1059 ( 1069 (
1060 $w + $self->{padding} * 2, 1070 $w + $self->{padding} * 2,
1061 $h + $self->{padding} * 2, 1071 $h + $self->{padding} * 2,
1062 ) 1072 )
1063} 1073}
1064 1074
1065sub size_allocate { 1075sub size_allocate {
1066 my ($self, $x, $y, $w, $h) = @_; 1076 my ($self, $w, $h) = @_;
1067
1068 $self->_size_allocate ($x, $y, $w, $h) or return;
1069 1077
1070 delete $self->{texture}; 1078 delete $self->{texture};
1071}
1072
1073sub update {
1074 my ($self) = @_;
1075
1076 delete $self->{texture};
1077 $self->SUPER::update;
1078} 1079}
1079 1080
1080sub _draw { 1081sub _draw {
1081 my ($self) = @_; 1082 my ($self) = @_;
1082 1083
1083 my $tex = $self->{texture} ||= do { 1084 my $tex = $self->{texture} ||= do {
1084 $self->{layout}->set_width ($self->{w}); 1085 $self->{layout}->set_width ($self->{w});
1085 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize}); 1086 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1086 new_from_layout CFClient::Texture $self->{layout} 1087 new_from_layout CFClient::Texture $self->{layout}
1087 }; 1088 };
1088 1089
1089 glEnable GL_BLEND; 1090 glEnable GL_BLEND;
1090 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1091 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1115 1116
1116package CFClient::UI::EntryBase; 1117package CFClient::UI::EntryBase;
1117 1118
1118our @ISA = CFClient::UI::Label::; 1119our @ISA = CFClient::UI::Label::;
1119 1120
1120use SDL; 1121use CFClient::OpenGL;
1121use SDL::OpenGL;
1122 1122
1123sub new { 1123sub new {
1124 my $class = shift; 1124 my $class = shift;
1125 1125
1126 $class->SUPER::new ( 1126 $class->SUPER::new (
1140 1140
1141 delete $self->{cur_h}; 1141 delete $self->{cur_h};
1142 1142
1143 return if $self->{text} eq $text; 1143 return if $self->{text} eq $text;
1144 1144
1145 delete $self->{texture};
1146
1145 $self->{last_activity} = $::NOW; 1147 $self->{last_activity} = $::NOW;
1146 $self->{text} = $text; 1148 $self->{text} = $text;
1147 1149
1148 $text =~ s/./*/g if $self->{hidden}; 1150 $text =~ s/./*/g if $self->{hidden};
1149 $self->{layout}->set_text ("$text "); 1151 $self->{layout}->set_text ("$text ");
1162 1164
1163 ($w + 1, $h) # add 1 for cursor 1165 ($w + 1, $h) # add 1 for cursor
1164} 1166}
1165 1167
1166sub size_allocate { 1168sub size_allocate {
1167 my ($self, $x, $y, $w, $h) = @_; 1169 my ($self, $w, $h) = @_;
1168
1169 $self->SUPER::size_allocate ($x, $y, $w, $h) or return;
1170 1170
1171 $self->_set_text ($self->{text}); 1171 $self->_set_text ($self->{text});
1172} 1172}
1173 1173
1174sub set_text { 1174sub set_text {
1180} 1180}
1181 1181
1182sub key_down { 1182sub key_down {
1183 my ($self, $ev) = @_; 1183 my ($self, $ev) = @_;
1184 1184
1185 my $mod = $ev->key_mod; 1185 my $mod = $ev->{mod};
1186 my $sym = $ev->key_sym; 1186 my $sym = $ev->{sym};
1187
1188 my $uni = $ev->key_unicode; 1187 my $uni = $ev->{unicode};
1189 1188
1190 my $text = $self->get_text; 1189 my $text = $self->get_text;
1191 1190
1192 if ($sym == SDLK_BACKSPACE) { 1191 if ($sym == 8) {
1193 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1192 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1194 } elsif ($sym == SDLK_DELETE) { 1193 } elsif ($sym == 127) {
1195 substr $text, $self->{cursor}, 1, ""; 1194 substr $text, $self->{cursor}, 1, "";
1196 } elsif ($sym == SDLK_LEFT) { 1195 } elsif ($sym == CFClient::SDLK_LEFT) {
1197 --$self->{cursor} if $self->{cursor}; 1196 --$self->{cursor} if $self->{cursor};
1198 } elsif ($sym == SDLK_RIGHT) { 1197 } elsif ($sym == CFClient::SDLK_RIGHT) {
1199 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1198 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1200 } elsif ($sym == SDLK_HOME) { 1199 } elsif ($sym == CFClient::SDLK_HOME) {
1201 $self->{cursor} = 0; 1200 $self->{cursor} = 0;
1202 } elsif ($sym == SDLK_END) { 1201 } elsif ($sym == CFClient::SDLK_END) {
1203 $self->{cursor} = length $text; 1202 $self->{cursor} = length $text;
1204 } elsif ($sym == SDLK_ESCAPE) { 1203 } elsif ($sym == 27) {
1205 $self->emit ('escape'); 1204 $self->emit ('escape');
1206 } elsif ($uni) { 1205 } elsif ($uni) {
1207 substr $text, $self->{cursor}++, 0, chr $uni; 1206 substr $text, $self->{cursor}++, 0, chr $uni;
1208 } 1207 }
1209 1208
1284 1283
1285package CFClient::UI::Entry; 1284package CFClient::UI::Entry;
1286 1285
1287our @ISA = CFClient::UI::EntryBase::; 1286our @ISA = CFClient::UI::EntryBase::;
1288 1287
1289use SDL; 1288use CFClient::OpenGL;
1290use SDL::OpenGL;
1291 1289
1292sub key_down { 1290sub key_down {
1293 my ($self, $ev) = @_; 1291 my ($self, $ev) = @_;
1294 1292
1295 my $sym = $ev->key_sym; 1293 my $sym = $ev->{sym};
1296 1294
1297 if ($sym == SDLK_RETURN) { 1295 if ($sym == 13) {
1298 $self->emit (activate => $self->get_text); 1296 $self->emit (activate => $self->get_text);
1299 $self->update; 1297 $self->update;
1300 1298
1301 } else { 1299 } else {
1302 $self->SUPER::key_down ($ev); 1300 $self->SUPER::key_down ($ev);
1308 1306
1309package CFClient::UI::Button; 1307package CFClient::UI::Button;
1310 1308
1311our @ISA = CFClient::UI::Label::; 1309our @ISA = CFClient::UI::Label::;
1312 1310
1313use SDL; 1311use CFClient::OpenGL;
1314use SDL::OpenGL;
1315 1312
1316my @tex = 1313my @tex =
1317 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1314 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1318 qw(b1_button_active.png); 1315 qw(b1_button_active.png);
1319 1316
1324 padding => 4, 1321 padding => 4,
1325 fg => [1, 1, 1], 1322 fg => [1, 1, 1],
1326 bg => [1, 1, 1, 0.2], 1323 bg => [1, 1, 1, 0.2],
1327 active_fg => [0, 0, 1], 1324 active_fg => [0, 0, 1],
1328 can_hover => 1, 1325 can_hover => 1,
1326 align => 0,
1327 valign => 0,
1329 @_ 1328 @_
1330 ) 1329 )
1331} 1330}
1332 1331
1333sub button_up { 1332sub button_up {
1370 1369
1371my @tex = 1370my @tex =
1372 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1371 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1373 qw(c1_checkbox_bg.png c1_checkbox_active.png); 1372 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1374 1373
1375use SDL; 1374use CFClient::OpenGL;
1376use SDL::OpenGL;
1377 1375
1378sub new { 1376sub new {
1379 my $class = shift; 1377 my $class = shift;
1380 1378
1381 $class->SUPER::new ( 1379 $class->SUPER::new (
1392 my ($self) = @_; 1390 my ($self) = @_;
1393 1391
1394 ($self->{padding} * 2 + 6) x 2 1392 ($self->{padding} * 2 + 6) x 2
1395} 1393}
1396 1394
1397sub size_allocate {
1398 my ($self, $x, $y, $w, $h) = @_;
1399
1400 $self->_size_allocate ($x, $y, $w, $h) or return;
1401}
1402
1403sub button_down { 1395sub button_down {
1404 my ($self, $ev, $x, $y) = @_; 1396 my ($self, $ev, $x, $y) = @_;
1405 1397
1406 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} 1398 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding}
1407 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { 1399 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) {
1437 1429
1438package CFClient::UI::VGauge; 1430package CFClient::UI::VGauge;
1439 1431
1440our @ISA = CFClient::UI::Base::; 1432our @ISA = CFClient::UI::Base::;
1441 1433
1442use SDL::OpenGL; 1434use CFClient::OpenGL;
1443 1435
1444my %tex = ( 1436my %tex = (
1445 food => [ 1437 food => [
1446 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1438 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1447 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1439 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1462 1454
1463# eg. VGauge->new (gauge => 'food'), default gauge: food 1455# eg. VGauge->new (gauge => 'food'), default gauge: food
1464sub new { 1456sub new {
1465 my $class = shift; 1457 my $class = shift;
1466 1458
1467 my $self = $class->SUPER::new (gauge => 'food', @_); 1459 my $self = $class->SUPER::new (
1460 gauge => 'food',
1461 @_
1462 );
1463
1464 $self->{aspect} = $tex{$self->{gauge}}[0]{w} / $tex{$self->{gauge}}[0]{h};
1468 1465
1469 $self 1466 $self
1470} 1467}
1471 1468
1472sub size_request { 1469sub size_request {
1473 my ($self) = @_; 1470 my ($self) = @_;
1474 1471
1475 ($self->{w}, $self->{h}) 1472 my $tex = $tex{$self->{gauge}}[0];
1473
1474 @$tex{qw(w h)}
1476} 1475}
1477 1476
1478sub set_max { 1477sub set_max {
1479 my ($self, $max) = @_; 1478 my ($self, $max) = @_;
1479
1480 $self->{max_val} = $max; 1480 $self->{max_val} = $max;
1481} 1481}
1482 1482
1483sub set_value { 1483sub set_value {
1484 my ($self, $val, $max) = @_; 1484 my ($self, $val, $max) = @_;
1513 my $h1 = $self->{h} - $ycut * $self->{h}; 1513 my $h1 = $self->{h} - $ycut * $self->{h};
1514 my $h2 = $ycut * $self->{h}; 1514 my $h2 = $ycut * $self->{h};
1515 1515
1516 my $yp = 0; 1516 my $yp = 0;
1517 1517
1518 glBindTexture (GL_TEXTURE_2D, $t1->{name}); 1518 glBindTexture GL_TEXTURE_2D, $t1->{name};
1519 glBegin (GL_QUADS); 1519 glBegin GL_QUADS;
1520 glTexCoord (0, 0); glVertex (0 , $yp); 1520 glTexCoord 0 , 0; glVertex 0 , $yp;
1521 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp + $h1); 1521 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1;
1522 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp + $h1); 1522 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1;
1523 glTexCoord (1, 0); glVertex (0 + $w, $yp); 1523 glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp;
1524 glEnd (); 1524 glEnd;
1525 1525
1526 $yp += $h1; 1526 $yp += $h1;
1527 1527
1528 glBindTexture (GL_TEXTURE_2D, $t2->{name}); 1528 glBindTexture GL_TEXTURE_2D, $t2->{name};
1529 glBegin (GL_QUADS); 1529 glBegin GL_QUADS;
1530 glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp); 1530 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp;
1531 glTexCoord (0, 1); glVertex (0 , $yp + $h2); 1531 glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2;
1532 glTexCoord (1, 1); glVertex (0 + $w, $yp + $h2); 1532 glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2;
1533 glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp); 1533 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp;
1534 glEnd (); 1534 glEnd;
1535 1535
1536 glDisable GL_BLEND; 1536 glDisable GL_BLEND;
1537 glDisable GL_TEXTURE_2D; 1537 glDisable GL_TEXTURE_2D;
1538} 1538}
1539 1539
1541 1541
1542package CFClient::UI::Slider; 1542package CFClient::UI::Slider;
1543 1543
1544use strict; 1544use strict;
1545 1545
1546use SDL::OpenGL; 1546use CFClient::OpenGL;
1547 1547
1548our @ISA = CFClient::UI::DrawBG::; 1548our @ISA = CFClient::UI::DrawBG::;
1549 1549
1550my @tex = 1550my @tex =
1551 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1551 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1561 # TODO: calculations are off 1561 # TODO: calculations are off
1562 my $self = $class->SUPER::new ( 1562 my $self = $class->SUPER::new (
1563 fg => [1, 1, 1], 1563 fg => [1, 1, 1],
1564 active_fg => [0, 0, 0], 1564 active_fg => [0, 0, 0],
1565 range => [0, 0, 100, 10], 1565 range => [0, 0, 100, 10],
1566 req_w => 40, 1566 req_w => 20,
1567 req_h => 13, 1567 req_h => 20,
1568 vertical => 0, 1568 vertical => 0,
1569 can_hover => 1, 1569 can_hover => 1,
1570 inner_pad => 5, 1570 inner_pad => 5,
1571 @_ 1571 @_
1572 ); 1572 );
1676 1676
1677package CFClient::UI::TextView; 1677package CFClient::UI::TextView;
1678 1678
1679our @ISA = CFClient::UI::HBox::; 1679our @ISA = CFClient::UI::HBox::;
1680 1680
1681use SDL::OpenGL; 1681use CFClient::OpenGL;
1682 1682
1683sub new { 1683sub new {
1684 my $class = shift; 1684 my $class = shift;
1685 1685
1686 my $self = $class->SUPER::new ( 1686 my $self = $class->SUPER::new (
1687 req_w => $::WIDTH / 6,
1688 req_h => $::HEIGHT / 6,
1689 fontsize => $::FONTSIZE, 1687 fontsize => 1,
1690 @_, 1688 @_,
1691 1689
1692 layout => (new CFClient::Layout), 1690 layout => (new CFClient::Layout),
1693 par => [], 1691 par => [],
1694 height => 0, 1692 height => 0,
1715sub text_height { 1713sub text_height {
1716 my ($self, $text) = @_; 1714 my ($self, $text) = @_;
1717 1715
1718 my $layout = $self->{layout}; 1716 my $layout = $self->{layout};
1719 1717
1720 $layout->set_height ($self->{fontsize}); 1718 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
1721 $layout->set_width ($self->{w}); 1719 $layout->set_width ($self->{w});
1722 $layout->set_text ($text); 1720 $layout->set_text ($text);
1723 1721
1724 ($layout->size)[1] 1722 ($layout->size)[1]
1725} 1723}
1729 1727
1730 $self->{need_reflow}++; 1728 $self->{need_reflow}++;
1731 $self->update; 1729 $self->update;
1732} 1730}
1733 1731
1734sub size_request {
1735 my ($self) = @_;
1736
1737 ($self->{req_w}, $self->{req_h})
1738}
1739
1740sub size_allocate { 1732sub size_allocate {
1741 my ($self, $x, $y, $w, $h) = @_; 1733 my ($self, $w, $h) = @_;
1742 1734
1743 $self->SUPER::size_allocate ($x, $y, $w, $h) or return; 1735 $self->SUPER::size_allocate ($w, $h);
1744 1736
1745 $self->{layout}->set_height ($self->{fontsize}); 1737 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1746 $self->{layout}->set_width ($self->{w}); 1738 $self->{layout}->set_width ($self->{children}[0]{w});
1747 1739
1748 $self->reflow; 1740 $self->reflow;
1749 $self->update;
1750} 1741}
1751 1742
1752sub add_paragraph { 1743sub add_paragraph {
1753 my ($self, $color, $text) = @_; 1744 my ($self, $color, $text) = @_;
1754 1745
1839 1830
1840} 1831}
1841 1832
1842############################################################################# 1833#############################################################################
1843 1834
1844package CFClient::UI::MapWidget;
1845
1846use strict;
1847
1848use List::Util qw(min max);
1849
1850use SDL;
1851use SDL::OpenGL;
1852
1853our @ISA = CFClient::UI::Base::;
1854
1855sub new {
1856 my $class = shift;
1857
1858 $class->SUPER::new (
1859 z => -1,
1860 can_focus => 1,
1861 list => (glGenLists 1),
1862 @_
1863 )
1864}
1865
1866sub key_down {
1867 print "MAPKEYDOWN\n";
1868}
1869
1870sub key_up {
1871}
1872
1873sub button_down {
1874 my ($self, $ev, $x, $y) = @_;
1875
1876 $self->focus_in;
1877
1878 if ($ev->button == 2) {
1879 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
1880 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
1881
1882 $self->{motion} = sub {
1883 my ($ev, $x, $y) = @_;
1884
1885 ($x, $y) = ($ev->motion_x, $ev->motion_y);
1886
1887 $::CFG->{map_shift_x} = $bw + $x - $ox;
1888 $::CFG->{map_shift_y} = $bh + $y - $oy;
1889
1890 $self->update;
1891 };
1892 }
1893}
1894
1895sub button_up {
1896 my ($self, $ev, $x, $y) = @_;
1897
1898 delete $self->{motion};
1899}
1900
1901sub mouse_motion {
1902 my ($self, $ev, $x, $y) = @_;
1903
1904 $self->{motion}->($ev, $x, $y) if $self->{motion};
1905}
1906
1907sub size_request {
1908 (
1909 1 + 32 * int $::WIDTH / 32,
1910 1 + 32 * int $::HEIGHT / 32,
1911 )
1912}
1913
1914sub update {
1915 my ($self) = @_;
1916
1917 $self->{need_update} = 1;
1918 $self->SUPER::update;
1919}
1920
1921sub draw {
1922 my ($self) = @_;
1923
1924 if (delete $self->{need_update}) {
1925 glNewList $self->{list}, GL_COMPILE;
1926
1927 if ($::MAP) {
1928 my $sw = int $::WIDTH / 32;
1929 my $sh = int $::HEIGHT / 32;
1930
1931 my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
1932 my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
1933
1934 glTranslate $sx0 - 32, $sy0 - 32, 0;
1935
1936 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
1937
1938 if ($::CFG->{fow_enable}) {
1939 if ($::CFG->{fow_smooth}) { # smooth fog of war
1940 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER;
1941 glConvolutionFilter2D
1942 GL_CONVOLUTION_2D,
1943 GL_ALPHA,
1944 3, 3,
1945 GL_ALPHA, GL_FLOAT,
1946 pack "f*",
1947 0.1, 0.1, 0.1,
1948 0.1, 0.2, 0.1,
1949 0.1, 0.1, 0.1,
1950 ;
1951 glEnable GL_CONVOLUTION_2D;
1952 }
1953
1954 $self->{fow_texture} = new CFClient::Texture
1955 w => $w,
1956 h => $h,
1957 data => $data,
1958 internalformat => GL_ALPHA,
1959 format => GL_ALPHA;
1960
1961 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
1962
1963 glEnable GL_BLEND;
1964 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1965 glEnable GL_TEXTURE_2D;
1966 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1967
1968 glColor +($::CFG->{fow_intensity}) x 3, 1;
1969 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
1970
1971 glDisable GL_TEXTURE_2D;
1972 glDisable GL_BLEND;
1973 }
1974
1975 # HACK BEGIN
1976 {
1977 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove
1978 my ($w, $h) = (250, 250);
1979
1980 glEnable GL_BLEND;
1981 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1982 glEnable GL_TEXTURE_2D;
1983 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1984
1985 $self->{mapmap_texture} =
1986 new CFClient::Texture
1987 w => $w,
1988 h => $h,
1989 data => $::MAP->mapmap ($w, $h),
1990 type => GL_UNSIGNED_INT_8_8_8_8_REV;
1991
1992 $self->{mapmap_texture}->draw_quad (100, 100);
1993
1994 glDisable GL_TEXTURE_2D;
1995 glDisable GL_BLEND;
1996 }
1997 # HACK END
1998 }
1999
2000 glEndList;
2001 }
2002
2003 glPushMatrix;
2004 glCallList $self->{list};
2005 glPopMatrix;
2006
2007 if ($FOCUS != $self) {
2008 glColor 64/255, 64/255, 64/255;
2009 glLogicOp GL_AND;
2010 glEnable GL_COLOR_LOGIC_OP;
2011 glBegin GL_QUADS;
2012 glVertex 0, 0;
2013 glVertex 0, $::HEIGHT;
2014 glVertex $::WIDTH, $::HEIGHT;
2015 glVertex $::WIDTH, 0;
2016 glEnd;
2017 glDisable GL_COLOR_LOGIC_OP;
2018 }
2019}
2020
2021my %DIR = (
2022 SDLK_KP8, [1, "north"],
2023 SDLK_KP9, [2, "northeast"],
2024 SDLK_KP6, [3, "east"],
2025 SDLK_KP3, [4, "southeast"],
2026 SDLK_KP2, [5, "south"],
2027 SDLK_KP1, [6, "southwest"],
2028 SDLK_KP4, [7, "west"],
2029 SDLK_KP7, [8, "northwest"],
2030
2031 SDLK_UP, [1, "north"],
2032 SDLK_RIGHT, [3, "east"],
2033 SDLK_DOWN, [5, "south"],
2034 SDLK_LEFT, [7, "west"],
2035);
2036
2037sub key_down {
2038 my ($self, $ev) = @_;
2039
2040 my $mod = $ev->key_mod;
2041 my $sym = $ev->key_sym;
2042
2043 if ($sym == SDLK_KP5) {
2044 $::CONN->user_send ("stay fire");
2045 } elsif ($sym == SDLK_a) {
2046 $::CONN->user_send ("apply");
2047 } elsif ($sym == SDLK_QUOTE) {
2048 $self->emit ('activate_console');
2049 } elsif ($sym == SDLK_SLASH) {
2050 $self->emit ('activate_console' => '/');
2051 } elsif (exists $DIR{$sym}) {
2052 if ($mod & KMOD_SHIFT) {
2053 $self->{shft}++;
2054 $::CONN->user_send ("fire $DIR{$sym}[0]");
2055 } elsif ($mod & KMOD_CTRL) {
2056 $self->{ctrl}++;
2057 $::CONN->user_send ("run $DIR{$sym}[0]");
2058 } else {
2059 $::CONN->user_send ("$DIR{$sym}[1]");
2060 }
2061 }
2062}
2063
2064sub key_up {
2065 my ($self, $ev) = @_;
2066
2067 my $mod = $ev->key_mod;
2068 my $sym = $ev->key_sym;
2069
2070 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
2071 $::CONN->user_send ("fire_stop");
2072 }
2073 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
2074 $::CONN->user_send ("run_stop");
2075 }
2076}
2077
2078#############################################################################
2079
2080package CFClient::UI::Animator; 1835package CFClient::UI::Animator;
2081 1836
2082use SDL::OpenGL; 1837use CFClient::OpenGL;
2083 1838
2084our @ISA = CFClient::UI::Bin::; 1839our @ISA = CFClient::UI::Bin::;
2085 1840
2086sub moveto { 1841sub moveto {
2087 my ($self, $x, $y) = @_; 1842 my ($self, $x, $y) = @_;
2160 1915
2161package CFClient::UI::Root; 1916package CFClient::UI::Root;
2162 1917
2163our @ISA = CFClient::UI::Container::; 1918our @ISA = CFClient::UI::Container::;
2164 1919
2165use SDL::OpenGL; 1920use CFClient::OpenGL;
2166 1921
2167sub check_size { 1922sub check_size {
2168 my ($self) = @_; 1923 my ($self) = @_;
2169 1924
2170 $self->size_allocate (0, 0, $::WITH, $::HEIGHT); 1925 $self->configure (0, 0, $::WITH, $::HEIGHT);
2171} 1926}
2172 1927
2173sub size_request { 1928sub size_request {
2174 ($::WIDTH, $::HEIGHT) 1929 ($::WIDTH, $::HEIGHT)
2175} 1930}
2176 1931
2177sub size_allocate { 1932sub configure {
2178 my ($self, $x, $y, $w, $h) = @_; 1933 my ($self, $x, $y, $w, $h) = @_;
2179 1934
2180 $self->_size_allocate ($x, $y, $w, $h); 1935 $self->SUPER::configure ($x, $y, $w, $h);
2181 1936
2182 $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) 1937 $_->configure ($_->{x}, $_->{y}, $_->size_request)
2183 for @{$self->{children}}; 1938 for @{$self->{children}};
2184} 1939}
2185 1940
2186sub _topleft { 1941sub _topleft {
2187 my ($self, $x, $y) = @_; 1942 my ($self, $x, $y) = @_;
2195 $self->check_size; 1950 $self->check_size;
2196 ::refresh (); 1951 ::refresh ();
2197} 1952}
2198 1953
2199sub add { 1954sub add {
2200 my ($self, $widget) = @_; 1955 my ($self, $child) = @_;
2201 1956
2202 $self->SUPER::add ($widget); 1957 $self->SUPER::add ($child);
2203
2204 $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request);
2205} 1958}
2206 1959
2207sub on_refresh { 1960sub on_refresh {
2208 my ($self, $id, $cb) = @_; 1961 my ($self, $id, $cb) = @_;
2209 1962

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines