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.38 by root, Sun Apr 9 21:34:49 2006 UTC vs.
Revision 1.41 by root, Sun Apr 9 21:50:21 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;
134 my ($self) = @_; 137 my ($self) = @_;
135 138
136 #$self->deactivate; 139 #$self->deactivate;
137} 140}
138 141
142#############################################################################
143
139package Crossfire::Client::Widget::Container; 144package Crossfire::Client::Widget::Container;
140 145
141our @ISA = Crossfire::Client::Widget::; 146our @ISA = Crossfire::Client::Widget::;
142 147
143sub new { 148sub new {
200 my ($self) = @_; 205 my ($self) = @_;
201 206
202 $_->draw for @{$self->{children}}; 207 $_->draw for @{$self->{children}};
203} 208}
204 209
210#############################################################################
211
205package Crossfire::Client::Widget::Bin; 212package Crossfire::Client::Widget::Bin;
206 213
207our @ISA = Crossfire::Client::Widget::Container::; 214our @ISA = Crossfire::Client::Widget::Container::;
208 215
209sub get { $_[0]->{children}[0] } 216sub child { $_[0]->{children}[0] }
210 217
211sub size_request { 218sub size_request {
212 $_[0]{children}[0]->size_request if $_[0]{children}[0]; 219 $_[0]{children}[0]->size_request if $_[0]{children}[0];
213} 220}
214 221
217 $self->SUPER::size_allocate ($w, $h); 224 $self->SUPER::size_allocate ($w, $h);
218 $self->{children}[0]->size_allocate ($w, $h) 225 $self->{children}[0]->size_allocate ($w, $h)
219 if $self->{children}[0] 226 if $self->{children}[0]
220} 227}
221 228
229#############################################################################
230
222package Crossfire::Client::Widget::Toplevel; 231package Crossfire::Client::Widget::Toplevel;
223 232
224our @ISA = Crossfire::Client::Widget::Container::; 233our @ISA = Crossfire::Client::Widget::Container::;
225 234
226sub update { 235sub update {
227 my ($self) = @_; 236 my ($self) = @_;
228 237
229 ::refresh (); 238 ::refresh ();
230} 239}
240
241#############################################################################
231 242
232package Crossfire::Client::Widget::Window; 243package Crossfire::Client::Widget::Window;
233 244
234our @ISA = Crossfire::Client::Widget::Bin::; 245our @ISA = Crossfire::Client::Widget::Bin::;
235 246
305 316
306 glDisable GL_BLEND; 317 glDisable GL_BLEND;
307 glDisable GL_TEXTURE_2D; 318 glDisable GL_TEXTURE_2D;
308} 319}
309 320
321#############################################################################
322
310package Crossfire::Client::Widget::Frame; 323package Crossfire::Client::Widget::Frame;
311 324
312our @ISA = Crossfire::Client::Widget::Bin::; 325our @ISA = Crossfire::Client::Widget::Bin::;
313 326
314use SDL::OpenGL; 327use SDL::OpenGL;
315 328
316sub size_request { 329sub size_request {
317 my ($self) = @_; 330 my ($self) = @_;
318 my $chld = $self->get 331 my $chld = $self->child
319 or return (0, 0); 332 or return (0, 0);
320 333
321 $chld->move (2, 2); 334 $chld->move (2, 2);
322 335
323 map { $_ + 4 } $chld->size_request; 336 map { $_ + 4 } $chld->size_request;
324} 337}
325 338
326sub size_allocate { 339sub size_allocate {
327 my ($self, $w, $h) = @_; 340 my ($self, $w, $h) = @_;
328 341
329 $self->w ($w); 342 $self->SUPER::size_allocate ($w, $h);
330 $self->h ($h);
331 343
332 $self->get->size_allocate ($w - 4, $h - 4); 344 $self->child->size_allocate ($w - 4, $h - 4);
333 $self->get->move (2, 2); 345 $self->child->move (2, 2);
334} 346}
335 347
336sub _draw { 348sub _draw {
337 my ($self) = @_; 349 my ($self) = @_;
338 350
339 my $chld = $self->get; 351 my $chld = $self->child;
340 352
341 my ($w, $h) = $chld->size_request; 353 my ($w, $h) = $chld->size_request;
342 354
343 glBegin GL_QUADS; 355 glBegin GL_QUADS;
344 glColor 0, 0, 0; 356 glColor 0, 0, 0;
349 glEnd; 361 glEnd;
350 362
351 $chld->draw; 363 $chld->draw;
352} 364}
353 365
366#############################################################################
367
354package Crossfire::Client::Widget::FancyFrame; 368package Crossfire::Client::Widget::FancyFrame;
355 369
356our @ISA = Crossfire::Client::Widget::Frame::; 370our @ISA = Crossfire::Client::Widget::Bin::;
357 371
358use SDL::OpenGL; 372use SDL::OpenGL;
359 373
360sub new { 374my @tex =
361 my ($self, $theme) = @_;
362 $self = $self->SUPER::new;
363
364 $self->{txts} = [
365 map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } 375 map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ }
366 qw/d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png/ 376 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
367 ];
368 $self
369}
370 377
371sub size_request { 378sub size_request {
372 my ($self) = @_; 379 my ($self) = @_;
380
373 my ($w, $h) = $self->get->size_request; 381 my ($w, $h) = $self->SUPER::size_request;
374 382
375 $h += $self->{txts}->[1]->{height}; 383 $h += $tex[1]->{height};
376 $h += $self->{txts}->[4]->{height}; 384 $h += $tex[4]->{height};
377 $w += $self->{txts}->[2]->{width}; 385 $w += $tex[2]->{width};
378 $w += $self->{txts}->[3]->{width}; 386 $w += $tex[3]->{width};
379 387
380 ($w, $h) 388 ($w, $h)
381} 389}
382 390
383sub size_allocate { 391sub size_allocate {
384 my ($self, $w, $h) = @_; 392 my ($self, $w, $h) = @_;
385 393
386 $self->w ($w); 394 $self->SUPER::size_allocate ($w, $h);
387 $self->h ($h); 395
388 $h -= $self->{txts}->[1]->{height}; 396 $h -= $tex[1]->{height};
389 $h -= $self->{txts}->[4]->{height}; 397 $h -= $tex[4]->{height};
390 $w -= $self->{txts}->[2]->{width}; 398 $w -= $tex[2]->{width};
391 $w -= $self->{txts}->[3]->{width}; 399 $w -= $tex[3]->{width};
392 400
393 $h = $h < 0 ? 0 : $h; 401 $h = $h < 0 ? 0 : $h;
394 $w = $w < 0 ? 0 : $w; 402 $w = $w < 0 ? 0 : $w;
395 warn "CHILD:$w $h\n"; 403 warn "CHILD:$w $h\n";
396 $self->get->size_allocate ($w, $h); 404 $self->child->size_allocate ($w, $h);
397 $self->get->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); 405 $self->child->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height});
398} 406}
399 407
400sub _draw { 408sub _draw {
401 my ($self) = @_; 409 my ($self) = @_;
402 410
403 my ($w, $h) = ($self->w, $self->h); 411 my ($w, $h) = ($self->w, $self->h);
404 my ($cw, $ch) = ($self->get->w, $self->get->h); 412 my ($cw, $ch) = ($self->child->w, $self->child->h);
405 413
406 glEnable GL_BLEND; 414 glEnable GL_BLEND;
407 glEnable GL_TEXTURE_2D; 415 glEnable GL_TEXTURE_2D;
408 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 416 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
409 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 417 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
410 418
411 my $top = $self->{txts}->[1]; 419 my $top = $tex[1];
412 glBindTexture GL_TEXTURE_2D, $top->{name}; 420 glBindTexture GL_TEXTURE_2D, $top->{name};
413 421
414 glBegin GL_QUADS; 422 glBegin GL_QUADS;
415 glTexCoord 0, 0; glVertex 0 , 0; 423 glTexCoord 0, 0; glVertex 0 , 0;
416 glTexCoord 0, 1; glVertex 0 , $top->{height}; 424 glTexCoord 0, 1; glVertex 0 , $top->{height};
417 glTexCoord 1, 1; glVertex $w , $top->{height}; 425 glTexCoord 1, 1; glVertex $w , $top->{height};
418 glTexCoord 1, 0; glVertex $w , 0; 426 glTexCoord 1, 0; glVertex $w , 0;
419 glEnd; 427 glEnd;
420 428
421 my $left = $self->{txts}->[3]; 429 my $left = $tex[3];
422 glBindTexture GL_TEXTURE_2D, $left->{name}; 430 glBindTexture GL_TEXTURE_2D, $left->{name};
423 431
424 glBegin GL_QUADS; 432 glBegin GL_QUADS;
425 glTexCoord 0, 0; glVertex 0 , $top->{height}; 433 glTexCoord 0, 0; glVertex 0 , $top->{height};
426 glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; 434 glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch;
427 glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; 435 glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch;
428 glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; 436 glTexCoord 1, 0; glVertex $left->{width}, $top->{height};
429 glEnd; 437 glEnd;
430 438
431 my $right = $self->{txts}->[2]; 439 my $right = $tex[2];
432 glBindTexture GL_TEXTURE_2D, $right->{name}; 440 glBindTexture GL_TEXTURE_2D, $right->{name};
433 441
434 glBegin GL_QUADS; 442 glBegin GL_QUADS;
435 glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; 443 glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height};
436 glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; 444 glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch;
437 glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; 445 glTexCoord 1, 1; glVertex $w , $top->{height} + $ch;
438 glTexCoord 1, 0; glVertex $w , $top->{height}; 446 glTexCoord 1, 0; glVertex $w , $top->{height};
439 glEnd; 447 glEnd;
440 448
441 my $bottom = $self->{txts}->[4]; 449 my $bottom = $tex[4];
442 glBindTexture GL_TEXTURE_2D, $bottom->{name}; 450 glBindTexture GL_TEXTURE_2D, $bottom->{name};
443 451
444 glBegin GL_QUADS; 452 glBegin GL_QUADS;
445 glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; 453 glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height};
446 glTexCoord 0, 1; glVertex 0 , $h; 454 glTexCoord 0, 1; glVertex 0 , $h;
447 glTexCoord 1, 1; glVertex $w , $h; 455 glTexCoord 1, 1; glVertex $w , $h;
448 glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; 456 glTexCoord 1, 0; glVertex $w , $h - $bottom->{height};
449 glEnd; 457 glEnd;
450 458
451 my $bg = $self->{txts}->[0]; 459 my $bg = $tex[0];
452 glBindTexture GL_TEXTURE_2D, $bg->{name}; 460 glBindTexture GL_TEXTURE_2D, $bg->{name};
453 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 461 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
454 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; 462 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT;
455 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; 463 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT;
456 464
465 glEnd; 473 glEnd;
466 474
467 glDisable GL_BLEND; 475 glDisable GL_BLEND;
468 glDisable GL_TEXTURE_2D; 476 glDisable GL_TEXTURE_2D;
469 477
470 $self->get->draw; 478 $self->child->draw;
471 479
472} 480}
481
482#############################################################################
473 483
474package Crossfire::Client::Widget::Table; 484package Crossfire::Client::Widget::Table;
475 485
476our @ISA = Crossfire::Client::Widget::Bin::; 486our @ISA = Crossfire::Client::Widget::Bin::;
477 487
553 } 563 }
554 564
555 $y += $self->max_row_height ($yi); 565 $y += $self->max_row_height ($yi);
556 } 566 }
557} 567}
568
569#############################################################################
558 570
559package Crossfire::Client::Widget::VBox; 571package Crossfire::Client::Widget::VBox;
560 572
561our @ISA = Crossfire::Client::Widget::Container::; 573our @ISA = Crossfire::Client::Widget::Container::;
562 574
611 $_->draw; 623 $_->draw;
612 $y += $_->h; 624 $y += $_->h;
613 } 625 }
614} 626}
615 627
628#############################################################################
629
616package Crossfire::Client::Widget::Label; 630package Crossfire::Client::Widget::Label;
617 631
618our @ISA = Crossfire::Client::Widget::; 632our @ISA = Crossfire::Client::Widget::;
619 633
620use SDL::OpenGL; 634use SDL::OpenGL;
676 690
677 glDisable GL_BLEND; 691 glDisable GL_BLEND;
678 glDisable GL_TEXTURE_2D; 692 glDisable GL_TEXTURE_2D;
679} 693}
680 694
695#############################################################################
696
681package Crossfire::Client::Widget::TextEntry; 697package Crossfire::Client::Widget::TextEntry;
682 698
683our @ISA = Crossfire::Client::Widget::Label::; 699our @ISA = Crossfire::Client::Widget::Label::;
684 700
685use SDL; 701use SDL;
702 } elsif ($uni) { 718 } elsif ($uni) {
703 $text .= chr $uni; 719 $text .= chr $uni;
704 } 720 }
705 $self->set_text ($text); 721 $self->set_text ($text);
706} 722}
723
724#############################################################################
707 725
708package Crossfire::Client::Widget::MapWidget; 726package Crossfire::Client::Widget::MapWidget;
709 727
710use strict; 728use strict;
711 729
878 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { 896 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
879 $::CONN->send ("command run_stop"); 897 $::CONN->send ("command run_stop");
880 } 898 }
881} 899}
882 900
901#############################################################################
902
883package Crossfire::Client::Widget::Animator; 903package Crossfire::Client::Widget::Animator;
884 904
885use SDL::OpenGL; 905use SDL::OpenGL;
886 906
887our @ISA = Crossfire::Client::Widget::Bin::; 907our @ISA = Crossfire::Client::Widget::Bin::;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines