Author Topic: SpriteEditor  (Read 3946 times)

John

  • Sr. Member
  • ****
  • Posts: 362
    • View Profile
Re: SpriteEditor
« Reply #15 on: November 17, 2014 »
I just figured out the same result and was about to let you know... I figured out the reason why I couldn't see it. No coffee! Well, that's my excuse, and I'm sticking with that one. Many thanks.

Now that problem is out of the way, I can concentrate on the next one...

J

Isn't it like 3 in the morning over there? Are you up early or haven't you gone to bed yet?  The weirdness of pixeli is all my fault (and Marcus's).

johnno56

  • Guest
Re: SpriteEditor
« Reply #16 on: November 17, 2014 »
NOOO.... It's just after 5  :-[

johnno56

  • Guest
Re: SpriteEditor
« Reply #17 on: November 18, 2014 »
Here is the next installment.

I decided to go with the 64x64 (but that could change). I have upsized the display to 1024x768 to accommodate the 64x64 grid.

What's new: Controls: New, Load, Save (not coded yet), Quit (I have not forgotten the new button code ;) )

At the moment, Load will use a sample image. I am yet to figure out how to scan the system for files and how to put files on the system.

When the image loads, it will be displayed at normal size, and will be transferred to the main grid. It took me ages to figure out how to do that.

Current colour selection is also done, due to the assistance, of you guys. Much appreciated.

To do: The hard part. To draw on the grid. I am yet to find or code a decent "fill" routine. All the ones I have tried, so far, have caused memory problems. Even on my windows box. I have tried non-recursive; recursive; simple scanline fill; I have not tried the 4 and 8 direction fills as the cells are very small, I had considered using a simple filled rectangles, but will not line up with the grid cell, when the mouse is clicked. I miss the old basic paint command.

I have no idea how to code and implement other "tools". eg: Line draw; Circle with or without fill; Square/rectangle draw with or without fill; "Brush" size... I don't want to "over do" the tools, as that would negate the reason for simplicity.

I know the coding is not too efficient, but at the moment, it seems to work.

I am wide open for ANY suggestions/criticisms/advice, as long as it is constructive, just remember, I bruise easily...

J

Rick3137

  • Sr. Member
  • ****
  • Posts: 342
  • May the Force be with You
    • View Profile
    • Rick's Programs
Re: SpriteEditor
« Reply #18 on: November 18, 2014 »
  I think this is going to be a top notch utility. I like your easy to read coding style.
  I have one little idea about style that might help. Make your main loop shorter and move most of your code to procedures. I have been trying to do this with my programs and it has helped me when I go back later and try to find a piece of code to edit.  John put a neat little goto box at the top of the editor that I use alot to find my code.

 About the paint function. I think that a simple draw rect function (with fill) would work here.

John

  • Sr. Member
  • ****
  • Posts: 362
    • View Profile
Re: SpriteEditor
« Reply #19 on: November 18, 2014 »
I am yet to figure out how to scan the system for files and how to put files on the system.

I'm not sure if this is what you're asking for. But you can use 'openfile' and 'savefile' to show file dialogs:

Code: [Select]
rem Show 'Open file' dialog.
filename$ = openfile("bmp")
wln "File to open = ", filename, " Press any key to continue"
wait keydown

rem Show 'Save file' dialog.
filename$ = savefile("bmp")
wln "File to save = ", filename, " Press any key to exit"
wait keydown

I recommend following Rick's advice and use more subroutines. The entire image information is in the 'maingrid' image, right? Have one procedure that redraws the big picture and one that updates the small one. That would clean things up a little.

Anyway, everything looks great :) Looking forward to the next update.
 

johnno56

  • Guest
Re: SpriteEditor
« Reply #20 on: November 18, 2014 »
Thanks for the advise guys.

John:

You all must be mind readers. Just after I posted, I searched the documentation, for file commands. Which then inspired the search through the examples. Your coding looks so simple. Cool. I will try that asap.

Rick:

Thought of the "rectangle" approach. But I could not figure out how to draw a rectangle by just moving the mouse over a cell. Drawing the rectangle is obviously the most efficient way to go, but getting the rectangle to align with a cell, that's hard. I hope I am making sense.

To all:

I too agree with the "procedure" method. I am still a bit "old school". I am used to the old method of jumping around the program with goto's and gosub's. I am trying to get away from the spaghetti basic days and trying to do things more sequentially. I was going to try to "clean up" once the program was working. You guys a right. I should use more procedures and functions.

I will implement your suggestions as soon as I can and post an update.

Admin:

I think this "code snippet" is becoming more than just a "snippet". Can we transfer this thing to "Projects"?

Again. Thanks for the advice. This noob appreciates your efforts.

J

John

  • Sr. Member
  • ****
  • Posts: 362
    • View Profile
Re: SpriteEditor
« Reply #21 on: November 18, 2014 »
Regarding the rectangles. I'd draw everything every frame of the loop, to start with atleast.  When the mouse cursor is over the big picture I'd also draw the current color, as a marker:

mousegridx = mousex()/10
mousegridy = mousey()/10
if mousedown
   change pixel in maingrid to current color
   maingrid[mousegridx][mousegridy]= current
endif
...
draw entire big picture, then draw marker rect under mouse
set colori current
draw rect mousegridx*10, mousegridy*10, 10, 10, true

Or something like that. you'll probably figure out a good solution yourself that works the best for this project.

Now I neef to sleep, so tired ...


johnno56

  • Guest
Re: SpriteEditor
« Reply #22 on: November 18, 2014 »
Thanks for the transfer and the advise. Have a good sleep.

J

johnno56

  • Guest
Re: SpriteEditor
« Reply #23 on: November 18, 2014 »
John:

Your code for loading a file worked like a charm. Modified the "load" routine and up came the image.

Not so fortunate with the save. Created a "save" routine; loaded the sample file; "save" to save a file; dialog popped up; entered sample64x64.png as the filename; "New" to clear the grids; "load" to load file, but the new file just saved, was not listed. Looked at the directory on the system and noticed that the file had not been created... I will do some more research and get back to you.

J

ps: Ignore the "save" problem... it was me... I had left out the "save image" command. All is well...
« Last Edit: November 18, 2014 by johnno56 »

johnno56

  • Guest
Re: SpriteEditor
« Reply #24 on: November 19, 2014 »
Found another minor glitch. I accidentally loaded the 'colourpatch' image, instead of the sample image, and it loaded. But only the first 64x64 pixel area appeared on the main grid and the whole image appeared in the preview.

Used the width() and height() commands to restrict the size of the image being loaded to 64x64. Which then caused me to consider creating warning messages....  Does this kind of stuff happen to you guys as well, or is it just me?  **sigh**

Now for drawing on the main grid. This will require a LOT of caffeine....

J

johnno56

  • Guest
Re: SpriteEditor
« Reply #25 on: November 19, 2014 »
John:

With you assist with the drawing code, I can now draw on the main grid, using rectangles that actually align... Woo Hoo!!

I have a question about saving. Loading a sample file works fine. After viewing the file, I select "new", to create my own. The image is saved using a filename of choice. To test, I select "new" to erase it, then load the file I had just saved. The problem is that the file that I saved was "not" the one I created, but the one I loaded before. I tried the 'free file' command and that did not appear to work.

The idea is that an images is drawn on the main grid and transferred to the preview area. When save is selected, the image is meant to be scanned and saved as a file. That 64x64 file is then loaded back into the preview area and immediately transferred to the main grid.

As it stands, that is not what is happening. The file that is loaded into memory is being saved instead. Are there any commands that will grab an area of an image and save that grabbed area as a file? I hope that I am making sense...

J

johnno56

  • Guest
Re: SpriteEditor
« Reply #26 on: November 19, 2014 »
Latest instalment. Try the "save" function and you will see what I mean. I cannot save anything that I create on the main grid.

Please ignore all the "rem" statements. Combination of just comments and proposed modifications. I also testing out 'procedures'. Very untidy at the moment...

J

John

  • Sr. Member
  • ****
  • Posts: 362
    • View Profile
Re: SpriteEditor
« Reply #27 on: November 19, 2014 »
I haven't looked at it yet. But - bad news - naalaa can only save images as bmp (and tga using some code from the examples). Give me a moment (maybe more) and I shall see what can be done about it for other image formats.

I'll be back.


Rick3137

  • Sr. Member
  • ****
  • Posts: 342
  • May the Force be with You
    • View Profile
    • Rick's Programs
Re: SpriteEditor
« Reply #28 on: November 19, 2014 »
 Here's what you need to fix it:

procedure updatepreview()
   for prevx = 0 to 63
      for prevy = 0 to 63
         set colori pixeli((prevx*10)+5,(prevy*10)+5)
         set pixel 700+prevx,100+prevy
      set image 1
         set pixel prevx,prevy
      set image primary
      next
   next
endproc

 And it does do .png files. (At least on Window7)
 There is a bug in a Dll somewhere that makes you type in the whole file name...
 test.png   
 It will not add the '' .png "

 T

John

  • Sr. Member
  • ****
  • Posts: 362
    • View Profile
Re: SpriteEditor
« Reply #29 on: November 19, 2014 »
And it does do .png files. (At least on Window7)
 There is a bug in a Dll somewhere that makes you type in the whole file name...
 test.png   
 It will not add the '' .png "
 T

I'm in a rush, so I'm not quite sure what I'm answering now ;)

The last version of NaaLaa could only save images as BMP. But I've released a patch that allows saving as PNG. Check the announcement section.

Right, the file dialog does not automatically add the extension (like png or bmp) to the filename you type in. Do a check before saving the image:

Code: [Select]
if not lower(right(filename, 4)) = ".png" then filename = filename + ".png"

I have not looked at the program yet. But Rick's code suggests that you've created an image (id 1) the size of the preview (64x64) that you can use when saving?
« Last Edit: November 19, 2014 by John »