Exemplo n.º 1
0
bool Bitmap::CreateTransparent(int width, int height, int color_depth)
{
    if (Create(width, height, color_depth))
    {
        clear_to_color(_alBitmap, bitmap_mask_color(_alBitmap));
        return true;
    }
    return false;
}
Exemplo n.º 2
0
Menu::Menu()
    : m_up(KEY_UP)
    , m_down(KEY_DOWN)
    , m_enter(KEY_ENTER)
    , m_esc(KEY_ESC)
{
    m_start_time = GAME_T;
    m_selected = 0;
    m_options = 4;

    m_logo = create_bitmap(text_length(gamefont, gametitle),
                           text_height(gamefont));
    clear_to_color(m_logo, bitmap_mask_color(m_logo));
    draw_text(m_logo, 0, 0, makecol(200, 180, 0), gametitle);
}
Exemplo n.º 3
0
static BITMAP *convert_bitmap_alpha(BITMAP *bmp_orig, bool keep_alpha)
{
    if (!bmp_orig) return NULL;

    // Non 32bpp bitmap just can't contain alpha channel
    if (bitmap_color_depth(bmp_orig) != 32) return bmp_orig;

    // Try to detect alpha channel in the bitmap
    bool has_alpha = false;
    bool has_trans = false;
    bool has_opaque = false;
    for (int y = 0; y < bmp_orig->h; y++) {
        const uint32 *line = (const uint32 *)bmp_orig->line[y];
        for (int x = 0; x < bmp_orig->w; x++) {
            uint32 a = line[x] & 0xFF000000;
            if (a == 0)
                has_trans = true;
            else if (a == 0xFF000000)
                has_opaque = true;
            else
                has_alpha = true;
        }
    }
    
    if (has_alpha || keep_alpha) {
        for (int x = 0; x < bmp_orig->w; x++)
            for (int y = 0; y < bmp_orig->h; y++) {
                int c = getpixel(bmp_orig, x, y);
                if (geta32(c) == 0)
                    putpixel(bmp_orig, x, y, MASK_COLOR_32);
            }
        return bmp_orig;
    } else {
        bool has_1bit_alpha = has_trans && has_opaque;
        BITMAP *bmp = create_bitmap(bmp_orig->w, bmp_orig->h);
        clear_to_color(bmp, bitmap_mask_color(bmp));
        for (int x = 0; x < bmp_orig->w; x++)
            for (int y = 0; y < bmp_orig->h; y++) {
                int c = getpixel(bmp_orig, x, y);
                if (!has_1bit_alpha || geta32(c) != 0) {
                    putpixel(bmp, x, y, makeacol(getr32(c), getg32(c), getb32(c), 255));
                }
            }
        destroy_bitmap(bmp_orig);
        return bmp;
    }
}
Exemplo n.º 4
0
void ALSoftwareGraphicsDriver::draw_sprite_with_transparency(BITMAP* piccy, int xxx, int yyy, int transparency)
{
    int screen_depth = bitmap_color_depth(virtualScreen);
    int sprite_depth = bitmap_color_depth(piccy);

    if (sprite_depth < screen_depth) {

        if ((sprite_depth == 8) && (screen_depth >= 24)) {
            // 256-col sprite -> truecolor background
            // this is automatically supported by allegro, no twiddling needed
            draw_sprite(virtualScreen, piccy, xxx, yyy);
            return;
        }
        // 256-col spirte -> hi-color background, or
        // 16-bit sprite -> 32-bit background
        BITMAP* hctemp=create_bitmap_ex(screen_depth, piccy->w, piccy->h);
        blit(piccy,hctemp,0,0,0,0,hctemp->w,hctemp->h);
        int bb,cc,mask_col = bitmap_mask_color(virtualScreen);

        if (sprite_depth == 8) {
            // only do this for 256-col, cos the blit call converts
            // transparency for 16->32 bit
            for (bb=0; bb<hctemp->w; bb++) {
                for (cc=0; cc<hctemp->h; cc++)
                    if (_getpixel(piccy,bb,cc)==0) putpixel(hctemp,bb,cc,mask_col);
            }
        }

        draw_sprite(virtualScreen, hctemp, xxx, yyy);
        destroy_bitmap(hctemp);
    }
    else
    {
        if ((transparency != 0) && (screen_depth > 8) &&
                (sprite_depth > 8) && (bitmap_color_depth(virtualScreen) > 8))
        {
            set_trans_blender(0,0,0, transparency);
            draw_trans_sprite(virtualScreen, piccy, xxx, yyy);
        }
        else
            draw_sprite(virtualScreen, piccy, xxx, yyy);
    }

}
Exemplo n.º 5
0
int IAGSEngine::CreateDynamicSprite(int32 coldepth, int32 width, int32 height) {

  int gotSlot = spriteset.findFreeSlot();
  if (gotSlot <= 0)
    return 0;

  if ((width < 1) || (height < 1))
    quit("!IAGSEngine::CreateDynamicSprite: invalid width/height requested by plugin");

  // resize the sprite to the requested size
  block newPic = create_bitmap_ex(coldepth, width, height);
  if (newPic == NULL)
    return 0;

  clear_to_color(newPic, bitmap_mask_color(newPic));

   // add it into the sprite set
  add_dynamic_sprite(gotSlot, newPic);
  return gotSlot;
}
Exemplo n.º 6
0
static BITMAP *generate_bitmap(AL_CONST unsigned char templat[], int w, int h)
{
    BITMAP *bmp;
    AL_CONST unsigned char *p;
    int x, y;

    bmp = create_bitmap(w, h);
    p = templat;

    for (y = 0; y < h; y++) {
        for (x = 0; x < w; x++) {
            if (*p == 0)
		putpixel(bmp, x, y, bitmap_mask_color(bmp));
            else
		putpixel(bmp, x, y, makecol(*p, *p, *p));
            p++;
        }
    }            
        
    return bmp;
}
Exemplo n.º 7
0
void draw_text(BITMAP *bmp, int x, int y, int w, int h, int color, const char *format, ...)
{
  if (w > 0 && h > 0) {
    char buf[512];
    va_list ap;

    va_start(ap, format);
    uvszprintf(buf, sizeof(buf), format, ap);
    va_end(ap);

    BITMAP *tmp = create_bitmap(text_length(gamefont, buf),
				text_height(gamefont)+1);

    clear_to_color(tmp, bitmap_mask_color(tmp));
    textout_ex(tmp, gamefont, buf, 0, 1, blend_color(color, makecol(0, 0, 0), 0.5), -1);
    textout_ex(tmp, gamefont, buf, 0, 0, color, -1);

    masked_stretch_blit(tmp, bmp, 0, 0, tmp->w, tmp->h, x, y, w, h);
    destroy_bitmap(tmp);
  }
}
Exemplo n.º 8
0
void shadowed_masked_image::set_image(BITMAP *_image)
{
  if (image = _image)
  {  
    if (bitmap_color_depth(image) != 8)
    {
      if (shadow_mask) destroy_bitmap(shadow_mask);
      shadow_mask = create_bitmap_ex(bitmap_color_depth(image), image->w, image->h);
  
      clear_to_color(shadow_mask, bitmap_mask_color(shadow_mask));
  
      set_trans_blender(shadow_level, shadow_level, shadow_level, 0);
      draw_lit_sprite(shadow_mask, image, 0, 0, 255);
      set_trans_blender(255, 0, 255, 0);
      draw_lit_sprite(shadow_mask, image, -x_offset, -y_offset, 255);
    } else
    {
      if (shadow_mask) destroy_bitmap(shadow_mask);
      shadow_mask = 0;
    }
  
    resize(image->w - 1 + x_offset, image->h - 1 + y_offset);
  } 
}                                                       
Exemplo n.º 9
0
void Bitmap::FillTransparent()
{
    clear_to_color(_alBitmap, bitmap_mask_color(_alBitmap));
}
Exemplo n.º 10
0
int IAGSEngine::GetBitmapTransparentColor(BITMAP *bmp) {
  return bitmap_mask_color (bmp);
}
Exemplo n.º 11
0
BITMAP *IAGSEngine::CreateBlankBitmap (int32 width, int32 height, int32 coldep) {
  BITMAP *tempb = create_bitmap_ex(coldep, width, height);
  clear_to_color(tempb, bitmap_mask_color(tempb));
  return tempb;
}
Exemplo n.º 12
0
/*
 * call-seq:
 *   bitmap_mask_color(bmp) -> int
 *
 * Returns the mask color for the specified bitmap (the value which is skipped
 * when drawing sprites). For 256-color bitmaps this is zero, and for truecolor
 * bitmaps it is bright pink (maximum red and blue, zero green). A frequent use
 * of this function is to clear a bitmap with the mask color so you can later
 * use this bitmap with masked_blit or draw_sprite after drawing other stuff on
 * it. Example:
 *   # Replace mask color with another color.
 *   (0...bmp.h).each do |y|
 *     (0...bmp.w).each do |x|
 *       if (getpixel(bmp, x, y) == bitmap_mask_color(bmp))
 *         putpixel(bmp, x, y, another_color)
 *       end
 *     end
 *   end
 */
