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.68 by root, Tue Apr 11 17:02:36 2006 UTC vs.
Revision 1.72 by root, Tue Apr 11 18:00:45 2006 UTC

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
174sub _draw { 177sub _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
224sub connect {
225 my ($self, $signal, $cb) = @_;
226
227 push @{ $self->{cb}{$signal} }, $cb;
228}
229
230sub emit {
231 my ($self, $signal, @args) = @_;
232
233 $_->($self, @args)
234 for @{$self->{cb}{$signal} || []};
235}
236
221sub DESTROY { 237sub DESTROY {
222 my ($self) = @_; 238 my ($self) = @_;
223 239
224 #$self->deactivate; 240 #$self->deactivate;
225} 241}
504sub size_request { 520sub 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
517sub size_allocate { 533sub 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
538sub _draw { 554sub _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
581package CFClient::Widget::Table; 597package CFClient::Widget::Table;
582 598
583our @ISA = CFClient::Widget::Bin::; 599our @ISA = CFClient::Widget::;
584 600
585use SDL::OpenGL; 601use SDL::OpenGL;
586 602
587sub add { 603sub 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
992our @ISA = CFClient::Widget::DrawBG::; 1018our @ISA = CFClient::Widget::DrawBG::;
993 1019
994sub size_request { 1020sub size_request {
995 my ($self) = @_; 1021 my ($self) = @_;
996 1022
997 my $w = 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
1007 1033
1008 $class->SUPER::new ( 1034 $class->SUPER::new (
1009 fg => [1, 1, 1], 1035 fg => [1, 1, 1],
1010 active_fg => [0, 0, 0], 1036 active_fg => [0, 0, 0],
1011 range => [0, 0, 100, 10], 1037 range => [0, 0, 100, 10],
1012 vertical => 0, 1038 vertical => 1,
1013 @_ 1039 @_
1014 ) 1040 )
1041}
1042
1043sub button_down {
1044 my ($self, $ev, $x, $y) = @_;
1045
1046 $self->SUPER::button_down ($ev, $x, $y);
1047 $self->mouse_motion ($ev, $x, $y);
1048}
1049
1050sub mouse_motion {
1051 my ($self, $ev, $x, $y) = @_;
1052
1053 if ($GRAB == $self) {
1054 my ($value, $lo, $hi, $page) = @{$self->{range}};
1055
1056 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w});
1057
1058 $x = $x * ($hi - $lo) / $w + $lo;
1059 $x = $lo if $x < $lo;
1060 $x = $hi - $page if $x > $hi - $page;
1061 $self->{range}[0] = $x;
1062
1063 $self->emit (changed => $x);
1064 $self->update;
1065 }
1015} 1066}
1016 1067
1017sub _draw { 1068sub _draw {
1018 my ($self) = @_; 1069 my ($self) = @_;
1019 1070
1022 my ($w, $h) = @$self{qw(w h)}; 1073 my ($w, $h) = @$self{qw(w h)};
1023 1074
1024 if ($self->{vertical}) { 1075 if ($self->{vertical}) {
1025 # draw a vertical slider like a rotated horizontal slider 1076 # draw a vertical slider like a rotated horizontal slider
1026 1077
1027 glTranslate 0, $self->{w};
1028 glRotate 90, 0, 0, 1; 1078 glRotate 90, 0, 0, 1;
1079 glTranslate 0, -$self->{w}, 0;
1029 1080
1030 ($w, $h) = ($h, $w); 1081 ($w, $h) = ($h, $w);
1031 } 1082 }
1032 1083
1033 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 1084 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
1034 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 1085 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
1086
1087 my ($value, $lo, $hi, $page) = @{$self->{range}};
1088
1089 $page = int $page * $w / ($hi - $lo);
1090 $value = int +($value - $lo) * $w / ($hi - $lo);
1091
1092 $w -= $page;
1093 $page &= ~1;
1094 glTranslate $page * 0.5, 0, 0;
1035 1095
1036 glColor @$fg; 1096 glColor @$fg;
1037 glBegin GL_LINES; 1097 glBegin GL_LINES;
1038 glVertex 0, 0; glVertex 0, $h; 1098 glVertex 0, 0; glVertex 0, $h;
1039 glVertex $w - 1, 0; glVertex $w - 1, $h; 1099 glVertex $w - 1, 0; glVertex $w - 1, $h;
1040 glVertex 0, $h * 0.5; glVertex $w, $h * 0.5; 1100 glVertex 0, $h * 0.5; glVertex $w, $h * 0.5;
1041 glEnd; 1101 glEnd;
1102
1103 my $knob_a = $value - $page * 0.5;
1104 my $knob_b = $value + $page * 0.5;
1105
1106 glBegin GL_QUADS;
1107 glColor @$fg;
1108 glVertex $knob_a, 0;
1109 glVertex $knob_a, $h;
1110 glVertex $knob_b, $h;
1111 glVertex $knob_b, 0;
1112
1113 if ($knob_a < $knob_b - 2) {
1114 glColor @$bg;
1115 glVertex $knob_a + 1, 1;
1116 glVertex $knob_a + 1, $h - 1;
1117 glVertex $knob_b - 1, $h - 1;
1118 glVertex $knob_b - 1, 1;
1119 }
1120 glEnd;
1042} 1121}
1043 1122
1044############################################################################# 1123#############################################################################
1045 1124
1046package CFClient::Widget::MapWidget; 1125package CFClient::Widget::MapWidget;
1135 } 1214 }
1136 1215
1137 for my $num (grep $_, @$cell[1,2,3]) { 1216 for my $num (grep $_, @$cell[1,2,3]) {
1138 my $tex = $::CONN->{face}[$num]{texture} || next; 1217 my $tex = $::CONN->{face}[$num]{texture} || next;
1139 1218
1140 my $w = $tex->{width}; 1219 my ($w, $h) = @$tex{qw(w h)};
1141 my $h = $tex->{height};
1142 1220
1143 $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);
1144 } 1222 }
1145 } 1223 }
1146 } 1224 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines