ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/MapWidget.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/MapWidget.pm (file contents):
Revision 1.109 by root, Tue Jul 17 17:39:07 2007 UTC vs.
Revision 1.110 by root, Thu Jul 19 13:45:18 2007 UTC

430 } 430 }
431 431
432 $res 432 $res
433} 433}
434 434
435sub invoke_visibility_change {
436 my ($self) = @_;
437
438 $self->refresh_hook;
439
440 0
441}
442
435sub set_magicmap { 443sub set_magicmap {
436 my ($self, $w, $h, $x, $y, $data) = @_; 444 my ($self, $w, $h, $x, $y, $data) = @_;
437 445
438 $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w; 446 $x -= $::MAP->ox + 1 + int 0.5 * $::MAP->w;
439 $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h; 447 $y -= $::MAP->oy + 1 + int 0.5 * $::MAP->h;
441 $self->{magicmap} = [$x, $y, $w, $h, $data]; 449 $self->{magicmap} = [$x, $y, $w, $h, $data];
442 450
443 $self->update; 451 $self->update;
444} 452}
445 453
446sub draw { 454sub refresh_hook {
447 my ($self) = @_; 455 my ($self) = @_;
448 456
449 return unless $::MAP; 457 return unless $::MAP;
450
451 my $focused = $CFPlus::UI::FOCUS == $self
452 || $CFPlus::UI::FOCUS == $self->{completer}{entry};
453
454 return
455 unless $focused || !$::FAST;
456 458
457 if (delete $self->{need_update}) { 459 if (delete $self->{need_update}) {
458 my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1; 460 my $tilesize = $self->{ctilesize} = (int $self->{tilesize} * $::CFG->{map_scale}) || 1;
459 461
460 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize; 462 my $sw = $self->{sw} = 1 + CFPlus::ceil $self->{w} / $tilesize;
521 } 523 }
522 524
523 glPopMatrix; 525 glPopMatrix;
524 glEndList; 526 glEndList;
525 } 527 }
528
529}
530
531sub draw {
532 my ($self) = @_;
533
534 $self->{root}->on_post_alloc (prepare => sub { $self->refresh_hook });
535
536 return unless $self->{list};
537
538 my $focused = $CFPlus::UI::FOCUS == $self
539 || $CFPlus::UI::FOCUS == $self->{completer}{entry};
540
541 return
542 unless $focused || !$::FAST;
526 543
527 glCallList $self->{list}; 544 glCallList $self->{list};
528 545
529 # TNT2 emulates logops in software (or worse :) 546 # TNT2 emulates logops in software (or worse :)
530 unless ($focused) { 547 unless ($focused) {
561 578
562sub size_request { 579sub size_request {
563 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 580 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
564} 581}
565 582
566sub invoke_size_allocate { 583sub refresh_hook {
567 my ($self, $w, $h) = @_; 584 my ($self) = @_;
568 585
569 $self->update; 586 if ($::MAP && $self->{texture_atime} < time) {
570
571 1
572}
573
574sub update {
575 my ($self) = @_;
576
577 delete $self->{texture_atime};
578 $self->SUPER::update;
579}
580
581sub _draw {
582 my ($self) = @_;
583
584 $::MAP or return;
585
586 my ($w, $h) = @$self{qw(w h)}; 587 my ($w, $h) = @$self{qw(w h)};
587 588
588 my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; 589 my $sw = int $::WIDTH / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
589 my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99; 590 my $sh = int $::HEIGHT / ($::MAPWIDGET->{tilesize} * $::CFG->{map_scale}) + 0.99;
590 591
592 my $ox = 0.5 * ($w - $sw);
593 my $oy = 0.5 * ($h - $sh);
594
591 my $sx = int $::CFG->{map_shift_x} / $::MAPWIDGET->{tilesize}; 595 my $sx = int $::CFG->{map_shift_x} / $::MAPWIDGET->{tilesize};
592 my $sy = int $::CFG->{map_shift_y} / $::MAPWIDGET->{tilesize}; 596 my $sy = int $::CFG->{map_shift_y} / $::MAPWIDGET->{tilesize};
593 597
594 my $ox = 0.5 * ($w - $sw); 598 #TODO: map scale is completely borked
595 my $oy = 0.5 * ($h - $sh);
596 599
597 glEnable GL_BLEND; 600 my $x0 = int $ox - $sx + 0.5;
598 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 601 my $y0 = int $oy - $sy + 0.5;
599 glEnable GL_TEXTURE_2D;
600 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
601 602
602 if ($self->{texture_atime} < time) { 603 $self->{sw} = $sw;
604 $self->{sh} = $sh;
605
606 $self->{x0} = $x0;
607 $self->{y0} = $y0;
608
603 $self->{texture_atime} = time + 1/3; 609 $self->{texture_atime} = time + 1/3;
604 610
605 $self->{texture} = 611 $self->{texture} =
606 new CFPlus::Texture 612 new CFPlus::Texture
607 w => $w, 613 w => $w,
608 h => $h, 614 h => $h,
609 data => $::MAP->mapmap (-$ox, -$oy, $w, $h), 615 data => $::MAP->mapmap (-$ox, -$oy, $w, $h),
610 type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE; 616 type => $CFPlus::GL_VERSION >= 1.2 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_BYTE;
611 } 617 }
618}
619
620sub invoke_visibility_change {
621 my ($self) = @_;
622
623 $self->refresh_hook;
624
625 0
626}
627
628sub invoke_size_allocate {
629 my ($self, $w, $h) = @_;
630
631 $self->update;
632
633 1
634}
635
636sub update {
637 my ($self) = @_;
638
639 delete $self->{texture_atime};
640 $self->SUPER::update;
641}
642
643sub _draw {
644 my ($self) = @_;
645
646 $self->{root}->on_post_alloc (texture => sub { $self->refresh_hook });
647
648 $self->{texture} or return;
649
650 glEnable GL_BLEND;
651 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
652 glEnable GL_TEXTURE_2D;
653 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
612 654
613 $self->{texture}->draw_quad (0, 0); 655 $self->{texture}->draw_quad (0, 0);
614 656
615 glDisable GL_TEXTURE_2D; 657 glDisable GL_TEXTURE_2D;
616 658
617 glTranslate 0.375, 0.375; 659 glTranslate 0.375, 0.375;
618
619 #TODO: map scale is completely borked
620
621 my $x0 = int $ox - $sx + 0.5;
622 my $y0 = int $oy - $sy + 0.5;
623 660
624 glColor 1, 1, 0, 1; 661 glColor 1, 1, 0, 1;
625 glBegin GL_LINE_LOOP; 662 glBegin GL_LINE_LOOP;
626 glVertex $x0 , $y0 ; 663 glVertex $self->{x0} , $self->{y0} ;
627 glVertex $x0 , $y0 + $sh; 664 glVertex $self->{x0} , $self->{y0} + $self->{sh};
628 glVertex $x0 + $sw, $y0 + $sh; 665 glVertex $self->{x0} + $self->{sw}, $self->{y0} + $self->{sh};
629 glVertex $x0 + $sw, $y0 ; 666 glVertex $self->{x0} + $self->{sw}, $self->{y0} ;
630 glEnd; 667 glEnd;
631 668
632 glDisable GL_BLEND; 669 glDisable GL_BLEND;
633} 670}
634 671

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines