… | |
… | |
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 | |
… | |
… | |
1028 | my $x = |
1043 | my $x = |
1029 | $self->{align} < 0 ? $self->{padding} |
1044 | $self->{align} < 0 ? $self->{padding} |
1030 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1045 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1031 | : ($self->{w} - $tex->{w}) * 0.5; |
1046 | : ($self->{w} - $tex->{w}) * 0.5; |
1032 | |
1047 | |
1033 | $tex->draw_quad (int $x, int +($self->{h} - $tex->{h}) * 0.5); |
1048 | my $y = |
|
|
1049 | $self->{valign} < 0 ? $self->{padding} |
|
|
1050 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
|
|
1051 | : ($self->{h} - $tex->{h}) * 0.5; |
|
|
1052 | |
|
|
1053 | $tex->draw_quad (int $x, int $y); |
1034 | |
1054 | |
1035 | glDisable GL_TEXTURE_2D; |
1055 | glDisable GL_TEXTURE_2D; |
1036 | glDisable GL_BLEND; |
1056 | glDisable GL_BLEND; |
1037 | } |
1057 | } |
1038 | |
1058 | |
… | |
… | |
1053 | bg => [0, 0, 0, 0.2], |
1073 | bg => [0, 0, 0, 0.2], |
1054 | active_bg => [1, 1, 1, 0.5], |
1074 | active_bg => [1, 1, 1, 0.5], |
1055 | active_fg => [0, 0, 0], |
1075 | active_fg => [0, 0, 0], |
1056 | can_hover => 1, |
1076 | can_hover => 1, |
1057 | can_focus => 1, |
1077 | can_focus => 1, |
|
|
1078 | valign => 0, |
1058 | @_ |
1079 | @_ |
1059 | ) |
1080 | ) |
1060 | } |
1081 | } |
1061 | |
1082 | |
1062 | sub _set_text { |
1083 | sub _set_text { |
… | |
… | |
1261 | |
1282 | |
1262 | sub _draw { |
1283 | sub _draw { |
1263 | my ($self) = @_; |
1284 | my ($self) = @_; |
1264 | |
1285 | |
1265 | local $self->{fg} = $self->{fg}; |
1286 | 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 | |
1287 | |
1272 | if ($GRAB == $self) { |
1288 | if ($GRAB == $self) { |
1273 | $self->{fg} = $self->{active_fg}; |
1289 | $self->{fg} = $self->{active_fg}; |
1274 | } |
1290 | } |
1275 | |
1291 | |
1276 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
1292 | glEnable GL_BLEND; |
|
|
1293 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1294 | glEnable GL_TEXTURE_2D; |
1277 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1295 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1296 | glColor 0, 0, 0, 1; |
1278 | |
1297 | |
1279 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
1298 | $tex[0]->draw_quad (0, 0, $self->{w}, $self->{h}); |
1280 | |
1299 | |
1281 | glDisable GL_TEXTURE_2D; |
1300 | glDisable GL_TEXTURE_2D; |
1282 | glDisable GL_BLEND; |
1301 | glDisable GL_BLEND; |
1283 | |
1302 | |
1284 | $self->SUPER::_draw; |
1303 | $self->SUPER::_draw; |
… | |
… | |
1766 | 0.1, 0.1, 0.1, |
1785 | 0.1, 0.1, 0.1, |
1767 | ; |
1786 | ; |
1768 | glEnable GL_CONVOLUTION_2D; |
1787 | glEnable GL_CONVOLUTION_2D; |
1769 | } |
1788 | } |
1770 | |
1789 | |
1771 | my $tex = new CFClient::Texture |
1790 | $self->{fow_texture} = new CFClient::Texture |
1772 | w => $w, |
1791 | w => $w, |
1773 | h => $h, |
1792 | h => $h, |
1774 | data => $data, |
1793 | data => $data, |
1775 | internalformat => GL_ALPHA, |
1794 | internalformat => GL_ALPHA, |
1776 | format => GL_ALPHA; |
1795 | format => GL_ALPHA; |
… | |
… | |
1781 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1800 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1782 | glEnable GL_TEXTURE_2D; |
1801 | glEnable GL_TEXTURE_2D; |
1783 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1802 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1784 | |
1803 | |
1785 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1804 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1786 | $tex->draw_quad (0, 0, $w * 32, $h * 32); |
1805 | $self->{fow_texture}->draw_quad (0, 0, $w * 32, $h * 32); |
1787 | |
1806 | |
1788 | glDisable GL_TEXTURE_2D; |
1807 | glDisable GL_TEXTURE_2D; |
1789 | glDisable GL_BLEND; |
1808 | glDisable GL_BLEND; |
1790 | } |
1809 | } |
1791 | |
1810 | |
… | |
… | |
1797 | glEnable GL_BLEND; |
1816 | glEnable GL_BLEND; |
1798 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1817 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1799 | glEnable GL_TEXTURE_2D; |
1818 | glEnable GL_TEXTURE_2D; |
1800 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1819 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1801 | |
1820 | |
|
|
1821 | $self->{mapmap_texture} = |
1802 | CFClient::Texture->new ( |
1822 | new CFClient::Texture |
1803 | w => $w, |
1823 | w => $w, |
1804 | h => $h, |
1824 | h => $h, |
1805 | data => $::MAP->mapmap ($w, $h), |
1825 | data => $::MAP->mapmap ($w, $h), |
1806 | type => GL_UNSIGNED_INT_8_8_8_8_REV |
1826 | type => GL_UNSIGNED_INT_8_8_8_8_REV; |
1807 | )->draw_quad (100, 100); |
1827 | |
|
|
1828 | $self->{mapmap_texture}->draw_quad (100, 100); |
1808 | |
1829 | |
1809 | glDisable GL_TEXTURE_2D; |
1830 | glDisable GL_TEXTURE_2D; |
1810 | glDisable GL_BLEND; |
1831 | glDisable GL_BLEND; |
1811 | } |
1832 | } |
1812 | # HACK END |
1833 | # HACK END |
… | |
… | |
2008 | sub add { |
2029 | sub add { |
2009 | my ($self, $widget) = @_; |
2030 | my ($self, $widget) = @_; |
2010 | |
2031 | |
2011 | $self->SUPER::add ($widget); |
2032 | $self->SUPER::add ($widget); |
2012 | |
2033 | |
2013 | $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); |
2034 | $widget->size_allocate (int $widget->{x}, int $widget->{y}, $widget->size_request); |
2014 | } |
2035 | } |
2015 | |
2036 | |
2016 | sub on_refresh { |
2037 | sub on_refresh { |
2017 | my ($self, $id, $cb) = @_; |
2038 | my ($self, $id, $cb) = @_; |
2018 | |
2039 | |