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.38 by root, Sun Apr 9 21:34:49 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
139package Crossfire::Client::Widget::Container;
140
141our @ISA = Crossfire::Client::Widget::;
142
143sub new {
144 my ($class, @widgets) = @_;
145
146 my $self = $class->SUPER::new (children => []);
147 $self->add ($_) for @widgets;
148
149 $self
150}
151
152sub add {
153 my ($self, $chld, $expand) = @_;
154
155 $chld->{expand} = $expand;
156 $chld->set_parent ($self);
157
158 @{$self->{children}} =
159 sort { $a->{z} <=> $b->{z} }
160 @{$self->{children}}, $chld;
161
162 $self->size_allocate ($self->{w}, $self->{h});
163}
164
165sub remove {
166 my ($self, $widget) = @_;
167
168 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ];
169
170 $self->size_allocate ($self->{w}, $self->{h});
171}
172
173sub find_widget {
174 my ($self, $x, $y) = @_;
175
176 my $res;
177
178 for (@{ $self->{children} }) {
179 $res = $_->find_widget ($x, $y)
180 and return $res;
181 }
182
183 ()
184}
185
186sub size_request {
187 my ($self) = @_;
188
189 my ($hs, $ws) = (0, 0);
190 for (@{$self->{children} || []}) {
191 my ($w, $h) = $_->size_request;
192 $hs += $h;
193 if ($ws < $w) { $ws = $w }
194 }
195
196 return ($ws, $hs);
197}
198
199sub _draw {
200 my ($self) = @_;
201
202 $_->draw for @{$self->{children}};
203}
204
127package Crossfire::Client::Widget::Bin; 205package Crossfire::Client::Widget::Bin;
128 206
129our @ISA = Crossfire::Client::Widget::; 207our @ISA = Crossfire::Client::Widget::Container::;
130 208
131sub add { $_[0]->{child} = $_[1]; $_[1]->set_parent ($_[0]); $_[1]->{expand} = $_[2] }
132sub get { $_[0]->{child} } 209sub get { $_[0]->{children}[0] }
133
134sub remove {
135 my ($self, $chld) = @_;
136 delete $self->{child}
137 if $self->{child} == $chld;
138}
139 210
140sub size_request { 211sub size_request {
141 $_[0]->{child}->size_request if $_[0]->{child} 212 $_[0]{children}[0]->size_request if $_[0]{children}[0];
142} 213}
214
143sub size_allocate { 215sub size_allocate {
144 my ($self, $w, $h) = @_; 216 my ($self, $w, $h) = @_;
145 $self->SUPER::size_allocate ($w, $h); 217 $self->SUPER::size_allocate ($w, $h);
146 $self->{child}->size_allocate ($w, $h) 218 $self->{children}[0]->size_allocate ($w, $h)
147 if $self->{child} 219 if $self->{children}[0]
148}
149
150sub _draw {
151 my ($self) = @_;
152
153 $self->{child}->draw;
154} 220}
155 221
156package Crossfire::Client::Widget::Toplevel; 222package Crossfire::Client::Widget::Toplevel;
157 223
158our @ISA = Crossfire::Client::Widget::; 224our @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 225
182sub update { 226sub update {
183 my ($self) = @_; 227 my ($self) = @_;
228
184 ::refresh (); 229 ::refresh ();
185}
186
187sub _draw {
188 my ($self) = @_;
189
190 $_->draw for @{$self->{childs}};
191} 230}
192 231
193package Crossfire::Client::Widget::Window; 232package Crossfire::Client::Widget::Window;
194 233
195our @ISA = Crossfire::Client::Widget::Bin::; 234our @ISA = Crossfire::Client::Widget::Bin::;
438 477
439use SDL::OpenGL; 478use SDL::OpenGL;
440 479
441sub add { 480sub add {
442 my ($self, $x, $y, $chld) = @_; 481 my ($self, $x, $y, $chld) = @_;
443 my $old_chld = $self->{childs}[$y][$x]; 482 my $old_chld = $self->{children}[$y][$x];
444 483
445 $self->{childs}[$y][$x] = $chld; 484 $self->{children}[$y][$x] = $chld;
446 $chld->set_parent ($self); 485 $chld->set_parent ($self);
447 $self->update; 486 $self->update;
448} 487}
449 488
450sub max_row_height { 489sub max_row_height {
451 my ($self, $row) = @_; 490 my ($self, $row) = @_;
452 491
453 my $hs = 0; 492 my $hs = 0;
454 for (my $xi = 0; $xi <= $#{$self->{childs}->[$row] || []}; $xi++) { 493 for (my $xi = 0; $xi <= $#{$self->{children}->[$row] || []}; $xi++) {
455 my $c = $self->{childs}->[$row]->[$xi]; 494 my $c = $self->{children}->[$row]->[$xi];
456 if ($c) { 495 if ($c) {
457 my ($w, $h) = $c->size_request; 496 my ($w, $h) = $c->size_request;
458 if ($hs < $h) { $hs = $h } 497 if ($hs < $h) { $hs = $h }
459 } 498 }
460 } 499 }
463 502
464sub max_col_width { 503sub max_col_width {
465 my ($self, $col) = @_; 504 my ($self, $col) = @_;
466 505
467 my $ws = 0; 506 my $ws = 0;
468 for (my $yi = 0; $yi <= $#{$self->{childs} || []}; $yi++) { 507 for (my $yi = 0; $yi <= $#{$self->{children} || []}; $yi++) {
469 my $c = ($self->{childs}->[$yi] || [])->[$col]; 508 my $c = ($self->{children}->[$yi] || [])->[$col];
470 if ($c) { 509 if ($c) {
471 my ($w, $h) = $c->size_request; 510 my ($w, $h) = $c->size_request;
472 if ($ws < $w) { $ws = $w } 511 if ($ws < $w) { $ws = $w }
473 } 512 }
474 } 513 }
478sub size_request { 517sub size_request {
479 my ($self) = @_; 518 my ($self) = @_;
480 519
481 my ($hs, $ws) = (0, 0); 520 my ($hs, $ws) = (0, 0);
482 521
483 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 522 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) {
484 $hs += $self->max_row_height ($yi); 523 $hs += $self->max_row_height ($yi);
485 } 524 }
486 525
487 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 526 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) {
488 my $wm = 0; 527 my $wm = 0;
489 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { 528 for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) {
490 $wm += $self->max_col_width ($xi) 529 $wm += $self->max_col_width ($xi)
491 } 530 }
492 if ($ws < $wm) { $ws = $wm } 531 if ($ws < $wm) { $ws = $wm }
493 } 532 }
494 533
497 536
498sub _draw { 537sub _draw {
499 my ($self) = @_; 538 my ($self) = @_;
500 539
501 my $y = 0; 540 my $y = 0;
502 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 541 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) {
503 my $x = 0; 542 my $x = 0;
504 543
505 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { 544 for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) {
506 545
507 my $c = $self->{childs}->[$yi]->[$xi]; 546 my $c = $self->{children}->[$yi]->[$xi];
508 if ($c) { 547 if ($c) {
509 $c->move ($x, $y, 0); #TODO: Move to size_request 548 $c->move ($x, $y, 0); #TODO: Move to size_request
510 $c->draw if $c; 549 $c->draw if $c;
511 } 550 }
512 551
517 } 556 }
518} 557}
519 558
520package Crossfire::Client::Widget::VBox; 559package Crossfire::Client::Widget::VBox;
521 560
522our @ISA = Crossfire::Client::Widget::Bin::; 561our @ISA = Crossfire::Client::Widget::Container::;
523 562
524use SDL::OpenGL; 563use 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 564
547sub size_allocate { 565sub size_allocate {
548 my ($self, $w, $h) = @_; 566 my ($self, $w, $h) = @_;
549 567
550 $self->w ($w); 568 $self->w ($w);
551 $self->h ($h); 569 $self->h ($h);
552 570
553 my $exp; 571 my $exp;
554 my @oth; 572 my @oth;
555 # find expand widget 573 # find expand widget
556 for (@{$self->{childs}}) { 574 for (@{$self->{children}}) {
557 if ($_->{expand}) { 575 if ($_->{expand}) {
558 $exp = $_; 576 $exp = $_;
559 last; 577 last;
560 } 578 }
561 push @oth, $_; 579 push @oth, $_;
569 $oh += $h; 587 $oh += $h;
570 if ($ow < $w) { $ow = $w } 588 if ($ow < $w) { $ow = $w }
571 } 589 }
572 590
573 my $y = 0; 591 my $y = 0;
574 for (@{$self->{childs}}) { 592 for (@{$self->{children}}) {
575 $_->move (0, $y); 593 $_->move (0, $y);
576 594
577 if ($_ == $exp) { 595 if ($_ == $exp) {
578 $_->size_allocate ($w, $h - $oh); 596 $_->size_allocate ($w, $h - $oh);
579 $y += $h - $oh; 597 $y += $h - $oh;
587 605
588sub _draw { 606sub _draw {
589 my ($self) = @_; 607 my ($self) = @_;
590 608
591 my ($x, $y); 609 my ($x, $y);
592 for (@{$self->{childs} || []}) { 610 for (@{$self->{children} || []}) {
593 $_->draw; 611 $_->draw;
594 $y += $_->h; 612 $y += $_->h;
595 } 613 }
596} 614}
597 615
896sub _draw { 914sub _draw {
897 my ($self) = @_; 915 my ($self) = @_;
898 916
899 glPushMatrix; 917 glPushMatrix;
900 glRotate $self->{time} * 10000, 0, 1, 0; 918 glRotate $self->{time} * 10000, 0, 1, 0;
901 $self->{child}->draw; 919 $self->{children}[0]->draw;
902 glPopMatrix; 920 glPopMatrix;
903} 921}
904 922
9051; 9231;
906 924

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines