Project Perfect Mod Forums
:: Home :: Get Hosted :: PPM FAQ :: Forum FAQ :: Privacy Policy :: Search :: Memberlist :: Usergroups :: Register :: Profile :: Log in to check your private messages :: Log in ::


The time now is Thu Mar 28, 2024 1:22 pm
All times are UTC + 0
My contribution to the OS SHP Builder
Moderators: stucuk
Post new topic   Reply to topic Page 1 of 1 [15 Posts] Mark the topic unread ::  View previous topic :: View next topic
Author Message
pd
Laser Commando


Joined: 19 Jun 2005
Location: Gone

PostPosted: Wed Jul 06, 2005 11:00 am    Post subject:  My contribution to the OS SHP Builder Reply with quote  Mark this post and the followings unread

Hail Open Source! Very Happy

I just needed a new option in the SHP Builder so I coded it.
I think it's pretty useful and it should be included in the official version.

My question to the makers:
How can I give you the code so you can update it?

It might need some optimizations, I dunno.
Anyway it works, in all the zoom stages.
Check the screenies Smile



os_shp_grid2.PNG
 Description:
Is the grid too much on the right?
 Filesize:  38.22 KB
 Viewed:  12554 Time(s)

os_shp_grid2.PNG



os_shp.png
 Description:
The toggle button needs a new icon.
 Filesize:  46.71 KB
 Viewed:  12555 Time(s)

os_shp.png



Back to top
View user's profile Send private message
Havoc
Commander


Joined: 04 Jan 2005
Location: Toronto, Canada

PostPosted: Wed Jul 06, 2005 12:50 pm    Post subject: Reply with quote  Mark this post and the followings unread

So you meen this tool makes a grid on which you can "build" the structures.

Back to top
View user's profile Send private message
pd
Laser Commando


Joined: 19 Jun 2005
Location: Gone

PostPosted: Wed Jul 06, 2005 1:14 pm    Post subject: Reply with quote  Mark this post and the followings unread

Yes.
I needed to edit the gems, so I needed the grid.
And I didn't want to always copy-n-paste those help grids.
This grids function makes life much more easier when you need grids.

Back to top
View user's profile Send private message
Havoc
Commander


Joined: 04 Jan 2005
Location: Toronto, Canada

PostPosted: Wed Jul 06, 2005 1:15 pm    Post subject: Reply with quote  Mark this post and the followings unread

It's really useful. It eases your work. This is a good idea. Let's wait and see what Banshee says.

Back to top
View user's profile Send private message
Banshee
Supreme Banshee


Also Known As: banshee_revora (Steam)
Joined: 15 Aug 2002
Location: Brazil

PostPosted: Wed Jul 06, 2005 1:19 pm    Post subject: Reply with quote  Mark this post and the followings unread

You rock, PaD!

