a2d/MGTK.md

269 lines
7.8 KiB
Markdown
Raw Normal View History

2018-01-29 05:18:00 +00:00
# MGTK API
2017-09-22 16:00:30 +00:00
2018-02-19 19:33:13 +00:00
This is a complex API library written by Apple circa 1985. It consists of:
2017-09-22 16:00:30 +00:00
2018-02-19 19:33:13 +00:00
* Graphics Primitives - screen management, lines, rects, polys, text, patterns, pens
* Mouse Graphics - windows, menus, events, cursors
2017-09-22 16:00:30 +00:00
2018-02-19 19:33:13 +00:00
For the purposes of DeskTop, the entry point is fixed at $4000 AUX, called MLI-style (JSR followed by command type and address of param block).
2017-09-22 16:00:30 +00:00
2018-02-19 21:29:57 +00:00
---
2017-09-22 16:00:30 +00:00
2018-02-19 21:29:57 +00:00
# Graphics Primitives
2017-09-22 16:00:30 +00:00
2018-02-19 21:29:57 +00:00
## Concepts
2017-09-22 16:00:30 +00:00
2018-02-19 21:29:57 +00:00
ca65 syntax is used for primitives: `.byte`, `.word` (interpreted as 16-bit signed integer), `.addr` (16-bit address), `.res N` (N byte buffer)
### Point
2017-09-22 16:00:30 +00:00
```
2018-02-19 21:29:57 +00:00
.word xcoord
.word ycoord
2017-09-22 16:00:30 +00:00
```
2018-02-19 21:29:57 +00:00
### Rect
```
.word x1
.word y1
.word x2
.word y3
```
2017-09-22 16:00:30 +00:00
2018-02-19 21:29:57 +00:00
### Pattern
2017-09-22 16:00:30 +00:00
A simple repeating 8x8 _pattern_ is defined by 8 bytes. All bits of each byte are used.
2018-02-19 21:29:57 +00:00
### MapInfo
Used with GrafPorts to define offsets/clipping, and bitmaps for source data.
```
Point viewloc
.addr mapbits $2000 for the screen, or bitmap bits
.byte mapwidth $80, or stride for bitmap
.byte reserved
Rect maprect a.k.a. cliprect
```
### GrafPort
There is always a current GrafPort (or "port" for short) that defines
the destination and pen state of drawing operations.
```
MapInfo portmap
.res 8 penpattern
.byte colormask_and
.byte colormask_or
Point penloc
.byte penwidth horizontal pen thickness
.byte penheight vertical pen thickness
.byte penmode
.byte textback text background
.addr textfont
```
### PolyList
```
.byte count number of vertices in this polygon
.byte last high bit set if there are more polygons
Point vertex0
... repeats for each vertex
... repeats for each polygon
```
### Font
```
.byte fonttype 0=regular, $80=double-width
.byte lastchar char code of last character (usually $7F)
.byte height pixels (1-16)
.res N charwidth pixels, for each char
.res N row0 bits
.res N row0right bits (double-width only)
... repeats for each row
```
## Commands
Includes:
* Initialization
* GrafPort - assign, update, query ports
* Drawing - draw lines; frame, fill, and test rects and polys
* Text - draw and measure text
* Utility - configuration and version
---
# Mouse Graphics
Includes:
## Concepts
### Cursor
```
.res 24 bitmap 2x12 byte bitmap (XOR'd after mask)
.res 24 mask 2x12 byte mask (OR'd with screen)
.byte hotx hotspot coords (pixels)
.byte hoty
```
### Event
```
.byte kind event_kind_*
.res 4
```
if `kind` is `event_kind_key_down`:
```
.byte kind event_kind_*
.byte key (ASCII code; high bit clear)
.byte modifiers (0=none, 1=open-apple, 2=solid-apple, 3=both)
.res 2 reserved
```
if `kind` is `event_kind_update:`
```
.byte kind event_kind_*
.byte window_id
.res 3 reserved
```
otherwise:
```
.byte kind event_kind_*
.word mousex
.word mousey
```
2018-02-20 03:21:10 +00:00
```
event_kind_no_event := 0 ; No mouse or keypress
event_kind_button_down := 1 ; Mouse button was depressed
event_kind_button_up := 2 ; Mouse button was released
event_kind_key_down := 3 ; Key was pressed
event_kind_drag := 4 ; Mouse button still down
event_kind_apple_key := 5 ; Mouse button was depressed, modifier key down
event_kind_update := 6 ; Window update needed
event_modifier_open_apple := 1 << 0
event_modifier_solid_apple := 1 << 1
```
2018-02-19 21:29:57 +00:00
### Menu
Menu Bar record:
```
.word count Number of menu bar items
.byte menu_id Menu identifier
.byte disabled Flag
.addr title Address of length-prefixed string
.addr menu Address of Menu record
.res 6 reserved Reserved
... repeats for each menu
```
Menu record:
```
.word count Number of items in menu
.res 5 reserved Reserved
.byte options bit 0=OA, 1=SA, 2=mark, 5=check, 6=filler, 7=disabled
.byte mark_char Custom mark character if mark option set
.byte char1 ASCII code of shortcut #1 (e.g. uppercase B); or 0
.byte char2 ASCII code of shortcut #2 (e.g. lowercase b, or same); or 0
.addr name Address of length-prefixed string
... repeats for each menu item
```
### Window "winfo"
```
.byte id
.byte options option_*
.addr title
.byte hscroll scroll_option_*
.byte vscroll scroll_option_*
.byte hthumbmax
.byte hthumbpos
.byte vthumbmax
.byte vthumbpos
.byte status
.byte reserved
.word mincontwidth minimum content size (horizontal)
.word maxcontwidth maximum content size (horizontal)
.word mincontlength minimum content size (vertical)
.word maxcontlength maximum content size (vertical)
GrafPort windowport GrafPort record
.addr nextwinfo address of next lower window in stack
```
2017-09-22 16:00:30 +00:00
2018-02-19 19:33:13 +00:00
Windows have a _content area_ which has the requested dimensions. Above this is an optional
_title bar_ which in turn has an optional _close box_. Within the content area are an
2017-09-22 16:00:30 +00:00
optional _resize box_ and optional _scroll bars_.
2018-02-20 03:21:10 +00:00
```
option_dialog_box := 1 << 0
option_go_away_box := 1 << 1
option_grow_box := 1 << 2
scroll_option_none := 0
scroll_option_present := 1 << 7
scroll_option_thumb := 1 << 6
scroll_option_active := 1 << 0
scroll_option_normal := scroll_option_present | scroll_option_thumb | scroll_option_active
```
2018-02-19 21:29:57 +00:00
## Commands
Includes:
* Initialization
* Cursor Manager - set, show, hide
* Event Manager - get, peek, post
* Menu Manager - configure, enable, disable, select
* Window Manager - open, close, drag, grow, update
* Control Manager - scrollbars
## More
2017-09-22 16:33:49 +00:00
> NOTE: Movable windows must maintain an _offscreen_flag_. If a window is moved so that the
2018-02-19 19:33:13 +00:00
> content area is entirely offscreen then various operations should be skipped because
2017-09-22 16:33:49 +00:00
> the window's box coordinates will not be set correctly.
2018-02-20 03:21:10 +00:00
### Use by DAs
2017-09-24 23:20:32 +00:00
#### Input Loop
2017-09-22 16:33:49 +00:00
2018-02-20 03:21:10 +00:00
* Call `GetEvent`.
2018-02-05 05:05:31 +00:00
* If a key, then check modifiers (Open/Solid Apple) and key code, ignore or take action.
2018-01-29 05:18:00 +00:00
* If a click, call FindWindow.
2017-09-24 23:26:15 +00:00
* If target id not the window id, ignore.
2018-01-29 05:18:00 +00:00
* If target element is desktop or menu then ignore.
* If target element is close box then initiate [window close](#window-close).
* If target element is title bar then initiate [window drag](#window-drag).
* If target element is resize box then initiate [window resize](#window-resize).
2018-02-20 03:21:10 +00:00
* Otherwise, it is content area; call `FindControl`.
2018-02-19 19:33:13 +00:00
* If content part is a scrollbar then initiate a [scroll](#window-scroll).
* Otherwise, handle a content click using custom logic (e.g. hit testing buttons, etc)
2017-09-24 23:26:15 +00:00
#### Window Close
2018-02-20 03:21:10 +00:00
* Call `TrackGoAway`, which enters a modal loop to handle the mouse moving out/in the box.
* Result indicates clicked or canceled. If canceled, return to input loop.
* Call `CloseWindow`
2017-09-24 23:16:36 +00:00
2017-09-24 23:20:32 +00:00
#### Window Drag
2017-09-22 16:33:49 +00:00
2018-02-20 03:21:10 +00:00
* Call `DragWindow`, which enters a modal loop to handle the mouse moving out/in the box.
* Result indicates moved or canceled. If canceled, return to input loop.
* Call `JUMP_TABLE_REDRAW_ALL`.
* If _offscreen flag_ was not set, redraw desktop icons (`DESKTOP_REDRAW_ICONS`).
2017-09-22 16:33:49 +00:00
* Set _offscreen flag_ if window's `top` is greater than or equal to the screen bottom (191), clear otherwise.
* If _offscreen flag_ is not set, redraw window.
2017-09-24 23:20:32 +00:00
#### Window Resize
2017-09-22 16:33:49 +00:00
2018-02-20 03:21:10 +00:00
* Call `GrowWindow`, which enters a modal loop to handle resizing.
* Result indicates changed or canceled. If canceled, return to input loop.
* Call `JUMP_TABLE_REDRAW_ALL`.
* Call `DESKTOP_REDRAW_ICONS`.
* Call `UpdateThumb` if needed to adjust scroll bar settings.
2017-09-22 16:33:49 +00:00
* Redraw window.
2017-09-24 23:20:32 +00:00
#### Window Scroll
2018-02-20 03:21:10 +00:00
* Call `TrackThumb`, which enters a modal loop to handle dragging.
* Redraw window.