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.81 by root, Wed Apr 12 00:40:45 2006 UTC vs.
Revision 1.96 by root, Fri Apr 14 00:15:52 2006 UTC

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
139sub translate { 139sub 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
806sub size_allocate { 803sub 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
866sub size_allocate { 861sub 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
1000 my $x = 993 my $x =
1001 $self->{align} < 0 ? $self->{padding} 994 $self->{align} < 0 ? $self->{padding}
1002 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 995 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
1003 : ($self->{w} - $tex->{w}) * 0.5; 996 : ($self->{w} - $tex->{w}) * 0.5;
1004 997
1005 $tex->draw_quad ($x, $self->{padding}); 998 glTranslate $x, ($self->{h} - $tex->{h}) * 0.5, 0;
999 $tex->draw_quad (0, 0);
1006 1000
1007 glDisable GL_TEXTURE_2D; 1001 glDisable GL_TEXTURE_2D;
1008 glDisable GL_BLEND; 1002 glDisable GL_BLEND;
1009} 1003}
1010 1004
1034 1028
1035 $self->{last_activity} = $::NOW; 1029 $self->{last_activity} = $::NOW;
1036 1030
1037 $self->{text} = $text; 1031 $self->{text} = $text;
1038 $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});
1039 1034
1040 $text =~ s/./*/g if $self->{hidden}; 1035 $text =~ s/./*/g if $self->{hidden};
1041 1036
1042 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1037 $self->{layout}->set_markup ($self->escape_text ($text) . " ");
1043 1038
1171our @ISA = CFClient::UI::Label::; 1166our @ISA = CFClient::UI::Label::;
1172 1167
1173use SDL; 1168use SDL;
1174use SDL::OpenGL; 1169use SDL::OpenGL;
1175 1170
1171my @tex =
1172 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1173 qw(b1_button_active.png);
1174
1176sub new { 1175sub new {
1177 my $class = shift; 1176 my $class = shift;
1178 1177
1179 $class->SUPER::new ( 1178 $class->SUPER::new (
1180 padding => 4, 1179 padding => 4,
1181 fg => [1, 1, 1], 1180 fg => [1, 1, 1],
1182 bg => [1, 1, 1, 0.2], 1181 bg => [1, 1, 1, 0.2],
1183 active_bg => [0, 0, 0, 0.5],
1184 active_fg => [1, 1, 0], 1182 active_fg => [1, 1, 0],
1183# active_bg => [0, 0, 0, 0.5],
1185 border_fg => [1, 1, 0], 1184# border_fg => [1, 1, 0],
1186 @_ 1185 @_
1187 ) 1186 )
1188} 1187}
1189 1188
1190sub button_up { 1189sub button_up {
1198 1197
1199sub _draw { 1198sub _draw {
1200 my ($self) = @_; 1199 my ($self) = @_;
1201 1200
1202 local $self->{fg} = $self->{fg}; 1201 local $self->{fg} = $self->{fg};
1202 my $tex = $tex[0];
1203 1203
1204 glEnable GL_BLEND; 1204 glEnable GL_BLEND;
1205 glEnable GL_TEXTURE_2D;
1205 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1206 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1206 1207
1207 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
1225package CFClient::UI::CheckBox;
1226
1227our @ISA = CFClient::UI::DrawBG::;
1228
1229use SDL;
1230use SDL::OpenGL;
1231
1232sub 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
1244sub size_request {
1245 my ($self) = @_;
1246
1247 ($self->{padding} * 2 + 6) x 2
1248}
1249
1250sub size_allocate {
1251 my ($self, $x, $y, $w, $h) = @_;
1252
1253 $self->_size_allocate ($x, $y, $w, $h);
1254}
1255
1256sub 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
1266sub _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} };
1208 1276
1209 glBegin GL_LINE_LOOP; 1277 glBegin GL_LINE_LOOP;
1210 glColor @{$self->{border_fg}}; 1278 glVertex 0 , 0;
1211 glVertex 1 , 1; 1279 glVertex 0 , $s;
1212 glVertex 1 , $self->{h} - 2; 1280 glVertex $s, $s;
1213 glVertex $self->{w} - 2, $self->{h} - 2; 1281 glVertex $s, 0;
1214 glVertex $self->{w} - 2, 1;
1215 glEnd; 1282 glEnd;
1216
1217 if ($GRAB == $self) {
1218 glColor @{$self->{active_bg}};
1219 $self->{fg} = $self->{active_fg};
1220 } else {
1221 glColor @{$self->{bg}};
1222 }
1223 1283
1224 glBegin GL_QUADS; 1284 if ($self->{state}) {
1225 glVertex 2 , 2; 1285 glBegin GL_LINES;
1226 glVertex 2 , $self->{h} - 2; 1286 glVertex 0 , 0;
1227 glVertex $self->{w} - 2, $self->{h} - 2; 1287 glVertex $s, $s;
1228 glVertex $self->{w} - 2, 2; 1288 glVertex $s, 0;
1289 glVertex 0 , $s;
1229 glEnd; 1290 glEnd;
1230 glDisable GL_BLEND; 1291 }
1231
1232 $self->SUPER::_draw;
1233} 1292}
1234 1293
1235############################################################################# 1294#############################################################################
1236 1295
1237package CFClient::UI::Slider; 1296package CFClient::UI::Slider;
1395} 1454}
1396 1455
1397sub draw { 1456sub draw {
1398 my ($self) = @_; 1457 my ($self) = @_;
1399 1458
1459 $self->{need_update}++;#d#
1400 if (delete $self->{need_update}) { 1460 if (delete $self->{need_update}) {
1401 glNewList $self->{list}, GL_COMPILE; 1461 glNewList $self->{list}, GL_COMPILE;
1402 1462
1403 my $mx = $::CONN->{mapx};
1404 my $my = $::CONN->{mapy};
1405
1406 my $map = $::CONN->{map};
1407
1408 my ($xofs, $yofs);
1409
1410 my $sw = 1 + int $::WIDTH / 32; 1463 my $sw = int $::WIDTH / 32;
1411 my $sh = 1 + int $::HEIGHT / 32; 1464 my $sh = int $::HEIGHT / 32;
1412 1465
1413 if ($::CONN->{mapw} > $sw) { 1466 if ($::MAP) {
1414 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; 1467 my ($w, $h, $data) = $::MAP->draw (0, 0, $sw, $sh);
1415 } else {
1416 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs};
1417 }
1418 1468
1419 if ($::CONN->{maph} > $sh) { 1469 if ($::CFG->{fow_enable}) {
1420 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; 1470 if ($::CFG->{fow_smooth}) { # smooth fog of war
1421 } else { 1471 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER;
1422 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; 1472 glConvolutionFilter2D
1423 } 1473 GL_CONVOLUTION_2D,
1424 1474 GL_ALPHA,
1425 glEnable GL_TEXTURE_2D; 1475 3, 3,
1426 glEnable GL_BLEND; 1476 GL_ALPHA, GL_FLOAT,
1427 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1477 pack "f*",
1428 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1478 0.1, 0.1, 0.1,
1429 1479 0.1, 0.2, 0.1,
1430 my $sw4 = ($sw + 3) & ~3; 1480 0.1, 0.1, 0.1,
1431 my $darkness = "\x00" x ($sw4 * $sh);
1432
1433 for my $x (0 .. $sw - 1) {
1434 my $row = $map->[$x + $xofs];
1435 for my $y (0 .. $sh - 1) {
1436
1437 my $cell = $row->[$y + $yofs]
1438 or next; 1481 ;
1439 1482 glEnable GL_CONVOLUTION_2D;
1440 my $dark = $cell->[0];
1441 if ($dark < 0) {
1442 substr $darkness, $y * $sw4 + $x, 1, chr 224;
1443 } else {
1444 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark;
1445 } 1483 }
1446 1484
1447 for my $num (grep $_, @$cell[1,2,3]) { 1485 my $tex = new CFClient::Texture
1448 my $tex = $::CONN->{face}[$num]{texture} || next; 1486 w => $w,
1449 1487 h => $h,
1450 my ($w, $h) = @$tex{qw(w h)}; 1488 data => $data,
1489 internalformat => GL_ALPHA,
1490 format => GL_ALPHA;
1451 1491
1452 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); 1492 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
1453 } 1493
1494 glEnable GL_BLEND;
1495 glEnable GL_TEXTURE_2D;
1496 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1497
1498 glColor +($::CFG->{fow_intensity}) x 3, 1;
1499 $tex->draw_quad (0, 0, $w * 32, $h * 32);
1500
1501 glDisable GL_TEXTURE_2D;
1502 glDisable GL_BLEND;
1454 } 1503 }
1455 } 1504 }
1456 1505
1457# if (1) { # higher quality darkness 1506 glEndList;
1458# $lighting =~ s/(.)/$1$1$1/gs;
1459# my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3;
1460#
1461# $pb = $pb->scale_simple ($sw4 * 0.5, $sh * 0.5, "bilinear");
1462#
1463# $lighting = $pb->get_pixels;
1464# $lighting =~ s/(.)../$1/gs;
1465# } 1507 }
1466 1508
1467 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1509 glCallList $self->{list};
1468 1510
1469 $darkness = new CFClient::Texture 1511 if ($FOCUS != $self) {
1470 w => $sw4, 1512 glEnable GL_BLEND;
1471 h => $sh, 1513 glColor 0, 0, 1, 0.4;
1472 data => $darkness, 1514 glBegin GL_QUADS;
1473 internalformat => GL_ALPHA, 1515 glVertex 0, 0;
1474 format => GL_ALPHA; 1516 glVertex 0, $::HEIGHT;
1475 1517 glVertex $::WIDTH, $::HEIGHT;
1476 glColor 0.45, 0.45, 0.45, 1; 1518 glVertex $::WIDTH, 0;
1477 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); 1519 glEnd;
1478
1479 glDisable GL_TEXTURE_2D;
1480 glDisable GL_BLEND; 1520 glDisable GL_BLEND;
1481
1482 glEndList;
1483 } 1521 }
1484
1485 glCallList $self->{list};
1486} 1522}
1487 1523
1488my %DIR = ( 1524my %DIR = (
1489 SDLK_KP8, [1, "north"], 1525 SDLK_KP8, [1, "north"],
1490 SDLK_KP9, [2, "northeast"], 1526 SDLK_KP9, [2, "northeast"],
1506 1542
1507 my $mod = $ev->key_mod; 1543 my $mod = $ev->key_mod;
1508 my $sym = $ev->key_sym; 1544 my $sym = $ev->key_sym;
1509 1545
1510 if ($sym == SDLK_KP5) { 1546 if ($sym == SDLK_KP5) {
1511 $::CONN->send ("command stay fire"); 1547 $::CONN->user_send ("command stay fire");
1548 } elsif ($sym == SDLK_a) {
1549 $::CONN->user_send ("command apply");
1512 } elsif (exists $DIR{$sym}) { 1550 } elsif (exists $DIR{$sym}) {
1513 if ($mod & KMOD_SHIFT) { 1551 if ($mod & KMOD_SHIFT) {
1514 $self->{shft}++; 1552 $self->{shft}++;
1515 $::CONN->send ("command fire $DIR{$sym}[0]"); 1553 $::CONN->user_send ("command fire $DIR{$sym}[0]");
1516 } elsif ($mod & KMOD_CTRL) { 1554 } elsif ($mod & KMOD_CTRL) {
1517 $self->{ctrl}++; 1555 $self->{ctrl}++;
1518 $::CONN->send ("command run $DIR{$sym}[0]"); 1556 $::CONN->user_send ("command run $DIR{$sym}[0]");
1519 } else { 1557 } else {
1520 $::CONN->send ("command $DIR{$sym}[1]"); 1558 $::CONN->user_send ("command $DIR{$sym}[1]");
1521 } 1559 }
1522 } 1560 }
1523} 1561}
1524 1562
1525sub key_up { 1563sub key_up {
1527 1565
1528 my $mod = $ev->key_mod; 1566 my $mod = $ev->key_mod;
1529 my $sym = $ev->key_sym; 1567 my $sym = $ev->key_sym;
1530 1568
1531 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { 1569 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
1532 $::CONN->send ("command fire_stop"); 1570 $::CONN->user_send ("command fire_stop");
1533 } 1571 }
1534 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { 1572 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
1535 $::CONN->send ("command run_stop"); 1573 $::CONN->user_send ("command run_stop");
1536 } 1574 }
1537} 1575}
1538 1576
1539############################################################################# 1577#############################################################################
1540 1578
1578 glPopMatrix; 1616 glPopMatrix;
1579} 1617}
1580 1618
1581############################################################################# 1619#############################################################################
1582 1620
1621package CFClient::UI::Flopper;
1622
1623our @ISA = CFClient::UI::Button::;
1624
1625sub new {
1626 my $class = shift;
1627
1628 my $self = $class->SUPER::new (
1629 state => 0,
1630 connect_activate => \&toggle_flopper,
1631 @_
1632 );
1633
1634 if ($self->{state}) {
1635 $self->{state} = 0;
1636 $self->toggle_flopper;
1637 }
1638
1639 $self
1640}
1641
1642sub toggle_flopper {
1643 my ($self) = @_;
1644
1645 if ($self->{state} = !$self->{state}) {
1646 $CFClient::UI::TOPLEVEL->add ($self->{other});
1647 $self->{other}->move (
1648 ($::WIDTH - $self->{other}{w}) * 0.5,
1649 ($::HEIGHT - $self->{other}{h}) * 0.5,
1650 );
1651 } else {
1652 $CFClient::UI::TOPLEVEL->remove ($self->{other});
1653 }
1654}
1655
1656#############################################################################
1657
1583package CFClient::UI::Toplevel; 1658package CFClient::UI::Toplevel;
1584 1659
1585our @ISA = CFClient::UI::Container::; 1660our @ISA = CFClient::UI::Container::;
1586 1661
1587sub size_request { 1662sub size_request {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines