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.53 by root, Mon Apr 10 11:56:28 2006 UTC vs.
Revision 1.63 by root, Tue Apr 11 13:29:24 2006 UTC

1package Crossfire::Client::Widget; 1package CFClient::Widget;
2 2
3use strict; 3use strict;
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 9
10use Crossfire::Client; 10use CFClient;
11 11
12our ($FOCUS, $HOVER, $GRAB); # various widgets 12our ($FOCUS, $HOVER, $GRAB); # various widgets
13 13
14our $TOPLEVEL; 14our $TOPLEVEL;
15our $BUTTON_STATE; 15our $BUTTON_STATE;
34 $GRAB->update if $GRAB; 34 $GRAB->update if $GRAB;
35 } 35 }
36 36
37 $BUTTON_STATE |= 1 << ($ev->button - 1); 37 $BUTTON_STATE |= 1 << ($ev->button - 1);
38 38
39 $GRAB->button_down ($ev) if $GRAB; 39 $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB;
40} 40}
41 41
42sub feed_sdl_button_up_event { 42sub feed_sdl_button_up_event {
43 my ($ev) = @_; 43 my ($ev) = @_;
44 my ($x, $y) = ($ev->motion_x, $ev->motion_y); 44 my ($x, $y) = ($ev->motion_x, $ev->motion_y);
45 45
46 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); 46 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y);
47 47
48 $BUTTON_STATE &= ~(1 << ($ev->button - 1)); 48 $BUTTON_STATE &= ~(1 << ($ev->button - 1));
49
50 $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB;
49 51
50 if (!$BUTTON_STATE) { 52 if (!$BUTTON_STATE) {
51 my $grab = $GRAB; undef $GRAB; 53 my $grab = $GRAB; undef $GRAB;
52 $grab->update if $grab; 54 $grab->update if $grab;
53 $GRAB->update if $GRAB; 55 $GRAB->update if $GRAB;
65 67
66 $hover->update if $hover; 68 $hover->update if $hover;
67 $HOVER->update if $HOVER; 69 $HOVER->update if $HOVER;
68 } 70 }
69 71
70 $HOVER->mouse_motion ($ev) if $HOVER; 72 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER;
71} 73}
72 74
73sub new { 75sub new {
74 my $class = shift; 76 my $class = shift;
75 77
95sub size_allocate { 97sub size_allocate {
96 my ($self, $w, $h) = @_; 98 my ($self, $w, $h) = @_;
97 99
98 $self->{w} = $w; 100 $self->{w} = $w;
99 $self->{h} = $h; 101 $self->{h} = $h;
102}
103
104# translate global koordinates to local coordinate system
105sub translate {
106 my ($self, $x, $y) = @_;
107
108 $self->{parent}->translate ($x - $self->{x}, $y - $self->{y});
100} 109}
101 110
102sub focus_in { 111sub focus_in {
103 my ($self) = @_; 112 my ($self) = @_;
104 113
201 #$self->deactivate; 210 #$self->deactivate;
202} 211}
203 212
204############################################################################# 213#############################################################################
205 214
206package Crossfire::Client::Widget::Container; 215package CFClient::Widget::Container;
207 216
208our @ISA = Crossfire::Client::Widget::; 217our @ISA = CFClient::Widget::;
209 218
210sub new { 219sub new {
211 my ($class, @widgets) = @_; 220 my ($class, @widgets) = @_;
212 221
213 my $self = $class->SUPER::new (children => []); 222 my $self = $class->SUPER::new (children => []);
260 $_->draw for @{$self->{children}}; 269 $_->draw for @{$self->{children}};
261} 270}
262 271
263############################################################################# 272#############################################################################
264 273
265package Crossfire::Client::Widget::Bin; 274package CFClient::Widget::Bin;
266 275
267our @ISA = Crossfire::Client::Widget::Container::; 276our @ISA = CFClient::Widget::Container::;
268 277
269sub child { $_[0]->{children}[0] } 278sub child { $_[0]->{children}[0] }
270 279
271sub size_request { 280sub size_request {
272 $_[0]{children}[0]->size_request if $_[0]{children}[0]; 281 $_[0]{children}[0]->size_request if $_[0]{children}[0];
280 if $self->{children}[0] 289 if $self->{children}[0]
281} 290}
282 291
283############################################################################# 292#############################################################################
284 293
285package Crossfire::Client::Widget::Window; 294package CFClient::Widget::Window;
286 295
287our @ISA = Crossfire::Client::Widget::Bin::; 296our @ISA = CFClient::Widget::Bin::;
288 297
289use SDL::OpenGL; 298use SDL::OpenGL;
290 299
291sub new { 300sub new {
292 my ($class, $x, $y, $z, $w, $h) = @_; 301 my ($class, $x, $y, $z, $w, $h) = @_;
297} 306}
298 307
299sub update { 308sub update {
300 my ($self) = @_; 309 my ($self) = @_;
301 310
311 # we want to do this delayed...
302 $self->render_chld; 312 $self->render_chld;
303 $self->SUPER::update; 313 $self->SUPER::update;
304} 314}
305 315
306sub render_chld { 316sub render_chld {
307 my ($self) = @_; 317 my ($self) = @_;
308 318
309 $self->{texture} = 319 $self->{texture} =
310 Crossfire::Client::Texture->new_from_opengl ( 320 CFClient::Texture->new_from_opengl (
311 $self->{w}, $self->{h}, sub { $self->child->draw } 321 $self->{w}, $self->{h}, sub { $self->child->draw }
312 ); 322 );
313} 323}
314 324
315sub size_allocate { 325sub size_allocate {
332 or return; 342 or return;
333 343
334 glEnable GL_BLEND; 344 glEnable GL_BLEND;
335 glEnable GL_TEXTURE_2D; 345 glEnable GL_TEXTURE_2D;
336 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 346 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
337 glBindTexture GL_TEXTURE_2D, $tex->{name};
338 347
339 glBegin GL_QUADS; 348 $tex->draw_quad (0, 0, $w, $h);
340 glTexCoord 0, 0; glVertex 0, 0;
341 glTexCoord 0, 1; glVertex 0, $h;
342 glTexCoord 1, 1; glVertex $w, $h;
343 glTexCoord 1, 0; glVertex $w, 0;
344 glEnd;
345 349
346 glDisable GL_BLEND; 350 glDisable GL_BLEND;
347 glDisable GL_TEXTURE_2D; 351 glDisable GL_TEXTURE_2D;
348} 352}
349 353
350############################################################################# 354#############################################################################
351 355
352package Crossfire::Client::Widget::Frame; 356package CFClient::Widget::Frame;
353 357
354our @ISA = Crossfire::Client::Widget::Bin::; 358our @ISA = CFClient::Widget::Bin::;
355 359
356use SDL::OpenGL; 360use SDL::OpenGL;
357 361
358sub size_request { 362sub size_request {
359 my ($self) = @_; 363 my ($self) = @_;
382 386
383 my ($w, $h) = $chld->size_request; 387 my ($w, $h) = $chld->size_request;
384 388
385 glBegin GL_QUADS; 389 glBegin GL_QUADS;
386 glColor 0, 0, 0; 390 glColor 0, 0, 0;
387 glTexCoord 0, 0; glVertex 0 , 0; 391 glVertex 0 , 0;
388 glTexCoord 0, 1; glVertex 0 , $h + 4; 392 glVertex 0 , $h + 4;
389 glTexCoord 1, 1; glVertex $w + 4 , $h + 4; 393 glVertex $w + 4 , $h + 4;
390 glTexCoord 1, 0; glVertex $w + 4 , 0; 394 glVertex $w + 4 , 0;
391 glEnd; 395 glEnd;
392 396
393 $chld->draw; 397 $chld->draw;
394} 398}
395 399
396############################################################################# 400#############################################################################
397 401
398package Crossfire::Client::Widget::FancyFrame; 402package CFClient::Widget::FancyFrame;
399 403
400our @ISA = Crossfire::Client::Widget::Bin::; 404our @ISA = CFClient::Widget::Bin::;
401 405
402use SDL::OpenGL; 406use SDL::OpenGL;
403 407
404my @tex = 408my @tex =
405 map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } 409 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
406 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 410 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
407 411
408sub size_request { 412sub size_request {
409 my ($self) = @_; 413 my ($self) = @_;
410 414
445 glEnable GL_TEXTURE_2D; 449 glEnable GL_TEXTURE_2D;
446 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 450 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
447 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 451 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
448 452
449 my $top = $tex[1]; 453 my $top = $tex[1];
450 glBindTexture GL_TEXTURE_2D, $top->{name}; 454 $top->draw_quad (0, 0, $w, $top->{height});
451
452 glBegin GL_QUADS;
453 glTexCoord 0, 0; glVertex 0 , 0;
454 glTexCoord 0, 1; glVertex 0 , $top->{height};
455 glTexCoord 1, 1; glVertex $w , $top->{height};
456 glTexCoord 1, 0; glVertex $w , 0;
457 glEnd;
458 455
459 my $left = $tex[3]; 456 my $left = $tex[3];
460 glBindTexture GL_TEXTURE_2D, $left->{name}; 457 $left->draw_quad (0, $top->{height}, $left->{width}, $ch);
461
462 glBegin GL_QUADS;
463 glTexCoord 0, 0; glVertex 0 , $top->{height};
464 glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch;
465 glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch;
466 glTexCoord 1, 0; glVertex $left->{width}, $top->{height};
467 glEnd;
468 458
469 my $right = $tex[2]; 459 my $right = $tex[2];
470 glBindTexture GL_TEXTURE_2D, $right->{name}; 460 $right->draw_quad ($w - $right->{width}, $top->{height}, $right->{width}, $ch);
471
472 glBegin GL_QUADS;
473 glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height};
474 glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch;
475 glTexCoord 1, 1; glVertex $w , $top->{height} + $ch;
476 glTexCoord 1, 0; glVertex $w , $top->{height};
477 glEnd;
478 461
479 my $bottom = $tex[4]; 462 my $bottom = $tex[4];
480 glBindTexture GL_TEXTURE_2D, $bottom->{name}; 463 $bottom->draw_quad (0, $h - $bottom->{height}, $w, $bottom->{height});
481
482 glBegin GL_QUADS;
483 glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height};
484 glTexCoord 0, 1; glVertex 0 , $h;
485 glTexCoord 1, 1; glVertex $w , $h;
486 glTexCoord 1, 0; glVertex $w , $h - $bottom->{height};
487 glEnd;
488 464
489 my $bg = $tex[0]; 465 my $bg = $tex[0];
490 glBindTexture GL_TEXTURE_2D, $bg->{name}; 466 glBindTexture GL_TEXTURE_2D, $bg->{name};
491 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 467 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
492 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; 468 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT;
493 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; 469 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT;
494 470
495 my $rep_x = $cw / $bg->{width}; 471 my $rep_x = $cw / $bg->{width};
496 my $rep_y = $ch / $bg->{height}; 472 my $rep_y = $ch / $bg->{height};
497 473
498 glBegin GL_QUADS; 474 $bg->draw_quad ($left->{width}, $top->{height}, $cw, $ch);
499 glTexCoord 0, 0; glVertex $left->{width}, $top->{height};
500 glTexCoord 0, $rep_y; glVertex $left->{width}, $top->{height} + $ch;
501 glTexCoord $rep_x, $rep_y; glVertex $left->{width} + $cw , $top->{height} + $ch;
502 glTexCoord $rep_x, 0; glVertex $left->{width} + $cw , $top->{height};
503 glEnd;
504 475
505 glDisable GL_BLEND; 476 glDisable GL_BLEND;
506 glDisable GL_TEXTURE_2D; 477 glDisable GL_TEXTURE_2D;
507 478
508 $self->child->draw; 479 $self->child->draw;
509 480
510} 481}
511 482
512############################################################################# 483#############################################################################
513 484
514package Crossfire::Client::Widget::Table; 485package CFClient::Widget::Table;
515 486
516our @ISA = Crossfire::Client::Widget::Bin::; 487our @ISA = CFClient::Widget::Bin::;
517 488
518use SDL::OpenGL; 489use SDL::OpenGL;
519 490
520sub add { 491sub add {
521 my ($self, $x, $y, $chld) = @_; 492 my ($self, $x, $y, $chld) = @_;
596 } 567 }
597} 568}
598 569
599############################################################################# 570#############################################################################
600 571
601package Crossfire::Client::Widget::VBox; 572package CFClient::Widget::VBox;
602 573
603our @ISA = Crossfire::Client::Widget::Container::; 574our @ISA = CFClient::Widget::Container::;
604 575
605use SDL::OpenGL; 576use SDL::OpenGL;
606 577
607sub size_request { 578sub size_request {
608 my ($self) = @_; 579 my ($self) = @_;
656 } 627 }
657} 628}
658 629
659############################################################################# 630#############################################################################
660 631
661package Crossfire::Client::Widget::Label; 632package CFClient::Widget::Label;
662 633
663our @ISA = Crossfire::Client::Widget::; 634our @ISA = CFClient::Widget::;
664 635
665use SDL::OpenGL; 636use SDL::OpenGL;
666 637
667sub new { 638sub new {
668 my ($class, $x, $y, $z, $height, $text) = @_; 639 my ($class, $x, $y, $z, $height, $text) = @_;
669 640
670 $height ||= $::FONTSIZE; 641 $height ||= $::FONTSIZE;
671 642
672 # TODO: color, and make height, xyz etc. optional 643 # TODO: color, and make height, xyz etc. optional
673 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); 644 my $self = $class->SUPER::new (
645 color => [1, 1, 1],
646 x => $x,
647 y => $y,
648 z => $z,
649 height => $height,
650 layout => new CFClient::Layout $height,
651 );
674 652
675 $self->set_text ($text); 653 $self->set_text ($text);
676 654
677 $self 655 $self
678} 656}
679 657
680sub set_text { 658sub set_text {
681 my ($self, $text) = @_; 659 my ($self, $text) = @_;
682 660
683 $self->{text} = $text; 661 $self->{text} = $text;
684 $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; 662 $self->{layout}->set_markup ($text);
685 663
686 $self->update; 664 delete $self->{texture};
687} 665}
688 666
689sub get_text { 667sub get_text {
690 my ($self, $text) = @_; 668 my ($self, $text) = @_;
691 669
693} 671}
694 672
695sub size_request { 673sub size_request {
696 my ($self) = @_; 674 my ($self) = @_;
697 675
676 $self->{layout}->set_width;
677 $self->{layout}->size
698 if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack 678# if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack
699 ( 679# (
700 $self->{texture}{width}, 680# $self->{texture}{width},
701 $self->{texture}{height}, 681# $self->{texture}{height},
702 ) 682# )
703 } else { 683# } else {
704 my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height}; 684# my ($w, $h, $data) = CFClient::font_render "Yy", $self->{height};
705 685#
706 ($w, $h) 686# ($w, $h)
707 } 687# }
688}
708 689
690sub size_allocate {
691 my ($self, $w, $h) = @_;
692
693 $self->SUPER::size_allocate ($w, $h);
694 delete $self->{texture};
709} 695}
710 696
711sub _draw { 697sub _draw {
712 my ($self) = @_; 698 my ($self) = @_;
713 699
714 my $tex = $self->{texture}; 700 my $tex = $self->{texture} ||= do {
701 $self->{layout}->set_width ($self->{w});
702 new_from_layout CFClient::Texture $self->{layout};
703 };
715 704
716 glEnable GL_BLEND; 705 glEnable GL_BLEND;
717 glEnable GL_TEXTURE_2D; 706 glEnable GL_TEXTURE_2D;
718 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 707 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
719 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 708 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
720 glBindTexture GL_TEXTURE_2D, $tex->{name};
721 709
722 glColor 1, 0, 0, 1; # TODO color 710 glColor @{$self->{color}};
723 711
724 glBegin GL_QUADS; 712 $tex->draw_quad (0, 0);
725 glTexCoord 0, 0; glVertex 0 , 0;
726 glTexCoord 0, 1; glVertex 0 , $tex->{height};
727 glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height};
728 glTexCoord 1, 0; glVertex $tex->{width}, 0;
729 glEnd;
730 713
731 glDisable GL_BLEND; 714 glDisable GL_BLEND;
732 glDisable GL_TEXTURE_2D; 715 glDisable GL_TEXTURE_2D;
733} 716}
734 717
735############################################################################# 718#############################################################################
736 719
737package Crossfire::Client::Widget::Entry; 720package CFClient::Widget::Entry;
738 721
739our @ISA = Crossfire::Client::Widget::Label::; 722our @ISA = CFClient::Widget::Label::;
740 723
741use SDL; 724use SDL;
742use SDL::OpenGL; 725use SDL::OpenGL;
743 726
744sub key_down { 727sub key_down {
753 736
754 if ($sym == SDLK_BACKSPACE) { 737 if ($sym == SDLK_BACKSPACE) {
755 substr $text, -1, 1, ''; 738 substr $text, -1, 1, '';
756 } elsif ($uni) { 739 } elsif ($uni) {
757 $text .= chr $uni; 740 $text .= chr $uni;
758 print "$uni <$text>\n";#d#
759 } 741 }
760 742
761 $self->set_text ($text); 743 $self->set_text ($text);
762} 744}
763 745
764sub button_down { 746sub button_down {
765 my ($self, $ev) = @_; 747 my ($self, $ev) = @_;
766 748
767 $self->focus_in; 749 $self->focus_in;
750}
751
752sub mouse_motion {
753 my ($self, $ev, $x, $y) = @_;
754 printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d#
768} 755}
769 756
770sub _draw { 757sub _draw {
771 my ($self) = @_; 758 my ($self) = @_;
772 759
786 $self->SUPER::_draw; 773 $self->SUPER::_draw;
787} 774}
788 775
789############################################################################# 776#############################################################################
790 777
791package Crossfire::Client::Widget::MapWidget; 778package CFClient::Widget::MapWidget;
792 779
793use strict; 780use strict;
794 781
795use List::Util qw(min max); 782use List::Util qw(min max);
796 783
797use SDL; 784use SDL;
798use SDL::OpenGL; 785use SDL::OpenGL;
799use SDL::OpenGL::Constants; 786use SDL::OpenGL::Constants;
800 787
801our @ISA = Crossfire::Client::Widget::; 788our @ISA = CFClient::Widget::;
802 789
803sub key_down { 790sub key_down {
804 print "MAPKEYDOWN\n"; 791 print "MAPKEYDOWN\n";
805} 792}
806 793
842 glEnable GL_TEXTURE_2D; 829 glEnable GL_TEXTURE_2D;
843 glEnable GL_BLEND; 830 glEnable GL_BLEND;
844 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 831 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
845 832
846 my $sw4 = ($sw + 3) & ~3; 833 my $sw4 = ($sw + 3) & ~3;
847 my $lighting = "\x00" x ($sw4 * $sh); 834 my $darkness = "\x00" x ($sw4 * $sh);
848 835
849 for my $x (0 .. $sw - 1) { 836 for my $x (0 .. $sw - 1) {
837 my $row = $map->[$x + $xofs];
850 for my $y (0 .. $sh - 1) { 838 for my $y (0 .. $sh - 1) {
851 839
852 my $cell = $map->[$x + $xofs][$y + $yofs] 840 my $cell = $row->[$y + $yofs]
853 or next; 841 or next;
854 842
855 my $darkness = $cell->[0] * (1 / 255); 843 my $dark = $cell->[0];
856 if ($darkness < 0) { 844 if ($dark < 0) {
857 $darkness = $cell->[1] ? 0.2 : 0; 845 substr $darkness, $y * $sw4 + $x, 1, chr 224;
846 } else {
847 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark;
858 } 848 }
859 substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255;
860 849
861 for my $num (grep $_, @$cell[1,2,3]) { 850 for my $num (grep $_, @$cell[1,2,3]) {
862 my $tex = $::CONN->{face}[$num]{texture} || next; 851 my $tex = $::CONN->{face}[$num]{texture} || next;
863 852
864 glBindTexture GL_TEXTURE_2D, $tex->{name};
865
866 my $w = $tex->{width}; 853 my $w = $tex->{width};
867 my $h = $tex->{height}; 854 my $h = $tex->{height};
868 855
869 my $px = ($x + 1) * 32 - $w; 856 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h);
870 my $py = ($y + 1) * 32 - $h;
871
872 glBegin GL_QUADS;
873 glTexCoord 0, 0; glVertex $px , $py;
874 glTexCoord 0, 1; glVertex $px , $py + $h;
875 glTexCoord 1, 1; glVertex $px + $w, $py + $h;
876 glTexCoord 1, 0; glVertex $px + $w, $py;
877 glEnd;
878 } 857 }
879 } 858 }
880 } 859 }
881 860
882# if (1) { # higher quality darkness 861# if (1) { # higher quality darkness
887# 866#
888# $lighting = $pb->get_pixels; 867# $lighting = $pb->get_pixels;
889# $lighting =~ s/(.)../$1/gs; 868# $lighting =~ s/(.)../$1/gs;
890# } 869# }
891 870
892 $lighting = new Crossfire::Client::Texture 871 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
872 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
873
874 $darkness = new CFClient::Texture
893 width => $sw4, 875 width => $sw4,
894 height => $sh, 876 height => $sh,
895 data => $lighting, 877 data => $darkness,
896 internalformat => GL_ALPHA, 878 internalformat => GL_ALPHA,
897 format => GL_ALPHA; 879 format => GL_ALPHA;
898 880
899 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
900 glColor 0.5, 0.5, 0.5, 1; 881 glColor 0.45, 0.45, 0.45, 1;
901 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 882 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32);
902 glBindTexture GL_TEXTURE_2D, $lighting->{name};
903 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
904 glBegin GL_QUADS;
905 glTexCoord 0, 0; glVertex 0 , 0;
906 glTexCoord 0, 1; glVertex 0 , $sh * 32;
907 glTexCoord 1, 1; glVertex $sw4 * 32, $sh * 32;
908 glTexCoord 1, 0; glVertex $sw4 * 32, 0;
909 glEnd;
910 883
911 glDisable GL_TEXTURE_2D; 884 glDisable GL_TEXTURE_2D;
912 glDisable GL_BLEND; 885 glDisable GL_BLEND;
913} 886}
914 887
963 } 936 }
964} 937}
965 938
966############################################################################# 939#############################################################################
967 940
968package Crossfire::Client::Widget::Animator; 941package CFClient::Widget::Animator;
969 942
970use SDL::OpenGL; 943use SDL::OpenGL;
971 944
972our @ISA = Crossfire::Client::Widget::Bin::; 945our @ISA = CFClient::Widget::Bin::;
973 946
974sub moveto { 947sub moveto {
975 my ($self, $x, $y) = @_; 948 my ($self, $x, $y) = @_;
976 949
977 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 950 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
978 $self->{speed} = 2; 951 $self->{speed} = 0.001;
979 $self->{time} = 1; 952 $self->{time} = 1;
980 953
981 ::animation_start $self; 954 ::animation_start $self;
982} 955}
983 956
1005 glPopMatrix; 978 glPopMatrix;
1006} 979}
1007 980
1008############################################################################# 981#############################################################################
1009 982
1010package Crossfire::Client::Widget::Toplevel; 983package CFClient::Widget::Toplevel;
1011 984
1012our @ISA = Crossfire::Client::Widget::Container::; 985our @ISA = CFClient::Widget::Container::;
1013 986
1014sub size_request { 987sub size_request {
1015 ($::WIDTH, $::HEIGHT) 988 ($::WIDTH, $::HEIGHT)
1016} 989}
1017 990
1022 995
1023 $_->size_allocate ($_->size_request) 996 $_->size_allocate ($_->size_request)
1024 for @{$self->{children}}; 997 for @{$self->{children}};
1025} 998}
1026 999
1000sub translate {
1001 my ($self, $x, $y) = @_;
1002
1003 ($x, $y)
1004}
1005
1027sub update { 1006sub update {
1028 my ($self) = @_; 1007 my ($self) = @_;
1029 1008
1030 $self->size_allocate ($self->size_request); 1009 $self->size_allocate ($self->size_request);
1031 ::refresh (); 1010 ::refresh ();
1045 $self->_draw; 1024 $self->_draw;
1046} 1025}
1047 1026
1048############################################################################# 1027#############################################################################
1049 1028
1050package Crossfire::Client::Widget; 1029package CFClient::Widget;
1051 1030
1052$TOPLEVEL = new Crossfire::Client::Widget::Toplevel; 1031$TOPLEVEL = new CFClient::Widget::Toplevel;
1053 1032
10541 10331
1055 1034

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines