Author Topic: sprite editor  (Read 334 times)

Re: sprite editor
« Reply #30 on: July 05, 2018, 05:03:58 AM »
Quote
ls *.bas > files.txt works just fine and the list is sorted...

Johnno56, please add this file as an attachment, and I will work on it.  If you just want to browse the current folder, do this list without subdirectory names, but if you want to browse disk, then do it with subdirectory names. I want it to see how Linux marks folders (windows writes <DIR>) and whether the file contains characters for text formatting or not and also whether it contains a header or not. Because your editor will probably support more than just one format, you can not use the mask as * .BMP> file.txt, but better *. * , the appropriate files will then be filtered in program from this listing. So my program return then output for all PNG, BMP, JPG, GIF from this one text file.
Coding is relax (At least sometimes)

Offline johnno56

  • Live long and prosper.
Re: sprite editor
« Reply #31 on: July 05, 2018, 06:12:34 AM »
Another slight wrinkle. Unlike Windows, Linux is VERY particular with filenames, especially being case sensitive. For example: if Windows sees a file TeSt.TxT chances are it will see it as test.txt or TEST.TXT... Not with Linux. If the file test.txt exists and Linux is searching for TEST.TXT the test.txt file will be ignored.

If you want to see directories, the "ls" command will need to be told to include them. I am not familiar with all of the parameters for the "ls" command. This one I have used to create the file 'ls -l -a *.* > myfiles.txt

In the file, the character "d" at the begining of each record, indicates a directory.

I hope this helps.

J
Logic is the beginning of wisdom.

Re: sprite editor
« Reply #32 on: July 05, 2018, 06:20:16 AM »
Thank you. I'll try what I can do with it.
Coding is relax (At least sometimes)

Re: sprite editor
« Reply #33 on: July 05, 2018, 07:06:58 AM »
Johnno56, please try, if this first code works for you. It show you directories and files with mask *.BMP, *.JPG, *.PNG, *.GIF (regardless of the font size). If this work, I can proceed to the next stage and add it to the user interface for selecting files and directories. If there is a bug, write to me what the program does not like. Thank you.

Code: [Select]
IF INSTR(1, _OS$, "WINDOWS") THEN cmd$ = "DIR >filelist.txt": user = 0
IF INSTR(1, _OS$, "LINUX") THEN cmd$ = "ls -l -a *.* >filelist.txt": user = 1


'user = 1

SHELL cmd$ 'commented, because you use Linux

IF _FILEEXISTS("filelist.txt") THEN
    SELECT CASE user
        CASE 0 '                                                 windows
            F = FREEFILE
            OPEN "filelist.txt" FOR INPUT AS #F

            DO WHILE NOT EOF(F)
                LINE INPUT #F, value$
                infilePos = infilePos + 1
                IF infilePos > 4 THEN
                    IF INSTR(1, value$, "<DIR>") THEN
                        REDIM _PRESERVE Directories(D) AS STRING:
                        Directories(D) = MID$(value$, 36, LEN(value$) - 35)
                        D = D + 1
                    ELSE
                        REDIM _PRESERVE Filess(Fi) AS STRING:
                        Filess(Fi) = MID$(value$, 36, LEN(value$) - 35)
                        Fi = Fi + 1
                    END IF
                END IF
            LOOP
            REDIM _PRESERVE Filess(Fi - 3) AS STRING 'delete 3 last records, because this are not files but summary in file

        CASE 1 '                                                 linux

            F = FREEFILE
            OPEN "filelist.txt" FOR INPUT AS #F

            DO WHILE NOT EOF(F)
                LINE INPUT #F, value$
                infilePos = infilePos + 1
                IF infilePos > 1 THEN '                                 first line cotains "total...."
                    IF LEFT$(value$, 1) = "d" THEN
                        REDIM _PRESERVE Directories(D) AS STRING:
                        Directories(D) = MID$(value$, 46, LEN(value$) - 45)
                        D = D + 1
                    ELSE
                        REDIM _PRESERVE Filess(Fi) AS STRING:
                        Filess(Fi) = MID$(value$, 46, LEN(value$) - 45)
                        Fi = Fi + 1
                    END IF
                END IF
            LOOP
            REDIM _PRESERVE Filess(Fi - 1) AS STRING 'last record is empty line in Linux









    END SELECT
ELSE BEEP: PRINT "Error: filelist.txt file not found"

END IF

Filter Filess(), "BMP JPG GIF PNG"

COLOR 14: PRINT "Directories list:": COLOR 7
FOR Dl = 0 TO UBOUND(directories)
    PRINT Directories(Dl)
    IF Dl MOD 21 = 0 AND Dl > 0 THEN SLEEP: CLS: COLOR 14: PRINT "Directories list:": COLOR 7
NEXT Dl

COLOR 14: PRINT "Files list:": COLOR 7
FOR Dl = 0 TO UBOUND(filess)
    PRINT Filess(Dl)
    IF Dl MOD 21 = 0 AND Dl > 0 THEN SLEEP: CLS: COLOR 14: PRINT "Files list:": COLOR 7
NEXT Dl














SUB Filter (fil() AS STRING, mask AS STRING)
    FOR S = 1 TO LEN(mask$)
        N = INSTR(S, mask$, " ")
        oldmask$ = newmask$
        newmask$ = MID$(mask$, N + 1, 3)
        IF newmask$ <> oldmask$ THEN
            REDIM _PRESERVE listmask(li) AS STRING
            listmask(li) = newmask$
            li = li + 1
        END IF
    NEXT S

    'sort files in array by mask:
    DIM newfil(0) AS STRING
    FOR Sort = 0 TO UBOUND(fil)
        ext$ = RIGHT$(fil(Sort), 3)
        FOR Searchmask = 0 TO UBOUND(listmask)
            IF UCASE$(ext$) = UCASE$(listmask(Searchmask)) THEN
                REDIM _PRESERVE newfil(nn) AS STRING
                newfil(nn) = fil(Sort): nn = nn + 1
            END IF
        NEXT
    NEXT

    'replace incomming array with filtered content:
    REDIM fil(nn - 1) AS STRING
    FOR rewr = 0 TO nn - 1
        fil(rewr) = newfil(rewr)
    NEXT rewr
    ERASE newfil
    ERASE listmask
END SUB
Coding is relax (At least sometimes)

Offline johnno56

  • Live long and prosper.
Re: sprite editor
« Reply #34 on: July 05, 2018, 07:59:21 AM »
Error on line: "FOR Dl = 0 TO UBOUND(directories)"

Subscipt out of range

The filelist.txt file is created. Screen clears and only "Directories List:" is displayed then the error appears.
Logic is the beginning of wisdom.

Re: sprite editor
« Reply #35 on: July 05, 2018, 08:31:51 AM »
That's weird. It seems that the program found nothing in the file. Try this, it write how much  directories and files he found in file. Please add the created filelist.txt file. Thank you.

Code: [Select]
IF INSTR(1, _OS$, "WINDOWS") THEN cmd$ = "DIR >filelist.txt": user = 0
IF INSTR(1, _OS$, "LINUX") THEN cmd$ = "ls -l -a *.* >filelist.txt": user = 1


'user = 1

SHELL cmd$

IF _FILEEXISTS("filelist.txt") THEN
    SELECT CASE user
        CASE 0 '                                                 windows
            F = FREEFILE
            OPEN "filelist.txt" FOR INPUT AS #F

            DO WHILE NOT EOF(F)
                LINE INPUT #F, value$
                infilePos = infilePos + 1
                IF infilePos > 4 THEN
                    IF INSTR(1, value$, "<DIR>") THEN
                        REDIM _PRESERVE Directories(D) AS STRING:
                        Directories(D) = MID$(value$, 36, LEN(value$) - 35) 'every windows language version have set this differently. So if you see nonsense, modify this 36 and 35 numbers.
                        D = D + 1
                    ELSE
                        REDIM _PRESERVE Filess(Fi) AS STRING:
                        Filess(Fi) = MID$(value$, 36, LEN(value$) - 35)
                        Fi = Fi + 1
                    END IF
                END IF
            LOOP
            REDIM _PRESERVE Filess(Fi - 3) AS STRING 'delete 3 last records, because this are not files but summary in file

        CASE 1 '                                                 linux

            F = FREEFILE
            OPEN "filelist.txt" FOR INPUT AS #F

            DO WHILE NOT EOF(F)
                LINE INPUT #F, value$
                infilePos = infilePos + 1
                IF infilePos > 1 THEN '                                 first line cotains "total...."
                    IF LEFT$(value$, 1) = "d" THEN
                        REDIM _PRESERVE Directories(D) AS STRING:
                        Directories(D) = MID$(value$, 46, LEN(value$) - 45)
                        D = D + 1
                    ELSE
                        REDIM _PRESERVE Filess(Fi) AS STRING:
                        Filess(Fi) = MID$(value$, 46, LEN(value$) - 45)
                        Fi = Fi + 1
                    END IF
                END IF
            LOOP
            REDIM _PRESERVE Filess(Fi - 1) AS STRING 'last record is empty line in Linux

        CASE ELSE
            BEEP: PRINT "OS error": SLEEP 2: END
    END SELECT
ELSE BEEP: PRINT "Error: filelist.txt file not found"

END IF

Filter Filess(), "BMP JPG GIF PNG"

COLOR 14: PRINT "Directories list:": COLOR 7
PRINT "Found directories:"; D - 1: SLEEP 2

FOR Dl = 0 TO UBOUND(directories)
    PRINT Directories(Dl)
    IF Dl MOD 21 = 0 AND Dl > 0 THEN SLEEP: CLS: COLOR 14: PRINT "Directories list:": COLOR 7
NEXT Dl

COLOR 14: PRINT "Files list:": COLOR 7
PRINT "Found files:"; Fi - 1: SLEEP 2 ' return total files, not files using correct mask
FOR Dl = 0 TO UBOUND(filess)
    PRINT Filess(Dl)
    IF Dl MOD 21 = 0 AND Dl > 0 THEN SLEEP: CLS: COLOR 14: PRINT "Files list:": COLOR 7
NEXT Dl














SUB Filter (fil() AS STRING, mask AS STRING)
    FOR S = 1 TO LEN(mask$)
        N = INSTR(S, mask$, " ")
        oldmask$ = newmask$
        newmask$ = MID$(mask$, N + 1, 3)
        IF newmask$ <> oldmask$ THEN
            REDIM _PRESERVE listmask(li) AS STRING
            listmask(li) = newmask$
            li = li + 1
        END IF
    NEXT S

    'sort files in array by mask:
    DIM newfil(0) AS STRING
    FOR Sort = 0 TO UBOUND(fil)
        ext$ = RIGHT$(fil(Sort), 3)
        FOR Searchmask = 0 TO UBOUND(listmask)
            IF UCASE$(ext$) = UCASE$(listmask(Searchmask)) THEN
                REDIM _PRESERVE newfil(nn) AS STRING
                newfil(nn) = fil(Sort): nn = nn + 1
            END IF
        NEXT
    NEXT

    'replace incomming array with filtered content:
    REDIM fil(nn - 1) AS STRING
    FOR rewr = 0 TO nn - 1
        fil(rewr) = newfil(rewr)
    NEXT rewr
    ERASE newfil
    ERASE listmask
END SUB
Coding is relax (At least sometimes)

Offline johnno56

  • Live long and prosper.
Re: sprite editor
« Reply #36 on: July 05, 2018, 09:07:04 AM »
This time a window popped displaying;
Directories list:
Found Directories:-1

Moments later an error:
Unhandled error #9
Line: 66 (in main module)
Subscipt out of range
Continue?
Yes No

Logic is the beginning of wisdom.

