Forum > Graphics

Jigsaw Program (attached) :)

(1/2) > >>

speter:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button_startClick(Sender: TObject);type  tpts = array [0..200] of tpoint;var  a, x,y : integer;  p : array of tpoint;  clip : hrgn;  clip_pts : tpts;  dest : trect;begin...          for a := 0 to num_pts-1 do // @ line 618            clip_pts[a] := point(p[a].x-ext_min.x,p[a].y-ext_min.y);           clip := createpolygonrgn(clip_pts,num_pts,alternate);           selectcliprgn(pic.Canvas.handle,clip);          pic.Canvas.CopyRect(dest,image1.Picture.Bitmap.Canvas,          rect(ext_min.x,ext_min.y, ext_max.x,ext_max.y));           selectcliprgn(pic.Canvas.handle,0);          deleteobject(clip);      end;   drawstage;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.

mike_p:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---           (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.

GetMem:
@speter

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

GetMem:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---ini_fn  = data_folder+ "\jigsaw.ini".The directory separator is wrong.

speter:
Thanks very much everyone. I'll do a bit of work/thinking and post a new version in 6 hours of so. :)

cheers
S.

Navigation

[0] Message Index

[#] Next page

Go to full version