Adding Images to forms (advanced) - Mad Cow

Discussion in 'Code Snippets and Tutorials' started by Anonymous, Jan 26, 2007.

  1. Anonymous

    Anonymous Guest

    Adding colour and images (Advanced)
    By: Mad Cow

    This course will teach you about forms. The difficulty varies from beginner to intermediate to advanced.


    Requirements
    Pretty good knowlage of SCAR Forms

    Overview
    In Chapter 3, I will show you how to add images and change the background colour of your forms.

    Setting up
    First we need to open the form editor and either continue a project or start a new one



    Adding a background colour
    First of all, open the SCAR Form Editor(You should know how to by now ;))

    Now click on the blank form and in object inspector Go to "Border Icons -> Color".

    Eg.
    [​IMG]

    It's that simple!!!

    Now save the form and exit the form editor.

    Implementing the Form into the script

    Go to "Tools -> Load DFM Form"

    Declare the variables and place the code in a new procedure called "InitForm"(I know you've been through this a million times, just incase someone forgets).

    Now add your SafeCall procedures:

    Code (Text):
    1. procedure SafeInitForm;
    2. var
    3.   v: TVariantArray;
    4. begin
    5.   setarraylength(V, 0);
    6.   ThreadSafeCall('InitForm', v);
    7. end;
    8.  
    9. procedure ShowFormModal;
    10. begin
    11.   frmDesign.ShowModal;
    12. end;
    13.  
    14. procedure SafeShowFormModal;
    15. var
    16.   v: TVariantArray;
    17. begin
    18.   setarraylength(V, 0);
    19.   ThreadSafeCall('ShowFormModal', v);
    20. end;
    And also set
    Code (Text):
    1.   frmDesign.Visible := True;
    to

    Code (Text):
    1.   frmDesign.Visible := False;
    Finally add
    Code (Text):
    1.   SafeInitForm;
    2.   SafeShowFormModal;
    to your main begin

    Your script should look something like this:
    Code (Text):
    1. program FormTutorialAddingBackGroundColours;
    2. var
    3.   frmDesign : TForm;
    4.  
    5. procedure ShowFormModal;
    6. begin
    7.   frmDesign.ShowModal;
    8. end;
    9.  
    10. procedure SafeShowFormModal;
    11. var
    12.   v: TVariantArray;
    13. begin
    14.   setarraylength(V, 0);
    15.   ThreadSafeCall('ShowFormModal', v);
    16. end;
    17.  
    18. procedure SafeInitForm;
    19. var
    20.   v: TVariantArray;
    21. begin
    22.   setarraylength(V, 0);
    23.   ThreadSafeCall('InitForm', v);
    24. end;
    25.  
    26. procedure InitForm;
    27. begin
    28.   frmDesign := CreateForm;
    29.   frmDesign.Left := 256;
    30.   frmDesign.Top := 84;
    31.   frmDesign.Width := 419;
    32.   frmDesign.Height := 310;
    33.   frmDesign.Caption := 'frmDesign';
    34.   frmDesign.Color := clBlack;
    35.   frmDesign.Font.Color := clWindowText;
    36.   frmDesign.Font.Height := -11;
    37.   frmDesign.Font.Name := 'MS Sans Serif';
    38.   frmDesign.Font.Style := [];
    39.   frmDesign.Visible := False;
    40.   frmDesign.PixelsPerInch := 96;
    41. end;
    42.  
    43. begin
    44.   SafeInitForm;
    45.   SafeShowFormModal;
    46. end.

    Now your done! Moving on to the hard part - Images.

    Adding images to Forms
    So you want to add images huh? Well let me go through a few procedure's that I will be using.

    Code (Text):
    1. GetBitmapCanvas(ImageNameHere);
    This basically gets the bitmap canvas so we can use it for our next procedure

    Code (Text):
    1. procedure SafeCopyCanvas(Source, Dest: TCanvas; sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2: Integer);
    Alright.
    Source = The canvas
    Destination = frmDesign.Canvas (Copies the bitmap canvas to the form)
    sx1, sy1, sx2, sy2 = Basically the size of the Bitmap(Or change if you on;y want to use part of the bitmap)
    dx1, dy1, dx2, dy2 = Where to copy the image to(Usually the same as sx1, sy1, sx2, sy2)

    Now we got the procedures worked out, you will need to find a bitmap to use. Depending on how big the bitmap is, either use “Script -> Picture to Stringâ€
     
  2. Ryan

    Ryan Level II

    Joined:
    Jan 23, 2007
    Messages:
    251
    Likes Received:
    1
    Nice tutorial!