Re: sprite editor
« Reply #37 on: July 05, 2018, 09:29:11 AM »

Good. File size fileslist.txt is not 0 bytes? Please try this again.

Code: [Select]
IF INSTR(1, _OS$, "WINDOWS") THEN cmd$ = "DIR >filelist.txt": user = 0
IF INSTR(1, _OS$, "LINUX") THEN cmd$ = "ls -l -a *.* >filelist.txt": user = 1


'user = 1

SHELL cmd$
_DELAY 1
IF _FILEEXISTS("filelist.txt") THEN
    SELECT CASE user
        CASE 0 '                                                 windows
            F = FREEFILE
            OPEN "filelist.txt" FOR INPUT AS #F

            DO WHILE NOT EOF(F)
                LINE INPUT #F, value$
                infilePos = infilePos + 1
                IF infilePos > 4 THEN
                    IF INSTR(1, value$, "<DIR>") THEN
                        REDIM _PRESERVE Directories(D) AS STRING:
                        Directories(D) = MID$(value$, 36, LEN(value$) - 35) 'every windows language version have set this differently. So if you see nonsense, modify this 36 and 35 numbers.
                        D = D + 1
                    ELSE
                        REDIM _PRESERVE Filess(Fi) AS STRING
                        Filess(Fi) = MID$(value$, 36, LEN(value$) - 35)
                        Fi = Fi + 1
                    END IF
                END IF
            LOOP

            REDIM _PRESERVE Filess(Fi - 3) AS STRING 'delete 3 last records, because this are not files but summary in file
            n:
        CASE 1 '                                                 linux

            F = FREEFILE
            OPEN "filelist.txt" FOR INPUT AS #F
            IF LOF(F) = 0 THEN BEEP: PRINT "Invalid file format. O bytes size found": END
            DO WHILE NOT EOF(F)
                LINE INPUT #F, value$
                infilePos = infilePos + 1
                IF infilePos > 1 THEN '                                 first line cotains "total...."
                    IF LEFT$(value$, 1) = "d" THEN
                        REDIM _PRESERVE Directories(D) AS STRING
                        Directories(D) = MID$(value$, 46, LEN(value$) - 45)
                        D = D + 1
                    ELSE
                        REDIM _PRESERVE Filess(Fi) AS STRING
                        Filess(Fi) = MID$(value$, 46, LEN(value$) - 45)
                        Fi = Fi + 1
                    END IF
                END IF
            LOOP
            REDIM _PRESERVE Filess(Fi - 1) AS STRING 'last record is empty line in Linux

        CASE ELSE
            BEEP: PRINT "OS error": SLEEP 2: END
    END SELECT
ELSE BEEP: PRINT "Error: filelist.txt file not found"

END IF

Filter Filess(), "BMP JPG GIF PNG", numfiles

COLOR 14: PRINT "Directories list:": COLOR 7
PRINT "Found directories:": SLEEP 2

IF D > 0 THEN
    FOR Dl = 0 TO UBOUND(directories)
        PRINT Directories(Dl)
        IF Dl MOD 21 = 0 AND Dl > 0 THEN SLEEP: CLS: COLOR 14: PRINT "Directories list:": COLOR 7
    NEXT Dl
ELSE PRINT "No directories found"
END IF

IF numfiles > 0 THEN
    COLOR 14: PRINT "Files list:": COLOR 7
    PRINT "Found files:"; numfiles: SLEEP 2 ' return total files, not files using correct mask
    FOR Dl = 0 TO UBOUND(filess)
        PRINT Filess(Dl)
        IF Dl MOD 21 = 0 AND Dl > 0 THEN SLEEP: CLS: COLOR 14: PRINT "Files list:": COLOR 7
    NEXT Dl
ELSE PRINT "No files found."
END IF
SLEEP 2

'text file test:
PRINT "test created file:"
PRINT "file lenght is"; LOF(F)
CLOSE #F
OPEN "filelist.txt" FOR INPUT AS #1
PRINT "in file is writed:"; SEEK(1)
DO WHILE NOT EOF(1)
    LINE INPUT #1, ff$
    PRINT ff$
