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.123 by root, Mon Apr 17 19:50:22 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) = @_;
260 my ($self, $parent) = @_; 281 my ($self, $parent) = @_;
261 282
262 Scalar::Util::weaken ($self->{parent} = $parent); 283 Scalar::Util::weaken ($self->{parent} = $parent);
263} 284}
264 285
286sub check_size {
287 my ($self) = @_;
288
289 my ($w, $h) = $self->size_request;
290
291 if ($w != $self->{req_w} || $h != $self->{req_h}) {
292 $self->{req_w} = $w;
293 $self->{req_h} = $h;
294
295 $self->{parent}->check_size
296 if $self->{parent};
297 }
298}
299
265sub update { 300sub update {
266 my ($self) = @_; 301 my ($self) = @_;
267 302
268 $self->{parent}->update 303 $self->{parent}->update
269 if $self->{parent}; 304 if $self->{parent};
270} 305}
271 306
272sub connect { 307sub connect {
273 my ($self, $signal, $cb) = @_; 308 my ($self, $signal, $cb) = @_;
274 309
275 push @{ $self->{cb}{$signal} }, $cb; 310 push @{ $self->{signal_cb}{$signal} }, $cb;
276} 311}
277 312
278sub emit { 313sub emit {
279 my ($self, $signal, @args) = @_; 314 my ($self, $signal, @args) = @_;
280 315
316 for my $cb (@{$self->{signal_cb}{$signal} || []}) {
281 $_->($self, @args) 317 $cb->($self, @args);
282 for @{$self->{cb}{$signal} || []}; 318 }
283} 319}
284 320
285sub DESTROY { 321sub DESTROY {
286 my ($self) = @_; 322 my ($self) = @_;
287 323
293package CFClient::UI::DrawBG; 329package CFClient::UI::DrawBG;
294 330
295our @ISA = CFClient::UI::Base::; 331our @ISA = CFClient::UI::Base::;
296 332
297use strict; 333use strict;
298use SDL::OpenGL; 334use CFClient::OpenGL;
299 335
300sub new { 336sub new {
301 my $class = shift; 337 my $class = shift;
302 338
303 # range [value, low, high, page] 339 # range [value, low, high, page]
367 $self->{children} = [ 403 $self->{children} = [
368 sort { $a->{z} <=> $b->{z} } 404 sort { $a->{z} <=> $b->{z} }
369 @{$self->{children}}, $child 405 @{$self->{children}}, $child
370 ]; 406 ];
371 407
372 $self->{w} = $self->{h} = -1; 408 $child->check_size;
373 $self->update;
374} 409}
375 410
376sub remove { 411sub remove {
377 my ($self, $widget) = @_; 412 my ($self, $child) = @_;
378 413
414 delete $child->{parent};
415
379 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 416 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
380 417
381 $self->size_allocate (0, 0, $self->{w}, $self->{h}); 418 $self->check_size;
382} 419}
383 420
384sub find_widget { 421sub find_widget {
385 my ($self, $x, $y) = @_; 422 my ($self, $x, $y) = @_;
386 423
416 453
417 $class->SUPER::new (children => [$child], %arg) 454 $class->SUPER::new (children => [$child], %arg)
418} 455}
419 456
420sub add { 457sub add {
421 my ($self, $widget) = @_; 458 my ($self, $child) = @_;
422 459
423 $self->{children} = []; 460 $self->{children} = [];
424 461
425 $self->SUPER::add ($widget); 462 $self->SUPER::add ($child);
426} 463}
427 464
428sub remove { 465sub remove {
429 my ($self, $widget) = @_; 466 my ($self, $widget) = @_;
430 467
439sub size_request { 476sub size_request {
440 $_[0]{children}[0]->size_request 477 $_[0]{children}[0]->size_request
441} 478}
442 479
443sub size_allocate { 480sub size_allocate {
444 my ($self, $x, $y, $w, $h) = @_; 481 my ($self, $w, $h) = @_;
445 482
446 $self->_size_allocate ($x, $y, $w, $h) or return;
447
448 $self->{children}[0]->size_allocate (0, 0, $w, $h); 483 $self->{children}[0]->configure (0, 0, $w, $h);
449} 484}
450 485
451############################################################################# 486#############################################################################
452 487
453package CFClient::UI::Window; 488package CFClient::UI::Window;
454 489
455our @ISA = CFClient::UI::Bin::; 490our @ISA = CFClient::UI::Bin::;
456 491
457use SDL::OpenGL; 492use CFClient::OpenGL;
458 493
459sub new { 494sub new {
460 my ($class, %arg) = @_; 495 my ($class, %arg) = @_;
461 496
462 my $self = $class->SUPER::new (%arg); 497 my $self = $class->SUPER::new (%arg);
479 $self->child->draw; 514 $self->child->draw;
480 }; 515 };
481} 516}
482 517
483sub size_allocate { 518sub size_allocate {
484 my ($self, $x, $y, $w, $h) = @_; 519 my ($self, $w, $h) = @_;
485 520
486 $self->_size_allocate ($x, $y, $w, $h) or return;
487
488 $self->child->size_allocate (0, 0, $w, $h); 521 $self->child->configure (0, 0, $w, $h);
489 522
490 $self->render_chld; 523 $self->render_chld;
491} 524}
492 525
493sub _draw { 526sub _draw {
509 glDisable GL_TEXTURE_2D; 542 glDisable GL_TEXTURE_2D;
510} 543}
511 544
512############################################################################# 545#############################################################################
513 546
547package CFClient::UI::ViewPort;
548
549our @ISA = CFClient::UI::Window::;
550
551sub new { die }
552
553sub size_request {
554 my ($self) = @_;
555
556 @$self{qw(child_w child_h)} = $self->child->size_request;
557 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
558
559 @$self{qw(child_w child_h)}
560}
561
562sub _draw {
563 my ($self) = @_;
564
565 $self->{children}[1]->draw;
566}
567
568
569#############################################################################
570
514package CFClient::UI::Frame; 571package CFClient::UI::Frame;
515 572
516our @ISA = CFClient::UI::Bin::; 573our @ISA = CFClient::UI::Bin::;
517 574
518use SDL::OpenGL; 575use CFClient::OpenGL;
519 576
520sub size_request { 577sub size_request {
521 my ($self) = @_; 578 my ($self) = @_;
522 my $chld = $self->child 579 my $chld = $self->child
523 or return (0, 0); 580 or return (0, 0);
528} 585}
529 586
530sub size_allocate { 587sub size_allocate {
531 my ($self, $x, $y, $w, $h) = @_; 588 my ($self, $x, $y, $w, $h) = @_;
532 589
533 $self->_size_allocate ($x, $y, $w, $h) or return;
534
535 $self->child->size_allocate (2, 2, $w - 4, $h - 4); 590 $self->child->configure (2, 2, $w - 4, $h - 4);
536} 591}
537 592
538sub _draw { 593sub _draw {
539 my ($self) = @_; 594 my ($self) = @_;
540 595
557 612
558package CFClient::UI::FancyFrame; 613package CFClient::UI::FancyFrame;
559 614
560our @ISA = CFClient::UI::Bin::; 615our @ISA = CFClient::UI::Bin::;
561 616
562use SDL::OpenGL; 617use CFClient::OpenGL;
563 618
564my @tex = 619my @tex =
565 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 620 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
566 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);
567 622
571 # TODO: user_x, user_y, overwrite moveto? 626 # TODO: user_x, user_y, overwrite moveto?
572 627
573 $class->SUPER::new ( 628 $class->SUPER::new (
574 bg => [1, 1, 1, 1], 629 bg => [1, 1, 1, 1],
575 border_bg => [1, 1, 1, 1], 630 border_bg => [1, 1, 1, 1],
576 border => int $::FONTSIZE * 0.8, 631 border => 0.8,
577 @_ 632 @_
578 ) 633 )
579} 634}
580 635
636sub border {
637 int $_[0]{border} * $::FONTSIZE
638}
639
581sub size_request { 640sub size_request {
582 my ($self) = @_; 641 my ($self) = @_;
583 642
584 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};
585 644
586 my ($w, $h) = $self->SUPER::size_request; 645 my ($w, $h) = $self->SUPER::size_request;
587 646
588 ( 647 (
589 $w + $self->{border} * 2, 648 $w + $self->border * 2,
590 $h + $self->{border} * 2, 649 $h + $self->border * 2,
591 ) 650 )
592} 651}
593 652
594sub size_allocate { 653sub size_allocate {
595 my ($self, $x, $y, $w, $h) = @_; 654 my ($self, $w, $h) = @_;
596 655
597 $self->_size_allocate ($x, $y, $w, $h) or return;
598
599 $h -= List::Util::max 0, $self->{border} * 2; 656 $h -= List::Util::max 0, $self->border * 2;
600 $w -= List::Util::max 0, $self->{border} * 2; 657 $w -= List::Util::max 0, $self->border * 2;
601 658
602 $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); 659 $self->child->configure ($self->border, $self->border, $w, $h);
603} 660}
604 661
605sub button_down { 662sub button_down {
606 my ($self, $ev, $x, $y) = @_; 663 my ($self, $ev, $x, $y) = @_;
607 664
665 my $border = $self->border;
666
608 if ($x < $self->{w} && $x >= $self->{w} - $self->{border} 667 if ($x < $self->{w} && $x >= $self->{w} - $border
609 && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { 668 && $y < $self->{h} && $y >= $self->{h} - $border) {
610 669
611 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 670 my ($ox, $oy) = ($ev->{x}, $ev->{y});
612 my ($bw, $bh) = ($self->{w}, $self->{h}); 671 my ($bw, $bh) = ($self->{w}, $self->{h});
613 672
614 $self->{motion} = sub { 673 $self->{motion} = sub {
615 my ($ev, $x, $y) = @_; 674 my ($ev, $x, $y) = @_;
616 675
617 ($x, $y) = ($ev->motion_x, $ev->motion_y); 676 ($x, $y) = ($ev->{x}, $ev->{y});
618 677
619 $self->{user_w} = $bw + $x - $ox; 678 $self->{user_w} = $bw + $x - $ox;
620 $self->{user_h} = $bh + $y - $oy; 679 $self->{user_h} = $bh + $y - $oy;
621 $self->update; 680 $self->check_size;
622 }; 681 };
623 682
624 } elsif ($x >= 0 && $x < $self->{w} 683 } elsif ($x >= 0 && $x < $self->{w}
625 && $y >= 0 && $y < $self->{border}) { 684 && $y >= 0 && $y < $border) {
626 685
627 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 686 my ($ox, $oy) = ($ev->{x}, $ev->{y});
628 my ($bx, $by) = ($self->{x}, $self->{y}); 687 my ($bx, $by) = ($self->{x}, $self->{y});
629 688
630 $self->{motion} = sub { 689 $self->{motion} = sub {
631 my ($ev, $x, $y) = @_; 690 my ($ev, $x, $y) = @_;
632 691
633 ($x, $y) = ($ev->motion_x, $ev->motion_y); 692 ($x, $y) = ($ev->{x}, $ev->{y});
634 693
635 $self->move ($bx + $x - $ox, $by + $y - $oy); 694 $self->move ($bx + $x - $ox, $by + $y - $oy);
636 $self->update; 695 $self->update;
637 }; 696 };
638 } 697 }
659 glEnable GL_BLEND; 718 glEnable GL_BLEND;
660 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 719 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
661 glEnable GL_TEXTURE_2D; 720 glEnable GL_TEXTURE_2D;
662 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 721 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
663 722
723 my $border = $self->border;
724
664 glColor @{ $self->{border_bg} }; 725 glColor @{ $self->{border_bg} };
665 $tex[1]->draw_quad (0, 0, $w, $self->{border}); 726 $tex[1]->draw_quad (0, 0, $w, $border);
666 $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); 727 $tex[3]->draw_quad (0, $border, $border, $ch);
667 $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); 728 $tex[2]->draw_quad ($w - $border, $border, $border, $ch);
668 $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); 729 $tex[4]->draw_quad (0, $h - $border, $w, $border);
669 730
670 my $bg = $tex[0]; 731 my $bg = $tex[0];
671 732
672 # TODO: repeat texture not scale 733 # TODO: repeat texture not scale
673 my $rep_x = $cw / $bg->{w}; 734 my $rep_x = $cw / $bg->{w};
676 glColor @{ $self->{bg} }; 737 glColor @{ $self->{bg} };
677 738
678 $bg->{s} = $rep_x; 739 $bg->{s} = $rep_x;
679 $bg->{t} = $rep_y; 740 $bg->{t} = $rep_y;
680 $bg->{wrap_mode} = 1; 741 $bg->{wrap_mode} = 1;
681 $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); 742 $bg->draw_quad ($border, $border, $cw, $ch);
682 743
683 glDisable GL_TEXTURE_2D; 744 glDisable GL_TEXTURE_2D;
684 glDisable GL_BLEND; 745 glDisable GL_BLEND;
685 746
686 $self->child->draw; 747 $self->child->draw;
692 753
693our @ISA = CFClient::UI::Base::; 754our @ISA = CFClient::UI::Base::;
694 755
695use List::Util qw(max sum); 756use List::Util qw(max sum);
696 757
697use SDL::OpenGL; 758use CFClient::OpenGL;
698 759
699sub new { 760sub new {
700 my $class = shift; 761 my $class = shift;
701 762
702 $class->SUPER::new ( 763 $class->SUPER::new (
709 my ($self, $x, $y, $child) = @_; 770 my ($self, $x, $y, $child) = @_;
710 771
711 $child->set_parent ($self); 772 $child->set_parent ($self);
712 $self->{children}[$y][$x] = $child; 773 $self->{children}[$y][$x] = $child;
713 774
714 $self->{w} = $self->{h} = -1; 775 $child->check_size;
715 $self->update;
716} 776}
717 777
718# 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?
719sub clear { 779sub clear {
720 my ($self) = @_; 780 my ($self) = @_;
755 (sum @$hs), 815 (sum @$hs),
756 ) 816 )
757} 817}
758 818
759sub size_allocate { 819sub size_allocate {
760 my ($self, $x, $y, $w, $h) = @_; 820 my ($self, $w, $h) = @_;
761
762 $self->_size_allocate ($x, $y, $w, $h) or return;
763 821
764 my ($ws, $hs) = $self->get_wh; 822 my ($ws, $hs) = $self->get_wh;
765 823
766 my $req_w = sum @$ws; 824 my $req_w = sum @$ws;
767 my $req_h = sum @$hs; 825 my $req_h = sum @$hs;
789 847
790 for my $c (0 .. $#$row) { 848 for my $c (0 .. $#$row) {
791 my $col_w = $ws->[$c]; 849 my $col_w = $ws->[$c];
792 850
793 if (my $widget = $row->[$c]) { 851 if (my $widget = $row->[$c]) {
794 $widget->size_allocate ($x, $y, $col_w, $row_h); 852 $widget->configure ($x, $y, $col_w, $row_h);
795 } 853 }
796 854
797 $x += $col_w; 855 $x += $col_w;
798 } 856 }
799 857
844 (List::Util::max map $_->[1], @alloc), 902 (List::Util::max map $_->[1], @alloc),
845 ) 903 )
846} 904}
847 905
848sub size_allocate { 906sub size_allocate {
849 my ($self, $x, $y, $w, $h) = @_; 907 my ($self, $w, $h) = @_;
850
851 $self->_size_allocate ($x, $y, $w, $h);
852 908
853 ($h, $w) = ($w, $h); 909 ($h, $w) = ($w, $h);
854 910
855 my $children = $self->{children}; 911 my $children = $self->{children};
856 912
878 934
879 my $y = 0; 935 my $y = 0;
880 for (0 .. $#$children) { 936 for (0 .. $#$children) {
881 my $child = $children->[$_]; 937 my $child = $children->[$_];
882 my $h = $h[$_]; 938 my $h = $h[$_];
883 $child->size_allocate ($y, 0, $h, $w); 939 $child->configure ($y, 0, $h, $w);
884 940
885 $y += $h; 941 $y += $h;
886 } 942 }
943
944 1
887} 945}
888 946
889############################################################################# 947#############################################################################
890 948
891package CFClient::UI::VBox; 949package CFClient::UI::VBox;
904 (List::Util::sum map $_->[1], @alloc), 962 (List::Util::sum map $_->[1], @alloc),
905 ) 963 )
906} 964}
907 965
908sub size_allocate { 966sub size_allocate {
909 my ($self, $x, $y, $w, $h) = @_; 967 my ($self, $w, $h) = @_;
910
911 $self->_size_allocate ($x, $y, $w, $h);
912 968
913 my $children = $self->{children}; 969 my $children = $self->{children};
914 970
915 my @h = map +($_->size_request)[1], @$children; 971 my @h = map +($_->size_request)[1], @$children;
916 972
934 990
935 my $y = 0; 991 my $y = 0;
936 for (0 .. $#$children) { 992 for (0 .. $#$children) {
937 my $child = $children->[$_]; 993 my $child = $children->[$_];
938 my $h = $h[$_]; 994 my $h = $h[$_];
939 $child->size_allocate (0, $y, $w, $h); 995 $child->configure (0, $y, $w, $h);
940 996
941 $y += $h; 997 $y += $h;
942 } 998 }
999
1000 1
943} 1001}
944 1002
945############################################################################# 1003#############################################################################
946 1004
947package CFClient::UI::Label; 1005package CFClient::UI::Label;
948 1006
949our @ISA = CFClient::UI::Base::; 1007our @ISA = CFClient::UI::Base::;
950 1008
951use SDL::OpenGL; 1009use CFClient::OpenGL;
952 1010
953sub new { 1011sub new {
954 my ($class, %arg) = @_; 1012 my ($class, %arg) = @_;
955 1013
956 my $self = $class->SUPER::new ( 1014 my $self = $class->SUPER::new (
957 fg => [1, 1, 1], 1015 fg => [1, 1, 1],
958 fontsize => $::FONTSIZE, 1016 fontsize => 1,
959 text => "", 1017 text => "",
960 align => -1, 1018 align => -1,
961 valign => -1, 1019 valign => -1,
962 padding => 2, 1020 padding => 2,
963 layout => new CFClient::Layout, 1021 layout => new CFClient::Layout,
1002 1060
1003sub size_request { 1061sub size_request {
1004 my ($self) = @_; 1062 my ($self) = @_;
1005 1063
1006 $self->{layout}->set_width; 1064 $self->{layout}->set_width;
1007 $self->{layout}->set_height ($self->{fontsize}); 1065 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1008 1066
1009 my ($w, $h) = $self->{layout}->size; 1067 my ($w, $h) = $self->{layout}->size;
1010 1068
1011 ( 1069 (
1012 $w + $self->{padding} * 2, 1070 $w + $self->{padding} * 2,
1013 $h + $self->{padding} * 2, 1071 $h + $self->{padding} * 2,
1014 ) 1072 )
1015} 1073}
1016 1074
1017sub size_allocate { 1075sub size_allocate {
1018 my ($self, $x, $y, $w, $h) = @_; 1076 my ($self, $w, $h) = @_;
1019
1020 $self->_size_allocate ($x, $y, $w, $h) or return;
1021 1077
1022 delete $self->{texture}; 1078 delete $self->{texture};
1023}
1024
1025sub update {
1026 my ($self) = @_;
1027
1028 delete $self->{texture};
1029 $self->SUPER::update;
1030} 1079}
1031 1080
1032sub _draw { 1081sub _draw {
1033 my ($self) = @_; 1082 my ($self) = @_;
1034 1083
1035 my $tex = $self->{texture} ||= do { 1084 my $tex = $self->{texture} ||= do {
1036 $self->{layout}->set_width ($self->{w}); 1085 $self->{layout}->set_width ($self->{w});
1037 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize}); 1086 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1038 new_from_layout CFClient::Texture $self->{layout} 1087 new_from_layout CFClient::Texture $self->{layout}
1039 }; 1088 };
1040 1089
1041 glEnable GL_BLEND; 1090 glEnable GL_BLEND;
1042 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1091 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1067 1116
1068package CFClient::UI::EntryBase; 1117package CFClient::UI::EntryBase;
1069 1118
1070our @ISA = CFClient::UI::Label::; 1119our @ISA = CFClient::UI::Label::;
1071 1120
1072use SDL; 1121use CFClient::OpenGL;
1073use SDL::OpenGL;
1074 1122
1075sub new { 1123sub new {
1076 my $class = shift; 1124 my $class = shift;
1077 1125
1078 $class->SUPER::new ( 1126 $class->SUPER::new (
1092 1140
1093 delete $self->{cur_h}; 1141 delete $self->{cur_h};
1094 1142
1095 return if $self->{text} eq $text; 1143 return if $self->{text} eq $text;
1096 1144
1145 delete $self->{texture};
1146
1097 $self->{last_activity} = $::NOW; 1147 $self->{last_activity} = $::NOW;
1098 $self->{text} = $text; 1148 $self->{text} = $text;
1099 1149
1100 $text =~ s/./*/g if $self->{hidden}; 1150 $text =~ s/./*/g if $self->{hidden};
1101 $self->{layout}->set_text ("$text "); 1151 $self->{layout}->set_text ("$text ");
1114 1164
1115 ($w + 1, $h) # add 1 for cursor 1165 ($w + 1, $h) # add 1 for cursor
1116} 1166}
1117 1167
1118sub size_allocate { 1168sub size_allocate {
1119 my ($self, $x, $y, $w, $h) = @_; 1169 my ($self, $w, $h) = @_;
1120
1121 $self->SUPER::size_allocate ($x, $y, $w, $h);
1122 1170
1123 $self->_set_text ($self->{text}); 1171 $self->_set_text ($self->{text});
1124} 1172}
1125 1173
1126sub set_text { 1174sub set_text {
1132} 1180}
1133 1181
1134sub key_down { 1182sub key_down {
1135 my ($self, $ev) = @_; 1183 my ($self, $ev) = @_;
1136 1184
1137 my $mod = $ev->key_mod; 1185 my $mod = $ev->{mod};
1138 my $sym = $ev->key_sym; 1186 my $sym = $ev->{sym};
1139
1140 my $uni = $ev->key_unicode; 1187 my $uni = $ev->{unicode};
1141 1188
1142 my $text = $self->get_text; 1189 my $text = $self->get_text;
1143 1190
1144 if ($sym == SDLK_BACKSPACE) { 1191 if ($sym == 8) {
1145 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1192 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1146 } elsif ($sym == SDLK_DELETE) { 1193 } elsif ($sym == 127) {
1147 substr $text, $self->{cursor}, 1, ""; 1194 substr $text, $self->{cursor}, 1, "";
1148 } elsif ($sym == SDLK_LEFT) { 1195 } elsif ($sym == CFClient::SDLK_LEFT) {
1149 --$self->{cursor} if $self->{cursor}; 1196 --$self->{cursor} if $self->{cursor};
1150 } elsif ($sym == SDLK_RIGHT) { 1197 } elsif ($sym == CFClient::SDLK_RIGHT) {
1151 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1198 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1152 } elsif ($sym == SDLK_HOME) { 1199 } elsif ($sym == CFClient::SDLK_HOME) {
1153 $self->{cursor} = 0; 1200 $self->{cursor} = 0;
1154 } elsif ($sym == SDLK_END) { 1201 } elsif ($sym == CFClient::SDLK_END) {
1155 $self->{cursor} = length $text; 1202 $self->{cursor} = length $text;
1156 } elsif ($sym == SDLK_ESCAPE) { 1203 } elsif ($sym == 27) {
1157 $self->emit ('escape'); 1204 $self->emit ('escape');
1158 } elsif ($uni) { 1205 } elsif ($uni) {
1159 substr $text, $self->{cursor}++, 0, chr $uni; 1206 substr $text, $self->{cursor}++, 0, chr $uni;
1160 } 1207 }
1161 1208
1236 1283
1237package CFClient::UI::Entry; 1284package CFClient::UI::Entry;
1238 1285
1239our @ISA = CFClient::UI::EntryBase::; 1286our @ISA = CFClient::UI::EntryBase::;
1240 1287
1241use SDL; 1288use CFClient::OpenGL;
1242use SDL::OpenGL;
1243 1289
1244sub key_down { 1290sub key_down {
1245 my ($self, $ev) = @_; 1291 my ($self, $ev) = @_;
1246 1292
1247 my $sym = $ev->key_sym; 1293 my $sym = $ev->{sym};
1248 1294
1249 if ($sym == SDLK_RETURN) { 1295 if ($sym == 13) {
1250 $self->emit (activate => $self->get_text); 1296 $self->emit (activate => $self->get_text);
1251 $self->update; 1297 $self->update;
1252 1298
1253 } else { 1299 } else {
1254 $self->SUPER::key_down ($ev); 1300 $self->SUPER::key_down ($ev);
1260 1306
1261package CFClient::UI::Button; 1307package CFClient::UI::Button;
1262 1308
1263our @ISA = CFClient::UI::Label::; 1309our @ISA = CFClient::UI::Label::;
1264 1310
1265use SDL; 1311use CFClient::OpenGL;
1266use SDL::OpenGL;
1267 1312
1268my @tex = 1313my @tex =
1269 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1314 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1270 qw(b1_button_active.png); 1315 qw(b1_button_active.png);
1271 1316
1276 padding => 4, 1321 padding => 4,
1277 fg => [1, 1, 1], 1322 fg => [1, 1, 1],
1278 bg => [1, 1, 1, 0.2], 1323 bg => [1, 1, 1, 0.2],
1279 active_fg => [0, 0, 1], 1324 active_fg => [0, 0, 1],
1280 can_hover => 1, 1325 can_hover => 1,
1326 align => 0,
1327 valign => 0,
1281 @_ 1328 @_
1282 ) 1329 )
1283} 1330}
1284 1331
1285sub button_up { 1332sub button_up {
1322 1369
1323my @tex = 1370my @tex =
1324 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1371 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1325 qw(c1_checkbox_bg.png c1_checkbox_active.png); 1372 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1326 1373
1327use SDL; 1374use CFClient::OpenGL;
1328use SDL::OpenGL;
1329 1375
1330sub new { 1376sub new {
1331 my $class = shift; 1377 my $class = shift;
1332 1378
1333 $class->SUPER::new ( 1379 $class->SUPER::new (
1344 my ($self) = @_; 1390 my ($self) = @_;
1345 1391
1346 ($self->{padding} * 2 + 6) x 2 1392 ($self->{padding} * 2 + 6) x 2
1347} 1393}
1348 1394
1349sub size_allocate {
1350 my ($self, $x, $y, $w, $h) = @_;
1351
1352 $self->_size_allocate ($x, $y, $w, $h);
1353}
1354
1355sub button_down { 1395sub button_down {
1356 my ($self, $ev, $x, $y) = @_; 1396 my ($self, $ev, $x, $y) = @_;
1357 1397
1358 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} 1398 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding}
1359 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { 1399 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) {
1385 glDisable GL_BLEND; 1425 glDisable GL_BLEND;
1386} 1426}
1387 1427
1388############################################################################# 1428#############################################################################
1389 1429
1430package CFClient::UI::VGauge;
1431
1432our @ISA = CFClient::UI::Base::;
1433
1434use CFClient::OpenGL;
1435
1436my %tex = (
1437 food => [
1438 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1439 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1440 ],
1441 grace => [
1442 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1443 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1444 ],
1445 hp => [
1446 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1447 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1448 ],
1449 mana => [
1450 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1451 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1452 ],
1453);
1454
1455# eg. VGauge->new (gauge => 'food'), default gauge: food
1456sub new {
1457 my $class = shift;
1458
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};
1465
1466 $self
1467}
1468
1469sub size_request {
1470 my ($self) = @_;
1471
1472 my $tex = $tex{$self->{gauge}}[0];
1473
1474 @$tex{qw(w h)}
1475}
1476
1477sub set_max {
1478 my ($self, $max) = @_;
1479
1480 $self->{max_val} = $max;
1481}
1482
1483sub set_value {
1484 my ($self, $val, $max) = @_;
1485
1486 $self->set_max ($max)
1487 if defined $max;
1488
1489 $max = $self->{max_val};
1490 $self->{val} = $val;
1491
1492 $self->update;
1493}
1494
1495sub _draw {
1496 my ($self) = @_;
1497
1498 my $tex = $tex{$self->{gauge}};
1499
1500 my ($w, $h) = ($self->{w}, $self->{h});
1501
1502 my $ycut = $self->{val} / ($self->{max_val} || 1);
1503 $ycut = 1 if $self->{val} > $self->{max_val};
1504
1505 my $t1 = $tex->[0];
1506 my $t2 = $tex->[1];
1507
1508 glEnable GL_BLEND;
1509 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1510 glEnable GL_TEXTURE_2D;
1511 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1512
1513 my $h1 = $self->{h} - $ycut * $self->{h};
1514 my $h2 = $ycut * $self->{h};
1515
1516 my $yp = 0;
1517
1518 glBindTexture GL_TEXTURE_2D, $t1->{name};
1519 glBegin GL_QUADS;
1520 glTexCoord 0 , 0; glVertex 0 , $yp;
1521 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1;
1522 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1;
1523 glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp;
1524 glEnd;
1525
1526 $yp += $h1;
1527
1528 glBindTexture GL_TEXTURE_2D, $t2->{name};
1529 glBegin GL_QUADS;
1530 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp;
1531 glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2;
1532 glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2;
1533 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp;
1534 glEnd;
1535
1536 glDisable GL_BLEND;
1537 glDisable GL_TEXTURE_2D;
1538}
1539
1540#############################################################################
1541
1390package CFClient::UI::Slider; 1542package CFClient::UI::Slider;
1391 1543
1392use strict; 1544use strict;
1393 1545
1394use SDL::OpenGL; 1546use CFClient::OpenGL;
1395 1547
1396our @ISA = CFClient::UI::DrawBG::; 1548our @ISA = CFClient::UI::DrawBG::;
1397 1549
1398my @tex = 1550my @tex =
1399 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1551 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1409 # TODO: calculations are off 1561 # TODO: calculations are off
1410 my $self = $class->SUPER::new ( 1562 my $self = $class->SUPER::new (
1411 fg => [1, 1, 1], 1563 fg => [1, 1, 1],
1412 active_fg => [0, 0, 0], 1564 active_fg => [0, 0, 0],
1413 range => [0, 0, 100, 10], 1565 range => [0, 0, 100, 10],
1414 req_w => 40, 1566 req_w => 20,
1415 req_h => 13, 1567 req_h => 20,
1416 vertical => 0, 1568 vertical => 0,
1417 can_hover => 1, 1569 can_hover => 1,
1418 inner_pad => 5, 1570 inner_pad => 5,
1419 @_ 1571 @_
1420 ); 1572 );
1524 1676
1525package CFClient::UI::TextView; 1677package CFClient::UI::TextView;
1526 1678
1527our @ISA = CFClient::UI::HBox::; 1679our @ISA = CFClient::UI::HBox::;
1528 1680
1529use SDL::OpenGL; 1681use CFClient::OpenGL;
1530 1682
1531sub new { 1683sub new {
1532 my $class = shift; 1684 my $class = shift;
1533 1685
1534 my $self = $class->SUPER::new ( 1686 my $self = $class->SUPER::new (
1535 req_w => $::WIDTH / 6,
1536 req_h => $::HEIGHT / 6,
1537 fontsize => $::FONTSIZE, 1687 fontsize => 1,
1538 @_, 1688 @_,
1539 1689
1540 layout => (new CFClient::Layout), 1690 layout => (new CFClient::Layout),
1541 par => [], 1691 par => [],
1542 height => 0, 1692 height => 0,
1563sub text_height { 1713sub text_height {
1564 my ($self, $text) = @_; 1714 my ($self, $text) = @_;
1565 1715
1566 my $layout = $self->{layout}; 1716 my $layout = $self->{layout};
1567 1717
1568 $layout->set_height ($self->{fontsize}); 1718 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
1569 $layout->set_width ($self->{w}); 1719 $layout->set_width ($self->{w});
1570 $layout->set_text ($text); 1720 $layout->set_text ($text);
1571 1721
1572 ($layout->size)[1] 1722 ($layout->size)[1]
1573} 1723}
1577 1727
1578 $self->{need_reflow}++; 1728 $self->{need_reflow}++;
1579 $self->update; 1729 $self->update;
1580} 1730}
1581 1731
1582sub size_request {
1583 my ($self) = @_;
1584
1585 ($self->{req_w}, $self->{req_h})
1586}
1587
1588sub size_allocate { 1732sub size_allocate {
1589 my ($self, $x, $y, $w, $h) = @_; 1733 my ($self, $w, $h) = @_;
1590 1734
1591 $self->SUPER::size_allocate ($x, $y, $w, $h); 1735 $self->SUPER::size_allocate ($w, $h);
1592 1736
1593 $self->{layout}->set_height ($self->{fontsize}); 1737 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1594 $self->{layout}->set_width ($self->{w}); 1738 $self->{layout}->set_width ($self->{children}[0]{w});
1595 1739
1596 $self->reflow; 1740 $self->reflow;
1597} 1741}
1598 1742
1599sub add_paragraph { 1743sub add_paragraph {
1686 1830
1687} 1831}
1688 1832
1689############################################################################# 1833#############################################################################
1690 1834
1691package CFClient::UI::MapWidget;
1692
1693use strict;
1694
1695use List::Util qw(min max);
1696
1697use SDL;
1698use SDL::OpenGL;
1699
1700our @ISA = CFClient::UI::Base::;
1701
1702sub new {
1703 my $class = shift;
1704
1705 $class->SUPER::new (
1706 z => -1,
1707 can_focus => 1,
1708 list => (glGenLists 1),
1709 @_
1710 )
1711}
1712
1713sub key_down {
1714 print "MAPKEYDOWN\n";
1715}
1716
1717sub key_up {
1718}
1719
1720sub button_down {
1721 my ($self, $ev, $x, $y) = @_;
1722
1723 $self->focus_in;
1724
1725 if ($ev->button == 2) {
1726 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
1727 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
1728
1729 $self->{motion} = sub {
1730 my ($ev, $x, $y) = @_;
1731
1732 ($x, $y) = ($ev->motion_x, $ev->motion_y);
1733
1734 $::CFG->{map_shift_x} = $bw + $x - $ox;
1735 $::CFG->{map_shift_y} = $bh + $y - $oy;
1736
1737 $self->update;
1738 };
1739 }
1740}
1741
1742sub button_up {
1743 my ($self, $ev, $x, $y) = @_;
1744
1745 delete $self->{motion};
1746}
1747
1748sub mouse_motion {
1749 my ($self, $ev, $x, $y) = @_;
1750
1751 $self->{motion}->($ev, $x, $y) if $self->{motion};
1752}
1753
1754sub size_request {
1755 (
1756 1 + 32 * int $::WIDTH / 32,
1757 1 + 32 * int $::HEIGHT / 32,
1758 )
1759}
1760
1761sub update {
1762 my ($self) = @_;
1763
1764 $self->{need_update} = 1;
1765 $self->SUPER::update;
1766}
1767
1768sub draw {
1769 my ($self) = @_;
1770
1771 if (delete $self->{need_update}) {
1772 glNewList $self->{list}, GL_COMPILE;
1773
1774 if ($::MAP) {
1775 my $sw = int $::WIDTH / 32;
1776 my $sh = int $::HEIGHT / 32;
1777
1778 my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
1779 my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
1780
1781 glTranslate $sx0 - 32, $sy0 - 32, 0;
1782
1783 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
1784
1785 if ($::CFG->{fow_enable}) {
1786 if ($::CFG->{fow_smooth}) { # smooth fog of war
1787 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER;
1788 glConvolutionFilter2D
1789 GL_CONVOLUTION_2D,
1790 GL_ALPHA,
1791 3, 3,
1792 GL_ALPHA, GL_FLOAT,
1793 pack "f*",
1794 0.1, 0.1, 0.1,
1795 0.1, 0.2, 0.1,
1796 0.1, 0.1, 0.1,
1797 ;
1798 glEnable GL_CONVOLUTION_2D;
1799 }
1800
1801 $self->{fow_texture} = new CFClient::Texture
1802 w => $w,
1803 h => $h,
1804 data => $data,
1805 internalformat => GL_ALPHA,
1806 format => GL_ALPHA;
1807
1808 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
1809
1810 glEnable GL_BLEND;
1811 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1812 glEnable GL_TEXTURE_2D;
1813 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1814
1815 glColor +($::CFG->{fow_intensity}) x 3, 1;
1816 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
1817
1818 glDisable GL_TEXTURE_2D;
1819 glDisable GL_BLEND;
1820 }
1821
1822 # HACK BEGIN
1823 {
1824 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove
1825 my ($w, $h) = (250, 250);
1826
1827 glEnable GL_BLEND;
1828 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1829 glEnable GL_TEXTURE_2D;
1830 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1831
1832 $self->{mapmap_texture} =
1833 new CFClient::Texture
1834 w => $w,
1835 h => $h,
1836 data => $::MAP->mapmap ($w, $h),
1837 type => GL_UNSIGNED_INT_8_8_8_8_REV;
1838
1839 $self->{mapmap_texture}->draw_quad (100, 100);
1840
1841 glDisable GL_TEXTURE_2D;
1842 glDisable GL_BLEND;
1843 }
1844 # HACK END
1845 }
1846
1847 glEndList;
1848 }
1849
1850 glPushMatrix;
1851 glCallList $self->{list};
1852 glPopMatrix;
1853
1854 if ($FOCUS != $self) {
1855 glColor 64/255, 64/255, 64/255;
1856 glLogicOp GL_AND;
1857 glEnable GL_COLOR_LOGIC_OP;
1858 glBegin GL_QUADS;
1859 glVertex 0, 0;
1860 glVertex 0, $::HEIGHT;
1861 glVertex $::WIDTH, $::HEIGHT;
1862 glVertex $::WIDTH, 0;
1863 glEnd;
1864 glDisable GL_COLOR_LOGIC_OP;
1865 }
1866}
1867
1868my %DIR = (
1869 SDLK_KP8, [1, "north"],
1870 SDLK_KP9, [2, "northeast"],
1871 SDLK_KP6, [3, "east"],
1872 SDLK_KP3, [4, "southeast"],
1873 SDLK_KP2, [5, "south"],
1874 SDLK_KP1, [6, "southwest"],
1875 SDLK_KP4, [7, "west"],
1876 SDLK_KP7, [8, "northwest"],
1877
1878 SDLK_UP, [1, "north"],
1879 SDLK_RIGHT, [3, "east"],
1880 SDLK_DOWN, [5, "south"],
1881 SDLK_LEFT, [7, "west"],
1882);
1883
1884sub key_down {
1885 my ($self, $ev) = @_;
1886
1887 my $mod = $ev->key_mod;
1888 my $sym = $ev->key_sym;
1889
1890 if ($sym == SDLK_KP5) {
1891 $::CONN->user_send ("stay fire");
1892 } elsif ($sym == SDLK_a) {
1893 $::CONN->user_send ("apply");
1894 } elsif ($sym == SDLK_QUOTE) {
1895 $self->emit ('activate_console');
1896 } elsif ($sym == SDLK_SLASH) {
1897 $self->emit ('activate_console' => '/');
1898 } elsif (exists $DIR{$sym}) {
1899 if ($mod & KMOD_SHIFT) {
1900 $self->{shft}++;
1901 $::CONN->user_send ("fire $DIR{$sym}[0]");
1902 } elsif ($mod & KMOD_CTRL) {
1903 $self->{ctrl}++;
1904 $::CONN->user_send ("run $DIR{$sym}[0]");
1905 } else {
1906 $::CONN->user_send ("$DIR{$sym}[1]");
1907 }
1908 }
1909}
1910
1911sub key_up {
1912 my ($self, $ev) = @_;
1913
1914 my $mod = $ev->key_mod;
1915 my $sym = $ev->key_sym;
1916
1917 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
1918 $::CONN->user_send ("fire_stop");
1919 }
1920 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
1921 $::CONN->user_send ("run_stop");
1922 }
1923}
1924
1925#############################################################################
1926
1927package CFClient::UI::Animator; 1835package CFClient::UI::Animator;
1928 1836
1929use SDL::OpenGL; 1837use CFClient::OpenGL;
1930 1838
1931our @ISA = CFClient::UI::Bin::; 1839our @ISA = CFClient::UI::Bin::;
1932 1840
1933sub moveto { 1841sub moveto {
1934 my ($self, $x, $y) = @_; 1842 my ($self, $x, $y) = @_;
2007 1915
2008package CFClient::UI::Root; 1916package CFClient::UI::Root;
2009 1917
2010our @ISA = CFClient::UI::Container::; 1918our @ISA = CFClient::UI::Container::;
2011 1919
2012use SDL::OpenGL; 1920use CFClient::OpenGL;
1921
1922sub check_size {
1923 my ($self) = @_;
1924
1925 $self->configure (0, 0, $::WITH, $::HEIGHT);
1926}
2013 1927
2014sub size_request { 1928sub size_request {
2015 ($::WIDTH, $::HEIGHT) 1929 ($::WIDTH, $::HEIGHT)
2016} 1930}
2017 1931
2018sub size_allocate { 1932sub configure {
2019 my ($self, $x, $y, $w, $h) = @_; 1933 my ($self, $x, $y, $w, $h) = @_;
2020 1934
2021 $self->_size_allocate ($x, $y, $w, $h); 1935 $self->SUPER::configure ($x, $y, $w, $h);
2022 1936
2023 $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) 1937 $_->configure ($_->{x}, $_->{y}, $_->size_request)
2024 for @{$self->{children}}; 1938 for @{$self->{children}};
2025} 1939}
2026 1940
2027sub _topleft { 1941sub _topleft {
2028 my ($self, $x, $y) = @_; 1942 my ($self, $x, $y) = @_;
2031} 1945}
2032 1946
2033sub update { 1947sub update {
2034 my ($self) = @_; 1948 my ($self) = @_;
2035 1949
2036 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); 1950 $self->check_size;
2037 ::refresh (); 1951 ::refresh ();
2038} 1952}
2039 1953
2040sub add { 1954sub add {
2041 my ($self, $widget) = @_; 1955 my ($self, $child) = @_;
2042 1956
2043 $self->SUPER::add ($widget); 1957 $self->SUPER::add ($child);
2044
2045 $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request);
2046} 1958}
2047 1959
2048sub on_refresh { 1960sub on_refresh {
2049 my ($self, $id, $cb) = @_; 1961 my ($self, $id, $cb) = @_;
2050 1962

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines