コード例 #1
0
ファイル: frame.cpp プロジェクト: AmandaBayless/Lix
void Frame::draw_self()
{
    // Diese hier machen das Zeichnen übersichtlicher.
    BITMAP* g    = get_ground().get_al_bitmap();
    const int x1 = get_x_here() - 2;
    const int y1 = get_y_here() - 2;
    const int x2 = get_x_here() + 1 + get_xl();
    const int y2 = get_y_here() + 1 + get_yl();

    // Farben wählen
    int col_1 = color[COL_API_D];
    int col_3 = color[COL_API_L];

    // Acquiren, malen, freilassen
    acquire_bitmap(g);
    vline   (g, x1,   y1,         y2-1, col_1); // Links  außen
    vline   (g, x1+1, y1,         y2-2, col_1); // Links  innen
    hline   (g, x1+2, y1,   x2-1,       col_1); // Oben   außen
    hline   (g, x1+2, y1+1, x2-2,       col_1); // Oben   innen
    vline   (g, x2,   y1+1,       y2,   col_3); // Rechts außen
    vline   (g, x2-1, y1+2,       y2,   col_3); // Rechts innen
    hline   (g, x1+1, y2,   x2-2,       col_3); // Unten  außen
    hline   (g, x1+2, y2-1, x2-2,       col_3); // Unten  innen
    release_bitmap(g);
}
コード例 #2
0
/*
 * call-seq:
 *   acquire_bitmap(bmp) -> nil
 *
 * Acquires the specified video bitmap prior to drawing onto it. You never need
 * to call the function explicitly as it is low level, and will only give you a
 * speed up if you know what you are doing. Using it wrongly may cause slowdown,
 * or even lock up your program.
 *
 * Note: You do never need to use acquire_bitmap on a memory bitmap, i.e. a
 * normal bitmap created with create_bitmap. It will simply do nothing in that
 * case.
 *
 * It still can be useful, because e.g. under the current DirectDraw driver of
 * Allegro, most drawing functions need to lock a video bitmap before drawing to
 * it. But doing this is very slow, so you will get much better performance if
 * you acquire the screen just once at the start of your main redraw function,
 * then call multiple drawing operations which need the bitmap locked, and only
 * release it when done.
 *
 * Multiple acquire calls may be nested, but you must make sure to match up the
 * acquire_bitmap and release_bitmap calls. Be warned that DirectX and X11
 * programs activate a mutex lock whenever a surface is locked, which prevents
 * them from getting any input messages, so you must be sure to release all your
 * bitmaps before using any timer, keyboard, or other non-graphics routines!
 *
 * Note that if you are using hardware accelerated VRAM->VRAM functions, you
 * should not call acquire_bitmap. Such functions need an unlocked target bitmap
 * under DirectX, so there is now just the opposite case from before - if the
 * bitmap is already locked with acquire_bitmap, the drawing operation has to
 * unlock it.
 *
 * Note: For backwards compatibility, the unlocking behavior of such functions
 * is permanent. That is, if you call acquire_bitmap first, then call e.g. an
 * accelerated blit, the DirectX bitmap will be unlocked internally (it won't
 * affect the nesting counter of acquire/release calls).
 *
 * There is no clear cross-platform way in this Allegro version to know which
 * drawing operations need a locked/unlocked state. For example a normal
 * rectfill most probably is accelerated under DirectX, and therefore needs the
 * screen unlocked, but an XOR rectfill, or one with blending activated, most
 * probably is not, and therefore locks the screen. And while the DirectX driver
 * will do automatic unlocking, there is no such thing under X11, where the
 * function is used to synchronize X11 calls from different threads. Your best
 * bet is to never use acquire_bitmap - changes are you are doing something in
 * the wrong way if you think you need it.
 *
 * Warning: This function can be very dangerous to use, since the whole program
 * may get locked while the bitmap is locked. So the lock should only be held
 * for a short time, and you should not call anything but drawing operations
 * onto the locked video bitmap while a lock is in place. Especially don't call
 * things like show_mouse (or scare_mouse which calls that) or readkey, since it
 * will most likely deadlock your entire program.
 */
VALUE a4r_API_acquire_bitmap(VALUE self, VALUE bmp)
{
  BITMAP *bitmap;
  Data_Get_Struct(bmp, BITMAP, bitmap);
  acquire_bitmap(bitmap);
  return Qnil;
}
コード例 #3
0
/** \ingroup faders
 *  Fades source bitmap from/to a color and places output bitmap into the
 *  destination at the specified coordinates. Source and destination
 *  bitmaps must have the same color depth; supported color depths are 15,
 *  16 and 32 bpp. Fact should range 0-255, and it is used to specify the
 *  fade factor with which the destination bitmap will be drawn.
 *  A factor of 255 will render the original bitmap, whereas a factor of 0
 *  will only draw a rectangle of the specified color.
 *
 * <pre>
 *  dest_red = (src_red * fact / 255) + (color * (255 - fact) / 255)
 * </pre>
 *  Repeat for green and blue, and for all pixels to be displayed.
 *
 *  MMX and SSE will automatically be used if they are present.
 *
 *  \param src  The source bitmap. Must be a linear memory bitmap or
 *              sub-bitmap thereof, and must be in 15, 16 or 32 bpp.
 *  \param dst  The destination bitmap. Must be in 15, 16 or 32 bpp
 *              and linear, but not necessarily a memory bitmap.
 *  \param x    The coordinate on the X axis of teh destination bitmap
 *              to place the faded source bitmap at.
 *  \param y    The coordinate on the Y axis of teh destination bitmap
 *              to place the faded source bitmap at.
 *  \param color The color to fade to. This needs to be in the same depth
 *              as the bitmaps.
 *  \param fact Fade factor. Should be in the range 0-255.
 */
void fblend_fade_to_color(BITMAP *src, BITMAP *dst, int x, int y, int color, int fact) {

    int w, h;
	
	int src_x = 0, src_y = 0, dst_x = x, dst_y = y;
	int src_depth, dst_depth;
	
	w = src->w;
	h = src->h;
	
	/* Clip the image */
	if (dst_x < 0) {
		w += dst_x;
		src_x -= dst_x;
		dst_x = 0;
	}
	if (dst_y < 0) {
		h += dst_y;
		src_y -= dst_y;
		dst_y = 0;
	}
	if (dst_x + w >= dst->w)
		w -= dst_x + w - dst->w;
	if (dst_y + h >= dst->h)
		h -= dst_y + h - dst->h;

	/* Nothing to do? */
	if (w < 1 || h < 1)
		return;
	
	src_depth = bitmap_color_depth(src);
	dst_depth = bitmap_color_depth(dst);
	
	/* Incorrct color depths */
	if (!(src_depth == 16 && dst_depth == 16)
			&& !(src_depth == 15 && dst_depth == 15)
			&& !(src_depth == 32 && dst_depth == 32))
		return;
		
	/* Can we do a blit or rectfill instead? */
	if (fact >= 255) {
		blit(src, dst, src_x, src_y, dst_x, dst_y, w, h);
		return;
	}
	if (fact <= 0) {
		rectfill(dst, dst_x, dst_y, dst_x + w - 1, dst_y + h - 1, color);
		return;
	}

	acquire_bitmap(dst);

	/* 16 bit code */	
	if (src_depth == 16) {

		#ifdef FBLEND_MMX
			if (cpu_capabilities & CPU_MMX) {
				fact = (fact + 7) >> 3;
				fblend_fade_mmx_16(src, dst, src_x, src_y, dst_x, dst_y, w, h, color, fact);
			}
			else
コード例 #4
0
ファイル: MODEX.cpp プロジェクト: mcgrue/maped2w
int ModeXShowPage() {
	CheckTimerStuff();

	acquire_bitmap(screen);
	stretch_blit(get_offscreen(), screen, 0, 0, tsx, tsy, 0, 0, SCREEN_W, SCREEN_H);
	release_bitmap(screen);

	return 0;
}
コード例 #5
0
ファイル: game.cpp プロジェクト: OscarRPR/extreme-blocks
void drawScreen()
{
	//Draw everything need for play the game
	clearScreen();

	acquire_bitmap(score_buffer);
	drawInfo(score, lev_act, time_l, rows_del, myfont, speed-9);
	
	acquire_bitmap(map_buffer);
	drawBoard();
	drawPiece(current, 0);

	acquire_bitmap(next_buffer);
	drawPiece(next, 1);

	blit (map_buffer, screen, 0, 0, 100, 40, 200, 400);
	blit (score_buffer, screen, 0, 0, 350, 40, 180, 160);
	blit (next_buffer, screen, 0, 0, 350, 210, 80, 80);

	release_bitmap(map_buffer);
	release_bitmap(score_buffer);
	release_bitmap(next_buffer);

}
コード例 #6
0
ファイル: button.cpp プロジェクト: Lucki/Lix
void Button::draw_self() {
    // Diese hier machen das Zeichnen übersichtlicher.
    BITMAP* g    = get_ground().get_al_bitmap();
    const int x1 = get_x_here();
    const int y1 = get_y_here();
    const int x2 = get_x_here() + get_xl() - 1;
    const int y2 = get_y_here() + get_yl() - 1;

    if (down) {
        color_1    = color[COL_API_DOWN_D];
        color_2    = color[COL_API_DOWN_M];
        color_3    = color[COL_API_DOWN_L];
        color_text = color[COL_TEXT  ];
    } else if (on) {
        color_1    = color[COL_API_ON_D];
        color_2    = color[COL_API_ON_M];
        color_3    = color[COL_API_ON_L];
        color_text = color[COL_TEXT_ON   ];
    } else {
        color_1    = color[COL_API_L   ];
        color_2    = color[COL_API_M   ];
        color_3    = color[COL_API_D   ];
        color_text = color[COL_TEXT];
    }

    // Jetzt wird's ernst
    acquire_bitmap(g);

    // Jetzt malen!
    putpixel(g, x1,   y2,               color_2); // Unten links außen
    putpixel(g, x1+1, y2-1,             color_2); // Unten links innen
    putpixel(g, x2-1, y1+1,             color_2); // Oben rechts außen
    putpixel(g, x2,   y1,               color_2); // Oben rechts innen
    rectfill(g, x1+2, y1+2, x2-2, y2-2, color_2); // Mittelfläche
    vline   (g, x1,   y1,         y2-1, color_1); // Links  außen
    vline   (g, x1+1, y1,         y2-2, color_1); // Links  innen
    hline   (g, x1+2, y1,   x2-1,       color_1); // Oben   außen
    hline   (g, x1+2, y1+1, x2-2,       color_1); // Oben   innen
    vline   (g, x2,   y1+1,       y2,   color_3); // Rechts außen
    vline   (g, x2-1, y1+2,       y2,   color_3); // Rechts innen
    hline   (g, x1+1, y2,   x2-2,       color_3); // Unten  außen
    hline   (g, x1+2, y2-1, x2-2,       color_3); // Unten  innen

    release_bitmap(g);
}
コード例 #7
0
ファイル: mouse.c プロジェクト: AntonLanghoff/whitecatlib
/* mouse_move:
 *  Timer interrupt handler for redrawing the mouse pointer.
 */
static void mouse_move(void)
{
   if (mouse_semaphore)
      return;

   mouse_semaphore = TRUE;

   /* periodic poll */
   if (mouse_driver->timer_poll) {
      mouse_driver->timer_poll();
      if (!mouse_polled)
	 update_mouse();
   }

   /* redraw pointer */
   if ((!freeze_mouse_flag) && (_mouse_screen) && ((mx != _mouse_x) || (my != _mouse_y) || (mon != _mouse_on))) {
      acquire_bitmap(_mouse_screen);

      if (gfx_capabilities & GFX_HW_CURSOR) {
	 if (_mouse_on) {
	    gfx_driver->move_mouse(mx=_mouse_x, my=_mouse_y);
	    mon = TRUE;
	 }
	 else {
	    gfx_driver->move_mouse(mx=MOUSE_OFFSCREEN, my=MOUSE_OFFSCREEN);
	    mon = FALSE;
	 }
      }
      else {
#ifdef ALLEGRO_DOS
	 /* bodge to avoid using non legacy 386 asm code inside a timer handler */
	 int old_capabilities = cpu_capabilities;
	 cpu_capabilities = 0;
#endif
	 draw_mouse(TRUE, TRUE);
#ifdef ALLEGRO_DOS
	 cpu_capabilities = old_capabilities;
#endif
      }

      release_bitmap(_mouse_screen);
   }

   mouse_semaphore = FALSE;
}
コード例 #8
0
ファイル: savepng.c プロジェクト: zeromus/ZeldaClassic
int save_png(AL_CONST char *filename, BITMAP *bmp, AL_CONST RGB *pal)
{
    PACKFILE *fp;
    int result;

    ASSERT(filename);
    ASSERT(bmp);

    fp = pack_fopen(filename, "w");
    if (!fp)
	return -1;
    
    acquire_bitmap(bmp);
    result = really_save_png(fp, bmp, pal);
    release_bitmap(bmp);

    pack_fclose(fp);

    return result;
}
コード例 #9
0
ファイル: globaldata.cpp プロジェクト: marmistrz/atanks
void GLOBALDATA::do_updates ()
{
	bool isBgUpdNeeded = lastUpdatesCount > 0;

	acquire_bitmap(screen);
	for (int32_t i = 0; i < updateCount; ++i) {
		blit( canvas, screen,
				updates[i].x, updates[i].y, updates[i].x, updates[i].y,
				updates[i].w, updates[i].h);

		if (isBgUpdNeeded)
			make_bgupdate( updates[i].x, updates[i].y,
							updates[i].w, updates[i].h);
	}
	release_bitmap(screen);
	if (!isBgUpdNeeded) {
		lastUpdatesCount = updateCount;
		memcpy (lastUpdates, updates, sizeof (BOX) * updateCount);
	}
	updateCount = 0;
}
コード例 #10
0
ファイル: game.cpp プロジェクト: weimingtom/db-speedhack07
void Game::draw()
{
	acquire_bitmap(mBuffer);

    switch (mState) 
    {
    case SPLASHSCREEN:
        mSplashScreen->draw(mBuffer);
        break;
	case END:
		mEnding->draw(mBuffer);
		break;
    case BONUS_LEVEL_OR_SHOP:
        clear_to_color(mBuffer, makecol(0, 0, 0));
        mLevel->draw(mBuffer);
        mAllegroGraphics->setTarget(mBuffer);
        mGui->draw();
        draw_sprite(mBuffer, mouse_sprite, mouse_x / 2, mouse_y / 2);
        break;
    case HIGH_SCORE:
    case SHOP:
	case MENU:
        mAllegroGraphics->setTarget(mBuffer);
        mGui->draw();
        draw_sprite(mBuffer, mouse_sprite, mouse_x / 2, mouse_y / 2);
		break;
    case LEVEL:
        clear_to_color(mBuffer, makecol(0, 0, 0));
        mLevel->draw(mBuffer);
        break;
    case PAUSE:
        break;
	case EXIT:
		break;
	default:
		throw DBSH07_EXCEPTION("Unknown game state.");
   }
	release_bitmap(mBuffer);
}
コード例 #11
0
ファイル: font.cpp プロジェクト: Fomka/ufo2000
/** Renders a glyph corresponding to given char at given position in given bitmap.
 *
 * @param f The 'this' pointer.
 * @param ch The character.
 * @param fg Foreground color. Currently five color indexes starting with this one are used to draw the glyph.
 * @param bg Background color, AKA textmode.
 * @param bmp Destination bitmap.
 * @param  x  X coordinate of top left corner of glyph bounding box.
 * @param  y  Y coordinate of top left corner of glyph bounding box.
 * @return Glyph width in pixels.
 */
static int uaf_render_char(AL_CONST FONT *f, int ch, int fg, int bg, BITMAP *bmp, int x, int y) {
    uaf_fontcache *thecache = NULL;
    uaf_internal_data *idat = (uaf_internal_data *) (f->data);
    int i, gotcache = 0, srcy, srcw, srch;
    BITMAP *srcbmp;
    
    /* dump_font_info(f); */
    
    if (ch == 0x0020) { /* skip space. */
        return idat->space_width;
    }
    
    if (fg < 0) {
        fg = idat->base_color;
    }
    
    if ( idat->cachecount != 0 )  {
        /* try to find matching cache entry. */
        for (i=0; i<idat->cachecount; i++) {
            thecache = idat->cache + i;
            if ( (thecache->tmode == bg) && (thecache->fgcol == fg) ) {
                gotcache = 1;
                break;
            }
        }
    }
    
    /* cache miss: create */
    if ((!gotcache) || idat->cachecount == 0 ) {
        thecache = uaf_make_cacheentry(f, bg, fg);
    }
    
    srch = f->height;
    
    switch (ch >> 8) {
        case 0: /* basic latin & latin-1 */
            if (idat->rectU00[ch & 0xFF].w >= 0) {
                srcbmp = thecache->U00;
                srcw = idat->rectU00[ch & 0xFF].w;
                srcy = idat->rectU00[ch & 0xFF].y;
                break;
            } else { /* w<0 : glyph does not exist. */
                if (ch != allegro_404_char) {
                    return f->vtable->render_char(f, allegro_404_char, fg, bg, bmp, x, y);
                } else {
                    return 0; /* prevent loop */
                }
            }
            
        case 4: /* cyrillic */
            if (idat->rectU04[ch & 0xFF].w >= 0) {
                srcbmp = thecache->U04;
                srcw = idat->rectU04[ch & 0xFF].w;
                srcy = idat->rectU04[ch & 0xFF].y;
                break;
            } else { /* w<0 : glyph does not exist. */
                if (ch != allegro_404_char) {
                    return f->vtable->render_char(f, allegro_404_char, fg, bg, bmp, x, y);
                } else {
                    return 0; /* prevent loop */
                }
            }
        default: /* unicode section not implemented. */
            if (ch != allegro_404_char) {
                return f->vtable->render_char(f, allegro_404_char, fg, bg, bmp, x, y);
            } else {
                return 0;
            }
    }
    if (srcw > 0) {
        /* do ze blit. Fgcol is already normalized. */
        acquire_bitmap(bmp);
        
        if (bg > 0) {
            blit(srcbmp, bmp, 0, srcy, x, y, srcw, f->height);
        } else {
            masked_blit(srcbmp, bmp, 0, srcy, x, y, srcw, f->height);
        }
        
        release_bitmap(bmp);
    }
    return srcw;
}
コード例 #12
0
void Bitmap::Acquire()
{
	acquire_bitmap(_alBitmap);
}
コード例 #13
0
ファイル: exaccel.c プロジェクト: AntonLanghoff/whitecatlib
int main(int argc, char *argv[])
{
   char buf[256];
   PALETTE pal;
   BITMAP *image;
   BITMAP *page[2];
   BITMAP *vimage;
   IMAGE images[MAX_IMAGES];
   int num_images = 4;
   int page_num = 1;
   int done = FALSE;
   int i;

   if (allegro_init() != 0)
      return 1;
   install_keyboard(); 
   install_timer();

   /* see comments in exflip.c */
#ifdef ALLEGRO_VRAM_SINGLE_SURFACE
   if (set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 2 * 768 + 200) != 0) {
#else
   if (set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0) != 0) {
#endif
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error setting graphics mode\n%s\n", allegro_error);
      return 1;
   }

   /* read in the source graphic */
   replace_filename(buf, argv[0], "mysha.pcx", sizeof(buf));
   image = load_bitmap(buf, pal);
   if (!image) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Error reading %s!\n", buf);
      return 1;
   }

   set_palette(pal);

   /* initialise the images to random positions */
   for (i=0; i<MAX_IMAGES; i++)
      init_image(images+i);

   /* create two video memory bitmaps for page flipping */
   page[0] = create_video_bitmap(SCREEN_W, SCREEN_H);
   page[1] = create_video_bitmap(SCREEN_W, SCREEN_H);

   /* create a video memory bitmap to store our picture */
   vimage = create_video_bitmap(image->w, image->h);

   if ((!page[0]) || (!page[1]) || (!vimage)) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Not enough video memory (need two 1024x768 pages "
		      "and a 320x200 image)\n");
      return 1;
   }

   /* copy the picture into offscreen video memory */
   blit(image, vimage, 0, 0, 0, 0, image->w, image->h);

   while (!done) {
      acquire_bitmap(page[page_num]);

      /* clear the screen */
      clear_bitmap(page[page_num]);

      /* draw onto it */
      for (i=0; i<num_images; i++)
	 blit(vimage, page[page_num], 0, 0, images[i].x, images[i].y,
	      vimage->w, vimage->h);

      textprintf_ex(page[page_num], font, 0, 0, 255, -1,
		    "Images: %d (arrow keys to change)", num_images);

      /* tell the user which functions are being done in hardware */
      if (gfx_capabilities & GFX_HW_FILL)
	 textout_ex(page[page_num], font, "Clear: hardware accelerated",
		    0, 16, 255, -1);
      else
	 textout_ex(page[page_num], font, "Clear: software (urgh, this "
		    "is not good!)", 0, 16, 255, -1);

      if (gfx_capabilities & GFX_HW_VRAM_BLIT)
	 textout_ex(page[page_num], font, "Blit: hardware accelerated",
		    0, 32, 255, -1);
      else
	 textout_ex(page[page_num], font, "Blit: software (urgh, this program "
		    "will run too sloooooowly without hardware acceleration!)",
		    0, 32, 255, -1);

      release_bitmap(page[page_num]);

      /* page flip */
      show_video_bitmap(page[page_num]);
      page_num = 1-page_num;

      /* deal with keyboard input */
      while (keypressed()) {
	 switch (readkey()>>8) {

	    case KEY_UP:
	    case KEY_RIGHT:
	       if (num_images < MAX_IMAGES)
		  num_images++;
	       break;

	    case KEY_DOWN:
	    case KEY_LEFT:
	       if (num_images > 0)
		  num_images--;
	       break;

	    case KEY_ESC:
	       done = TRUE;
	       break;
	 }
      }

      /* bounce the images around the screen */
      for (i=0; i<num_images; i++)
	 update_image(images+i);
   }

   destroy_bitmap(image);
   destroy_bitmap(vimage);
   destroy_bitmap(page[0]);
   destroy_bitmap(page[1]);

   return 0;
}

