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

Latest commit

 

History

History
99 lines (84 loc) · 3.49 KB

SDL_cocoashape.m

File metadata and controls

99 lines (84 loc) · 3.49 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"
Aug 16, 2010
Aug 16, 2010
26
#include "../src/video/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
32
33
SDL_WindowData* windata = (SDL_WindowData*)window->driverdata;
[windata->nswindow setOpaque:NO];
[windata->nswindow setStyleMask:NSBorderlessWindowMask];
SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper));
Aug 9, 2010
Aug 9, 2010
34
35
36
result->window = window;
result->mode.mode = ShapeModeDefault;
result->mode.parameters.binarizationCutoff = 1;
Aug 16, 2010
Aug 16, 2010
37
result->userx = result->usery = 0;
Aug 9, 2010
Aug 9, 2010
38
39
40
41
window->shaper = result;
SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData));
result->driverdata = data;
Aug 16, 2010
Aug 16, 2010
42
43
44
data->context = [windata->nswindow graphicsContext];
data->saved = SDL_FALSE;
data->shape = NULL;
Aug 9, 2010
Aug 9, 2010
45
46
47
48
int resized_properly = Cocoa_ResizeWindowShape(window);
assert(resized_properly == 0);
return result;
Jul 27, 2010
Jul 27, 2010
49
50
}
Aug 16, 2010
Aug 16, 2010
51
52
53
54
55
56
57
58
59
60
61
62
63
64
typedef struct {
NSView* view;
NSBezierPath* path;
} 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,tree->data.shape.y,tree->data.shape.w,tree->data.shape.h);
[data->path appendBezierPathWithRect:[data->view convertRect:rect toView:nil]];
}
}
Aug 9, 2010
Aug 9, 2010
65
int
Aug 16, 2010
Aug 16, 2010
66
67
68
69
70
71
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
72
[data->context restoreGraphicsState];
Aug 16, 2010
Aug 16, 2010
73
data->saved = SDL_FALSE;
Aug 9, 2010
Aug 9, 2010
74
75
}
Aug 16, 2010
Aug 16, 2010
76
77
//[data->context saveGraphicsState];
//data->saved = SDL_TRUE;
Aug 9, 2010
Aug 9, 2010
78
79
[[NSColor clearColor] set];
Aug 16, 2010
Aug 16, 2010
80
NSRectFill([[windata->nswindow contentView] frame]);
Aug 9, 2010
Aug 9, 2010
81
/* TODO: It looks like Cocoa can set a clipping path based on a list of rectangles. That's what we get from the
Jul 27, 2010
Jul 27, 2010
82
Windoze shape-calculation code: a list of rectangles. This will work... I think. */
Aug 16, 2010
Aug 16, 2010
83
84
85
86
87
88
89
90
91
data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
pool = [[NSAutoreleasePool alloc] init];
closure.view = [windata->nswindow contentView];
closure.path = [[NSBezierPath bezierPath] autorelease];
SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
[NSGraphicsContext setCurrentContext:data->context];
[closure.path setClip];
[pool drain];
Jul 27, 2010
Jul 27, 2010
92
93
}
Aug 9, 2010
Aug 9, 2010
94
95
96
97
98
int
Cocoa_ResizeWindowShape(SDL_Window *window) {
SDL_ShapeData* data = window->shaper->driverdata;
assert(data != NULL);
return 0;
Jul 27, 2010
Jul 27, 2010
99
}