_TITLE "8x8 ASCII Character Editor" 'started 2018-08-27 by bplus 'QB64 X 64 version 1.2 20180228/86 from git b301f92
' 2020-09-18 Modify this to 8x8 Editor
' 2020-09-19 Make it better.
' fix: check if character set changes have been saved on exit.
' OK but almost doubled lines of code adding inputBox$ code,
' but it is the perfect job for inputBox$ !
' fix: alignment of text under the save character to set button. OK
' fix: previews of character as it is being changed. Done
'========================== Instructions: =================================
'
' Arrow keys move the highlighter around, spacebar toggles tile on/off
' or just click with mouse to do the same.
' Click buttons to either
' 1. Enter an ascii by number to edit.
' 2. Enter a character by pressing the key(s) from which the ascii number is taken.
' 3. Save a modified character.
' 4. Save all edits made to file called "8X8 Character Set.DAT".
'
' You must save character changes to update an array tracking data. 3rd button
' But you also must File this array data back to disk to save changes after Run.
' use the 4th button or be prompted.
' Note: If want to work with more sets, just rename Character Set.DAT
' If that file isn't found, this app will start from scratch.
'
'==========================================================================
CONST cFile$
= "8x8 Character Set.DAT"
'============================== main
'see if there is a file in the works to load else start from scratch
SAVED = -1 ' fine if no saved changed to characters
blank
= POINT(1, 1) 'why isn't black &HFF000000 ??? b$ = ""
CS(a) = b$
SAVED = 0 'haven't written this file yet
'FOR j = 0 TO 255 'checking characters
' CLS
' FOR i = 1 TO 64
' PRINT MID$(CS(j), i, 1);
' IF i MOD CW = 0 THEN PRINT
' NEXT
' IF j > 5 AND j < 32 THEN _CONTINUE
' PRINT: PRINT j, CHR$(j)
' PRINT
' INPUT "Ok, any + enter to quit ", w$
' IF LEN(w$) THEN EXIT FOR
'NEXT
'sample B for starters
AN% = 66 ' SHARED variable tracking the Ascii number we are modifying
load 66 'B for some reason the pixel on B is getting pressed, that was from check code above
CX = 1: CY = 1 ' this is the cursor position inside the pixel map of character
'ascii # to edit
LINE (500, 50)-(700, 100), BLACK
, BF
IF a%
>= 0 AND a%
<= 255 THEN AN%
= a%: load AN%
'chr$ to edit
LINE (500, 110)-(700, 160), BLACK
, BF
IF a%
>= 0 AND a%
<= 255 THEN AN%
= a%: load AN%
'save character edit
b$ = build$
CS(AN%) = b$
LINE (500, 170)-(700, 220), BLACK
, BF
SAVED = 0
'file character set
'mouse over edit box, toggle tiles and update cursor
tx = (mx - XOFF) \ SQ: ty = (my - YOFF) \ SQ
CX = tx: CY = ty
IF MAP
(CX
, CY
) = "1" THEN MAP
(CX
, CY
) = "0" ELSE MAP
(CX
, CY
) = "1" IF MAP
(CX
, CY
) = "1" THEN MAP
(CX
, CY
) = "0" ELSE MAP
(CX
, CY
) = "1" IF CY
- 1 >= 1 THEN CY
= CY
- 1 IF CY
+ 1 <= CH
THEN CY
= CY
+ 1 IF CX
- 1 >= 1 THEN CX
= CX
- 1 IF CX
+ 1 <= CW
THEN CX
= CX
+ 1
IF SAVED
= 0 THEN ' a message box would be nice ans$ = inputBox$("Do you want to save your changes to the set? (y for yes)", "Save changes before leaving?", 60)
update
FUNCTION build$
'need to do twice in program so a sub, take squares b$ = ""
b$ = b$ + MAP(x, y)
build$ = b$
SUB saveSet
' along with saving the set this displays a little message in save file button LINE (500, 230)-(700, 280), BLACK
, BF
SAVED = -1
SUB load
(asci
) ' loads 2D MAP array with 0's and 1's to make it easier to display y = i \ CW + 1
MAP
(x
, y
) = MID$(CS
(asci
), i
, 1)
drwBtn 500, 50, "Load map with Ascii"
drwBtn 500, 110, "Load map with Chr$"
drwBtn 500, 170, "Save Character Edit"
drwBtn 500, 230, "File Character Set"
IF SAVED
THEN s$
= " Saved." ELSE s$
= " not Saved yet." LINE (XOFF
- 1, YOFF
- 1)-STEP((CW
+ 2) * SQ
+ 2, (CH
+ 2) * SQ
+ 2), _RGB32(255, 255, 0), B
LINE (XOFF
+ 1, YOFF
+ 1)-STEP((CW
+ 2) * SQ
, (CH
+ 2) * SQ
), BLACK
, B
LINE (XOFF
, YOFF
)-STEP((CW
+ 2) * SQ
, (CH
+ 2) * SQ
), _RGB32(255, 80, 0), BF
LINE ((x
) * SQ
+ XOFF
, (y
) * SQ
+ YOFF
)-STEP(SQ
- 2, SQ
- 2), c&
, BF
' let's see actual size!
b$ = build$
FOR i
= 1 TO 4 'update Previews drwStr01 XOFF + 16 * (i * 2), .5 * YOFF - (8 * i) / 2, b$, i
'highlight sqr
LINE (CX
* SQ
- 1 + XOFF
, CY
* SQ
- 1 + YOFF
)-STEP(SQ
, SQ
), WHITE
, B
th
= 16: tw
= 8 * LEN(s$
): gray&
= _RGB32(190, 190, 190) LINE (x
+ 1, y
+ 1)-STEP(197, 47), gray&
, BF
SUB drwStr01
(x0
, y0
, s01$
, size
) 'what ever the present color is set at i = i + 1
IF MID$(s01$
, i
, 1) = "1" THEN LINE (x0
+ x
* size
, y0
+ y
* size
)-STEP(size
- 1, size
- 1), , BF
' for saving and restoring screen settins
COLOR DefaultColor
, BackGroundColor
' You can grab this box by title and drag it around screen for full viewing while answering prompt.
' Only one line allowed for prompt$
' boxWidth is 4 more than the allowed length of input, it needs to be longer than title$ and prompt$ also
' Utilities > Input Box > Input Box 1 tester v 2019-07-31
'colors
ForeColor = &HFF000055 '< change as desired prompt text color, back color or type in area
BackColor = &HFF6080CC '< change as desired used fore color in type in area
'items to restore at exit
scnState 0
'screen snapshot
'moving box around on screen
'draw message box
bxW = boxWidth * 8: bxH = 7 * 16
COLOR &HFF880000, &HFFFFFFFF COLOR &HFFFFFFFF, &HFFBB0000 COLOR ForeColor
, BackColor
'convert to pixels the top left corner of box at moment
bxW = boxWidth * 8: bxH = 5 * 16
tlx = (sw - bxW) / 2: tly = (sh - bxH) / 2
lastx = tlx: lasty = tly
'now allow user to move it around or just read it
IF mx
>= tlx
AND mx
<= tlx
+ bxW
AND my
>= tly
AND my
<= tly
+ 16 THEN 'mouse down on title bar grabx = mx - tlx: graby = my - tly
IF mx
- grabx
>= 0 AND mx
- grabx
<= sw
- bxW
AND my
- graby
>= 0 AND my
- graby
<= sh
- bxH
THEN 'attempt to speed up with less updates
IF ((lastx
- (mx
- grabx
)) ^ 2 + (lasty
- (my
- graby
)) ^ 2) ^ .5 > 10 THEN tlx = mx - grabx: tly = my - graby
lastx = tlx: lasty = tly
SELECT CASE kh&
'whew not much for the main event!
'put things back
scnState 1 'need fg and bg colors set to cls
CLS '? is this needed YES!! scnState 1 'because we have to call _display, we have to call this again
finishBox:
COLOR BackColor
, ForeColor