LOOP
CLOSE














SUB Filter (fil() AS STRING, mask AS STRING, nn)
    FOR S = 1 TO LEN(mask$)
        n = INSTR(S, mask$, " ")
        oldmask$ = newmask$
        newmask$ = MID$(mask$, n + 1, 3)
        IF newmask$ <> oldmask$ THEN
            REDIM _PRESERVE listmask(li) AS STRING
            listmask(li) = newmask$
            li = li + 1
        END IF
    NEXT S

    'sort files in array by mask:
    DIM newfil(0) AS STRING
    FOR Sort = 0 TO UBOUND(fil)
        ext$ = RIGHT$(fil(Sort), 3)
        FOR Searchmask = 0 TO UBOUND(listmask)
            IF UCASE$(ext$) = UCASE$(listmask(Searchmask)) THEN
                REDIM _PRESERVE newfil(nn) AS STRING
                newfil(nn) = fil(Sort): nn = nn + 1
            END IF
        NEXT
    NEXT

    'replace incomming array with filtered content:
    REDIM fil(nn - 1) AS STRING
    FOR rewr = 0 TO nn - 1
        fil(rewr) = newfil(rewr)
    NEXT rewr
    ERASE newfil
    ERASE listmask
END SUB

Coding is relax (At least sometimes)

Re: sprite editor
« Reply #38 on: July 05, 2018, 09:45:16 AM »
Maybe i found it.... add space on line 2:

Code: [Select]
IF INSTR(1, _OS$, "LINUX") THEN cmd$ = "ls -l -a *.* > filelist.txt": user = 1

maybe this is the problem, bacause i write it without space between > and filelist.txt
Coding is relax (At least sometimes)

Offline johnno56

  • Live long and prosper.
Re: sprite editor
« Reply #39 on: July 05, 2018, 10:22:38 AM »
That seems to have done the trick. No errors that time!

It said that it found directories but did not display them.
Found 8 files and displayed various graphics files of different formats.
Then displayed the filelist.

Maybe the list I provided is not what is needed. I will attach the "ls" command manual for you to read... It's not really a manual... That is what Linux calls it. It's about 2 or 3 pages long. Perhaps you can make some sense of it all... I'm getting too tired to think straight...

J



Logic is the beginning of wisdom.

Offline bplus

  • B = B + geberation
Re: sprite editor
« Reply #40 on: July 05, 2018, 10:30:43 AM »
This app might be suited for InForm. Is there an example of with InForm catching mouse clicks over a picture box?

I know the Load button could made into a drop down list box when you guys manage to get files data from OS.
« Last Edit: July 05, 2018, 10:32:12 AM by bplus »
B = B + ...

Offline bplus

  • B = B + geberation
Re: sprite editor
« Reply #41 on: July 05, 2018, 10:49:43 AM »
Another way to go for getting a pathed filename (to load):

Open a file explorer in your favorite OS

Then copy/paste a file name from clipboard Or just type the dang thing out.     I hear Linux users love to type. ;-))
B = B + ...

Offline bplus

  • B = B + geberation
Re: sprite editor
« Reply #42 on: July 05, 2018, 11:05:26 AM »
Modify

More thoughts on using InForm:

Instead of loading a limited color palette, you could use 3 slider bars for RGB and create custom colors on the fly!

Think of all the code that could be slashed from the Sprite Editor with just that one move!
B = B + ...

Offline bplus

  • B = B + geberation
Re: sprite editor
« Reply #43 on: July 05, 2018, 11:11:46 AM »
Modify

Hmm... I wonder about reversing that process, click a point from the blown up image and set color selector to that color (along with the slider bars).
B = B + ...

Online FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: sprite editor
« Reply #44 on: July 05, 2018, 11:23:46 AM »
All of that sounds very possible with InForm indeed. Here's a sample that catches clicks on a picturebox control: https://www.qb64.org/forum/index.php?topic=254.0