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.75 by root, Tue Apr 11 20:44:49 2006 UTC vs.
Revision 1.78 by root, Tue Apr 11 22:49:13 2006 UTC

43 43
44 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); 44 my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y);
45 45
46 $BUTTON_STATE &= ~(1 << ($ev->button - 1)); 46 $BUTTON_STATE &= ~(1 << ($ev->button - 1));
47 47
48 $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB; 48 $GRAB->button_up ($ev, $GRAB->translate ($x, $y)) if $GRAB;
49 49
50 if (!$BUTTON_STATE) { 50 if (!$BUTTON_STATE) {
51 my $grab = $GRAB; undef $GRAB; 51 my $grab = $GRAB; undef $GRAB;
52 $grab->update if $grab; 52 $grab->update if $grab;
53 $GRAB->update if $GRAB; 53 $GRAB->update if $GRAB;
181 glPopMatrix; 181 glPopMatrix;
182 182
183 if ($self == $HOVER) { 183 if ($self == $HOVER) {
184 my ($x, $y) = @$self{qw(x y)}; 184 my ($x, $y) = @$self{qw(x y)};
185 185
186 glColor 1, 1, 1, 0.1; 186 glColor 0, 0, 1, 0.2;
187 glEnable GL_BLEND; 187 glEnable GL_BLEND;
188 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 188 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
189 glBegin GL_QUADS; 189 glBegin GL_QUADS;
190 glVertex $x , $y; 190 glVertex $x , $y;
191 glVertex $x + $self->{w}, $y; 191 glVertex $x + $self->{w}, $y;
200 my ($self) = @_; 200 my ($self) = @_;
201 201
202 warn "no draw defined for $self\n"; 202 warn "no draw defined for $self\n";
203} 203}
204 204
205sub bbox {
206 my ($self) = @_;
207 my ($w, $h) = $self->size_request;
208 (
209 $self->{x},
210 $self->{y},
211 $self->{x} = $w,
212 $self->{y} = $h
213 )
214}
215
216sub find_widget { 205sub find_widget {
217 my ($self, $x, $y) = @_; 206 my ($self, $x, $y) = @_;
218 207
219 return $self 208 return $self
220 if $x >= $self->{x} && $x < $self->{x} + $self->{w} 209 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
221 && $y >= $self->{y} && $y < $self->{y} + $self->{h}; 210 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
222 211
223 () 212 ()
224} 213}
225 214
226sub del_parent { $_[0]->{parent} = undef }
227
228sub set_parent { 215sub set_parent {
229 my ($self, $par) = @_; 216 my ($self, $par) = @_;
230 217
231 $self->{parent} = $par; 218 $self->{parent} = $par;
232 Scalar::Util::weaken $self->{parent}; 219 Scalar::Util::weaken $self->{parent};
275 my $class = shift; 262 my $class = shift;
276 263
277 # range [value, low, high, page] 264 # range [value, low, high, page]
278 265
279 $class->SUPER::new ( 266 $class->SUPER::new (
280 bg => [0, 0, 0, 0.4], 267 bg => [0, 0, 0, 0.2],
281 active_bg => [1, 1, 1], 268 active_bg => [1, 1, 1],
282 @_ 269 @_
283 ) 270 )
284} 271}
285 272
286sub _draw { 273sub _draw {
287 my ($self) = @_; 274 my ($self) = @_;
288 275
289 my ($w, $h) = @$self{qw(w h)}; 276 my ($w, $h) = @$self{qw(w h)};
290 277
278 glEnable GL_BLEND;
279 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
291 glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} }; 280 glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} };
281
292 glBegin GL_QUADS; 282 glBegin GL_QUADS;
293 glVertex 0 , 0; 283 glVertex 0 , 0;
294 glVertex 0 , $h; 284 glVertex 0 , $h;
295 glVertex $w, $h; 285 glVertex $w, $h;
296 glVertex $w, 0; 286 glVertex $w, 0;
297 glEnd; 287 glEnd;
288
289 glDisable GL_BLEND;
298} 290}
299 291
300############################################################################# 292#############################################################################
301 293
302package CFClient::UI::Empty; 294package CFClient::UI::Empty;
325 317
326 $self 318 $self
327} 319}
328 320
329sub add { 321sub add {
330 my ($self, $chld, $expand) = @_; 322 my ($self, $chld) = @_;
331 323
332 $chld->{expand} = $expand;
333 $chld->set_parent ($self); 324 $chld->set_parent ($self);
334 325
335 $self->{children} = [ 326 $self->{children} = [
336 sort { $a->{z} <=> $b->{z} } 327 sort { $a->{z} <=> $b->{z} }
337 @{$self->{children}}, $chld 328 @{$self->{children}}, $chld
533 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 524 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
534 525
535sub size_request { 526sub size_request {
536 my ($self) = @_; 527 my ($self) = @_;
537 528
529 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
530
538 my ($w, $h) = $self->SUPER::size_request; 531 my ($w, $h) = $self->SUPER::size_request;
539 532
540 $h += $tex[1]->{h}; 533 $h += $tex[1]->{h};
541 $h += $tex[4]->{h}; 534 $h += $tex[4]->{h};
542 $w += $tex[2]->{w}; 535 $w += $tex[2]->{w};
548sub size_allocate { 541sub size_allocate {
549 my ($self, $x, $y, $w, $h) = @_; 542 my ($self, $x, $y, $w, $h) = @_;
550 543
551 $self->_size_allocate ($x, $y, $w, $h) or return; 544 $self->_size_allocate ($x, $y, $w, $h) or return;
552 545
553 $h -= $tex[1]->{h}; 546 $h -= $tex[1]{h};
554 $h -= $tex[4]->{h}; 547 $h -= $tex[4]{h};
555 $w -= $tex[2]->{w}; 548 $w -= $tex[2]{w};
556 $w -= $tex[3]->{w}; 549 $w -= $tex[3]{w};
557 550
558 $h = $h < 0 ? 0 : $h; 551 $h = $h < 0 ? 0 : $h;
559 $w = $w < 0 ? 0 : $w; 552 $w = $w < 0 ? 0 : $w;
560 553
561 my $child = $self->child; 554 my $child = $self->child;
562 555
563 $child->size_allocate ($tex[3]->{w}, $tex[1]->{h}, $w, $h); 556 $child->size_allocate ($tex[3]->{w}, $tex[1]->{h}, $w, $h);
557}
558
559sub button_down {
560 my ($self, $ev, $x, $y) = @_;
561
562 if ($x < $self->{w} && $x >= $self->{w} - $tex[2]{w}
563 && $y < $self->{h} && $y >= $self->{h} - $tex[4]{h}) {
564
565 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
566 my ($bw, $bh) = ($self->{w}, $self->{h});
567
568 $self->{motion} = sub {
569 my ($ev, $x, $y) = @_;
570
571 ($x, $y) = ($ev->motion_x, $ev->motion_y);
572
573 $self->{user_w} = $bw + $x - $ox;
574 $self->{user_h} = $bh + $y - $oy;
575 $self->update;
576 };
577
578 } elsif ($x >= 0 && $x < $self->{w}
579 && $y >= 0 && $y < $tex[1]{h}) {
580
581 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
582 my ($bx, $by) = ($self->{x}, $self->{y});
583
584 $self->{motion} = sub {
585 my ($ev, $x, $y) = @_;
586
587 ($x, $y) = ($ev->motion_x, $ev->motion_y);
588
589 $self->move ($bx + $x - $ox, $by + $y - $oy);
590 $self->update;
591 };
592 }
593}
594
595sub button_up {
596 my ($self, $ev, $x, $y) = @_;
597
598 delete $self->{motion};
599}
600
601sub mouse_motion {
602 my ($self, $ev, $x, $y) = @_;
603
604 $self->{motion}->($ev, $x, $y) if $self->{motion};
564} 605}
565 606
566sub _draw { 607sub _draw {
567 my ($self) = @_; 608 my ($self) = @_;
568 609
585 626
586 my $bottom = $tex[4]; 627 my $bottom = $tex[4];
587 $bottom->draw_quad (0, $h - $bottom->{h}, $w, $bottom->{h}); 628 $bottom->draw_quad (0, $h - $bottom->{h}, $w, $bottom->{h});
588 629
589 my $bg = $tex[0]; 630 my $bg = $tex[0];
631
590 glBindTexture GL_TEXTURE_2D, $bg->{name}; 632 glBindTexture GL_TEXTURE_2D, $bg->{name};
591 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 633 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
592 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; 634 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT;
593 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; 635 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT;
594 636
595 my $rep_x = $cw / $bg->{w}; 637 my $rep_x = $cw / $bg->{w};
596 my $rep_y = $ch / $bg->{h}; 638 my $rep_y = $ch / $bg->{h};
597 639
598 $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); 640 $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch);
599 641
642 glDisable GL_TEXTURE_2D;
600 glDisable GL_BLEND; 643 glDisable GL_BLEND;
601 glDisable GL_TEXTURE_2D;
602 644
603 $self->child->draw; 645 $self->child->draw;
604 646
605} 647}
606 648
611our @ISA = CFClient::UI::Base::; 653our @ISA = CFClient::UI::Base::;
612 654
613use List::Util qw(max sum); 655use List::Util qw(max sum);
614 656
615use SDL::OpenGL; 657use SDL::OpenGL;
658
659sub new {
660 my $class = shift;
661
662 $class->SUPER::new (
663 col_expand => [],
664 @_
665 )
666}
616 667
617sub add { 668sub add {
618 my ($self, $x, $y, $chld) = @_; 669 my ($self, $x, $y, $chld) = @_;
619 670
620 $self->{children}[$y][$x] = $chld; 671 $self->{children}[$y][$x] = $chld;
650 my ($self) = @_; 701 my ($self) = @_;
651 702
652 my ($ws, $hs) = $self->get_wh; 703 my ($ws, $hs) = $self->get_wh;
653 704
654 ( 705 (
655 (List::Util::sum @$ws), 706 (sum @$ws),
656 (List::Util::sum @$hs), 707 (sum @$hs),
657 ) 708 )
658} 709}
659 710
660sub size_allocate { 711sub size_allocate {
661 my ($self, $x, $y, $w, $h) = @_; 712 my ($self, $x, $y, $w, $h) = @_;
662 713
663 $self->_size_allocate ($x, $y, $w, $h) or return; 714 $self->_size_allocate ($x, $y, $w, $h) or return;
664 715
665 my ($ws, $hs) = $self->get_wh; 716 my ($ws, $hs) = $self->get_wh;
666 717
667 my $req_w = List::Util::sum @$ws; 718 my $req_w = sum @$ws;
668 my $req_h = List::Util::sum @$hs; 719 my $req_h = sum @$hs;
720
721 # TODO: nicer code && do row_expand
722 my @col_expand = @{$self->{col_expand}};
723 @col_expand = (1) x @$ws unless @col_expand;
724 my $col_expand = (sum @col_expand) || 1;
669 725
670 # linearly scale sizes 726 # linearly scale sizes
671 $_ *= $req_w / $w for @$ws; 727 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
672 $_ *= $req_h / $h for @$hs; 728 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
673 729
674 my $y; 730 my $y;
675 731
676 for my $r (0 .. $#{$self->{children}}) { 732 for my $r (0 .. $#{$self->{children}}) {
677 my $row = $self->{children}[$r] 733 my $row = $self->{children}[$r]
694 $y += $row_h; 750 $y += $row_h;
695 } 751 }
696 752
697} 753}
698 754
755sub find_widget {
756 my ($self, $x, $y) = @_;
757
758 $x -= $self->{x};
759 $y -= $self->{y};
760
761 my $res;
762
763 for (grep $_, map @$_, grep $_, @{ $self->{children} }) {
764 $res = $_->find_widget ($x, $y)
765 and return $res;
766 }
767
768 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y})
769}
770
699sub _draw { 771sub _draw {
700 my ($self) = @_; 772 my ($self) = @_;
701 773
702 for (grep $_, @{$self->{children}}) { 774 for (grep $_, @{$self->{children}}) {
703 $_->draw for grep $_, @$_; 775 $_->draw for grep $_, @$_;
704 } 776 }
705} 777}
706 778
707############################################################################# 779#############################################################################
708 780
781package CFClient::UI::HBox;
782
783# TODO: wrap into common Box base class
784
785our @ISA = CFClient::UI::Container::;
786
787sub size_request {
788 my ($self) = @_;
789
790 my @alloc = map [$_->size_request], @{$self->{children}};
791
792 (
793 (List::Util::sum map $_->[0], @alloc),
794 (List::Util::max map $_->[1], @alloc),
795 )
796}
797
798sub size_allocate {
799 my ($self, $x, $y, $w, $h) = @_;
800
801 $self->_size_allocate ($x, $y, $w, $h) or return;
802
803 return unless $self->{w};
804
805 ($h, $w) = ($w, $h);
806
807 my $children = $self->{children};
808
809 my @h = map +($_->size_request)[0], @$children;
810
811 my $req_h = List::Util::sum @h;
812
813 if ($req_h > $h) {
814 # ah well, not enough space
815 $_ *= $h / $req_h for @h;
816 } else {
817 my $exp = List::Util::sum map $_->{expand}, @$children;
818 $exp ||= 1;
819
820 for (0 .. $#$children) {
821 my $child = $children->[$_];
822
823 my $alloc_h = $h[$_];
824 $alloc_h += ($h - $req_h) * $child->{expand} / $exp;
825 $h[$_] = $alloc_h;
826 }
827 }
828
829 my $y = 0;
830 for (0 .. $#$children) {
831 my $child = $children->[$_];
832 my $h = $h[$_];
833 $child->size_allocate ($y, 0, $h, $w);
834
835 $y += $h;
836 }
837}
838
839#############################################################################
840
709package CFClient::UI::VBox; 841package CFClient::UI::VBox;
710 842
843# TODO: wrap into common Box base class
844
711our @ISA = CFClient::UI::Container::; 845our @ISA = CFClient::UI::Container::;
712
713use SDL::OpenGL;
714 846
715sub size_request { 847sub size_request {
716 my ($self) = @_; 848 my ($self) = @_;
717 849
718 my @alloc = map [$_->size_request], @{$self->{children}}; 850 my @alloc = map [$_->size_request], @{$self->{children}};
736 868
737 my $req_h = List::Util::sum @h; 869 my $req_h = List::Util::sum @h;
738 870
739 if ($req_h > $h) { 871 if ($req_h > $h) {
740 # ah well, not enough space 872 # ah well, not enough space
741 $_ = $h[$_] * $h / $req_h for @h; 873 $_ *= $h / $req_h for @h;
742 } else { 874 } else {
743 my @exp = grep $_->{expand}, @$children; 875 my $exp = List::Util::sum map $_->{expand}, @$children;
744 @exp = @$children unless @exp; 876 $exp ||= 1;
745 877
746 my %exp = map +($_ => 1), @exp;
747
748 for (0 .. $#$children) { 878 for (0 .. $#$children) {
749 my $child = $children->[$_]; 879 my $child = $children->[$_];
750 880
751 my $alloc_h = $h[$_]; 881 $h[$_] += ($h - $req_h) * $child->{expand} / $exp;
752 $alloc_h += ($h - $req_h) / @exp if $exp{$child};
753 $h[$_] = $alloc_h;
754 } 882 }
755 } 883 }
756 884
757 my $y = 0; 885 my $y = 0;
758 for (0 .. $#$children) { 886 for (0 .. $#$children) {
774 902
775sub new { 903sub new {
776 my ($class, %arg) = @_; 904 my ($class, %arg) = @_;
777 905
778 my $self = $class->SUPER::new ( 906 my $self = $class->SUPER::new (
779 fg => [1, 1, 1], 907 fg => [1, 1, 1],
780 height => $::FONTSIZE, 908 height => $::FONTSIZE,
781 text => "", 909 text => "",
782 align => -1, 910 align => -1,
911 padding => 2,
783 layout => new CFClient::Layout, 912 layout => new CFClient::Layout,
784 %arg 913 %arg
785 ); 914 );
786 915
787 $self->set_text ($self->{text}); 916 $self->set_text ($self->{text});
788 917
818sub size_request { 947sub size_request {
819 my ($self) = @_; 948 my ($self) = @_;
820 949
821 $self->{layout}->set_width; 950 $self->{layout}->set_width;
822 $self->{layout}->set_height ($self->{height}); 951 $self->{layout}->set_height ($self->{height});
823 $self->{layout}->size 952 my ($w, $h) = $self->{layout}->size;
824# if ($self->{texture}{w} > 1 && $self->{texture}{height} > 1) { #TODO: hack 953
825# ( 954 (
826# $self->{texture}{w}, 955 $w + $self->{padding} * 2,
827# $self->{texture}{h}, 956 $h + $self->{padding} * 2,
828# ) 957 )
829# } else {
830# my ($w, $h, $data) = CFClient::font_render "Yy", $self->{h};
831#
832# ($w, $h)
833# }
834} 958}
835 959
836sub size_allocate { 960sub size_allocate {
837 my ($self, $x, $y, $w, $h) = @_; 961 my ($self, $x, $y, $w, $h) = @_;
838 962
851sub _draw { 975sub _draw {
852 my ($self) = @_; 976 my ($self) = @_;
853 977
854 my $tex = $self->{texture} ||= do { 978 my $tex = $self->{texture} ||= do {
855 $self->{layout}->set_width ($self->{w}); 979 $self->{layout}->set_width ($self->{w});
980 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{height});
856 new_from_layout CFClient::Texture $self->{layout} 981 new_from_layout CFClient::Texture $self->{layout}
857 }; 982 };
858 983
859 glEnable GL_BLEND; 984 glEnable GL_BLEND;
860 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 985 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
862 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 987 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
863 988
864 glColor @{$self->{fg}}; 989 glColor @{$self->{fg}};
865 990
866 my $x = 991 my $x =
867 $self->{align} < 0 ? 0 992 $self->{align} < 0 ? $self->{padding}
868 : $self->{align} > 0 ? $self->{w} - $tex->{w} 993 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
869 : ($self->{w} - $tex->{w}) * 0.5; 994 : ($self->{w} - $tex->{w}) * 0.5;
870 995
871 $tex->draw_quad ($x, 0); 996 $tex->draw_quad ($x, $self->{padding});
872 997
873 glDisable GL_TEXTURE_2D; 998 glDisable GL_TEXTURE_2D;
874 glDisable GL_BLEND; 999 glDisable GL_BLEND;
875} 1000}
876 1001
886sub new { 1011sub new {
887 my $class = shift; 1012 my $class = shift;
888 1013
889 $class->SUPER::new ( 1014 $class->SUPER::new (
890 fg => [1, 1, 1], 1015 fg => [1, 1, 1],
891 bg => [0, 0, 0, 0.4], 1016 bg => [0, 0, 0, 0.2],
892 active_bg => [1, 1, 1], 1017 active_bg => [1, 1, 1],
893 active_fg => [0, 0, 0], 1018 active_fg => [0, 0, 0],
894 @_ 1019 @_
895 ) 1020 )
896} 1021}
903 $self->{text} = $text; 1028 $self->{text} = $text;
904 $self->{layout}->set_width ($self->{w}); 1029 $self->{layout}->set_width ($self->{w});
905 1030
906 $text =~ s/./*/g if $self->{hidden}; 1031 $text =~ s/./*/g if $self->{hidden};
907 1032
908
909 $self->{layout}->set_markup ($self->escape_text ($text)); 1033 $self->{layout}->set_markup ($self->escape_text ($text) . " ");
910 1034
911 $text = substr $text, 0, $self->{cursor}; 1035 $text = substr $text, 0, $self->{cursor};
912 utf8::encode $text; 1036 utf8::encode $text;
913 1037
914 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); 1038 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
954 substr $text, $self->{cursor}, 1, ""; 1078 substr $text, $self->{cursor}, 1, "";
955 } elsif ($sym == SDLK_LEFT) { 1079 } elsif ($sym == SDLK_LEFT) {
956 --$self->{cursor} if $self->{cursor}; 1080 --$self->{cursor} if $self->{cursor};
957 } elsif ($sym == SDLK_RIGHT) { 1081 } elsif ($sym == SDLK_RIGHT) {
958 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1082 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1083 } elsif ($sym == SDLK_HOME) {
1084 $self->{cursor} = 0;
1085 } elsif ($sym == SDLK_END) {
1086 $self->{cursor} = length $text;
959 } elsif ($uni) { 1087 } elsif ($uni) {
960 substr $text, $self->{cursor}++, 0, chr $uni; 1088 substr $text, $self->{cursor}++, 0, chr $uni;
961 } 1089 }
962 1090
963 $self->_set_text ($text); 1091 $self->_set_text ($text);
978 $self->SUPER::button_down ($ev, $x, $y); 1106 $self->SUPER::button_down ($ev, $x, $y);
979 1107
980 my $idx = $self->{layout}->xy_to_index ($x, $y); 1108 my $idx = $self->{layout}->xy_to_index ($x, $y);
981 1109
982 # byte-index to char-index 1110 # byte-index to char-index
983 my $text = $self->{layout}; 1111 my $text = $self->{text};
984 utf8::encode $text; 1112 utf8::encode $text;
985 $self->{cursor} = length substr $text, 0, $idx; 1113 $self->{cursor} = length substr $text, 0, $idx;
986 1114
987 $self->_set_text ($self->{text}); 1115 $self->_set_text ($self->{text});
988 $self->update; 1116 $self->update;
1003 $self->{fg} = $self->{active_fg}; 1131 $self->{fg} = $self->{active_fg};
1004 } else { 1132 } else {
1005 glColor @{$self->{bg}}; 1133 glColor @{$self->{bg}};
1006 } 1134 }
1007 1135
1136 glEnable GL_BLEND;
1137 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1008 glBegin GL_QUADS; 1138 glBegin GL_QUADS;
1009 glVertex 0 , 0; 1139 glVertex 0 , 0;
1010 glVertex 0 , $self->{h}; 1140 glVertex 0 , $self->{h};
1011 glVertex $self->{w}, $self->{h}; 1141 glVertex $self->{w}, $self->{h};
1012 glVertex $self->{w}, 0; 1142 glVertex $self->{w}, 0;
1013 glEnd; 1143 glEnd;
1144 glDisable GL_BLEND;
1014 1145
1015 $self->SUPER::_draw; 1146 $self->SUPER::_draw;
1016 1147
1017 #TODO: force update every cursor change :( 1148 #TODO: force update every cursor change :(
1018 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { 1149 if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) {
1032 1163
1033use SDL::OpenGL; 1164use SDL::OpenGL;
1034 1165
1035our @ISA = CFClient::UI::DrawBG::; 1166our @ISA = CFClient::UI::DrawBG::;
1036 1167
1037sub size_request {
1038 my ($self) = @_;
1039
1040 my $w = 50;
1041 my $h = 10;
1042
1043 $self->{vertical} ? ($h, $w) : ($w, $h)
1044}
1045
1046sub new { 1168sub new {
1047 my $class = shift; 1169 my $class = shift;
1048 1170
1049 # range [value, low, high, page] 1171 # range [value, low, high, page]
1050 1172
1051 $class->SUPER::new ( 1173 my $self = $class->SUPER::new (
1052 fg => [1, 1, 1], 1174 fg => [1, 1, 1],
1053 active_fg => [0, 0, 0], 1175 active_fg => [0, 0, 0],
1054 range => [0, 0, 100, 10], 1176 range => [0, 0, 100, 10],
1177 req_w => 40,
1178 req_h => 10,
1055 vertical => 1, 1179 vertical => 0,
1056 @_ 1180 @_
1057 ) 1181 );
1182
1183 $self
1184}
1185
1186sub size_request {
1187 my ($self) = @_;
1188
1189 my $w = $self->{req_w};
1190 my $h = $self->{req_h};
1191
1192 $self->{vertical} ? ($h, $w) : ($w, $h)
1058} 1193}
1059 1194
1060sub button_down { 1195sub button_down {
1061 my ($self, $ev, $x, $y) = @_; 1196 my ($self, $ev, $x, $y) = @_;
1062 1197
1167sub key_up { 1302sub key_up {
1168} 1303}
1169 1304
1170sub size_request { 1305sub size_request {
1171 ( 1306 (
1172 1 + int $::WIDTH / 32, 1307 1 + 32 * int $::WIDTH / 32,
1173 1 + int $::HEIGHT / 32, 1308 1 + 32 * int $::HEIGHT / 32,
1174 ) 1309 )
1175} 1310}
1176 1311
1177sub update { 1312sub update {
1178 my ($self) = @_; 1313 my ($self) = @_;
1179 1314
1180 $self->{need_update} = 1; 1315 $self->{need_update} = 1;
1181 $self->SUPER::update; 1316 $self->SUPER::update;
1182} 1317}
1183 1318
1184sub _draw { 1319sub draw {
1185 my ($self) = @_; 1320 my ($self) = @_;
1186 1321
1187 if (delete $self->{need_update}) { 1322 if (delete $self->{need_update}) {
1188 glNewList $self->{list}, GL_COMPILE; 1323 glNewList $self->{list}, GL_COMPILE;
1189 1324

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines