… | |
… | |
114 | } |
114 | } |
115 | |
115 | |
116 | sub focus_in { |
116 | sub focus_in { |
117 | my ($self) = @_; |
117 | my ($self) = @_; |
118 | |
118 | |
|
|
119 | return if $FOCUS == $self; |
|
|
120 | |
119 | my $focus = $FOCUS; $FOCUS = $self; |
121 | my $focus = $FOCUS; $FOCUS = $self; |
120 | $focus->update if $focus; |
122 | $focus->update if $focus; |
121 | $FOCUS->update; |
123 | $FOCUS->update; |
122 | } |
124 | } |
123 | |
125 | |
… | |
… | |
130 | $focus->update if $focus; #? |
132 | $focus->update if $focus; #? |
131 | } |
133 | } |
132 | |
134 | |
133 | sub mouse_motion { } |
135 | sub mouse_motion { } |
134 | sub button_up { } |
136 | sub button_up { } |
135 | sub button_down { } |
|
|
136 | sub key_down { } |
137 | sub key_down { } |
137 | sub key_up { } |
138 | sub key_up { } |
|
|
139 | |
|
|
140 | sub button_down { |
|
|
141 | my ($self, $ev, $x, $y) = @_; |
|
|
142 | |
|
|
143 | $self->focus_in; |
|
|
144 | } |
138 | |
145 | |
139 | sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } |
146 | sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } |
140 | sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } |
147 | sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } |
141 | sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } |
148 | sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } |
142 | sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } |
149 | sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } |
143 | sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } |
150 | sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } |
144 | |
151 | |
145 | sub draw { |
152 | sub draw { |
146 | my ($self) = @_; |
153 | my ($self) = @_; |
|
|
154 | |
|
|
155 | return unless $self->{h} && $self->{w}; |
147 | |
156 | |
148 | glPushMatrix; |
157 | glPushMatrix; |
149 | glTranslate $self->{x}, $self->{y}, 0; |
158 | glTranslate $self->{x}, $self->{y}, 0; |
150 | $self->_draw; |
159 | $self->_draw; |
151 | if ($self == $HOVER) { |
160 | if ($self == $HOVER) { |
… | |
… | |
215 | #$self->deactivate; |
224 | #$self->deactivate; |
216 | } |
225 | } |
217 | |
226 | |
218 | ############################################################################# |
227 | ############################################################################# |
219 | |
228 | |
|
|
229 | package CFClient::Widget::DrawBG; |
|
|
230 | |
|
|
231 | our @ISA = CFClient::Widget::; |
|
|
232 | |
|
|
233 | use strict; |
|
|
234 | use SDL::OpenGL; |
|
|
235 | |
|
|
236 | sub new { |
|
|
237 | my $class = shift; |
|
|
238 | |
|
|
239 | # range [value, low, high, page] |
|
|
240 | |
|
|
241 | $class->SUPER::new ( |
|
|
242 | bg => [0, 0, 0, 0.4], |
|
|
243 | active_bg => [1, 1, 1], |
|
|
244 | @_ |
|
|
245 | ) |
|
|
246 | } |
|
|
247 | |
|
|
248 | sub _draw { |
|
|
249 | my ($self) = @_; |
|
|
250 | |
|
|
251 | my ($w, $h) = @$self{qw(w h)}; |
|
|
252 | |
|
|
253 | glColor @{ $FOCUS == $self ? $self->{active_bg} : $self->{bg} }; |
|
|
254 | glBegin GL_QUADS; |
|
|
255 | glVertex 0 , 0; |
|
|
256 | glVertex 0 , $h; |
|
|
257 | glVertex $w, $h; |
|
|
258 | glVertex $w, 0; |
|
|
259 | glEnd; |
|
|
260 | } |
|
|
261 | |
|
|
262 | ############################################################################# |
|
|
263 | |
220 | package CFClient::Widget::Empty; |
264 | package CFClient::Widget::Empty; |
221 | |
265 | |
222 | our @ISA = CFClient::Widget::; |
266 | our @ISA = CFClient::Widget::; |
223 | |
267 | |
224 | sub size_request { |
268 | sub size_request { |
225 | (0, 0) |
269 | (0, 0) |
226 | } |
270 | } |
227 | |
271 | |
228 | sub draw { |
272 | sub draw { } |
229 | } |
|
|
230 | |
273 | |
231 | ############################################################################# |
274 | ############################################################################# |
232 | |
275 | |
233 | package CFClient::Widget::Container; |
276 | package CFClient::Widget::Container; |
234 | |
277 | |
… | |
… | |
322 | } |
365 | } |
323 | |
366 | |
324 | sub child { $_[0]->{children}[0] } |
367 | sub child { $_[0]->{children}[0] } |
325 | |
368 | |
326 | sub size_request { |
369 | sub size_request { |
327 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
370 | $_[0]{children}[0]->size_request |
328 | } |
371 | } |
329 | |
372 | |
330 | sub size_allocate { |
373 | sub size_allocate { |
331 | my ($self, $w, $h) = @_; |
374 | my ($self, $w, $h) = @_; |
332 | |
375 | |
|
|
376 | return unless $self->{w} != $w || $self->{h} != $h; |
|
|
377 | |
333 | $self->SUPER::size_allocate ($w, $h); |
378 | $self->SUPER::size_allocate ($w, $h); |
334 | $self->{children}[0]->size_allocate ($w, $h) |
379 | $self->{children}[0]->size_allocate ($w, $h); |
335 | if $self->{children}[0] |
|
|
336 | } |
380 | } |
337 | |
381 | |
338 | ############################################################################# |
382 | ############################################################################# |
339 | |
383 | |
340 | package CFClient::Widget::Window; |
384 | package CFClient::Widget::Window; |
… | |
… | |
367 | } |
411 | } |
368 | |
412 | |
369 | sub size_allocate { |
413 | sub size_allocate { |
370 | my ($self, $w, $h) = @_; |
414 | my ($self, $w, $h) = @_; |
371 | |
415 | |
|
|
416 | return unless $self->{w} != $w || $self->{h} != $h; |
|
|
417 | |
372 | $self->{w} = $w; |
418 | $self->{w} = $w; |
373 | $self->{h} = $h; |
419 | $self->{h} = $h; |
374 | |
420 | |
375 | $self->child->size_allocate ($w, $h); |
421 | $self->child->size_allocate ($w, $h); |
376 | |
422 | |
… | |
… | |
414 | } |
460 | } |
415 | |
461 | |
416 | sub size_allocate { |
462 | sub size_allocate { |
417 | my ($self, $w, $h) = @_; |
463 | my ($self, $w, $h) = @_; |
418 | |
464 | |
|
|
465 | return unless $self->{w} != $w || $self->{h} != $h; |
|
|
466 | |
419 | $self->{w} = $w; |
467 | $self->{w} = $w; |
420 | $self->{h} = $h; |
468 | $self->{h} = $h; |
421 | |
469 | |
422 | $self->child->size_allocate ($w - 4, $h - 4); |
470 | $self->child->size_allocate ($w - 4, $h - 4); |
423 | $self->child->move (2, 2); |
471 | $self->child->move (2, 2); |
… | |
… | |
467 | } |
515 | } |
468 | |
516 | |
469 | sub size_allocate { |
517 | sub size_allocate { |
470 | my ($self, $w, $h) = @_; |
518 | my ($self, $w, $h) = @_; |
471 | |
519 | |
|
|
520 | return unless $self->{w} != $w || $self->{h} != $h; |
|
|
521 | |
472 | $self->SUPER::size_allocate ($w, $h); |
522 | $self->SUPER::size_allocate ($w, $h); |
473 | |
523 | |
474 | $h -= $tex[1]->{height}; |
524 | $h -= $tex[1]->{height}; |
475 | $h -= $tex[4]->{height}; |
525 | $h -= $tex[4]->{height}; |
476 | $w -= $tex[2]->{width}; |
526 | $w -= $tex[2]->{width}; |
… | |
… | |
633 | } |
683 | } |
634 | |
684 | |
635 | sub size_allocate { |
685 | sub size_allocate { |
636 | my ($self, $w, $h) = @_; |
686 | my ($self, $w, $h) = @_; |
637 | |
687 | |
|
|
688 | return unless $self->{w} != $w || $self->{h} != $h; |
|
|
689 | |
638 | $self->w ($w); |
690 | $self->{w} = $w; |
639 | $self->h ($h); |
691 | $self->{h} = $h; |
640 | |
692 | |
641 | my $exp; |
693 | return unless $self->{h}; |
642 | my @oth; |
694 | |
643 | # find expand widget |
695 | my $children = $self->{children}; |
644 | for (@{$self->{children}}) { |
696 | |
645 | if ($_->{expand}) { |
697 | my @h = map +($_->size_request)[1], @$children; |
646 | $exp = $_; |
698 | |
647 | last; |
699 | my $req_h = List::Util::sum @h; |
|
|
700 | |
|
|
701 | if ($req_h > $h) { |
|
|
702 | # ah well, not enough space |
|
|
703 | $_ = $h[$_] * $h / $req_h for @h; |
|
|
704 | } else { |
|
|
705 | my @exp = grep $_->{expand}, @$children; |
|
|
706 | @exp = @$children unless @exp; |
|
|
707 | |
|
|
708 | my %exp = map +($_ => 1), @exp; |
|
|
709 | |
|
|
710 | for (0 .. $#$children) { |
|
|
711 | my $child = $children->[$_]; |
|
|
712 | |
|
|
713 | my $alloc_h = $h[$_]; |
|
|
714 | $alloc_h += ($h - $req_h) / @exp if $exp{$child}; |
|
|
715 | $h[$_] = $alloc_h; |
648 | } |
716 | } |
649 | push @oth, $_; |
|
|
650 | } |
|
|
651 | |
|
|
652 | my ($ow, $oh); |
|
|
653 | |
|
|
654 | # get sizes of other widgets |
|
|
655 | for (@oth) { |
|
|
656 | my ($w, $h) = $_->size_request; |
|
|
657 | $oh += $h; |
|
|
658 | if ($ow < $w) { $ow = $w } |
|
|
659 | } |
717 | } |
660 | |
718 | |
661 | my $y = 0; |
719 | my $y = 0; |
662 | for (@{$self->{children}}) { |
720 | for (0 .. $#$children) { |
|
|
721 | my $child = $children->[$_]; |
|
|
722 | my $h = $h[$_]; |
663 | $_->move (0, $y); |
723 | $child->move (0, $y); |
664 | |
|
|
665 | if ($_ == $exp) { |
|
|
666 | $_->size_allocate ($w, $h - $oh); |
|
|
667 | $y += $h - $oh; |
|
|
668 | } else { |
|
|
669 | my ($cw, $h) = $_->size_request; |
|
|
670 | $_->size_allocate ($w, $h); |
724 | $child->size_allocate ($w, $h); |
|
|
725 | |
671 | $y += $h; |
726 | $y += $h; |
672 | } |
|
|
673 | } |
727 | } |
674 | } |
728 | } |
675 | |
729 | |
676 | ############################################################################# |
730 | ############################################################################# |
677 | |
731 | |
… | |
… | |
682 | use SDL::OpenGL; |
736 | use SDL::OpenGL; |
683 | |
737 | |
684 | sub new { |
738 | sub new { |
685 | my ($class, %arg) = @_; |
739 | my ($class, %arg) = @_; |
686 | |
740 | |
687 | # TODO: color, and make height, xyz etc. optional |
|
|
688 | my $self = $class->SUPER::new ( |
741 | my $self = $class->SUPER::new ( |
689 | color => [1, 1, 1], |
742 | fg => [1, 1, 1], |
690 | height => $::FONTSIZE, |
743 | height => $::FONTSIZE, |
691 | text => "", |
744 | text => "", |
692 | layout => new CFClient::Layout, |
745 | layout => new CFClient::Layout, |
693 | %arg |
746 | %arg |
694 | ); |
747 | ); |
… | |
… | |
696 | $self->set_text ($self->{text}); |
749 | $self->set_text ($self->{text}); |
697 | |
750 | |
698 | $self |
751 | $self |
699 | } |
752 | } |
700 | |
753 | |
|
|
754 | sub escape_text { |
|
|
755 | local $_ = $_[1]; |
|
|
756 | |
|
|
757 | s/&/&/g; |
|
|
758 | s/>/>/g; |
|
|
759 | s/</</g; |
|
|
760 | |
|
|
761 | $_[1] |
|
|
762 | } |
|
|
763 | |
701 | sub set_text { |
764 | sub set_text { |
702 | my ($self, $text) = @_; |
765 | my ($self, $text) = @_; |
703 | |
766 | |
704 | $self->{text} = $text; |
767 | $self->{text} = $text; |
705 | $self->{layout}->set_markup ($text); |
768 | $self->{layout}->set_markup ($text); |
706 | |
769 | |
707 | delete $self->{texture}; |
770 | delete $self->{texture}; |
|
|
771 | $self->update; |
708 | } |
772 | } |
709 | |
773 | |
710 | sub get_text { |
774 | sub get_text { |
711 | my ($self, $text) = @_; |
775 | my ($self, $text) = @_; |
712 | |
776 | |
… | |
… | |
732 | } |
796 | } |
733 | |
797 | |
734 | sub size_allocate { |
798 | sub size_allocate { |
735 | my ($self, $w, $h) = @_; |
799 | my ($self, $w, $h) = @_; |
736 | |
800 | |
|
|
801 | return unless $self->{w} != $w || $self->{h} != $h; |
|
|
802 | |
737 | $self->SUPER::size_allocate ($w, $h); |
803 | $self->SUPER::size_allocate ($w, $h); |
738 | delete $self->{texture}; |
804 | delete $self->{texture}; |
|
|
805 | } |
|
|
806 | |
|
|
807 | sub update { |
|
|
808 | my ($self) = @_; |
|
|
809 | |
|
|
810 | delete $self->{texture}; |
|
|
811 | $self->SUPER::update; |
739 | } |
812 | } |
740 | |
813 | |
741 | sub _draw { |
814 | sub _draw { |
742 | my ($self) = @_; |
815 | my ($self) = @_; |
743 | |
816 | |
… | |
… | |
749 | glEnable GL_BLEND; |
822 | glEnable GL_BLEND; |
750 | glEnable GL_TEXTURE_2D; |
823 | glEnable GL_TEXTURE_2D; |
751 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
824 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
752 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
825 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
753 | |
826 | |
754 | glColor @{$self->{color}}; |
827 | glColor @{$self->{fg}}; |
755 | |
828 | |
756 | $tex->draw_quad (0, 0); |
829 | $tex->draw_quad (0, 0); |
757 | |
830 | |
758 | glDisable GL_BLEND; |
831 | glDisable GL_BLEND; |
759 | glDisable GL_TEXTURE_2D; |
832 | glDisable GL_TEXTURE_2D; |
… | |
… | |
766 | our @ISA = CFClient::Widget::Label::; |
839 | our @ISA = CFClient::Widget::Label::; |
767 | |
840 | |
768 | use SDL; |
841 | use SDL; |
769 | use SDL::OpenGL; |
842 | use SDL::OpenGL; |
770 | |
843 | |
|
|
844 | sub new { |
|
|
845 | my $class = shift; |
|
|
846 | |
|
|
847 | $class->SUPER::new ( |
|
|
848 | fg => [1, 1, 1], |
|
|
849 | bg => [0, 0, 0, 0.4], |
|
|
850 | active_bg => [1, 1, 1], |
|
|
851 | active_fg => [0, 0, 0], |
|
|
852 | @_ |
|
|
853 | ) |
|
|
854 | } |
|
|
855 | |
|
|
856 | sub _set_text { |
|
|
857 | my ($self, $text) = @_; |
|
|
858 | |
|
|
859 | $self->{last_activity} = $::NOW; |
|
|
860 | |
|
|
861 | $self->{text} = $text; |
|
|
862 | $self->{layout}->set_width ($self->{w}); |
|
|
863 | $self->{layout}->set_markup ($self->escape_text ($text)); |
|
|
864 | |
|
|
865 | $text = substr $text, 0, $self->{cursor}; |
|
|
866 | utf8::encode $text; |
|
|
867 | |
|
|
868 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
|
|
869 | } |
|
|
870 | |
|
|
871 | sub size_request { |
|
|
872 | my ($self) = @_; |
|
|
873 | |
|
|
874 | my ($w, $h) = $self->SUPER::size_request; |
|
|
875 | |
|
|
876 | ($w + 1, $h) # add 1 for cursor |
|
|
877 | } |
|
|
878 | |
|
|
879 | sub size_allocate { |
|
|
880 | my ($self, $w, $h) = @_; |
|
|
881 | |
|
|
882 | return unless $self->{w} != $w || $self->{h} != $h; |
|
|
883 | |
|
|
884 | $self->SUPER::size_allocate ($w, $h); |
|
|
885 | |
|
|
886 | $self->_set_text ($self->{text}); |
|
|
887 | } |
|
|
888 | |
|
|
889 | sub set_text { |
|
|
890 | my ($self, $text) = @_; |
|
|
891 | |
|
|
892 | $self->{cursor} = length $text; |
|
|
893 | $self->_set_text ($text); |
|
|
894 | $self->update; |
|
|
895 | } |
|
|
896 | |
771 | sub key_down { |
897 | sub key_down { |
772 | my ($self, $ev) = @_; |
898 | my ($self, $ev) = @_; |
773 | |
899 | |
774 | my $mod = $ev->key_mod; |
900 | my $mod = $ev->key_mod; |
775 | my $sym = $ev->key_sym; |
901 | my $sym = $ev->key_sym; |
… | |
… | |
777 | my $uni = $ev->key_unicode; |
903 | my $uni = $ev->key_unicode; |
778 | |
904 | |
779 | my $text = $self->get_text; |
905 | my $text = $self->get_text; |
780 | |
906 | |
781 | if ($sym == SDLK_BACKSPACE) { |
907 | if ($sym == SDLK_BACKSPACE) { |
782 | substr $text, -1, 1, ''; |
908 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
|
|
909 | } elsif ($sym == SDLK_DELETE) { |
|
|
910 | substr $text, $self->{cursor}, 1, ""; |
|
|
911 | } elsif ($sym == SDLK_LEFT) { |
|
|
912 | --$self->{cursor} if $self->{cursor}; |
|
|
913 | } elsif ($sym == SDLK_RIGHT) { |
|
|
914 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
783 | } elsif ($uni) { |
915 | } elsif ($uni) { |
784 | $text .= chr $uni; |
916 | substr $text, $self->{cursor}++, 0, chr $uni; |
785 | } |
917 | } |
786 | |
918 | |
787 | $self->set_text ($text); |
919 | $self->_set_text ($text); |
|
|
920 | $self->update; |
|
|
921 | } |
|
|
922 | |
|
|
923 | sub focus_in { |
|
|
924 | my ($self) = @_; |
|
|
925 | |
|
|
926 | $self->{last_activity} = $::NOW; |
|
|
927 | |
|
|
928 | $self->SUPER::focus_in; |
788 | } |
929 | } |
789 | |
930 | |
790 | sub button_down { |
931 | sub button_down { |
791 | my ($self, $ev) = @_; |
932 | my ($self, $ev, $x, $y) = @_; |
792 | |
933 | |
793 | $self->focus_in; |
934 | $self->SUPER::button_down ($ev, $x, $y); |
|
|
935 | |
|
|
936 | my $idx = $self->{layout}->xy_to_index ($x, $y); |
|
|
937 | |
|
|
938 | # byte-index to char-index |
|
|
939 | my $text = $self->{layout}; |
|
|
940 | utf8::encode $text; |
|
|
941 | $self->{cursor} = length substr $text, 0, $idx; |
|
|
942 | |
|
|
943 | $self->_set_text ($self->{text}); |
|
|
944 | $self->update; |
794 | } |
945 | } |
795 | |
946 | |
796 | sub mouse_motion { |
947 | sub mouse_motion { |
797 | my ($self, $ev, $x, $y) = @_; |
948 | my ($self, $ev, $x, $y) = @_; |
798 | printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
949 | # printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
799 | } |
950 | } |
800 | |
951 | |
801 | sub _draw { |
952 | sub _draw { |
802 | my ($self) = @_; |
953 | my ($self) = @_; |
803 | |
954 | |
|
|
955 | local $self->{fg} = $self->{fg}; |
|
|
956 | |
804 | if ($FOCUS == $self) { |
957 | if ($FOCUS == $self) { |
805 | glColor 1, 1, 1; |
958 | glColor @{$self->{active_bg}}; |
|
|
959 | $self->{fg} = $self->{active_fg}; |
806 | } else { |
960 | } else { |
807 | glColor 0.7, 0.7, 0.7; |
961 | glColor @{$self->{bg}}; |
808 | } |
962 | } |
809 | |
963 | |
810 | glBegin GL_QUADS; |
964 | glBegin GL_QUADS; |
811 | glVertex 0 , 0; |
965 | glVertex 0 , 0; |
812 | glVertex 0 , $self->{h} - 1; |
966 | glVertex 0 , $self->{h}; |
813 | glVertex $self->{w} - 1, $self->{h} - 1; |
967 | glVertex $self->{w}, $self->{h}; |
814 | glVertex $self->{w} - 1, 0; |
968 | glVertex $self->{w}, 0; |
815 | glEnd; |
969 | glEnd; |
816 | |
970 | |
817 | $self->SUPER::_draw; |
971 | $self->SUPER::_draw; |
|
|
972 | |
|
|
973 | #TODO: force update every cursor change :( |
|
|
974 | if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { |
|
|
975 | glColor @{$self->{fg}}; |
|
|
976 | glBegin GL_LINES; |
|
|
977 | glVertex $self->{cur_x}, $self->{cur_y}; |
|
|
978 | glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; |
|
|
979 | glEnd; |
|
|
980 | } |
|
|
981 | } |
|
|
982 | |
|
|
983 | ############################################################################# |
|
|
984 | |
|
|
985 | package CFClient::Widget::Slider; |
|
|
986 | |
|
|
987 | use strict; |
|
|
988 | |
|
|
989 | use SDL::OpenGL; |
|
|
990 | use SDL::OpenGL::Constants; |
|
|
991 | |
|
|
992 | our @ISA = CFClient::Widget::DrawBG::; |
|
|
993 | |
|
|
994 | sub size_request { |
|
|
995 | my ($self) = @_; |
|
|
996 | |
|
|
997 | my $w = 20; |
|
|
998 | my $h = 10; |
|
|
999 | |
|
|
1000 | $self->{vertical} ? ($h, $w) : ($w, $h) |
|
|
1001 | } |
|
|
1002 | |
|
|
1003 | sub new { |
|
|
1004 | my $class = shift; |
|
|
1005 | |
|
|
1006 | # range [value, low, high, page] |
|
|
1007 | |
|
|
1008 | $class->SUPER::new ( |
|
|
1009 | fg => [1, 1, 1], |
|
|
1010 | active_fg => [0, 0, 0], |
|
|
1011 | range => [0, 0, 100, 10], |
|
|
1012 | vertical => 0, |
|
|
1013 | @_ |
|
|
1014 | ) |
|
|
1015 | } |
|
|
1016 | |
|
|
1017 | sub button_down { |
|
|
1018 | my ($self, $ev, $x, $y) = @_; |
|
|
1019 | |
|
|
1020 | $self->SUPER::button_down ($ev, $x, $y); |
|
|
1021 | $self->mouse_motion ($ev, $x, $y); |
|
|
1022 | } |
|
|
1023 | |
|
|
1024 | sub mouse_motion { |
|
|
1025 | my ($self, $ev, $x, $y) = @_; |
|
|
1026 | |
|
|
1027 | if ($GRAB == $self) { |
|
|
1028 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
|
|
1029 | |
|
|
1030 | $x = $x * ($hi - $lo) / $self->{w} + $lo; |
|
|
1031 | $x = $lo if $x < $lo; |
|
|
1032 | $x = $hi - $page if $x > $hi - $page; |
|
|
1033 | $self->{range}[0] = $x; |
|
|
1034 | |
|
|
1035 | $self->{changed}($x) if $self->{changed}; |
|
|
1036 | $self->update; |
|
|
1037 | } |
|
|
1038 | } |
|
|
1039 | |
|
|
1040 | sub _draw { |
|
|
1041 | my ($self) = @_; |
|
|
1042 | |
|
|
1043 | $self->SUPER::_draw (); |
|
|
1044 | |
|
|
1045 | glPushMatrix; |
|
|
1046 | |
|
|
1047 | my ($w, $h) = @$self{qw(w h)}; |
|
|
1048 | |
|
|
1049 | if ($self->{vertical}) { |
|
|
1050 | # draw a vertical slider like a rotated horizontal slider |
|
|
1051 | |
|
|
1052 | glTranslate 0, $self->{w}; |
|
|
1053 | glRotate 90, 0, 0, 1; |
|
|
1054 | |
|
|
1055 | ($w, $h) = ($h, $w); |
|
|
1056 | } |
|
|
1057 | |
|
|
1058 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
|
|
1059 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
|
|
1060 | |
|
|
1061 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
|
|
1062 | |
|
|
1063 | $page = int $page * $w / ($hi - $lo); |
|
|
1064 | $value = int +($value - $lo) * $w / ($hi - $lo); |
|
|
1065 | |
|
|
1066 | $w -= $page; |
|
|
1067 | $page &= ~1; |
|
|
1068 | glTranslate $page * 0.5, 0, 0; |
|
|
1069 | |
|
|
1070 | glColor @$fg; |
|
|
1071 | glBegin GL_LINES; |
|
|
1072 | glVertex 0, 0; glVertex 0, $h; |
|
|
1073 | glVertex $w - 1, 0; glVertex $w - 1, $h; |
|
|
1074 | glVertex 0, $h * 0.5; glVertex $w, $h * 0.5; |
|
|
1075 | glEnd; |
|
|
1076 | |
|
|
1077 | my $knob_a = $value - $page * 0.5; |
|
|
1078 | my $knob_b = $value + $page * 0.5; |
|
|
1079 | |
|
|
1080 | glBegin GL_QUADS; |
|
|
1081 | glColor @$fg; |
|
|
1082 | glVertex $knob_a, 0; |
|
|
1083 | glVertex $knob_a, $h; |
|
|
1084 | glVertex $knob_b, $h; |
|
|
1085 | glVertex $knob_b, 0; |
|
|
1086 | |
|
|
1087 | if ($knob_a < $knob_b - 2) { |
|
|
1088 | glColor @$bg; |
|
|
1089 | glVertex $knob_a + 1, 1; |
|
|
1090 | glVertex $knob_a + 1, $h - 1; |
|
|
1091 | glVertex $knob_b - 1, $h - 1; |
|
|
1092 | glVertex $knob_b - 1, 1; |
|
|
1093 | } |
|
|
1094 | glEnd; |
|
|
1095 | |
|
|
1096 | glPopMatrix; |
818 | } |
1097 | } |
819 | |
1098 | |
820 | ############################################################################# |
1099 | ############################################################################# |
821 | |
1100 | |
822 | package CFClient::Widget::MapWidget; |
1101 | package CFClient::Widget::MapWidget; |