SoundDir$ = ".\Alphabet Sounds\"
DIM AlphaSound(65 TO 90)
FOR i = 65 TO 90
temp$ = SoundDir$ + CHR$(i) + ".ogg"
AlphaSound(i) = _SNDOPEN(temp$, "VOL,SYNC,LEN,PAUSE")
NEXT
DO
INPUT "Input word to spell aloud: "; word$
IF word$ = "" THEN SYSTEM
word$ = UCASE$(word$)
FOR i = 1 TO LEN(word$)
_SNDPLAY AlphaSound(ASC(word$, i))
_DELAY 1
NEXT
LOOP
SCREEN _NEWIMAGE(800, 600, 32)
_TITLE "Spell It Aloud"
DEFLNG A-Z
RANDOMIZE TIMER
CONST ImageDir$ = ".\Images\"
CONST SoundDir$ = ".\Alphabet Sounds\"
DIM AlphaSound(65 TO 90)
REDIM SHARED PhotoList(100000) AS STRING
REDIM SHARED PhotoTags(100000) AS STRING
DIM SHARED f AS LONG, f1 AS LONG
'load our fonts
f = _LOADFONT("courbd.ttf", 84, "MONOSPACE")
f1 = _LOADFONT("courbd.ttf", 20, "MONOSPACE")
_FONT f
fw = _FONTWIDTH: fh = _FONTHEIGHT
'Load the alphabet sound library
FOR i = 65 TO 90
temp$ = SoundDir$ + CHR$(i) + ".ogg"
AlphaSound(i) = _SNDOPEN(temp$, "VOL,SYNC,LEN,PAUSE")
NEXT
_FONT f
'Get a listing of the files
PhotoList$ = ImageDir$ + "*.bmp " + ImageDir$ + "*.jpg " + ImageDir$ + "*.png " + ImageDir$ + "*.gif "
SHELL _HIDE "DIR " + PhotoList$ + "/b /s /a-d >PhotoList.txt"
'Load those names into a file.
OPEN "Photolist.txt" FOR BINARY AS #1
DO UNTIL EOF(1)
PhotoCount = PhotoCount + 1
LINE INPUT #1, PhotoList(PhotoCount)
LOOP
REDIM _PRESERVE PhotoList(PhotoCount)
CLOSE
_DELAY 1 'Give everything a moment to initialize and get started for us.
DO
DO UNTIL photochosen <> oldpic
photochosen = INT(RND * PhotoCount) + 1
LOOP
oldpic = photochosen
word$ = UCASE$(PhotoList(photochosen))
word$ = MID$(word$, _INSTRREV(word$, "\") + 1)
word$ = LEFT$(word$, INSTR(word$, ".") - 1)
IF tempimage <> 0 THEN _FREEIMAGE tempimage 'free the old image
tempimage = _LOADIMAGE(PhotoList(photochosen), 32) 'get the new image
GetTags word$
CLS
_PUTIMAGE (50, 50)-(750, 500), tempimage 'Put the image to the screen
ShowTags 'Display the tags up top
'Put the letters to the screen one by one
pw = _PRINTWIDTH(word$): StartX = (_WIDTH - pw) \ 2 'center position
FOR i = 1 TO LEN(word$)
a = ASC(word$, i) AND NOT 32 'play lowercase letters as uppercase sounds
_PRINTSTRING (StartX + (i - 1) * fw, 510), MID$(word$, i, 1)
IF a < 65 OR a > 90 THEN _CONTINUE 'ignore non-letters in the file name
_SNDPLAY AlphaSound(a)
WHILE _SNDPLAYING(AlphaSound(a)) 'wait for sound to finish before playing again
_LIMIT 10 'play nice with CPU during wait
WEND
NEXT
DO
k = _KEYHIT
_KEYCLEAR
_LIMIT 10
SELECT CASE k
CASE 65, 97 'a,A
AddTags word$
CASE 68, 100 'd,D
DeleteTags word$
CASE 32 'space
_DELAY 1
EXIT DO
CASE 27 'escape
SYSTEM 'quit
END SELECT
LOOP
LOOP
SUB BlankTop
LINE (0, 0)-(799, 49), &HFF000000, BF 'blank out the top info
END SUB
SUB AddTags (tfile$)
BlankTop
_FONT f1
LOCATE 1, 1: PRINT "Add Tag:";
INPUT tag$
IF tag$ <> "" THEN
u = UBOUND(phototags)
FOR i = 1 TO u
IF _STRICMP(tag$, PhotoTags(i)) = 0 THEN TagExists = -1: EXIT FOR
NEXT
IF NOT TagExists THEN
REDIM _PRESERVE PhotoTags(u + 1) AS STRING
PhotoTags(u + 1) = tag$
file$ = ".\Images\" + tfile$ + ".txt"
OPEN file$ FOR OUTPUT AS #1
FOR i = 1 TO u + 1
PRINT #1, "#";
PRINT #1, PhotoTags(i);
PRINT #1, " ";
NEXT
CLOSE
END IF
END IF
ShowTags
_FONT f
END SUB
SUB DeleteTags (tfile$)
BlankTop
_FONT f1
LOCATE 1, 1: PRINT "Delete Tag:";
INPUT tag$
IF tag$ <> "" THEN
u = UBOUND(phototags)
FOR i = 1 TO u
IF _STRICMP(tag$, PhotoTags(i)) = 0 THEN TagExists = -1: EXIT FOR
NEXT
IF TagExists THEN
FOR j = i TO u - 1
PhotoTags(j) = PhotoTags(j + 1)
NEXT
REDIM _PRESERVE PhotoTags(u - 1) AS STRING
file$ = ".\Images\" + tfile$ + ".txt"
OPEN file$ FOR OUTPUT AS #1
FOR i = 1 TO u - 1
PRINT #1, "#";
PRINT #1, PhotoTags(i);
PRINT #1, " ";
NEXT
CLOSE
END IF
END IF
ShowTags
_FONT f
END SUB
SUB GetTags (tfile$)
'Load the PhotoTags
file$ = ".\Images\" + tfile$ + ".txt"
OPEN file$ FOR BINARY AS #1
IF LOF(1) = 0 THEN 'if there's no tags, we can't get them.
CLOSE
REDIM _PRESERVE PhotoTags(0) AS STRING
EXIT SUB
END IF
DO UNTIL EOF(1)
LINE INPUT #1, junk$
l = 1
DO UNTIL l = 0
l = INSTR(junk$, "#")
IF l THEN
junk$ = MID$(junk$, l + 1)
l1 = INSTR(junk$, "#")
IF l1 = 0 THEN 'nothing more, we now have the tag
tag$ = junk$
l = 0
ELSE
tag$ = LEFT$(junk$, l1 - 1)
junk$ = MID$(junk$, l1)
END IF
END IF
tag$ = _TRIM$(tag$) 'no leading/tailing spaces for ease of matching
TagFound = 0
FOR i = 1 TO TagCount 'Check the existing tags to see if these exist
IF PhotoTags(i) = tag$ THEN TagFound = -1: EXIT FOR
NEXT
IF NOT TagFound THEN 'If not, add the new tags to the list
TagCount = TagCount + 1
IF TagCount > UBOUND(PhotoTags) THEN REDIM _PRESERVE PhotoTags(TagCount + 1000) AS STRING
PhotoTags(TagCount) = tag$
END IF
LOOP
LOOP
CLOSE
REDIM _PRESERVE PhotoTags(TagCount) AS STRING
END SUB
SUB ShowTags
BlankTop
_FONT f1
PRINT UBOUND(phototags); " TAGS: "
FOR i = 1 TO UBOUND(Phototags)
PRINT "#"; PhotoTags(i); " ";
NEXT
_FONT f
END SUB
'Steve's idea: 10 different words, each of which is repeated three times and then one is picked and the child writes image name
'(text input, I suppose, because QB64 does not have microphone support)?
SCREEN _NEWIMAGE(800, 600, 32)
_TITLE "Spell It Aloud"
RANDOMIZE TIMER
ImageDir$ = ".\Images\"
SoundDir$ = ".\Alphabet Sounds\"
DIM SHARED AlphaSound(65 TO 90), f AS LONG, f1 AS LONG
REDIM SHARED PhotoList(100000) AS STRING
REDIM SHARED PhotoTags(100000) AS STRING
REDIM SHARED IMG10(9) AS LONG 'array fo 10 different images. Contains diferent indexes numbers for PhotoList()
'load our fonts
f = _LOADFONT("courbd.ttf", 84, "MONOSPACE")
f1 = _LOADFONT("courbd.ttf", 20, "MONOSPACE")
_FONT f
fw = _FONTWIDTH: fh = _FONTHEIGHT
'Load the alphabet sound library
FOR i = 65 TO 90
temp$ = SoundDir$ + CHR$(i) + ".ogg"
AlphaSound(i) = _SNDOPEN(temp$, "VOL,SYNC,LEN,PAUSE")
NEXT
'Get a listing of the files
PhotoList$ = ImageDir$ + "*.bmp " + ImageDir$ + "*.jpg " + ImageDir$ + "*.png " + ImageDir$ + "*.gif "
SHELL _HIDE "DIR " + PhotoList$ + "/b /s /a-d >PhotoList.txt"
'Load those names into a file.
OPEN "Photolist.txt" FOR BINARY AS #1
DO UNTIL EOF(1)
PhotoCount = PhotoCount + 1
LINE INPUT #1, PhotoList(PhotoCount)
LOOP
CLOSE #1
REDIM _PRESERVE PhotoList(PhotoCount)
_DELAY 1 'Give everything a moment to initialize and get started for us.
Insert_10_Different_Images 'insert 10 different indexes numbers from PhotoList, to array IMG10() [LONG] [0..9]
DO
' DO UNTIL photochosen <> oldpic
' RANDOMIZE TIMER
' photochosen = INT(RND * PhotoCount) + 1
' LOOP
' oldpic = photochosen
photochosen = IMG10(index)
index = index + 1
IF index > 9 THEN index = INT(1 + RND * 8): Query = 1
word$ = UCASE$(PhotoList(photochosen))
word$ = MID$(word$, _INSTRREV(word$, "\") + 1)
word$ = LEFT$(word$, INSTR(word$, ".") - 1)
IF tempimage < -1 THEN _FREEIMAGE tempimage
tempimage = _LOADIMAGE(PhotoList(photochosen), 32)
GetTags word$
'Put the image to the screen UPGRADE
FOR Loop_it = 1 TO 3 'as you say. 3x one word + image, this 10x with different images an then query.
CLS
'program photo area is 700 x 450 pixels. So:
GetNewWH 700, 450, tempimage, nW, nH
Ws = 400 - (nW / 2)
We = 400 + (nW / 2)
Hs = 300 - (nH / 2) - 25
He = 300 + (nH / 2) - 25
_PUTIMAGE (Ws, Hs)-(We, He), tempimage
ShowTags 'Display the tags up top
'Put the letters to the screen one by one
pw = _PRINTWIDTH(word$)
StartX = (_WIDTH - pw) \ 2
IF Query = 0 THEN 'as you need: 10x 3 words and then query to image name
FOR i = 1 TO LEN(word$)
a = ASC(word$, i) AND NOT 32
_PRINTSTRING (StartX + (i - 1) * fw, 510), MID$(word$, i, 1)
IF ASC(word$, i) = 32 THEN _DELAY .5: _CONTINUE
IF a < 65 OR a > 90 THEN _CONTINUE
_SNDPLAY AlphaSound(ASC(word$, i))
DO WHILE _SNDPLAYING(AlphaSound(ASC(word$, i))): LOOP ' UPGRADE
NEXT
ELSE
oldFont = _FONT
_FONT 16
'is time to query.....none _INPUTSTRING statement.... :) i am so lasy!!!!!
_PRINTSTRING (10, 510), "Insert image name: "
DO UNTIL inpt$ = CHR$(13)
inpt$ = INKEY$
IF INT(TIMER) MOD 2 = 0 THEN cursor$ = "_" ELSE cursor$ = ""
IF LEN(inpt$) THEN
word2$ = word2$ + UCASE$(inpt$)
IF inpt$ = CHR$(9) THEN word2$ = LEFT$(word2$, LEN(word2$) - 1) 'backspace
END IF
_PRINTSTRING (10 + (20 * 8), 510), word2$ + cursor$
LOOP
ok$ = "Correct!"
okl = _PRINTWIDTH(ok$)
word2$ = MID$(word2$, 1, LEN(word2$) - 1) 'erase CHR$(13) - ENTER from this word
IF UCASE$(_TRIM$(word2$)) = UCASE$(_TRIM$(word$)) THEN
_FONT oldFont
StartX = _WIDTH / 2 - okl / 2
_PRINTSTRING (StartX, 510), ok$
SLEEP 2
END IF
Query = 0
Insert_10_Different_Images
_FONT oldFont
index = 0
_CONTINUE
END IF ' if query condition
WordPlay word$
DO
WHILE _MOUSEINPUT: WEND
MX = _MOUSEX
MY = _MOUSEY
IF MX > Ws AND MX < We AND MY > Hs AND MY < He THEN
IF _FILEEXISTS(_CWD$ + "\animal sounds\" + word$ + ".mp3") THEN
_MOUSESHOW "link"
IF _MOUSEBUTTON(1) THEN AnimalSound word$
END IF
ELSE
_MOUSESHOW "default"
END IF
'keyboard access
k = _KEYHIT
_KEYCLEAR
_LIMIT 10
SELECT CASE k
CASE 65, 97 'a,A
AddTags word$
CASE 68, 100 'd,D
DeleteTags word$
CASE 32 'space
' _DELAY 1
SLEEP 1 ' Better for testing it
EXIT DO
CASE 27 'escape
SYSTEM 'quit
END SELECT
LOOP
NEXT Loop_it
LOOP
SUB AnimalSound (Word$)
ASound$ = _CWD$ + "\animal sounds\" + Word$ + ".mp3"
aAsound = _SNDOPEN(ASound$)
_SNDPLAY aAsound
DO WHILE _SNDPLAYING(aAsound)
IF LEN(INKEY$) THEN _SNDSTOP (aAsound): EXIT DO
LOOP
_SNDCLOSE aAsound
_MOUSESHOW "default"
END SUB
SUB GetNewWH (destWidth, destHeight, handle AS LONG, NewWidth, NewHeight) 'Sub return in variables NewWidth and NewHeight new image Width and image Height with the same ratio for optimal picture to set area width and height with [destWidth, destHeight]
W = _WIDTH(handle)
H = _HEIGHT(handle)
Pw = W / destWidth
Ph = H / destHeight
IF W > H THEN P = Pw ELSE P = Ph
NewWidth = W / P
NewHeight = H / P
END SUB
SUB Insert_10_Different_Images 'place 10 different indexes from array PhotoList
Max = UBOUND(photolist) 'PhotoList [1..?]
REDIM IMG10(9) AS LONG
pass = 0
DIM i_nr AS INTEGER
DO UNTIL pass = 10
st:
RANDOMIZE TIMER
i_nr = 1 + RND * Max
FOR t = 0 TO 9
IF IMG10(t) = i_nr THEN GOTO st
NEXT t
FOR t = 0 TO 9
IF IMG10(t) = 0 THEN IMG10(t) = i_nr: pass = pass + 1: EXIT FOR
NEXT t
LOOP
END SUB
SUB WordPlay (W AS STRING) 'will be replaced to my own mp3..... i never learn english, BUT I TRY IT.
'path$ = _CWD$ + "\Words\" + W$ + ".mp3"
'Word = _SNDOPEN(path$)
'_SNDPLAY Word
'DO WHILE _SNDPLAYING(Word): LOOP
FOR l = 1 TO LEN(W)
char = ASC(W, l)
IF char = 32 THEN _DELAY .5: _CONTINUE
_SNDPLAY AlphaSound(char)
_DELAY .35
NEXT l
END SUB
SUB BlankTop
LINE (0, 0)-(799, 49), &HFF000000, BF 'blank out the top info
END SUB
SUB AddTags (tfile$)
BlankTop
_FONT f1
LOCATE 1, 1: PRINT "Add Tag:";
INPUT tag$
IF tag$ <> "" THEN
u = UBOUND(phototags)
FOR i = 1 TO u
IF _STRICMP(tag$, PhotoTags(i)) = 0 THEN TagExists = -1: EXIT FOR
NEXT
IF NOT TagExists THEN
REDIM _PRESERVE PhotoTags(u + 1) AS STRING
PhotoTags(u + 1) = tag$
file$ = ".\Images\" + tfile$ + ".txt"
OPEN file$ FOR OUTPUT AS #1
FOR i = 1 TO u + 1
PRINT #1, "#";
PRINT #1, PhotoTags(i);
PRINT #1, " ";
NEXT
CLOSE
END IF
END IF
ShowTags
_FONT f
END SUB
SUB DeleteTags (tfile$)
BlankTop
_FONT f1
LOCATE 1, 1: PRINT "Delete Tag:";
INPUT tag$
IF tag$ <> "" THEN
u = UBOUND(phototags)
FOR i = 1 TO u
IF _STRICMP(tag$, PhotoTags(i)) = 0 THEN TagExists = -1: EXIT FOR
NEXT
IF TagExists THEN
FOR j = i TO u - 1
PhotoTags(j) = PhotoTags(j + 1)
NEXT
REDIM _PRESERVE PhotoTags(u - 1) AS STRING
file$ = ".\Images\" + tfile$ + ".txt"
OPEN file$ FOR OUTPUT AS #1
FOR i = 1 TO u - 1
PRINT #1, "#";
PRINT #1, PhotoTags(i);
PRINT #1, " ";
NEXT
CLOSE
END IF
END IF
ShowTags
_FONT f
END SUB
SUB GetTags (tfile$)
'Load the PhotoTags
file$ = ".\Images\" + tfile$ + ".txt"
OPEN file$ FOR BINARY AS #1
IF LOF(1) = 0 THEN 'if there's no tags, we can't get them.
CLOSE
REDIM _PRESERVE PhotoTags(0) AS STRING
EXIT SUB
END IF
DO UNTIL EOF(1)
LINE INPUT #1, junk$
l = 1
DO UNTIL l = 0
l = INSTR(junk$, "#")
IF l THEN
junk$ = MID$(junk$, l + 1)
l1 = INSTR(junk$, "#")
IF l1 = 0 THEN 'nothing more, we now have the tag
tag$ = junk$
l = 0
ELSE
tag$ = LEFT$(junk$, l1 - 1)
junk$ = MID$(junk$, l1)
END IF
END IF
tag$ = _TRIM$(tag$) 'no leading/tailing spaces for ease of matching
TagFound = 0
FOR i = 1 TO TagCount 'Check the existing tags to see if these exist
IF PhotoTags(i) = tag$ THEN TagFound = -1: EXIT FOR
NEXT
IF NOT TagFound THEN 'If not, add the new tags to the list
TagCount = TagCount + 1
IF TagCount > UBOUND(PhotoTags) THEN REDIM _PRESERVE PhotoTags(TagCount + 1000) AS STRING
PhotoTags(TagCount) = tag$
END IF
LOOP
LOOP
CLOSE
REDIM _PRESERVE PhotoTags(TagCount) AS STRING
END SUB
SUB ShowTags
BlankTop
_FONT f1
PRINT UBOUND(phototags); " TAGS: "
FOR i = 1 TO UBOUND(Phototags)
PRINT "#"; PhotoTags(i); " ";
NEXT
_FONT f
END SUB
SCREEN _NEWIMAGE(800,600,32)
CONST White = &HFFFFFFFF ‘bright white
COLOR White
PSET (0,0), White
IF POINT(0,0) = White THEN
PRINT “It matches”
ELSE
PRINT “You broke your program! Try UNSIGNED LONG instead!
END IF
I still do on it, but today not so fast...
So here is next develop version with icons (buttons). Tomorrow i try solving buttons reaction time (sometimes is loooong). Add new folder "Config" contains background image and icon image. Functional buttons:
next image, replay word, set volume, quit. Buttons for quiz and for test are not programmed.
This easy and very stupid code show, what i mean, if i say, that ON TIMER get out in middle in the loop:Code: QB64: [Select]
DIM f AS LONG
ON TIMER(.1) GOSUB timerdone
TIMER ON
DO
c = (c + 1) MOD 16
COLOR c
PRINT "COLOR "; c,
_LIMIT 10 'no need to use a lot of CPU; we're going to handle things VIA the timed routine
LOOP
timerdone:
IF NOT paused THEN
f = f + 1
PRINT "For next loop value is:"; f
END IF
k = _KEYHIT
IF k = 32 THEN GOSUB pausetimer
RETURN
pausetimer:
paused = NOT paused
RETURN
_SNDPLAY AlphaSound(a)
WHILE _SNDPLAYING(AlphaSound(a)) 'wait for sound to finish before playing again
_LIMIT 10 'play nice with CPU during wait
IF ControlVariable1 THEN _SNDSTOP (AlphaSound(a))
WEND
Steve.... i am very curious. How is this possible?
IF a3u$ = "$COLOR32" THEN
ColorHack = -1
It's actually a glitch which I didn't notice in the last BAS file I posted earlier.
If you open QB64.bas (which you downloaded from earlier), do a quick search for $COLOR32. At line 2981, you'll see where there's:Code: [Select]IF a3u$ = "$COLOR32" THEN
ColorHack = -1
This is where QB64 is now parsing the metacommand for $COLOR32. What it's doing is very simple -- it's actually just injecting those lines into your code (much like a native $INCLUDE statement would), and adding them to your available CONST list...
The glitch is rather simple: I didn't bother to parse those statements and add the values manually to the CONST list (it's a bunch of different TYPE values which we use to track them), since QB64 already parses and deals with them for us, as it reads our code. The glitch is that each time it processes them, it adds to the linecount for them -- all 200+ times!
Fix is really simple:
Add a line for: oldlinenumber = linenumber to the start of that IF block, and then linenumber = oldlinenumber to the end of that IF block (right before the GOTO which continues processing the rest of our code.
So that error you're getting isn't past the end of the file; your internal line counter is just off, until that one little glitch is corrected.
(There's always something simple like this, which is overlooked when making changes, which is why we have a development build for people to test these things, and a stable build so they don't have to worry about them.) ;D
Steve, because I don't have enough imagination, I ask you to elaborate on the idea. Five buttons. Good. Specifically, what to this 5 buttons have to do. Thanks for your patience.
$COLOR:32
TYPE TagType
Year AS INTEGER
Week AS INTEGER
Sound AS STRING
Theme AS STRING
END TYPE
SCREEN _NEWIMAGE(800, 600, 32)
_TITLE "Spell It Aloud"
RANDOMIZE TIMER
$IF WIN THEN
temp$ = MID$(_CWD$, _INSTRREV(_CWD$, "\") + 1)
$ELSE
temp$ = MID$(_CWD$, _INSTRREV(_CWD$, "/") + 1)
$END IF
IF temp$ <> "Spell It Aloud" THEN
PRINT "ERROR -- Program not in proper directory."
PRINT "Stopping execution..."
PRINT
PRINT "Please don't be a dufus, and fix it!"
END IF
CONST ImageDir$ = ".\Images\"
CONST SoundDir$ = ".\Alphabet Sounds\"
CONST TagDir$ = ".\Image Tags\"
CONST WordSoundDir$ = ".\Word Sounds\"
DIM SHARED PhotoTag AS TagType
DIM SHARED LimitTag AS TagType
DIM SHARED AlphaSound(65 TO 90)
REDIM SHARED PhotoList(100000) AS STRING
REDIM SHARED WordList(0) AS LONG
DIM SHARED PhotoCount AS LONG
DIM SHARED PhotoChosen AS LONG
DIM SHARED f AS LONG, f1 AS LONG
DIM SHARED IsHowYouSpell AS LONG
DIM SHARED ControlVariable1 AS LONG
DIM SHARED ShowNext AS LONG
'load our fonts
f = _LOADFONT("courbd.ttf", 84, "MONOSPACE")
f1 = _LOADFONT("courbd.ttf", 48, "MONOSPACE")
_FONT f
fw = _FONTWIDTH: fh = _FONTHEIGHT
'Load the alphabet sound library
FOR i = 65 TO 90
temp$ = SoundDir$ + CHR$(i) + ".ogg"
AlphaSound(i) = _SNDOPEN(temp$, "VOL,SYNC,LEN,PAUSE")
NEXT
temp$ = WordSoundDir$ + "is how you spell.ogg"
IsHowYouSpell = _SNDOPEN(temp$, "VOL,SYNC,LEN,PAUSE")
_FONT f
_DELAY 1 'Give everything a moment to initialize and get started for us.
WordList(0) = 3 'three times repeating the list, as default
ChangeSearchTags
ShowNext = -1
DO
ControlVariable = 0
WHILE _MOUSEINPUT: WEND
MB = _MOUSEBUTTON(1)
Mx = _MOUSEX: My = _MOUSEY
IF MB AND NOT oldmouse THEN
IF Mx >= 650 AND Mx <= 750 THEN 'the mouse is in the correct X area for input
SELECT CASE My
CASE 171 TO 190
temp$ = ChangeValue(650, 171, STR$(LimitTag.Year), -1)
LimitTag.Year = VAL(temp$)
ChangeSearchTags
ShowNext = -1
CASE 191 TO 210
temp$ = ChangeValue(650, 191, STR$(LimitTag.Week), -1)
LimitTag.Week = VAL(temp$)
ChangeSearchTags
ShowNext = -1
CASE 211 TO 230
temp$ = ChangeValue(650, 211, LimitTag.Sound, 0)
LimitTag.Sound = temp$
ChangeSearchTags
ShowNext = -1
CASE 231 TO 250
temp$ = ChangeValue(650, 231, LimitTag.Theme, 0)
LimitTag.Theme = temp$
ChangeSearchTags
ShowNext = -1
CASE 324 TO 340
PhotoTag.Year = VAL(ChangeValue(650, 324, STR$(PhotoTag.Year), -1))
ChangePhotoTags word$
ShowNext = -1: ControlVariable1 = -1
CASE 341 TO 360
PhotoTag.Week = VAL(ChangeValue(650, 341, STR$(PhotoTag.Week), -1))
ChangePhotoTags word$
ShowNext = -1: ControlVariable1 = -1
CASE 361 TO 380
PhotoTag.Sound = ChangeValue(650, 361, PhotoTag.Sound, 0)
ChangePhotoTags word$
ShowNext = -1: ControlVariable1 = -1
CASE 381 TO 400
PhotoTag.Theme = ChangeValue(650, 381, PhotoTag.Theme, 0)
ChangePhotoTags word$
ShowNext = -1: ControlVariable1 = -1
END SELECT
END IF
IF _MOUSEY > 450 AND _MOUSEY < 470 THEN 'it's the right Y pos for the top control buttons
SELECT CASE _MOUSEX
CASE 575 TO 640 'Last
PhotoChosen = PhotoChosen - 1
IF PhotoChosen < 1 THEN PhotoChosen = 1
ShowNext = -1
CASE 641 TO 705 'Play
ShowNext = -1
CASE 706 TO 770 'Next
PhotoChosen = PhotoChosen + 1
IF PhotoChosen > UBOUND(WordList) THEN PhotoChosen = 1
ShowNext = -1
END SELECT
ELSEIF _MOUSEY > 471 AND _MOUSEY < 491 THEN 'it's the right Y pos for the 2nd row of control buttons
SELECT CASE _MOUSEX
CASE 575 TO 640 'Vol not yet implemented
CASE 641 TO 705 'Stop now handled via the sound sub
CASE 706 TO 770: SYSTEM 'Quit
END SELECT
ELSEIF _MOUSEY > 495 AND _MOUSEY < 515 THEN 'it's in the review column
oldR = WordList(0)
R = (_MOUSEX - 641) / 26
IF R <> oldR THEN
IF R > 0 AND R < 5 THEN WordList(0) = INT(R + 1)
MakeList
ShowNext = -1
END IF
END IF
END IF
k = _KEYHIT
SELECT CASE k
CASE 32 'space for next picture
PhotoChosen = PhotoChosen + 1
IF PhotoChosen > WordList(0) THEN PhotoChosen = 1
ShowNext = -1
CASE 27 'escape
SYSTEM 'quit
END SELECT
IF ShowNext THEN
ShowNext = 0
IF PhotoChosen THEN
temp$ = PhotoList(WordList(PhotoChosen))
word$ = MID$(temp$, _INSTRREV(temp$, "\") + 1)
word$ = LEFT$(word$, INSTR(word$, ".") - 1)
IF tempimage <> 0 THEN _FREEIMAGE tempimage 'free the old image
tempimage = _LOADIMAGE(temp$, 32) 'get the new image
CLS
_FONT f1: CenterText 0, 0, 800, 50, "Spell It Aloud": _FONT f
'program photo area is 500 x 450 pixels. So:
GetNewWH 500, 450, tempimage, nW, nH
_PUTIMAGE (300 - (nW / 2), 300 - (nH / 2) - 25)-STEP(nW, nH), tempimage
LoadPhotoTags word$
temp$ = "Search Tags (" + _TRIM$(STR$(PhotoChosen)) + " of " + _TRIM$(STR$(UBOUND(wordlist))) + ")"
DisplayTags 575, 150, temp$, LimitTag
DisplayTags 575, 300, "Photo Tags", PhotoTag
DrawCommandBoxes
IF ControlVariable1 = 0 THEN PlayLetters word$
ELSE
DrawNoMatches
END IF
ControlVariable1 = 0
END IF
_LIMIT 10
_DISPLAY
oldmouse = MB
LOOP
SUB DrawCommandBoxes
s = SaveState
_FONT 16
COLOR Black, 0
BoxTitle 575, 450, 640, 470, 2, BlueGray, Gold, "LAST"
BoxTitle 641, 450, 705, 470, 2, BlueGray, Gold, "PLAY"
BoxTitle 706, 450, 770, 470, 2, BlueGray, Gold, "NEXT"
BoxTitle 575, 471, 640, 490, 2, BlueGray, Gold, "VOL"
COLOR Maroon
BoxTitle 641, 471, 705, 490, 2, BlueGray, Gold, "STOP"
COLOR Yellow
BoxTitle 706, 471, 770, 490, 2, BlueGray, Gold, "QUIT"
COLOR Black
BoxTitle 575, 495, 640, 515, 2, BlueGray, Gold, "REVIEW:"
R = WordList(0) '3
FOR i = 1 TO 5
IF i <> R THEN
COLOR LightGray
BoxTitle 641 + (i - 1) * 26, 495, 641 + i * 26, 515, 1, Black, Gold, STR$(i)
ELSE
COLOR White
BoxTitle 641 + (i - 1) * 26, 495, 641 + i * 26, 515, 1, BlueGray, Gold, STR$(i)
END IF
NEXT
RestoreState s
END SUB
SUB BoxTitle (x1, y1, x2, y2, thick, fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG, title$)
Box x1, y1, x2 - x1 + 1, y2 - y1 + 1, thick, fg, bg
CenterText x1, y1 + thick, x2, y2 + thick, title$
END SUB
SUB DrawNoMatches
S = SaveState
CLS
_FONT f1
Box 50, 50, 500, 500, 5, Silver, Gold
CenterText 0, 0, 800, 50, "Spell It Aloud"
FOR i = 1 TO 10 STEP .5
CIRCLE (300, 300), 200 - i, BrickRed
LINE (300 + SIN(_D2R(-45)) * 198 + i, 300 + COS(_D2R(-45)) * 198 + i)-(300 + SIN(_D2R(135)) * 198 + i, 300 + COS(_D2R(135)) * 198 + i), BrickRed
NEXT
COLOR Yellow, 0
CenterText 50, 50, 550, 550, "No Matches"
PhotoTag.Year = 0
PhotoTag.Week = 0
PhotoTag.Sound = ""
PhotoTag.Theme = ""
DisplayTags 575, 150, "Search Tags (0)", LimitTag
DisplayTags 575, 300, "Photo Tags", PhotoTag
RestoreState S
END SUB
SUB PlayLetters (word$)
'Put the letters to the screen one by one
ControlVariable1 = 0
pw = _PRINTWIDTH(word$): StartX = (600 - pw) \ 2 'center position
FOR i = 1 TO LEN(word$)
a = ASC(word$, i) AND NOT 32 'play lowercase letters as uppercase sounds
_PRINTSTRING (StartX + (i - 1) * _FONTWIDTH, 510), CHR$(a)
_DISPLAY
IF a < 65 OR a > 90 THEN _CONTINUE 'ignore non-letters in the file name
_SNDPLAY AlphaSound(a)
WHILE _SNDPLAYING(AlphaSound(a)) 'wait for sound to finish before playing again
_LIMIT 10 'play nice with CPU during wait
GOSUB checkstop
IF ControlVariable1 THEN _SNDSTOP (AlphaSound(a))
WEND
NEXT
IF ContolVariable1 = 0 THEN
temp$ = WordSoundDir$ + word$ + ".ogg"
IF _FILEEXISTS(temp$) THEN
_SNDVOL IsHowYouSpell, .5
_SNDPLAY IsHowYouSpell
WHILE _SNDPLAYING(IsHowYouSpell) 'wait for sound to finish before playing again
_LIMIT 10 'play nice with CPU during wait
GOSUB checkstop
IF ControlVariable1 THEN _SNDSTOP (IsHowYouSpell): EXIT SUB
WEND
temp = _SNDOPEN(temp$, "VOL,SYNC,LEN,PAUSE")
_SNDPLAY temp
WHILE _SNDPLAYING(temp) 'wait for sound to finish before playing again
_LIMIT 10 'play nice with CPU during wait
GOSUB checkstop
IF ControlVariable1 THEN _SNDCLOSE temp: EXIT SUB
WEND
_SNDCLOSE temp
FOR i = 1 TO LEN(word$)
a = ASC(word$, i) AND NOT 32 'play lowercase letters as uppercase sounds
_PRINTSTRING (StartX + (i - 1) * _FONTWIDTH, 510), CHR$(a)
IF a < 65 OR a > 90 THEN _CONTINUE 'ignore non-letters in the file name
_SNDPLAY AlphaSound(a)
WHILE _SNDPLAYING(AlphaSound(a)) 'wait for sound to finish before playing again
_LIMIT 10 'play nice with CPU during wait
GOSUB checkstop
IF ControlVariable1 THEN EXIT SUB
WEND
NEXT
END IF
END IF
EXIT SUB
checkstop:
WHILE _MOUSEINPUT: WEND
IF _MOUSEBUTTON(1) THEN
IF _MOUSEY > 451 AND _MOUSEY < 491 THEN
IF _MOUSEX > 575 AND _MOUSEX < 770 THEN 'stop
ControlVariable1 = -1 'Stop Command for playing the word
END IF
END IF
END IF
RETURN
END SUB
SUB ChangePhotoTags (word$)
'Get a listing of the files
file$ = TagDir$ + word$ + ".txt"
OPEN file$ FOR OUTPUT AS #1
PRINT #1, PhotoTag.Year
PRINT #1, PhotoTag.Week
PRINT #1, PhotoTag.Sound
PRINT #1, PhotoTag.Theme
CLOSE
END SUB
SUB LoadPhotoTags (word$)
file$ = TagDir$ + word$ + ".txt"
IF _FILEEXISTS(file$) THEN
OPEN file$ FOR INPUT AS #1
INPUT #1, PhotoTag.Year
INPUT #1, PhotoTag.Week
INPUT #1, PhotoTag.Sound
INPUT #1, PhotoTag.Theme
CLOSE
ELSE
PhotoTag.Year = 0
PhotoTag.Week = 0
PhotoTag.Sound = ""
PhotoTag.Theme = ""
IF word$ <> "" THEN ChangePhotoTags word$
END IF
END SUB
SUB ChangeSearchTags
'Get a listing of the files
PhotoList$ = ImageDir$ + "*.bmp " + ImageDir$ + "*.jpg " + ImageDir$ + "*.png " + ImageDir$ + "*.gif "
SHELL _HIDE "DIR " + PhotoList$ + "/b /s /a-d >PhotoList.txt"
REDIM _PRESERVE PhotoList(100000)
'Load those names into a file.
OPEN "Photolist.txt" FOR BINARY AS #1
PhotoCount = 0
DO UNTIL EOF(1)
LINE INPUT #1, fullpath$
word$ = MID$(fullpath$, _INSTRREV(fullpath$, "\") + 1)
word$ = LEFT$(word$, INSTR(word$, ".") - 1)
file$ = TagDir$ + word$ + ".txt"
IF _FILEEXISTS(file$) THEN
OPEN file$ FOR INPUT AS #2
INPUT #2, PhotoTag.Year
INPUT #2, PhotoTag.Week
INPUT #2, PhotoTag.Sound
INPUT #2, PhotoTag.Theme
ELSE
OPEN file$ FOR OUTPUT AS #2
PRINT #2, 0
PRINT #2, 0
PRINT #2, ""
PRINT #2, ""
END IF
CLOSE #2
good = -1
IF LimitTag.Year <> 0 AND LimitTag.Year <> PhotoTag.Year THEN good = 0
IF LimitTag.Week <> 0 AND LimitTag.Week <> PhotoTag.Week THEN good = 0
IF LimitTag.Sound <> "" AND LimitTag.Sound <> PhotoTag.Sound THEN good = 0
IF LimitTag.Theme <> "" AND LimitTag.Theme <> PhotoTag.Theme THEN good = 0
IF good THEN
PhotoCount = PhotoCount + 1
PhotoList(PhotoCount) = fullpath$
END IF
LOOP
REDIM _PRESERVE PhotoList(PhotoCount)
CLOSE
MakeList
END SUB
SUB MakeList
RepeatCount = WordList(0)
REDIM WordList(PhotoCount * RepeatCount) AS LONG
WordList(0) = RepeatCount
IF UBOUND(wordlist) > 0 THEN
PhotoChosen = 1
ELSE
PhotoChosen = 0
EXIT SUB
END IF
DIM TempList(PhotoCount) AS LONG
FOR i = 1 TO PhotoCount
TempList(i) = i
NEXT
FOR i = 1 TO RepeatCount
FOR j = 1 TO PhotoCount
r = INT(RND * PhotoCount) + 1
SWAP TempList(j), TempList(r)
NEXT
FOR j = 1 TO PhotoCount
Count = Count + 1
WordList(Count) = TempList(j)
NEXT
NEXT
END SUB
FUNCTION ChangeValue$ (x, y, tword$, limit)
S = SaveState
_FONT 16
temp$ = CHR$(179)
_KEYCLEAR
_AUTODISPLAY
DO
Box x, y, 100, 20, 1, Black, Gold
CenterText x, y, x + 100, y + 20, temp$
k = _KEYHIT
SELECT CASE k
CASE 8
tword$ = LEFT$(tword$, LEN(tword$) - 1)
CASE 13
EXIT DO
CASE 48 TO 57 'We'll always accept numeric input
tword$ = tword$ + CHR$(k)
CASE 65 TO 90, 97 TO 122 'A-Z (a-z) only when we're dealing with a string
IF NOT limit THEN tword$ = tword$ + CHR$(k)
END SELECT
temp$ = tword$ + CHR$(179)
_LIMIT 10
DisplayTags 575, 150, "Search Tags (" + _TRIM$(STR$(PhotoCount)) + ")", LimitTag
DisplayTags 575, 300, "Photo Tags", PhotoTag
LOOP
ChangeValue$ = tword$
RestoreState S
END SUB
SUB DisplayTags (x, y, Title AS STRING, DisplayTag AS TagType)
S = SaveState
_FONT 16
W = 200: h = 106
Box x, y, W, h, 2, BlueGray, Gold
COLOR Gold, 0
CenterText x, y + 2, x + 200, y + 20, Title
LINE (x + 1, y + 19)-STEP(W - 2, 0), Gold
COLOR White, 0
xs = x + 24: ys = y + 24 'x/y start after the box offset
_PRINTSTRING (xs, ys), "Year :"
_PRINTSTRING (xs, ys + 20), "Week :"
_PRINTSTRING (xs, ys + 40), "Sound:"
_PRINTSTRING (xs, ys + 60), "Theme:"
bxs = xs + 50: bys = ys - 2 'x/y start for the display boxes
FOR i = 0 TO 3
Box bxs, bys + i * 20, 100, 20, 1, Black, Gold
NEXT
CenterValue bxs, bys, bxs + 100, bys + 20, DisplayTag.Year
CenterValue bxs, bys + 20, bxs + 100, bys + 40, DisplayTag.Week
CenterText bxs, bys + 40, bxs + 100, bys + 60, DisplayTag.Sound
CenterText bxs, bys + 60, bxs + 100, bys + 80, DisplayTag.Theme
RestoreState S
END SUB
SUB Box (x, y, wide, high, thick, Kolor AS _UNSIGNED LONG, Trim AS _UNSIGNED LONG)
LINE (x, y)-STEP(wide, high), Kolor, BF
FOR i = 0 TO thick - 1
LINE (x + i, y + i)-STEP(wide - 2 * i, high - 2 * i), Trim, B
NEXT
END SUB
SUB CenterText (x1, y1, x2, y2, text$)
text$ = _TRIM$(text$)
xmax = x2 - x1: ymax = y2 - y1
textlength = _PRINTWIDTH(text$)
xpos = (xmax - textlength) / 2
ypos = (ymax - _FONTHEIGHT) / 2
_PRINTSTRING (x1 + xpos, y1 + ypos), text$
END SUB
SUB CenterValue (x1, y1, x2, y2, value AS LONG)
text$ = _TRIM$(STR$(value))
CenterText x1, y1, x2, y2, text$
END SUB
FUNCTION SaveState
TYPE SaveStateType
InUse AS INTEGER
DC AS INTEGER
BG AS INTEGER
F AS INTEGER
D AS INTEGER
S AS INTEGER
Disp AS INTEGER
CurX AS INTEGER
CurY AS INTEGER
END TYPE
DIM SS AS SaveStateType, Temp AS SaveStateType
SHARED NSS AS LONG 'Number of Saved States
SHARED SaveMem AS _MEM
IF NOT _MEMEXISTS(SaveMem) THEN
SaveMem = _MEMNEW(LEN(SS) * 255) 'Save up to 255 save states; More than 255 and we toss an error
$CHECKING:OFF
_MEMFILL SaveMem, SaveMem.OFFSET, SaveMem.SIZE, 0 AS _UNSIGNED _BYTE
$CHECKING:ON
END IF
'Data to Save
SS.InUse = -1
SS.F = _FONT
SS.DC = _DEFAULTCOLOR
SS.BG = _BACKGROUNDCOLOR
SS.D = _DEST
SS.S = _SOURCE
SS.Disp = _AUTODISPLAY
SS.CurX = POS(0)
SS.CurY = CSRLIN
$CHECKING:OFF
FOR i = 1 TO NSS
o = (i - 1) * LEN(SS)
_MEMGET SaveMem, SaveMem.OFFSET + o, Temp
IF Temp.InUse = 0 THEN
_MEMPUT SaveMem, SaveMem.OFFSET + o, SS
SaveState = i
EXIT FUNCTION
END IF
NEXT
_MEMPUT SaveMem, SaveMem.OFFSET + NSS * LEN(SS), SS
$CHECKING:ON
NSS = NSS + 1
SaveState = NSS
END SUB
SUB RestoreState (WhichOne AS LONG)
DIM SS AS SaveStateType
SHARED NSS AS LONG 'Number of Saved States
SHARED SaveMem AS _MEM
_MEMGET SaveMem, SaveMem.OFFSET + (WhichOne - 1) * LEN(SS), SS
$CHECKING:ON
IF SS.InUse THEN
SS.InUse = 0 'Let the routine know that we're no longer in use for this handle
$CHECKING:OFF
_MEMPUT SaveMem, SaveMem.OFFSET + (WhichOne - 1) * LEN(SS), SS
$CHECKING:ON
_FONT SS.F
COLOR SS.DC, SS.BG
_DEST SS.D
_SOURCE SS.S
IF SS.Disp THEN _AUTODISPLAY ELSE _DISPLAY
LOCATE SS.CurY, SS.CurX
END IF
END SUB
SUB GetNewWH (destWidth, destHeight, handle AS LONG, NewWidth, NewHeight) 'Sub return in variables NewWidth and NewHeight new image Width and image Height with the same ratio for optimal picture to set area width and height with [destWidth, destHeight]
W = _WIDTH(handle)
H = _HEIGHT(handle)
Pw = W / destWidth
Ph = H / destHeight
IF W > H THEN P = Pw ELSE P = Ph
NewWidth = W / P
NewHeight = H / P
END SUB