… | |
… | |
1049 | xy_to_index (CFPlus::Layout self, int x, int y) |
1049 | xy_to_index (CFPlus::Layout self, int x, int y) |
1050 | CODE: |
1050 | CODE: |
1051 | { |
1051 | { |
1052 | int index, trailing; |
1052 | int index, trailing; |
1053 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1053 | pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); |
1054 | RETVAL = index; |
1054 | RETVAL = index + trailing; |
1055 | } |
1055 | } |
1056 | OUTPUT: |
1056 | OUTPUT: |
1057 | RETVAL |
1057 | RETVAL |
1058 | |
1058 | |
1059 | void |
1059 | void |
… | |
… | |
1065 | |
1065 | |
1066 | EXTEND (SP, 3); |
1066 | EXTEND (SP, 3); |
1067 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
1067 | PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); |
1068 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1068 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1069 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1069 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
|
|
1070 | } |
|
|
1071 | |
|
|
1072 | void |
|
|
1073 | index_to_line_x (CFPlus::Layout self, int index, int trailing = 0) |
|
|
1074 | PPCODE: |
|
|
1075 | { |
|
|
1076 | int line, x; |
|
|
1077 | |
|
|
1078 | pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x); |
|
|
1079 | /* pango bug: line is between 1..numlines, not 0..numlines-1 */ |
|
|
1080 | |
|
|
1081 | EXTEND (SP, 2); |
|
|
1082 | PUSHs (sv_2mortal (newSViv (line - 1))); |
|
|
1083 | PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE))); |
|
|
1084 | } |
|
|
1085 | |
|
|
1086 | void |
|
|
1087 | line_x_to_index (CFPlus::Layout self, int line, int x) |
|
|
1088 | PPCODE: |
|
|
1089 | { |
|
|
1090 | PangoLayoutLine *lp; |
|
|
1091 | int index, trailing; |
|
|
1092 | |
|
|
1093 | if (line < 0) |
|
|
1094 | XSRETURN_EMPTY; |
|
|
1095 | |
|
|
1096 | if (!(lp = pango_layout_get_line (self->pl, line))) |
|
|
1097 | XSRETURN_EMPTY; /* do better */ |
|
|
1098 | |
|
|
1099 | pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing); |
|
|
1100 | |
|
|
1101 | EXTEND (SP, 2); |
|
|
1102 | if (GIMME_V == G_SCALAR) |
|
|
1103 | PUSHs (sv_2mortal (newSViv (index + trailing))); |
|
|
1104 | else |
|
|
1105 | { |
|
|
1106 | PUSHs (sv_2mortal (newSViv (index))); |
|
|
1107 | PUSHs (sv_2mortal (newSViv (trailing))); |
|
|
1108 | } |
1070 | } |
1109 | } |
1071 | |
1110 | |
1072 | void |
1111 | void |
1073 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1112 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1074 | PPCODE: |
1113 | PPCODE: |
… | |
… | |
1168 | } |
1207 | } |
1169 | |
1208 | |
1170 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1209 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1171 | |
1210 | |
1172 | CFPlus::Map |
1211 | CFPlus::Map |
1173 | new (SV *class, int map_width, int map_height) |
1212 | new (SV *class) |
1174 | CODE: |
1213 | CODE: |
1175 | New (0, RETVAL, 1, struct map); |
1214 | New (0, RETVAL, 1, struct map); |
1176 | RETVAL->x = 0; |
1215 | RETVAL->x = 0; |
1177 | RETVAL->y = 0; |
1216 | RETVAL->y = 0; |
1178 | RETVAL->w = map_width; |
1217 | RETVAL->w = 0; |
1179 | RETVAL->h = map_height; |
1218 | RETVAL->h = 0; |
1180 | RETVAL->ox = 0; |
1219 | RETVAL->ox = 0; |
1181 | RETVAL->oy = 0; |
1220 | RETVAL->oy = 0; |
1182 | RETVAL->faces = 8192; |
1221 | RETVAL->faces = 8192; |
1183 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
1222 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
1184 | RETVAL->texs = 8192; |
1223 | RETVAL->texs = 8192; |
… | |
… | |
1195 | map_clear (self); |
1234 | map_clear (self); |
1196 | Safefree (self->face); |
1235 | Safefree (self->face); |
1197 | Safefree (self->tex); |
1236 | Safefree (self->tex); |
1198 | Safefree (self); |
1237 | Safefree (self); |
1199 | } |
1238 | } |
|
|
1239 | |
|
|
1240 | void |
|
|
1241 | resize (CFPlus::Map self, int map_width, int map_height) |
|
|
1242 | CODE: |
|
|
1243 | self->w = map_width; |
|
|
1244 | self->h = map_height; |
1200 | |
1245 | |
1201 | void |
1246 | void |
1202 | clear (CFPlus::Map self) |
1247 | clear (CFPlus::Map self) |
1203 | CODE: |
1248 | CODE: |
1204 | map_clear (self); |
1249 | map_clear (self); |
… | |
… | |
1444 | } |
1489 | } |
1445 | OUTPUT: |
1490 | OUTPUT: |
1446 | RETVAL |
1491 | RETVAL |
1447 | |
1492 | |
1448 | void |
1493 | void |
1449 | draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1494 | draw (CFPlus::Map self, int mx, int my, int sw, int sh) |
1450 | CODE: |
1495 | CODE: |
1451 | { |
1496 | { |
1452 | int vx, vy; |
|
|
1453 | int x, y, z; |
1497 | int x, y, z; |
1454 | int last_name; |
1498 | int last_name; |
1455 | mapface face; |
1499 | mapface face; |
1456 | |
|
|
1457 | vx = self->x + self->w / 2 - sw / 2 - shift_x; |
|
|
1458 | vy = self->y + self->h / 2 - sh / 2 - shift_y; |
|
|
1459 | |
|
|
1460 | /* |
|
|
1461 | int vx = self->vx = self->w >= sw |
|
|
1462 | ? self->x + (self->w - sw) / 2 |
|
|
1463 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
|
|
1464 | |
|
|
1465 | int vy = self->vy = self->h >= sh |
|
|
1466 | ? self->y + (self->h - sh) / 2 |
|
|
1467 | : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); |
|
|
1468 | */ |
|
|
1469 | |
1500 | |
1470 | glColor4ub (255, 255, 255, 255); |
1501 | glColor4ub (255, 255, 255, 255); |
1471 | |
1502 | |
1472 | glEnable (GL_BLEND); |
1503 | glEnable (GL_BLEND); |
1473 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1504 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
… | |
… | |
1476 | |
1507 | |
1477 | glBegin (GL_QUADS); |
1508 | glBegin (GL_QUADS); |
1478 | |
1509 | |
1479 | last_name = 0; |
1510 | last_name = 0; |
1480 | |
1511 | |
|
|
1512 | mx += self->x; |
|
|
1513 | my += self->y; |
|
|
1514 | |
1481 | for (z = 0; z < 3; z++) |
1515 | for (z = 0; z < 3; z++) |
1482 | for (y = 0; y < sh; y++) |
1516 | for (y = 0; y < sh; y++) |
1483 | if (0 <= y + vy && y + vy < self->rows) |
1517 | if (0 <= y + my && y + my < self->rows) |
1484 | { |
1518 | { |
1485 | maprow *row = self->row + (y + vy); |
1519 | maprow *row = self->row + (y + my); |
1486 | |
1520 | |
1487 | for (x = 0; x < sw; x++) |
1521 | for (x = 0; x < sw; x++) |
1488 | if (row->c0 <= x + vx && x + vx < row->c1) |
1522 | if (row->c0 <= x + mx && x + mx < row->c1) |
1489 | { |
1523 | { |
1490 | mapcell *cell = row->col + (x + vx - row->c0); |
1524 | mapcell *cell = row->col + (x + mx - row->c0); |
1491 | |
1525 | |
1492 | face = cell->face [z]; |
1526 | face = cell->face [z]; |
1493 | |
1527 | |
1494 | if (face && face < self->texs) |
1528 | if (face && face < self->texs) |
1495 | { |
1529 | { |
… | |
… | |
1536 | glDisable (GL_TEXTURE_2D); |
1570 | glDisable (GL_TEXTURE_2D); |
1537 | glDisable (GL_BLEND); |
1571 | glDisable (GL_BLEND); |
1538 | |
1572 | |
1539 | // top layer: overlays such as the health bar |
1573 | // top layer: overlays such as the health bar |
1540 | for (y = 0; y < sh; y++) |
1574 | for (y = 0; y < sh; y++) |
1541 | if (0 <= y + vy && y + vy < self->rows) |
1575 | if (0 <= y + my && y + my < self->rows) |
1542 | { |
1576 | { |
1543 | maprow *row = self->row + (y + vy); |
1577 | maprow *row = self->row + (y + my); |
1544 | |
1578 | |
1545 | for (x = 0; x < sw; x++) |
1579 | for (x = 0; x < sw; x++) |
1546 | if (row->c0 <= x + vx && x + vx < row->c1) |
1580 | if (row->c0 <= x + mx && x + mx < row->c1) |
1547 | { |
1581 | { |
1548 | mapcell *cell = row->col + (x + vx - row->c0); |
1582 | mapcell *cell = row->col + (x + mx - row->c0); |
1549 | |
1583 | |
1550 | int px = x * 32; |
1584 | int px = x * 32; |
1551 | int py = y * 32; |
1585 | int py = y * 32; |
1552 | |
1586 | |
1553 | if (cell->stat_hp) |
1587 | if (cell->stat_hp) |
… | |
… | |
1627 | glDisable (GL_BLEND); |
1661 | glDisable (GL_BLEND); |
1628 | glDisable (GL_TEXTURE_2D); |
1662 | glDisable (GL_TEXTURE_2D); |
1629 | } |
1663 | } |
1630 | |
1664 | |
1631 | void |
1665 | void |
1632 | fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1666 | fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) |
1633 | PPCODE: |
1667 | PPCODE: |
1634 | { |
1668 | { |
1635 | int vx, vy; |
|
|
1636 | int x, y; |
1669 | int x, y; |
1637 | int sw4 = (sw + 3) & ~3; |
1670 | int sw4 = (sw + 3) & ~3; |
1638 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
1671 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
1639 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
1672 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
1640 | |
1673 | |
1641 | memset (darkness, 255, sw4 * sh); |
1674 | memset (darkness, 255, sw4 * sh); |
1642 | SvPOK_only (darkness_sv); |
1675 | SvPOK_only (darkness_sv); |
1643 | SvCUR_set (darkness_sv, sw4 * sh); |
1676 | SvCUR_set (darkness_sv, sw4 * sh); |
1644 | |
1677 | |
1645 | vx = self->x + (self->w - sw + 1) / 2 - shift_x; |
1678 | mx += self->x; |
1646 | vy = self->y + (self->h - sh + 1) / 2 - shift_y; |
1679 | my += self->y; |
1647 | |
1680 | |
1648 | for (y = 0; y < sh; y++) |
1681 | for (y = 0; y < sh; y++) |
1649 | if (0 <= y + vy && y + vy < self->rows) |
1682 | if (0 <= y + my && y + my < self->rows) |
1650 | { |
1683 | { |
1651 | maprow *row = self->row + (y + vy); |
1684 | maprow *row = self->row + (y + my); |
1652 | |
1685 | |
1653 | for (x = 0; x < sw; x++) |
1686 | for (x = 0; x < sw; x++) |
1654 | if (row->c0 <= x + vx && x + vx < row->c1) |
1687 | if (row->c0 <= x + mx && x + mx < row->c1) |
1655 | { |
1688 | { |
1656 | mapcell *cell = row->col + (x + vx - row->c0); |
1689 | mapcell *cell = row->col + (x + mx - row->c0); |
1657 | |
1690 | |
1658 | darkness[y * sw4 + x] = cell->darkness |
1691 | darkness[y * sw4 + x] = cell->darkness |
1659 | ? 255 - (cell->darkness - 1) |
1692 | ? 255 - (cell->darkness - 1) |
1660 | : 255 - FOW_DARKNESS; |
1693 | : 255 - FOW_DARKNESS; |
1661 | } |
1694 | } |