[41] | 1 | ; Project name : Assembly Library |
---|
| 2 | ; Description : Functions for drawing scroll bars over menu borders. |
---|
| 3 | |
---|
| 4 | ; Section containing code |
---|
| 5 | SECTION .text |
---|
| 6 | |
---|
| 7 | ;-------------------------------------------------------------------- |
---|
| 8 | ; MenuScrollbars_AreScrollbarsNeeded |
---|
| 9 | ; Parameters |
---|
| 10 | ; SS:BP: Ptr to MENU |
---|
| 11 | ; Returns: |
---|
| 12 | ; CF: Set if scroll bars are needed |
---|
| 13 | ; Cleared if no scroll bars needed |
---|
| 14 | ; Corrupts registers: |
---|
[67] | 15 | ; AX |
---|
[41] | 16 | ;-------------------------------------------------------------------- |
---|
| 17 | ALIGN JUMP_ALIGN |
---|
| 18 | MenuScrollbars_AreScrollbarsNeeded: |
---|
[67] | 19 | xchg ax, cx |
---|
[41] | 20 | call MenuScrollbars_GetMaxVisibleItemsOnPageToCX |
---|
| 21 | cmp cx, [bp+MENUINIT.wItems] ; Set CF if max visible < total items |
---|
[67] | 22 | xchg cx, ax |
---|
[41] | 23 | ret |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | ;-------------------------------------------------------------------- |
---|
| 27 | ; MenuScrollbars_GetScrollCharacterToALForLineInDI |
---|
| 28 | ; Parameters |
---|
| 29 | ; DI: Index of item line to draw |
---|
| 30 | ; SS:BP: Ptr to MENU |
---|
| 31 | ; Returns: |
---|
| 32 | ; AL: Scroll track or thumb character |
---|
| 33 | ; Corrupts registers: |
---|
| 34 | ; AH, CX, DX |
---|
| 35 | ;-------------------------------------------------------------------- |
---|
| 36 | ALIGN JUMP_ALIGN |
---|
| 37 | MenuScrollbars_GetScrollCharacterToALForLineInDI: |
---|
| 38 | call MenuScrollbars_GetMaxVisibleItemsOnPageToCX |
---|
| 39 | call .GetFirstThumbLineToAX |
---|
| 40 | cmp di, ax ; Before first thumb line? |
---|
| 41 | jb SHORT .ReturnTrackCharacter |
---|
| 42 | call .GetLastThumbLineToAX |
---|
| 43 | cmp di, ax ; After last thumb line? |
---|
| 44 | ja SHORT .ReturnTrackCharacter |
---|
| 45 | mov al, SCROLL_THUMB_CHARACTER |
---|
| 46 | ret |
---|
| 47 | ALIGN JUMP_ALIGN |
---|
| 48 | .ReturnTrackCharacter: |
---|
| 49 | mov al, SCROLL_TRACK_CHARACTER |
---|
| 50 | ret |
---|
| 51 | |
---|
| 52 | ;-------------------------------------------------------------------- |
---|
| 53 | ; .GetLastThumbLineToAX |
---|
| 54 | ; Parameters |
---|
| 55 | ; CX: Max visible items on page |
---|
| 56 | ; SS:BP: Ptr to MENU |
---|
| 57 | ; Returns: |
---|
| 58 | ; AX: Item line for last thumb character |
---|
| 59 | ; Corrupts registers: |
---|
| 60 | ; CX, DX |
---|
[133] | 61 | ;-------------------------------------------------------------------- |
---|
[41] | 62 | ALIGN JUMP_ALIGN |
---|
| 63 | .GetLastThumbLineToAX: |
---|
| 64 | call MenuScrollbars_GetLastVisibleItemOnPageToAX |
---|
| 65 | jmp SHORT .CalculateFirstOrLastThumbLineToAX |
---|
| 66 | |
---|
| 67 | ;-------------------------------------------------------------------- |
---|
| 68 | ; .GetFirstThumbLineToAX |
---|
| 69 | ; Parameters |
---|
| 70 | ; CX: Max visible items on page |
---|
| 71 | ; SS:BP: Ptr to MENU |
---|
| 72 | ; Returns: |
---|
| 73 | ; AX: Item line for first thumb character |
---|
| 74 | ; Corrupts registers: |
---|
| 75 | ; CX, DX |
---|
| 76 | ;-------------------------------------------------------------------- |
---|
| 77 | ALIGN JUMP_ALIGN |
---|
| 78 | .GetFirstThumbLineToAX: |
---|
| 79 | mov ax, [bp+MENU.wFirstVisibleItem] |
---|
| 80 | .CalculateFirstOrLastThumbLineToAX: |
---|
| 81 | mul cx |
---|
| 82 | div WORD [bp+MENUINIT.wItems] |
---|
| 83 | ret ; (Visible items on page * First visible item on page) / total items |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | ;-------------------------------------------------------------------- |
---|
| 87 | ; MenuScrollbars_MoveHighlightedItemByAX |
---|
| 88 | ; Parameters |
---|
| 89 | ; AX: Signed offset to new item to be highlighted |
---|
| 90 | ; SS:BP: Ptr to MENU |
---|
| 91 | ; Returns: |
---|
| 92 | ; Nothing |
---|
| 93 | ; Corrupts registers: |
---|
| 94 | ; AX, BX, CX, DX, SI, DI |
---|
| 95 | ;-------------------------------------------------------------------- |
---|
| 96 | ALIGN JUMP_ALIGN |
---|
| 97 | MenuScrollbars_MoveHighlightedItemByAX: |
---|
[52] | 98 | mov cx, [bp+MENUINIT.wHighlightedItem] |
---|
[41] | 99 | add cx, ax |
---|
| 100 | call .RotateItemInCX |
---|
| 101 | ; Fall to .ScrollPageForNewItemInCX |
---|
| 102 | |
---|
| 103 | ;-------------------------------------------------------------------- |
---|
| 104 | ; .ScrollPageForNewItemInCX |
---|
| 105 | ; Parameters |
---|
| 106 | ; CX: New item to be highlighted |
---|
| 107 | ; SS:BP: Ptr to MENU |
---|
| 108 | ; Returns: |
---|
| 109 | ; Nothing |
---|
| 110 | ; Corrupts registers: |
---|
| 111 | ; AX, BX, CX, DX, SI, DI |
---|
| 112 | ;-------------------------------------------------------------------- |
---|
| 113 | .ScrollPageForNewItemInCX: |
---|
| 114 | call MenuScrollbars_IsItemInCXonVisiblePage |
---|
| 115 | jc SHORT .HighlightNewItemOnCX |
---|
| 116 | |
---|
| 117 | mov dx, [bp+MENU.wFirstVisibleItem] |
---|
[52] | 118 | sub dx, [bp+MENUINIT.wHighlightedItem] |
---|
[41] | 119 | add dx, cx |
---|
| 120 | MAX_S dx, 0 |
---|
| 121 | call .GetMaxFirstVisibleItemToAX |
---|
| 122 | MIN_U ax, dx |
---|
| 123 | mov [bp+MENU.wFirstVisibleItem], ax |
---|
| 124 | call MenuText_RefreshAllItems |
---|
| 125 | |
---|
| 126 | ALIGN JUMP_ALIGN |
---|
| 127 | .HighlightNewItemOnCX: |
---|
| 128 | jmp MenuEvent_HighlightItemFromCX |
---|
| 129 | |
---|
| 130 | ;-------------------------------------------------------------------- |
---|
| 131 | ; .GetMaxFirstVisibleItemToAX |
---|
| 132 | ; Parameters |
---|
| 133 | ; SS:BP: Ptr to MENU |
---|
| 134 | ; Returns: |
---|
| 135 | ; AX: Max first visible item |
---|
| 136 | ; Corrupts registers: |
---|
| 137 | ; Nothing |
---|
| 138 | ;-------------------------------------------------------------------- |
---|
| 139 | ALIGN JUMP_ALIGN |
---|
| 140 | .GetMaxFirstVisibleItemToAX: |
---|
| 141 | push cx |
---|
| 142 | |
---|
| 143 | call MenuScrollbars_GetMaxVisibleItemsOnPageToCX |
---|
| 144 | mov ax, [bp+MENUINIT.wItems] |
---|
| 145 | sub ax, cx |
---|
| 146 | |
---|
| 147 | pop cx |
---|
| 148 | ret |
---|
| 149 | |
---|
| 150 | ;-------------------------------------------------------------------- |
---|
| 151 | ; .RotateItemInCX |
---|
| 152 | ; Parameters |
---|
| 153 | ; CX: Possibly under of overflown item to be rotated |
---|
| 154 | ; SS:BP: Ptr to MENU |
---|
| 155 | ; Returns: |
---|
| 156 | ; CX: Valid item index |
---|
| 157 | ; Corrupts registers: |
---|
| 158 | ; DX |
---|
| 159 | ;-------------------------------------------------------------------- |
---|
| 160 | ALIGN JUMP_ALIGN |
---|
| 161 | .RotateItemInCX: |
---|
| 162 | mov dx, [bp+MENUINIT.wItems] |
---|
[133] | 163 | test cx, cx |
---|
| 164 | js SHORT .RotateNegativeItemInCX |
---|
[41] | 165 | cmp cx, dx |
---|
| 166 | jae SHORT .RotatePositiveItemInCX |
---|
| 167 | ret |
---|
| 168 | |
---|
| 169 | ALIGN JUMP_ALIGN |
---|
| 170 | .RotatePositiveItemInCX: |
---|
| 171 | sub cx, dx |
---|
| 172 | ;jae SHORT .RotatePositiveItemInCX ; Not needed by scrolling |
---|
| 173 | ret |
---|
| 174 | |
---|
| 175 | ALIGN JUMP_ALIGN |
---|
| 176 | .RotateNegativeItemInCX: |
---|
| 177 | add cx, dx |
---|
| 178 | ;js SHORT .RotateNegativeItemInCX ; Not needed by scrolling |
---|
| 179 | ret |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | ;-------------------------------------------------------------------- |
---|
[105] | 183 | ; MenuScrollbars_IsItemInCXonVisiblePage |
---|
[41] | 184 | ; Parameters |
---|
| 185 | ; CX: Item whose visibility is to be checked |
---|
| 186 | ; SS:BP: Ptr to MENU |
---|
| 187 | ; Returns: |
---|
| 188 | ; CF: Set if item is on visible page |
---|
| 189 | ; Cleared if item is not on visible page |
---|
| 190 | ; Corrupts registers: |
---|
| 191 | ; AX |
---|
| 192 | ;-------------------------------------------------------------------- |
---|
| 193 | ALIGN JUMP_ALIGN |
---|
| 194 | MenuScrollbars_IsItemInCXonVisiblePage: |
---|
[133] | 195 | cmp [bp+MENU.wFirstVisibleItem], cx |
---|
| 196 | ja SHORT .ItemIsNotVisible |
---|
[41] | 197 | |
---|
| 198 | call MenuScrollbars_GetLastVisibleItemOnPageToAX |
---|
| 199 | cmp cx, ax |
---|
| 200 | ja SHORT .ItemIsNotVisible |
---|
| 201 | stc ; Item is visible |
---|
[133] | 202 | ALIGN JUMP_ALIGN, ret |
---|
[41] | 203 | .ItemIsNotVisible: |
---|
| 204 | ret |
---|
| 205 | |
---|
| 206 | |
---|
| 207 | ;-------------------------------------------------------------------- |
---|
[105] | 208 | ; MenuScrollbars_GetLastVisibleItemOnPageToAX |
---|
[41] | 209 | ; Parameters |
---|
| 210 | ; SS:BP: Ptr to MENU |
---|
| 211 | ; Returns: |
---|
| 212 | ; AX: Index of last visible item on page |
---|
| 213 | ; Corrupts registers: |
---|
| 214 | ; Nothing |
---|
| 215 | ;-------------------------------------------------------------------- |
---|
| 216 | ALIGN JUMP_ALIGN |
---|
| 217 | MenuScrollbars_GetLastVisibleItemOnPageToAX: |
---|
| 218 | push cx |
---|
| 219 | |
---|
| 220 | call MenuScrollbars_GetActualVisibleItemsOnPageToCX |
---|
| 221 | xchg ax, cx |
---|
| 222 | dec ax |
---|
| 223 | add ax, [bp+MENU.wFirstVisibleItem] |
---|
| 224 | |
---|
| 225 | pop cx |
---|
| 226 | ret |
---|
| 227 | |
---|
| 228 | |
---|
| 229 | ;-------------------------------------------------------------------- |
---|
| 230 | ; MenuScrollbars_GetActualVisibleItemsOnPageToCX |
---|
| 231 | ; Parameters |
---|
| 232 | ; SS:BP: Ptr to MENU |
---|
| 233 | ; Returns: |
---|
| 234 | ; CX: Currently visible items |
---|
| 235 | ; Corrupts registers: |
---|
| 236 | ; Nothing |
---|
| 237 | ;-------------------------------------------------------------------- |
---|
| 238 | ALIGN JUMP_ALIGN |
---|
| 239 | MenuScrollbars_GetActualVisibleItemsOnPageToCX: |
---|
| 240 | call MenuScrollbars_GetMaxVisibleItemsOnPageToCX |
---|
| 241 | MIN_U cx, [bp+MENUINIT.wItems] |
---|
| 242 | ret |
---|
| 243 | |
---|
| 244 | |
---|
| 245 | ;-------------------------------------------------------------------- |
---|
| 246 | ; MenuScrollbars_GetMaxVisibleItemsOnPageToCX |
---|
| 247 | ; Parameters |
---|
| 248 | ; SS:BP: Ptr to MENU |
---|
| 249 | ; Returns: |
---|
| 250 | ; CX: Maximum number of visible items |
---|
| 251 | ; Corrupts registers: |
---|
| 252 | ; Nothing |
---|
| 253 | ;-------------------------------------------------------------------- |
---|
| 254 | ALIGN JUMP_ALIGN |
---|
| 255 | MenuScrollbars_GetMaxVisibleItemsOnPageToCX: |
---|
| 256 | eMOVZX cx, BYTE [bp+MENUINIT.bHeight] |
---|
| 257 | sub cl, [bp+MENUINIT.bTitleLines] |
---|
| 258 | sub cl, [bp+MENUINIT.bInfoLines] |
---|
| 259 | sub cl, MENU_VERTICAL_BORDER_LINES |
---|
| 260 | ret |
---|