MAG Disk (Jun 1990) : source / Highlight.a

	       INCLUDE	  "exec/types.i"
	       INCLUDE	  "graphics/rastport.i"
	       INCLUDE	  "intuition/intuition.i"
	       INCLUDE	  "PopUpMenu.i"

_LVOSetDrMd    EQU	  -$162
_LVODraw       EQU	  -$f6
_LVOMove       EQU	  -$f0
_LVORectFill   EQU	  -$132

BORDERSIZE     EQU	  2

	       xdef	  @HighLightItem
	       xdef	  @ToggleMenu

	       xref	  @DrawMenuItem

	       section	  text,code

***************************************************
* HighLightItem(Item, ItemWindow, Mode)           *
*						  *
* Input:					  *
*   Item  -	  Item to highlight.		  *
*   ItemWindow -  Data for the window to draw in. *
*   Mode   -	  HIGHLIGHTON or HIGHLIGHTOFF.	  *
* Output:					  *
*   none					  *
***************************************************
@HighLightItem:
	       MOVEM.L	 D2-D7/A2-A3/A5-A6,-(SP)
	       MOVEA.L	 A0,A3
	       MOVEA.L	 A1,A2

* ------------ Possible to highlight item ?
	       MOVEQ.L	 #ITEMENABLED,D1
	       AND.W	 mi_Flags(A3),D1
	       BEQ.B	 HighlightDone

* ------------ Start highlighting.
	       LEA	 _Rp(A4),A5
	       MOVEA.L	 _GfxBase(A4),A6

	       MOVE.W	 #HIGHFLAGS,D7
	       AND.W	 mi_Flags(A3),D7
	       BNE.B	 NotHighImage

* ------------ Invert Mode and call DrawMenuItem.
* ------------ DrawMenuItem(Item, ItemWindow, !Mode,CLEAROLD);
HighImage:     MOVEQ.L	 #1,D1		  * CLEAROLD
	       ADDQ.W	 #1,D0
	       AND.W	 D1,D0
	       JSR	 @DrawMenuItem(PC)
	       BRA.B	 HighlightDone

* ------------ Left   = Item->LeftEdge - ItemWindow->LeftValue
NotHighImage:  MOVE.W	 mi_LeftEdge(A3),D6
	       SUB.W	 wd_LeftValue(A2),D6
	       EXT.L	 D6

* ------------ Right  = Left + Item->Width
	       MOVE.W	 mi_Width(A3),D5
	       EXT.L	 D5
	       ADD.L	 D6,D5

* ------------ Top    = Item->TopEdge - ItemWindow->TopValue
	       MOVE.W	 mi_TopEdge(A3),D4
	       SUB.W	 wd_TopValue(A2),D4
	       EXT.L	 D4

* ------------ Bottom = Top + Item->Height
	       MOVE.W	 mi_Height(A3),D3
	       EXT.L	 D3
	       ADD.L	 D4,D3

* ------------ Set drawmode = COMPLEMENT.
	       MOVEQ.L	 #RP_COMPLEMENT,D0
	       MOVEA.L	 A5,A1
	       JSR	 _LVOSetDrMd(A6)

* ------------ Check out kind of highlighting.
HighType:      CMPI.W	 #HIGHBOX,D7
	       BEQ.B	 HighBox
	       CMPI.W	 #HIGHCOMP,D7
	       BNE.B	 HighlightDone

* ------------ RectFill(Left, Top, Right - 1, Bottom - 1)
HighComp:      MOVE.L	 D6,D0
	       MOVE.L	 D4,D1
	       MOVEA.L	 A5,A1
	       MOVE.L	 D5,D2
	       SUBQ.L	 #1,D2
	       SUBQ.L	 #1,D3
	       JSR	 _LVORectFill(A6)
	       BRA.B	 HighlightDone

* ------------ DrawRect(Left, Top, Right, Bottom)
HighBox:       BSR.B	 DrawRect

* ------------ DrawRect(Left - 1, Top - 1, Right + 1, Bottom + 1)
	       ADDQ.L	 #1,D5
	       ADDQ.L	 #1,D3
	       BSR.B	 DrawRect

HighlightDone: MOVEM.L	 (SP)+,D2-D7/A2-A3/A5-A6
	       RTS

* ------------ Draw a rectangle.
* ------------ Move(--Left,Top).
DrawRect:      SUBQ.L	 #1,D6
	       MOVE.L	 D6,D0
	       MOVE.L	 D4,D1
	       MOVEA.L	 A5,A1
	       JSR	 _LVOMove(A6)

* ------------ Draw(Left,Bottom).
	       MOVE.L	 D6,D0
	       MOVE.L	 D3,D1
	       BSR.B	 Draw

* ------------ Draw(Right,Bottom).
	       MOVE.L	 D5,D0
	       MOVE.L	 D3,D1
	       BSR.B	 Draw

* ------------ Draw(Right,--Top).
	       SUBQ.L	 #1,D4
	       MOVE.L	 D5,D0
	       MOVE.L	 D4,D1
	       BSR.B	 Draw

* ------------ Draw(Left,Top).
	       MOVE.L	 D6,D0
	       MOVE.L	 D4,D1

Draw:	       MOVEA.L	 A5,A1	       * Get RastPort
	       JMP	 _LVODraw(A6)

*********************************************
* ToggleMenu(Number,Menu)                   *
*					    *
* Input:				    *
*   Number - Menu to highlight. 	    *
*   Menu   - Pointer to the Menu structure. *
* Output:				    *
*   none				    *
*********************************************
@ToggleMenu    MOVEM.L	 D2-D3/A6,-(A7)

* ------------ Menu enabled ?
	       MOVEQ.L	 #MENUENABLED,D2
	       AND.W	 mu_Flags(A0),D2
	       BEQ.B	 ToggleDone

	       MOVE.W	 D0,D3

* ------------ Set drawmode = COMPLEMENT.
	       LEA	 _Rp(A4),A1
	       MOVEQ	 #RP_COMPLEMENT,D0
	       MOVEA.L	 _GfxBase(A4),A6
	       JSR	 _LVOSetDrMd(A6)

* ------------ Invert menu.
* ------------ Bottom = Number * MenuFontSize + MenuWindow.TopEdge.
	       MOVE.W	 _MenuFontSize(A4),D2
	       MULU.W	 D2,D3
	       ADD.W	 _MenuWindow+wd_TopEdge(A4),D3

* ------------ Top = Bottom - MenuFontSize + BORDERSIZE.
	       MOVE.L	 D3,D1
	       SUB.L	 D2,D1
	       ADDQ.L	 #BORDERSIZE,D1

* ------------ Left = MenuWindow.LeftEdge + BORDERSIZE.
	       MOVEQ.L	 #BORDERSIZE,D0
	       ADD.W	 _MenuWindow+wd_LeftEdge(A4),D0

* ------------ Right = MenuWindow.RightEdge - BORDERSIZE.
	       MOVE.W	 _MenuWindow+wd_RightEdge(A4),D2
	       SUBQ.L	 #BORDERSIZE,D2

	       LEA	 _Rp(A4),A1
	       JSR	 _LVORectFill(A6)

ToggleDone     MOVEM.L	 (A7)+,D2-D3/A6
	       RTS


	       section	 __MERGED,bss

	       xref	 _Rp
	       xref	 _GfxBase
	       xref	 _MenuFontSize
	       xref	 _MenuWindow

	       END