dst_x += part->viewport_x;
dst_y += part->viewport_y;
+ SetBitmapAlphaNextBlit(src_bitmap, g->alpha);
+
if (drawing_target == DRAW_TO_SCREEN)
blit_screen(src_bitmap, src_x, src_y, width, height,
dst_x, dst_y);
{ ".sort_priority", ARG_UNDEFINED, TYPE_INTEGER },
{ ".class", ARG_UNDEFINED, TYPE_STRING },
{ ".style", ARG_UNDEFINED, TYPE_STRING },
+ { ".alpha", ARG_UNDEFINED, TYPE_INTEGER },
{ ".active_xoffset", "0", TYPE_INTEGER },
{ ".active_yoffset", "0", TYPE_INTEGER },
{ ".pressed_xoffset", "0", TYPE_INTEGER },
g->sort_priority = 0; // default for title screens
g->class = 0;
g->style = STYLE_DEFAULT;
+ g->alpha = -1;
g->bitmaps = src_bitmaps;
g->bitmap = src_bitmap;
g->class = parameter[GFX_ARG_CLASS];
if (parameter[GFX_ARG_STYLE] != ARG_UNDEFINED_VALUE)
g->style = parameter[GFX_ARG_STYLE];
+ if (parameter[GFX_ARG_ALPHA] != ARG_UNDEFINED_VALUE)
+ g->alpha = parameter[GFX_ARG_ALPHA];
// this is only used for drawing menu buttons and text
g->active_xoffset = parameter[GFX_ARG_ACTIVE_XOFFSET];
return (blend_mode == SDL_BLENDMODE_BLEND);
}
-void SDLSetAlpha(SDL_Surface *surface, boolean set, int alpha)
+static void SDLSetSurfaceAlpha(SDL_Surface *surface, boolean set, int alpha)
{
SDL_BlendMode blend_mode = (set ? SDL_BLENDMODE_BLEND : SDL_BLENDMODE_NONE);
SDL_SetSurfaceAlphaMod(surface, alpha);
}
+static void SDLSetTextureAlpha(SDL_Texture *texture, boolean set, int alpha)
+{
+ SDL_BlendMode blend_mode = (set ? SDL_BLENDMODE_BLEND : SDL_BLENDMODE_NONE);
+
+ SDL_SetTextureBlendMode(texture, blend_mode);
+ SDL_SetTextureAlphaMod(texture, alpha);
+}
+
+static void SDLSetBitmapAlpha(Bitmap *bitmap, boolean is_texture,
+ boolean is_masked)
+{
+ int alpha_next_blit = bitmap->alpha_next_blit;
+
+ // alpha value must be requested every time before blitting, if needed
+ bitmap->alpha_next_blit = -1;
+
+ // nothing to do if requested alpha value is already set
+ if (bitmap->alpha[is_texture][is_masked] == alpha_next_blit)
+ return;
+
+ // store requested alpha value for masked/unmasked surface/texture
+ bitmap->alpha[is_texture][is_masked] = alpha_next_blit;
+
+ // set blend mode if bitmap is masked or if alpha value is defined
+ boolean set_blend_mode = (is_masked || alpha_next_blit != -1);
+
+ // if alpha value is undefined, use default (opaque) alpha value
+ if (alpha_next_blit == -1)
+ alpha_next_blit = SDL_ALPHA_OPAQUE;
+
+ if (is_texture)
+ SDLSetTextureAlpha(is_masked ? bitmap->texture_masked : bitmap->texture,
+ set_blend_mode, alpha_next_blit);
+ else
+ SDLSetSurfaceAlpha(is_masked ? bitmap->surface_masked : bitmap->surface,
+ set_blend_mode, alpha_next_blit);
+}
+
+void SDLSetAlpha(SDL_Surface *surface, boolean set, int alpha)
+{
+ SDLSetSurfaceAlpha(surface, set, alpha);
+}
+
const char *SDLGetRendererName(void)
{
static SDL_RendererInfo renderer_info;
dst_rect.w = width;
dst_rect.h = height;
+ SDLSetBitmapAlpha(src_bitmap, FALSE, mask_mode == BLIT_MASKED);
+
// if (src_bitmap != backbuffer || dst_bitmap != window)
if (!(src_bitmap == backbuffer && dst_bitmap == window))
SDL_BlitSurface((mask_mode == BLIT_MASKED ?
dst_rect.w = width;
dst_rect.h = height;
+ SDLSetBitmapAlpha(bitmap, TRUE, mask_mode == BLIT_MASKED);
+
SDL_RenderCopy(sdl_renderer, texture, &src_rect, &dst_rect);
}
char *source_filename;
int width, height;
+
+ int alpha[2][2]; // [surface|texture][opaque|masked]
+ int alpha_next_blit;
+
SDL_Surface *surface;
SDL_Surface *surface_masked;
SDL_Texture *texture;
Bitmap *CreateBitmapStruct(void)
{
- return checked_calloc(sizeof(Bitmap));
+ Bitmap *new_bitmap = checked_calloc(sizeof(Bitmap));
+
+ new_bitmap->alpha[0][0] = -1;
+ new_bitmap->alpha[0][1] = -1;
+ new_bitmap->alpha[1][0] = -1;
+ new_bitmap->alpha[1][1] = -1;
+ new_bitmap->alpha_next_blit = -1;
+
+ return new_bitmap;
}
Bitmap *CreateBitmap(int width, int height, int depth)
return TRUE;
}
+void SetBitmapAlphaNextBlit(Bitmap *bitmap, int alpha)
+{
+ // set alpha value for next blitting of bitmap
+ bitmap->alpha_next_blit = alpha;
+}
+
void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap,
int src_x, int src_y, int width, int height,
int dst_x, int dst_y)
Bitmap *CreateBitmap(int, int, int);
void ReCreateBitmap(Bitmap **, int, int);
void FreeBitmap(Bitmap *);
+void SetBitmapAlphaNextBlit(Bitmap *, int);
void BlitBitmap(Bitmap *, Bitmap *, int, int, int, int, int, int);
void BlitBitmapTiled(Bitmap *, Bitmap *, int, int, int, int, int, int, int, int);
void FadeRectangle(int, int, int, int, int, int, int,
GFX_ARG_SORT_PRIORITY,
GFX_ARG_CLASS,
GFX_ARG_STYLE,
+ GFX_ARG_ALPHA,
GFX_ARG_ACTIVE_XOFFSET,
GFX_ARG_ACTIVE_YOFFSET,
GFX_ARG_PRESSED_XOFFSET,
int class;
int style;
+ int alpha;
int active_xoffset;
int active_yoffset;