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.113 by root, Sat Apr 15 12:46:48 2006 UTC vs.
Revision 1.134 by root, Wed Apr 19 06:06:45 2006 UTC

74sub harmonize { 74sub harmonize {
75 my ($vals) = @_; 75 my ($vals) = @_;
76 76
77 my $rem = 0; 77 my $rem = 0;
78 78
79 for ($vals) { 79 for (@$vals) {
80 my $i = int $_ + $rem; 80 my $i = int $_ + $rem;
81 $rem += $_ - $i; 81 $rem += $_ - $i;
82 $_ = $i; 82 $_ = $i;
83 } 83 }
84} 84}
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} = $x; 132 $self->{x} = int $x;
118 $self->{y} = $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) = @_;
176 192
177 return if $FOCUS == $self; 193 return if $FOCUS == $self;
178 return unless $self->{can_focus}; 194 return unless $self->{can_focus};
179 195
180 my $focus = $FOCUS; $FOCUS = $self; 196 my $focus = $FOCUS; $FOCUS = $self;
197
198 $self->emit (focus_in => $focus);
199
181 $focus->update if $focus; 200 $focus->update if $focus;
182 $FOCUS->update; 201 $FOCUS->update;
183} 202}
184 203
185sub focus_out { 204sub focus_out {
186 my ($self) = @_; 205 my ($self) = @_;
187 206
188 return unless $FOCUS == $self; 207 return unless $FOCUS == $self;
189 208
190 my $focus = $FOCUS; undef $FOCUS; 209 my $focus = $FOCUS; undef $FOCUS;
210
211 $self->emit (focus_out => $focus);
212
191 $focus->update if $focus; #? 213 $focus->update if $focus; #?
192} 214}
193 215
194sub mouse_motion { } 216sub mouse_motion { }
195sub button_up { } 217sub button_up { }
219 glPopMatrix; 241 glPopMatrix;
220 242
221 if ($self == $HOVER && $self->{can_hover}) { 243 if ($self == $HOVER && $self->{can_hover}) {
222 my ($x, $y) = @$self{qw(x y)}; 244 my ($x, $y) = @$self{qw(x y)};
223 245
224 glColor 0, 0, 1, 0.2; 246 glColor 1, 0.8, 0.5, 0.2;
225 glEnable GL_BLEND; 247 glEnable GL_BLEND;
226 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 248 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
227 glBegin GL_QUADS; 249 glBegin GL_QUADS;
228 glVertex $x , $y; 250 glVertex $x , $y;
229 glVertex $x + $self->{w}, $y; 251 glVertex $x + $self->{w}, $y;
254 my ($self, $parent) = @_; 276 my ($self, $parent) = @_;
255 277
256 Scalar::Util::weaken ($self->{parent} = $parent); 278 Scalar::Util::weaken ($self->{parent} = $parent);
257} 279}
258 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
259sub update { 295sub update {
260 my ($self) = @_; 296 my ($self) = @_;
261 297
262 $self->{parent}->update 298 $self->{parent}->update
263 if $self->{parent}; 299 if $self->{parent};
264} 300}
265 301
266sub connect { 302sub connect {
267 my ($self, $signal, $cb) = @_; 303 my ($self, $signal, $cb) = @_;
268 304
269 push @{ $self->{cb}{$signal} }, $cb; 305 push @{ $self->{signal_cb}{$signal} }, $cb;
270} 306}
271 307
272sub emit { 308sub emit {
273 my ($self, $signal, @args) = @_; 309 my ($self, $signal, @args) = @_;
274 310
311 for my $cb (@{$self->{signal_cb}{$signal} || []}) {
275 $_->($self, @args) 312 $cb->($self, @args);
276 for @{$self->{cb}{$signal} || []}; 313 }
277} 314}
278 315
279sub DESTROY { 316sub DESTROY {
280 my ($self) = @_; 317 my ($self) = @_;
281 318
361 $self->{children} = [ 398 $self->{children} = [
362 sort { $a->{z} <=> $b->{z} } 399 sort { $a->{z} <=> $b->{z} }
363 @{$self->{children}}, $child 400 @{$self->{children}}, $child
364 ]; 401 ];
365 402
366 $self->{w} = $self->{h} = -1; 403 $child->check_size;
367 $self->update;
368} 404}
369 405
370sub remove { 406sub remove {
371 my ($self, $widget) = @_; 407 my ($self, $child) = @_;
372 408
409 delete $child->{parent};
410
373 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 411 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
374 412
375 $self->size_allocate (0, 0, $self->{w}, $self->{h}); 413 $self->check_size;
376} 414}
377 415
378sub find_widget { 416sub find_widget {
379 my ($self, $x, $y) = @_; 417 my ($self, $x, $y) = @_;
380 418
410 448
411 $class->SUPER::new (children => [$child], %arg) 449 $class->SUPER::new (children => [$child], %arg)
412} 450}
413 451
414sub add { 452sub add {
415 my ($self, $widget) = @_; 453 my ($self, $child) = @_;
416 454
417 $self->{children} = []; 455 $self->{children} = [];
418 456
419 $self->SUPER::add ($widget); 457 $self->SUPER::add ($child);
420} 458}
421 459
422sub remove { 460sub remove {
423 my ($self, $widget) = @_; 461 my ($self, $widget) = @_;
424 462
433sub size_request { 471sub size_request {
434 $_[0]{children}[0]->size_request 472 $_[0]{children}[0]->size_request
435} 473}
436 474
437sub size_allocate { 475sub size_allocate {
438 my ($self, $x, $y, $w, $h) = @_; 476 my ($self, $w, $h) = @_;
439 477
440 $self->_size_allocate ($x, $y, $w, $h) or return;
441
442 $self->{children}[0]->size_allocate (0, 0, $w, $h); 478 $self->{children}[0]->configure (0, 0, $w, $h);
443} 479}
444 480
445############################################################################# 481#############################################################################
446 482
447package CFClient::UI::Window; 483package CFClient::UI::Window;
473 $self->child->draw; 509 $self->child->draw;
474 }; 510 };
475} 511}
476 512
477sub size_allocate { 513sub size_allocate {
478 my ($self, $x, $y, $w, $h) = @_; 514 my ($self, $w, $h) = @_;
479 515
480 $self->_size_allocate ($x, $y, $w, $h) or return;
481
482 $self->child->size_allocate (0, 0, $w, $h); 516 $self->child->configure (0, 0, $w, $h);
483 517
484 $self->render_chld; 518 $self->render_chld;
485} 519}
486 520
487sub _draw { 521sub _draw {
503 glDisable GL_TEXTURE_2D; 537 glDisable GL_TEXTURE_2D;
504} 538}
505 539
506############################################################################# 540#############################################################################
507 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
508package CFClient::UI::Frame; 566package CFClient::UI::Frame;
509 567
510our @ISA = CFClient::UI::Bin::; 568our @ISA = CFClient::UI::Bin::;
511 569
512use SDL::OpenGL; 570use SDL::OpenGL;
522} 580}
523 581
524sub size_allocate { 582sub size_allocate {
525 my ($self, $x, $y, $w, $h) = @_; 583 my ($self, $x, $y, $w, $h) = @_;
526 584
527 $self->_size_allocate ($x, $y, $w, $h) or return;
528
529 $self->child->size_allocate (2, 2, $w - 4, $h - 4); 585 $self->child->configure (2, 2, $w - 4, $h - 4);
530} 586}
531 587
532sub _draw { 588sub _draw {
533 my ($self) = @_; 589 my ($self) = @_;
534 590
565 # TODO: user_x, user_y, overwrite moveto? 621 # TODO: user_x, user_y, overwrite moveto?
566 622
567 $class->SUPER::new ( 623 $class->SUPER::new (
568 bg => [1, 1, 1, 1], 624 bg => [1, 1, 1, 1],
569 border_bg => [1, 1, 1, 1], 625 border_bg => [1, 1, 1, 1],
570 border => $::FONTSIZE * 0.8, 626 border => 0.8,
571 @_ 627 @_
572 ) 628 )
573} 629}
574 630
631sub border {
632 int $_[0]{border} * $::FONTSIZE
633}
634
575sub size_request { 635sub size_request {
576 my ($self) = @_; 636 my ($self) = @_;
577 637
578 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};
579 639
580 my ($w, $h) = $self->SUPER::size_request; 640 my ($w, $h) = $self->SUPER::size_request;
581 641
582 ( 642 (
583 $w + $self->{border} * 2, 643 $w + $self->border * 2,
584 $h + $self->{border} * 2, 644 $h + $self->border * 2,
585 ) 645 )
586} 646}
587 647
588sub size_allocate { 648sub size_allocate {
589 my ($self, $x, $y, $w, $h) = @_; 649 my ($self, $w, $h) = @_;
590 650
591 $self->_size_allocate ($x, $y, $w, $h) or return;
592
593 $h -= List::Util::max 0, $self->{border} * 2; 651 $h -= List::Util::max 0, $self->border * 2;
594 $w -= List::Util::max 0, $self->{border} * 2; 652 $w -= List::Util::max 0, $self->border * 2;
595 653
596 $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); 654 $self->child->configure ($self->border, $self->border, $w, $h);
597} 655}
598 656
599sub button_down { 657sub button_down {
600 my ($self, $ev, $x, $y) = @_; 658 my ($self, $ev, $x, $y) = @_;
601 659
660 my $border = $self->border;
661
602 if ($x < $self->{w} && $x >= $self->{w} - $self->{border} 662 if ($x < $self->{w} && $x >= $self->{w} - $border
603 && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { 663 && $y < $self->{h} && $y >= $self->{h} - $border) {
604 664
605 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 665 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
606 my ($bw, $bh) = ($self->{w}, $self->{h}); 666 my ($bw, $bh) = ($self->{w}, $self->{h});
607 667
608 $self->{motion} = sub { 668 $self->{motion} = sub {
610 670
611 ($x, $y) = ($ev->motion_x, $ev->motion_y); 671 ($x, $y) = ($ev->motion_x, $ev->motion_y);
612 672
613 $self->{user_w} = $bw + $x - $ox; 673 $self->{user_w} = $bw + $x - $ox;
614 $self->{user_h} = $bh + $y - $oy; 674 $self->{user_h} = $bh + $y - $oy;
615 $self->update; 675 $self->check_size;
616 }; 676 };
617 677
618 } elsif ($x >= 0 && $x < $self->{w} 678 } elsif ($x >= 0 && $x < $self->{w}
619 && $y >= 0 && $y < $self->{border}) { 679 && $y >= 0 && $y < $border) {
620 680
621 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 681 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
622 my ($bx, $by) = ($self->{x}, $self->{y}); 682 my ($bx, $by) = ($self->{x}, $self->{y});
623 683
624 $self->{motion} = sub { 684 $self->{motion} = sub {
653 glEnable GL_BLEND; 713 glEnable GL_BLEND;
654 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 714 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
655 glEnable GL_TEXTURE_2D; 715 glEnable GL_TEXTURE_2D;
656 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 716 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
657 717
718 my $border = $self->border;
719
658 glColor @{ $self->{border_bg} }; 720 glColor @{ $self->{border_bg} };
659 $tex[1]->draw_quad (0, 0, $w, $self->{border}); 721 $tex[1]->draw_quad (0, 0, $w, $border);
660 $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); 722 $tex[3]->draw_quad (0, $border, $border, $ch);
661 $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); 723 $tex[2]->draw_quad ($w - $border, $border, $border, $ch);
662 $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); 724 $tex[4]->draw_quad (0, $h - $border, $w, $border);
663 725
664 my $bg = $tex[0]; 726 my $bg = $tex[0];
665 727
666 # TODO: repeat texture not scale 728 # TODO: repeat texture not scale
667 my $rep_x = $cw / $bg->{w}; 729 my $rep_x = $cw / $bg->{w};
670 glColor @{ $self->{bg} }; 732 glColor @{ $self->{bg} };
671 733
672 $bg->{s} = $rep_x; 734 $bg->{s} = $rep_x;
673 $bg->{t} = $rep_y; 735 $bg->{t} = $rep_y;
674 $bg->{wrap_mode} = 1; 736 $bg->{wrap_mode} = 1;
675 $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); 737 $bg->draw_quad ($border, $border, $cw, $ch);
676 738
677 glDisable GL_TEXTURE_2D; 739 glDisable GL_TEXTURE_2D;
678 glDisable GL_BLEND; 740 glDisable GL_BLEND;
679 741
680 $self->child->draw; 742 $self->child->draw;
703 my ($self, $x, $y, $child) = @_; 765 my ($self, $x, $y, $child) = @_;
704 766
705 $child->set_parent ($self); 767 $child->set_parent ($self);
706 $self->{children}[$y][$x] = $child; 768 $self->{children}[$y][$x] = $child;
707 769
708 $self->{w} = $self->{h} = -1; 770 $child->check_size;
771}
772
773# TODO: move to container class maybe? send childs a signal on removal?
774sub clear {
775 my ($self) = @_;
776
777 delete $self->{children};
709 $self->update; 778 $self->update;
710} 779}
711 780
712sub get_wh { 781sub get_wh {
713 my ($self) = @_; 782 my ($self) = @_;
741 (sum @$hs), 810 (sum @$hs),
742 ) 811 )
743} 812}
744 813
745sub size_allocate { 814sub size_allocate {
746 my ($self, $x, $y, $w, $h) = @_; 815 my ($self, $w, $h) = @_;
747
748 $self->_size_allocate ($x, $y, $w, $h) or return;
749 816
750 my ($ws, $hs) = $self->get_wh; 817 my ($ws, $hs) = $self->get_wh;
751 818
752 my $req_w = sum @$ws; 819 my $req_w = sum @$ws;
753 my $req_h = sum @$hs; 820 my $req_h = sum @$hs;
775 842
776 for my $c (0 .. $#$row) { 843 for my $c (0 .. $#$row) {
777 my $col_w = $ws->[$c]; 844 my $col_w = $ws->[$c];
778 845
779 if (my $widget = $row->[$c]) { 846 if (my $widget = $row->[$c]) {
780 $widget->size_allocate ($x, $y, $col_w, $row_h); 847 $widget->configure ($x, $y, $col_w, $row_h);
781 } 848 }
782 849
783 $x += $col_w; 850 $x += $col_w;
784 } 851 }
785 852
830 (List::Util::max map $_->[1], @alloc), 897 (List::Util::max map $_->[1], @alloc),
831 ) 898 )
832} 899}
833 900
834sub size_allocate { 901sub size_allocate {
835 my ($self, $x, $y, $w, $h) = @_; 902 my ($self, $w, $h) = @_;
836
837 $self->_size_allocate ($x, $y, $w, $h);
838 903
839 ($h, $w) = ($w, $h); 904 ($h, $w) = ($w, $h);
840 905
841 my $children = $self->{children}; 906 my $children = $self->{children};
842 907
864 929
865 my $y = 0; 930 my $y = 0;
866 for (0 .. $#$children) { 931 for (0 .. $#$children) {
867 my $child = $children->[$_]; 932 my $child = $children->[$_];
868 my $h = $h[$_]; 933 my $h = $h[$_];
869 $child->size_allocate ($y, 0, $h, $w); 934 $child->configure ($y, 0, $h, $w);
870 935
871 $y += $h; 936 $y += $h;
872 } 937 }
938
939 1
873} 940}
874 941
875############################################################################# 942#############################################################################
876 943
877package CFClient::UI::VBox; 944package CFClient::UI::VBox;
890 (List::Util::sum map $_->[1], @alloc), 957 (List::Util::sum map $_->[1], @alloc),
891 ) 958 )
892} 959}
893 960
894sub size_allocate { 961sub size_allocate {
895 my ($self, $x, $y, $w, $h) = @_; 962 my ($self, $w, $h) = @_;
896
897 $self->_size_allocate ($x, $y, $w, $h);
898 963
899 my $children = $self->{children}; 964 my $children = $self->{children};
900 965
901 my @h = map +($_->size_request)[1], @$children; 966 my @h = map +($_->size_request)[1], @$children;
902 967
920 985
921 my $y = 0; 986 my $y = 0;
922 for (0 .. $#$children) { 987 for (0 .. $#$children) {
923 my $child = $children->[$_]; 988 my $child = $children->[$_];
924 my $h = $h[$_]; 989 my $h = $h[$_];
925 $child->size_allocate (0, $y, $w, $h); 990 $child->configure (0, $y, $w, $h);
926 991
927 $y += $h; 992 $y += $h;
928 } 993 }
994
995 1
929} 996}
930 997
931############################################################################# 998#############################################################################
932 999
933package CFClient::UI::Label; 1000package CFClient::UI::Label;
939sub new { 1006sub new {
940 my ($class, %arg) = @_; 1007 my ($class, %arg) = @_;
941 1008
942 my $self = $class->SUPER::new ( 1009 my $self = $class->SUPER::new (
943 fg => [1, 1, 1], 1010 fg => [1, 1, 1],
944 fontsize => $::FONTSIZE, 1011 fontsize => 1,
945 text => "", 1012 text => "",
946 align => -1, 1013 align => -1,
1014 valign => -1,
947 padding => 2, 1015 padding => 2,
948 layout => new CFClient::Layout, 1016 layout => new CFClient::Layout,
949 %arg 1017 %arg
950 ); 1018 );
951 1019
952 $self->set_text ($self->{text}); 1020 $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d#
1021
1022 $self->set_text (delete $self->{text}) if exists $self->{text};
1023 $self->set_markup (delete $self->{markup}) if exists $self->{markup};
953 1024
954 $self 1025 $self
955} 1026}
956 1027
957sub escape_text { 1028sub escape_text {
965} 1036}
966 1037
967sub set_text { 1038sub set_text {
968 my ($self, $text) = @_; 1039 my ($self, $text) = @_;
969 1040
970 $self->{text} = $text;
971 $self->{layout}->set_markup ($text); 1041 $self->{layout}->set_text ($text);
972 1042
973 delete $self->{texture}; 1043 delete $self->{texture};
974# $self->{w} = $self->{h} = -1;
975 $self->update; 1044 $self->update;
976} 1045}
977 1046
978sub get_text { 1047sub set_markup {
979 my ($self, $text) = @_; 1048 my ($self, $markup) = @_;
980 1049
981 $self->{text} 1050 $self->{layout}->set_markup ($markup);
1051
1052 delete $self->{texture};
1053 $self->update;
982} 1054}
983 1055
984sub size_request { 1056sub size_request {
985 my ($self) = @_; 1057 my ($self) = @_;
986 1058
987 $self->{layout}->set_width; 1059 $self->{layout}->set_width;
988 $self->{layout}->set_height ($self->{fontsize}); 1060 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1061
989 my ($w, $h) = $self->{layout}->size; 1062 my ($w, $h) = $self->{layout}->size;
990 1063
991 ( 1064 (
992 $w + $self->{padding} * 2, 1065 $w + $self->{padding} * 2,
993 $h + $self->{padding} * 2, 1066 $h + $self->{padding} * 2,
994 ) 1067 )
995} 1068}
996 1069
997sub size_allocate { 1070sub size_allocate {
998 my ($self, $x, $y, $w, $h) = @_; 1071 my ($self, $w, $h) = @_;
999
1000 $self->_size_allocate ($x, $y, $w, $h) or return;
1001 1072
1002 delete $self->{texture}; 1073 delete $self->{texture};
1003}
1004
1005sub update {
1006 my ($self) = @_;
1007
1008 delete $self->{texture};
1009 $self->SUPER::update;
1010} 1074}
1011 1075
1012sub _draw { 1076sub _draw {
1013 my ($self) = @_; 1077 my ($self) = @_;
1014 1078
1015 my $tex = $self->{texture} ||= do { 1079 my $tex = $self->{texture} ||= do {
1016 $self->{layout}->set_width ($self->{w}); 1080 $self->{layout}->set_width ($self->{w});
1017 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); 1081 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1018 new_from_layout CFClient::Texture $self->{layout} 1082 new_from_layout CFClient::Texture $self->{layout}
1019 }; 1083 };
1020 1084
1021 glEnable GL_BLEND; 1085 glEnable GL_BLEND;
1022 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1086 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1023 glEnable GL_TEXTURE_2D; 1087 glEnable GL_TEXTURE_2D;
1024 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1088 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1025 1089
1026 glColor @{$self->{fg}}; 1090 glColor @{$self->{fg}};
1027 1091
1028 my $x = 1092 $self->{ox} = int (
1029 $self->{align} < 0 ? $self->{padding} 1093 $self->{align} < 0 ? $self->{padding}
1030 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1094 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1031 : ($self->{w} - $tex->{w}) * 0.5; 1095 : ($self->{w} - $tex->{w}) * 0.5
1096 );
1032 1097
1033 $tex->draw_quad (int $x, int +($self->{h} - $tex->{h}) * 0.5); 1098 $self->{oy} = int (
1099 $self->{valign} < 0 ? $self->{padding}
1100 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1101 : ($self->{h} - $tex->{h}) * 0.5
1102 );
1103
1104 $tex->draw_quad ($self->{ox}, $self->{oy});
1034 1105
1035 glDisable GL_TEXTURE_2D; 1106 glDisable GL_TEXTURE_2D;
1036 glDisable GL_BLEND; 1107 glDisable GL_BLEND;
1037} 1108}
1038 1109
1039############################################################################# 1110#############################################################################
1040 1111
1041package CFClient::UI::Entry; 1112package CFClient::UI::EntryBase;
1042 1113
1043our @ISA = CFClient::UI::Label::; 1114our @ISA = CFClient::UI::Label::;
1044 1115
1045use SDL; 1116use SDL;
1046use SDL::OpenGL; 1117use SDL::OpenGL;
1053 bg => [0, 0, 0, 0.2], 1124 bg => [0, 0, 0, 0.2],
1054 active_bg => [1, 1, 1, 0.5], 1125 active_bg => [1, 1, 1, 0.5],
1055 active_fg => [0, 0, 0], 1126 active_fg => [0, 0, 0],
1056 can_hover => 1, 1127 can_hover => 1,
1057 can_focus => 1, 1128 can_focus => 1,
1129 valign => 0,
1058 @_ 1130 @_
1059 ) 1131 )
1060} 1132}
1061 1133
1062sub _set_text { 1134sub _set_text {
1063 my ($self, $text) = @_; 1135 my ($self, $text) = @_;
1064 1136
1065 my $old_text = $self->{text}; 1137 delete $self->{cur_h};
1138
1139 return if $self->{text} eq $text;
1140
1141 delete $self->{texture};
1066 1142
1067 $self->{last_activity} = $::NOW; 1143 $self->{last_activity} = $::NOW;
1068
1069 $self->{text} = $text; 1144 $self->{text} = $text;
1070 $self->{layout}->set_width ($self->{w});
1071 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize});
1072 1145
1073 $text =~ s/./*/g if $self->{hidden}; 1146 $text =~ s/./*/g if $self->{hidden};
1147 $self->{layout}->set_text ("$text ");
1074 1148
1075 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1149 $self->emit (changed => $self->{text});
1150}
1076 1151
1077 $text = substr $text, 0, $self->{cursor}; 1152sub get_text {
1078 utf8::encode $text; 1153 $_[0]{text}
1079
1080 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
1081
1082 $self->emit (changed => $self->{text}) # XXX: is this the right place to do this?
1083 if $old_text ne $self->{text};
1084} 1154}
1085 1155
1086sub size_request { 1156sub size_request {
1087 my ($self) = @_; 1157 my ($self) = @_;
1088 1158
1090 1160
1091 ($w + 1, $h) # add 1 for cursor 1161 ($w + 1, $h) # add 1 for cursor
1092} 1162}
1093 1163
1094sub size_allocate { 1164sub size_allocate {
1095 my ($self, $x, $y, $w, $h) = @_; 1165 my ($self, $w, $h) = @_;
1096
1097 $self->SUPER::size_allocate ($x, $y, $w, $h);
1098 1166
1099 $self->_set_text ($self->{text}); 1167 $self->_set_text ($self->{text});
1100} 1168}
1101 1169
1102sub set_text { 1170sub set_text {
1192 1260
1193 $self->SUPER::_draw; 1261 $self->SUPER::_draw;
1194 1262
1195 #TODO: force update every cursor change :( 1263 #TODO: force update every cursor change :(
1196 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { 1264 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) {
1265
1266 unless (exists $self->{cur_h}) {
1267 my $text = substr $self->{text}, 0, $self->{cursor};
1268 utf8::encode $text;
1269
1270 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text)
1271 }
1272
1197 glColor @{$self->{fg}}; 1273 glColor @{$self->{fg}};
1198 glBegin GL_LINES; 1274 glBegin GL_LINES;
1199 glVertex $self->{cur_x}, $self->{cur_y};
1200 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; 1275 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy};
1276 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
1201 glEnd; 1277 glEnd;
1202 } 1278 }
1203} 1279}
1204 1280
1205package CFClient::UI::LineEntry; 1281package CFClient::UI::Entry;
1206 1282
1207our @ISA = CFClient::UI::Entry::; 1283our @ISA = CFClient::UI::EntryBase::;
1208 1284
1209use SDL; 1285use SDL;
1210use SDL::OpenGL; 1286use SDL::OpenGL;
1211 1287
1212sub key_down { 1288sub key_down {
1242 1318
1243 $class->SUPER::new ( 1319 $class->SUPER::new (
1244 padding => 4, 1320 padding => 4,
1245 fg => [1, 1, 1], 1321 fg => [1, 1, 1],
1246 bg => [1, 1, 1, 0.2], 1322 bg => [1, 1, 1, 0.2],
1247 active_fg => [1, 1, 0], 1323 active_fg => [0, 0, 1],
1248 can_hover => 1, 1324 can_hover => 1,
1325 align => 0,
1326 valign => 0,
1249 @_ 1327 @_
1250 ) 1328 )
1251} 1329}
1252 1330
1253sub button_up { 1331sub button_up {
1261 1339
1262sub _draw { 1340sub _draw {
1263 my ($self) = @_; 1341 my ($self) = @_;
1264 1342
1265 local $self->{fg} = $self->{fg}; 1343 local $self->{fg} = $self->{fg};
1266 my $tex = $tex[0];
1267
1268 glEnable GL_BLEND;
1269 glEnable GL_TEXTURE_2D;
1270 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1271 1344
1272 if ($GRAB == $self) { 1345 if ($GRAB == $self) {
1273 $self->{fg} = $self->{active_fg}; 1346 $self->{fg} = $self->{active_fg};
1274 } 1347 }
1275 1348
1276 glBindTexture GL_TEXTURE_2D, $tex->{name}; 1349 glEnable GL_BLEND;
1350 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1351 glEnable GL_TEXTURE_2D;
1277 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1352 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1353 glColor 0, 0, 0, 1;
1278 1354
1279 $tex->draw_quad (0, 0, $self->{w}, $self->{h}); 1355 $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h});
1280 1356
1281 glDisable GL_TEXTURE_2D; 1357 glDisable GL_TEXTURE_2D;
1282 glDisable GL_BLEND; 1358 glDisable GL_BLEND;
1283 1359
1284 $self->SUPER::_draw; 1360 $self->SUPER::_draw;
1314 my ($self) = @_; 1390 my ($self) = @_;
1315 1391
1316 ($self->{padding} * 2 + 6) x 2 1392 ($self->{padding} * 2 + 6) x 2
1317} 1393}
1318 1394
1319sub size_allocate {
1320 my ($self, $x, $y, $w, $h) = @_;
1321
1322 $self->_size_allocate ($x, $y, $w, $h);
1323}
1324
1325sub button_down { 1395sub button_down {
1326 my ($self, $ev, $x, $y) = @_; 1396 my ($self, $ev, $x, $y) = @_;
1327 1397
1328 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} 1398 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding}
1329 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { 1399 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) {
1351 1421
1352 $tex->draw_quad (0, 0, $s, $s); 1422 $tex->draw_quad (0, 0, $s, $s);
1353 1423
1354 glDisable GL_TEXTURE_2D; 1424 glDisable GL_TEXTURE_2D;
1355 glDisable GL_BLEND; 1425 glDisable GL_BLEND;
1426}
1427
1428#############################################################################
1429
1430package CFClient::UI::VGauge;
1431
1432our @ISA = CFClient::UI::Base::;
1433
1434use SDL::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 (gauge => 'food', @_);
1460
1461 $self
1462}
1463
1464sub size_request {
1465 my ($self) = @_;
1466
1467 my $tex = $tex{$self->{gauge}}[0];
1468
1469 @$tex{qw(w h)}
1470}
1471
1472sub set_max {
1473 my ($self, $max) = @_;
1474
1475 $self->{max_val} = $max;
1476}
1477
1478sub set_value {
1479 my ($self, $val, $max) = @_;
1480
1481 $self->set_max ($max)
1482 if defined $max;
1483
1484 $max = $self->{max_val};
1485 $self->{val} = $val;
1486
1487 $self->update;
1488}
1489
1490sub _draw {
1491 my ($self) = @_;
1492
1493 my $tex = $tex{$self->{gauge}};
1494
1495 my ($w, $h) = ($self->{w}, $self->{h});
1496
1497 my $ycut = $self->{val} / ($self->{max_val} || 1);
1498 $ycut = 1 if $self->{val} > $self->{max_val};
1499
1500 my $t1 = $tex->[0];
1501 my $t2 = $tex->[1];
1502
1503 glEnable GL_BLEND;
1504 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1505 glEnable GL_TEXTURE_2D;
1506 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1507
1508 my $h1 = $self->{h} - $ycut * $self->{h};
1509 my $h2 = $ycut * $self->{h};
1510
1511 my $yp = 0;
1512
1513 glBindTexture GL_TEXTURE_2D, $t1->{name};
1514 glBegin GL_QUADS;
1515 glTexCoord 0 , 0; glVertex 0 , $yp;
1516 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1;
1517 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1;
1518 glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp;
1519 glEnd;
1520
1521 $yp += $h1;
1522
1523 glBindTexture GL_TEXTURE_2D, $t2->{name};
1524 glBegin GL_QUADS;
1525 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp;
1526 glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2;
1527 glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2;
1528 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp;
1529 glEnd;
1530
1531 glDisable GL_BLEND;
1532 glDisable GL_TEXTURE_2D;
1356} 1533}
1357 1534
1358############################################################################# 1535#############################################################################
1359 1536
1360package CFClient::UI::Slider; 1537package CFClient::UI::Slider;
1379 # TODO: calculations are off 1556 # TODO: calculations are off
1380 my $self = $class->SUPER::new ( 1557 my $self = $class->SUPER::new (
1381 fg => [1, 1, 1], 1558 fg => [1, 1, 1],
1382 active_fg => [0, 0, 0], 1559 active_fg => [0, 0, 0],
1383 range => [0, 0, 100, 10], 1560 range => [0, 0, 100, 10],
1384 req_w => 40, 1561 req_w => 20,
1385 req_h => 13, 1562 req_h => 20,
1386 vertical => 0, 1563 vertical => 0,
1387 can_hover => 1, 1564 can_hover => 1,
1388 inner_pad => 5, 1565 inner_pad => 5,
1389 @_ 1566 @_
1390 ); 1567 );
1500 1677
1501sub new { 1678sub new {
1502 my $class = shift; 1679 my $class = shift;
1503 1680
1504 my $self = $class->SUPER::new ( 1681 my $self = $class->SUPER::new (
1505 req_w => $::WIDTH / 6,
1506 req_h => $::HEIGHT / 6,
1507 fontsize => $::FONTSIZE, 1682 fontsize => 1,
1508 @_, 1683 @_,
1509 1684
1510 layout => (new CFClient::Layout), 1685 layout => (new CFClient::Layout),
1511 par => [], 1686 par => [],
1512 height => 0, 1687 height => 0,
1533sub text_height { 1708sub text_height {
1534 my ($self, $text) = @_; 1709 my ($self, $text) = @_;
1535 1710
1536 my $layout = $self->{layout}; 1711 my $layout = $self->{layout};
1537 1712
1538 $layout->set_height ($self->{fontsize}); 1713 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
1539 $layout->set_width ($self->{w}); 1714 $layout->set_width ($self->{w});
1540 $layout->set_text ($text); 1715 $layout->set_text ($text);
1541 1716
1542 ($layout->size)[1] 1717 ($layout->size)[1]
1543} 1718}
1547 1722
1548 $self->{need_reflow}++; 1723 $self->{need_reflow}++;
1549 $self->update; 1724 $self->update;
1550} 1725}
1551 1726
1552sub size_request {
1553 my ($self) = @_;
1554
1555 ($self->{req_w}, $self->{req_h})
1556}
1557
1558sub size_allocate { 1727sub size_allocate {
1559 my ($self, $x, $y, $w, $h) = @_; 1728 my ($self, $w, $h) = @_;
1560 1729
1561 $self->SUPER::size_allocate ($x, $y, $w, $h); 1730 $self->SUPER::size_allocate ($w, $h);
1562 1731
1563 $self->{layout}->set_height ($self->{fontsize}); 1732 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1564 $self->{layout}->set_width ($self->{w}); 1733 $self->{layout}->set_width ($self->{children}[0]{w});
1565 1734
1566 $self->reflow; 1735 $self->reflow;
1567} 1736}
1568 1737
1569sub add_paragraph { 1738sub add_paragraph {
1751 glTranslate $sx0 - 32, $sy0 - 32, 0; 1920 glTranslate $sx0 - 32, $sy0 - 32, 0;
1752 1921
1753 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1); 1922 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
1754 1923
1755 if ($::CFG->{fow_enable}) { 1924 if ($::CFG->{fow_enable}) {
1756 if ($::CFG->{fow_smooth}) { # smooth fog of war 1925 if ($::CFG->{fow_smooth} && $CFClient::GL_VERSION >= 1.2) { # smooth fog of war
1757 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; 1926 glConvolutionParameter (GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER);
1758 glConvolutionFilter2D 1927 glConvolutionFilter2D (
1759 GL_CONVOLUTION_2D, 1928 GL_CONVOLUTION_2D,
1760 GL_ALPHA, 1929 GL_ALPHA,
1761 3, 3, 1930 3, 3,
1762 GL_ALPHA, GL_FLOAT, 1931 GL_ALPHA, GL_FLOAT,
1763 pack "f*", 1932 pack "f*",
1764 0.1, 0.1, 0.1, 1933 0.1, 0.1, 0.1,
1765 0.1, 0.2, 0.1, 1934 0.1, 0.2, 0.1,
1766 0.1, 0.1, 0.1, 1935 0.1, 0.1, 0.1,
1767 ; 1936 );
1768 glEnable GL_CONVOLUTION_2D; 1937 glEnable GL_CONVOLUTION_2D;
1769 } 1938 }
1770 1939
1771 my $tex = new CFClient::Texture 1940 $self->{fow_texture} = new CFClient::Texture
1772 w => $w, 1941 w => $w,
1773 h => $h, 1942 h => $h,
1774 data => $data, 1943 data => $data,
1775 internalformat => GL_ALPHA, 1944 internalformat => GL_ALPHA,
1776 format => GL_ALPHA; 1945 format => GL_ALPHA;
1781 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1950 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1782 glEnable GL_TEXTURE_2D; 1951 glEnable GL_TEXTURE_2D;
1783 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1952 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1784 1953
1785 glColor +($::CFG->{fow_intensity}) x 3, 1; 1954 glColor +($::CFG->{fow_intensity}) x 3, 1;
1786 $tex->draw_quad (0, 0, $w * 32, $h * 32); 1955 $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32);
1787 1956
1788 glDisable GL_TEXTURE_2D; 1957 glDisable GL_TEXTURE_2D;
1789 glDisable GL_BLEND; 1958 glDisable GL_BLEND;
1790 } 1959 }
1791 1960
1797 glEnable GL_BLEND; 1966 glEnable GL_BLEND;
1798 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1967 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1799 glEnable GL_TEXTURE_2D; 1968 glEnable GL_TEXTURE_2D;
1800 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1969 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1801 1970
1971 $self->{mapmap_texture} =
1802 CFClient::Texture->new ( 1972 new CFClient::Texture
1803 w => $w, 1973 w => $w,
1804 h => $h, 1974 h => $h,
1805 data => $::MAP->mapmap ($w, $h), 1975 data => $::MAP->mapmap ($w, $h),
1806 type => GL_UNSIGNED_INT_8_8_8_8_REV 1976 type => $CFClient::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
1807 )->draw_quad (100, 100); 1977
1978 $self->{mapmap_texture}->draw_quad (100, 100);
1808 1979
1809 glDisable GL_TEXTURE_2D; 1980 glDisable GL_TEXTURE_2D;
1810 glDisable GL_BLEND; 1981 glDisable GL_BLEND;
1811 } 1982 }
1812 # HACK END 1983 # HACK END
1854 2025
1855 my $mod = $ev->key_mod; 2026 my $mod = $ev->key_mod;
1856 my $sym = $ev->key_sym; 2027 my $sym = $ev->key_sym;
1857 2028
1858 if ($sym == SDLK_KP5) { 2029 if ($sym == SDLK_KP5) {
1859 $::CONN->user_send ("command stay fire"); 2030 $::CONN->user_send ("stay fire");
1860 } elsif ($sym == SDLK_a) { 2031 } elsif ($sym == SDLK_a) {
1861 $::CONN->user_send ("command apply"); 2032 $::CONN->user_send ("apply");
1862 } elsif ($sym == SDLK_QUOTE) { 2033 } elsif ($sym == SDLK_QUOTE) {
1863 $self->emit ('activate_console'); 2034 $self->emit ('activate_console');
1864 } elsif ($sym == SDLK_SLASH) { 2035 } elsif ($sym == SDLK_SLASH) {
1865 $self->emit ('activate_console' => '/'); 2036 $self->emit ('activate_console' => '/');
1866 } elsif (exists $DIR{$sym}) { 2037 } elsif (exists $DIR{$sym}) {
1867 if ($mod & KMOD_SHIFT) { 2038 if ($mod & KMOD_SHIFT) {
1868 $self->{shft}++; 2039 $self->{shft}++;
1869 $::CONN->user_send ("command fire $DIR{$sym}[0]"); 2040 $::CONN->user_send ("fire $DIR{$sym}[0]");
1870 } elsif ($mod & KMOD_CTRL) { 2041 } elsif ($mod & KMOD_CTRL) {
1871 $self->{ctrl}++; 2042 $self->{ctrl}++;
1872 $::CONN->user_send ("command run $DIR{$sym}[0]"); 2043 $::CONN->user_send ("run $DIR{$sym}[0]");
1873 } else { 2044 } else {
1874 $::CONN->user_send ("command $DIR{$sym}[1]"); 2045 $::CONN->user_send ("$DIR{$sym}[1]");
1875 } 2046 }
1876 } 2047 }
1877} 2048}
1878 2049
1879sub key_up { 2050sub key_up {
1881 2052
1882 my $mod = $ev->key_mod; 2053 my $mod = $ev->key_mod;
1883 my $sym = $ev->key_sym; 2054 my $sym = $ev->key_sym;
1884 2055
1885 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { 2056 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
1886 $::CONN->user_send ("command fire_stop"); 2057 $::CONN->user_send ("fire_stop");
1887 } 2058 }
1888 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { 2059 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
1889 $::CONN->user_send ("command run_stop"); 2060 $::CONN->user_send ("run_stop");
1890 } 2061 }
1891} 2062}
1892 2063
1893############################################################################# 2064#############################################################################
1894 2065
1960 2131
1961 # TODO: use animation 2132 # TODO: use animation
1962 if ($self->{state} = !$self->{state}) { 2133 if ($self->{state} = !$self->{state}) {
1963 $CFClient::UI::ROOT->add ($self->{other}); 2134 $CFClient::UI::ROOT->add ($self->{other});
1964 $self->{other}->move ($self->coord2global (0, $self->{h})); 2135 $self->{other}->move ($self->coord2global (0, $self->{h}));
2136 $self->emit ("open");
1965 } else { 2137 } else {
1966 $CFClient::UI::ROOT->remove ($self->{other}); 2138 $CFClient::UI::ROOT->remove ($self->{other});
2139 $self->emit ("close");
1967 } 2140 }
2141
2142 $self->emit (changed => $self->{state});
1968} 2143}
1969 2144
1970############################################################################# 2145#############################################################################
1971 2146
1972package CFClient::UI::Root; 2147package CFClient::UI::Root;
1973 2148
1974our @ISA = CFClient::UI::Container::; 2149our @ISA = CFClient::UI::Container::;
1975 2150
1976use SDL::OpenGL; 2151use SDL::OpenGL;
2152
2153sub check_size {
2154 my ($self) = @_;
2155
2156 $self->configure (0, 0, $::WITH, $::HEIGHT);
2157}
1977 2158
1978sub size_request { 2159sub size_request {
1979 ($::WIDTH, $::HEIGHT) 2160 ($::WIDTH, $::HEIGHT)
1980} 2161}
1981 2162
1982sub size_allocate { 2163sub configure {
1983 my ($self, $x, $y, $w, $h) = @_; 2164 my ($self, $x, $y, $w, $h) = @_;
1984 2165
1985 $self->_size_allocate ($x, $y, $w, $h); 2166 $self->SUPER::configure ($x, $y, $w, $h);
1986 2167
1987 $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) 2168 $_->configure ($_->{x}, $_->{y}, $_->size_request)
1988 for @{$self->{children}}; 2169 for @{$self->{children}};
1989} 2170}
1990 2171
1991sub _topleft { 2172sub _topleft {
1992 my ($self, $x, $y) = @_; 2173 my ($self, $x, $y) = @_;
1995} 2176}
1996 2177
1997sub update { 2178sub update {
1998 my ($self) = @_; 2179 my ($self) = @_;
1999 2180
2000 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); 2181 $self->check_size;
2001 ::refresh (); 2182 ::refresh ();
2002} 2183}
2003 2184
2004sub add { 2185sub add {
2005 my ($self, $widget) = @_; 2186 my ($self, $child) = @_;
2006 2187
2007 $self->SUPER::add ($widget); 2188 $self->SUPER::add ($child);
2008
2009 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request);
2010} 2189}
2011 2190
2012sub on_refresh { 2191sub on_refresh {
2013 my ($self, $id, $cb) = @_; 2192 my ($self, $id, $cb) = @_;
2014 2193

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines