Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Updated test code, updated win32 code a bit (still not complete, but …
…hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
  • Loading branch information
esennesh committed Jul 7, 2010
1 parent 415427e commit 9476867e79b56f051ff343af7fe661b401f9cff1
Showing with 88 additions and 225 deletions.
  1. +0 −92 include/SDL_ellipse.h
  2. +0 −110 include/SDL_poly.h
  3. +0 −2 include/SDL_video.h
  4. +3 −3 src/video/SDL_shape.c
  5. +61 −2 src/video/win32/SDL_win32shape.c
  6. +3 −2 src/video/x11/SDL_x11shape.c
  7. +21 −14 test/testeyes.c

This file was deleted.

This file was deleted.

@@ -32,8 +32,6 @@
#include "SDL_stdinc.h"
#include "SDL_pixels.h"
#include "SDL_rect.h"
#include "SDL_ellipse.h"
#include "SDL_poly.h"
#include "SDL_surface.h"

#include "begin_code.h"
@@ -45,7 +45,7 @@ SDL_bool SDL_IsShapedWindow(const SDL_Window *window) {
}

/* REQUIRES that bitmap point to a w-by-h bitmap with 1bpp. */
void SDL_CalculateShapeBitmap(Uint8 alphacutoff,SDL_Surface *shape,Uint8* bitmap) {
void SDL_CalculateShapeBitmap(Uint8 alphacutoff,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb,Uint8 value) {
if(SDL_MUSTLOCK(shape))
SDL_LockSurface(shape);
int x = 0,y = 0;
@@ -55,7 +55,7 @@ void SDL_CalculateShapeBitmap(Uint8 alphacutoff,SDL_Surface *shape,Uint8* bitmap
Uint8 alpha = 0;
SDL_GetRGBA(*(Uint32*)pixel,shape->format,NULL,NULL,NULL,&alpha);
Uint32 bitmap_pixel = y*shape->w + x;
bitmap[bitmap_pixel / 8] |= (alpha >= alphacutoff ? 1 : 0) << (8 - (bitmap_pixel % 8));
bitmap[bitmap_pixel / ppb] |= (alpha >= alphacutoff ? value : 0) << ((ppb - 1) - (bitmap_pixel % ppb));
}
if(SDL_MUSTLOCK(shape))
SDL_UnlockSurface(shape);
@@ -81,7 +81,7 @@ int SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode
}
}
}
//TODO: Platform-specific implementations of SetWindowShape. X11 is in-progress.
//TODO: Platform-specific implementations of SetWindowShape. X11 is finished. Win32 is in progress.
int result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shapeMode);
window->shaper->hasshape = SDL_TRUE;
if(window->shaper->usershownflag & SDL_WINDOW_SHOWN == SDL_WINDOW_SHOWN) {
@@ -20,6 +20,65 @@
eligottlieb@gmail.com
*/

#include "SDL_shape.h"
#include <windows.h>
#include "SDL_win32shape.h"

/* Functions implementing shaped windows for Win32 will be implemented when the API is set. */
SDL_WindowShaper* Win32_CreateShaper(SDL_Window * window) {
SDL_WindowShaper* result = malloc(sizeof(SDL_WindowShaper));
result->window = window;
result->alphacutoff = 0;
result->usershownflag = 0;
//Put some driver-data here.
window->shaper = result;
int resized_properly = X11ResizeWindowShape(window);
assert(resized_properly == 0);
return result;
}

int Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
assert(shaper != NULL && shape != NULL);
if(!SDL_ISPIXELFORMAT_ALPHA(SDL_MasksToPixelFormatEnum(shape->format->BitsPerPixel,shape->format->Rmask,shape->format->Gmask,shape->format->Bmask,shape->format->Amask)))
return -2;
if(shape->w != shaper->window->w || shape->h != shaper->window->h)
return -3;

/* Assume that shaper->alphacutoff already has a value, because SDL_SetWindowShape() should have given it one. */
/*
* Start with empty region
*/
HRGN MaskRegion = CreateRectRgn(0, 0, 0, 0);

unsigned int pitch = shape->pitch;
unsigned int width = shape->width;
unsigned int height = shape->height;
unsigned int dy = pitch - width;

SDL_ShapeData *data = (SDL_ShapeData*)shaper->driverdata;
/*
* Transfer binarized mask image into workbuffer
*/
SDL_CalculateShapeBitmap(shaper->alphacutoff,shape,data->shapebuffer,1,0xff);
//Move code over to here from AW_windowShape.c

}

int Win32_ResizeWindowShape(SDL_Window *window) {
SDL_ShapeData* data = window->shaper->driverdata;
assert(data != NULL);

unsigned int buffersize = window->w * window->h;
if(data->buffersize != buffersize || data->shapebuffer == NULL) {
data->buffersize = buffersize;
if(data->shapebuffer != NULL)
free(data->shapebuffer);
data->shapebuffer = malloc(data->buffersize);
if(data->shapebuffer == NULL) {
SDL_SetError("Could not allocate memory for shaped-window bitmap.");
return -1;
}
}

window->shaper->usershownflag = window->flags & SDL_WINDOW_SHOWN;

return 0;
}
@@ -62,15 +62,16 @@ int X11_ResizeWindowShape(SDL_Window* window) {
}

int X11_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
assert(shaper != NULL && shape != NULL);
if(!SDL_ISPIXELFORMAT_ALPHA(SDL_MasksToPixelFormatEnum(shape->format->BitsPerPixel,shape->format->Rmask,shape->format->Gmask,shape->format->Bmask,shape->format->Amask)))
return -2;
if(shape->w != shaper->window->w || shape->h != shaper->window->h)
return -3;
SDL_ShapeData *data = shaper->driverdata;
assert(data != NULL);

/* Assume that shaper->alphacutoff already has a value. */
SDL_CalculateShapeBitmap(shaper->alphacutoff,shape,data->bitmap);
/* Assume that shaper->alphacutoff already has a value, because SDL_SetWindowShape() should have given it one. */
SDL_CalculateShapeBitmap(shaper->alphacutoff,shape,data->bitmap,8,1);

SDL_WindowData *windowdata = (SDL_WindowData*)(shaper->window->driverdata);
Pixmap shapemask = XCreateBitmapFromData(windowdata->videodata->display,windowdata->xwindow,data->bitmap,shaper->window->w,shaper->window->h);
@@ -143,7 +143,7 @@ int main(int argc,char** argv) {
exit(-3);
}

SDL_Color bnw_palette[2] = {{0,0,0,0},{255,255,255,255}};
SDL_Color bnw_palette[2] = {{0,0,0,255},{255,255,255,255}};
SDL_Texture *eyes_texture = SDL_CreateTexture(SDL_PIXELFORMAT_INDEX1LSB,SDL_TEXTUREACCESS_STREAMING,eyes_width,eyes_height);
if(eyes_texture == NULL) {
SDL_DestroyRenderer(window);
@@ -162,28 +162,32 @@ int main(int argc,char** argv) {
memcpy(pixels+pitch*row,eyes_bits+(eyes_width/8)*row,eyes_width/8);
SDL_UnlockTexture(eyes_texture);

SDL_Texture *mask_texture = SDL_CreateTexture(SDL_PIXELFORMAT_INDEX1LSB,SDL_TEXTUREACCESS_STREAMING,eyesmask_width,eyesmask_height);
if(mask_texture == NULL) {
int bpp = 0;
Uint32 r = 0,g = 0,b = 0,a = 0;
SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ARGB4444,&bpp,&r,&g,&b,&a);
SDL_Surface *mask = SDL_CreateRGBSurface(0,eyesmask_width,eyesmask_height,bpp,r,g,b,a);
if(mask == NULL) {
SDL_DestroyTexture(eyes_texture);
SDL_DestroyRenderer(window);
SDL_DestroyWindow(window);
SDL_VideoQuit();
printf("Could not create shape mask texture.\n");
exit(-5);
}
SDL_SetTexturePalette(mask_texture,bnw_palette,0,2);

rect.x = rect.y = 0;
rect.w = eyesmask_width;
rect.h = eyesmask_height;
SDL_LockTexture(mask_texture,&rect,1,&pixels,&pitch);
for(int row = 0;row<eyesmask_height;row++)
memcpy(pixels+pitch*row,eyesmask_bits+(eyesmask_width/8)*row,eyesmask_width/8);
SDL_UnlockTexture(mask_texture);
if(SDL_MUSTLOCK(mask))
SDL_LockSurface(mask);
pixels = mask->pixels;
for(int y=0;y<eyesmask_height;y++)
for(int x=0;x<eyesmask_width;x++) {
Uint8 alpha = *(Uint8*)(eyesmask_bits+(eyesmask_width/8)*y+(x/8)) & (1 << (7 - x % 8)) ? 1 : 0;
*(Uint16*)(pixels+pitch*y+x*bpp/8) = SDL_MapRGBA(mask->format,0,0,0,alpha);
}
if(SDL_MUSTLOCK(mask))
SDL_UnlockSurface(mask);

SDL_SelectShapeRenderer(window);
SDL_RenderCopy(mask_texture,&rect,&rect);
SDL_RenderPresent();
SDL_WindowShapeMode mode = {ShapeModeDefault,1};
SDL_SetWindowShape(window,mask,&mode);

SDL_Event event;
int event_pending = 0;
@@ -203,6 +207,9 @@ int main(int argc,char** argv) {
event_pending = SDL_PollEvent(&event);
}

SDL_FreeSurface(mask);
SDL_DestroyTexture(eyes_texture);
SDL_DestroyWindow(window);
//Call SDL_VideoQuit() before quitting.
SDL_VideoQuit();
}

0 comments on commit 9476867

Please sign in to comment.