Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. void drawBitmapTransparence(Bitmap* bmp, int x, int y, Alignment alignment) {
  2.     if (bmp == NULL){
  3.         return;
  4.     }
  5.  
  6.     int width = bmp->bitmapInfoHeader.width;
  7.     int drawWidth = width;
  8.     int height = bmp->bitmapInfoHeader.height;
  9.  
  10.     if (alignment == ALIGN_CENTER)
  11.         x -= width / 2;
  12.     else if (alignment == ALIGN_RIGHT)
  13.         x -= width;
  14.  
  15.     if (x + width < 0 || x > get_Hres() || y + height < 0
  16.             || y > get_Vres())
  17.         return;
  18.  
  19.     int xCorrection = 0;
  20.     if (x < 0) {
  21.         xCorrection = -x;
  22.         drawWidth -= xCorrection;
  23.         x = 0;
  24.  
  25.         if (drawWidth > get_Hres())
  26.             drawWidth = get_Hres();
  27.     } else if (x + drawWidth >= get_Hres()) {
  28.         drawWidth = get_Hres() - x;
  29.     }
  30.  
  31.     char* bufferStartPos;
  32.     char* imgStartPos;
  33.  
  34.     for (y = y1; y < height; y++) {
  35.         for (x = x1; x < width; x++) {
  36.             if((*imgStartPos | ((*(imgStartPos + 1))))!=Green)
  37.             draw_pixel(x, y, color);
  38.            
  39.         int pos = y + height - 1 - i;
  40.  
  41.         if (pos < 0 || pos >= get_Vres())
  42.             continue;
  43.         bufferStartPos = getGraphicsBuffer();
  44.         bufferStartPos += (x * 2 + pos * get_Hres()) * 2;
  45.  
  46.         imgStartPos = bmp->bitmapData + xCorrection * 2 + i * width * 2;
  47.         memcpy(bufferStartPos, imgStartPos, drawWidth * 2);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement