i currently work on a program that does not have the typical Windows-window and instead is transparent, so i can make 'my own window design' looking like a slice of toast.
Now i´m on to quit my window by clicking the top right corner, works just fine.
But what i want is a 'eating' animation when you close it, so i want the toast to get eaten from the screen. Therefore i need to get rid of the old image without just overwriting the screen with SDL_FillRect or any background.
Wherever i look for this problem people always suggest those two attempts and never talk about a way to really 'clear' the screen.
I print all my images with SDL_BlitSurface to one SDL_Surface, then i use SDL_UpdateWindowSurface and free the surface with SDL_FreeSurface. Is there maybe a way to free the SDL_Window like one can free a SDL_Surface?
Or is there a way to get a 'mask' for my window so i can just 'bite' the mask and the SDL_Window just shows whats in the 'visible' part of the mask?
Is it even possible to achieve what i want with SDL on windows or would i have to achieve this a totally other way?
If you already have a window that appears to be non-rectangular then presumably you're drawing to a 32-bit surface. If you want to make it look as if chunks are being bitten off then all you have to do is set the alpha of some irregularly-shaped region to zero (or some value less than 255). You can do this by directly accessing the pixels.
I´m not sure if i misunderstand, but the function i use to make the window transparent just makes 1 color transparent, i don't see how i can use that.
This is my function:
1 2 3 4 5 6 7 8 9 10 11 12 13
bool makeWindowTransparent(int r, int g, int b) {
// Get window handle (https://stackoverflow.com/a/24118145/3357935)
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version); // Initialize wmInfo
SDL_GetWindowWMInfo(gvScreenWindow, &wmInfo);
HWND hWnd = wmInfo.info.win.window;
// Change window type to layered (https://stackoverflow.com/a/3970218/3357935)
SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
// Set transparency color
return SetLayeredWindowAttributes(hWnd, RGB(r,g,b), 0, LWA_COLORKEY);
}
But lets say i want to access the pixel like you said, do i have to manually change each pixel to achieve my goal? Or would it be possible to load a mask that's used to change all the pixels alpha i need? The function to make one color transparent i got from a forum, i do not like to just copy code for my files, but this was the only thing that worked for me.
Is there no other way to 'just' clear the SDL_Window?
the function i use to make the window transparent just makes 1 color transparent
Ah, I see. You're using chroma.
Or would it be possible to load a mask that's used to change all the pixels alpha i need?
Yes, that's possible. For example, if the transparent color (the chroma key) is green, you could take a rectangular green surface and blit into the window using a mask shaped like a bite. That would effectively "take a bite" out of the window.
Is there no other way to 'just' clear the SDL_Window?
I imagine there is, but the problem is that you don't "just" want to clear the window. You're trying to clear in a very stylish manner. Making it simply disappear would definitely be much easier.
I just now realized that my png´s have no background color on them, for some reason i assumed that png´s are always loaded with a black background when i save them without any, that was my mistake.