… | |
… | |
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 { |
… | |
… | |
704 | |
710 | |
705 | $child->set_parent ($self); |
711 | $child->set_parent ($self); |
706 | $self->{children}[$y][$x] = $child; |
712 | $self->{children}[$y][$x] = $child; |
707 | |
713 | |
708 | $self->{w} = $self->{h} = -1; |
714 | $self->{w} = $self->{h} = -1; |
|
|
715 | $self->update; |
|
|
716 | } |
|
|
717 | |
|
|
718 | # TODO: move to container class maybe? send childs a signal on removal? |
|
|
719 | sub clear { |
|
|
720 | my ($self) = @_; |
|
|
721 | |
|
|
722 | delete $self->{children}; |
709 | $self->update; |
723 | $self->update; |
710 | } |
724 | } |
711 | |
725 | |
712 | sub get_wh { |
726 | sub get_wh { |
713 | my ($self) = @_; |
727 | my ($self) = @_; |
… | |
… | |
942 | my $self = $class->SUPER::new ( |
956 | my $self = $class->SUPER::new ( |
943 | fg => [1, 1, 1], |
957 | fg => [1, 1, 1], |
944 | fontsize => $::FONTSIZE, |
958 | fontsize => $::FONTSIZE, |
945 | text => "", |
959 | text => "", |
946 | align => -1, |
960 | align => -1, |
|
|
961 | valign => -1, |
947 | padding => 2, |
962 | padding => 2, |
948 | layout => new CFClient::Layout, |
963 | layout => new CFClient::Layout, |
949 | %arg |
964 | %arg |
950 | ); |
965 | ); |
951 | |
966 | |
952 | $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}; |
953 | |
971 | |
954 | $self |
972 | $self |
955 | } |
973 | } |
956 | |
974 | |
957 | sub escape_text { |
975 | sub escape_text { |
… | |
… | |
965 | } |
983 | } |
966 | |
984 | |
967 | sub set_text { |
985 | sub set_text { |
968 | my ($self, $text) = @_; |
986 | my ($self, $text) = @_; |
969 | |
987 | |
970 | $self->{text} = $text; |
|
|
971 | $self->{layout}->set_markup ($text); |
988 | $self->{layout}->set_text ($text); |
972 | |
989 | |
973 | delete $self->{texture}; |
990 | delete $self->{texture}; |
974 | # $self->{w} = $self->{h} = -1; |
|
|
975 | $self->update; |
991 | $self->update; |
976 | } |
992 | } |
977 | |
993 | |
978 | sub get_text { |
994 | sub set_markup { |
979 | my ($self, $text) = @_; |
995 | my ($self, $markup) = @_; |
980 | |
996 | |
981 | $self->{text} |
997 | $self->{layout}->set_markup ($markup); |
|
|
998 | |
|
|
999 | delete $self->{texture}; |
|
|
1000 | $self->update; |
982 | } |
1001 | } |
983 | |
1002 | |
984 | sub size_request { |
1003 | sub size_request { |
985 | my ($self) = @_; |
1004 | my ($self) = @_; |
986 | |
1005 | |
987 | $self->{layout}->set_width; |
1006 | $self->{layout}->set_width; |
988 | $self->{layout}->set_height ($self->{fontsize}); |
1007 | $self->{layout}->set_height ($self->{fontsize}); |
|
|
1008 | |
989 | my ($w, $h) = $self->{layout}->size; |
1009 | my ($w, $h) = $self->{layout}->size; |
990 | |
1010 | |
991 | ( |
1011 | ( |
992 | $w + $self->{padding} * 2, |
1012 | $w + $self->{padding} * 2, |
993 | $h + $self->{padding} * 2, |
1013 | $h + $self->{padding} * 2, |
… | |
… | |
1012 | sub _draw { |
1032 | sub _draw { |
1013 | my ($self) = @_; |
1033 | my ($self) = @_; |
1014 | |
1034 | |
1015 | my $tex = $self->{texture} ||= do { |
1035 | my $tex = $self->{texture} ||= do { |
1016 | $self->{layout}->set_width ($self->{w}); |
1036 | $self->{layout}->set_width ($self->{w}); |
1017 | $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}); |
1018 | new_from_layout CFClient::Texture $self->{layout} |
1038 | new_from_layout CFClient::Texture $self->{layout} |
1019 | }; |
1039 | }; |
1020 | |
1040 | |
1021 | glEnable GL_BLEND; |
1041 | glEnable GL_BLEND; |
1022 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1042 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
… | |
… | |
1028 | my $x = |
1048 | my $x = |
1029 | $self->{align} < 0 ? $self->{padding} |
1049 | $self->{align} < 0 ? $self->{padding} |
1030 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1050 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1031 | : ($self->{w} - $tex->{w}) * 0.5; |
1051 | : ($self->{w} - $tex->{w}) * 0.5; |
1032 | |
1052 | |
1033 | $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); |
1034 | |
1059 | |
1035 | glDisable GL_TEXTURE_2D; |
1060 | glDisable GL_TEXTURE_2D; |
1036 | glDisable GL_BLEND; |
1061 | glDisable GL_BLEND; |
1037 | } |
1062 | } |
1038 | |
1063 | |
1039 | ############################################################################# |
1064 | ############################################################################# |
1040 | |
1065 | |
1041 | package CFClient::UI::Entry; |
1066 | package CFClient::UI::EntryBase; |
1042 | |
1067 | |
1043 | our @ISA = CFClient::UI::Label::; |
1068 | our @ISA = CFClient::UI::Label::; |
1044 | |
1069 | |
1045 | use SDL; |
1070 | use SDL; |
1046 | use SDL::OpenGL; |
1071 | use SDL::OpenGL; |
… | |
… | |
1053 | bg => [0, 0, 0, 0.2], |
1078 | bg => [0, 0, 0, 0.2], |
1054 | active_bg => [1, 1, 1, 0.5], |
1079 | active_bg => [1, 1, 1, 0.5], |
1055 | active_fg => [0, 0, 0], |
1080 | active_fg => [0, 0, 0], |
1056 | can_hover => 1, |
1081 | can_hover => 1, |
1057 | can_focus => 1, |
1082 | can_focus => 1, |
|
|
1083 | valign => 0, |
1058 | @_ |
1084 | @_ |
1059 | ) |
1085 | ) |
1060 | } |
1086 | } |
1061 | |
1087 | |
1062 | sub _set_text { |
1088 | sub _set_text { |
1063 | my ($self, $text) = @_; |
1089 | my ($self, $text) = @_; |
1064 | |
1090 | |
1065 | my $old_text = $self->{text}; |
1091 | delete $self->{cur_h}; |
|
|
1092 | |
|
|
1093 | return if $self->{text} eq $text; |
1066 | |
1094 | |
1067 | $self->{last_activity} = $::NOW; |
1095 | $self->{last_activity} = $::NOW; |
1068 | |
|
|
1069 | $self->{text} = $text; |
1096 | $self->{text} = $text; |
1070 | $self->{layout}->set_width ($self->{w}); |
|
|
1071 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); |
|
|
1072 | |
1097 | |
1073 | $text =~ s/./*/g if $self->{hidden}; |
1098 | $text =~ s/./*/g if $self->{hidden}; |
|
|
1099 | $self->{layout}->set_text ("$text "); |
1074 | |
1100 | |
1075 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1101 | $self->emit (changed => $self->{text}); |
|
|
1102 | } |
1076 | |
1103 | |
1077 | $text = substr $text, 0, $self->{cursor}; |
1104 | sub get_text { |
1078 | utf8::encode $text; |
1105 | $_[0]{text} |
1079 | |
|
|
1080 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
|
|
1081 | |
|
|
1082 | $self->emit (changed => $self->{text}) # XXX: is this the right place to do this? |
|
|
1083 | if $old_text ne $self->{text}; |
|
|
1084 | } |
1106 | } |
1085 | |
1107 | |
1086 | sub size_request { |
1108 | sub size_request { |
1087 | my ($self) = @_; |
1109 | my ($self) = @_; |
1088 | |
1110 | |
… | |
… | |
1192 | |
1214 | |
1193 | $self->SUPER::_draw; |
1215 | $self->SUPER::_draw; |
1194 | |
1216 | |
1195 | #TODO: force update every cursor change :( |
1217 | #TODO: force update every cursor change :( |
1196 | 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 | |
1197 | glColor @{$self->{fg}}; |
1227 | glColor @{$self->{fg}}; |
1198 | glBegin GL_LINES; |
1228 | glBegin GL_LINES; |
1199 | glVertex $self->{cur_x}, $self->{cur_y}; |
1229 | glVertex $self->{cur_x}, $self->{cur_y}; |
1200 | glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; |
1230 | glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; |
1201 | glEnd; |
1231 | glEnd; |
1202 | } |
1232 | } |
1203 | } |
1233 | } |
1204 | |
1234 | |
1205 | package CFClient::UI::LineEntry; |
1235 | package CFClient::UI::Entry; |
1206 | |
1236 | |
1207 | our @ISA = CFClient::UI::Entry::; |
1237 | our @ISA = CFClient::UI::EntryBase::; |
1208 | |
1238 | |
1209 | use SDL; |
1239 | use SDL; |
1210 | use SDL::OpenGL; |
1240 | use SDL::OpenGL; |
1211 | |
1241 | |
1212 | sub key_down { |
1242 | sub key_down { |
… | |
… | |
1261 | |
1291 | |
1262 | sub _draw { |
1292 | sub _draw { |
1263 | my ($self) = @_; |
1293 | my ($self) = @_; |
1264 | |
1294 | |
1265 | local $self->{fg} = $self->{fg}; |
1295 | local $self->{fg} = $self->{fg}; |
1266 | my $tex = $tex[0]; |
|
|
1267 | |
|
|
1268 | glEnable GL_BLEND; |
|
|
1269 | glEnable GL_TEXTURE_2D; |
|
|
1270 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1271 | |
1296 | |
1272 | if ($GRAB == $self) { |
1297 | if ($GRAB == $self) { |
1273 | $self->{fg} = $self->{active_fg}; |
1298 | $self->{fg} = $self->{active_fg}; |
1274 | } |
1299 | } |
1275 | |
1300 | |
1276 | 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; |
1277 | 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; |
1278 | |
1306 | |
1279 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
1307 | $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h}); |
1280 | |
1308 | |
1281 | glDisable GL_TEXTURE_2D; |
1309 | glDisable GL_TEXTURE_2D; |
1282 | glDisable GL_BLEND; |
1310 | glDisable GL_BLEND; |
1283 | |
1311 | |
1284 | $self->SUPER::_draw; |
1312 | $self->SUPER::_draw; |
… | |
… | |
1766 | 0.1, 0.1, 0.1, |
1794 | 0.1, 0.1, 0.1, |
1767 | ; |
1795 | ; |
1768 | glEnable GL_CONVOLUTION_2D; |
1796 | glEnable GL_CONVOLUTION_2D; |
1769 | } |
1797 | } |
1770 | |
1798 | |
1771 | my $tex = new CFClient::Texture |
1799 | $self->{fow_texture} = new CFClient::Texture |
1772 | w => $w, |
1800 | w => $w, |
1773 | h => $h, |
1801 | h => $h, |
1774 | data => $data, |
1802 | data => $data, |
1775 | internalformat => GL_ALPHA, |
1803 | internalformat => GL_ALPHA, |
1776 | format => GL_ALPHA; |
1804 | format => GL_ALPHA; |
… | |
… | |
1781 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1809 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1782 | glEnable GL_TEXTURE_2D; |
1810 | glEnable GL_TEXTURE_2D; |
1783 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1811 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1784 | |
1812 | |
1785 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1813 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1786 | $tex->draw_quad (0, 0, $w * 32, $h * 32); |
1814 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
1787 | |
1815 | |
1788 | glDisable GL_TEXTURE_2D; |
1816 | glDisable GL_TEXTURE_2D; |
1789 | glDisable GL_BLEND; |
1817 | glDisable GL_BLEND; |
1790 | } |
1818 | } |
1791 | |
1819 | |
… | |
… | |
1797 | glEnable GL_BLEND; |
1825 | glEnable GL_BLEND; |
1798 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1826 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1799 | glEnable GL_TEXTURE_2D; |
1827 | glEnable GL_TEXTURE_2D; |
1800 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1828 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1801 | |
1829 | |
|
|
1830 | $self->{mapmap_texture} = |
1802 | CFClient::Texture->new ( |
1831 | new CFClient::Texture |
1803 | w => $w, |
1832 | w => $w, |
1804 | h => $h, |
1833 | h => $h, |
1805 | data => $::MAP->mapmap ($w, $h), |
1834 | data => $::MAP->mapmap ($w, $h), |
1806 | type => GL_UNSIGNED_INT_8_8_8_8_REV |
1835 | type => GL_UNSIGNED_INT_8_8_8_8_REV; |
1807 | )->draw_quad (100, 100); |
1836 | |
|
|
1837 | $self->{mapmap_texture}->draw_quad (100, 100); |
1808 | |
1838 | |
1809 | glDisable GL_TEXTURE_2D; |
1839 | glDisable GL_TEXTURE_2D; |
1810 | glDisable GL_BLEND; |
1840 | glDisable GL_BLEND; |
1811 | } |
1841 | } |
1812 | # HACK END |
1842 | # HACK END |
… | |
… | |
1960 | |
1990 | |
1961 | # TODO: use animation |
1991 | # TODO: use animation |
1962 | if ($self->{state} = !$self->{state}) { |
1992 | if ($self->{state} = !$self->{state}) { |
1963 | $CFClient::UI::ROOT->add ($self->{other}); |
1993 | $CFClient::UI::ROOT->add ($self->{other}); |
1964 | $self->{other}->move ($self->coord2global (0, $self->{h})); |
1994 | $self->{other}->move ($self->coord2global (0, $self->{h})); |
|
|
1995 | $self->emit ("open"); |
1965 | } else { |
1996 | } else { |
1966 | $CFClient::UI::ROOT->remove ($self->{other}); |
1997 | $CFClient::UI::ROOT->remove ($self->{other}); |
|
|
1998 | $self->emit ("close"); |
1967 | } |
1999 | } |
|
|
2000 | |
|
|
2001 | $self->emit (changed => $self->{state}); |
1968 | } |
2002 | } |
1969 | |
2003 | |
1970 | ############################################################################# |
2004 | ############################################################################# |
1971 | |
2005 | |
1972 | package CFClient::UI::Root; |
2006 | package CFClient::UI::Root; |
… | |
… | |
2004 | sub add { |
2038 | sub add { |
2005 | my ($self, $widget) = @_; |
2039 | my ($self, $widget) = @_; |
2006 | |
2040 | |
2007 | $self->SUPER::add ($widget); |
2041 | $self->SUPER::add ($widget); |
2008 | |
2042 | |
2009 | $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); |
2043 | $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request); |
2010 | } |
2044 | } |
2011 | |
2045 | |
2012 | sub on_refresh { |
2046 | sub on_refresh { |
2013 | my ($self, $id, $cb) = @_; |
2047 | my ($self, $id, $cb) = @_; |
2014 | |
2048 | |