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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines