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.59 by root, Tue Apr 11 13:05:12 2006 UTC

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
332 or return; 341 or return;
333 342
334 glEnable GL_BLEND; 343 glEnable GL_BLEND;
335 glEnable GL_TEXTURE_2D; 344 glEnable GL_TEXTURE_2D;
336 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 345 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
337 glBindTexture GL_TEXTURE_2D, $tex->{name};
338 346
339 glBegin GL_QUADS; 347 $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 348
346 glDisable GL_BLEND; 349 glDisable GL_BLEND;
347 glDisable GL_TEXTURE_2D; 350 glDisable GL_TEXTURE_2D;
348} 351}
349 352
382 385
383 my ($w, $h) = $chld->size_request; 386 my ($w, $h) = $chld->size_request;
384 387
385 glBegin GL_QUADS; 388 glBegin GL_QUADS;
386 glColor 0, 0, 0; 389 glColor 0, 0, 0;
387 glTexCoord 0, 0; glVertex 0 , 0; 390 glVertex 0 , 0;
388 glTexCoord 0, 1; glVertex 0 , $h + 4; 391 glVertex 0 , $h + 4;
389 glTexCoord 1, 1; glVertex $w + 4 , $h + 4; 392 glVertex $w + 4 , $h + 4;
390 glTexCoord 1, 0; glVertex $w + 4 , 0; 393 glVertex $w + 4 , 0;
391 glEnd; 394 glEnd;
392 395
393 $chld->draw; 396 $chld->draw;
394} 397}
395 398
445 glEnable GL_TEXTURE_2D; 448 glEnable GL_TEXTURE_2D;
446 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 449 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
447 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 450 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
448 451
449 my $top = $tex[1]; 452 my $top = $tex[1];
450 glBindTexture GL_TEXTURE_2D, $top->{name}; 453 $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 454
459 my $left = $tex[3]; 455 my $left = $tex[3];
460 glBindTexture GL_TEXTURE_2D, $left->{name}; 456 $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 457
469 my $right = $tex[2]; 458 my $right = $tex[2];
470 glBindTexture GL_TEXTURE_2D, $right->{name}; 459 $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 460
479 my $bottom = $tex[4]; 461 my $bottom = $tex[4];
480 glBindTexture GL_TEXTURE_2D, $bottom->{name}; 462 $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 463
489 my $bg = $tex[0]; 464 my $bg = $tex[0];
490 glBindTexture GL_TEXTURE_2D, $bg->{name}; 465 glBindTexture GL_TEXTURE_2D, $bg->{name};
491 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 466 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
492 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; 467 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT;
493 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; 468 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT;
494 469
495 my $rep_x = $cw / $bg->{width}; 470 my $rep_x = $cw / $bg->{width};
496 my $rep_y = $ch / $bg->{height}; 471 my $rep_y = $ch / $bg->{height};
497 472
498 glBegin GL_QUADS; 473 $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 474
505 glDisable GL_BLEND; 475 glDisable GL_BLEND;
506 glDisable GL_TEXTURE_2D; 476 glDisable GL_TEXTURE_2D;
507 477
508 $self->child->draw; 478 $self->child->draw;
668 my ($class, $x, $y, $z, $height, $text) = @_; 638 my ($class, $x, $y, $z, $height, $text) = @_;
669 639
670 $height ||= $::FONTSIZE; 640 $height ||= $::FONTSIZE;
671 641
672 # TODO: color, and make height, xyz etc. optional 642 # TODO: color, and make height, xyz etc. optional
673 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); 643 my $self = $class->SUPER::new (
644 x => $x,
645 y => $y,
646 z => $z,
647 height => $height,
648 layout => new Crossfire::Client::Layout,
649 );
674 650
675 $self->set_text ($text); 651 $self->set_text ($text);
676 652
677 $self 653 $self
678} 654}
679 655
680sub set_text { 656sub set_text {
681 my ($self, $text) = @_; 657 my ($self, $text) = @_;
682 658
683 $self->{text} = $text; 659 $self->{text} = $text;
684 $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; 660 $self->{layout}->set_markup ($text);
685 661
686 $self->update; 662 delete $self->{texture};
687} 663}
688 664
689sub get_text { 665sub get_text {
690 my ($self, $text) = @_; 666 my ($self, $text) = @_;
691 667
693} 669}
694 670
695sub size_request { 671sub size_request {
696 my ($self) = @_; 672 my ($self) = @_;
697 673
674 $self->{layout}->set_width;
675 $self->{layout}->size
698 if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack 676# if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack
699 ( 677# (
700 $self->{texture}{width}, 678# $self->{texture}{width},
701 $self->{texture}{height}, 679# $self->{texture}{height},
702 ) 680# )
703 } else { 681# } else {
704 my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height}; 682# my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height};
705 683#
706 ($w, $h) 684# ($w, $h)
707 } 685# }
686}
708 687
688sub size_allocate {
689 my ($self, $w, $h) = @_;
690
691 $self->SUPER::size_allocate ($w, $h);
692 delete $self->{texture};
709} 693}
710 694
711sub _draw { 695sub _draw {
712 my ($self) = @_; 696 my ($self) = @_;
713 697
714 my $tex = $self->{texture}; 698 my $tex = $self->{texture} ||= do {
699 $self->{layout}->set_width ($self->{w});
700 new_from_layout Crossfire::Client::Texture $self->{layout};
701 };
715 702
716 glEnable GL_BLEND; 703 glEnable GL_BLEND;
717 glEnable GL_TEXTURE_2D; 704 glEnable GL_TEXTURE_2D;
718 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 705 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
719 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 706 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
720 glBindTexture GL_TEXTURE_2D, $tex->{name};
721 707
722 glColor 1, 0, 0, 1; # TODO color 708 glColor 1, 0, 0, 1; # TODO color
723 709
724 glBegin GL_QUADS; 710 $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 711
731 glDisable GL_BLEND; 712 glDisable GL_BLEND;
732 glDisable GL_TEXTURE_2D; 713 glDisable GL_TEXTURE_2D;
733} 714}
734 715
753 734
754 if ($sym == SDLK_BACKSPACE) { 735 if ($sym == SDLK_BACKSPACE) {
755 substr $text, -1, 1, ''; 736 substr $text, -1, 1, '';
756 } elsif ($uni) { 737 } elsif ($uni) {
757 $text .= chr $uni; 738 $text .= chr $uni;
758 print "$uni <$text>\n";#d#
759 } 739 }
760 740
761 $self->set_text ($text); 741 $self->set_text ($text);
762} 742}
763 743
764sub button_down { 744sub button_down {
765 my ($self, $ev) = @_; 745 my ($self, $ev) = @_;
766 746
767 $self->focus_in; 747 $self->focus_in;
748}
749
750sub mouse_motion {
751 my ($self, $ev, $x, $y) = @_;
752 printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d#
768} 753}
769 754
770sub _draw { 755sub _draw {
771 my ($self) = @_; 756 my ($self) = @_;
772 757
842 glEnable GL_TEXTURE_2D; 827 glEnable GL_TEXTURE_2D;
843 glEnable GL_BLEND; 828 glEnable GL_BLEND;
844 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 829 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
845 830
846 my $sw4 = ($sw + 3) & ~3; 831 my $sw4 = ($sw + 3) & ~3;
847 my $lighting = "\x00" x ($sw4 * $sh); 832 my $darkness = "\x00" x ($sw4 * $sh);
848 833
849 for my $x (0 .. $sw - 1) { 834 for my $x (0 .. $sw - 1) {
835 my $row = $map->[$x + $xofs];
850 for my $y (0 .. $sh - 1) { 836 for my $y (0 .. $sh - 1) {
851 837
852 my $cell = $map->[$x + $xofs][$y + $yofs] 838 my $cell = $row->[$y + $yofs]
853 or next; 839 or next;
854 840
855 my $darkness = $cell->[0] * (1 / 255); 841 my $dark = $cell->[0];
856 if ($darkness < 0) { 842 if ($dark < 0) {
857 $darkness = $cell->[1] ? 0.2 : 0; 843 substr $darkness, $y * $sw4 + $x, 1, chr 224;
844 } else {
845 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark;
858 } 846 }
859 substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255;
860 847
861 for my $num (grep $_, @$cell[1,2,3]) { 848 for my $num (grep $_, @$cell[1,2,3]) {
862 my $tex = $::CONN->{face}[$num]{texture} || next; 849 my $tex = $::CONN->{face}[$num]{texture} || next;
863 850
864 glBindTexture GL_TEXTURE_2D, $tex->{name};
865
866 my $w = $tex->{width}; 851 my $w = $tex->{width};
867 my $h = $tex->{height}; 852 my $h = $tex->{height};
868 853
869 my $px = ($x + 1) * 32 - $w; 854 $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 } 855 }
879 } 856 }
880 } 857 }
881 858
882# if (1) { # higher quality darkness 859# if (1) { # higher quality darkness
887# 864#
888# $lighting = $pb->get_pixels; 865# $lighting = $pb->get_pixels;
889# $lighting =~ s/(.)../$1/gs; 866# $lighting =~ s/(.)../$1/gs;
890# } 867# }
891 868
869 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
870 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
871
892 $lighting = new Crossfire::Client::Texture 872 $darkness = new Crossfire::Client::Texture
893 width => $sw4, 873 width => $sw4,
894 height => $sh, 874 height => $sh,
895 data => $lighting, 875 data => $darkness,
896 internalformat => GL_ALPHA, 876 internalformat => GL_ALPHA,
897 format => GL_ALPHA; 877 format => GL_ALPHA;
898 878
899 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
900 glColor 0.5, 0.5, 0.5, 1; 879 glColor 0.45, 0.45, 0.45, 1;
901 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 880 $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 881
911 glDisable GL_TEXTURE_2D; 882 glDisable GL_TEXTURE_2D;
912 glDisable GL_BLEND; 883 glDisable GL_BLEND;
913} 884}
914 885
973 944
974sub moveto { 945sub moveto {
975 my ($self, $x, $y) = @_; 946 my ($self, $x, $y) = @_;
976 947
977 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 948 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
978 $self->{speed} = 2; 949 $self->{speed} = 0.001;
979 $self->{time} = 1; 950 $self->{time} = 1;
980 951
981 ::animation_start $self; 952 ::animation_start $self;
982} 953}
983 954
1022 993
1023 $_->size_allocate ($_->size_request) 994 $_->size_allocate ($_->size_request)
1024 for @{$self->{children}}; 995 for @{$self->{children}};
1025} 996}
1026 997
998sub translate {
999 my ($self, $x, $y) = @_;
1000
1001 ($x, $y)
1002}
1003
1027sub update { 1004sub update {
1028 my ($self) = @_; 1005 my ($self) = @_;
1029 1006
1030 $self->size_allocate ($self->size_request); 1007 $self->size_allocate ($self->size_request);
1031 ::refresh (); 1008 ::refresh ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines