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.37 by root, Sun Apr 9 21:05:50 2006 UTC vs.
Revision 1.40 by root, Sun Apr 9 21:41:11 2006 UTC

37 Carp::confess "size_request is abtract"; 37 Carp::confess "size_request is abtract";
38} 38}
39 39
40sub size_allocate { 40sub size_allocate {
41 my ($self, $w, $h) = @_; 41 my ($self, $w, $h) = @_;
42
42 $self->w ($w); 43 $self->{w} = $w;
43 $self->h ($h); 44 $self->{h} = $h;
44} 45}
45 46
46sub focus_in { 47sub focus_in {
47 my ($widget) = @_; 48 my ($widget) = @_;
48 $FOCUS = $widget; 49 $FOCUS = $widget;
82 $self->_draw; 83 $self->_draw;
83 glPopMatrix; 84 glPopMatrix;
84} 85}
85 86
86sub _draw { 87sub _draw {
87 my ($widget) = @_; 88 my ($self) = @_;
89
90 warn "no draw defined for $self\n";
88} 91}
89 92
90sub bbox { 93sub bbox {
91 my ($self) = @_; 94 my ($self) = @_;
92 my ($w, $h) = $self->size_request; 95 my ($w, $h) = $self->size_request;
96 $self->{x} = $w, 99 $self->{x} = $w,
97 $self->{y} = $h 100 $self->{y} = $h
98 ) 101 )
99} 102}
100 103
104sub find_widget {
105 my ($self, $x, $y) = @_;
106
107 return $self
108 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
109 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
110
111 ()
112}
113
101sub del_parent { $_[0]->{parent} = undef } 114sub del_parent { $_[0]->{parent} = undef }
102 115
103sub set_parent { 116sub set_parent {
104 my ($self, $par) = @_; 117 my ($self, $par) = @_;
105 118
122 my ($self) = @_; 135 my ($self) = @_;
123 136
124 #$self->deactivate; 137 #$self->deactivate;
125} 138}
126 139
140#############################################################################
141
142package Crossfire::Client::Widget::Container;
143
144our @ISA = Crossfire::Client::Widget::;
145
146sub new {
147 my ($class, @widgets) = @_;
148
149 my $self = $class->SUPER::new (children => []);
150 $self->add ($_) for @widgets;
151
152 $self
153}
154
155sub add {
156 my ($self, $chld, $expand) = @_;
157
158 $chld->{expand} = $expand;
159 $chld->set_parent ($self);
160
161 @{$self->{children}} =
162 sort { $a->{z} <=> $b->{z} }
163 @{$self->{children}}, $chld;
164
165 $self->size_allocate ($self->{w}, $self->{h});
166}
167
168sub remove {
169 my ($self, $widget) = @_;
170
171 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ];
172
173 $self->size_allocate ($self->{w}, $self->{h});
174}
175
176sub find_widget {
177 my ($self, $x, $y) = @_;
178
179 my $res;
180
181 for (@{ $self->{children} }) {
182 $res = $_->find_widget ($x, $y)
183 and return $res;
184 }
185
186 ()
187}
188
189sub size_request {
190 my ($self) = @_;
191
192 my ($hs, $ws) = (0, 0);
193 for (@{$self->{children} || []}) {
194 my ($w, $h) = $_->size_request;
195 $hs += $h;
196 if ($ws < $w) { $ws = $w }
197 }
198
199 return ($ws, $hs);
200}
201
202sub _draw {
203 my ($self) = @_;
204
205 $_->draw for @{$self->{children}};
206}
207
208#############################################################################
209
127package Crossfire::Client::Widget::Bin; 210package Crossfire::Client::Widget::Bin;
128 211
129our @ISA = Crossfire::Client::Widget::; 212our @ISA = Crossfire::Client::Widget::Container::;
130 213
131sub add { $_[0]->{child} = $_[1]; $_[1]->set_parent ($_[0]); $_[1]->{expand} = $_[2] }
132sub get { $_[0]->{child} } 214sub child { $_[0]->{children}[0] }
133
134sub remove {
135 my ($self, $chld) = @_;
136 delete $self->{child}
137 if $self->{child} == $chld;
138}
139 215
140sub size_request { 216sub size_request {
141 $_[0]->{child}->size_request if $_[0]->{child} 217 $_[0]{children}[0]->size_request if $_[0]{children}[0];
142} 218}
219
143sub size_allocate { 220sub size_allocate {
144 my ($self, $w, $h) = @_; 221 my ($self, $w, $h) = @_;
145 $self->SUPER::size_allocate ($w, $h); 222 $self->SUPER::size_allocate ($w, $h);
146 $self->{child}->size_allocate ($w, $h) 223 $self->{children}[0]->size_allocate ($w, $h)
147 if $self->{child} 224 if $self->{children}[0]
148} 225}
149 226
150sub _draw { 227#############################################################################
151 my ($self) = @_;
152
153 $self->{child}->draw;
154}
155 228
156package Crossfire::Client::Widget::Toplevel; 229package Crossfire::Client::Widget::Toplevel;
157 230
158our @ISA = Crossfire::Client::Widget::; 231our @ISA = Crossfire::Client::Widget::Container::;
159
160use SDL::OpenGL;
161
162sub add {
163 my ($self, $chld) = @_;
164
165 push @{$self->{childs}}, $chld;
166 @{$self->{childs}} =
167 sort { $a->{z} <=> $b->{z} }
168 @{$self->{childs}};
169
170 $chld->set_parent ($self);
171 $chld->size_allocate ($chld->size_request);
172}
173
174sub remove {
175 my ($self, $chld) = @_;
176 @{$self->{childs}} =
177 sort { $a->{z} <=> $b->{z} }
178 grep { $_ && $_ != $_[0] }
179 @{$self->{childs}}
180}
181 232
182sub update { 233sub update {
183 my ($self) = @_; 234 my ($self) = @_;
235
184 ::refresh (); 236 ::refresh ();
185} 237}
186 238
187sub _draw { 239#############################################################################
188 my ($self) = @_;
189
190 $_->draw for @{$self->{childs}};
191}
192 240
193package Crossfire::Client::Widget::Window; 241package Crossfire::Client::Widget::Window;
194 242
195our @ISA = Crossfire::Client::Widget::Bin::; 243our @ISA = Crossfire::Client::Widget::Bin::;
196 244
266 314
267 glDisable GL_BLEND; 315 glDisable GL_BLEND;
268 glDisable GL_TEXTURE_2D; 316 glDisable GL_TEXTURE_2D;
269} 317}
270 318
319#############################################################################
320
271package Crossfire::Client::Widget::Frame; 321package Crossfire::Client::Widget::Frame;
272 322
273our @ISA = Crossfire::Client::Widget::Bin::; 323our @ISA = Crossfire::Client::Widget::Bin::;
274 324
275use SDL::OpenGL; 325use SDL::OpenGL;
276 326
277sub size_request { 327sub size_request {
278 my ($self) = @_; 328 my ($self) = @_;
279 my $chld = $self->get 329 my $chld = $self->child
280 or return (0, 0); 330 or return (0, 0);
281 331
282 $chld->move (2, 2); 332 $chld->move (2, 2);
283 333
284 map { $_ + 4 } $chld->size_request; 334 map { $_ + 4 } $chld->size_request;
288 my ($self, $w, $h) = @_; 338 my ($self, $w, $h) = @_;
289 339
290 $self->w ($w); 340 $self->w ($w);
291 $self->h ($h); 341 $self->h ($h);
292 342
293 $self->get->size_allocate ($w - 4, $h - 4); 343 $self->child->size_allocate ($w - 4, $h - 4);
294 $self->get->move (2, 2); 344 $self->child->move (2, 2);
295} 345}
296 346
297sub _draw { 347sub _draw {
298 my ($self) = @_; 348 my ($self) = @_;
299 349
300 my $chld = $self->get; 350 my $chld = $self->child;
301 351
302 my ($w, $h) = $chld->size_request; 352 my ($w, $h) = $chld->size_request;
303 353
304 glBegin GL_QUADS; 354 glBegin GL_QUADS;
305 glColor 0, 0, 0; 355 glColor 0, 0, 0;
310 glEnd; 360 glEnd;
311 361
312 $chld->draw; 362 $chld->draw;
313} 363}
314 364
365#############################################################################
366
315package Crossfire::Client::Widget::FancyFrame; 367package Crossfire::Client::Widget::FancyFrame;
316 368
317our @ISA = Crossfire::Client::Widget::Frame::; 369our @ISA = Crossfire::Client::Widget::Frame::;
318 370
319use SDL::OpenGL; 371use SDL::OpenGL;
322 my ($self, $theme) = @_; 374 my ($self, $theme) = @_;
323 $self = $self->SUPER::new; 375 $self = $self->SUPER::new;
324 376
325 $self->{txts} = [ 377 $self->{txts} = [
326 map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } 378 map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ }
327 qw/d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png/ 379 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png)
328 ]; 380 ];
329 $self 381 $self
330} 382}
331 383
332sub size_request { 384sub size_request {
333 my ($self) = @_; 385 my ($self) = @_;
386
334 my ($w, $h) = $self->get->size_request; 387 my ($w, $h) = $self->SUPER::size_request;
335 388
336 $h += $self->{txts}->[1]->{height}; 389 $h += $self->{txts}->[1]->{height};
337 $h += $self->{txts}->[4]->{height}; 390 $h += $self->{txts}->[4]->{height};
338 $w += $self->{txts}->[2]->{width}; 391 $w += $self->{txts}->[2]->{width};
339 $w += $self->{txts}->[3]->{width}; 392 $w += $self->{txts}->[3]->{width};
342} 395}
343 396
344sub size_allocate { 397sub size_allocate {
345 my ($self, $w, $h) = @_; 398 my ($self, $w, $h) = @_;
346 399
347 $self->w ($w); 400 $self->SUPER::size_allocate ($w, $h);
348 $self->h ($h); 401
349 $h -= $self->{txts}->[1]->{height}; 402 $h -= $self->{txts}->[1]->{height};
350 $h -= $self->{txts}->[4]->{height}; 403 $h -= $self->{txts}->[4]->{height};
351 $w -= $self->{txts}->[2]->{width}; 404 $w -= $self->{txts}->[2]->{width};
352 $w -= $self->{txts}->[3]->{width}; 405 $w -= $self->{txts}->[3]->{width};
353 406
354 $h = $h < 0 ? 0 : $h; 407 $h = $h < 0 ? 0 : $h;
355 $w = $w < 0 ? 0 : $w; 408 $w = $w < 0 ? 0 : $w;
356 warn "CHILD:$w $h\n"; 409 warn "CHILD:$w $h\n";
357 $self->get->size_allocate ($w, $h); 410 $self->child->size_allocate ($w, $h);
358 $self->get->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); 411 $self->child->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height});
359} 412}
360 413
361sub _draw { 414sub _draw {
362 my ($self) = @_; 415 my ($self) = @_;
363 416
364 my ($w, $h) = ($self->w, $self->h); 417 my ($w, $h) = ($self->w, $self->h);
365 my ($cw, $ch) = ($self->get->w, $self->get->h); 418 my ($cw, $ch) = ($self->child->w, $self->child->h);
366 419
367 glEnable GL_BLEND; 420 glEnable GL_BLEND;
368 glEnable GL_TEXTURE_2D; 421 glEnable GL_TEXTURE_2D;
369 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 422 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
370 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 423 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
426 glEnd; 479 glEnd;
427 480
428 glDisable GL_BLEND; 481 glDisable GL_BLEND;
429 glDisable GL_TEXTURE_2D; 482 glDisable GL_TEXTURE_2D;
430 483
431 $self->get->draw; 484 $self->child->draw;
432 485
433} 486}
487
488#############################################################################
434 489
435package Crossfire::Client::Widget::Table; 490package Crossfire::Client::Widget::Table;
436 491
437our @ISA = Crossfire::Client::Widget::Bin::; 492our @ISA = Crossfire::Client::Widget::Bin::;
438 493
439use SDL::OpenGL; 494use SDL::OpenGL;
440 495
441sub add { 496sub add {
442 my ($self, $x, $y, $chld) = @_; 497 my ($self, $x, $y, $chld) = @_;
443 my $old_chld = $self->{childs}[$y][$x]; 498 my $old_chld = $self->{children}[$y][$x];
444 499
445 $self->{childs}[$y][$x] = $chld; 500 $self->{children}[$y][$x] = $chld;
446 $chld->set_parent ($self); 501 $chld->set_parent ($self);
447 $self->update; 502 $self->update;
448} 503}
449 504
450sub max_row_height { 505sub max_row_height {
451 my ($self, $row) = @_; 506 my ($self, $row) = @_;
452 507
453 my $hs = 0; 508 my $hs = 0;
454 for (my $xi = 0; $xi <= $#{$self->{childs}->[$row] || []}; $xi++) { 509 for (my $xi = 0; $xi <= $#{$self->{children}->[$row] || []}; $xi++) {
455 my $c = $self->{childs}->[$row]->[$xi]; 510 my $c = $self->{children}->[$row]->[$xi];
456 if ($c) { 511 if ($c) {
457 my ($w, $h) = $c->size_request; 512 my ($w, $h) = $c->size_request;
458 if ($hs < $h) { $hs = $h } 513 if ($hs < $h) { $hs = $h }
459 } 514 }
460 } 515 }
463 518
464sub max_col_width { 519sub max_col_width {
465 my ($self, $col) = @_; 520 my ($self, $col) = @_;
466 521
467 my $ws = 0; 522 my $ws = 0;
468 for (my $yi = 0; $yi <= $#{$self->{childs} || []}; $yi++) { 523 for (my $yi = 0; $yi <= $#{$self->{children} || []}; $yi++) {
469 my $c = ($self->{childs}->[$yi] || [])->[$col]; 524 my $c = ($self->{children}->[$yi] || [])->[$col];
470 if ($c) { 525 if ($c) {
471 my ($w, $h) = $c->size_request; 526 my ($w, $h) = $c->size_request;
472 if ($ws < $w) { $ws = $w } 527 if ($ws < $w) { $ws = $w }
473 } 528 }
474 } 529 }
478sub size_request { 533sub size_request {
479 my ($self) = @_; 534 my ($self) = @_;
480 535
481 my ($hs, $ws) = (0, 0); 536 my ($hs, $ws) = (0, 0);
482 537
483 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 538 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) {
484 $hs += $self->max_row_height ($yi); 539 $hs += $self->max_row_height ($yi);
485 } 540 }
486 541
487 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 542 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) {
488 my $wm = 0; 543 my $wm = 0;
489 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { 544 for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) {
490 $wm += $self->max_col_width ($xi) 545 $wm += $self->max_col_width ($xi)
491 } 546 }
492 if ($ws < $wm) { $ws = $wm } 547 if ($ws < $wm) { $ws = $wm }
493 } 548 }
494 549
497 552
498sub _draw { 553sub _draw {
499 my ($self) = @_; 554 my ($self) = @_;
500 555
501 my $y = 0; 556 my $y = 0;
502 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 557 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) {
503 my $x = 0; 558 my $x = 0;
504 559
505 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { 560 for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) {
506 561
507 my $c = $self->{childs}->[$yi]->[$xi]; 562 my $c = $self->{children}->[$yi]->[$xi];
508 if ($c) { 563 if ($c) {
509 $c->move ($x, $y, 0); #TODO: Move to size_request 564 $c->move ($x, $y, 0); #TODO: Move to size_request
510 $c->draw if $c; 565 $c->draw if $c;
511 } 566 }
512 567
515 570
516 $y += $self->max_row_height ($yi); 571 $y += $self->max_row_height ($yi);
517 } 572 }
518} 573}
519 574
575#############################################################################
576
520package Crossfire::Client::Widget::VBox; 577package Crossfire::Client::Widget::VBox;
521 578
522our @ISA = Crossfire::Client::Widget::Bin::; 579our @ISA = Crossfire::Client::Widget::Container::;
523 580
524use SDL::OpenGL; 581use SDL::OpenGL;
525
526sub add {
527 my ($self, $chld, $expand) = @_;
528 push @{$self->{childs}}, $chld;
529 $chld->{expand} = $expand;
530 $chld->set_parent ($self);
531 $self->update;
532}
533
534sub size_request {
535 my ($self) = @_;
536
537 my ($hs, $ws) = (0, 0);
538 for (@{$self->{childs} || []}) {
539 my ($w, $h) = $_->size_request;
540 $hs += $h;
541 if ($ws < $w) { $ws = $w }
542 }
543
544 return ($ws, $hs);
545}
546 582
547sub size_allocate { 583sub size_allocate {
548 my ($self, $w, $h) = @_; 584 my ($self, $w, $h) = @_;
549 585
550 $self->w ($w); 586 $self->w ($w);
551 $self->h ($h); 587 $self->h ($h);
552 588
553 my $exp; 589 my $exp;
554 my @oth; 590 my @oth;
555 # find expand widget 591 # find expand widget
556 for (@{$self->{childs}}) { 592 for (@{$self->{children}}) {
557 if ($_->{expand}) { 593 if ($_->{expand}) {
558 $exp = $_; 594 $exp = $_;
559 last; 595 last;
560 } 596 }
561 push @oth, $_; 597 push @oth, $_;
569 $oh += $h; 605 $oh += $h;
570 if ($ow < $w) { $ow = $w } 606 if ($ow < $w) { $ow = $w }
571 } 607 }
572 608
573 my $y = 0; 609 my $y = 0;
574 for (@{$self->{childs}}) { 610 for (@{$self->{children}}) {
575 $_->move (0, $y); 611 $_->move (0, $y);
576 612
577 if ($_ == $exp) { 613 if ($_ == $exp) {
578 $_->size_allocate ($w, $h - $oh); 614 $_->size_allocate ($w, $h - $oh);
579 $y += $h - $oh; 615 $y += $h - $oh;
587 623
588sub _draw { 624sub _draw {
589 my ($self) = @_; 625 my ($self) = @_;
590 626
591 my ($x, $y); 627 my ($x, $y);
592 for (@{$self->{childs} || []}) { 628 for (@{$self->{children} || []}) {
593 $_->draw; 629 $_->draw;
594 $y += $_->h; 630 $y += $_->h;
595 } 631 }
596} 632}
633
634#############################################################################
597 635
598package Crossfire::Client::Widget::Label; 636package Crossfire::Client::Widget::Label;
599 637
600our @ISA = Crossfire::Client::Widget::; 638our @ISA = Crossfire::Client::Widget::;
601 639
658 696
659 glDisable GL_BLEND; 697 glDisable GL_BLEND;
660 glDisable GL_TEXTURE_2D; 698 glDisable GL_TEXTURE_2D;
661} 699}
662 700
701#############################################################################
702
663package Crossfire::Client::Widget::TextEntry; 703package Crossfire::Client::Widget::TextEntry;
664 704
665our @ISA = Crossfire::Client::Widget::Label::; 705our @ISA = Crossfire::Client::Widget::Label::;
666 706
667use SDL; 707use SDL;
684 } elsif ($uni) { 724 } elsif ($uni) {
685 $text .= chr $uni; 725 $text .= chr $uni;
686 } 726 }
687 $self->set_text ($text); 727 $self->set_text ($text);
688} 728}
729
730#############################################################################
689 731
690package Crossfire::Client::Widget::MapWidget; 732package Crossfire::Client::Widget::MapWidget;
691 733
692use strict; 734use strict;
693 735
860 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { 902 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
861 $::CONN->send ("command run_stop"); 903 $::CONN->send ("command run_stop");
862 } 904 }
863} 905}
864 906
907#############################################################################
908
865package Crossfire::Client::Widget::Animator; 909package Crossfire::Client::Widget::Animator;
866 910
867use SDL::OpenGL; 911use SDL::OpenGL;
868 912
869our @ISA = Crossfire::Client::Widget::Bin::; 913our @ISA = Crossfire::Client::Widget::Bin::;
896sub _draw { 940sub _draw {
897 my ($self) = @_; 941 my ($self) = @_;
898 942
899 glPushMatrix; 943 glPushMatrix;
900 glRotate $self->{time} * 10000, 0, 1, 0; 944 glRotate $self->{time} * 10000, 0, 1, 0;
901 $self->{child}->draw; 945 $self->{children}[0]->draw;
902 glPopMatrix; 946 glPopMatrix;
903} 947}
904 948
9051; 9491;
906 950

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines