Re: [AD] proposal: draw_sprite_*_ex |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Peter Wang wrote:
On 2007-10-07, Milan Mimica <milan.mimica@xxxxxxxxxx> wrote:
DRAW_SPRITE_NO_FLIP | DRAW_SPRITE_H_FLIP Is the only open issue.
Can't we just have DRAW_SPRITE_HV_FLIP and not allow or-ing?
I don't remember why I suggesting OR-ing, so I have no problem
with that.
The patch needs some reformatting.
Here is the reformatted and cleaned patch.
Flipping mode flags are:
/* 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
#define DRAW_SPRITE_HV_FLIP 0x3
- No or-ing (at least not between these).
- DRAW_SPRITE_NO_FLIP could be changed to DRAW_SPRITE_PLAIN but that's a
minor thing.
- No docs.
- The patch is only for non-ASM version. That's the problem.
Should we (in 4.3.10+):
a) remove the ASM version completely?
b) just make the non-ASM version default?
(b) is a lot easier to do. Although, it doesn't really fix anything. ASM
and non-ASM would not be *API* compatible this time.
And, heh, looks like Watcom port doesn't support non-ASM.
--
Milan Mimica
http://sparklet.sf.net
Index: src/vtable24.c
===================================================================
--- src/vtable24.c (revision 9732)
+++ 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 9732)
+++ 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 9732)
+++ 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_EX(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 9732)
+++ 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_EX(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 9732)
+++ 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_EX(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 9732)
+++ 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_EX(p,d) ((p) += d)
#define DEC_PIXEL_PTR(p) ((p)--)
#define PUT_PIXEL(p,c) bmp_write16((uintptr_t) (p), (c))
@@ -37,7 +38,7 @@
/* Blender for putpixel (DRAW_MODE_TRANS). */
#define PP_BLENDER BLENDER_FUNC
-#define MAKE_PP_BLENDER(c) _blender_func16
+#define MAKE_PP_BLENDER(c) (!_blender_func16 && (al_assert(__FILE__,__LINE__), 0), _blender_func16)
#define PP_BLEND(b,o,n) ((*(b))((n), (o), _blender_alpha))
/* Blender for draw_trans_*_sprite. */
@@ -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 9732)
+++ src/c/cspr.h (working copy)
@@ -18,6 +18,138 @@
#ifndef __bma_cspr_h
#define __bma_cspr_h
+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 = ((tmp < 0) ? 0 : tmp);
+ dxbeg = sxbeg + dx;
+
+ tmp = dst->cr - dx;
+ w = ((tmp > src->w) ? 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 = ((tmp < 0) ? 0 : tmp);
+ dybeg = sybeg + dy;
+
+ tmp = dst->cb - dy;
+ h = ((tmp > src->h) ? 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_EX(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_EX(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.
@@ -178,8 +310,111 @@
}
}
+/* _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 = ((tmp < 0) ? 0 : tmp);
+ dxbeg = sxbeg + dx;
+
+ tmp = dst->cr - dx;
+ w = ((tmp > src->w) ? src->w : tmp) - sxbeg;
+ if (w <= 0)
+ return;
+
+ tmp = dst->ct - dy;
+ sybeg = ((tmp < 0) ? 0 : tmp);
+ dybeg = sybeg + dy;
+
+ tmp = dst->cb - dy;
+ h = ((tmp > src->h) ? 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.
*/
@@ -258,16 +493,96 @@
}
}
+/* _linear_draw_sprite_h_flip:
+ * Draws a sprite to a linear bitmap, flipping horizontally.
+ */
+void FUNC_LINEAR_DRAW_SPRITE_H_FLIP(BITMAP *dst, BITMAP *src, int dx, int dy)
+{
+ int x, y, w, h;
+ int dxbeg, dybeg;
+ int sxbeg, sybeg;
+ ASSERT(dst);
+ ASSERT(src);
+
+ if (dst->clip) {
+ int tmp;
+
+ tmp = dst->cl - dx;
+ sxbeg = ((tmp < 0) ? 0 : tmp);
+ dxbeg = sxbeg + dx;
+
+ tmp = dst->cr - dx;
+ w = ((tmp > src->w) ? 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 = ((tmp < 0) ? 0 : tmp);
+ dybeg = sybeg + dy;
+
+ tmp = dst->cb - dy;
+ h = ((tmp > src->h) ? 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;
+ }
+
+ 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)) {
+ 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)) {
+ PUT_MEMORY_PIXEL(d, c);
+ }
+ }
+ }
+ }
+}
+
/* _linear_draw_sprite_h_flip:
* Draws a sprite to a linear bitmap, flipping horizontally.
*/
-void FUNC_LINEAR_DRAW_SPRITE_H_FLIP(BITMAP *dst, BITMAP *src, int dx, int dy)
+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);
@@ -306,6 +621,9 @@
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);
@@ -316,6 +634,17 @@
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);
}
}
@@ -331,6 +660,17 @@
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);
}
}
@@ -338,8 +678,115 @@
}
}
+/* _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 = ((tmp < 0) ? 0 : tmp);
+ dxbeg = sxbeg + dx;
+
+ tmp = dst->cr - dx;
+ w = ((tmp > src->w) ? 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 = ((tmp < 0) ? 0 : tmp);
+ dybeg = sybeg + dy;
+
+ tmp = dst->cb - dy;
+ h = ((tmp > src->h) ? 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 9732)
+++ 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_EX(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 9732)
+++ 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 9732)
+++ 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 9732)
+++ 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 9732)
+++ 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 9732)
+++ 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 9732)
+++ include/allegro/gfx.h (working copy)
@@ -37,7 +37,18 @@
#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
+#define DRAW_SPRITE_HV_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 +225,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 9732)
+++ 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 9732)
+++ 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,241 @@
+/*
+ * 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 UP 0
+#define LEFT 1
+#define DOWN 2
+#define RIGHT 3
+
+/* define the number of sprites that will be displayed */
+#define SPRITE_COUNT 20
+
+
+/* define our sprite */
+typedef struct {
+ int x;
+ int y;
+
+ /* 0 = up, 1 = left, 2 = down, 3 = right */
+ int 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 = 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 = 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 = 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 = UP;
+ s->draw_type = DRAW_SPRITE_TRANS;
+ s->level = 3;
+ break;
+ }
+ }
+}
+
+
+/* used by sort function to compare sprites */
+int compare(AL_CONST void * a, AL_CONST void * b) {
+ sprite * s1 = (sprite *)a;
+ sprite * s2 = (sprite *)b;
+ if (s1->level < s2->level) {
+ return -1;
+ }
+ if (s1->level > s2->level) {
+ return 1;
+ }
+ return 0;
+}
+
+
+/* moves the sprite by one pixel acording to its direction */
+void move_sprite(sprite *s) {
+ switch (s->direction) {
+ case UP : {
+ s->y--;
+ if (s->y < -64) {
+ s->y = 480;
+ }
+ break;
+ }
+ case DOWN : {
+ s->y++;
+ if (s->y > 480) {
+ s->y = -64;
+ }
+ break;
+ }
+ case RIGHT : {
+ s->x++;
+ if (s->x > 640) {
+ s->x = -64;
+ }
+ break;
+ }
+ case 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), 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()
+