adamwulf / JotUI

OpenGL based drawing view built for and used by Loose Leaf for iPad
http://getlooseleaf.com/opensource/
MIT License
268 stars 28 forks source link

Can we save current drawing for later use and start another fresh drawing ? #13

Open KrLikeblue opened 7 years ago

KrLikeblue commented 7 years ago

Hello Adam, It's me again :)

I want to ask you that, I want to save current drawing for later use and want to start another fresh drawing, So is it possible ?

Basically I want to know that can we save as many files as we want ? and when we use them again, that particular file must have previous drawing which we had drawn on it.

Waiting for your great answer.

Thanks.

adamwulf commented 7 years ago

Yep! check out the loadState: method to load from disk, and use the exportImageTo:exportThumbnailTo:andStateTo:withThumbnailScale:onComplete: to save to disk. Loose Leaf handles save/load in the https://github.com/adamwulf/loose-leaf/blob/master/Project/LooseLeaf/MMEditablePaperView.m class as an example.

KrLikeblue commented 7 years ago

I understood it.. :)

Will try it.

Thanks.

KrLikeblue commented 7 years ago

Hello Adam,

There is one bug while saving multiple drawing items.

All drawings are being saved successfully when I call "exportImageTo:" for saving.

But when I tried to load any previous drawing, then it comes blank.

When I try to load current drawing, then that drawing is appearing.

The reason is all previous .strokedata files are removed from documents directory folder when you save current drawing .strokedata files

And bug is in #import "JotViewImmutableState.m" file

here are lines of code which cause this bug NSArray contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:stateDirectory error:nil]; for (NSString item in contents) { NSString* fileInDir = [stateDirectory stringByAppendingPathComponent:item]; if (![fileNamesOfStrokes containsObject:fileInDir] && [[fileInDir pathExtension] isEqualToString:kJotStrokeFileExt]) { [[NSFileManager defaultManager] removeItemAtPath:fileInDir error:nil]; } }

I have commented above code and then I can access all my drawings.

So I have commented that code, will It cause any problem for my drawings ?

Waiting for an answer. Thanks.

adamwulf commented 7 years ago

Instead of saving all drawings to the same directory, you should be saving each to their own directory. Use the delegate methods during load/save, and return different directories for each drawing. Otherwise, you'll find that the ink.png and thumb.png are constantly overridden as well if you continue saving into the same directory.

KrLikeblue commented 7 years ago

So you mean to say, I will have to create different folder in documents directory every time I start drawing fresh ? In your example, you are saving all in just documents directory folder.

And Right now what I am doing is, I am naming "ink.png" ad "thumb.png" different names for every drawing like "ink1.png" "thumb1.png" , "ink2.png" "thumb2.png" like this, so i think they will not override, What I want to ask you is, can stroke path(saved in documents directory) of different drawing be overridden ? or they will be unique ?

adamwulf commented 7 years ago

ah - if you're renaming the ink/thumb pngs, then it should be ok to keep the strokedata all in the same directory. they'll be unique for each drawing. though i initially designed it to be saved per-folder, just to keep things clean and separate. if it works for you to stay in 1 folder, that'll work fine though.