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.39 by root, Sun Apr 9 21:39:08 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines