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.36 by elmex, Sun Apr 9 17:39:56 2006 UTC vs.
Revision 1.45 by root, Sun Apr 9 22:19:03 2006 UTC

4 4
5use Scalar::Util; 5use Scalar::Util;
6 6
7use SDL::OpenGL; 7use SDL::OpenGL;
8use SDL::OpenGL::Constants; 8use SDL::OpenGL::Constants;
9
10use Crossfire::Client;
9 11
10our $FOCUS; # the widget with current focus 12our $FOCUS; # the widget with current focus
11 13
12# class methods for events 14# class methods for events
13sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } 15sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS }
37 Carp::confess "size_request is abtract"; 39 Carp::confess "size_request is abtract";
38} 40}
39 41
40sub size_allocate { 42sub size_allocate {
41 my ($self, $w, $h) = @_; 43 my ($self, $w, $h) = @_;
44
42 $self->w ($w); 45 $self->{w} = $w;
43 $self->h ($h); 46 $self->{h} = $h;
44} 47}
45 48
46sub focus_in { 49sub focus_in {
47 my ($widget) = @_; 50 my ($widget) = @_;
48 $FOCUS = $widget; 51 $FOCUS = $widget;
82 $self->_draw; 85 $self->_draw;
83 glPopMatrix; 86 glPopMatrix;
84} 87}
85 88
86sub _draw { 89sub _draw {
87 my ($widget) = @_; 90 my ($self) = @_;
91
92 warn "no draw defined for $self\n";
88} 93}
89 94
90sub bbox { 95sub bbox {
91 my ($self) = @_; 96 my ($self) = @_;
92 my ($w, $h) = $self->size_request; 97 my ($w, $h) = $self->size_request;
96 $self->{x} = $w, 101 $self->{x} = $w,
97 $self->{y} = $h 102 $self->{y} = $h
98 ) 103 )
99} 104}
100 105
106sub find_widget {
107 my ($self, $x, $y) = @_;
108
109 return $self
110 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
111 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
112
113 ()
114}
115
101sub del_parent { $_[0]->{parent} = undef } 116sub del_parent { $_[0]->{parent} = undef }
102 117
103sub set_parent { 118sub set_parent {
104 my ($self, $par) = @_; 119 my ($self, $par) = @_;
105 120
122 my ($self) = @_; 137 my ($self) = @_;
123 138
124 #$self->deactivate; 139 #$self->deactivate;
125} 140}
126 141
142#############################################################################
143
144package Crossfire::Client::Widget::Container;
145
146our @ISA = Crossfire::Client::Widget::;
147
148sub new {
149 my ($class, @widgets) = @_;
150
151 my $self = $class->SUPER::new (children => []);
152 $self->add ($_) for @widgets;
153
154 $self
155}
156
157sub add {
158 my ($self, $chld, $expand) = @_;
159
160 $chld->{expand} = $expand;
161 $chld->set_parent ($self);
162
163 @{$self->{children}} =
164 sort { $a->{z} <=> $b->{z} }
165 @{$self->{children}}, $chld;
166
167 $self->size_allocate ($self->{w}, $self->{h})
168 if $self->{w}; #TODO: check for "realised state"
169}
170
171sub remove {
172 my ($self, $widget) = @_;
173
174 $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ];
175
176 $self->size_allocate ($self->{w}, $self->{h});
177}
178
179sub find_widget {
180 my ($self, $x, $y) = @_;
181
182 $x -= $self->{x};
183 $y -= $self->{y};
184
185 my $res;
186
187 for (@{ $self->{children} }) {
188 $res = $_->find_widget ($x, $y)
189 and return $res;
190 }
191
192 ()
193}
194
195sub _draw {
196 my ($self) = @_;
197
198 $_->draw for @{$self->{children}};
199}
200
201#############################################################################
202
127package Crossfire::Client::Widget::Bin; 203package Crossfire::Client::Widget::Bin;
128 204
129our @ISA = Crossfire::Client::Widget::; 205our @ISA = Crossfire::Client::Widget::Container::;
130 206
131sub add { $_[0]->{child} = $_[1]; $_[1]->set_parent ($_[0]); $_[1]->{expand} = $_[2] }
132sub get { $_[0]->{child} } 207sub child { $_[0]->{children}[0] }
133
134sub remove {
135 my ($self, $chld) = @_;
136 delete $self->{child}
137 if $self->{child} == $chld;
138}
139 208
140sub size_request { 209sub size_request {
141 $_[0]->{child}->size_request if $_[0]->{child} 210 $_[0]{children}[0]->size_request if $_[0]{children}[0];
142} 211}
212
143sub size_allocate { 213sub size_allocate {
144 my ($self, $w, $h) = @_; 214 my ($self, $w, $h) = @_;
215
145 $self->SUPER::size_allocate ($w, $h); 216 $self->SUPER::size_allocate ($w, $h);
146 $self->{child}->size_allocate ($w, $h) 217 $self->{children}[0]->size_allocate ($w, $h)
147 if $self->{child} 218 if $self->{children}[0]
148} 219}
149 220
150sub _draw { 221#############################################################################
151 my ($self) = @_;
152
153 $self->{child}->draw;
154}
155 222
156package Crossfire::Client::Widget::Toplevel; 223package Crossfire::Client::Widget::Toplevel;
157 224
225our @ISA = Crossfire::Client::Widget::Container::;
226
227sub update {
228 my ($self) = @_;
229
230 ::refresh ();
231}
232
233sub add {
234 my ($self, $widget) = @_;
235
236 $self->SUPER::add ($widget);
237
238 $widget->size_allocate ($widget->size_request);
239}
240
241#############################################################################
242
243package Crossfire::Client::Widget::Window;
244
158our @ISA = Crossfire::Client::Widget::; 245our @ISA = Crossfire::Client::Widget::Bin::;
159 246
160use SDL::OpenGL; 247use SDL::OpenGL;
161 248
162sub add { 249sub new {
163 my ($self, $chld) = @_; 250 my ($class, $x, $y, $z, $w, $h) = @_;
164 251
165 push @{$self->{childs}}, $chld; 252 my $self = $class->SUPER::new;
166 @{$self->{childs}} =
167 sort { $a->{z} <=> $b->{z} }
168 @{$self->{childs}};
169 253
170 $chld->set_parent ($self); 254 @$self{qw(x y z w h)} = ($x, $y, $z, $w, $h);
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} 255}
181 256
182sub update { 257sub update {
183 my ($self) = @_; 258 my ($self) = @_;
184 ::refresh ();
185}
186 259
187sub _draw {
188 my ($self) = @_;
189
190 $_->draw for @{$self->{childs}};
191}
192
193package Crossfire::Client::Widget::Window;
194
195our @ISA = Crossfire::Client::Widget::Bin::;
196
197use SDL::OpenGL;
198
199sub add {
200 my ($self, $chld) = @_;
201 warn "ADD $chld\n";
202 $self->SUPER::add ($chld);
203 $chld->set_parent ($self);
204}
205
206sub remove {
207 my ($self) = @_;
208 # TODO FIXME: removing a child from a window will crash, see render_chld
209 # $self->update;
210}
211
212sub update {
213 my ($self) = @_;
214 $self->render_chld; 260 $self->render_chld;
261 $self->SUPER::update;
215} 262}
216 263
217sub render_chld { 264sub render_chld {
218 my ($self) = @_; 265 my ($self) = @_;
219 my $chld = $self->get;
220 my ($w, $h) = $self->size_request;
221 266
222 require Carp;
223 Carp::cluck "RENDERCHI $w $h";
224 warn "RENDERCHI $w $h\n";
225 $self->{texture} = 267 $self->{texture} =
226 Crossfire::Client::Texture->new_from_opengl ( 268 Crossfire::Client::Texture->new_from_opengl (
227 $w, $h, sub { $chld->draw } 269 $self->{w}, $self->{h}, sub { $self->child->draw }
228 ); 270 );
229 $self->{texture}->upload;
230}
231
232sub size_request {
233 my ($self) = @_;
234 ($self->w, $self->h)
235} 271}
236 272
237sub size_allocate { 273sub size_allocate {
238 my ($self, $w, $h) = @_; 274 my ($self, $w, $h) = @_;
239 275
240 $self->w ($w); 276 $self->{w} = $w;
241 $self->h ($h); 277 $self->{h} = $h;
278
242 $self->get->size_allocate ($w, $h); 279 $self->child->size_allocate ($w, $h);
243 280
244 $self->update; #TODO: Move this to the size_request event propably? 281 $self->render_chld;
245} 282}
246 283
247sub _draw { 284sub _draw {
248 my ($self) = @_; 285 my ($self) = @_;
249 286
266 303
267 glDisable GL_BLEND; 304 glDisable GL_BLEND;
268 glDisable GL_TEXTURE_2D; 305 glDisable GL_TEXTURE_2D;
269} 306}
270 307
308#############################################################################
309
271package Crossfire::Client::Widget::Frame; 310package Crossfire::Client::Widget::Frame;
272 311
273our @ISA = Crossfire::Client::Widget::Bin::; 312our @ISA = Crossfire::Client::Widget::Bin::;
274 313
275use SDL::OpenGL; 314use SDL::OpenGL;
276 315
277sub size_request { 316sub size_request {
278 my ($self) = @_; 317 my ($self) = @_;
279 my $chld = $self->get 318 my $chld = $self->child
280 or return (0, 0); 319 or return (0, 0);
281 320
282 $chld->move (2, 2); 321 $chld->move (2, 2);
283 322
284 map { $_ + 4 } $chld->size_request; 323 map { $_ + 4 } $chld->size_request;
285} 324}
286 325
287sub size_allocate { 326sub size_allocate {
288 my ($self, $w, $h) = @_; 327 my ($self, $w, $h) = @_;
289 328
290 $self->w ($w); 329 $self->{w} = $w;
291 $self->h ($h); 330 $self->{h} = $h;
292 331
293 $self->get->size_allocate ($w - 4, $h - 4); 332 $self->child->size_allocate ($w - 4, $h - 4);
294 $self->get->move (2, 2); 333 $self->child->move (2, 2);
295} 334}
296 335
297sub _draw { 336sub _draw {
298 my ($self) = @_; 337 my ($self) = @_;
299 338
300 my $chld = $self->get; 339 my $chld = $self->child;
301 340
302 my ($w, $h) = $chld->size_request; 341 my ($w, $h) = $chld->size_request;
303 342
304 glBegin GL_QUADS; 343 glBegin GL_QUADS;
305 glColor 0, 0, 0; 344 glColor 0, 0, 0;
310 glEnd; 349 glEnd;
311 350
312 $chld->draw; 351 $chld->draw;
313} 352}
314 353
354#############################################################################
355
315package Crossfire::Client::Widget::FancyFrame; 356package Crossfire::Client::Widget::FancyFrame;
316 357
317our @ISA = Crossfire::Client::Widget::Frame::; 358our @ISA = Crossfire::Client::Widget::Bin::;
318 359
319use SDL::OpenGL; 360use SDL::OpenGL;
320 361
321sub new { 362my @tex =
322 my ($self, $theme) = @_;
323 $self = $self->SUPER::new;
324
325 $self->{txts} = [
326 map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } 363 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/ 364 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
328 ];
329 $self
330}
331 365
332sub size_request { 366sub size_request {
333 my ($self) = @_; 367 my ($self) = @_;
368
334 my ($w, $h) = $self->get->size_request; 369 my ($w, $h) = $self->SUPER::size_request;
335 370
336 $h += $self->{txts}->[1]->{height}; 371 $h += $tex[1]->{height};
337 $h += $self->{txts}->[4]->{height}; 372 $h += $tex[4]->{height};
338 $w += $self->{txts}->[2]->{width}; 373 $w += $tex[2]->{width};
339 $w += $self->{txts}->[3]->{width}; 374 $w += $tex[3]->{width};
340 375
341 ($w, $h) 376 ($w, $h)
342} 377}
343 378
344sub size_allocate { 379sub size_allocate {
345 my ($self, $w, $h) = @_; 380 my ($self, $w, $h) = @_;
346 381
347 $self->w ($w); 382 $self->SUPER::size_allocate ($w, $h);
348 $self->h ($h); 383
349 $h -= $self->{txts}->[1]->{height}; 384 $h -= $tex[1]->{height};
350 $h -= $self->{txts}->[4]->{height}; 385 $h -= $tex[4]->{height};
351 $w -= $self->{txts}->[2]->{width}; 386 $w -= $tex[2]->{width};
352 $w -= $self->{txts}->[3]->{width}; 387 $w -= $tex[3]->{width};
353 388
354 $h = $h < 0 ? 0 : $h; 389 $h = $h < 0 ? 0 : $h;
355 $w = $w < 0 ? 0 : $w; 390 $w = $w < 0 ? 0 : $w;
356 warn "CHILD:$w $h\n"; 391
357 $self->get->size_allocate ($w, $h); 392 $self->child->size_allocate ($w, $h);
358 $self->get->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); 393 $self->child->move ($tex[3]->{width}, $tex[1]->{height});
359} 394}
360 395
361sub _draw { 396sub _draw {
362 my ($self) = @_; 397 my ($self) = @_;
363 398
364 my ($w, $h) = ($self->w, $self->h); 399 my ($w, $h) = ($self->{w}, $self->{h});
365 my ($cw, $ch) = ($self->get->w, $self->get->h); 400 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
366 401
367 glEnable GL_BLEND; 402 glEnable GL_BLEND;
368 glEnable GL_TEXTURE_2D; 403 glEnable GL_TEXTURE_2D;
369 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 404 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
370 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 405 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
371 406
372 my $top = $self->{txts}->[1]; 407 my $top = $tex[1];
373 glBindTexture GL_TEXTURE_2D, $top->{name}; 408 glBindTexture GL_TEXTURE_2D, $top->{name};
374 409
375 glBegin GL_QUADS; 410 glBegin GL_QUADS;
376 glTexCoord 0, 0; glVertex 0 , 0; 411 glTexCoord 0, 0; glVertex 0 , 0;
377 glTexCoord 0, 1; glVertex 0 , $top->{height}; 412 glTexCoord 0, 1; glVertex 0 , $top->{height};
378 glTexCoord 1, 1; glVertex $w , $top->{height}; 413 glTexCoord 1, 1; glVertex $w , $top->{height};
379 glTexCoord 1, 0; glVertex $w , 0; 414 glTexCoord 1, 0; glVertex $w , 0;
380 glEnd; 415 glEnd;
381 416
382 my $left = $self->{txts}->[3]; 417 my $left = $tex[3];
383 glBindTexture GL_TEXTURE_2D, $left->{name}; 418 glBindTexture GL_TEXTURE_2D, $left->{name};
384 419
385 glBegin GL_QUADS; 420 glBegin GL_QUADS;
386 glTexCoord 0, 0; glVertex 0 , $top->{height}; 421 glTexCoord 0, 0; glVertex 0 , $top->{height};
387 glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; 422 glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch;
388 glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; 423 glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch;
389 glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; 424 glTexCoord 1, 0; glVertex $left->{width}, $top->{height};
390 glEnd; 425 glEnd;
391 426
392 my $right = $self->{txts}->[2]; 427 my $right = $tex[2];
393 glBindTexture GL_TEXTURE_2D, $right->{name}; 428 glBindTexture GL_TEXTURE_2D, $right->{name};
394 429
395 glBegin GL_QUADS; 430 glBegin GL_QUADS;
396 glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; 431 glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height};
397 glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; 432 glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch;
398 glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; 433 glTexCoord 1, 1; glVertex $w , $top->{height} + $ch;
399 glTexCoord 1, 0; glVertex $w , $top->{height}; 434 glTexCoord 1, 0; glVertex $w , $top->{height};
400 glEnd; 435 glEnd;
401 436
402 my $bottom = $self->{txts}->[4]; 437 my $bottom = $tex[4];
403 glBindTexture GL_TEXTURE_2D, $bottom->{name}; 438 glBindTexture GL_TEXTURE_2D, $bottom->{name};
404 439
405 glBegin GL_QUADS; 440 glBegin GL_QUADS;
406 glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; 441 glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height};
407 glTexCoord 0, 1; glVertex 0 , $h; 442 glTexCoord 0, 1; glVertex 0 , $h;
408 glTexCoord 1, 1; glVertex $w , $h; 443 glTexCoord 1, 1; glVertex $w , $h;
409 glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; 444 glTexCoord 1, 0; glVertex $w , $h - $bottom->{height};
410 glEnd; 445 glEnd;
411 446
412 my $bg = $self->{txts}->[0]; 447 my $bg = $tex[0];
413 glBindTexture GL_TEXTURE_2D, $bg->{name}; 448 glBindTexture GL_TEXTURE_2D, $bg->{name};
414 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 449 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
415 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; 450 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT;
416 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; 451 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT;
417 452
426 glEnd; 461 glEnd;
427 462
428 glDisable GL_BLEND; 463 glDisable GL_BLEND;
429 glDisable GL_TEXTURE_2D; 464 glDisable GL_TEXTURE_2D;
430 465
431 $self->get->draw; 466 $self->child->draw;
432 467
433} 468}
469
470#############################################################################
434 471
435package Crossfire::Client::Widget::Table; 472package Crossfire::Client::Widget::Table;
436 473
437our @ISA = Crossfire::Client::Widget::Bin::; 474our @ISA = Crossfire::Client::Widget::Bin::;
438 475
439use SDL::OpenGL; 476use SDL::OpenGL;
440 477
441sub add { 478sub add {
442 my ($self, $x, $y, $chld) = @_; 479 my ($self, $x, $y, $chld) = @_;
443 my $old_chld = $self->{childs}[$y][$x]; 480 my $old_chld = $self->{children}[$y][$x];
444 481
445 $self->{childs}[$y][$x] = $chld; 482 $self->{children}[$y][$x] = $chld;
446 $chld->set_parent ($self); 483 $chld->set_parent ($self);
447 $self->update; 484 $self->update;
448} 485}
449 486
450sub max_row_height { 487sub max_row_height {
451 my ($self, $row) = @_; 488 my ($self, $row) = @_;
452 489
453 my $hs = 0; 490 my $hs = 0;
454 for (my $xi = 0; $xi <= $#{$self->{childs}->[$row] || []}; $xi++) { 491 for (my $xi = 0; $xi <= $#{$self->{children}->[$row] || []}; $xi++) {
455 my $c = $self->{childs}->[$row]->[$xi]; 492 my $c = $self->{children}->[$row]->[$xi];
456 if ($c) { 493 if ($c) {
457 my ($w, $h) = $c->size_request; 494 my ($w, $h) = $c->size_request;
458 if ($hs < $h) { $hs = $h } 495 if ($hs < $h) { $hs = $h }
459 } 496 }
460 } 497 }
463 500
464sub max_col_width { 501sub max_col_width {
465 my ($self, $col) = @_; 502 my ($self, $col) = @_;
466 503
467 my $ws = 0; 504 my $ws = 0;
468 for (my $yi = 0; $yi <= $#{$self->{childs} || []}; $yi++) { 505 for (my $yi = 0; $yi <= $#{$self->{children} || []}; $yi++) {
469 my $c = ($self->{childs}->[$yi] || [])->[$col]; 506 my $c = ($self->{children}->[$yi] || [])->[$col];
470 if ($c) { 507 if ($c) {
471 my ($w, $h) = $c->size_request; 508 my ($w, $h) = $c->size_request;
472 if ($ws < $w) { $ws = $w } 509 if ($ws < $w) { $ws = $w }
473 } 510 }
474 } 511 }
478sub size_request { 515sub size_request {
479 my ($self) = @_; 516 my ($self) = @_;
480 517
481 my ($hs, $ws) = (0, 0); 518 my ($hs, $ws) = (0, 0);
482 519
483 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 520 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) {
484 $hs += $self->max_row_height ($yi); 521 $hs += $self->max_row_height ($yi);
485 } 522 }
486 523
487 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 524 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) {
488 my $wm = 0; 525 my $wm = 0;
489 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { 526 for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) {
490 $wm += $self->max_col_width ($xi) 527 $wm += $self->max_col_width ($xi)
491 } 528 }
492 if ($ws < $wm) { $ws = $wm } 529 if ($ws < $wm) { $ws = $wm }
493 } 530 }
494 531
497 534
498sub _draw { 535sub _draw {
499 my ($self) = @_; 536 my ($self) = @_;
500 537
501 my $y = 0; 538 my $y = 0;
502 for (my $yi = 0; $yi <= $#{$self->{childs}}; $yi++) { 539 for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) {
503 my $x = 0; 540 my $x = 0;
504 541
505 for (my $xi = 0; $xi <= $#{$self->{childs}->[$yi]}; $xi++) { 542 for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) {
506 543
507 my $c = $self->{childs}->[$yi]->[$xi]; 544 my $c = $self->{children}->[$yi]->[$xi];
508 if ($c) { 545 if ($c) {
509 $c->move ($x, $y, 0); #TODO: Move to size_request 546 $c->move ($x, $y, 0); #TODO: Move to size_request
510 $c->draw if $c; 547 $c->draw if $c;
511 } 548 }
512 549
515 552
516 $y += $self->max_row_height ($yi); 553 $y += $self->max_row_height ($yi);
517 } 554 }
518} 555}
519 556
557#############################################################################
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 564
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 { 565sub size_request {
535 my ($self) = @_; 566 my ($self) = @_;
536 567
537 my ($hs, $ws) = (0, 0); 568 my @alloc = map [$_->size_request], @{$self->{children}};
538 for (@{$self->{childs} || []}) { 569
539 my ($w, $h) = $_->size_request;
540 $hs += $h;
541 if ($ws < $w) { $ws = $w }
542 } 570 (
543 571 (List::Util::max map $_->[0], @alloc),
544 return ($ws, $hs); 572 (List::Util::sum map $_->[1], @alloc),
573 )
545} 574}
546 575
547sub size_allocate { 576sub size_allocate {
548 my ($self, $w, $h) = @_; 577 my ($self, $w, $h) = @_;
549 578
551 $self->h ($h); 580 $self->h ($h);
552 581
553 my $exp; 582 my $exp;
554 my @oth; 583 my @oth;
555 # find expand widget 584 # find expand widget
556 for (@{$self->{childs}}) { 585 for (@{$self->{children}}) {
557 if ($_->{expand}) { 586 if ($_->{expand}) {
558 $exp = $_; 587 $exp = $_;
559 last; 588 last;
560 } 589 }
561 push @oth, $_; 590 push @oth, $_;
569 $oh += $h; 598 $oh += $h;
570 if ($ow < $w) { $ow = $w } 599 if ($ow < $w) { $ow = $w }
571 } 600 }
572 601
573 my $y = 0; 602 my $y = 0;
574 for (@{$self->{childs}}) { 603 for (@{$self->{children}}) {
575 $_->move (0, $y); 604 $_->move (0, $y);
576 605
577 if ($_ == $exp) { 606 if ($_ == $exp) {
578 $_->size_allocate ($w, $h - $oh); 607 $_->size_allocate ($w, $h - $oh);
579 $y += $h - $oh; 608 $y += $h - $oh;
583 $y += $h; 612 $y += $h;
584 } 613 }
585 } 614 }
586} 615}
587 616
588sub _draw { 617#############################################################################
589 my ($self) = @_;
590
591 my ($x, $y);
592 for (@{$self->{childs} || []}) {
593 $_->draw;
594 $y += $_->h;
595 }
596}
597 618
598package Crossfire::Client::Widget::Label; 619package Crossfire::Client::Widget::Label;
599 620
600our @ISA = Crossfire::Client::Widget::; 621our @ISA = Crossfire::Client::Widget::;
601 622
658 679
659 glDisable GL_BLEND; 680 glDisable GL_BLEND;
660 glDisable GL_TEXTURE_2D; 681 glDisable GL_TEXTURE_2D;
661} 682}
662 683
684#############################################################################
685
663package Crossfire::Client::Widget::TextEntry; 686package Crossfire::Client::Widget::TextEntry;
664 687
665our @ISA = Crossfire::Client::Widget::Label::; 688our @ISA = Crossfire::Client::Widget::Label::;
666 689
667use SDL; 690use SDL;
684 } elsif ($uni) { 707 } elsif ($uni) {
685 $text .= chr $uni; 708 $text .= chr $uni;
686 } 709 }
687 $self->set_text ($text); 710 $self->set_text ($text);
688} 711}
712
713#############################################################################
689 714
690package Crossfire::Client::Widget::MapWidget; 715package Crossfire::Client::Widget::MapWidget;
691 716
692use strict; 717use strict;
693 718
860 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { 885 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
861 $::CONN->send ("command run_stop"); 886 $::CONN->send ("command run_stop");
862 } 887 }
863} 888}
864 889
890#############################################################################
891
865package Crossfire::Client::Widget::Animator; 892package Crossfire::Client::Widget::Animator;
866 893
867use SDL::OpenGL; 894use SDL::OpenGL;
868 895
869our @ISA = Crossfire::Client::Widget::Bin::; 896our @ISA = Crossfire::Client::Widget::Bin::;
870 897
871sub moveto { 898sub moveto {
872 my ($self, $x, $y) = @_; 899 my ($self, $x, $y) = @_;
873 900
874 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 901 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
875 $self->{speed} = 0.01; 902 $self->{speed} = 0.2;
876 $self->{time} = 1; 903 $self->{time} = 1;
877 904
878 ::animation_start $self; 905 ::animation_start $self;
879} 906}
880 907
896sub _draw { 923sub _draw {
897 my ($self) = @_; 924 my ($self) = @_;
898 925
899 glPushMatrix; 926 glPushMatrix;
900 glRotate $self->{time} * 10000, 0, 1, 0; 927 glRotate $self->{time} * 10000, 0, 1, 0;
901 $self->{child}->draw; 928 $self->{children}[0]->draw;
902 glPopMatrix; 929 glPopMatrix;
903} 930}
904 931
9051; 9321;
906 933

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines