… | |
… | |
155 | return unless $self->{h} && $self->{w}; |
155 | return unless $self->{h} && $self->{w}; |
156 | |
156 | |
157 | glPushMatrix; |
157 | glPushMatrix; |
158 | glTranslate $self->{x}, $self->{y}, 0; |
158 | glTranslate $self->{x}, $self->{y}, 0; |
159 | $self->_draw; |
159 | $self->_draw; |
|
|
160 | glPopMatrix; |
|
|
161 | |
160 | if ($self == $HOVER) { |
162 | if ($self == $HOVER) { |
|
|
163 | my ($x, $y) = @$self->{qw(x y)}; |
|
|
164 | |
161 | glColor 1, 1, 1, 0.4; |
165 | glColor 1, 1, 1, 0.1; |
162 | glEnable GL_BLEND; |
166 | glEnable GL_BLEND; |
163 | glBegin GL_QUADS; |
167 | glBegin GL_QUADS; |
164 | glVertex 0 , 0; |
168 | glVertex $x , $y; |
165 | glVertex $self->{w}, 0; |
169 | glVertex $x + $self->{w}, $y; |
166 | glVertex $self->{w}, $self->{h}; |
170 | glVertex $x + $self->{w}, $y + $self->{h}; |
167 | glVertex 0 , $self->{h}; |
171 | glVertex $x , $y + $self->{h}; |
168 | glEnd; |
172 | glEnd; |
169 | glDisable GL_BLEND; |
173 | glDisable GL_BLEND; |
170 | } |
174 | } |
171 | glPopMatrix; |
|
|
172 | } |
175 | } |
173 | |
176 | |
174 | sub _draw { |
177 | sub _draw { |
175 | my ($self) = @_; |
178 | my ($self) = @_; |
176 | |
179 | |
… | |
… | |
216 | |
219 | |
217 | $self->{parent}->update |
220 | $self->{parent}->update |
218 | if $self->{parent}; |
221 | if $self->{parent}; |
219 | } |
222 | } |
220 | |
223 | |
|
|
224 | sub connect { |
|
|
225 | my ($self, $signal, $cb) = @_; |
|
|
226 | |
|
|
227 | push @{ $self->{cb}{$signal} }, $cb; |
|
|
228 | } |
|
|
229 | |
|
|
230 | sub emit { |
|
|
231 | my ($self, $signal, @args) = @_; |
|
|
232 | |
|
|
233 | $_->($self, @args) |
|
|
234 | for @{$self->{cb}{$signal} || []}; |
|
|
235 | } |
|
|
236 | |
221 | sub DESTROY { |
237 | sub DESTROY { |
222 | my ($self) = @_; |
238 | my ($self) = @_; |
223 | |
239 | |
224 | #$self->deactivate; |
240 | #$self->deactivate; |
225 | } |
241 | } |
… | |
… | |
504 | sub size_request { |
520 | sub size_request { |
505 | my ($self) = @_; |
521 | my ($self) = @_; |
506 | |
522 | |
507 | my ($w, $h) = $self->SUPER::size_request; |
523 | my ($w, $h) = $self->SUPER::size_request; |
508 | |
524 | |
509 | $h += $tex[1]->{height}; |
525 | $h += $tex[1]->{h}; |
510 | $h += $tex[4]->{height}; |
526 | $h += $tex[4]->{h}; |
511 | $w += $tex[2]->{width}; |
527 | $w += $tex[2]->{w}; |
512 | $w += $tex[3]->{width}; |
528 | $w += $tex[3]->{w}; |
513 | |
529 | |
514 | ($w, $h) |
530 | ($w, $h) |
515 | } |
531 | } |
516 | |
532 | |
517 | sub size_allocate { |
533 | sub size_allocate { |
… | |
… | |
519 | |
535 | |
520 | return unless $self->{w} != $w || $self->{h} != $h; |
536 | return unless $self->{w} != $w || $self->{h} != $h; |
521 | |
537 | |
522 | $self->SUPER::size_allocate ($w, $h); |
538 | $self->SUPER::size_allocate ($w, $h); |
523 | |
539 | |
524 | $h -= $tex[1]->{height}; |
540 | $h -= $tex[1]->{h}; |
525 | $h -= $tex[4]->{height}; |
541 | $h -= $tex[4]->{h}; |
526 | $w -= $tex[2]->{width}; |
542 | $w -= $tex[2]->{w}; |
527 | $w -= $tex[3]->{width}; |
543 | $w -= $tex[3]->{w}; |
528 | |
544 | |
529 | $h = $h < 0 ? 0 : $h; |
545 | $h = $h < 0 ? 0 : $h; |
530 | $w = $w < 0 ? 0 : $w; |
546 | $w = $w < 0 ? 0 : $w; |
531 | |
547 | |
532 | my $child = $self->child; |
548 | my $child = $self->child; |
533 | |
549 | |
534 | $child->size_allocate ($w, $h); |
550 | $child->size_allocate ($w, $h); |
535 | $child->move ($tex[3]->{width}, $tex[1]->{height}); |
551 | $child->move ($tex[3]->{w}, $tex[1]->{h}); |
536 | } |
552 | } |
537 | |
553 | |
538 | sub _draw { |
554 | sub _draw { |
539 | my ($self) = @_; |
555 | my ($self) = @_; |
540 | |
556 | |
… | |
… | |
545 | glEnable GL_TEXTURE_2D; |
561 | glEnable GL_TEXTURE_2D; |
546 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
562 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
547 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
563 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
548 | |
564 | |
549 | my $top = $tex[1]; |
565 | my $top = $tex[1]; |
550 | $top->draw_quad (0, 0, $w, $top->{height}); |
566 | $top->draw_quad (0, 0, $w, $top->{h}); |
551 | |
567 | |
552 | my $left = $tex[3]; |
568 | my $left = $tex[3]; |
553 | $left->draw_quad (0, $top->{height}, $left->{width}, $ch); |
569 | $left->draw_quad (0, $top->{h}, $left->{w}, $ch); |
554 | |
570 | |
555 | my $right = $tex[2]; |
571 | my $right = $tex[2]; |
556 | $right->draw_quad ($w - $right->{width}, $top->{height}, $right->{width}, $ch); |
572 | $right->draw_quad ($w - $right->{w}, $top->{h}, $right->{w}, $ch); |
557 | |
573 | |
558 | my $bottom = $tex[4]; |
574 | my $bottom = $tex[4]; |
559 | $bottom->draw_quad (0, $h - $bottom->{height}, $w, $bottom->{height}); |
575 | $bottom->draw_quad (0, $h - $bottom->{h}, $w, $bottom->{h}); |
560 | |
576 | |
561 | my $bg = $tex[0]; |
577 | my $bg = $tex[0]; |
562 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
578 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
563 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
579 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
564 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
580 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
565 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
581 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
566 | |
582 | |
567 | my $rep_x = $cw / $bg->{width}; |
583 | my $rep_x = $cw / $bg->{w}; |
568 | my $rep_y = $ch / $bg->{height}; |
584 | my $rep_y = $ch / $bg->{h}; |
569 | |
585 | |
570 | $bg->draw_quad ($left->{width}, $top->{height}, $cw, $ch); |
586 | $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); |
571 | |
587 | |
572 | glDisable GL_BLEND; |
588 | glDisable GL_BLEND; |
573 | glDisable GL_TEXTURE_2D; |
589 | glDisable GL_TEXTURE_2D; |
574 | |
590 | |
575 | $self->child->draw; |
591 | $self->child->draw; |
… | |
… | |
578 | |
594 | |
579 | ############################################################################# |
595 | ############################################################################# |
580 | |
596 | |
581 | package CFClient::Widget::Table; |
597 | package CFClient::Widget::Table; |
582 | |
598 | |
583 | our @ISA = CFClient::Widget::Bin::; |
599 | our @ISA = CFClient::Widget::; |
584 | |
600 | |
585 | use SDL::OpenGL; |
601 | use SDL::OpenGL; |
586 | |
602 | |
587 | sub add { |
603 | sub add { |
588 | my ($self, $x, $y, $chld) = @_; |
604 | my ($self, $x, $y, $chld) = @_; |
… | |
… | |
740 | |
756 | |
741 | my $self = $class->SUPER::new ( |
757 | my $self = $class->SUPER::new ( |
742 | fg => [1, 1, 1], |
758 | fg => [1, 1, 1], |
743 | height => $::FONTSIZE, |
759 | height => $::FONTSIZE, |
744 | text => "", |
760 | text => "", |
|
|
761 | align => -1, |
745 | layout => new CFClient::Layout, |
762 | layout => new CFClient::Layout, |
746 | %arg |
763 | %arg |
747 | ); |
764 | ); |
748 | |
765 | |
749 | $self->set_text ($self->{text}); |
766 | $self->set_text ($self->{text}); |
… | |
… | |
781 | my ($self) = @_; |
798 | my ($self) = @_; |
782 | |
799 | |
783 | $self->{layout}->set_width; |
800 | $self->{layout}->set_width; |
784 | $self->{layout}->set_height ($self->{height}); |
801 | $self->{layout}->set_height ($self->{height}); |
785 | $self->{layout}->size |
802 | $self->{layout}->size |
786 | # if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
803 | # if ($self->{texture}{w} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
787 | # ( |
804 | # ( |
788 | # $self->{texture}{width}, |
805 | # $self->{texture}{w}, |
789 | # $self->{texture}{height}, |
806 | # $self->{texture}{h}, |
790 | # ) |
807 | # ) |
791 | # } else { |
808 | # } else { |
792 | # my ($w, $h, $data) = CFClient::font_render "Yy", $self->{height}; |
809 | # my ($w, $h, $data) = CFClient::font_render "Yy", $self->{h}; |
793 | # |
810 | # |
794 | # ($w, $h) |
811 | # ($w, $h) |
795 | # } |
812 | # } |
796 | } |
813 | } |
797 | |
814 | |
… | |
… | |
824 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
841 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
825 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
842 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
826 | |
843 | |
827 | glColor @{$self->{fg}}; |
844 | glColor @{$self->{fg}}; |
828 | |
845 | |
|
|
846 | my $x = |
|
|
847 | $self->{align} < 0 ? 0 |
|
|
848 | : $self->{align} > 0 ? $self->{w} - $self->{texture}{w} |
|
|
849 | : ($self->{w} + $self->{texture}{w}) * 0.5; |
|
|
850 | |
829 | $tex->draw_quad (0, 0); |
851 | $tex->draw_quad ($x, 0); |
830 | |
852 | |
831 | glDisable GL_BLEND; |
853 | glDisable GL_BLEND; |
832 | glDisable GL_TEXTURE_2D; |
854 | glDisable GL_TEXTURE_2D; |
833 | } |
855 | } |
834 | |
856 | |
… | |
… | |
858 | |
880 | |
859 | $self->{last_activity} = $::NOW; |
881 | $self->{last_activity} = $::NOW; |
860 | |
882 | |
861 | $self->{text} = $text; |
883 | $self->{text} = $text; |
862 | $self->{layout}->set_width ($self->{w}); |
884 | $self->{layout}->set_width ($self->{w}); |
|
|
885 | |
|
|
886 | $text =~ s/./*/g if $self->{hidden}; |
|
|
887 | |
|
|
888 | |
863 | $self->{layout}->set_markup ($self->escape_text ($text)); |
889 | $self->{layout}->set_markup ($self->escape_text ($text)); |
864 | |
890 | |
865 | $text = substr $text, 0, $self->{cursor}; |
891 | $text = substr $text, 0, $self->{cursor}; |
866 | utf8::encode $text; |
892 | utf8::encode $text; |
867 | |
893 | |
… | |
… | |
992 | our @ISA = CFClient::Widget::DrawBG::; |
1018 | our @ISA = CFClient::Widget::DrawBG::; |
993 | |
1019 | |
994 | sub size_request { |
1020 | sub size_request { |
995 | my ($self) = @_; |
1021 | my ($self) = @_; |
996 | |
1022 | |
997 | my $w = 20; |
1023 | my $w = 50; |
998 | my $h = 10; |
1024 | my $h = 10; |
999 | |
1025 | |
1000 | $self->{vertical} ? ($h, $w) : ($w, $h) |
1026 | $self->{vertical} ? ($h, $w) : ($w, $h) |
1001 | } |
1027 | } |
1002 | |
1028 | |
… | |
… | |
1025 | my ($self, $ev, $x, $y) = @_; |
1051 | my ($self, $ev, $x, $y) = @_; |
1026 | |
1052 | |
1027 | if ($GRAB == $self) { |
1053 | if ($GRAB == $self) { |
1028 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
1054 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
1029 | |
1055 | |
|
|
1056 | my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); |
|
|
1057 | |
1030 | $x = $x * ($hi - $lo) / $self->{w} + $lo; |
1058 | $x = $x * ($hi - $lo) / $w + $lo; |
1031 | $x = $lo if $x < $lo; |
1059 | $x = $lo if $x < $lo; |
1032 | $x = $hi - $page if $x > $hi - $page; |
1060 | $x = $hi - $page if $x > $hi - $page; |
1033 | $self->{range}[0] = $x; |
1061 | $self->{range}[0] = $x; |
1034 | |
1062 | |
1035 | $self->{changed}($x) if $self->{changed}; |
1063 | $self->emit (changed => $x); |
1036 | $self->update; |
1064 | $self->update; |
1037 | } |
1065 | } |
1038 | } |
1066 | } |
1039 | |
1067 | |
1040 | sub _draw { |
1068 | sub _draw { |
1041 | my ($self) = @_; |
1069 | my ($self) = @_; |
1042 | |
1070 | |
1043 | $self->SUPER::_draw (); |
1071 | $self->SUPER::_draw (); |
1044 | |
|
|
1045 | glPushMatrix; |
|
|
1046 | |
1072 | |
1047 | my ($w, $h) = @$self{qw(w h)}; |
1073 | my ($w, $h) = @$self{qw(w h)}; |
1048 | |
1074 | |
1049 | if ($self->{vertical}) { |
1075 | if ($self->{vertical}) { |
1050 | # draw a vertical slider like a rotated horizontal slider |
1076 | # draw a vertical slider like a rotated horizontal slider |
1051 | |
1077 | |
1052 | glTranslate 0, $self->{w}; |
|
|
1053 | glRotate 90, 0, 0, 1; |
1078 | glRotate 90, 0, 0, 1; |
|
|
1079 | glTranslate 0, -$self->{w}, 0; |
1054 | |
1080 | |
1055 | ($w, $h) = ($h, $w); |
1081 | ($w, $h) = ($h, $w); |
1056 | } |
1082 | } |
1057 | |
1083 | |
1058 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
1084 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
… | |
… | |
1090 | glVertex $knob_a + 1, $h - 1; |
1116 | glVertex $knob_a + 1, $h - 1; |
1091 | glVertex $knob_b - 1, $h - 1; |
1117 | glVertex $knob_b - 1, $h - 1; |
1092 | glVertex $knob_b - 1, 1; |
1118 | glVertex $knob_b - 1, 1; |
1093 | } |
1119 | } |
1094 | glEnd; |
1120 | glEnd; |
1095 | |
|
|
1096 | glPopMatrix; |
|
|
1097 | } |
1121 | } |
1098 | |
1122 | |
1099 | ############################################################################# |
1123 | ############################################################################# |
1100 | |
1124 | |
1101 | package CFClient::Widget::MapWidget; |
1125 | package CFClient::Widget::MapWidget; |
… | |
… | |
1190 | } |
1214 | } |
1191 | |
1215 | |
1192 | for my $num (grep $_, @$cell[1,2,3]) { |
1216 | for my $num (grep $_, @$cell[1,2,3]) { |
1193 | my $tex = $::CONN->{face}[$num]{texture} || next; |
1217 | my $tex = $::CONN->{face}[$num]{texture} || next; |
1194 | |
1218 | |
1195 | my $w = $tex->{width}; |
1219 | my ($w, $h) = @$tex{qw(w h)}; |
1196 | my $h = $tex->{height}; |
|
|
1197 | |
1220 | |
1198 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
1221 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
1199 | } |
1222 | } |
1200 | } |
1223 | } |
1201 | } |
1224 | } |