SDL_cocoashape.m
Go to the documentation of this file.
/*
Simple DirectMedia Layer
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_COCOA
#include "SDL_cocoavideo.h"
#include "SDL_shape.h"
#include "SDL_cocoashape.h"
#include "../SDL_sysvideo.h"
#include "SDL_assert.h"
SDL_WindowShaper*
Cocoa_CreateShaper(SDL_Window* window)
{
SDL_WindowData* windata = (SDL_WindowData*)window->driverdata;
[windata->nswindow setOpaque:NO];
if ([windata->nswindow respondsToSelector:@selector(setStyleMask:)]) {
[windata->nswindow setStyleMask:NSBorderlessWindowMask];
}
SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper));
result->window = window;
result->mode.mode = ShapeModeDefault;
result->mode.parameters.binarizationCutoff = 1;
result->userx = result->usery = 0;
window->shaper = result;
SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData));
result->driverdata = data;
data->context = [windata->nswindow graphicsContext];
data->saved = SDL_FALSE;
data->shape = NULL;
int resized_properly = Cocoa_ResizeWindowShape(window);
SDL_assert(resized_properly == 0);
return result;
}
typedef struct {
NSView* view;
NSBezierPath* path;
SDL_Window* window;
} SDL_CocoaClosure;
void
ConvertRects(SDL_ShapeTree* tree, void* closure)
{
SDL_CocoaClosure* data = (SDL_CocoaClosure*)closure;
if(tree->kind == OpaqueShape) {
NSRect rect = NSMakeRect(tree->data.shape.x,data->window->h - tree->data.shape.y,tree->data.shape.w,tree->data.shape.h);
[data->path appendBezierPathWithRect:[data->view convertRect:rect toView:nil]];
}
}
int
Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
{ @autoreleasepool
{
SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
SDL_CocoaClosure closure;
if(data->saved == SDL_TRUE) {
[data->context restoreGraphicsState];
data->saved = SDL_FALSE;
}
/*[data->context saveGraphicsState];*/
/*data->saved = SDL_TRUE;*/
[NSGraphicsContext setCurrentContext:data->context];
[[NSColor clearColor] set];
NSRectFill([[windata->nswindow contentView] frame]);
data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
closure.view = [windata->nswindow contentView];
closure.path = [NSBezierPath bezierPath];
closure.window = shaper->window;
SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
[closure.path addClip];
return 0;
}}
int
Cocoa_ResizeWindowShape(SDL_Window *window)
{
SDL_ShapeData* data = window->shaper->driverdata;
SDL_assert(data != NULL);
return 0;
}
#endif /* SDL_VIDEO_DRIVER_COCOA */
/* vi: set ts=4 sw=4 expandtab: */
SDL_CalculateShapeTree
SDL_ShapeTree * SDL_CalculateShapeTree(SDL_WindowShapeMode mode, SDL_Surface *shape)
Definition: SDL_shape.c:207
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
rect
SDL_Rect rect
Definition: testrelative.c:27
window
SDL_Window * window
Definition: testautomation_render.c:26
SDL_Surface
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
SDL_WindowShaper::driverdata
void * driverdata
Definition: SDL_sysvideo.h:52
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1967
OpaqueShape
Definition: SDL_shape_internals.h:47
SDL_ShapeTree::data
SDL_ShapeUnion data
Definition: SDL_shape_internals.h:51
SDL_ShapeData
Definition: SDL_cocoashape.h:32
SDL_WindowShaper
Definition: SDL_sysvideo.h:38
SDL_WindowData
Definition: SDL_androidwindow.h:34
SDL_cocoavideo.h
Cocoa_SetWindowShape
int Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowShapeMode *shape_mode)
SDL_shape.h
SDL_WindowShaper::mode
SDL_WindowShapeMode mode
Definition: SDL_sysvideo.h:47
SDL_Window::shaper
SDL_WindowShaper * shaper
Definition: SDL_sysvideo.h:99
SDL_WindowShaper::window
SDL_Window * window
Definition: SDL_sysvideo.h:41
frame
int frame
Definition: teststreaming.c:60
Cocoa_CreateShaper
SDL_WindowShaper * Cocoa_CreateShaper(SDL_Window *window)
ShapeModeDefault
The default mode, a binarized alpha cutoff of 1.
Definition: SDL_shape.h:81
SDL_ShapeData::shape
SDL_ShapeTree * shape
Definition: SDL_cocoashape.h:36
SDL_WindowShapeMode::parameters
SDL_WindowShapeParams parameters
Window-shape parameters.
Definition: SDL_shape.h:104
SDL_Rect::x
int x
Definition: SDL_rect.h:66
SDL_WindowShaper::userx
Uint32 userx
Definition: SDL_sysvideo.h:44
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_WindowShaper::usery
Uint32 usery
Definition: SDL_sysvideo.h:44
SDL_Rect::w
int w
Definition: SDL_rect.h:67
SDL_WindowData::nswindow
NSWindow * nswindow
Definition: SDL_cocoawindow.h:111
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:167
SDL_ShapeData::saved
SDL_bool saved
Definition: SDL_cocoashape.h:34
NULL
#define NULL
Definition: begin_code.h:143
malloc
#define malloc
Definition: SDL_malloc.c:641
SDL_ShapeUnion::shape
SDL_Rect shape
Definition: SDL_shape_internals.h:44
SDL_Rect::h
int h
Definition: SDL_rect.h:67
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:71
SDL_FALSE
Definition: SDL_stdinc.h:128
SDL_TraverseShapeTree
void SDL_TraverseShapeTree(SDL_ShapeTree *tree, SDL_TraversalFunction function, void *closure)
Definition: SDL_shape.c:220
Cocoa_ResizeWindowShape
int Cocoa_ResizeWindowShape(SDL_Window *window)
SDL_ShapeTree
Definition: SDL_shape_internals.h:49
SDL_ShapeData::context
NSGraphicsContext * context
Definition: SDL_cocoashape.h:33
SDL_WindowShapeParams::binarizationCutoff
Uint8 binarizationCutoff
a cutoff alpha value for binarization of the window shape&#39;s alpha channel.
Definition: SDL_shape.h:95
SDL_WindowShapeMode
A struct that tags the SDL_WindowShapeParams union with an enum describing the type of its contents...
Definition: SDL_shape.h:100
path
GLsizei const GLchar *const * path
Definition: SDL_opengl_glext.h:3730
SDL_Window::driverdata
void * driverdata
Definition: SDL_sysvideo.h:106
SDL_ShapeTree::kind
SDL_ShapeKind kind
Definition: SDL_shape_internals.h:50
SDL_WindowShapeMode::mode
WindowShapeMode mode
The mode of these window-shape parameters.
Definition: SDL_shape.h:102
SDL_cocoashape.h
SDL_Rect::y
int y
Definition: SDL_rect.h:66
SDL_assert.h