Attach the changed files (and if you could post which part of the files where these changes are, I'd be happy #Tongue).

_________________


Mods, Mods Support, Public Researchs, Map Archives, Tutorials, A Friendly Community and much more. Check it out now!

Back to top
View user's profile Send private message Visit poster's website Skype Account
pd
Laser Commando


Joined: 19 Jun 2005
Location: Gone

PostPosted: Wed Jul 06, 2005 3:35 pm    Post subject: Reply with quote  Mark this post and the followings unread

K.
First thing I did is adding a new Button to ToolBar1. It should be ToolButton15 then.

The OnClick-Event:
Code:
procedure TSHPBuilderFrmMain.ToolButton15Click(Sender: TObject);
begin
ActiveForm^.show_grid := not ActiveForm^.show_grid;
ToolButton15.Down := ActiveForm^.show_grid;


In TSHPBuilderFrmMain.SetIsEditable (in FormMain), add this:
Code:
ToolButton15.enabled := isEditable;


ActiveForm^.RefreshImage1;
end;[/code]

In FormSHPImage, below the declaration of show_center, declare show_grid:
Code:
show_grid : boolean;


In the proc LoadNewSHPImageSettings in SHP_DataMatrix, I added these lines:
Code:
Form.show_grid := false;
FrmMain.ToolButton15.Down := false;


The main code, in TFrmSHPImage.RefreshImage1 in FormSHPImage, add this after or before the show_center stuff:

Code:
   if show_grid then // Create Grid -pd
      begin
         r:=-1;
         for x:=SHPData^.SHP.Header.Width div 2 downto -30 do
            begin
               y:=abs((x div 2)-(SHPData^.SHP.Header.Width div 4))+((SHPData^.SHP.Header.Height) div 2)-1;
               image1.Picture.Bitmap.Canvas.Brush.Color := OpositeColour(image1.Picture.Bitmap.Canvas.Pixels[x*Zoom,y*Zoom]);
               image1.Picture.Bitmap.Canvas.FillRect(Rect((x*Zoom),(y*Zoom),(x*Zoom)+Zoom,(y*Zoom)+Zoom));
               r:=r+1;
               if (r mod 30=0) and (r>0) then
                  begin
                     r:=0;
                     x2:=x;
                     y2:=y;
                     c:=y-(x div 2);
                     while y2<SHPData^.SHP.Header.Height do
                        begin
                           y2:=(x2 div 2)+c;
                           image1.Picture.Bitmap.Canvas.Brush.Color := OpositeColour(image1.Picture.Bitmap.Canvas.Pixels[x2*Zoom,y2*Zoom]);
                           image1.Picture.Bitmap.Canvas.FillRect(Rect((x2*Zoom),(y2*Zoom),(x2*Zoom)+Zoom,(y2*Zoom)+Zoom));
                           x2:=x2+1;
                        end;
                  end;
            end;

         r:=-1;
         for x:=SHPData^.SHP.Header.Width div 2 to SHPData^.SHP.Header.Width+30 do
            begin
               y:=abs((x div 2)-(SHPData^.SHP.Header.Width div 4))+((SHPData^.SHP.Header.Height) div 2)-1;
               image1.Picture.Bitmap.Canvas.Brush.Color := OpositeColour(image1.Picture.Bitmap.Canvas.Pixels[x*Zoom,y*Zoom]);
               image1.Picture.Bitmap.Canvas.FillRect(Rect((x*Zoom),(y*Zoom),(x*Zoom)+Zoom,(y*Zoom)+Zoom));
               r:=r+1;
               if (r mod 30=0) and (r>0) then
                  begin
                     r:=0;
                     x2:=x;
                     y2:=y;
                     c:=y+(x div 2);
                     while y2<SHPData^.SHP.Header.Height do
                        begin
                           y2:=-(x2 div 2)+c;
                           image1.Picture.Bitmap.Canvas.Brush.Color := OpositeColour(image1.Picture.Bitmap.Canvas.Pixels[x2*Zoom,y2*Zoom]);
                           image1.Picture.Bitmap.Canvas.FillRect(Rect((x2*Zoom),(y2*Zoom),(x2*Zoom)+Zoom,(y2*Zoom)+Zoom));
                           x2:=x2-1;
                        end;
                  end;
            end;

      end;


Don't forget to declare variables in that proc:
Code:
x,y,r,x2,y2,c:integer;


I think that's all.

As said, possibly, the main algorithm could be a slightly optimized.
The main idea turned out to be the fastest.

Back to top
View user's profile Send private message
pd
Laser Commando


Joined: 19 Jun 2005
Location: Gone

PostPosted: Wed Jul 06, 2005 3:49 pm    Post subject: Reply with quote  Mark this post and the followings unread

Sorry for double-posting, but this is important.

I just optimized the algorithms for show_center and show_grid.
There are more variables now...

Code:
x,y,r,x2,y2,c,xZ,yZ,xdiv2:integer;


...but only half as many calculation (speeds the whole thing up, result is noticeable):

Code:
   if show_center then // Create Cross
      for x := 0 to SHPData^.SHP.Header.Width -1 do
         for y := 0 to SHPData^.SHP.Header.Height-1 do
            if (x = (SHPData^.SHP.Header.Width-1) div 2) or (y = (SHPData^.SHP.Header.Height-1) div 2) then
            begin
               xZ:=x*Zoom;
               yZ:=y*Zoom;
               image1.Picture.Bitmap.Canvas.Brush.Color := OpositeColour(image1.Picture.Bitmap.Canvas.Pixels[xZ,yZ]);
               image1.Picture.Bitmap.Canvas.FillRect(Rect(xZ,yZ,xZ+Zoom,yZ+Zoom));
            end;


   if show_grid then // Create Grid -pd
      begin
         r:=-1;
         for x:=SHPData^.SHP.Header.Width div 2 downto -30 do
            begin
               xdiv2:=x div 2;
               y:=abs(xdiv2-(SHPData^.SHP.Header.Width div 4))+((SHPData^.SHP.Header.Height) div 2)-1;
               xZ:=x*Zoom;
               yZ:=y*Zoom;
               image1.Picture.Bitmap.Canvas.Brush.Color := OpositeColour(image1.Picture.Bitmap.Canvas.Pixels[xZ,yZ]);
               image1.Picture.Bitmap.Canvas.FillRect(Rect(xZ,yZ,xZ+Zoom,yZ+Zoom));
               r:=r+1;
               if (r mod 30=0) and (r>0) then
                  begin
                     r:=0;
                     x2:=x;
                     y2:=y;
                     c:=y-xdiv2;
                     while y2<SHPData^.SHP.Header.Height do
                        begin
                           y2:=(x2 div 2)+c;
                           xZ:=x2*Zoom;
                           yZ:=y2*Zoom;
                           image1.Picture.Bitmap.Canvas.Brush.Color := OpositeColour(image1.Picture.Bitmap.Canvas.Pixels[xZ,yZ]);
                           image1.Picture.Bitmap.Canvas.FillRect(Rect(xZ,yZ,xZ+Zoom,yZ+Zoom));
                           x2:=x2+1;
                        end;
                  end;
            end;

         r:=-1;
         for x:=SHPData^.SHP.Header.Width div 2 to SHPData^.SHP.Header.Width+30 do
            begin
               y:=abs((x div 2)-(SHPData^.SHP.Header.Width div 4))+((SHPData^.SHP.Header.Height) div 2)-1;
               image1.Picture.Bitmap.Canvas.Brush.Color := OpositeColour(image1.Picture.Bitmap.Canvas.Pixels[x*Zoom,y*Zoom]);
               image1.Picture.Bitmap.Canvas.FillRect(Rect((x*Zoom),(y*Zoom),(x*Zoom)+Zoom,(y*Zoom)+Zoom));
               r:=r+1;
               if (r mod 30=0) and (r>0) then
                  begin
                     r:=0;
                     x2:=x;
                     y2:=y;
                     c:=y+(x div 2);
                     while y2<SHPData^.SHP.Header.Height do
                        begin
                           y2:=-(x2 div 2)+c;
                           image1.Picture.Bitmap.Canvas.Brush.Color := OpositeColour(image1.Picture.Bitmap.Canvas.Pixels[x2*Zoom,y2*Zoom]);
                           image1.Picture.Bitmap.Canvas.FillRect(Rect((x2*Zoom),(y2*Zoom),(x2*Zoom)+Zoom,(y2*Zoom)+Zoom));
                           x2:=x2-1;
                        end;
                  end;
            end;

      end;


Again, sorry for double-posting.

Back to top
View user's profile Send private message
GeckoYamori
Cyborg Artillery


Joined: 06 Jun 2004
Location: Sweden

PostPosted: Wed Jul 06, 2005 3:53 pm    Post subject: Reply with quote  Mark this post and the followings unread

Excellent, this will be mighty useful for me. Now I won't have to rely on others to align structures correctly for me Very Happy

_________________

Back to top
View user's profile Send private message
Banshee
Supreme Banshee


Also Known As: banshee_revora (Steam)
Joined: 15 Aug 2002
Location: Brazil

PostPosted: Wed Jul 06, 2005 4:41 pm    Post subject: Reply with quote  Mark this post and the followings unread

Thanks a lot, PaD Smile. A new version will be online soon... (as soon as I get rid of some homework first #Tongue).

_________________


Mods, Mods Support, Public Researchs, Map Archives, Tutorials, A Friendly Community and much more. Check it out now!

Back to top
View user's profile Send private message Visit poster's website Skype Account
Havoc
Commander


Joined: 04 Jan 2005
Location: Toronto, Canada

PostPosted: Wed Jul 06, 2005 4:46 pm    Post subject: Reply with quote  Mark this post and the followings unread

pd, good job. Now I'll finally be able to make structures.
@Banshee: Screw the homework. It's a waste of time! #Tongue (<-just ignore it!).

Back to top
View user's profile Send private message
pd
Laser Commando


Joined: 19 Jun 2005
Location: Gone

PostPosted: Wed Jul 06, 2005 4:50 pm    Post subject: Reply with quote  Mark this post and the followings unread

OK, before, I still got an improvement  Razz
*me = perfectionist*

Change the
xZ:=x*Zoom;
yZ:=y*Zoom;

to

xZ:=(x-1)*Zoom;
yZ:=(y-1)*Zoom;

(remember to do this for both!)
It will make the grid being aligned better.

And I just forgot that there's a menu entry for "Show Center", so there should also be one for "Show Grid".
I've also been reminded that this is only the RA2 cell size, maybe a TS one would be useful as well.

Back to top
View user's profile Send private message
The DvD
TiberiumWeb.com Webmaster


Joined: 30 Dec 2002
Location: Netherlands

PostPosted: Wed Jul 06, 2005 4:51 pm    Post subject: Reply with quote  Mark this post and the followings unread

This is exactly what many people needed. Too bad it came to late for Gecko and I had to do it for him #Tongue

Back to top
View user's profile Send private message Visit poster's website Skype Account
Banshee
Supreme Banshee


Also Known As: banshee_revora (Steam)
Joined: 15 Aug 2002
Location: Brazil

PostPosted: Wed Jul 06, 2005 4:55 pm    Post subject: Reply with quote  Mark this post and the followings unread

to make it compatible with TS, just change the 30 below into a variable and I'll make the user set the variable somewhere (30 for RA2, 24 for TS)

Code:
if (r mod 30=0) and (r>0) then

_________________


Mods, Mods Support, Public Researchs, Map Archives, Tutorials, A Friendly Community and much more. Check it out now!

Back to top
View user's profile Send private message Visit poster's website Skype Account
Banshee
Supreme Banshee


Also Known As: banshee_revora (Steam)
Joined: 15 Aug 2002
Location: Brazil

PostPosted: Sun Jul 24, 2005 6:19 am    Post subject: Reply with quote  Mark this post and the followings unread

I've implemented your stuff here and tested it, PaD.

I made few changes in order to make it support RA2 and TS Grids.

It worked on some SHPs (specially small ones), and caused infinite loops on other bigger ones. This part, I've fixed, so I'm ready to release a new version with it.

Code:
                     while y2<SHPData^.SHP.Header.Height do
                        begin
                           y2:=-(x2 div 2)+c;


(The y2 above could receive some negative values and this would cause an infinite loop, since the condition in the while would never be reached)



However, the grids are not looking fully cool on these big images. I'm gonna be releasing the OS SHP Builder 3.33 soon, so we can get fixing it with the community feedback.

_________________


Mods, Mods Support, Public Researchs, Map Archives, Tutorials, A Friendly Community and much more. Check it out now!

Back to top
View user's profile Send private message Visit poster's website Skype Account
christophski the great
Energy Commando


Joined: 21 May 2004
Location: England

PostPosted: Sun Jul 24, 2005 8:16 am    Post subject: Reply with quote  Mark this post and the followings unread

oh my god, finally what i've been waiting for!
thankyou so much pd!

_________________
Singer-Songwriter Christie Isaac

Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [15 Posts] Mark the topic unread ::  View previous topic :: View next topic
 
Share on TwitterShare on FacebookShare on Google+Share on DiggShare on RedditShare on PInterestShare on Del.icio.usShare on Stumble Upon
Quick Reply
Username:


If you are visually impaired or cannot otherwise answer the challenges below please contact the Administrator for help.


Write only two of the following words separated by a sharp: Brotherhood, unity, peace! 

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © phpBB Group

[ Time: 0.1772s ][ Queries: 15 (0.0132s) ][ Debug on ]