Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/ui/ui-drv/cocoa/ui_cocoa.m
blob: 0e107dce85971a5a6c5c3ca49eb8b2c3736eaf8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*
 *     XaoS, a fast portable realtime fractal zoomer 
 *                  Copyright (C) 1996 by
 *
 *      Jan Hubicka          (hubicka@paru.cas.cz)
 *      Thomas Marsh         (tmarsh@austin.ibm.com)
 *
 *    Cocoa Driver by J.B. Langston III (jb-langston@austin.rr.com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#import "AppController.h"

#include "ui.h"

struct ui_driver cocoa_driver, cocoa_fullscreen_driver;

#ifdef USE_LOCALEPATH
char *localepath;
#endif

static void
cocoa_printText(int x, int y, CONST char *text)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [[controller view] printText:text atX:x y:y];
    [pool release];
}

static void
cocoa_refreshDisplay()
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [[controller view] display];
    [pool release];
}

static void
cocoa_flipBuffers ()
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [[controller view] flipBuffers];
    [pool release];
}

static void 
cocoa_freeBuffers (char *b1, char *b2)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [[controller view] freeBuffers];
    [pool release];
}

static int
cocoa_allocBuffers (char **b1, char **b2)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int rowLength = [[controller view] allocBuffer1:b1 buffer2:b2];
    [pool release];
    return rowLength;
}

static void
cocoa_getImageSize (int *w, int *h)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [[controller view] getWidth:w height:h];
    [pool release];
}

static void
cocoa_processEvents (int wait, int *mx, int *my, int *mb, int *k)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    //NSDate *eventDate = wait ? [NSDate distantFuture] : [NSDate distantPast];
    NSEvent *event = [NSApp nextEventMatchingMask: NSAnyEventMask
					untilDate: nil //eventDate
					   inMode: NSDefaultRunLoopMode
					  dequeue: YES];
    if (event != nil) {
	[NSApp sendEvent: event];
    }
    [[controller view] getMouseX:mx mouseY:my mouseButton:mb keys:k];
    [pool release];
}


static int
cocoa_initDriver ()
{	
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int status = [controller initDriver:&cocoa_driver fullscreen:NO];
    [pool release];
    return status;
}

static int
cocoa_initFullScreenDriver ()
{	
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int status = [controller initDriver:&cocoa_fullscreen_driver fullscreen:YES];
    [pool release];
    return status;
}

static void
cocoa_uninitDriver ()
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [controller uninitDriver];
    [pool release];
}

static void
cocoa_getMouse (int *x, int *y, int *b)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [[controller view] getMouseX:x mouseY:y mouseButton:b];
    [pool release];
}


static void
cocoa_setCursorType (int type)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [[controller view] setCursorType:type];
    [pool release];
}

static void 
cocoa_buildMenu (struct uih_context *uih, CONST char *name)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [controller buildMenuWithContext:uih name:name];
    [pool release];
}

static void 
cocoa_showPopUpMenu (struct uih_context *c, CONST char *name)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [controller showPopUpMenuWithContext:c name:name];
    [pool release];
}


static void 
cocoa_showDialog (struct uih_context *c, CONST char *name)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [controller showDialogWithContext:c name:name];
    [pool release];
}

static void 
cocoa_showHelp (struct uih_context *c, CONST char *name)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [controller showHelpWithContext:c name:name];
    [pool release];
}

int 
main(int argc, char* argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    [NSApplication sharedApplication];
    [NSBundle loadNibNamed:@"MainMenu" owner:NSApp];
    controller = [[AppController alloc] init];
    [pool release];
    return MAIN_FUNCTION(argc, argv);
}

struct gui_driver cocoa_gui_driver = {
/* setrootmenu */   cocoa_buildMenu,
/* enabledisable */ NULL,
/* menu */          cocoa_showPopUpMenu,
/* dialog */        cocoa_showDialog,
/* help */          cocoa_showHelp
};


static struct params cocoa_params[] = {
{NULL, 0, NULL, NULL}
};

struct ui_driver cocoa_driver = {
/* name */          "Mac OS X Windowed Driver",
/* init */          cocoa_initDriver,
/* getsize */       cocoa_getImageSize,
/* processevents */ cocoa_processEvents,
/* getmouse */      cocoa_getMouse,
/* uninit */        cocoa_uninitDriver,
/* set_color */     NULL,
/* set_range */     NULL,
/* print */         cocoa_printText,
/* display */       cocoa_refreshDisplay,
/* alloc_buffers */ cocoa_allocBuffers,
/* free_buffers */  cocoa_freeBuffers,
/* filp_buffers */  cocoa_flipBuffers,
/* mousetype */     cocoa_setCursorType,
/* flush */         NULL,
/* textwidth */     12,
/* textheight */    12,
/* params */        cocoa_params,
/* flags */         PIXELSIZE,
/* width */         0.0, 
/* height */        0.0,
/* maxwidth */      0, 
/* maxheight */     0,
/* imagetype */     UI_TRUECOLOR,
/* palettestart */  0, 
/* paletteend */    256, 
/* maxentries */    255,
/* rmask */         RMASK,
/* gmask */         GMASK,
/* bmask */         BMASK,
/* gui_driver */    &cocoa_gui_driver
};

struct ui_driver cocoa_fullscreen_driver = {
/* name */          "Mac OS X Full Screen Driver",
/* init */          cocoa_initFullScreenDriver,
/* getsize */       cocoa_getImageSize,
/* processevents */ cocoa_processEvents,
/* getmouse */      cocoa_getMouse,
/* uninit */        cocoa_uninitDriver,
/* set_color */     NULL,
/* set_range */     NULL,
/* print */         cocoa_printText,
/* display */       cocoa_refreshDisplay,
/* alloc_buffers */ cocoa_allocBuffers,
/* free_buffers */  cocoa_freeBuffers,
/* filp_buffers */  cocoa_flipBuffers,
/* mousetype */     cocoa_setCursorType,
/* flush */         NULL,
/* textwidth */     12,
/* textheight */    12,
/* params */        cocoa_params,
/* flags */         PIXELSIZE | FULLSCREEN,
/* width */         0.0, 
/* height */        0.0,
/* maxwidth */      0, 
/* maxheight */     0,
/* imagetype */     UI_TRUECOLOR,
/* palettestart */  0, 
/* paletteend */    256, 
/* maxentries */    255,
/* rmask */         RMASK,
/* gmask */         GMASK,
/* bmask */         BMASK,
/* gui_driver */    &cocoa_gui_driver
};
/* DONT FORGET TO ADD DOCUMENTATION ABOUT YOUR DRIVER INTO xaos.hlp FILE!*/