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.71 by root, Tue Apr 11 17:39:39 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
1032 $x = $x * ($hi - $lo) / $w + $lo; 1058 $x = $x * ($hi - $lo) / $w + $lo;
1033 $x = $lo if $x < $lo; 1059 $x = $lo if $x < $lo;
1034 $x = $hi - $page if $x > $hi - $page; 1060 $x = $hi - $page if $x > $hi - $page;
1035 $self->{range}[0] = $x; 1061 $self->{range}[0] = $x;
1036 1062
1037 $self->{changed}($x) if $self->{changed}; 1063 $self->emit (changed => $x);
1038 $self->update; 1064 $self->update;
1039 } 1065 }
1040} 1066}
1041 1067
1042sub _draw { 1068sub _draw {
1043 my ($self) = @_; 1069 my ($self) = @_;
1044 1070
1045 $self->SUPER::_draw (); 1071 $self->SUPER::_draw ();
1046
1047 glPushMatrix;
1048 1072
1049 my ($w, $h) = @$self{qw(w h)}; 1073 my ($w, $h) = @$self{qw(w h)};
1050 1074
1051 if ($self->{vertical}) { 1075 if ($self->{vertical}) {
1052 # draw a vertical slider like a rotated horizontal slider 1076 # draw a vertical slider like a rotated horizontal slider
1092 glVertex $knob_a + 1, $h - 1; 1116 glVertex $knob_a + 1, $h - 1;
1093 glVertex $knob_b - 1, $h - 1; 1117 glVertex $knob_b - 1, $h - 1;
1094 glVertex $knob_b - 1, 1; 1118 glVertex $knob_b - 1, 1;
1095 } 1119 }
1096 glEnd; 1120 glEnd;
1097
1098 glPopMatrix;
1099} 1121}
1100 1122
1101############################################################################# 1123#############################################################################
1102 1124
1103package CFClient::Widget::MapWidget; 1125package CFClient::Widget::MapWidget;
1192 } 1214 }
1193 1215
1194 for my $num (grep $_, @$cell[1,2,3]) { 1216 for my $num (grep $_, @$cell[1,2,3]) {
1195 my $tex = $::CONN->{face}[$num]{texture} || next; 1217 my $tex = $::CONN->{face}[$num]{texture} || next;
1196 1218
1197 my $w = $tex->{width}; 1219 my ($w, $h) = @$tex{qw(w h)};
1198 my $h = $tex->{height};
1199 1220
1200 $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);
1201 } 1222 }
1202 } 1223 }
1203 } 1224 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines