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.271 by root, Fri Jun 2 22:13:47 2006 UTC

439 439
440 $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus 440 $::MAPWIDGET->focus_in #d# focus mapwidget if no other widget has focus
441 unless $FOCUS; 441 unless $FOCUS;
442} 442}
443 443
444sub mouse_motion { } 444sub mouse_motion { 0 }
445sub button_up { } 445sub button_up { 0 }
446sub key_down { } 446sub key_down { 0 }
447sub key_up { } 447sub key_up { 0 }
448 448
449sub button_down { 449sub button_down {
450 my ($self, $ev, $x, $y) = @_; 450 my ($self, $ev, $x, $y) = @_;
451 451
452 $self->focus_in; 452 $self->focus_in;
453
454 0
453} 455}
454 456
455sub find_widget { 457sub find_widget {
456 my ($self, $x, $y) = @_; 458 my ($self, $x, $y) = @_;
457 459
1050my @border = 1052my @border =
1051 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1053 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); 1054 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1053 1055
1054sub new { 1056sub new {
1055 my $class = shift; 1057 my ($class, %arg) = @_;
1058
1059 my $title = delete $arg{title};
1056 1060
1057 my $self = $class->SUPER::new ( 1061 my $self = $class->SUPER::new (
1058 bg => [1, 1, 1, 1], 1062 bg => [1, 1, 1, 1],
1059 border_bg => [1, 1, 1, 1], 1063 border_bg => [1, 1, 1, 1],
1060 border => 0.6, 1064 border => 0.6,
1061 can_events => 1, 1065 can_events => 1,
1062 min_w => 16, 1066 min_w => 16,
1063 min_h => 16, 1067 min_h => 16,
1064 @_ 1068 %arg,
1065 ); 1069 );
1066 1070
1067 $self->{title} &&= new CFClient::UI::Label 1071 $self->{title} = new CFClient::UI::Label
1068 align => 0, 1072 align => 0,
1069 valign => 1, 1073 valign => 1,
1070 text => $self->{title}, 1074 text => $title,
1071 fontsize => $self->{border}; 1075 fontsize => $self->{border}
1076 if defined $title;
1072 1077
1073 $self 1078 $self
1079}
1080
1081sub add {
1082 my ($self, @widgets) = @_;
1083
1084 $self->SUPER::add (@widgets);
1085 $self->CFClient::UI::Container::add ($self->{title}) if $self->{title};
1074} 1086}
1075 1087
1076sub border { 1088sub border {
1077 int $_[0]{border} * $::FONTSIZE 1089 int $_[0]{border} * $::FONTSIZE
1078} 1090}
1079 1091
1080sub size_request { 1092sub size_request {
1081 my ($self) = @_; 1093 my ($self) = @_;
1094
1095 $self->{title}->size_request
1096 if $self->{title};
1082 1097
1083 my ($w, $h) = $self->SUPER::size_request; 1098 my ($w, $h) = $self->SUPER::size_request;
1084 1099
1085 ( 1100 (
1086 $w + $self->border * 2, 1101 $w + $self->border * 2,
1089} 1104}
1090 1105
1091sub size_allocate { 1106sub size_allocate {
1092 my ($self, $w, $h) = @_; 1107 my ($self, $w, $h) = @_;
1093 1108
1109 if ($self->{title}) {
1110 $self->{title}{w} = $w;
1111 $self->{title}{h} = $h;
1112 $self->{title}->size_allocate ($w, $h);
1113 }
1114
1115 my $border = $self->border;
1116
1094 $h -= List::Util::max 0, $self->border * 2; 1117 $h -= List::Util::max 0, $border * 2;
1095 $w -= List::Util::max 0, $self->border * 2; 1118 $w -= List::Util::max 0, $border * 2;
1096 1119
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); 1120 $self->child->configure ($border, $border, $w, $h);
1101} 1121}
1102 1122
1103sub button_down { 1123sub button_down {
1104 my ($self, $ev, $x, $y) = @_; 1124 my ($self, $ev, $x, $y) = @_;
1105 1125
1139 1159
1140 ($x, $y) = ($ev->{x}, $ev->{y}); 1160 ($x, $y) = ($ev->{x}, $ev->{y});
1141 1161
1142 $self->move_abs ($bx + $x - $ox, $by + $y - $oy); 1162 $self->move_abs ($bx + $x - $ox, $by + $y - $oy);
1143 }; 1163 };
1164 } else {
1165 return 0;
1166 }
1167
1144 } 1168 1
1145} 1169}
1146 1170
1147sub button_up { 1171sub button_up {
1148 my ($self, $ev, $x, $y) = @_; 1172 my ($self, $ev, $x, $y) = @_;
1149 1173
1150 delete $self->{motion}; 1174 !!delete $self->{motion}
1151} 1175}
1152 1176
1153sub mouse_motion { 1177sub mouse_motion {
1154 my ($self, $ev, $x, $y) = @_; 1178 my ($self, $ev, $x, $y) = @_;
1155 1179
1156 $self->{motion}->($ev, $x, $y) if $self->{motion}; 1180 $self->{motion}->($ev, $x, $y) if $self->{motion};
1181
1182 !!$self->{motion}
1157} 1183}
1158 1184
1159sub _draw { 1185sub _draw {
1160 my ($self) = @_; 1186 my ($self) = @_;
1161 1187
1188 my $child = $self->{children}[0];
1189
1162 my ($w, $h ) = ($self->{w}, $self->{h}); 1190 my ($w, $h ) = ($self->{w}, $self->{h});
1163 my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); 1191 my ($cw, $ch) = ($child->{w}, $child->{h});
1164 1192
1165 glEnable GL_TEXTURE_2D; 1193 glEnable GL_TEXTURE_2D;
1166 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1194 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1167 1195
1168 my $border = $self->border; 1196 my $border = $self->border;
1183 $bg->draw_quad_alpha ($border, $border, $cw, $ch); 1211 $bg->draw_quad_alpha ($border, $border, $cw, $ch);
1184 } 1212 }
1185 1213
1186 glDisable GL_TEXTURE_2D; 1214 glDisable GL_TEXTURE_2D;
1187 1215
1188 $self->{title}->draw if $self->{title};
1189
1190 $self->child->draw; 1216 $child->draw;
1217
1218 if ($self->{title}) {
1219 glTranslate 0, $border - $self->{h};
1220 $self->{title}->_draw;
1221 }
1191} 1222}
1192 1223
1193############################################################################# 1224#############################################################################
1194 1225
1195package CFClient::UI::Table; 1226package CFClient::UI::Table;
1543} 1574}
1544 1575
1545sub size_allocate { 1576sub size_allocate {
1546 my ($self, $w, $h) = @_; 1577 my ($self, $w, $h) = @_;
1547 1578
1579 delete $self->{ox};
1580
1548 delete $self->{texture} 1581 delete $self->{texture}
1549 unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w}; 1582 unless $w >= $self->{req_w} && $self->{old_w} >= $self->{req_w};
1550} 1583}
1551 1584
1552sub set_fontsize { 1585sub set_fontsize {
1569 $self->{layout}->set_width ($self->{w}); 1602 $self->{layout}->set_width ($self->{w});
1570 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1603 $self->{layout}->set_ellipsise ($self->{ellipsise});
1571 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1604 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1572 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1605 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1573 1606
1574 my $tex = new_from_layout CFClient::Texture $self->{layout}; 1607 new_from_layout CFClient::Texture $self->{layout}
1608 };
1575 1609
1610 unless (exists $self->{ox}) {
1576 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} 1611 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x}
1577 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x} 1612 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding_x}
1578 : ($self->{w} - $tex->{w}) * 0.5); 1613 : ($self->{w} - $tex->{w}) * 0.5);
1579 1614
1580 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} 1615 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
1581 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y} 1616 : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding_y}
1582 : ($self->{h} - $tex->{h}) * 0.5); 1617 : ($self->{h} - $tex->{h}) * 0.5);
1583
1584 $tex
1585 }; 1618 };
1586 1619
1587 glEnable GL_TEXTURE_2D; 1620 glEnable GL_TEXTURE_2D;
1588 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1621 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1589 1622
1684 $self->{cursor} = length $text; 1717 $self->{cursor} = length $text;
1685 } elsif ($uni == 27) { 1718 } elsif ($uni == 27) {
1686 $self->_emit ('escape'); 1719 $self->_emit ('escape');
1687 } elsif ($uni) { 1720 } elsif ($uni) {
1688 substr $text, $self->{cursor}++, 0, chr $uni; 1721 substr $text, $self->{cursor}++, 0, chr $uni;
1722 } else {
1723 return 0;
1689 } 1724 }
1690 1725
1691 $self->_set_text ($text); 1726 $self->_set_text ($text);
1692 1727
1693 $self->realloc; 1728 $self->realloc;
1729
1730 1
1694} 1731}
1695 1732
1696sub focus_in { 1733sub focus_in {
1697 my ($self) = @_; 1734 my ($self) = @_;
1698 1735
1713 utf8::encode $text; 1750 utf8::encode $text;
1714 $self->{cursor} = length substr $text, 0, $idx; 1751 $self->{cursor} = length substr $text, 0, $idx;
1715 1752
1716 $self->_set_text ($self->{text}); 1753 $self->_set_text ($self->{text});
1717 $self->update; 1754 $self->update;
1755
1756 1
1718} 1757}
1719 1758
1720sub mouse_motion { 1759sub mouse_motion {
1721 my ($self, $ev, $x, $y) = @_; 1760 my ($self, $ev, $x, $y) = @_;
1722# printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# 1761# printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d#
1762
1763 0
1723} 1764}
1724 1765
1725sub _draw { 1766sub _draw {
1726 my ($self) = @_; 1767 my ($self) = @_;
1727 1768
1804 } else { 1845 } else {
1805 $self->set_text ($self->{history_saveback}); 1846 $self->set_text ($self->{history_saveback});
1806 } 1847 }
1807 1848
1808 } else { 1849 } else {
1809 $self->SUPER::key_down ($ev); 1850 return $self->SUPER::key_down ($ev)
1851 }
1852
1810 } 1853 1
1811
1812} 1854}
1813 1855
1814############################################################################# 1856#############################################################################
1815 1857
1816package CFClient::UI::Button; 1858package CFClient::UI::Button;
1845 my ($self, $ev, $x, $y) = @_; 1887 my ($self, $ev, $x, $y) = @_;
1846 1888
1847 $self->emit ("activate") 1889 $self->emit ("activate")
1848 if $x >= 0 && $x < $self->{w} 1890 if $x >= 0 && $x < $self->{w}
1849 && $y >= 0 && $y < $self->{h}; 1891 && $y >= 0 && $y < $self->{h};
1892
1893 1
1850} 1894}
1851 1895
1852sub _draw { 1896sub _draw {
1853 my ($self) = @_; 1897 my ($self) = @_;
1854 1898
1908 1952
1909 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} 1953 if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x}
1910 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { 1954 && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) {
1911 $self->{state} = !$self->{state}; 1955 $self->{state} = !$self->{state};
1912 $self->_emit (changed => $self->{state}); 1956 $self->_emit (changed => $self->{state});
1957 } else {
1958 return 0
1959 }
1960
1913 } 1961 1
1914} 1962}
1915 1963
1916sub _draw { 1964sub _draw {
1917 my ($self) = @_; 1965 my ($self) = @_;
1918 1966
2256 2304
2257 $self->SUPER::button_down ($ev, $x, $y); 2305 $self->SUPER::button_down ($ev, $x, $y);
2258 2306
2259 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; 2307 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x];
2260 2308
2261 $self->mouse_motion ($ev, $x, $y); 2309 $self->mouse_motion ($ev, $x, $y)
2262} 2310}
2263 2311
2264sub mouse_motion { 2312sub mouse_motion {
2265 my ($self, $ev, $x, $y) = @_; 2313 my ($self, $ev, $x, $y) = @_;
2266 2314
2270 my (undef, $lo, $hi, $page) = @{$self->{range}}; 2318 my (undef, $lo, $hi, $page) = @{$self->{range}};
2271 2319
2272 $x = ($x - $self->{click}[1]) / ($w * $self->{scale}); 2320 $x = ($x - $self->{click}[1]) / ($w * $self->{scale});
2273 2321
2274 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo)); 2322 $self->set_value ($self->{click}[0] + $x * ($hi - $page - $lo));
2323 } else {
2324 return 0;
2325 }
2326
2275 } 2327 1
2276} 2328}
2277 2329
2278sub update { 2330sub update {
2279 my ($self) = @_; 2331 my ($self) = @_;
2280 2332
2858 my ($self, $ev, $x, $y) = @_; 2910 my ($self, $ev, $x, $y) = @_;
2859 2911
2860 # TODO: should use vbox->find_widget or so 2912 # TODO: should use vbox->find_widget or so
2861 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y}); 2913 $HOVER = $ROOT->find_widget ($ev->{x}, $ev->{y});
2862 $self->{hover} = $self->{item}{$HOVER}; 2914 $self->{hover} = $self->{item}{$HOVER};
2915
2916 0
2863} 2917}
2864 2918
2865sub button_up { 2919sub button_up {
2866 my ($self, $ev, $x, $y) = @_; 2920 my ($self, $ev, $x, $y) = @_;
2867 2921
2869 undef $GRAB; 2923 undef $GRAB;
2870 $self->hide; 2924 $self->hide;
2871 2925
2872 $self->_emit ("popdown"); 2926 $self->_emit ("popdown");
2873 $self->{hover}[1]->() if $self->{hover}; 2927 $self->{hover}[1]->() if $self->{hover};
2928 } else {
2929 return 0
2930 }
2931
2874 } 2932 1
2875} 2933}
2876 2934
2877############################################################################# 2935#############################################################################
2878 2936
2879package CFClient::UI::Statusbox; 2937package CFClient::UI::Statusbox;
3126 $rec = $::CONN->stop_record if $::CONN; 3184 $rec = $::CONN->stop_record if $::CONN;
3127 return unless ref $rec eq 'ARRAY'; 3185 return unless ref $rec eq 'ARRAY';
3128 $self->set_command_list ($rec); 3186 $self->set_command_list ($rec);
3129} 3187}
3130 3188
3131# if $commit is true, the binding will be set after the user entered a key combo 3189
3190sub ask_for_bind_and_commit {
3191 my ($self) = @_;
3192 $self->ask_for_bind (1);
3193}
3194
3132sub ask_for_bind { 3195sub ask_for_bind {
3133 my ($self, $commit) = @_; 3196 my ($self, $commit) = @_;
3134 3197
3135 CFClient::Binder::open_binding_dialog (sub { 3198 CFClient::Binder::open_binding_dialog (sub {
3136 my ($mod, $sym) = @_; 3199 my ($mod, $sym) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines