1 | package Crossfire::Client::Widget; |
1 | package CFClient::Widget; |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | |
4 | |
5 | use Scalar::Util; |
5 | use Scalar::Util; |
6 | |
6 | |
7 | use SDL::OpenGL; |
7 | use SDL::OpenGL; |
8 | use SDL::OpenGL::Constants; |
8 | use SDL::OpenGL::Constants; |
9 | |
9 | |
10 | use Crossfire::Client; |
10 | use CFClient; |
11 | |
11 | |
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
13 | |
13 | |
14 | our $TOPLEVEL; |
14 | our $TOPLEVEL; |
15 | our $BUTTON_STATE; |
15 | our $BUTTON_STATE; |
… | |
… | |
73 | } |
73 | } |
74 | |
74 | |
75 | sub new { |
75 | sub new { |
76 | my $class = shift; |
76 | my $class = shift; |
77 | |
77 | |
78 | bless { @_ }, $class |
78 | bless { |
|
|
79 | x => 0, |
|
|
80 | y => 0, |
|
|
81 | z => 0, |
|
|
82 | @_ |
|
|
83 | }, $class |
79 | } |
84 | } |
80 | |
85 | |
81 | sub move { |
86 | sub move { |
82 | my ($self, $x, $y, $z) = @_; |
87 | my ($self, $x, $y, $z) = @_; |
83 | $self->{x} = $x; |
88 | $self->{x} = $x; |
… | |
… | |
210 | #$self->deactivate; |
215 | #$self->deactivate; |
211 | } |
216 | } |
212 | |
217 | |
213 | ############################################################################# |
218 | ############################################################################# |
214 | |
219 | |
|
|
220 | package CFClient::Widget::Empty; |
|
|
221 | |
|
|
222 | our @ISA = CFClient::Widget::; |
|
|
223 | |
|
|
224 | sub size_request { |
|
|
225 | (0, 0) |
|
|
226 | } |
|
|
227 | |
|
|
228 | sub draw { |
|
|
229 | } |
|
|
230 | |
|
|
231 | ############################################################################# |
|
|
232 | |
215 | package Crossfire::Client::Widget::Container; |
233 | package CFClient::Widget::Container; |
216 | |
234 | |
217 | our @ISA = Crossfire::Client::Widget::; |
235 | our @ISA = CFClient::Widget::; |
218 | |
236 | |
219 | sub new { |
237 | sub new { |
220 | my ($class, @widgets) = @_; |
238 | my ($class, %arg) = @_; |
221 | |
239 | |
|
|
240 | my $children = delete $arg{children} || []; |
|
|
241 | |
222 | my $self = $class->SUPER::new (children => []); |
242 | my $self = $class->SUPER::new (children => [], %arg); |
223 | $self->add ($_) for @widgets; |
243 | $self->add ($_) for @$children; |
224 | |
244 | |
225 | $self |
245 | $self |
226 | } |
246 | } |
227 | |
247 | |
228 | sub add { |
248 | sub add { |
229 | my ($self, $chld, $expand) = @_; |
249 | my ($self, $chld, $expand) = @_; |
230 | |
250 | |
231 | $chld->{expand} = $expand; |
251 | $chld->{expand} = $expand; |
232 | $chld->set_parent ($self); |
252 | $chld->set_parent ($self); |
233 | |
253 | |
234 | @{$self->{children}} = |
254 | $self->{children} = [ |
235 | sort { $a->{z} <=> $b->{z} } |
255 | sort { $a->{z} <=> $b->{z} } |
236 | @{$self->{children}}, $chld; |
256 | @{$self->{children}}, $chld |
|
|
257 | ]; |
237 | |
258 | |
238 | $self->size_allocate ($self->{w}, $self->{h}) |
259 | $self->size_allocate ($self->{w}, $self->{h}) |
239 | if $self->{w}; #TODO: check for "realised state" |
260 | if $self->{w}; #TODO: check for "realised state" |
240 | } |
261 | } |
241 | |
262 | |
… | |
… | |
269 | $_->draw for @{$self->{children}}; |
290 | $_->draw for @{$self->{children}}; |
270 | } |
291 | } |
271 | |
292 | |
272 | ############################################################################# |
293 | ############################################################################# |
273 | |
294 | |
274 | package Crossfire::Client::Widget::Bin; |
295 | package CFClient::Widget::Bin; |
275 | |
296 | |
276 | our @ISA = Crossfire::Client::Widget::Container::; |
297 | our @ISA = CFClient::Widget::Container::; |
|
|
298 | |
|
|
299 | sub new { |
|
|
300 | my ($class, %arg) = @_; |
|
|
301 | |
|
|
302 | my $child = (delete $arg{child}) || new CFClient::Widget::Empty::; |
|
|
303 | |
|
|
304 | $class->SUPER::new (children => [$child], %arg) |
|
|
305 | } |
|
|
306 | |
|
|
307 | sub add { |
|
|
308 | my ($self, $widget) = @_; |
|
|
309 | |
|
|
310 | $self->{children} = []; |
|
|
311 | |
|
|
312 | $self->SUPER::add ($widget); |
|
|
313 | } |
|
|
314 | |
|
|
315 | sub remove { |
|
|
316 | my ($self, $widget) = @_; |
|
|
317 | |
|
|
318 | $self->SUPER::remove ($widget); |
|
|
319 | |
|
|
320 | $self->{children} = [new CFClient::Widget::Empty] |
|
|
321 | unless @{$self->{children}}; |
|
|
322 | } |
277 | |
323 | |
278 | sub child { $_[0]->{children}[0] } |
324 | sub child { $_[0]->{children}[0] } |
279 | |
325 | |
280 | sub size_request { |
326 | sub size_request { |
281 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
327 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
… | |
… | |
289 | if $self->{children}[0] |
335 | if $self->{children}[0] |
290 | } |
336 | } |
291 | |
337 | |
292 | ############################################################################# |
338 | ############################################################################# |
293 | |
339 | |
294 | package Crossfire::Client::Widget::Window; |
340 | package CFClient::Widget::Window; |
295 | |
341 | |
296 | our @ISA = Crossfire::Client::Widget::Bin::; |
342 | our @ISA = CFClient::Widget::Bin::; |
297 | |
343 | |
298 | use SDL::OpenGL; |
344 | use SDL::OpenGL; |
299 | |
345 | |
300 | sub new { |
346 | sub new { |
301 | my ($class, $x, $y, $z, $w, $h) = @_; |
347 | my ($class, %arg) = @_; |
302 | |
348 | |
303 | my $self = $class->SUPER::new; |
349 | my $self = $class->SUPER::new (%arg); |
304 | |
|
|
305 | @$self{qw(x y z w h)} = ($x, $y, $z, $w, $h); |
|
|
306 | } |
350 | } |
307 | |
351 | |
308 | sub update { |
352 | sub update { |
309 | my ($self) = @_; |
353 | my ($self) = @_; |
310 | |
354 | |
|
|
355 | # we want to do this delayed... |
311 | $self->render_chld; |
356 | $self->render_chld; |
312 | $self->SUPER::update; |
357 | $self->SUPER::update; |
313 | } |
358 | } |
314 | |
359 | |
315 | sub render_chld { |
360 | sub render_chld { |
316 | my ($self) = @_; |
361 | my ($self) = @_; |
317 | |
362 | |
318 | $self->{texture} = |
363 | $self->{texture} = |
319 | Crossfire::Client::Texture->new_from_opengl ( |
364 | CFClient::Texture->new_from_opengl ( |
320 | $self->{w}, $self->{h}, sub { $self->child->draw } |
365 | $self->{w}, $self->{h}, sub { $self->child->draw } |
321 | ); |
366 | ); |
322 | } |
367 | } |
323 | |
368 | |
324 | sub size_allocate { |
369 | sub size_allocate { |
… | |
… | |
350 | glDisable GL_TEXTURE_2D; |
395 | glDisable GL_TEXTURE_2D; |
351 | } |
396 | } |
352 | |
397 | |
353 | ############################################################################# |
398 | ############################################################################# |
354 | |
399 | |
355 | package Crossfire::Client::Widget::Frame; |
400 | package CFClient::Widget::Frame; |
356 | |
401 | |
357 | our @ISA = Crossfire::Client::Widget::Bin::; |
402 | our @ISA = CFClient::Widget::Bin::; |
358 | |
403 | |
359 | use SDL::OpenGL; |
404 | use SDL::OpenGL; |
360 | |
405 | |
361 | sub size_request { |
406 | sub size_request { |
362 | my ($self) = @_; |
407 | my ($self) = @_; |
… | |
… | |
396 | $chld->draw; |
441 | $chld->draw; |
397 | } |
442 | } |
398 | |
443 | |
399 | ############################################################################# |
444 | ############################################################################# |
400 | |
445 | |
401 | package Crossfire::Client::Widget::FancyFrame; |
446 | package CFClient::Widget::FancyFrame; |
402 | |
447 | |
403 | our @ISA = Crossfire::Client::Widget::Bin::; |
448 | our @ISA = CFClient::Widget::Bin::; |
404 | |
449 | |
405 | use SDL::OpenGL; |
450 | use SDL::OpenGL; |
406 | |
451 | |
407 | my @tex = |
452 | my @tex = |
408 | map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } |
453 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
409 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
454 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
410 | |
455 | |
411 | sub size_request { |
456 | sub size_request { |
412 | my ($self) = @_; |
457 | my ($self) = @_; |
413 | |
458 | |
… | |
… | |
432 | $w -= $tex[3]->{width}; |
477 | $w -= $tex[3]->{width}; |
433 | |
478 | |
434 | $h = $h < 0 ? 0 : $h; |
479 | $h = $h < 0 ? 0 : $h; |
435 | $w = $w < 0 ? 0 : $w; |
480 | $w = $w < 0 ? 0 : $w; |
436 | |
481 | |
|
|
482 | my $child = $self->child; |
|
|
483 | |
437 | $self->child->size_allocate ($w, $h); |
484 | $child->size_allocate ($w, $h); |
438 | $self->child->move ($tex[3]->{width}, $tex[1]->{height}); |
485 | $child->move ($tex[3]->{width}, $tex[1]->{height}); |
439 | } |
486 | } |
440 | |
487 | |
441 | sub _draw { |
488 | sub _draw { |
442 | my ($self) = @_; |
489 | my ($self) = @_; |
443 | |
490 | |
… | |
… | |
479 | |
526 | |
480 | } |
527 | } |
481 | |
528 | |
482 | ############################################################################# |
529 | ############################################################################# |
483 | |
530 | |
484 | package Crossfire::Client::Widget::Table; |
531 | package CFClient::Widget::Table; |
485 | |
532 | |
486 | our @ISA = Crossfire::Client::Widget::Bin::; |
533 | our @ISA = CFClient::Widget::Bin::; |
487 | |
534 | |
488 | use SDL::OpenGL; |
535 | use SDL::OpenGL; |
489 | |
536 | |
490 | sub add { |
537 | sub add { |
491 | my ($self, $x, $y, $chld) = @_; |
538 | my ($self, $x, $y, $chld) = @_; |
… | |
… | |
566 | } |
613 | } |
567 | } |
614 | } |
568 | |
615 | |
569 | ############################################################################# |
616 | ############################################################################# |
570 | |
617 | |
571 | package Crossfire::Client::Widget::VBox; |
618 | package CFClient::Widget::VBox; |
572 | |
619 | |
573 | our @ISA = Crossfire::Client::Widget::Container::; |
620 | our @ISA = CFClient::Widget::Container::; |
574 | |
621 | |
575 | use SDL::OpenGL; |
622 | use SDL::OpenGL; |
576 | |
623 | |
577 | sub size_request { |
624 | sub size_request { |
578 | my ($self) = @_; |
625 | my ($self) = @_; |
… | |
… | |
626 | } |
673 | } |
627 | } |
674 | } |
628 | |
675 | |
629 | ############################################################################# |
676 | ############################################################################# |
630 | |
677 | |
631 | package Crossfire::Client::Widget::Label; |
678 | package CFClient::Widget::Label; |
632 | |
679 | |
633 | our @ISA = Crossfire::Client::Widget::; |
680 | our @ISA = CFClient::Widget::; |
634 | |
681 | |
635 | use SDL::OpenGL; |
682 | use SDL::OpenGL; |
636 | |
683 | |
637 | sub new { |
684 | sub new { |
638 | my ($class, $x, $y, $z, $height, $text) = @_; |
685 | my ($class, %arg) = @_; |
639 | |
|
|
640 | $height ||= $::FONTSIZE; |
|
|
641 | |
686 | |
642 | # TODO: color, and make height, xyz etc. optional |
687 | # TODO: color, and make height, xyz etc. optional |
643 | my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); |
688 | my $self = $class->SUPER::new ( |
|
|
689 | color => [1, 1, 1], |
|
|
690 | height => $::FONTSIZE, |
|
|
691 | text => "", |
|
|
692 | layout => new CFClient::Layout, |
|
|
693 | %arg |
|
|
694 | ); |
644 | |
695 | |
645 | $self->set_text ($text); |
696 | $self->set_text ($self->{text}); |
646 | |
697 | |
647 | $self |
698 | $self |
648 | } |
699 | } |
649 | |
700 | |
650 | sub set_text { |
701 | sub set_text { |
651 | my ($self, $text) = @_; |
702 | my ($self, $text) = @_; |
652 | |
703 | |
653 | $self->{text} = $text; |
704 | $self->{text} = $text; |
654 | $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; |
705 | $self->{layout}->set_markup ($text); |
655 | |
706 | |
656 | $self->update; |
707 | delete $self->{texture}; |
657 | } |
708 | } |
658 | |
709 | |
659 | sub get_text { |
710 | sub get_text { |
660 | my ($self, $text) = @_; |
711 | my ($self, $text) = @_; |
661 | |
712 | |
… | |
… | |
663 | } |
714 | } |
664 | |
715 | |
665 | sub size_request { |
716 | sub size_request { |
666 | my ($self) = @_; |
717 | my ($self) = @_; |
667 | |
718 | |
|
|
719 | $self->{layout}->set_width; |
|
|
720 | $self->{layout}->set_height ($self->{height}); |
|
|
721 | $self->{layout}->size |
668 | if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
722 | # if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
669 | ( |
723 | # ( |
670 | $self->{texture}{width}, |
724 | # $self->{texture}{width}, |
671 | $self->{texture}{height}, |
725 | # $self->{texture}{height}, |
672 | ) |
726 | # ) |
673 | } else { |
727 | # } else { |
674 | my ($w, $h, $data) = Crossfire::Client::font_render "Yy", $self->{height}; |
728 | # my ($w, $h, $data) = CFClient::font_render "Yy", $self->{height}; |
675 | |
729 | # |
676 | ($w, $h) |
730 | # ($w, $h) |
677 | } |
731 | # } |
|
|
732 | } |
678 | |
733 | |
|
|
734 | sub size_allocate { |
|
|
735 | my ($self, $w, $h) = @_; |
|
|
736 | |
|
|
737 | $self->SUPER::size_allocate ($w, $h); |
|
|
738 | delete $self->{texture}; |
679 | } |
739 | } |
680 | |
740 | |
681 | sub _draw { |
741 | sub _draw { |
682 | my ($self) = @_; |
742 | my ($self) = @_; |
683 | |
743 | |
684 | my $tex = $self->{texture}; |
744 | my $tex = $self->{texture} ||= do { |
|
|
745 | $self->{layout}->set_width ($self->{w}); |
|
|
746 | new_from_layout CFClient::Texture $self->{layout}; |
|
|
747 | }; |
685 | |
748 | |
686 | glEnable GL_BLEND; |
749 | glEnable GL_BLEND; |
687 | glEnable GL_TEXTURE_2D; |
750 | glEnable GL_TEXTURE_2D; |
688 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
751 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
689 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
752 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
690 | |
753 | |
691 | glColor 1, 0, 0, 1; # TODO color |
754 | glColor @{$self->{color}}; |
692 | |
755 | |
693 | $tex->draw_quad (0, 0); |
756 | $tex->draw_quad (0, 0); |
694 | |
757 | |
695 | glDisable GL_BLEND; |
758 | glDisable GL_BLEND; |
696 | glDisable GL_TEXTURE_2D; |
759 | glDisable GL_TEXTURE_2D; |
697 | } |
760 | } |
698 | |
761 | |
699 | ############################################################################# |
762 | ############################################################################# |
700 | |
763 | |
701 | package Crossfire::Client::Widget::Entry; |
764 | package CFClient::Widget::Entry; |
702 | |
765 | |
703 | our @ISA = Crossfire::Client::Widget::Label::; |
766 | our @ISA = CFClient::Widget::Label::; |
704 | |
767 | |
705 | use SDL; |
768 | use SDL; |
706 | use SDL::OpenGL; |
769 | use SDL::OpenGL; |
707 | |
770 | |
708 | sub key_down { |
771 | sub key_down { |
… | |
… | |
754 | $self->SUPER::_draw; |
817 | $self->SUPER::_draw; |
755 | } |
818 | } |
756 | |
819 | |
757 | ############################################################################# |
820 | ############################################################################# |
758 | |
821 | |
759 | package Crossfire::Client::Widget::MapWidget; |
822 | package CFClient::Widget::MapWidget; |
760 | |
823 | |
761 | use strict; |
824 | use strict; |
762 | |
825 | |
763 | use List::Util qw(min max); |
826 | use List::Util qw(min max); |
764 | |
827 | |
765 | use SDL; |
828 | use SDL; |
766 | use SDL::OpenGL; |
829 | use SDL::OpenGL; |
767 | use SDL::OpenGL::Constants; |
830 | use SDL::OpenGL::Constants; |
768 | |
831 | |
769 | our @ISA = Crossfire::Client::Widget::; |
832 | our @ISA = CFClient::Widget::; |
|
|
833 | |
|
|
834 | sub new { |
|
|
835 | my $class = shift; |
|
|
836 | |
|
|
837 | $class->SUPER::new ( |
|
|
838 | z => -1, |
|
|
839 | list => (glGenLists 1), |
|
|
840 | @_ |
|
|
841 | ) |
|
|
842 | } |
770 | |
843 | |
771 | sub key_down { |
844 | sub key_down { |
772 | print "MAPKEYDOWN\n"; |
845 | print "MAPKEYDOWN\n"; |
773 | } |
846 | } |
774 | |
847 | |
… | |
… | |
780 | 1 + int $::WIDTH / 32, |
853 | 1 + int $::WIDTH / 32, |
781 | 1 + int $::HEIGHT / 32, |
854 | 1 + int $::HEIGHT / 32, |
782 | ) |
855 | ) |
783 | } |
856 | } |
784 | |
857 | |
|
|
858 | sub update { |
|
|
859 | my ($self) = @_; |
|
|
860 | |
|
|
861 | $self->{need_update} = 1; |
|
|
862 | } |
|
|
863 | |
785 | sub _draw { |
864 | sub _draw { |
786 | my ($self) = @_; |
865 | my ($self) = @_; |
787 | |
866 | |
|
|
867 | if (delete $self->{need_update}) { |
|
|
868 | glNewList $self->{list}, GL_COMPILE; |
|
|
869 | |
788 | my $mx = $::CONN->{mapx}; |
870 | my $mx = $::CONN->{mapx}; |
789 | my $my = $::CONN->{mapy}; |
871 | my $my = $::CONN->{mapy}; |
790 | |
872 | |
791 | my $map = $::CONN->{map}; |
873 | my $map = $::CONN->{map}; |
792 | |
874 | |
793 | my ($xofs, $yofs); |
875 | my ($xofs, $yofs); |
794 | |
876 | |
795 | my $sw = 1 + int $::WIDTH / 32; |
877 | my $sw = 1 + int $::WIDTH / 32; |
796 | my $sh = 1 + int $::HEIGHT / 32; |
878 | my $sh = 1 + int $::HEIGHT / 32; |
797 | |
879 | |
798 | if ($::CONN->{mapw} > $sw) { |
880 | if ($::CONN->{mapw} > $sw) { |
799 | $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; |
881 | $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; |
800 | } else { |
882 | } else { |
801 | $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; |
883 | $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; |
802 | } |
884 | } |
803 | |
885 | |
804 | if ($::CONN->{maph} > $sh) { |
886 | if ($::CONN->{maph} > $sh) { |
805 | $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; |
887 | $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; |
806 | } else { |
888 | } else { |
807 | $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; |
889 | $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; |
808 | } |
890 | } |
809 | |
891 | |
810 | glEnable GL_TEXTURE_2D; |
892 | glEnable GL_TEXTURE_2D; |
811 | glEnable GL_BLEND; |
893 | glEnable GL_BLEND; |
812 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
894 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
813 | |
895 | |
814 | my $sw4 = ($sw + 3) & ~3; |
896 | my $sw4 = ($sw + 3) & ~3; |
815 | my $darkness = "\x00" x ($sw4 * $sh); |
897 | my $darkness = "\x00" x ($sw4 * $sh); |
816 | |
898 | |
817 | for my $x (0 .. $sw - 1) { |
899 | for my $x (0 .. $sw - 1) { |
818 | my $row = $map->[$x + $xofs]; |
900 | my $row = $map->[$x + $xofs]; |
819 | for my $y (0 .. $sh - 1) { |
901 | for my $y (0 .. $sh - 1) { |
820 | |
902 | |
821 | my $cell = $row->[$y + $yofs] |
903 | my $cell = $row->[$y + $yofs] |
822 | or next; |
904 | or next; |
823 | |
905 | |
824 | my $dark = $cell->[0]; |
906 | my $dark = $cell->[0]; |
825 | if ($dark < 0) { |
907 | if ($dark < 0) { |
826 | substr $darkness, $y * $sw4 + $x, 1, chr 224; |
908 | substr $darkness, $y * $sw4 + $x, 1, chr 224; |
827 | } else { |
909 | } else { |
828 | substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; |
910 | substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; |
829 | } |
911 | } |
830 | |
912 | |
831 | for my $num (grep $_, @$cell[1,2,3]) { |
913 | for my $num (grep $_, @$cell[1,2,3]) { |
832 | my $tex = $::CONN->{face}[$num]{texture} || next; |
914 | my $tex = $::CONN->{face}[$num]{texture} || next; |
833 | |
915 | |
834 | my $w = $tex->{width}; |
916 | my $w = $tex->{width}; |
835 | my $h = $tex->{height}; |
917 | my $h = $tex->{height}; |
836 | |
918 | |
837 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
919 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
|
|
920 | } |
838 | } |
921 | } |
839 | } |
922 | } |
840 | } |
|
|
841 | |
923 | |
842 | # if (1) { # higher quality darkness |
924 | # if (1) { # higher quality darkness |
843 | # $lighting =~ s/(.)/$1$1$1/gs; |
925 | # $lighting =~ s/(.)/$1$1$1/gs; |
844 | # my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; |
926 | # my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; |
845 | # |
927 | # |
… | |
… | |
847 | # |
929 | # |
848 | # $lighting = $pb->get_pixels; |
930 | # $lighting = $pb->get_pixels; |
849 | # $lighting =~ s/(.)../$1/gs; |
931 | # $lighting =~ s/(.)../$1/gs; |
850 | # } |
932 | # } |
851 | |
933 | |
852 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
934 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
853 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
935 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
854 | |
936 | |
855 | $darkness = new Crossfire::Client::Texture |
937 | $darkness = new CFClient::Texture |
856 | width => $sw4, |
938 | width => $sw4, |
857 | height => $sh, |
939 | height => $sh, |
858 | data => $darkness, |
940 | data => $darkness, |
859 | internalformat => GL_ALPHA, |
941 | internalformat => GL_ALPHA, |
860 | format => GL_ALPHA; |
942 | format => GL_ALPHA; |
861 | |
943 | |
862 | glColor 0.45, 0.45, 0.45, 1; |
944 | glColor 0.45, 0.45, 0.45, 1; |
863 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
945 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
864 | |
946 | |
865 | glDisable GL_TEXTURE_2D; |
947 | glDisable GL_TEXTURE_2D; |
866 | glDisable GL_BLEND; |
948 | glDisable GL_BLEND; |
|
|
949 | |
|
|
950 | glEndList; |
|
|
951 | } |
|
|
952 | |
|
|
953 | glCallList $self->{list}; |
867 | } |
954 | } |
868 | |
955 | |
869 | my %DIR = ( |
956 | my %DIR = ( |
870 | SDLK_KP8, [1, "north"], |
957 | SDLK_KP8, [1, "north"], |
871 | SDLK_KP9, [2, "northeast"], |
958 | SDLK_KP9, [2, "northeast"], |
… | |
… | |
917 | } |
1004 | } |
918 | } |
1005 | } |
919 | |
1006 | |
920 | ############################################################################# |
1007 | ############################################################################# |
921 | |
1008 | |
922 | package Crossfire::Client::Widget::Animator; |
1009 | package CFClient::Widget::Animator; |
923 | |
1010 | |
924 | use SDL::OpenGL; |
1011 | use SDL::OpenGL; |
925 | |
1012 | |
926 | our @ISA = Crossfire::Client::Widget::Bin::; |
1013 | our @ISA = CFClient::Widget::Bin::; |
927 | |
1014 | |
928 | sub moveto { |
1015 | sub moveto { |
929 | my ($self, $x, $y) = @_; |
1016 | my ($self, $x, $y) = @_; |
930 | |
1017 | |
931 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
1018 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
… | |
… | |
959 | glPopMatrix; |
1046 | glPopMatrix; |
960 | } |
1047 | } |
961 | |
1048 | |
962 | ############################################################################# |
1049 | ############################################################################# |
963 | |
1050 | |
964 | package Crossfire::Client::Widget::Toplevel; |
1051 | package CFClient::Widget::Toplevel; |
965 | |
1052 | |
966 | our @ISA = Crossfire::Client::Widget::Container::; |
1053 | our @ISA = CFClient::Widget::Container::; |
967 | |
1054 | |
968 | sub size_request { |
1055 | sub size_request { |
969 | ($::WIDTH, $::HEIGHT) |
1056 | ($::WIDTH, $::HEIGHT) |
970 | } |
1057 | } |
971 | |
1058 | |
… | |
… | |
1005 | $self->_draw; |
1092 | $self->_draw; |
1006 | } |
1093 | } |
1007 | |
1094 | |
1008 | ############################################################################# |
1095 | ############################################################################# |
1009 | |
1096 | |
1010 | package Crossfire::Client::Widget; |
1097 | package CFClient::Widget; |
1011 | |
1098 | |
1012 | $TOPLEVEL = new Crossfire::Client::Widget::Toplevel; |
1099 | $TOPLEVEL = new CFClient::Widget::Toplevel; |
1013 | |
1100 | |
1014 | 1 |
1101 | 1 |
1015 | |
1102 | |