Recent

Author Topic: Jigsaw Program (attached) :)  (Read 5273 times)

speter

  • Sr. Member
  • ****
  • Posts: 345
Jigsaw Program (attached) :)
« on: December 29, 2021, 05:30:54 am »
G'Day Folks,

Last year, at about this time of the year, I posted a Perspective program
(https://forum.lazarus.freepascal.org/index.php/topic,52526.0.html)
and received lots of help making it work better (especially in MacOS & Linux).

I'm back. :)

This year I am posting a (windows) Jigsaw Puzzle program; and I think I'll need plenty of help (again), making it work in MacOS & Linux.

In particular, the bitmap clipping code I am using seems to be windows specific. Is there alternative coding I can use to implement this!?

Procedure Button_startClick() at line 530 in mainu.pas includes:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button_startClick(Sender: TObject);
  2. type
  3.   tpts = array [0..200] of tpoint;
  4. var
  5.   a, x,y : integer;
  6.   p : array of tpoint;
  7.   clip : hrgn;
  8.   clip_pts : tpts;
  9.   dest : trect;
  10. begin
  11. ...
  12.           for a := 0 to num_pts-1 do // @ line 618
  13.             clip_pts[a] := point(p[a].x-ext_min.x,p[a].y-ext_min.y);
  14.  
  15.           clip := createpolygonrgn(clip_pts,num_pts,alternate);
  16.  
  17.           selectcliprgn(pic.Canvas.handle,clip);
  18.           pic.Canvas.CopyRect(dest,image1.Picture.Bitmap.Canvas,
  19.           rect(ext_min.x,ext_min.y, ext_max.x,ext_max.y));
  20.  
  21.           selectcliprgn(pic.Canvas.handle,0);
  22.           deleteobject(clip);
  23.       end;
  24.  
  25.   drawstage;
  26. end;

In addition to the above, (at present) the program saves the INI file in the executable's folder. I haven't included an INI file with the attached project, so the program will ask you to select an images folder when it starts (and doesn't find the INI file).

For your entertainment (particularly if you are using windows); I've attached the project (with 4 sample images).

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

mike_p

  • New Member
  • *
  • Posts: 20
Re: Jigsaw Program (attached) :)
« Reply #1 on: December 29, 2021, 10:29:27 am »
Lovely project: I particularly like the algorithm that creates the pieces!

Unfortunately I cant help with MacOS and linux as I dont have them setup at at the moment.
Just a few ideas for you:

1/  When I first ran it it couldn't find my images: I had to add lowercase to the file extension: (line 180 in mainu)
Code: Pascal  [Select][+][-]
  1.            (pos(lowercase(ExtractFileExt(info.name)),ok_img_ext) > 0) then    

2/ After initial start, no opportunity to change directory: maybe have a simple button for the purpose?

3/ Good place for inifile: GetAppConfigDir(False);

4/ I expected to be able to drag and drop the pieces. I took me a while to work out how to do it. Would prefer to use classic drag n drop where by the piece is only dragged as long as you keep the mouse button pressed. This would also help because the way it works now, the piece will automatically place it self as it get dragged over its position. Would be better if it only fitted when you release it.

5/ Would be nice to have the option to not show the piece positions (ie more like normal jigsaw puzzles)

6/ Allow different background colours. With an image I tested, I had pale pieces that I couldn't see against the white background.

balazsszekely

  • Guest
Re: Jigsaw Program (attached) :)
« Reply #2 on: December 29, 2021, 11:50:01 am »
@speter

Remove windows from uses, add math, lcltypes, lclintf and your project should compile both on linux and macOS(not tested).

balazsszekely

  • Guest
Re: Jigsaw Program (attached) :)
« Reply #3 on: December 29, 2021, 01:07:05 pm »
It compiles fine for me with Lazarus Trunk, however there are some hard coded ini file paths, which are not gonna work on linux and macOS:
Code: Pascal  [Select][+][-]
  1. ini_fn  = data_folder+ "\jigsaw.ini".
The directory separator is wrong.

speter

  • Sr. Member
  • ****
  • Posts: 345
Re: Jigsaw Program (attached) :)
« Reply #4 on: December 29, 2021, 11:55:32 pm »
Thanks very much everyone. I'll do a bit of work/thinking and post a new version in 6 hours of so. :)

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

speter

  • Sr. Member
  • ****
  • Posts: 345
Re: Jigsaw Program (attached) :)
« Reply #5 on: December 30, 2021, 04:51:04 am »
I've attached a new version of the program. :)

I made the following changes:
  + changed data_folder, ini_fn & help_fn to variables.
  + changed to use "DirectorySeparator" constant instead of "\".
  + added a call to GetAppConfigDir() in FormCreate.
  + included help text as a constant (in case the program can't find the help text file).
  + replaced "uses windows" with "uses math, lcltype, lclintf".
  + added "..." button to allow the images folder to be changed.
  + added upper-case image extensions (BMP etc).

I didn't change:
  + the move-piece code to respond to dragging (it still requires an initial click, then a mouse-move).
  + the drawing of the piece outlines on the stage.

Once again, my thanks to everyone for their very helpful comments & suggestions.

As before, I'd really like to hear from folks (specially those not using windows). :)

cheers
S.
« Last Edit: December 30, 2021, 04:54:28 am by speter »
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

balazsszekely

  • Guest
Re: Jigsaw Program (attached) :)
« Reply #6 on: December 30, 2021, 09:39:29 am »
@speter

Now it works on macOS too  :), however it's very hard to move the pieces around. Maybe you should improve the method a little bit. Please note, this is not OS specific, does not work on windows either.

speter

  • Sr. Member
  • ****
  • Posts: 345
Re: Jigsaw Program (attached) :)
« Reply #7 on: December 30, 2021, 10:32:33 am »
Now it works on macOS too  :), however it's very hard to move the pieces around. Maybe you should improve the method a little bit. Please note, this is not OS specific, does not work on windows either.
Excellent, thanks for that info.

Can you please explain what you mean by "hard to move the pieces"?

Has anyone tried the program on Linux!?

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

balazsszekely

  • Guest
Re: Jigsaw Program (attached) :)
« Reply #8 on: December 30, 2021, 10:46:18 am »
Quote
Has anyone tried the program on Linux!?
Yes. It works on linux too(Mint cinnamon 20.02 64 bit).

Quote
Can you please explain what you mean by "hard to move the pieces"?
I read the help file:
Quote
To place a jigsaw piece, click on the piece (don't hold the mouse-button down), then move the mouse (& piece) to the stage
This is counterintuitive, at least for me. Anyways congratulation for your game!

speter

  • Sr. Member
  • ****
  • Posts: 345
Re: Jigsaw Program (attached) :)
« Reply #9 on: January 07, 2022, 05:23:25 am »
G'Day Folks,

Sorry for the delay (I've been a bit sick over the past week). ;)

I am attaching a new version of the Jigsaw Puzzle program to this post.
I have implemented most suggestions; except for drag'n'drop.

The main changes are:
  + added a "settings" tab;
  + moved the "help" text to the settings tab;
  + allow the images folder to be reset;
  + set the background colour of the Jigsaw tab;
  + added 2 new jigsaw styles (which are kinda horrible);
  + allow the user to _not_ see the piece outlines on the stage;
  + a warning is displayed at startup (for mouse-move);
  + ^^ this warning can be turned off on the settings tab.
  + added an option to replace old INI & Help files.

In case I didn't write it earlier, I recommend that you use your own images with the program! But, if you like the four images I have included, I have uploaded larger versions to imgur.com; the URLs of the images are:
  https://i.imgur.com/sc8zWPw.jpg
  https://i.imgur.com/0lTLSxH.jpg
  https://i.imgur.com/AhRjdno.jpg
  https://i.imgur.com/DryyBd7.jpg

When I looked at drag'n'drop, it all seemed easy / resonable until I wanted to show the piece being moved during the drag action. So, at present I have not included that functionality. :)

My sincere thanks to everyone for their advice and suggestions.

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

 

TinyPortal © 2005-2018