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.202 by root, Sun May 14 20:51:19 2006 UTC vs.
Revision 1.234 by root, Thu May 25 16:24:44 2006 UTC

31 $TOOLTIP->set_tooltip_from ($widget); 31 $TOOLTIP->set_tooltip_from ($widget);
32 $TOOLTIP->show; 32 $TOOLTIP->show;
33 33
34 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 34 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
35 35
36 if ($x + $TOOLTIP->{w} > $::WIDTH) {
37 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); 36 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0)
38 } 37 if $x + $TOOLTIP->{w} > $::WIDTH;
39 38
40 $TOOLTIP->move ($x, $y); 39 $TOOLTIP->move ($x, $y);
41 $TOOLTIP->check_size; 40 $TOOLTIP->check_size;
42 $TOOLTIP->update; 41 $TOOLTIP->update;
43 } 42 }
51 delete $TOOLTIP->{owner}; 50 delete $TOOLTIP->{owner};
52} 51}
53 52
54# class methods for events 53# class methods for events
55sub feed_sdl_key_down_event { 54sub feed_sdl_key_down_event {
56 $FOCUS->emit (key_down => $_[0]) || $FOCUS->key_down ($_[0]) 55 $FOCUS->emit (key_down => $_[0])
57 if $FOCUS; 56 if $FOCUS;
58} 57}
59 58
60sub feed_sdl_key_up_event { 59sub feed_sdl_key_up_event {
61 $FOCUS->emit (key_up => $_[0]) || $FOCUS->key_up ($_[0]) 60 $FOCUS->emit (key_up => $_[0])
62 if $FOCUS; 61 if $FOCUS;
63} 62}
64 63
65sub feed_sdl_button_down_event { 64sub feed_sdl_button_down_event {
66 my ($ev) = @_; 65 my ($ev) = @_;
75 check_tooltip; 74 check_tooltip;
76 } 75 }
77 76
78 $BUTTON_STATE |= 1 << ($ev->{button} - 1); 77 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
79 78
80 if ($GRAB) { 79 $GRAB->emit (button_down => $ev, $GRAB->coord2local ($x, $y))
81 ($x, $y) = $GRAB->coord2local ($x, $y); 80 if $GRAB;
82 $GRAB->emit (button_down => $ev, $x, $y) || $GRAB->button_down ($ev, $x, $y);
83 }
84} 81}
85 82
86sub feed_sdl_button_up_event { 83sub feed_sdl_button_up_event {
87 my ($ev) = @_; 84 my ($ev) = @_;
88 my ($x, $y) = ($ev->{x}, $ev->{y}); 85 my ($x, $y) = ($ev->{x}, $ev->{y});
89 86
90 my $widget = $GRAB || $ROOT->find_widget ($x, $y); 87 my $widget = $GRAB || $ROOT->find_widget ($x, $y);
91 88
92 $BUTTON_STATE &= ~(1 << ($ev->{button} - 1)); 89 $BUTTON_STATE &= ~(1 << ($ev->{button} - 1));
93 90
94 if ($GRAB) { 91 $GRAB->emit (button_up => $ev, $GRAB->coord2local ($x, $y))
95 ($x, $y) = $GRAB->coord2local ($x, $y); 92 if $GRAB;
96 $GRAB->emit (button_up => $ev, $x, $y) || $GRAB->button_up ($ev, $x, $y);
97 }
98 93
99 if (!$BUTTON_STATE) { 94 if (!$BUTTON_STATE) {
100 my $grab = $GRAB; undef $GRAB; 95 my $grab = $GRAB; undef $GRAB;
101 $grab->update if $grab; 96 $grab->update if $grab;
102 $GRAB->update if $GRAB; 97 $GRAB->update if $GRAB;
118 $HOVER->update if $HOVER && $HOVER->{can_hover}; 113 $HOVER->update if $HOVER && $HOVER->{can_hover};
119 114
120 check_tooltip; 115 check_tooltip;
121 } 116 }
122 117
123 if ($HOVER) {
124 ($x, $y) = $HOVER->coord2local ($x, $y);
125 $HOVER->emit (mouse_motion => $ev, $x, $y) || $HOVER->mouse_motion ($ev, $x, $y); 118 $HOVER->emit (mouse_motion => $ev, $HOVER->coord2local ($x, $y))
126 } 119 if $HOVER;
127} 120}
128 121
129# convert position array to integers 122# convert position array to integers
130sub harmonize { 123sub harmonize {
131 my ($vals) = @_; 124 my ($vals) = @_;
137 $rem += $_ - $i; 130 $rem += $_ - $i;
138 $_ = $i; 131 $_ = $i;
139 } 132 }
140} 133}
141 134
135sub full_refresh {
136 # make a copy, otherwise for complains about freed values.
137 my @widgets = values %WIDGET;
138
139 $_->update
140 for @widgets;
141}
142
143sub reconfigure_widgets {
144 # make a copy, otherwise C<for> complains about freed values.
145 my @widgets = values %WIDGET;
146
147 $_->reconfigure
148 for @widgets;
149}
150
142# call when resolution changes etc. 151# call when resolution changes etc.
143sub rescale_widgets { 152sub rescale_widgets {
144 my ($sx, $sy) = @_; 153 my ($sx, $sy) = @_;
145 154
146 for my $widget (values %WIDGET) { 155 for my $widget (values %WIDGET) {
147 if ($widget->{toplevel}) { 156 if ($widget->{is_toplevel}) {
148 $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; 157 $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x};
149 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; 158 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
150 $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; 159 $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w};
151 $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; 160 $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w};
152 $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; 161 $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y};
153 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; 162 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h};
154 $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; 163 $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h};
155 $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h}; 164 $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h};
156 } 165 }
157
158 $widget->reconfigure;
159 } 166 }
167
168 reconfigure_widgets;
160} 169}
161 170
162############################################################################# 171#############################################################################
163 172
164package CFClient::UI::Base; 173package CFClient::UI::Base;
196 %$self = (); 205 %$self = ();
197} 206}
198 207
199sub show { 208sub show {
200 my ($self) = @_; 209 my ($self) = @_;
201
202 return if $self->{parent}; 210 return if $self->{parent};
203 211
204 $self->{toplevel} = 1;
205 $CFClient::UI::ROOT->add ($self); 212 $CFClient::UI::ROOT->add ($self);
206} 213}
207 214
208sub hide { 215sub show_centered {
209 my ($self) = @_; 216 my ($self) = @_;
217 return if $self->{parent};
218
219 $self->show;
220
221 $CFClient::UI::ROOT->on_post_alloc (
222 "centered $self" => sub {
223 $self->move (($::WIDTH - $self->{w}) * 0.5, ($::HEIGHT - $self->{h}) * 0.5);
224 },
225 );
226}
227
228sub set_invisible {
229 my ($self) = @_;
230
231 # broken show/hide model
232
233 delete $self->{visible};
210 234
211 undef $GRAB if $GRAB == $self; 235 undef $GRAB if $GRAB == $self;
212 undef $HOVER if $HOVER == $self; 236 undef $HOVER if $HOVER == $self;
237
238 CFClient::UI::check_tooltip
239 if $CFClient::UI::TOOLTIP->{owner} == $self;
240
241 $self->focus_out;
242}
243
244sub hide {
245 my ($self) = @_;
246
247 $self->set_invisible;
213 248
214 $self->{parent}->remove ($self) 249 $self->{parent}->remove ($self)
215 if $self->{parent}; 250 if $self->{parent};
216} 251}
217 252
284 319
285 delete $self->{max_w}; $self->{max_w} = $w if $w; 320 delete $self->{max_w}; $self->{max_w} = $w if $w;
286 delete $self->{max_h}; $self->{max_h} = $h if $h; 321 delete $self->{max_h}; $self->{max_h} = $h if $h;
287} 322}
288 323
324sub set_tooltip {
325 my ($self, $tooltip) = @_;
326
327 $tooltip =~ s/^\s+//;
328 $tooltip =~ s/\s+$//;
329
330 return if $self->{tooltip} eq $tooltip;
331
332 $self->{tooltip} = $tooltip;
333
334 if ($CFClient::UI::TOOLTIP->{owner} == $self) {
335 delete $CFClient::UI::TOOLTIP->{owner};
336 CFClient::UI::check_tooltip;
337 }
338}
339
289# translate global coordinates to local coordinate system 340# translate global coordinates to local coordinate system
290sub coord2local { 341sub coord2local {
291 my ($self, $x, $y) = @_; 342 my ($self, $x, $y) = @_;
292 343
293 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) 344 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y})
306 return if $FOCUS == $self; 357 return if $FOCUS == $self;
307 return unless $self->{can_focus}; 358 return unless $self->{can_focus};
308 359
309 my $focus = $FOCUS; $FOCUS = $self; 360 my $focus = $FOCUS; $FOCUS = $self;
310 361
311 $self->emit (focus_in => $focus); 362 $self->_emit (focus_in => $focus);
312 363
313 $focus->update if $focus; 364 $focus->update if $focus;
314 $FOCUS->update; 365 $FOCUS->update;
315} 366}
316 367
319 370
320 return unless $FOCUS == $self; 371 return unless $FOCUS == $self;
321 372
322 my $focus = $FOCUS; undef $FOCUS; 373 my $focus = $FOCUS; undef $FOCUS;
323 374
324 $self->emit (focus_out => $focus); 375 $self->_emit (focus_out => $focus);
325 376
326 $focus->update if $focus; #? 377 $focus->update if $focus; #?
378
379 $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus
380 unless $FOCUS;
327} 381}
328 382
329sub mouse_motion { } 383sub mouse_motion { }
330sub button_up { } 384sub button_up { }
331sub key_down { } 385sub key_down { }
332sub key_up { } 386sub key_up { }
333 387
334sub button_down { 388sub button_down {
335 my ($self, $ev, $x, $y) = @_; 389 my ($self, $ev, $x, $y) = @_;
336 390
337 $self->focus_in; 391 $self->focus_in;
371 if ($ENV{PCLIENT_DEBUG}) { 425 if ($ENV{PCLIENT_DEBUG}) {
372 glPushMatrix; 426 glPushMatrix;
373 glColor 1, 1, 0, 1; 427 glColor 1, 1, 0, 1;
374 glTranslate $self->{x} + 0.375, $self->{y} + 0.375; 428 glTranslate $self->{x} + 0.375, $self->{y} + 0.375;
375 glBegin GL_LINE_LOOP; 429 glBegin GL_LINE_LOOP;
376 glVertex 0 , 0; 430 glVertex 0 , 0;
377 glVertex $self->{w}, 0; 431 glVertex $self->{w} - 1, 0;
378 glVertex $self->{w}, $self->{h}; 432 glVertex $self->{w} - 1, $self->{h} - 1;
379 glVertex 0 , $self->{h}; 433 glVertex 0 , $self->{h} - 1;
380 glEnd; 434 glEnd;
381 glPopMatrix; 435 glPopMatrix;
382 CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; 436 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
383 } 437 }
384} 438}
385 439
386sub _draw { 440sub _draw {
387 my ($self) = @_; 441 my ($self) = @_;
407 Scalar::Util::weaken ($self->{parent} = $parent); 461 Scalar::Util::weaken ($self->{parent} = $parent);
408 462
409 # TODO: req_w _does_change after ->reconfigure 463 # TODO: req_w _does_change after ->reconfigure
410 $self->check_size 464 $self->check_size
411 unless exists $self->{req_w}; 465 unless exists $self->{req_w};
466
467 $self->show;
412} 468}
413 469
414sub check_size { 470sub check_size {
415 my ($self, $forced) = @_; 471 my ($self, $forced) = @_;
416 472
429 my ($self, $signal, $cb) = @_; 485 my ($self, $signal, $cb) = @_;
430 486
431 push @{ $self->{signal_cb}{$signal} }, $cb; 487 push @{ $self->{signal_cb}{$signal} }, $cb;
432} 488}
433 489
490sub _emit {
491 my ($self, $signal, @args) = @_;
492
493 List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []}
494}
495
434sub emit { 496sub emit {
435 my ($self, $signal, @args) = @_; 497 my ($self, $signal, @args) = @_;
436 498
437 List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []} 499 $self->_emit ($signal, @args)
500 || $self->$signal (@args);
438} 501}
439 502
440sub DESTROY { 503sub DESTROY {
441 my ($self) = @_; 504 my ($self) = @_;
442 505
457 my $class = shift; 520 my $class = shift;
458 521
459 # range [value, low, high, page] 522 # range [value, low, high, page]
460 523
461 $class->SUPER::new ( 524 $class->SUPER::new (
462 bg => [0, 0, 0, 0.2], 525 #bg => [0, 0, 0, 0.2],
463 active_bg => [1, 1, 1, 0.5], 526 #active_bg => [1, 1, 1, 0.5],
464 @_ 527 @_
465 ) 528 )
466} 529}
467 530
468sub _draw { 531sub _draw {
469 my ($self) = @_; 532 my ($self) = @_;
470 533
534 my $color = $FOCUS == $self && $self->{active_bg}
535 ? $self->{active_bg}
536 : $self->{bg};
537
538 if ($color && (@$color < 4 || $color->[3])) {
471 my ($w, $h) = @$self{qw(w h)}; 539 my ($w, $h) = @$self{qw(w h)};
472 540
473 glEnable GL_BLEND; 541 glEnable GL_BLEND;
474 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 542 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
475 glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} }; 543 glColor @$color;
476 544
477 glBegin GL_QUADS; 545 glBegin GL_QUADS;
478 glVertex 0 , 0; 546 glVertex 0 , 0;
479 glVertex 0 , $h; 547 glVertex 0 , $h;
480 glVertex $w, $h; 548 glVertex $w, $h;
481 glVertex $w, 0; 549 glVertex $w, 0;
482 glEnd; 550 glEnd;
483 551
484 glDisable GL_BLEND; 552 glDisable GL_BLEND;
553 }
485} 554}
486 555
487############################################################################# 556#############################################################################
488 557
489package CFClient::UI::Empty; 558package CFClient::UI::Empty;
673 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 742 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
674 glClearColor 0, 0, 0, 0; 743 glClearColor 0, 0, 0, 0;
675 glClear GL_COLOR_BUFFER_BIT; 744 glClear GL_COLOR_BUFFER_BIT;
676 745
677 $self->_render; 746 $self->_render;
678# glColorMask 1, 1, 1, 0;
679# glEnable GL_BLEND;
680# glBlendFunc GL_SRC_ALPHA, GL_ZERO;
681# glRasterPos 0, 0;
682# glCopyPixels 0, 0, $self->{w}, $self->{h};
683# glDisable GL_BLEND;
684# glColorMask 1, 1, 1, 1;
685 }; 747 };
686} 748}
687 749
688sub _draw { 750sub _draw {
689 my ($self) = @_; 751 my ($self) = @_;
693 my $tex = $self->{texture} 755 my $tex = $self->{texture}
694 or return; 756 or return;
695 757
696 glEnable GL_TEXTURE_2D; 758 glEnable GL_TEXTURE_2D;
697 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 759 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
698 glColor 0, 0, 0, 1; 760 glColor 1, 1, 1, 1;
699 761
700 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); 762 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h);
701 763
702 glDisable GL_TEXTURE_2D; 764 glDisable GL_TEXTURE_2D;
703} 765}
706 768
707package CFClient::UI::ViewPort; 769package CFClient::UI::ViewPort;
708 770
709our @ISA = CFClient::UI::Window::; 771our @ISA = CFClient::UI::Window::;
710 772
773sub new {
774 my $class = shift;
775
776 $class->SUPER::new (
777 scroll_x => 0,
778 scroll_y => 1,
779 @_,
780 )
781}
782
711sub size_request { 783sub size_request {
712 my ($self) = @_; 784 my ($self) = @_;
713 785
714 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; 786 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)};
715 $self->child->configure (0, 0, @$self{qw(child_w child_h)});
716 787
717 @$self{qw(child_w child_h)} 788 @$self{qw(child_w child_h)}
718} 789}
719 790
720sub size_allocate { 791sub size_allocate {
721 my ($self, $w, $h) = @_; 792 my ($self, $w, $h) = @_;
722 793
794 $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w};
795 $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h};
796
797 $self->child->configure (0, 0, $w, $h);
723 $self->update; 798 $self->update;
724} 799}
725 800
726sub set_offset { 801sub set_offset {
727 my ($self, $x, $y) = @_; 802 my ($self, $x, $y) = @_;
781 856
782 my $slider = new CFClient::UI::Slider 857 my $slider = new CFClient::UI::Slider
783 vertical => 1, 858 vertical => 1,
784 range => [0, 0, 1, 0.01], # HACK fix 859 range => [0, 0, 1, 0.01], # HACK fix
785 connect_changed => sub { 860 connect_changed => sub {
786 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); 861 $self->{vp}->set_offset (0, $_[1]);
787 }, 862 },
788 ; 863 ;
789 864
790 $self = $class->SUPER::new ( 865 $self = $class->SUPER::new (
791 vp => (new CFClient::UI::ViewPort), 866 vp => (new CFClient::UI::ViewPort expand => 1),
792 slider => $slider, 867 slider => $slider,
793 @_, 868 @_,
794 ); 869 );
795 870
796 $self->{vp}->add ($self->{scrolled}); 871 $self->{vp}->add ($self->{scrolled});
797 $self->add ($self->{vp}); 872 $self->add ($self->{vp});
798 $self->add ($self->{slider}); 873 $self->add ($self->{slider});
799 874
800 $self 875 $self
876}
877
878sub size_allocate {
879 my ($self, $w, $h) = @_;
880
881 $self->SUPER::size_allocate ($w, $h);
882
883 my $child = $self->{vp}->child;
884 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]);
801} 885}
802 886
803#TODO# update range on size_allocate depending on child 887#TODO# update range on size_allocate depending on child
804# update viewport offset on scroll 888# update viewport offset on scroll
805 889
859 my $class = shift; 943 my $class = shift;
860 944
861 # TODO: user_x, user_y, overwrite moveto? 945 # TODO: user_x, user_y, overwrite moveto?
862 946
863 my $self = $class->SUPER::new ( 947 my $self = $class->SUPER::new (
864 bg => [1, 1, 1, 1], 948 bg => [1, 1, 1, 1],
865 border_bg => [1, 1, 1, 1], 949 border_bg => [1, 1, 1, 1],
866 border => 0.6, 950 border => 0.6,
867 toplevel => 1, 951 is_toplevel => 1,
868 can_events => 1, 952 can_events => 1,
869 @_ 953 @_
870 ); 954 );
871 955
872 $self->{title} &&= new CFClient::UI::Label 956 $self->{title} &&= new CFClient::UI::Label
873 align => 0, 957 align => 0,
897 my ($self, $w, $h) = @_; 981 my ($self, $w, $h) = @_;
898 982
899 $h -= List::Util::max 0, $self->border * 2; 983 $h -= List::Util::max 0, $self->border * 2;
900 $w -= List::Util::max 0, $self->border * 2; 984 $w -= List::Util::max 0, $self->border * 2;
901 985
902 $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) 986 $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2)
903 if $self->{title}; 987 if $self->{title};
904 988
905 $self->child->configure ($self->border, $self->border, $w, $h); 989 $self->child->configure ($self->border, $self->border, $w, $h);
906} 990}
907 991
1013sub new { 1097sub new {
1014 my $class = shift; 1098 my $class = shift;
1015 1099
1016 $class->SUPER::new ( 1100 $class->SUPER::new (
1017 col_expand => [], 1101 col_expand => [],
1018 @_ 1102 @_,
1019 ) 1103 )
1020} 1104}
1021 1105
1022sub add { 1106sub add {
1023 my ($self, $x, $y, $child) = @_; 1107 my ($self, $x, $y, $child) = @_;
1268 1352
1269############################################################################# 1353#############################################################################
1270 1354
1271package CFClient::UI::Label; 1355package CFClient::UI::Label;
1272 1356
1273our @ISA = CFClient::UI::Base::; 1357our @ISA = CFClient::UI::DrawBG::;
1274 1358
1275use CFClient::OpenGL; 1359use CFClient::OpenGL;
1276 1360
1277sub new { 1361sub new {
1278 my ($class, %arg) = @_; 1362 my ($class, %arg) = @_;
1279 1363
1280 my $self = $class->SUPER::new ( 1364 my $self = $class->SUPER::new (
1281 fg => [1, 1, 1], 1365 fg => [1, 1, 1],
1366 #bg => none
1367 #active_bg => none
1282 #font => default_font 1368 #font => default_font
1283 #text => initial text 1369 #text => initial text
1284 #markup => initial narkup 1370 #markup => initial narkup
1371 #max_w => maximum pixel width
1372 ellipsise => 3, # end
1285 layout => (new CFClient::Layout), 1373 layout => (new CFClient::Layout),
1286 fontsize => 1, 1374 fontsize => 1,
1287 align => -1, 1375 align => -1,
1288 valign => -1, 1376 valign => -1,
1289 padding => 2, 1377 padding => 2,
1304 } 1392 }
1305 1393
1306 $self 1394 $self
1307} 1395}
1308 1396
1309sub escape { 1397sub escape($) {
1310 local $_ = $_[1]; 1398 local $_ = $_[0];
1311 1399
1312 s/&/&amp;/g; 1400 s/&/&amp;/g;
1313 s/>/&gt;/g; 1401 s/>/&gt;/g;
1314 s/</&lt;/g; 1402 s/</&lt;/g;
1315 1403
1316 $_[1] 1404 $_
1317} 1405}
1318 1406
1319sub update { 1407sub update {
1320 my ($self) = @_; 1408 my ($self) = @_;
1321 1409
1354sub size_request { 1442sub size_request {
1355 my ($self) = @_; 1443 my ($self) = @_;
1356 1444
1357 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1445 $self->{layout}->set_font ($self->{font}) if $self->{font};
1358 $self->{layout}->set_width ($self->{max_w} || -1); 1446 $self->{layout}->set_width ($self->{max_w} || -1);
1447 $self->{layout}->set_ellipsise ($self->{ellipsise});
1448 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1359 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1449 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1360 1450
1361 my ($w, $h) = $self->{layout}->size; 1451 my ($w, $h) = $self->{layout}->size;
1362 1452
1363 if (exists $self->{template}) { 1453 if (exists $self->{template}) {
1393} 1483}
1394 1484
1395sub _draw { 1485sub _draw {
1396 my ($self) = @_; 1486 my ($self) = @_;
1397 1487
1488 $self->SUPER::_draw; # draw background, if applicable
1489
1398 my $tex = $self->{texture} ||= do { 1490 my $tex = $self->{texture} ||= do {
1399 $self->{layout}->set_foreground (@{$self->{fg}}); 1491 $self->{layout}->set_foreground (@{$self->{fg}});
1400 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1492 $self->{layout}->set_font ($self->{font}) if $self->{font};
1401 $self->{layout}->set_width ($self->{w}); 1493 $self->{layout}->set_width ($self->{w});
1494 $self->{layout}->set_ellipsise ($self->{ellipsise});
1495 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1402 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1496 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1403 1497
1404 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1498 my $tex = new_from_layout CFClient::Texture $self->{layout};
1405 1499
1406 $self->{ox} = int $self->{align} < 0 ? $self->{padding} 1500 $self->{ox} = int ($self->{align} < 0 ? $self->{padding}
1407 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1501 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1408 : ($self->{w} - $tex->{w}) * 0.5; 1502 : ($self->{w} - $tex->{w}) * 0.5);
1409 1503
1410 $self->{oy} = int $self->{valign} < 0 ? $self->{padding} 1504 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding}
1411 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} 1505 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1412 : ($self->{h} - $tex->{h}) * 0.5; 1506 : ($self->{h} - $tex->{h}) * 0.5);
1413 1507
1414 $tex 1508 $tex
1415 }; 1509 };
1416 1510
1417 glEnable GL_TEXTURE_2D; 1511 glEnable GL_TEXTURE_2D;
1445 active_fg => [0, 0, 0], 1539 active_fg => [0, 0, 0],
1446 can_hover => 1, 1540 can_hover => 1,
1447 can_focus => 1, 1541 can_focus => 1,
1448 valign => 0, 1542 valign => 0,
1449 can_events => 1, 1543 can_events => 1,
1544 #text => ...
1450 @_ 1545 @_
1451 ) 1546 )
1452} 1547}
1453 1548
1454sub _set_text { 1549sub _set_text {
1464 $self->{text} = $text; 1559 $self->{text} = $text;
1465 1560
1466 $text =~ s/./*/g if $self->{hidden}; 1561 $text =~ s/./*/g if $self->{hidden};
1467 $self->{layout}->set_text ("$text "); 1562 $self->{layout}->set_text ("$text ");
1468 1563
1469 $self->emit (changed => $self->{text}); 1564 $self->_emit (changed => $self->{text});
1470} 1565}
1471 1566
1472sub set_text { 1567sub set_text {
1473 my ($self, $text) = @_; 1568 my ($self, $text) = @_;
1474 1569
1475 $self->{cursor} = length $text; 1570 $self->{cursor} = length $text;
1476 $self->_set_text ($text); 1571 $self->_set_text ($text);
1572 $self->update;
1477 $self->check_size; 1573 $self->check_size;
1478 $self->update;
1479} 1574}
1480 1575
1481sub get_text { 1576sub get_text {
1482 $_[0]{text} 1577 $_[0]{text}
1483} 1578}
1486 my ($self) = @_; 1581 my ($self) = @_;
1487 1582
1488 my ($w, $h) = $self->SUPER::size_request; 1583 my ($w, $h) = $self->SUPER::size_request;
1489 1584
1490 ($w + 1, $h) # add 1 for cursor 1585 ($w + 1, $h) # add 1 for cursor
1491}
1492
1493sub size_allocate {
1494 my ($self, $w, $h) = @_;
1495
1496 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text
1497} 1586}
1498 1587
1499sub key_down { 1588sub key_down {
1500 my ($self, $ev) = @_; 1589 my ($self, $ev) = @_;
1501 1590
1516 } elsif ($sym == CFClient::SDLK_HOME) { 1605 } elsif ($sym == CFClient::SDLK_HOME) {
1517 $self->{cursor} = 0; 1606 $self->{cursor} = 0;
1518 } elsif ($sym == CFClient::SDLK_END) { 1607 } elsif ($sym == CFClient::SDLK_END) {
1519 $self->{cursor} = length $text; 1608 $self->{cursor} = length $text;
1520 } elsif ($uni == 27) { 1609 } elsif ($uni == 27) {
1521 $self->emit ('escape'); 1610 $self->_emit ('escape');
1522 } elsif ($uni) { 1611 } elsif ($uni) {
1523 substr $text, $self->{cursor}++, 0, chr $uni; 1612 substr $text, $self->{cursor}++, 0, chr $uni;
1524 } 1613 }
1525 1614
1526 $self->_set_text ($text); 1615 $self->_set_text ($text);
1527 $self->update; 1616 $self->update;
1617 $self->check_size;
1528} 1618}
1529 1619
1530sub focus_in { 1620sub focus_in {
1531 my ($self) = @_; 1621 my ($self) = @_;
1532 1622
1612 if ($sym == 13) { 1702 if ($sym == 13) {
1613 unshift @{$self->{history}}, 1703 unshift @{$self->{history}},
1614 my $txt = $self->get_text; 1704 my $txt = $self->get_text;
1615 $self->{history_pointer} = -1; 1705 $self->{history_pointer} = -1;
1616 $self->{history_saveback} = ''; 1706 $self->{history_saveback} = '';
1617 $self->emit (activate => $txt); 1707 $self->_emit (activate => $txt);
1618 $self->update; 1708 $self->update;
1619 1709
1620 } elsif ($sym == CFClient::SDLK_UP) { 1710 } elsif ($sym == CFClient::SDLK_UP) {
1621 if ($self->{history_pointer} < 0) { 1711 if ($self->{history_pointer} < 0) {
1622 $self->{history_saveback} = $self->get_text; 1712 $self->{history_saveback} = $self->get_text;
1661 my $class = shift; 1751 my $class = shift;
1662 1752
1663 $class->SUPER::new ( 1753 $class->SUPER::new (
1664 padding => 4, 1754 padding => 4,
1665 fg => [1, 1, 1], 1755 fg => [1, 1, 1],
1666 bg => [1, 1, 1, 0.2],
1667 active_fg => [0, 0, 1], 1756 active_fg => [0, 0, 1],
1668 can_hover => 1, 1757 can_hover => 1,
1669 align => 0, 1758 align => 0,
1670 valign => 0, 1759 valign => 0,
1671 can_events => 1, 1760 can_events => 1,
1672 @_ 1761 @_
1673 ) 1762 )
1674} 1763}
1675 1764
1765sub activate { }
1766
1676sub button_up { 1767sub button_up {
1677 my ($self, $ev, $x, $y) = @_; 1768 my ($self, $ev, $x, $y) = @_;
1678 1769
1770 $self->emit ("activate")
1679 if ($x >= 0 && $x < $self->{w} 1771 if $x >= 0 && $x < $self->{w}
1680 && $y >= 0 && $y < $self->{h}) { 1772 && $y >= 0 && $y < $self->{h};
1681 $self->emit ("activate");
1682 }
1683} 1773}
1684 1774
1685sub _draw { 1775sub _draw {
1686 my ($self) = @_; 1776 my ($self) = @_;
1687 1777
1719 1809
1720 $class->SUPER::new ( 1810 $class->SUPER::new (
1721 padding => 2, 1811 padding => 2,
1722 fg => [1, 1, 1], 1812 fg => [1, 1, 1],
1723 active_fg => [1, 1, 0], 1813 active_fg => [1, 1, 0],
1814 bg => [0, 0, 0, 0.2],
1815 active_bg => [1, 1, 1, 0.5],
1724 state => 0, 1816 state => 0,
1725 can_hover => 1, 1817 can_hover => 1,
1726 @_ 1818 @_
1727 ) 1819 )
1728} 1820}
1737 my ($self, $ev, $x, $y) = @_; 1829 my ($self, $ev, $x, $y) = @_;
1738 1830
1739 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} 1831 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding}
1740 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { 1832 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) {
1741 $self->{state} = !$self->{state}; 1833 $self->{state} = !$self->{state};
1742 $self->emit (changed => $self->{state}); 1834 $self->_emit (changed => $self->{state});
1743 } 1835 }
1744} 1836}
1745 1837
1746sub _draw { 1838sub _draw {
1747 my ($self) = @_; 1839 my ($self) = @_;
2012 qw(s1_slider.png s1_slider_bg.png); 2104 qw(s1_slider.png s1_slider_bg.png);
2013 2105
2014sub new { 2106sub new {
2015 my $class = shift; 2107 my $class = shift;
2016 2108
2017 # range [value, low, high, page] 2109 # range [value, low, high, page, unit]
2018 2110
2019 # TODO: 0-width page 2111 # TODO: 0-width page
2020 # TODO: req_w/h are wrong with vertical 2112 # TODO: req_w/h are wrong with vertical
2021 # TODO: calculations are off 2113 # TODO: calculations are off
2022 my $self = $class->SUPER::new ( 2114 my $self = $class->SUPER::new (
2023 fg => [1, 1, 1], 2115 fg => [1, 1, 1],
2024 active_fg => [0, 0, 0], 2116 active_fg => [0, 0, 0],
2117 bg => [0, 0, 0, 0.2],
2118 active_bg => [1, 1, 1, 0.5],
2025 range => [0, 0, 100, 10], 2119 range => [0, 0, 100, 10, 0],
2026 req_w => $::WIDTH / 80, 2120 req_w => $::WIDTH / 80,
2027 req_h => $::WIDTH / 80, 2121 req_h => $::WIDTH / 80,
2028 vertical => 0, 2122 vertical => 0,
2029 can_hover => 1, 2123 can_hover => 1,
2030 inner_pad => 5, 2124 inner_pad => 0.02,
2031 @_ 2125 @_
2032 ); 2126 );
2033 2127
2128 $self->set_value ($self->{range}[0]);
2129 $self->update;
2130
2034 $self 2131 $self
2132}
2133
2134sub set_range {
2135 my ($self, $range) = @_;
2136
2137 $self->{range} = $range;
2138
2139 $self->update;
2140}
2141
2142sub set_value {
2143 my ($self, $value) = @_;
2144
2145 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}};
2146
2147 $hi = $lo + 1 if $hi <= $lo;
2148
2149 $page = $hi - $lo if $page > $hi - $lo;
2150
2151 $value = $lo if $value < $lo;
2152 $value = $hi - $page if $value > $hi - $page;
2153
2154 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit
2155 if $unit;
2156
2157 @{$self->{range}} = ($value, $lo, $hi, $page, $unit);
2158
2159 if ($value != $old_value) {
2160 $self->_emit (changed => $value);
2161 $self->update;
2162 }
2035} 2163}
2036 2164
2037sub size_request { 2165sub size_request {
2038 my ($self) = @_; 2166 my ($self) = @_;
2039 2167
2045 2173
2046sub button_down { 2174sub button_down {
2047 my ($self, $ev, $x, $y) = @_; 2175 my ($self, $ev, $x, $y) = @_;
2048 2176
2049 $self->SUPER::button_down ($ev, $x, $y); 2177 $self->SUPER::button_down ($ev, $x, $y);
2178
2179 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x];
2180
2050 $self->mouse_motion ($ev, $x, $y); 2181 $self->mouse_motion ($ev, $x, $y);
2051} 2182}
2052 2183
2053sub mouse_motion { 2184sub mouse_motion {
2054 my ($self, $ev, $x, $y) = @_; 2185 my ($self, $ev, $x, $y) = @_;
2055 2186
2056 if ($GRAB == $self) { 2187 if ($GRAB == $self) {
2188 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w});
2189
2190 my (undef, $lo, $hi, $page) = @{$self->{range}};
2191
2192 $x = ($x - $self->{click}[1]) / ($w * $self->{scale});
2193
2194 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo));
2195 }
2196}
2197
2198sub update {
2199 my ($self) = @_;
2200
2201 $CFClient::UI::ROOT->on_post_alloc ($self => sub {
2202 $self->set_value ($self->{range}[0]);
2203
2057 my ($value, $lo, $hi, $page) = @{$self->{range}}; 2204 my ($value, $lo, $hi, $page) = @{$self->{range}};
2205 my $range = ($hi - $page - $lo) || 1e-100;
2058 2206
2059 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); 2207 my $knob_w = List::Util::min 1, $page / ($hi - $lo) || 0.1;
2060 2208
2061 my $inner_pad_px = $self->_calc_inner_pad_px ($w); 2209 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5;
2062 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right 2210 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100;
2063 2211
2064 $x -= $inner_pad_px; # substract the padding 2212 $value = ($value - $lo) / $range;
2065 $x = $x * ($hi - $lo) / $inner_w + $lo; 2213 $value = $value * $self->{scale} + $self->{offset};
2066 $x = $lo if $x < $lo;
2067 $x = $hi - $page if $x > $hi - $page;
2068 $self->{range}[0] = $x;
2069 2214
2070 $self->emit (changed => $x); 2215 $self->{knob_x} = $value - $knob_w * 0.5;
2071 $self->update; 2216 $self->{knob_w} = $knob_w;
2072 } 2217 });
2073}
2074 2218
2075# the inner_* stuff is for generating a padding for the slider handle, 2219 $self->SUPER::update;
2076# so that the handle doesn't leave the texture. This calculation isn't 100%
2077# correct propably, but it does the job for now
2078sub _calc_inner_pad_px {
2079 my ($self, $w) = @_;
2080 ($w / 100) * $self->{inner_pad} # % to pixels
2081} 2220}
2082 2221
2083sub _draw { 2222sub _draw {
2084 my ($self) = @_; 2223 my ($self) = @_;
2085 2224
2086 $self->SUPER::_draw (); 2225 $self->SUPER::_draw ();
2087 2226
2088 my ($w, $h) = @$self{qw(w h)}; 2227 glScale $self->{w}, $self->{h};
2089 2228
2090 if ($self->{vertical}) { 2229 if ($self->{vertical}) {
2091 # draw a vertical slider like a rotated horizontal slider 2230 # draw a vertical slider like a rotated horizontal slider
2092 2231
2232 glTranslate 1, 0, 0;
2093 glRotate 90, 0, 0, 1; 2233 glRotate 90, 0, 0, 1;
2094 glTranslate 0, -$self->{w}, 0;
2095
2096 ($w, $h) = ($h, $w);
2097 } 2234 }
2098 2235
2099 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 2236 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
2100 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 2237 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
2101 2238
2102 my ($value, $lo, $hi, $page) = @{$self->{range}};
2103
2104 $hi = $value + 1 if $lo == $hi;
2105
2106 my $inner_pad_px = $self->_calc_inner_pad_px ($w);
2107 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
2108
2109 $page = int $page * $inner_w / ($hi - $lo);
2110 $value = int +($value - $lo) * $inner_w / ($hi - $lo);
2111
2112 $w -= $page;
2113 $page &= ~1;
2114 glTranslate $page * 0.5, 0, 0;
2115 $page ||= 2;
2116
2117 my $knob_a = $inner_pad_px + ($value - $page * 0.5);
2118 my $knob_b = $inner_pad_px + ($value + $page * 0.5);
2119
2120 glEnable GL_TEXTURE_2D; 2239 glEnable GL_TEXTURE_2D;
2121 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2240 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2122 2241
2123 # draw background 2242 # draw background
2124 $tex[1]->draw_quad_alpha (0, 0, $w, $h); 2243 $tex[1]->draw_quad_alpha (0, 0, 1, 1);
2125 2244
2126 # draw handle 2245 # draw handle
2127 $tex[0]->draw_quad_alpha ($knob_a, 0, $knob_b - $knob_a, $h); 2246 $tex[0]->draw_quad_alpha ($self->{knob_x}, 0, $self->{knob_w}, 1);
2128 2247
2129 glDisable GL_TEXTURE_2D; 2248 glDisable GL_TEXTURE_2D;
2130} 2249}
2250
2251#############################################################################
2252
2253package CFClient::UI::ValSlider;
2254
2255our @ISA = CFClient::UI::HBox::;
2256
2257sub new {
2258 my ($class, %arg) = @_;
2259
2260 my $range = delete $arg{range};
2261
2262 my $self = $class->SUPER::new (
2263 slider => (new CFClient::UI::Slider expand => 1, range => $range),
2264 entry => (new CFClient::UI::Label text => "", template => delete $arg{template}),
2265 to_value => sub { shift },
2266 from_value => sub { shift },
2267 %arg,
2268 );
2269
2270 $self->{slider}->connect (changed => sub {
2271 my ($self, $value) = @_;
2272 $self->{parent}{entry}->set_text ($self->{parent}{to_value}->($value));
2273 $self->{parent}->emit (changed => $value);
2274 });
2275
2276# $self->{entry}->connect (changed => sub {
2277# my ($self, $value) = @_;
2278# $self->{parent}{slider}->set_value ($self->{parent}{from_value}->($value));
2279# $self->{parent}->emit (changed => $value);
2280# });
2281
2282 $self->add ($self->{slider}, $self->{entry});
2283
2284 $self->{slider}->emit (changed => $self->{slider}{range}[0]);
2285
2286 $self
2287}
2288
2289sub set_range { shift->{slider}->set_range (@_) }
2290sub set_value { shift->{slider}->set_value (@_) }
2131 2291
2132############################################################################# 2292#############################################################################
2133 2293
2134package CFClient::UI::TextView; 2294package CFClient::UI::TextView;
2135 2295
2165 2325
2166 $self->{fontsize} = $fontsize; 2326 $self->{fontsize} = $fontsize;
2167 $self->reflow; 2327 $self->reflow;
2168} 2328}
2169 2329
2170sub text_height {
2171 my ($self, $text) = @_;
2172
2173 my $layout = $self->{layout};
2174
2175 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2176 $layout->set_width ($self->{children}[0]{w});
2177 $layout->set_markup ($text);
2178
2179 ($layout->size)[1]
2180}
2181
2182sub reflow {
2183 my ($self) = @_;
2184
2185 $self->{need_reflow}++;
2186 $self->update;
2187}
2188
2189sub size_allocate { 2330sub size_allocate {
2190 my ($self, $w, $h) = @_; 2331 my ($self, $w, $h) = @_;
2191 2332
2192 $self->SUPER::size_allocate ($w, $h); 2333 $self->SUPER::size_allocate ($w, $h);
2193 2334
2196 $self->{layout}->set_width ($self->{children}[0]{w}); 2337 $self->{layout}->set_width ($self->{children}[0]{w});
2197 2338
2198 $self->reflow; 2339 $self->reflow;
2199} 2340}
2200 2341
2342sub text_size {
2343 my ($self, $text, $indent) = @_;
2344
2345 my $layout = $self->{layout};
2346
2347 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2348 $layout->set_width ($self->{children}[0]{w} - $indent);
2349 $layout->set_markup ($text);
2350
2351 $layout->size
2352}
2353
2354sub reflow {
2355 my ($self) = @_;
2356
2357 $self->{need_reflow}++;
2358 $self->update;
2359}
2360
2361sub set_offset {
2362 my ($self, $offset) = @_;
2363
2364 # todo: base offset on lines or so, not on pixels
2365 $self->{children}[1]->set_value ($offset);
2366}
2367
2368sub clear {
2369 my ($self) = @_;
2370
2371 $self->{par} = [];
2372 $self->{height} = 0;
2373 $self->{children}[1]->set_range ([0, 0, 0, 1, 1]);
2374}
2375
2201sub add_paragraph { 2376sub add_paragraph {
2202 my ($self, $color, $text) = @_; 2377 my ($self, $color, $text, $indent) = @_;
2203 2378
2204 #TODO: intelligently "reformat" paragraph 2379 for my $line (split /\n/, $text) {
2205 2380 my ($w, $h) = $self->text_size ($line);
2206 my $height = $self->text_height ($text);
2207
2208 $self->{height} += $height; 2381 $self->{height} += $h;
2382 push @{$self->{par}}, [$w + $indent, $h, $color, $indent, $line];
2383 }
2209 2384
2210 push @{$self->{par}}, [$height, $color, $text];
2211
2212 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; 2385 $self->{children}[1]->set_range ([$self->{height}, 0, $self->{height}, $self->{h}, 1]);
2213 $self->{children}[1]->update;
2214} 2386}
2215 2387
2216sub update { 2388sub update {
2217 my ($self) = @_; 2389 my ($self) = @_;
2218 2390
2221 return unless $self->{h} > 0; 2393 return unless $self->{h} > 0;
2222 2394
2223 delete $self->{texture}; 2395 delete $self->{texture};
2224 2396
2225 $ROOT->on_post_alloc ($self, sub { 2397 $ROOT->on_post_alloc ($self, sub {
2398 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
2399
2226 if (delete $self->{need_reflow}) { 2400 if (delete $self->{need_reflow}) {
2227 my $height = 0; 2401 my $height = 0;
2228 2402
2229 $height += $_->[0] = $self->text_height ($_->[2]) 2403 my $layout = $self->{layout};
2404
2405 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2406
2230 for @{$self->{par}}; 2407 for (@{$self->{par}}) {
2408 if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support
2409 $layout->set_width ($W - $_->[3]);
2410 $layout->set_markup ($_->[4]);
2411 my ($w, $h) = $layout->size;
2412 $_->[0] = $w + $_->[3];
2413 $_->[1] = $h;
2414 }
2415
2416 $height += $_->[1];
2417 }
2231 2418
2232 $self->{height} = $height; 2419 $self->{height} = $height;
2233 2420
2234 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2421 $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]);
2235 2422
2236 delete $self->{texture}; 2423 delete $self->{texture};
2237 } 2424 }
2238 2425
2239 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2426 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub {
2240 glClearColor 0, 0, 0, 0; 2427 glClearColor 0.5, 0.5, 0.5, 0;
2241 glClear GL_COLOR_BUFFER_BIT; 2428 glClear GL_COLOR_BUFFER_BIT;
2242 2429
2243 glEnable GL_TEXTURE_2D;
2244 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2245
2246 my $top = int $self->{children}[1]{range}[0]; 2430 my $top = int $self->{children}[1]{range}[0];
2247 2431
2248 my $y0 = $top; 2432 my $y0 = $top;
2249 my $y1 = $top + $self->{h}; 2433 my $y1 = $top + $H;
2250 2434
2251 my $y = 0; 2435 my $y = 0;
2252 2436
2253 my $layout = $self->{layout}; 2437 my $layout = $self->{layout};
2254 2438
2255 $layout->set_font ($self->{font}) if $self->{font}; 2439 $layout->set_font ($self->{font}) if $self->{font};
2256 2440
2441 glEnable GL_BLEND;
2442 #TODO# not correct in windows where rgba is forced off
2443 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2444
2257 for my $par (@{$self->{par}}) { 2445 for my $par (@{$self->{par}}) {
2258 my $h = $par->[0]; 2446 my $h = $par->[1];
2259 2447
2260 if ($y0 < $y + $h && $y < $y1) { 2448 if ($y0 < $y + $h && $y < $y1) {
2261 $layout->set_foreground (@{ $par->[1] }); 2449 $layout->set_foreground (@{ $par->[2] });
2450 $layout->set_width ($W - $par->[3]);
2262 $layout->set_markup ($par->[2]); 2451 $layout->set_markup ($par->[4]);
2263 2452
2264 my ($W, $H) = $layout->size; 2453 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2265 CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); 2454
2455 glRasterPos $par->[3], $y - $y0;
2456 glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data;
2266 } 2457 }
2267 2458
2268 $y += $h; 2459 $y += $h;
2269 } 2460 }
2270 2461
2271 glDisable GL_TEXTURE_2D; 2462 glDisable GL_BLEND;
2272 }; 2463 };
2273 }); 2464 });
2274} 2465}
2275 2466
2276sub _draw { 2467sub _draw {
2277 my ($self) = @_; 2468 my ($self) = @_;
2278 2469
2279 glEnable GL_TEXTURE_2D; 2470 glEnable GL_TEXTURE_2D;
2280 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2471 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2281 glColor 1, 1, 1, 1; 2472 glColor 1, 1, 1, 1;
2282 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); 2473 $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2283 glDisable GL_TEXTURE_2D; 2474 glDisable GL_TEXTURE_2D;
2284 2475
2285 $self->{children}[1]->draw; 2476 $self->{children}[1]->draw;
2286 2477
2287} 2478}
2356 2547
2357 # TODO: use animation 2548 # TODO: use animation
2358 if ($self->{state} = !$self->{state}) { 2549 if ($self->{state} = !$self->{state}) {
2359 $CFClient::UI::ROOT->add ($self->{other}); 2550 $CFClient::UI::ROOT->add ($self->{other});
2360 $self->{other}->move ($self->coord2global (0, $self->{h})); 2551 $self->{other}->move ($self->coord2global (0, $self->{h}));
2361 $self->emit ("open"); 2552 $self->_emit ("open");
2362 } else { 2553 } else {
2363 $CFClient::UI::ROOT->remove ($self->{other}); 2554 $CFClient::UI::ROOT->remove ($self->{other});
2364 $self->emit ("close"); 2555 $self->_emit ("close");
2365 } 2556 }
2366 2557
2367 $self->emit (changed => $self->{state}); 2558 $self->_emit (changed => $self->{state});
2368} 2559}
2369 2560
2370############################################################################# 2561#############################################################################
2371 2562
2372package CFClient::UI::Tooltip; 2563package CFClient::UI::Tooltip;
2386 2577
2387sub set_tooltip_from { 2578sub set_tooltip_from {
2388 my ($self, $widget) = @_; 2579 my ($self, $widget) = @_;
2389 2580
2390 $self->add (new CFClient::UI::Label 2581 $self->add (new CFClient::UI::Label
2391 markup => $widget->{tooltip}, 2582 markup => $widget->{tooltip},
2392 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2583 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2393 fontsize => 0.8, 2584 fontsize => 0.8,
2394 fg => [0, 0, 0, 1], 2585 fg => [0, 0, 0, 1],
2586 ellipsise => 0,
2395 font => ($widget->{tooltip_font} || $::FONT_PROP), 2587 font => ($widget->{tooltip_font} || $::FONT_PROP),
2396 ); 2588 );
2397} 2589}
2398 2590
2399sub size_request { 2591sub size_request {
2400 my ($self) = @_; 2592 my ($self) = @_;
2446use CFClient::OpenGL; 2638use CFClient::OpenGL;
2447 2639
2448sub new { 2640sub new {
2449 my $class = shift; 2641 my $class = shift;
2450 2642
2451 $class->SUPER::new ( 2643 my $self = $class->SUPER::new (
2452 aspect => 1, 2644 aspect => 1,
2645 can_events => 0,
2453 @_, 2646 @_,
2454 ) 2647 );
2648
2649 if ($self->{anim} && $self->{animspeed}) {
2650 Scalar::Util::weaken (my $widget = $self);
2651
2652 $self->{timer} = Event->timer (
2653 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
2654 hard => 1,
2655 interval => $self->{animspeed},
2656 cb => sub {
2657 ++$widget->{frame};
2658 $widget->update;
2659 },
2660 );
2661 }
2662
2663 $self
2455} 2664}
2456 2665
2457sub size_request { 2666sub size_request {
2458 (32, 8) 2667 (32, 8)
2459} 2668}
2460 2669
2670sub update {
2671 my ($self) = @_;
2672
2673 return unless $self->{visible};
2674
2675 $self->SUPER::update;
2676}
2677
2461sub _draw { 2678sub _draw {
2462 my ($self) = @_; 2679 my ($self) = @_;
2463 2680
2464 return unless $::CONN;#d# manage and cache textures differently 2681 return unless $::CONN;
2682
2683 my $face;
2684
2685 if ($self->{frame}) {
2686 my $anim = $::CONN->{anim}[$self->{anim}];
2687
2688 $face = $anim->[ $self->{frame} % @$anim ]
2689 if $anim && @$anim;
2690 }
2691
2465 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2692 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]];
2466 2693
2467 # TODO animation
2468 if ($tex) { 2694 if ($tex) {
2469 glEnable GL_TEXTURE_2D; 2695 glEnable GL_TEXTURE_2D;
2470 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2696 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2471 glColor 1, 1, 1, 1; 2697 glColor 1, 1, 1, 1;
2472 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2698 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2473 glDisable GL_TEXTURE_2D; 2699 glDisable GL_TEXTURE_2D;
2474 } 2700 }
2475} 2701}
2476 2702
2703sub DESTROY {
2704 my ($self) = @_;
2705
2706 $self->{timer}->cancel
2707 if $self->{timer};
2708
2709 $self->SUPER::DESTROY;
2710}
2711
2477############################################################################# 2712#############################################################################
2478 2713
2479package CFClient::UI::InventoryItem; 2714package CFClient::UI::InventoryItem;
2480 2715
2481our @ISA = CFClient::UI::HBox::; 2716our @ISA = CFClient::UI::HBox::;
2485 2720
2486 my %args = @_; 2721 my %args = @_;
2487 2722
2488 my $item = delete $args{item}; 2723 my $item = delete $args{item};
2489 2724
2490 my $desc = $item->{nrof} < 2 2725 my $desc = CFClient::Item::desc_string $item;
2491 ? $item->{name}
2492 : "$item->{nrof} $item->{name_pl}";
2493
2494 2726
2495 my $self = $class->SUPER::new ( 2727 my $self = $class->SUPER::new (
2496 can_hover => 1, 2728 can_hover => 1,
2497 can_events => 1, 2729 can_events => 1,
2498 tooltip => (CFClient::UI::Label->escape ($desc) 2730 tooltip => ((CFClient::UI::Label::escape $desc)
2499 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), 2731 . "\n<small>leftclick - examine\nshift+leftclick - move/pickup/drop\nmiddle click - apply\nrightclick - menu</small>"),
2500 connect_button_down => sub { 2732 connect_button_down => sub {
2501 my ($self, $ev, $x, $y) = @_; 2733 my ($self, $ev, $x, $y) = @_;
2502 2734
2503 # todo: maybe put examine on 1? but should just be a tooltip :( 2735 # todo: maybe put examine on 1? but should just be a tooltip :(
2736 if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) {
2737 my $targ = $::CONN->{player}{tag};
2738
2739 if ($item->{container} == $::CONN->{player}{tag}) {
2740 $targ = $main::OPENCONT;
2741 }
2742
2743 $::CONN->send ("move $targ $item->{tag} 0");
2504 if ($ev->{button} == 1) { 2744 } elsif ($ev->{button} == 1) {
2505 $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); 2745 $::CONN->send ("examine $item->{tag}");
2506 } elsif ($ev->{button} == 2) { 2746 } elsif ($ev->{button} == 2) {
2507 $::CONN->send ("apply $item->{tag}"); 2747 $::CONN->send ("apply $item->{tag}");
2508 } elsif ($ev->{button} == 3) { 2748 } elsif ($ev->{button} == 3) {
2509 CFClient::UI::Menu->new ( 2749 my @menu_items = (
2510 items => [
2511 ["examine", sub { $::CONN->send ("examine $item->{tag}") }], 2750 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2512 [
2513 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2514 sub { $::CONN->send ("lock $item->{tag}") },
2515 ],
2516 ["mark", sub { $::CONN->send ("mark $item->{tag}") }], 2751 ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }],
2517 ["apply", sub { $::CONN->send ("apply $item->{tag}") }], 2752 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2753 (
2754 $item->{flags} & Crossfire::Protocol::F_LOCKED
2755 ? (
2756 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }],
2757 )
2758 : (
2759 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }],
2518 ["drop", sub { $::CONN->send ("move 0 $item->{tag} 0") }], 2760 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2761 )
2519 ], 2762 ),
2520 )->popup ($ev); 2763 );
2764
2765 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2521 } 2766 }
2522 2767
2523 1 2768 1
2524 }, 2769 },
2525 %args 2770 %args
2526 ); 2771 );
2772
2527 2773
2528 $self->add (new CFClient::UI::Face 2774 $self->add (new CFClient::UI::Face
2529 can_events => 0, 2775 can_events => 0,
2530 face => $item->{face}, 2776 face => $item->{face},
2531 anim => $item->{anim}, 2777 anim => $item->{anim},
2532 animspeed => $item->{animspeed}, 2778 animspeed => $item->{animspeed},
2533 ); 2779 );
2534 2780
2535 $self->add (new CFClient::UI::Label 2781 $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0);
2536 can_events => 0, 2782
2537 text => $desc, 2783 $self->{item} = $item;
2538 ); 2784
2785 $self->update_item;
2539 2786
2540 $self 2787 $self
2788}
2789
2790sub update_item {
2791 my ($self) = @_;
2792
2793 my $desc = CFClient::Item::desc_string ($self->{item});
2794
2795 $self->{name_lbl}->set_text ($desc);
2541} 2796}
2542 2797
2543############################################################################# 2798#############################################################################
2544 2799
2545package CFClient::UI::Inventory; 2800package CFClient::UI::Inventory;
2548 2803
2549sub new { 2804sub new {
2550 my $class = shift; 2805 my $class = shift;
2551 2806
2552 my $self = $class->SUPER::new ( 2807 my $self = $class->SUPER::new (
2553 scrolled => (new CFClient::UI::VBox), 2808 scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]),
2554 @_, 2809 @_,
2555 ); 2810 );
2556 2811
2557 $self 2812 $self
2558} 2813}
2568 or ($a->{name} cmp $b->{name}) 2823 or ($a->{name} cmp $b->{name})
2569 } @$items; 2824 } @$items;
2570 2825
2571 $self->{real_items} = \@items; 2826 $self->{real_items} = \@items;
2572 2827
2828 my $row = 0;
2573 for my $item (@items) { 2829 for my $item (@items) {
2574 my $desc = $item->{nrof} < 2 2830 CFClient::Item::update_widgets $item;
2575 ? $item->{name}
2576 : "$item->{nrof} $item->{name_pl}";
2577 2831
2578 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; 2832 $self->{scrolled}->add (0, $row, $item->{face_widget});
2579 } 2833 $self->{scrolled}->add (1, $row, $item->{desc_widget});
2834 $self->{scrolled}->add (2, $row, $item->{weight_widget});
2580 2835
2581 $self->{scrolled}->add (@items); 2836 $row++;
2837 }
2582 2838
2583# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2839# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2584} 2840}
2585 2841
2586sub size_request { 2842sub size_request {
2628 2884
2629# popup given the event (must be a mouse button down event currently) 2885# popup given the event (must be a mouse button down event currently)
2630sub popup { 2886sub popup {
2631 my ($self, $ev) = @_; 2887 my ($self, $ev) = @_;
2632 2888
2633 $self->emit ("popdown"); 2889 $self->_emit ("popdown");
2634 2890
2635 # maybe save $GRAB? must be careful about events... 2891 # maybe save $GRAB? must be careful about events...
2636 $GRAB = $self; 2892 $GRAB = $self;
2637 $self->{button} = $ev->{button}; 2893 $self->{button} = $ev->{button};
2638 2894
2653 2909
2654 if ($ev->{button} == $self->{button}) { 2910 if ($ev->{button} == $self->{button}) {
2655 undef $GRAB; 2911 undef $GRAB;
2656 $self->hide; 2912 $self->hide;
2657 2913
2658 $self->emit ("popdown"); 2914 $self->_emit ("popdown");
2659 $self->{hover}[1]->() if $self->{hover}; 2915 $self->{hover}[1]->() if $self->{hover};
2660 } 2916 }
2661} 2917}
2662 2918
2663############################################################################# 2919#############################################################################
2664 2920
2665package CFClient::UI::Statusbox; 2921package CFClient::UI::Statusbox;
2666 2922
2667our @ISA = CFClient::UI::VBox::; 2923our @ISA = CFClient::UI::VBox::;
2924
2925sub new {
2926 my $class = shift;
2927
2928 $class->SUPER::new (
2929 fontsize => 0.8,
2930 @_,
2931 )
2932}
2668 2933
2669sub reorder { 2934sub reorder {
2670 my ($self) = @_; 2935 my ($self) = @_;
2671 my $NOW = time; 2936 my $NOW = time;
2672 2937
2691 ? "<b>$item->{count} ×</b> $item->{text}" 2956 ? "<b>$item->{count} ×</b> $item->{text}"
2692 : $item->{text}; 2957 : $item->{text};
2693 2958
2694 for ($short) { 2959 for ($short) {
2695 s/^\s+//; 2960 s/^\s+//;
2696 s/\012.*/…/s; 2961 s/\s+/ /g;
2697 my $len = int 40 / $item->{fontsize};
2698 substr $_, $len, length, "…" if $len < length;
2699 } 2962 }
2700 2963
2701 new CFClient::UI::Label 2964 new CFClient::UI::Label
2702 markup => $short, 2965 markup => $short,
2703 tooltip => $item->{tooltip}, 2966 tooltip => $item->{tooltip},
2704 tooltip_font => $::FONT_PROP, 2967 tooltip_font => $::FONT_PROP,
2705 tooltip_width => 0.67, 2968 tooltip_width => 0.67,
2706 fontsize => $item->{fontsize}, 2969 fontsize => $item->{fontsize} || $self->{fontsize},
2970 max_w => $::WIDTH * 0.44,
2707 color => $item->{color}, 2971 fg => $item->{fg},
2708 can_events => 1, 2972 can_events => 1,
2709 can_hover => 1 2973 can_hover => 1
2710 }; 2974 };
2711 } 2975 }
2712 2976
2717sub add { 2981sub add {
2718 my ($self, $text, %arg) = @_; 2982 my ($self, $text, %arg) = @_;
2719 2983
2720 $text =~ s/^\s+//; 2984 $text =~ s/^\s+//;
2721 $text =~ s/\s+$//; 2985 $text =~ s/\s+$//;
2986
2987 return unless $text;
2722 2988
2723 my $timeout = time + ((delete $arg{timeout}) || 60); 2989 my $timeout = time + ((delete $arg{timeout}) || 60);
2724 2990
2725 my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; 2991 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
2726 2992
2738 $self->{item}{$group} = { 3004 $self->{item}{$group} = {
2739 id => ++$self->{id}, 3005 id => ++$self->{id},
2740 text => $text, 3006 text => $text,
2741 timeout => $timeout, 3007 timeout => $timeout,
2742 tooltip => $text, 3008 tooltip => $text,
2743 fontsize => 0.8,
2744 color => [0.8, 0.8, 0.8, 0.8], 3009 fg => [0.8, 0.8, 0.8, 0.8],
2745 pri => 0, 3010 pri => 0,
2746 count => 1, 3011 count => 1,
2747 %arg, 3012 %arg,
2748 }; 3013 };
2749 } 3014 }
2750 3015
2751 $self->reorder; 3016 $self->reorder;
2752} 3017}
2753 3018
3019sub reconfigure {
3020 my ($self) = @_;
3021
3022 delete $_->{label}
3023 for values %{ $self->{item} || {} };
3024
3025 $self->reorder;
3026 $self->SUPER::reconfigure;
3027}
3028
2754############################################################################# 3029#############################################################################
2755 3030
2756package CFClient::UI::Root; 3031package CFClient::UI::Root;
2757 3032
2758our @ISA = CFClient::UI::Container::; 3033our @ISA = CFClient::UI::Container::;
2788} 3063}
2789 3064
2790sub size_allocate { 3065sub size_allocate {
2791 my ($self, $w, $h) = @_; 3066 my ($self, $w, $h) = @_;
2792 3067
2793 my $old_w = $self->{old_w}; $self->{old_w} = $w;
2794 my $old_h = $self->{old_h}; $self->{old_h} = $h;
2795
2796 CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h
2797 if $old_w && $old_h && ($old_w != $w || $old_h != $h);
2798
2799 for my $child ($self->children) { 3068 for my $child ($self->children) {
2800 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; 3069 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2801 3070
3071 $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1
3072 if exists $child->{req_x};
3073
3074 $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1
3075 if exists $child->{req_y};
3076
2802 $X = List::Util::max 0, List::Util::min $w - $W, $X; 3077 $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5;
2803 $Y = List::Util::max 0, List::Util::min $h - $H, $Y; 3078 $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5;
3079
2804 $child->configure ($X, $Y, $W, $H); 3080 $child->configure ($X, $Y, $W, $H);
2805 } 3081 }
2806} 3082}
2807 3083
2808sub coord2local { 3084sub coord2local {
2823 $self->check_size; 3099 $self->check_size;
2824 $::WANT_REFRESH++; 3100 $::WANT_REFRESH++;
2825} 3101}
2826 3102
2827sub add { 3103sub add {
2828 my ($self, $child) = @_; 3104 my ($self, @children) = @_;
2829 3105
3106 for (my @widgets = @children; my $w = pop @widgets; ) {
3107 push @widgets, $w->children;
3108 $w->{root} = $self;
3109 $w->{visible} = 1;
3110 }
3111
3112 for my $child (@children) {
3113 $child->{is_toplevel} = 1;
3114
2830 # integerise window positions 3115 # integerise window positions
2831 $child->{x} = int $child->{x}; 3116 $child->{x} = int $child->{x};
2832 $child->{y} = int $child->{y}; 3117 $child->{y} = int $child->{y};
3118 }
2833 3119
2834 $self->SUPER::add ($child); 3120 $self->SUPER::add (@children);
3121}
3122
3123sub remove {
3124 my ($self, @children) = @_;
3125
3126 $self->SUPER::remove (@children);
3127
3128 while (@children) {
3129 my $w = pop @children;
3130 push @children, $w->children;
3131 $w->set_invisible;
3132 }
2835} 3133}
2836 3134
2837sub on_refresh { 3135sub on_refresh {
2838 my ($self, $id, $cb) = @_; 3136 my ($self, $id, $cb) = @_;
2839 3137
2892 $w = 0 if $w < 0; 3190 $w = 0 if $w < 0;
2893 $h = 0 if $h < 0; 3191 $h = 0 if $h < 0;
2894 3192
2895 $widget->{w} = $w; 3193 $widget->{w} = $w;
2896 $widget->{h} = $h; 3194 $widget->{h} = $h;
2897 $widget->size_allocate ($w, $h);
2898 $widget->emit (size_allocate => $w, $h); 3195 $widget->emit (size_allocate => $w, $h);
2899 } 3196 }
2900 } 3197 }
2901 3198
2902 while ($self->{post_alloc_hook}) { 3199 while ($self->{post_alloc_hook}) {
2908 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 3205 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2909 glClear GL_COLOR_BUFFER_BIT; 3206 glClear GL_COLOR_BUFFER_BIT;
2910 3207
2911 glMatrixMode GL_PROJECTION; 3208 glMatrixMode GL_PROJECTION;
2912 glLoadIdentity; 3209 glLoadIdentity;
2913 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000; 3210 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
2914 glMatrixMode GL_MODELVIEW; 3211 glMatrixMode GL_MODELVIEW;
2915 glLoadIdentity; 3212 glLoadIdentity;
2916 3213
2917 $self->_draw; 3214 $self->_draw;
2918} 3215}
2920############################################################################# 3217#############################################################################
2921 3218
2922package CFClient::UI; 3219package CFClient::UI;
2923 3220
2924$ROOT = new CFClient::UI::Root; 3221$ROOT = new CFClient::UI::Root;
2925$TOOLTIP = new CFClient::UI::Tooltip; 3222$TOOLTIP = new CFClient::UI::Tooltip z => 900;
2926 3223
29271 32241
2928 3225

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines