Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
100 lines (85 loc) · 3.39 KB

SDL_cocoashape.m

File metadata and controls

100 lines (85 loc) · 3.39 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
SDL - Simple DirectMedia Layer
Copyright (C) 2010 Eli Gottlieb
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Eli Gottlieb
eligottlieb@gmail.com
*/
Jul 27, 2010
Jul 27, 2010
23
#include "SDL_cocoavideo.h"
24
#include "SDL_shape.h"
Jul 27, 2010
Jul 27, 2010
25
#include "SDL_cocoashape.h"
Nov 16, 2010
Nov 16, 2010
26
#include "../SDL_sysvideo.h"
Jun 5, 2010
Jun 5, 2010
27
Aug 9, 2010
Aug 9, 2010
28
29
SDL_WindowShaper*
Cocoa_CreateShaper(SDL_Window* window) {
Aug 16, 2010
Aug 16, 2010
30
31
SDL_WindowData* windata = (SDL_WindowData*)window->driverdata;
[windata->nswindow setOpaque:NO];
Dec 1, 2010
Dec 1, 2010
32
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
Aug 16, 2010
Aug 16, 2010
33
[windata->nswindow setStyleMask:NSBorderlessWindowMask];
Dec 1, 2010
Dec 1, 2010
34
#endif
Aug 16, 2010
Aug 16, 2010
35
SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper));
Aug 9, 2010
Aug 9, 2010
36
37
38
result->window = window;
result->mode.mode = ShapeModeDefault;
result->mode.parameters.binarizationCutoff = 1;
Aug 16, 2010
Aug 16, 2010
39
result->userx = result->usery = 0;
Aug 9, 2010
Aug 9, 2010
40
41
42
43
window->shaper = result;
SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData));
result->driverdata = data;
Aug 16, 2010
Aug 16, 2010
44
45
46
data->context = [windata->nswindow graphicsContext];
data->saved = SDL_FALSE;
data->shape = NULL;
Aug 9, 2010
Aug 9, 2010
47
48
49
50
int resized_properly = Cocoa_ResizeWindowShape(window);
assert(resized_properly == 0);
return result;
Jul 27, 2010
Jul 27, 2010
51
52
}
Aug 16, 2010
Aug 16, 2010
53
54
55
typedef struct {
NSView* view;
NSBezierPath* path;
Aug 17, 2010
Aug 17, 2010
56
SDL_Window* window;
Aug 16, 2010
Aug 16, 2010
57
58
59
60
61
62
} SDL_CocoaClosure;
void
ConvertRects(SDL_ShapeTree* tree,void* closure) {
SDL_CocoaClosure* data = (SDL_CocoaClosure*)closure;
if(tree->kind == OpaqueShape) {
Aug 17, 2010
Aug 17, 2010
63
NSRect rect = NSMakeRect(tree->data.shape.x,data->window->h - tree->data.shape.y,tree->data.shape.w,tree->data.shape.h);
Aug 16, 2010
Aug 16, 2010
64
65
66
67
[data->path appendBezierPathWithRect:[data->view convertRect:rect toView:nil]];
}
}
Aug 9, 2010
Aug 9, 2010
68
int
Aug 16, 2010
Aug 16, 2010
69
70
71
72
73
74
Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
SDL_CocoaClosure closure;
NSAutoreleasePool *pool = NULL;
if(data->saved == SDL_TRUE) {
Aug 9, 2010
Aug 9, 2010
75
[data->context restoreGraphicsState];
Aug 16, 2010
Aug 16, 2010
76
data->saved = SDL_FALSE;
Aug 9, 2010
Aug 9, 2010
77
78
}
Aug 16, 2010
Aug 16, 2010
79
80
//[data->context saveGraphicsState];
//data->saved = SDL_TRUE;
Aug 17, 2010
Aug 17, 2010
81
[NSGraphicsContext setCurrentContext:data->context];
Aug 9, 2010
Aug 9, 2010
82
83
[[NSColor clearColor] set];
Aug 16, 2010
Aug 16, 2010
84
85
86
87
88
89
NSRectFill([[windata->nswindow contentView] frame]);
data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
pool = [[NSAutoreleasePool alloc] init];
closure.view = [windata->nswindow contentView];
closure.path = [[NSBezierPath bezierPath] autorelease];
Aug 17, 2010
Aug 17, 2010
90
closure.window = shaper->window;
Aug 16, 2010
Aug 16, 2010
91
SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
Aug 17, 2010
Aug 17, 2010
92
[closure.path addClip];
Jul 27, 2010
Jul 27, 2010
93
94
}
Aug 9, 2010
Aug 9, 2010
95
96
97
98
99
int
Cocoa_ResizeWindowShape(SDL_Window *window) {
SDL_ShapeData* data = window->shaper->driverdata;
assert(data != NULL);
return 0;
Jul 27, 2010
Jul 27, 2010
100
}