Re: [AD] proposal: draw_sprite_*_ex |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
The example was left out the patch. Resending it.
--
Milan Mimica
http://sparklet.sf.net
Index: src/vtable24.c
===================================================================
--- src/vtable24.c (revision 9738)
+++ src/vtable24.c (working copy)
@@ -91,7 +91,11 @@
_soft_triangle3d,
_soft_triangle3d_f,
_soft_quad3d,
- _soft_quad3d_f
+ _soft_quad3d_f,
+ _linear_draw_sprite_ex24,
+ _linear_draw_sprite_h_flip_ex24,
+ _linear_draw_sprite_v_flip_ex24,
+ _linear_draw_sprite_vh_flip_ex24
};
Index: src/vtable16.c
===================================================================
--- src/vtable16.c (revision 9738)
+++ src/vtable16.c (working copy)
@@ -91,7 +91,11 @@
_soft_triangle3d,
_soft_triangle3d_f,
_soft_quad3d,
- _soft_quad3d_f
+ _soft_quad3d_f,
+ _linear_draw_sprite_ex16,
+ _linear_draw_sprite_h_flip_ex16,
+ _linear_draw_sprite_v_flip_ex16,
+ _linear_draw_sprite_vh_flip_ex16
};
Index: src/c/cdefs24.h
===================================================================
--- src/c/cdefs24.h (revision 9738)
+++ src/c/cdefs24.h (working copy)
@@ -24,6 +24,7 @@
#define PTR_PER_PIXEL 3
#define OFFSET_PIXEL_PTR(p,x) ((PIXEL_PTR) (p) + 3 * (x))
#define INC_PIXEL_PTR(p) ((p) += 3)
+#define INC_PIXEL_PTR_N(p,d) ((p) += 3 * d)
#define DEC_PIXEL_PTR(p) ((p) -= 3)
#define PUT_PIXEL(p,c) bmp_write24((uintptr_t) (p), (c))
@@ -48,6 +49,7 @@
#define DLS_BLENDER BLENDER_FUNC
#define MAKE_DLS_BLENDER(a) _blender_func24
#define DLS_BLEND(b,a,n) ((*(b))(_blender_col_24, (n), (a)))
+#define DLSX_BLEND(b,n) ((*(b))(_blender_col_24, (n), _blender_alpha))
/* Blender for RGBA sprites. */
#define RGBA_BLENDER BLENDER_FUNC
@@ -79,10 +81,14 @@
#define FUNC_LINEAR_VLINE _linear_vline24
#define FUNC_LINEAR_DRAW_SPRITE _linear_draw_sprite24
+#define FUNC_LINEAR_DRAW_SPRITE_EX _linear_draw_sprite_ex24
#define FUNC_LINEAR_DRAW_256_SPRITE _linear_draw_256_sprite24
#define FUNC_LINEAR_DRAW_SPRITE_V_FLIP _linear_draw_sprite_v_flip24
+#define FUNC_LINEAR_DRAW_SPRITE_V_FLIP_EX _linear_draw_sprite_v_flip_ex24
#define FUNC_LINEAR_DRAW_SPRITE_H_FLIP _linear_draw_sprite_h_flip24
+#define FUNC_LINEAR_DRAW_SPRITE_H_FLIP_EX _linear_draw_sprite_h_flip_ex24
#define FUNC_LINEAR_DRAW_SPRITE_VH_FLIP _linear_draw_sprite_vh_flip24
+#define FUNC_LINEAR_DRAW_SPRITE_VH_FLIP_EX _linear_draw_sprite_vh_flip_ex24
#define FUNC_LINEAR_DRAW_TRANS_SPRITE _linear_draw_trans_sprite24
#define FUNC_LINEAR_DRAW_TRANS_RGBA_SPRITE _linear_draw_trans_rgba_sprite24
#define FUNC_LINEAR_DRAW_LIT_SPRITE _linear_draw_lit_sprite24
Index: src/c/cdefs32.h
===================================================================
--- src/c/cdefs32.h (revision 9738)
+++ src/c/cdefs32.h (working copy)
@@ -24,6 +24,7 @@
#define PTR_PER_PIXEL 1
#define OFFSET_PIXEL_PTR(p,x) ((PIXEL_PTR) (p) + (x))
#define INC_PIXEL_PTR(p) ((p)++)
+#define INC_PIXEL_PTR_N(p,d) ((p) += d)
#define DEC_PIXEL_PTR(p) ((p)--)
#define PUT_PIXEL(p,c) bmp_write32((uintptr_t) (p), (c))
@@ -49,6 +50,7 @@
#define DLS_BLENDER BLENDER_FUNC
#define MAKE_DLS_BLENDER(a) _blender_func32
#define DLS_BLEND(b,a,n) ((*(b))(_blender_col_32, (n), (a)))
+#define DLSX_BLEND(b,n) ((*(b))(_blender_col_32, (n), _blender_alpha))
/* Blender for poly_scanline_*_lit. */
#define PS_BLENDER BLENDER_FUNC
@@ -75,10 +77,14 @@
#define FUNC_LINEAR_VLINE _linear_vline32
#define FUNC_LINEAR_DRAW_SPRITE _linear_draw_sprite32
+#define FUNC_LINEAR_DRAW_SPRITE_EX _linear_draw_sprite_ex32
#define FUNC_LINEAR_DRAW_256_SPRITE _linear_draw_256_sprite32
#define FUNC_LINEAR_DRAW_SPRITE_V_FLIP _linear_draw_sprite_v_flip32
+#define FUNC_LINEAR_DRAW_SPRITE_V_FLIP_EX _linear_draw_sprite_v_flip_ex32
#define FUNC_LINEAR_DRAW_SPRITE_H_FLIP _linear_draw_sprite_h_flip32
+#define FUNC_LINEAR_DRAW_SPRITE_H_FLIP_EX _linear_draw_sprite_h_flip_ex32
#define FUNC_LINEAR_DRAW_SPRITE_VH_FLIP _linear_draw_sprite_vh_flip32
+#define FUNC_LINEAR_DRAW_SPRITE_VH_FLIP_EX _linear_draw_sprite_vh_flip_ex32
#define FUNC_LINEAR_DRAW_TRANS_SPRITE _linear_draw_trans_sprite32
#define FUNC_LINEAR_DRAW_TRANS_RGBA_SPRITE _linear_draw_trans_rgba_sprite32
#define FUNC_LINEAR_DRAW_LIT_SPRITE _linear_draw_lit_sprite32
Index: src/c/cdefs15.h
===================================================================
--- src/c/cdefs15.h (revision 9738)
+++ src/c/cdefs15.h (working copy)
@@ -23,6 +23,7 @@
#define PIXEL_PTR unsigned short*
#define OFFSET_PIXEL_PTR(p,x) ((PIXEL_PTR) (p) + (x))
#define INC_PIXEL_PTR(p) ((p)++)
+#define INC_PIXEL_PTR_N(p,d) ((p) += d)
#define DEC_PIXEL_PTR(p) ((p)--)
#define PUT_PIXEL(p,c) bmp_write15((uintptr_t) (p), (c))
@@ -48,6 +49,7 @@
#define DLS_BLENDER BLENDER_FUNC
#define MAKE_DLS_BLENDER(a) _blender_func15
#define DLS_BLEND(b,a,n) ((*(b))(_blender_col_15, (n), (a)))
+#define DLSX_BLEND(b,n) ((*(b))(_blender_col_15, (n), _blender_alpha))
/* Blender for RGBA sprites. */
#define RGBA_BLENDER BLENDER_FUNC
@@ -79,10 +81,14 @@
#define FUNC_LINEAR_VLINE _linear_vline15
#define FUNC_LINEAR_DRAW_SPRITE _linear_draw_sprite15
+#define FUNC_LINEAR_DRAW_SPRITE_EX _linear_draw_sprite_ex15
#define FUNC_LINEAR_DRAW_256_SPRITE _linear_draw_256_sprite15
#define FUNC_LINEAR_DRAW_SPRITE_V_FLIP _linear_draw_sprite_v_flip15
+#define FUNC_LINEAR_DRAW_SPRITE_V_FLIP_EX _linear_draw_sprite_v_flip_ex15
#define FUNC_LINEAR_DRAW_SPRITE_H_FLIP _linear_draw_sprite_h_flip15
+#define FUNC_LINEAR_DRAW_SPRITE_H_FLIP_EX _linear_draw_sprite_h_flip_ex15
#define FUNC_LINEAR_DRAW_SPRITE_VH_FLIP _linear_draw_sprite_vh_flip15
+#define FUNC_LINEAR_DRAW_SPRITE_VH_FLIP_EX _linear_draw_sprite_vh_flip_ex15
#define FUNC_LINEAR_DRAW_TRANS_SPRITE _linear_draw_trans_sprite15
#define FUNC_LINEAR_DRAW_TRANS_RGBA_SPRITE _linear_draw_trans_rgba_sprite15
#define FUNC_LINEAR_DRAW_LIT_SPRITE _linear_draw_lit_sprite15
Index: src/c/cdefs16.h
===================================================================
--- src/c/cdefs16.h (revision 9738)
+++ src/c/cdefs16.h (working copy)
@@ -24,6 +24,7 @@
#define PTR_PER_PIXEL 1
#define OFFSET_PIXEL_PTR(p,x) ((PIXEL_PTR) (p) + (x))
#define INC_PIXEL_PTR(p) ((p)++)
+#define INC_PIXEL_PTR_N(p,d) ((p) += d)
#define DEC_PIXEL_PTR(p) ((p)--)
#define PUT_PIXEL(p,c) bmp_write16((uintptr_t) (p), (c))
@@ -49,6 +50,7 @@
#define DLS_BLENDER BLENDER_FUNC
#define MAKE_DLS_BLENDER(a) _blender_func16
#define DLS_BLEND(b,a,n) ((*(b))(_blender_col_16, (n), (a)))
+#define DLSX_BLEND(b,n) ((*(b))(_blender_col_16, (n), _blender_alpha))
/* Blender for RGBA sprites. */
#define RGBA_BLENDER BLENDER_FUNC
@@ -80,10 +82,14 @@
#define FUNC_LINEAR_VLINE _linear_vline16
#define FUNC_LINEAR_DRAW_SPRITE _linear_draw_sprite16
+#define FUNC_LINEAR_DRAW_SPRITE_EX _linear_draw_sprite_ex16
#define FUNC_LINEAR_DRAW_256_SPRITE _linear_draw_256_sprite16
#define FUNC_LINEAR_DRAW_SPRITE_V_FLIP _linear_draw_sprite_v_flip16
+#define FUNC_LINEAR_DRAW_SPRITE_V_FLIP_EX _linear_draw_sprite_v_flip_ex16
#define FUNC_LINEAR_DRAW_SPRITE_H_FLIP _linear_draw_sprite_h_flip16
+#define FUNC_LINEAR_DRAW_SPRITE_H_FLIP_EX _linear_draw_sprite_h_flip_ex16
#define FUNC_LINEAR_DRAW_SPRITE_VH_FLIP _linear_draw_sprite_vh_flip16
+#define FUNC_LINEAR_DRAW_SPRITE_VH_FLIP_EX _linear_draw_sprite_vh_flip_ex16
#define FUNC_LINEAR_DRAW_TRANS_SPRITE _linear_draw_trans_sprite16
#define FUNC_LINEAR_DRAW_TRANS_RGBA_SPRITE _linear_draw_trans_rgba_sprite16
#define FUNC_LINEAR_DRAW_LIT_SPRITE _linear_draw_lit_sprite16
Index: src/c/cspr.h
===================================================================
--- src/c/cspr.h (revision 9738)
+++ src/c/cspr.h (working copy)
@@ -18,6 +18,146 @@
#ifndef __bma_cspr_h
#define __bma_cspr_h
+
+/* _linear_draw_sprite_ex:
+ * Draws a masked sprite onto a linear bitmap at the specified dx, dy position,
+ * using drawing mode specified by 'mode' and flipping mode specified by
+ * 'flip'.
+ */
+void FUNC_LINEAR_DRAW_SPRITE_EX(BITMAP * dst, BITMAP * src, int dx, int dy,
+ int mode, int flip)
+{
+ int x, y, w, h;
+ int x_dir = 1, y_dir = 1;
+ int dxbeg, dybeg;
+ int sxbeg, sybeg;
+ DLS_BLENDER lit_blender;
+ DTS_BLENDER trans_blender;
+
+ ASSERT(dst);
+ ASSERT(src);
+
+ if (flip == DRAW_SPRITE_V_FLIP) {
+ y_dir = -1;
+ }
+ if (flip == DRAW_SPRITE_H_FLIP) {
+ x_dir = -1;
+ }
+ if (flip == DRAW_SPRITE_VH_FLIP) {
+ y_dir = -1;
+ x_dir = -1;
+ }
+
+ if (dst->clip) {
+ int tmp;
+
+ tmp = dst->cl - dx;
+ sxbeg = MAX(0, tmp);
+ dxbeg = sxbeg + dx;
+
+ tmp = dst->cr - dx;
+ w = MIN(src->w, tmp) - sxbeg;
+ if (w <= 0)
+ return;
+
+ if (flip == DRAW_SPRITE_H_FLIP || flip == DRAW_SPRITE_VH_FLIP) {
+ /* use backward drawing onto dst */
+ sxbeg = src->w - (sxbeg + w);
+ dxbeg += w - 1;
+ }
+
+ tmp = dst->ct - dy;
+ sybeg = MAX(0, tmp);
+ dybeg = sybeg + dy;
+
+ tmp = dst->cb - dy;
+ h = MIN(src->h, tmp) - sybeg;
+ if (h <= 0)
+ return;
+
+ if (flip == DRAW_SPRITE_V_FLIP || flip == DRAW_SPRITE_VH_FLIP) {
+ /* use backward drawing onto dst */
+ sybeg = src->h - (sybeg + h);
+ dybeg += h - 1;
+ }
+ }
+ else {
+ w = src->w;
+ h = src->h;
+ sxbeg = 0;
+ sybeg = 0;
+ dxbeg = dx;
+ if (flip == DRAW_SPRITE_H_FLIP || flip == DRAW_SPRITE_VH_FLIP) {
+ dxbeg = dx + w - 1;
+ }
+ dybeg = dy;
+ if (flip == DRAW_SPRITE_V_FLIP || flip == DRAW_SPRITE_VH_FLIP) {
+ dybeg = dy + h - 1;
+ }
+ }
+
+ lit_blender = MAKE_DLS_BLENDER(0);
+ trans_blender = MAKE_DTS_BLENDER();
+
+ if (dst->id & (BMP_ID_VIDEO | BMP_ID_SYSTEM)) {
+ bmp_select(dst);
+
+ for (y = 0; y < h; y++) {
+ PIXEL_PTR s = OFFSET_PIXEL_PTR(src->line[sybeg + y], sxbeg);
+
+ /* flipped if y_dir is -1 */
+ PIXEL_PTR d = OFFSET_PIXEL_PTR(bmp_write_line(dst, dybeg + y * y_dir), dxbeg);
+
+ /* d is incremented by x_dir, -1 if flipped */
+ for (x = w - 1; x >= 0; INC_PIXEL_PTR(s), INC_PIXEL_PTR_N(d,x_dir), x--) {
+ unsigned long c = GET_MEMORY_PIXEL(s);
+ if (!IS_SPRITE_MASK(src, c)) {
+ switch(mode) {
+ case DRAW_SPRITE_NORMAL: break;
+
+ case DRAW_SPRITE_LIT:
+ c = DLSX_BLEND(lit_blender, c);
+ break;
+
+ case DRAW_SPRITE_TRANS:
+ c = DTS_BLEND(trans_blender, GET_PIXEL(d), c);
+ break;
+ }
+ PUT_PIXEL(d, c);
+ }
+ }
+ }
+
+ bmp_unwrite_line(dst);
+ }
+ else {
+ for (y = 0; y < h; y++) {
+ PIXEL_PTR s = OFFSET_PIXEL_PTR(src->line[sybeg + y], sxbeg);
+ PIXEL_PTR d = OFFSET_PIXEL_PTR(bmp_write_line(dst, dybeg + y * y_dir), dxbeg);
+
+ for (x = w - 1; x >= 0; INC_PIXEL_PTR(s), INC_PIXEL_PTR_N(d,x_dir), x--) {
+ unsigned long c = GET_MEMORY_PIXEL(s);
+ if (!IS_SPRITE_MASK(src, c)) {
+ switch(mode) {
+ case DRAW_SPRITE_NORMAL: break;
+
+ case DRAW_SPRITE_LIT:
+ c = DLSX_BLEND(lit_blender, c);
+ break;
+
+ case DRAW_SPRITE_TRANS:
+ c = DTS_BLEND(trans_blender, GET_PIXEL(d), c);
+ break;
+ }
+ PUT_MEMORY_PIXEL(d, c);
+ }
+ }
+ }
+ }
+}
+
+
+
/* _linear_draw_sprite:
* Draws a sprite onto a linear bitmap at the specified x, y position,
* using a masked drawing mode where zero pixels are not output.
@@ -180,6 +320,114 @@
+/* _linear_draw_sprite_v_flip_ex:
+ * Draws a sprite to a linear bitmap, flipping vertically.
+ */
+void FUNC_LINEAR_DRAW_SPRITE_V_FLIP_EX(BITMAP *dst, BITMAP *src,
+ int dx, int dy, int mode)
+{
+ int x, y, w, h;
+ int dxbeg, dybeg;
+ int sxbeg, sybeg;
+ DLS_BLENDER lit_blender;
+ DTS_BLENDER trans_blender;
+
+ ASSERT(dst);
+ ASSERT(src);
+
+ if (dst->clip) {
+ int tmp;
+
+ tmp = dst->cl - dx;
+ sxbeg = MAX(0, tmp);
+ dxbeg = sxbeg + dx;
+
+ tmp = dst->cr - dx;
+ w = MIN(src->w, tmp) - sxbeg;
+ if (w <= 0)
+ return;
+
+ tmp = dst->ct - dy;
+ sybeg = MAX(0, tmp);
+ dybeg = sybeg + dy;
+
+ tmp = dst->cb - dy;
+ h = MIN(src->h, tmp) - sybeg;
+ if (h <= 0)
+ return;
+
+ /* use backward drawing onto dst */
+ sybeg = src->h - (sybeg + h);
+ dybeg += h - 1;
+ }
+ else {
+ w = src->w;
+ h = src->h;
+ sxbeg = 0;
+ sybeg = 0;
+ dxbeg = dx;
+ dybeg = dy + h - 1;
+ }
+
+ lit_blender = MAKE_DLS_BLENDER(0);
+ trans_blender = MAKE_DTS_BLENDER();
+
+ if (dst->id & (BMP_ID_VIDEO | BMP_ID_SYSTEM)) {
+ bmp_select(dst);
+
+ for (y = 0; y < h; y++) {
+ PIXEL_PTR s = OFFSET_PIXEL_PTR(src->line[sybeg + y], sxbeg);
+ PIXEL_PTR d = OFFSET_PIXEL_PTR(bmp_write_line(dst, dybeg - y), dxbeg);
+
+ for (x = w - 1; x >= 0; INC_PIXEL_PTR(s), INC_PIXEL_PTR(d), x--) {
+ unsigned long c = GET_MEMORY_PIXEL(s);
+ if (!IS_SPRITE_MASK(src, c)) {
+ switch(mode) {
+ case DRAW_SPRITE_NORMAL: break;
+
+ case DRAW_SPRITE_LIT:
+ c = DLSX_BLEND(lit_blender, c);
+ break;
+
+ case DRAW_SPRITE_TRANS:
+ c = DTS_BLEND(trans_blender, GET_PIXEL(d), c);
+ break;
+ }
+ PUT_PIXEL(d, c);
+ }
+ }
+ }
+
+ bmp_unwrite_line(dst);
+ }
+ else {
+ for (y = 0; y < h; y++) {
+ PIXEL_PTR s = OFFSET_PIXEL_PTR(src->line[sybeg + y], sxbeg);
+ PIXEL_PTR d = OFFSET_PIXEL_PTR(dst->line[dybeg - y], dxbeg);
+
+ for (x = w - 1; x >= 0; INC_PIXEL_PTR(s), INC_PIXEL_PTR(d), x--) {
+ unsigned long c = GET_MEMORY_PIXEL(s);
+ if (!IS_SPRITE_MASK(src, c)) {
+ switch(mode) {
+ case DRAW_SPRITE_NORMAL: break;
+
+ case DRAW_SPRITE_LIT:
+ c = DLSX_BLEND(lit_blender, c);
+ break;
+
+ case DRAW_SPRITE_TRANS:
+ c = DTS_BLEND(trans_blender, GET_PIXEL(d), c);
+ break;
+ }
+ PUT_MEMORY_PIXEL(d, c);
+ }
+ }
+ }
+ }
+}
+
+
+
/* _linear_draw_sprite_v_flip:
* Draws a sprite to a linear bitmap, flipping vertically.
*/
@@ -340,6 +588,228 @@
+/* _linear_draw_sprite_h_flip:
+ * Draws a sprite to a linear bitmap, flipping horizontally.
+ */
+void FUNC_LINEAR_DRAW_SPRITE_H_FLIP_EX(BITMAP *dst, BITMAP *src,
+ int dx, int dy, int mode)
+{
+
+ int x, y, w, h;
+ int dxbeg, dybeg;
+ int sxbeg, sybeg;
+ DLS_BLENDER lit_blender;
+ DTS_BLENDER trans_blender;
+
+ ASSERT(dst);
+ ASSERT(src);
+
+ if (dst->clip) {
+ int tmp;
+
+ tmp = dst->cl - dx;
+ sxbeg = MAX(0, tmp);
+ dxbeg = sxbeg + dx;
+
+ tmp = dst->cr - dx;
+ w = MIN(src->w, tmp) - sxbeg;
+ if (w <= 0)
+ return;
+
+ /* use backward drawing onto dst */
+ sxbeg = src->w - (sxbeg + w);
+ dxbeg += w - 1;
+
+ tmp = dst->ct - dy;
+ sybeg = MAX(0, tmp);
+ dybeg = sybeg + dy;
+
+ tmp = dst->cb - dy;
+ h = MIN(src->h, tmp) - sybeg;
+ if (h <= 0)
+ return;
+ }
+ else {
+ w = src->w;
+ h = src->h;
+ sxbeg = 0;
+ sybeg = 0;
+ dxbeg = dx + w - 1;
+ dybeg = dy;
+ }
+
+ lit_blender = MAKE_DLS_BLENDER(0);
+ trans_blender = MAKE_DTS_BLENDER();
+
+ if (dst->id & (BMP_ID_VIDEO | BMP_ID_SYSTEM)) {
+ bmp_select(dst);
+
+ for (y = 0; y < h; y++) {
+ PIXEL_PTR s = OFFSET_PIXEL_PTR(src->line[sybeg + y], sxbeg);
+ PIXEL_PTR d = OFFSET_PIXEL_PTR(bmp_write_line(dst, dybeg + y), dxbeg);
+
+ for (x = w - 1; x >= 0; INC_PIXEL_PTR(s), DEC_PIXEL_PTR(d), x--) {
+ unsigned long c = GET_MEMORY_PIXEL(s);
+ if (!IS_SPRITE_MASK(src, c)) {
+ switch(mode) {
+ case DRAW_SPRITE_NORMAL: break;
+
+ case DRAW_SPRITE_LIT:
+ c = DLSX_BLEND(lit_blender, c);
+ break;
+
+ case DRAW_SPRITE_TRANS:
+ c = DTS_BLEND(trans_blender, GET_PIXEL(d), c);
+ break;
+ }
+ PUT_PIXEL(d, c);
+ }
+ }
+ }
+
+ bmp_unwrite_line(dst);
+ }
+ else {
+ for (y = 0; y < h; y++) {
+ PIXEL_PTR s = OFFSET_PIXEL_PTR(src->line[sybeg + y], sxbeg);
+ PIXEL_PTR d = OFFSET_PIXEL_PTR(dst->line[dybeg + y], dxbeg);
+
+ for (x = w - 1; x >= 0; INC_PIXEL_PTR(s), DEC_PIXEL_PTR(d), x--) {
+ unsigned long c = GET_MEMORY_PIXEL(s);
+ if (!IS_SPRITE_MASK(src, c)) {
+ switch(mode) {
+ case DRAW_SPRITE_NORMAL: break;
+
+ case DRAW_SPRITE_LIT:
+ c = DLSX_BLEND(lit_blender, c);
+ break;
+
+ case DRAW_SPRITE_TRANS:
+ c = DTS_BLEND(trans_blender, GET_PIXEL(d), c);
+ break;
+ }
+ PUT_MEMORY_PIXEL(d, c);
+ }
+ }
+ }
+ }
+}
+
+
+
+/* _linear_draw_sprite_vh_flip_ex:
+ * Draws a sprite to a linear bitmap, flipping both vertically and
+ * horizontally.
+ */
+void FUNC_LINEAR_DRAW_SPRITE_VH_FLIP_EX(BITMAP *dst, BITMAP *src,
+ int dx, int dy, int mode)
+{
+ int x, y, w, h;
+ int dxbeg, dybeg;
+ int sxbeg, sybeg;
+ DLS_BLENDER lit_blender;
+ DTS_BLENDER trans_blender;
+
+ ASSERT(dst);
+ ASSERT(src);
+
+ if (dst->clip) {
+ int tmp;
+
+ tmp = dst->cl - dx;
+ sxbeg = MAX(0, tmp);
+ dxbeg = sxbeg + dx;
+
+ tmp = dst->cr - dx;
+ w = MIN(src->w, tmp) - sxbeg;
+ if (w <= 0)
+ return;
+
+ /* use backward drawing onto dst */
+ sxbeg = src->w - (sxbeg + w);
+ dxbeg += w - 1;
+
+ tmp = dst->ct - dy;
+ sybeg = MAX(0, tmp);
+ dybeg = sybeg + dy;
+
+ tmp = dst->cb - dy;
+ h = MIN(src->h, tmp) - sybeg;
+ if (h <= 0)
+ return;
+
+ /* use backward drawing onto dst */
+ sybeg = src->h - (sybeg + h);
+ dybeg += h - 1;
+ }
+ else {
+ w = src->w;
+ h = src->h;
+ sxbeg = 0;
+ sybeg = 0;
+ dxbeg = dx + w - 1;
+ dybeg = dy + h - 1;
+ }
+
+ lit_blender = MAKE_DLS_BLENDER(0);
+ trans_blender = MAKE_DTS_BLENDER();
+
+ if (dst->id & (BMP_ID_VIDEO | BMP_ID_SYSTEM)) {
+ bmp_select(dst);
+
+ for (y = 0; y < h; y++) {
+ PIXEL_PTR s = OFFSET_PIXEL_PTR(src->line[sybeg + y], sxbeg);
+ PIXEL_PTR d = OFFSET_PIXEL_PTR(bmp_write_line(dst, dybeg - y), dxbeg);
+
+ for (x = w - 1; x >= 0; INC_PIXEL_PTR(s), DEC_PIXEL_PTR(d), x--) {
+ unsigned long c = GET_MEMORY_PIXEL(s);
+ if (!IS_SPRITE_MASK(src, c)) {
+ switch(mode) {
+ case DRAW_SPRITE_NORMAL: break;
+
+ case DRAW_SPRITE_LIT:
+ c = DLSX_BLEND(lit_blender, c);
+ break;
+
+ case DRAW_SPRITE_TRANS:
+ c = DTS_BLEND(trans_blender, GET_PIXEL(d), c);
+ break;
+ }
+ PUT_PIXEL(d, c);
+ }
+ }
+ }
+
+ bmp_unwrite_line(dst);
+ }
+ else {
+ for (y = 0; y < h; y++) {
+ PIXEL_PTR s = OFFSET_PIXEL_PTR(src->line[sybeg + y], sxbeg);
+ PIXEL_PTR d = OFFSET_PIXEL_PTR(dst->line[dybeg - y], dxbeg);
+
+ for (x = w - 1; x >= 0; INC_PIXEL_PTR(s), DEC_PIXEL_PTR(d), x--) {
+ unsigned long c = GET_MEMORY_PIXEL(s);
+ if (!IS_SPRITE_MASK(src, c)) {
+ switch(mode) {
+ case DRAW_SPRITE_NORMAL: break;
+
+ case DRAW_SPRITE_LIT:
+ c = DLSX_BLEND(lit_blender, c);
+ break;
+
+ case DRAW_SPRITE_TRANS:
+ c = DTS_BLEND(trans_blender, GET_PIXEL(d), c);
+ break;
+ }
+ PUT_MEMORY_PIXEL(d, c);
+ }
+ }
+ }
+ }
+}
+
+
+
/* _linear_draw_sprite_vh_flip:
* Draws a sprite to a linear bitmap, flipping both vertically and horizontally.
*/
Index: src/c/cdefs8.h
===================================================================
--- src/c/cdefs8.h (revision 9738)
+++ src/c/cdefs8.h (working copy)
@@ -24,6 +24,7 @@
#define PTR_PER_PIXEL 1
#define OFFSET_PIXEL_PTR(p,x) ((PIXEL_PTR) (p) + (x))
#define INC_PIXEL_PTR(p) ((p)++)
+#define INC_PIXEL_PTR_N(p,d) ((p) += d)
#define DEC_PIXEL_PTR(p) ((p)--)
#define PUT_PIXEL(p,c) bmp_write8((uintptr_t) (p), (c))
@@ -49,6 +50,7 @@
#define DLS_BLENDER unsigned char*
#define MAKE_DLS_BLENDER(a) (color_map->data[(a) & 0xFF])
#define DLS_BLEND(b,a,c) ((b)[(c) & 0xFF])
+#define DLSX_BLEND(b,c) ((b)[(c) & 0xFF])
/* Blender for poly_scanline_*_lit. */
#define PS_BLENDER COLOR_MAP*
@@ -74,10 +76,14 @@
#define FUNC_LINEAR_VLINE _linear_vline8
#define FUNC_LINEAR_DRAW_SPRITE _linear_draw_sprite8
+#define FUNC_LINEAR_DRAW_SPRITE_EX _linear_draw_sprite_ex8
#define FUNC_LINEAR_DRAW_256_SPRITE _linear_draw_256_sprite8
#define FUNC_LINEAR_DRAW_SPRITE_V_FLIP _linear_draw_sprite_v_flip8
+#define FUNC_LINEAR_DRAW_SPRITE_V_FLIP_EX _linear_draw_sprite_v_flip_ex8
#define FUNC_LINEAR_DRAW_SPRITE_H_FLIP _linear_draw_sprite_h_flip8
+#define FUNC_LINEAR_DRAW_SPRITE_H_FLIP_EX _linear_draw_sprite_h_flip_ex8
#define FUNC_LINEAR_DRAW_SPRITE_VH_FLIP _linear_draw_sprite_vh_flip8
+#define FUNC_LINEAR_DRAW_SPRITE_VH_FLIP_EX _linear_draw_sprite_vh_flip_ex8
#define FUNC_LINEAR_DRAW_TRANS_SPRITE _linear_draw_trans_sprite8
#define FUNC_LINEAR_DRAW_TRANS_RGBA_SPRITE _linear_draw_trans_rgba_sprite8
#define FUNC_LINEAR_DRAW_LIT_SPRITE _linear_draw_lit_sprite8
Index: src/vtable8.c
===================================================================
--- src/vtable8.c (revision 9738)
+++ src/vtable8.c (working copy)
@@ -91,7 +91,11 @@
_soft_triangle3d,
_soft_triangle3d_f,
_soft_quad3d,
- _soft_quad3d_f
+ _soft_quad3d_f,
+ _linear_draw_sprite_ex8,
+ _linear_draw_sprite_h_flip_ex8,
+ _linear_draw_sprite_v_flip_ex8,
+ _linear_draw_sprite_vh_flip_ex8
};
Index: src/vtable32.c
===================================================================
--- src/vtable32.c (revision 9738)
+++ src/vtable32.c (working copy)
@@ -91,7 +91,11 @@
_soft_triangle3d,
_soft_triangle3d_f,
_soft_quad3d,
- _soft_quad3d_f
+ _soft_quad3d_f,
+ _linear_draw_sprite_ex32,
+ _linear_draw_sprite_h_flip_ex32,
+ _linear_draw_sprite_v_flip_ex32,
+ _linear_draw_sprite_vh_flip_ex32
};
Index: src/vtable15.c
===================================================================
--- src/vtable15.c (revision 9738)
+++ src/vtable15.c (working copy)
@@ -91,7 +91,11 @@
_soft_triangle3d,
_soft_triangle3d_f,
_soft_quad3d,
- _soft_quad3d_f
+ _soft_quad3d_f,
+ _linear_draw_sprite_ex16,
+ _linear_draw_sprite_h_flip_ex16,
+ _linear_draw_sprite_v_flip_ex16,
+ _linear_draw_sprite_vh_flip_ex16
};
Index: src/x/xvtable.c
===================================================================
--- src/x/xvtable.c (revision 9738)
+++ src/x/xvtable.c (working copy)
@@ -33,10 +33,14 @@
static void _xwin_hline(BITMAP *dst, int dx1, int dy, int dx2, int color);
static void _xwin_rectfill(BITMAP *dst, int dx1, int dy1, int dx2, int dy2, int color);
static void _xwin_draw_sprite(BITMAP *dst, BITMAP *src, int dx, int dy);
+static void _xwin_draw_sprite_ex(BITMAP *dst, BITMAP *src, int dx, int dy, int mode, int flip);
static void _xwin_draw_256_sprite(BITMAP *dst, BITMAP *src, int dx, int dy);
static void _xwin_draw_sprite_v_flip(BITMAP *dst, BITMAP *src, int dx, int dy);
+static void _xwin_draw_sprite_v_flip_ex(BITMAP *dst, BITMAP *src, int dx, int dy, int mode);
static void _xwin_draw_sprite_h_flip(BITMAP *dst, BITMAP *src, int dx, int dy);
+static void _xwin_draw_sprite_h_flip_ex(BITMAP *dst, BITMAP *src, int dx, int dy, int mode);
static void _xwin_draw_sprite_vh_flip(BITMAP *dst, BITMAP *src, int dx, int dy);
+static void _xwin_draw_sprite_vh_flip_ex(BITMAP *dst, BITMAP *src, int dx, int dy, int mode);
static void _xwin_draw_trans_sprite(BITMAP *dst, BITMAP *src, int dx, int dy);
static void _xwin_draw_trans_rgba_sprite(BITMAP *dst, BITMAP *src, int dx, int dy);
static void _xwin_draw_lit_sprite(BITMAP *dst, BITMAP *src, int dx, int dy, int color);
@@ -233,10 +237,14 @@
vtable->hfill = _xwin_hline;
vtable->rectfill = _xwin_rectfill;
vtable->draw_sprite = _xwin_draw_sprite;
+ vtable->draw_sprite_ex = _xwin_draw_sprite_ex;
vtable->draw_256_sprite = _xwin_draw_256_sprite;
vtable->draw_sprite_v_flip = _xwin_draw_sprite_v_flip;
+ vtable->draw_sprite_v_flip_ex = _xwin_draw_sprite_v_flip_ex;
vtable->draw_sprite_h_flip = _xwin_draw_sprite_h_flip;
+ vtable->draw_sprite_h_flip_ex = _xwin_draw_sprite_h_flip_ex;
vtable->draw_sprite_vh_flip = _xwin_draw_sprite_vh_flip;
+ vtable->draw_sprite_vh_flip_ex = _xwin_draw_sprite_vh_flip_ex;
vtable->draw_trans_sprite = _xwin_draw_trans_sprite;
vtable->draw_trans_rgba_sprite = _xwin_draw_trans_rgba_sprite;
vtable->draw_lit_sprite = _xwin_draw_lit_sprite;
@@ -569,8 +577,26 @@
_xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
}
+/* _xwin_draw_sprite_ex:
+ * Wrapper for draw_sprite_ex.
+ */
+static void _xwin_draw_sprite_ex(BITMAP *dst, BITMAP *src, int dx, int dy, int mode, int flip)
+{
+ int dxbeg, dybeg, w, h;
+ if (_xwin_in_gfx_call) {
+ _xwin_vtable.draw_sprite_ex(dst, src, dx, dy, mode, flip);
+ return;
+ }
+ CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
+
+ _xwin_in_gfx_call = 1;
+ _xwin_vtable.draw_sprite_ex(dst, src, dx, dy, mode, flip);
+ _xwin_in_gfx_call = 0;
+ _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
+}
+
/* _xwin_draw_256_sprite:
* Wrapper for draw_256_sprite.
*/
@@ -613,8 +639,28 @@
_xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
}
+/* _xwin_draw_sprite_v_flip:
+ * Wrapper for draw_sprite_v_flip.
+ */
+static void _xwin_draw_sprite_v_flip_ex(BITMAP *dst, BITMAP *src, int dx, int dy, int mode)
+{
+ int dxbeg, dybeg, w, h;
+ if (_xwin_in_gfx_call) {
+ _xwin_vtable.draw_sprite_v_flip_ex(dst, src, dx, dy, mode);
+ return;
+ }
+ CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
+
+ _xwin_in_gfx_call = 1;
+ _xwin_vtable.draw_sprite_v_flip_ex(dst, src, dx, dy, mode);
+ _xwin_in_gfx_call = 0;
+ _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
+}
+
+
+
/* _xwin_draw_sprite_h_flip:
* Wrapper for draw_sprite_h_flip.
*/
@@ -635,8 +681,26 @@
_xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
}
+/* _xwin_draw_sprite_h_flip_ex:
+ * Wrapper for draw_sprite_h_flip_ex.
+ */
+static void _xwin_draw_sprite_h_flip_ex(BITMAP *dst, BITMAP *src, int dx, int dy, int mode)
+{
+ int dxbeg, dybeg, w, h;
+ if (_xwin_in_gfx_call) {
+ _xwin_vtable.draw_sprite_h_flip_ex(dst, src, dx, dy, mode);
+ return;
+ }
+ CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
+
+ _xwin_in_gfx_call = 1;
+ _xwin_vtable.draw_sprite_h_flip_ex(dst, src, dx, dy, mode);
+ _xwin_in_gfx_call = 0;
+ _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
+}
+
/* _xwin_draw_sprite_vh_flip:
* Wrapper for draw_sprite_vh_flip.
*/
@@ -657,8 +721,26 @@
_xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
}
+/* _xwin_draw_sprite_vh_flip_ex:
+ * Wrapper for draw_sprite_vh_flip_ex.
+ */
+static void _xwin_draw_sprite_vh_flip_ex(BITMAP *dst, BITMAP *src, int dx, int dy, int mode)
+{
+ int dxbeg, dybeg, w, h;
+ if (_xwin_in_gfx_call) {
+ _xwin_vtable.draw_sprite_vh_flip_ex(dst, src, dx, dy, mode);
+ return;
+ }
+ CLIP_BOX(dst, dxbeg, dybeg, w, h, dx, dy, src->w, src->h)
+
+ _xwin_in_gfx_call = 1;
+ _xwin_vtable.draw_sprite_vh_flip_ex(dst, src, dx, dy, mode);
+ _xwin_in_gfx_call = 0;
+ _xwin_update_video_bitmap(dst, dxbeg, dybeg, w, h);
+}
+
/* _xwin_draw_trans_sprite:
* Wrapper for draw_trans_sprite.
*/
Index: makefile.lst
===================================================================
--- makefile.lst (revision 9738)
+++ makefile.lst (working copy)
@@ -564,6 +564,7 @@
examples/exswitch.c \
examples/extimer.c \
examples/extrans.c \
+ examples/extrans2.c \
examples/extruec.c \
examples/exunicod.c \
examples/exupdate.c \
@@ -615,6 +616,7 @@
examples/exswitch \
examples/extimer \
examples/extrans \
+ examples/extrans2 \
examples/extruec \
examples/exunicod \
examples/exupdate \
Index: include/allegro/gfx.h
===================================================================
--- include/allegro/gfx.h (revision 9738)
+++ include/allegro/gfx.h (working copy)
@@ -37,7 +37,17 @@
#define GFX_AUTODETECT_WINDOWED 2
#define GFX_SAFE AL_ID('S','A','F','E')
+/* drawing modes for draw_sprite_ex() */
+#define DRAW_SPRITE_NORMAL 0
+#define DRAW_SPRITE_LIT 1
+#define DRAW_SPRITE_TRANS 2
+/* flipping modes for draw_sprite_ex() */
+#define DRAW_SPRITE_NO_FLIP 0x0
+#define DRAW_SPRITE_H_FLIP 0x1
+#define DRAW_SPRITE_V_FLIP 0x2
+#define DRAW_SPRITE_VH_FLIP 0x3
+
/* Blender mode defines, for the gfx_driver->set_blender_mode() function */
#define blender_mode_none 0
#define blender_mode_trans 1
@@ -214,6 +224,11 @@
AL_METHOD(void, triangle3d_f, (struct BITMAP *bmp, int type, struct BITMAP *texture, V3D_f *v1, V3D_f *v2, V3D_f *v3));
AL_METHOD(void, quad3d, (struct BITMAP *bmp, int type, struct BITMAP *texture, V3D *v1, V3D *v2, V3D *v3, V3D *v4));
AL_METHOD(void, quad3d_f, (struct BITMAP *bmp, int type, struct BITMAP *texture, V3D_f *v1, V3D_f *v2, V3D_f *v3, V3D_f *v4));
+
+ AL_METHOD(void, draw_sprite_ex, (struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int mode, int flip ));
+ AL_METHOD(void, draw_sprite_h_flip_ex, (struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int mode ));
+ AL_METHOD(void, draw_sprite_v_flip_ex, (struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int mode ));
+ AL_METHOD(void, draw_sprite_vh_flip_ex, (struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int mode ));
} GFX_VTABLE;
Index: include/allegro/internal/aintern.h
===================================================================
--- include/allegro/internal/aintern.h (revision 9738)
+++ include/allegro/internal/aintern.h (working copy)
@@ -530,9 +530,13 @@
AL_FUNC(void, _linear_vline8, (BITMAP *bmp, int x, int y_1, int y2, int color));
AL_FUNC(void, _linear_hline8, (BITMAP *bmp, int x1, int y, int x2, int color));
AL_FUNC(void, _linear_draw_sprite8, (BITMAP *bmp, BITMAP *sprite, int x, int y));
+AL_FUNC(void, _linear_draw_sprite_ex8, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode, int flip));
AL_FUNC(void, _linear_draw_sprite_v_flip8, (BITMAP *bmp, BITMAP *sprite, int x, int y));
+AL_FUNC(void, _linear_draw_sprite_v_flip_ex8, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode));
AL_FUNC(void, _linear_draw_sprite_h_flip8, (BITMAP *bmp, BITMAP *sprite, int x, int y));
+AL_FUNC(void, _linear_draw_sprite_h_flip_ex8, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode));
AL_FUNC(void, _linear_draw_sprite_vh_flip8, (BITMAP *bmp, BITMAP *sprite, int x, int y));
+AL_FUNC(void, _linear_draw_sprite_vh_flip_ex8, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode));
AL_FUNC(void, _linear_draw_trans_sprite8, (BITMAP *bmp, BITMAP *sprite, int x, int y));
AL_FUNC(void, _linear_draw_lit_sprite8, (BITMAP *bmp, BITMAP *sprite, int x, int y, int color));
AL_FUNC(void, _linear_draw_rle_sprite8, (BITMAP *bmp, AL_CONST struct RLE_SPRITE *sprite, int x, int y));
@@ -565,10 +569,14 @@
AL_FUNC(void, _linear_vline16, (BITMAP *bmp, int x, int y_1, int y2, int color));
AL_FUNC(void, _linear_hline16, (BITMAP *bmp, int x1, int y, int x2, int color));
AL_FUNC(void, _linear_draw_sprite16, (BITMAP *bmp, BITMAP *sprite, int x, int y));
+AL_FUNC(void, _linear_draw_sprite_ex16, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode, int flip));
AL_FUNC(void, _linear_draw_256_sprite16, (BITMAP *bmp, BITMAP *sprite, int x, int y));
AL_FUNC(void, _linear_draw_sprite_v_flip16, (BITMAP *bmp, BITMAP *sprite, int x, int y));
+AL_FUNC(void, _linear_draw_sprite_v_flip_ex16, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode));
AL_FUNC(void, _linear_draw_sprite_h_flip16, (BITMAP *bmp, BITMAP *sprite, int x, int y));
+AL_FUNC(void, _linear_draw_sprite_h_flip_ex16, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode));
AL_FUNC(void, _linear_draw_sprite_vh_flip16, (BITMAP *bmp, BITMAP *sprite, int x, int y));
+AL_FUNC(void, _linear_draw_sprite_vh_flip_ex16, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode));
AL_FUNC(void, _linear_draw_trans_sprite16, (BITMAP *bmp, BITMAP *sprite, int x, int y));
AL_FUNC(void, _linear_draw_trans_rgba_sprite16, (BITMAP *bmp, BITMAP *sprite, int x, int y));
AL_FUNC(void, _linear_draw_lit_sprite16, (BITMAP *bmp, BITMAP *sprite, int x, int y, int color));
@@ -592,10 +600,14 @@
AL_FUNC(void, _linear_vline24, (BITMAP *bmp, int x, int y_1, int y2, int color));
AL_FUNC(void, _linear_hline24, (BITMAP *bmp, int x1, int y, int x2, int color));
AL_FUNC(void, _linear_draw_sprite24, (BITMAP *bmp, BITMAP *sprite, int x, int y));
+AL_FUNC(void, _linear_draw_sprite_ex24, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode, int flip));
AL_FUNC(void, _linear_draw_256_sprite24, (BITMAP *bmp, BITMAP *sprite, int x, int y));
AL_FUNC(void, _linear_draw_sprite_v_flip24, (BITMAP *bmp, BITMAP *sprite, int x, int y));
+AL_FUNC(void, _linear_draw_sprite_v_flip_ex24, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode));
AL_FUNC(void, _linear_draw_sprite_h_flip24, (BITMAP *bmp, BITMAP *sprite, int x, int y));
+AL_FUNC(void, _linear_draw_sprite_h_flip_ex24, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode));
AL_FUNC(void, _linear_draw_sprite_vh_flip24, (BITMAP *bmp, BITMAP *sprite, int x, int y));
+AL_FUNC(void, _linear_draw_sprite_vh_flip_ex24, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode));
AL_FUNC(void, _linear_draw_trans_sprite24, (BITMAP *bmp, BITMAP *sprite, int x, int y));
AL_FUNC(void, _linear_draw_trans_rgba_sprite24, (BITMAP *bmp, BITMAP *sprite, int x, int y));
AL_FUNC(void, _linear_draw_lit_sprite24, (BITMAP *bmp, BITMAP *sprite, int x, int y, int color));
@@ -619,10 +631,14 @@
AL_FUNC(void, _linear_vline32, (BITMAP *bmp, int x, int y_1, int y2, int color));
AL_FUNC(void, _linear_hline32, (BITMAP *bmp, int x1, int y, int x2, int color));
AL_FUNC(void, _linear_draw_sprite32, (BITMAP *bmp, BITMAP *sprite, int x, int y));
+AL_FUNC(void, _linear_draw_sprite_ex32, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode, int flip));
AL_FUNC(void, _linear_draw_256_sprite32, (BITMAP *bmp, BITMAP *sprite, int x, int y));
AL_FUNC(void, _linear_draw_sprite_v_flip32, (BITMAP *bmp, BITMAP *sprite, int x, int y));
+AL_FUNC(void, _linear_draw_sprite_v_flip_ex32, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode));
AL_FUNC(void, _linear_draw_sprite_h_flip32, (BITMAP *bmp, BITMAP *sprite, int x, int y));
+AL_FUNC(void, _linear_draw_sprite_h_flip_ex32, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode));
AL_FUNC(void, _linear_draw_sprite_vh_flip32, (BITMAP *bmp, BITMAP *sprite, int x, int y));
+AL_FUNC(void, _linear_draw_sprite_vh_flip_ex32, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode));
AL_FUNC(void, _linear_draw_trans_sprite32, (BITMAP *bmp, BITMAP *sprite, int x, int y));
AL_FUNC(void, _linear_draw_lit_sprite32, (BITMAP *bmp, BITMAP *sprite, int x, int y, int color));
AL_FUNC(void, _linear_draw_rle_sprite32, (BITMAP *bmp, AL_CONST struct RLE_SPRITE *sprite, int x, int y));
Index: include/allegro/inline/draw.inl
===================================================================
--- include/allegro/inline/draw.inl (revision 9738)
+++ include/allegro/inline/draw.inl (working copy)
@@ -249,7 +249,16 @@
}
})
+AL_INLINE(void, draw_sprite_ex, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode, int flip),
+{
+ ASSERT(bmp);
+ ASSERT(sprite);
+ ASSERT(bmp->vtable->color_depth == sprite->vtable->color_depth);
+ bmp->vtable->draw_sprite_ex(bmp, sprite, x, y, mode, flip);
+})
+
+
AL_INLINE(void, draw_sprite_v_flip, (BITMAP *bmp, BITMAP *sprite, int x, int y),{
ASSERT(bmp);
ASSERT(sprite);
@@ -258,7 +267,14 @@
bmp->vtable->draw_sprite_v_flip(bmp, sprite, x, y);
})
+AL_INLINE(void, draw_sprite_v_flip_ex, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode),{
+ ASSERT(bmp);
+ ASSERT(sprite);
+ ASSERT(bmp->vtable->color_depth == sprite->vtable->color_depth);
+ bmp->vtable->draw_sprite_v_flip_ex(bmp, sprite, x, y, mode);
+})
+
AL_INLINE(void, draw_sprite_h_flip, (BITMAP *bmp, BITMAP *sprite, int x, int y),{
ASSERT(bmp);
ASSERT(sprite);
@@ -267,7 +283,14 @@
bmp->vtable->draw_sprite_h_flip(bmp, sprite, x, y);
})
+AL_INLINE(void, draw_sprite_h_flip_ex, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode ),{
+ ASSERT(bmp);
+ ASSERT(sprite);
+ ASSERT(bmp->vtable->color_depth == sprite->vtable->color_depth);
+ bmp->vtable->draw_sprite_h_flip_ex(bmp, sprite, x, y, mode);
+})
+
AL_INLINE(void, draw_sprite_vh_flip, (BITMAP *bmp, BITMAP *sprite, int x, int y),
{
ASSERT(bmp);
@@ -277,7 +300,15 @@
bmp->vtable->draw_sprite_vh_flip(bmp, sprite, x, y);
})
+AL_INLINE(void, draw_sprite_vh_flip_ex, (BITMAP *bmp, BITMAP *sprite, int x, int y, int mode),
+{
+ ASSERT(bmp);
+ ASSERT(sprite);
+ ASSERT(bmp->vtable->color_depth == sprite->vtable->color_depth);
+ bmp->vtable->draw_sprite_vh_flip_ex(bmp, sprite, x, y, mode);
+})
+
AL_INLINE(void, draw_trans_sprite, (BITMAP *bmp, BITMAP *sprite, int x, int y),
{
ASSERT(bmp);
Index: examples/extrans2.c
===================================================================
--- examples/extrans2.c (revision 0)
+++ examples/extrans2.c (revision 0)
@@ -0,0 +1,235 @@
+/*
+ * Example program for the Allegro library, by Jon Rafkind.
+ *
+ * This program demonstrates how to draw trans and lit sprites and flip them
+ * at the same time, using draw_trans_sprite_ex() function.
+ * It displays several images moving around using different drawing modes
+ * while you can press space key to change the flipping mode.
+ */
+
+#include <stdio.h>
+
+#include <allegro.h>
+
+/* define the number of sprites that will be displayed */
+#define SPRITE_COUNT 20
+
+/* define directions in which the sprites can move */
+enum DIRECTION { DIR_UP, DIR_DOWN, DIR_LEFT, DIR_RIGHT };
+
+
+/* define our sprite */
+typedef struct {
+ int x;
+ int y;
+
+ enum DIRECTION direction;
+
+ /* what order to draw this sprite at, lower before higher */
+ int level;
+
+ /* SPRITE_NORMAL, SPRITE_TRANS, or SPRITE_LIT */
+ int draw_type;
+} SPRITE;
+
+
+/* puts the sprite somewhere on the screen and sets its initial state */
+void setup_sprite(SPRITE *s, int i)
+{
+ switch (i % 4) {
+ case 0 : {
+ s->x = -100 + i * 50;
+ s->y = 40 + (i % 3) * 100;
+ s->direction = DIR_RIGHT;
+ s->draw_type = DRAW_SPRITE_NORMAL;
+ s->level = 0;
+ break;
+ }
+ case 1 : {
+ s->x = 640 + 100 - i * 70;
+ s->y = 50 + (i % 3) * 110;
+ s->direction = DIR_LEFT;
+ s->draw_type = DRAW_SPRITE_TRANS;
+ s->level = 1;
+ break;
+ }
+ case 2 : {
+ s->x = 90 + (i % 3) * 200;
+ s->y = -100 + i * 70;
+ s->direction = DIR_DOWN;
+ s->draw_type = DRAW_SPRITE_LIT;
+ s->level = 2;
+ break;
+ }
+ case 3 : {
+ s->x = 50 + (i % 3) * 200;
+ s->y = 480 + 100 - i * 70;
+ s->direction = DIR_UP;
+ s->draw_type = DRAW_SPRITE_TRANS;
+ s->level = 3;
+ break;
+ }
+ }
+}
+
+
+/* used by sort function to compare sprites */
+int sprite_compare(AL_CONST void * a, AL_CONST void * b)
+{
+ SPRITE *s1 = (SPRITE *)a;
+ SPRITE *s2 = (SPRITE *)b;
+
+ return s1->level - s2->level;
+}
+
+
+/* moves the sprite by one pixel acording to its direction */
+void move_sprite(SPRITE *s)
+{
+ switch (s->direction) {
+ case DIR_UP : {
+ s->y--;
+ if (s->y < -64) {
+ s->y = 480;
+ }
+ break;
+ }
+ case DIR_DOWN : {
+ s->y++;
+ if (s->y > 480) {
+ s->y = -64;
+ }
+ break;
+ }
+ case DIR_RIGHT : {
+ s->x++;
+ if (s->x > 640) {
+ s->x = -64;
+ }
+ break;
+ }
+ case DIR_LEFT : {
+ s->x--;
+ if (s->x < -64) {
+ s->x = 640;
+ }
+ break;
+ }
+ }
+}
+
+
+int main(int argc, char ** argv)
+{
+ SPRITE sprites[SPRITE_COUNT];
+ BITMAP *buffer;
+ BITMAP *pic;
+ BITMAP *tmp;
+ char buf[1024];
+ char *filename;
+ int mode = 0;
+ int i;
+ int hold_space = 0;
+
+ /* standard init */
+ if (allegro_init() != 0)
+ return 1;
+ install_timer();
+ install_keyboard();
+
+ /* setting graphics mode */
+ set_color_depth(16);
+ if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0) {
+ if (set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) != 0) {
+ set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
+ allegro_message("Unable to set any graphic mode\n%s\n",
+ allegro_error);
+ return 1;
+ }
+ }
+
+ /* set initial position, direction and drawing for all sprites */
+ for (i = 0; i < SPRITE_COUNT; i++)
+ setup_sprite(&sprites[i], i);
+
+ /* sort the sprites by drawing level */
+ qsort(sprites, SPRITE_COUNT, sizeof(SPRITE), sprite_compare);
+
+ /* locate the bitmap we will use */
+ replace_filename(buf, argv[0], "allegro.pcx", sizeof(buf));
+ filename = buf;
+
+ /* load the bitmap and stretch it */
+ tmp = load_bitmap(filename, NULL);
+ pic = create_bitmap(64, 64);
+ stretch_blit(tmp, pic, 0, 0, tmp->w, tmp->h, 0, 0, pic->w, pic->h);
+ destroy_bitmap(tmp);
+
+ /* we are using double buffer mode, so create the back buffer */
+ buffer = create_bitmap(screen->w, screen->h);
+
+ set_trans_blender(128, 0, 64, 128);
+
+ /* exit on Esc key */
+ while (!key[KEY_ESC]) {
+ /* move every sprite and draw it on the back buffer */
+ for (i = 0; i < SPRITE_COUNT; i++) {
+ SPRITE *s = &sprites[i];
+ move_sprite(s);
+ draw_sprite_ex(buffer, pic, s->x, s->y, s->draw_type, mode);
+ }
+
+ /* handle the space key */
+ if (key[KEY_SPACE] && !hold_space) {
+ hold_space = 1;
+ /* switch to next flipping mode */
+ switch (mode) {
+ case DRAW_SPRITE_H_FLIP:
+ mode = DRAW_SPRITE_V_FLIP;
+ break;
+ case DRAW_SPRITE_V_FLIP:
+ mode = DRAW_SPRITE_VH_FLIP;
+ break;
+ case DRAW_SPRITE_VH_FLIP:
+ mode = DRAW_SPRITE_NO_FLIP;
+ break;
+ case DRAW_SPRITE_NO_FLIP:
+ mode = DRAW_SPRITE_H_FLIP;
+ break;
+ }
+ }
+ if (!key[KEY_SPACE]) {
+ hold_space = 0;
+ }
+
+ /* set the title according to the flipping mode used */
+ {
+ char * msg = 0;
+ if (mode == DRAW_SPRITE_VH_FLIP) {
+ msg = "horizontal and vertical flip";
+ } else if (mode == DRAW_SPRITE_H_FLIP) {
+ msg = "horizontal flip";
+ } else if (mode == DRAW_SPRITE_V_FLIP) {
+ msg = "vertical flip";
+ } else {
+ msg = "no flipping";
+ }
+ textprintf_ex(buffer, font, 1, 1, makecol(255, 255, 255), -1, msg);
+ }
+
+ /* finally blit the back buffer on the screen */
+ blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h);
+ clear_bitmap(buffer);
+
+ /* reduce CPU usage */
+ rest(20);
+ }
+
+ /* clean up */
+ destroy_bitmap(pic);
+ destroy_bitmap(buffer);
+
+ return 0;
+}
+END_OF_MAIN()
+