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.147 by root, Sat Apr 22 03:50:25 2006 UTC

7 7
8use CFClient; 8use CFClient;
9 9
10our ($FOCUS, $HOVER, $GRAB); # various widgets 10our ($FOCUS, $HOVER, $GRAB); # various widgets
11 11
12our $TOPLEVEL; 12our $ROOT;
13our $BUTTON_STATE; 13our $BUTTON_STATE;
14 14
15# class methods for events 15# class methods for events
16sub feed_sdl_key_down_event { 16sub feed_sdl_key_down_event {
17 $FOCUS->key_down ($_[0]) if $FOCUS; 17 $FOCUS->key_down ($_[0]) if $FOCUS;
21 $FOCUS->key_up ($_[0]) if $FOCUS; 21 $FOCUS->key_up ($_[0]) if $FOCUS;
22} 22}
23 23
24sub feed_sdl_button_down_event { 24sub feed_sdl_button_down_event {
25 my ($ev) = @_; 25 my ($ev) = @_;
26 my ($x, $y) = ($ev->motion_x, $ev->motion_y); 26 my ($x, $y) = ($ev->{x}, $ev->{y});
27 27
28 if (!$BUTTON_STATE) { 28 if (!$BUTTON_STATE) {
29 my $widget = $TOPLEVEL->find_widget ($x, $y); 29 my $widget = $ROOT->find_widget ($x, $y);
30 30
31 $GRAB = $widget; 31 $GRAB = $widget;
32 $GRAB->update if $GRAB; 32 $GRAB->update if $GRAB;
33 } 33 }
34 34
35 $BUTTON_STATE |= 1 << ($ev->button - 1); 35 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
36 36
37 $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB; 37 $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB;
38} 38}
39 39
40sub feed_sdl_button_up_event { 40sub feed_sdl_button_up_event {
41 my ($ev) = @_; 41 my ($ev) = @_;
42 my ($x, $y) = ($ev->motion_x, $ev->motion_y); 42 my ($x, $y) = ($ev->{x}, $ev->{y});
43 43
44 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); 44 my $widget = $GRAB || $ROOT->find_widget ($x, $y);
45 45
46 $BUTTON_STATE &= ~(1 << ($ev->button - 1)); 46 $BUTTON_STATE &= ~(1 << ($ev->{button} - 1));
47 47
48 $GRAB->button_up ($ev, $GRAB->translate ($x, $y)) if $GRAB; 48 $GRAB->button_up ($ev, $GRAB->coord2local ($x, $y)) if $GRAB;
49 49
50 if (!$BUTTON_STATE) { 50 if (!$BUTTON_STATE) {
51 my $grab = $GRAB; undef $GRAB; 51 my $grab = $GRAB; undef $GRAB;
52 $grab->update if $grab; 52 $grab->update if $grab;
53 $GRAB->update if $GRAB; 53 $GRAB->update if $GRAB;
54 } 54 }
55} 55}
56 56
57sub feed_sdl_motion_event { 57sub feed_sdl_motion_event {
58 my ($ev) = @_; 58 my ($ev) = @_;
59 my ($x, $y) = ($ev->motion_x, $ev->motion_y); 59 my ($x, $y) = ($ev->{x}, $ev->{y});
60 60
61 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); 61 my $widget = $GRAB || $ROOT->find_widget ($x, $y);
62 62
63 if ($widget != $HOVER) { 63 if ($widget != $HOVER) {
64 my $hover = $HOVER; $HOVER = $widget; 64 my $hover = $HOVER; $HOVER = $widget;
65 65
66 $hover->update if $hover && $hover->{can_hover}; 66 $hover->update if $hover && $hover->{can_hover};
67 $HOVER->update if $HOVER && $HOVER->{can_hover}; 67 $HOVER->update if $HOVER && $HOVER->{can_hover};
68 } 68 }
69 69
70 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; 70 $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER;
71} 71}
72 72
73# convert position array to integers 73# convert position array to integers
74sub harmonize { 74sub harmonize {
75 my ($vals) = @_; 75 my ($vals) = @_;
76 76
77 my $rem = 0; 77 my $rem = 0;
78 78
79 for ($vals) { 79 for (@$vals) {
80 my $i = int $_ + $rem; 80 my $i = int $_ + $rem;
81 $rem += $_ - $i; 81 $rem += $_ - $i;
82 $_ = $i; 82 $_ = $i;
83 } 83 }
84} 84}
87 87
88package CFClient::UI::Base; 88package CFClient::UI::Base;
89 89
90use strict; 90use strict;
91 91
92use SDL::OpenGL; 92use CFClient::OpenGL;
93 93
94sub new { 94sub new {
95 my $class = shift; 95 my $class = shift;
96 96
97 my $self = bless { 97 my $self = bless {
98 x => 0, 98 x => 0,
99 y => 0, 99 y => 0,
100 z => 0, 100 z => 0,
101 w => -1,
102 h => -1,
103 @_ 101 @_
104 }, $class; 102 }, $class;
105 103
106 for (keys %$self) { 104 for (keys %$self) {
107 if (/^connect_(.*)$/) { 105 if (/^connect_(.*)$/) {
110 } 108 }
111 109
112 $self 110 $self
113} 111}
114 112
113sub show {
114 my ($self) = @_;
115
116 return if $self->{parent};
117
118 $CFClient::UI::ROOT->add ($self);
119}
120
121sub hide {
122 my ($self) = @_;
123
124 return unless $self->{parent};
125
126 $self->{parent}->remove ($self);
127}
128
115sub move { 129sub move {
116 my ($self, $x, $y, $z) = @_; 130 my ($self, $x, $y, $z) = @_;
131
117 $self->{x} = $x; 132 $self->{x} = int $x;
118 $self->{y} = $y; 133 $self->{y} = int $y;
119 $self->{z} = $z if defined $z; 134 $self->{z} = $z if defined $z;
135
136 $self->update;
120} 137}
121 138
122sub needs_redraw { 139sub needs_redraw {
123 0 140 0
124} 141}
125 142
126sub size_request { 143sub size_request {
127 require Carp; 144 require Carp;
128 Carp::confess "size_request is abtract"; 145 Carp::confess "size_request is abstract";
129} 146}
130 147
131sub _size_allocate { 148sub configure {
132 my ($self, $x, $y, $w, $h) = @_; 149 my ($self, $x, $y, $w, $h) = @_;
133 150
151 if ($self->{aspect}) {
152 my $w2 = List::Util::min $w, int $h * $self->{aspect};
153 my $h2 = List::Util::min $h, int $w / $self->{aspect};
154
155 # use alignment to adjust x, y
156
157 $x += int +($w - $w2) * 0.5;
158 $y += int +($h - $h2) * 0.5;
159
160 ($w, $h) = ($w2, $h2);
161 }
162
163 if ($self->{x} != $x || $self->{y} != $y) {
134 $self->{x} = $x; 164 $self->{x} = $x;
135 $self->{y} = $y; 165 $self->{y} = $y;
166 $self->update;
167 }
136 168
137 return unless $self->{w} != $w || $self->{h} != $h; 169 if ($self->{w} != $w || $self->{h} != $h) {
138
139 $self->{w} = $w; 170 $self->{w} = $w;
140 $self->{h} = $h; 171 $self->{h} = $h;
141 172
173 $self->size_allocate ($w, $h);
174 $self->update;
142 1 175 }
143} 176}
144 177
145sub size_allocate { 178sub size_allocate {
179 # nothing to be done
180}
181
182# return top left coordinates
183sub _topleft {
146 my ($self, $x, $y, $w, $h) = @_; 184 my ($self, $x, $y) = @_;
147 185
148 $self->_size_allocate ($x, $y, $w, $h); 186 $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y});
149} 187}
150 188
151# translate global coordinates to local coordinate system 189# translate global coordinates to local coordinate system
152sub translate { 190sub coord2local {
153 my ($self, $x, $y) = @_; 191 my ($self, $x, $y) = @_;
154 192
155 $self->{parent}->translate ($x - $self->{x}, $y - $self->{y}); 193 my ($X, $Y) = $self->_topleft;
194 ($x - $X, $y - $Y)
195}
196
197# translate local coordinates to global coordinate system
198sub coord2global {
199 my ($self, $x, $y) = @_;
200
201 my ($X, $Y) = $self->_topleft;
202 ($x + $X, $y + $Y)
156} 203}
157 204
158sub focus_in { 205sub focus_in {
159 my ($self) = @_; 206 my ($self) = @_;
160 207
161 return if $FOCUS == $self; 208 return if $FOCUS == $self;
162 return unless $self->{can_focus}; 209 return unless $self->{can_focus};
163 210
164 my $focus = $FOCUS; $FOCUS = $self; 211 my $focus = $FOCUS; $FOCUS = $self;
212
213 $self->emit (focus_in => $focus);
214
165 $focus->update if $focus; 215 $focus->update if $focus;
166 $FOCUS->update; 216 $FOCUS->update;
167} 217}
168 218
169sub focus_out { 219sub focus_out {
170 my ($self) = @_; 220 my ($self) = @_;
171 221
172 return unless $FOCUS == $self; 222 return unless $FOCUS == $self;
173 223
174 my $focus = $FOCUS; undef $FOCUS; 224 my $focus = $FOCUS; undef $FOCUS;
225
226 $self->emit (focus_out => $focus);
227
175 $focus->update if $focus; #? 228 $focus->update if $focus; #?
176} 229}
177 230
178sub mouse_motion { } 231sub mouse_motion { }
179sub button_up { } 232sub button_up { }
203 glPopMatrix; 256 glPopMatrix;
204 257
205 if ($self == $HOVER && $self->{can_hover}) { 258 if ($self == $HOVER && $self->{can_hover}) {
206 my ($x, $y) = @$self{qw(x y)}; 259 my ($x, $y) = @$self{qw(x y)};
207 260
208 glColor 0, 0, 1, 0.2; 261 glColor 1, 0.8, 0.5, 0.2;
209 glEnable GL_BLEND; 262 glEnable GL_BLEND;
210 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 263 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
211 glBegin GL_QUADS; 264 glBegin GL_QUADS;
212 glVertex $x , $y; 265 glVertex $x , $y;
213 glVertex $x + $self->{w}, $y; 266 glVertex $x + $self->{w}, $y;
233 286
234 () 287 ()
235} 288}
236 289
237sub set_parent { 290sub set_parent {
238 my ($self, $par) = @_; 291 my ($self, $parent) = @_;
239 292
240 $self->{parent} = $par;
241 Scalar::Util::weaken $self->{parent}; 293 Scalar::Util::weaken ($self->{parent} = $parent);
242} 294}
243 295
244sub get_parent { 296sub check_size {
245 $_[0]->{parent} 297 my ($self) = @_;
298
299 my ($w, $h) = $self->size_request;
300
301 if ($w != $self->{req_w} || $h != $self->{req_h}) {
302 $self->{req_w} = $w;
303 $self->{req_h} = $h;
304
305 $self->{parent}->check_size
306 if $self->{parent};
307 }
246} 308}
247 309
248sub update { 310sub update {
249 my ($self) = @_; 311 my ($self) = @_;
250 312
253} 315}
254 316
255sub connect { 317sub connect {
256 my ($self, $signal, $cb) = @_; 318 my ($self, $signal, $cb) = @_;
257 319
258 push @{ $self->{cb}{$signal} }, $cb; 320 push @{ $self->{signal_cb}{$signal} }, $cb;
259} 321}
260 322
261sub emit { 323sub emit {
262 my ($self, $signal, @args) = @_; 324 my ($self, $signal, @args) = @_;
263 325
326 for my $cb (@{$self->{signal_cb}{$signal} || []}) {
264 $_->($self, @args) 327 $cb->($self, @args);
265 for @{$self->{cb}{$signal} || []}; 328 }
266} 329}
267 330
268sub DESTROY { 331sub DESTROY {
269 my ($self) = @_; 332 my ($self) = @_;
270 333
276package CFClient::UI::DrawBG; 339package CFClient::UI::DrawBG;
277 340
278our @ISA = CFClient::UI::Base::; 341our @ISA = CFClient::UI::Base::;
279 342
280use strict; 343use strict;
281use SDL::OpenGL; 344use CFClient::OpenGL;
282 345
283sub new { 346sub new {
284 my $class = shift; 347 my $class = shift;
285 348
286 # range [value, low, high, page] 349 # range [value, low, high, page]
339 402
340 $self 403 $self
341} 404}
342 405
343sub add { 406sub add {
344 my ($self, $chld) = @_; 407 my ($self, $child) = @_;
345 408
346 $chld->set_parent ($self); 409 $child->set_parent ($self);
410
411 use sort 'stable';
347 412
348 $self->{children} = [ 413 $self->{children} = [
349 sort { $a->{z} <=> $b->{z} } 414 sort { $a->{z} <=> $b->{z} }
350 @{$self->{children}}, $chld 415 @{$self->{children}}, $child
351 ]; 416 ];
352 417
353 $self->{w} = $self->{h} = -1; 418 $child->check_size;
354 $self->update;
355} 419}
356 420
357sub remove { 421sub remove {
358 my ($self, $widget) = @_; 422 my ($self, $child) = @_;
359 423
424 delete $child->{parent};
425
360 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; 426 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
361 427
362 $self->size_allocate (0, 0, $self->{w}, $self->{h}); 428 $self->check_size;
363} 429}
364 430
365sub find_widget { 431sub find_widget {
366 my ($self, $x, $y) = @_; 432 my ($self, $x, $y) = @_;
367 433
397 463
398 $class->SUPER::new (children => [$child], %arg) 464 $class->SUPER::new (children => [$child], %arg)
399} 465}
400 466
401sub add { 467sub add {
402 my ($self, $widget) = @_; 468 my ($self, $child) = @_;
403 469
404 $self->{children} = []; 470 $self->{children} = [];
405 471
406 $self->SUPER::add ($widget); 472 $self->SUPER::add ($child);
407} 473}
408 474
409sub remove { 475sub remove {
410 my ($self, $widget) = @_; 476 my ($self, $widget) = @_;
411 477
420sub size_request { 486sub size_request {
421 $_[0]{children}[0]->size_request 487 $_[0]{children}[0]->size_request
422} 488}
423 489
424sub size_allocate { 490sub size_allocate {
425 my ($self, $x, $y, $w, $h) = @_; 491 my ($self, $w, $h) = @_;
426 492
427 $self->_size_allocate ($x, $y, $w, $h) or return;
428
429 $self->{children}[0]->size_allocate (0, 0, $w, $h); 493 $self->{children}[0]->configure (0, 0, $w, $h);
430} 494}
431 495
432############################################################################# 496#############################################################################
433 497
434package CFClient::UI::Window; 498package CFClient::UI::Window;
435 499
436our @ISA = CFClient::UI::Bin::; 500our @ISA = CFClient::UI::Bin::;
437 501
438use SDL::OpenGL; 502use CFClient::OpenGL;
439 503
440sub new { 504sub new {
441 my ($class, %arg) = @_; 505 my ($class, %arg) = @_;
442 506
443 my $self = $class->SUPER::new (%arg); 507 my $self = $class->SUPER::new (%arg);
460 $self->child->draw; 524 $self->child->draw;
461 }; 525 };
462} 526}
463 527
464sub size_allocate { 528sub size_allocate {
465 my ($self, $x, $y, $w, $h) = @_; 529 my ($self, $w, $h) = @_;
466 530
467 $self->_size_allocate ($x, $y, $w, $h) or return;
468
469 $self->child->size_allocate (0, 0, $w, $h); 531 $self->child->configure (0, 0, $w, $h);
470 532
471 $self->render_chld; 533 $self->render_chld;
472} 534}
473 535
474sub _draw { 536sub _draw {
490 glDisable GL_TEXTURE_2D; 552 glDisable GL_TEXTURE_2D;
491} 553}
492 554
493############################################################################# 555#############################################################################
494 556
557package CFClient::UI::ViewPort;
558
559our @ISA = CFClient::UI::Window::;
560
561sub new { die }
562
563sub size_request {
564 my ($self) = @_;
565
566 @$self{qw(child_w child_h)} = $self->child->size_request;
567 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
568
569 @$self{qw(child_w child_h)}
570}
571
572sub _draw {
573 my ($self) = @_;
574
575 $self->{children}[1]->draw;
576}
577
578
579#############################################################################
580
495package CFClient::UI::Frame; 581package CFClient::UI::Frame;
496 582
497our @ISA = CFClient::UI::Bin::; 583our @ISA = CFClient::UI::Bin::;
498 584
499use SDL::OpenGL; 585use CFClient::OpenGL;
500 586
501sub size_request { 587sub size_request {
502 my ($self) = @_; 588 my ($self) = @_;
503 my $chld = $self->child 589 my $chld = $self->child
504 or return (0, 0); 590 or return (0, 0);
509} 595}
510 596
511sub size_allocate { 597sub size_allocate {
512 my ($self, $x, $y, $w, $h) = @_; 598 my ($self, $x, $y, $w, $h) = @_;
513 599
514 $self->_size_allocate ($x, $y, $w, $h) or return;
515
516 $self->child->size_allocate (2, 2, $w - 4, $h - 4); 600 $self->child->configure (2, 2, $w - 4, $h - 4);
517} 601}
518 602
519sub _draw { 603sub _draw {
520 my ($self) = @_; 604 my ($self) = @_;
521 605
538 622
539package CFClient::UI::FancyFrame; 623package CFClient::UI::FancyFrame;
540 624
541our @ISA = CFClient::UI::Bin::; 625our @ISA = CFClient::UI::Bin::;
542 626
543use SDL::OpenGL; 627use CFClient::OpenGL;
544 628
545my @tex = 629my @tex =
546 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 630 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
547 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 631 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
548 632
549sub new { 633sub new {
550 my $class = shift; 634 my $class = shift;
551 635
552 # TODO: user_x, user_y, overwrite moveto? 636 # TODO: user_x, user_y, overwrite moveto?
553 637
554 $class->SUPER::new ( 638 my $self = $class->SUPER::new (
555 bg => [1, 1, 1, 1], 639 bg => [1, 1, 1, 1],
556 border_bg => [1, 1, 1, 1], 640 border_bg => [1, 1, 1, 1],
557 border => $::FONTSIZE * 0.8, 641 border => 0.8,
558 @_ 642 @_
643 );
644
645 $self->{title} &&= new CFClient::UI::Label
646 align => 0,
647 valign => 1,
648 text => $self->{title},
649 fontsize => 1;
650
651 $self
652}
653
654sub border {
655 int $_[0]{border} * $::FONTSIZE
656}
657
658sub size_request {
659 my ($self) = @_;
660
661 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
662
663 my ($w, $h) = $self->SUPER::size_request;
664
665 (
666 $w + $self->border * 2,
667 $h + $self->border * 2,
559 ) 668 )
560} 669}
561 670
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 { 671sub size_allocate {
576 my ($self, $x, $y, $w, $h) = @_; 672 my ($self, $w, $h) = @_;
577 673
578 $self->_size_allocate ($x, $y, $w, $h) or return;
579
580 $h -= List::Util::max 0, $self->{border} * 2; 674 $h -= List::Util::max 0, $self->border * 2;
581 $w -= List::Util::max 0, $self->{border} * 2; 675 $w -= List::Util::max 0, $self->border * 2;
582 676
677 $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2)
678 if $self->{title};
679
583 $self->child->size_allocate ($self->{border}, $self->{border}, $w, $h); 680 $self->child->configure ($self->border, $self->border, $w, $h);
584} 681}
585 682
586sub button_down { 683sub button_down {
587 my ($self, $ev, $x, $y) = @_; 684 my ($self, $ev, $x, $y) = @_;
588 685
686 my $border = $self->border;
687
589 if ($x < $self->{w} && $x >= $self->{w} - $self->{border} 688 if ($x < $self->{w} && $x >= $self->{w} - $border
590 && $y < $self->{h} && $y >= $self->{h} - $self->{border}) { 689 && $y < $self->{h} && $y >= $self->{h} - $border) {
591 690
592 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 691 my ($ox, $oy) = ($ev->{x}, $ev->{y});
593 my ($bw, $bh) = ($self->{w}, $self->{h}); 692 my ($bw, $bh) = ($self->{w}, $self->{h});
594 693
595 $self->{motion} = sub { 694 $self->{motion} = sub {
596 my ($ev, $x, $y) = @_; 695 my ($ev, $x, $y) = @_;
597 696
598 ($x, $y) = ($ev->motion_x, $ev->motion_y); 697 ($x, $y) = ($ev->{x}, $ev->{y});
599 698
600 $self->{user_w} = $bw + $x - $ox; 699 $self->{user_w} = $bw + $x - $ox;
601 $self->{user_h} = $bh + $y - $oy; 700 $self->{user_h} = $bh + $y - $oy;
602 $self->update; 701 $self->check_size;
603 }; 702 };
604 703
605 } elsif ($x >= 0 && $x < $self->{w} 704 } elsif ($x >= 0 && $x < $self->{w}
606 && $y >= 0 && $y < $self->{border}) { 705 && $y >= 0 && $y < $border) {
607 706
608 my ($ox, $oy) = ($ev->button_x, $ev->button_y); 707 my ($ox, $oy) = ($ev->{x}, $ev->{y});
609 my ($bx, $by) = ($self->{x}, $self->{y}); 708 my ($bx, $by) = ($self->{x}, $self->{y});
610 709
611 $self->{motion} = sub { 710 $self->{motion} = sub {
612 my ($ev, $x, $y) = @_; 711 my ($ev, $x, $y) = @_;
613 712
614 ($x, $y) = ($ev->motion_x, $ev->motion_y); 713 ($x, $y) = ($ev->{x}, $ev->{y});
615 714
616 $self->move ($bx + $x - $ox, $by + $y - $oy); 715 $self->move ($bx + $x - $ox, $by + $y - $oy);
617 $self->update; 716 $self->update;
618 }; 717 };
619 } 718 }
640 glEnable GL_BLEND; 739 glEnable GL_BLEND;
641 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 740 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
642 glEnable GL_TEXTURE_2D; 741 glEnable GL_TEXTURE_2D;
643 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 742 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
644 743
744 my $border = $self->border;
745
645 glColor @{ $self->{border_bg} }; 746 glColor @{ $self->{border_bg} };
646 $tex[1]->draw_quad (0, 0, $w, $self->{border}); 747 $tex[1]->draw_quad (0, 0, $w, $border);
647 $tex[3]->draw_quad (0, $self->{border}, $self->{border}, $ch); 748 $tex[3]->draw_quad (0, $border, $border, $ch);
648 $tex[2]->draw_quad ($w - $self->{border}, $self->{border}, $self->{border}, $ch); 749 $tex[2]->draw_quad ($w - $border, $border, $border, $ch);
649 $tex[4]->draw_quad (0, $h - $self->{border}, $w, $self->{border}); 750 $tex[4]->draw_quad (0, $h - $border, $w, $border);
650 751
651 my $bg = $tex[0]; 752 my $bg = $tex[0];
652 753
653 # TODO: repeat texture not scale 754 # TODO: repeat texture not scale
654 my $rep_x = $cw / $bg->{w}; 755 my $rep_x = $cw / $bg->{w};
657 glColor @{ $self->{bg} }; 758 glColor @{ $self->{bg} };
658 759
659 $bg->{s} = $rep_x; 760 $bg->{s} = $rep_x;
660 $bg->{t} = $rep_y; 761 $bg->{t} = $rep_y;
661 $bg->{wrap_mode} = 1; 762 $bg->{wrap_mode} = 1;
662 $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); 763 $bg->draw_quad ($border, $border, $cw, $ch);
663 764
664 glDisable GL_TEXTURE_2D; 765 glDisable GL_TEXTURE_2D;
665 glDisable GL_BLEND; 766 glDisable GL_BLEND;
666 767
768 $self->{title}->draw if $self->{title};
667 $self->child->draw; 769 $self->child->draw;
668} 770}
669 771
670############################################################################# 772#############################################################################
671 773
673 775
674our @ISA = CFClient::UI::Base::; 776our @ISA = CFClient::UI::Base::;
675 777
676use List::Util qw(max sum); 778use List::Util qw(max sum);
677 779
678use SDL::OpenGL; 780use CFClient::OpenGL;
679 781
680sub new { 782sub new {
681 my $class = shift; 783 my $class = shift;
682 784
683 $class->SUPER::new ( 785 $class->SUPER::new (
685 @_ 787 @_
686 ) 788 )
687} 789}
688 790
689sub add { 791sub add {
690 my ($self, $x, $y, $chld) = @_; 792 my ($self, $x, $y, $child) = @_;
691 793
794 $child->set_parent ($self);
692 $self->{children}[$y][$x] = $chld; 795 $self->{children}[$y][$x] = $child;
693 $chld->set_parent ($self);
694 796
695 $self->{w} = $self->{h} = -1; 797 $child->check_size;
798}
799
800# TODO: move to container class maybe? send childs a signal on removal?
801sub clear {
802 my ($self) = @_;
803
804 delete $self->{children};
696 $self->update; 805 $self->update;
697} 806}
698 807
699sub get_wh { 808sub get_wh {
700 my ($self) = @_; 809 my ($self) = @_;
728 (sum @$hs), 837 (sum @$hs),
729 ) 838 )
730} 839}
731 840
732sub size_allocate { 841sub size_allocate {
733 my ($self, $x, $y, $w, $h) = @_; 842 my ($self, $w, $h) = @_;
734
735 $self->_size_allocate ($x, $y, $w, $h) or return;
736 843
737 my ($ws, $hs) = $self->get_wh; 844 my ($ws, $hs) = $self->get_wh;
738 845
739 my $req_w = sum @$ws; 846 my $req_w = sum @$ws;
740 my $req_h = sum @$hs; 847 my $req_h = sum @$hs;
762 869
763 for my $c (0 .. $#$row) { 870 for my $c (0 .. $#$row) {
764 my $col_w = $ws->[$c]; 871 my $col_w = $ws->[$c];
765 872
766 if (my $widget = $row->[$c]) { 873 if (my $widget = $row->[$c]) {
767 $widget->size_allocate ($x, $y, $col_w, $row_h); 874 $widget->configure ($x, $y, $col_w, $row_h);
768 } 875 }
769 876
770 $x += $col_w; 877 $x += $col_w;
771 } 878 }
772 879
817 (List::Util::max map $_->[1], @alloc), 924 (List::Util::max map $_->[1], @alloc),
818 ) 925 )
819} 926}
820 927
821sub size_allocate { 928sub size_allocate {
822 my ($self, $x, $y, $w, $h) = @_; 929 my ($self, $w, $h) = @_;
823
824 $self->_size_allocate ($x, $y, $w, $h);
825 930
826 ($h, $w) = ($w, $h); 931 ($h, $w) = ($w, $h);
827 932
828 my $children = $self->{children}; 933 my $children = $self->{children};
829 934
851 956
852 my $y = 0; 957 my $y = 0;
853 for (0 .. $#$children) { 958 for (0 .. $#$children) {
854 my $child = $children->[$_]; 959 my $child = $children->[$_];
855 my $h = $h[$_]; 960 my $h = $h[$_];
856 $child->size_allocate ($y, 0, $h, $w); 961 $child->configure ($y, 0, $h, $w);
857 962
858 $y += $h; 963 $y += $h;
859 } 964 }
965
966 1
860} 967}
861 968
862############################################################################# 969#############################################################################
863 970
864package CFClient::UI::VBox; 971package CFClient::UI::VBox;
877 (List::Util::sum map $_->[1], @alloc), 984 (List::Util::sum map $_->[1], @alloc),
878 ) 985 )
879} 986}
880 987
881sub size_allocate { 988sub size_allocate {
882 my ($self, $x, $y, $w, $h) = @_; 989 my ($self, $w, $h) = @_;
883
884 $self->_size_allocate ($x, $y, $w, $h);
885 990
886 my $children = $self->{children}; 991 my $children = $self->{children};
887 992
888 my @h = map +($_->size_request)[1], @$children; 993 my @h = map +($_->size_request)[1], @$children;
889 994
907 1012
908 my $y = 0; 1013 my $y = 0;
909 for (0 .. $#$children) { 1014 for (0 .. $#$children) {
910 my $child = $children->[$_]; 1015 my $child = $children->[$_];
911 my $h = $h[$_]; 1016 my $h = $h[$_];
912 $child->size_allocate (0, $y, $w, $h); 1017 $child->configure (0, $y, $w, $h);
913 1018
914 $y += $h; 1019 $y += $h;
915 } 1020 }
1021
1022 1
916} 1023}
917 1024
918############################################################################# 1025#############################################################################
919 1026
920package CFClient::UI::Label; 1027package CFClient::UI::Label;
921 1028
922our @ISA = CFClient::UI::Base::; 1029our @ISA = CFClient::UI::Base::;
923 1030
924use SDL::OpenGL; 1031use CFClient::OpenGL;
925 1032
926sub new { 1033sub new {
927 my ($class, %arg) = @_; 1034 my ($class, %arg) = @_;
928 1035
929 my $self = $class->SUPER::new ( 1036 my $self = $class->SUPER::new (
930 fg => [1, 1, 1], 1037 fg => [1, 1, 1],
931 fontsize => $::FONTSIZE, 1038 fontsize => 1,
932 text => "", 1039 text => "",
933 align => -1, 1040 align => -1,
1041 valign => -1,
934 padding => 2, 1042 padding => 2,
935 layout => new CFClient::Layout, 1043 layout => new CFClient::Layout,
936 %arg 1044 %arg
937 ); 1045 );
938 1046
939 $self->set_text ($self->{text}); 1047 if (exists $self->{template}) {
1048 my $layout = new CFClient::Layout;
1049 $layout->set_text (delete $self->{template});
1050 $self->{template} = $layout;
1051 }
1052
1053 $self->set_text (delete $self->{text}) if exists $self->{text};
1054 $self->set_markup (delete $self->{markup}) if exists $self->{markup};
940 1055
941 $self 1056 $self
942} 1057}
943 1058
944sub escape_text { 1059sub escape_text {
952} 1067}
953 1068
954sub set_text { 1069sub set_text {
955 my ($self, $text) = @_; 1070 my ($self, $text) = @_;
956 1071
957 $self->{text} = $text;
958 $self->{layout}->set_markup ($text); 1072 $self->{layout}->set_text ($text);
959 1073
960 delete $self->{texture}; 1074 delete $self->{texture};
961# $self->{w} = $self->{h} = -1;
962 $self->update; 1075 $self->update;
963} 1076}
964 1077
965sub get_text { 1078sub set_markup {
966 my ($self, $text) = @_; 1079 my ($self, $markup) = @_;
967 1080
968 $self->{text} 1081 $self->{layout}->set_markup ($markup);
1082
1083 delete $self->{texture};
1084 $self->update;
969} 1085}
970 1086
971sub size_request { 1087sub size_request {
972 my ($self) = @_; 1088 my ($self) = @_;
973 1089
974 $self->{layout}->set_width; 1090 $self->{layout}->set_width;
975 $self->{layout}->set_height ($self->{fontsize}); 1091 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1092
976 my ($w, $h) = $self->{layout}->size; 1093 my ($w, $h) = $self->{layout}->size;
1094
1095 if (exists $self->{template}) {
1096 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1097
1098 my ($w2, $h2) = $self->{template}->size;
1099
1100 $w = List::Util::max $w, $w2;
1101 $h = List::Util::max $h, $h2;
1102 }
977 1103
978 ( 1104 (
979 $w + $self->{padding} * 2, 1105 $w + $self->{padding} * 2,
980 $h + $self->{padding} * 2, 1106 $h + $self->{padding} * 2,
981 ) 1107 )
982} 1108}
983 1109
984sub size_allocate { 1110sub size_allocate {
985 my ($self, $x, $y, $w, $h) = @_; 1111 my ($self, $w, $h) = @_;
986
987 $self->_size_allocate ($x, $y, $w, $h) or return;
988 1112
989 delete $self->{texture}; 1113 delete $self->{texture};
990} 1114}
991 1115
992sub update { 1116sub set_fontsize {
993 my ($self) = @_; 1117 my ($self, $fontsize) = @_;
994 1118
995 delete $self->{texture}; 1119 $self->{fontsize} = $fontsize;
996 $self->SUPER::update; 1120 $self->check_size;
997} 1121}
998 1122
999sub _draw { 1123sub _draw {
1000 my ($self) = @_; 1124 my ($self) = @_;
1001 1125
1002 my $tex = $self->{texture} ||= do { 1126 my $tex = $self->{texture} ||= do {
1003 $self->{layout}->set_width ($self->{w}); 1127 $self->{layout}->set_width ($self->{w});
1004 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); 1128 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1005 new_from_layout CFClient::Texture $self->{layout} 1129 new_from_layout CFClient::Texture $self->{layout}
1006 }; 1130 };
1007 1131
1008 glEnable GL_BLEND; 1132 glEnable GL_BLEND;
1009 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1133 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1010 glEnable GL_TEXTURE_2D; 1134 glEnable GL_TEXTURE_2D;
1011 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1135 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1012 1136
1013 glColor @{$self->{fg}}; 1137 glColor @{$self->{fg}};
1014 1138
1015 my $x = 1139 $self->{ox} = int (
1016 $self->{align} < 0 ? $self->{padding} 1140 $self->{align} < 0 ? $self->{padding}
1017 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1141 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1018 : ($self->{w} - $tex->{w}) * 0.5; 1142 : ($self->{w} - $tex->{w}) * 0.5
1143 );
1019 1144
1020 $tex->draw_quad (int $x, int +($self->{h} - $tex->{h}) * 0.5); 1145 $self->{oy} = int (
1146 $self->{valign} < 0 ? $self->{padding}
1147 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding}
1148 : ($self->{h} - $tex->{h}) * 0.5
1149 );
1150
1151 $tex->draw_quad ($self->{ox}, $self->{oy});
1021 1152
1022 glDisable GL_TEXTURE_2D; 1153 glDisable GL_TEXTURE_2D;
1023 glDisable GL_BLEND; 1154 glDisable GL_BLEND;
1024} 1155}
1025 1156
1026############################################################################# 1157#############################################################################
1027 1158
1028package CFClient::UI::Entry; 1159package CFClient::UI::EntryBase;
1029 1160
1030our @ISA = CFClient::UI::Label::; 1161our @ISA = CFClient::UI::Label::;
1031 1162
1032use SDL; 1163use CFClient::OpenGL;
1033use SDL::OpenGL;
1034 1164
1035sub new { 1165sub new {
1036 my $class = shift; 1166 my $class = shift;
1037 1167
1038 $class->SUPER::new ( 1168 $class->SUPER::new (
1040 bg => [0, 0, 0, 0.2], 1170 bg => [0, 0, 0, 0.2],
1041 active_bg => [1, 1, 1, 0.5], 1171 active_bg => [1, 1, 1, 0.5],
1042 active_fg => [0, 0, 0], 1172 active_fg => [0, 0, 0],
1043 can_hover => 1, 1173 can_hover => 1,
1044 can_focus => 1, 1174 can_focus => 1,
1175 valign => 0,
1045 @_ 1176 @_
1046 ) 1177 )
1047} 1178}
1048 1179
1049sub _set_text { 1180sub _set_text {
1050 my ($self, $text) = @_; 1181 my ($self, $text) = @_;
1051 1182
1052 my $old_text = $self->{text}; 1183 delete $self->{cur_h};
1184
1185 return if $self->{text} eq $text;
1186
1187 delete $self->{texture};
1053 1188
1054 $self->{last_activity} = $::NOW; 1189 $self->{last_activity} = $::NOW;
1055
1056 $self->{text} = $text; 1190 $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 1191
1060 $text =~ s/./*/g if $self->{hidden}; 1192 $text =~ s/./*/g if $self->{hidden};
1193 $self->{layout}->set_text ("$text ");
1061 1194
1062 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1195 $self->emit (changed => $self->{text});
1196}
1063 1197
1064 $text = substr $text, 0, $self->{cursor}; 1198sub get_text {
1065 utf8::encode $text; 1199 $_[0]{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} 1200}
1072 1201
1073sub size_request { 1202sub size_request {
1074 my ($self) = @_; 1203 my ($self) = @_;
1075 1204
1077 1206
1078 ($w + 1, $h) # add 1 for cursor 1207 ($w + 1, $h) # add 1 for cursor
1079} 1208}
1080 1209
1081sub size_allocate { 1210sub size_allocate {
1082 my ($self, $x, $y, $w, $h) = @_; 1211 my ($self, $w, $h) = @_;
1083
1084 $self->SUPER::size_allocate ($x, $y, $w, $h);
1085 1212
1086 $self->_set_text ($self->{text}); 1213 $self->_set_text ($self->{text});
1087} 1214}
1088 1215
1089sub set_text { 1216sub set_text {
1095} 1222}
1096 1223
1097sub key_down { 1224sub key_down {
1098 my ($self, $ev) = @_; 1225 my ($self, $ev) = @_;
1099 1226
1100 my $mod = $ev->key_mod; 1227 my $mod = $ev->{mod};
1101 my $sym = $ev->key_sym; 1228 my $sym = $ev->{sym};
1102
1103 my $uni = $ev->key_unicode; 1229 my $uni = $ev->{unicode};
1104 1230
1105 my $text = $self->get_text; 1231 my $text = $self->get_text;
1106 1232
1107 if ($sym == SDLK_BACKSPACE) { 1233 if ($sym == 8) {
1108 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 1234 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
1109 } elsif ($sym == SDLK_DELETE) { 1235 } elsif ($sym == 127) {
1110 substr $text, $self->{cursor}, 1, ""; 1236 substr $text, $self->{cursor}, 1, "";
1111 } elsif ($sym == SDLK_LEFT) { 1237 } elsif ($sym == CFClient::SDLK_LEFT) {
1112 --$self->{cursor} if $self->{cursor}; 1238 --$self->{cursor} if $self->{cursor};
1113 } elsif ($sym == SDLK_RIGHT) { 1239 } elsif ($sym == CFClient::SDLK_RIGHT) {
1114 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1240 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1115 } elsif ($sym == SDLK_HOME) { 1241 } elsif ($sym == CFClient::SDLK_HOME) {
1116 $self->{cursor} = 0; 1242 $self->{cursor} = 0;
1117 } elsif ($sym == SDLK_END) { 1243 } elsif ($sym == CFClient::SDLK_END) {
1118 $self->{cursor} = length $text; 1244 $self->{cursor} = length $text;
1119 } elsif ($sym == SDLK_ESCAPE) { 1245 } elsif ($sym == 27) {
1120 $self->emit ('escape'); 1246 $self->emit ('escape');
1121 } elsif ($uni) { 1247 } elsif ($uni) {
1122 substr $text, $self->{cursor}++, 0, chr $uni; 1248 substr $text, $self->{cursor}++, 0, chr $uni;
1123 } 1249 }
1124 1250
1179 1305
1180 $self->SUPER::_draw; 1306 $self->SUPER::_draw;
1181 1307
1182 #TODO: force update every cursor change :( 1308 #TODO: force update every cursor change :(
1183 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { 1309 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) {
1310
1311 unless (exists $self->{cur_h}) {
1312 my $text = substr $self->{text}, 0, $self->{cursor};
1313 utf8::encode $text;
1314
1315 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text)
1316 }
1317
1184 glColor @{$self->{fg}}; 1318 glColor @{$self->{fg}};
1185 glBegin GL_LINES; 1319 glBegin GL_LINES;
1186 glVertex $self->{cur_x}, $self->{cur_y};
1187 glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; 1320 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy};
1321 glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
1188 glEnd; 1322 glEnd;
1189 } 1323 }
1190} 1324}
1191 1325
1192package CFClient::UI::LineEntry; 1326package CFClient::UI::Entry;
1193 1327
1194our @ISA = CFClient::UI::Entry::; 1328our @ISA = CFClient::UI::EntryBase::;
1195 1329
1196use SDL; 1330use CFClient::OpenGL;
1197use SDL::OpenGL;
1198 1331
1199sub key_down { 1332sub key_down {
1200 my ($self, $ev) = @_; 1333 my ($self, $ev) = @_;
1201 1334
1202 my $sym = $ev->key_sym; 1335 my $sym = $ev->{sym};
1203 1336
1204 if ($sym == SDLK_RETURN) { 1337 if ($sym == 13) {
1205 $self->emit (activate => $self->get_text); 1338 $self->emit (activate => $self->get_text);
1206 $self->update; 1339 $self->update;
1207 1340
1208 } else { 1341 } else {
1209 $self->SUPER::key_down ($ev); 1342 $self->SUPER::key_down ($ev);
1215 1348
1216package CFClient::UI::Button; 1349package CFClient::UI::Button;
1217 1350
1218our @ISA = CFClient::UI::Label::; 1351our @ISA = CFClient::UI::Label::;
1219 1352
1220use SDL; 1353use CFClient::OpenGL;
1221use SDL::OpenGL;
1222 1354
1223my @tex = 1355my @tex =
1224 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1356 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1225 qw(b1_button_active.png); 1357 qw(b1_button_active.png);
1226 1358
1227sub new { 1359sub new {
1228 my $class = shift; 1360 my $class = shift;
1229 1361
1230 $class->SUPER::new ( 1362 $class->SUPER::new (
1231 padding => 4, 1363 padding => 4,
1232 fg => [1, 1, 1], 1364 fg => [1, 1, 1],
1233 bg => [1, 1, 1, 0.2], 1365 bg => [1, 1, 1, 0.2],
1234 active_fg => [1, 1, 0], 1366 active_fg => [0, 0, 1],
1235 can_hover => 1, 1367 can_hover => 1,
1368 align => 0,
1369 valign => 0,
1236 @_ 1370 @_
1237 ) 1371 )
1238} 1372}
1239 1373
1240sub button_up { 1374sub button_up {
1248 1382
1249sub _draw { 1383sub _draw {
1250 my ($self) = @_; 1384 my ($self) = @_;
1251 1385
1252 local $self->{fg} = $self->{fg}; 1386 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 1387
1259 if ($GRAB == $self) { 1388 if ($GRAB == $self) {
1260 $self->{fg} = $self->{active_fg}; 1389 $self->{fg} = $self->{active_fg};
1261 } 1390 }
1262 1391
1263 glBindTexture GL_TEXTURE_2D, $tex->{name}; 1392 glEnable GL_BLEND;
1393 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1394 glEnable GL_TEXTURE_2D;
1264 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1395 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1396 glColor 0, 0, 0, 1;
1265 1397
1266 $tex->draw_quad (0, 0, $self->{w}, $self->{h}); 1398 $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h});
1267 1399
1268 glDisable GL_TEXTURE_2D; 1400 glDisable GL_TEXTURE_2D;
1269 glDisable GL_BLEND; 1401 glDisable GL_BLEND;
1270 1402
1271 $self->SUPER::_draw; 1403 $self->SUPER::_draw;
1276package CFClient::UI::CheckBox; 1408package CFClient::UI::CheckBox;
1277 1409
1278our @ISA = CFClient::UI::DrawBG::; 1410our @ISA = CFClient::UI::DrawBG::;
1279 1411
1280my @tex = 1412my @tex =
1281 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1413 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1282 qw(c1_checkbox_bg.png c1_checkbox_active.png); 1414 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1283 1415
1284use SDL; 1416use CFClient::OpenGL;
1285use SDL::OpenGL;
1286 1417
1287sub new { 1418sub new {
1288 my $class = shift; 1419 my $class = shift;
1289 1420
1290 $class->SUPER::new ( 1421 $class->SUPER::new (
1301 my ($self) = @_; 1432 my ($self) = @_;
1302 1433
1303 ($self->{padding} * 2 + 6) x 2 1434 ($self->{padding} * 2 + 6) x 2
1304} 1435}
1305 1436
1306sub size_allocate {
1307 my ($self, $x, $y, $w, $h) = @_;
1308
1309 $self->_size_allocate ($x, $y, $w, $h);
1310}
1311
1312sub button_down { 1437sub button_down {
1313 my ($self, $ev, $x, $y) = @_; 1438 my ($self, $ev, $x, $y) = @_;
1314 1439
1315 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} 1440 if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding}
1316 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { 1441 && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) {
1342 glDisable GL_BLEND; 1467 glDisable GL_BLEND;
1343} 1468}
1344 1469
1345############################################################################# 1470#############################################################################
1346 1471
1472package CFClient::UI::Image;
1473
1474our @ISA = CFClient::UI::Base::;
1475
1476use CFClient::OpenGL;
1477use Carp qw/confess/;
1478
1479our %loaded_images;
1480
1481sub new {
1482 my $class = shift;
1483
1484 my $self = $class->SUPER::new (@_);
1485
1486 $self->{image} or confess "Image has 'image' not set. This is a fatal error!";
1487
1488 $loaded_images{$self->{image}} ||=
1489 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1490
1491 my $tex = $self->{tex} = $loaded_images{$self->{image}};
1492
1493 Scalar::Util::weaken $loaded_images{$self->{image}};
1494
1495 $self->{aspect} = $tex->{w} / $tex->{h};
1496
1497 $self
1498}
1499
1500sub size_request {
1501 my ($self) = @_;
1502
1503 ($self->{tex}->{w}, $self->{tex}->{h})
1504}
1505
1506sub _draw {
1507 my ($self) = @_;
1508
1509 my $tex = $self->{tex};
1510
1511 my ($w, $h) = ($self->{w}, $self->{h});
1512
1513 if ($self->{rot90}) {
1514 glRotate 90, 0, 0, 1;
1515 glTranslate 0, -$self->{w}, 0;
1516
1517 ($w, $h) = ($h, $w);
1518 }
1519
1520 glEnable GL_BLEND;
1521 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1522 glEnable GL_TEXTURE_2D;
1523 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1524
1525 $tex->draw_quad (0, 0, $w, $h);
1526
1527 glDisable GL_BLEND;
1528 glDisable GL_TEXTURE_2D;
1529}
1530
1531#############################################################################
1532
1533package CFClient::UI::VGauge;
1534
1535our @ISA = CFClient::UI::Base::;
1536
1537use CFClient::OpenGL;
1538
1539my %tex = (
1540 food => [
1541 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1542 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1543 ],
1544 grace => [
1545 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1546 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1547 ],
1548 hp => [
1549 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1550 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1551 ],
1552 mana => [
1553 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1554 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1555 ],
1556);
1557
1558# eg. VGauge->new (gauge => 'food'), default gauge: food
1559sub new {
1560 my $class = shift;
1561
1562 my $self = $class->SUPER::new (
1563 type => 'food',
1564 @_
1565 );
1566
1567 $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h};
1568
1569 $self
1570}
1571
1572sub size_request {
1573 my ($self) = @_;
1574
1575 #my $tex = $tex{$self->{type}}[0];
1576 #@$tex{qw(w h)}
1577 (0, 0)
1578}
1579
1580sub set_max {
1581 my ($self, $max) = @_;
1582
1583 $self->{max_val} = $max;
1584}
1585
1586sub set_value {
1587 my ($self, $val, $max) = @_;
1588
1589 $self->set_max ($max)
1590 if defined $max;
1591
1592 $max = $self->{max_val};
1593 $self->{val} = $val;
1594
1595 $self->update;
1596}
1597
1598sub _draw {
1599 my ($self) = @_;
1600
1601 my $tex = $tex{$self->{type}};
1602
1603 my ($w, $h) = ($self->{w}, $self->{h});
1604
1605 if ($self->{vertical}) {
1606 glRotate 90, 0, 0, 1;
1607 glTranslate 0, -$self->{w}, 0;
1608
1609 ($w, $h) = ($h, $w);
1610 }
1611
1612 my $ycut = $self->{val} / ($self->{max_val} || 1);
1613 $ycut = 1 if $self->{val} > $self->{max_val};
1614
1615 my $t1 = $tex->[0];
1616 my $t2 = $tex->[1];
1617
1618 glEnable GL_BLEND;
1619 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1620 glEnable GL_TEXTURE_2D;
1621 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1622
1623 my $h1 = $self->{h} - $ycut * $self->{h};
1624 my $h2 = $ycut * $self->{h};
1625
1626 glBindTexture GL_TEXTURE_2D, $t1->{name};
1627 glBegin GL_QUADS;
1628 glTexCoord 0 , 0; glVertex 0 , 0;
1629 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1;
1630 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1;
1631 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1632 glEnd;
1633
1634 glBindTexture GL_TEXTURE_2D, $t2->{name};
1635 glBegin GL_QUADS;
1636 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1;
1637 glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2;
1638 glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2;
1639 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1;
1640 glEnd;
1641
1642 glDisable GL_BLEND;
1643 glDisable GL_TEXTURE_2D;
1644}
1645
1646#############################################################################
1647
1648package CFClient::UI::Gauge;
1649
1650our @ISA = CFClient::UI::VBox::;
1651
1652sub new {
1653 my ($class, %arg) = shift;
1654
1655 my $self = $class->SUPER::new (
1656 @_,
1657 );
1658
1659 $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999");
1660 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1);
1661 $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999");
1662
1663 $self
1664}
1665
1666sub set_fontsize {
1667 my ($self, $fsize) = @_;
1668
1669 $self->{value}->set_fontsize ($fsize);
1670 $self->{max} ->set_fontsize ($fsize);
1671}
1672
1673sub set_value {
1674 my ($self, $val, $max) = @_;
1675
1676 $self->set_max ($max)
1677 if defined $max;
1678
1679 $self->{gauge}->set_value ($val, $max);
1680 $self->{value}->set_text ($val);
1681}
1682
1683sub set_max {
1684 my ($self, $max) = @_;
1685
1686 $self->{gauge}->set_max ($max);
1687 $self->{max}->set_text ($max);
1688}
1689
1690#############################################################################
1691
1347package CFClient::UI::Slider; 1692package CFClient::UI::Slider;
1348 1693
1349use strict; 1694use strict;
1350 1695
1351use SDL::OpenGL; 1696use CFClient::OpenGL;
1352 1697
1353our @ISA = CFClient::UI::DrawBG::; 1698our @ISA = CFClient::UI::DrawBG::;
1354 1699
1355my @tex = 1700my @tex =
1356 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1701 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1366 # TODO: calculations are off 1711 # TODO: calculations are off
1367 my $self = $class->SUPER::new ( 1712 my $self = $class->SUPER::new (
1368 fg => [1, 1, 1], 1713 fg => [1, 1, 1],
1369 active_fg => [0, 0, 0], 1714 active_fg => [0, 0, 0],
1370 range => [0, 0, 100, 10], 1715 range => [0, 0, 100, 10],
1371 req_w => 40, 1716 req_w => 20,
1372 req_h => 13, 1717 req_h => 20,
1373 vertical => 0, 1718 vertical => 0,
1374 can_hover => 1, 1719 can_hover => 1,
1375 inner_pad => 5, 1720 inner_pad => 5,
1376 @_ 1721 @_
1377 ); 1722 );
1481 1826
1482package CFClient::UI::TextView; 1827package CFClient::UI::TextView;
1483 1828
1484our @ISA = CFClient::UI::HBox::; 1829our @ISA = CFClient::UI::HBox::;
1485 1830
1486use SDL::OpenGL; 1831use CFClient::OpenGL;
1487 1832
1488sub new { 1833sub new {
1489 my $class = shift; 1834 my $class = shift;
1490 1835
1491 my $self = $class->SUPER::new ( 1836 my $self = $class->SUPER::new (
1492 req_w => $::WIDTH / 6,
1493 req_h => $::HEIGHT / 6,
1494 fontsize => $::FONTSIZE, 1837 fontsize => 1,
1495 @_, 1838 @_,
1496 1839
1497 layout => (new CFClient::Layout), 1840 layout => (new CFClient::Layout),
1498 par => [], 1841 par => [],
1499 height => 0, 1842 height => 0,
1520sub text_height { 1863sub text_height {
1521 my ($self, $text) = @_; 1864 my ($self, $text) = @_;
1522 1865
1523 my $layout = $self->{layout}; 1866 my $layout = $self->{layout};
1524 1867
1525 $layout->set_height ($self->{fontsize}); 1868 $layout->set_height ($self->{fontsize} * $::FONTSIZE);
1526 $layout->set_width ($self->{w}); 1869 $layout->set_width ($self->{w});
1527 $layout->set_text ($text); 1870 $layout->set_text ($text);
1528 1871
1529 ($layout->size)[1] 1872 ($layout->size)[1]
1530} 1873}
1534 1877
1535 $self->{need_reflow}++; 1878 $self->{need_reflow}++;
1536 $self->update; 1879 $self->update;
1537} 1880}
1538 1881
1539sub size_request {
1540 my ($self) = @_;
1541
1542 ($self->{req_w}, $self->{req_h})
1543}
1544
1545sub size_allocate { 1882sub size_allocate {
1546 my ($self, $x, $y, $w, $h) = @_; 1883 my ($self, $w, $h) = @_;
1547 1884
1548 $self->SUPER::size_allocate ($x, $y, $w, $h); 1885 $self->SUPER::size_allocate ($w, $h);
1549 1886
1550 $self->{layout}->set_height ($self->{fontsize}); 1887 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1551 $self->{layout}->set_width ($self->{w}); 1888 $self->{layout}->set_width ($self->{children}[0]{w});
1552 1889
1553 $self->reflow; 1890 $self->reflow;
1554} 1891}
1555 1892
1556sub add_paragraph { 1893sub add_paragraph {
1575 1912
1576 return unless $self->{h} > 0; 1913 return unless $self->{h} > 0;
1577 1914
1578 delete $self->{texture}; 1915 delete $self->{texture};
1579 1916
1580 $TOPLEVEL->on_refresh ($self, sub { 1917 $ROOT->on_refresh ($self, sub {
1581 if (delete $self->{need_reflow}) { 1918 if (delete $self->{need_reflow}) {
1582 my $height = 0; 1919 my $height = 0;
1583 1920
1584 $height += $_->[0] = $self->text_height ($_->[2]) 1921 $height += $_->[0] = $self->text_height ($_->[2])
1585 for @{$self->{par}}; 1922 for @{$self->{par}};
1643 1980
1644} 1981}
1645 1982
1646############################################################################# 1983#############################################################################
1647 1984
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; 1985package CFClient::UI::Animator;
1883 1986
1884use SDL::OpenGL; 1987use CFClient::OpenGL;
1885 1988
1886our @ISA = CFClient::UI::Bin::; 1989our @ISA = CFClient::UI::Bin::;
1887 1990
1888sub moveto { 1991sub moveto {
1889 my ($self, $x, $y) = @_; 1992 my ($self, $x, $y) = @_;
1945sub toggle_flopper { 2048sub toggle_flopper {
1946 my ($self) = @_; 2049 my ($self) = @_;
1947 2050
1948 # TODO: use animation 2051 # TODO: use animation
1949 if ($self->{state} = !$self->{state}) { 2052 if ($self->{state} = !$self->{state}) {
1950 $CFClient::UI::TOPLEVEL->add ($self->{other}); 2053 $CFClient::UI::ROOT->add ($self->{other});
1951 $self->{other}->move ( 2054 $self->{other}->move ($self->coord2global (0, $self->{h}));
1952 ($::WIDTH - $self->{other}{w}) * 0.5, 2055 $self->emit ("open");
1953 ($::HEIGHT - $self->{other}{h}) * 0.5,
1954 );
1955 } else { 2056 } else {
1956 $CFClient::UI::TOPLEVEL->remove ($self->{other}); 2057 $CFClient::UI::ROOT->remove ($self->{other});
2058 $self->emit ("close");
1957 } 2059 }
1958}
1959 2060
1960############################################################################# 2061 $self->emit (changed => $self->{state});
2062}
1961 2063
2064#############################################################################
2065
1962package CFClient::UI::Toplevel; 2066package CFClient::UI::Root;
1963 2067
1964our @ISA = CFClient::UI::Container::; 2068our @ISA = CFClient::UI::Container::;
1965 2069
1966use SDL::OpenGL; 2070use CFClient::OpenGL;
2071
2072sub check_size {
2073 my ($self) = @_;
2074
2075 $self->configure (0, 0, $::WITH, $::HEIGHT);
2076}
1967 2077
1968sub size_request { 2078sub size_request {
1969 ($::WIDTH, $::HEIGHT) 2079 ($::WIDTH, $::HEIGHT)
1970} 2080}
1971 2081
1972sub size_allocate { 2082sub configure {
1973 my ($self, $x, $y, $w, $h) = @_; 2083 my ($self, $x, $y, $w, $h) = @_;
1974 2084
1975 $self->_size_allocate ($x, $y, $w, $h); 2085 $self->SUPER::configure ($x, $y, $w, $h);
1976 2086
1977 $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) 2087 $_->configure ($_->{x}, $_->{y}, $_->size_request)
1978 for @{$self->{children}}; 2088 for @{$self->{children}};
1979} 2089}
1980 2090
1981sub translate { 2091sub _topleft {
1982 my ($self, $x, $y) = @_; 2092 my ($self, $x, $y) = @_;
1983 2093
1984 ($x, $y) 2094 ($x, $y)
1985} 2095}
1986 2096
1987sub update { 2097sub update {
1988 my ($self) = @_; 2098 my ($self) = @_;
1989 2099
1990 $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); 2100 $self->check_size;
1991 ::refresh (); 2101 ::refresh ();
1992} 2102}
1993 2103
1994sub add { 2104sub add {
1995 my ($self, $widget) = @_; 2105 my ($self, $child) = @_;
1996 2106
2107 # integerize window positions
2108 $child->{x} = int $child->{x};
2109 $child->{y} = int $child->{y};
2110
1997 $self->SUPER::add ($widget); 2111 $self->SUPER::add ($child);
1998
1999 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request);
2000} 2112}
2001 2113
2002sub on_refresh { 2114sub on_refresh {
2003 my ($self, $id, $cb) = @_; 2115 my ($self, $id, $cb) = @_;
2004 2116
2027 2139
2028############################################################################# 2140#############################################################################
2029 2141
2030package CFClient::UI; 2142package CFClient::UI;
2031 2143
2032$TOPLEVEL = new CFClient::UI::Toplevel; 2144$ROOT = new CFClient::UI::Root;
2033 2145
20341 21461
2035 2147

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines