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