Author Topic: sprite editor  (Read 31246 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: sprite editor
« Reply #30 on: July 05, 2018, 04: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.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
Re: sprite editor
« Reply #31 on: July 05, 2018, 05: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
* myfiles.txt (Filesize: 6.44 KB, Downloads: 224)
Logic is the beginning of wisdom.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: sprite editor
« Reply #32 on: July 05, 2018, 05:20:16 am »
Thank you. I'll try what I can do with it.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: sprite editor
« Reply #33 on: July 05, 2018, 06: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: QB64: [Select]
  1. IF INSTR(1, _OS$, "WINDOWS") THEN cmd$ = "DIR >filelist.txt": user = 0
  2. IF INSTR(1, _OS$, "LINUX") THEN cmd$ = "ls -l -a *.* >filelist.txt": user = 1
  3.  
  4.  
  5. 'user = 1
  6.  
  7. SHELL cmd$ 'commented, because you use Linux
  8.  
  9. IF _FILEEXISTS("filelist.txt") THEN
  10.     SELECT CASE user
  11.         CASE 0 '                                                 windows
  12.             F = FREEFILE
  13.             OPEN "filelist.txt" FOR INPUT AS #F
  14.  
  15.             DO WHILE NOT EOF(F)
  16.                 LINE INPUT #F, value$
  17.                 infilePos = infilePos + 1
  18.                 IF infilePos > 4 THEN
  19.                     IF INSTR(1, value$, "<DIR>") THEN
  20.                         REDIM _PRESERVE Directories(D) AS STRING:
  21.                         Directories(D) = MID$(value$, 36, LEN(value$) - 35)
  22.                         D = D + 1
  23.                     ELSE
  24.                         REDIM _PRESERVE Filess(Fi) AS STRING:
  25.                         Filess(Fi) = MID$(value$, 36, LEN(value$) - 35)
  26.                         Fi = Fi + 1
  27.                     END IF
  28.                 END IF
  29.             LOOP
  30.             REDIM _PRESERVE Filess(Fi - 3) AS STRING 'delete 3 last records, because this are not files but summary in file
  31.  
  32.         CASE 1 '                                                 linux
  33.  
  34.             F = FREEFILE
  35.             OPEN "filelist.txt" FOR INPUT AS #F
  36.  
  37.             DO WHILE NOT EOF(F)
  38.                 LINE INPUT #F, value$
  39.                 infilePos = infilePos + 1
  40.                 IF infilePos > 1 THEN '                                 first line cotains "total...."
  41.                     IF LEFT$(value$, 1) = "d" THEN
  42.                         REDIM _PRESERVE Directories(D) AS STRING:
  43.                         Directories(D) = MID$(value$, 46, LEN(value$) - 45)
  44.                         D = D + 1
  45.                     ELSE
  46.                         REDIM _PRESERVE Filess(Fi) AS STRING:
  47.                         Filess(Fi) = MID$(value$, 46, LEN(value$) - 45)
  48.                         Fi = Fi + 1
  49.                     END IF
  50.                 END IF
  51.             LOOP
  52.             REDIM _PRESERVE Filess(Fi - 1) AS STRING 'last record is empty line in Linux
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.     END SELECT
  63. ELSE BEEP: PRINT "Error: filelist.txt file not found"
  64.  
  65.  
  66. Filter Filess(), "BMP JPG GIF PNG"
  67.  
  68. COLOR 14: PRINT "Directories list:": COLOR 7
  69. FOR Dl = 0 TO UBOUND(directories)
  70.     PRINT Directories(Dl)
  71.     IF Dl MOD 21 = 0 AND Dl > 0 THEN SLEEP: CLS: COLOR 14: PRINT "Directories list:": COLOR 7
  72. NEXT Dl
  73.  
  74. COLOR 14: PRINT "Files list:": COLOR 7
  75. FOR Dl = 0 TO UBOUND(filess)
  76.     PRINT Filess(Dl)
  77.     IF Dl MOD 21 = 0 AND Dl > 0 THEN SLEEP: CLS: COLOR 14: PRINT "Files list:": COLOR 7
  78. NEXT Dl
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. SUB Filter (fil() AS STRING, mask AS STRING)
  94.     FOR S = 1 TO LEN(mask$)
  95.         N = INSTR(S, mask$, " ")
  96.         oldmask$ = newmask$
  97.         newmask$ = MID$(mask$, N + 1, 3)
  98.         IF newmask$ <> oldmask$ THEN
  99.             REDIM _PRESERVE listmask(li) AS STRING
  100.             listmask(li) = newmask$
  101.             li = li + 1
  102.         END IF
  103.     NEXT S
  104.  
  105.     'sort files in array by mask:
  106.     DIM newfil(0) AS STRING
  107.     FOR Sort = 0 TO UBOUND(fil)
  108.         ext$ = RIGHT$(fil(Sort), 3)
  109.         FOR Searchmask = 0 TO UBOUND(listmask)
  110.             IF UCASE$(ext$) = UCASE$(listmask(Searchmask)) THEN
  111.                 REDIM _PRESERVE newfil(nn) AS STRING
  112.                 newfil(nn) = fil(Sort): nn = nn + 1
  113.             END IF
  114.         NEXT
  115.     NEXT
  116.  
  117.     'replace incomming array with filtered content:
  118.     REDIM fil(nn - 1) AS STRING
  119.     FOR rewr = 0 TO nn - 1
  120.         fil(rewr) = newfil(rewr)
  121.     NEXT rewr
  122.     ERASE newfil
  123.     ERASE listmask
  124.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
Re: sprite editor
« Reply #34 on: July 05, 2018, 06: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.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: sprite editor
« Reply #35 on: July 05, 2018, 07: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: QB64: [Select]
  1. IF INSTR(1, _OS$, "WINDOWS") THEN cmd$ = "DIR >filelist.txt": user = 0
  2. IF INSTR(1, _OS$, "LINUX") THEN cmd$ = "ls -l -a *.* >filelist.txt": user = 1
  3.  
  4.  
  5. 'user = 1
  6.  
  7. SHELL cmd$
  8.  
  9. IF _FILEEXISTS("filelist.txt") THEN
  10.     SELECT CASE user
  11.         CASE 0 '                                                 windows
  12.             F = FREEFILE
  13.             OPEN "filelist.txt" FOR INPUT AS #F
  14.  
  15.             DO WHILE NOT EOF(F)
  16.                 LINE INPUT #F, value$
  17.                 infilePos = infilePos + 1
  18.                 IF infilePos > 4 THEN
  19.                     IF INSTR(1, value$, "<DIR>") THEN
  20.                         REDIM _PRESERVE Directories(D) AS STRING:
  21.                         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.
  22.                         D = D + 1
  23.                     ELSE
  24.                         REDIM _PRESERVE Filess(Fi) AS STRING:
  25.                         Filess(Fi) = MID$(value$, 36, LEN(value$) - 35)
  26.                         Fi = Fi + 1
  27.                     END IF
  28.                 END IF
  29.             LOOP
  30.             REDIM _PRESERVE Filess(Fi - 3) AS STRING 'delete 3 last records, because this are not files but summary in file
  31.  
  32.         CASE 1 '                                                 linux
  33.  
  34.             F = FREEFILE
  35.             OPEN "filelist.txt" FOR INPUT AS #F
  36.  
  37.             DO WHILE NOT EOF(F)
  38.                 LINE INPUT #F, value$
  39.                 infilePos = infilePos + 1
  40.                 IF infilePos > 1 THEN '                                 first line cotains "total...."
  41.                     IF LEFT$(value$, 1) = "d" THEN
  42.                         REDIM _PRESERVE Directories(D) AS STRING:
  43.                         Directories(D) = MID$(value$, 46, LEN(value$) - 45)
  44.                         D = D + 1
  45.                     ELSE
  46.                         REDIM _PRESERVE Filess(Fi) AS STRING:
  47.                         Filess(Fi) = MID$(value$, 46, LEN(value$) - 45)
  48.                         Fi = Fi + 1
  49.                     END IF
  50.                 END IF
  51.             LOOP
  52.             REDIM _PRESERVE Filess(Fi - 1) AS STRING 'last record is empty line in Linux
  53.  
  54.         CASE ELSE
  55.             BEEP: PRINT "OS error": SLEEP 2: END
  56.     END SELECT
  57. ELSE BEEP: PRINT "Error: filelist.txt file not found"
  58.  
  59.  
  60. Filter Filess(), "BMP JPG GIF PNG"
  61.  
  62. COLOR 14: PRINT "Directories list:": COLOR 7
  63. PRINT "Found directories:"; D - 1: SLEEP 2
  64.  
  65. FOR Dl = 0 TO UBOUND(directories)
  66.     PRINT Directories(Dl)
  67.     IF Dl MOD 21 = 0 AND Dl > 0 THEN SLEEP: CLS: COLOR 14: PRINT "Directories list:": COLOR 7
  68. NEXT Dl
  69.  
  70. COLOR 14: PRINT "Files list:": COLOR 7
  71. PRINT "Found files:"; Fi - 1: SLEEP 2 ' return total files, not files using correct mask
  72. FOR Dl = 0 TO UBOUND(filess)
  73.     PRINT Filess(Dl)
  74.     IF Dl MOD 21 = 0 AND Dl > 0 THEN SLEEP: CLS: COLOR 14: PRINT "Files list:": COLOR 7
  75. NEXT Dl
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. SUB Filter (fil() AS STRING, mask AS STRING)
  91.     FOR S = 1 TO LEN(mask$)
  92.         N = INSTR(S, mask$, " ")
  93.         oldmask$ = newmask$
  94.         newmask$ = MID$(mask$, N + 1, 3)
  95.         IF newmask$ <> oldmask$ THEN
  96.             REDIM _PRESERVE listmask(li) AS STRING
  97.             listmask(li) = newmask$
  98.             li = li + 1
  99.         END IF
  100.     NEXT S
  101.  
  102.     'sort files in array by mask:
  103.     DIM newfil(0) AS STRING
  104.     FOR Sort = 0 TO UBOUND(fil)
  105.         ext$ = RIGHT$(fil(Sort), 3)
  106.         FOR Searchmask = 0 TO UBOUND(listmask)
  107.             IF UCASE$(ext$) = UCASE$(listmask(Searchmask)) THEN
  108.                 REDIM _PRESERVE newfil(nn) AS STRING
  109.                 newfil(nn) = fil(Sort): nn = nn + 1
  110.             END IF
  111.         NEXT
  112.     NEXT
  113.  
  114.     'replace incomming array with filtered content:
  115.     REDIM fil(nn - 1) AS STRING
  116.     FOR rewr = 0 TO nn - 1
  117.         fil(rewr) = newfil(rewr)
  118.     NEXT rewr
  119.     ERASE newfil
  120.     ERASE listmask
  121.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
Re: sprite editor
« Reply #36 on: July 05, 2018, 08: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.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: sprite editor
« Reply #37 on: July 05, 2018, 08:29:11 am »

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

Code: QB64: [Select]
  1. IF INSTR(1, _OS$, "WINDOWS") THEN cmd$ = "DIR >filelist.txt": user = 0
  2. IF INSTR(1, _OS$, "LINUX") THEN cmd$ = "ls -l -a *.* >filelist.txt": user = 1
  3.  
  4.  
  5. 'user = 1
  6.  
  7. SHELL cmd$
  8. IF _FILEEXISTS("filelist.txt") THEN
  9.     SELECT CASE user
  10.         CASE 0 '                                                 windows
  11.             F = FREEFILE
  12.             OPEN "filelist.txt" FOR INPUT AS #F
  13.  
  14.             DO WHILE NOT EOF(F)
  15.                 LINE INPUT #F, value$
  16.                 infilePos = infilePos + 1
  17.                 IF infilePos > 4 THEN
  18.                     IF INSTR(1, value$, "<DIR>") THEN
  19.                         REDIM _PRESERVE Directories(D) AS STRING:
  20.                         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.
  21.                         D = D + 1
  22.                     ELSE
  23.                         REDIM _PRESERVE Filess(Fi) AS STRING
  24.                         Filess(Fi) = MID$(value$, 36, LEN(value$) - 35)
  25.                         Fi = Fi + 1
  26.                     END IF
  27.                 END IF
  28.             LOOP
  29.  
  30.             REDIM _PRESERVE Filess(Fi - 3) AS STRING 'delete 3 last records, because this are not files but summary in file
  31.             n:
  32.         CASE 1 '                                                 linux
  33.  
  34.             F = FREEFILE
  35.             OPEN "filelist.txt" FOR INPUT AS #F
  36.             IF LOF(F) = 0 THEN BEEP: PRINT "Invalid file format. O bytes size found": END
  37.             DO WHILE NOT EOF(F)
  38.                 LINE INPUT #F, value$
  39.                 infilePos = infilePos + 1
  40.                 IF infilePos > 1 THEN '                                 first line cotains "total...."
  41.                     IF LEFT$(value$, 1) = "d" THEN
  42.                         REDIM _PRESERVE Directories(D) AS STRING
  43.                         Directories(D) = MID$(value$, 46, LEN(value$) - 45)
  44.                         D = D + 1
  45.                     ELSE
  46.                         REDIM _PRESERVE Filess(Fi) AS STRING
  47.                         Filess(Fi) = MID$(value$, 46, LEN(value$) - 45)
  48.                         Fi = Fi + 1
  49.                     END IF
  50.                 END IF
  51.             LOOP
  52.             REDIM _PRESERVE Filess(Fi - 1) AS STRING 'last record is empty line in Linux
  53.  
  54.         CASE ELSE
  55.             BEEP: PRINT "OS error": SLEEP 2: END
  56.     END SELECT
  57. ELSE BEEP: PRINT "Error: filelist.txt file not found"
  58.  
  59.  
  60. Filter Filess(), "BMP JPG GIF PNG", numfiles
  61.  
  62. COLOR 14: PRINT "Directories list:": COLOR 7
  63. PRINT "Found directories:": SLEEP 2
  64.  
  65. IF D > 0 THEN
  66.     FOR Dl = 0 TO UBOUND(directories)
  67.         PRINT Directories(Dl)
  68.         IF Dl MOD 21 = 0 AND Dl > 0 THEN SLEEP: CLS: COLOR 14: PRINT "Directories list:": COLOR 7
  69.     NEXT Dl
  70. ELSE PRINT "No directories found"
  71.  
  72. IF numfiles > 0 THEN
  73.     COLOR 14: PRINT "Files list:": COLOR 7
  74.     PRINT "Found files:"; numfiles: SLEEP 2 ' return total files, not files using correct mask
  75.     FOR Dl = 0 TO UBOUND(filess)
  76.         PRINT Filess(Dl)
  77.         IF Dl MOD 21 = 0 AND Dl > 0 THEN SLEEP: CLS: COLOR 14: PRINT "Files list:": COLOR 7
  78.     NEXT Dl
  79. ELSE PRINT "No files found."
  80.  
  81. 'text file test:
  82. PRINT "test created file:"
  83. PRINT "file lenght is"; LOF(F)
  84. OPEN "filelist.txt" FOR INPUT AS #1
  85. PRINT "in file is writed:"; SEEK(1)
  86.     LINE INPUT #1, ff$
  87.     PRINT ff$
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102. SUB Filter (fil() AS STRING, mask AS STRING, nn)
  103.     FOR S = 1 TO LEN(mask$)
  104.         n = INSTR(S, mask$, " ")
  105.         oldmask$ = newmask$
  106.         newmask$ = MID$(mask$, n + 1, 3)
  107.         IF newmask$ <> oldmask$ THEN
  108.             REDIM _PRESERVE listmask(li) AS STRING
  109.             listmask(li) = newmask$
  110.             li = li + 1
  111.         END IF
  112.     NEXT S
  113.  
  114.     'sort files in array by mask:
  115.     DIM newfil(0) AS STRING
  116.     FOR Sort = 0 TO UBOUND(fil)
  117.         ext$ = RIGHT$(fil(Sort), 3)
  118.         FOR Searchmask = 0 TO UBOUND(listmask)
  119.             IF UCASE$(ext$) = UCASE$(listmask(Searchmask)) THEN
  120.                 REDIM _PRESERVE newfil(nn) AS STRING
  121.                 newfil(nn) = fil(Sort): nn = nn + 1
  122.             END IF
  123.         NEXT
  124.     NEXT
  125.  
  126.     'replace incomming array with filtered content:
  127.     REDIM fil(nn - 1) AS STRING
  128.     FOR rewr = 0 TO nn - 1
  129.         fil(rewr) = newfil(rewr)
  130.     NEXT rewr
  131.     ERASE newfil
  132.     ERASE listmask
  133.  


Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: sprite editor
« Reply #38 on: July 05, 2018, 08:45:16 am »
Maybe i found it.... add space on line 2:

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

maybe this is the problem, bacause i write it without space between > and filelist.txt

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
Re: sprite editor
« Reply #39 on: July 05, 2018, 09: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



* ls.txt (Filesize: 7.69 KB, Downloads: 174)
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: sprite editor
« Reply #40 on: July 05, 2018, 09: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, 09:32:12 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: sprite editor
« Reply #41 on: July 05, 2018, 09: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. ;-))

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: sprite editor
« Reply #42 on: July 05, 2018, 10: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!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: sprite editor
« Reply #43 on: July 05, 2018, 10: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).

FellippeHeitor

  • Guest
Re: sprite editor
« Reply #44 on: July 05, 2018, 10: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