… | |
… | |
133 | my ($self, $x, $y, $w, $h) = @_; |
133 | my ($self, $x, $y, $w, $h) = @_; |
134 | |
134 | |
135 | $self->_size_allocate ($x, $y, $w, $h); |
135 | $self->_size_allocate ($x, $y, $w, $h); |
136 | } |
136 | } |
137 | |
137 | |
138 | # translate global koordinates to local coordinate system |
138 | # translate global coordinates to local coordinate system |
139 | sub translate { |
139 | sub translate { |
140 | my ($self, $x, $y) = @_; |
140 | my ($self, $x, $y) = @_; |
141 | |
141 | |
142 | $self->{parent}->translate ($x - $self->{x}, $y - $self->{y}); |
142 | $self->{parent}->translate ($x - $self->{x}, $y - $self->{y}); |
143 | } |
143 | } |
… | |
… | |
637 | |
637 | |
638 | my $bg = $tex[0]; |
638 | my $bg = $tex[0]; |
639 | |
639 | |
640 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
640 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
641 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
641 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
642 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
|
|
643 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
|
|
644 | |
642 | |
645 | my $rep_x = $cw / $bg->{w}; |
643 | my $rep_x = $cw / $bg->{w}; |
646 | my $rep_y = $ch / $bg->{h}; |
644 | my $rep_y = $ch / $bg->{h}; |
647 | |
645 | |
648 | $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); |
646 | $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); |
… | |
… | |
743 | |
741 | |
744 | my $x = 0; |
742 | my $x = 0; |
745 | my $row_h = $hs->[$r]; |
743 | my $row_h = $hs->[$r]; |
746 | |
744 | |
747 | for my $c (0 .. $#$row) { |
745 | for my $c (0 .. $#$row) { |
748 | my $widget = $row->[$c] |
|
|
749 | or next; |
|
|
750 | |
|
|
751 | my $col_w = $ws->[$c]; |
746 | my $col_w = $ws->[$c]; |
752 | |
747 | |
|
|
748 | if (my $widget = $row->[$c]) { |
753 | $widget->size_allocate ($x, $y, $col_w, $row_h); |
749 | $widget->size_allocate ($x, $y, $col_w, $row_h); |
|
|
750 | } |
754 | |
751 | |
755 | $x += $col_w; |
752 | $x += $col_w; |
756 | } |
753 | } |
757 | |
754 | |
758 | $y += $row_h; |
755 | $y += $row_h; |
… | |
… | |
804 | } |
801 | } |
805 | |
802 | |
806 | sub size_allocate { |
803 | sub size_allocate { |
807 | my ($self, $x, $y, $w, $h) = @_; |
804 | my ($self, $x, $y, $w, $h) = @_; |
808 | |
805 | |
809 | $self->_size_allocate ($x, $y, $w, $h) or return; |
806 | $self->_size_allocate ($x, $y, $w, $h); |
810 | |
|
|
811 | return unless $self->{w}; |
|
|
812 | |
807 | |
813 | ($h, $w) = ($w, $h); |
808 | ($h, $w) = ($w, $h); |
814 | |
809 | |
815 | my $children = $self->{children}; |
810 | my $children = $self->{children}; |
816 | |
811 | |
… | |
… | |
864 | } |
859 | } |
865 | |
860 | |
866 | sub size_allocate { |
861 | sub size_allocate { |
867 | my ($self, $x, $y, $w, $h) = @_; |
862 | my ($self, $x, $y, $w, $h) = @_; |
868 | |
863 | |
869 | $self->_size_allocate ($x, $y, $w, $h) or return; |
864 | $self->_size_allocate ($x, $y, $w, $h); |
870 | |
|
|
871 | return unless $self->{h}; |
|
|
872 | |
865 | |
873 | my $children = $self->{children}; |
866 | my $children = $self->{children}; |
874 | |
867 | |
875 | my @h = map +($_->size_request)[1], @$children; |
868 | my @h = map +($_->size_request)[1], @$children; |
876 | |
869 | |
… | |
… | |
941 | |
934 | |
942 | $self->{text} = $text; |
935 | $self->{text} = $text; |
943 | $self->{layout}->set_markup ($text); |
936 | $self->{layout}->set_markup ($text); |
944 | |
937 | |
945 | delete $self->{texture}; |
938 | delete $self->{texture}; |
|
|
939 | # $self->{w} = $self->{h} = -1; |
946 | $self->update; |
940 | $self->update; |
947 | } |
941 | } |
948 | |
942 | |
949 | sub get_text { |
943 | sub get_text { |
950 | my ($self, $text) = @_; |
944 | my ($self, $text) = @_; |
… | |
… | |
983 | sub _draw { |
977 | sub _draw { |
984 | my ($self) = @_; |
978 | my ($self) = @_; |
985 | |
979 | |
986 | my $tex = $self->{texture} ||= do { |
980 | my $tex = $self->{texture} ||= do { |
987 | $self->{layout}->set_width ($self->{w}); |
981 | $self->{layout}->set_width ($self->{w}); |
988 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{height}); |
982 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); |
989 | new_from_layout CFClient::Texture $self->{layout} |
983 | new_from_layout CFClient::Texture $self->{layout} |
990 | }; |
984 | }; |
991 | |
985 | |
992 | glEnable GL_BLEND; |
986 | glEnable GL_BLEND; |
993 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
987 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
… | |
… | |
999 | my $x = |
993 | my $x = |
1000 | $self->{align} < 0 ? $self->{padding} |
994 | $self->{align} < 0 ? $self->{padding} |
1001 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
995 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1002 | : ($self->{w} - $tex->{w}) * 0.5; |
996 | : ($self->{w} - $tex->{w}) * 0.5; |
1003 | |
997 | |
1004 | $tex->draw_quad ($x, $self->{padding}); |
998 | glTranslate $x, ($self->{h} - $tex->{h}) * 0.5, 0; |
|
|
999 | $tex->draw_quad (0, 0); |
1005 | |
1000 | |
1006 | glDisable GL_TEXTURE_2D; |
1001 | glDisable GL_TEXTURE_2D; |
1007 | glDisable GL_BLEND; |
1002 | glDisable GL_BLEND; |
1008 | } |
1003 | } |
1009 | |
1004 | |
… | |
… | |
1033 | |
1028 | |
1034 | $self->{last_activity} = $::NOW; |
1029 | $self->{last_activity} = $::NOW; |
1035 | |
1030 | |
1036 | $self->{text} = $text; |
1031 | $self->{text} = $text; |
1037 | $self->{layout}->set_width ($self->{w}); |
1032 | $self->{layout}->set_width ($self->{w}); |
|
|
1033 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); |
1038 | |
1034 | |
1039 | $text =~ s/./*/g if $self->{hidden}; |
1035 | $text =~ s/./*/g if $self->{hidden}; |
1040 | |
1036 | |
1041 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1037 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1042 | |
1038 | |
… | |
… | |
1170 | our @ISA = CFClient::UI::Label::; |
1166 | our @ISA = CFClient::UI::Label::; |
1171 | |
1167 | |
1172 | use SDL; |
1168 | use SDL; |
1173 | use SDL::OpenGL; |
1169 | use SDL::OpenGL; |
1174 | |
1170 | |
|
|
1171 | my @tex = |
|
|
1172 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1173 | qw(b1_button_active.png); |
|
|
1174 | |
1175 | sub new { |
1175 | sub new { |
1176 | my $class = shift; |
1176 | my $class = shift; |
1177 | |
1177 | |
1178 | $class->SUPER::new ( |
1178 | $class->SUPER::new ( |
1179 | padding => 4, |
1179 | padding => 4, |
1180 | fg => [1, 1, 1], |
1180 | fg => [1, 1, 1], |
1181 | bg => [1, 1, 1, 0.2], |
1181 | bg => [1, 1, 1, 0.2], |
1182 | active_bg => [0, 0, 0, 0.5], |
|
|
1183 | active_fg => [1, 1, 0], |
1182 | active_fg => [1, 1, 0], |
|
|
1183 | # active_bg => [0, 0, 0, 0.5], |
1184 | border_fg => [1, 1, 0], |
1184 | # border_fg => [1, 1, 0], |
1185 | @_ |
1185 | @_ |
1186 | ) |
1186 | ) |
1187 | } |
1187 | } |
1188 | |
1188 | |
1189 | sub button_up { |
1189 | sub button_up { |
… | |
… | |
1197 | |
1197 | |
1198 | sub _draw { |
1198 | sub _draw { |
1199 | my ($self) = @_; |
1199 | my ($self) = @_; |
1200 | |
1200 | |
1201 | local $self->{fg} = $self->{fg}; |
1201 | local $self->{fg} = $self->{fg}; |
|
|
1202 | my $tex = $tex[0]; |
1202 | |
1203 | |
1203 | glEnable GL_BLEND; |
1204 | glEnable GL_BLEND; |
|
|
1205 | glEnable GL_TEXTURE_2D; |
1204 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1206 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1205 | |
1207 | |
1206 | glTranslate 0.375, 0.375, 0; # make line and polyogon coordinates behave similarly |
1208 | if ($GRAB == $self) { |
|
|
1209 | $self->{fg} = $self->{active_fg}; |
|
|
1210 | } |
|
|
1211 | |
|
|
1212 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
1213 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1214 | |
|
|
1215 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
|
|
1216 | |
|
|
1217 | glDisable GL_TEXTURE_2D; |
|
|
1218 | glDisable GL_BLEND; |
|
|
1219 | |
|
|
1220 | $self->SUPER::_draw; |
|
|
1221 | } |
|
|
1222 | |
|
|
1223 | ############################################################################# |
|
|
1224 | |
|
|
1225 | package CFClient::UI::CheckBox; |
|
|
1226 | |
|
|
1227 | our @ISA = CFClient::UI::DrawBG::; |
|
|
1228 | |
|
|
1229 | use SDL; |
|
|
1230 | use SDL::OpenGL; |
|
|
1231 | |
|
|
1232 | sub new { |
|
|
1233 | my $class = shift; |
|
|
1234 | |
|
|
1235 | $class->SUPER::new ( |
|
|
1236 | padding => 2, |
|
|
1237 | fg => [1, 1, 1], |
|
|
1238 | active_fg => [1, 1, 0], |
|
|
1239 | state => 0, |
|
|
1240 | @_ |
|
|
1241 | ) |
|
|
1242 | } |
|
|
1243 | |
|
|
1244 | sub size_request { |
|
|
1245 | my ($self) = @_; |
|
|
1246 | |
|
|
1247 | ($self->{padding} * 2 + 6) x 2 |
|
|
1248 | } |
|
|
1249 | |
|
|
1250 | sub size_allocate { |
|
|
1251 | my ($self, $x, $y, $w, $h) = @_; |
|
|
1252 | |
|
|
1253 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
1254 | } |
|
|
1255 | |
|
|
1256 | sub button_down { |
|
|
1257 | my ($self, $ev, $x, $y) = @_; |
|
|
1258 | |
|
|
1259 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
|
|
1260 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
|
|
1261 | $self->{state} = !$self->{state}; |
|
|
1262 | $self->emit (changed => $self->{state}); |
|
|
1263 | } |
|
|
1264 | } |
|
|
1265 | |
|
|
1266 | sub _draw { |
|
|
1267 | my ($self) = @_; |
|
|
1268 | |
|
|
1269 | $self->SUPER::_draw; |
|
|
1270 | |
|
|
1271 | glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0; |
|
|
1272 | |
|
|
1273 | my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; |
|
|
1274 | |
|
|
1275 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1207 | |
1276 | |
1208 | glBegin GL_LINE_LOOP; |
1277 | glBegin GL_LINE_LOOP; |
1209 | glColor @{$self->{border_fg}}; |
1278 | glVertex 0 , 0; |
1210 | glVertex 1 , 1; |
1279 | glVertex 0 , $s; |
1211 | glVertex 1 , $self->{h} - 2; |
1280 | glVertex $s, $s; |
1212 | glVertex $self->{w} - 2, $self->{h} - 2; |
1281 | glVertex $s, 0; |
1213 | glVertex $self->{w} - 2, 1; |
|
|
1214 | glEnd; |
1282 | glEnd; |
1215 | |
|
|
1216 | if ($GRAB == $self) { |
|
|
1217 | glColor @{$self->{active_bg}}; |
|
|
1218 | $self->{fg} = $self->{active_fg}; |
|
|
1219 | } else { |
|
|
1220 | glColor @{$self->{bg}}; |
|
|
1221 | } |
|
|
1222 | |
1283 | |
1223 | glBegin GL_QUADS; |
1284 | if ($self->{state}) { |
1224 | glVertex 2 , 2; |
1285 | glBegin GL_LINES; |
1225 | glVertex 2 , $self->{h} - 2; |
1286 | glVertex 0 , 0; |
1226 | glVertex $self->{w} - 2, $self->{h} - 2; |
1287 | glVertex $s, $s; |
1227 | glVertex $self->{w} - 2, 2; |
1288 | glVertex $s, 0; |
|
|
1289 | glVertex 0 , $s; |
1228 | glEnd; |
1290 | glEnd; |
1229 | glDisable GL_BLEND; |
1291 | } |
1230 | |
|
|
1231 | $self->SUPER::_draw; |
|
|
1232 | } |
1292 | } |
1233 | |
1293 | |
1234 | ############################################################################# |
1294 | ############################################################################# |
1235 | |
1295 | |
1236 | package CFClient::UI::Slider; |
1296 | package CFClient::UI::Slider; |
… | |
… | |
1318 | $value = int +($value - $lo) * $w / ($hi - $lo); |
1378 | $value = int +($value - $lo) * $w / ($hi - $lo); |
1319 | |
1379 | |
1320 | $w -= $page; |
1380 | $w -= $page; |
1321 | $page &= ~1; |
1381 | $page &= ~1; |
1322 | glTranslate $page * 0.5, 0, 0; |
1382 | glTranslate $page * 0.5, 0, 0; |
|
|
1383 | $page ||= 2; |
1323 | |
1384 | |
1324 | glColor @$fg; |
1385 | glColor @$fg; |
1325 | glBegin GL_LINES; |
1386 | glBegin GL_LINES; |
1326 | glVertex 0, 0; glVertex 0, $h; |
1387 | glVertex 0, 0; glVertex 0, $h; |
1327 | glVertex $w - 1, 0; glVertex $w - 1, $h; |
1388 | glVertex $w - 1, 0; glVertex $w - 1, $h; |
… | |
… | |
1422 | |
1483 | |
1423 | glEnable GL_TEXTURE_2D; |
1484 | glEnable GL_TEXTURE_2D; |
1424 | glEnable GL_BLEND; |
1485 | glEnable GL_BLEND; |
1425 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1486 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1426 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1487 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1488 | glColor 1, 1, 1, 1; |
1427 | |
1489 | |
1428 | my $sw4 = ($sw + 3) & ~3; |
1490 | my $sw4 = ($sw + 3) & ~3; |
1429 | my $darkness = "\x00" x ($sw4 * $sh); |
1491 | my $darkness = "\x00" x ($sw4 * $sh); |
1430 | |
1492 | |
1431 | for my $x (0 .. $sw - 1) { |
1493 | for my $x (0 .. $sw - 1) { |
… | |
… | |
1479 | |
1541 | |
1480 | glEndList; |
1542 | glEndList; |
1481 | } |
1543 | } |
1482 | |
1544 | |
1483 | glCallList $self->{list}; |
1545 | glCallList $self->{list}; |
|
|
1546 | |
|
|
1547 | if ($FOCUS != $self) { |
|
|
1548 | glEnable GL_BLEND; |
|
|
1549 | glColor 0, 0, 1, 0.4; |
|
|
1550 | glBegin GL_QUADS; |
|
|
1551 | glVertex 0, 0; |
|
|
1552 | glVertex 0, $::HEIGHT; |
|
|
1553 | glVertex $::WIDTH, $::HEIGHT; |
|
|
1554 | glVertex $::WIDTH, 0; |
|
|
1555 | glEnd; |
|
|
1556 | glDisable GL_BLEND; |
|
|
1557 | } |
1484 | } |
1558 | } |
1485 | |
1559 | |
1486 | my %DIR = ( |
1560 | my %DIR = ( |
1487 | SDLK_KP8, [1, "north"], |
1561 | SDLK_KP8, [1, "north"], |
1488 | SDLK_KP9, [2, "northeast"], |
1562 | SDLK_KP9, [2, "northeast"], |
… | |
… | |
1505 | my $mod = $ev->key_mod; |
1579 | my $mod = $ev->key_mod; |
1506 | my $sym = $ev->key_sym; |
1580 | my $sym = $ev->key_sym; |
1507 | |
1581 | |
1508 | if ($sym == SDLK_KP5) { |
1582 | if ($sym == SDLK_KP5) { |
1509 | $::CONN->send ("command stay fire"); |
1583 | $::CONN->send ("command stay fire"); |
|
|
1584 | } elsif ($sym == SDLK_a) { |
|
|
1585 | $::CONN->send ("command apply"); |
1510 | } elsif (exists $DIR{$sym}) { |
1586 | } elsif (exists $DIR{$sym}) { |
1511 | if ($mod & KMOD_SHIFT) { |
1587 | if ($mod & KMOD_SHIFT) { |
1512 | $self->{shft}++; |
1588 | $self->{shft}++; |
1513 | $::CONN->send ("command fire $DIR{$sym}[0]"); |
1589 | $::CONN->send ("command fire $DIR{$sym}[0]"); |
1514 | } elsif ($mod & KMOD_CTRL) { |
1590 | } elsif ($mod & KMOD_CTRL) { |