diff --git a/MGTK.md b/MGTK.md index e767b11..3d81367 100644 --- a/MGTK.md +++ b/MGTK.md @@ -4,7 +4,7 @@ This is a complex API library written by Apple circa 1985. It consists of: * [Graphics Primitives](#graphics-primitives) - screen management, lines, rects, polys, text, patterns, pens * [Concepts](#concepts) - * [Commands](#commands) + * [Commands](#commands) * [Mouse Graphics](#mouse-graphics) - windows, menus, events, cursors * [Concepts](#concepts-1) * [Commands](#commands-1) @@ -14,7 +14,7 @@ For the purposes of DeskTop, the entry point is fixed at $4000 AUX, called MLI-s ``` JSR $4000 .byte call - .addr params + .addr params ``` Result will be in A, with Z bit set, 0 indicating success (so `BNE error` works). @@ -609,7 +609,8 @@ Parameters: ### Menu Manager - configure, enable, disable, select #### InitMenu ($2F) - +Configure characters used for menu glyphs. Optional. The defaults +are solid=$1E, open=$1F, check=$1D, control=$01. Parameters: ``` @@ -903,51 +904,125 @@ Parameters: ## More -> NOTE: Movable windows must maintain an _offscreen_flag_. If a window is moved so that the +> NOTE: Movable DA windows must maintain an _offscreen_flag_. If a window is moved so that the > content area is entirely offscreen then various operations should be skipped because > the window's box coordinates will not be set correctly. +> TODO: Figure out if this is just a bug in the DAs. -### Use by DAs +### Application Use -#### Input Loop +#### Initialization -* Call `GetEvent`. -* If a key, then check modifiers (Open/Solid Apple) and key code, ignore or take action. -* If a click, call FindWindow. -* If target id not the window id, ignore. -* 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). -* Otherwise, it is content area; call `FindControl`. -* 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) +* `StartDeskTop` +* `InitMenu` (if necessary; the defaults are sensible) +* `SetMenu` +* Run main loop until quit +* `StopDeskTop` -#### Window Close -* 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` +#### Main Loop -#### Window Drag +* `GetEvent` +* If `event_kind_button_down`: + * `FindWindow` to figure out what was clicked + * If `area_desktop` - ignore + * If `area_menubar` - handle menu + * If `area_dragbar` - [handle window drag](#handle-window-drag) + * If `area_grow_box` - [handle window resize](#handle-window-resize) + * If `area_close_box` - [handle window close](#handle-window-close) + * If `area_content`: + * `FindControl` + * If `ctl_*_scroll_bar` - [handle scrolling](#handle-scrolling) + * If `ctl_dead_zone` - ignore + * If `ctl_not_a_control`: + * If not topmost: + * `SelectWindow` + * Otherwise, handle content click per app +* If `event_kind_key_down`: + * TODO +* If `event_kind_drag`: + * TODO +* If `event_kind_apple_key`: + * TODO +* If `event_kind_update`: + * [Redraw](#redraw-window) contents of `window_id` -* 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`). -* 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. -#### Window Resize +#### Redraw window -* 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. -* Redraw window. +* `GetWinPort` - get pointer to window's port +* `SetPort` - make it current +* `HideCursor` - if multiple drawing calls will be made +* ... draw ... +* `ShowCursor` - if needed +* `SetWinPort` - save attributes if desired -#### Window Scroll -* Call `TrackThumb`, which enters a modal loop to handle dragging. -* Redraw window. +#### Handle Menu + +* `MenuSelect` to initiate menu modal loop +* Dispatch for `menu_id` and `menu_item` (0 if cancelled) +* `HiliteMenu` to toggle state back off when done + + +#### Handle Window Drag + +* `SelectWindow` to make topmost if necessary +* `DragWindow` to initiate drag modal loop +* [Handle update events](#handle-update-events) +* [Redraw](#redraw-window) window content if not moved and was made topmost +* If canceled - done +* For DeskTop DAs: + * Call `JUMP_TABLE_REDRAW_ALL`. + * If _offscreen flag_ was not set, redraw desktop icons (`DESKTOP_REDRAW_ICONS`). + * 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. + + +#### Handle Window Close + +* `TrackGoAway` to initiate modal close loop +* If canceled - done +* `CloseWindow` + + +#### Handle Scrolling + +* If `part_thumb`: + * `TrackThumb` to initiate modal scroll loop + * If thumb did not move - done + * [Redraw](#redraw-window) window content + * `UpdateThumb` +* If `part_page_*`: + * Scroll by a "page" + * [Redraw](#redraw-window) window content + * `UpdateThumb` +* If `part_*_arrow`: + * Scroll by a "line" + * [Redraw](#redraw-window) window content + * `UpdateThumb` + + +#### Handle Window Resize + +* `GrowWindow` to initiate modal resize loop +* If canceled - done +* `UpdateThumb` if needed to adjust scroll bars +* [Redraw](#redraw-window) window content +* For DeskTop DAs: + * Call `JUMP_TABLE_REDRAW_ALL`. + * Call `DESKTOP_REDRAW_ICONS`. + + +#### Handle Update Events + +* Repeat: + * `PeekEvent` + * If not `event_kind_update` - exit these steps + * Otherwise: + * `GetEvent` + * `BeginUpdate` + * If error, continue + * Otherwise: + * [Redraw](#redraw-window) `window_id`'s content + * `EndUpdate` diff --git a/desktop/desktop.s b/desktop/desktop.s index c5c8599..d43fbec 100644 --- a/desktop/desktop.s +++ b/desktop/desktop.s @@ -8319,9 +8319,11 @@ L56F8: .byte 0 ;;; ============================================================ -L56F9: sta getwinport_params2::window_id +.proc L56F9 + sta getwinport_params2::window_id jsr get_port2 jmp offset_grafport2_and_set +.endproc ;;; ============================================================ ;;; Handle keyboard-based window activation @@ -10494,11 +10496,11 @@ L6B3A: lda icon_params2 L6B60: lda #$00 sta checkitem_params::check - jsr L6C0F + jsr check_item L6B68: lda #$01 sta checkitem_params::menu_item sta checkitem_params::check - jsr L6C0F + jsr check_item lda icon_params2 jsr icon_entry_lookup stax $06 @@ -10561,8 +10563,10 @@ L6C0E: .byte 0 ;;; ============================================================ -L6C0F: MGTK_RELAY_CALL MGTK::CheckItem, checkitem_params +.proc check_item + MGTK_RELAY_CALL MGTK::CheckItem, checkitem_params rts +.endproc ;;; ============================================================ @@ -14197,23 +14201,25 @@ skip: lda icon_params2 .proc L8B5C ldy #$80 - bne L8B62 + bne :+ L8B60: ldy #$00 -L8B62: sty L8D4A +: sty L8D4A stax L8D4B txa jsr window_lookup stax $06 + lda #$14 clc adc #$23 tay ldx #$23 -L8B7B: lda ($06),y +: lda ($06),y sta grafport2,x dey dex - bpl L8B7B + bpl :- + lda L8D4B jsr icon_entry_lookup stax $06 @@ -14290,11 +14296,12 @@ L8C8C: lsr16 L8D50 asl a tax bit L8D4E - bpl L8CC9 + bpl :+ sub16 L0800, L8D50, L0800,x jmp L8CDC -L8CC9: add16 L0800, L8D50, L0800,x +: add16 L0800, L8D50, L0800,x + L8CDC: bit L8D4F bpl L8CF7 sub16 $0802, L8D52, $0802,x @@ -14347,15 +14354,17 @@ L8D6C: lda L8DB2 asl a asl a asl a + clc - adc #$07 + adc #7 tax ldy #7 -L8D7C: lda L0800,x +: lda L0800,x sta rect_E230,y dex dey - bpl L8D7C + bpl :- + jsr draw_rect_E230 L8D89: lda L8DB2 sec @@ -14391,7 +14400,8 @@ L8DB2: .byte 0 jsr reset_grafport3 MGTK_RELAY_CALL MGTK::SetPattern, checkerboard_pattern3 jsr set_penmode_xor -L8DC7: lda L8E0F + +loop: lda L8E0F bmi L8DE4 beq L8DE4 asl a @@ -14400,12 +14410,14 @@ L8DC7: lda L8E0F clc adc #$07 tax + ldy #7 -L8DD7: lda L0800,x +: lda L0800,x sta rect_E230,y dex dey - bpl L8DD7 + bpl :- + jsr draw_rect_E230 L8DE4: lda L8E0F clc @@ -14428,7 +14440,7 @@ L8DF7: lda L0800,x L8E04: dec L8E0F lda L8E0F cmp #$FD - bne L8DC7 + bne loop rts L8E0F: .byte 0