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.47 by root, Sun Apr 9 22:24:43 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines