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.201 by root, Sat May 13 23:17:49 2006 UTC vs.
Revision 1.231 by root, Thu May 25 00:26:19 2006 UTC

11our ($FOCUS, $HOVER, $GRAB); # various widgets 11our ($FOCUS, $HOVER, $GRAB); # various widgets
12 12
13our $ROOT; 13our $ROOT;
14our $TOOLTIP; 14our $TOOLTIP;
15our $BUTTON_STATE; 15our $BUTTON_STATE;
16
17our %WIDGET; # all widgets, weak-referenced
16 18
17sub check_tooltip { 19sub check_tooltip {
18 if (!$GRAB) { 20 if (!$GRAB) {
19 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 21 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
20 if (length $widget->{tooltip}) { 22 if (length $widget->{tooltip}) {
29 $TOOLTIP->set_tooltip_from ($widget); 31 $TOOLTIP->set_tooltip_from ($widget);
30 $TOOLTIP->show; 32 $TOOLTIP->show;
31 33
32 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 34 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
33 35
34 if ($x + $TOOLTIP->{w} > $::WIDTH) {
35 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); 36 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0)
36 } 37 if $x + $TOOLTIP->{w} > $::WIDTH;
37 38
38 $TOOLTIP->move ($x, $y); 39 $TOOLTIP->move ($x, $y);
39 $TOOLTIP->check_size; 40 $TOOLTIP->check_size;
40 $TOOLTIP->update; 41 $TOOLTIP->update;
41 } 42 }
49 delete $TOOLTIP->{owner}; 50 delete $TOOLTIP->{owner};
50} 51}
51 52
52# class methods for events 53# class methods for events
53sub feed_sdl_key_down_event { 54sub feed_sdl_key_down_event {
54 $FOCUS->emit (key_down => $_[0]) || $FOCUS->key_down ($_[0]) 55 $FOCUS->emit (key_down => $_[0])
55 if $FOCUS; 56 if $FOCUS;
56} 57}
57 58
58sub feed_sdl_key_up_event { 59sub feed_sdl_key_up_event {
59 $FOCUS->emit (key_up => $_[0]) || $FOCUS->key_up ($_[0]) 60 $FOCUS->emit (key_up => $_[0])
60 if $FOCUS; 61 if $FOCUS;
61} 62}
62 63
63sub feed_sdl_button_down_event { 64sub feed_sdl_button_down_event {
64 my ($ev) = @_; 65 my ($ev) = @_;
73 check_tooltip; 74 check_tooltip;
74 } 75 }
75 76
76 $BUTTON_STATE |= 1 << ($ev->{button} - 1); 77 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
77 78
78 if ($GRAB) { 79 $GRAB->emit (button_down => $ev, $GRAB->coord2local ($x, $y))
79 ($x, $y) = $GRAB->coord2local ($x, $y); 80 if $GRAB;
80 $GRAB->emit (button_down => $ev, $x, $y) || $GRAB->button_down ($ev, $x, $y);
81 }
82} 81}
83 82
84sub feed_sdl_button_up_event { 83sub feed_sdl_button_up_event {
85 my ($ev) = @_; 84 my ($ev) = @_;
86 my ($x, $y) = ($ev->{x}, $ev->{y}); 85 my ($x, $y) = ($ev->{x}, $ev->{y});
87 86
88 my $widget = $GRAB || $ROOT->find_widget ($x, $y); 87 my $widget = $GRAB || $ROOT->find_widget ($x, $y);
89 88
90 $BUTTON_STATE &= ~(1 << ($ev->{button} - 1)); 89 $BUTTON_STATE &= ~(1 << ($ev->{button} - 1));
91 90
92 if ($GRAB) { 91 $GRAB->emit (button_up => $ev, $GRAB->coord2local ($x, $y))
93 ($x, $y) = $GRAB->coord2local ($x, $y); 92 if $GRAB;
94 $GRAB->emit (button_up => $ev, $x, $y) || $GRAB->button_up ($ev, $x, $y);
95 }
96 93
97 if (!$BUTTON_STATE) { 94 if (!$BUTTON_STATE) {
98 my $grab = $GRAB; undef $GRAB; 95 my $grab = $GRAB; undef $GRAB;
99 $grab->update if $grab; 96 $grab->update if $grab;
100 $GRAB->update if $GRAB; 97 $GRAB->update if $GRAB;
116 $HOVER->update if $HOVER && $HOVER->{can_hover}; 113 $HOVER->update if $HOVER && $HOVER->{can_hover};
117 114
118 check_tooltip; 115 check_tooltip;
119 } 116 }
120 117
121 if ($HOVER) {
122 ($x, $y) = $HOVER->coord2local ($x, $y);
123 $HOVER->emit (mouse_motion => $ev, $x, $y) || $HOVER->mouse_motion ($ev, $x, $y); 118 $HOVER->emit (mouse_motion => $ev, $HOVER->coord2local ($x, $y))
124 } 119 if $HOVER;
125} 120}
126 121
127# convert position array to integers 122# convert position array to integers
128sub harmonize { 123sub harmonize {
129 my ($vals) = @_; 124 my ($vals) = @_;
133 for (@$vals) { 128 for (@$vals) {
134 my $i = int $_ + $rem; 129 my $i = int $_ + $rem;
135 $rem += $_ - $i; 130 $rem += $_ - $i;
136 $_ = $i; 131 $_ = $i;
137 } 132 }
133}
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
151# call when resolution changes etc.
152sub rescale_widgets {
153 my ($sx, $sy) = @_;
154
155 for my $widget (values %WIDGET) {
156 if ($widget->{is_toplevel}) {
157 $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x};
158 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
159 $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w};
160 $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w};
161 $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y};
162 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h};
163 $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h};
164 $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h};
165 }
166 }
167
168 reconfigure_widgets;
138} 169}
139 170
140############################################################################# 171#############################################################################
141 172
142package CFClient::UI::Base; 173package CFClient::UI::Base;
160 if (/^connect_(.*)$/) { 191 if (/^connect_(.*)$/) {
161 $self->connect ($1 => delete $self->{$_}); 192 $self->connect ($1 => delete $self->{$_});
162 } 193 }
163 } 194 }
164 195
196 Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self);
197
165 $self 198 $self
166} 199}
167 200
168sub destroy { 201sub destroy {
169 my ($self) = @_; 202 my ($self) = @_;
172 %$self = (); 205 %$self = ();
173} 206}
174 207
175sub show { 208sub show {
176 my ($self) = @_; 209 my ($self) = @_;
177
178 return if $self->{parent}; 210 return if $self->{parent};
179 211
180 $CFClient::UI::ROOT->add ($self); 212 $CFClient::UI::ROOT->add ($self);
181} 213}
182 214
183sub hide { 215sub show_centered {
184 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};
185 234
186 undef $GRAB if $GRAB == $self; 235 undef $GRAB if $GRAB == $self;
187 undef $HOVER if $HOVER == $self; 236 undef $HOVER if $HOVER == $self;
237
238 $self->focus_out;
239}
240
241sub hide {
242 my ($self) = @_;
243
244 $self->set_invisible;
188 245
189 $self->{parent}->remove ($self) 246 $self->{parent}->remove ($self)
190 if $self->{parent}; 247 if $self->{parent};
191} 248}
192 249
242 299
243sub size_allocate { 300sub size_allocate {
244 # nothing to be done 301 # nothing to be done
245} 302}
246 303
247sub children {
248}
249
250# call when resolution changes etc.
251sub reconfigure { 304sub reconfigure {
252 my ($self) = @_; 305 my ($self) = @_;
253
254 $_->reconfigure
255 for $self->children;
256 306
257 $self->check_size (1); 307 $self->check_size (1);
258 $self->update; 308 $self->update;
259} 309}
260 310
311sub children {
312}
313
261sub set_max_size { 314sub set_max_size {
262 my ($self, $w, $h) = @_; 315 my ($self, $w, $h) = @_;
263 316
264 delete $self->{max_w}; $self->{max_w} = $w if $w; 317 delete $self->{max_w}; $self->{max_w} = $w if $w;
265 delete $self->{max_h}; $self->{max_h} = $h if $h; 318 delete $self->{max_h}; $self->{max_h} = $h if $h;
319}
320
321sub set_tooltip {
322 my ($self, $tooltip) = @_;
323
324 $self->{tooltip} = $tooltip;
325
326 if ($CFClient::UI::TOOLTIP->{owner} == $self) {
327 delete $CFClient::UI::TOOLTIP->{owner};
328 CFClient::UI::check_tooltip;
329 }
266} 330}
267 331
268# translate global coordinates to local coordinate system 332# translate global coordinates to local coordinate system
269sub coord2local { 333sub coord2local {
270 my ($self, $x, $y) = @_; 334 my ($self, $x, $y) = @_;
285 return if $FOCUS == $self; 349 return if $FOCUS == $self;
286 return unless $self->{can_focus}; 350 return unless $self->{can_focus};
287 351
288 my $focus = $FOCUS; $FOCUS = $self; 352 my $focus = $FOCUS; $FOCUS = $self;
289 353
290 $self->emit (focus_in => $focus); 354 $self->_emit (focus_in => $focus);
291 355
292 $focus->update if $focus; 356 $focus->update if $focus;
293 $FOCUS->update; 357 $FOCUS->update;
294} 358}
295 359
298 362
299 return unless $FOCUS == $self; 363 return unless $FOCUS == $self;
300 364
301 my $focus = $FOCUS; undef $FOCUS; 365 my $focus = $FOCUS; undef $FOCUS;
302 366
303 $self->emit (focus_out => $focus); 367 $self->_emit (focus_out => $focus);
304 368
305 $focus->update if $focus; #? 369 $focus->update if $focus; #?
370
371 $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus
372 unless $FOCUS;
306} 373}
307 374
308sub mouse_motion { } 375sub mouse_motion { }
309sub button_up { } 376sub button_up { }
310sub key_down { } 377sub key_down { }
311sub key_up { } 378sub key_up { }
312 379
313sub button_down { 380sub button_down {
314 my ($self, $ev, $x, $y) = @_; 381 my ($self, $ev, $x, $y) = @_;
315 382
316 $self->focus_in; 383 $self->focus_in;
356 glVertex $self->{w}, 0; 423 glVertex $self->{w}, 0;
357 glVertex $self->{w}, $self->{h}; 424 glVertex $self->{w}, $self->{h};
358 glVertex 0 , $self->{h}; 425 glVertex 0 , $self->{h};
359 glEnd; 426 glEnd;
360 glPopMatrix; 427 glPopMatrix;
361 CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; 428 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
362 } 429 }
363} 430}
364 431
365sub _draw { 432sub _draw {
366 my ($self) = @_; 433 my ($self) = @_;
386 Scalar::Util::weaken ($self->{parent} = $parent); 453 Scalar::Util::weaken ($self->{parent} = $parent);
387 454
388 # TODO: req_w _does_change after ->reconfigure 455 # TODO: req_w _does_change after ->reconfigure
389 $self->check_size 456 $self->check_size
390 unless exists $self->{req_w}; 457 unless exists $self->{req_w};
458
459 $self->show;
391} 460}
392 461
393sub check_size { 462sub check_size {
394 my ($self, $forced) = @_; 463 my ($self, $forced) = @_;
395 464
408 my ($self, $signal, $cb) = @_; 477 my ($self, $signal, $cb) = @_;
409 478
410 push @{ $self->{signal_cb}{$signal} }, $cb; 479 push @{ $self->{signal_cb}{$signal} }, $cb;
411} 480}
412 481
482sub _emit {
483 my ($self, $signal, @args) = @_;
484
485 List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []}
486}
487
413sub emit { 488sub emit {
414 my ($self, $signal, @args) = @_; 489 my ($self, $signal, @args) = @_;
415 490
416 List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []} 491 $self->_emit ($signal, @args)
492 || $self->$signal (@args);
417} 493}
418 494
419sub DESTROY { 495sub DESTROY {
420 my ($self) = @_; 496 my ($self) = @_;
421 497
498 delete $WIDGET{$self+0};
422 #$self->deactivate; 499 #$self->deactivate;
423} 500}
424 501
425############################################################################# 502#############################################################################
426 503
435 my $class = shift; 512 my $class = shift;
436 513
437 # range [value, low, high, page] 514 # range [value, low, high, page]
438 515
439 $class->SUPER::new ( 516 $class->SUPER::new (
440 bg => [0, 0, 0, 0.2], 517 #bg => [0, 0, 0, 0.2],
441 active_bg => [1, 1, 1, 0.5], 518 #active_bg => [1, 1, 1, 0.5],
442 @_ 519 @_
443 ) 520 )
444} 521}
445 522
446sub _draw { 523sub _draw {
447 my ($self) = @_; 524 my ($self) = @_;
448 525
526 my $color = $FOCUS == $self && $self->{active_bg}
527 ? $self->{active_bg}
528 : $self->{bg};
529
530 if ($color && (@$color < 4 || $color->[3])) {
449 my ($w, $h) = @$self{qw(w h)}; 531 my ($w, $h) = @$self{qw(w h)};
450 532
451 glEnable GL_BLEND; 533 glEnable GL_BLEND;
452 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 534 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
453 glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} }; 535 glColor @$color;
454 536
455 glBegin GL_QUADS; 537 glBegin GL_QUADS;
456 glVertex 0 , 0; 538 glVertex 0 , 0;
457 glVertex 0 , $h; 539 glVertex 0 , $h;
458 glVertex $w, $h; 540 glVertex $w, $h;
459 glVertex $w, 0; 541 glVertex $w, 0;
460 glEnd; 542 glEnd;
461 543
462 glDisable GL_BLEND; 544 glDisable GL_BLEND;
545 }
463} 546}
464 547
465############################################################################# 548#############################################################################
466 549
467package CFClient::UI::Empty; 550package CFClient::UI::Empty;
651 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 734 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
652 glClearColor 0, 0, 0, 0; 735 glClearColor 0, 0, 0, 0;
653 glClear GL_COLOR_BUFFER_BIT; 736 glClear GL_COLOR_BUFFER_BIT;
654 737
655 $self->_render; 738 $self->_render;
656# glColorMask 1, 1, 1, 0;
657# glEnable GL_BLEND;
658# glBlendFunc GL_SRC_ALPHA, GL_ZERO;
659# glRasterPos 0, 0;
660# glCopyPixels 0, 0, $self->{w}, $self->{h};
661# glDisable GL_BLEND;
662# glColorMask 1, 1, 1, 1;
663 }; 739 };
664} 740}
665 741
666sub _draw { 742sub _draw {
667 my ($self) = @_; 743 my ($self) = @_;
671 my $tex = $self->{texture} 747 my $tex = $self->{texture}
672 or return; 748 or return;
673 749
674 glEnable GL_TEXTURE_2D; 750 glEnable GL_TEXTURE_2D;
675 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 751 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
676 glColor 0, 0, 0, 1; 752 glColor 1, 1, 1, 1;
677 753
678 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); 754 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h);
679 755
680 glDisable GL_TEXTURE_2D; 756 glDisable GL_TEXTURE_2D;
681} 757}
688 764
689sub size_request { 765sub size_request {
690 my ($self) = @_; 766 my ($self) = @_;
691 767
692 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; 768 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)};
693 $self->child->configure (0, 0, @$self{qw(child_w child_h)});
694 769
695 @$self{qw(child_w child_h)} 770 @$self{qw(child_w child_h)}
696} 771}
697 772
698sub size_allocate { 773sub size_allocate {
699 my ($self, $w, $h) = @_; 774 my ($self, $w, $h) = @_;
700 775
776 my ($cw, $ch) = @$self{qw(child_w child_h)};
777# $w = $self->{w};
778 $self->child->configure (0, 0, $cw, $ch);
701 $self->update; 779 $self->update;
702} 780}
703 781
704sub set_offset { 782sub set_offset {
705 my ($self, $x, $y) = @_; 783 my ($self, $x, $y) = @_;
759 837
760 my $slider = new CFClient::UI::Slider 838 my $slider = new CFClient::UI::Slider
761 vertical => 1, 839 vertical => 1,
762 range => [0, 0, 1, 0.01], # HACK fix 840 range => [0, 0, 1, 0.01], # HACK fix
763 connect_changed => sub { 841 connect_changed => sub {
764 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); 842 $self->{vp}->set_offset (0, $_[1]);
765 }, 843 },
766 ; 844 ;
767 845
768 $self = $class->SUPER::new ( 846 $self = $class->SUPER::new (
769 vp => (new CFClient::UI::ViewPort), 847 vp => (new CFClient::UI::ViewPort expand => 1),
770 slider => $slider, 848 slider => $slider,
771 @_, 849 @_,
772 ); 850 );
773 851
774 $self->{vp}->add ($self->{scrolled}); 852 $self->{vp}->add ($self->{scrolled});
775 $self->add ($self->{vp}); 853 $self->add ($self->{vp});
776 $self->add ($self->{slider}); 854 $self->add ($self->{slider});
777 855
778 $self 856 $self
857}
858
859sub size_allocate {
860 my ($self, $w, $h) = @_;
861
862 $self->SUPER::size_allocate ($w, $h);
863
864 my $child = $self->{vp}->child;
865 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]);
779} 866}
780 867
781#TODO# update range on size_allocate depending on child 868#TODO# update range on size_allocate depending on child
782# update viewport offset on scroll 869# update viewport offset on scroll
783 870
837 my $class = shift; 924 my $class = shift;
838 925
839 # TODO: user_x, user_y, overwrite moveto? 926 # TODO: user_x, user_y, overwrite moveto?
840 927
841 my $self = $class->SUPER::new ( 928 my $self = $class->SUPER::new (
842 bg => [1, 1, 1, 1], 929 bg => [1, 1, 1, 1],
843 border_bg => [1, 1, 1, 1], 930 border_bg => [1, 1, 1, 1],
844 border => 0.6, 931 border => 0.6,
932 is_toplevel => 1,
845 can_events => 1, 933 can_events => 1,
846 @_ 934 @_
847 ); 935 );
848 936
849 $self->{title} &&= new CFClient::UI::Label 937 $self->{title} &&= new CFClient::UI::Label
850 align => 0, 938 align => 0,
874 my ($self, $w, $h) = @_; 962 my ($self, $w, $h) = @_;
875 963
876 $h -= List::Util::max 0, $self->border * 2; 964 $h -= List::Util::max 0, $self->border * 2;
877 $w -= List::Util::max 0, $self->border * 2; 965 $w -= List::Util::max 0, $self->border * 2;
878 966
879 $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) 967 $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2)
880 if $self->{title}; 968 if $self->{title};
881 969
882 $self->child->configure ($self->border, $self->border, $w, $h); 970 $self->child->configure ($self->border, $self->border, $w, $h);
883} 971}
884 972
1245 1333
1246############################################################################# 1334#############################################################################
1247 1335
1248package CFClient::UI::Label; 1336package CFClient::UI::Label;
1249 1337
1250our @ISA = CFClient::UI::Base::; 1338our @ISA = CFClient::UI::DrawBG::;
1251 1339
1252use CFClient::OpenGL; 1340use CFClient::OpenGL;
1253 1341
1254sub new { 1342sub new {
1255 my ($class, %arg) = @_; 1343 my ($class, %arg) = @_;
1256 1344
1257 my $self = $class->SUPER::new ( 1345 my $self = $class->SUPER::new (
1258 fg => [1, 1, 1], 1346 fg => [1, 1, 1],
1347 #bg => none
1348 #active_bg => none
1259 #font => default_font 1349 #font => default_font
1260 #text => initial text 1350 #text => initial text
1261 #markup => initial narkup 1351 #markup => initial narkup
1352 #max_w => maximum pixel width
1353 ellipsise => 3, # end
1262 layout => (new CFClient::Layout), 1354 layout => (new CFClient::Layout),
1263 fontsize => 1, 1355 fontsize => 1,
1264 align => -1, 1356 align => -1,
1265 valign => -1, 1357 valign => -1,
1266 padding => 2, 1358 padding => 2,
1281 } 1373 }
1282 1374
1283 $self 1375 $self
1284} 1376}
1285 1377
1286sub escape { 1378sub escape($) {
1287 local $_ = $_[1]; 1379 local $_ = $_[0];
1288 1380
1289 s/&/&amp;/g; 1381 s/&/&amp;/g;
1290 s/>/&gt;/g; 1382 s/>/&gt;/g;
1291 s/</&lt;/g; 1383 s/</&lt;/g;
1292 1384
1293 $_[1] 1385 $_
1294} 1386}
1295 1387
1296sub update { 1388sub update {
1297 my ($self) = @_; 1389 my ($self) = @_;
1298 1390
1331sub size_request { 1423sub size_request {
1332 my ($self) = @_; 1424 my ($self) = @_;
1333 1425
1334 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1426 $self->{layout}->set_font ($self->{font}) if $self->{font};
1335 $self->{layout}->set_width ($self->{max_w} || -1); 1427 $self->{layout}->set_width ($self->{max_w} || -1);
1428 $self->{layout}->set_ellipsise ($self->{ellipsise});
1429 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1336 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1430 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1337 1431
1338 my ($w, $h) = $self->{layout}->size; 1432 my ($w, $h) = $self->{layout}->size;
1339 1433
1340 if (exists $self->{template}) { 1434 if (exists $self->{template}) {
1370} 1464}
1371 1465
1372sub _draw { 1466sub _draw {
1373 my ($self) = @_; 1467 my ($self) = @_;
1374 1468
1469 $self->SUPER::_draw; # draw background, if applicable
1470
1375 my $tex = $self->{texture} ||= do { 1471 my $tex = $self->{texture} ||= do {
1376 $self->{layout}->set_foreground (@{$self->{fg}}); 1472 $self->{layout}->set_foreground (@{$self->{fg}});
1377 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1473 $self->{layout}->set_font ($self->{font}) if $self->{font};
1378 $self->{layout}->set_width ($self->{w}); 1474 $self->{layout}->set_width ($self->{w});
1475 $self->{layout}->set_ellipsise ($self->{ellipsise});
1476 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1379 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1477 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1380 1478
1381 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1479 my $tex = new_from_layout CFClient::Texture $self->{layout};
1382 1480
1383 $self->{ox} = int $self->{align} < 0 ? $self->{padding} 1481 $self->{ox} = int ($self->{align} < 0 ? $self->{padding}
1384 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1482 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1385 : ($self->{w} - $tex->{w}) * 0.5; 1483 : ($self->{w} - $tex->{w}) * 0.5);
1386 1484
1387 $self->{oy} = int $self->{valign} < 0 ? $self->{padding} 1485 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding}
1388 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} 1486 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1389 : ($self->{h} - $tex->{h}) * 0.5; 1487 : ($self->{h} - $tex->{h}) * 0.5);
1390 1488
1391 $tex 1489 $tex
1392 }; 1490 };
1393 1491
1394 glEnable GL_TEXTURE_2D; 1492 glEnable GL_TEXTURE_2D;
1422 active_fg => [0, 0, 0], 1520 active_fg => [0, 0, 0],
1423 can_hover => 1, 1521 can_hover => 1,
1424 can_focus => 1, 1522 can_focus => 1,
1425 valign => 0, 1523 valign => 0,
1426 can_events => 1, 1524 can_events => 1,
1525 #text => ...
1427 @_ 1526 @_
1428 ) 1527 )
1429} 1528}
1430 1529
1431sub _set_text { 1530sub _set_text {
1441 $self->{text} = $text; 1540 $self->{text} = $text;
1442 1541
1443 $text =~ s/./*/g if $self->{hidden}; 1542 $text =~ s/./*/g if $self->{hidden};
1444 $self->{layout}->set_text ("$text "); 1543 $self->{layout}->set_text ("$text ");
1445 1544
1446 $self->emit (changed => $self->{text}); 1545 $self->_emit (changed => $self->{text});
1447} 1546}
1448 1547
1449sub set_text { 1548sub set_text {
1450 my ($self, $text) = @_; 1549 my ($self, $text) = @_;
1451 1550
1452 $self->{cursor} = length $text; 1551 $self->{cursor} = length $text;
1453 $self->_set_text ($text); 1552 $self->_set_text ($text);
1553 $self->update;
1454 $self->check_size; 1554 $self->check_size;
1455 $self->update;
1456} 1555}
1457 1556
1458sub get_text { 1557sub get_text {
1459 $_[0]{text} 1558 $_[0]{text}
1460} 1559}
1493 } elsif ($sym == CFClient::SDLK_HOME) { 1592 } elsif ($sym == CFClient::SDLK_HOME) {
1494 $self->{cursor} = 0; 1593 $self->{cursor} = 0;
1495 } elsif ($sym == CFClient::SDLK_END) { 1594 } elsif ($sym == CFClient::SDLK_END) {
1496 $self->{cursor} = length $text; 1595 $self->{cursor} = length $text;
1497 } elsif ($uni == 27) { 1596 } elsif ($uni == 27) {
1498 $self->emit ('escape'); 1597 $self->_emit ('escape');
1499 } elsif ($uni) { 1598 } elsif ($uni) {
1500 substr $text, $self->{cursor}++, 0, chr $uni; 1599 substr $text, $self->{cursor}++, 0, chr $uni;
1501 } 1600 }
1502 1601
1503 $self->_set_text ($text); 1602 $self->_set_text ($text);
1504 $self->update; 1603 $self->update;
1604 $self->check_size;
1505} 1605}
1506 1606
1507sub focus_in { 1607sub focus_in {
1508 my ($self) = @_; 1608 my ($self) = @_;
1509 1609
1589 if ($sym == 13) { 1689 if ($sym == 13) {
1590 unshift @{$self->{history}}, 1690 unshift @{$self->{history}},
1591 my $txt = $self->get_text; 1691 my $txt = $self->get_text;
1592 $self->{history_pointer} = -1; 1692 $self->{history_pointer} = -1;
1593 $self->{history_saveback} = ''; 1693 $self->{history_saveback} = '';
1594 $self->emit (activate => $txt); 1694 $self->_emit (activate => $txt);
1595 $self->update; 1695 $self->update;
1596 1696
1597 } elsif ($sym == CFClient::SDLK_UP) { 1697 } elsif ($sym == CFClient::SDLK_UP) {
1598 if ($self->{history_pointer} < 0) { 1698 if ($self->{history_pointer} < 0) {
1599 $self->{history_saveback} = $self->get_text; 1699 $self->{history_saveback} = $self->get_text;
1638 my $class = shift; 1738 my $class = shift;
1639 1739
1640 $class->SUPER::new ( 1740 $class->SUPER::new (
1641 padding => 4, 1741 padding => 4,
1642 fg => [1, 1, 1], 1742 fg => [1, 1, 1],
1643 bg => [1, 1, 1, 0.2],
1644 active_fg => [0, 0, 1], 1743 active_fg => [0, 0, 1],
1645 can_hover => 1, 1744 can_hover => 1,
1646 align => 0, 1745 align => 0,
1647 valign => 0, 1746 valign => 0,
1648 can_events => 1, 1747 can_events => 1,
1649 @_ 1748 @_
1650 ) 1749 )
1651} 1750}
1652 1751
1752sub activate { }
1753
1653sub button_up { 1754sub button_up {
1654 my ($self, $ev, $x, $y) = @_; 1755 my ($self, $ev, $x, $y) = @_;
1655 1756
1757 $self->emit ("activate")
1656 if ($x >= 0 && $x < $self->{w} 1758 if $x >= 0 && $x < $self->{w}
1657 && $y >= 0 && $y < $self->{h}) { 1759 && $y >= 0 && $y < $self->{h};
1658 $self->emit ("activate");
1659 }
1660} 1760}
1661 1761
1662sub _draw { 1762sub _draw {
1663 my ($self) = @_; 1763 my ($self) = @_;
1664 1764
1696 1796
1697 $class->SUPER::new ( 1797 $class->SUPER::new (
1698 padding => 2, 1798 padding => 2,
1699 fg => [1, 1, 1], 1799 fg => [1, 1, 1],
1700 active_fg => [1, 1, 0], 1800 active_fg => [1, 1, 0],
1801 bg => [0, 0, 0, 0.2],
1802 active_bg => [1, 1, 1, 0.5],
1701 state => 0, 1803 state => 0,
1702 can_hover => 1, 1804 can_hover => 1,
1703 @_ 1805 @_
1704 ) 1806 )
1705} 1807}
1714 my ($self, $ev, $x, $y) = @_; 1816 my ($self, $ev, $x, $y) = @_;
1715 1817
1716 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} 1818 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding}
1717 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { 1819 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) {
1718 $self->{state} = !$self->{state}; 1820 $self->{state} = !$self->{state};
1719 $self->emit (changed => $self->{state}); 1821 $self->_emit (changed => $self->{state});
1720 } 1822 }
1721} 1823}
1722 1824
1723sub _draw { 1825sub _draw {
1724 my ($self) = @_; 1826 my ($self) = @_;
1989 qw(s1_slider.png s1_slider_bg.png); 2091 qw(s1_slider.png s1_slider_bg.png);
1990 2092
1991sub new { 2093sub new {
1992 my $class = shift; 2094 my $class = shift;
1993 2095
1994 # range [value, low, high, page] 2096 # range [value, low, high, page, unit]
1995 2097
1996 # TODO: 0-width page 2098 # TODO: 0-width page
1997 # TODO: req_w/h are wrong with vertical 2099 # TODO: req_w/h are wrong with vertical
1998 # TODO: calculations are off 2100 # TODO: calculations are off
1999 my $self = $class->SUPER::new ( 2101 my $self = $class->SUPER::new (
2000 fg => [1, 1, 1], 2102 fg => [1, 1, 1],
2001 active_fg => [0, 0, 0], 2103 active_fg => [0, 0, 0],
2104 bg => [0, 0, 0, 0.2],
2105 active_bg => [1, 1, 1, 0.5],
2002 range => [0, 0, 100, 10], 2106 range => [0, 0, 100, 10, 0],
2003 req_w => $::WIDTH / 80, 2107 req_w => $::WIDTH / 80,
2004 req_h => $::WIDTH / 80, 2108 req_h => $::WIDTH / 80,
2005 vertical => 0, 2109 vertical => 0,
2006 can_hover => 1, 2110 can_hover => 1,
2007 inner_pad => 5, 2111 inner_pad => 0.02,
2008 @_ 2112 @_
2009 ); 2113 );
2010 2114
2115 $self->set_value ($self->{range}[0]);
2116 $self->update;
2117
2011 $self 2118 $self
2119}
2120
2121sub set_range {
2122 my ($self, $range) = @_;
2123
2124 $self->{range} = $range;
2125
2126 $self->update;
2127}
2128
2129sub set_value {
2130 my ($self, $value) = @_;
2131
2132 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}};
2133
2134 $hi = $lo + 1 if $hi <= $lo;
2135
2136 $page = $hi - $lo if $page > $hi - $lo;
2137
2138 $value = $lo if $value < $lo;
2139 $value = $hi - $page if $value > $hi - $page;
2140
2141 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit
2142 if $unit;
2143
2144 @{$self->{range}} = ($value, $lo, $hi, $page, $unit);
2145
2146 if ($value != $old_value) {
2147 $self->_emit (changed => $value);
2148 $self->update;
2149 }
2012} 2150}
2013 2151
2014sub size_request { 2152sub size_request {
2015 my ($self) = @_; 2153 my ($self) = @_;
2016 2154
2022 2160
2023sub button_down { 2161sub button_down {
2024 my ($self, $ev, $x, $y) = @_; 2162 my ($self, $ev, $x, $y) = @_;
2025 2163
2026 $self->SUPER::button_down ($ev, $x, $y); 2164 $self->SUPER::button_down ($ev, $x, $y);
2165
2166 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x];
2167
2027 $self->mouse_motion ($ev, $x, $y); 2168 $self->mouse_motion ($ev, $x, $y);
2028} 2169}
2029 2170
2030sub mouse_motion { 2171sub mouse_motion {
2031 my ($self, $ev, $x, $y) = @_; 2172 my ($self, $ev, $x, $y) = @_;
2032 2173
2033 if ($GRAB == $self) { 2174 if ($GRAB == $self) {
2175 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w});
2176
2177 my (undef, $lo, $hi, $page) = @{$self->{range}};
2178
2179 $x = ($x - $self->{click}[1]) / ($w * $self->{scale});
2180
2181 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo));
2182 }
2183}
2184
2185sub update {
2186 my ($self) = @_;
2187
2188 $CFClient::UI::ROOT->on_post_alloc ($self => sub {
2189 $self->set_value ($self->{range}[0]);
2190
2034 my ($value, $lo, $hi, $page) = @{$self->{range}}; 2191 my ($value, $lo, $hi, $page) = @{$self->{range}};
2192 my $range = ($hi - $page - $lo) || 1e-100;
2035 2193
2036 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); 2194 my $knob_w = List::Util::min 1, $page / ($hi - $lo) || 0.1;
2037 2195
2038 my $inner_pad_px = $self->_calc_inner_pad_px ($w); 2196 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5;
2039 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right 2197 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100;
2040 2198
2041 $x -= $inner_pad_px; # substract the padding 2199 $value = ($value - $lo) / $range;
2042 $x = $x * ($hi - $lo) / $inner_w + $lo; 2200 $value = $value * $self->{scale} + $self->{offset};
2043 $x = $lo if $x < $lo;
2044 $x = $hi - $page if $x > $hi - $page;
2045 $self->{range}[0] = $x;
2046 2201
2047 $self->emit (changed => $x); 2202 $self->{knob_x} = $value - $knob_w * 0.5;
2048 $self->update; 2203 $self->{knob_w} = $knob_w;
2049 } 2204 });
2050}
2051 2205
2052# the inner_* stuff is for generating a padding for the slider handle, 2206 $self->SUPER::update;
2053# so that the handle doesn't leave the texture. This calculation isn't 100%
2054# correct propably, but it does the job for now
2055sub _calc_inner_pad_px {
2056 my ($self, $w) = @_;
2057 ($w / 100) * $self->{inner_pad} # % to pixels
2058} 2207}
2059 2208
2060sub _draw { 2209sub _draw {
2061 my ($self) = @_; 2210 my ($self) = @_;
2062 2211
2063 $self->SUPER::_draw (); 2212 $self->SUPER::_draw ();
2064 2213
2065 my ($w, $h) = @$self{qw(w h)}; 2214 glScale $self->{w}, $self->{h};
2066 2215
2067 if ($self->{vertical}) { 2216 if ($self->{vertical}) {
2068 # draw a vertical slider like a rotated horizontal slider 2217 # draw a vertical slider like a rotated horizontal slider
2069 2218
2219 glTranslate 1, 0, 0;
2070 glRotate 90, 0, 0, 1; 2220 glRotate 90, 0, 0, 1;
2071 glTranslate 0, -$self->{w}, 0;
2072
2073 ($w, $h) = ($h, $w);
2074 } 2221 }
2075 2222
2076 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 2223 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
2077 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 2224 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
2078 2225
2079 my ($value, $lo, $hi, $page) = @{$self->{range}};
2080
2081 $hi = $value + 1 if $lo == $hi;
2082
2083 my $inner_pad_px = $self->_calc_inner_pad_px ($w);
2084 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
2085
2086 $page = int $page * $inner_w / ($hi - $lo);
2087 $value = int +($value - $lo) * $inner_w / ($hi - $lo);
2088
2089 $w -= $page;
2090 $page &= ~1;
2091 glTranslate $page * 0.5, 0, 0;
2092 $page ||= 2;
2093
2094 my $knob_a = $inner_pad_px + ($value - $page * 0.5);
2095 my $knob_b = $inner_pad_px + ($value + $page * 0.5);
2096
2097 glEnable GL_TEXTURE_2D; 2226 glEnable GL_TEXTURE_2D;
2098 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2227 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2099 2228
2100 # draw background 2229 # draw background
2101 $tex[1]->draw_quad_alpha (0, 0, $w, $h); 2230 $tex[1]->draw_quad_alpha (0, 0, 1, 1);
2102 2231
2103 # draw handle 2232 # draw handle
2104 $tex[0]->draw_quad_alpha ($knob_a, 0, $knob_b - $knob_a, $h); 2233 $tex[0]->draw_quad_alpha ($self->{knob_x}, 0, $self->{knob_w}, 1);
2105 2234
2106 glDisable GL_TEXTURE_2D; 2235 glDisable GL_TEXTURE_2D;
2107} 2236}
2237
2238#############################################################################
2239
2240package CFClient::UI::ValSlider;
2241
2242our @ISA = CFClient::UI::HBox::;
2243
2244sub new {
2245 my ($class, %arg) = @_;
2246
2247 my $range = delete $arg{range};
2248
2249 my $self = $class->SUPER::new (
2250 slider => (new CFClient::UI::Slider expand => 1, range => $range),
2251 entry => (new CFClient::UI::Label text => "", template => delete $arg{template}),
2252 to_value => sub { shift },
2253 from_value => sub { shift },
2254 %arg,
2255 );
2256
2257 $self->{slider}->connect (changed => sub {
2258 my ($self, $value) = @_;
2259 $self->{parent}{entry}->set_text ($self->{parent}{to_value}->($value));
2260 $self->{parent}->emit (changed => $value);
2261 });
2262
2263# $self->{entry}->connect (changed => sub {
2264# my ($self, $value) = @_;
2265# $self->{parent}{slider}->set_value ($self->{parent}{from_value}->($value));
2266# $self->{parent}->emit (changed => $value);
2267# });
2268
2269 $self->add ($self->{slider}, $self->{entry});
2270
2271 $self->{slider}->emit (changed => $self->{slider}{range}[0]);
2272
2273 $self
2274}
2275
2276sub set_range { shift->{slider}->set_range (@_) }
2277sub set_value { shift->{slider}->set_value (@_) }
2108 2278
2109############################################################################# 2279#############################################################################
2110 2280
2111package CFClient::UI::TextView; 2281package CFClient::UI::TextView;
2112 2282
2142 2312
2143 $self->{fontsize} = $fontsize; 2313 $self->{fontsize} = $fontsize;
2144 $self->reflow; 2314 $self->reflow;
2145} 2315}
2146 2316
2147sub text_height {
2148 my ($self, $text) = @_;
2149
2150 my $layout = $self->{layout};
2151
2152 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2153 $layout->set_width ($self->{children}[0]{w});
2154 $layout->set_markup ($text);
2155
2156 ($layout->size)[1]
2157}
2158
2159sub reflow {
2160 my ($self) = @_;
2161
2162 $self->{need_reflow}++;
2163 $self->update;
2164}
2165
2166sub size_allocate { 2317sub size_allocate {
2167 my ($self, $w, $h) = @_; 2318 my ($self, $w, $h) = @_;
2168 2319
2169 $self->SUPER::size_allocate ($w, $h); 2320 $self->SUPER::size_allocate ($w, $h);
2170 2321
2173 $self->{layout}->set_width ($self->{children}[0]{w}); 2324 $self->{layout}->set_width ($self->{children}[0]{w});
2174 2325
2175 $self->reflow; 2326 $self->reflow;
2176} 2327}
2177 2328
2329sub text_size {
2330 my ($self, $text, $indent) = @_;
2331
2332 my $layout = $self->{layout};
2333
2334 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2335 $layout->set_width ($self->{children}[0]{w} - $indent);
2336 $layout->set_markup ($text);
2337
2338 $layout->size
2339}
2340
2341sub reflow {
2342 my ($self) = @_;
2343
2344 $self->{need_reflow}++;
2345 $self->update;
2346}
2347
2348sub set_offset {
2349 my ($self, $offset) = @_;
2350
2351 # todo: base offset on lines or so, not on pixels
2352 $self->{children}[1]->set_value ($offset);
2353}
2354
2355sub clear {
2356 my ($self) = @_;
2357
2358 $self->{par} = [];
2359 $self->{height} = 0;
2360 $self->{children}[1]->set_range ([0, 0, 0, 1, 1]);
2361}
2362
2178sub add_paragraph { 2363sub add_paragraph {
2179 my ($self, $color, $text) = @_; 2364 my ($self, $color, $text, $indent) = @_;
2180 2365
2181 #TODO: intelligently "reformat" paragraph 2366 for my $line (split /\n/, $text) {
2182 2367 my ($w, $h) = $self->text_size ($line);
2183 my $height = $self->text_height ($text);
2184
2185 $self->{height} += $height; 2368 $self->{height} += $h;
2369 push @{$self->{par}}, [$w + $indent, $h, $color, $indent, $line];
2370 }
2186 2371
2187 push @{$self->{par}}, [$height, $color, $text];
2188
2189 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; 2372 $self->{children}[1]->set_range ([$self->{height}, 0, $self->{height}, $self->{h}, 1]);
2190 $self->{children}[1]->update;
2191} 2373}
2192 2374
2193sub update { 2375sub update {
2194 my ($self) = @_; 2376 my ($self) = @_;
2195 2377
2198 return unless $self->{h} > 0; 2380 return unless $self->{h} > 0;
2199 2381
2200 delete $self->{texture}; 2382 delete $self->{texture};
2201 2383
2202 $ROOT->on_post_alloc ($self, sub { 2384 $ROOT->on_post_alloc ($self, sub {
2385 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
2386
2203 if (delete $self->{need_reflow}) { 2387 if (delete $self->{need_reflow}) {
2204 my $height = 0; 2388 my $height = 0;
2205 2389
2206 $height += $_->[0] = $self->text_height ($_->[2]) 2390 my $layout = $self->{layout};
2391
2392 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
2393
2207 for @{$self->{par}}; 2394 for (@{$self->{par}}) {
2395 if (1 || $_->[0] >= $W) { # TODO: works,but needs reconfigure etc. support
2396 $layout->set_width ($W - $_->[3]);
2397 $layout->set_markup ($_->[4]);
2398 my ($w, $h) = $layout->size;
2399 $_->[0] = $w + $_->[3];
2400 $_->[1] = $h;
2401 }
2402
2403 $height += $_->[1];
2404 }
2208 2405
2209 $self->{height} = $height; 2406 $self->{height} = $height;
2210 2407
2211 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2408 $self->{children}[1]->set_range ([$height, 0, $height, $H, 1]);
2212 2409
2213 delete $self->{texture}; 2410 delete $self->{texture};
2214 } 2411 }
2215 2412
2216 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub { 2413 $self->{texture} ||= new_from_opengl CFClient::Texture $W, $H, sub {
2217 glClearColor 0, 0, 0, 0; 2414 glClearColor 0.5, 0.5, 0.5, 0;
2218 glClear GL_COLOR_BUFFER_BIT; 2415 glClear GL_COLOR_BUFFER_BIT;
2219 2416
2220 glEnable GL_TEXTURE_2D;
2221 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2222
2223 my $top = int $self->{children}[1]{range}[0]; 2417 my $top = int $self->{children}[1]{range}[0];
2224 2418
2225 my $y0 = $top; 2419 my $y0 = $top;
2226 my $y1 = $top + $self->{h}; 2420 my $y1 = $top + $H;
2227 2421
2228 my $y = 0; 2422 my $y = 0;
2229 2423
2230 my $layout = $self->{layout}; 2424 my $layout = $self->{layout};
2231 2425
2232 $layout->set_font ($self->{font}) if $self->{font}; 2426 $layout->set_font ($self->{font}) if $self->{font};
2233 2427
2428 glEnable GL_BLEND;
2429 #TODO# not correct in windows where rgba is forced off
2430 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2431
2234 for my $par (@{$self->{par}}) { 2432 for my $par (@{$self->{par}}) {
2235 my $h = $par->[0]; 2433 my $h = $par->[1];
2236 2434
2237 if ($y0 < $y + $h && $y < $y1) { 2435 if ($y0 < $y + $h && $y < $y1) {
2238 $layout->set_foreground (@{ $par->[1] }); 2436 $layout->set_foreground (@{ $par->[2] });
2437 $layout->set_width ($W - $par->[3]);
2239 $layout->set_markup ($par->[2]); 2438 $layout->set_markup ($par->[4]);
2240 2439
2241 my ($W, $H) = $layout->size; 2440 my ($w, $h, $data, $format, $internalformat) = $layout->render;
2242 CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0); 2441
2442 glRasterPos $par->[3], $y - $y0;
2443 glDrawPixels $w, $h, $format, GL_UNSIGNED_BYTE, $data;
2243 } 2444 }
2244 2445
2245 $y += $h; 2446 $y += $h;
2246 } 2447 }
2247 2448
2248 glDisable GL_TEXTURE_2D; 2449 glDisable GL_BLEND;
2249 }; 2450 };
2250 }); 2451 });
2251} 2452}
2252 2453
2253sub _draw { 2454sub _draw {
2254 my ($self) = @_; 2455 my ($self) = @_;
2255 2456
2256 glEnable GL_TEXTURE_2D; 2457 glEnable GL_TEXTURE_2D;
2257 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2458 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2258 glColor 1, 1, 1, 1; 2459 glColor 1, 1, 1, 1;
2259 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h}); 2460 $self->{texture}->draw_quad_alpha (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
2260 glDisable GL_TEXTURE_2D; 2461 glDisable GL_TEXTURE_2D;
2261 2462
2262 $self->{children}[1]->draw; 2463 $self->{children}[1]->draw;
2263 2464
2264} 2465}
2333 2534
2334 # TODO: use animation 2535 # TODO: use animation
2335 if ($self->{state} = !$self->{state}) { 2536 if ($self->{state} = !$self->{state}) {
2336 $CFClient::UI::ROOT->add ($self->{other}); 2537 $CFClient::UI::ROOT->add ($self->{other});
2337 $self->{other}->move ($self->coord2global (0, $self->{h})); 2538 $self->{other}->move ($self->coord2global (0, $self->{h}));
2338 $self->emit ("open"); 2539 $self->_emit ("open");
2339 } else { 2540 } else {
2340 $CFClient::UI::ROOT->remove ($self->{other}); 2541 $CFClient::UI::ROOT->remove ($self->{other});
2341 $self->emit ("close"); 2542 $self->_emit ("close");
2342 } 2543 }
2343 2544
2344 $self->emit (changed => $self->{state}); 2545 $self->_emit (changed => $self->{state});
2345} 2546}
2346 2547
2347############################################################################# 2548#############################################################################
2348 2549
2349package CFClient::UI::Tooltip; 2550package CFClient::UI::Tooltip;
2363 2564
2364sub set_tooltip_from { 2565sub set_tooltip_from {
2365 my ($self, $widget) = @_; 2566 my ($self, $widget) = @_;
2366 2567
2367 $self->add (new CFClient::UI::Label 2568 $self->add (new CFClient::UI::Label
2368 markup => $widget->{tooltip}, 2569 markup => $widget->{tooltip},
2369 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 2570 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2370 fontsize => 0.8, 2571 fontsize => 0.8,
2371 fg => [0, 0, 0, 1], 2572 fg => [0, 0, 0, 1],
2573 ellipsise => 0,
2372 font => ($widget->{tooltip_font} || $::FONT_PROP), 2574 font => ($widget->{tooltip_font} || $::FONT_PROP),
2373 ); 2575 );
2374} 2576}
2375 2577
2376sub size_request { 2578sub size_request {
2377 my ($self) = @_; 2579 my ($self) = @_;
2423use CFClient::OpenGL; 2625use CFClient::OpenGL;
2424 2626
2425sub new { 2627sub new {
2426 my $class = shift; 2628 my $class = shift;
2427 2629
2428 $class->SUPER::new ( 2630 my $self = $class->SUPER::new (
2429 aspect => 1, 2631 aspect => 1,
2430 @_, 2632 @_,
2431 ) 2633 );
2634
2635 if ($self->{anim} && $self->{animspeed}) {
2636 Scalar::Util::weaken (my $widget = $self);
2637
2638 $self->{timer} = Event->timer (
2639 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
2640 hard => 1,
2641 interval => $self->{animspeed},
2642 cb => sub {
2643 ++$widget->{frame};
2644 $widget->update;
2645 },
2646 );
2647 }
2648
2649 $self
2432} 2650}
2433 2651
2434sub size_request { 2652sub size_request {
2435 (32, 8) 2653 (32, 8)
2436} 2654}
2437 2655
2656sub update {
2657 my ($self) = @_;
2658
2659 return unless $self->{visible};
2660
2661 $self->SUPER::update;
2662}
2663
2438sub _draw { 2664sub _draw {
2439 my ($self) = @_; 2665 my ($self) = @_;
2440 2666
2441 return unless $::CONN;#d# manage and cache textures differently 2667 return unless $::CONN;
2668
2669 my $face;
2670
2671 if ($self->{frame}) {
2672 my $anim = $::CONN->{anim}[$self->{anim}];
2673
2674 $face = $anim->[ $self->{frame} % @$anim ]
2675 if $anim && @$anim;
2676 }
2677
2442 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]]; 2678 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$face || $self->{face}]];
2443 2679
2444 # TODO animation
2445 if ($tex) { 2680 if ($tex) {
2446 glEnable GL_TEXTURE_2D; 2681 glEnable GL_TEXTURE_2D;
2447 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2682 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2448 glColor 1, 1, 1, 1; 2683 glColor 1, 1, 1, 1;
2449 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); 2684 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2450 glDisable GL_TEXTURE_2D; 2685 glDisable GL_TEXTURE_2D;
2451 } 2686 }
2452} 2687}
2453 2688
2689sub DESTROY {
2690 my ($self) = @_;
2691
2692 $self->{timer}->cancel
2693 if $self->{timer};
2694
2695 $self->SUPER::DESTROY;
2696}
2697
2454############################################################################# 2698#############################################################################
2455 2699
2456package CFClient::UI::InventoryItem; 2700package CFClient::UI::InventoryItem;
2457 2701
2458our @ISA = CFClient::UI::HBox::; 2702our @ISA = CFClient::UI::HBox::;
2703
2704sub _item_to_desc {
2705 my ($item) = @_;
2706
2707 my $desc =
2708 $item->{nrof} < 2
2709 ? $item->{name}
2710 : "$item->{nrof} × $item->{name_pl}";
2711
2712 $item->{flags} & Crossfire::Protocol::F_OPEN
2713 and $desc .= " (open)";
2714 $item->{flags} & Crossfire::Protocol::F_APPLIED
2715 and $desc .= " (applied)";
2716 $item->{flags} & Crossfire::Protocol::F_UNPAID
2717 and $desc .= " (unpaid)";
2718 $item->{flags} & Crossfire::Protocol::F_MAGIC
2719 and $desc .= " (magic)";
2720 $item->{flags} & Crossfire::Protocol::F_CURSED
2721 and $desc .= " (cursed)";
2722 $item->{flags} & Crossfire::Protocol::F_DAMNED
2723 and $desc .= " (damned)";
2724 $item->{flags} & Crossfire::Protocol::F_LOCKED
2725 and $desc .= " *";
2726
2727 $desc
2728}
2459 2729
2460sub new { 2730sub new {
2461 my $class = shift; 2731 my $class = shift;
2462 2732
2463 my %args = @_; 2733 my %args = @_;
2464 2734
2465 my $item = delete $args{item}; 2735 my $item = delete $args{item};
2466 2736
2467 my $desc = $item->{nrof} < 2 2737 my $desc = _item_to_desc ($item);
2468 ? $item->{name}
2469 : "$item->{nrof} $item->{name_pl}";
2470
2471 2738
2472 my $self = $class->SUPER::new ( 2739 my $self = $class->SUPER::new (
2473 can_hover => 1, 2740 can_hover => 1,
2474 can_events => 1, 2741 can_events => 1,
2475 tooltip => (CFClient::UI::Label->escape ($desc) 2742 tooltip => ((CFClient::UI::Label::escape $desc)
2476 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), 2743 . "\n<small>leftclick - examine\nshift+leftclick - move/pickup/drop\nmiddle click - apply\nrightclick - menu</small>"),
2477 connect_button_down => sub { 2744 connect_button_down => sub {
2478 my ($self, $ev, $x, $y) = @_; 2745 my ($self, $ev, $x, $y) = @_;
2479 2746
2480 # todo: maybe put examine on 1? but should just be a tooltip :( 2747 # todo: maybe put examine on 1? but should just be a tooltip :(
2748 if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) {
2749 my $targ = $::CONN->{player}{tag};
2750
2751 if ($item->{container} == $::CONN->{player}{tag}) {
2752 $targ = $main::OPENCONT;
2753 }
2754
2755 $::CONN->send ("move $targ $item->{tag} 0");
2481 if ($ev->{button} == 1) { 2756 } elsif ($ev->{button} == 1) {
2482 $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0"); 2757 $::CONN->send ("examine $item->{tag}");
2483 } elsif ($ev->{button} == 2) { 2758 } elsif ($ev->{button} == 2) {
2484 $::CONN->send ("apply $item->{tag}"); 2759 $::CONN->send ("apply $item->{tag}");
2485 } elsif ($ev->{button} == 3) { 2760 } elsif ($ev->{button} == 3) {
2486 CFClient::UI::Menu->new ( 2761 my @menu_items = (
2487 items => [
2488 ["examine", sub { $::CONN->send ("examine $item->{tag}") }], 2762 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2489 [
2490 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2491 sub { $::CONN->send ("lock $item->{tag}") },
2492 ],
2493 ["mark", sub { $::CONN->send ("mark $item->{tag}") }], 2763 ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }],
2494 ["apply", sub { $::CONN->send ("apply $item->{tag}") }], 2764 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2765 (
2766 $item->{flags} & Crossfire::Protocol::F_LOCKED
2767 ? (
2768 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }],
2769 )
2770 : (
2771 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }],
2495 ["drop", sub { $::CONN->send ("move 0 $item->{tag} 0") }], 2772 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2773 )
2496 ], 2774 ),
2497 )->popup ($ev); 2775 );
2776
2777 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2498 } 2778 }
2499 2779
2500 1 2780 1
2501 }, 2781 },
2502 %args 2782 %args
2503 ); 2783 );
2784
2504 2785
2505 $self->add (new CFClient::UI::Face 2786 $self->add (new CFClient::UI::Face
2506 can_events => 0, 2787 can_events => 0,
2507 face => $item->{face}, 2788 face => $item->{face},
2508 anim => $item->{anim}, 2789 anim => $item->{anim},
2509 animspeed => $item->{animspeed}, 2790 animspeed => $item->{animspeed},
2510 ); 2791 );
2511 2792
2512 $self->add (new CFClient::UI::Label 2793 $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0);
2513 can_events => 0, 2794
2514 text => $desc, 2795 $self->{item} = $item;
2515 ); 2796
2797 $self->update_item;
2516 2798
2517 $self 2799 $self
2800}
2801
2802sub update_item {
2803 my ($self) = @_;
2804
2805 my $desc = _item_to_desc ($self->{item});
2806
2807 $self->{name_lbl}->set_text ($desc);
2518} 2808}
2519 2809
2520############################################################################# 2810#############################################################################
2521 2811
2522package CFClient::UI::Inventory; 2812package CFClient::UI::Inventory;
2525 2815
2526sub new { 2816sub new {
2527 my $class = shift; 2817 my $class = shift;
2528 2818
2529 my $self = $class->SUPER::new ( 2819 my $self = $class->SUPER::new (
2530 scrolled => (new CFClient::UI::VBox), 2820 scrolled => (new CFClient::UI::Table),
2531 @_, 2821 @_,
2532 ); 2822 );
2533 2823
2534 $self 2824 $self
2535} 2825}
2546 } @$items; 2836 } @$items;
2547 2837
2548 $self->{real_items} = \@items; 2838 $self->{real_items} = \@items;
2549 2839
2550 for my $item (@items) { 2840 for my $item (@items) {
2551 my $desc = $item->{nrof} < 2 2841 $item->{item} = $item;
2552 ? $item->{name}
2553 : "$item->{nrof} $item->{name_pl}";
2554
2555 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; 2842 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2843 $item->update_item ();
2556 } 2844 }
2557 2845
2846 my $i = 0;
2847 for (@items) {
2558 $self->{scrolled}->add (@items); 2848 $self->{scrolled}->add (0, $i, $_);
2849 my $nrof = $_->{item}->{nrof} || 1;
2850 $self->{scrolled}->add (1, $i++, new CFClient::UI::Label text => ($_->{item}->{weight} * $nrof) / 1000);
2851 }
2559 2852
2560# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2853# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2561} 2854}
2562 2855
2563sub size_request { 2856sub size_request {
2605 2898
2606# popup given the event (must be a mouse button down event currently) 2899# popup given the event (must be a mouse button down event currently)
2607sub popup { 2900sub popup {
2608 my ($self, $ev) = @_; 2901 my ($self, $ev) = @_;
2609 2902
2610 $self->emit ("popdown"); 2903 $self->_emit ("popdown");
2611 2904
2612 # maybe save $GRAB? must be careful about events... 2905 # maybe save $GRAB? must be careful about events...
2613 $GRAB = $self; 2906 $GRAB = $self;
2614 $self->{button} = $ev->{button}; 2907 $self->{button} = $ev->{button};
2615 2908
2630 2923
2631 if ($ev->{button} == $self->{button}) { 2924 if ($ev->{button} == $self->{button}) {
2632 undef $GRAB; 2925 undef $GRAB;
2633 $self->hide; 2926 $self->hide;
2634 2927
2635 $self->emit ("popdown"); 2928 $self->_emit ("popdown");
2636 $self->{hover}[1]->() if $self->{hover}; 2929 $self->{hover}[1]->() if $self->{hover};
2637 } 2930 }
2638} 2931}
2639 2932
2640############################################################################# 2933#############################################################################
2641 2934
2642package CFClient::UI::Statusbox; 2935package CFClient::UI::Statusbox;
2643 2936
2644our @ISA = CFClient::UI::VBox::; 2937our @ISA = CFClient::UI::VBox::;
2938
2939sub new {
2940 my $class = shift;
2941
2942 $class->SUPER::new (
2943 fontsize => 0.8,
2944 @_,
2945 )
2946}
2645 2947
2646sub reorder { 2948sub reorder {
2647 my ($self) = @_; 2949 my ($self) = @_;
2648 my $NOW = time; 2950 my $NOW = time;
2649 2951
2668 ? "<b>$item->{count} ×</b> $item->{text}" 2970 ? "<b>$item->{count} ×</b> $item->{text}"
2669 : $item->{text}; 2971 : $item->{text};
2670 2972
2671 for ($short) { 2973 for ($short) {
2672 s/^\s+//; 2974 s/^\s+//;
2673 s/\012.*/…/s; 2975 s/\s+/ /g;
2674 my $len = int 40 / $item->{fontsize};
2675 substr $_, $len, length, "…" if $len < length;
2676 } 2976 }
2677 2977
2678 new CFClient::UI::Label 2978 new CFClient::UI::Label
2679 markup => $short, 2979 markup => $short,
2680 tooltip => $item->{tooltip}, 2980 tooltip => $item->{tooltip},
2681 tooltip_font => $::FONT_PROP, 2981 tooltip_font => $::FONT_PROP,
2682 tooltip_width => 0.67, 2982 tooltip_width => 0.67,
2683 fontsize => $item->{fontsize}, 2983 fontsize => $item->{fontsize} || $self->{fontsize},
2984 max_w => $::WIDTH * 0.44,
2684 color => $item->{color}, 2985 fg => $item->{fg},
2685 can_events => 1, 2986 can_events => 1,
2686 can_hover => 1 2987 can_hover => 1
2687 }; 2988 };
2688 } 2989 }
2689 2990
2715 $self->{item}{$group} = { 3016 $self->{item}{$group} = {
2716 id => ++$self->{id}, 3017 id => ++$self->{id},
2717 text => $text, 3018 text => $text,
2718 timeout => $timeout, 3019 timeout => $timeout,
2719 tooltip => $text, 3020 tooltip => $text,
2720 fontsize => 0.8,
2721 color => [0.8, 0.8, 0.8, 0.8], 3021 fg => [0.8, 0.8, 0.8, 0.8],
2722 pri => 0, 3022 pri => 0,
2723 count => 1, 3023 count => 1,
2724 %arg, 3024 %arg,
2725 }; 3025 };
2726 } 3026 }
2727 3027
2728 $self->reorder; 3028 $self->reorder;
2729} 3029}
2730 3030
3031sub reconfigure {
3032 my ($self) = @_;
3033
3034 delete $_->{label}
3035 for values %{ $self->{item} || {} };
3036
3037 $self->reorder;
3038 $self->SUPER::reconfigure;
3039}
3040
2731############################################################################# 3041#############################################################################
2732 3042
2733package CFClient::UI::Root; 3043package CFClient::UI::Root;
2734 3044
2735our @ISA = CFClient::UI::Container::; 3045our @ISA = CFClient::UI::Container::;
2765} 3075}
2766 3076
2767sub size_allocate { 3077sub size_allocate {
2768 my ($self, $w, $h) = @_; 3078 my ($self, $w, $h) = @_;
2769 3079
2770 my $old_w = $self->{old_w};
2771 my $old_h = $self->{old_h};
2772
2773 if ($old_w && $old_h) {
2774 for my $child ($self->children) {
2775 $child->{x} = int 0.5 + $child->{x} * $w / $old_w;
2776 $child->{w} = int 0.5 + $child->{w} * $w / $old_w;
2777 $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w};
2778 $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w};
2779 $child->{y} = int 0.5 + $child->{y} * $h / $old_h;
2780 $child->{h} = int 0.5 + $child->{h} * $h / $old_h;
2781 $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h};
2782 $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h};
2783 }
2784 }
2785
2786 for my $child ($self->children) { 3080 for my $child ($self->children) {
2787 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; 3081 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2788 3082
3083 $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1
3084 if exists $child->{req_x};
3085
3086 $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1
3087 if exists $child->{req_y};
3088
2789 $X = List::Util::max 0, List::Util::min $w - $W, $X; 3089 $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5;
2790 $Y = List::Util::max 0, List::Util::min $h - $H, $Y; 3090 $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5;
3091
2791 $child->configure ($X, $Y, $W, $H); 3092 $child->configure ($X, $Y, $W, $H);
2792 } 3093 }
2793
2794 $self->{old_w} = $w;
2795 $self->{old_h} = $h;
2796} 3094}
2797 3095
2798sub coord2local { 3096sub coord2local {
2799 my ($self, $x, $y) = @_; 3097 my ($self, $x, $y) = @_;
2800 3098
2813 $self->check_size; 3111 $self->check_size;
2814 $::WANT_REFRESH++; 3112 $::WANT_REFRESH++;
2815} 3113}
2816 3114
2817sub add { 3115sub add {
2818 my ($self, $child) = @_; 3116 my ($self, @children) = @_;
2819 3117
3118 for (my @widgets = @children; my $w = pop @widgets; ) {
3119 push @widgets, $w->children;
3120 $w->{root} = $self;
3121 $w->{visible} = 1;
3122 }
3123
3124 for my $child (@children) {
3125 $child->{is_toplevel} = 1;
3126
2820 # integerise window positions 3127 # integerise window positions
2821 $child->{x} = int $child->{x}; 3128 $child->{x} = int $child->{x};
2822 $child->{y} = int $child->{y}; 3129 $child->{y} = int $child->{y};
3130 }
2823 3131
2824 $self->SUPER::add ($child); 3132 $self->SUPER::add (@children);
3133}
3134
3135sub remove {
3136 my ($self, @children) = @_;
3137
3138 $self->SUPER::remove (@children);
3139
3140 while (@children) {
3141 my $w = pop @children;
3142 push @children, $w->children;
3143 $w->set_invisible;
3144 }
2825} 3145}
2826 3146
2827sub on_refresh { 3147sub on_refresh {
2828 my ($self, $id, $cb) = @_; 3148 my ($self, $id, $cb) = @_;
2829 3149
2882 $w = 0 if $w < 0; 3202 $w = 0 if $w < 0;
2883 $h = 0 if $h < 0; 3203 $h = 0 if $h < 0;
2884 3204
2885 $widget->{w} = $w; 3205 $widget->{w} = $w;
2886 $widget->{h} = $h; 3206 $widget->{h} = $h;
2887 $widget->size_allocate ($w, $h);
2888 $widget->emit (size_allocate => $w, $h); 3207 $widget->emit (size_allocate => $w, $h);
2889 } 3208 }
2890 } 3209 }
2891 3210
2892 while ($self->{post_alloc_hook}) { 3211 while ($self->{post_alloc_hook}) {
2898 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 3217 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2899 glClear GL_COLOR_BUFFER_BIT; 3218 glClear GL_COLOR_BUFFER_BIT;
2900 3219
2901 glMatrixMode GL_PROJECTION; 3220 glMatrixMode GL_PROJECTION;
2902 glLoadIdentity; 3221 glLoadIdentity;
2903 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000; 3222 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000, 10000;
2904 glMatrixMode GL_MODELVIEW; 3223 glMatrixMode GL_MODELVIEW;
2905 glLoadIdentity; 3224 glLoadIdentity;
2906 3225
2907 $self->_draw; 3226 $self->_draw;
2908} 3227}
2910############################################################################# 3229#############################################################################
2911 3230
2912package CFClient::UI; 3231package CFClient::UI;
2913 3232
2914$ROOT = new CFClient::UI::Root; 3233$ROOT = new CFClient::UI::Root;
2915$TOOLTIP = new CFClient::UI::Tooltip; 3234$TOOLTIP = new CFClient::UI::Tooltip z => 900;
2916 3235
29171 32361
2918 3237

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines