… | |
… | |
74 | sub harmonize { |
74 | sub harmonize { |
75 | my ($vals) = @_; |
75 | my ($vals) = @_; |
76 | |
76 | |
77 | my $rem = 0; |
77 | my $rem = 0; |
78 | |
78 | |
79 | for ($vals) { |
79 | for (@$vals) { |
80 | my $i = int $_ + $rem; |
80 | my $i = int $_ + $rem; |
81 | $rem += $_ - $i; |
81 | $rem += $_ - $i; |
82 | $_ = $i; |
82 | $_ = $i; |
83 | } |
83 | } |
84 | } |
84 | } |
… | |
… | |
112 | $self |
112 | $self |
113 | } |
113 | } |
114 | |
114 | |
115 | sub move { |
115 | sub move { |
116 | my ($self, $x, $y, $z) = @_; |
116 | my ($self, $x, $y, $z) = @_; |
117 | $self->{x} = $x; |
117 | $self->{x} = int $x; |
118 | $self->{y} = $y; |
118 | $self->{y} = int $y; |
119 | $self->{z} = $z if defined $z; |
119 | $self->{z} = $z if defined $z; |
120 | } |
120 | } |
121 | |
121 | |
122 | sub needs_redraw { |
122 | sub needs_redraw { |
123 | 0 |
123 | 0 |
… | |
… | |
176 | |
176 | |
177 | return if $FOCUS == $self; |
177 | return if $FOCUS == $self; |
178 | return unless $self->{can_focus}; |
178 | return unless $self->{can_focus}; |
179 | |
179 | |
180 | my $focus = $FOCUS; $FOCUS = $self; |
180 | my $focus = $FOCUS; $FOCUS = $self; |
|
|
181 | |
|
|
182 | $self->emit (focus_in => $focus); |
|
|
183 | |
181 | $focus->update if $focus; |
184 | $focus->update if $focus; |
182 | $FOCUS->update; |
185 | $FOCUS->update; |
183 | } |
186 | } |
184 | |
187 | |
185 | sub focus_out { |
188 | sub focus_out { |
186 | my ($self) = @_; |
189 | my ($self) = @_; |
187 | |
190 | |
188 | return unless $FOCUS == $self; |
191 | return unless $FOCUS == $self; |
189 | |
192 | |
190 | my $focus = $FOCUS; undef $FOCUS; |
193 | my $focus = $FOCUS; undef $FOCUS; |
|
|
194 | |
|
|
195 | $self->emit (focus_out => $focus); |
|
|
196 | |
191 | $focus->update if $focus; #? |
197 | $focus->update if $focus; #? |
192 | } |
198 | } |
193 | |
199 | |
194 | sub mouse_motion { } |
200 | sub mouse_motion { } |
195 | sub button_up { } |
201 | sub button_up { } |
… | |
… | |
565 | # TODO: user_x, user_y, overwrite moveto? |
571 | # TODO: user_x, user_y, overwrite moveto? |
566 | |
572 | |
567 | $class->SUPER::new ( |
573 | $class->SUPER::new ( |
568 | bg => [1, 1, 1, 1], |
574 | bg => [1, 1, 1, 1], |
569 | border_bg => [1, 1, 1, 1], |
575 | border_bg => [1, 1, 1, 1], |
570 | border => $::FONTSIZE * 0.8, |
576 | border => int $::FONTSIZE * 0.8, |
571 | @_ |
577 | @_ |
572 | ) |
578 | ) |
573 | } |
579 | } |
574 | |
580 | |
575 | sub size_request { |
581 | sub size_request { |
… | |
… | |
950 | my $self = $class->SUPER::new ( |
956 | my $self = $class->SUPER::new ( |
951 | fg => [1, 1, 1], |
957 | fg => [1, 1, 1], |
952 | fontsize => $::FONTSIZE, |
958 | fontsize => $::FONTSIZE, |
953 | text => "", |
959 | text => "", |
954 | align => -1, |
960 | align => -1, |
|
|
961 | valign => -1, |
955 | padding => 2, |
962 | padding => 2, |
956 | layout => new CFClient::Layout, |
963 | layout => new CFClient::Layout, |
957 | %arg |
964 | %arg |
958 | ); |
965 | ); |
959 | |
966 | |
960 | $self->set_text ($self->{text}); |
967 | $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# |
|
|
968 | |
|
|
969 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
|
|
970 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
961 | |
971 | |
962 | $self |
972 | $self |
963 | } |
973 | } |
964 | |
974 | |
965 | sub escape_text { |
975 | sub escape_text { |
… | |
… | |
973 | } |
983 | } |
974 | |
984 | |
975 | sub set_text { |
985 | sub set_text { |
976 | my ($self, $text) = @_; |
986 | my ($self, $text) = @_; |
977 | |
987 | |
978 | $self->{text} = $text; |
|
|
979 | $self->{layout}->set_markup ($text); |
988 | $self->{layout}->set_text ($text); |
980 | |
989 | |
981 | delete $self->{texture}; |
990 | delete $self->{texture}; |
982 | # $self->{w} = $self->{h} = -1; |
|
|
983 | $self->update; |
991 | $self->update; |
984 | } |
992 | } |
985 | |
993 | |
986 | sub get_text { |
994 | sub set_markup { |
987 | my ($self, $text) = @_; |
995 | my ($self, $markup) = @_; |
988 | |
996 | |
989 | $self->{text} |
997 | $self->{layout}->set_markup ($markup); |
|
|
998 | |
|
|
999 | delete $self->{texture}; |
|
|
1000 | $self->update; |
990 | } |
1001 | } |
991 | |
1002 | |
992 | sub size_request { |
1003 | sub size_request { |
993 | my ($self) = @_; |
1004 | my ($self) = @_; |
994 | |
1005 | |
995 | $self->{layout}->set_width; |
1006 | $self->{layout}->set_width; |
996 | $self->{layout}->set_height ($self->{fontsize}); |
1007 | $self->{layout}->set_height ($self->{fontsize}); |
|
|
1008 | |
997 | my ($w, $h) = $self->{layout}->size; |
1009 | my ($w, $h) = $self->{layout}->size; |
998 | |
1010 | |
999 | ( |
1011 | ( |
1000 | $w + $self->{padding} * 2, |
1012 | $w + $self->{padding} * 2, |
1001 | $h + $self->{padding} * 2, |
1013 | $h + $self->{padding} * 2, |
… | |
… | |
1020 | sub _draw { |
1032 | sub _draw { |
1021 | my ($self) = @_; |
1033 | my ($self) = @_; |
1022 | |
1034 | |
1023 | my $tex = $self->{texture} ||= do { |
1035 | my $tex = $self->{texture} ||= do { |
1024 | $self->{layout}->set_width ($self->{w}); |
1036 | $self->{layout}->set_width ($self->{w}); |
1025 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); |
1037 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize}); |
1026 | new_from_layout CFClient::Texture $self->{layout} |
1038 | new_from_layout CFClient::Texture $self->{layout} |
1027 | }; |
1039 | }; |
1028 | |
1040 | |
1029 | glEnable GL_BLEND; |
1041 | glEnable GL_BLEND; |
1030 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1042 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
… | |
… | |
1036 | my $x = |
1048 | my $x = |
1037 | $self->{align} < 0 ? $self->{padding} |
1049 | $self->{align} < 0 ? $self->{padding} |
1038 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1050 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1039 | : ($self->{w} - $tex->{w}) * 0.5; |
1051 | : ($self->{w} - $tex->{w}) * 0.5; |
1040 | |
1052 | |
1041 | $tex->draw_quad (int $x, int +($self->{h} - $tex->{h}) * 0.5); |
1053 | my $y = |
|
|
1054 | $self->{valign} < 0 ? $self->{padding} |
|
|
1055 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
|
|
1056 | : ($self->{h} - $tex->{h}) * 0.5; |
|
|
1057 | |
|
|
1058 | $tex->draw_quad (int $x, int $y); |
1042 | |
1059 | |
1043 | glDisable GL_TEXTURE_2D; |
1060 | glDisable GL_TEXTURE_2D; |
1044 | glDisable GL_BLEND; |
1061 | glDisable GL_BLEND; |
1045 | } |
1062 | } |
1046 | |
1063 | |
1047 | ############################################################################# |
1064 | ############################################################################# |
1048 | |
1065 | |
1049 | package CFClient::UI::Entry; |
1066 | package CFClient::UI::EntryBase; |
1050 | |
1067 | |
1051 | our @ISA = CFClient::UI::Label::; |
1068 | our @ISA = CFClient::UI::Label::; |
1052 | |
1069 | |
1053 | use SDL; |
1070 | use SDL; |
1054 | use SDL::OpenGL; |
1071 | use SDL::OpenGL; |
… | |
… | |
1061 | bg => [0, 0, 0, 0.2], |
1078 | bg => [0, 0, 0, 0.2], |
1062 | active_bg => [1, 1, 1, 0.5], |
1079 | active_bg => [1, 1, 1, 0.5], |
1063 | active_fg => [0, 0, 0], |
1080 | active_fg => [0, 0, 0], |
1064 | can_hover => 1, |
1081 | can_hover => 1, |
1065 | can_focus => 1, |
1082 | can_focus => 1, |
|
|
1083 | valign => 0, |
1066 | @_ |
1084 | @_ |
1067 | ) |
1085 | ) |
1068 | } |
1086 | } |
1069 | |
1087 | |
1070 | sub _set_text { |
1088 | sub _set_text { |
1071 | my ($self, $text) = @_; |
1089 | my ($self, $text) = @_; |
1072 | |
1090 | |
1073 | my $old_text = $self->{text}; |
1091 | delete $self->{cur_h}; |
|
|
1092 | |
|
|
1093 | return if $self->{text} eq $text; |
1074 | |
1094 | |
1075 | $self->{last_activity} = $::NOW; |
1095 | $self->{last_activity} = $::NOW; |
1076 | |
|
|
1077 | $self->{text} = $text; |
1096 | $self->{text} = $text; |
1078 | $self->{layout}->set_width ($self->{w}); |
|
|
1079 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); |
|
|
1080 | |
1097 | |
1081 | $text =~ s/./*/g if $self->{hidden}; |
1098 | $text =~ s/./*/g if $self->{hidden}; |
|
|
1099 | $self->{layout}->set_text ("$text "); |
1082 | |
1100 | |
1083 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1101 | $self->emit (changed => $self->{text}); |
|
|
1102 | } |
1084 | |
1103 | |
1085 | $text = substr $text, 0, $self->{cursor}; |
1104 | sub get_text { |
1086 | utf8::encode $text; |
1105 | $_[0]{text} |
1087 | |
|
|
1088 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
|
|
1089 | |
|
|
1090 | $self->emit (changed => $self->{text}) # XXX: is this the right place to do this? |
|
|
1091 | if $old_text ne $self->{text}; |
|
|
1092 | } |
1106 | } |
1093 | |
1107 | |
1094 | sub size_request { |
1108 | sub size_request { |
1095 | my ($self) = @_; |
1109 | my ($self) = @_; |
1096 | |
1110 | |
… | |
… | |
1200 | |
1214 | |
1201 | $self->SUPER::_draw; |
1215 | $self->SUPER::_draw; |
1202 | |
1216 | |
1203 | #TODO: force update every cursor change :( |
1217 | #TODO: force update every cursor change :( |
1204 | if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { |
1218 | if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { |
|
|
1219 | |
|
|
1220 | unless (exists $self->{cur_h}) { |
|
|
1221 | my $text = substr $self->{text}, 0, $self->{cursor}; |
|
|
1222 | utf8::encode $text; |
|
|
1223 | |
|
|
1224 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
|
|
1225 | } |
|
|
1226 | |
1205 | glColor @{$self->{fg}}; |
1227 | glColor @{$self->{fg}}; |
1206 | glBegin GL_LINES; |
1228 | glBegin GL_LINES; |
1207 | glVertex $self->{cur_x}, $self->{cur_y}; |
1229 | glVertex $self->{cur_x}, $self->{cur_y}; |
1208 | glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; |
1230 | glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; |
1209 | glEnd; |
1231 | glEnd; |
1210 | } |
1232 | } |
1211 | } |
1233 | } |
1212 | |
1234 | |
1213 | package CFClient::UI::LineEntry; |
1235 | package CFClient::UI::Entry; |
1214 | |
1236 | |
1215 | our @ISA = CFClient::UI::Entry::; |
1237 | our @ISA = CFClient::UI::EntryBase::; |
1216 | |
1238 | |
1217 | use SDL; |
1239 | use SDL; |
1218 | use SDL::OpenGL; |
1240 | use SDL::OpenGL; |
1219 | |
1241 | |
1220 | sub key_down { |
1242 | sub key_down { |
… | |
… | |
1269 | |
1291 | |
1270 | sub _draw { |
1292 | sub _draw { |
1271 | my ($self) = @_; |
1293 | my ($self) = @_; |
1272 | |
1294 | |
1273 | local $self->{fg} = $self->{fg}; |
1295 | local $self->{fg} = $self->{fg}; |
1274 | my $tex = $tex[0]; |
|
|
1275 | |
|
|
1276 | glEnable GL_BLEND; |
|
|
1277 | glEnable GL_TEXTURE_2D; |
|
|
1278 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1279 | |
1296 | |
1280 | if ($GRAB == $self) { |
1297 | if ($GRAB == $self) { |
1281 | $self->{fg} = $self->{active_fg}; |
1298 | $self->{fg} = $self->{active_fg}; |
1282 | } |
1299 | } |
1283 | |
1300 | |
1284 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
1301 | glEnable GL_BLEND; |
|
|
1302 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1303 | glEnable GL_TEXTURE_2D; |
1285 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1304 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1305 | glColor 0, 0, 0, 1; |
1286 | |
1306 | |
1287 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
1307 | $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h}); |
1288 | |
1308 | |
1289 | glDisable GL_TEXTURE_2D; |
1309 | glDisable GL_TEXTURE_2D; |
1290 | glDisable GL_BLEND; |
1310 | glDisable GL_BLEND; |
1291 | |
1311 | |
1292 | $self->SUPER::_draw; |
1312 | $self->SUPER::_draw; |
… | |
… | |
1774 | 0.1, 0.1, 0.1, |
1794 | 0.1, 0.1, 0.1, |
1775 | ; |
1795 | ; |
1776 | glEnable GL_CONVOLUTION_2D; |
1796 | glEnable GL_CONVOLUTION_2D; |
1777 | } |
1797 | } |
1778 | |
1798 | |
1779 | my $tex = new CFClient::Texture |
1799 | $self->{fow_texture} = new CFClient::Texture |
1780 | w => $w, |
1800 | w => $w, |
1781 | h => $h, |
1801 | h => $h, |
1782 | data => $data, |
1802 | data => $data, |
1783 | internalformat => GL_ALPHA, |
1803 | internalformat => GL_ALPHA, |
1784 | format => GL_ALPHA; |
1804 | format => GL_ALPHA; |
… | |
… | |
1789 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1809 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1790 | glEnable GL_TEXTURE_2D; |
1810 | glEnable GL_TEXTURE_2D; |
1791 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1811 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1792 | |
1812 | |
1793 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1813 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1794 | $tex->draw_quad (0, 0, $w * 32, $h * 32); |
1814 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
1795 | |
1815 | |
1796 | glDisable GL_TEXTURE_2D; |
1816 | glDisable GL_TEXTURE_2D; |
1797 | glDisable GL_BLEND; |
1817 | glDisable GL_BLEND; |
1798 | } |
1818 | } |
1799 | |
1819 | |
… | |
… | |
1805 | glEnable GL_BLEND; |
1825 | glEnable GL_BLEND; |
1806 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1826 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1807 | glEnable GL_TEXTURE_2D; |
1827 | glEnable GL_TEXTURE_2D; |
1808 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1828 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1809 | |
1829 | |
|
|
1830 | $self->{mapmap_texture} = |
1810 | CFClient::Texture->new ( |
1831 | new CFClient::Texture |
1811 | w => $w, |
1832 | w => $w, |
1812 | h => $h, |
1833 | h => $h, |
1813 | data => $::MAP->mapmap ($w, $h), |
1834 | data => $::MAP->mapmap ($w, $h), |
1814 | type => GL_UNSIGNED_INT_8_8_8_8_REV |
1835 | type => GL_UNSIGNED_INT_8_8_8_8_REV; |
1815 | )->draw_quad (100, 100); |
1836 | |
|
|
1837 | $self->{mapmap_texture}->draw_quad (100, 100); |
1816 | |
1838 | |
1817 | glDisable GL_TEXTURE_2D; |
1839 | glDisable GL_TEXTURE_2D; |
1818 | glDisable GL_BLEND; |
1840 | glDisable GL_BLEND; |
1819 | } |
1841 | } |
1820 | # HACK END |
1842 | # HACK END |
… | |
… | |
2016 | sub add { |
2038 | sub add { |
2017 | my ($self, $widget) = @_; |
2039 | my ($self, $widget) = @_; |
2018 | |
2040 | |
2019 | $self->SUPER::add ($widget); |
2041 | $self->SUPER::add ($widget); |
2020 | |
2042 | |
2021 | $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); |
2043 | $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request); |
2022 | } |
2044 | } |
2023 | |
2045 | |
2024 | sub on_refresh { |
2046 | sub on_refresh { |
2025 | my ($self, $id, $cb) = @_; |
2047 | my ($self, $id, $cb) = @_; |
2026 | |
2048 | |