… | |
… | |
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; |
… | |
… | |
275 | my $class = shift; |
275 | my $class = shift; |
276 | |
276 | |
277 | # range [value, low, high, page] |
277 | # range [value, low, high, page] |
278 | |
278 | |
279 | $class->SUPER::new ( |
279 | $class->SUPER::new ( |
280 | bg => [0, 0, 0, 0.4], |
280 | bg => [0, 0, 0, 0.2], |
281 | active_bg => [1, 1, 1], |
281 | active_bg => [1, 1, 1], |
282 | @_ |
282 | @_ |
283 | ) |
283 | ) |
284 | } |
284 | } |
285 | |
285 | |
286 | sub _draw { |
286 | sub _draw { |
287 | my ($self) = @_; |
287 | my ($self) = @_; |
288 | |
288 | |
289 | my ($w, $h) = @$self{qw(w h)}; |
289 | my ($w, $h) = @$self{qw(w h)}; |
290 | |
290 | |
|
|
291 | glEnable GL_BLEND; |
|
|
292 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
291 | glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} }; |
293 | glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} }; |
|
|
294 | |
292 | glBegin GL_QUADS; |
295 | glBegin GL_QUADS; |
293 | glVertex 0 , 0; |
296 | glVertex 0 , 0; |
294 | glVertex 0 , $h; |
297 | glVertex 0 , $h; |
295 | glVertex $w, $h; |
298 | glVertex $w, $h; |
296 | glVertex $w, 0; |
299 | glVertex $w, 0; |
297 | glEnd; |
300 | glEnd; |
|
|
301 | |
|
|
302 | glDisable GL_BLEND; |
298 | } |
303 | } |
299 | |
304 | |
300 | ############################################################################# |
305 | ############################################################################# |
301 | |
306 | |
302 | package CFClient::UI::Empty; |
307 | package CFClient::UI::Empty; |
… | |
… | |
325 | |
330 | |
326 | $self |
331 | $self |
327 | } |
332 | } |
328 | |
333 | |
329 | sub add { |
334 | sub add { |
330 | my ($self, $chld, $expand) = @_; |
335 | my ($self, $chld) = @_; |
331 | |
336 | |
332 | $chld->{expand} = $expand; |
|
|
333 | $chld->set_parent ($self); |
337 | $chld->set_parent ($self); |
334 | |
338 | |
335 | $self->{children} = [ |
339 | $self->{children} = [ |
336 | sort { $a->{z} <=> $b->{z} } |
340 | sort { $a->{z} <=> $b->{z} } |
337 | @{$self->{children}}, $chld |
341 | @{$self->{children}}, $chld |
… | |
… | |
533 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
537 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
534 | |
538 | |
535 | sub size_request { |
539 | sub size_request { |
536 | my ($self) = @_; |
540 | my ($self) = @_; |
537 | |
541 | |
|
|
542 | my ($w, $h) = |
|
|
543 | $self->{user_w} && $self->{user_h} |
|
|
544 | ? ($self->{user_w}, $self->{user_h}) |
538 | my ($w, $h) = $self->SUPER::size_request; |
545 | : ($self->SUPER::size_request); |
539 | |
546 | |
540 | $h += $tex[1]->{h}; |
547 | $h += $tex[1]->{h}; |
541 | $h += $tex[4]->{h}; |
548 | $h += $tex[4]->{h}; |
542 | $w += $tex[2]->{w}; |
549 | $w += $tex[2]->{w}; |
543 | $w += $tex[3]->{w}; |
550 | $w += $tex[3]->{w}; |
… | |
… | |
548 | sub size_allocate { |
555 | sub size_allocate { |
549 | my ($self, $x, $y, $w, $h) = @_; |
556 | my ($self, $x, $y, $w, $h) = @_; |
550 | |
557 | |
551 | $self->_size_allocate ($x, $y, $w, $h) or return; |
558 | $self->_size_allocate ($x, $y, $w, $h) or return; |
552 | |
559 | |
553 | $h -= $tex[1]->{h}; |
560 | $h -= $tex[1]{h}; |
554 | $h -= $tex[4]->{h}; |
561 | $h -= $tex[4]{h}; |
555 | $w -= $tex[2]->{w}; |
562 | $w -= $tex[2]{w}; |
556 | $w -= $tex[3]->{w}; |
563 | $w -= $tex[3]{w}; |
557 | |
564 | |
558 | $h = $h < 0 ? 0 : $h; |
565 | $h = $h < 0 ? 0 : $h; |
559 | $w = $w < 0 ? 0 : $w; |
566 | $w = $w < 0 ? 0 : $w; |
560 | |
567 | |
561 | my $child = $self->child; |
568 | my $child = $self->child; |
562 | |
569 | |
563 | $child->size_allocate ($tex[3]->{w}, $tex[1]->{h}, $w, $h); |
570 | $child->size_allocate ($tex[3]->{w}, $tex[1]->{h}, $w, $h); |
|
|
571 | } |
|
|
572 | |
|
|
573 | sub button_down { |
|
|
574 | my ($self, $ev, $x, $y) = @_; |
|
|
575 | |
|
|
576 | if ($x < $self->{w} && $x >= $self->{w} - $tex[2]{w} |
|
|
577 | && $y < $self->{h} && $y >= $self->{h} - $tex[4]{h}) { |
|
|
578 | |
|
|
579 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
|
|
580 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
|
|
581 | |
|
|
582 | $self->{motion} = sub { |
|
|
583 | my ($ev, $x, $y) = @_; |
|
|
584 | |
|
|
585 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
586 | |
|
|
587 | $self->{user_w} = $bw + $x - $ox; |
|
|
588 | $self->{user_h} = $bh + $y - $oy; |
|
|
589 | $self->update; |
|
|
590 | }; |
|
|
591 | |
|
|
592 | } elsif ($x >= 0 && $x < $self->{w} |
|
|
593 | && $y >= 0 && $y < $tex[1]{h}) { |
|
|
594 | |
|
|
595 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
|
|
596 | my ($bx, $by) = ($self->{x}, $self->{y}); |
|
|
597 | |
|
|
598 | $self->{motion} = sub { |
|
|
599 | my ($ev, $x, $y) = @_; |
|
|
600 | |
|
|
601 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
602 | |
|
|
603 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
|
|
604 | $self->update; |
|
|
605 | }; |
|
|
606 | } |
|
|
607 | } |
|
|
608 | |
|
|
609 | sub button_up { |
|
|
610 | my ($self, $ev, $x, $y) = @_; |
|
|
611 | |
|
|
612 | delete $self->{motion}; |
|
|
613 | } |
|
|
614 | |
|
|
615 | sub mouse_motion { |
|
|
616 | my ($self, $ev, $x, $y) = @_; |
|
|
617 | |
|
|
618 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
564 | } |
619 | } |
565 | |
620 | |
566 | sub _draw { |
621 | sub _draw { |
567 | my ($self) = @_; |
622 | my ($self) = @_; |
568 | |
623 | |
… | |
… | |
585 | |
640 | |
586 | my $bottom = $tex[4]; |
641 | my $bottom = $tex[4]; |
587 | $bottom->draw_quad (0, $h - $bottom->{h}, $w, $bottom->{h}); |
642 | $bottom->draw_quad (0, $h - $bottom->{h}, $w, $bottom->{h}); |
588 | |
643 | |
589 | my $bg = $tex[0]; |
644 | my $bg = $tex[0]; |
|
|
645 | |
590 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
646 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
591 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
647 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
592 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
648 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
593 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
649 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
594 | |
650 | |
595 | my $rep_x = $cw / $bg->{w}; |
651 | my $rep_x = $cw / $bg->{w}; |
596 | my $rep_y = $ch / $bg->{h}; |
652 | my $rep_y = $ch / $bg->{h}; |
597 | |
653 | |
598 | $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); |
654 | $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); |
599 | |
655 | |
|
|
656 | glDisable GL_TEXTURE_2D; |
600 | glDisable GL_BLEND; |
657 | glDisable GL_BLEND; |
601 | glDisable GL_TEXTURE_2D; |
|
|
602 | |
658 | |
603 | $self->child->draw; |
659 | $self->child->draw; |
604 | |
660 | |
605 | } |
661 | } |
606 | |
662 | |
… | |
… | |
666 | |
722 | |
667 | my $req_w = List::Util::sum @$ws; |
723 | my $req_w = List::Util::sum @$ws; |
668 | my $req_h = List::Util::sum @$hs; |
724 | my $req_h = List::Util::sum @$hs; |
669 | |
725 | |
670 | # linearly scale sizes |
726 | # linearly scale sizes |
671 | $_ *= $req_w / $w for @$ws; |
727 | $_ *= $w / $req_w for @$ws; |
672 | $_ *= $req_h / $h for @$hs; |
728 | $_ *= $h / $req_h for @$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 | |
|
|
755 | sub 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 | |
699 | sub _draw { |
771 | sub _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 | |
|
|
781 | package CFClient::UI::HBox; |
|
|
782 | |
|
|
783 | # TODO: wrap into common Box base class |
|
|
784 | |
|
|
785 | our @ISA = CFClient::UI::Container::; |
|
|
786 | |
|
|
787 | sub 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 | |
|
|
798 | sub 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[$_] * $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 | |
709 | package CFClient::UI::VBox; |
841 | package CFClient::UI::VBox; |
710 | |
842 | |
|
|
843 | # TODO: wrap into common Box base class |
|
|
844 | |
711 | our @ISA = CFClient::UI::Container::; |
845 | our @ISA = CFClient::UI::Container::; |
712 | |
|
|
713 | use SDL::OpenGL; |
|
|
714 | |
846 | |
715 | sub size_request { |
847 | sub 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}}; |
… | |
… | |
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[$_] * $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 | |
775 | sub new { |
903 | sub 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 | |
… | |
… | |
818 | sub size_request { |
947 | sub 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 | |
836 | sub size_allocate { |
960 | sub size_allocate { |
837 | my ($self, $x, $y, $w, $h) = @_; |
961 | my ($self, $x, $y, $w, $h) = @_; |
838 | |
962 | |
… | |
… | |
862 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
986 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
863 | |
987 | |
864 | glColor @{$self->{fg}}; |
988 | glColor @{$self->{fg}}; |
865 | |
989 | |
866 | my $x = |
990 | my $x = |
867 | $self->{align} < 0 ? 0 |
991 | $self->{align} < 0 ? $self->{padding} |
868 | : $self->{align} > 0 ? $self->{w} - $tex->{w} |
992 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
869 | : ($self->{w} - $tex->{w}) * 0.5; |
993 | : ($self->{w} - $tex->{w}) * 0.5; |
870 | |
994 | |
871 | $tex->draw_quad ($x, 0); |
995 | $tex->draw_quad ($x, $self->{padding}); |
872 | |
996 | |
873 | glDisable GL_TEXTURE_2D; |
997 | glDisable GL_TEXTURE_2D; |
874 | glDisable GL_BLEND; |
998 | glDisable GL_BLEND; |
875 | } |
999 | } |
876 | |
1000 | |
… | |
… | |
886 | sub new { |
1010 | sub new { |
887 | my $class = shift; |
1011 | my $class = shift; |
888 | |
1012 | |
889 | $class->SUPER::new ( |
1013 | $class->SUPER::new ( |
890 | fg => [1, 1, 1], |
1014 | fg => [1, 1, 1], |
891 | bg => [0, 0, 0, 0.4], |
1015 | bg => [0, 0, 0, 0.2], |
892 | active_bg => [1, 1, 1], |
1016 | active_bg => [1, 1, 1], |
893 | active_fg => [0, 0, 0], |
1017 | active_fg => [0, 0, 0], |
894 | @_ |
1018 | @_ |
895 | ) |
1019 | ) |
896 | } |
1020 | } |
… | |
… | |
903 | $self->{text} = $text; |
1027 | $self->{text} = $text; |
904 | $self->{layout}->set_width ($self->{w}); |
1028 | $self->{layout}->set_width ($self->{w}); |
905 | |
1029 | |
906 | $text =~ s/./*/g if $self->{hidden}; |
1030 | $text =~ s/./*/g if $self->{hidden}; |
907 | |
1031 | |
908 | |
|
|
909 | $self->{layout}->set_markup ($self->escape_text ($text)); |
1032 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
910 | |
1033 | |
911 | $text = substr $text, 0, $self->{cursor}; |
1034 | $text = substr $text, 0, $self->{cursor}; |
912 | utf8::encode $text; |
1035 | utf8::encode $text; |
913 | |
1036 | |
914 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
1037 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
… | |
… | |
954 | substr $text, $self->{cursor}, 1, ""; |
1077 | substr $text, $self->{cursor}, 1, ""; |
955 | } elsif ($sym == SDLK_LEFT) { |
1078 | } elsif ($sym == SDLK_LEFT) { |
956 | --$self->{cursor} if $self->{cursor}; |
1079 | --$self->{cursor} if $self->{cursor}; |
957 | } elsif ($sym == SDLK_RIGHT) { |
1080 | } elsif ($sym == SDLK_RIGHT) { |
958 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1081 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
|
|
1082 | } elsif ($sym == SDLK_HOME) { |
|
|
1083 | $self->{cursor} = 0; |
|
|
1084 | } elsif ($sym == SDLK_END) { |
|
|
1085 | $self->{cursor} = length $text; |
959 | } elsif ($uni) { |
1086 | } elsif ($uni) { |
960 | substr $text, $self->{cursor}++, 0, chr $uni; |
1087 | substr $text, $self->{cursor}++, 0, chr $uni; |
961 | } |
1088 | } |
962 | |
1089 | |
963 | $self->_set_text ($text); |
1090 | $self->_set_text ($text); |
… | |
… | |
978 | $self->SUPER::button_down ($ev, $x, $y); |
1105 | $self->SUPER::button_down ($ev, $x, $y); |
979 | |
1106 | |
980 | my $idx = $self->{layout}->xy_to_index ($x, $y); |
1107 | my $idx = $self->{layout}->xy_to_index ($x, $y); |
981 | |
1108 | |
982 | # byte-index to char-index |
1109 | # byte-index to char-index |
983 | my $text = $self->{layout}; |
1110 | my $text = $self->{text}; |
984 | utf8::encode $text; |
1111 | utf8::encode $text; |
985 | $self->{cursor} = length substr $text, 0, $idx; |
1112 | $self->{cursor} = length substr $text, 0, $idx; |
986 | |
1113 | |
987 | $self->_set_text ($self->{text}); |
1114 | $self->_set_text ($self->{text}); |
988 | $self->update; |
1115 | $self->update; |
… | |
… | |
1003 | $self->{fg} = $self->{active_fg}; |
1130 | $self->{fg} = $self->{active_fg}; |
1004 | } else { |
1131 | } else { |
1005 | glColor @{$self->{bg}}; |
1132 | glColor @{$self->{bg}}; |
1006 | } |
1133 | } |
1007 | |
1134 | |
|
|
1135 | glEnable GL_BLEND; |
|
|
1136 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1008 | glBegin GL_QUADS; |
1137 | glBegin GL_QUADS; |
1009 | glVertex 0 , 0; |
1138 | glVertex 0 , 0; |
1010 | glVertex 0 , $self->{h}; |
1139 | glVertex 0 , $self->{h}; |
1011 | glVertex $self->{w}, $self->{h}; |
1140 | glVertex $self->{w}, $self->{h}; |
1012 | glVertex $self->{w}, 0; |
1141 | glVertex $self->{w}, 0; |
1013 | glEnd; |
1142 | glEnd; |
|
|
1143 | glDisable GL_BLEND; |
1014 | |
1144 | |
1015 | $self->SUPER::_draw; |
1145 | $self->SUPER::_draw; |
1016 | |
1146 | |
1017 | #TODO: force update every cursor change :( |
1147 | #TODO: force update every cursor change :( |
1018 | if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { |
1148 | if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { |
… | |
… | |
1032 | |
1162 | |
1033 | use SDL::OpenGL; |
1163 | use SDL::OpenGL; |
1034 | |
1164 | |
1035 | our @ISA = CFClient::UI::DrawBG::; |
1165 | our @ISA = CFClient::UI::DrawBG::; |
1036 | |
1166 | |
1037 | sub size_request { |
|
|
1038 | my ($self) = @_; |
|
|
1039 | |
|
|
1040 | my $w = 50; |
|
|
1041 | my $h = 10; |
|
|
1042 | |
|
|
1043 | $self->{vertical} ? ($h, $w) : ($w, $h) |
|
|
1044 | } |
|
|
1045 | |
|
|
1046 | sub new { |
1167 | sub new { |
1047 | my $class = shift; |
1168 | my $class = shift; |
1048 | |
1169 | |
1049 | # range [value, low, high, page] |
1170 | # range [value, low, high, page] |
1050 | |
1171 | |
1051 | $class->SUPER::new ( |
1172 | my $self = $class->SUPER::new ( |
1052 | fg => [1, 1, 1], |
1173 | fg => [1, 1, 1], |
1053 | active_fg => [0, 0, 0], |
1174 | active_fg => [0, 0, 0], |
1054 | range => [0, 0, 100, 10], |
1175 | range => [0, 0, 100, 10], |
|
|
1176 | req_w => 40, |
|
|
1177 | req_h => 10, |
1055 | vertical => 1, |
1178 | vertical => 0, |
1056 | @_ |
1179 | @_ |
1057 | ) |
1180 | ); |
|
|
1181 | |
|
|
1182 | $self |
|
|
1183 | } |
|
|
1184 | |
|
|
1185 | sub size_request { |
|
|
1186 | my ($self) = @_; |
|
|
1187 | |
|
|
1188 | my $w = $self->{req_w}; |
|
|
1189 | my $h = $self->{req_h}; |
|
|
1190 | |
|
|
1191 | $self->{vertical} ? ($h, $w) : ($w, $h) |
1058 | } |
1192 | } |
1059 | |
1193 | |
1060 | sub button_down { |
1194 | sub button_down { |
1061 | my ($self, $ev, $x, $y) = @_; |
1195 | my ($self, $ev, $x, $y) = @_; |
1062 | |
1196 | |
… | |
… | |
1167 | sub key_up { |
1301 | sub key_up { |
1168 | } |
1302 | } |
1169 | |
1303 | |
1170 | sub size_request { |
1304 | sub size_request { |
1171 | ( |
1305 | ( |
1172 | 1 + int $::WIDTH / 32, |
1306 | 1 + 32 * int $::WIDTH / 32, |
1173 | 1 + int $::HEIGHT / 32, |
1307 | 1 + 32 * int $::HEIGHT / 32, |
1174 | ) |
1308 | ) |
1175 | } |
1309 | } |
1176 | |
1310 | |
1177 | sub update { |
1311 | sub update { |
1178 | my ($self) = @_; |
1312 | my ($self) = @_; |
1179 | |
1313 | |
1180 | $self->{need_update} = 1; |
1314 | $self->{need_update} = 1; |
1181 | $self->SUPER::update; |
1315 | $self->SUPER::update; |
1182 | } |
1316 | } |
1183 | |
1317 | |
1184 | sub _draw { |
1318 | sub draw { |
1185 | my ($self) = @_; |
1319 | my ($self) = @_; |
1186 | |
1320 | |
1187 | if (delete $self->{need_update}) { |
1321 | if (delete $self->{need_update}) { |
1188 | glNewList $self->{list}, GL_COMPILE; |
1322 | glNewList $self->{list}, GL_COMPILE; |
1189 | |
1323 | |