zenilib: zenilib/jni/external/sdl/src/video/cocoa/SDL_cocoashape.m Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_cocoashape.m
Go to the documentation of this file.
1 /*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20 */
21
22 #include "SDL_config.h"
23
24 #if SDL_VIDEO_DRIVER_COCOA
25
26 #include "SDL_cocoavideo.h"
27 #include "SDL_shape.h"
28 #include "SDL_cocoashape.h"
29 #include "../SDL_sysvideo.h"
30 #include "SDL_assert.h"
31
32 SDL_WindowShaper*
33 Cocoa_CreateShaper(SDL_Window* window) {
34 SDL_WindowData* windata = (SDL_WindowData*)window->driverdata;
35 [windata->nswindow setOpaque:NO];
36
37 if ([windata->nswindow respondsToSelector:@selector(setStyleMask:)]) {
38 [windata->nswindow setStyleMask:NSBorderlessWindowMask];
39 }
40
41 SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper));
42 result->window = window;
43 result->mode.mode = ShapeModeDefault;
44 result->mode.parameters.binarizationCutoff = 1;
45 result->userx = result->usery = 0;
46 window->shaper = result;
47
48 SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData));
49 result->driverdata = data;
50 data->context = [windata->nswindow graphicsContext];
51 data->saved = SDL_FALSE;
52 data->shape = NULL;
53
54 int resized_properly = Cocoa_ResizeWindowShape(window);
55 SDL_assert(resized_properly == 0);
56 return result;
57 }
58
59 typedef struct {
60 NSView* view;
61 NSBezierPath* path;
62 SDL_Window* window;
63 } SDL_CocoaClosure;
64
65 void
66 ConvertRects(SDL_ShapeTree* tree,void* closure) {
67 SDL_CocoaClosure* data = (SDL_CocoaClosure*)closure;
68 if(tree->kind == OpaqueShape) {
69 NSRect rect = NSMakeRect(tree->data.shape.x,data->window->h - tree->data.shape.y,tree->data.shape.w,tree->data.shape.h);
70 [data->path appendBezierPathWithRect:[data->view convertRect:rect toView:nil]];
71 }
72 }
73
74 int
75 Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
76 SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
77 SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
78 SDL_CocoaClosure closure;
79 NSAutoreleasePool *pool = NULL;
80 if(data->saved == SDL_TRUE) {
81 [data->context restoreGraphicsState];
82 data->saved = SDL_FALSE;
83 }
84
85 //[data->context saveGraphicsState];
86 //data->saved = SDL_TRUE;
87 [NSGraphicsContext setCurrentContext:data->context];
88
89 [[NSColor clearColor] set];
90 NSRectFill([[windata->nswindow contentView] frame]);
91 data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
92
93 pool = [[NSAutoreleasePool alloc] init];
94 closure.view = [windata->nswindow contentView];
95 closure.path = [[NSBezierPath bezierPath] autorelease];
96 closure.window = shaper->window;
97 SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
98 [closure.path addClip];
99 [pool release];
100
101 return 0;
102 }
103
104 int
105 Cocoa_ResizeWindowShape(SDL_Window *window) {
106 SDL_ShapeData* data = window->shaper->driverdata;
107 SDL_assert(data != NULL);
108 return 0;
109 }
110
111 #endif /* SDL_VIDEO_DRIVER_COCOA */
112
113 /* vi: set ts=4 sw=4 expandtab: */
SDL_CalculateShapeTree
SDL_ShapeTree * SDL_CalculateShapeTree(SDL_WindowShapeMode mode, SDL_Surface *shape)
Definition: SDL_shape.c:196
NULL
#define NULL
Definition: ftobjs.h:61
SDL_TRUE
Definition: SDL_stdinc.h:119
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
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
if
if(!yyg->yy_init)
Definition: glslang_lex.cpp:1037
SDL_FALSE
Definition: SDL_stdinc.h:118
SDL_WindowShaper
Definition: SDL_sysvideo.h:38
path
GLsizei const GLchar *const * path
Definition: glew.h:5828
SDL_config.h
SDL_WindowData
Definition: SDL_androidwindow.h:33
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
result
GLuint64EXT * result
Definition: glew.h:12708
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
SDL_Window::shaper
SDL_WindowShaper * shaper
Definition: SDL_sysvideo.h:95
SDL_WindowShaper::window
SDL_Window * window
Definition: SDL_sysvideo.h:41
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:65
SDL_WindowShaper::userx
Uint32 userx
Definition: SDL_sysvideo.h:44
SDL_WindowShaper::usery
Uint32 usery
Definition: SDL_sysvideo.h:44
SDL_Rect::w
int w
Definition: SDL_rect.h:66
SDL_WindowData::nswindow
NSWindow * nswindow
Definition: SDL_cocoawindow.h:86
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:159
SDL_ShapeData::saved
SDL_bool saved
Definition: SDL_cocoashape.h:34
malloc
#define malloc
Definition: SDL_malloc.c:635
SDL_ShapeUnion::shape
SDL_Rect shape
Definition: SDL_shape_internals.h:44
SDL_Rect::h
int h
Definition: SDL_rect.h:66
SDL_Window
Definition: SDL_sysvideo.h:71
SDL_TraverseShapeTree
void SDL_TraverseShapeTree(SDL_ShapeTree *tree, SDL_TraversalFunction function, void *closure)
Definition: SDL_shape.c:209
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
SDL_Window::driverdata
void * driverdata
Definition: SDL_sysvideo.h:99
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:65
SDL_assert.h