END_OF_MAIN()
コード例 #14
0
ファイル: polygon.c プロジェクト: 1007650105/aseprite
/* polygon:
 *  Draws a filled polygon with an arbitrary number of corners. Pass the
 *  number of vertices, then an array containing a series of x, y points
 *  (a total of vertices*2 values).
 */
void _soft_polygon(BITMAP *bmp, int vertices, AL_CONST int *points, int color)
{
   int c;
   int top = INT_MAX;
   int bottom = INT_MIN;
   AL_CONST int *i1, *i2;
   POLYGON_EDGE *edge, *next_edge;
   POLYGON_EDGE *active_edges = NULL;
   POLYGON_EDGE *inactive_edges = NULL;
   ASSERT(bmp);

   /* allocate some space and fill the edge table */
   _grow_scratch_mem(sizeof(POLYGON_EDGE) * vertices);

   edge = (POLYGON_EDGE *)_scratch_mem;
   i1 = points;
   i2 = points + (vertices-1) * 2;

   for (c=0; c<vertices; c++) {
      fill_edge_structure(edge, i1, i2);

      if (edge->bottom >= edge->top) {

         if (edge->top < top)
            top = edge->top;

         if (edge->bottom > bottom)
            bottom = edge->bottom;

         inactive_edges = _add_edge(inactive_edges, edge, FALSE);
         edge++;
      }

      i2 = i1;
      i1 += 2;
   }

   if (bottom >= bmp->cb)
      bottom = bmp->cb-1;

   acquire_bitmap(bmp);

   /* for each scanline in the polygon... */
   for (c=top; c<=bottom; c++) {
      int hid = 0;
      int b1 = 0;
      int e1 = 0;
      int up = 0;
      int draw = 0;
      int e;

      /* check for newly active edges */
      edge = inactive_edges;
      while ((edge) && (edge->top == c)) {
         next_edge = edge->next;
         inactive_edges = _remove_edge(inactive_edges, edge);
         active_edges = _add_edge(active_edges, edge, TRUE);
         edge = next_edge;
      }

      /* draw horizontal line segments */
      edge = active_edges;
      while (edge) {
         e = edge->w;
         if (edge->bottom != c) {
            up = 1 - up;
         }
         else {
            e = edge->w >> 1;
         }

         if (edge->top == c) {
            e = edge->w >> 1;
         }

         if ((draw < 1) && (up >= 1)) {
            b1 = (edge->x + e) >> POLYGON_FIX_SHIFT;
         }
         else if (draw >= 1) {
コード例 #15
0
ファイル: exscroll.c プロジェクト: AntonLanghoff/whitecatlib
int main(void)
{
   BITMAP *scroller;
   RGB black = { 0, 0, 0, 0 };
   int x = 0;
   int next_x;
   int h = 100;

   if (allegro_init() != 0)
      return 1;
   install_keyboard();

   if (set_gfx_mode(GFX_AUTODETECT, 320, 240, 640, 240) != 0) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Unable to set a 320x240 mode with 640x240 "
		      "virtual dimensions\n");
      return 1;
   }

   /* the scrolling area is twice the width of the screen (640x240) */
   scroller = create_sub_bitmap(screen, 0, 0, SCREEN_W*2, SCREEN_H);

   set_palette(desktop_palette);
   set_color(0, &black);

   rectfill(scroller, 0, 0, SCREEN_W, 100, 6);
   rectfill(scroller, 0, 100, SCREEN_W, SCREEN_H, 2);

   do {
      /* advance the scroller, wrapping every 320 pixels */
      next_x = x + 1;
      if (next_x >= 320)
	 next_x = 0;

      /* draw another column of the landscape */
      acquire_bitmap(scroller);
      vline(scroller, next_x+SCREEN_W-1, 0, h, 6);
      vline(scroller, next_x+SCREEN_W-1, h+1, SCREEN_H, 2);
      release_bitmap(scroller);

      /* scroll the screen */
      scroll_screen(next_x, 0);

      /* duplicate the landscape column so we can wrap the scroller */
      if (next_x > 0) {
	 acquire_bitmap(scroller);
	 vline(scroller, x, 0, h, 6);
	 vline(scroller, x, h+1, SCREEN_H, 2);
	 release_bitmap(scroller);
      }

      /* randomly alter the landscape position */
      if (AL_RAND()&1) {
	 if (h > 5)
	    h--;
      }
      else {
	 if (h < 195)
	    h++;
      }

      x = next_x;

      rest(0);
   } while (!keypressed());

   destroy_bitmap(scroller);

   clear_keybuf();

   return 0;
}
コード例 #16
0
ファイル: alleg_surface.cpp プロジェクト: webbie1887/aseprite
void Alleg4Surface::lock()
{
  ASSERT(m_lock >= 0);
  if (m_lock++ == 0)
    acquire_bitmap(m_bmp);
}
コード例 #17
0
ファイル: capture.c プロジェクト: dafyddcrosby/meka
//-----------------------------------------------------------------------------
// Capture_Screen(void)
// Capture current screen to a file
//-----------------------------------------------------------------------------
static void		Capture_Screen(void)
{
    //PALETTE     pal;
    BITMAP *    bmp;
    BITMAP *    source;
    char        s1[FILENAME_LEN];
    int         x_start, x_len;
    int         y_start, y_len;

    // Get a filename
    Capture_FileName_Get(s1);
    if (Capture.id_number >= CAPTURE_ID_MAX)
    {
        Msg(MSGT_USER, Msg_Get(MSG_Capture_Error_File));
        return;
    }

	if ((Meka_State == MEKA_STATE_FULLSCREEN) || (!g_Configuration.capture_include_gui)) 
	{
		// Fullscreen
		source = screenbuffer;
		x_start = cur_drv->x_start;
		y_start = cur_drv->y_show_start;
		x_len = cur_drv->x_res;
		y_len = cur_drv->y_res;

		// Crop left column
		if (g_Configuration.capture_crop_scrolling_column)
		{
			if ((cur_drv->id == DRV_SMS) && (tsms.VDP_VideoMode > 4) && (Mask_Left_8))
			{
				x_start += 8;
				x_len -= 8;
			}
		}

		// Automatic crop on tile boundaries (for map making)
		// In total, remove 8 pixels from each axis
		if (g_Configuration.capture_crop_align_8x8)
		{
			const int scroll_x = cur_machine.VDP.scroll_x_latched;
			const int scroll_y = cur_machine.VDP.scroll_y_latched;
			x_start += scroll_x & 7;
			y_start += 8 - (scroll_y & 7);
			x_len -= 8;
			y_len -= 8;
		}
	}
	else if (Meka_State == MEKA_STATE_GUI)
	{
		// GUI mode
		x_start = 0;
		y_start = 0;
		x_len = g_Configuration.video_mode_gui_res_x;
		y_len = g_Configuration.video_mode_gui_res_y;
		source = gui_buffer;
	}
	else
	{
		// Unknown Mode
		assert(0);
		return;
	}

    acquire_bitmap(source);
    bmp = create_sub_bitmap(source, x_start, y_start, x_len, y_len);
    if (bmp == NULL)
    {
        Msg(MSGT_USER, Msg_Get(MSG_Capture_Error));
        return;
    }
    release_bitmap(source);

    //get_palette(pal);
    if (save_bitmap(s1, bmp, NULL) != 0)
    {
        Msg(MSGT_USER, Msg_Get(MSG_Capture_Error));
        destroy_bitmap(bmp);
        return;
    }

    destroy_bitmap(bmp);

    // Verbose
    killpath(s1);
    Msg(MSGT_USER, Msg_Get(MSG_Capture_Done), s1);
}
コード例 #18
0
ファイル: graphics.c プロジェクト: Skiles/aseprite
/* create_sub_bitmap:
 *  Creates a sub bitmap, ie. a bitmap sharing drawing memory with a
 *  pre-existing bitmap, but possibly with different clipping settings.
 *  Usually will be smaller, and positioned at some arbitrary point.
 *
 *  Mark Wodrich is the owner of the brain responsible this hugely useful 
 *  and beautiful function.
 */
BITMAP *create_sub_bitmap(BITMAP *parent, int x, int y, int width, int height)
{
   BITMAP *bitmap;
   int nr_pointers;
   int i;

   ASSERT(parent);
   ASSERT((x >= 0) && (y >= 0) && (x < parent->w) && (y < parent->h));
   ASSERT((width > 0) && (height > 0));
   ASSERT(system_driver);

   if (x+width > parent->w) 
      width = parent->w-x;

   if (y+height > parent->h) 
      height = parent->h-y;

   if (parent->vtable->create_sub_bitmap)
      return parent->vtable->create_sub_bitmap(parent, x, y, width, height);

   if (system_driver->create_sub_bitmap)
      return system_driver->create_sub_bitmap(parent, x, y, width, height);

   /* get memory for structure and line pointers */
   /* (see create_bitmap for the reason we need at least two) */
   nr_pointers = MAX(2, height);
   bitmap = _AL_MALLOC(sizeof(BITMAP) + (sizeof(char *) * nr_pointers));
   if (!bitmap)
      return NULL;

   acquire_bitmap(parent);

   bitmap->w = bitmap->cr = width;
   bitmap->h = bitmap->cb = height;
   bitmap->clip = TRUE;
   bitmap->cl = bitmap->ct = 0;
   bitmap->vtable = parent->vtable;
   bitmap->write_bank = parent->write_bank;
   bitmap->read_bank = parent->read_bank;
   bitmap->dat = NULL;
   bitmap->extra = NULL;
   bitmap->x_ofs = x + parent->x_ofs;
   bitmap->y_ofs = y + parent->y_ofs;
   bitmap->seg = parent->seg;

   /* All bitmaps are created with zero ID's. When a sub-bitmap is created,
    * a unique ID is needed to identify the relationship when blitting from
    * one to the other. This is obtained from the global variable
    * _sub_bitmap_id_count, which provides a sequence of integers (yes I
    * know it will wrap eventually, but not for a long time :-) If the
    * parent already has an ID the sub-bitmap adopts it, otherwise a new
    * ID is given to both the parent and the child.
    */
   if (!(parent->id & BMP_ID_MASK)) {
      parent->id |= _sub_bitmap_id_count;
      _sub_bitmap_id_count = (_sub_bitmap_id_count+1) & BMP_ID_MASK;
   }

   bitmap->id = parent->id | BMP_ID_SUB;
   bitmap->id &= ~BMP_ID_LOCKED;

   if (is_planar_bitmap(bitmap))
      x /= 4;

   x *= BYTES_PER_PIXEL(bitmap_color_depth(bitmap));

   /* setup line pointers: each line points to a line in the parent bitmap */
   for (i=0; i<height; i++)
      bitmap->line[i] = parent->line[y+i] + x;

   if (bitmap->vtable->set_clip)
      bitmap->vtable->set_clip(bitmap);

   if (parent->vtable->created_sub_bitmap)
      parent->vtable->created_sub_bitmap(bitmap, parent);

   if (system_driver->created_sub_bitmap)
      system_driver->created_sub_bitmap(bitmap, parent);

   if (parent->id & BMP_ID_VIDEO)
      _register_switch_bitmap(bitmap, parent);

   release_bitmap(parent);

   return bitmap;
}
コード例 #19
0
ファイル: mouse.c プロジェクト: AntonLanghoff/whitecatlib
/* show_mouse:
 *  Tells Allegro to display a mouse pointer. This only works when the timer 
 *  module is active. The mouse pointer will be drawn onto the bitmap bmp, 
 *  which should normally be the hardware screen. To turn off the mouse 
 *  pointer, which you must do before you draw anything onto the screen, call 
 *  show_mouse(NULL). If you forget to turn off the mouse pointer when 
 *  drawing something, the SVGA bank switching code will become confused and 
 *  will produce garbage all over the screen.
 */
void show_mouse(BITMAP *bmp)
{
   if (!mouse_driver)
      return;

   remove_int(mouse_move);

   /* Remove the mouse cursor */
   if (_mouse_screen) {
      acquire_bitmap(_mouse_screen);

      if (gfx_capabilities & GFX_HW_CURSOR) {
	 gfx_driver->hide_mouse();
	 gfx_capabilities &= ~(GFX_HW_CURSOR|GFX_SYSTEM_CURSOR);
 	 hw_cursor_dirty = TRUE;
      }
      else
	 draw_mouse(TRUE, FALSE);

      release_bitmap(_mouse_screen);
   }

   _mouse_screen = bmp;

   if (bmp && (current_cursor != MOUSE_CURSOR_NONE)) {
      acquire_bitmap(_mouse_screen);

      /* Default system cursor? */
      if ((current_cursor != MOUSE_CURSOR_ALLEGRO) && allow_system_cursor) {
         if (mouse_driver && mouse_driver->select_system_cursor) {
            use_system_cursor = mouse_driver->select_system_cursor(current_cursor);
            if (use_system_cursor) {
               gfx_capabilities |= GFX_HW_CURSOR|GFX_SYSTEM_CURSOR;
               hw_cursor_dirty = FALSE;
               got_hw_cursor = TRUE;
            }
         }
      }
      else {
         use_system_cursor = FALSE;
      }

      /* Custom hardware cursor? */
      if (hw_cursor_dirty) {
	 got_hw_cursor = FALSE;

	 if ((gfx_driver) && (gfx_driver->set_mouse_sprite) && (!_dispsw_status))
	    if (gfx_driver->set_mouse_sprite(mouse_sprite, mouse_x_focus, mouse_y_focus) == 0)
	       got_hw_cursor = TRUE;

	 hw_cursor_dirty = FALSE;
      }
      
      /* Try to display hardware (custom or system) cursor */
      if ((got_hw_cursor) && (is_same_bitmap(bmp, screen)))
	 if (gfx_driver->show_mouse(bmp, mx=mouse_x, my=mouse_y) == 0)
	    gfx_capabilities |= GFX_HW_CURSOR;

      /* Draw cursor manually if we can't do that */
      if (!(gfx_capabilities & GFX_HW_CURSOR)) {
	 draw_mouse(FALSE, TRUE);
         use_system_cursor = FALSE;
      }

      release_bitmap(_mouse_screen);

      install_int(mouse_move, 10);
   }
   else {
      if (mouse_driver->timer_poll) 
	 install_int(mouse_move, 10);
   }
}
コード例 #20
0
ファイル: spline.c プロジェクト: 1007650105/aseprite
/* spline:
 *  Draws a bezier spline onto the specified bitmap in the specified color.
 */
void _soft_spline(BITMAP *bmp, AL_CONST int points[8], int color)
{
   #define MAX_POINTS   64

   int xpts[MAX_POINTS], ypts[MAX_POINTS];
   int i;
   int num_points;
   int c;
   int old_drawing_mode, old_drawing_x_anchor, old_drawing_y_anchor;
   BITMAP *old_drawing_pattern;
   ASSERT(bmp);

   /* Calculate the number of points to draw. We want to draw as few as
      possible without loosing image quality. This algorithm is rather
      random; I have no motivation for it at all except that it seems to work
      quite well. The length of the spline is approximated by the sum of
      distances from first to second to third to last point. The number of
      points to draw is then the square root of this distance. I first tried
      to make the number of points proportional to this distance without
      taking the square root of it, but then short splines kind of had too
      few points and long splines had too many. Since sqrt() increases more
      for small input than for large, it seems in a way logical to use it,
      but I don't precisely have any mathematical proof for it. So if someone
      has a better idea of how this could be done, don't hesitate to let us
      know...
   */

   #undef DIST
   #define DIST(x, y) (sqrt((x) * (x) + (y) * (y)))
   num_points = (int)(sqrt(DIST(points[2]-points[0], points[3]-points[1]) +
                           DIST(points[4]-points[2], points[5]-points[3]) +
                           DIST(points[6]-points[4], points[7]-points[5])) *
                      1.2);

   if (num_points > MAX_POINTS)
      num_points = MAX_POINTS;

   calc_spline(points, num_points, xpts, ypts);

   acquire_bitmap(bmp);

   if ((_drawing_mode == DRAW_MODE_XOR) ||
       (_drawing_mode == DRAW_MODE_TRANS)) {
      /* Must compensate for the end pixel being drawn twice,
         hence the mess. */
      old_drawing_mode = _drawing_mode;
      old_drawing_pattern = _drawing_pattern;
      old_drawing_x_anchor = _drawing_x_anchor;
      old_drawing_y_anchor = _drawing_y_anchor;
      for (i=1; i<num_points-1; i++) {
         c = getpixel(bmp, xpts[i], ypts[i]);
         line(bmp, xpts[i-1], ypts[i-1], xpts[i], ypts[i], color);
         solid_mode();
         putpixel(bmp, xpts[i], ypts[i], c);
         drawing_mode(old_drawing_mode, old_drawing_pattern,
                      old_drawing_x_anchor, old_drawing_y_anchor);
      }
      line(bmp, xpts[i-1], ypts[i-1], xpts[i], ypts[i], color);
   }
   else {
      for (i=1; i<num_points; i++)
         line(bmp, xpts[i-1], ypts[i-1], xpts[i], ypts[i], color);
   }

   release_bitmap(bmp);
}