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.64 by root, Tue Apr 11 13:38:22 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, %arg) = @_;
221
222 my $children = delete $arg{children} || [];
212 223
213 my $self = $class->SUPER::new (children => []); 224 my $self = $class->SUPER::new (children => []);
214 $self->add ($_) for @widgets; 225 $self->add ($_) for @$children;
215 226
216 $self 227 $self
217} 228}
218 229
219sub add { 230sub add {
260 $_->draw for @{$self->{children}}; 271 $_->draw for @{$self->{children}};
261} 272}
262 273
263############################################################################# 274#############################################################################
264 275
265package Crossfire::Client::Widget::Bin; 276package CFClient::Widget::Bin;
266 277
267our @ISA = Crossfire::Client::Widget::Container::; 278our @ISA = CFClient::Widget::Container::;
268 279
269sub child { $_[0]->{children}[0] } 280sub child { $_[0]->{children}[0] }
270 281
271sub size_request { 282sub size_request {
272 $_[0]{children}[0]->size_request if $_[0]{children}[0]; 283 $_[0]{children}[0]->size_request if $_[0]{children}[0];
280 if $self->{children}[0] 291 if $self->{children}[0]
281} 292}
282 293
283############################################################################# 294#############################################################################
284 295
285package Crossfire::Client::Widget::Window; 296package CFClient::Widget::Window;
286 297
287our @ISA = Crossfire::Client::Widget::Bin::; 298our @ISA = CFClient::Widget::Bin::;
288 299
289use SDL::OpenGL; 300use SDL::OpenGL;
290 301
291sub new { 302sub new {
292 my ($class, $x, $y, $z, $w, $h) = @_; 303 my ($class, %arg) = @_;
293 304
294 my $self = $class->SUPER::new; 305 my $self = $class->SUPER::new (%arg);
295
296 @$self{qw(x y z w h)} = ($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, %arg) = @_;
669
670 $height ||= $::FONTSIZE;
671 640
672 # TODO: color, and make height, xyz etc. optional 641 # TODO: color, and make height, xyz etc. optional
673 my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); 642 my $self = $class->SUPER::new (
643 color => [1, 1, 1],
644 height => $::FONTSIZE,
645 text => "",
646 layout => new CFClient::Layout,
647 %arg
648 );
674 649
675 $self->set_text ($text); 650 $self->set_text ($self->{text});
676 651
677 $self 652 $self
678} 653}
679 654
680sub set_text { 655sub set_text {
681 my ($self, $text) = @_; 656 my ($self, $text) = @_;
682 657
683 $self->{text} = $text; 658 $self->{text} = $text;
684 $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; 659 $self->{layout}->set_markup ($text);
685 660
686 $self->update; 661 delete $self->{texture};
687} 662}
688 663
689sub get_text { 664sub get_text {
690 my ($self, $text) = @_; 665 my ($self, $text) = @_;
691 666
693} 668}
694 669
695sub size_request { 670sub size_request {
696 my ($self) = @_; 671 my ($self) = @_;
697 672
673 $self->{layout}->set_width;
674 $self->{layout}->set_height ($self->{height});
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) = CFClient::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 CFClient::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 @{$self->{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
735############################################################################# 716#############################################################################
736 717
737package Crossfire::Client::Widget::Entry; 718package CFClient::Widget::Entry;
738 719
739our @ISA = Crossfire::Client::Widget::Label::; 720our @ISA = CFClient::Widget::Label::;
740 721
741use SDL; 722use SDL;
742use SDL::OpenGL; 723use SDL::OpenGL;
743 724
744sub key_down { 725sub key_down {
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
786 $self->SUPER::_draw; 771 $self->SUPER::_draw;
787} 772}
788 773
789############################################################################# 774#############################################################################
790 775
791package Crossfire::Client::Widget::MapWidget; 776package CFClient::Widget::MapWidget;
792 777
793use strict; 778use strict;
794 779
795use List::Util qw(min max); 780use List::Util qw(min max);
796 781
797use SDL; 782use SDL;
798use SDL::OpenGL; 783use SDL::OpenGL;
799use SDL::OpenGL::Constants; 784use SDL::OpenGL::Constants;
800 785
801our @ISA = Crossfire::Client::Widget::; 786our @ISA = CFClient::Widget::;
787
788sub new {
789 my $class = shift;
790
791 $class->SUPER::new (z => -1, @_)
792}
802 793
803sub key_down { 794sub key_down {
804 print "MAPKEYDOWN\n"; 795 print "MAPKEYDOWN\n";
805} 796}
806 797
842 glEnable GL_TEXTURE_2D; 833 glEnable GL_TEXTURE_2D;
843 glEnable GL_BLEND; 834 glEnable GL_BLEND;
844 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 835 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
845 836
846 my $sw4 = ($sw + 3) & ~3; 837 my $sw4 = ($sw + 3) & ~3;
847 my $lighting = "\x00" x ($sw4 * $sh); 838 my $darkness = "\x00" x ($sw4 * $sh);
848 839
849 for my $x (0 .. $sw - 1) { 840 for my $x (0 .. $sw - 1) {
841 my $row = $map->[$x + $xofs];
850 for my $y (0 .. $sh - 1) { 842 for my $y (0 .. $sh - 1) {
851 843
852 my $cell = $map->[$x + $xofs][$y + $yofs] 844 my $cell = $row->[$y + $yofs]
853 or next; 845 or next;
854 846
855 my $darkness = $cell->[0] * (1 / 255); 847 my $dark = $cell->[0];
856 if ($darkness < 0) { 848 if ($dark < 0) {
857 $darkness = $cell->[1] ? 0.2 : 0; 849 substr $darkness, $y * $sw4 + $x, 1, chr 224;
850 } else {
851 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark;
858 } 852 }
859 substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255;
860 853
861 for my $num (grep $_, @$cell[1,2,3]) { 854 for my $num (grep $_, @$cell[1,2,3]) {
862 my $tex = $::CONN->{face}[$num]{texture} || next; 855 my $tex = $::CONN->{face}[$num]{texture} || next;
863 856
864 glBindTexture GL_TEXTURE_2D, $tex->{name};
865
866 my $w = $tex->{width}; 857 my $w = $tex->{width};
867 my $h = $tex->{height}; 858 my $h = $tex->{height};
868 859
869 my $px = ($x + 1) * 32 - $w; 860 $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 } 861 }
879 } 862 }
880 } 863 }
881 864
882# if (1) { # higher quality darkness 865# if (1) { # higher quality darkness
887# 870#
888# $lighting = $pb->get_pixels; 871# $lighting = $pb->get_pixels;
889# $lighting =~ s/(.)../$1/gs; 872# $lighting =~ s/(.)../$1/gs;
890# } 873# }
891 874
892 $lighting = new Crossfire::Client::Texture 875 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
876 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
877
878 $darkness = new CFClient::Texture
893 width => $sw4, 879 width => $sw4,
894 height => $sh, 880 height => $sh,
895 data => $lighting, 881 data => $darkness,
896 internalformat => GL_ALPHA, 882 internalformat => GL_ALPHA,
897 format => GL_ALPHA; 883 format => GL_ALPHA;
898 884
899 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
900 glColor 0.5, 0.5, 0.5, 1; 885 glColor 0.45, 0.45, 0.45, 1;
901 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 886 $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 887
911 glDisable GL_TEXTURE_2D; 888 glDisable GL_TEXTURE_2D;
912 glDisable GL_BLEND; 889 glDisable GL_BLEND;
913} 890}
914 891
963 } 940 }
964} 941}
965 942
966############################################################################# 943#############################################################################
967 944
968package Crossfire::Client::Widget::Animator; 945package CFClient::Widget::Animator;
969 946
970use SDL::OpenGL; 947use SDL::OpenGL;
971 948
972our @ISA = Crossfire::Client::Widget::Bin::; 949our @ISA = CFClient::Widget::Bin::;
973 950
974sub moveto { 951sub moveto {
975 my ($self, $x, $y) = @_; 952 my ($self, $x, $y) = @_;
976 953
977 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 954 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
978 $self->{speed} = 2; 955 $self->{speed} = 0.001;
979 $self->{time} = 1; 956 $self->{time} = 1;
980 957
981 ::animation_start $self; 958 ::animation_start $self;
982} 959}
983 960
1005 glPopMatrix; 982 glPopMatrix;
1006} 983}
1007 984
1008############################################################################# 985#############################################################################
1009 986
1010package Crossfire::Client::Widget::Toplevel; 987package CFClient::Widget::Toplevel;
1011 988
1012our @ISA = Crossfire::Client::Widget::Container::; 989our @ISA = CFClient::Widget::Container::;
1013 990
1014sub size_request { 991sub size_request {
1015 ($::WIDTH, $::HEIGHT) 992 ($::WIDTH, $::HEIGHT)
1016} 993}
1017 994
1022 999
1023 $_->size_allocate ($_->size_request) 1000 $_->size_allocate ($_->size_request)
1024 for @{$self->{children}}; 1001 for @{$self->{children}};
1025} 1002}
1026 1003
1004sub translate {
1005 my ($self, $x, $y) = @_;
1006
1007 ($x, $y)
1008}
1009
1027sub update { 1010sub update {
1028 my ($self) = @_; 1011 my ($self) = @_;
1029 1012
1030 $self->size_allocate ($self->size_request); 1013 $self->size_allocate ($self->size_request);
1031 ::refresh (); 1014 ::refresh ();
1045 $self->_draw; 1028 $self->_draw;
1046} 1029}
1047 1030
1048############################################################################# 1031#############################################################################
1049 1032
1050package Crossfire::Client::Widget; 1033package CFClient::Widget;
1051 1034
1052$TOPLEVEL = new Crossfire::Client::Widget::Toplevel; 1035$TOPLEVEL = new CFClient::Widget::Toplevel;
1053 1036
10541 10371
1055 1038

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines