blob: c0e05cdf01a868bcb7f3ca8358a9022772d37903 [file] [log] [blame]
Jack Jansena4e6ae61999-03-07 23:11:21 +00001
2/* ========================= Module Qdoffs ========================== */
3
4#include "Python.h"
5
6
7
Jack Jansena4e6ae61999-03-07 23:11:21 +00008#include "macglue.h"
Jack Jansen9d8b96c2000-07-14 22:16:45 +00009#include "pymactoolbox.h"
Jack Jansena4e6ae61999-03-07 23:11:21 +000010
11#include <QDOffscreen.h>
12
Jack Jansen6dc8ce92000-03-03 16:03:06 +000013#define as_GrafPtr(gworld) ((GrafPtr)(gworld))
14
Jack Jansena4e6ae61999-03-07 23:11:21 +000015
16static PyObject *Qdoffs_Error;
17
18/* ----------------------- Object type GWorld ----------------------- */
19
20PyTypeObject GWorld_Type;
21
22#define GWorldObj_Check(x) ((x)->ob_type == &GWorld_Type)
23
24typedef struct GWorldObject {
25 PyObject_HEAD
26 GWorldPtr ob_itself;
27} GWorldObject;
28
29PyObject *GWorldObj_New(itself)
30 GWorldPtr itself;
31{
32 GWorldObject *it;
33 if (itself == NULL) return PyMac_Error(resNotFound);
34 it = PyObject_NEW(GWorldObject, &GWorld_Type);
35 if (it == NULL) return NULL;
36 it->ob_itself = itself;
37 return (PyObject *)it;
38}
39GWorldObj_Convert(v, p_itself)
40 PyObject *v;
41 GWorldPtr *p_itself;
42{
43 if (!GWorldObj_Check(v))
44 {
45 PyErr_SetString(PyExc_TypeError, "GWorld required");
46 return 0;
47 }
48 *p_itself = ((GWorldObject *)v)->ob_itself;
49 return 1;
50}
51
52static void GWorldObj_dealloc(self)
53 GWorldObject *self;
54{
55 DisposeGWorld(self->ob_itself);
56 PyMem_DEL(self);
57}
58
59static PyObject *GWorldObj_GetGWorldDevice(_self, _args)
60 GWorldObject *_self;
61 PyObject *_args;
62{
63 PyObject *_res = NULL;
64 GDHandle _rv;
65 if (!PyArg_ParseTuple(_args, ""))
66 return NULL;
67 _rv = GetGWorldDevice(_self->ob_itself);
68 _res = Py_BuildValue("O&",
69 ResObj_New, _rv);
70 return _res;
71}
72
73static PyObject *GWorldObj_GetGWorldPixMap(_self, _args)
74 GWorldObject *_self;
75 PyObject *_args;
76{
77 PyObject *_res = NULL;
78 PixMapHandle _rv;
79 if (!PyArg_ParseTuple(_args, ""))
80 return NULL;
81 _rv = GetGWorldPixMap(_self->ob_itself);
82 _res = Py_BuildValue("O&",
83 ResObj_New, _rv);
84 return _res;
85}
86
Jack Jansen6dc8ce92000-03-03 16:03:06 +000087static PyObject *GWorldObj_as_GrafPtr(_self, _args)
88 GWorldObject *_self;
89 PyObject *_args;
90{
91 PyObject *_res = NULL;
92 GrafPtr _rv;
93 if (!PyArg_ParseTuple(_args, ""))
94 return NULL;
95 _rv = as_GrafPtr(_self->ob_itself);
96 _res = Py_BuildValue("O&",
97 GrafObj_New, _rv);
98 return _res;
99}
100
Jack Jansena4e6ae61999-03-07 23:11:21 +0000101static PyMethodDef GWorldObj_methods[] = {
102 {"GetGWorldDevice", (PyCFunction)GWorldObj_GetGWorldDevice, 1,
103 "() -> (GDHandle _rv)"},
104 {"GetGWorldPixMap", (PyCFunction)GWorldObj_GetGWorldPixMap, 1,
105 "() -> (PixMapHandle _rv)"},
Jack Jansen6dc8ce92000-03-03 16:03:06 +0000106 {"as_GrafPtr", (PyCFunction)GWorldObj_as_GrafPtr, 1,
107 "() -> (GrafPtr _rv)"},
Jack Jansena4e6ae61999-03-07 23:11:21 +0000108 {NULL, NULL, 0}
109};
110
111PyMethodChain GWorldObj_chain = { GWorldObj_methods, NULL };
112
113static PyObject *GWorldObj_getattr(self, name)
114 GWorldObject *self;
115 char *name;
116{
117 return Py_FindMethodInChain(&GWorldObj_chain, (PyObject *)self, name);
118}
119
120#define GWorldObj_setattr NULL
121
Jack Jansena05ac601999-12-12 21:41:51 +0000122#define GWorldObj_compare NULL
123
124#define GWorldObj_repr NULL
125
126#define GWorldObj_hash NULL
127
Jack Jansena4e6ae61999-03-07 23:11:21 +0000128PyTypeObject GWorld_Type = {
129 PyObject_HEAD_INIT(&PyType_Type)
130 0, /*ob_size*/
131 "GWorld", /*tp_name*/
132 sizeof(GWorldObject), /*tp_basicsize*/
133 0, /*tp_itemsize*/
134 /* methods */
135 (destructor) GWorldObj_dealloc, /*tp_dealloc*/
136 0, /*tp_print*/
137 (getattrfunc) GWorldObj_getattr, /*tp_getattr*/
138 (setattrfunc) GWorldObj_setattr, /*tp_setattr*/
Jack Jansena05ac601999-12-12 21:41:51 +0000139 (cmpfunc) GWorldObj_compare, /*tp_compare*/
140 (reprfunc) GWorldObj_repr, /*tp_repr*/
141 (PyNumberMethods *)0, /* tp_as_number */
142 (PySequenceMethods *)0, /* tp_as_sequence */
143 (PyMappingMethods *)0, /* tp_as_mapping */
144 (hashfunc) GWorldObj_hash, /*tp_hash*/
Jack Jansena4e6ae61999-03-07 23:11:21 +0000145};
146
147/* --------------------- End object type GWorld --------------------- */
148
149
150static PyObject *Qdoffs_NewGWorld(_self, _args)
151 PyObject *_self;
152 PyObject *_args;
153{
154 PyObject *_res = NULL;
155 QDErr _err;
156 GWorldPtr offscreenGWorld;
157 short PixelDepth;
158 Rect boundsRect;
159 CTabHandle cTable;
160 GDHandle aGDevice;
161 GWorldFlags flags;
162 if (!PyArg_ParseTuple(_args, "hO&O&O&l",
163 &PixelDepth,
164 PyMac_GetRect, &boundsRect,
165 OptResObj_Convert, &cTable,
166 OptResObj_Convert, &aGDevice,
167 &flags))
168 return NULL;
169 _err = NewGWorld(&offscreenGWorld,
170 PixelDepth,
171 &boundsRect,
172 cTable,
173 aGDevice,
174 flags);
175 if (_err != noErr) return PyMac_Error(_err);
176 _res = Py_BuildValue("O&",
177 GWorldObj_New, offscreenGWorld);
178 return _res;
179}
180
181static PyObject *Qdoffs_LockPixels(_self, _args)
182 PyObject *_self;
183 PyObject *_args;
184{
185 PyObject *_res = NULL;
186 Boolean _rv;
187 PixMapHandle pm;
188 if (!PyArg_ParseTuple(_args, "O&",
189 ResObj_Convert, &pm))
190 return NULL;
191 _rv = LockPixels(pm);
192 _res = Py_BuildValue("b",
193 _rv);
194 return _res;
195}
196
197static PyObject *Qdoffs_UnlockPixels(_self, _args)
198 PyObject *_self;
199 PyObject *_args;
200{
201 PyObject *_res = NULL;
202 PixMapHandle pm;
203 if (!PyArg_ParseTuple(_args, "O&",
204 ResObj_Convert, &pm))
205 return NULL;
206 UnlockPixels(pm);
207 Py_INCREF(Py_None);
208 _res = Py_None;
209 return _res;
210}
211
212static PyObject *Qdoffs_UpdateGWorld(_self, _args)
213 PyObject *_self;
214 PyObject *_args;
215{
216 PyObject *_res = NULL;
217 GWorldFlags _rv;
218 GWorldPtr offscreenGWorld;
219 short pixelDepth;
220 Rect boundsRect;
221 CTabHandle cTable;
222 GDHandle aGDevice;
223 GWorldFlags flags;
224 if (!PyArg_ParseTuple(_args, "hO&O&O&l",
225 &pixelDepth,
226 PyMac_GetRect, &boundsRect,
227 OptResObj_Convert, &cTable,
228 OptResObj_Convert, &aGDevice,
229 &flags))
230 return NULL;
231 _rv = UpdateGWorld(&offscreenGWorld,
232 pixelDepth,
233 &boundsRect,
234 cTable,
235 aGDevice,
236 flags);
237 _res = Py_BuildValue("lO&",
238 _rv,
239 GWorldObj_New, offscreenGWorld);
240 return _res;
241}
242
243static PyObject *Qdoffs_GetGWorld(_self, _args)
244 PyObject *_self;
245 PyObject *_args;
246{
247 PyObject *_res = NULL;
248 CGrafPtr port;
249 GDHandle gdh;
250 if (!PyArg_ParseTuple(_args, ""))
251 return NULL;
252 GetGWorld(&port,
253 &gdh);
254 _res = Py_BuildValue("O&O&",
255 GrafObj_New, port,
256 ResObj_New, gdh);
257 return _res;
258}
259
260static PyObject *Qdoffs_SetGWorld(_self, _args)
261 PyObject *_self;
262 PyObject *_args;
263{
264 PyObject *_res = NULL;
265 CGrafPtr port;
266 GDHandle gdh;
267 if (!PyArg_ParseTuple(_args, "O&O&",
268 GrafObj_Convert, &port,
269 OptResObj_Convert, &gdh))
270 return NULL;
271 SetGWorld(port,
272 gdh);
273 Py_INCREF(Py_None);
274 _res = Py_None;
275 return _res;
276}
277
278static PyObject *Qdoffs_CTabChanged(_self, _args)
279 PyObject *_self;
280 PyObject *_args;
281{
282 PyObject *_res = NULL;
283 CTabHandle ctab;
284 if (!PyArg_ParseTuple(_args, "O&",
285 OptResObj_Convert, &ctab))
286 return NULL;
287 CTabChanged(ctab);
288 Py_INCREF(Py_None);
289 _res = Py_None;
290 return _res;
291}
292
293static PyObject *Qdoffs_PixPatChanged(_self, _args)
294 PyObject *_self;
295 PyObject *_args;
296{
297 PyObject *_res = NULL;
298 PixPatHandle ppat;
299 if (!PyArg_ParseTuple(_args, "O&",
300 ResObj_Convert, &ppat))
301 return NULL;
302 PixPatChanged(ppat);
303 Py_INCREF(Py_None);
304 _res = Py_None;
305 return _res;
306}
307
308static PyObject *Qdoffs_PortChanged(_self, _args)
309 PyObject *_self;
310 PyObject *_args;
311{
312 PyObject *_res = NULL;
313 GrafPtr port;
314 if (!PyArg_ParseTuple(_args, "O&",
315 GrafObj_Convert, &port))
316 return NULL;
317 PortChanged(port);
318 Py_INCREF(Py_None);
319 _res = Py_None;
320 return _res;
321}
322
323static PyObject *Qdoffs_GDeviceChanged(_self, _args)
324 PyObject *_self;
325 PyObject *_args;
326{
327 PyObject *_res = NULL;
328 GDHandle gdh;
329 if (!PyArg_ParseTuple(_args, "O&",
330 OptResObj_Convert, &gdh))
331 return NULL;
332 GDeviceChanged(gdh);
333 Py_INCREF(Py_None);
334 _res = Py_None;
335 return _res;
336}
337
338static PyObject *Qdoffs_AllowPurgePixels(_self, _args)
339 PyObject *_self;
340 PyObject *_args;
341{
342 PyObject *_res = NULL;
343 PixMapHandle pm;
344 if (!PyArg_ParseTuple(_args, "O&",
345 ResObj_Convert, &pm))
346 return NULL;
347 AllowPurgePixels(pm);
348 Py_INCREF(Py_None);
349 _res = Py_None;
350 return _res;
351}
352
353static PyObject *Qdoffs_NoPurgePixels(_self, _args)
354 PyObject *_self;
355 PyObject *_args;
356{
357 PyObject *_res = NULL;
358 PixMapHandle pm;
359 if (!PyArg_ParseTuple(_args, "O&",
360 ResObj_Convert, &pm))
361 return NULL;
362 NoPurgePixels(pm);
363 Py_INCREF(Py_None);
364 _res = Py_None;
365 return _res;
366}
367
368static PyObject *Qdoffs_GetPixelsState(_self, _args)
369 PyObject *_self;
370 PyObject *_args;
371{
372 PyObject *_res = NULL;
373 GWorldFlags _rv;
374 PixMapHandle pm;
375 if (!PyArg_ParseTuple(_args, "O&",
376 ResObj_Convert, &pm))
377 return NULL;
378 _rv = GetPixelsState(pm);
379 _res = Py_BuildValue("l",
380 _rv);
381 return _res;
382}
383
384static PyObject *Qdoffs_SetPixelsState(_self, _args)
385 PyObject *_self;
386 PyObject *_args;
387{
388 PyObject *_res = NULL;
389 PixMapHandle pm;
390 GWorldFlags state;
391 if (!PyArg_ParseTuple(_args, "O&l",
392 ResObj_Convert, &pm,
393 &state))
394 return NULL;
395 SetPixelsState(pm,
396 state);
397 Py_INCREF(Py_None);
398 _res = Py_None;
399 return _res;
400}
401
Jack Jansena05ac601999-12-12 21:41:51 +0000402static PyObject *Qdoffs_GetPixRowBytes(_self, _args)
403 PyObject *_self;
404 PyObject *_args;
405{
406 PyObject *_res = NULL;
407 long _rv;
408 PixMapHandle pm;
409 if (!PyArg_ParseTuple(_args, "O&",
410 ResObj_Convert, &pm))
411 return NULL;
412 _rv = GetPixRowBytes(pm);
413 _res = Py_BuildValue("l",
414 _rv);
415 return _res;
416}
417
Jack Jansena4e6ae61999-03-07 23:11:21 +0000418static PyObject *Qdoffs_NewScreenBuffer(_self, _args)
419 PyObject *_self;
420 PyObject *_args;
421{
422 PyObject *_res = NULL;
423 QDErr _err;
424 Rect globalRect;
425 Boolean purgeable;
426 GDHandle gdh;
427 PixMapHandle offscreenPixMap;
428 if (!PyArg_ParseTuple(_args, "O&b",
429 PyMac_GetRect, &globalRect,
430 &purgeable))
431 return NULL;
432 _err = NewScreenBuffer(&globalRect,
433 purgeable,
434 &gdh,
435 &offscreenPixMap);
436 if (_err != noErr) return PyMac_Error(_err);
437 _res = Py_BuildValue("O&O&",
438 ResObj_New, gdh,
439 ResObj_New, offscreenPixMap);
440 return _res;
441}
442
443static PyObject *Qdoffs_DisposeScreenBuffer(_self, _args)
444 PyObject *_self;
445 PyObject *_args;
446{
447 PyObject *_res = NULL;
448 PixMapHandle offscreenPixMap;
449 if (!PyArg_ParseTuple(_args, "O&",
450 ResObj_Convert, &offscreenPixMap))
451 return NULL;
452 DisposeScreenBuffer(offscreenPixMap);
453 Py_INCREF(Py_None);
454 _res = Py_None;
455 return _res;
456}
457
458static PyObject *Qdoffs_QDDone(_self, _args)
459 PyObject *_self;
460 PyObject *_args;
461{
462 PyObject *_res = NULL;
463 Boolean _rv;
464 GrafPtr port;
465 if (!PyArg_ParseTuple(_args, "O&",
466 GrafObj_Convert, &port))
467 return NULL;
468 _rv = QDDone(port);
469 _res = Py_BuildValue("b",
470 _rv);
471 return _res;
472}
473
474static PyObject *Qdoffs_OffscreenVersion(_self, _args)
475 PyObject *_self;
476 PyObject *_args;
477{
478 PyObject *_res = NULL;
479 long _rv;
480 if (!PyArg_ParseTuple(_args, ""))
481 return NULL;
482 _rv = OffscreenVersion();
483 _res = Py_BuildValue("l",
484 _rv);
485 return _res;
486}
487
488static PyObject *Qdoffs_NewTempScreenBuffer(_self, _args)
489 PyObject *_self;
490 PyObject *_args;
491{
492 PyObject *_res = NULL;
493 QDErr _err;
494 Rect globalRect;
495 Boolean purgeable;
496 GDHandle gdh;
497 PixMapHandle offscreenPixMap;
498 if (!PyArg_ParseTuple(_args, "O&b",
499 PyMac_GetRect, &globalRect,
500 &purgeable))
501 return NULL;
502 _err = NewTempScreenBuffer(&globalRect,
503 purgeable,
504 &gdh,
505 &offscreenPixMap);
506 if (_err != noErr) return PyMac_Error(_err);
507 _res = Py_BuildValue("O&O&",
508 ResObj_New, gdh,
509 ResObj_New, offscreenPixMap);
510 return _res;
511}
512
513static PyObject *Qdoffs_PixMap32Bit(_self, _args)
514 PyObject *_self;
515 PyObject *_args;
516{
517 PyObject *_res = NULL;
518 Boolean _rv;
519 PixMapHandle pmHandle;
520 if (!PyArg_ParseTuple(_args, "O&",
521 ResObj_Convert, &pmHandle))
522 return NULL;
523 _rv = PixMap32Bit(pmHandle);
524 _res = Py_BuildValue("b",
525 _rv);
526 return _res;
527}
528
Jack Jansen6dc8ce92000-03-03 16:03:06 +0000529static PyObject *Qdoffs_GetPixMapBytes(_self, _args)
530 PyObject *_self;
531 PyObject *_args;
532{
533 PyObject *_res = NULL;
534
535 PixMapHandle pm;
536 int from, length;
537 char *cp;
538
539 if ( !PyArg_ParseTuple(_args, "O&ii", ResObj_Convert, &pm, &from, &length) )
540 return NULL;
541 cp = GetPixBaseAddr(pm)+from;
542 return PyString_FromStringAndSize(cp, length);
543
544}
545
546static PyObject *Qdoffs_PutPixMapBytes(_self, _args)
547 PyObject *_self;
548 PyObject *_args;
549{
550 PyObject *_res = NULL;
551
552 PixMapHandle pm;
553 int from, length;
554 char *cp, *icp;
555
556 if ( !PyArg_ParseTuple(_args, "O&is#", ResObj_Convert, &pm, &from, &icp, &length) )
557 return NULL;
558 cp = GetPixBaseAddr(pm)+from;
559 memcpy(cp, icp, length);
560 Py_INCREF(Py_None);
561 return Py_None;
562
563}
564
Jack Jansena4e6ae61999-03-07 23:11:21 +0000565static PyMethodDef Qdoffs_methods[] = {
566 {"NewGWorld", (PyCFunction)Qdoffs_NewGWorld, 1,
567 "(short PixelDepth, Rect boundsRect, CTabHandle cTable, GDHandle aGDevice, GWorldFlags flags) -> (GWorldPtr offscreenGWorld)"},
568 {"LockPixels", (PyCFunction)Qdoffs_LockPixels, 1,
569 "(PixMapHandle pm) -> (Boolean _rv)"},
570 {"UnlockPixels", (PyCFunction)Qdoffs_UnlockPixels, 1,
571 "(PixMapHandle pm) -> None"},
572 {"UpdateGWorld", (PyCFunction)Qdoffs_UpdateGWorld, 1,
573 "(short pixelDepth, Rect boundsRect, CTabHandle cTable, GDHandle aGDevice, GWorldFlags flags) -> (GWorldFlags _rv, GWorldPtr offscreenGWorld)"},
574 {"GetGWorld", (PyCFunction)Qdoffs_GetGWorld, 1,
575 "() -> (CGrafPtr port, GDHandle gdh)"},
576 {"SetGWorld", (PyCFunction)Qdoffs_SetGWorld, 1,
577 "(CGrafPtr port, GDHandle gdh) -> None"},
578 {"CTabChanged", (PyCFunction)Qdoffs_CTabChanged, 1,
579 "(CTabHandle ctab) -> None"},
580 {"PixPatChanged", (PyCFunction)Qdoffs_PixPatChanged, 1,
581 "(PixPatHandle ppat) -> None"},
582 {"PortChanged", (PyCFunction)Qdoffs_PortChanged, 1,
583 "(GrafPtr port) -> None"},
584 {"GDeviceChanged", (PyCFunction)Qdoffs_GDeviceChanged, 1,
585 "(GDHandle gdh) -> None"},
586 {"AllowPurgePixels", (PyCFunction)Qdoffs_AllowPurgePixels, 1,
587 "(PixMapHandle pm) -> None"},
588 {"NoPurgePixels", (PyCFunction)Qdoffs_NoPurgePixels, 1,
589 "(PixMapHandle pm) -> None"},
590 {"GetPixelsState", (PyCFunction)Qdoffs_GetPixelsState, 1,
591 "(PixMapHandle pm) -> (GWorldFlags _rv)"},
592 {"SetPixelsState", (PyCFunction)Qdoffs_SetPixelsState, 1,
593 "(PixMapHandle pm, GWorldFlags state) -> None"},
Jack Jansena05ac601999-12-12 21:41:51 +0000594 {"GetPixRowBytes", (PyCFunction)Qdoffs_GetPixRowBytes, 1,
595 "(PixMapHandle pm) -> (long _rv)"},
Jack Jansena4e6ae61999-03-07 23:11:21 +0000596 {"NewScreenBuffer", (PyCFunction)Qdoffs_NewScreenBuffer, 1,
597 "(Rect globalRect, Boolean purgeable) -> (GDHandle gdh, PixMapHandle offscreenPixMap)"},
598 {"DisposeScreenBuffer", (PyCFunction)Qdoffs_DisposeScreenBuffer, 1,
599 "(PixMapHandle offscreenPixMap) -> None"},
600 {"QDDone", (PyCFunction)Qdoffs_QDDone, 1,
601 "(GrafPtr port) -> (Boolean _rv)"},
602 {"OffscreenVersion", (PyCFunction)Qdoffs_OffscreenVersion, 1,
603 "() -> (long _rv)"},
604 {"NewTempScreenBuffer", (PyCFunction)Qdoffs_NewTempScreenBuffer, 1,
605 "(Rect globalRect, Boolean purgeable) -> (GDHandle gdh, PixMapHandle offscreenPixMap)"},
606 {"PixMap32Bit", (PyCFunction)Qdoffs_PixMap32Bit, 1,
607 "(PixMapHandle pmHandle) -> (Boolean _rv)"},
Jack Jansen6dc8ce92000-03-03 16:03:06 +0000608 {"GetPixMapBytes", (PyCFunction)Qdoffs_GetPixMapBytes, 1,
609 "(pixmap, int start, int size) -> string. Return bytes from the pixmap"},
610 {"PutPixMapBytes", (PyCFunction)Qdoffs_PutPixMapBytes, 1,
611 "(pixmap, int start, string data). Store bytes into the pixmap"},
Jack Jansena4e6ae61999-03-07 23:11:21 +0000612 {NULL, NULL, 0}
613};
614
615
616
617
618void initQdoffs()
619{
620 PyObject *m;
621 PyObject *d;
622
623
624
625
626 m = Py_InitModule("Qdoffs", Qdoffs_methods);
627 d = PyModule_GetDict(m);
628 Qdoffs_Error = PyMac_GetOSErrException();
629 if (Qdoffs_Error == NULL ||
630 PyDict_SetItemString(d, "Error", Qdoffs_Error) != 0)
631 Py_FatalError("can't initialize Qdoffs.Error");
632 GWorld_Type.ob_type = &PyType_Type;
633 Py_INCREF(&GWorld_Type);
634 if (PyDict_SetItemString(d, "GWorldType", (PyObject *)&GWorld_Type) != 0)
635 Py_FatalError("can't initialize GWorldType");
636}
637
638/* ======================= End module Qdoffs ======================== */
639