… | |
… | |
205 | struct cf_layout { |
205 | struct cf_layout { |
206 | PangoLayout *pl; |
206 | PangoLayout *pl; |
207 | float r, g, b, a; // default color for rgba mode |
207 | float r, g, b, a; // default color for rgba mode |
208 | int base_height; |
208 | int base_height; |
209 | DC__Font font; |
209 | DC__Font font; |
210 | rc_t *rc; |
210 | rc_t rc; |
211 | }; |
211 | }; |
212 | |
212 | |
213 | typedef cf_layout *DC__Layout; |
213 | typedef cf_layout *DC__Layout; |
214 | |
214 | |
215 | static DC__Font default_font; |
215 | static DC__Font default_font; |
… | |
… | |
1369 | tc_restore (); |
1369 | tc_restore (); |
1370 | |
1370 | |
1371 | DC::Layout |
1371 | DC::Layout |
1372 | new (SV *klass) |
1372 | new (SV *klass) |
1373 | CODE: |
1373 | CODE: |
1374 | New (0, RETVAL, 1, struct cf_layout); |
1374 | RETVAL = new cf_layout; |
1375 | |
1375 | |
1376 | RETVAL->pl = pango_layout_new (opengl_context); |
1376 | RETVAL->pl = pango_layout_new (opengl_context); |
1377 | RETVAL->r = 1.; |
1377 | RETVAL->r = 1.; |
1378 | RETVAL->g = 1.; |
1378 | RETVAL->g = 1.; |
1379 | RETVAL->b = 1.; |
1379 | RETVAL->b = 1.; |
1380 | RETVAL->a = 1.; |
1380 | RETVAL->a = 1.; |
1381 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1381 | RETVAL->base_height = MIN_FONT_HEIGHT; |
1382 | RETVAL->font = 0; |
1382 | RETVAL->font = 0; |
1383 | RETVAL->rc = rc_alloc (); |
|
|
1384 | |
1383 | |
1385 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1384 | pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); |
1386 | layout_update_font (RETVAL); |
1385 | layout_update_font (RETVAL); |
1387 | OUTPUT: |
1386 | OUTPUT: |
1388 | RETVAL |
1387 | RETVAL |
1389 | |
1388 | |
1390 | void |
1389 | void |
1391 | DESTROY (DC::Layout self) |
1390 | DESTROY (DC::Layout self) |
1392 | CODE: |
1391 | CODE: |
1393 | g_object_unref (self->pl); |
1392 | g_object_unref (self->pl); |
1394 | rc_free (self->rc); |
|
|
1395 | Safefree (self); |
1393 | delete self; |
1396 | |
1394 | |
1397 | void |
1395 | void |
1398 | set_text (DC::Layout self, SV *text_) |
1396 | set_text (DC::Layout self, SV *text_) |
1399 | CODE: |
1397 | CODE: |
1400 | { |
1398 | { |
… | |
… | |
1654 | } |
1652 | } |
1655 | |
1653 | |
1656 | void |
1654 | void |
1657 | render (DC::Layout self, float x, float y, int flags = 0) |
1655 | render (DC::Layout self, float x, float y, int flags = 0) |
1658 | CODE: |
1656 | CODE: |
1659 | rc_clear (self->rc); |
1657 | self->rc.clear (); |
1660 | pango_opengl_render_layout_subpixel ( |
1658 | pango_opengl_render_layout_subpixel ( |
1661 | self->pl, |
1659 | self->pl, |
1662 | self->rc, |
1660 | &self->rc, |
1663 | x * PANGO_SCALE, y * PANGO_SCALE, |
1661 | x * PANGO_SCALE, y * PANGO_SCALE, |
1664 | self->r, self->g, self->b, self->a, |
1662 | self->r, self->g, self->b, self->a, |
1665 | flags |
1663 | flags |
1666 | ); |
1664 | ); |
1667 | // we assume that context_change actually clears/frees stuff |
1665 | // we assume that context_change actually clears/frees stuff |
… | |
… | |
1678 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
1676 | gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
1679 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
1677 | GL_ONE , GL_ONE_MINUS_SRC_ALPHA); |
1680 | glEnable (GL_ALPHA_TEST); |
1678 | glEnable (GL_ALPHA_TEST); |
1681 | glAlphaFunc (GL_GREATER, 7.f / 255.f); |
1679 | glAlphaFunc (GL_GREATER, 7.f / 255.f); |
1682 | |
1680 | |
1683 | rc_draw (self->rc); |
1681 | self->rc.draw (); |
1684 | |
1682 | |
1685 | glDisable (GL_ALPHA_TEST); |
1683 | glDisable (GL_ALPHA_TEST); |
1686 | glDisable (GL_BLEND); |
1684 | glDisable (GL_BLEND); |
1687 | glDisable (GL_TEXTURE_2D); |
1685 | glDisable (GL_TEXTURE_2D); |
1688 | } |
1686 | } |
… | |
… | |
2227 | int x, y, z; |
2225 | int x, y, z; |
2228 | |
2226 | |
2229 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static! |
2227 | static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static! |
2230 | int pl_x, pl_y; |
2228 | int pl_x, pl_y; |
2231 | maptex pl_tex; |
2229 | maptex pl_tex; |
2232 | rc_t *rc = rc_alloc (); |
2230 | rc_t rc; |
2233 | rc_t *rc_ov = rc_alloc (); |
2231 | rc_t rc_ov; |
2234 | rc_key_t key; |
2232 | rc_key_t key; |
2235 | rc_array_t *arr; |
2233 | rc_t::array_t *arr; |
2236 | |
2234 | |
2237 | pl_tex.name = 0; |
2235 | pl_tex.name = 0; |
2238 | |
2236 | |
2239 | // that's current max. sorry. |
2237 | // that's current max. sorry. |
2240 | if (sw > 255) sw = 255; |
2238 | if (sw > 255) sw = 255; |
… | |
… | |
2306 | |
2304 | |
2307 | if (!tex.name) |
2305 | if (!tex.name) |
2308 | tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ |
2306 | tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ |
2309 | |
2307 | |
2310 | key.texname = tex.name; |
2308 | key.texname = tex.name; |
2311 | arr = rc_array (rc, &key); |
2309 | arr = &rc.array (key); |
2312 | } |
2310 | } |
2313 | |
2311 | |
2314 | px = (x + 1) * Th - tex.w; |
2312 | px = (x + 1) * Th - tex.w; |
2315 | py = (y + 1) * Tw - tex.h; |
2313 | py = (y + 1) * Tw - tex.h; |
2316 | |
2314 | |
… | |
… | |
2320 | pl_y = py; |
2318 | pl_y = py; |
2321 | pl_tex = tex; |
2319 | pl_tex = tex; |
2322 | continue; |
2320 | continue; |
2323 | } |
2321 | } |
2324 | |
2322 | |
2325 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2323 | arr->t2f_v3f (0 , 0 , px , py , 0); |
2326 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
2324 | arr->t2f_v3f (0 , tex.t, px , py + tex.h, 0); |
2327 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
2325 | arr->t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0); |
2328 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
2326 | arr->t2f_v3f (tex.s, 0 , px + tex.w, py , 0); |
2329 | |
2327 | |
2330 | // update smooth hash |
2328 | // update smooth hash |
2331 | if (tex.smoothtile) |
2329 | if (tex.smoothtile) |
2332 | { |
2330 | { |
2333 | skey.tile = tex.smoothtile; |
2331 | skey.tile = tex.smoothtile; |
… | |
… | |
2371 | { |
2369 | { |
2372 | // overlays such as the speech bubble, probably more to come |
2370 | // overlays such as the speech bubble, probably more to come |
2373 | if (cell->flags & 1) |
2371 | if (cell->flags & 1) |
2374 | { |
2372 | { |
2375 | rc_key_t key_ov = key; |
2373 | rc_key_t key_ov = key; |
2376 | maptex tex = self->tex [TEXID_SPEECH]; |
2374 | maptex tex = self->tex[TEXID_SPEECH]; |
2377 | rc_array_t *arr; |
|
|
2378 | int px = x * Tw + Tw * 2 / 32; |
2375 | int px = x * Tw + Tw * 2 / 32; |
2379 | int py = y * Th - Th * 6 / 32; |
2376 | int py = y * Th - Th * 6 / 32; |
2380 | |
2377 | |
2381 | key_ov.texname = tex.name; |
2378 | key_ov.texname = tex.name; |
2382 | arr = rc_array (rc_ov, &key_ov); |
2379 | rc_t::array_t &arr = rc_ov.array (key_ov); |
2383 | |
2380 | |
2384 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2381 | arr.t2f_v3f (0 , 0 , px , py , 0); |
2385 | rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); |
2382 | arr.t2f_v3f (0 , tex.t, px , py + Th, 0); |
2386 | rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0); |
2383 | arr.t2f_v3f (tex.s, tex.t, px + Tw, py + Th, 0); |
2387 | rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); |
2384 | arr.t2f_v3f (tex.s, 0 , px + Tw, py , 0); |
2388 | } |
2385 | } |
2389 | } |
2386 | } |
2390 | } |
2387 | } |
2391 | } |
2388 | } |
2392 | |
2389 | |
2393 | rc_draw (rc); |
2390 | rc.draw (); |
2394 | rc_clear (rc); |
2391 | rc.clear (); |
2395 | |
2392 | |
2396 | // go through all smoothlevels, lowest to highest, then draw. |
2393 | // go through all smoothlevels, lowest to highest, then draw. |
2397 | // this is basically counting sort |
2394 | // this is basically counting sort |
2398 | { |
2395 | { |
2399 | int w, b; |
2396 | int w, b; |
… | |
… | |
2466 | maptex tex = pl_tex; |
2463 | maptex tex = pl_tex; |
2467 | int px = pl_x + sdx; |
2464 | int px = pl_x + sdx; |
2468 | int py = pl_y + sdy; |
2465 | int py = pl_y + sdy; |
2469 | |
2466 | |
2470 | key.texname = tex.name; |
2467 | key.texname = tex.name; |
2471 | arr = rc_array (rc, &key); |
2468 | rc_t::array_t &arr = rc.array (key); |
2472 | |
2469 | |
2473 | rc_t2f_v3f (arr, 0 , 0 , px , py , 0); |
2470 | arr.t2f_v3f (0 , 0 , px , py , 0); |
2474 | rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); |
2471 | arr.t2f_v3f (0 , tex.t, px , py + tex.h, 0); |
2475 | rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); |
2472 | arr.t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0); |
2476 | rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); |
2473 | arr.t2f_v3f (tex.s, 0 , px + tex.w, py , 0); |
2477 | |
2474 | |
2478 | rc_draw (rc); |
2475 | rc.draw (); |
2479 | } |
2476 | } |
2480 | |
2477 | |
2481 | rc_draw (rc_ov); |
2478 | rc_ov.draw (); |
2482 | rc_clear (rc_ov); |
2479 | rc_ov.clear (); |
2483 | |
2480 | |
2484 | glDisable (GL_BLEND); |
2481 | glDisable (GL_BLEND); |
2485 | rc_free (rc); |
|
|
2486 | rc_free (rc_ov); |
|
|
2487 | |
2482 | |
2488 | // top layer: overlays such as the health bar |
2483 | // top layer: overlays such as the health bar |
2489 | for (y = 0; y < sh; y++) |
2484 | for (y = 0; y < sh; y++) |
2490 | if (0 <= y + my && y + my < self->rows) |
2485 | if (0 <= y + my && y + my < self->rows) |
2491 | { |
2486 | { |