|
| 1 | +// -------------------------------------------------- |
| 2 | +// Library: a8libmenu.c |
| 3 | +// Desc...: Atari 8 Bit Menu Library |
| 4 | +// Author.: Wade Ripkowski |
| 5 | +// Date...: 2022.08 |
| 6 | +// License: GNU General Public License v3.0 |
| 7 | +// Note...: Requires: a8defines.c |
| 8 | +// -Converted from Action! |
| 9 | +// -Type byte is synonymous with unsigned char (a8defines.h) |
| 10 | +// Require: a8libwin.c |
| 11 | +// a8libstr.c |
| 12 | +// a8libmisc.c |
| 13 | +// Revised: 2024.02.20-Correct GVERT dehilite location. |
| 14 | +// -------------------------------------------------- |
| 15 | + |
| 16 | +// -------------------------------------------------- |
| 17 | +// Includes |
| 18 | +// -------------------------------------------------- |
| 19 | +#include "a8defines.h" |
| 20 | + |
| 21 | + |
| 22 | +// -------------------------------------------------- |
| 23 | +// Defines to preserve backward call compatability. |
| 24 | +// -------------------------------------------------- |
| 25 | +#define MenuV(a,b,c,d,e,f,g) Menu(a,b,c,GVERT,d,e,f,g) |
| 26 | + |
| 27 | + |
| 28 | +// -------------------------------------------------- |
| 29 | +// Function Prototypes |
| 30 | +// -------------------------------------------------- |
| 31 | +byte Menu(byte bN, byte x, byte y, byte bO, byte bI, byte bS, byte bC, unsigned char **pS); |
| 32 | + |
| 33 | + |
| 34 | +// ------------------------------------------------------------ |
| 35 | +// Func...: byte Menu(byte bN, byte x, byte y, byte bO, byte bI, byte bS, byte bC, unsigned char **pS) |
| 36 | +// Desc...: Vertical or Horizontal menu |
| 37 | +// Param..: bN = Window handle number |
| 38 | +// x = window column for cursor |
| 39 | +// y = window row for cursor |
| 40 | +// bO = Orientation |
| 41 | +// GHORZ = Horizontal (1 line) |
| 42 | +// GVERT = Vertical (stacked) |
| 43 | +// bI = Inverse flag (WON = leave on at selection) |
| 44 | +// bS = Start item number |
| 45 | +// bC = Number of menu items |
| 46 | +// pS = pointer to array of menu item strings |
| 47 | +// Return.: Selected item #, ESC (XESC), or TAB (XTAB) |
| 48 | +// ------------------------------------------------------------ |
| 49 | +byte Menu(byte bN, byte x, byte y, byte bO, byte bI, byte bS, byte bC, unsigned char **pS) |
| 50 | +{ |
| 51 | + byte bF = FALSE; |
| 52 | + byte bL, bR, bK; |
| 53 | + unsigned char cL[41]; |
| 54 | + |
| 55 | + // Set default return to start item # |
| 56 | + bR = bS; |
| 57 | + |
| 58 | + // Continue until finished |
| 59 | + while (! bF) { |
| 60 | + // Display each item |
| 61 | + for (bL=0; bL<bC; bL++) { |
| 62 | + strcpy(cL, pS[bL]); |
| 63 | + |
| 64 | + // Highlight selection based on orientation |
| 65 | + if (bO == GHORZ) { |
| 66 | + // Display item at row count - inverse if start item |
| 67 | + WPrint(bN, x+(bL*strlen(cL)), y, (bL+1 == bR ? ! baW.bI[bN] : baW.bI[bN]), cL); |
| 68 | + } else { |
| 69 | + // Display item at row count - inverse if start item |
| 70 | + WPrint(bN, x, y+bL, (bL+1 == bR ? WON : WOFF), cL); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + // Get key (no inverse key) |
| 75 | + bK = WaitKCX(WOFF); |
| 76 | + |
| 77 | + // Process key |
| 78 | + if ((bK == KDOWN) || (bK == KEQUAL) || (bK == KRIGHT) || (bK == KASTER)) { |
| 79 | + // Increment (move down list) |
| 80 | + bR += 1; |
| 81 | + |
| 82 | + // Check for overrun and roll to top |
| 83 | + if (bR > bC) { |
| 84 | + bR = 1; |
| 85 | + } |
| 86 | + } |
| 87 | + else if ((bK == KUP) || (bK == KMINUS) || (bK == KLEFT) || (bK == KPLUS)) { |
| 88 | + // Decrement (move up list) |
| 89 | + bR -= 1; |
| 90 | + |
| 91 | + // Check for underrun and roll to bottom |
| 92 | + if (bR < 1) { |
| 93 | + bR = bC; |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + // Set last selected item before checking for ESC/TAB/ENTER |
| 98 | + bL = bR; |
| 99 | + |
| 100 | + // If ESC, set choice to XESC |
| 101 | + if (bK == KESC) { |
| 102 | + bR = XESC; |
| 103 | + bF = TRUE; |
| 104 | + } |
| 105 | + // For TAB, set choice to XTAB |
| 106 | + else if (bK == KTAB) { |
| 107 | + bR = XTAB; |
| 108 | + bF = TRUE; |
| 109 | + } |
| 110 | + // For enter, just exit |
| 111 | + else if (bK == KENTER) { |
| 112 | + bF = TRUE; |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + // Uninverse last selection if needed |
| 117 | + if (bI == WOFF) { |
| 118 | + strcpy(cL, pS[bL-1]); |
| 119 | + |
| 120 | + // Unhighlight selection based on orientation |
| 121 | + if (bO == GHORZ) { |
| 122 | + WPrint(bN, x+((bL-1)*strlen(cL)), y, WOFF, cL); |
| 123 | + } else { |
| 124 | + WPrint(bN, x, y+bL-1, WOFF, cL); |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + return(bR); |
| 129 | +} |
0 commit comments