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.69 by root, Tue Apr 11 17:32:14 2006 UTC vs.
Revision 1.74 by root, Tue Apr 11 19:31:18 2006 UTC

1package CFClient::Widget; 1package CFClient::UI;
2 2
3use strict; 3use strict;
4 4
5use Scalar::Util; 5use Scalar::Util ();
6 6use List::Util ();
7use SDL::OpenGL;
8use SDL::OpenGL::Constants;
9 7
10use CFClient; 8use CFClient;
11 9
12our ($FOCUS, $HOVER, $GRAB); # various widgets 10our ($FOCUS, $HOVER, $GRAB); # various widgets
13 11
69 $HOVER->update if $HOVER; 67 $HOVER->update if $HOVER;
70 } 68 }
71 69
72 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; 70 $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER;
73} 71}
72
73#############################################################################
74
75package CFClient::UI::Base;
76
77use strict;
78
79use SDL::OpenGL;
74 80
75sub new { 81sub new {
76 my $class = shift; 82 my $class = shift;
77 83
78 bless { 84 bless {
155 return unless $self->{h} && $self->{w}; 161 return unless $self->{h} && $self->{w};
156 162
157 glPushMatrix; 163 glPushMatrix;
158 glTranslate $self->{x}, $self->{y}, 0; 164 glTranslate $self->{x}, $self->{y}, 0;
159 $self->_draw; 165 $self->_draw;
166 glPopMatrix;
167
160 if ($self == $HOVER) { 168 if ($self == $HOVER) {
169 my ($x, $y) = @$self{qw(x y)};
170
161 glColor 1, 1, 1, 0.4; 171 glColor 1, 1, 1, 0.1;
162 glEnable GL_BLEND; 172 glEnable GL_BLEND;
173 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
163 glBegin GL_QUADS; 174 glBegin GL_QUADS;
164 glVertex 0 , 0; 175 glVertex $x , $y;
165 glVertex $self->{w}, 0; 176 glVertex $x + $self->{w}, $y;
166 glVertex $self->{w}, $self->{h}; 177 glVertex $x + $self->{w}, $y + $self->{h};
167 glVertex 0 , $self->{h}; 178 glVertex $x , $y + $self->{h};
168 glEnd; 179 glEnd;
169 glDisable GL_BLEND; 180 glDisable GL_BLEND;
170 } 181 }
171 glPopMatrix;
172} 182}
173 183
174sub _draw { 184sub _draw {
175 my ($self) = @_; 185 my ($self) = @_;
176 186
216 226
217 $self->{parent}->update 227 $self->{parent}->update
218 if $self->{parent}; 228 if $self->{parent};
219} 229}
220 230
231sub connect {
232 my ($self, $signal, $cb) = @_;
233
234 push @{ $self->{cb}{$signal} }, $cb;
235}
236
237sub emit {
238 my ($self, $signal, @args) = @_;
239
240 $_->($self, @args)
241 for @{$self->{cb}{$signal} || []};
242}
243
221sub DESTROY { 244sub DESTROY {
222 my ($self) = @_; 245 my ($self) = @_;
223 246
224 #$self->deactivate; 247 #$self->deactivate;
225} 248}
226 249
227############################################################################# 250#############################################################################
228 251
229package CFClient::Widget::DrawBG; 252package CFClient::UI::DrawBG;
230 253
231our @ISA = CFClient::Widget::; 254our @ISA = CFClient::UI::Base::;
232 255
233use strict; 256use strict;
234use SDL::OpenGL; 257use SDL::OpenGL;
235 258
236sub new { 259sub new {
259 glEnd; 282 glEnd;
260} 283}
261 284
262############################################################################# 285#############################################################################
263 286
264package CFClient::Widget::Empty; 287package CFClient::UI::Empty;
265 288
266our @ISA = CFClient::Widget::; 289our @ISA = CFClient::UI::Base::;
267 290
268sub size_request { 291sub size_request {
269 (0, 0) 292 (0, 0)
270} 293}
271 294
272sub draw { } 295sub draw { }
273 296
274############################################################################# 297#############################################################################
275 298
276package CFClient::Widget::Container; 299package CFClient::UI::Container;
277 300
278our @ISA = CFClient::Widget::; 301our @ISA = CFClient::UI::Base::;
279 302
280sub new { 303sub new {
281 my ($class, %arg) = @_; 304 my ($class, %arg) = @_;
282 305
283 my $children = delete $arg{children} || []; 306 my $children = delete $arg{children} || [];
333 $_->draw for @{$self->{children}}; 356 $_->draw for @{$self->{children}};
334} 357}
335 358
336############################################################################# 359#############################################################################
337 360
338package CFClient::Widget::Bin; 361package CFClient::UI::Bin;
339 362
340our @ISA = CFClient::Widget::Container::; 363our @ISA = CFClient::UI::Container::;
341 364
342sub new { 365sub new {
343 my ($class, %arg) = @_; 366 my ($class, %arg) = @_;
344 367
345 my $child = (delete $arg{child}) || new CFClient::Widget::Empty::; 368 my $child = (delete $arg{child}) || new CFClient::UI::Empty::;
346 369
347 $class->SUPER::new (children => [$child], %arg) 370 $class->SUPER::new (children => [$child], %arg)
348} 371}
349 372
350sub add { 373sub add {
358sub remove { 381sub remove {
359 my ($self, $widget) = @_; 382 my ($self, $widget) = @_;
360 383
361 $self->SUPER::remove ($widget); 384 $self->SUPER::remove ($widget);
362 385
363 $self->{children} = [new CFClient::Widget::Empty] 386 $self->{children} = [new CFClient::UI::Empty]
364 unless @{$self->{children}}; 387 unless @{$self->{children}};
365} 388}
366 389
367sub child { $_[0]->{children}[0] } 390sub child { $_[0]->{children}[0] }
368 391
379 $self->{children}[0]->size_allocate ($w, $h); 402 $self->{children}[0]->size_allocate ($w, $h);
380} 403}
381 404
382############################################################################# 405#############################################################################
383 406
384package CFClient::Widget::Window; 407package CFClient::UI::Window;
385 408
386our @ISA = CFClient::Widget::Bin::; 409our @ISA = CFClient::UI::Bin::;
387 410
388use SDL::OpenGL; 411use SDL::OpenGL;
389 412
390sub new { 413sub new {
391 my ($class, %arg) = @_; 414 my ($class, %arg) = @_;
430 453
431 my $tex = $self->{texture} 454 my $tex = $self->{texture}
432 or return; 455 or return;
433 456
434 glEnable GL_BLEND; 457 glEnable GL_BLEND;
458 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
435 glEnable GL_TEXTURE_2D; 459 glEnable GL_TEXTURE_2D;
436 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 460 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
437 461
438 $tex->draw_quad (0, 0, $w, $h); 462 $tex->draw_quad (0, 0, $w, $h);
439 463
441 glDisable GL_TEXTURE_2D; 465 glDisable GL_TEXTURE_2D;
442} 466}
443 467
444############################################################################# 468#############################################################################
445 469
446package CFClient::Widget::Frame; 470package CFClient::UI::Frame;
447 471
448our @ISA = CFClient::Widget::Bin::; 472our @ISA = CFClient::UI::Bin::;
449 473
450use SDL::OpenGL; 474use SDL::OpenGL;
451 475
452sub size_request { 476sub size_request {
453 my ($self) = @_; 477 my ($self) = @_;
489 $chld->draw; 513 $chld->draw;
490} 514}
491 515
492############################################################################# 516#############################################################################
493 517
494package CFClient::Widget::FancyFrame; 518package CFClient::UI::FancyFrame;
495 519
496our @ISA = CFClient::Widget::Bin::; 520our @ISA = CFClient::UI::Bin::;
497 521
498use SDL::OpenGL; 522use SDL::OpenGL;
499 523
500my @tex = 524my @tex =
501 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 525 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
504sub size_request { 528sub size_request {
505 my ($self) = @_; 529 my ($self) = @_;
506 530
507 my ($w, $h) = $self->SUPER::size_request; 531 my ($w, $h) = $self->SUPER::size_request;
508 532
509 $h += $tex[1]->{height}; 533 $h += $tex[1]->{h};
510 $h += $tex[4]->{height}; 534 $h += $tex[4]->{h};
511 $w += $tex[2]->{width}; 535 $w += $tex[2]->{w};
512 $w += $tex[3]->{width}; 536 $w += $tex[3]->{w};
513 537
514 ($w, $h) 538 ($w, $h)
515} 539}
516 540
517sub size_allocate { 541sub size_allocate {
519 543
520 return unless $self->{w} != $w || $self->{h} != $h; 544 return unless $self->{w} != $w || $self->{h} != $h;
521 545
522 $self->SUPER::size_allocate ($w, $h); 546 $self->SUPER::size_allocate ($w, $h);
523 547
524 $h -= $tex[1]->{height}; 548 $h -= $tex[1]->{h};
525 $h -= $tex[4]->{height}; 549 $h -= $tex[4]->{h};
526 $w -= $tex[2]->{width}; 550 $w -= $tex[2]->{w};
527 $w -= $tex[3]->{width}; 551 $w -= $tex[3]->{w};
528 552
529 $h = $h < 0 ? 0 : $h; 553 $h = $h < 0 ? 0 : $h;
530 $w = $w < 0 ? 0 : $w; 554 $w = $w < 0 ? 0 : $w;
531 555
532 my $child = $self->child; 556 my $child = $self->child;
533 557
534 $child->size_allocate ($w, $h); 558 $child->size_allocate ($w, $h);
535 $child->move ($tex[3]->{width}, $tex[1]->{height}); 559 $child->move ($tex[3]->{w}, $tex[1]->{h});
536} 560}
537 561
538sub _draw { 562sub _draw {
539 my ($self) = @_; 563 my ($self) = @_;
540 564
541 my ($w, $h) = ($self->{w}, $self->{h}); 565 my ($w, $h) = ($self->{w}, $self->{h});
542 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 566 my ($cw, $ch) = ($self->child->{w}, $self->child->{h});
543 567
544 glEnable GL_BLEND; 568 glEnable GL_BLEND;
569 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
545 glEnable GL_TEXTURE_2D; 570 glEnable GL_TEXTURE_2D;
546 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
547 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 571 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
548 572
549 my $top = $tex[1]; 573 my $top = $tex[1];
550 $top->draw_quad (0, 0, $w, $top->{height}); 574 $top->draw_quad (0, 0, $w, $top->{h});
551 575
552 my $left = $tex[3]; 576 my $left = $tex[3];
553 $left->draw_quad (0, $top->{height}, $left->{width}, $ch); 577 $left->draw_quad (0, $top->{h}, $left->{w}, $ch);
554 578
555 my $right = $tex[2]; 579 my $right = $tex[2];
556 $right->draw_quad ($w - $right->{width}, $top->{height}, $right->{width}, $ch); 580 $right->draw_quad ($w - $right->{w}, $top->{h}, $right->{w}, $ch);
557 581
558 my $bottom = $tex[4]; 582 my $bottom = $tex[4];
559 $bottom->draw_quad (0, $h - $bottom->{height}, $w, $bottom->{height}); 583 $bottom->draw_quad (0, $h - $bottom->{h}, $w, $bottom->{h});
560 584
561 my $bg = $tex[0]; 585 my $bg = $tex[0];
562 glBindTexture GL_TEXTURE_2D, $bg->{name}; 586 glBindTexture GL_TEXTURE_2D, $bg->{name};
563 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 587 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
564 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; 588 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT;
565 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; 589 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT;
566 590
567 my $rep_x = $cw / $bg->{width}; 591 my $rep_x = $cw / $bg->{w};
568 my $rep_y = $ch / $bg->{height}; 592 my $rep_y = $ch / $bg->{h};
569 593
570 $bg->draw_quad ($left->{width}, $top->{height}, $cw, $ch); 594 $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch);
571 595
572 glDisable GL_BLEND; 596 glDisable GL_BLEND;
573 glDisable GL_TEXTURE_2D; 597 glDisable GL_TEXTURE_2D;
574 598
575 $self->child->draw; 599 $self->child->draw;
576 600
577} 601}
578 602
579############################################################################# 603#############################################################################
580 604
581package CFClient::Widget::Table; 605package CFClient::UI::Table;
582 606
583our @ISA = CFClient::Widget::Bin::; 607our @ISA = CFClient::UI::Base::;
584 608
585use SDL::OpenGL; 609use SDL::OpenGL;
586 610
587sub add { 611sub add {
588 my ($self, $x, $y, $chld) = @_; 612 my ($self, $x, $y, $chld) = @_;
663 } 687 }
664} 688}
665 689
666############################################################################# 690#############################################################################
667 691
668package CFClient::Widget::VBox; 692package CFClient::UI::VBox;
669 693
670our @ISA = CFClient::Widget::Container::; 694our @ISA = CFClient::UI::Container::;
671 695
672use SDL::OpenGL; 696use SDL::OpenGL;
673 697
674sub size_request { 698sub size_request {
675 my ($self) = @_; 699 my ($self) = @_;
727 } 751 }
728} 752}
729 753
730############################################################################# 754#############################################################################
731 755
732package CFClient::Widget::Label; 756package CFClient::UI::Label;
733 757
734our @ISA = CFClient::Widget::; 758our @ISA = CFClient::UI::Base::;
735 759
736use SDL::OpenGL; 760use SDL::OpenGL;
737 761
738sub new { 762sub new {
739 my ($class, %arg) = @_; 763 my ($class, %arg) = @_;
740 764
741 my $self = $class->SUPER::new ( 765 my $self = $class->SUPER::new (
742 fg => [1, 1, 1], 766 fg => [1, 1, 1],
743 height => $::FONTSIZE, 767 height => $::FONTSIZE,
744 text => "", 768 text => "",
769 align => -1,
745 layout => new CFClient::Layout, 770 layout => new CFClient::Layout,
746 %arg 771 %arg
747 ); 772 );
748 773
749 $self->set_text ($self->{text}); 774 $self->set_text ($self->{text});
781 my ($self) = @_; 806 my ($self) = @_;
782 807
783 $self->{layout}->set_width; 808 $self->{layout}->set_width;
784 $self->{layout}->set_height ($self->{height}); 809 $self->{layout}->set_height ($self->{height});
785 $self->{layout}->size 810 $self->{layout}->size
786# if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack 811# if ($self->{texture}{w} > 1 && $self->{texture}{height} > 1) { #TODO: hack
787# ( 812# (
788# $self->{texture}{width}, 813# $self->{texture}{w},
789# $self->{texture}{height}, 814# $self->{texture}{h},
790# ) 815# )
791# } else { 816# } else {
792# my ($w, $h, $data) = CFClient::font_render "Yy", $self->{height}; 817# my ($w, $h, $data) = CFClient::font_render "Yy", $self->{h};
793# 818#
794# ($w, $h) 819# ($w, $h)
795# } 820# }
796} 821}
797 822
814sub _draw { 839sub _draw {
815 my ($self) = @_; 840 my ($self) = @_;
816 841
817 my $tex = $self->{texture} ||= do { 842 my $tex = $self->{texture} ||= do {
818 $self->{layout}->set_width ($self->{w}); 843 $self->{layout}->set_width ($self->{w});
819 new_from_layout CFClient::Texture $self->{layout}; 844 new_from_layout CFClient::Texture $self->{layout}
820 }; 845 };
821 846
822 glEnable GL_BLEND; 847 glEnable GL_BLEND;
848 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
823 glEnable GL_TEXTURE_2D; 849 glEnable GL_TEXTURE_2D;
824 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
825 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 850 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
826 851
827 glColor @{$self->{fg}}; 852 glColor @{$self->{fg}};
828 853
854 my $x =
855 $self->{align} < 0 ? 0
856 : $self->{align} > 0 ? $self->{w} - $tex->{w}
857 : ($self->{w} - $tex->{w}) * 0.5;
858
829 $tex->draw_quad (0, 0); 859 $tex->draw_quad ($x, 0);
830 860
861 glDisable GL_TEXTURE_2D;
831 glDisable GL_BLEND; 862 glDisable GL_BLEND;
832 glDisable GL_TEXTURE_2D; 863 glGetError and die;
833} 864}
834 865
835############################################################################# 866#############################################################################
836 867
837package CFClient::Widget::Entry; 868package CFClient::UI::Entry;
838 869
839our @ISA = CFClient::Widget::Label::; 870our @ISA = CFClient::UI::Label::;
840 871
841use SDL; 872use SDL;
842use SDL::OpenGL; 873use SDL::OpenGL;
843 874
844sub new { 875sub new {
858 889
859 $self->{last_activity} = $::NOW; 890 $self->{last_activity} = $::NOW;
860 891
861 $self->{text} = $text; 892 $self->{text} = $text;
862 $self->{layout}->set_width ($self->{w}); 893 $self->{layout}->set_width ($self->{w});
894
895 $text =~ s/./*/g if $self->{hidden};
896
897
863 $self->{layout}->set_markup ($self->escape_text ($text)); 898 $self->{layout}->set_markup ($self->escape_text ($text));
864 899
865 $text = substr $text, 0, $self->{cursor}; 900 $text = substr $text, 0, $self->{cursor};
866 utf8::encode $text; 901 utf8::encode $text;
867 902
980 } 1015 }
981} 1016}
982 1017
983############################################################################# 1018#############################################################################
984 1019
985package CFClient::Widget::Slider; 1020package CFClient::UI::Slider;
986 1021
987use strict; 1022use strict;
988 1023
989use SDL::OpenGL; 1024use SDL::OpenGL;
990use SDL::OpenGL::Constants;
991 1025
992our @ISA = CFClient::Widget::DrawBG::; 1026our @ISA = CFClient::UI::DrawBG::;
993 1027
994sub size_request { 1028sub size_request {
995 my ($self) = @_; 1029 my ($self) = @_;
996 1030
997 my $w = 20; 1031 my $w = 50;
998 my $h = 10; 1032 my $h = 10;
999 1033
1000 $self->{vertical} ? ($h, $w) : ($w, $h) 1034 $self->{vertical} ? ($h, $w) : ($w, $h)
1001} 1035}
1002 1036
1007 1041
1008 $class->SUPER::new ( 1042 $class->SUPER::new (
1009 fg => [1, 1, 1], 1043 fg => [1, 1, 1],
1010 active_fg => [0, 0, 0], 1044 active_fg => [0, 0, 0],
1011 range => [0, 0, 100, 10], 1045 range => [0, 0, 100, 10],
1012 vertical => 0, 1046 vertical => 1,
1013 @_ 1047 @_
1014 ) 1048 )
1015} 1049}
1016 1050
1017sub button_down { 1051sub button_down {
1025 my ($self, $ev, $x, $y) = @_; 1059 my ($self, $ev, $x, $y) = @_;
1026 1060
1027 if ($GRAB == $self) { 1061 if ($GRAB == $self) {
1028 my ($value, $lo, $hi, $page) = @{$self->{range}}; 1062 my ($value, $lo, $hi, $page) = @{$self->{range}};
1029 1063
1064 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w});
1065
1030 $x = $x * ($hi - $lo) / $self->{w} + $lo; 1066 $x = $x * ($hi - $lo) / $w + $lo;
1031 $x = $lo if $x < $lo; 1067 $x = $lo if $x < $lo;
1032 $x = $hi - $page if $x > $hi - $page; 1068 $x = $hi - $page if $x > $hi - $page;
1033 $self->{range}[0] = $x; 1069 $self->{range}[0] = $x;
1034 1070
1035 $self->{changed}($x) if $self->{changed}; 1071 $self->emit (changed => $x);
1036 $self->update; 1072 $self->update;
1037 } 1073 }
1038} 1074}
1039 1075
1040sub _draw { 1076sub _draw {
1041 my ($self) = @_; 1077 my ($self) = @_;
1042 1078
1043 $self->SUPER::_draw (); 1079 $self->SUPER::_draw ();
1044
1045 glPushMatrix;
1046 1080
1047 my ($w, $h) = @$self{qw(w h)}; 1081 my ($w, $h) = @$self{qw(w h)};
1048 1082
1049 if ($self->{vertical}) { 1083 if ($self->{vertical}) {
1050 # draw a vertical slider like a rotated horizontal slider 1084 # draw a vertical slider like a rotated horizontal slider
1051 1085
1052 glTranslate 0, $self->{w};
1053 glRotate 90, 0, 0, 1; 1086 glRotate 90, 0, 0, 1;
1087 glTranslate 0, -$self->{w}, 0;
1054 1088
1055 ($w, $h) = ($h, $w); 1089 ($w, $h) = ($h, $w);
1056 } 1090 }
1057 1091
1058 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 1092 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
1090 glVertex $knob_a + 1, $h - 1; 1124 glVertex $knob_a + 1, $h - 1;
1091 glVertex $knob_b - 1, $h - 1; 1125 glVertex $knob_b - 1, $h - 1;
1092 glVertex $knob_b - 1, 1; 1126 glVertex $knob_b - 1, 1;
1093 } 1127 }
1094 glEnd; 1128 glEnd;
1095
1096 glPopMatrix;
1097} 1129}
1098 1130
1099############################################################################# 1131#############################################################################
1100 1132
1101package CFClient::Widget::MapWidget; 1133package CFClient::UI::MapWidget;
1102 1134
1103use strict; 1135use strict;
1104 1136
1105use List::Util qw(min max); 1137use List::Util qw(min max);
1106 1138
1107use SDL; 1139use SDL;
1108use SDL::OpenGL; 1140use SDL::OpenGL;
1109use SDL::OpenGL::Constants;
1110 1141
1111our @ISA = CFClient::Widget::; 1142our @ISA = CFClient::UI::Base::;
1112 1143
1113sub new { 1144sub new {
1114 my $class = shift; 1145 my $class = shift;
1115 1146
1116 $class->SUPER::new ( 1147 $class->SUPER::new (
1136 1167
1137sub update { 1168sub update {
1138 my ($self) = @_; 1169 my ($self) = @_;
1139 1170
1140 $self->{need_update} = 1; 1171 $self->{need_update} = 1;
1172 $self->SUPER::update;
1141} 1173}
1142 1174
1143sub _draw { 1175sub _draw {
1144 my ($self) = @_; 1176 my ($self) = @_;
1145 1177
1168 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; 1200 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs};
1169 } 1201 }
1170 1202
1171 glEnable GL_TEXTURE_2D; 1203 glEnable GL_TEXTURE_2D;
1172 glEnable GL_BLEND; 1204 glEnable GL_BLEND;
1205 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1173 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1206 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1174 1207
1175 my $sw4 = ($sw + 3) & ~3; 1208 my $sw4 = ($sw + 3) & ~3;
1176 my $darkness = "\x00" x ($sw4 * $sh); 1209 my $darkness = "\x00" x ($sw4 * $sh);
1177 1210
1190 } 1223 }
1191 1224
1192 for my $num (grep $_, @$cell[1,2,3]) { 1225 for my $num (grep $_, @$cell[1,2,3]) {
1193 my $tex = $::CONN->{face}[$num]{texture} || next; 1226 my $tex = $::CONN->{face}[$num]{texture} || next;
1194 1227
1195 my $w = $tex->{width}; 1228 my ($w, $h) = @$tex{qw(w h)};
1196 my $h = $tex->{height};
1197 1229
1198 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); 1230 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h);
1199 } 1231 }
1200 } 1232 }
1201 } 1233 }
1208# 1240#
1209# $lighting = $pb->get_pixels; 1241# $lighting = $pb->get_pixels;
1210# $lighting =~ s/(.)../$1/gs; 1242# $lighting =~ s/(.)../$1/gs;
1211# } 1243# }
1212 1244
1213 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1214 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1245 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1215 1246
1216 $darkness = new CFClient::Texture 1247 $darkness = new CFClient::Texture
1217 width => $sw4, 1248 w => $sw4,
1218 height => $sh, 1249 h => $sh,
1219 data => $darkness, 1250 data => $darkness,
1220 internalformat => GL_ALPHA, 1251 internalformat => GL_ALPHA,
1221 format => GL_ALPHA; 1252 format => GL_ALPHA;
1222 1253
1223 glColor 0.45, 0.45, 0.45, 1; 1254 glColor 0.45, 0.45, 0.45, 1;
1283 } 1314 }
1284} 1315}
1285 1316
1286############################################################################# 1317#############################################################################
1287 1318
1288package CFClient::Widget::Animator; 1319package CFClient::UI::Animator;
1289 1320
1290use SDL::OpenGL; 1321use SDL::OpenGL;
1291 1322
1292our @ISA = CFClient::Widget::Bin::; 1323our @ISA = CFClient::UI::Bin::;
1293 1324
1294sub moveto { 1325sub moveto {
1295 my ($self, $x, $y) = @_; 1326 my ($self, $x, $y) = @_;
1296 1327
1297 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 1328 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
1325 glPopMatrix; 1356 glPopMatrix;
1326} 1357}
1327 1358
1328############################################################################# 1359#############################################################################
1329 1360
1330package CFClient::Widget::Toplevel; 1361package CFClient::UI::Toplevel;
1331 1362
1332our @ISA = CFClient::Widget::Container::; 1363our @ISA = CFClient::UI::Container::;
1333 1364
1334sub size_request { 1365sub size_request {
1335 ($::WIDTH, $::HEIGHT) 1366 ($::WIDTH, $::HEIGHT)
1336} 1367}
1337 1368
1371 $self->_draw; 1402 $self->_draw;
1372} 1403}
1373 1404
1374############################################################################# 1405#############################################################################
1375 1406
1376package CFClient::Widget; 1407package CFClient::UI;
1377 1408
1378$TOPLEVEL = new CFClient::Widget::Toplevel; 1409$TOPLEVEL = new CFClient::UI::Toplevel;
1379 1410
13801 14111
1381 1412

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines