QB64.org Forum

Active Forums => Programs => Topic started by: johnno56 on July 03, 2018, 04:03:49 am

Title: sprite editor
Post by: johnno56 on July 03, 2018, 04:03:49 am
I decided to 'dust off' my old incomplete sdlbasic sprite editor in the hope of getting it to work. Conversion is going slow but I have come up against an interesting 'random feature'.

When a sprite is loaded, it is placed into a 'preview' box. The image is scanned, using the point() command, then places the colour into an array whilst, at the same time, translating the image to the main display. All of this function works just fine... except... the colours are different. See the screen dump. Nothing is done to the pixels. Point picks up the colour and places it in the main display.

Has anyone had this kind of problem before?

J
Title: Re: sprite editor
Post by: johnno56 on July 03, 2018, 07:00:59 am
Here is a simple test. I cannot understand why the colours are different.

J

ps: Change the path...
Title: Re: sprite editor
Post by: bplus on July 03, 2018, 07:48:10 am
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2. ' >>>>>>>>>>>>>>>>> path$ = "/home/john/Desktop/spriteditor/"
  3. patch = _LOADIMAGE("colourpatch.png")
  4. _PUTIMAGE (10, 10), patch
  5.  
  6. DIM current AS LONG '<<<<<<<<<<<<<<<<< simple type problem, colors need big integers _UNSIGNED LONG better for alpha range
  7.  
  8.  
  9.     mx = _MOUSEX
  10.     my = _MOUSEY
  11.     mb = _MOUSEBUTTON(1)
  12.  
  13.     LINE (120, 220)-(152, 252), _RGB32(90, 90, 90), B
  14.  
  15.     IF mx > 10 AND mx < 284 AND my > 10 AND my < 200 AND POINT(mx, my) <> _RGB32(90, 90, 90) AND mb THEN
  16.         current = POINT(mx, my)
  17.         LINE (121, 221)-(151, 251), current, BF
  18.     END IF
Title: Re: sprite editor
Post by: johnno56 on July 03, 2018, 08:10:35 am
Ah, ya blood's worth bottling! Worked for 'testing.bas' and for the editor. Very cool... :D

Many thanks...

J
Title: Re: sprite editor
Post by: Petr on July 03, 2018, 08:37:51 am
The same effect is, if you use &, because & = LONG:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2. path$ = "/home/john/Desktop/spriteditor/"
  3. patch = _LOADIMAGE("colourpatch.png")
  4. _PUTIMAGE (10, 10), patch
  5.  
  6.  
  7.  
  8.     mx = _MOUSEX
  9.     my = _MOUSEY
  10.     mb = _MOUSEBUTTON(1)
  11.  
  12.     LINE (120, 220)-(152, 252), _RGB32(90, 90, 90), B
  13.  
  14.     IF mx > 10 AND mx < 284 AND my > 10 AND my < 200 AND POINT(mx, my) <> _RGB32(90, 90, 90) AND mb THEN
  15.         current& = POINT(mx, my)
  16.         LINE (121, 221)-(151, 251), current&, BF
  17.     END IF
  18.  

Title: Re: sprite editor
Post by: johnno56 on July 03, 2018, 11:26:54 am
Thanks Petr. One character! Saved some sore fingers there... lol

J
Title: Re: sprite editor
Post by: johnno56 on July 03, 2018, 09:57:43 pm
This is the editor so far... VERY limited functionality. Again, change the file path to your taste...

This is my first attempt at converting my 'non completed' editor from sdlbasic to qb64. I know, before you say anything, the coding is terribly sloppy.

What works... hmm... interesting...

Colour selection works..
Drawing on the main grid works...
"New" works...
"Load" works but is limited to a specific file...
"Save"... not yet..
"Quit" works... The only part that functioned flawlessly from the start! Who woulda thought?

BIG thanks to bplus and petr for their tips with my colour problem...

Still LOTS to do!! There are FAR too many 'If.. Then's for my liking but it seems to work ok...

As usual, any 'constructive' criticism is welcomed as is any reasonable suggestion (my skills are quite limited... lol)

Let me know what you think?

J
Title: Re: sprite editor
Post by: bplus on July 04, 2018, 08:34:34 am
Johnno, is this along the same lines of what we did in Naalaa?
Title: Re: sprite editor
Post by: johnno56 on July 04, 2018, 09:25:51 am
Oh nuts! The secret is out! nah kidding...

Yeah, basically (no pun intended)... Trying my hand at converting to QB64. The program is far from finished... crumbs, never got very far with sdl. I know and editor has been 'done to death' and I know that there are other editors 'out there' but I'm not going to learn anything if I don't to it myself.... lol  I may never finish it, but that's not the point, is it?

Yeah, I think someone else is trying their hand, using Naalaa. I think I wrote sprEdit in late 2014 and it ended up migrating to Naalaa earlier this year and has been gathering dust ever since... *sigh*  Maybe I'll have better luck here... crossed fingers...

Have you tried it yet? I have spent more time on since posting, cosmetics mainly, but slowly plugging away at it... I still need to check out how to save and load to and from the file system... What's the point of writing this beastie if you can't save your work? lol  Once that bit is done then I can start looking at how to implement other drawing tools. eg: circles (ellipses); boxes; lines; fill (the dreaded fill - my aching back...) Perhaps different modes? ie: 8x8, 16x16 etc. (my very early version had these... but I think I lost it in a drive crash... Just simple 'buttons' containing "8" and "16" and the main grid would change accordingly (handy for retro sprites)... anyway, just some ideas... Saving to files.... hmmm...
Title: Re: sprite editor
Post by: bplus on July 04, 2018, 09:40:01 am
Yes, I just tried it and had to cut path in line 306 so the file loads from same folder as source.

I'd say work on saving a file to same folder as source, use a time stamped name so you don't have to worry about getting input about file name from user or loosing your title 01 sample file. Let Windows or your OS do the work of renaming the file if you really want to save the file with a real name.

Too much concern for color names for my taste, but not my app! ;-))

Naalaa was nice little editor, we had gone a long way with it. I will see if I can dig it up. ;)
Title: Re: sprite editor
Post by: johnno56 on July 04, 2018, 10:12:46 am
I tried having the just the file in the same directory, but for some reason and I think it maybe Linux related, qb64 would alway kick up a fuss unless the full path was given. It's no big deal for me as I'm used to it... lol

My very first version was tedious. I had a colour patch with way more colours than a bag of Skittles and each colour square had it's rgb code and paint command... sore fingers THAT day!! You're right about the names. They are only there for my benefit. It's simple enough just to leave out.

I'm still toying with the idea to change the colour patch... the current one seem to be all over the place.

Hey. I went looking for the first version on another disc and found it... Horrible code. Simply horrible. I don't know what I was thinking. But it DID have two main grid sizes 10 an 20 pixels (for 16x16 and 32x32)

Well. It's just gone midnight and my eyes are struggling to stay open...  I've started tidying up the listing a little by using subs and comments. Since the last version I had put all the colour names and rgb codes into an external file. Made for a slightly smaller listing... I'll do some more in the morning, and if I remember, I may post an update. But, it's only cosmetic, no real advancement... lol

My mug of coffee has finally worn off... Goodnight.

J
Title: Re: sprite editor
Post by: bplus on July 04, 2018, 10:23:44 am
Now I have a question, how do you save a file with say, a .png format?
Title: Re: sprite editor
Post by: Petr on July 04, 2018, 11:00:26 am
Hi Johnno56. I'm interested in this topic, but unfortunately I'm just on the way away. I'll add some suggestions to you later. I made my video editor (it was an experiment, so it only knows two colors), the output can be seen for example at Voleyball game. Did you see her? I add it here and I also add a Galleon program that lets you save your images to BMP format.

GalleonĀ“s save utility:
Code: QB64: [Select]
  1. 'program create file CIRCLE.BMP on your harddrive (tested in windows)
  2.  
  3. circleimage& = _NEWIMAGE(320, 240, 32) '                                     create virtual screen
  4. _DEST circleimage&
  5. CIRCLE (160, 120), 120, _RGB32(255, 0, 0)
  6. PAINT (160, 120), _RGB32(255, 0, 0), _RGB32(255, 0, 0)
  7. SaveImage circleimage&, "CIRCLE.BMP"
  8. _FREEIMAGE circleimage&
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21. SUB SaveImage (image AS LONG, filename AS STRING)
  22.     bytesperpixel& = _PIXELSIZE(image&)
  23.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  24.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  25.     x& = _WIDTH(image&)
  26.     y& = _HEIGHT(image&)
  27.     b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + STRING$(16, 0) 'partial BMP header info(???? to be filled later)
  28.     IF bytesperpixel& = 1 THEN
  29.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  30.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  31.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  32.         NEXT
  33.     END IF
  34.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  35.     lastsource& = _SOURCE
  36.     _SOURCE image&
  37.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  38.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  39.         r$ = ""
  40.         FOR px& = 0 TO x& - 1
  41.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  42.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  43.         NEXT px&
  44.         d$ = d$ + r$ + padder$
  45.     NEXT py&
  46.     _SOURCE lastsource&
  47.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  48.     b$ = b$ + d$ ' total file data bytes to create file
  49.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  50.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  51.     f& = FREEFILE
  52.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  53.     OPEN filename$ + ext$ FOR BINARY AS #f&
  54.     PUT #f&, , b$
  55.     CLOSE #f&
  56.  

Title: Re: sprite editor
Post by: FellippeHeitor on July 04, 2018, 12:08:05 pm
Steve has a library somewhere to export images to PNG format too.
Title: Re: sprite editor
Post by: FellippeHeitor on July 04, 2018, 12:22:31 pm
Here's Steve's SaveImage library: http://qb64.freeforums.net/thread/55/save-image-library
Title: Re: sprite editor
Post by: bplus on July 04, 2018, 12:34:00 pm
Thanks Petr, Fellippe and Steve!

Johnno needs to update image as drawn, already tested Petr's save, worked great!
Title: Re: sprite editor
Post by: bplus on July 04, 2018, 12:36:36 pm
and thanks to Galleon!
Title: Re: sprite editor
Post by: johnno56 on July 04, 2018, 04:21:52 pm
Sorry. Cannot use 'saveimage'. All files placed with my program's directory. Placed the appropriate 'include' lines at the top and bottom. Before I can even execute the editor I get the error message, "DYNAMIC LIBRARY not found in line 2 of /home/john/Desktop/spriteditor/SaveImage.BI included on line 1"
The dll reffered to is 'zlib1'

I'm going to go out on a limb here and suggest that the saveimage library is for Windows only.... Just a guess.

J
Title: Re: sprite editor
Post by: FellippeHeitor on July 04, 2018, 04:32:02 pm
It does use the dll that Steve provides in the package so yes, it's Windows only (and I failed to remember you're a Linux user, sorry about that).

If anyone using Windows would like to try the library, just make sure to fix SaveImage.BI file to make the declare library line reference the .dll file using a relative path by adding ".\" to the file name:

Code: QB64: [Select]
Title: Re: sprite editor
Post by: johnno56 on July 04, 2018, 05:00:24 pm
What I need to know is, Does QB64 have the ability to pop up the OS's Save or Load GUI so as to either display all the previous files or give you the choice to enter a new filename. eg: Using MSPaint: If you select "File", from the top menu bar, a GUI panel pops up so that you can either 'Load' or 'Save' a file... That sort of thing...

Using variations of "get" and "put" still requires the user to "remember" the name of the file to load (or do a previous search for the filename)

This is exactly the same problem I had when I first started this editor using sdlbasic back in 2014. The upside is that I have learned some stuff about QB64 that I didn't know before... Cool.

Now. How about a nice game of Pong.... lol
Title: Re: sprite editor
Post by: FellippeHeitor on July 04, 2018, 05:21:20 pm
If you were using Windows, you could just call the API and have the default dialogs show. For Linux, no easy deal.
Title: Re: sprite editor
Post by: Petr on July 04, 2018, 05:45:05 pm
Hi Johnno56, it can be programmed. I would do this by creating a text file into which the program would store the last open file (a list of the last 20 open files and a path, that's not a problem), - if you mean doing this into a sprite editor. I can write it to you if you want to. I mean something similar to the IDE menu: File / Recent. It will only read a text file, and after the confirmation, the link you are pointing to will open.  In addition, I add a small sample of the sprite editor who does not do anything. :-D Use the arrows and the mouse wheel. This is the basis, tomorrow, if have time, if you want, I can add this Recent menu. Perhaps on the top edge, after mouse move to this area, what do you say?
Unfortunately, I can not help you with program for selecting files on a Linux disk if you mean this and you want to move around on the disk to select the file for editing. I have none knowledge in this - in Linux.

Code: QB64: [Select]
  1. 'sprite editor - base:
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. 'first i load a picture and show it in grid:
  4. i& = _LOADIMAGE("bart.jpg", 32) '200 x 200 px image
  5.  
  6. grid = 5: W = _WIDTH(i&): H = _HEIGHT(i&)
  7. PutToArray D(), i&: _FREEIMAGE i&
  8.  
  9.         IF _MOUSEWHEEL THEN grid = grid + _MOUSEWHEEL: LINE (10, 10)-(500 + grid, 500 + grid), _RGB32(0, 0, 0), BF
  10.     WEND
  11.     IF grid > 25 THEN grid = 25
  12.     IF grid < 3 THEN grid = 3
  13.     CreateGrid D(), 10, 10, 500, 500, grid, a, b
  14.  
  15.     'keyboard for grid move (arrows)
  16.         CASE 19200: a = a - 1 'left arrow
  17.         CASE 19712: a = a + 1 'right arrow
  18.         CASE 18432: b = b - 1 ' up arrow
  19.         CASE 20480: b = b + 1 'down arrow
  20.     END SELECT
  21.     IF a < 0 THEN a = 0
  22.     IF b < 0 THEN b = 0
  23.     cellsX = (500 - 10) / grid
  24.     cellsY = (500 - 10) / grid 'so is writed call for CreateGrid, for X is 1st and 3th parameter, for Y is 2nd and 4th parameter
  25.     IF a > W - cellsX - 1 THEN a = W - cellsX - 1
  26.     IF b > H - cellsY - 1 THEN b = H - cellsY - 1
  27.     _DISPLAY
  28.  
  29.  
  30.  
  31.  
  32.  
  33. SUB CreateGrid (D( x , y) AS LONG, PosXStart, PosYStart, PosXend, PosYend, ElementSize, a, b)
  34.  
  35.     xx = a: yy = b 'draw start array values
  36.  
  37.  
  38.     FOR Y = PosYStart TO PosYend STEP ElementSize
  39.         FOR X = PosXStart TO PosXend STEP ElementSize
  40.             IF xx > UBOUND(D, 1) OR yy > UBOUND(d, 2) OR xx < LBOUND(d, 1) OR yy < LBOUND(d, 2) THEN EXIT SUB
  41.             clr& = D(xx, yy)
  42.             LINE (X, Y)-(X + ElementSize - 1, Y + ElementSize - 1), clr&, BF
  43.             LINE (X, Y)-(X + ElementSize - 1, Y + ElementSize - 1), _RGB32(0, 0, 255), B
  44.             xx = xx + 1
  45.         NEXT X
  46.         yy = yy + 1
  47.         xx = a
  48.     NEXT Y
  49.  
  50.  
  51. SUB PutToArray (arr() AS LONG, image&)
  52.     W = _WIDTH(image&)
  53.     H = _HEIGHT(image&)
  54.     DIM m AS _MEM
  55.     m = _MEMIMAGE(image&)
  56.     REDIM arr(W, H) AS LONG
  57.     FOR y& = 0 TO W - 1
  58.         FOR h& = 0 TO H - 1
  59.             _MEMGET m, m.OFFSET + 4 * ((W * y&) + h&), arr(x, y)
  60.             PSET (x + 550, y + 50), arr(x, y)
  61.             x = x + 1
  62.         NEXT h&
  63.         y = y + 1: x = 0
  64.     NEXT y&
  65.     _MEMFREE m
  66.  
Title: Re: sprite editor
Post by: johnno56 on July 04, 2018, 05:52:56 pm
Fellippe,

I'm running with Linux... Even though I am using the Linux version of QB64, it usually always boils down to, 'It's a Linux/Windows thing'... Maybe, if I leave the editor 'on the shelf' for another 4 years, I may try again... lol

I need coffee...

Petr,

Thank you for the code sample and your advice... I am not using Windows...
This is the part were I duplicate the message to Fellippe... lol

I still need coffee...

J
Title: Re: sprite editor
Post by: bplus on July 04, 2018, 06:01:58 pm
For SaveImage I think Galleon's version should work, that Petr gave us.

As for getting files from current folder from which to select and load, also should be able to do in Linux.
But it would be easier if can clear screen to display list of files from which to pick and then be able to redisplay editor.

Title: Re: sprite editor
Post by: Petr on July 04, 2018, 06:04:09 pm
Johnno56 - is there a command in Linux for list a disk into a text file, like in DOS DIR *. * > file.txt? If so, a primitive way to crawl the disk would go write. It should be the ls -l -R command but how to redirect it to a text file under linux, I do not know.
Title: Re: sprite editor
Post by: Petr on July 04, 2018, 06:14:18 pm
Quote
As for getting files from current folder from which to select and load, also should be able to do in Linux.
But it would be easier if can clear screen to display list of files from which to pick and then be able to redisplay editor.

This is exactly what I'm going to write if we find out how to list the contents of a linux disk into a text file. I've already done it under windows, so when we get a text file  under linux, that's just the different SHELL command.
Title: Re: sprite editor
Post by: Petr on July 04, 2018, 06:21:10 pm
Johnno56, try what do this: cat >files.txt  if it create files.txt file contains disk files list.
Title: Re: sprite editor
Post by: johnno56 on July 04, 2018, 11:17:14 pm
Petr,

ls *.bas > files.txt works just fine and the list is sorted...

J
Title: Re: sprite editor
Post by: SMcNeill on July 05, 2018, 01:04:53 am
It does use the dll that Steve provides in the package so yes, it's Windows only (and I failed to remember you're a Linux user, sorry about that).

If anyone using Windows would like to try the library, just make sure to fix SaveImage.BI file to make the declare library line reference the .dll file using a relative path by adding ".\" to the file name:

Code: QB64: [Select]

I'm thinking the library should still work for Linux users, as long as you point it to where zlib puts itself on your machine.

go to
System->Administration->Synaptic Package Manager
search for zlib1g-dev and install the package.

Of course, it's not going to find a *.dll file, but there should be a Linux equivelant to work off of.  QB64 SDL used to require ZLIB, and it worked on Linux, so somebody out there should be able to patch it all together to work.  (At least, I'd hope so.).
Title: Re: sprite editor
Post by: johnno56 on July 05, 2018, 03:12:53 am
zlib1g-dev is already installed... Thanks for trying, Steve. Much appreciated.

J
Title: Re: sprite editor
Post by: Petr 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.
Title: Re: sprite editor
Post by: johnno56 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
Title: Re: sprite editor
Post by: Petr on July 05, 2018, 05:20:16 am
Thank you. I'll try what I can do with it.
Title: Re: sprite editor
Post by: Petr 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.  
Title: Re: sprite editor
Post by: johnno56 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.
Title: Re: sprite editor
Post by: Petr 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.  
Title: Re: sprite editor
Post by: johnno56 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

Title: Re: sprite editor
Post by: Petr 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.  

Title: Re: sprite editor
Post by: Petr 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
Title: Re: sprite editor
Post by: johnno56 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



Title: Re: sprite editor
Post by: bplus 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.
Title: Re: sprite editor
Post by: bplus 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. ;-))
Title: Re: sprite editor
Post by: bplus 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!
Title: Re: sprite editor
Post by: bplus 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).
Title: Re: sprite editor
Post by: FellippeHeitor 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
Title: Re: sprite editor
Post by: bplus on July 05, 2018, 12:11:46 pm
Thanks Fellippe, that should do nicely.

Do you know of any InForm apps that did use 3 sliders for RGB, seems to me it would be THE Demo for slider bars.
Title: Re: sprite editor
Post by: FellippeHeitor on July 05, 2018, 01:17:54 pm
Well, InForm Designer has three sliders for RGB color mixing, and it's been created using InForm Designer itself, so there's your app.
Title: Re: sprite editor
Post by: bplus on July 05, 2018, 01:29:44 pm
That's where I saw it before!  :)

 Thanks Fellippe
Title: Re: sprite editor
Post by: Petr on July 05, 2018, 03:13:03 pm
Thank you very much, Johnno56. What version of Linux do you use? I repaired one of the deferred older notebooks, so I would install it there to test it. First I will have to find instructions on installing QB64 under Linux ....
Title: Re: sprite editor
Post by: Petr on July 05, 2018, 03:45:27 pm
Quote
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).

It is not difficult. This is a normal percent example: You have a R bar, a G bar and a B bar. 0% is on the left and it is 0. 100% is on right, the value for R and G i B is maximum 255. So if it loads with the POINT or _MEMGET command a pixel of the image, the function returns three R, G, B values. For example the color _RGB32 (128,255,0), so 128 is exactly 50 percent of 256, the driver for R is set in the middle. 255 for G is 100 percent, that set driver to the right. B is 0, ie zero percent. The driver for B will be at the beginning. On the same principle working drivers in my SNDRAW player.
Title: Re: sprite editor
Post by: johnno56 on July 05, 2018, 05:39:52 pm
Petr,

In regards to installing Linux, now days, it's not hard at all. You mentioned an "older" notebook... Some of the mainstream versions of Linux, as with newer versions of Windows, will probably be a bit sluggish on older machines mainly because the newer OS's can be quite taxing on older systems.

Linux has installations for older machines... Yay! Ubuntu has Lubuntu and Xubuntu for example... All you do is go to their homepage; Download the ISO image; Burn it to a DVD or USB drive; Pop it into the notebook and boot. You can either install or test it without installing... Just in case... lol

[abandoned, outdated and now likely malicious qb64 dot net website - donā€™t go there] has both 32 and 64 bit versions for Linux. (Oh no! [abandoned, outdated and now likely malicious qb64 dot net website - donā€™t go there] has problems! No. the main website is fine. It seems that the Forums are "on the fritz"...)

If you need help... You know where I am... lol

J
Title: Re: sprite editor
Post by: Petr on July 06, 2018, 03:45:19 pm
Outside the topic: BPlus, Here's your realization, setings graphics drivers according to the returned color. Fullscreen is NOT USED :-D

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2.     i& = _LOADIMAGE("bart.jpg", 32)
  3.     _PUTIMAGE , i&
  4.     c& = POINT(_MOUSEX, _MOUSEY)
  5.     Red = _RED32(c&): green = _GREEN32(c&): blue = _BLUE32(c&)
  6.     clr$ = STR$(Red) + ", " + STR$(green) + ", " + STR$(blue)
  7.     LOCATE 4, 1: PRINT "Selected color is"; clr$
  8.     LINE (550, 10)-(750, 70), _RGB32(0, 0, 0), BF
  9.  
  10.     _PRINTSTRING (570, 12), "R"
  11.     R = Drive(600, 20, 255, Red)
  12.     _PRINTSTRING (570, 32), "G"
  13.     g = Drive(600, 40, 255, green)
  14.     _PRINTSTRING (570, 52), "B"
  15.     b = Drive(600, 60, 255, blue)
  16.  
  17.     LOCATE 1, 1: PRINT "R driver is set to"; R; " percent"
  18.     LOCATE 2, 1: PRINT "G driver is set to"; g; " percent"
  19.     LOCATE 3, 1: PRINT "B driver is set to"; b; " percent"
  20.     _DISPLAY
  21.  
  22. FUNCTION Drive (xpos, ypos, max, vlue)
  23.     LINE (xpos, ypos)-(xpos + 100, ypos)
  24.     Drive = (vlue / max) * 100
  25.     l2 = xpos + Drive
  26.     LINE (l2, ypos + 5)-(l2 + 5, ypos - 5), , BF
  27.  
Title: Re: sprite editor
Post by: Petr on July 06, 2018, 03:54:29 pm
please, give LOADIMAGE before DO. This Odin politic - time limited edit for own sources is really bad.
Title: Re: sprite editor
Post by: johnno56 on July 06, 2018, 07:41:21 pm
Guys,

I have decided to shelve the Sprite Editor. I originally started it to, "See if I could", but came up against what "I" call a problem, of simply loading and saving each project. I ended up with the same problem using sdlbasic (original version) as I am now having with QB64. Projects can eventually be saved and loaded but not 'simply'. I feel the amount of work needed to complete the project kind of out weighs the concept of a "simple" editor. You guys have put in more work than I could have hoped for and for that I'm very appreciative. I think from now on I will restrict my ideas to what I can actually achieve...

Thanks guys.

J
Title: Re: sprite editor
Post by: FellippeHeitor on July 06, 2018, 10:03:03 pm
Steve also has a file select library that's cross platform, maybe he could repost it.
Title: Re: sprite editor
Post by: SMcNeill on July 07, 2018, 02:02:13 am
Steve also has a file select library that's cross platform, maybe he could repost it.

http://qb64.freeforums.net/thread/63/file-directory-listing-arrays

Try the above. It's not a GUI file selection tool, but it's a crossplatform way to get information into a set of directory and file arrays.  I've got a GUI version around here somewhere as well, but most folks just seem to enjoy making their own interface and using the stripped down version here to get the information they need, instead.  ;)
Title: Re: sprite editor
Post by: Petr on July 07, 2018, 04:29:06 am
Johnno56, do not be sad. Every such project just wants to do it in small steps until you finally get a big result. I will continue with this and add commented source codes here. This time I will test them in both Linux and Windows before i post it here.
Title: Re: sprite editor
Post by: bplus on July 08, 2018, 12:29:29 pm
Johnno, this is excellent project idea!
Title: Re: sprite editor
Post by: bplus on September 07, 2020, 04:42:54 pm
OK here is an update of Johnno's v03 and some mods to get an image loaded and into the grid edit area.

Code: QB64: [Select]
  1. '   =========================================================
  2. '
  3. '       SPRITE DRAW v03 by johnno    b+ mods 2020-09-07  comment with " '<
  4. '
  5. '   =========================================================
  6.  
  7. SCREEN _NEWIMAGE(1280, 640, 32) '< reduce width to fit my screen
  8. _DELAY .25
  9. _SCREENMOVE 66, 50 '<  get it off my left side title bar, you will likely want some other adjustment
  10.  
  11. DIM SHARED currentcolour AS _UNSIGNED LONG
  12. 'DIM SHARED clr AS _UNSIGNED LONG
  13.  
  14.  
  15. gridcolour = _RGB32(64, 64, 64)
  16. red = _RGB32(255, 0, 0)
  17. darkred = _RGB32(160, 0, 0)
  18. green = _RGB32(0, 160, 0)
  19. yellow = _RGB32(160, 160, 0)
  20. black = _RGB32(0, 0, 0)
  21. gray = _RGB32(164, 164, 164)
  22. white = _RGB32(255, 255, 255)
  23. currentcolour = _RGB32(0, 0, 0)
  24.  
  25. DIM SHARED gridsize, gsize ' < the rest of these too
  26. gridsize = 64
  27. gsize = 9
  28. psize = 1
  29. tools = 5
  30. resetcurrentcolour = 0
  31. DIM SHARED symmetry AS INTEGER
  32. symmetry = 0
  33. exist = 0
  34.  
  35. ' < for ? don't need
  36. 'r5 = 0
  37. 'g5 = 0
  38. 'b5 = 0
  39.  
  40. zones = 9 ' < mouse cleck areas
  41. quit = 0
  42. 'mousegridx = 0
  43. 'mousegridy = 0
  44. 'mousegridx2 = 0
  45. 'mousegridy2 = 0
  46.  
  47. DIM SHARED maingrid(gridsize, gridsize) AS _UNSIGNED LONG
  48. 'DIM SHARED bgrid(gridsize, gridsize)
  49. 'DIM SHARED prevgrid(gridsize, gridsize)
  50. DIM SHARED tool(tools)
  51. DIM SHARED zone(zones)
  52.  
  53. buttonclick = _SNDOPEN("assets/buttonClick.wav")
  54. buttonclick2 = _SNDOPEN("assets/buttonClick2.wav")
  55. buttonclick3 = _SNDOPEN("assets/buttonClick3.wav")
  56. wip = _SNDOPEN("assets/bzzzt.wav")
  57.  
  58. DIM SHARED sample AS LONG
  59. sample = _LOADIMAGE("assets/sample64x64.png", 32) ' < ok let's try
  60. 'PRINT sample  '<  got it
  61. 'end ' < test sample load
  62.  
  63. setup '< dang where is sample
  64.  
  65.     '   Wait for mouse movement or button press
  66.     '
  67.     mx = _MOUSEX
  68.     my = _MOUSEY
  69.     mb1 = _MOUSEBUTTON(1)
  70.     mb2 = _MOUSEBUTTON(2)
  71.  
  72.     '   ----------------------------
  73.     '       Determine Mouse Zone
  74.     '   ----------------------------
  75.  
  76.     '   Zone 1 - Main Grid
  77.     '
  78.     IF mx > 0 AND mx < 640 AND my > 0 AND my < 640 THEN
  79.         zone(1) = 1
  80.     ELSE
  81.         zone(1) = 0
  82.     END IF
  83.  
  84.     '   Zone 2 - NEW Button
  85.     '
  86.     IF mx > 690 AND mx < 770 AND my > 520 AND my < 560 THEN
  87.         zone(2) = 1
  88.     ELSE
  89.         zone(2) = 0
  90.     END IF
  91.  
  92.     '   Zone 3 - LOAD Button
  93.     '
  94.     IF mx > 690 AND mx < 770 AND my > 570 AND my < 610 THEN
  95.         zone(3) = 1
  96.     ELSE
  97.         zone(3) = 0
  98.     END IF
  99.  
  100.     '   Zone 4 - SAVE Button
  101.     '
  102.     IF mx > 790 AND mx < 870 AND my > 570 AND my < 610 THEN
  103.         zone(4) = 1
  104.     ELSE
  105.         zone(4) = 0
  106.     END IF
  107.  
  108.     '   Zone 5 - QUIT Button
  109.     '
  110.     IF mx > 884 AND mx < 964 AND my > 520 AND my < 560 THEN
  111.         zone(5) = 1
  112.     ELSE
  113.         zone(5) = 0
  114.     END IF
  115.  
  116.     '   Zone 6 - PENCIL Button
  117.     '
  118.     IF mx > 1014 AND mx < 1094 AND my > 98 AND my < 138 THEN
  119.         zone(6) = 1
  120.     ELSE
  121.         zone(6) = 0
  122.     END IF
  123.  
  124.     '   Zone 7 - LINE Button
  125.     '
  126.     IF mx > 1014 AND mx < 1094 AND my > 148 AND my < 188 THEN
  127.         zone(7) = 1
  128.     ELSE
  129.         zone(7) = 0
  130.     END IF
  131.  
  132.     '   Zone 8 - MIRROR Button
  133.     '
  134.     IF mx > 1014 AND mx < 1094 AND my > 198 AND my < 238 THEN
  135.         zone(8) = 1
  136.     ELSE
  137.         zone(8) = 0
  138.     END IF
  139.  
  140.     '   Zone 9 - CLEAR Button
  141.     '
  142.     IF mx > 884 AND mx < 964 AND my > 570 AND my < 610 THEN
  143.         zone(9) = 1
  144.     ELSE
  145.         zone(9) = 0
  146.     END IF
  147.  
  148.     '   --------------------
  149.     '       Draw On Grid
  150.     '   --------------------
  151.     IF zone(1) = 1 AND mb1 THEN
  152.         drawongrid
  153.     END IF
  154.  
  155.     '   -----------------------
  156.     '       Erase From Grid
  157.     '   -----------------------
  158.     IF zone(1) = 1 AND mb2 THEN
  159.         erasefromgrid
  160.     END IF
  161.     'updatepreview   ' <  should these be outside IF?
  162.     'redrawgrid
  163.  
  164.     '   ------------
  165.     '       QUIT
  166.     '   ------------
  167.     IF zone(5) = 1 AND mb1 THEN
  168.         _SNDPLAY (buttonclick3)
  169.         _DELAY .2
  170.         COLOR darkred
  171.         LINE (884, 520)-STEP(80, 40), , B
  172.         COLOR red
  173.         _PRINTSTRING (891, 523), "Quit"
  174.         _DELAY .2
  175.         quit = 1
  176.     END IF
  177.  
  178.     '   ------------------
  179.     '       LOAD Image
  180.     '   ------------------
  181.     IF zone(3) = 1 AND mb1 THEN
  182.         _SNDPLAY (buttonclick2)
  183.         _DELAY .2
  184.         tool(1) = 0
  185.         pencil
  186.         loadfile
  187.     END IF
  188.  
  189.     '   ------------------
  190.     '       SAVE Image
  191.     '   ------------------
  192.     IF zone(4) = 1 AND mb1 THEN
  193.         _SNDPLAY (wip)
  194.         _DELAY .2
  195.         'savefile
  196.     END IF
  197.  
  198.     '   -----------------
  199.     '       NEW Image
  200.     '   -----------------
  201.     IF zone(2) = 1 AND mb1 THEN
  202.         _SNDPLAY (buttonclick2)
  203.         _DELAY .2
  204.         newimage
  205.     END IF
  206.  
  207.     '   -------------------
  208.     '       CLEAR Image
  209.     '   -------------------
  210.     IF zone(9) = 1 AND mb1 THEN
  211.         _SNDPLAY (buttonclick2)
  212.         _DELAY .2
  213.         clearimage
  214.     END IF
  215.  
  216.     '   ----------------------
  217.     '       TOOLS - Pencil
  218.     '   ----------------------
  219.     IF zone(6) = 1 AND mb1 THEN
  220.         _SNDPLAY (buttonclick2)
  221.         _DELAY .2
  222.         tool(1) = 1
  223.         pencil
  224.         tool(2) = 0
  225.         drawline
  226.         tool(3) = 0
  227.         symmetry = 0
  228.         mirror
  229.     END IF
  230.  
  231.     '   --------------------------
  232.     '       TOOLS - Line (wip)
  233.     '   --------------------------
  234.     IF zone(7) = 1 AND mb1 THEN
  235.         _SNDPLAY (wip)
  236.         _DELAY .2
  237.         'tool(1) = 1
  238.         'pencil
  239.         'tool(2) = 1
  240.         'drawline
  241.         'tool(3) = 0
  242.         'symmetry = 0
  243.         'mirror
  244.     END IF
  245.  
  246.     '   ---------------------------------
  247.     '       TOOLS - Mirror / Symmetry
  248.     '   ---------------------------------
  249.     IF mb1 AND zone(8) = 1 AND tool(3) = 0 THEN
  250.         _SNDPLAY (buttonclick2)
  251.         _DELAY .2
  252.         tool(1) = 1
  253.         pencil
  254.         tool(2) = 0
  255.         drawline
  256.         tool(3) = 1
  257.         symmetry = 1
  258.         mirror
  259.     END IF
  260.  
  261.     '   -----------------------------
  262.     '       Select Current Colour
  263.     '   -----------------------------
  264.     IF mx > 690 AND mx < 964 AND my > 300 AND my < 490 AND mb1 THEN
  265.         currentcolour = POINT(_MOUSEX, _MOUSEY)
  266.         'convert (currentcolour)
  267.         'r5 = getR(currentcolour)
  268.         'g5 = getG(currentcolour)
  269.         'b5 = getB(currentcolour)
  270.     END IF
  271.     COLOR currentcolour
  272.     LINE (821, 521)-STEP(28, 28), , BF
  273.  
  274.     _DISPLAY
  275.  
  276.     _LIMIT 60 ' <<< cut down the looping save the CPU!
  277. LOOP UNTIL quit = 1 OR INKEY$ = CHR$(27)
  278.  
  279. '==================================================================
  280.  
  281. '   ----------------------
  282. '       Convert to RGB
  283. '   ----------------------
  284. 'SUB convert (clr)
  285. '    r5 = _RED32(clr)
  286. '    g5 = _GREEN32(clr)
  287. '    b5 = _BLUE32(clr)
  288. 'END SUB
  289. '   ==================================================================
  290. '
  291. '       PROCEDURES AND FUNCTIONS
  292. '
  293. '   ==================================================================
  294.  
  295. '   -----------------------
  296. '       Initial Display
  297. '   -----------------------
  298.  
  299. SUB setup
  300.  
  301.     logo = _LOADIMAGE("assets/draw3.png", 32)
  302.     patch = _LOADIMAGE("assets/colourpatch.png", 32)
  303.  
  304.     gsize = 9
  305.  
  306.     '   ------------------------
  307.     '       Reset Tool flags
  308.     '   ------------------------
  309.     FOR i = 1 TO tools
  310.         tool(i) = 0
  311.     NEXT
  312.  
  313.     '   ------------------------
  314.     '       Reset Zone flags
  315.     '   ------------------------
  316.     FOR i = 1 TO zones
  317.         zone(i) = 0
  318.     NEXT
  319.  
  320.     '   ----------------------
  321.     '       Draw Main Grid
  322.     '   ----------------------
  323.     COLOR gridcolour
  324.     FOR x = 0 TO 640
  325.         LINE (x, 0)-(x, 640)
  326.         x = x + gsize
  327.     NEXT
  328.     FOR y = 0 TO 640
  329.         LINE (0, y)-(640, y)
  330.         y = y + gsize
  331.     NEXT
  332.     'redrawgrid
  333.  
  334.     '   ---------------------
  335.     '       Program Logo
  336.     '   ---------------------
  337.     _PUTIMAGE (720, 0), logo
  338.     COLOR _RGB32(0, 128, 128)
  339.     _PRINTSTRING (750, 620), "(C) 2015 John Baldwin"
  340.  
  341.     '   -----------------------------
  342.     '       Colour Selection Grid
  343.     '   -----------------------------
  344.     _PUTIMAGE (690, 300), patch
  345.  
  346.     '   ----------------------------------
  347.     '       Sprite Preview Box - 64x64
  348.     '   ----------------------------------
  349.     COLOR gridcolour
  350.     LINE (698, 98)-STEP(67, 67), , B
  351.     _PUTIMAGE (700, 100), sample, 0 ' < add sample
  352.     COLOR gray
  353.     _PRINTSTRING (703, 170), "Preview"
  354.     'update grid
  355.     preview2grid
  356.  
  357.     '   -----------------------------------------
  358.     '       Sprite Preview Box - Magnified x2
  359.     '   -----------------------------------------
  360.     COLOR gridcolour
  361.     LINE (798, 98)-STEP(134, 134), , B
  362.     _PUTIMAGE (800, 100)-STEP(128, 128), sample, 0 ' < add sample
  363.     COLOR gray
  364.     _PRINTSTRING (830, 235), "Preview x2"
  365.  
  366.     '   -----------------------------------
  367.     '       Current Selected Colour Box
  368.     '   -----------------------------------
  369.     COLOR gridcolour
  370.     LINE (820, 520)-STEP(30, 30), , B
  371.  
  372.     '   --------------------
  373.     '       Menu Buttons
  374.     '   --------------------
  375.     COLOR gridcolour
  376.     LINE (690, 520)-STEP(80, 40), , B
  377.     _PRINTSTRING (698, 523), "New"
  378.  
  379.     COLOR gridcolour
  380.     LINE (690, 570)-STEP(80, 40), , B
  381.     _PRINTSTRING (698, 573), "Load"
  382.  
  383.     COLOR gridcolour
  384.     LINE (790, 570)-STEP(80, 40), , B
  385.     _PRINTSTRING (798, 573), "Save"
  386.  
  387.     COLOR gridcolour
  388.     LINE (884, 520)-STEP(80, 40), , B
  389.     _PRINTSTRING (891, 523), "Quit"
  390.  
  391.     COLOR gridcolour
  392.     LINE (884, 570)-STEP(80, 40), , B
  393.     _PRINTSTRING (892, 573), "Clear"
  394.  
  395.     '   --------------------
  396.     '       TOOL BUTTONS
  397.     '   --------------------
  398.  
  399.     '   Pencil
  400.  
  401.     COLOR gridcolour
  402.     LINE (1014, 98)-STEP(80, 40), , B
  403.     _PRINTSTRING (1022, 101), "Pencil"
  404.     tool(1) = 0
  405.  
  406.     '   Line
  407.  
  408.     COLOR gridcolour
  409.     LINE (1014, 148)-STEP(80, 40), , B
  410.     COLOR gridcolour
  411.     _PRINTSTRING (1022, 151), "Line"
  412.     _PRINTSTRING (1059, 168), "wip"
  413.     tool(2) = 0
  414.  
  415.     '   Mirror / Symmetry
  416.  
  417.     COLOR gridcolour
  418.     LINE (1014, 198)-STEP(80, 40), , B
  419.     _PRINTSTRING (1022, 201), "Mirror"
  420.     tool(3) = 0
  421.  
  422.     '   Spares
  423.  
  424.     COLOR _RGB32(32, 32, 32)
  425.     LINE (1014, 248)-STEP(80, 40), , B
  426.     LINE (1014, 298)-STEP(80, 40), , B
  427.     LINE (1014, 348)-STEP(80, 40), , B
  428.     LINE (1014, 398)-STEP(80, 40), , B
  429.     LINE (1014, 448)-STEP(80, 40), , B
  430.  
  431.     LINE (1104, 98)-STEP(80, 40), , B
  432.     LINE (1104, 148)-STEP(80, 40), , B
  433.     LINE (1104, 198)-STEP(80, 40), , B
  434.     LINE (1104, 248)-STEP(80, 40), , B
  435.     LINE (1104, 298)-STEP(80, 40), , B
  436.     LINE (1104, 348)-STEP(80, 40), , B
  437.     LINE (1104, 398)-STEP(80, 40), , B
  438.     LINE (1104, 448)-STEP(80, 40), , B
  439.  
  440.     LINE (1194, 98)-STEP(80, 40), , B
  441.  
  442.  
  443. SUB drawongrid
  444.     IF tool(1) <> 0 THEN
  445.         COLOR currentcolour
  446.         mousegridx = INT(_MOUSEX / 10) * 10
  447.         mousegridy = INT(_MOUSEY / 10) * 10
  448.         LINE (mousegridx, mousegridy)-STEP(10, 10), , BF
  449.  
  450.         IF symmetry = 1 THEN
  451.             COLOR currentcolour
  452.             mousegridx2 = 640 - (INT(_MOUSEX / 10) * 10) - 9
  453.             mousegridy2 = INT(_MOUSEY / 10) * 10
  454.             LINE (mousegridx2, mousegridy2)-STEP(10, 10), , BF
  455.         END IF
  456.     END IF
  457.  
  458. SUB erasefromgrid
  459.     IF tool(1) <> 0 THEN
  460.         COLOR _RGB32(0, 0, 0)
  461.         mousegridx = INT(_MOUSEX / 10) * 10
  462.         mousegridy = INT(_MOUSEY / 10) * 10
  463.         LINE (mousegridx, mousegridy)-STEP(10, 10), , BF
  464.         _DISPLAY
  465.     END IF
  466.  
  467. SUB newimage
  468.     sure
  469.     IF exist = 1 THEN
  470.         savefile
  471.         exist = 0
  472.     END IF
  473.     tool(1) = 0
  474.     pencil
  475.     tool(2) = 0
  476.     drawline
  477.     tool(3) = 0
  478.     symmetry = 0
  479.     mirror
  480.     FOR imagex = 0 TO 63
  481.         FOR imagey = 0 TO 63
  482.             maingrid(imagex, imagey) = black
  483.             COLOR maingrid(imagex, imagey)
  484.             '   -------------------------
  485.             '       "Poor Man's" Fill
  486.             '   -------------------------
  487.             'r5 = getR(maingrid[imagex][imagey])
  488.             'g5 = getG(maingrid[imagex][imagey])
  489.             'b5 = getB(maingrid[imagex][imagey])
  490.             'set color r5,g5,b5
  491.             dotx = imagex * 10
  492.             doty = imagey * 10
  493.             LINE (dotx, doty)-STEP(10, 10), , BF
  494.             '   --------------------
  495.             '       Draw Preview
  496.             '   --------------------
  497.             PSET (700 + imagex, 100 + imagey)
  498.             '   ------------------------------
  499.             '       Draw Magnified Preview
  500.             '   ------------------------------
  501.             PSET (800 + imagex, 100 + imagey)
  502.         NEXT
  503.     NEXT
  504.  
  505.     resetcurrentcolour = 1
  506.  
  507.     redrawgrid
  508.  
  509.     _DELAY .1
  510.  
  511.     'free file 1
  512.  
  513.  
  514. SUB loadfile
  515.     sample = _LOADIMAGE("assets/sample64x64.png", 32)
  516.     _PUTIMAGE (700, 100), sample
  517.     COLOR gridcolour
  518.     '   --------------------
  519.     '       SCAN IMAGE ?
  520.     '   --------------------
  521.     FOR imagex = 0 TO 63
  522.         FOR imagey = 0 TO 63
  523.             maingrid(imagex, imagey) = POINT(700 + imagex, 100 + imagey)
  524.         NEXT
  525.     NEXT
  526.     '   -------------------------------
  527.     '       TRANSFER TO MAIN GRID ?
  528.     '   -------------------------------
  529.     FOR imagex = 0 TO 63
  530.         FOR imagey = 0 TO 63
  531.             COLOR maingrid(imagex, imagey)
  532.             '   -------------------------
  533.             '       "Poor Man's" Fill
  534.             '   -------------------------
  535.             'r5 = getR(maingrid[imagex][imagey])
  536.             'g5 = getG(maingrid[imagex][imagey])
  537.             'b5 = getB(maingrid[imagex][imagey])
  538.             'set color r5,g5,b5
  539.             dotx = imagex * 10
  540.             doty = imagey * 10
  541.             LINE (dotx, doty)-STEP(10, 10), , BF
  542.         NEXT
  543.     NEXT
  544.     redrawgrid
  545.  
  546. SUB savefile
  547.  
  548.  
  549. SUB clearimage
  550.     tool(1) = 0
  551.     pencil
  552.     tool(2) = 0
  553.     drawline
  554.     tool(3) = 0
  555.     mirror
  556.     FOR imagex = 0 TO 63
  557.         FOR imagey = 0 TO 63
  558.             maingrid(imagex, imagey) = black
  559.             COLOR maingrid(imagex, imagey)
  560.             '   -------------------------
  561.             '       "Poor Man's" Fill
  562.             '   -------------------------
  563.             'r5 = getR(maingrid[imagex][imagey])
  564.             'g5 = getG(maingrid[imagex][imagey])
  565.             'b5 = getB(maingrid[imagex][imagey])
  566.             'set color r5,g5,b5
  567.             dotx = imagex * 10
  568.             doty = imagey * 10
  569.             LINE (dotx, doty)-STEP(10, 10), , BF
  570.             '   --------------------
  571.             '       Draw Preview
  572.             '   --------------------
  573.             PSET (700 + imagex, 100 + imagey)
  574.             '   ------------------------------
  575.             '       Draw Magnified Preview
  576.             '   ------------------------------
  577.             PSET (800 + imagex, 100 + imagey)
  578.         NEXT
  579.     NEXT
  580.  
  581.     resetcurrentcolour = 1
  582.  
  583.     redrawgrid
  584.  
  585.     _DELAY .1
  586.  
  587.     'free file 1
  588.  
  589.  
  590. SUB sure
  591.     exist = 0
  592.     FOR imagex = 0 TO 63
  593.         FOR imagey = 0 TO 63
  594.             IF POINT(700 + imagex, 100 + imagey) <> black THEN
  595.                 exist = 1
  596.             END IF
  597.         NEXT
  598.     NEXT
  599.  
  600. SUB msgbox
  601.  
  602.  
  603. '   -----------------------
  604. '       TOOL PROCEDURES
  605. '   -----------------------
  606.  
  607. SUB pencil
  608.     IF tool(1) = 0 THEN
  609.         COLOR gridcolour
  610.         LINE (1014, 98)-STEP(80, 40), , B
  611.         _PRINTSTRING (1022, 101), "Pencil"
  612.     END IF
  613.     IF tool(1) = 1 THEN
  614.         COLOR white
  615.         LINE (1014, 98)-STEP(80, 40), , B
  616.         COLOR yellow
  617.         _PRINTSTRING (1022, 101), "Pencil"
  618.         COLOR gridcolour
  619.         tool(2) = 0
  620.         drawline
  621.         tool(3) = 0
  622.         symmetry = 0
  623.         mirror
  624.     END IF
  625.  
  626. SUB drawline
  627.     '   -------------------------------------
  628.     '       Change state of 'line' button
  629.     '   -------------------------------------
  630.     'IF tool(2) = 0 THEN
  631.     'COLOR gridcolour
  632.     'LINE (1014, 148)-STEP(80, 40), , B
  633.     '_PRINTSTRING (1022, 151), "Line"
  634.     'END IF
  635.     'IF tool(2) = 1 THEN
  636.     'COLOR white
  637.     'LINE (1014, 148)-STEP(80, 40), , B
  638.     'COLOR yellow
  639.     '_PRINTSTRING (1022, 151), "Line"
  640.     'COLOR gridcolour
  641.     'END IF
  642.     '   -----------------------------------------
  643.     '       Line function goes here... W.I.P.
  644.     '   -----------------------------------------
  645.     'COLOR currentcolour
  646.     'x1 = 0
  647.     'x2 = 0
  648.     'y1 = 0
  649.     'y2 = 0
  650.     'click = 0
  651.     'WHILE click = 0
  652.     'IF _MOUSEBUTTON(1) AND zone(1) = 1 THEN
  653.     'click = 1
  654.     'x = _MOUSEX
  655.     'y = _MOUSEY
  656.     'x1 = x
  657.     'y1 = y
  658.     'mousegridx = INT(x1 / 10) * 10
  659.     'mousegridy = INT(y1 / 10) * 10
  660.     'LINE (mousegridx, mousegridy)-STEP(10, 10), , BF
  661.     'END IF
  662.     'IF mb2 AND zone(1) = 1 THEN
  663.     '    x = _MOUSEX
  664.     'y = _MOUSEY
  665.     'x2 = x
  666.     'y2 = y
  667.     'mousegridx = INT(x2 / 10) * 10
  668.     'mousegridy = INT(y2 / 10) * 10
  669.     'LINE (mousegridx, mousegridy)-STEP(10, 10), , BF
  670.     'click = 1
  671.     'dx = ABS(x2 - x1)
  672.     'sx = -1
  673.     'IF x1 < x2 THEN sx = 1
  674.     'dy = ABS(y2 - y1)
  675.     'sy = -1
  676.     'IF y1 < y2 THEN sy = 1
  677.     'er = -dy
  678.     'IF dx > dy THEN er = dx
  679.     'er = INT(er / 2)
  680.     'DO
  681.     '    LINE (INT(x1 / 10) * 10, INT(y1 / 10) * 10)-STEP(10, 10), , BF
  682.     'e2 = er
  683.     'IF e2 > -dx THEN
  684.     '    er = er - dy
  685.     'x1 = x1 + sx
  686.     'END IF
  687.     'IF e2 < dy THEN
  688.     '    er = er + dx
  689.     'y1 = y1 + sy
  690.     'END IF
  691.     '_DISPLAY
  692.     'LOOP UNTIL x1 = x2 AND y1 = y2
  693.     'END IF
  694.     '_DISPLAY
  695.     'IF INKEY$ = CHR$(27) THEN SYSTEM
  696.     'WEND
  697.     'END IF
  698.  
  699. SUB mirror
  700.     '
  701.     '    Change state of 'symmetry' button
  702.     '
  703.     IF tool(3) = 0 THEN
  704.         COLOR gridcolour
  705.         LINE (1014, 198)-STEP(80, 40), , B
  706.         _PRINTSTRING (1022, 201), "Mirror"
  707.     END IF
  708.     IF tool(3) = 1 THEN
  709.         COLOR white
  710.         LINE (1014, 198)-STEP(80, 40), , B
  711.         COLOR yellow
  712.         _PRINTSTRING (1022, 201), "Mirror"
  713.         COLOR gridcolour
  714.     END IF
  715.  
  716. SUB redrawgrid
  717.     gsize = 9
  718.     COLOR gridcolour
  719.     FOR x = 0 TO 640
  720.         LINE (x, 0)-(x, 640)
  721.         x = x + gsize
  722.     NEXT
  723.     FOR y = 0 TO 640
  724.         LINE (0, y)-(640, y)
  725.         y = y + gsize
  726.     NEXT
  727.  
  728. SUB updatepreview
  729.     FOR prevx = 0 TO 63
  730.         FOR prevy = 0 TO 63
  731.             COLOR POINT((prevx * 10) + 5, (prevy * 10) + 5)
  732.             PSET (700 + prevx, 100 + prevy)
  733.         NEXT
  734.     NEXT
  735.     '    Magnified Preview
  736.     FOR prevx = 0 TO 63
  737.         FOR prevy = 0 TO 63
  738.             COLOR POINT((prevx * 10) + 5, (prevy * 10) + 5)
  739.             PSET (800 + (prevx * 2), 100 + (prevy * 2))
  740.             PSET (801 + (prevx * 2), 100 + (prevy * 2))
  741.  
  742.             PSET (800 + (prevx * 2), 101 + (prevy * 2))
  743.             PSET (801 + (prevx * 2), 101 + (prevy * 2))
  744.  
  745.             'REM draw rect 800+(prevx*2),100+(prevy*2),2,2,true
  746.         NEXT
  747.     NEXT
  748.  
  749. SUB preview2grid '< this whole sub
  750.     FOR prevx = 0 TO 63
  751.         FOR prevy = 0 TO 63
  752.             COLOR POINT(700 + prevx, 100 + prevy)
  753.             LINE (prevx * 10, prevy * 10)-STEP(gsize, gsize), , BF
  754.         NEXT
  755.     NEXT
  756.  


Hey looks like we are ready to save an image ;-)   

And looks like we will need a tool to set current color from the image!
Title: Re: sprite editor
Post by: johnno56 on September 07, 2020, 05:32:35 pm
As per your request... This is the current version (unmodified) including the assets...
Title: Re: sprite editor
Post by: johnno56 on September 07, 2020, 06:19:31 pm
As per your request....

I have cobbled together an 'eyedrop' function that will select a colour from the main grid... There maybe bugs... (no surprises there... lol)  Give it a test and if it's ok then we'll keep it....

The attached file is only the main program.
Title: Re: sprite editor
Post by: bplus on September 07, 2020, 07:57:36 pm
Oh man! you were already loading the sample image. I've got to catch up with all your procedures.
Title: Re: sprite editor
Post by: bplus on September 07, 2020, 08:54:44 pm
Ok as minimally invasive as I could I added stuff so you can save image. You are now loading "untitled.png" when you Load and Save to same when you save. You will have to figure out how to handle getting file name strings. But perhaps I could help with that too by getting list of files in the directory, my next addition.

SaveImage will not save if it finds a file with save name already existing, it also has a number of other numbered error messages. I just moved on whether the file actually got saved or not. But you can find out if file actually did get saved or what kind of error.  It's in the giant BM file.

I also decreased screen width a shade and centered to my screen to just fit out from under my tool bar.

I also put a _LIMIT in the main loop to save me from CPU fan noise!

So here is v03b with save image:
Title: Re: sprite editor
Post by: johnno56 on September 08, 2020, 12:47:57 am
Check your messages.... Here is your result...
Title: Re: sprite editor
Post by: johnno56 on September 08, 2020, 01:10:16 am
The size of the screen is fine. If you need it to be smaller (in width) then the "spare box" to the far right can be removed. It was only put there to gauge the width of three sets of buttons.

Saving and loading worked as you had coded. Cool.

I had made some changes to version 3 while you were working on 3b... The mods were mainly around the messagebox routine and a few messages. No drama. I will add the changes to 3b... Somebody has to move to someone's timezone... lol Hmm... That could be difficult. I cannot go more that 5kms from home (a few exceptions) and the Victorian borders have been closed. So you cannot move here.

Can you imagine if we both made significant changes? Oh the duplication of effort... There has to be a better way to manage projects remotely.... Any ideas?
Title: Re: sprite editor
Post by: johnno56 on September 08, 2020, 02:21:38 am
Ok. I have merged v3 and v3b into v4.

I think the message box system, although works, could do with an overhaul... lol
"Line" has been hard coded with a message.
"Save" message works.
Note: I think a scan of the main grid prior to saving may be in order. Even though the main grid is "blank" the save function will store an empty sprite...
Not sure if the "lucon" font is needed...
I have removed the far right button... just in case...

Anyway. Give it a test and see what you think?
Title: Re: sprite editor
Post by: bplus on September 08, 2020, 10:52:56 am
The size of the screen is fine. If you need it to be smaller (in width) then the "spare box" to the far right can be removed. It was only put there to gauge the width of three sets of buttons.

Good but I am optimistically hoping we will eventually need that many buttons! But if they stay the same size, they could be shifted a tiny bit to get and keep overall screen width to where I had it set. 1300 is just over my screen limit with my toolbar along the left side of screen.


Quote
Saving and loading worked as you had coded. Cool.

This is very good news that I'm so glad to have confirmed. Yeah Steve McNeill!

Quote
I had made some changes to version 3 while you were working on 3b... The mods were mainly around the messagebox routine and a few messages. No drama. I will add the changes to 3b... Somebody has to move to someone's timezone... lol Hmm... That could be difficult. I cannot go more that 5kms from home (a few exceptions) and the Victorian borders have been closed. So you cannot move here.

Perhaps this would be a good time, to mention I have a pop up Dialog type Message Box you can move around the screen and then closes and gone with message read. I also have a pop up Input Box you also can move around the screen. Altogether they would be maybe another 300 lines of code?

Quote
Can you imagine if we both made significant changes? Oh the duplication of effort... There has to be a better way to manage projects remotely.... Any ideas?

Yeah I had already duplicated an effort of yours by loading the sample at startup and making a preview2grid subroutine. You already had all that in the Load button!

But we have done alright in the past working together on projects: Battleship, Blackjack... and that's just the B's ;-))

Well you are in charge of the Official Code versions in this project I will just offer mods to be assimilated into it or not adding a b at end of version number to distinguish code sets.
Title: Re: sprite editor
Post by: bplus on September 08, 2020, 11:05:43 am
Ok. I have merged v3 and v3b into v4.

I think the message box system, although works, could do with an overhaul... lol
"Line" has been hard coded with a message.
"Save" message works.
Note: I think a scan of the main grid prior to saving may be in order. Even though the main grid is "blank" the save function will store an empty sprite...
Not sure if the "lucon" font is needed...
I have removed the far right button... just in case...

Anyway. Give it a test and see what you think?

Yeah, how married to your message box system are you? I am sorry I had forgotten I had worked out a Message Box dialog that you can move around the screen and then close. Same with an Input Box. So you might want to see those before going further with built in one on your main screen.

And the Tiny Navigator app might be just the thing for retrieving filenames but it also has a rather large set of lines of code and would be done on a whole separate screen.

It's like I've been building tools (except for save image) with this program in mind. eg I have a color picker too that employs slide bars but I think I like the point and click style better that Dav is working on for this kind of app and that Ken used with one of his Paint Programs.

Well while you sleep, the night shift elves will be working on adding tools to version #4.  ;-))
Title: Re: sprite editor
Post by: johnno56 on September 08, 2020, 12:31:30 pm
I'm open to any type of msgbox... I only put a 'fixed' box in the corner because it was the easiest... not necessarily then best...

It's about 2:30am and I'd better get some sleep. Sat through the original 1960 'Time Machine' AND the 2002 version back to back... Can't get enough of H.G....

BIG day tomorrow... hopefully... Our coffee delivery should arrive.... Moo Ha Ha...
Title: Re: sprite editor
Post by: bplus on September 08, 2020, 05:27:32 pm
Hi @johnno56

Just started going over version 4 and 2 notes:
1) Include all files needed to run the bas code in the package so people wont have to be looking all over for stuff.
also if you want to use a special font include it in the zip package.

PPS if you are worried about cluttering up forum with attachments, we can delete old abandoned ones as the new ones come to replace them as with Blackjack.

2) Don't forget to update the title / header label of program, v04 here. With all sorts of copies about this is needed to sort out which it is we are looking at. I am trying to keep an untouched copy of your newest program and one that I am modifying plus backup files of older versions.

PS your message box looks good and works :)
Title: Re: sprite editor
Post by: johnno56 on September 08, 2020, 07:09:03 pm
My first posting was over 2mb (didn't think about all the 'clutter' I tend to gather... lol) Now it's down to about 5k without the assets. The special font was just for me... Being a mono-spaced font helped with text placement within the message box. Most of the users here are Windows-based and Lucon.ttf, if I am not mistaken, is either already part of the OS's fonts or is supplied with the Windows version of QB64. But, you are correct, I should include the font file.

Clutter on a forum? Interesting turn of phrase... Isn't what we are all submitting a 'type' of 'clutter'? lol
No. I'm not concerned about forum clutter. That responsibility usually falls to either the site Admin or the forum host. But we should be mindful of how much we contribute... To that end... We have all been given the ability to create and edit our own posts so perhaps we could be given the ability to only delete our own posts... Just thinking outside the box... We should make it a habit, ok "I" should make it a habit, to properly manage my backups and leave 'site clutter' management to those who do it so well...

Title headers.... I almost always forget about those... Good point.

Message box. It's a drastically modified "Perter" version. It's not Peter's but it will do until something better comes along. Thanks anyway. That might be an interesting project... A message box library... This is the part where someone says, "But we already have a library for that." and totally destroy one of my few ideas...  Story of my life.... *sigh*

Coffee time!
Title: Re: sprite editor
Post by: bplus on September 09, 2020, 12:18:04 am
Well the elves had to work overtime because they hit a few snags. But we have everything working, at least in Windows.

I have to warn when you Load a file you have to press f to get the real filenames list up. The one showing on the right is just a 20 file sample of the whole list that is loaded into an array that you can scroll, mouse click, arrow key, page home end... even type in item number and enter, all these options to select a file off the listing. And if you change your mind use top right X or escape.

Oh yeah, I included a copy of direntry.h and Readme.txt file that reminds you to make sure you have a copy of this in your QB64 folder. This is so, hopefully, the file name retriever can work both in Windows and Linux.

Some screen shots from SprDraw04b and the zip is last attachment:

Title: Re: sprite editor
Post by: johnno56 on September 09, 2020, 12:29:57 am
Stone the flammin' crows! Ya blood's worth bottling!
Title: Re: sprite editor
Post by: bplus on September 09, 2020, 12:33:46 am
Can you load files?

Oh you are going to keep me hanging in suspense :)
Title: Re: sprite editor
Post by: johnno56 on September 09, 2020, 01:21:09 am
Yes. I can load files.... Cool...
Title: Re: sprite editor
Post by: bplus on September 09, 2020, 01:31:10 am
Yes. I can load files.... Cool...

Yeah! Yea to Steve there is allot of his influence in that code!

I know its annoying to have to press f to get the files list up. It was a way for mouse and keypresses to work on just one list at a time. I will work on that. I'll also have a look at the drawing circles and lines that you have penciled in.

Might try a fill like Paint? Have you any requests?
Title: Re: sprite editor
Post by: johnno56 on September 09, 2020, 02:02:28 am
Just need an editor to draw pixels, lines, circles(plus fill), rectangles(plus fill)
For sprites 16x16 and up... Maybe a texture fill. There was a really old Amstrad (8 bit) that used a user-made texture fill. Amstrad CPC464 did not have a paint or fill command. The standard 4-way fill routine would work but was painfully slow... I have pretty much all of Amstrads programs, games and magazines... I will begin a search... manually... yikes!
Title: Re: sprite editor
Post by: bplus on September 10, 2020, 12:07:34 pm
@johnno56

Quick question, were the buttons setup to use the Lucon font? I ask because they are all aligned to top left corner and that would be what would happen if a bigger font were expected to be used. Are you using a Windows version of Lucon? I would like a copy if not. I am overhauling the code so I can add the drawing tools line, circle, fill, undo...

Also need more idea about what "textures" are, like checkerboards of colors or gradients of colors or...?

So far 469 LOC eliminated plus some more safety checks with LoadFile still far from idiot proof but at least you wont accidentally KILL QB64.exe ;-)) or any other files except png, jpg, bmp plus some save to file checks at newImage, Quit, LoadFile.
Title: Re: sprite editor
Post by: bplus on September 10, 2020, 05:25:19 pm
OK Line drawing working in overhauled SprDraw v04b2:

hmm... now I see a little misalignment, back to drawing board ;-) Lines sure look ragged!
Title: Re: sprite editor
Post by: johnno56 on September 11, 2020, 08:30:40 am
In regards to the font placement... Pure guess work. Didn't like the idea of the text starting from the 'edge'... Simply added a few pixels to the x and y of the _printstring()... and that's it... The use of lucon was purely mathematical. Before being introduce to _printwidth() and _printheight(), I used Lucon to help calculate the length of the string in pixels. Size 14 is 8 pixels wide. Number of letters in a label... the rest is simple math... Also, placing the text in the middle of the button has in my opinion, been done to death... lol But no, Lucon no longer needs to be used. If you find a font that looks better, by all means, give a try... I'd use Klingon if I could read it... lol 

In reference to the 'jagged' line... Just the other day, while researching line drawing, I read something about how to 'neaten' the line.... I only wish I could remember where I read it. It was just a passing note and didn't give it much thought... Don't you just hate that?

I am going to assume that the "Get Hue" button implies that the "default" drawing colour is now White? Cool.

In regards to textures. Mainly "fill patterns". Cherry Paint was written to be used on the Amstrad... Ugly as... But that was the mid 80's... lol
See attached...
Title: Re: sprite editor
Post by: bplus on September 11, 2020, 10:22:13 am
Hey @johnno56

Here is something to make note of: the default font in QB64 is 8 pixels wide and 16 pixels high (you can specify _FONT 8 for drawing special ASCII Characters, those are 8x8 and switch back and forth with _FONT 16, did you see my ASCII dice game?). You need to know that often in QB64 unless in screen mode 0 or as you say using your own font. I've been partial to Arial for clean lines ttf. If you don't, you should keep notes to track QB64 and the other Basics you use, QB64 is the one with all the Type stuff :)

QB64 should do Font width and height like they do Image width and height because after all it is an image too.
And images could be concatenated like printing font so you can tile a whole background with a strings of tile numbers.

Anyway, Get Hue is my name for what you called "Eye dropper". I didn't think "eye dropper" is too common but maybe "Get Hue" is obscure too, just remember Hue is the guy with all the colors in the grid ;-)) I didn't think it was really a drawing tool but you have to deactivate all the others so your mouse click on the grid picks up the color. So I put it 1st under drawing tools. For Mirror, not a drawing tool but an drawing tool enhancement is just a flag you toggle on and off. 

I got rid of zones and tools and track drawing mode with a letter and zone click is handled right there in main loop with left mouse button on, jobbed out to a sub if code is longer than a dozen lines. BTW what is difference between your right click "erase" and just setting color to background? None, I think, so no right mouse click stuff at moment but might be changed for popup menu for file stuff of maybe cherry picking color patterns like in your snapshot. That snapshot is loaded with ideas!

Yeah, icons for drawing tools much better than words! I am thinking your message box might be helpful for tool tips and helping instruct for more complicated too operations.


RE: Real Sprites!

So far what we are making are really tiles and restricted to square ones @64x64 eh...

I have been wondering how to do transparent color for real sprites, no background, just the object image like I did with Templar Cross. PNG files dont work well there is always background black when you take a point reading to save an image.

I am thinking a new extension .trn for transparent or .clr for clear so we can just layer an object image over everything behind it. Will need our own loadimage say loadSprite, easy enough I think.

What do you all think? Am I reinventing a wheel here?

Hmm... on second thought just make an image, load it into program then clearcolor the black, probably a lot less trouble.

RE: ICO files
Now I am wondering how an ico image is made. I tried to make one for Sudoku and going On-line to convert the PNG but the shrink always distorted the image beyond recognition. So I am wondering if we can make .ico images with this Editor.
Title: Re: sprite editor
Post by: johnno56 on September 11, 2020, 06:18:39 pm
Ok. Where to start... Someone has been busy! At least one of us knows what we are doing... lol

I'm still getting used to QB64. I thought that _font 8 etc where used for text only screen... Obviously I'm not ready enough of the help file...

Eyedropper was the first word I thought of... In most image editors the colour picker is an eyedropper. If you look in the assets folder there is a toolbox folder within it. I had whipped up a bunch of images to use in stead of using text. After all, most users, expect icons... I suppose I can make them into buttons.... That would take care of any font issues and or text placement. What do you think? I happy to go either way...

I figured the messagebox could be used not only as warning and errors. Oh... maybe a little humour in the messages? Like if you try to draw on the main grid... "Really? Without colour?" (I know. With a default colour this won't apply) It's just an idea. 'normal' messages are so... dull.

Transparencies... I have seen in the past when images were made, a specific colour - usually magenta - was used as the 'transparent' colour. The game editor would set that colour to be transparent. I don't know if QB64 can do that. I know Naalaa and SDLBasic can... Other than that, I have no idea how to achieve transparency, using QB64. That is probably why I chose right mouse click to erase using black. Logic: The mouse pointer is already on the pixel in error. Much more efficient to right click than mouse travel to the erase icon and back and when done mouse travel to change colour and back... Without transparency, right click, for me, works best. But that may change... To achieve transparency, a little mouse travel, could be an acceptable sacrifice...

Icon files. I have no idea as to the difference between ICO and any other image. I know that Linux will use just about 'any' image as a traditional ICO file. eg: When I right click on a Desktop application icon I can examine the 'properties' and can change that application icon to any image type (obviously of similar size) that I want. I can even use one that I made myself. I don't know if Windows can do that, but if it can, then ICO isn't really needed if it can you can use 'any' type of image. If any image can be used then we don't need to convert an ICO file... But, I suppose, we will have to cater for our Windows purists... lol  This may help. https://en.wikipedia.org/wiki/ICO_(file_format)
Title: Re: sprite editor
Post by: bplus on September 11, 2020, 06:47:53 pm
Definitely images for tools! so eyedropper is standard thing :)

Well I have frame and boxes working but a little difficulty getting ellipses symmetric (including circles), no, big problem! ;-))

Yeah, right mouse click way more convenient for erasing. That's easy and might be needed for fixing ellipses.
Title: Re: sprite editor
Post by: johnno56 on September 11, 2020, 07:34:02 pm
Gimp and MsPaint online... See attached.

I will work on the images. Draw the button and display the image or make the whole button an image? Either way is fine by me...

Hadn't thought of using the right mouse button for anchoring circles and ellipses (and other shapes).... I wasn't sure of getting that far with the editor... lol

Got to go shopping... Maybe back in a hour or so...
Title: Re: sprite editor
Post by: johnno56 on September 11, 2020, 10:02:36 pm
First attempt "toolbox".

Two sets of images, colour and minimal. Button "selected" images not done yet... If either of these, or if you have any images that you would prefer, let me know? Th finished buttons will have a transparent background.

These we just a simple copy, paste and recolour of the "toolbox" icons... The eyedropper is new.
Title: Re: sprite editor
Post by: bplus on September 11, 2020, 10:23:50 pm
OK finally got the symmetry worked out for ellipse / oval then everything came together after that. Back to calling it eyedropper and right click erases, it will erase Mirror also if that is still on = flagged.

Here I drew a sample of everything over a sample image mostly with Mirror toggled on.
 


A master piece ;-))

OK @johnno56  back to you for comments :)


Title: Re: sprite editor
Post by: johnno56 on September 11, 2020, 11:24:18 pm
Cool !!!  Nothing short of brilliant!

Minor suggestion: You have 'Oval' and 'Oval Fill'... Perhaps, if you prefer text buttons, instead of 'Frame', 'Box' and 'Box Fill'
What did you do to my mushroom? Looks like a rainbow threw up on him... lol

I think our next challenge: Sprite size. 8x8, 16x16 and 32x32... I only wished that I had not lost the early version that had various grid sizes.... The boxes and circles may not work so well on 8x8 and possibly the 16x16... The 8x8 is handy for "old school" games but I won't complain if we leave it out... lol  I'm going to go over my discs and archives to at least find a working prototype of grid changes. As you suggested before... there is no point re-inventing the wheel.... I will keep you posted.

Again. Brilliant job!!
Title: Re: sprite editor
Post by: johnno56 on September 11, 2020, 11:33:41 pm
I found a disk that has individual editors for 8x8, 16x16 and 32x32. They were all written with sdlbasic and 'prior' to the 'various' version. I will keep looking...
Title: Re: sprite editor
Post by: johnno56 on September 11, 2020, 11:48:33 pm
Version 2 and 3 were written using Naalaa. Both had the physical size change buttons coded but nothing else... Where's Sherlock when you need him?
Title: Re: sprite editor
Post by: johnno56 on September 12, 2020, 01:12:24 am
Performed an experiment... To draw a grid of 64x64 the gsize is set to 10 (64X10 =gridwidth). Likewise setting gsize to 20 etc etc.

In the plot() routine the 'size' is hard coded to 10 (64x64). Changed '10's to gsize. Hard coded gsize to 20 and a 32x32 grid was drawn... Hard coded to 40 - 16x16 grid. Coded to 80 - 8x8 grid.

Checked all the tools. Pencil, Line, Frame and Box performed correctly. Ovals (also fill)... Not so much. The other tools took advantage of plot(), which resized exactly, but the ellipses are drawn with the line()-() command. Single sized line. Ovals and filled ovals will still draw on all grid sizes, but because the line is a single thickness, the lines do not match the grid. See attached

The attached was hard coded to a gsize of 40 (16x16)

Another issue are the preview boxes. They also would need 'scaling'.  64x64 and 32x32 seem to be ok. The smaller grids seem to be an issue.
Title: Re: sprite editor
Post by: bplus on September 12, 2020, 12:22:33 pm
Performed an experiment... To draw a grid of 64x64 the gsize is set to 10 (64X10 =gridwidth). Likewise setting gsize to 20 etc etc.

In the plot() routine the 'size' is hard coded to 10 (64x64). Changed '10's to gsize. Hard coded gsize to 20 and a 32x32 grid was drawn... Hard coded to 40 - 16x16 grid. Coded to 80 - 8x8 grid.

Checked all the tools. Pencil, Line, Frame and Box performed correctly. Ovals (also fill)... Not so much. The other tools took advantage of plot(), which resized exactly, but the ellipses are drawn with the line()-() command. Single sized line. Ovals and filled ovals will still draw on all grid sizes, but because the line is a single thickness, the lines do not match the grid. See attached

The attached was hard coded to a gsize of 40 (16x16)

Another issue are the preview boxes. They also would need 'scaling'.  64x64 and 32x32 seem to be ok. The smaller grids seem to be an issue.

Right, I made the drawing tools leaving open the idea we will want to do squares of any size, including n X m rectangles eventually, just wanted to get one set working first. You can fix Plot4Way just as easy as Plot for the circle ellipse tools. I was also thinking with dot tool we could set a radius so we have a perfect circle fill. I don't know if you  noticed but ellipse /oval are drawn with 4 pixel = squares center and the left side gets shifted in alignment over a bit from the ellipse drawn while mouse button is down showing general placement of ellipse.

BTW Last night I had a wild and crazy idea, why don't we use Spr Draw to make our drawing tools icons?!?!
Title: Re: sprite editor
Post by: johnno56 on September 12, 2020, 05:37:31 pm
Well, you were correct, of course. Modifying plot4way did indeed solve the grid problem.

To change the the grid size, either by keyboard or button, would not be practical if one was in the midst of a project. I would dare to suggest that there are two opportunities to change the grid. 1. When the program starts and 2. When "New" is selected. I will the simplest option, keyboard 1 to 4, for 8x8 to 64x64... Sounds like fun...

Use sprdraw to make our own icons... At the moment, as long as the icons were squares, like the ones in the toolbox. No. I don't think that is a crazy idea. Our regular buttons are 80x40, slightly out of the range of the editor, but who said the buttons had to be rectangular? lol To keep similar button spacing, 40x40 could be possible... By changing gsize to 16...  Which I just tried and the grid size indeed changed to 40x40... :)

I will re-draw the "buttons", using sprdraw, to 40x40... Of course there will be no transparency... lol  Not a big deal at the moment... Seeing the background is black anyway... lol  This morning (Sunday) is quite busy for us, so it could be around noon before I can find the time. Just though of another function... 'Move'. When I was creating the last 'screenshot' I would have to draw, erase, redraw the ellipses. It's more of a time saver on larger icons really. Just a thought. Not sure why I thought of that at that particular time... 'Move' isn't important... Just an idea... Must remember the program was initially designed to do pixel art... Sprites and stuff...If we add too much then it becomes a Photoshop wanna-be.... lol Sorry. No coffee yet...
Title: Re: sprite editor
Post by: bplus on September 12, 2020, 07:04:48 pm
Hey @johnno56

What's wrong with buttons at 64X64? Just happens to be the size we have working now. Or do you already have any size working? I mean what's so special about 40?

It is not hard to draw a whole grid of 64x64 or any n X m buttons, have a tool belt that looks like a metal jacket.

hmm... to make draw objects to move around or manipulate, I like!

Oh yeah, for sizing grids just start a standard of loading and saving as "*NXM.png" where N and M are two numbers so we can read the grid size off the filename. Might be a limit to the size M and N though.

Oh and for transparency, we can read something else in file name a color code maybe to set the _CLEARCOLOR to that color and that color will be converted in a little sub so that color will be transparent when used in QB64.
Title: Re: sprite editor
Post by: Dav on September 12, 2020, 08:06:31 pm
Hey, this project is looking pretty neat!  I'll be following it.  I'm always interested in doodling programs. 

- Dav
Title: Re: sprite editor
Post by: johnno56 on September 12, 2020, 09:10:20 pm
Bplus,

Absolutely nothing wrong with 64x64. 40x40 special? Nope. Just the same height as the existing buttons and would not take much to modify their placement. As we don't have too many 'active' buttons at the moment, 64x64 buttons, will work just fine. MSPaint uses small square image buttons. Gimp (and I think Photoshop) uses an 'area' populated with clickable images. We already use rectangular buttons. I will try to make a 'mockup' of an 'area' of images.  See the 'area' that Gimp uses... Of course, we do not have as many tools, but it's the idea of the layout...
Title: Re: sprite editor
Post by: johnno56 on September 13, 2020, 12:11:19 am
Just threw together a vertical 'tree' of tool icons (40x40). It's easy enough to bump them up to 64x64.

If you have any ideas on layouts, just let me know, and I'll whip up a new batch....
Title: Re: sprite editor
Post by: bplus on September 13, 2020, 12:16:59 am
I was just going to say, I had another look at those Toolbox buttons and they looked OK too.

You make the call on buttons, I am going to try and get that file retriever to have both lists going at once.

Also do you have doing the different gsizes worked out?
Title: Re: sprite editor
Post by: johnno56 on September 13, 2020, 02:55:04 am
In reference to gsizes... So far all I have is hard coding. But, there are issues with previews. I need to look at scaling the image, for different main grid sizes, to occupy the entire preview window. If I hard code the the gsize (80) to display an 8x8 main grid, the preview image, is just a tiny copy in the upper left corner of the preview. As, saving and loading requires 'scanning' of the small preview, if would be best if the entire preview window is occupied. I hope I am making sense...
Title: Re: sprite editor
Post by: johnno56 on September 13, 2020, 04:40:18 am
I don't mean to harp on this... The attached images will give you an idea of the preview issue.
The main grid (10x10) contains a filled 10x10 oval. The main grid is translated to the preview box. The preview box image is the image saved. When the saved image (with the tiny oval in the top left corner) is loaded, it is placed in the preview box and translated back to the main grid. The main grid will display a small oval in the top left corner.

Any ideas?
Title: Re: sprite editor
Post by: bplus on September 13, 2020, 10:41:03 am
I don't mean to harp on this... The attached images will give you an idea of the preview issue.
The main grid (10x10) contains a filled 10x10 oval. The main grid is translated to the preview box. The preview box image is the image saved. When the saved image (with the tiny oval in the top left corner) is loaded, it is placed in the preview box and translated back to the main grid. The main grid will display a small oval in the top left corner.

Any ideas?

Yes, that is why we need to save the the N X M grid size in the file name and offer grid size input when start a new image or loading some part of an image. Then track down every place that uses gsize or 10 for gsize and change all that from const gsize to Dim Shared gSize or 2: gSizeX and gSizeY if you want to graduate from squares.

The trickiest part is tacking a N X M.png onto the end of the filename. I am just saying .png to get one extension going , could be jpg or .bmp.  What character will Linux take in file name that we can use to separate Name part from number part $? So it would be "Filename$64x32.png" for a 64 x 32 image grid

Then we can read gSizeX = 64 and gSizeY = 32 and adjust those variables and then draw our grid and run the code from there. So yeah, if we start a new image the file name will have to be setup, thank goodness we have an inputBox sub or function (I forgot).

BTW I don't know well numbers not divisible by 2 will work or if we should mess with different x and y sizes.

I'd say get the buttons nailed down first. I hope to have 2 lists going in file retriever then start on grid size problem.
If you use a grid of buttons, you can tell which one is clicked just like you can tell which grid cell is clicked on the grid, it's just a different grid with different grid sizes.
Title: Re: sprite editor
Post by: bplus on September 13, 2020, 10:43:42 am
Hey, this project is looking pretty neat!  I'll be following it.  I'm always interested in doodling programs. 

- Dav

Thanks Dav, your input welcome! :)

A little reminder, Johnno has Linux and we can't use normal Windows tools for things.
Title: Re: sprite editor
Post by: SMcNeill on September 13, 2020, 12:32:10 pm
If you guys want my simple take on how I'd set this project up and work with it, I'd go with a main layout similar to something like this:

Code: QB64: [Select]
  1. MainScreen = _NEWIMAGE(1024, 720, 32)
  2. ZoomLevel = 16
  3.  
  4. SCREEN MainScreen
  5.  
  6.  
  7.     CLS , 0
  8.  
  9.     DrawGrid ZoomLevel
  10.         SELECT CASE _MOUSEWHEEL
  11.             CASE IS > 0: ZoomLevel = ZoomLevel * 2: IF ZoomLevel > 512 THEN ZoomLevel = 512
  12.             CASE IS < 0: ZoomLevel = ZoomLevel \ 2: IF ZoomLevel < 1 THEN ZoomLevel = 1
  13.         END SELECT
  14.     WEND
  15.  
  16.  
  17.     LOCATE 1, 80: PRINT "GRID SIZE :"; 512 \ ZoomLevel; "X"; 512 \ ZoomLevel
  18.     LOCATE 2, 80: PRINT "PIXEL SIZE:"; ZoomLevel; "X"; ZoomLevel
  19.     _LIMIT 30
  20.     _DISPLAY
  21.  
  22.  
  23. SUB DrawGrid (ZoomLevel)
  24.     FOR i = 0 TO 512 STEP ZoomLevel
  25.         LINE (i, 0)-STEP(0, 512)
  26.         LINE (0, i)-STEP(512, 0)
  27.     NEXT

The concept here is rather simple:  Load any sort of image which you want and work with it inside a fixed 512x512 screen area.  (Add a simple set of scroll bars to the side, if you need to see more than that area at any given time.)

The default resolution which we work at is a 32x32 grid area, of 16x16 pixels, for ease of selecting and editing, but it can be easily zoomed in, or zoomed out, as we desire -- to between a 512x512 grid of 1x1 pixels, up to a 1x1 grid of 512x512 pixels.  (The demo here showcases the zoom feature, and shows how easy you can implement it.)

All your mouse needs to do is convert any clicks you make upon the grid into coordinates for the original, unscaled image, and then apply your changes there.

Like this, you can easily work with any sort of sprite size, and at various levels of zoomability, to have your editor working with whatever images/sprites, you want to create.  ;)
Title: Re: sprite editor
Post by: bplus on September 13, 2020, 02:08:09 pm
If you guys want my simple take on how I'd set this project up and work with it, I'd go with a main layout similar to something like this:

Code: QB64: [Select]
  1. MainScreen = _NEWIMAGE(1024, 720, 32)
  2. ZoomLevel = 16
  3.  
  4. SCREEN MainScreen
  5.  
  6.  
  7.     CLS , 0
  8.  
  9.     DrawGrid ZoomLevel
  10.         SELECT CASE _MOUSEWHEEL
  11.             CASE IS > 0: ZoomLevel = ZoomLevel * 2: IF ZoomLevel > 512 THEN ZoomLevel = 512
  12.             CASE IS < 0: ZoomLevel = ZoomLevel \ 2: IF ZoomLevel < 1 THEN ZoomLevel = 1
  13.         END SELECT
  14.     WEND
  15.  
  16.  
  17.     LOCATE 1, 80: PRINT "GRID SIZE :"; 512 \ ZoomLevel; "X"; 512 \ ZoomLevel
  18.     LOCATE 2, 80: PRINT "PIXEL SIZE:"; ZoomLevel; "X"; ZoomLevel
  19.     _LIMIT 30
  20.     _DISPLAY
  21.  
  22.  
  23. SUB DrawGrid (ZoomLevel)
  24.     FOR i = 0 TO 512 STEP ZoomLevel
  25.         LINE (i, 0)-STEP(0, 512)
  26.         LINE (0, i)-STEP(512, 0)
  27.     NEXT

The concept here is rather simple:  Load any sort of image which you want and work with it inside a fixed 512x512 screen area.  (Add a simple set of scroll bars to the side, if you need to see more than that area at any given time.)

The default resolution which we work at is a 32x32 grid area, of 16x16 pixels, for ease of selecting and editing, but it can be easily zoomed in, or zoomed out, as we desire -- to between a 512x512 grid of 1x1 pixels, up to a 1x1 grid of 512x512 pixels.  (The demo here showcases the zoom feature, and shows how easy you can implement it.)

All your mouse needs to do is convert any clicks you make upon the grid into coordinates for the original, unscaled image, and then apply your changes there.

Like this, you can easily work with any sort of sprite size, and at various levels of zoomability, to have your editor working with whatever images/sprites, you want to create.  ;)

This gives me some ideas to test.
Title: Re: sprite editor
Post by: SMcNeill on September 13, 2020, 06:43:34 pm
This gives me some ideas to test.

Give this little demo a quick test and see if it's not about what you'd be wanting for your sprite editor:

Code: QB64: [Select]
  1. DIM SHARED StartX, StartY, CurrentX, CurrentY, StopX, StopY, EndX, EndY
  2. DIM SHARED EditScreen
  3.  
  4. MainScreen = _NEWIMAGE(1024, 720, 32)
  5. EditScreen = _LOADIMAGE("wood.jpg", 32)
  6. ZoomLevel = 16
  7.  
  8. SCREEN MainScreen
  9. CurrentX = 0: CurrentY = 0
  10.  
  11.  
  12.     CLS , 0
  13.  
  14.     _PUTIMAGE (0, 0)-(511, 511), EditScreen, MainScreen, (CurrentX, CurrentY)-STEP(512 \ ZoomLevel - 1, 512 \ ZoomLevel - 1)
  15.     DrawGrid ZoomLevel
  16.         SELECT CASE _MOUSEWHEEL
  17.             CASE IS > 0: ZoomLevel = ZoomLevel * 2: IF ZoomLevel > 512 THEN ZoomLevel = 512
  18.             CASE IS < 0: ZoomLevel = ZoomLevel \ 2: IF ZoomLevel < 1 THEN ZoomLevel = 1
  19.         END SELECT
  20.     WEND
  21.     k = _KEYHIT
  22.     SELECT CASE k
  23.         CASE 27: SYSTEM
  24.         CASE 19200: CurrentX = CurrentX - 1: IF CurrentX < 0 THEN CurrentX = 0
  25.         CASE 19712: CurrentX = CurrentX + 1: IF CurrentX > StopX THEN CurrentX = StopX
  26.         CASE 18432: CurrentY = CurrentY - 1: IF CurrentY < 0 THEN CurrentY = 0
  27.         CASE 20480: CurrentY = CurrentY + 1: IF CurrentY > StopY THEN CurrentY = StopY
  28.     END SELECT
  29.  
  30.     LOCATE 1, 80: PRINT "GRID SIZE :"; 512 \ ZoomLevel; "X"; 512 \ ZoomLevel
  31.     LOCATE 2, 80: PRINT "PIXEL SIZE:"; ZoomLevel; "X"; ZoomLevel
  32.     LOCATE 3, 80: PRINT "X/Y START :"; CurrentX, CurrentY
  33.     LOCATE 4, 80: PRINT "X/Y END   :"; CurrentX + 512 \ ZoomLevel, CurrentY + 512 \ ZoomLevel
  34.     LOCATE 6, 80: PRINT "PIC SIZE  :"; _WIDTH(EditScreen), _HEIGHT(EditScreen)
  35.     LOCATE 7, 80: PRINT "X/Y STOP  :"; StopX, StopY
  36.  
  37.     _LIMIT 30
  38.     _DISPLAY
  39.  
  40.  
  41.  
  42.  
  43. SUB DrawGrid (ZoomLevel)
  44.     EndX = _WIDTH(EditScreen)
  45.     EndY = _HEIGHT(EditScreen)
  46.     StopX = EndX - 512 \ ZoomLevel
  47.     StopY = EndY - 512 \ ZoomLevel
  48.     FOR i = 0 TO 512 STEP ZoomLevel
  49.         LINE (i, 0)-STEP(0, 512), _RGBA(64, 64, 64, 64)
  50.         LINE (0, i)-STEP(512, 0), _RGBA(64, 64, 64, 64)
  51.     NEXT

This should work with any image file, but I attached the one I was using.  (Which I think was one Cobalt provided for one of his game demos, and I hadn't cleaned it out yet?)

There's no actual selection of anything yet, and I haven't bothered to convert any sort of mousex/mousey input to make it useful, but I think this goes a long ways towards highlighting how I'd work up an image editor with built-in zoomability functionality. 

Honestly, I can't imagine any way to work with something like this, any simpler than the above.  Our sprite/image is always separate from the main program (EditScreen), so we're not tracking pixels, or an array of information, or anything like that.  All we do is convert the coordinates, and the command we want, and we apply it directly to the image in question.  When finished, simply save that image with the SaveImage library.  :)

Test it out.  See if the little demo here isn't doing about what you'd want it to do.  Here's to hoping it'll help spark all sorts of nice ideas for you guys to add into your own work-in-progress.  ;D


NOTE:  As I'm lazy and haven't implemented scrollbars just for a demo, use the arrow keys to navigate around in your image. 
Title: Re: sprite editor
Post by: bplus on September 13, 2020, 10:06:27 pm
Hi Steve,

I was thinking about something like that when loading images to work in the editor. If we can scan over an image at various zoom levels and pickup some section to workup in the editor...

I am in middle of 2nd massive over haul actually making it easier to modify buttons, maybe. With a 512 grid I reduced screen width to 1024, and moved things around and have a ton of room for more buttons. All this could be giant waste of time if I can't rework all the tools to different gSizes, just about getting to that now.
Title: Re: sprite editor
Post by: SMcNeill on September 14, 2020, 02:21:22 am
I couple of important buttons I think you guys should have: BLEND and NO BLEND, and REPLACE.

(No) Blend is a simple toggle which dictates whatto do with an alpha color.   When on, your color blends into the background.  (RGBA(128,128,128,128) might fade to a light pink while on a deep red background, for example.). When off, the area selected becomes that value, instead.

Replace simply lets you choose a color in the image, and then replace it with another.  You could select black, for instance, and with a single click turn it all red.

In combination, the two provide the extremelt useful functionality of letting one choose a 255 alpha black, and transform it into a 255 alpha clear, before saving.
Title: Re: sprite editor
Post by: bplus on September 14, 2020, 01:15:10 pm
Update: now drawing different sized tiles or sprites from 3X3 pixels to 64X64 pixels (still finding little clunkers so won't post code yet).

Here is Celtic Knot testing at 15X, I attached the 15X Cletic knot file so you can check out it's pixel size :)
Title: Re: sprite editor
Post by: bplus on September 15, 2020, 12:46:50 am
Hey @johnno56  and all!

Here is SprDraw v04b3 another overhaul and some refinements, see how you get along without any instructions ;-))

Oops there is a sub folder too, just a sec...  OK my tests of 2nd zip look good.