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.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 = 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 )
1049}
1050
1051sub button_down {
1052 my ($self, $ev, $x, $y) = @_;
1053
1054 $self->SUPER::button_down ($ev, $x, $y);
1055 $self->mouse_motion ($ev, $x, $y);
1056}
1057
1058sub mouse_motion {
1059 my ($self, $ev, $x, $y) = @_;
1060
1061 if ($GRAB == $self) {
1062 my ($value, $lo, $hi, $page) = @{$self->{range}};
1063
1064 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w});
1065
1066 $x = $x * ($hi - $lo) / $w + $lo;
1067 $x = $lo if $x < $lo;
1068 $x = $hi - $page if $x > $hi - $page;
1069 $self->{range}[0] = $x;
1070
1071 $self->emit (changed => $x);
1072 $self->update;
1073 }
1015} 1074}
1016 1075
1017sub _draw { 1076sub _draw {
1018 my ($self) = @_; 1077 my ($self) = @_;
1019 1078
1022 my ($w, $h) = @$self{qw(w h)}; 1081 my ($w, $h) = @$self{qw(w h)};
1023 1082
1024 if ($self->{vertical}) { 1083 if ($self->{vertical}) {
1025 # draw a vertical slider like a rotated horizontal slider 1084 # draw a vertical slider like a rotated horizontal slider
1026 1085
1027 glTranslate 0, $self->{w};
1028 glRotate 90, 0, 0, 1; 1086 glRotate 90, 0, 0, 1;
1087 glTranslate 0, -$self->{w}, 0;
1029 1088
1030 ($w, $h) = ($h, $w); 1089 ($w, $h) = ($h, $w);
1031 } 1090 }
1032 1091
1033 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 1092 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
1034 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 1093 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
1094
1095 my ($value, $lo, $hi, $page) = @{$self->{range}};
1096
1097 $page = int $page * $w / ($hi - $lo);
1098 $value = int +($value - $lo) * $w / ($hi - $lo);
1099
1100 $w -= $page;
1101 $page &= ~1;
1102 glTranslate $page * 0.5, 0, 0;
1035 1103
1036 glColor @$fg; 1104 glColor @$fg;
1037 glBegin GL_LINES; 1105 glBegin GL_LINES;
1038 glVertex 0, 0; glVertex 0, $h; 1106 glVertex 0, 0; glVertex 0, $h;
1039 glVertex $w - 1, 0; glVertex $w - 1, $h; 1107 glVertex $w - 1, 0; glVertex $w - 1, $h;
1040 glVertex 0, $h * 0.5; glVertex $w, $h * 0.5; 1108 glVertex 0, $h * 0.5; glVertex $w, $h * 0.5;
1041 glEnd; 1109 glEnd;
1042}
1043 1110
1044############################################################################# 1111 my $knob_a = $value - $page * 0.5;
1112 my $knob_b = $value + $page * 0.5;
1045 1113
1114 glBegin GL_QUADS;
1115 glColor @$fg;
1116 glVertex $knob_a, 0;
1117 glVertex $knob_a, $h;
1118 glVertex $knob_b, $h;
1119 glVertex $knob_b, 0;
1120
1121 if ($knob_a < $knob_b - 2) {
1122 glColor @$bg;
1123 glVertex $knob_a + 1, 1;
1124 glVertex $knob_a + 1, $h - 1;
1125 glVertex $knob_b - 1, $h - 1;
1126 glVertex $knob_b - 1, 1;
1127 }
1128 glEnd;
1129}
1130
1131#############################################################################
1132
1046package CFClient::Widget::MapWidget; 1133package CFClient::UI::MapWidget;
1047 1134
1048use strict; 1135use strict;
1049 1136
1050use List::Util qw(min max); 1137use List::Util qw(min max);
1051 1138
1052use SDL; 1139use SDL;
1053use SDL::OpenGL; 1140use SDL::OpenGL;
1054use SDL::OpenGL::Constants;
1055 1141
1056our @ISA = CFClient::Widget::; 1142our @ISA = CFClient::UI::Base::;
1057 1143
1058sub new { 1144sub new {
1059 my $class = shift; 1145 my $class = shift;
1060 1146
1061 $class->SUPER::new ( 1147 $class->SUPER::new (
1081 1167
1082sub update { 1168sub update {
1083 my ($self) = @_; 1169 my ($self) = @_;
1084 1170
1085 $self->{need_update} = 1; 1171 $self->{need_update} = 1;
1172 $self->SUPER::update;
1086} 1173}
1087 1174
1088sub _draw { 1175sub _draw {
1089 my ($self) = @_; 1176 my ($self) = @_;
1090 1177
1113 $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};
1114 } 1201 }
1115 1202
1116 glEnable GL_TEXTURE_2D; 1203 glEnable GL_TEXTURE_2D;
1117 glEnable GL_BLEND; 1204 glEnable GL_BLEND;
1205 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1118 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1206 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1119 1207
1120 my $sw4 = ($sw + 3) & ~3; 1208 my $sw4 = ($sw + 3) & ~3;
1121 my $darkness = "\x00" x ($sw4 * $sh); 1209 my $darkness = "\x00" x ($sw4 * $sh);
1122 1210
1135 } 1223 }
1136 1224
1137 for my $num (grep $_, @$cell[1,2,3]) { 1225 for my $num (grep $_, @$cell[1,2,3]) {
1138 my $tex = $::CONN->{face}[$num]{texture} || next; 1226 my $tex = $::CONN->{face}[$num]{texture} || next;
1139 1227
1140 my $w = $tex->{width}; 1228 my ($w, $h) = @$tex{qw(w h)};
1141 my $h = $tex->{height};
1142 1229
1143 $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);
1144 } 1231 }
1145 } 1232 }
1146 } 1233 }
1153# 1240#
1154# $lighting = $pb->get_pixels; 1241# $lighting = $pb->get_pixels;
1155# $lighting =~ s/(.)../$1/gs; 1242# $lighting =~ s/(.)../$1/gs;
1156# } 1243# }
1157 1244
1158 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1159 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1245 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1160 1246
1161 $darkness = new CFClient::Texture 1247 $darkness = new CFClient::Texture
1162 width => $sw4, 1248 w => $sw4,
1163 height => $sh, 1249 h => $sh,
1164 data => $darkness, 1250 data => $darkness,
1165 internalformat => GL_ALPHA, 1251 internalformat => GL_ALPHA,
1166 format => GL_ALPHA; 1252 format => GL_ALPHA;
1167 1253
1168 glColor 0.45, 0.45, 0.45, 1; 1254 glColor 0.45, 0.45, 0.45, 1;
1228 } 1314 }
1229} 1315}
1230 1316
1231############################################################################# 1317#############################################################################
1232 1318
1233package CFClient::Widget::Animator; 1319package CFClient::UI::Animator;
1234 1320
1235use SDL::OpenGL; 1321use SDL::OpenGL;
1236 1322
1237our @ISA = CFClient::Widget::Bin::; 1323our @ISA = CFClient::UI::Bin::;
1238 1324
1239sub moveto { 1325sub moveto {
1240 my ($self, $x, $y) = @_; 1326 my ($self, $x, $y) = @_;
1241 1327
1242 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; 1328 $self->{moveto} = [$self->{x}, $self->{y}, $x, $y];
1270 glPopMatrix; 1356 glPopMatrix;
1271} 1357}
1272 1358
1273############################################################################# 1359#############################################################################
1274 1360
1275package CFClient::Widget::Toplevel; 1361package CFClient::UI::Toplevel;
1276 1362
1277our @ISA = CFClient::Widget::Container::; 1363our @ISA = CFClient::UI::Container::;
1278 1364
1279sub size_request { 1365sub size_request {
1280 ($::WIDTH, $::HEIGHT) 1366 ($::WIDTH, $::HEIGHT)
1281} 1367}
1282 1368
1316 $self->_draw; 1402 $self->_draw;
1317} 1403}
1318 1404
1319############################################################################# 1405#############################################################################
1320 1406
1321package CFClient::Widget; 1407package CFClient::UI;
1322 1408
1323$TOPLEVEL = new CFClient::Widget::Toplevel; 1409$TOPLEVEL = new CFClient::UI::Toplevel;
1324 1410
13251 14111
1326 1412

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines