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

162 162
163 @{$self->{children}} = 163 @{$self->{children}} =
164 sort { $a->{z} <=> $b->{z} } 164 sort { $a->{z} <=> $b->{z} }
165 @{$self->{children}}, $chld; 165 @{$self->{children}}, $chld;
166 166
167 $self->size_allocate ($self->{w}, $self->{h}); 167 $self->size_allocate ($self->{w}, $self->{h})
168 if $self->{w}; #TODO: check for "realised state"
168} 169}
169 170
170sub remove { 171sub remove {
171 my ($self, $widget) = @_; 172 my ($self, $widget) = @_;
172 173
186 } 187 }
187 188
188 () 189 ()
189} 190}
190 191
191sub size_request {
192 my ($self) = @_;
193
194 my ($hs, $ws) = (0, 0);
195 for (@{$self->{children} || []}) {
196 my ($w, $h) = $_->size_request;
197 $hs += $h;
198 if ($ws < $w) { $ws = $w }
199 }
200
201 return ($ws, $hs);
202}
203
204sub _draw { 192sub _draw {
205 my ($self) = @_; 193 my ($self) = @_;
206 194
207 $_->draw for @{$self->{children}}; 195 $_->draw for @{$self->{children}};
208} 196}
219 $_[0]{children}[0]->size_request if $_[0]{children}[0]; 207 $_[0]{children}[0]->size_request if $_[0]{children}[0];
220} 208}
221 209
222sub size_allocate { 210sub size_allocate {
223 my ($self, $w, $h) = @_; 211 my ($self, $w, $h) = @_;
212
224 $self->SUPER::size_allocate ($w, $h); 213 $self->SUPER::size_allocate ($w, $h);
225 $self->{children}[0]->size_allocate ($w, $h) 214 $self->{children}[0]->size_allocate ($w, $h)
226 if $self->{children}[0] 215 if $self->{children}[0]
227} 216}
228 217
236 my ($self) = @_; 225 my ($self) = @_;
237 226
238 ::refresh (); 227 ::refresh ();
239} 228}
240 229
230sub add {
231 my ($self, $widget) = @_;
232
233 $self->SUPER::add ($widget);
234
235 $widget->size_allocate ($widget->size_request);
236}
237
241############################################################################# 238#############################################################################
242 239
243package Crossfire::Client::Widget::Window; 240package Crossfire::Client::Widget::Window;
244 241
245our @ISA = Crossfire::Client::Widget::Bin::; 242our @ISA = Crossfire::Client::Widget::Bin::;
246 243
247use SDL::OpenGL; 244use SDL::OpenGL;
248 245
249sub add { 246sub new {
250 my ($self, $chld) = @_; 247 my ($class, $x, $y, $z, $w, $h) = @_;
251 warn "ADD $chld\n";
252 $self->SUPER::add ($chld);
253 $chld->set_parent ($self);
254}
255 248
256sub remove { 249 my $self = $class->SUPER::new;
257 my ($self) = @_; 250
258 # TODO FIXME: removing a child from a window will crash, see render_chld 251 @$self{qw(x y z w h)} = ($x, $y, $z, $w, $h);
259 # $self->update;
260} 252}
261 253
262sub update { 254sub update {
263 my ($self) = @_; 255 my ($self) = @_;
256
264 $self->render_chld; 257 $self->render_chld;
258 $self->SUPER::update;
265} 259}
266 260
267sub render_chld { 261sub render_chld {
268 my ($self) = @_; 262 my ($self) = @_;
269 my $chld = $self->get;
270 my ($w, $h) = $self->size_request;
271 263
272 require Carp;
273 Carp::cluck "RENDERCHI $w $h";
274 warn "RENDERCHI $w $h\n";
275 $self->{texture} = 264 $self->{texture} =
276 Crossfire::Client::Texture->new_from_opengl ( 265 Crossfire::Client::Texture->new_from_opengl (
277 $w, $h, sub { $chld->draw } 266 $self->{w}, $self->{h}, sub { $self->child->draw }
278 ); 267 );
279 $self->{texture}->upload;
280}
281
282sub size_request {
283 my ($self) = @_;
284 ($self->w, $self->h)
285} 268}
286 269
287sub size_allocate { 270sub size_allocate {
288 my ($self, $w, $h) = @_; 271 my ($self, $w, $h) = @_;
289 272
290 $self->w ($w); 273 $self->{w} = $w;
291 $self->h ($h); 274 $self->{h} = $h;
275
292 $self->get->size_allocate ($w, $h); 276 $self->child->size_allocate ($w, $h);
293 277
294 $self->update; #TODO: Move this to the size_request event propably? 278 $self->render_chld;
295} 279}
296 280
297sub _draw { 281sub _draw {
298 my ($self) = @_; 282 my ($self) = @_;
299 283
336 map { $_ + 4 } $chld->size_request; 320 map { $_ + 4 } $chld->size_request;
337} 321}
338 322
339sub size_allocate { 323sub size_allocate {
340 my ($self, $w, $h) = @_; 324 my ($self, $w, $h) = @_;
341 325
342 $self->SUPER::size_allocate ($w, $h); 326 $self->{w} = $w;
327 $self->{h} = $h;
343 328
344 $self->child->size_allocate ($w - 4, $h - 4); 329 $self->child->size_allocate ($w - 4, $h - 4);
345 $self->child->move (2, 2); 330 $self->child->move (2, 2);
346} 331}
347 332
398 $w -= $tex[2]->{width}; 383 $w -= $tex[2]->{width};
399 $w -= $tex[3]->{width}; 384 $w -= $tex[3]->{width};
400 385
401 $h = $h < 0 ? 0 : $h; 386 $h = $h < 0 ? 0 : $h;
402 $w = $w < 0 ? 0 : $w; 387 $w = $w < 0 ? 0 : $w;
403 warn "CHILD:$w $h\n"; 388
404 $self->child->size_allocate ($w, $h); 389 $self->child->size_allocate ($w, $h);
405 $self->child->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); 390 $self->child->move ($tex[3]->{width}, $tex[1]->{height});
406} 391}
407 392
408sub _draw { 393sub _draw {
409 my ($self) = @_; 394 my ($self) = @_;
410 395
411 my ($w, $h) = ($self->w, $self->h); 396 my ($w, $h) = ($self->{w}, $self->{h});
412 my ($cw, $ch) = ($self->child->w, $self->child->h); 397 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
413 398
414 glEnable GL_BLEND; 399 glEnable GL_BLEND;
415 glEnable GL_TEXTURE_2D; 400 glEnable GL_TEXTURE_2D;
416 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 401 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
417 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 402 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
571package Crossfire::Client::Widget::VBox; 556package Crossfire::Client::Widget::VBox;
572 557
573our @ISA = Crossfire::Client::Widget::Container::; 558our @ISA = Crossfire::Client::Widget::Container::;
574 559
575use SDL::OpenGL; 560use SDL::OpenGL;
561
562sub size_request {
563 my ($self) = @_;
564
565 my @alloc = map [$_->size_request], @{$self->{children}};
566
567 (
568 (List::Util::max map $_->[0], @alloc),
569 (List::Util::sum map $_->[1], @alloc),
570 )
571}
576 572
577sub size_allocate { 573sub size_allocate {
578 my ($self, $w, $h) = @_; 574 my ($self, $w, $h) = @_;
579 575
580 $self->w ($w); 576 $self->w ($w);
610 } else { 606 } else {
611 my ($cw, $h) = $_->size_request; 607 my ($cw, $h) = $_->size_request;
612 $_->size_allocate ($w, $h); 608 $_->size_allocate ($w, $h);
613 $y += $h; 609 $y += $h;
614 } 610 }
615 }
616}
617
618sub _draw {
619 my ($self) = @_;
620
621 my ($x, $y);
622 for (@{$self->{children} || []}) {
623 $_->draw;
624 $y += $_->h;
625 } 611 }
626} 612}
627 613
628############################################################################# 614#############################################################################
629 615

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines