ScummVM API documentation
toolbox.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef GRAPHICS_MACTOOLBOX_MACTOOLBOX_H
23#define GRAPHICS_MACTOOLBOX_MACTOOLBOX_H
24
25#include "common/bitstream.h"
26#include "common/hashmap.h"
27#include "common/system.h"
28#include "common/macresman.h"
29#include "common/str.h"
30#include "common/ustr.h"
31
32#include "audio/mixer.h"
33#include "graphics/cursor.h"
34#include "graphics/framelimiter.h"
35#include "graphics/macgui/macfontmanager.h"
36#include "graphics/macgui/macwindow.h"
37#include "graphics/macgui/macwindowmanager.h"
38#include "graphics/mactoolbox/siphash/halfsip.h"
39
40
41namespace Audio {
42class PCSpeakerStream;
43}
44
45namespace Graphics {
46namespace MacToolbox {
47
48struct RGBColor {
49 uint16 red;
50 uint16 green;
51 uint16 blue;
52};
53
54struct ColorSpec {
55 uint16 value;
56 RGBColor rgb;
57};
58
59struct ColorTable {
60 uint32 ctSeed;
61 uint16 ctFlags;
62 uint16 ctSize;
64};
65
66struct Region {
67 uint16 rgnSize;
68 Common::Rect rgnBBox;
70};
71
72struct PixMap {
73 uint32 baseAddr;
74 uint16 rowBytes;
75 Common::Rect bounds;
76 uint16 pmVersion;
77 uint16 packType;
78 uint32 packSize;
79 uint32 hRes;
80 uint32 vRes;
81 uint16 pixelType;
82 uint16 pixelSize;
83 uint16 cmpCount;
84 uint16 cmpSize;
85 uint32 planeBytes;
86 uint32 pmTable;
87 uint32 pmReserved;
88 bool _isBitMap = false;
89};
90
91struct Polygon {
92 uint16 polySize;
93 Common::Rect polyBBox;
95};
96
97// In QuickDraw 0 means white and 1 means black
98struct Pattern {
99 uint8 data[8];
100
101 Common::String format() const {
102 return Common::String::format("%02x%02x%02x%02x%02x%02x%02x%02x", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
103 }
104};
105
106enum PictureOpType : uint16 {
107 kOpNOP = 0x0000,
108 kOpClip = 0x0001,
109 kOpBkPat = 0x0002,
110 kOpTxFont = 0x0003,
111 kOpTxFace = 0x0004,
112 kOpTxMode = 0x0005,
113 kOpSpExtra = 0x0006,
114 kOpPnSize = 0x0007,
115 kOpPnMode = 0x0008,
116 kOpPnPat = 0x0009,
117 kOpFillPat = 0x000a,
118 kOpOvSize = 0x000b,
119 kOpOrigin = 0x000c,
120 kOpTxSize = 0x000d,
121 kOpFgColor = 0x000e,
122 kOpBkColor = 0x000f,
123 kOpTxRatio = 0x0010,
124 kOpVersion2 = 0x0011,
125 kOpBkPixPat = 0x0012,
126 kOpPnPixPat = 0x0013,
127 kOpFillPixPat = 0x0014,
128 kOpPnLocHFrac = 0x0015,
129 kOpChExtra = 0x0016,
130 // reserved 0x0017
131 // reserved 0x0018
132 // reserved 0x0019
133 kOpRGBFgCol = 0x001a,
134 kOpRGBBkCol = 0x001b,
135 kOpHiliteMode = 0x001c,
136 kOpHiliteColor = 0x001d,
137 kOpDefHilite = 0x001e,
138 kOpColor = 0x001f,
139 kOpLine = 0x0020,
140 kOpLineFrom = 0x0021,
141 kOpShortLine = 0x0022,
142 kOpShortLineFrom = 0x0023,
143 // reserved 0x0024
144 // reserved 0x0025
145 // reserved 0x0026
146 // reserved 0x0027
147 kOpLongText = 0x0028,
148 kOpDHText = 0x0029,
149 kOpDVText = 0x002a,
150 kOpDHDVText = 0x002b,
151 kOpFontName = 0x002c,
152 kOpLineJustify = 0x002d,
153 kOpGlyphState = 0x002e,
154 // reserved 0x002f
155 kOpFrameRect = 0x0030,
156 kOpPaintRect = 0x0031,
157 kOpEraseRect = 0x0032,
158 kOpInvertRect = 0x0033,
159 kOpFillRect = 0x0034,
160 // reserved 0x0035
161 // reserved 0x0036
162 // reserved 0x0037
163 kOpFrameSameRect = 0x0038,
164 kOpPaintSameRect = 0x0039,
165 kOpEraseSameRect = 0x003a,
166 kOpInvertSameRect = 0x003b,
167 kOpFillSameRect = 0x003c,
168 // reserved 0x003d
169 // reserved 0x003e
170 // reserved 0x003f
171 kOpFrameRRect = 0x0040,
172 kOpPaintRRect = 0x0041,
173 kOpEraseRRect = 0x0042,
174 kOpInvertRRect = 0x0043,
175 kOpFillRRect = 0x0044,
176 // reserved 0x0045
177 // reserved 0x0046
178 // reserved 0x0047
179 kOpFrameSameRRect = 0x0048,
180 kOpPaintSameRRect = 0x0049,
181 kOpEraseSameRRect = 0x004a,
182 kOpInvertSameRRect = 0x004b,
183 kOpFillSameRRect = 0x004c,
184 // reserved 0x004d
185 // reserved 0x004e
186 // reserved 0x004f
187 kOpFrameOval = 0x0050,
188 kOpPaintOval = 0x0051,
189 kOpEraseOval = 0x0052,
190 kOpInvertOval = 0x0053,
191 kOpFillOval = 0x0054,
192 // reserved 0x0055
193 // reserved 0x0056
194 // reserved 0x0057
195 kOpFrameSameOval = 0x0058,
196 kOpPaintSameOval = 0x0059,
197 kOpEraseSameOval = 0x005a,
198 kOpInvertSameOval = 0x005b,
199 kOpFillSameOval = 0x005c,
200 // reserved 0x005d
201 // reserved 0x005e
202 // reserved 0x005f
203
204 kOpFramePoly = 0x0070,
205 kOpPaintPoly = 0x0071,
206 kOpErasePoly = 0x0072,
207 kOpInvertPoly = 0x0073,
208 kOpFillPoly = 0x0074,
209 // reserved 0x0075
210 // reserved 0x0076
211 // reserved 0x0077
212 kOpFrameSamePoly = 0x0078,
213 kOpPaintSamePoly = 0x0079,
214 kOpEraseSamePoly = 0x007a,
215 kOpInvertSamePoly = 0x007b,
216 kOpFillSamePoly = 0x007c,
217 // reserved 0x007d
218 // reserved 0x007e
219 // reserved 0x007f
220
221 kOpBitsRect = 0x0090,
222 kOpBitsRgn = 0x0091,
223
224 kOpPackBitsRect = 0x0098,
225 kOpPackBitsRgn = 0x0099,
226
227 kOpShortComment = 0x00a0,
228 kOpLongComment = 0x00a1,
229
230 kOpEndPic = 0x00ff,
231
232 kOpHeaderOp = 0x0c00,
233 kOpVersion1 = 0x1101,
234};
235
236// BitMap is the monochrome surface format.
238typedef Common::SharedPtr<Polygon> PolyHandle;
240typedef Common::SharedPtr<Region> RgnHandle;
241
242struct Picture {
243 uint32 picSize = 0;
244 Common::Rect picFrame;
245 Common::Array<byte> picData;
246 size_t picPtr = 0;
247 // simulate slow drawing
248 uint32 _opsPerTick = 0;
249
250 void pushOp(PictureOpType op) {
251 picData.push_back(op >> 8);
252 picData.push_back(op & 0xff);
253 }
254
255 void pushOpU16(PictureOpType op, uint16 val) {
256 picData.push_back(op >> 8);
257 picData.push_back(op & 0xff);
258 picData.push_back(val >> 8);
259 picData.push_back(val & 0xff);
260 }
261
262 void pushHeader();
263 void pushOpPoly(PictureOpType op, const PolyHandle &poly);
264 void pushOpPat(PictureOpType op, const Pattern &pat);
265 void pushOpRect(PictureOpType op, const Common::Rect &rect);
266 void pushOpPoint(PictureOpType op, const Common::Point &point);
267 void pushOpPointStr(PictureOpType op, const Common::Point &point, const Common::String &str);
268};
269
270
272
273typedef uint32 ResType;
274typedef size_t Size;
275
276}; // namespace MacToolbox
277}; // namespace Graphics
278
279namespace Common {
280
281template<>
282struct Hash<Graphics::MacToolbox::Handle> {
283 uint operator()(const Graphics::MacToolbox::Handle& h) const {
284 void *target = h.get();
285 uint result;
286 Graphics::MacToolbox::halfsiphash((const void *)&target, sizeof(intptr_t), "TBHANDLE", (byte *)&result, sizeof(uint));
287 return result;
288 }
289};
290
291template<>
292struct Hash<Graphics::MacToolbox::PicHandle> {
293 uint operator()(const Graphics::MacToolbox::PicHandle& h) const {
294 void *target = h.get();
295 uint result;
296 Graphics::MacToolbox::halfsiphash((const void *)&target, sizeof(intptr_t), "TBHANDLE", (byte *)&result, sizeof(uint));
297 return result;
298 }
299};
300
301}; // namespace Common
302
303namespace Graphics {
304namespace MacToolbox {
305
306// TYPE BOOLEAN: int16
307// TYPE INTEGER: int16
308// TYPE LONGINT: int32
309// TYPE CHAR: int16
310// TYPE Rect: top: INTEGER; left: INTEGER; bottom: INTEGER; right: INTEGER;
311// TYPE Point: v: INTEGER; h: INTEGER;
312
314public:
315 uint16 data[16];
316 uint16 mask[16];
317 Common::Point mouse;
318
319 void render() {
320 for (int y = 0; y < 16; y++) {
321 for (int x = 0; x < 16; x++) {
322 _surface[y*16+x] = (this->data[y] & (1 << (15 - x))) ? 1 : 0;
323 _mask[y*16+x] = (this->mask[y] & (1 << (15 - x))) ? kCursorMaskOpaque : kCursorMaskTransparent;
324 }
325 }
326 }
327
328 virtual uint16 getWidth() const { return 16; }
329 virtual uint16 getHeight() const { return 16; }
330 virtual uint16 getHotspotX() const { return mouse.x; }
331 virtual uint16 getHotspotY() const { return mouse.y; }
332 virtual byte getKeyColor() const { return 3; }
333 virtual const byte *getSurface() const { return _surface; }
334 virtual const byte *getMask() const { return _mask; }
335 virtual const byte *getPalette() const { return _palette; }
336 virtual byte getPaletteStartIndex() const { return 0; }
337 virtual uint16 getPaletteCount() const { return _paletteCount; }
338
339
340private:
341 byte _surface[16*16] = { 0 };
342 byte _mask[16*16] = { 0 };
343 byte _palette[6] = { 0xff, 0xff, 0xff, 0x00, 0x00, 0x00 };
344 uint16 _paletteCount = 2;
345}; // 0x44
346
347typedef uint32 OSType;
348typedef int16 OSErr;
349typedef uint32 ProcPtr;
350
351// source: Inside Macintosh II-138
352enum OSErrCode : int16 {
353 kNoErr = 0,
354 kBadMDBErr = -60,
355 kBdNamErr = -37,
356 kDirFulErr = -33,
357 kDskFulErr = -34,
358 kDupFNErr = -48,
359 kEOFErr = -39,
360 kExtFSErr = -58,
361 kFBsyErr = -47,
362 kFLckdErr = -45,
363 kFnfErr = -43,
364 kFnOpnErr = -38,
365 kFsRnErr = -59,
366 kGfpErr = -52,
367 kIoErr = -36,
368 kMemFullErr = -108,
369 kNoMacDskErr = -57,
370 kNsDrvErr = -56,
371 kNsvErr = -35,
372 kOpWrErr = -49,
373 kParamErr = -50,
374 kPermErr = -54,
375 kPosErr = -40,
376 kRfNumErr = -51,
377 kTmfoErr = -42,
378 kVolOffLinErr = -53,
379 kVolOnLinErr = -55,
380 kVLckdErr = -46,
381 kWrPermErr = -61,
382 kWPrErr = -44,
383};
384
385enum EventCode : uint16 {
386 kNullEvent = 0,
387 kMouseDown = 1,
388 kMouseUp = 2,
389 kKeyDown = 3,
390 kKeyUp = 4,
391 kAutoKey = 5,
392 kUpdateEvt = 6,
393 kDiskEvt = 7,
394 kActivateEvt = 8,
395 kNetworkEvt = 10,
396 kDriverEvt = 11,
397 kApp1Evt = 12,
398 kApp2Evt = 13,
399 kApp3Evt = 14,
400 kOsEvt = 15,
401 kHighLevelEvt = 23,
402 kScummVMQuitEvt = 24,
403 kScummVMReturnToLauncherEvt = 25,
404};
405
406enum ModifierMask : uint16 {
407 kModForegroundSwitch = 0x0001,
408 kModMouseButtonUp = 0x0080,
409 kModCommandKeyDown = 0x0100,
410 kModLShiftKeyDown = 0x0200,
411 kModCapsLockKeyDown = 0x0400,
412 kModLOptionKeyDown = 0x0800,
413 kModLControlKeyDown = 0x1000,
414 kModRShiftKeyDown = 0x2000,
415 kModROptionKeyDown = 0x4000,
416 kModRControlKeyDown = 0x8000,
417};
418
419enum SourceMode : uint16 {
420 kSrcCopy = 0,
421 kSrcOr = 1,
422 kSrcXor = 2,
423 kSrcBic = 3,
424 kNotSrcCopy = 4,
425 kNotSrcOr = 5,
426 kNotSrcXor = 6,
427 kNotSrcBic = 7
428};
429
430enum PatternMode : uint16 {
431 kPatCopy = 8,
432 kPatOr = 9,
433 kPatXor = 10,
434 kPatBic = 11,
435 kNotPatCopy = 12,
436 kNotPatOr = 13,
437 kNotPatXor = 14,
438 kNotPatBic = 15
439};
440
441enum WindowDefinition {
442 kDocumentProc = 0,
443 kDBoxProc = 1,
444 kPlainDBox = 2,
445 kAltDBoxProc = 3,
446 kNoGrowDocProc = 4,
447 kRDocProc = 16,
448};
449
450// for text style: use kMacFont*
451
452struct GrafPort {
453 uint16 device = 0;
454 BitMap portBits;
455 Common::Rect portRect;
456 RgnHandle visRgn;
457 RgnHandle clipRgn;
458 Pattern bkPat = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; // white
459 Pattern fillPat = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; // black
460 Common::Point pnLoc = {0, 0};
461 Common::Point pnSize = {1, 1};
462 PatternMode pnMode = kPatCopy;
463 Pattern pnPat = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; // black
464 uint16 pnVis = 0;
465 uint16 txFont = 0;
466 uint16 txFace;
467 SourceMode txMode = kSrcOr;
468 uint16 txSize = 0;
469 uint32 spExtra = 0;
470 uint32 fgColor;
471 uint32 bkColor;
472 uint16 colrBit = 0;
473 uint16 patStretch = 0;
474 PicHandle picSave;
475 RgnHandle rgnSave;
476 PolyHandle polySave;
477
478};
479typedef GrafPort * GrafPtr;
480
482 GrafPort port;
483 uint16 windowKind;
484};
485
487 EventCode what = kNullEvent; // 0
488 uint32 message = 0; // 2
489 WindowRecord *windowPtr = nullptr; // also 2
490 uint32 when = 0; // 6
491 Common::Point where; // 10
492 uint16 modifiers = 0; // 14
493};
494
496 int16 fileID;
497 ResType type;
498 uint16 resID;
499 Handle handle;
500 Common::String name;
501};
502
503struct FontInfo {
504 int16 ascent;
505 int16 descent;
506 int16 widMax;
507 int16 leading;
508};
509
510struct MenuInfo {
511 uint16 menuID;
512 uint16 menuWidth;
513 uint16 menuHeight;
514 Handle menuProc;
515 uint32 enableFlags;
516 // original record stores this as a single string blob, we split it up.
518};
519
521
523 uint32 qLink = 0;
524 uint16 qType = 0;
525 uint16 ioTrap = 0;
526 uint32 ioCmdAddr = 0;
527 uint32 ioCompletion = 0;
528 OSErr ioResult = 0;
529 Common::String ioNamePtr;
530 uint16 ioVRefNum = 0;
531};
532
534 OSType types[4];
535};
536
537struct SFReply {
538 bool good; // 0
539 bool copy; // 1
540 OSType fType; // 2
541 int16 vRefNum; // 6
542 int16 version; // 8
543 Common::String fName; // 10
544}; // total: 76
545
546enum SynthMode : int16 {
547 swMode = -1, // square-wave
548 ftMode = 1, // four-tone
549 ffMode = 0, // free-form
550};
551
552struct Tone {
553 uint16 count;
554 uint16 amplitude;
555 uint16 duration;
556};
557
558struct SynthRec {
559 SynthMode mode;
560};
561typedef SynthRec * SynthPtr;
562
564
565 SWSynthRec() {
566 mode = swMode;
567 }
568 Common::Array<Tone> triplets;
569};
570
571typedef Common::String (*FileModalCallback)(bool save, const Common::String &suggested, const Common::String &title);
572
573class Toolbox {
574
575public:
576 // Compatibility shim for the Macintosh Toolbox/QuickDraw API.
578 ~Toolbox();
579
580 Graphics::MacWindow *_defaultWindow;
581 Graphics::MacMenu *_defaultMenu;
582 BitMap _defaultBits;
583 BitMap _defaultMenuBits;
584
585
586 // toolbox.cpp
587
588 // PROCEDURE Delay (numTicks: LONGINT; VAR finalTicks: LONGINT);
589 // Delay causes the system to wait for the number of ticks (sixtieths of a second) specified by numTicks, and returns in finalTicks the total number of ticks from system startup to the end of the delay.
590 uint32 Delay(uint32 numTicks);
591
592 // PROCEDURE FlushEvents (eventMask, stopMask: INTEGER);
593 // FlushEvents removes events from the event queue as specified by the given event masks. It
594 // removes all events of the type or types specified by eventMask, up to but not including the first
595 // event of any type specified by stopMask; if the event queue doesn't contain any events of the
596 // types specified by eventMask, it does nothing. To remove all events specified by eventMask, use
597 // a stopMask value of 0.
598 void FlushEvents(uint32 eventMask, uint32 stopMask);
599
600 // FUNCTION GetNextEvent (eventMask: INTEGER; VAR theEvent: EventRecord) : BOOLEAN;
601 // GetNextEvent returns the next available event of a specified type or types and, if the event is in
602 // the event queue, removes it from the queue. The event is returned in the parameter theEvent. The
603 // eventMask parameter specifies which event types are of interest. GetNextEvent returns the next
604 // available event of any type designated by the mask, subject to the priority rules discussed above
605 // under "Priority of Events". If no event of any of the designated types is available, GetNextEvent
606 // returns a null event.
607 bool GetNextEvent(int32 eventMask, EventRecord &theEvent);
608
609 // FUNCTION TickCount : LONGINT;
610 // TickCount returns the current number of ticks (sixtieths of a second) since the system last started
611 // up.
612 uint32 TickCount();
613
614 // toolbox_fileman.cpp
615 OSErr GetFInfo(const Common::U32String &fileName, int16 vRefNum, Common::MacFinderInfo &fndrInfo);
616
617 OSErr PBGetVol(ParamBlockRec &paramBlock);
618
619 OSErr PBSetVol(ParamBlockRec &paramBlock);
620
621 void SFGetFile(const Common::Point &where, const Common::U32String &prompt, ProcPtr fileFilter, int16 numTypes, const SFTypeList &typeList, const ProcPtr &dlgHook, SFReply &reply);
622
623 // PROCEDURE SFPutFile (where: Point; prompt: Str255; origName:
624 // Str255; dlgHook: ProcPtr; VAR reply: SFReply);
625 void SFPutFile(const Common::Point &where, const Common::U32String &prompt, const Common::U32String &origName, const ProcPtr &dlgHook, SFReply &reply);
626
627 // toolbox_sound.cpp
628
629 // PROCEDURE GetSoundVol (VAR level : INTEGER);
630 // GetSoundVol returns the current speaker volume, from 0 (silent) to 7 (loudest).
631 int16 GetSoundVol();
632
633 // PROCEDURE SetSoundVol (level: INTEGER);
634 // SetSoundVol immediately sets the speaker volume to the specified level, from 0 (silent) to 7 (loudest).
635 void SetSoundVol(int16 level);
636
637 // FUNCTION SoundDone: BOOLEAN;
638 // SoundDone returns TRUE if the Sound Driver isn't currently producing sound and there are no
639 // asynchronous StartSound calls pending; otherwise it returns FALSE.
640 bool SoundDone();
641
642 // PROCEDURE StartSound (synthRec: Ptr; numBytes: LONGINT; completionRtn: ProcPtr);
643 // StartSound begins producing the sound described by the synthesizer buffer pointed to by
644 // synthRec. NumBytes indicates the size of the synthesizer buffer (in bytes), and completionRtn
645 // points to a completion routine to be executed when the sound finishes:
646 // • If completionRtn is POINTER(-l), the sound will be produced synchronously.
647 // • If completionRtn is NIL, the sound will be produced asynchronously, but no completion
648 // routine will be executed.
649 // • Otherwise, the sound will be produced asynchronously and the routine pointed to by
650 // completionRtn will be executed when the sound finishes.
651 void StartSound(SynthPtr synthRec, uint32 numBytes, ProcPtr completionRtn);
652
653 // PROCEDURE StopSound;
654 // StopSound immediately stops the current StartSound call (if any), executes the current
655 // StartSound call's completion routine (if any), and cancels any pending asynchronous StartSound calls.
656 void StopSound();
657
658 // toolbox_resman.cpp
659
660 // PROCEDURE CloseResFile (refNum: INTEGER);
661 // Given the reference number of a resource file, CloseResFile does the following:
662 // - updates the resource file by calling the UpdateResFile procedure
663 // - for each resource in the resource file, releases the memory it occupies by calling the
664 // ReleaseResource procedure
665 // - releases the memory occupied by the resource map
666 // - closes the resource file
667 void CloseResFile(int16 refNum);
668
669 // FUNCTION CountResources (theType: ResType): Integer;
670 // Given a resource type, the CountResources function reads the resource maps in
671 // memory for all resource forks open to your application. It returns as its function result
672 // the total number of resources of the given type in all resource forks open to your
673 // application.
674 uint16 CountResources(ResType theType);
675
676 // FUNCTION CurResFile: INTEGER;
677 // CurResFile returns the reference number of the current resource file. You can call it when the
678 // application starts up to get the reference number of its resource file.
679 int16 CurResFile();
680
681 // PROCEDURE DetachResource (theResource: Handle);
682 // Given a handle to a resource, DetachResource replaces the handle to that resource in the resource
683 // map with NIL (see Figure 7 above). The given handle will no longer be recognized as a handle to
684 // a resource; if the Resource Manager is subsequendy called to get the detached resource, a new
685 // handle will be allocated.
686 void DetachResource(Handle &h);
687 void DetachResource(PicHandle &h);
688
689 // PROCEDURE DisposHandle (h: Handle);
690 // DisposHandle releases the memory occupied by the relocatable block whose handle is h.
691 void DisposHandle(Handle &h);
692
693 // FUNCTION GetHandleSize (h: Handle) : Size;
694 // GetHandleSize returns the logical size, in bytes, of the relocatable block whose handle is h. In
695 // case of an error, GetHandleSize returns 0.
696 Size GetHandleSize(Handle &h);
697
698 // FUNCTION GetIndResource (theType: ResType; index: Integer): Handle;
699 // Given an index ranging from 1 to the number of resources of a given type returned by
700 // CountResources (that is, the number of resources of that type in all resource forks open
701 // to your application), the GetIndResource function returns a handle to a resource of the
702 // given type. If you call GetIndResource repeatedly over the entire range of the index, it
703 // returns handles to all resources of the given type in all resource forks open to your
704 // application.
705 Handle GetIndResource(ResType theType, uint16 index);
706
707 // FUNCTION GetNamedResource (theType: ResType; name: Str255) : Handle;
708 // GetNamedResource is the same as GetResource (above) except that you pass a resource name
709 // instead of an ID number.
710 Handle GetNamedResource(ResType theType, const Common::String &name);
711
712 // PROCEDURE GetResInfo (theResource: Handle; VAR theID: INTEGER;
713 // VAR theType: ResType; VAR name: Str255);
714 // Given a handle to a resource, GetResInfo returns the ID number, type, and name of the resource.
715 // If the given handle isn't a handle to a resource, GetResInfo will do nothing and the ResError
716 // function will return the result code resNotFound.
717 void GetResInfo(Handle &theResource, uint16 &theID, ResType &theType, Common::String &name);
718
719 // FUNCTION GetResource (theType: ResType; theID: INTEGER) : Handle;
720 // GetResource returns a handle to the resource having the given type and ID number, reading
721 // the resource data into memory if it's not already in memory and if you haven't called
722 // SetResLoad(FALSE) (see the warning above for GetIndResource). If the resource data is already
723 // in memory, GetResource just returns the handle to the resource.
724 Handle GetResource(ResType theType, uint16 theID);
725
726 // FUNCTION HomeResFile (theResource: Handle) : INTEGER;
727 // Given a handle to a resource, HomeResFile returns the reference number of the resource file
728 // containing that resource. If the given handle isn't a handle to a resource, HomeResFile will
729 // return -1 and the ResError function will return the result code resNotFound.
730 int32 HomeResFile(Handle &theResource);
731
732 // FUNCTION NewHandle (logicalSize: Size) : Handle;
733 // NewHandle attempts to allocate a new relocatable block of logicalSize bytes from the current heap
734 // zone and then return a handle to it. The new block will be unlocked and unpurgeable. If
735 // logicalSize bytes can't be allocated, NewHandle returns NIL.
736 Handle NewHandle(Size logicalSize);
737
738 // FUNCTION OpenResFile (fileName: Str255): INTEGER;
739 // OpenResFile opens the resource file having the given name and makes it the current resource file.
740 // It reads the resource map from the file into memory and returns a reference number for the file. It
741 // also reads in every resource whose resPreload attribute is set. If the resource file is already open,
742 // it doesn't make it the current resource file; it simply returns the reference number.
743 // If the file can't be opened, OpenResFile will return -1 and the ResError function will return an
744 // appropriate Operating System result code. For example, an error occurs if there's no resource file
745 // with the given name.
746 int16 OpenResFile(const Common::Path &filename);
747
748 // PROCEDURE ReleaseResource (theResource: Handle);
749 // Given a handle to a resource, ReleaseResource releases the memory occupied by the resource
750 // data, if any, and replaces the handle to that resource in the resource map with NIL (see Figure 7).
751 // The given handle will no longer be recognized as a handle to a resource; if the Resource Manager
752 // is subsequendy called to get the released resource, a new handle will be allocated. Use this
753 // procedure only after you're completely through with a resource.
754 void ReleaseResource(Handle &handle);
755 void ReleaseResource(PicHandle &handle);
756
757 // FUNCTION SizeResource(theResource: Handle) : LONGINT;
758 // Given a handle to a resource, SizeResource returns the size in bytes of the resource in the
759 // resource file. If the given handle isn't a handle to a resource, SizeResource will return - 1 and the
760 // ResError function will return the result code resNotFound. It's a good idea to call SizeResource
761 // and ensure that sufficient space is available before reading a resource into memory.
762 int32 SizeResource(Handle &theResource);
763
764 // PROCEDURE UseResFile (refNum: INTEGER);
765 // Given the reference number of a resource file, UseResFile sets the current resource file to that
766 // file. If there's no resource file open with the given reference number, UseResFile will do nothing
767 // and the ResError function will return the result code resFNotFound. A refNum of 0 represents
768 // the system resource file.
769 void UseResFile(int16 refNum);
770
771
772 // toolbox_menu.cpp
773
774 // PROCEDURE AppendMenu(theMenu: MenuHandle; data: Str255);
775 // AppendMenu adds an item or items to the end of the given menu, which must previously have
776 // been allocated by NewMenu or read from a resource file by GetMenu. The data string consists of
777 // the text of the menu item; it may be blank but should not be the empty string. If it begins with a
778 // hyphen (-), the item will be a dividing line across the width of the menu. As described in the
779 // section "Creating a Menu in Your Program", meta-characters may be embedded in the data string.
780 void AppendMenu(MenuHandle &theMenu, const Common::U32String &data);
781
782 // PROCEDURE CheckItem (theMenu: MenuHandle; item: INTEGER, checked: BOOLEAN);
783 // CheckItem places or removes a check mark at the left of the given menu item. After you call
784 // CheckItem with checked=TRUE, a check mark will appear each subsequent time the menu is
785 // pulled down. Calling CheckItem with checked=FALSE removes the check mark from the menu
786 // item (or, if it's marked with a different character, removes that mark).
787 void CheckItem(MenuHandle &theMenu, uint16 item, bool checked);
788
789 // PROCEDURE ClearMenuBar;
790 // Call ClearMenuBar to remove all menus from the menu list when you want to start afresh with all
791 // new menus. Be sure to call DrawMenuBar to update the menu bar.
792 void ClearMenuBar();
793
794 // FUNCTION CountMItems (theMenu: MenuHandle): INTEGER;
795 // CountMItems returns the number of menu items in the given menu.
796 uint16 CountMItems(MenuHandle &theMenu);
797
798 // PROCEDURE DeleteMenu(menuID: INTEGER);
799 // DeleteMenu deletes a menu from the menu list. If there's no menu with the given menu ID in the
800 // menu list, DeleteMenu has no effect. Be sure to call DrawMenuBar to update the menu bar; the
801 // menu tides following the deleted menu will move over to fill the vacancy.
802 void DeleteMenu(uint16 menuID);
803
804 // PROCEDURE DisableItem(theMenu: MenuHandle; item: INTEGER);
805 // Given a menu item number in the item parameter, Disableltem disables that menu item; given 0 in
806 // the item parameter, it disables the entire menu.
807 void DisableItem(MenuHandle &theMenu, uint16 item);
808
809 // PROCEDURE DisposeMenu(theMenu: MenuHandle);
810 // Call DisposeMenu to release the memory occupied by a menu that you allocated with NewMenu.
811 // (For menus read from a resource file with GetMenu, use the Resource Manager procedure
812 // ReleaseResource instead.) This is useful if you've created temporary menus that you no longer
813 // need.
814 void DisposeMenu(MenuHandle &theMenu);
815
816 // PROCEDURE DrawMenuBar;
817 // DrawMenuBar redraws the menu bar according to the menu list, incorporating any changes since
818 // the last call to DrawMenuBar. This procedure should always be called after a sequence of
819 // InsertMenu or DeleteMenu calls, and after ClearMenuBar, SetMenuBar, or any other routine that
820 // changes the menu list.
821 void DrawMenuBar();
822
823 // PROCEDURE EnableItem(theMenu: MenuHandle; item: INTEGER);
824 // Given a menu item number in the item parameter, EnableItem enables the item (which may have
825 // been disabled with the Disableltem procedure, or with the "(" meta-character in the AppendMenu
826 // string).
827 void EnableItem(MenuHandle &theMenu, uint16 item);
828
829 // PROCEDURE GetItemMark(theMenu: MenuHandle, item: INTEGER, VAR markChar: CHAR);
830 // GetItemMark returns in markChar whatever character the given menu item is marked with, or the
831 // predefined constant noMark if no mark is present
832 void GetItemMark(MenuHandle &theMenu, uint16 item, uint8 &markChar);
833
834 // FUNCTION GetMHandle(menuID: INTEGER): MenuHandle;
835 // Given the menu ID of a menu currentiy installed in the menu list, GetMHandle returns a handle to
836 // that menu; given any other menu ID, it returns NIL.
837 MenuHandle GetMHandle(uint16 menuID);
838
839 // PROCEDURE HiliteMenu(menuID: INTEGER);
840 // HiliteMenu highlights the title of the given menu, or does nothing if the tide is already
841 // highlighted. Since only one menu tide can be highlighted at a time, it unhighlights any previously
842 // highlighted menu tide. If menuID is 0 (or isn't the ID of any menu in the menu list), HiliteMenu
843 // simply unhighlights whichever menu title is highlighted (if any).
844 void HiliteMenu(uint16 menuID);
845
846 uint32 MenuKey(char ch);
847
848 // FUNCTION MenuSelect(startPt: Point): LONGINT;
849 // When there's a mouse-down event in the menu bar, the application should call MenuSelect with
850 // startPt equal to the point (in global coordinates) where the mouse button was pressed.
851 // MenuSelect keeps control until the mouse button is released, tracking the mouse, pulling down
852 // menus as needed, and highlighting enabled menu items under the cursor. When the mouse button
853 // is released over an enabled item in an application menu, MenuSelect returns a long integer whose
854 // high-order word is the menu ED of the menu, and whose low-order word is the menu item
855 // number for the item chosen (see Figure 3). It leaves the selected menu tide highlighted. After
856 // performing the chosen task, your application should call HiliteMenu(O) to remove the
857 // highlighting from the menu title.
858 uint32 MenuSelect(const Common::Point &startPt);
859
860 // FUNCTION NewMenu(menuID: INTEGER; menuTitle: Str255): MenuHandle;
861 // NewMenu allocates space for a new menu with the given menu ID and tide, and returns a handle
862 // to it. It sets up the menu to use the standard menu definition procedure. (The menu definition
863 // procedure is read into memory if it isn't already in memory.) The new menu (which is created
864 // empty) is not installed in the menu list. To use this menu, you must first call AppendMenu or
865 // AddResMenu to fill it with items, InsertMenu to place it in the menu list, and DrawMenuBar to
866 // update the menu bar to include the new tide.
867 MenuHandle NewMenu(uint16 menuID, const Common::U32String &menuTitle);
868
869 // PROCEDURE SetItem(theMenu: MenuHandle; itemString: Str255);
870 // SetItem changes the text of the given menu item to itemString. It doesn't recognize the meta-
871 // characters used in AppendMenu; if you include them in itemString, they will appear in the text of
872 // the menu item. The attributes already in effect for this item—its character style, icon, and so
873 // on—remain in effect. ItemString may be blank but should not be the empty string.
874 void SetItem(MenuHandle &theMenu, uint16 item, const Common::U32String &itemString);
875
876 // PROCEDURE SetItemMark(theMenu: MenuHandle; item: INTEGER; markChar: CHAR);
877 // SetltemMark marks the given menu item in a more general manner than Checkltem. It allows you
878 // to place any character in the system font, not just the check mark, to the left of the item. The
879 // character is passed in the markChar parameter.
880 void SetItemMark(MenuHandle &theMenu, uint16 item, uint8 markChar);
881
882 // toolbox_pict.cpp
883
884 // PROCEDURE ClosePicture;
885 // The ClosePicture procedure stops collecting drawing commands and picture
886 // comments for the currently open picture. You should perform one and only one call to
887 // ClosePicture for every call to the OpenCPicture (or OpenPicture) function.
888 void ClosePicture();
889
890 // PROCEDURE DrawPicture (myPicture: PicHandle; dstRect: Rect);
891 // Within the rectangle that you specify in the dstRect parameter, the DrawPicture
892 // procedure draws the picture that you specify in the myPicture parameter.
893 void DrawPicture(PicHandle &myPicture, const Common::Rect &dstRect);
894
895 // FUNCTION GetPicture (picID: INTEGER) : PicHandle;
896 // GetPicture returns a handle to the picture having the given resource ID, reading it from the
897 // resource file if necessary. It calls the Resource Manager function GetResource('PICT',picID). If
898 // the resource can't be read, GetPicture returns NIL. The PicHandle data type is defined in
899 // QuickDraw.
900 PicHandle GetPicture(uint16 picID);
901
902 // PROCEDURE KillPicture(myPicture: PicHandle);
903 // The KillPicture procedure releases the memory occupied by the picture whose
904 // handle you pass in the myPicture parameter. Use this only when you’re completely
905 // finished with a picture.
906 void KillPicture(PicHandle &myPicture);
907
908 // FUNCTION OpenPicture (picFrame: Rect): PicHandle;
909 // OpenPicture returns a handle to a new picture that has the given rectangle as its picture frame, and
910 // tells QuickDraw to start saving as the picture definition all calls to drawing routines and all picture
911 // comments (if any).
912 PicHandle OpenPicture(const Common::Rect &picFame);
913
914 // toolbox_quickdraw.cpp
915
916 // PROCEDURE BackPat (pat: Pattern);
917 // The BackPat procedure sets the bit pattern defined in the Pattern record, which you
918 // specify in the pat parameter, to be the background pattern. (The standard bit patterns
919 // white, black, gray, ltGray, and dkGray are predefined; the initial background
920 // pattern for the graphics port is white.) This pattern is stored in the bkPat field of a
921 // GrafPort record.
922 void BackPat(const Pattern &pat);
923
924 // PROCEDURE BeginUpdate (theWindow: WindowPtr);
925 // Call BeginUpdate when an update event occurs for theWindow. BeginUpdate replaces the
926 // visRgn of the window's grafPort with the intersection of the visRgn and the update region and
927 // then sets the window's update region to an empty region. You would then usually draw the
928 // entire content region, though it suffices to draw only the visRgn; in either case, only the parts of
929 // the window that require updating will actually be drawn on the screen. Every call to
930 // BeginUpdate must be balanced by a call to EndUpdate.
931 void BeginUpdate(WindowRecord &theWindow);
932
933 // PROCEDURE ClipRect (r: Rect);
934 // ClipRect changes the clipping region of the current grafPort to a rectangle that's equivalent to the
935 // given rectangle. Note that this doesn't change the region handle, but affects the clipping region
936 // itself.
937 void ClipRect(Common::Rect &r);
938
939 // PROCEDURE ClosePoly;
940 // ClosePoly tells QuickDraw to stop saving the definition of the currently open polygon and computes
941 // the polyBBox rectangle. You should perform one and only one ClosePoly for every OpenPoly.
942 // ClosePoly calls ShowPen, balancing the HidePen call made by OpenPoly.
943 void ClosePoly();
944
945 // PROCEDURE CopyBits (srcBits,dstBits: BitMap; srcRect,dstRect: Rect; mode: INTEGER; maskRgn: RgnHandle);
946 // CopyBits transfers a bit image between any two bit maps and clips the result to the area specified
947 // by the maskRgn parameter. The transfer may be performed in any of the eight source transfer
948 // modes. The result is always clipped to the maskRgn and the boundary rectangle of the
949 // destination bit map; if the destination bit map is the current grafPort's portBits, it's also clipped to
950 // the intersection of the grafPort's clipRgn and visRgn. If you don't want to clip to a maskRgn,
951 // just pass NIL for the maskRgn parameter. The dstRect and maskRgn coordinates are in terms of
952 // the dstBits.bounds coordinate system, and the srcRect coordinates are in terms of the
953 // srcBits.bounds coordinates.
954 void CopyBits(const BitMap &srcBits, BitMap &dstBits, const Common::Rect &srcRect, const Common::Rect &dstRect, SourceMode mode, RgnHandle maskRgn);
955
956 // PROCEDURE EraseOval (r: Rect);
957 // Using the background pattern for the current graphics port and the patCopy pattern
958 // mode, the EraseOval procedure draws the interior of an oval just inside the bounding
959 // rectangle that you specify in the r parameter. This effectively erases the oval bounded by
960 // the specified rectangle.
961 void EraseOval(const Common::Rect &r);
962
963 // PROCEDURE ErasePoly (poly: PolyHandle);
964 // Using the patCopy pattern mode, the ErasePoly procedure draws the interior of the
965 // polygon whose handle you pass in the poly parameter with the background pattern for
966 // the current graphics port.
967 void ErasePoly(const PolyHandle &poly);
968
969 // PROCEDURE EraseRect (r: Rect);
970 // Using the patCopy pattern mode, the EraseRect procedure draws the interior of the
971 // rectangle that you specify in the r parameter with the background pattern for the current
972 // graphics port. This effectively erases the rectangle specified in the r parameter. For
973 // example, you can use EraseRect to erase the port rectangle for a window before
974 // redrawing into the window.
975 void EraseRect(const Common::Rect &r);
976
977 // PROCEDURE EraseRoundRect (r: Rect; ovalWidth,ovalHeight: Integer);
978 // Using the patCopy pattern mode, the EraseRoundRect procedure draws the interior of
979 // the rounded rectangle bounded by the rectangle that you specify in the r parameter with
980 // the background pattern of the current graphics port. This effectively erases the rounded
981 // rectangle. Use the ovalWidth and ovalHeight parameters to specify the diameters of
982 // curvature for the corners of the rounded rectangle.
983 void EraseRoundRect(const Common::Rect &r, uint16 ovalWidth, uint16 ovalHeight);
984
985 // PROCEDURE EndUpdate (theWindow: WindowPtr);
986 // Call EndUpdate to restore the normal visRgn of theWindow's grafPort, which was changed by
987 // BeginUpdate as described above.
988 void EndUpdate(WindowRecord &theWindow);
989
990 // PROCEDURE FillOval (r: Rect; pat: Pattern);
991 // FillOval fills an oval just inside the specified rectangle with the given pattern (in patCopy mode).
992 // The grafPort's pnPat, pnMode, and bkPat are all ignored; the pen location is not changed.
993 void FillOval(const Common::Rect &r, const Pattern &pat);
994
995 // PROCEDURE FillPoly (poly: PolyHandle; pat: Pattern);
996 // Using the patCopy pattern mode, the FillPoly procedure draws the interior of the
997 // polygon whose handle you pass in the poly parameter with the pattern defined in the
998 // Pattern record that you specify in the pat parameter.
999 void FillPoly(const PolyHandle &poly, const Pattern &pat);
1000
1001 // PROCEDURE FillRect (r: Rect; pat: Pattern);
1002 // FillRect fills the specified rectangle with the given pattern (in patCopy mode). The grafPort's
1003 // pnPat, pnMode, and bkPat are all ignored; the pen location is not changed.
1004 void FillRect(const Common::Rect &r, const Pattern &pat);
1005
1006 // PROCEDURE FillRoundRect (r: Rect; ovalWidth, ovalHeight: INTEGER, pat: Pattern);
1007 // FillRoundRect fills the specified rounded-comer rectangle with the given pattern (in patCopy
1008 // mode). OvalWidth and ovalHeight specify the diameters of curvature for the corners. The
1009 // grafPort's pnPat, pnMode, and bkPat are all ignored; the pen location is not changed.
1010 void FillRoundRect(const Common::Rect &r, uint16 ovalWidth, uint16 ovalHeight, const Pattern &pat);
1011
1012 // PROCEDURE FrameArc (r: Rect; startAngle,arcAngle: INTEGER);
1013 // FrameArc draws an arc of the oval that fits inside the specified rectangle, using the current
1014 // grafPort's pen pattern, mode, and size. StartAngle indicates where the arc begins and is treated
1015 // MOD 360. ArcAngle defines the extent of the arc. The angles are given in positive or negative
1016 // degrees; a positive angle goes clockwise, while a negative angle goes counterclockwise.
1017 void FrameArc(const Common::Rect &r, int16 startAngle, int16 arcAngle);
1018
1019 // PROCEDURE FrameOval (r: Rect);
1020 // FrameOval draws an outline just inside the oval that fits inside the specified rectangle, using the
1021 // current grafPort's pen pattern, mode, and size. The outline is as wide as the pen width and as tall
1022 // as the pen height. It's drawn with the pnPat, according to the pattern transfer mode specified by
1023 // pnMode. The pen location is not changed by this procedure.
1024 void FrameOval(const Common::Rect &r);
1025
1026 // PROCEDURE FramePoly (poly: PolyHandle);
1027 // Using the current graphics port’s pen pattern, pattern mode, and size, the FramePoly
1028 // procedure plays back the line-drawing commands that define the polygon whose handle
1029 // you pass in the poly parameter.
1030 void FramePoly(const PolyHandle &poly);
1031
1032 // PROCEDURE FrameRect (r: Rect);
1033 // FrameRect draws an outline just inside the specified rectangle, using the current grafPort's pen
1034 // pattern, mode, and size. The outline is as wide as the pen width and as tall as the pen height. It's
1035 // drawn with the pnPat, according to the pattern transfer mode specified by pnMode. The pen
1036 // location is not changed by this procedure.
1037 void FrameRect(const Common::Rect &r);
1038
1039 // PROCEDURE FrameRoundRect (r: Rect; ovalWidth,ovalHeight: Integer);
1040 // Using the pattern, pattern mode, and size of the graphics pen for the current graphics
1041 // port, the FrameRoundRect procedure draws an outline just inside the rounded
1042 // rectangle bounded by the rectangle that you specify in the r parameter. The outline is as
1043 // wide as the pen width and as tall as the pen height. The pen location does not change.
1044 void FrameRoundRect(const Common::Rect &r, uint16 ovalWidth, uint16 ovalHeight);
1045
1046 // PROCEDURE GetCPixel (h,v: INTEGER; VAR cPix: RGBColor);
1047 // The GetCPixel function returns the RGB of the pixel at the specified position in the current
1048 // port.
1049 void GetCPixel(int16 h, int16 v, RGBColor &cPix);
1050
1051 // FUNCTION GetIcon(iconID: INTEGER): Handle;
1052 // GetIcon returns a handle to the icon having the given resource ID, reading it from the resource file
1053 // if necessary. It calls the Resource Manager function GetResource('ICON ,iconID). If the
1054 // resource can't be read, GetIcon returns NIL.
1055 Handle GetIcon(uint16 iconID);
1056
1057 // PROCEDURE GetPort (VAR port: GrafPtr);
1058 // The GetPort procedure returns a pointer to the current graphics port in the port
1059 // parameter. The current graphics port is also available through the global variable
1060 // thePort, but you may prefer to use GetPort for better readability of your code. For
1061 // example, your program could include GetPort(savePort) before setting a new
1062 // graphics port, followed by SetPort(savePort) to restore the previous port.
1063 void GetPort(GrafPtr &port);
1064
1065 // PROCEDURE GlobalToLocal (VAR pt: Point);
1066 // GlobalToLocal takes a point expressed in global coordinates (with the top left corner of the bit
1067 // image as coordinate (0,0)) and converts it into the local coordinates of the current grafPort. The
1068 // global point can be obtained with the LocalToGlobal call (see above).
1069 void GlobalToLocal(Common::Point &pt);
1070
1071 // PROCEDURE HideCursor;
1072 // HideCursor removes the cursor from the screen, restoring the bits under it, and decrements the
1073 // cursor level (which InitCursor initialized to 0). Every call to HideCursor should be balanced by a
1074 // subsequent call to ShowCursor.
1075 void HideCursor();
1076
1077 // PROCEDURE HidePen;
1078 // HidePen decrements the current grafPort's pnVis field, which is initialized to 0 by OpenPort;
1079 // whenever pnVis is negative, the pen doesn't draw on the screen. PnVis keeps track of the
1080 // number of times the pen has been hidden to compensate for nested calls to HidePen and ShowPen
1081 // (below). Every call to HidePen should be balanced by a subsequent call to ShowPen. HidePen
1082 // is called by OpenRgn, OpenPicture, and OpenPoly so that you can define regions, pictures, and
1083 // polygons without drawing on the screen.
1084 void HidePen();
1085
1086 // PROCEDURE InitCursor;
1087 // InitCursor sets the current cursor to the standard arrow and sets the cursor level to 0, making
1088 // the cursor visible. The cursor level keeps track of the number of times the cursor has been
1089 // hidden to compensate for nested calls to HideCursor and ShowCursor, explained below.
1090 void InitCursor();
1091
1092 // PROCEDURE InsetRect (VAR r: Rect; dh,dv: INTEGER);
1093 // InsetRect shrinks or expands the given rectangle. The left and right sides are moved in by the
1094 // amount specified by dh; the top and bottom are moved toward the center by the amount specified
1095 // by dv. If dh or dv is negative, the appropriate pair of sides is moved outward instead of inward.
1096 // The effect is to alter the size by 2*dh horizontally and 2*dv vertically, with the rectangle
1097 // remaining centered in the same place on the coordinate plane.
1098 void InsetRect(Common::Rect &r, int16 dh, int16 dv);
1099
1100 // PROCEDURE InvertOval (r: Rect);
1101 // InvertOval inverts the pixels enclosed by an oval just inside the specified rectangle: Every white
1102 // pixel becomes black and every black pixel becomes white. The grafPort's pnPat, pnMode, and
1103 // bkPat are all ignored; the pen location is not changed.
1104 void InvertOval(const Common::Rect &r);
1105
1106 // PROCEDURE InvertPoly (poly: PolyHandle);
1107 // The InvertPoly procedure inverts the pixels enclosed by the polygon whose handle
1108 // you pass in the poly parameter. Every white pixel becomes black and every black pixel
1109 // becomes white.
1110 void InvertPoly(const PolyHandle &poly);
1111
1112 // PROCEDURE InvertRect (r: Rect);
1113 // InvertRect inverts the pixels enclosed by the specified rectangle: Every white pixel becomes
1114 // black and every black pixel becomes white. The grafPort's pnPat, pnMode, and bkPat are all
1115 // ignored; the pen location is not changed.
1116 void InvertRect(const Common::Rect &r);
1117
1118 // PROCEDURE InvertRoundRect (r: Rect; ovalWidth, ovalHeight: Integer);
1119 // The InvertRoundRect procedure inverts the pixels enclosed by the rounded rectangle
1120 // bounded by the rectangle that you specify in the r parameter. Every white pixel becomes
1121 // black and every black pixel becomes white. The ovalWidth and ovalHeight
1122 // parameters specify the diameters of curvature for the corners. The pen location does not
1123 // change.
1124 void InvertRoundRect(const Common::Rect &r, uint16 ovalWidth, uint16 ovalHeight);
1125
1126 // PROCEDURE KillPoly (poly: PolyHandle);
1127 // KillPoly releases the memory occupied by the given polygon. Use this only when you're completely
1128 // through with a polygon.
1129 void KillPoly(PolyHandle &poly);
1130
1131 // PROCEDURE Line(dh, dv: INTEGER);
1132 // This procedure draws a line to the location that's a distance of dh horizontally and dv vertically
1133 // from the current pen location; it calls LineTo(h+dh,v+dv), where (h,v) is the current location.
1134 // The positive directions are to the right and down. The pen location becomes the coordinates of
1135 // the end of the line after the line is drawn. See the "General Discussion of Drawing" section.
1136 void Line(int16 dh, int16 dv);
1137
1138 // PROCEDURE LineTo (h,v: INTEGER);
1139 // LineTo draws a line from the current pen location to the location specified (in local coordinates)
1140 // by h and v. The new pen location is (h,v) after the line is drawn.
1141 void LineTo(int16 h, int16 v);
1142
1143 // PROCEDURE LocalToGlobal (VAR pt: Point);
1144 // LocalToGlobal converts the given point from the current grafPort's local coordinate system into a
1145 // global coordinate system with the origin (0,0) at the top left corner of the port's bit image (such
1146 // as the screen). This global point can then be compared to other global points, or be changed into
1147 // the local coordinates of another grafPort.
1148 void LocalToGlobal(Common::Point &pt);
1149
1150 // PROCEDURE Move (dh,dv: INTEGER);
1151 // The Move procedure moves the graphics pen from its current location in the current
1152 // graphics port a horizontal distance that you specify in the dh parameter and a vertical
1153 // distance that you specify in the dv parameter.
1154 void Move(int16 dh, int16 dv);
1155
1156 // PROCEDURE MovePortTo (leftGlobal,topGlobal: INTEGER);
1157 // MovePortTo changes the position of the current grafPort's portRect. This does not affect the
1158 // screen; it merely changes the location at which subsequent drawing inside the port will appear.
1159 void MovePortTo(int16 leftGlobal, int16 topGlobal);
1160
1161 // PROCEDURE MoveTo (h,v: INTEGER);
1162 // MoveTo moves the pen to location (h,v) in the local coordinates of the current grafPort. No
1163 // drawing is performed.
1164 void MoveTo(int16 h, int16 v);
1165
1166 void OffsetRect(Common::Rect &r, int16 dh, int16 dv);
1167
1168 // FUNCTION OpenPoly : PolyHandle;
1169 // OpenPoly returns a handle to a new polygon and tells QuickDraw to start saving the polygon
1170 // definition as specified by calls to line-drawing routines. While a polygon is open, all calls to Line
1171 // and LineTo affect the outline of the polygon. Only the line endpoints affect the polygon
1172 // definition; the pen mode, pattern, and size do not affect it. In fact, OpenPoly calls HidePen, so
1173 // no drawing occurs on the screen while the polygon is open (unless you call ShowPen just after
1174 // OpenPoly, or you called ShowPen previously without balancing it by a call to HidePen).
1175 PolyHandle OpenPoly();
1176
1177 // PROCEDURE OpenPort (port: GrafPtr);
1178 // OpenPort allocates space for the given grafPort's visRgn and clipRgn, initializes the fields of the
1179 // grafPort as indicated below, and makes the grafPort the current port (by calling SetPort).
1180 // OpenPort is called by the Window Manager when you create a window, and you normally won't
1181 // call it yourself. If you do call OpenPort, you can create the grafPtr with the Memory Manager
1182 // procedure NewPtr or reserve the space on the stack (with a variable of type GrafPort).
1183 void OpenPort(GrafPtr port);
1184
1185 // PROCEDURE PaintOval (r: Rect);
1186 // PaintOval paints an oval just inside the specified rectangle with the current grafPort's pen pattern
1187 // and mode. The oval is filled with the pnPat, according to the pattern transfer mode specified by
1188 // pnMode. The pen location is not changed by this procedure.
1189 void PaintOval(const Common::Rect &r);
1190
1191 // PROCEDURE PaintPoly (poly: PolyHandle);
1192 // PaintPoly paints the specified polygon with the current grafPort's pen pattern and pen mode. The
1193 // polygon is filled with the pnPat, according to the pattern transfer mode specified by pnMode.
1194 // The pen location is not changed by this procedure.
1195 void PaintPoly(const PolyHandle &poly);
1196
1197 // PROCEDURE PaintRect (r: Rect);
1198 // PaintRect paints the specified rectangle with the current grafPoit's pen pattern and mode. The
1199 // rectangle is filled with the pnPat, according to the pattern transfer mode specified by pnMode.
1200 // The pen location is not changed by this procedure.
1201 void PaintRect(const Common::Rect &r);
1202
1203 // PROCEDURE PaintRoundRect (r: Rect; ovalWidth,ovalHeight: Integer);
1204 // Using the pattern and pattern mode of the graphics pen for the current graphics port, the
1205 // PaintRoundRect procedure draws the interior of the rounded rectangle bounded by
1206 // the rectangle that you specify in the r parameter. Use the ovalWidth and ovalHeight
1207 // parameters to specify the diameters of curvature for the corners of the rounded rectangle.
1208 void PaintRoundRect(const Common::Rect &r, uint16 ovalWidth, uint16 ovalHeight);
1209
1210 // PROCEDURE PenMode (mode: INTEGER);
1211 // PenMode sets the transfer mode through which the pen pattern is transferred onto the bit map
1212 // when lines or shapes are drawn in the current grafPort.
1213 void PenMode(PatternMode mode);
1214
1215 // PROCEDURE PenNormal;
1216 // PenNormal resets the initial state of the pen in the current grafPort.
1217 void PenNormal();
1218
1219 // PROCEDURE PenPat (pat: Pattern);
1220 // PenPat sets the pattern that's used by the pen in the current grafPort. The standard patterns
1221 // white, black, gray, ltGray, and dkGray are predefined; the initial pen pattern is black. The
1222 // current pen pattern can be accessed in the variable thePort .pnPat, and this value can be assigned
1223 // to any other variable of type Pattern.
1224 void PenPat(const Pattern &pat);
1225
1226 // PROCEDURE PenSize (width,height: INTEGER);
1227 // PenSize sets the dimensions of the graphics pen in the current grafPort. All subsequent calls to
1228 // Line, LineTo, and the procedures that draw framed shapes in the current grafPort will use the
1229 // new pen dimensions.
1230 void PenSize(uint16 width, uint16 height);
1231
1232 // PROCEDURE PlotIcon (theRect: Rect; theIcon: Handle);
1233 // Plotlcon draws the icon whose handle is thelcon in the rectangle theRect, which is in the local
1234 // coordinates of the current grafPort. It calls the QuickDraw procedure CopyBits and uses the
1235 // srcCopy transfer mode.
1236 void PlotIcon(const Common::Rect &theRect, const Handle &theIcon);
1237
1238 // PROCEDURE PortSize (width,height: INTEGER);
1239 // PortSize changes the size of the current grafPort's portRect. This does not affect the screen; it
1240 // merely changes the size of the "active area" of the grafPort.
1241 void PortSize(uint16 width, uint16 height);
1242
1243 // FUNCTION PtInRect (pt: Point; r: Rect): Boolean;
1244 // The PtInRect function determines whether the pixel below and to the right of the point
1245 // you specify in the pt parameter is enclosed in the rectangle that you specify in the Rect
1246 // parameter. The PtInRect function returns TRUE if it is, FALSE if it is not.
1247 bool PtInRect(const Common::Point &pt, const Common::Rect &r);
1248
1249 // PROCEDURE SetCPixel (h,v: INTEGER; cPix: RGBColor);
1250 // The SetCPixel function sets the pixel at the specified position to the pixel value that most
1251 // closely matches the specified RGB.
1252 void SetCPixel(int16 h, int16 v, const RGBColor &cPix);
1253
1254 void SetCursor(const Common::SharedPtr<Cursor> &crsr);
1255
1256 // PROCEDURE SetOrigin(h, v: Integer);
1257 // The SetOrigin procedure changes the coordinates of the upper-left corner of the
1258 // current graphics port’s port rectangle to the values supplied by the h and v parameters.
1259 // All other points in the current graphics port’s local coordinate system are calculated from
1260 // this point. All subsequent drawing and calculation routines use the new coordinate
1261 // system.
1262 void SetOrigin(int16 h, int16 v);
1263
1264 // PROCEDURE SetPort (port: GrafPtr);
1265 // SetPort makes the specified grafPort the current port.
1266 void SetPort(GrafPtr port);
1267
1268 // PROCEDURE SetPortBits (bm: BitMap);
1269 // SetPortBits sets the portBits field of the current grafPort to any previously defined bit map. This
1270 // allows you to perform all normal drawing and calculations on a buffer other than the screen—for
1271 // example, a small off-screen image for later "stamping" onto the screen (with the CopyBits
1272 // procedure, described under "Bit Transfer Operations" below).
1273 void SetPortBits(BitMap &bm);
1274
1275 // PROCEDURE SetRect (VAR r: Rect; left,top,right,bottom: INTEGER);
1276 // SetRect assigns the four boundary coordinates to the given rectangle. The result is a rectangle
1277 // with coordinates (left,top) (right,bottom).
1278 void SetRect(Common::Rect &r, int16 left, int16 top, int16 right, int16 bottom);
1279
1280 // PROCEDURE ShowCursor;
1281 // ShowCursor increments the cursor level, which may have been decremented by HideCursor, and
1282 // displays the cursor on the screen if the level becomes 0. A call to ShowCursor should balance
1283 // each previous call to HideCursor. The level isn't incremented beyond 0, so extra calls to
1284 // ShowCursor have no effect.
1285 void ShowCursor();
1286
1287 // PROCEDURE ShowPen;
1288 // ShowPen increments the current grafPort's pnVis field, which may have been decremented by
1289 // HidePen; if pnVis becomes 0, QuickDraw resumes drawing on the screen. Extra calls to
1290 // ShowPen will increment pnVis beyond 0, so every call to ShowPen should be balanced by a call
1291 // to HidePen. ShowPen is called by CloseRgn, ClosePicture, and ClosePoly.
1292 void ShowPen();
1293
1294 // toolbox_text.cpp
1295
1296 // PROCEDURE DrawChar (ch: CHAR);
1297 // DrawChar places the given character to the right of the pen location, with the left end of its base
1298 // line at the pen's location, and advances the pen accordingly. If the character isn't in the font, the
1299 // font's missing symbol is drawn.
1300 void DrawChar(Common::u32char_type_t ch);
1301
1302 // PROCEDURE DrawString (s: Str255);
1303 // DrawString calls DrawChar for each character in the given string. The string is placed beginning
1304 // at the current pen location and extending right. No formatting (such as carriage returns and line
1305 // feeds) is performed by QuickDraw. The pen location ends up to the right of the last character in
1306 // the string.
1307 void DrawString(const Common::U32String &s);
1308
1309 // PROCEDURE StringWidth (s: Str255) : INTEGER;
1310 // StringWidth returns the width of the given text string, which it calculates by adding the
1311 // CharWidths of all the characters in the string (see above).
1312 uint16 StringWidth(const Common::U32String &s);
1313
1314 // PROCEDURE TextFace (face: Style);
1315 // The TextFace procedure sets the style of the font in which the text is to be drawn in the
1316 // current graphics port.
1317 void TextFace(uint16 style);
1318
1319 // PROCEDURE TextFont (font: Integer);
1320 // The TextFont procedure sets the font of the current graphics port in which the text is
1321 // to be rendered.
1322 void TextFont(uint16 font);
1323
1324 // PROCEDURE TextMode (mode: Integer);
1325 // The TextMode procedure sets the transfer mode for drawing text in the current
1326 // graphics port.
1327 void TextMode(SourceMode mode);
1328
1329 // PROCEDURE TextSize (size: Integer);
1330 // The TextSize procedure sets the font size for text drawn in the current graphics port to
1331 // the specified number of points.
1332 void TextSize(uint16 size);
1333
1334 void _injectFOND(int16 resID, const byte *data, const size_t size, const Common::String &name);
1335
1336 void _loadFonts(int16 resID);
1337
1338 void _setFileModalCallback(FileModalCallback callback) { _fileModalCallback = callback; }
1339
1340private:
1342
1344 Common::Array<int16> _resOrder;
1345 int16 _nextResId = 1;
1346 size_t _resIndexStart = 0;
1349 Graphics::FrameLimiter *_frameLimiter = nullptr;
1352 int _cursorLevel = 0;
1353 Common::Point _mouse;
1354 uint16 _modifiers = 0x80;
1356 Audio::SoundHandle _soundDriver;
1357 Audio::PCSpeakerStream *_swSynth;
1358
1360
1361 GrafPtr _port = nullptr;
1362
1363 FileModalCallback _fileModalCallback;
1364
1365 void _pumpEvents();
1366 void _updateScreen();
1367 void _drawOval(const Common::Rect &r, const Pattern &pat, PatternMode mode, bool frame, uint32 fgColor, uint32 bkColor);
1368 void _drawPoly(const PolyHandle &p, const Pattern &pat, PatternMode mode, bool frame, uint32 fgColor, uint32 bkColor);
1369 void _drawRect(const Common::Rect &r, const Pattern &pat, PatternMode mode, bool frame, uint32 fgColor, uint32 bkColor);
1370 void _drawRoundRect(const Common::Rect &r, const Pattern &pat, PatternMode mode, bool frame, uint32 fgColor, uint32 bkColor, uint16 ovalWidth, uint16 ovalHeight);
1371 void _drawBitsRect(Common::SeekableReadStream &stream, const Common::Rect &picFrame, bool compressed);
1372 void _copyBits(const BitMap &srcBits, const BitMap &mask, BitMap &dstBits, const Common::Rect &srcRect, const Common::Rect &dstRect, SourceMode mode, RgnHandle maskRgn);
1373 void _addDirtyRect(const BitMap &dest, const Common::Rect &rect);
1374};
1375
1376} // namespace MacToolbox
1377} // namespace Graphics
1378
1379#endif
Definition: pcspk.h:88
Definition: mixer.h:49
Definition: array.h:52
void push_back(const T &element)
Definition: array.h:181
Definition: hashmap.h:85
Definition: list.h:44
Definition: path.h:52
Definition: stream.h:745
PointerType get() const
Definition: ptr.h:229
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: ustr.h:57
Definition: cursor.h:42
Definition: framelimiter.h:40
Definition: macmenu.h:95
Definition: toolbox.h:313
virtual byte getKeyColor() const
Definition: toolbox.h:332
virtual uint16 getPaletteCount() const
Definition: toolbox.h:337
virtual byte getPaletteStartIndex() const
Definition: toolbox.h:336
virtual uint16 getHeight() const
Definition: toolbox.h:329
virtual uint16 getHotspotX() const
Definition: toolbox.h:330
virtual uint16 getHotspotY() const
Definition: toolbox.h:331
virtual const byte * getMask() const
Definition: toolbox.h:334
virtual const byte * getSurface() const
Definition: toolbox.h:333
virtual uint16 getWidth() const
Definition: toolbox.h:328
virtual const byte * getPalette() const
Definition: toolbox.h:335
Definition: toolbox.h:573
Definition: macwindow.h:205
Definition: macwindowmanager.h:149
@ kCursorMaskOpaque
Definition: system.h:129
@ kCursorMaskTransparent
Definition: system.h:126
char32_t u32char_type_t
Definition: ustr.h:55
Definition: system.h:39
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: func.h:527
Definition: macresman.h:77
T y
Definition: rect.h:49
T x
Definition: rect.h:48
Definition: rect.h:144
Definition: rect.h:536
Definition: toolbox.h:54
Definition: toolbox.h:59
Definition: toolbox.h:486
Definition: toolbox.h:503
Definition: toolbox.h:452
Definition: toolbox.h:510
Definition: toolbox.h:522
Definition: toolbox.h:98
Definition: toolbox.h:242
Definition: toolbox.h:72
Definition: toolbox.h:91
Definition: toolbox.h:48
Definition: toolbox.h:66
Definition: toolbox.h:537
Definition: toolbox.h:533
Definition: toolbox.h:563
Definition: toolbox.h:558
Definition: toolbox.h:552
Definition: toolbox.h:495
Definition: toolbox.h:481