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.112 by root, Sat Apr 15 12:29:46 2006 UTC vs.
Revision 1.207 by elmex, Mon May 15 18:23:33 2006 UTC

1package CFClient::UI; 1package CFClient::UI;
2 2
3use utf8;
3use strict; 4use strict;
4 5
5use Scalar::Util (); 6use Scalar::Util ();
6use List::Util (); 7use List::Util ();
7 8
8use CFClient; 9use CFClient;
9 10
10our ($FOCUS, $HOVER, $GRAB); # various widgets 11our ($FOCUS, $HOVER, $GRAB); # various widgets
11 12
12our $TOPLEVEL; 13our $ROOT;
14our $TOOLTIP;
13our $BUTTON_STATE; 15our $BUTTON_STATE;
16
17our %WIDGET; # all widgets, weak-referenced
18
19sub check_tooltip {
20 if (!$GRAB) {
21 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
22 if (length $widget->{tooltip}) {
23
24 if ($TOOLTIP->{owner} != $widget) {
25 $TOOLTIP->{owner} = $widget;
26
27 my $tip = $widget->{tooltip};
28
29 $tip = $tip->($widget) if CODE:: eq ref $tip;
30
31 $TOOLTIP->set_tooltip_from ($widget);
32 $TOOLTIP->show;
33
34 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
35
36 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0)
37 if $x + $TOOLTIP->{w} > $::WIDTH;
38
39 $TOOLTIP->move ($x, $y);
40 $TOOLTIP->check_size;
41 $TOOLTIP->update;
42 }
43
44 return;
45 }
46 }
47 }
48
49 $TOOLTIP->hide;
50 delete $TOOLTIP->{owner};
51}
14 52
15# class methods for events 53# class methods for events
16sub feed_sdl_key_down_event { 54sub feed_sdl_key_down_event {
17 $FOCUS->key_down ($_[0]) if $FOCUS; 55 $FOCUS->emit (key_down => $_[0]) || $FOCUS->key_down ($_[0])
56 if $FOCUS;
18} 57}
19 58
20sub feed_sdl_key_up_event { 59sub feed_sdl_key_up_event {
21 $FOCUS->key_up ($_[0]) if $FOCUS; 60 $FOCUS->emit (key_up => $_[0]) || $FOCUS->key_up ($_[0])
61 if $FOCUS;
22} 62}
23 63
24sub feed_sdl_button_down_event { 64sub feed_sdl_button_down_event {
25 my ($ev) = @_; 65 my ($ev) = @_;
26 my ($x, $y) = ($ev->motion_x, $ev->motion_y); 66 my ($x, $y) = ($ev->{x}, $ev->{y});
27 67
28 if (!$BUTTON_STATE) { 68 if (!$BUTTON_STATE) {
29 my $widget = $TOPLEVEL->find_widget ($x, $y); 69 my $widget = $ROOT->find_widget ($x, $y);
30 70
31 $GRAB = $widget; 71 $GRAB = $widget;
32 $GRAB->update if $GRAB; 72 $GRAB->update if $GRAB;
33 }
34 73
74 check_tooltip;
75 }
76
35 $BUTTON_STATE |= 1 << ($ev->button - 1); 77 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
36 78
37 $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB; 79 if ($GRAB) {
80 ($x, $y) = $GRAB->coord2local ($x, $y);
81 $GRAB->emit (button_down => $ev, $x, $y) || $GRAB->button_down ($ev, $x, $y);
82 }
38} 83}
39 84
40sub feed_sdl_button_up_event { 85sub feed_sdl_button_up_event {
41 my ($ev) = @_; 86 my ($ev) = @_;
42 my ($x, $y) = ($ev->motion_x, $ev->motion_y); 87 my ($x, $y) = ($ev->{x}, $ev->{y});
43 88
44 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); 89 my $widget = $GRAB || $ROOT->find_widget ($x, $y);
45 90
46 $BUTTON_STATE &= ~(1 << ($ev->button - 1)); 91 $BUTTON_STATE &= ~(1 << ($ev->{button} - 1));
47 92
48 $GRAB->button_up ($ev, $GRAB->translate ($x, $y)) if $GRAB; 93 if ($GRAB) {
94 ($x, $y) = $GRAB->coord2local ($x, $y);
95 $GRAB->emit (button_up => $ev, $x, $y) || $GRAB->button_up ($ev, $x, $y);
96 }
49 97
50 if (!$BUTTON_STATE) { 98 if (!$BUTTON_STATE) {
51 my $grab = $GRAB; undef $GRAB; 99 my $grab = $GRAB; undef $GRAB;
52 $grab->update if $grab; 100 $grab->update if $grab;
53 $GRAB->update if $GRAB; 101 $GRAB->update if $GRAB;
102
103 check_tooltip;
54 } 104 }
55} 105}
56 106
57sub feed_sdl_motion_event { 107sub feed_sdl_motion_event {
58 my ($ev) = @_; 108 my ($ev) = @_;
59 my ($x, $y) = ($ev->motion_x, $ev->motion_y); 109 my ($x, $y) = ($ev->{x}, $ev->{y});
60 110
61 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); 111 my $widget = $GRAB || $ROOT->find_widget ($x, $y);
62 112
63 if ($widget != $HOVER) { 113 if ($widget != $HOVER) {
64 my $hover = $HOVER; $HOVER = $widget; 114 my $hover = $HOVER; $HOVER = $widget;
65 115
66 $hover->update if $hover && $hover->{can_hover}; 116 $hover->update if $hover && $hover->{can_hover};
67 $HOVER->update if $HOVER && $HOVER->{can_hover}; 117 $HOVER->update if $HOVER && $HOVER->{can_hover};
68 }
69 118
70 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; 119 check_tooltip;
120 }
121
122 if ($HOVER) {
123 ($x, $y) = $HOVER->coord2local ($x, $y);
124 $HOVER->emit (mouse_motion => $ev, $x, $y) || $HOVER->mouse_motion ($ev, $x, $y);
125 }
71} 126}
72 127
73# convert position array to integers 128# convert position array to integers
74sub harmonize { 129sub harmonize {
75 my ($vals) = @_; 130 my ($vals) = @_;
76 131
77 my $rem = 0; 132 my $rem = 0;
78 133
79 for ($vals) { 134 for (@$vals) {
80 my $i = int $_ + $rem; 135 my $i = int $_ + $rem;
81 $rem += $_ - $i; 136 $rem += $_ - $i;
82 $_ = $i; 137 $_ = $i;
83 } 138 }
84} 139}
85 140
141# call when resolution changes etc.
142sub rescale_widgets {
143 my ($sx, $sy) = @_;
144
145 for my $widget (values %WIDGET) {
146 if ($widget->{toplevel}) {
147 $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x};
148 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
149 $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w};
150 $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w};
151 $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y};
152 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h};
153 $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h};
154 $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h};
155 }
156
157 $widget->reconfigure;
158 }
159}
160
86############################################################################# 161#############################################################################
87 162
88package CFClient::UI::Base; 163package CFClient::UI::Base;
89 164
90use strict; 165use strict;
91 166
92use SDL::OpenGL; 167use CFClient::OpenGL;
93 168
94sub new { 169sub new {
95 my $class = shift; 170 my $class = shift;
96 171
97 my $self = bless { 172 my $self = bless {
98 x => 0, 173 x => 0,
99 y => 0, 174 y => 0,
100 z => 0, 175 z => 0,
101 w => -1, 176 can_events => 1,
102 h => -1,
103 @_ 177 @_
104 }, $class; 178 }, $class;
105 179
106 for (keys %$self) { 180 for (keys %$self) {
107 if (/^connect_(.*)$/) { 181 if (/^connect_(.*)$/) {
108 $self->connect ($1 => delete $self->{$_}); 182 $self->connect ($1 => delete $self->{$_});
109 } 183 }
110 } 184 }
111 185
186 Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self);
187
112 $self 188 $self
189}
190
191sub destroy {
192 my ($self) = @_;
193
194 $self->hide;
195 %$self = ();
196}
197
198sub show {
199 my ($self) = @_;
200
201 return if $self->{parent};
202
203 $CFClient::UI::ROOT->add ($self);
204}
205
206sub hide {
207 my ($self) = @_;
208
209 undef $GRAB if $GRAB == $self;
210 undef $HOVER if $HOVER == $self;
211
212 $self->{parent}->remove ($self)
213 if $self->{parent};
113} 214}
114 215
115sub move { 216sub move {
116 my ($self, $x, $y, $z) = @_; 217 my ($self, $x, $y, $z) = @_;
218
117 $self->{x} = $x; 219 $self->{x} = int $x;
118 $self->{y} = $y; 220 $self->{y} = int $y;
119 $self->{z} = $z if defined $z; 221 $self->{z} = $z if defined $z;
120}
121 222
122sub needs_redraw { 223 $self->update;
123 0 224}
225
226sub set_size {
227 my ($self, $w, $h) = @_;
228
229 $self->{user_w} = $w;
230 $self->{user_h} = $h;
231
232 $self->check_size;
124} 233}
125 234
126sub size_request { 235sub size_request {
127 require Carp; 236 require Carp;
128 Carp::confess "size_request is abtract"; 237 Carp::confess "size_request is abstract";
129} 238}
130 239
131sub _size_allocate { 240sub configure {
132 my ($self, $x, $y, $w, $h) = @_; 241 my ($self, $x, $y, $w, $h) = @_;
133 242
243 if ($self->{aspect}) {
244 my $w2 = List::Util::min $w, int $h * $self->{aspect};
245 my $h2 = List::Util::min $h, int $w / $self->{aspect};
246
247 # use alignment to adjust x, y
248
249 $x += int +($w - $w2) * 0.5;
250 $y += int +($h - $h2) * 0.5;
251
252 ($w, $h) = ($w2, $h2);
253 }
254
255 if ($self->{x} != $x || $self->{y} != $y) {
134 $self->{x} = $x; 256 $self->{x} = $x;
135 $self->{y} = $y; 257 $self->{y} = $y;
258 $self->update;
259 }
136 260
137 return unless $self->{w} != $w || $self->{h} != $h; 261 if ($self->{w} != $w || $self->{h} != $h) {
138 262 $CFClient::UI::ROOT->{size_alloc}{$self} = [$self, $w, $h];
139 $self->{w} = $w;
140 $self->{h} = $h;
141
142 1 263 }
143} 264}
144 265
145sub size_allocate { 266sub size_allocate {
267 # nothing to be done
268}
269
270sub reconfigure {
271 my ($self) = @_;
272
273 $self->check_size (1);
274 $self->update;
275}
276
277sub children {
278}
279
280sub set_max_size {
146 my ($self, $x, $y, $w, $h) = @_; 281 my ($self, $w, $h) = @_;
147 282
148 $self->_size_allocate ($x, $y, $w, $h); 283 delete $self->{max_w}; $self->{max_w} = $w if $w;
284 delete $self->{max_h}; $self->{max_h} = $h if $h;
149} 285}
150 286
151# translate global coordinates to local coordinate system 287# translate global coordinates to local coordinate system
152sub translate { 288sub coord2local {
153 my ($self, $x, $y) = @_; 289 my ($self, $x, $y) = @_;
154 290
155 $self->{parent}->translate ($x - $self->{x}, $y - $self->{y}); 291 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y})
292}
293
294# translate local coordinates to global coordinate system
295sub coord2global {
296 my ($self, $x, $y) = @_;
297
298 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y})
156} 299}
157 300
158sub focus_in { 301sub focus_in {
159 my ($self) = @_; 302 my ($self) = @_;
160 303
161 return if $FOCUS == $self; 304 return if $FOCUS == $self;
162 return unless $self->{can_focus}; 305 return unless $self->{can_focus};
163 306
164 my $focus = $FOCUS; $FOCUS = $self; 307 my $focus = $FOCUS; $FOCUS = $self;
308
309 $self->emit (focus_in => $focus);
310
165 $focus->update if $focus; 311 $focus->update if $focus;
166 $FOCUS->update; 312 $FOCUS->update;
167} 313}
168 314
169sub focus_out { 315sub focus_out {
170 my ($self) = @_; 316 my ($self) = @_;
171 317
172 return unless $FOCUS == $self; 318 return unless $FOCUS == $self;
173 319
174 my $focus = $FOCUS; undef $FOCUS; 320 my $focus = $FOCUS; undef $FOCUS;
321
322 $self->emit (focus_out => $focus);
323
175 $focus->update if $focus; #? 324 $focus->update if $focus; #?
176} 325}
177 326
178sub mouse_motion { } 327sub mouse_motion { }
179sub button_up { } 328sub button_up { }
203 glPopMatrix; 352 glPopMatrix;
204 353
205 if ($self == $HOVER && $self->{can_hover}) { 354 if ($self == $HOVER && $self->{can_hover}) {
206 my ($x, $y) = @$self{qw(x y)}; 355 my ($x, $y) = @$self{qw(x y)};
207 356
208 glColor 0, 0, 1, 0.2; 357 glColor 1, 0.8, 0.5, 0.2;
209 glEnable GL_BLEND; 358 glEnable GL_BLEND;
210 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 359 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
211 glBegin GL_QUADS; 360 glBegin GL_QUADS;
212 glVertex $x , $y; 361 glVertex $x , $y;
213 glVertex $x + $self->{w}, $y; 362 glVertex $x + $self->{w}, $y;
214 glVertex $x + $self->{w}, $y + $self->{h}; 363 glVertex $x + $self->{w}, $y + $self->{h};
215 glVertex $x , $y + $self->{h}; 364 glVertex $x , $y + $self->{h};
216 glEnd; 365 glEnd;
217 glDisable GL_BLEND; 366 glDisable GL_BLEND;
218 } 367 }
368
369 if ($ENV{PCLIENT_DEBUG}) {
370 glPushMatrix;
371 glColor 1, 1, 0, 1;
372 glTranslate $self->{x} + 0.375, $self->{y} + 0.375;
373 glBegin GL_LINE_LOOP;
374 glVertex 0 , 0;
375 glVertex $self->{w}, 0;
376 glVertex $self->{w}, $self->{h};
377 glVertex 0 , $self->{h};
378 glEnd;
379 glPopMatrix;
380 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
381 }
219} 382}
220 383
221sub _draw { 384sub _draw {
222 my ($self) = @_; 385 my ($self) = @_;
223 386
224 warn "no draw defined for $self\n"; 387 warn "no draw defined for $self\n";
225} 388}
226 389
227sub find_widget { 390sub find_widget {
228 my ($self, $x, $y) = @_; 391 my ($self, $x, $y) = @_;
392
393 return () unless $self->{can_events};
229 394
230 return $self 395 return $self
231 if $x >= $self->{x} && $x < $self->{x} + $self->{w} 396 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
232 && $y >= $self->{y} && $y < $self->{y} + $self->{h}; 397 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
233 398
234 () 399 ()
235} 400}
236 401
237sub set_parent { 402sub set_parent {
238 my ($self, $par) = @_; 403 my ($self, $parent) = @_;
239 404
240 $self->{parent} = $par;
241 Scalar::Util::weaken $self->{parent}; 405 Scalar::Util::weaken ($self->{parent} = $parent);
242}
243 406
244sub get_parent { 407 # TODO: req_w _does_change after ->reconfigure
245 $_[0]->{parent} 408 $self->check_size
409 unless exists $self->{req_w};
410}
411
412sub check_size {
413 my ($self, $forced) = @_;
414
415 $self->{force_alloc} = 1 if $forced;
416 $CFClient::UI::ROOT->{check_size}{$self} = $self;
246} 417}
247 418
248sub update { 419sub update {
249 my ($self) = @_; 420 my ($self) = @_;
250 421
253} 424}
254 425
255sub connect { 426sub connect {
256 my ($self, $signal, $cb) = @_; 427 my ($self, $signal, $cb) = @_;
257 428
258 push @{ $self->{cb}{$signal} }, $cb; 429 push @{ $self->{signal_cb}{$signal} }, $cb;
259} 430}
260 431
261sub emit { 432sub emit {
262 my ($self, $signal, @args) = @_; 433 my ($self, $signal, @args) = @_;
263 434
264 $_->($self, @args) 435 List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []}
265 for @{$self->{cb}{$signal} || []};
266} 436}
267 437
268sub DESTROY { 438sub DESTROY {
269 my ($self) = @_; 439 my ($self) = @_;
270 440
441 delete $WIDGET{$self+0};
271 #$self->deactivate; 442 #$self->deactivate;
272} 443}
273 444
274############################################################################# 445#############################################################################
275 446
276package CFClient::UI::DrawBG; 447package CFClient::UI::DrawBG;
277 448
278our @ISA = CFClient::UI::Base::; 449our @ISA = CFClient::UI::Base::;
279 450
280use strict; 451use strict;
281use SDL::OpenGL; 452use CFClient::OpenGL;
282 453
283sub new { 454sub new {
284 my $class = shift; 455 my $class = shift;
285 456
286 # range [value, low, high, page] 457 # range [value, low, high, page]
315 486
316package CFClient::UI::Empty; 487package CFClient::UI::Empty;
317 488
318our @ISA = CFClient::UI::Base::; 489our @ISA = CFClient::UI::Base::;
319 490
491sub new {
492 my ($class, %arg) = @_;
493 $class->SUPER::new (can_events => 0, %arg);
494}
495
320sub size_request { 496sub size_request {
321 (0, 0) 497 (0, 0)
322} 498}
323 499
324sub draw { } 500sub draw { }
332sub new { 508sub new {
333 my ($class, %arg) = @_; 509 my ($class, %arg) = @_;
334 510
335 my $children = delete $arg{children} || []; 511 my $children = delete $arg{children} || [];
336 512
337 my $self = $class->SUPER::new (children => [], %arg); 513 my $self = $class->SUPER::new (
514 children => [],
515 can_events => 0,
516 %arg,
517 );
338 $self->add ($_) for @$children; 518 $self->add ($_) for @$children;
339 519
340 $self 520 $self
341} 521}
342 522
343sub add { 523sub add {
344 my ($self, $chld) = @_; 524 my ($self, @widgets) = @_;
345 525
346 $chld->set_parent ($self); 526 $_->set_parent ($self)
527 for @widgets;
528
529 use sort 'stable';
347 530
348 $self->{children} = [ 531 $self->{children} = [
349 sort { $a->{z} <=> $b->{z} } 532 sort { $a->{z} <=> $b->{z} }
350 @{$self->{children}}, $chld 533 @{$self->{children}}, @widgets
351 ]; 534 ];
352 535
353 $self->{w} = $self->{h} = -1; 536 $self->check_size (1);
354 $self->update; 537 $self->update;
355} 538}
356 539
540sub children {
541 @{ $_[0]{children} }
542}
543
357sub remove { 544sub remove {
358 my ($self, $widget) = @_; 545 my ($self, $child) = @_;
359 546
547 delete $child->{parent};
548 $child->hide;
549
360 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 550 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
361 551
362 $self->size_allocate (0, 0, $self->{w}, $self->{h}); 552 $self->check_size;
553 $self->update;
554}
555
556sub clear {
557 my ($self) = @_;
558
559 my $children = delete $self->{children};
560 $self->{children} = [];
561
562 for (@$children) {
563 delete $_->{parent};
564 $_->hide;
565 }
566
567 $self->check_size;
568 $self->update;
363} 569}
364 570
365sub find_widget { 571sub find_widget {
366 my ($self, $x, $y) = @_; 572 my ($self, $x, $y) = @_;
367 573
397 603
398 $class->SUPER::new (children => [$child], %arg) 604 $class->SUPER::new (children => [$child], %arg)
399} 605}
400 606
401sub add { 607sub add {
402 my ($self, $widget) = @_; 608 my ($self, $child) = @_;
403 609
404 $self->{children} = []; 610 $self->{children} = [];
405 611
406 $self->SUPER::add ($widget); 612 $self->SUPER::add ($child);
407} 613}
408 614
409sub remove { 615sub remove {
410 my ($self, $widget) = @_; 616 my ($self, $widget) = @_;
411 617
420sub size_request { 626sub size_request {
421 $_[0]{children}[0]->size_request 627 $_[0]{children}[0]->size_request
422} 628}
423 629
424sub size_allocate { 630sub size_allocate {
425 my ($self, $x, $y, $w, $h) = @_; 631 my ($self, $w, $h) = @_;
426 632
427 $self->_size_allocate ($x, $y, $w, $h) or return;
428
429 $self->{children}[0]->size_allocate (0, 0, $w, $h); 633 $self->{children}[0]->configure (0, 0, $w, $h);
430} 634}
431 635
432############################################################################# 636#############################################################################
433 637
434package CFClient::UI::Window; 638package CFClient::UI::Window;
435 639
436our @ISA = CFClient::UI::Bin::; 640our @ISA = CFClient::UI::Bin::;
437 641
438use SDL::OpenGL; 642use CFClient::OpenGL;
439 643
440sub new { 644sub new {
441 my ($class, %arg) = @_; 645 my ($class, %arg) = @_;
442 646
443 my $self = $class->SUPER::new (%arg); 647 my $self = $class->SUPER::new (%arg);
444} 648}
445 649
446sub update { 650sub update {
447 my ($self) = @_; 651 my ($self) = @_;
448 652
449 # we want to do this delayed... 653 $ROOT->on_post_alloc ($self => sub { $self->render_child });
450 $self->render_chld;
451 $self->SUPER::update; 654 $self->SUPER::update;
452} 655}
453 656
657sub size_allocate {
658 my ($self, $w, $h) = @_;
659
660 $self->SUPER::size_allocate ($w, $h);
661 $self->update;
662}
663
664sub _render {
665 $_[0]{children}[0]->draw;
666}
667
454sub render_chld { 668sub render_child {
455 my ($self) = @_; 669 my ($self) = @_;
456 670
457 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 671 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
458 glClearColor 0, 0, 0, 1; 672 glClearColor 0, 0, 0, 0;
459 glClear GL_COLOR_BUFFER_BIT; 673 glClear GL_COLOR_BUFFER_BIT;
460 $self->child->draw; 674
675 $self->_render;
676# glColorMask 1, 1, 1, 0;
677# glEnable GL_BLEND;
678# glBlendFunc GL_SRC_ALPHA, GL_ZERO;
679# glRasterPos 0, 0;
680# glCopyPixels 0, 0, $self->{w}, $self->{h};
681# glDisable GL_BLEND;
682# glColorMask 1, 1, 1, 1;
461 }; 683 };
462}
463
464sub size_allocate {
465 my ($self, $x, $y, $w, $h) = @_;
466
467 $self->_size_allocate ($x, $y, $w, $h) or return;
468
469 $self->child->size_allocate (0, 0, $w, $h);
470
471 $self->render_chld;
472} 684}
473 685
474sub _draw { 686sub _draw {
475 my ($self) = @_; 687 my ($self) = @_;
476 688
477 my ($w, $h) = ($self->w, $self->h); 689 my ($w, $h) = ($self->w, $self->h);
478 690
479 my $tex = $self->{texture} 691 my $tex = $self->{texture}
480 or return; 692 or return;
481 693
482 glEnable GL_BLEND;
483 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
484 glEnable GL_TEXTURE_2D; 694 glEnable GL_TEXTURE_2D;
485 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 695 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
696 glColor 0, 0, 0, 1;
486 697
487 $tex->draw_quad (0, 0, $w, $h); 698 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h);
488 699
489 glDisable GL_BLEND;
490 glDisable GL_TEXTURE_2D; 700 glDisable GL_TEXTURE_2D;
491} 701}
492 702
493############################################################################# 703#############################################################################
494 704
495package CFClient::UI::Frame; 705package CFClient::UI::ViewPort;
496 706
497our @ISA = CFClient::UI::Bin::; 707our @ISA = CFClient::UI::Window::;
498
499use SDL::OpenGL;
500 708
501sub size_request { 709sub size_request {
502 my ($self) = @_; 710 my ($self) = @_;
503 my $chld = $self->child
504 or return (0, 0);
505 711
506 $chld->move (2, 2); 712 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)};
713 $self->child->configure (0, 0, @$self{qw(child_w child_h)});
507 714
508 map { $_ + 4 } $chld->size_request; 715 @$self{qw(child_w child_h)}
509} 716}
510 717
511sub size_allocate { 718sub size_allocate {
512 my ($self, $x, $y, $w, $h) = @_; 719 my ($self, $w, $h) = @_;
720
721 $self->update;
722}
723
724sub set_offset {
725 my ($self, $x, $y) = @_;
726
727 $self->{view_x} = int $x;
728 $self->{view_y} = int $y;
729
730 $self->update;
731}
732
733# hmm, this does not work for topleft of $self... but we should not ask for that
734sub coord2local {
735 my ($self, $x, $y) = @_;
736
737 $self->SUPER::coord2local ($x + $self->{view_x}, $y + $self->{view_y})
738}
739
740sub coord2global {
741 my ($self, $x, $y) = @_;
742
743 $x = List::Util::min $self->{w}, $x - $self->{view_x};
744 $y = List::Util::min $self->{h}, $y - $self->{view_y};
745
746 $self->SUPER::coord2global ($x, $y)
747}
748
749sub find_widget {
750 my ($self, $x, $y) = @_;
751
752 if ( $x >= $self->{x} && $x < $self->{x} + $self->{w}
753 && $y >= $self->{y} && $y < $self->{y} + $self->{h}
754 ) {
755 $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y})
756 } else {
757 $self->CFClient::UI::Base::find_widget ($x, $y)
513 758 }
514 $self->_size_allocate ($x, $y, $w, $h) or return;
515
516 $self->child->size_allocate (2, 2, $w - 4, $h - 4);
517} 759}
518 760
519sub _draw { 761sub _render {
520 my ($self) = @_; 762 my ($self) = @_;
521 763
522 my $chld = $self->child; 764 CFClient::OpenGL::glTranslate -$self->{view_x}, -$self->{view_y};
523 765
524 my ($w, $h) = $chld->size_request; 766 $self->SUPER::_render;
525
526 glBegin GL_QUADS;
527 glColor 0, 0, 0;
528 glVertex 0 , 0;
529 glVertex 0 , $h + 4;
530 glVertex $w + 4 , $h + 4;
531 glVertex $w + 4 , 0;
532 glEnd;
533
534 $chld->draw;
535} 767}
536 768
537############################################################################# 769#############################################################################
538 770
539package CFClient::UI::FancyFrame; 771package CFClient::UI::ScrolledWindow;
540 772
541our @ISA = CFClient::UI::Bin::; 773our @ISA = CFClient::UI::HBox::;
542
543use SDL::OpenGL;
544
545my @tex =
546 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
547 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
548 774
549sub new { 775sub new {
550 my $class = shift; 776 my $class = shift;
551 777
778 my $self;
779
780 my $slider = new CFClient::UI::Slider
781 vertical => 1,
782 range => [0, 0, 1, 0.01], # HACK fix
783 connect_changed => sub {
784 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h}));
785 },
786 ;
787
788 $self = $class->SUPER::new (
789 vp => (new CFClient::UI::ViewPort),
790 slider => $slider,
791 @_,
792 );
793
794 $self->{vp}->add ($self->{scrolled});
795 $self->add ($self->{vp});
796 $self->add ($self->{slider});
797
798 $self
799}
800
801#TODO# update range on size_allocate depending on child
802# update viewport offset on scroll
803
804#############################################################################
805
806package CFClient::UI::Frame;
807
808our @ISA = CFClient::UI::Bin::;
809
810use CFClient::OpenGL;
811
812sub new {
813 my $class = shift;
814
815 $class->SUPER::new (
816 bg => undef,
817 @_,
818 )
819}
820
821sub _draw {
822 my ($self) = @_;
823
824 if ($self->{bg}) {
825 my ($w, $h) = @$self{qw(w h)};
826
827 glEnable GL_BLEND;
828 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
829 glColor @{ $self->{bg} };
830
831 glBegin GL_QUADS;
832 glVertex 0 , 0;
833 glVertex 0 , $h;
834 glVertex $w, $h;
835 glVertex $w, 0;
836 glEnd;
837
838 glDisable GL_BLEND;
839 }
840
841 $self->SUPER::_draw;
842}
843
844#############################################################################
845
846package CFClient::UI::FancyFrame;
847
848our @ISA = CFClient::UI::Bin::;
849
850use CFClient::OpenGL;
851
852my @tex =
853 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
854 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
855
856sub new {
857 my $class = shift;
858
552 # TODO: user_x, user_y, overwrite moveto? 859 # TODO: user_x, user_y, overwrite moveto?
553 860
554 $class->SUPER::new ( 861 my $self = $class->SUPER::new (
555 bg => [1, 1, 1, 1], 862 bg => [1, 1, 1, 1],
556 border_bg => [1, 1, 1, 1], 863 border_bg => [1, 1, 1, 1],
557 border => $::FONTSIZE * 0.8, 864 border => 0.6,
865 toplevel => 1,
866 can_events => 1,
558 @_ 867 @_
868 );
869
870 $self->{title} &&= new CFClient::UI::Label
871 align => 0,
872 valign => 1,
873 text => $self->{title},
874 fontsize => $self->{border};
875
876 $self
877}
878
879sub border {
880 int $_[0]{border} * $::FONTSIZE
881}
882
883sub size_request {
884 my ($self) = @_;
885
886 my ($w, $h) = $self->SUPER::size_request;
887
888 (
889 $w + $self->border * 2,
890 $h + $self->border * 2,
559 ) 891 )
560} 892}
561 893
562sub size_request {
563 my ($self) = @_;
564
565 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
566
567 my ($w, $h) = $self->SUPER::size_request;
568
569 (
570 $w + $self->{border} * 2,
571 $h + $self->{border} * 2,
572 )
573}
574
575sub size_allocate { 894sub size_allocate {
576 my ($self, $x, $y, $w, $h) = @_; 895 my ($self, $w, $h) = @_;
577 896
578 $self->_size_allocate ($x, $y, $w, $h) or return;
579
580 $h -= List::Util::max 0, $self->{border} * 2; 897 $h -= List::Util::max 0, $self->border * 2;
581 $w -= List::Util::max 0, $self->{border} * 2; 898 $w -= List::Util::max 0, $self->border * 2;
582 899
900 $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2)
901 if $self->{title};
902
583 $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); 903 $self->child->configure ($self->border, $self->border, $w, $h);
584} 904}
585 905
586sub button_down { 906sub button_down {
587 my ($self, $ev, $x, $y) = @_; 907 my ($self, $ev, $x, $y) = @_;
588 908
589 if ($x < $self->{w} && $x >= $self->{w} - $self->{border} 909 my ($w, $h) = @$self{qw(w h)};
590 && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { 910 my $border = $self->border;
591 911
912 my $lr = ($x >= 0 && $x < $border) || ($x > $w - $border && $x < $w);
913 my $td = ($y >= 0 && $y < $border) || ($y > $h - $border && $y < $h);
914
915 if ($lr & $td) {
916 my ($wx, $wy) = ($self->{x}, $self->{y});
592 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 917 my ($ox, $oy) = ($ev->{x}, $ev->{y});
593 my ($bw, $bh) = ($self->{w}, $self->{h}); 918 my ($bw, $bh) = ($self->{w}, $self->{h});
919
920 my $mx = $x < $border;
921 my $my = $y < $border;
594 922
595 $self->{motion} = sub { 923 $self->{motion} = sub {
596 my ($ev, $x, $y) = @_; 924 my ($ev, $x, $y) = @_;
597 925
598 ($x, $y) = ($ev->motion_x, $ev->motion_y); 926 my $dx = $ev->{x} - $ox;
927 my $dy = $ev->{y} - $oy;
599 928
600 $self->{user_w} = $bw + $x - $ox; 929 $self->{user_w} = $bw + $dx * ($mx ? -1 : 1);
601 $self->{user_h} = $bh + $y - $oy; 930 $self->{user_h} = $bh + $dy * ($my ? -1 : 1);
602 $self->update; 931 $self->move ($wx + $dx * $mx, $wy + $dy * $my);
932 $self->check_size;
603 }; 933 };
604 934
605 } elsif ($x >= 0 && $x < $self->{w} 935 } elsif ($lr ^ $td) {
606 && $y >= 0 && $y < $self->{border}) {
607
608 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 936 my ($ox, $oy) = ($ev->{x}, $ev->{y});
609 my ($bx, $by) = ($self->{x}, $self->{y}); 937 my ($bx, $by) = ($self->{x}, $self->{y});
610 938
611 $self->{motion} = sub { 939 $self->{motion} = sub {
612 my ($ev, $x, $y) = @_; 940 my ($ev, $x, $y) = @_;
613 941
614 ($x, $y) = ($ev->motion_x, $ev->motion_y); 942 ($x, $y) = ($ev->{x}, $ev->{y});
615 943
616 $self->move ($bx + $x - $ox, $by + $y - $oy); 944 $self->move ($bx + $x - $ox, $by + $y - $oy);
617 $self->update; 945 $self->update;
618 }; 946 };
619 } 947 }
635 my ($self) = @_; 963 my ($self) = @_;
636 964
637 my ($w, $h ) = ($self->{w}, $self->{h}); 965 my ($w, $h ) = ($self->{w}, $self->{h});
638 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 966 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
639 967
640 glEnable GL_BLEND;
641 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
642 glEnable GL_TEXTURE_2D; 968 glEnable GL_TEXTURE_2D;
643 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 969 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
644 970
971 my $border = $self->border;
972
645 glColor @{ $self->{border_bg} }; 973 glColor @{ $self->{border_bg} };
646 $tex[1]->draw_quad (0, 0, $w, $self->{border}); 974 $tex[1]->draw_quad_alpha (0, 0, $w, $border);
647 $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); 975 $tex[3]->draw_quad_alpha (0, $border, $border, $ch);
648 $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); 976 $tex[2]->draw_quad_alpha ($w - $border, $border, $border, $ch);
649 $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); 977 $tex[4]->draw_quad_alpha (0, $h - $border, $w, $border);
650 978
979 if (@{$self->{bg}} < 4 || $self->{bg}[3]) {
651 my $bg = $tex[0]; 980 my $bg = $tex[0];
652 981
653 # TODO: repeat texture not scale 982 # TODO: repeat texture not scale
654 my $rep_x = $cw / $bg->{w}; 983 my $rep_x = $cw / $bg->{w};
655 my $rep_y = $ch / $bg->{h}; 984 my $rep_y = $ch / $bg->{h};
656 985
657 glColor @{ $self->{bg} }; 986 glColor @{ $self->{bg} };
658 987
659 $bg->{s} = $rep_x; 988 $bg->{s} = $rep_x;
660 $bg->{t} = $rep_y; 989 $bg->{t} = $rep_y;
661 $bg->{wrap_mode} = 1; 990 $bg->{wrap_mode} = 1;
662 $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); 991 $bg->draw_quad_alpha ($border, $border, $cw, $ch);
992 }
663 993
664 glDisable GL_TEXTURE_2D; 994 glDisable GL_TEXTURE_2D;
665 glDisable GL_BLEND; 995
996 $self->{title}->draw if $self->{title};
666 997
667 $self->child->draw; 998 $self->child->draw;
668} 999}
669 1000
670############################################################################# 1001#############################################################################
673 1004
674our @ISA = CFClient::UI::Base::; 1005our @ISA = CFClient::UI::Base::;
675 1006
676use List::Util qw(max sum); 1007use List::Util qw(max sum);
677 1008
678use SDL::OpenGL; 1009use CFClient::OpenGL;
679 1010
680sub new { 1011sub new {
681 my $class = shift; 1012 my $class = shift;
682 1013
683 $class->SUPER::new ( 1014 $class->SUPER::new (
685 @_ 1016 @_
686 ) 1017 )
687} 1018}
688 1019
689sub add { 1020sub add {
690 my ($self, $x, $y, $chld) = @_; 1021 my ($self, $x, $y, $child) = @_;
691 1022
1023 $child->set_parent ($self);
692 $self->{children}[$y][$x] = $chld; 1024 $self->{children}[$y][$x] = $child;
693 $chld->set_parent ($self);
694 1025
695 $self->{w} = $self->{h} = -1; 1026 $child->check_size;
1027}
1028
1029sub children {
1030 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1031}
1032
1033# TODO: move to container class maybe? send childs a signal on removal?
1034sub clear {
1035 my ($self) = @_;
1036
1037 my @children = $self->children;
1038 delete $self->{children};
1039
1040 for (@children) {
1041 delete $_->{parent};
1042 $_->hide;
1043 }
1044
696 $self->update; 1045 $self->update;
697} 1046}
698 1047
699sub get_wh { 1048sub get_wh {
700 my ($self) = @_; 1049 my ($self) = @_;
706 or next; 1055 or next;
707 1056
708 for my $x (0 .. $#$row) { 1057 for my $x (0 .. $#$row) {
709 my $widget = $row->[$x] 1058 my $widget = $row->[$x]
710 or next; 1059 or next;
711 my ($w, $h) = $widget->size_request; 1060 my ($w, $h) = @$widget{qw(req_w req_h)};
712 1061
713 $w[$x] = max $w[$x], $w; 1062 $w[$x] = max $w[$x], $w;
714 $h[$y] = max $h[$y], $h; 1063 $h[$y] = max $h[$y], $h;
715 } 1064 }
716 } 1065 }
728 (sum @$hs), 1077 (sum @$hs),
729 ) 1078 )
730} 1079}
731 1080
732sub size_allocate { 1081sub size_allocate {
733 my ($self, $x, $y, $w, $h) = @_; 1082 my ($self, $w, $h) = @_;
734
735 $self->_size_allocate ($x, $y, $w, $h) or return;
736 1083
737 my ($ws, $hs) = $self->get_wh; 1084 my ($ws, $hs) = $self->get_wh;
738 1085
739 my $req_w = sum @$ws; 1086 my $req_w = sum @$ws;
740 my $req_h = sum @$hs; 1087 my $req_h = sum @$hs;
762 1109
763 for my $c (0 .. $#$row) { 1110 for my $c (0 .. $#$row) {
764 my $col_w = $ws->[$c]; 1111 my $col_w = $ws->[$c];
765 1112
766 if (my $widget = $row->[$c]) { 1113 if (my $widget = $row->[$c]) {
767 $widget->size_allocate ($x, $y, $col_w, $row_h); 1114 $widget->configure ($x, $y, $col_w, $row_h);
768 } 1115 }
769 1116
770 $x += $col_w; 1117 $x += $col_w;
771 } 1118 }
772 1119
817 (List::Util::max map $_->[1], @alloc), 1164 (List::Util::max map $_->[1], @alloc),
818 ) 1165 )
819} 1166}
820 1167
821sub size_allocate { 1168sub size_allocate {
822 my ($self, $x, $y, $w, $h) = @_; 1169 my ($self, $w, $h) = @_;
823
824 $self->_size_allocate ($x, $y, $w, $h);
825 1170
826 ($h, $w) = ($w, $h); 1171 ($h, $w) = ($w, $h);
827 1172
828 my $children = $self->{children}; 1173 my $children = $self->{children};
829 1174
830 my @h = map +($_->size_request)[0], @$children; 1175 my @h = map $_->{req_w}, @$children;
831 1176
832 my $req_h = List::Util::sum @h; 1177 my $req_h = List::Util::sum @h;
833 1178
834 if ($req_h > $h) { 1179 if ($req_h > $h) {
835 # ah well, not enough space 1180 # ah well, not enough space
851 1196
852 my $y = 0; 1197 my $y = 0;
853 for (0 .. $#$children) { 1198 for (0 .. $#$children) {
854 my $child = $children->[$_]; 1199 my $child = $children->[$_];
855 my $h = $h[$_]; 1200 my $h = $h[$_];
856 $child->size_allocate ($y, 0, $h, $w); 1201 $child->configure ($y, 0, $h, $w);
857 1202
858 $y += $h; 1203 $y += $h;
859 } 1204 }
1205
1206 1
860} 1207}
861 1208
862############################################################################# 1209#############################################################################
863 1210
864package CFClient::UI::VBox; 1211package CFClient::UI::VBox;
877 (List::Util::sum map $_->[1], @alloc), 1224 (List::Util::sum map $_->[1], @alloc),
878 ) 1225 )
879} 1226}
880 1227
881sub size_allocate { 1228sub size_allocate {
882 my ($self, $x, $y, $w, $h) = @_; 1229 my ($self, $w, $h) = @_;
883 1230
884 $self->_size_allocate ($x, $y, $w, $h); 1231 Carp::confess "negative size" if $w < 0 || $h < 0;#d#
885 1232
886 my $children = $self->{children}; 1233 my $children = $self->{children};
887 1234
888 my @h = map +($_->size_request)[1], @$children; 1235 my @h = map $_->{req_h}, @$children;
889 1236
890 my $req_h = List::Util::sum @h; 1237 my $req_h = List::Util::sum @h;
891 1238
892 if ($req_h > $h) { 1239 if ($req_h > $h) {
893 # ah well, not enough space 1240 # ah well, not enough space
907 1254
908 my $y = 0; 1255 my $y = 0;
909 for (0 .. $#$children) { 1256 for (0 .. $#$children) {
910 my $child = $children->[$_]; 1257 my $child = $children->[$_];
911 my $h = $h[$_]; 1258 my $h = $h[$_];
912 $child->size_allocate (0, $y, $w, $h); 1259 $child->configure (0, $y, $w, $h);
913 1260
914 $y += $h; 1261 $y += $h;
915 } 1262 }
1263
1264 1
916} 1265}
917 1266
918############################################################################# 1267#############################################################################
919 1268
920package CFClient::UI::Label; 1269package CFClient::UI::Label;
921 1270
922our @ISA = CFClient::UI::Base::; 1271our @ISA = CFClient::UI::Base::;
923 1272
924use SDL::OpenGL; 1273use CFClient::OpenGL;
925 1274
926sub new { 1275sub new {
927 my ($class, %arg) = @_; 1276 my ($class, %arg) = @_;
928 1277
929 my $self = $class->SUPER::new ( 1278 my $self = $class->SUPER::new (
930 fg => [1, 1, 1], 1279 fg => [1, 1, 1],
931 fontsize => $::FONTSIZE, 1280 #font => default_font
932 text => "", 1281 #text => initial text
1282 #markup => initial narkup
1283 layout => (new CFClient::Layout),
1284 fontsize => 1,
933 align => -1, 1285 align => -1,
1286 valign => -1,
934 padding => 2, 1287 padding => 2,
935 layout => new CFClient::Layout, 1288 can_events => 0,
936 %arg 1289 %arg
937 ); 1290 );
938 1291
1292 if (exists $self->{template}) {
1293 my $layout = new CFClient::Layout;
1294 $layout->set_text (delete $self->{template});
1295 $self->{template} = $layout;
1296 }
1297
1298 if (exists $self->{markup}) {
1299 $self->set_markup (delete $self->{markup});
1300 } else {
939 $self->set_text ($self->{text}); 1301 $self->set_text (delete $self->{text});
1302 }
940 1303
941 $self 1304 $self
942} 1305}
943 1306
944sub escape_text { 1307sub escape {
945 local $_ = $_[1]; 1308 local $_ = $_[1];
946 1309
947 s/&/&amp;/g; 1310 s/&/&amp;/g;
948 s/>/&gt;/g; 1311 s/>/&gt;/g;
949 s/</&lt;/g; 1312 s/</&lt;/g;
950 1313
951 $_[1] 1314 $_[1]
952} 1315}
953 1316
1317sub update {
1318 my ($self) = @_;
1319
1320 delete $self->{texture};
1321 $self->SUPER::update;
1322}
1323
954sub set_text { 1324sub set_text {
955 my ($self, $text) = @_; 1325 my ($self, $text) = @_;
956 1326
1327 return if $self->{text} eq "T$text";
957 $self->{text} = $text; 1328 $self->{text} = "T$text";
1329
1330 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba;
958 $self->{layout}->set_markup ($text); 1331 $self->{layout}->set_text ($text);
959 1332
960 delete $self->{texture};
961# $self->{w} = $self->{h} = -1;
962 $self->update; 1333 $self->update;
1334 $self->check_size;
963} 1335}
964 1336
965sub get_text { 1337sub set_markup {
966 my ($self, $text) = @_; 1338 my ($self, $markup) = @_;
967 1339
968 $self->{text} 1340 return if $self->{text} eq "M$markup";
1341 $self->{text} = "M$markup";
1342
1343 my $rgba = $markup =~ /span.*(?:foreground|background)/;
1344
1345 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba;
1346 $self->{layout}->set_markup ($markup);
1347
1348 $self->update;
1349 $self->check_size;
969} 1350}
970 1351
971sub size_request { 1352sub size_request {
972 my ($self) = @_; 1353 my ($self) = @_;
973 1354
974 $self->{layout}->set_width; 1355 $self->{layout}->set_font ($self->{font}) if $self->{font};
1356 $self->{layout}->set_width ($self->{max_w} || -1);
975 $self->{layout}->set_height ($self->{fontsize}); 1357 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1358
976 my ($w, $h) = $self->{layout}->size; 1359 my ($w, $h) = $self->{layout}->size;
1360
1361 if (exists $self->{template}) {
1362 $self->{template}->set_font ($self->{font}) if $self->{font};
1363 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1364
1365 my ($w2, $h2) = $self->{template}->size;
1366
1367 $w = List::Util::max $w, $w2;
1368 $h = List::Util::max $h, $h2;
1369 }
977 1370
978 ( 1371 (
979 $w + $self->{padding} * 2, 1372 $w + $self->{padding} * 2,
980 $h + $self->{padding} * 2, 1373 $h + $self->{padding} * 2,
981 ) 1374 )
982} 1375}
983 1376
984sub size_allocate { 1377sub size_allocate {
985 my ($self, $x, $y, $w, $h) = @_; 1378 my ($self, $w, $h) = @_;
986
987 $self->_size_allocate ($x, $y, $w, $h) or return;
988 1379
989 delete $self->{texture}; 1380 delete $self->{texture};
990} 1381}
991 1382
992sub update { 1383sub set_fontsize {
993 my ($self) = @_; 1384 my ($self, $fontsize) = @_;
994 1385
1386 $self->{fontsize} = $fontsize;
995 delete $self->{texture}; 1387 delete $self->{texture};
1388
996 $self->SUPER::update; 1389 $self->update;
1390 $self->check_size;
997} 1391}
998 1392
999sub _draw { 1393sub _draw {
1000 my ($self) = @_; 1394 my ($self) = @_;
1001 1395
1002 my $tex = $self->{texture} ||= do { 1396 my $tex = $self->{texture} ||= do {
1397 $self->{layout}->set_foreground (@{$self->{fg}});
1398 $self->{layout}->set_font ($self->{font}) if $self->{font};
1003 $self->{layout}->set_width ($self->{w}); 1399 $self->{layout}->set_width ($self->{w});
1004 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); 1400 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1401
1005 new_from_layout CFClient::Texture $self->{layout} 1402 my $tex = new_from_layout CFClient::Texture $self->{layout};
1403
1404 $self->{ox} = int $self->{align} < 0 ? $self->{padding}
1405 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1406 : ($self->{w} - $tex->{w}) * 0.5;
1407
1408 $self->{oy} = int $self->{valign} < 0 ? $self->{padding}
1409 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1410 : ($self->{h} - $tex->{h}) * 0.5;
1411
1412 $tex
1006 }; 1413 };
1007 1414
1008 glEnable GL_BLEND;
1009 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1010 glEnable GL_TEXTURE_2D; 1415 glEnable GL_TEXTURE_2D;
1011 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1416 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1012 1417
1418 if ($tex->{format} == GL_ALPHA) {
1013 glColor @{$self->{fg}}; 1419 glColor @{$self->{fg}};
1014 1420 $tex->draw_quad_alpha ($self->{ox}, $self->{oy});
1015 my $x = 1421 } else {
1016 $self->{align} < 0 ? $self->{padding} 1422 $tex->draw_quad_alpha_premultiplied ($self->{ox}, $self->{oy});
1017 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1423 }
1018 : ($self->{w} - $tex->{w}) * 0.5;
1019
1020 $tex->draw_quad (int $x, int +($self->{h} - $tex->{h}) * 0.5);
1021 1424
1022 glDisable GL_TEXTURE_2D; 1425 glDisable GL_TEXTURE_2D;
1023 glDisable GL_BLEND;
1024} 1426}
1025 1427
1026############################################################################# 1428#############################################################################
1027 1429
1028package CFClient::UI::Entry; 1430package CFClient::UI::EntryBase;
1029 1431
1030our @ISA = CFClient::UI::Label::; 1432our @ISA = CFClient::UI::Label::;
1031 1433
1032use SDL; 1434use CFClient::OpenGL;
1033use SDL::OpenGL;
1034 1435
1035sub new { 1436sub new {
1036 my $class = shift; 1437 my $class = shift;
1037 1438
1038 $class->SUPER::new ( 1439 $class->SUPER::new (
1039 fg => [1, 1, 1], 1440 fg => [1, 1, 1],
1040 bg => [0, 0, 0, 0.2], 1441 bg => [0, 0, 0, 0.2],
1041 active_bg => [1, 1, 1, 0.5], 1442 active_bg => [1, 1, 1, 0.5],
1042 active_fg => [0, 0, 0], 1443 active_fg => [0, 0, 0],
1043 can_hover => 1, 1444 can_hover => 1,
1044 can_focus => 1, 1445 can_focus => 1,
1446 valign => 0,
1447 can_events => 1,
1045 @_ 1448 @_
1046 ) 1449 )
1047} 1450}
1048 1451
1049sub _set_text { 1452sub _set_text {
1050 my ($self, $text) = @_; 1453 my ($self, $text) = @_;
1051 1454
1052 my $old_text = $self->{text}; 1455 delete $self->{cur_h};
1456
1457 return if $self->{text} eq $text;
1458
1459 delete $self->{texture};
1053 1460
1054 $self->{last_activity} = $::NOW; 1461 $self->{last_activity} = $::NOW;
1055
1056 $self->{text} = $text; 1462 $self->{text} = $text;
1057 $self->{layout}->set_width ($self->{w});
1058 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize});
1059 1463
1060 $text =~ s/./*/g if $self->{hidden}; 1464 $text =~ s/./*/g if $self->{hidden};
1465 $self->{layout}->set_text ("$text ");
1061 1466
1062 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1467 $self->emit (changed => $self->{text});
1063
1064 $text = substr $text, 0, $self->{cursor};
1065 utf8::encode $text;
1066
1067 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
1068
1069 $self->emit (changed => $self->{text}) # XXX: is this the right place to do this?
1070 if $old_text ne $self->{text};
1071}
1072
1073sub size_request {
1074 my ($self) = @_;
1075
1076 my ($w, $h) = $self->SUPER::size_request;
1077
1078 ($w + 1, $h) # add 1 for cursor
1079}
1080
1081sub size_allocate {
1082 my ($self, $x, $y, $w, $h) = @_;
1083
1084 $self->SUPER::size_allocate ($x, $y, $w, $h);
1085
1086 $self->_set_text ($self->{text});
1087} 1468}
1088 1469
1089sub set_text { 1470sub set_text {
1090 my ($self, $text) = @_; 1471 my ($self, $text) = @_;
1091 1472
1092 $self->{cursor} = length $text; 1473 $self->{cursor} = length $text;
1093 $self->_set_text ($text); 1474 $self->_set_text ($text);
1475 $self->check_size;
1094 $self->update; 1476 $self->update;
1477}
1478
1479sub get_text {
1480 $_[0]{text}
1481}
1482
1483sub size_request {
1484 my ($self) = @_;
1485
1486 my ($w, $h) = $self->SUPER::size_request;
1487
1488 ($w + 1, $h) # add 1 for cursor
1489}
1490
1491sub size_allocate {
1492 my ($self, $w, $h) = @_;
1493
1494 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text
1095} 1495}
1096 1496
1097sub key_down { 1497sub key_down {
1098 my ($self, $ev) = @_; 1498 my ($self, $ev) = @_;
1099 1499
1100 my $mod = $ev->key_mod; 1500 my $mod = $ev->{mod};
1101 my $sym = $ev->key_sym; 1501 my $sym = $ev->{sym};
1102
1103 my $uni = $ev->key_unicode; 1502 my $uni = $ev->{unicode};
1104 1503
1105 my $text = $self->get_text; 1504 my $text = $self->get_text;
1106 1505
1107 if ($sym == SDLK_BACKSPACE) { 1506 if ($uni == 8) {
1108 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1507 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1109 } elsif ($sym == SDLK_DELETE) { 1508 } elsif ($uni == 127) {
1110 substr $text, $self->{cursor}, 1, ""; 1509 substr $text, $self->{cursor}, 1, "";
1111 } elsif ($sym == SDLK_LEFT) { 1510 } elsif ($sym == CFClient::SDLK_LEFT) {
1112 --$self->{cursor} if $self->{cursor}; 1511 --$self->{cursor} if $self->{cursor};
1113 } elsif ($sym == SDLK_RIGHT) { 1512 } elsif ($sym == CFClient::SDLK_RIGHT) {
1114 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1513 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1115 } elsif ($sym == SDLK_HOME) { 1514 } elsif ($sym == CFClient::SDLK_HOME) {
1116 $self->{cursor} = 0; 1515 $self->{cursor} = 0;
1117 } elsif ($sym == SDLK_END) { 1516 } elsif ($sym == CFClient::SDLK_END) {
1118 $self->{cursor} = length $text; 1517 $self->{cursor} = length $text;
1119 } elsif ($sym == SDLK_ESCAPE) { 1518 } elsif ($uni == 27) {
1120 $self->emit ('escape'); 1519 $self->emit ('escape');
1121 } elsif ($uni) { 1520 } elsif ($uni) {
1122 substr $text, $self->{cursor}++, 0, chr $uni; 1521 substr $text, $self->{cursor}++, 0, chr $uni;
1123 } 1522 }
1124 1523
1179 1578
1180 $self->SUPER::_draw; 1579 $self->SUPER::_draw;
1181 1580
1182 #TODO: force update every cursor change :( 1581 #TODO: force update every cursor change :(
1183 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { 1582 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) {
1583
1584 unless (exists $self->{cur_h}) {
1585 my $text = substr $self->{text}, 0, $self->{cursor};
1586 utf8::encode $text;
1587
1588 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text)
1589 }
1590
1184 glColor @{$self->{fg}}; 1591 glColor @{$self->{fg}};
1185 glBegin GL_LINES; 1592 glBegin GL_LINES;
1186 glVertex $self->{cur_x}, $self->{cur_y};
1187 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; 1593 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy};
1594 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
1188 glEnd; 1595 glEnd;
1189 } 1596 }
1190} 1597}
1191 1598
1192package CFClient::UI::LineEntry; 1599package CFClient::UI::Entry;
1193 1600
1194our @ISA = CFClient::UI::Entry::; 1601our @ISA = CFClient::UI::EntryBase::;
1195 1602
1196use SDL; 1603use CFClient::OpenGL;
1197use SDL::OpenGL;
1198 1604
1199sub key_down { 1605sub key_down {
1200 my ($self, $ev) = @_; 1606 my ($self, $ev) = @_;
1201 1607
1202 my $sym = $ev->key_sym; 1608 my $sym = $ev->{sym};
1203 1609
1204 if ($sym == SDLK_RETURN) { 1610 if ($sym == 13) {
1611 unshift @{$self->{history}},
1612 my $txt = $self->get_text;
1613 $self->{history_pointer} = -1;
1614 $self->{history_saveback} = '';
1205 $self->emit (activate => $self->get_text); 1615 $self->emit (activate => $txt);
1206 $self->update; 1616 $self->update;
1617
1618 } elsif ($sym == CFClient::SDLK_UP) {
1619 if ($self->{history_pointer} < 0) {
1620 $self->{history_saveback} = $self->get_text;
1621 }
1622 if (@{$self->{history} || []} > 0) {
1623 $self->{history_pointer}++;
1624 if ($self->{history_pointer} >= @{$self->{history} || []}) {
1625 $self->{history_pointer} = @{$self->{history} || []} - 1;
1626 }
1627 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1628 }
1629
1630 } elsif ($sym == CFClient::SDLK_DOWN) {
1631 $self->{history_pointer}--;
1632 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
1633
1634 if ($self->{history_pointer} >= 0) {
1635 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1636 } else {
1637 $self->set_text ($self->{history_saveback});
1638 }
1207 1639
1208 } else { 1640 } else {
1209 $self->SUPER::key_down ($ev); 1641 $self->SUPER::key_down ($ev);
1210 } 1642 }
1211 1643
1215 1647
1216package CFClient::UI::Button; 1648package CFClient::UI::Button;
1217 1649
1218our @ISA = CFClient::UI::Label::; 1650our @ISA = CFClient::UI::Label::;
1219 1651
1220use SDL; 1652use CFClient::OpenGL;
1221use SDL::OpenGL;
1222 1653
1223my @tex = 1654my @tex =
1224 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1655 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1225 qw(b1_button_active.png); 1656 qw(b1_button_active.png);
1226 1657
1227sub new { 1658sub new {
1228 my $class = shift; 1659 my $class = shift;
1229 1660
1230 $class->SUPER::new ( 1661 $class->SUPER::new (
1231 padding => 4, 1662 padding => 4,
1232 fg => [1, 1, 1], 1663 fg => [1, 1, 1],
1233 bg => [1, 1, 1, 0.2], 1664 bg => [1, 1, 1, 0.2],
1234 active_fg => [1, 1, 0], 1665 active_fg => [0, 0, 1],
1235 can_hover => 1, 1666 can_hover => 1,
1667 align => 0,
1668 valign => 0,
1669 can_events => 1,
1236 @_ 1670 @_
1237 ) 1671 )
1238} 1672}
1239 1673
1240sub button_up { 1674sub button_up {
1248 1682
1249sub _draw { 1683sub _draw {
1250 my ($self) = @_; 1684 my ($self) = @_;
1251 1685
1252 local $self->{fg} = $self->{fg}; 1686 local $self->{fg} = $self->{fg};
1253 my $tex = $tex[0];
1254
1255 glEnable GL_BLEND;
1256 glEnable GL_TEXTURE_2D;
1257 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1258 1687
1259 if ($GRAB == $self) { 1688 if ($GRAB == $self) {
1260 $self->{fg} = $self->{active_fg}; 1689 $self->{fg} = $self->{active_fg};
1261 } 1690 }
1262 1691
1263 glBindTexture GL_TEXTURE_2D, $tex->{name}; 1692 glEnable GL_TEXTURE_2D;
1264 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1693 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1694 glColor 0, 0, 0, 1;
1265 1695
1266 $tex->draw_quad (0, 0, $self->{w}, $self->{h}); 1696 $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
1267 1697
1268 glDisable GL_TEXTURE_2D; 1698 glDisable GL_TEXTURE_2D;
1269 glDisable GL_BLEND;
1270 1699
1271 $self->SUPER::_draw; 1700 $self->SUPER::_draw;
1272} 1701}
1273 1702
1274############################################################################# 1703#############################################################################
1276package CFClient::UI::CheckBox; 1705package CFClient::UI::CheckBox;
1277 1706
1278our @ISA = CFClient::UI::DrawBG::; 1707our @ISA = CFClient::UI::DrawBG::;
1279 1708
1280my @tex = 1709my @tex =
1281 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1710 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1282 qw(c1_checkbox_bg.png c1_checkbox_active.png); 1711 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1283 1712
1284use SDL; 1713use CFClient::OpenGL;
1285use SDL::OpenGL;
1286 1714
1287sub new { 1715sub new {
1288 my $class = shift; 1716 my $class = shift;
1289 1717
1290 $class->SUPER::new ( 1718 $class->SUPER::new (
1301 my ($self) = @_; 1729 my ($self) = @_;
1302 1730
1303 ($self->{padding} * 2 + 6) x 2 1731 ($self->{padding} * 2 + 6) x 2
1304} 1732}
1305 1733
1306sub size_allocate {
1307 my ($self, $x, $y, $w, $h) = @_;
1308
1309 $self->_size_allocate ($x, $y, $w, $h);
1310}
1311
1312sub button_down { 1734sub button_down {
1313 my ($self, $ev, $x, $y) = @_; 1735 my ($self, $ev, $x, $y) = @_;
1314 1736
1315 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} 1737 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding}
1316 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { 1738 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) {
1328 1750
1329 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; 1751 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2;
1330 1752
1331 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; 1753 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
1332 1754
1755 my $tex = $self->{state} ? $tex[1] : $tex[0];
1756
1757 glEnable GL_TEXTURE_2D;
1758 $tex->draw_quad_alpha (0, 0, $s, $s);
1759 glDisable GL_TEXTURE_2D;
1760}
1761
1762#############################################################################
1763
1764package CFClient::UI::Image;
1765
1766our @ISA = CFClient::UI::Base::;
1767
1768use CFClient::OpenGL;
1769use Carp qw/confess/;
1770
1771our %loaded_images;
1772
1773sub new {
1774 my $class = shift;
1775
1776 my $self = $class->SUPER::new (can_events => 0, @_);
1777
1778 $self->{image} or confess "Image has 'image' not set. This is a fatal error!";
1779
1780 $loaded_images{$self->{image}} ||=
1781 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1782
1783 my $tex = $self->{tex} = $loaded_images{$self->{image}};
1784
1785 Scalar::Util::weaken $loaded_images{$self->{image}};
1786
1787 $self->{aspect} = $tex->{w} / $tex->{h};
1788
1789 $self
1790}
1791
1792sub size_request {
1793 my ($self) = @_;
1794
1795 ($self->{tex}->{w}, $self->{tex}->{h})
1796}
1797
1798sub _draw {
1799 my ($self) = @_;
1800
1801 my $tex = $self->{tex};
1802
1803 my ($w, $h) = ($self->{w}, $self->{h});
1804
1805 if ($self->{rot90}) {
1806 glRotate 90, 0, 0, 1;
1807 glTranslate 0, -$self->{w}, 0;
1808
1809 ($w, $h) = ($h, $w);
1810 }
1811
1812 glEnable GL_TEXTURE_2D;
1813 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1814
1815 $tex->draw_quad_alpha (0, 0, $w, $h);
1816
1817 glDisable GL_TEXTURE_2D;
1818}
1819
1820#############################################################################
1821
1822package CFClient::UI::VGauge;
1823
1824our @ISA = CFClient::UI::Base::;
1825
1826use List::Util qw(min max);
1827
1828use CFClient::OpenGL;
1829
1830my %tex = (
1831 food => [
1832 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1833 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1834 ],
1835 grace => [
1836 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1837 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
1838 ],
1839 hp => [
1840 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1841 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1842 ],
1843 mana => [
1844 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1845 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
1846 ],
1847);
1848
1849# eg. VGauge->new (gauge => 'food'), default gauge: food
1850sub new {
1851 my $class = shift;
1852
1853 my $self = $class->SUPER::new (
1854 type => 'food',
1855 @_
1856 );
1857
1858 $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h};
1859
1860 $self
1861}
1862
1863sub size_request {
1864 my ($self) = @_;
1865
1866 #my $tex = $tex{$self->{type}}[0];
1867 #@$tex{qw(w h)}
1868 (0, 0)
1869}
1870
1871sub set_max {
1872 my ($self, $max) = @_;
1873
1874 return if $self->{max_val} == $max;
1875
1876 $self->{max_val} = $max;
1877 $self->update;
1878}
1879
1880sub set_value {
1881 my ($self, $val, $max) = @_;
1882
1883 $self->set_max ($max)
1884 if defined $max;
1885
1886 return if $self->{val} == $val;
1887
1888 $self->{val} = $val;
1889 $self->update;
1890}
1891
1892sub _draw {
1893 my ($self) = @_;
1894
1895 my $tex = $tex{$self->{type}};
1896 my ($t1, $t2, $t3) = @$tex;
1897
1898 my ($w, $h) = ($self->{w}, $self->{h});
1899
1900 if ($self->{vertical}) {
1901 glRotate 90, 0, 0, 1;
1902 glTranslate 0, -$self->{w}, 0;
1903
1904 ($w, $h) = ($h, $w);
1905 }
1906
1907 my $ycut = $self->{val} / ($self->{max_val} || 1);
1908
1909 my $ycut1 = max 0, min 1, $ycut;
1910 my $ycut2 = max 0, min 1, $ycut - 1;
1911
1912 my $h1 = $self->{h} * (1 - $ycut1);
1913 my $h2 = $self->{h} * (1 - $ycut2);
1914
1333 glEnable GL_BLEND; 1915 glEnable GL_BLEND;
1916 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1334 glEnable GL_TEXTURE_2D; 1917 glEnable GL_TEXTURE_2D;
1335 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1918 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1336 1919
1337 my $tex = $self->{state} ? $tex[1] : $tex[0]; 1920 glBindTexture GL_TEXTURE_2D, $t1->{name};
1921 glBegin GL_QUADS;
1922 glTexCoord 0 , 0; glVertex 0 , 0;
1923 glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1;
1924 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1;
1925 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1926 glEnd;
1338 1927
1339 $tex->draw_quad (0, 0, $s, $s); 1928 my $ycut1 = List::Util::min 1, $ycut;
1929 glBindTexture GL_TEXTURE_2D, $t2->{name};
1930 glBegin GL_QUADS;
1931 glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1;
1932 glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2;
1933 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2;
1934 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1;
1935 glEnd;
1340 1936
1937 if ($t3) {
1938 glBindTexture GL_TEXTURE_2D, $t3->{name};
1939 glBegin GL_QUADS;
1940 glTexCoord 0 , $t3->{t} * (1 - $ycut2); glVertex 0 , $h2;
1941 glTexCoord 0 , $t3->{t}; glVertex 0 , $self->{h};
1942 glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $self->{h};
1943 glTexCoord $t3->{s}, $t3->{t} * (1 - $ycut2); glVertex $w, $h2;
1944 glEnd;
1945 }
1946
1947 glDisable GL_BLEND;
1341 glDisable GL_TEXTURE_2D; 1948 glDisable GL_TEXTURE_2D;
1342 glDisable GL_BLEND; 1949}
1950
1951#############################################################################
1952
1953package CFClient::UI::Gauge;
1954
1955our @ISA = CFClient::UI::VBox::;
1956
1957sub new {
1958 my ($class, %arg) = @_;
1959
1960 my $self = $class->SUPER::new (
1961 tooltip => $arg{type},
1962 can_hover => 1,
1963 can_events => 1,
1964 %arg,
1965 );
1966
1967 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999");
1968 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
1969 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999");
1970
1971 $self
1972}
1973
1974sub set_fontsize {
1975 my ($self, $fsize) = @_;
1976
1977 $self->{value}->set_fontsize ($fsize);
1978 $self->{max} ->set_fontsize ($fsize);
1979}
1980
1981sub set_max {
1982 my ($self, $max) = @_;
1983
1984 $self->{gauge}->set_max ($max);
1985 $self->{max}->set_text ($max);
1986}
1987
1988sub set_value {
1989 my ($self, $val, $max) = @_;
1990
1991 $self->set_max ($max)
1992 if defined $max;
1993
1994 $self->{gauge}->set_value ($val, $max);
1995 $self->{value}->set_text ($val);
1343} 1996}
1344 1997
1345############################################################################# 1998#############################################################################
1346 1999
1347package CFClient::UI::Slider; 2000package CFClient::UI::Slider;
1348 2001
1349use strict; 2002use strict;
1350 2003
1351use SDL::OpenGL; 2004use CFClient::OpenGL;
1352 2005
1353our @ISA = CFClient::UI::DrawBG::; 2006our @ISA = CFClient::UI::DrawBG::;
1354 2007
1355my @tex = 2008my @tex =
1356 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 2009 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1357 qw(s1_slider.png s1_slider_bg.png); 2010 qw(s1_slider.png s1_slider_bg.png);
1358 2011
1359sub new { 2012sub new {
1360 my $class = shift; 2013 my $class = shift;
1361 2014
1362 # range [value, low, high, page] 2015 # range [value, low, high, page, unit]
1363 2016
1364 # TODO: 0-width page 2017 # TODO: 0-width page
1365 # TODO: req_w/h are wrong with vertical 2018 # TODO: req_w/h are wrong with vertical
1366 # TODO: calculations are off 2019 # TODO: calculations are off
1367 my $self = $class->SUPER::new ( 2020 my $self = $class->SUPER::new (
1368 fg => [1, 1, 1], 2021 fg => [1, 1, 1],
1369 active_fg => [0, 0, 0], 2022 active_fg => [0, 0, 0],
1370 range => [0, 0, 100, 10], 2023 range => [0, 0, 100, 10],
1371 req_w => 40, 2024 req_w => $::WIDTH / 80,
1372 req_h => 13, 2025 req_h => $::WIDTH / 80,
1373 vertical => 0, 2026 vertical => 0,
1374 can_hover => 1, 2027 can_hover => 1,
1375 inner_pad => 5, 2028 inner_pad => .05,
1376 @_ 2029 @_
1377 ); 2030 );
1378 2031
2032 $self->set_value ($self->{range}[0]);
2033 $self->update;
2034
1379 $self 2035 $self
2036}
2037
2038sub set_value {
2039 my ($self, $value) = @_;
2040
2041 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}};
2042
2043 $hi = $lo + 1 if $hi <= $lo;
2044
2045 $value = $lo if $value < $lo;
2046 $value = $hi if $value > $hi;
2047
2048 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit
2049 if $unit;
2050
2051 $page = $hi - $lo if $page > $hi - $lo;
2052
2053 @{$self->{range}} = ($value, $lo, $hi, $page, $unit);
2054
2055 if ($value != $old_value) {
2056 $self->emit (changed => $value);
2057 $self->update;
2058 }
1380} 2059}
1381 2060
1382sub size_request { 2061sub size_request {
1383 my ($self) = @_; 2062 my ($self) = @_;
1384 2063
1397 2076
1398sub mouse_motion { 2077sub mouse_motion {
1399 my ($self, $ev, $x, $y) = @_; 2078 my ($self, $ev, $x, $y) = @_;
1400 2079
1401 if ($GRAB == $self) { 2080 if ($GRAB == $self) {
2081 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w});
2082
2083 my (undef, $lo, $hi, $page) = @{$self->{range}};
2084
2085 $x = $x / ($w * (1 - 2 * $self->{inner_pad})) - $self->{inner_pad};
2086
2087 $self->set_value ($x * ($hi - $lo) + $lo);
2088 }
2089}
2090
2091sub update {
2092 my ($self) = @_;
2093
2094 $CFClient::UI::ROOT->on_post_alloc ($self => sub {
2095 $self->set_value ($self->{range}[0]);
2096
1402 my ($value, $lo, $hi, $page) = @{$self->{range}}; 2097 my ($value, $lo, $hi, $page) = @{$self->{range}};
1403 2098
1404 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); 2099 my $inner_w = 1 - 2 * $self->{inner_pad};
1405 2100
1406 my $inner_pad_px = $self->_calc_inner_pad_px ($w); 2101 $self->{scale} = ($inner_w / ($hi - $lo)) || 1;
1407 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
1408 2102
1409 $x -= $inner_pad_px; # substract the padding 2103 $page = $self->{scale} * $page || 10 / ($self->{w} || 1);
1410 $x = $x * ($hi - $lo) / $inner_w + $lo; 2104 $value = $self->{scale} * ($value - $lo);
1411 $x = $lo if $x < $lo;
1412 $x = $hi - $page if $x > $hi - $page;
1413 $self->{range}[0] = $x;
1414 2105
1415 $self->emit (changed => $x); 2106 $value = $self->{inner_pad} + ($value - $page * 0.5);
1416 $self->update; 2107
2108 $value = 0 if $value < 0;
2109 $page = 1 - $value if $value + $page > 1;
2110
2111 $self->{knob_x} = $value;
2112 $self->{knob_w} = $page;
1417 } 2113 });
1418}
1419 2114
1420# the inner_* stuff is for generating a padding for the slider handle, 2115 $self->SUPER::update;
1421# so that the handle doesn't leave the texture. This calculation isn't 100%
1422# correct propably, but it does the job for now
1423sub _calc_inner_pad_px {
1424 my ($self, $w) = @_;
1425 ($w / 100) * $self->{inner_pad} # % to pixels
1426} 2116}
1427 2117
1428sub _draw { 2118sub _draw {
1429 my ($self) = @_; 2119 my ($self) = @_;
1430 2120
1431 $self->SUPER::_draw (); 2121 $self->SUPER::_draw ();
1432 2122
1433 my ($w, $h) = @$self{qw(w h)}; 2123 glScale $self->{w}, $self->{h};
1434 2124
1435 if ($self->{vertical}) { 2125 if ($self->{vertical}) {
1436 # draw a vertical slider like a rotated horizontal slider 2126 # draw a vertical slider like a rotated horizontal slider
1437 2127
1438 glRotate 90, 0, 0, 1; 2128 glRotate 90, 0, 0, 1;
1439 glTranslate 0, -$self->{w}, 0; 2129 glTranslate 0, 1, 0;
1440
1441 ($w, $h) = ($h, $w);
1442 } 2130 }
1443 2131
1444 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 2132 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
1445 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 2133 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
1446 2134
1447 my ($value, $lo, $hi, $page) = @{$self->{range}};
1448
1449 $hi = $value + 1 if $lo == $hi;
1450
1451 my $inner_pad_px = $self->_calc_inner_pad_px ($w);
1452 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
1453
1454 $page = int $page * $inner_w / ($hi - $lo);
1455 $value = int +($value - $lo) * $inner_w / ($hi - $lo);
1456
1457 $w -= $page;
1458 $page &= ~1;
1459 glTranslate $page * 0.5, 0, 0;
1460 $page ||= 2;
1461
1462 my $knob_a = $inner_pad_px + ($value - $page * 0.5);
1463 my $knob_b = $inner_pad_px + ($value + $page * 0.5);
1464
1465 glEnable GL_BLEND;
1466 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1467 glEnable GL_TEXTURE_2D; 2135 glEnable GL_TEXTURE_2D;
1468 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2136 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1469 2137
1470 # draw background 2138 # draw background
1471 $tex[1]->draw_quad (0, 0, $w, $h); 2139 $tex[1]->draw_quad_alpha (0, 0, 1, 1);
1472 2140
1473 # draw handle 2141 # draw handle
1474 $tex[0]->draw_quad ($knob_a, 0, $knob_b - $knob_a, $h); 2142 $tex[0]->draw_quad_alpha ($self->{knob_x}, 0, $self->{knob_w}, 1);
1475 2143
1476 glDisable GL_BLEND;
1477 glDisable GL_TEXTURE_2D; 2144 glDisable GL_TEXTURE_2D;
1478} 2145}
1479 2146
1480############################################################################# 2147#############################################################################
1481 2148
1482package CFClient::UI::TextView; 2149package CFClient::UI::TextView;
1483 2150
1484our @ISA = CFClient::UI::HBox::; 2151our @ISA = CFClient::UI::HBox::;
1485 2152
1486use SDL::OpenGL; 2153use CFClient::OpenGL;
1487 2154
1488sub new { 2155sub new {
1489 my $class = shift; 2156 my $class = shift;
1490 2157
1491 my $self = $class->SUPER::new ( 2158 my $self = $class->SUPER::new (
1492 req_w => $::WIDTH / 6, 2159 fontsize => 1,
1493 req_h => $::HEIGHT / 6, 2160 can_events => 0,
1494 fontsize => $::FONTSIZE, 2161 #font => default_font
1495 @_, 2162 @_,
1496 2163
1497 layout => (new CFClient::Layout), 2164 layout => (new CFClient::Layout 1),
1498 par => [], 2165 par => [],
1499 height => 0, 2166 height => 0,
1500 children => [ 2167 children => [
1501 (new CFClient::UI::Empty expand => 1), 2168 (new CFClient::UI::Empty expand => 1),
1502 (new CFClient::UI::Slider vertical => 1), 2169 (new CFClient::UI::Slider vertical => 1),
1503 ], 2170 ],
1504 ); 2171 );
1505 2172
1506 $self->{children}[1]->connect (changed => sub { 2173 $self->{children}[1]->connect (changed => sub { $self->update });
1507 $self->update;
1508 });
1509 2174
1510 $self 2175 $self
1511} 2176}
1512 2177
1513sub set_fontsize { 2178sub set_fontsize {
1520sub text_height { 2185sub text_height {
1521 my ($self, $text) = @_; 2186 my ($self, $text) = @_;
1522 2187
1523 my $layout = $self->{layout}; 2188 my $layout = $self->{layout};
1524 2189
1525 $layout->set_height ($self->{fontsize}); 2190 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
1526 $layout->set_width ($self->{w}); 2191 $layout->set_width ($self->{children}[0]{w});
1527 $layout->set_text ($text); 2192 $layout->set_markup ($text);
1528 2193
1529 ($layout->size)[1] 2194 ($layout->size)[1]
1530} 2195}
1531 2196
1532sub reflow { 2197sub reflow {
1534 2199
1535 $self->{need_reflow}++; 2200 $self->{need_reflow}++;
1536 $self->update; 2201 $self->update;
1537} 2202}
1538 2203
1539sub size_request {
1540 my ($self) = @_;
1541
1542 ($self->{req_w}, $self->{req_h})
1543}
1544
1545sub size_allocate { 2204sub size_allocate {
1546 my ($self, $x, $y, $w, $h) = @_; 2205 my ($self, $w, $h) = @_;
1547 2206
1548 $self->SUPER::size_allocate ($x, $y, $w, $h); 2207 $self->SUPER::size_allocate ($w, $h);
1549 2208
2209 $self->{layout}->set_font ($self->{font}) if $self->{font};
1550 $self->{layout}->set_height ($self->{fontsize}); 2210 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1551 $self->{layout}->set_width ($self->{w}); 2211 $self->{layout}->set_width ($self->{children}[0]{w});
1552 2212
1553 $self->reflow; 2213 $self->reflow;
1554} 2214}
1555 2215
1556sub add_paragraph { 2216sub add_paragraph {
1575 2235
1576 return unless $self->{h} > 0; 2236 return unless $self->{h} > 0;
1577 2237
1578 delete $self->{texture}; 2238 delete $self->{texture};
1579 2239
1580 $TOPLEVEL->on_refresh ($self, sub { 2240 $ROOT->on_post_alloc ($self, sub {
1581 if (delete $self->{need_reflow}) { 2241 if (delete $self->{need_reflow}) {
1582 my $height = 0; 2242 my $height = 0;
1583 2243
1584 $height += $_->[0] = $self->text_height ($_->[2]) 2244 $height += $_->[0] = $self->text_height ($_->[2])
1585 for @{$self->{par}}; 2245 for @{$self->{par}};
1589 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}]; 2249 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
1590 2250
1591 delete $self->{texture}; 2251 delete $self->{texture};
1592 } 2252 }
1593 2253
1594 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { 2254 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{children}[0]{w}, $self->{children}[0]{h}, sub {
1595 glClearColor 0, 0, 0, 1; 2255 glClearColor 0, 0, 0, 0;
1596 glClear GL_COLOR_BUFFER_BIT; 2256 glClear GL_COLOR_BUFFER_BIT;
1597 2257
1598 glEnable GL_BLEND;
1599 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1600 glEnable GL_TEXTURE_2D; 2258 glEnable GL_TEXTURE_2D;
1601 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2259 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1602 2260
1603 my $top = int $self->{children}[1]{range}[0]; 2261 my $top = int $self->{children}[1]{range}[0];
1604 2262
1607 2265
1608 my $y = 0; 2266 my $y = 0;
1609 2267
1610 my $layout = $self->{layout}; 2268 my $layout = $self->{layout};
1611 2269
2270 $layout->set_font ($self->{font}) if $self->{font};
2271
1612 for my $par (@{$self->{par}}) { 2272 for my $par (@{$self->{par}}) {
1613 my $h = $par->[0]; 2273 my $h = $par->[0];
1614 2274
1615 if ($y0 < $y + $h && $y < $y1) { 2275 if ($y0 < $y + $h && $y < $y1) {
2276 $layout->set_foreground (@{ $par->[1] });
1616 $layout->set_text ($par->[2]); 2277 $layout->set_markup ($par->[2]);
1617 2278
1618 glColor @{ $par->[1] };
1619 my ($W, $H) = $layout->size; 2279 my ($W, $H) = $layout->size;
1620 CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0); 2280 CFClient::Texture->new_from_layout ($layout)->draw_quad_alpha_premultiplied (0, $y - $y0);
1621 } 2281 }
1622 2282
1623 $y += $h; 2283 $y += $h;
1624 } 2284 }
1625 2285
1626 glDisable GL_TEXTURE_2D; 2286 glDisable GL_TEXTURE_2D;
1627 glDisable GL_BLEND;
1628 }; 2287 };
1629 }); 2288 });
1630} 2289}
1631 2290
1632sub _draw { 2291sub _draw {
1633 my ($self) = @_; 2292 my ($self) = @_;
1634 2293
1635 if ($self->{texture}) {
1636 glEnable GL_TEXTURE_2D; 2294 glEnable GL_TEXTURE_2D;
1637 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2295 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1638 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); 2296 glColor 1, 1, 1, 1;
2297 $self->{texture}->draw_quad_alpha_premultiplied (0, 0, $self->{children}[0]{w}, $self->{children}[0]{h});
1639 glDisable GL_TEXTURE_2D; 2298 glDisable GL_TEXTURE_2D;
1640 }
1641 2299
1642 $self->{children}[1]->draw; 2300 $self->{children}[1]->draw;
1643 2301
1644} 2302}
1645 2303
1646############################################################################# 2304#############################################################################
1647 2305
1648package CFClient::UI::MapWidget;
1649
1650use strict;
1651
1652use List::Util qw(min max);
1653
1654use SDL;
1655use SDL::OpenGL;
1656
1657our @ISA = CFClient::UI::Base::;
1658
1659sub new {
1660 my $class = shift;
1661
1662 $class->SUPER::new (
1663 z => -1,
1664 can_focus => 1,
1665 list => (glGenLists 1),
1666 @_
1667 )
1668}
1669
1670sub key_down {
1671 print "MAPKEYDOWN\n";
1672}
1673
1674sub key_up {
1675}
1676
1677sub button_down {
1678 my ($self, $ev, $x, $y) = @_;
1679
1680 $self->focus_in;
1681
1682 if ($ev->button == 2) {
1683 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
1684 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
1685
1686 $self->{motion} = sub {
1687 my ($ev, $x, $y) = @_;
1688
1689 ($x, $y) = ($ev->motion_x, $ev->motion_y);
1690
1691 $::CFG->{map_shift_x} = $bw + $x - $ox;
1692 $::CFG->{map_shift_y} = $bh + $y - $oy;
1693
1694 $self->update;
1695 };
1696 }
1697}
1698
1699sub button_up {
1700 my ($self, $ev, $x, $y) = @_;
1701
1702 delete $self->{motion};
1703}
1704
1705sub mouse_motion {
1706 my ($self, $ev, $x, $y) = @_;
1707
1708 $self->{motion}->($ev, $x, $y) if $self->{motion};
1709}
1710
1711sub size_request {
1712 (
1713 1 + 32 * int $::WIDTH / 32,
1714 1 + 32 * int $::HEIGHT / 32,
1715 )
1716}
1717
1718sub update {
1719 my ($self) = @_;
1720
1721 $self->{need_update} = 1;
1722 $self->SUPER::update;
1723}
1724
1725sub draw {
1726 my ($self) = @_;
1727
1728 if (delete $self->{need_update}) {
1729 glNewList $self->{list}, GL_COMPILE;
1730
1731 if ($::MAP) {
1732 my $sw = int $::WIDTH / 32;
1733 my $sh = int $::HEIGHT / 32;
1734
1735 my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
1736 my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
1737
1738 glTranslate $sx0 - 32, $sy0 - 32, 0;
1739
1740 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
1741
1742 if ($::CFG->{fow_enable}) {
1743 if ($::CFG->{fow_smooth}) { # smooth fog of war
1744 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER;
1745 glConvolutionFilter2D
1746 GL_CONVOLUTION_2D,
1747 GL_ALPHA,
1748 3, 3,
1749 GL_ALPHA, GL_FLOAT,
1750 pack "f*",
1751 0.1, 0.1, 0.1,
1752 0.1, 0.2, 0.1,
1753 0.1, 0.1, 0.1,
1754 ;
1755 glEnable GL_CONVOLUTION_2D;
1756 }
1757
1758 my $tex = new CFClient::Texture
1759 w => $w,
1760 h => $h,
1761 data => $data,
1762 internalformat => GL_ALPHA,
1763 format => GL_ALPHA;
1764
1765 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
1766
1767 glEnable GL_BLEND;
1768 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1769 glEnable GL_TEXTURE_2D;
1770 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1771
1772 glColor +($::CFG->{fow_intensity}) x 3, 1;
1773 $tex->draw_quad (0, 0, $w * 32, $h * 32);
1774
1775 glDisable GL_TEXTURE_2D;
1776 glDisable GL_BLEND;
1777 }
1778
1779 # HACK BEGIN
1780 {
1781 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove
1782 my ($w, $h) = (250, 250);
1783
1784 glEnable GL_BLEND;
1785 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1786 glEnable GL_TEXTURE_2D;
1787 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1788
1789 CFClient::Texture->new (
1790 w => $w,
1791 h => $h,
1792 data => $::MAP->mapmap ($w, $h),
1793 type => GL_UNSIGNED_INT_8_8_8_8_REV
1794 )->draw_quad (100, 100);
1795
1796 glDisable GL_TEXTURE_2D;
1797 glDisable GL_BLEND;
1798 }
1799 # HACK END
1800 }
1801
1802 glEndList;
1803 }
1804
1805 glPushMatrix;
1806 glCallList $self->{list};
1807 glPopMatrix;
1808
1809 if ($FOCUS != $self) {
1810 glColor 64/255, 64/255, 64/255;
1811 glLogicOp GL_AND;
1812 glEnable GL_COLOR_LOGIC_OP;
1813 glBegin GL_QUADS;
1814 glVertex 0, 0;
1815 glVertex 0, $::HEIGHT;
1816 glVertex $::WIDTH, $::HEIGHT;
1817 glVertex $::WIDTH, 0;
1818 glEnd;
1819 glDisable GL_COLOR_LOGIC_OP;
1820 }
1821}
1822
1823my %DIR = (
1824 SDLK_KP8, [1, "north"],
1825 SDLK_KP9, [2, "northeast"],
1826 SDLK_KP6, [3, "east"],
1827 SDLK_KP3, [4, "southeast"],
1828 SDLK_KP2, [5, "south"],
1829 SDLK_KP1, [6, "southwest"],
1830 SDLK_KP4, [7, "west"],
1831 SDLK_KP7, [8, "northwest"],
1832
1833 SDLK_UP, [1, "north"],
1834 SDLK_RIGHT, [3, "east"],
1835 SDLK_DOWN, [5, "south"],
1836 SDLK_LEFT, [7, "west"],
1837);
1838
1839sub key_down {
1840 my ($self, $ev) = @_;
1841
1842 my $mod = $ev->key_mod;
1843 my $sym = $ev->key_sym;
1844
1845 if ($sym == SDLK_KP5) {
1846 $::CONN->user_send ("command stay fire");
1847 } elsif ($sym == SDLK_a) {
1848 $::CONN->user_send ("command apply");
1849 } elsif ($sym == SDLK_QUOTE) {
1850 $self->emit ('activate_console');
1851 } elsif ($sym == SDLK_SLASH) {
1852 $self->emit ('activate_console' => '/');
1853 } elsif (exists $DIR{$sym}) {
1854 if ($mod & KMOD_SHIFT) {
1855 $self->{shft}++;
1856 $::CONN->user_send ("command fire $DIR{$sym}[0]");
1857 } elsif ($mod & KMOD_CTRL) {
1858 $self->{ctrl}++;
1859 $::CONN->user_send ("command run $DIR{$sym}[0]");
1860 } else {
1861 $::CONN->user_send ("command $DIR{$sym}[1]");
1862 }
1863 }
1864}
1865
1866sub key_up {
1867 my ($self, $ev) = @_;
1868
1869 my $mod = $ev->key_mod;
1870 my $sym = $ev->key_sym;
1871
1872 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
1873 $::CONN->user_send ("command fire_stop");
1874 }
1875 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
1876 $::CONN->user_send ("command run_stop");
1877 }
1878}
1879
1880#############################################################################
1881
1882package CFClient::UI::Animator; 2306package CFClient::UI::Animator;
1883 2307
1884use SDL::OpenGL; 2308use CFClient::OpenGL;
1885 2309
1886our @ISA = CFClient::UI::Bin::; 2310our @ISA = CFClient::UI::Bin::;
1887 2311
1888sub moveto { 2312sub moveto {
1889 my ($self, $x, $y) = @_; 2313 my ($self, $x, $y) = @_;
1927 2351
1928sub new { 2352sub new {
1929 my $class = shift; 2353 my $class = shift;
1930 2354
1931 my $self = $class->SUPER::new ( 2355 my $self = $class->SUPER::new (
1932 state => 0, 2356 state => 0,
1933 connect_activate => \&toggle_flopper, 2357 connect_activate => \&toggle_flopper,
1934 @_ 2358 @_
1935 ); 2359 );
1936 2360
1937 if ($self->{state}) { 2361 if ($self->{state}) {
1945sub toggle_flopper { 2369sub toggle_flopper {
1946 my ($self) = @_; 2370 my ($self) = @_;
1947 2371
1948 # TODO: use animation 2372 # TODO: use animation
1949 if ($self->{state} = !$self->{state}) { 2373 if ($self->{state} = !$self->{state}) {
1950 $CFClient::UI::TOPLEVEL->add ($self->{other}); 2374 $CFClient::UI::ROOT->add ($self->{other});
1951 $self->{other}->move ( 2375 $self->{other}->move ($self->coord2global (0, $self->{h}));
1952 ($::WIDTH - $self->{other}{w}) * 0.5, 2376 $self->emit ("open");
1953 ($::HEIGHT - $self->{other}{h}) * 0.5,
1954 );
1955 } else { 2377 } else {
1956 $CFClient::UI::TOPLEVEL->remove ($self->{other}); 2378 $CFClient::UI::ROOT->remove ($self->{other});
2379 $self->emit ("close");
2380 }
2381
2382 $self->emit (changed => $self->{state});
2383}
2384
2385#############################################################################
2386
2387package CFClient::UI::Tooltip;
2388
2389our @ISA = CFClient::UI::Bin::;
2390
2391use CFClient::OpenGL;
2392
2393sub new {
2394 my $class = shift;
2395
2396 $class->SUPER::new (
2397 @_,
2398 can_events => 0,
2399 )
2400}
2401
2402sub set_tooltip_from {
2403 my ($self, $widget) = @_;
2404
2405 $self->add (new CFClient::UI::Label
2406 markup => $widget->{tooltip},
2407 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2408 fontsize => 0.8,
2409 fg => [0, 0, 0, 1],
2410 font => ($widget->{tooltip_font} || $::FONT_PROP),
2411 );
2412}
2413
2414sub size_request {
2415 my ($self) = @_;
2416
2417 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2418
2419 ($w + 4, $h + 4)
2420}
2421
2422sub size_allocate {
2423 my ($self, $w, $h) = @_;
2424
2425 $self->SUPER::size_allocate ($w - 4, $h - 4);
2426}
2427
2428sub _draw {
2429 my ($self) = @_;
2430
2431 glTranslate 0.375, 0.375;
2432
2433 my ($w, $h) = @$self{qw(w h)};
2434
2435 glColor 1, 0.8, 0.4;
2436 glBegin GL_QUADS;
2437 glVertex 0 , 0;
2438 glVertex 0 , $h;
2439 glVertex $w, $h;
2440 glVertex $w, 0;
2441 glEnd;
1957 } 2442
2443 glColor 0, 0, 0;
2444 glBegin GL_LINE_LOOP;
2445 glVertex 0 , 0;
2446 glVertex 0 , $h;
2447 glVertex $w, $h;
2448 glVertex $w, 0;
2449 glEnd;
2450
2451 glTranslate 2 - 0.375, 2 - 0.375;
2452 $self->SUPER::_draw;
1958} 2453}
1959 2454
1960############################################################################# 2455#############################################################################
1961 2456
1962package CFClient::UI::Toplevel; 2457package CFClient::UI::Face;
2458
2459our @ISA = CFClient::UI::Base::;
2460
2461use CFClient::OpenGL;
2462
2463sub new {
2464 my $class = shift;
2465
2466 $class->SUPER::new (
2467 aspect => 1,
2468 @_,
2469 )
2470}
2471
2472sub size_request {
2473 (32, 8)
2474}
2475
2476sub _draw {
2477 my ($self) = @_;
2478
2479 return unless $::CONN;#d# manage and cache textures differently
2480 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]];
2481
2482 # TODO animation
2483 if ($tex) {
2484 glEnable GL_TEXTURE_2D;
2485 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2486 glColor 1, 1, 1, 1;
2487 $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h});
2488 glDisable GL_TEXTURE_2D;
2489 }
2490}
2491
2492#############################################################################
2493
2494package CFClient::UI::InventoryItem;
2495
2496our @ISA = CFClient::UI::HBox::;
2497
2498sub new {
2499 my $class = shift;
2500
2501 my %args = @_;
2502
2503 my $item = delete $args{item};
2504
2505 my $desc = $item->{nrof} < 2
2506 ? $item->{name}
2507 : "$item->{nrof} $item->{name_pl}";
2508
2509 $item->{flags} & Crossfire::Protocol::F_OPEN
2510 and $desc .= " (open)";
2511 $item->{flags} & Crossfire::Protocol::F_APPLIED
2512 and $desc .= " (applied)";
2513 $item->{flags} & Crossfire::Protocol::F_UNPAID
2514 and $desc .= " (unpaid)";
2515 $item->{flags} & Crossfire::Protocol::F_MAGIC
2516 and $desc .= " (magic)";
2517 $item->{flags} & Crossfire::Protocol::F_CURSED
2518 and $desc .= " (cursed)";
2519 $item->{flags} & Crossfire::Protocol::F_DAMNED
2520 and $desc .= " (damned)";
2521 $item->{flags} & Crossfire::Protocol::F_LOCKED
2522 and $desc .= " *";
2523
2524 my $self = $class->SUPER::new (
2525 can_hover => 1,
2526 can_events => 1,
2527 tooltip => (CFClient::UI::Label->escape ($desc)
2528 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
2529 connect_button_down => sub {
2530 my ($self, $ev, $x, $y) = @_;
2531
2532 # todo: maybe put examine on 1? but should just be a tooltip :(
2533 if ($ev->{button} == 1) {
2534 $::CONN->send ("move $::CONN->{player}{tag} $item->{tag} 0");
2535 } elsif ($ev->{button} == 2) {
2536 $::CONN->send ("apply $item->{tag}");
2537 } elsif ($ev->{button} == 3) {
2538 my @menu_items = (
2539 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2540 ["mark", sub { $::CONN->send ("mark $item->{tag}") }],
2541 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2542 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2543 [
2544 $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
2545 sub { $::CONN->send ("lock ". () ."$item->{tag}") },
2546 ],
2547 );
2548
2549 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2550 }
2551
2552 1
2553 },
2554 %args
2555 );
2556
2557 $self->add (new CFClient::UI::Face
2558 can_events => 0,
2559 face => $item->{face},
2560 anim => $item->{anim},
2561 animspeed => $item->{animspeed},
2562 );
2563
2564 $self->add (new CFClient::UI::Label
2565 can_events => 0,
2566 text => $desc,
2567 );
2568
2569 $self
2570}
2571
2572#############################################################################
2573
2574package CFClient::UI::Inventory;
2575
2576our @ISA = CFClient::UI::ScrolledWindow::;
2577
2578sub new {
2579 my $class = shift;
2580
2581 my $self = $class->SUPER::new (
2582 scrolled => (new CFClient::UI::VBox),
2583 @_,
2584 );
2585
2586 $self
2587}
2588
2589sub set_items {
2590 my ($self, $items) = @_;
2591
2592 $self->{scrolled}->clear;
2593 return unless $items;
2594
2595 my @items = sort {
2596 ($a->{type} <=> $b->{type})
2597 or ($a->{name} cmp $b->{name})
2598 } @$items;
2599
2600 $self->{real_items} = \@items;
2601
2602 for my $item (@items) {
2603 my $desc = $item->{nrof} < 2
2604 ? $item->{name}
2605 : "$item->{nrof} $item->{name_pl}";
2606
2607 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2608 }
2609
2610 $self->{scrolled}->add (@items);
2611
2612# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page];
2613}
2614
2615sub size_request {
2616 my ($self) = @_;
2617 ($self->{req_w}, $self->{req_h});
2618}
2619
2620#############################################################################
2621
2622package CFClient::UI::Menu;
2623
2624our @ISA = CFClient::UI::FancyFrame::;
2625
2626use CFClient::OpenGL;
2627
2628sub new {
2629 my $class = shift;
2630
2631 my $self = $class->SUPER::new (
2632 items => [],
2633 z => 100,
2634 @_,
2635 );
2636
2637 $self->add ($self->{vbox} = new CFClient::UI::VBox);
2638
2639 for my $item (@{ $self->{items} }) {
2640 my ($widget, $cb) = @$item;
2641
2642 # handle various types of items, only text for now
2643 if (!ref $widget) {
2644 $widget = new CFClient::UI::Label
2645 can_hover => 1,
2646 can_events => 1,
2647 text => $widget;
2648 }
2649
2650 $self->{item}{$widget} = $item;
2651
2652 $self->{vbox}->add ($widget);
2653 }
2654
2655 $self
2656}
2657
2658# popup given the event (must be a mouse button down event currently)
2659sub popup {
2660 my ($self, $ev) = @_;
2661
2662 $self->emit ("popdown");
2663
2664 # maybe save $GRAB? must be careful about events...
2665 $GRAB = $self;
2666 $self->{button} = $ev->{button};
2667
2668 $self->show;
2669 $self->move ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5);
2670}
2671
2672sub mouse_motion {
2673 my ($self, $ev, $x, $y) = @_;
2674
2675 # TODO: should use vbox->find_widget or so
2676 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y});
2677 $self->{hover} = $self->{item}{$HOVER};
2678}
2679
2680sub button_up {
2681 my ($self, $ev, $x, $y) = @_;
2682
2683 if ($ev->{button} == $self->{button}) {
2684 undef $GRAB;
2685 $self->hide;
2686
2687 $self->emit ("popdown");
2688 $self->{hover}[1]->() if $self->{hover};
2689 }
2690}
2691
2692#############################################################################
2693
2694package CFClient::UI::Statusbox;
2695
2696our @ISA = CFClient::UI::VBox::;
2697
2698sub reorder {
2699 my ($self) = @_;
2700 my $NOW = time;
2701
2702 while (my ($k, $v) = each %{ $self->{item} }) {
2703 delete $self->{item}{$k} if $v->{timeout} < $NOW;
2704 }
2705
2706 my @widgets;
2707
2708 my @items = sort {
2709 $a->{pri} <=> $b->{pri}
2710 or $b->{id} <=> $a->{id}
2711 } values %{ $self->{item} };
2712
2713 my $count = 10 + 1;
2714 for my $item (@items) {
2715 last unless --$count;
2716
2717 push @widgets, $item->{label} ||= do {
2718 # TODO: doesn't handle markup well (read as: at all)
2719 my $short = $item->{count} > 1
2720 ? "<b>$item->{count} ×</b> $item->{text}"
2721 : $item->{text};
2722
2723 for ($short) {
2724 s/^\s+//;
2725 s/\s+/ /g;
2726 my $len = int 40 / $item->{fontsize};
2727 substr $_, $len, length, "…" if $len < length;
2728 }
2729
2730 new CFClient::UI::Label
2731 markup => $short,
2732 tooltip => $item->{tooltip},
2733 tooltip_font => $::FONT_PROP,
2734 tooltip_width => 0.67,
2735 fontsize => $item->{fontsize},
2736 fg => $item->{fg},
2737 can_events => 1,
2738 can_hover => 1
2739 };
2740 }
2741
2742 $self->clear;
2743 $self->SUPER::add (reverse @widgets);
2744}
2745
2746sub add {
2747 my ($self, $text, %arg) = @_;
2748
2749 $text =~ s/^\s+//;
2750 $text =~ s/\s+$//;
2751
2752 my $timeout = time + ((delete $arg{timeout}) || 60);
2753
2754 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
2755
2756 if (my $item = $self->{item}{$group}) {
2757 if ($item->{text} eq $text) {
2758 $item->{count}++;
2759 } else {
2760 $item->{count} = 1;
2761 $item->{text} = $item->{tooltip} = $text;
2762 }
2763 $item->{id} = ++$self->{id};
2764 $item->{timeout} = $timeout;
2765 delete $item->{label};
2766 } else {
2767 $self->{item}{$group} = {
2768 id => ++$self->{id},
2769 text => $text,
2770 timeout => $timeout,
2771 tooltip => $text,
2772 fontsize => 0.8,
2773 fg => [0.8, 0.8, 0.8, 0.8],
2774 pri => 0,
2775 count => 1,
2776 %arg,
2777 };
2778 }
2779
2780 $self->reorder;
2781}
2782
2783#############################################################################
2784
2785package CFClient::UI::Root;
1963 2786
1964our @ISA = CFClient::UI::Container::; 2787our @ISA = CFClient::UI::Container::;
1965 2788
1966use SDL::OpenGL; 2789use CFClient::OpenGL;
2790
2791sub new {
2792 my $class = shift;
2793
2794 $class->SUPER::new (
2795 @_,
2796 )
2797}
2798
2799sub configure {
2800 my ($self, $x, $y, $w, $h) = @_;
2801
2802 $self->{w} = $w;
2803 $self->{h} = $h;
2804}
2805
2806sub check_size {
2807 my ($self) = @_;
2808
2809 $self->size_allocate ($self->{w}, $self->{h})
2810 if $self->{w};
2811}
1967 2812
1968sub size_request { 2813sub size_request {
1969 ($::WIDTH, $::HEIGHT) 2814 my ($self) = @_;
2815
2816 ($self->{w}, $self->{h})
1970} 2817}
1971 2818
1972sub size_allocate { 2819sub size_allocate {
1973 my ($self, $x, $y, $w, $h) = @_; 2820 my ($self, $w, $h) = @_;
1974 2821
1975 $self->_size_allocate ($x, $y, $w, $h); 2822 my $old_w = $self->{old_w}; $self->{old_w} = $w;
2823 my $old_h = $self->{old_h}; $self->{old_h} = $h;
1976 2824
1977 $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) 2825 CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h
1978 for @{$self->{children}}; 2826 if $old_w && $old_h && ($old_w != $w || $old_h != $h);
1979}
1980 2827
1981sub translate { 2828 for my $child ($self->children) {
2829 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2830
2831 $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1
2832 if exists $child->{req_x};
2833
2834 $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1
2835 if exists $child->{req_y};
2836
2837 $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5;
2838 $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5;
2839
2840 $child->configure ($X, $Y, $W, $H);
2841 }
2842}
2843
2844sub coord2local {
1982 my ($self, $x, $y) = @_; 2845 my ($self, $x, $y) = @_;
1983 2846
1984 ($x, $y) 2847 ($x, $y)
1985} 2848}
1986 2849
2850sub coord2global {
2851 my ($self, $x, $y) = @_;
2852
2853 ($x, $y)
2854}
2855
1987sub update { 2856sub update {
1988 my ($self) = @_; 2857 my ($self) = @_;
1989 2858
1990 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); 2859 $self->check_size;
1991 ::refresh (); 2860 $::WANT_REFRESH++;
1992} 2861}
1993 2862
1994sub add { 2863sub add {
1995 my ($self, $widget) = @_; 2864 my ($self, @children) = @_;
1996 2865
2866 for my $child (@children) {
2867 $child->{toplevel} = 1;
2868
2869 # integerise window positions
2870 $child->{x} = int $child->{x};
2871 $child->{y} = int $child->{y};
2872 }
2873
1997 $self->SUPER::add ($widget); 2874 $self->SUPER::add (@children);
1998
1999 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request);
2000} 2875}
2001 2876
2002sub on_refresh { 2877sub on_refresh {
2003 my ($self, $id, $cb) = @_; 2878 my ($self, $id, $cb) = @_;
2004 2879
2005 $self->{refresh_hook}{$id} = $cb; 2880 $self->{refresh_hook}{$id} = $cb;
2006} 2881}
2007 2882
2883sub on_post_alloc {
2884 my ($self, $id, $cb) = @_;
2885
2886 $self->{post_alloc_hook}{$id} = $cb;
2887}
2888
2008sub draw { 2889sub draw {
2009 my ($self) = @_; 2890 my ($self) = @_;
2010 2891
2011 while (my $rcb = delete $self->{refresh_hook}) { 2892 while ($self->{refresh_hook}) {
2012 $_->() for values %$rcb; 2893 $_->()
2894 for values %{delete $self->{refresh_hook}};
2895 }
2896
2897 if ($self->{check_size}) {
2898 my @queue = ([], []);
2899
2900 for (;;) {
2901 if ($self->{check_size}) {
2902 # heuristic: check containers last
2903 push @{ $queue[ ! ! $_->isa ("CFClient::UI::Container") ] }, $_
2904 for values %{delete $self->{check_size}}
2905 }
2906
2907 my $widget = (pop @{ $queue[0] }) || (pop @{ $queue[1] }) || last;
2908
2909 my ($w, $h) = $widget->{user_w} && $widget->{user_h}
2910 ? @$widget{qw(user_w user_h)}
2911 : $widget->size_request;
2912
2913 if (delete $widget->{force_alloc}
2914 or $w != $widget->{req_w} or $h != $widget->{req_h}) {
2915 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d#
2916
2917 $widget->{req_w} = $w;
2918 $widget->{req_h} = $h;
2919
2920 $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h];
2921
2922 $widget->{parent}->check_size
2923 if $widget->{parent};
2924 }
2925 }
2926 }
2927
2928 while ($self->{size_alloc}) {
2929 for (values %{delete $self->{size_alloc}}) {
2930 my ($widget, $w, $h) = @$_;
2931
2932 $w = 0 if $w < 0;
2933 $h = 0 if $h < 0;
2934
2935 $widget->{w} = $w;
2936 $widget->{h} = $h;
2937 $widget->size_allocate ($w, $h);
2938 $widget->emit (size_allocate => $w, $h);
2939 }
2940 }
2941
2942 while ($self->{post_alloc_hook}) {
2943 $_->()
2944 for values %{delete $self->{post_alloc_hook}};
2013 } 2945 }
2014 2946
2015 glViewport 0, 0, $::WIDTH, $::HEIGHT; 2947 glViewport 0, 0, $::WIDTH, $::HEIGHT;
2016 glClearColor +($::CFG->{fow_intensity}) x 3, 1; 2948 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2017 glClear GL_COLOR_BUFFER_BIT; 2949 glClear GL_COLOR_BUFFER_BIT;
2027 2959
2028############################################################################# 2960#############################################################################
2029 2961
2030package CFClient::UI; 2962package CFClient::UI;
2031 2963
2964$ROOT = new CFClient::UI::Root;
2032$TOPLEVEL = new CFClient::UI::Toplevel; 2965$TOOLTIP = new CFClient::UI::Tooltip;
2033 2966
20341 29671
2035 2968

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines