NB. J Solitaire
NB. This is the options script for J Solitaire
NB. This script creates and runs the options form

NB. Creating the form
OPTIONS=: 0 : 0
pc options nomax nomenu nomin nosize owner;pn "Options";
xywh 14 17 36 48;cc back isigraph;
xywh 5 6 48 86;cc ccgroupbox groupbox;cn "Card Back";
xywh 64 6 98 86;cc ccgroupbox groupbox;cn "Draw Number";
xywh 80 137 34 12;cc ok button;cn "OK";
xywh 98 76 23 12;cc numbox edit;
xywh 70 18 89 55;cc ccstatic static;cn "ccstatic";
xywh 26 76 12 12;cc next spin;
xywh 45 137 34 12;cc no button;cn "Cancel";
xywh 18 96 130 14;cc band checkbox;cn "Draw Lines (Instead of the Cards) While Dragging";
xywh 35 119 95 12;cc bgc button;cn "Change Background Color";
xywh 27 108 78 8;cc bandtxt static;cn "This Allows for Faster Graphics";
pas 4 4;pcenter;
rem form end;
)

NB. running the form and setting up the isigraph and numbox
options_run=: 3 : 0
wd OPTIONS
NB. initialize form here
backNUM=: 51 + CARDBACK
wd 'psel options'
glclear''
glmap MM_RAW
wd 'setxywhx back 28 34 ',": cardWH
glpixels 0 0, cardWH, ,backNUM { CARDS
glshowx''
wd 'set numbox ',": NUMFLIP
wd'set band ',":BAND
wd'set ccstatic *Please enter the number of cards you want to flip each time the deck is clicked. Solitaire is usually played with 1 or 3 cards being turned over each time. However, for this version you can choose any number less than 6.'
wd 'pshow;'
tempBGCOLOR=: BGCOLOR
)

NB.options_band_button=: 3 : 0
NB.BAND=: band='1'
NB.)

NB. This verb closes the options form
options_close=: 3 : 0
wd'pclose'
)

NB. This verb is attached to the spin control (next) and changes the card back being displayed
options_next_button=: 3 : 0
if. ((backNUM + ".next) < 64) *. (backNUM + ".next) > 51 do.
  backNUM=: backNUM+ ".next
end.
wd 'psel options'
glclear''
glmap MM_RAW
glpixels 0 0, cardWH, ,backNUM { CARDS
glshow''
)

NB. This verb is tied to the ok control and checks to see if the data entered is valid; if so it updates the data.
options_ok_button=: 3 : 0
if. (5 >: ". numbox) *. (1<: ". numbox) *. (". numbox) = <. ". numbox do.
  NUMFLIP=: <. ". numbox
else.
  wdinfo 'Enter a valid number of cards to flip.'
  return.
end.
BAND=: band='1'
CARDBACK=: backNUM - 51
CB=: ,(51+CARDBACK){CARDS NB. current card back
CBTOP=: (CBTOPN*{.cardWH){.CB
BGCOLOR=: tempBGCOLOR
xy=. 2 3{".wd'qscreen'
DRAWINIT=: 2 2007 3 2016 1 5 2032, BGCOLOR, 2 2004, 6 2031 0 0,xy,6 2031 ,((cardOVER + 3 * cardSPACE), cardDOWN),cardWH, 6 2031 ,((cardOVER + 4 * cardSPACE), cardDOWN),cardWH, 6 2031 ,((cardOVER + 5 * cardSPACE), cardDOWN), cardWH, 6 2031 ,((cardOVER + 6 * cardSPACE), cardDOWN),cardWH
draw''
FILE=. (<(": CARDBACK),' ', (": NUMFLIP), ' ' , (": BGCOLOR), ' ', ": BAND), }. 'b' fread PATHRECORD
FILE=. ;FILE, each <LF
FILE fwrite PATHRECORD
wd 'psel options'
wd 'pclose'
)

NB. This verb is tied to the cancel control.  It exits without making changes.
options_no_button=: 3 : 0
wd 'psel options'
wd 'pclose'
)

NB. This verb allows the user to launch a color picker to chose the background
options_bgc_button=: 3 : 0
tempBGCOLOR=: wd 'mbcolor'
if. 1 > # tempBGCOLOR do.
  tempBGCOLOR=: BGCOLOR
else.
  tempBGCOLOR=: 3 {. ".tempBGCOLOR
end.
)

NB. triggers options_run'' so the form loads automaticly when the script is loaded
options_run''
