Beispiel #1
0
void Object::generate_error_bitmap()
{
	if(testBit(ISMEM_BITMAP))
	{
		bitmap = create_memory_bitmap();
	} else {
		bitmap = al_create_bitmap(w, h);
	}

    ALLEGRO_COLOR background = al_color_html("#3f51b5");
    ALLEGRO_COLOR shadow = al_color_html("#1a237e");
    ALLEGRO_COLOR sign = al_color_html("#ffeb3b");
	
	al_set_target_bitmap(bitmap);
    al_clear_to_color(background);

    // Shadow (3 triangles)
    al_draw_filled_triangle(w / 2.0f, h / 4.0f, w, (h * 3.0f) / 4.0f, w / 2.0f, h, shadow);
    al_draw_filled_triangle(w, (h * 3.0f) / 4.0f, w, h, w / 2.0f, h, shadow);
    al_draw_filled_triangle(w / 2.0f, h / 4.0f, w / 2.0f, h, w / 4.0f, (h * 3.0f) / 4.0f, shadow);
	
    // Alert sign triangle
	al_draw_filled_triangle(w / 2.0f, h / 4.0f, ((w * 3.0f) / 4), ((h * 3.0f) / 4.0f), w / 4.0f, ((h * 3.0f) / 4.0f), sign);
		
    // Exclamation point
	al_draw_filled_rectangle((w * 15.0f) / 32.0f, ((h * 14.0f) / 32.0f), ((w * 17.0f) / 32.0f), ((h * 19.0f) / 32.0f), background);
    al_draw_filled_rectangle((w * 15.0f) / 32.0f, (h * 5.0f) / 8.0f, (w * 17.0f) / 32.0f, (h * 11.0f) / 16.0f, background);
		
	al_set_target_backbuffer(al_get_current_display());
}
Beispiel #2
0
ALLEGRO_BITMAP *_al_create_bitmap_params(ALLEGRO_DISPLAY *current_display,
   int w, int h, int format, int flags)
{
   ALLEGRO_SYSTEM *system = al_get_system_driver();
   ALLEGRO_BITMAP *bitmap;
   ALLEGRO_BITMAP **back;
   int64_t mul;
   bool result;

   /* Reject bitmaps where a calculation pixel_size*w*h would overflow
    * int.  Supporting such bitmaps would require a lot more work.
    */
   mul = 4 * (int64_t) w * (int64_t) h;
   if (mul > (int64_t) INT_MAX) {
      ALLEGRO_WARN("Rejecting %dx%d bitmap\n", w, h);
      return NULL;
   }

   if ((flags & ALLEGRO_MEMORY_BITMAP) ||
         !current_display ||
         !current_display->vt ||
         current_display->vt->create_bitmap == NULL ||
         _al_vector_size(&system->displays) < 1)
   {
      if (flags & ALLEGRO_VIDEO_BITMAP)
         return NULL;

      return create_memory_bitmap(current_display, w, h, format, flags);
   }

   /* Else it's a display bitmap */

   bitmap = current_display->vt->create_bitmap(current_display, w, h,
      format, flags);
   if (!bitmap) {
      ALLEGRO_ERROR("failed to create display bitmap\n");
      return NULL;
   }

   bitmap->_display = current_display;
   bitmap->w = w;
   bitmap->h = h;
   bitmap->locked = false;
   bitmap->cl = 0;
   bitmap->ct = 0;
   bitmap->cr_excl = w;
   bitmap->cb_excl = h;
   al_identity_transform(&bitmap->transform);
   al_identity_transform(&bitmap->inverse_transform);
   bitmap->inverse_transform_dirty = false;
   al_identity_transform(&bitmap->proj_transform);
   al_orthographic_transform(&bitmap->proj_transform, 0, 0, -1.0, w, h, 1.0);
   bitmap->parent = NULL;
   bitmap->xofs = 0;
   bitmap->yofs = 0;
   bitmap->_flags |= ALLEGRO_VIDEO_BITMAP;
   bitmap->dirty = !(bitmap->_flags & ALLEGRO_NO_PRESERVE_TEXTURE);

   /* The display driver should have set the bitmap->memory field if
    * appropriate; video bitmaps may leave it NULL.
    */

   ASSERT(bitmap->pitch >= w * al_get_pixel_size(bitmap->_format));
   result = bitmap->vt->upload_bitmap(bitmap);

   if (!result) {
      al_destroy_bitmap(bitmap);
      if (flags & ALLEGRO_VIDEO_BITMAP)
         return NULL;
      /* With ALLEGRO_CONVERT_BITMAP, just use a memory bitmap instead if
      * video failed.
      */
      return create_memory_bitmap(current_display, w, h, format, flags);
   }
   
   /* We keep a list of bitmaps depending on the current display so that we can
    * convert them to memory bimaps when the display is destroyed. */
   back = _al_vector_alloc_back(&current_display->bitmaps);
   *back = bitmap;

   return bitmap;
}