VALUE a4r_API_bitmap_mask_color(VALUE self, VALUE bmp)
{
  BITMAP *bitmap;
  Data_Get_Struct(bmp, BITMAP, bitmap);
  return INT2FIX(bitmap_mask_color(bitmap));
}
Exemplo n.º 13
0
// prepares the person_bmp
BITMAP *Person::prepare_sprite()
{
  static BITMAP *person_bmp = NULL;
  if (person_bmp == NULL)
    person_bmp = create_bitmap(TILE_W, TILE_H);

  int ani_frame = -1;

  switch (m_state) {

    case STAND_PERSON:
      ani_frame = ANI_FRAME_STAND;
      break;

    case WALKING_PERSON:
      ani_frame = ((GAME_T - m_state_time) % (BPS/4)) < (BPS/8) ?
	ANI_FRAME_WALK1: ANI_FRAME_WALK2;
      break;

    case LOOKING_PERSON:
      ani_frame = ANI_FRAME_LOOK;
      break;

    case CALLING_PERSON: {
      if (GAME_T - m_state_time < CALLING_DURATION*1/6)
	ani_frame = ANI_FRAME_HELP1;
      else if (GAME_T - m_state_time < CALLING_DURATION*2/6)
	ani_frame = ANI_FRAME_HELP2;
      else if (GAME_T - m_state_time < CALLING_DURATION*3/6)
	ani_frame = ANI_FRAME_HELP3;
      else if (GAME_T - m_state_time < CALLING_DURATION*4/6)
	ani_frame = ANI_FRAME_HELP3;
      else if (GAME_T - m_state_time < CALLING_DURATION*5/6)
	ani_frame = ANI_FRAME_HELP3;
      else
	ani_frame = ANI_FRAME_HELP1;
      break;
    }

    case ABDUCTING_PERSON:
      ani_frame = ANI_FRAME_HELP3;
      break;

    case FALLING_PERSON:
      ani_frame = ANI_FRAME_HELP2;
      break;

    case DEAD_PERSON:
      // impossible to be here
      break;
  }

  if (ani_frame < -1) {
    clear_to_color(person_bmp, bitmap_mask_color(person_bmp));
    return person_bmp;
  }

  blit(MEDIA_BITMAP(PEOPLE_PCX), person_bmp,
       ani_frame*TILE_W, m_type*TILE_H,
       0, 0, TILE_W, TILE_H);

  lit_mode(0, 0, 0);
  draw_lit_sprite(person_bmp, person_bmp, 0, 0,
		  static_cast<int>(255 * m_toast_factor));
  solid_mode();

  return person_bmp;
}