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.268 by root, Thu Jun 1 05:04:41 2006 UTC vs.
Revision 1.278 by root, Sun Jun 4 23:05:06 2006 UTC

371sub size_allocate { 371sub size_allocate {
372 # nothing to be done 372 # nothing to be done
373} 373}
374 374
375sub children { 375sub children {
376 # nop
377}
378
379sub visible_children {
380 $_[0]->children
376} 381}
377 382
378sub set_max_size { 383sub set_max_size {
379 my ($self, $w, $h) = @_; 384 my ($self, $w, $h) = @_;
380 385
439 444
440 $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus 445 $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus
441 unless $FOCUS; 446 unless $FOCUS;
442} 447}
443 448
444sub mouse_motion { } 449sub mouse_motion { 0 }
445sub button_up { } 450sub button_up { 0 }
446sub key_down { } 451sub key_down { 0 }
447sub key_up { } 452sub key_up { 0 }
448 453
449sub button_down { 454sub button_down {
450 my ($self, $ev, $x, $y) = @_; 455 my ($self, $ev, $x, $y) = @_;
451 456
452 $self->focus_in; 457 $self->focus_in;
458
459 0
453} 460}
454 461
455sub find_widget { 462sub find_widget {
456 my ($self, $x, $y) = @_; 463 my ($self, $x, $y) = @_;
457 464
541 return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) 548 return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w)
542 || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); 549 || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h);
543 550
544 glPushMatrix; 551 glPushMatrix;
545 glTranslate $self->{x}, $self->{y}, 0; 552 glTranslate $self->{x}, $self->{y}, 0;
546 $self->_draw;
547 glPopMatrix;
548 553
549 if ($self == $HOVER && $self->{can_hover}) { 554 if ($self == $HOVER && $self->{can_hover}) {
550 my ($x, $y) = @$self{qw(x y)};
551
552 glColor 1, 0.8, 0.5, 0.2; 555 glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2;
553 glEnable GL_BLEND; 556 glEnable GL_BLEND;
554 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 557 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
555 glBegin GL_QUADS; 558 glBegin GL_QUADS;
556 glVertex $x , $y; 559 glVertex 0 , 0;
557 glVertex $x + $self->{w}, $y; 560 glVertex $self->{w}, 0;
558 glVertex $x + $self->{w}, $y + $self->{h}; 561 glVertex $self->{w}, $self->{h};
559 glVertex $x , $y + $self->{h}; 562 glVertex 0 , $self->{h};
560 glEnd; 563 glEnd;
561 glDisable GL_BLEND; 564 glDisable GL_BLEND;
562 } 565 }
563 566
564 if ($ENV{CFPLUS_DEBUG} & 1) { 567 if ($ENV{CFPLUS_DEBUG} & 1) {
565 glPushMatrix; 568 glPushMatrix;
566 glColor 1, 1, 0, 1; 569 glColor 1, 1, 0, 1;
567 glTranslate $self->{x} + 0.375, $self->{y} + 0.375; 570 glTranslate 0.375, 0.375;
568 glBegin GL_LINE_LOOP; 571 glBegin GL_LINE_LOOP;
569 glVertex 0 , 0; 572 glVertex 0 , 0;
570 glVertex $self->{w} - 1, 0; 573 glVertex $self->{w} - 1, 0;
571 glVertex $self->{w} - 1, $self->{h} - 1; 574 glVertex $self->{w} - 1, $self->{h} - 1;
572 glVertex 0 , $self->{h} - 1; 575 glVertex 0 , $self->{h} - 1;
573 glEnd; 576 glEnd;
574 glPopMatrix; 577 glPopMatrix;
575 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; 578 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
576 } 579 }
580
581 $self->_draw;
582 glPopMatrix;
577} 583}
578 584
579sub _draw { 585sub _draw {
580 my ($self) = @_; 586 my ($self) = @_;
581 587
619 625
620 if ($color && (@$color < 4 || $color->[3])) { 626 if ($color && (@$color < 4 || $color->[3])) {
621 my ($w, $h) = @$self{qw(w h)}; 627 my ($w, $h) = @$self{qw(w h)};
622 628
623 glEnable GL_BLEND; 629 glEnable GL_BLEND;
624 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 630 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
625 glColor @$color; 631 glColor_premultiply @$color;
626 632
627 glBegin GL_QUADS; 633 glBegin GL_QUADS;
628 glVertex 0 , 0; 634 glVertex 0 , 0;
629 glVertex 0 , $h; 635 glVertex 0 , $h;
630 glVertex $w, $h; 636 glVertex $w, $h;
661our @ISA = CFClient::UI::Base::; 667our @ISA = CFClient::UI::Base::;
662 668
663sub new { 669sub new {
664 my ($class, %arg) = @_; 670 my ($class, %arg) = @_;
665 671
666 my $children = delete $arg{children} || []; 672 my $children = delete $arg{children};
667 673
668 my $self = $class->SUPER::new ( 674 my $self = $class->SUPER::new (
669 children => [], 675 children => [],
670 can_events => 0, 676 can_events => 0,
671 %arg, 677 %arg,
672 ); 678 );
679
673 $self->add ($_) for @$children; 680 $self->add (@$children)
681 if $children;
674 682
675 $self 683 $self
676} 684}
677 685
678sub add { 686sub add {
726 $x -= $self->{x}; 734 $x -= $self->{x};
727 $y -= $self->{y}; 735 $y -= $self->{y};
728 736
729 my $res; 737 my $res;
730 738
731 for (reverse @{ $self->{children} }) { 739 for (reverse $self->visible_children) {
732 $res = $_->find_widget ($x, $y) 740 $res = $_->find_widget ($x, $y)
733 and return $res; 741 and return $res;
734 } 742 }
735 743
736 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) 744 $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y})
785 $self->{children}[0]->configure (0, 0, $w, $h); 793 $self->{children}[0]->configure (0, 0, $w, $h);
786} 794}
787 795
788############################################################################# 796#############################################################################
789 797
798# back-buffered drawing area
799
790package CFClient::UI::Window; 800package CFClient::UI::Window;
791 801
792our @ISA = CFClient::UI::Bin::; 802our @ISA = CFClient::UI::Bin::;
793 803
794use CFClient::OpenGL; 804use CFClient::OpenGL;
845 my $tex = $self->{texture} 855 my $tex = $self->{texture}
846 or return; 856 or return;
847 857
848 glEnable GL_TEXTURE_2D; 858 glEnable GL_TEXTURE_2D;
849 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 859 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
860 glEnable GL_BLEND;
861 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
850 glColor 1, 1, 1, 1; 862 glColor 0, 0, 0, 1;
851 863
852 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); 864 $tex->draw_quad (0, 0, $w, $h);
853 865
866 glDisable GL_BLEND;
854 glDisable GL_TEXTURE_2D; 867 glDisable GL_TEXTURE_2D;
855} 868}
856 869
857############################################################################# 870#############################################################################
858 871
946package CFClient::UI::ScrolledWindow; 959package CFClient::UI::ScrolledWindow;
947 960
948our @ISA = CFClient::UI::HBox::; 961our @ISA = CFClient::UI::HBox::;
949 962
950sub new { 963sub new {
951 my $class = shift; 964 my ($class, %arg) = @_;
965
966 my $child = delete $arg{child};
952 967
953 my $self; 968 my $self;
954 969
955 my $slider = new CFClient::UI::Slider 970 my $slider = new CFClient::UI::Slider
956 vertical => 1, 971 vertical => 1,
961 ; 976 ;
962 977
963 $self = $class->SUPER::new ( 978 $self = $class->SUPER::new (
964 vp => (new CFClient::UI::ViewPort expand => 1), 979 vp => (new CFClient::UI::ViewPort expand => 1),
965 slider => $slider, 980 slider => $slider,
966 @_, 981 %arg,
967 ); 982 );
968 983
969 $self->{vp}->add ($self->{scrolled});
970 $self->add ($self->{vp});
971 $self->add ($self->{slider}); 984 $self->SUPER::add ($self->{vp}, $self->{slider});
985 $self->add ($child) if $child;
972 986
973 $self 987 $self
988}
989
990sub add {
991 my ($self, $widget) = @_;
992
993 $self->{vp}->add ($self->{child} = $widget);
974} 994}
975 995
976sub update { 996sub update {
977 my ($self) = @_; 997 my ($self) = @_;
978 998
1017 1037
1018 if ($self->{bg}) { 1038 if ($self->{bg}) {
1019 my ($w, $h) = @$self{qw(w h)}; 1039 my ($w, $h) = @$self{qw(w h)};
1020 1040
1021 glEnable GL_BLEND; 1041 glEnable GL_BLEND;
1022 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1042 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
1023 glColor @{ $self->{bg} }; 1043 glColor_premultiply @{ $self->{bg} };
1024 1044
1025 glBegin GL_QUADS; 1045 glBegin GL_QUADS;
1026 glVertex 0 , 0; 1046 glVertex 0 , 0;
1027 glVertex 0 , $h; 1047 glVertex 0 , $h;
1028 glVertex $w, $h; 1048 glVertex $w, $h;
1050my @border = 1070my @border =
1051 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1071 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1052 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1072 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1053 1073
1054sub new { 1074sub new {
1055 my $class = shift; 1075 my ($class, %arg) = @_;
1076
1077 my $title = delete $arg{title};
1056 1078
1057 my $self = $class->SUPER::new ( 1079 my $self = $class->SUPER::new (
1058 bg => [1, 1, 1, 1], 1080 bg => [1, 1, 1, 1],
1059 border_bg => [1, 1, 1, 1], 1081 border_bg => [1, 1, 1, 1],
1060 border => 0.6, 1082 border => 0.6,
1061 can_events => 1, 1083 can_events => 1,
1062 min_w => 16, 1084 min_w => 16,
1063 min_h => 16, 1085 min_h => 16,
1064 @_ 1086 %arg,
1065 ); 1087 );
1066 1088
1067 $self->{title} &&= new CFClient::UI::Label 1089 $self->{title} = new CFClient::UI::Label
1068 align => 0, 1090 align => 0,
1069 valign => 1, 1091 valign => 1,
1070 text => $self->{title}, 1092 text => $title,
1071 fontsize => $self->{border}; 1093 fontsize => $self->{border}
1094 if defined $title;
1072 1095
1073 $self 1096 $self
1097}
1098
1099sub add {
1100 my ($self, @widgets) = @_;
1101
1102 $self->SUPER::add (@widgets);
1103 $self->CFClient::UI::Container::add ($self->{title}) if $self->{title};
1074} 1104}
1075 1105
1076sub border { 1106sub border {
1077 int $_[0]{border} * $::FONTSIZE 1107 int $_[0]{border} * $::FONTSIZE
1078} 1108}
1079 1109
1080sub size_request { 1110sub size_request {
1081 my ($self) = @_; 1111 my ($self) = @_;
1112
1113 $self->{title}->size_request
1114 if $self->{title};
1082 1115
1083 my ($w, $h) = $self->SUPER::size_request; 1116 my ($w, $h) = $self->SUPER::size_request;
1084 1117
1085 ( 1118 (
1086 $w + $self->border * 2, 1119 $w + $self->border * 2,
1089} 1122}
1090 1123
1091sub size_allocate { 1124sub size_allocate {
1092 my ($self, $w, $h) = @_; 1125 my ($self, $w, $h) = @_;
1093 1126
1127 if ($self->{title}) {
1128 $self->{title}{w} = $w;
1129 $self->{title}{h} = $h;
1130 $self->{title}->size_allocate ($w, $h);
1131 }
1132
1133 my $border = $self->border;
1134
1094 $h -= List::Util::max 0, $self->border * 2; 1135 $h -= List::Util::max 0, $border * 2;
1095 $w -= List::Util::max 0, $self->border * 2; 1136 $w -= List::Util::max 0, $border * 2;
1096 1137
1097 $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2)
1098 if $self->{title};
1099
1100 $self->child->configure ($self->border, $self->border, $w, $h); 1138 $self->child->configure ($border, $border, $w, $h);
1101} 1139}
1102 1140
1103sub button_down { 1141sub button_down {
1104 my ($self, $ev, $x, $y) = @_; 1142 my ($self, $ev, $x, $y) = @_;
1105 1143
1124 my $dy = $ev->{y} - $oy; 1162 my $dy = $ev->{y} - $oy;
1125 1163
1126 $self->{force_w} = $bw + $dx * ($mx ? -1 : 1); 1164 $self->{force_w} = $bw + $dx * ($mx ? -1 : 1);
1127 $self->{force_h} = $bh + $dy * ($my ? -1 : 1); 1165 $self->{force_h} = $bh + $dy * ($my ? -1 : 1);
1128 1166
1167 $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my);
1129 $self->realloc; 1168 $self->realloc;
1130 $self->move_abs ($wx + $dx * $mx, $wy + $dy * $my);
1131 }; 1169 };
1132 1170
1133 } elsif ($lr ^ $td) { 1171 } elsif ($lr ^ $td) {
1134 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 1172 my ($ox, $oy) = ($ev->{x}, $ev->{y});
1135 my ($bx, $by) = ($self->{x}, $self->{y}); 1173 my ($bx, $by) = ($self->{x}, $self->{y});
1138 my ($ev, $x, $y) = @_; 1176 my ($ev, $x, $y) = @_;
1139 1177
1140 ($x, $y) = ($ev->{x}, $ev->{y}); 1178 ($x, $y) = ($ev->{x}, $ev->{y});
1141 1179
1142 $self->move_abs ($bx + $x - $ox, $by + $y - $oy); 1180 $self->move_abs ($bx + $x - $ox, $by + $y - $oy);
1181 # HACK: the next line is required to enforce placement
1182 $self->{parent}->size_allocate ($self->{parent}{w}, $self->{parent}{h});
1143 }; 1183 };
1184 } else {
1185 return 0;
1186 }
1187
1144 } 1188 1
1145} 1189}
1146 1190
1147sub button_up { 1191sub button_up {
1148 my ($self, $ev, $x, $y) = @_; 1192 my ($self, $ev, $x, $y) = @_;
1149 1193
1150 delete $self->{motion}; 1194 !!delete $self->{motion}
1151} 1195}
1152 1196
1153sub mouse_motion { 1197sub mouse_motion {
1154 my ($self, $ev, $x, $y) = @_; 1198 my ($self, $ev, $x, $y) = @_;
1155 1199
1156 $self->{motion}->($ev, $x, $y) if $self->{motion}; 1200 $self->{motion}->($ev, $x, $y) if $self->{motion};
1201
1202 !!$self->{motion}
1157} 1203}
1158 1204
1159sub _draw { 1205sub _draw {
1160 my ($self) = @_; 1206 my ($self) = @_;
1161 1207
1208 my $child = $self->{children}[0];
1209
1162 my ($w, $h ) = ($self->{w}, $self->{h}); 1210 my ($w, $h ) = ($self->{w}, $self->{h});
1163 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 1211 my ($cw, $ch) = ($child->{w}, $child->{h});
1164 1212
1165 glEnable GL_TEXTURE_2D; 1213 glEnable GL_TEXTURE_2D;
1166 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1214 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1167 1215
1168 my $border = $self->border; 1216 my $border = $self->border;
1183 $bg->draw_quad_alpha ($border, $border, $cw, $ch); 1231 $bg->draw_quad_alpha ($border, $border, $cw, $ch);
1184 } 1232 }
1185 1233
1186 glDisable GL_TEXTURE_2D; 1234 glDisable GL_TEXTURE_2D;
1187 1235
1188 $self->{title}->draw if $self->{title};
1189
1190 $self->child->draw; 1236 $child->draw;
1237
1238 if ($self->{title}) {
1239 glTranslate 0, $border - $self->{h};
1240 $self->{title}->_draw;
1241 }
1191} 1242}
1192 1243
1193############################################################################# 1244#############################################################################
1194 1245
1195package CFClient::UI::Table; 1246package CFClient::UI::Table;
1543} 1594}
1544 1595
1545sub size_allocate { 1596sub size_allocate {
1546 my ($self, $w, $h) = @_; 1597 my ($self, $w, $h) = @_;
1547 1598
1599 delete $self->{ox};
1600
1548 delete $self->{texture} 1601 delete $self->{texture}
1549 unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w}; 1602 unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w};
1550} 1603}
1551 1604
1552sub set_fontsize { 1605sub set_fontsize {
1569 $self->{layout}->set_width ($self->{w}); 1622 $self->{layout}->set_width ($self->{w});
1570 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1623 $self->{layout}->set_ellipsise ($self->{ellipsise});
1571 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1624 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1572 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1625 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1573 1626
1574 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1627 new_from_layout CFClient::Texture $self->{layout}
1628 };
1575 1629
1630 unless (exists $self->{ox}) {
1576 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} 1631 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x}
1577 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} 1632 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x}
1578 : ($self->{w} - $tex->{w}) * 0.5); 1633 : ($self->{w} - $tex->{w}) * 0.5);
1579 1634
1580 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} 1635 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
1581 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} 1636 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y}
1582 : ($self->{h} - $tex->{h}) * 0.5); 1637 : ($self->{h} - $tex->{h}) * 0.5);
1583
1584 $tex
1585 }; 1638 };
1586 1639
1587 glEnable GL_TEXTURE_2D; 1640 glEnable GL_TEXTURE_2D;
1588 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1641 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1589 1642
1627 1680
1628 delete $self->{cur_h}; 1681 delete $self->{cur_h};
1629 1682
1630 return if $self->{text} eq $text; 1683 return if $self->{text} eq $text;
1631 1684
1632 delete $self->{texture};
1633
1634 $self->{last_activity} = $::NOW; 1685 $self->{last_activity} = $::NOW;
1635 $self->{text} = $text; 1686 $self->{text} = $text;
1636 1687
1637 $text =~ s/./*/g if $self->{hidden}; 1688 $text =~ s/./*/g if $self->{hidden};
1638 $self->{layout}->set_text ("$text "); 1689 $self->{layout}->set_text ("$text ");
1639 1690
1640 $self->_emit (changed => $self->{text}); 1691 $self->_emit (changed => $self->{text});
1692 $self->update;
1641} 1693}
1642 1694
1643sub set_text { 1695sub set_text {
1644 my ($self, $text) = @_; 1696 my ($self, $text) = @_;
1645 1697
1684 $self->{cursor} = length $text; 1736 $self->{cursor} = length $text;
1685 } elsif ($uni == 27) { 1737 } elsif ($uni == 27) {
1686 $self->_emit ('escape'); 1738 $self->_emit ('escape');
1687 } elsif ($uni) { 1739 } elsif ($uni) {
1688 substr $text, $self->{cursor}++, 0, chr $uni; 1740 substr $text, $self->{cursor}++, 0, chr $uni;
1741 } else {
1742 return 0;
1689 } 1743 }
1690 1744
1691 $self->_set_text ($text); 1745 $self->_set_text ($text);
1692 1746
1693 $self->realloc; 1747 $self->realloc;
1748
1749 1
1694} 1750}
1695 1751
1696sub focus_in { 1752sub focus_in {
1697 my ($self) = @_; 1753 my ($self) = @_;
1698 1754
1713 utf8::encode $text; 1769 utf8::encode $text;
1714 $self->{cursor} = length substr $text, 0, $idx; 1770 $self->{cursor} = length substr $text, 0, $idx;
1715 1771
1716 $self->_set_text ($self->{text}); 1772 $self->_set_text ($self->{text});
1717 $self->update; 1773 $self->update;
1774
1775 1
1718} 1776}
1719 1777
1720sub mouse_motion { 1778sub mouse_motion {
1721 my ($self, $ev, $x, $y) = @_; 1779 my ($self, $ev, $x, $y) = @_;
1722# printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# 1780# printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d#
1781
1782 0
1723} 1783}
1724 1784
1725sub _draw { 1785sub _draw {
1726 my ($self) = @_; 1786 my ($self) = @_;
1727 1787
1728 local $self->{fg} = $self->{fg}; 1788 local $self->{fg} = $self->{fg};
1729 1789
1730 if ($FOCUS == $self) { 1790 if ($FOCUS == $self) {
1731 glColor @{$self->{active_bg}}; 1791 glColor_premultiply @{$self->{active_bg}};
1732 $self->{fg} = $self->{active_fg}; 1792 $self->{fg} = $self->{active_fg};
1733 } else { 1793 } else {
1734 glColor @{$self->{bg}}; 1794 glColor_premultiply @{$self->{bg}};
1735 } 1795 }
1736 1796
1737 glEnable GL_BLEND; 1797 glEnable GL_BLEND;
1738 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1798 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
1739 glBegin GL_QUADS; 1799 glBegin GL_QUADS;
1740 glVertex 0 , 0; 1800 glVertex 0 , 0;
1741 glVertex 0 , $self->{h}; 1801 glVertex 0 , $self->{h};
1742 glVertex $self->{w}, $self->{h}; 1802 glVertex $self->{w}, $self->{h};
1743 glVertex $self->{w}, 0; 1803 glVertex $self->{w}, 0;
1804 } else { 1864 } else {
1805 $self->set_text ($self->{history_saveback}); 1865 $self->set_text ($self->{history_saveback});
1806 } 1866 }
1807 1867
1808 } else { 1868 } else {
1809 $self->SUPER::key_down ($ev); 1869 return $self->SUPER::key_down ($ev)
1870 }
1871
1810 } 1872 1
1811
1812} 1873}
1813 1874
1814############################################################################# 1875#############################################################################
1815 1876
1816package CFClient::UI::Button; 1877package CFClient::UI::Button;
1845 my ($self, $ev, $x, $y) = @_; 1906 my ($self, $ev, $x, $y) = @_;
1846 1907
1847 $self->emit ("activate") 1908 $self->emit ("activate")
1848 if $x >= 0 && $x < $self->{w} 1909 if $x >= 0 && $x < $self->{w}
1849 && $y >= 0 && $y < $self->{h}; 1910 && $y >= 0 && $y < $self->{h};
1911
1912 1
1850} 1913}
1851 1914
1852sub _draw { 1915sub _draw {
1853 my ($self) = @_; 1916 my ($self) = @_;
1854 1917
1908 1971
1909 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} 1972 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
1910 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { 1973 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
1911 $self->{state} = !$self->{state}; 1974 $self->{state} = !$self->{state};
1912 $self->_emit (changed => $self->{state}); 1975 $self->_emit (changed => $self->{state});
1976 } else {
1977 return 0
1978 }
1979
1913 } 1980 1
1914} 1981}
1915 1982
1916sub _draw { 1983sub _draw {
1917 my ($self) = @_; 1984 my ($self) = @_;
1918 1985
2085 2152
2086 my $h1 = $self->{h} * (1 - $ycut1); 2153 my $h1 = $self->{h} * (1 - $ycut1);
2087 my $h2 = $self->{h} * (1 - $ycut2); 2154 my $h2 = $self->{h} * (1 - $ycut2);
2088 2155
2089 glEnable GL_BLEND; 2156 glEnable GL_BLEND;
2090 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 2157 glBlendFuncSeparate GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
2158 GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2091 glEnable GL_TEXTURE_2D; 2159 glEnable GL_TEXTURE_2D;
2092 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2160 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2093 2161
2094 glBindTexture GL_TEXTURE_2D, $t1->{name}; 2162 glBindTexture GL_TEXTURE_2D, $t1->{name};
2095 glBegin GL_QUADS; 2163 glBegin GL_QUADS;
2256 2324
2257 $self->SUPER::button_down ($ev, $x, $y); 2325 $self->SUPER::button_down ($ev, $x, $y);
2258 2326
2259 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; 2327 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x];
2260 2328
2261 $self->mouse_motion ($ev, $x, $y); 2329 $self->mouse_motion ($ev, $x, $y)
2262} 2330}
2263 2331
2264sub mouse_motion { 2332sub mouse_motion {
2265 my ($self, $ev, $x, $y) = @_; 2333 my ($self, $ev, $x, $y) = @_;
2266 2334
2270 my (undef, $lo, $hi, $page) = @{$self->{range}}; 2338 my (undef, $lo, $hi, $page) = @{$self->{range}};
2271 2339
2272 $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); 2340 $x = ($x - $self->{click}[1]) / ($w * $self->{scale});
2273 2341
2274 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); 2342 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo));
2343 } else {
2344 return 0;
2345 }
2346
2275 } 2347 1
2276} 2348}
2277 2349
2278sub update { 2350sub update {
2279 my ($self) = @_; 2351 my ($self) = @_;
2280 2352
2281 $CFClient::UI::ROOT->on_post_alloc ($self => sub { 2353 delete $self->{knob_w};
2354 $self->SUPER::update;
2355}
2356
2357sub _draw {
2358 my ($self) = @_;
2359
2360 unless ($self->{knob_w}) {
2282 $self->set_value ($self->{range}[0]); 2361 $self->set_value ($self->{range}[0]);
2283 2362
2284 my ($value, $lo, $hi, $page) = @{$self->{range}}; 2363 my ($value, $lo, $hi, $page) = @{$self->{range}};
2285 my $range = ($hi - $page - $lo) || 1e-100; 2364 my $range = ($hi - $page - $lo) || 1e-100;
2286 2365
2292 $value = ($value - $lo) / $range; 2371 $value = ($value - $lo) / $range;
2293 $value = $value * $self->{scale} + $self->{offset}; 2372 $value = $value * $self->{scale} + $self->{offset};
2294 2373
2295 $self->{knob_x} = $value - $knob_w * 0.5; 2374 $self->{knob_x} = $value - $knob_w * 0.5;
2296 $self->{knob_w} = $knob_w; 2375 $self->{knob_w} = $knob_w;
2297 }); 2376 }
2298
2299 $self->SUPER::update;
2300}
2301
2302sub _draw {
2303 my ($self) = @_;
2304 2377
2305 $self->SUPER::_draw (); 2378 $self->SUPER::_draw ();
2306 2379
2307 glScale $self->{w}, $self->{h}; 2380 glScale $self->{w}, $self->{h};
2308 2381
2802 $self->SUPER::DESTROY; 2875 $self->SUPER::DESTROY;
2803} 2876}
2804 2877
2805############################################################################# 2878#############################################################################
2806 2879
2880package CFClient::UI::Buttonbar;
2881
2882our @ISA = CFClient::UI::HBox::;
2883
2884# TODO: should actualyl wrap buttons and other goodies.
2885
2886#############################################################################
2887
2807package CFClient::UI::Menu; 2888package CFClient::UI::Menu;
2808 2889
2809our @ISA = CFClient::UI::FancyFrame::; 2890our @ISA = CFClient::UI::FancyFrame::;
2810 2891
2811use CFClient::OpenGL; 2892use CFClient::OpenGL;
2858 my ($self, $ev, $x, $y) = @_; 2939 my ($self, $ev, $x, $y) = @_;
2859 2940
2860 # TODO: should use vbox->find_widget or so 2941 # TODO: should use vbox->find_widget or so
2861 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); 2942 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y});
2862 $self->{hover} = $self->{item}{$HOVER}; 2943 $self->{hover} = $self->{item}{$HOVER};
2944
2945 0
2863} 2946}
2864 2947
2865sub button_up { 2948sub button_up {
2866 my ($self, $ev, $x, $y) = @_; 2949 my ($self, $ev, $x, $y) = @_;
2867 2950
2869 undef $GRAB; 2952 undef $GRAB;
2870 $self->hide; 2953 $self->hide;
2871 2954
2872 $self->_emit ("popdown"); 2955 $self->_emit ("popdown");
2873 $self->{hover}[1]->() if $self->{hover}; 2956 $self->{hover}[1]->() if $self->{hover};
2957 } else {
2958 return 0
2959 }
2960
2961 1
2962}
2963
2964#############################################################################
2965
2966package CFClient::UI::Multiplexer;
2967
2968our @ISA = CFClient::UI::Container::;
2969
2970sub new {
2971 my $class = shift;
2972
2973 my $self = $class->SUPER::new (
2974 @_,
2975 );
2976
2977 $self->{current} = $self->{children}[0]
2978 if @{ $self->{children} };
2979
2980 $self
2981}
2982
2983sub add {
2984 my ($self, @widgets) = @_;
2985
2986 $self->SUPER::add (@widgets);
2987
2988 $self->{current} = $self->{children}[0]
2989 if @{ $self->{children} };
2990}
2991
2992sub set_current_page {
2993 my ($self, $page_or_widget) = @_;
2994
2995 my $widget = ref $page_or_widget
2996 ? $page_or_widget
2997 : $self->{children}[$page_or_widget];
2998
2999 $self->{current} = $widget;
3000 $self->{current}->configure (0, 0, $self->{w}, $self->{h});
3001
3002 $self->_emit (page_changed => $self->{current});
3003
3004 $self->realloc;
3005}
3006
3007sub visible_children {
3008 $_[0]{current}
3009}
3010
3011sub size_request {
3012 my ($self) = @_;
3013
3014 $self->{current}->size_request
3015}
3016
3017sub size_allocate {
3018 my ($self, $w, $h) = @_;
3019
3020 $self->{current}->configure (0, 0, $w, $h);
3021}
3022
3023sub _draw {
3024 my ($self) = @_;
3025
3026 $self->{current}->draw;
3027}
3028
3029#############################################################################
3030
3031package CFClient::UI::Notebook;
3032
3033our @ISA = CFClient::UI::VBox::;
3034
3035sub new {
3036 my $class = shift;
3037
3038 my $self = $class->SUPER::new (
3039 buttonbar => (new CFClient::UI::Buttonbar),
3040 multiplexer => (new CFClient::UI::Multiplexer expand => 1),
3041 # filter => # will be put between multiplexer and $self
3042 @_,
3043 );
2874 } 3044
3045 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3046 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer});
3047
3048 $self
3049}
3050
3051sub add {
3052 my ($self, $title, $widget, $tooltip) = @_;
3053
3054 Scalar::Util::weaken $self;
3055
3056 $self->{buttonbar}->add (new CFClient::UI::Button
3057 markup => $title,
3058 tooltip => $tooltip,
3059 on_activate => sub { $self->set_current_page ($widget) },
3060 );
3061
3062 $self->{multiplexer}->add ($widget);
3063}
3064
3065sub set_current_page {
3066 my ($self, $page) = @_;
3067
3068 $self->{multiplexer}->set_current_page ($page);
3069 $self->_emit (page_changed => $self->{multiplexer}{current});
2875} 3070}
2876 3071
2877############################################################################# 3072#############################################################################
2878 3073
2879package CFClient::UI::Statusbox; 3074package CFClient::UI::Statusbox;
2992 3187
2993sub new { 3188sub new {
2994 my $class = shift; 3189 my $class = shift;
2995 3190
2996 my $self = $class->SUPER::new ( 3191 my $self = $class->SUPER::new (
2997 scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), 3192 child => (new CFClient::UI::Table col_expand => [0, 1, 0]),
2998 @_, 3193 @_,
2999 ); 3194 );
3000 3195
3001 $self 3196 $self
3002} 3197}
3003 3198
3004sub set_items { 3199sub set_items {
3005 my ($self, $items) = @_; 3200 my ($self, $items) = @_;
3006 3201
3007 $self->{scrolled}->clear; 3202 $self->{child}->clear;
3008 return unless $items; 3203 return unless $items;
3009 3204
3010 my @items = sort { 3205 my @items = sort {
3011 ($a->{type} <=> $b->{type}) 3206 ($a->{type} <=> $b->{type})
3012 or ($a->{name} cmp $b->{name}) 3207 or ($a->{name} cmp $b->{name})
3016 3211
3017 my $row = 0; 3212 my $row = 0;
3018 for my $item (@items) { 3213 for my $item (@items) {
3019 CFClient::Item::update_widgets $item; 3214 CFClient::Item::update_widgets $item;
3020 3215
3021 $self->{scrolled}->add (0, $row, $item->{face_widget}); 3216 $self->{child}->add (0, $row, $item->{face_widget});
3022 $self->{scrolled}->add (1, $row, $item->{desc_widget}); 3217 $self->{child}->add (1, $row, $item->{desc_widget});
3023 $self->{scrolled}->add (2, $row, $item->{weight_widget}); 3218 $self->{child}->add (2, $row, $item->{weight_widget});
3024 3219
3025 $row++; 3220 $row++;
3026 } 3221 }
3027} 3222}
3028 3223
3126 $rec = $::CONN->stop_record if $::CONN; 3321 $rec = $::CONN->stop_record if $::CONN;
3127 return unless ref $rec eq 'ARRAY'; 3322 return unless ref $rec eq 'ARRAY';
3128 $self->set_command_list ($rec); 3323 $self->set_command_list ($rec);
3129} 3324}
3130 3325
3131# if $commit is true, the binding will be set after the user entered a key combo 3326
3327sub ask_for_bind_and_commit {
3328 my ($self) = @_;
3329 $self->ask_for_bind (1);
3330}
3331
3132sub ask_for_bind { 3332sub ask_for_bind {
3133 my ($self, $commit) = @_; 3333 my ($self, $commit) = @_;
3134 3334
3135 CFClient::Binder::open_binding_dialog (sub { 3335 CFClient::Binder::open_binding_dialog (sub {
3136 my ($mod, $sym) = @_; 3336 my ($mod, $sym) = @_;
3220 3420
3221############################################################################# 3421#############################################################################
3222 3422
3223package CFClient::UI::SpellList; 3423package CFClient::UI::SpellList;
3224 3424
3225our @ISA = CFClient::UI::FancyFrame::; 3425our @ISA = CFClient::UI::Table::;
3226 3426
3227sub new { 3427sub new {
3228 my $class = shift; 3428 my $class = shift;
3229 3429
3230 my $self = $class->SUPER::new (binding => [], commands => [], @_); 3430 my $self = $class->SUPER::new (
3231 3431 binding => [],
3232 $self->add (new CFClient::UI::ScrolledWindow 3432 commands => [],
3233 scrolled => $self->{spellbox} = new CFClient::UI::Table); 3433 @_,
3234 3434 )
3235 $self;
3236} 3435}
3237 3436
3238# XXX: Do sorting? Argl... 3437# XXX: Do sorting? Argl...
3239sub add_spell { 3438sub add_spell {
3240 my ($self, $spell) = @_; 3439 my ($self, $spell) = @_;
3241 $self->{spells}->{$spell->{name}} = $spell; 3440 $self->{spells}->{$spell->{name}} = $spell;
3242 3441
3243 $self->{spellbox}->add (0, $self->{tbl_idx}, new CFClient::UI::Face 3442 $self->add (0, $self->{tbl_idx}, new CFClient::UI::Face
3244 face => $spell->{face}, 3443 face => $spell->{face},
3245 can_hover => 1, 3444 can_hover => 1,
3246 can_events => 1, 3445 can_events => 1,
3247 tooltip => $spell->{message}); 3446 tooltip => $spell->{message});
3248 3447
3249 $self->{spellbox}->add (1, $self->{tbl_idx}, new CFClient::UI::Label 3448 $self->add (1, $self->{tbl_idx}, new CFClient::UI::Label
3250 text => $spell->{name}, 3449 text => $spell->{name},
3251 can_hover => 1, 3450 can_hover => 1,
3252 can_events => 1, 3451 can_events => 1,
3253 tooltip => $spell->{message}, 3452 tooltip => $spell->{message},
3254 expand => 1); 3453 expand => 1);
3255 3454
3256 $self->{spellbox}->add (2, $self->{tbl_idx}, new CFClient::UI::Label 3455 $self->add (2, $self->{tbl_idx}, new CFClient::UI::Label
3257 text => (sprintf "lvl: %2d sp: %2d dmg: %2d", 3456 text => (sprintf "lvl: %2d sp: %2d dmg: %2d",
3258 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}), 3457 $spell->{level}, ($spell->{mana} || $spell->{grace}), $spell->{damage}),
3259 expand => 1); 3458 expand => 1);
3260 3459
3261 $self->{spellbox}->add (3, $self->{tbl_idx}++, new CFClient::UI::Button 3460 $self->add (3, $self->{tbl_idx}++, new CFClient::UI::Button
3262 text => "bind to key", 3461 text => "bind to key",
3263 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) }); 3462 on_activate => sub { $::BIND_EDITOR->do_quick_binding (["cast $spell->{name}"]) });
3264} 3463}
3265 3464
3266sub rebuild_spell_list { 3465sub rebuild_spell_list {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines