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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines