home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / os2apipm.zip / PMEXAM / MENU / GPI.ADB next >
Text File  |  1996-07-22  |  18KB  |  526 lines

  1. with OS2; Use OS2;
  2. with OS2.Gpi; Use OS2.Gpi;
  3. with System;
  4. package body GPI is
  5.    Background_Mix_Values : constant array (Background_Mix_Type)
  6.                                                      of Long :=
  7.       (Bm_Error            => -1,
  8.        Bm_Default          => 0,
  9.        Bm_Or               => 1,
  10.        Bm_Overpaint        => 2,
  11.        Bm_Leave_Alone      => 5,
  12.        Bm_Xor              => 4,
  13.        Bm_And              => 6,
  14.        Bm_Subtract         => 7,
  15.        Bm_Mask_Src_Not     => 8,
  16.        Bm_Zero             => 9,
  17.        Bm_Not_Merge_Src    => 10,
  18.        Bm_Not_Xor_Src      => 11,
  19.        Bm_Invert           => 12,
  20.        Bm_Merge_Src_Not    => 13,
  21.        Bm_Not_Copy_Src     => 14,
  22.        Bm_Merge_Not_Src    => 15,
  23.        Bm_Not_Mask_Src     => 16,
  24.        Bm_One              => 17,
  25.        Bm_Src_Transparent  => 18,
  26.        Bm_Dest_Transparent => 19);
  27.   ---------------------------------------------------------
  28.     Outline_Values : constant array (Outline_Style_Type)
  29.                                                of Long :=
  30.         (Dro_Fill         => 1,
  31.          Dro_Outline      => 2,
  32.          Dro_Outline_Fill => 3);
  33.   ---------------------------------------------------------
  34.     function Failed_To (Value : Boolean) return Boolean is
  35.       begin
  36.         return not Value;
  37.       end Failed_To;
  38.   ---------------------------------------------------------
  39.    function Set_Background_Mix (
  40.               Ps  : Hps;
  41.               Mix : Background_Mix_Type) return Boolean is
  42.      begin
  43.        return GPISetBackMix (Ps, Background_Mix_Values (Mix)) = 1;
  44.      end Set_Background_Mix;
  45.   ---------------------------------------------------------
  46.    procedure Set_Background_Mix (
  47.               Ps  : Hps;
  48.               Mix : Background_Mix_Type) is
  49.     begin
  50.      if not Set_Background_Mix (Ps, Mix) then
  51.        raise GPI_Error;
  52.      end if;
  53.     end Set_Background_Mix;
  54.   ---------------------------------------------------------
  55.    function Set_Background_Color (
  56.                   Ps    : Hps;
  57.                   Color : Color_Type) return Boolean is
  58.    begin
  59.      return GpiSetBackColor (Ps, Long(Color)) = 1;
  60.    end Set_Background_Color;
  61.   ---------------------------------------------------------
  62.    procedure Set_Background_Color (
  63.                   Ps    : Hps;
  64.                   Color : Color_Type) is
  65.      begin
  66.        if not Set_Background_Color (Ps, Color) then
  67.          raise GPI_Error;
  68.        end if;
  69.      end Set_Background_Color;
  70.   ---------------------------------------------------------
  71.    function Set_Color (
  72.                   Ps    : Hps;
  73.                   Color : Color_Type) return Boolean is
  74.    begin
  75.      return GpiSetColor (Ps, Long(Color)) = 1;
  76.    end Set_Color;
  77.   ---------------------------------------------------------
  78.    procedure Set_Color (
  79.                   Ps    : Hps;
  80.                   Color : Color_Type) is
  81.      begin
  82.        if not Set_Color (Ps, Color) then
  83.          raise GPI_Error;
  84.        end if;
  85.      end Set_Color;
  86.   ---------------------------------------------------------
  87.   function Status_Is (Value : Long) return Status_Type is
  88.     begin
  89.       case Value is
  90.         when 0      => return Error;
  91.         when 1      => return Okay;
  92.         when 2      => return Hits;
  93.         when others => null;
  94.       end case;
  95.       return Error;
  96.     end Status_Is;
  97.   ---------------------------------------------------------
  98.    function Char_String_At (
  99.                   Ps    : Hps;
  100.                   Point : Pointl;
  101.                   Text  : String) return Status_Type is
  102.  
  103.      pointa : aliased pointl ; for pointa'address use point'address;
  104.      Result : Long;
  105.    begin
  106.      Result := GPICharStringAt (
  107.                  Ps         => Ps,
  108.                  pptlPoint  => Pointa'unchecked_access,
  109.                  lCount     => Long (Text'Length),
  110.                  pchString  => Text (Text'first)'address);
  111.  
  112.      return Status_Is (Result);
  113.   end Char_String_At;
  114.   ---------------------------------------------------------
  115.    procedure Char_String_At (
  116.                   Ps    : in Hps;
  117.                   Point : in Pointl;
  118.                   Text  : in String) is
  119.     begin
  120.       if Error = Char_String_At (Ps, Point, Text) then
  121.          raise GPI_Error;
  122.       end if;
  123.     end Char_String_At;
  124.   ---------------------------------------------
  125.    function Char_String (
  126.                   Ps    : Hps;
  127.                   Text  : String) return Status_Type is
  128.  
  129.    Result : Long;
  130.    begin
  131.      Result := GPICharString (
  132.                  Ps           => Ps,
  133.                  lCount       => Long (Text'Length),
  134.                  pchString    => Text (Text'first)'address);
  135.      return Status_Is (Result);
  136.   end Char_String;
  137.   ---------------------------------------------------------
  138.    procedure Char_String (
  139.                   Ps    : in Hps;
  140.                   Text  : in String) is
  141.     begin
  142.  
  143.       if Error = Char_String (Ps, Text) then
  144.          raise GPI_Error;
  145.       end if;
  146.     end Char_String;
  147.   ---------------------------------------------
  148.    function Set_Current_Position (
  149.               Ps    : Hps;
  150.               Point : Pointl) return Boolean is
  151.  
  152.    Pointa : aliased pointl ; for pointa'address use point'address;
  153.    Result : Bool;
  154.    begin
  155.      Result := GpiSetCurrentPosition (
  156.                  Ps        => Ps,
  157.                  pptlPoint => Pointa'unchecked_access);
  158.  
  159.      return Result = 1;
  160.    end Set_Current_Position;
  161.  
  162.   ---------------------------------------------
  163.    procedure Set_Current_Position (
  164.               Ps    : Hps;
  165.               Point : Pointl) is
  166.     begin
  167.       if not Set_Current_Position (Ps, Point) then
  168.         raise Gpi_Error;
  169.       end if;
  170.     end Set_Current_Position;
  171.   ---------------------------------------------
  172.    function Query_Current_Position (
  173.               Ps    : Hps;
  174.               Point : PPointL) return Boolean is
  175.  
  176.    Result : Bool;
  177.    begin
  178.      Result := GpiQueryCurrentPosition (
  179.                  Ps        => Ps,
  180.                  pptlPoint => Point);
  181.  
  182.      return Result = 1;
  183.    end Query_Current_Position;
  184.   ---------------------------------------------
  185.    procedure Query_Current_Position (
  186.               Ps    : in     Hps;
  187.               Point :    out Pointl) is
  188.  
  189.    Pointa : aliased pointl ; for pointa'address use point'address;
  190.      Result : Bool;
  191.    begin
  192.      Result := GpiQueryCurrentPosition (
  193.                  Ps        => Ps,
  194.                  pptlPoint => Pointa'unchecked_access);
  195.  
  196.      if Result /= 1 then
  197.        raise GPI_Error;
  198.      end if;
  199.    end Query_Current_Position;
  200.   ---------------------------------------------
  201.    function Erase (Ps : Hps) return Boolean is
  202.  
  203.      Result : Bool;
  204.    begin
  205.      Result := GpiErase (Ps);
  206.      return Result = 1;
  207.    end Erase;
  208.   ---------------------------------------------
  209.    procedure Erase (Ps : Hps) is
  210.      begin
  211.       if Failed_To (Erase (Ps)) then
  212.         raise GPI_Error;
  213.       end if;
  214.      end Erase;
  215.   ---------------------------------------------
  216.    function Destroy_Ps (Ps : Hps) return Boolean is
  217.  
  218.    Result : ulong;
  219.    begin
  220.    Result := GpiDestroyPS (Ps);
  221.    return Result = 1;
  222.    end Destroy_Ps;
  223.   ---------------------------------------------
  224.    procedure Destroy_Ps (Ps : in Hps) is
  225.      begin
  226.       if Failed_To (Destroy_Ps (Ps)) then
  227.         raise Gpi_Error;
  228.       end if;
  229.      end Destroy_Ps;
  230.   ---------------------------------------------
  231.    function Move (
  232.               Ps    : Hps;
  233.               Point : Pointl) return Boolean is
  234.  
  235.    Pointa : aliased pointl ; for pointa'address use point'address;
  236.      Result : Bool;
  237.    begin
  238.      Result := GpiMove (
  239.                  Ps        => Ps,
  240.                  pptlPoint => Pointa'unchecked_access);
  241.  
  242.      return Result = 1;
  243.    end Move;
  244.   ---------------------------------------------
  245.    procedure Move (
  246.               Ps    : Hps;
  247.               Point : Pointl) is
  248.     begin
  249.       if not Move (Ps, Point) then
  250.         raise Gpi_Error;
  251.       end if;
  252.     end Move;
  253.   ---------------------------------------------
  254.    function Set_Line_End (
  255.               Ps        : Hps;
  256.               Style     : Line_End_Style_Type) return Boolean is
  257.      begin
  258.        return False;
  259.      end Set_Line_End;
  260.   ---------------------------------------------
  261.    procedure Set_Line_End (
  262.               Ps        : in Hps;
  263.               Style     : in Line_End_Style_Type) is
  264.     begin
  265.       null;
  266.     end Set_Line_End;
  267.   ---------------------------------------------
  268.    function Query_Line_End (Ps : Hps)
  269.                                    return Line_End_Style_Type is
  270.      begin
  271.       return Line_End_Style_Type'first;
  272.      end Query_Line_End;
  273.   ---------------------------------------------
  274.    function Set_Line_Join (
  275.               Ps        : Hps;
  276.               Style     : Line_Join_Style_Type) return Boolean is
  277.      begin
  278.        return False;
  279.      end Set_Line_Join;
  280.   ---------------------------------------------
  281.    procedure Set_Line_Join (
  282.               Ps        : in Hps;
  283.               Style     : in Line_Join_Style_Type) is
  284.     begin
  285.       null;
  286.     end Set_Line_Join;
  287.   ---------------------------------------------
  288.    function Query_Line_Join (Ps : Hps)
  289.                                      return Line_Join_Style_Type is
  290.      begin
  291.        return Line_Join_Style_Type'first;
  292.      end Query_Line_Join;
  293.   ---------------------------------------------
  294.    function Line (
  295.               Ps        : Hps;
  296.               End_Point : Pointl) return Status_Type is
  297.  
  298.    Pointa : aliased pointl ; for pointa'address use End_point'address;
  299.      Result : Long;
  300.    begin
  301.  
  302.      Result := GpiLine (Ps           => Ps,
  303.                         pptlEndPoint => Pointa'unchecked_access);
  304.  
  305.      return Status_Is (Result);
  306.    end Line;
  307.   ---------------------------------------------
  308.    procedure Line (
  309.               Ps        : Hps;
  310.               End_Point : Pointl) is
  311.     begin
  312.       if Error = Line (Ps, End_Point) then
  313.         raise Gpi_Error;
  314.       end if;
  315.     end Line;
  316.   ---------------------------------------------
  317.    procedure Line (
  318.               Ps          : Hps;
  319.               Start_Point : Pointl;
  320.               End_Point   : Pointl) is
  321.     begin
  322.       if Failed_To (Set_Current_Position (Ps, Start_Point)) or else
  323.              Error = Line (Ps, End_Point) then
  324.            raise Gpi_Error;
  325.       end if;
  326.     end Line;
  327.   ---------------------------------------------
  328.    function Box (
  329.               Ps            : Hps;
  330.               Corner_Point  : Pointl;
  331.               Outline_Style : Outline_Style_Type;
  332.               Horz_Rounding : Long;
  333.               Vert_Rounding : Long) return Status_Type is
  334.      Corner_P : aliased Pointl ;  for Corner_P'address use Corner_Point'address;
  335.      Result : Long;
  336.    begin
  337.      Result := GpiBox (
  338.                     Ps         => Ps,
  339.                     lControl   => Outline_Values (Outline_Style),
  340.                     pptlPoint  => Corner_P'unchecked_access,
  341.                     lHRound    => Horz_Rounding,
  342.                     lVRound    => Vert_Rounding);
  343.  
  344.      return Status_Is (long(Result));
  345.    end Box;
  346.   ---------------------------------------------
  347.    procedure Box (
  348.               Ps            : in Hps;
  349.               Corner_Point  : in Pointl;
  350.               Outline_Style : in Outline_Style_Type;
  351.               Horz_Rounding : in Long;
  352.               Vert_Rounding : in Long) is
  353.     begin
  354.      if Error = Box (Ps,
  355.                      Corner_Point,
  356.                      Outline_Style,
  357.                      Horz_Rounding,
  358.                      Vert_Rounding) then
  359.        raise Gpi_Error;
  360.      end if;
  361.     end Box;
  362.   ---------------------------------------------
  363.    procedure Box (
  364.               Ps            : in Hps;
  365.               Start_Corner  : in Pointl;
  366.               End_Corner    : in Pointl;
  367.               Outline_Style : in Outline_Style_Type;
  368.               Horz_Rounding : in Long;
  369.               Vert_Rounding : in Long) is
  370.     begin
  371.  
  372.       if Failed_To (Set_Current_Position (Ps, Start_Corner)) or else
  373.          Error = Box (Ps,
  374.                       End_Corner,
  375.                       Outline_Style,
  376.                       Horz_Rounding,
  377.                       Vert_Rounding) then
  378.          raise Gpi_Error;
  379.       end if;
  380.     end Box;
  381.  ---------------------------------------------
  382.    function Set_Arc_Parameters (
  383.               Ps         : Hps;
  384.               Parameters : ArcParams) return Boolean is
  385.  
  386.  parm:aliased ArcParams; for parm'address use Parameters'address;
  387.  Result : Bool;
  388.  
  389.      begin
  390.        Result := GpiSetArcParams (Ps             => Ps,
  391.                                   parcpArcParams => Parm'unchecked_access);
  392.        return Result = 1;
  393.  
  394.      end Set_Arc_Parameters;
  395.  ---------------------------------------------
  396.    procedure Set_Arc_Parameters (
  397.               Ps         : in Hps;
  398.               Parameters : in ArcParams) is
  399.      begin
  400.        if not Set_Arc_Parameters (Ps, Parameters) then
  401.           raise Gpi_Error;
  402.        end if;
  403.      end Set_Arc_Parameters;
  404.  ---------------------------------------------
  405.    function Query_Arc_Parameters (
  406.               Ps         : Hps;
  407.               Parameters : PArcParams)
  408.                                           return Boolean is
  409.  
  410.      Result : Bool;
  411.      begin
  412.        Result := GpiQueryArcParams (Ps             => Ps,
  413.                                     parcpArcParams => Parameters);
  414.        return Result = 1;
  415.      end Query_Arc_Parameters;
  416.  ---------------------------------------------
  417.    procedure Query_Arc_Parameters (
  418.               Ps         : in     Hps;
  419.               Parameters :    out ArcParams) is
  420.  
  421. parm: aliased ArcParams; for parm'address use Parameters'address;
  422. Result : Bool;
  423.      begin
  424.        Result := GpiQueryArcParams (Ps             => Ps,
  425.                                     parcpArcParams => Parm'unchecked_access);
  426.        if Result /= 1 then
  427.          raise GPI_Error;
  428.        end if;
  429.      end Query_Arc_Parameters;
  430.  ---------------------------------------------
  431.    function Set_Default_Arc_Parameters (
  432.               Ps         : Hps;
  433.               Parameters : ArcParams) return Boolean is
  434.  
  435.  parm:aliased ArcParams; for parm'address use Parameters'address;
  436.      Result : Bool;
  437.      begin
  438.  
  439.        Result := GpiSetDefArcParams (Ps            => Ps,
  440.                                      parcpArcParams => Parm'unchecked_access);
  441.        return Result = 1;
  442.      end Set_Default_Arc_Parameters;
  443.  ---------------------------------------------
  444.    procedure Set_Default_Arc_Parameters (
  445.               Ps         : in Hps;
  446.               Parameters : in ArcParams) is
  447.      begin
  448.        if not Set_Default_Arc_Parameters (Ps, Parameters) then
  449.           raise Gpi_Error;
  450.        end if;
  451.      end Set_Default_Arc_Parameters;
  452.  ---------------------------------------------
  453.    function Query_Default_Arc_Parameters (
  454.               Ps         : Hps;
  455.               Parameters : PArcParams)
  456.                                              return Boolean is
  457.  
  458.      Result : Bool;
  459.      begin
  460.  
  461.        Result := GpiQueryDefArcParams (Ps             => Ps,
  462.                                        parcpArcParams => Parameters);
  463.        return Result = 1;
  464.      end Query_Default_Arc_Parameters;
  465.  ---------------------------------------------
  466.    procedure Query_Default_Arc_Parameters (
  467.               Ps         : in     Hps;
  468.               Parameters :    out ArcParams) is
  469.  
  470. parm: aliased ArcParams; for parm'address use Parameters'address;
  471.      Result : Bool;
  472.  
  473.      begin
  474.        Result := GpiQueryDefArcParams (Ps             => Ps,
  475.                                        parcpArcParams => Parm'unchecked_access);
  476.        if Result /= 1 then
  477.          raise GPI_Error;
  478.        end if;
  479.      end Query_Default_Arc_Parameters;
  480.  ---------------------------------------------
  481.   --GNAT BUG
  482.  
  483.    function Full_Arc (
  484.               Ps            : Hps;
  485.               Outline_Style : Outline_Style_Type;
  486.               Multiplier    : Multipler_Type) return Status_Type is
  487.  
  488.       Result : Long;
  489.       Mult   : Long;
  490.  
  491.      begin
  492.       Mult := 65_536 * Long (Multiplier);
  493.       Result := GpiFullArc (Ps            => Ps,
  494.                             LControl      => Outline_Values (Outline_Style),
  495.                             fxMultiplier  => Mult);
  496.       return Status_Is (Long(Result));
  497.  
  498.      end Full_Arc;
  499.  ---------------------------------------------
  500.    procedure Full_Arc (
  501.               Ps            : in Hps;
  502.               Outline_Style : in Outline_Style_Type;
  503.               Multiplier    : in Multipler_Type) is
  504.      begin
  505.        if Error = Full_Arc (Ps, Outline_Style, Multiplier) then
  506.          raise Gpi_Error;
  507.        end if;
  508.      end Full_Arc;
  509.  ---------------------------------------------
  510.    procedure Full_Arc (
  511.               Ps            : in Hps;
  512.               Center        : in Pointl;
  513.               Arc_Params    : in ArcParams;
  514.               Outline_Style : in Outline_Style_Type;
  515.               Multiplier    : in Multipler_Type) is
  516.     begin
  517.  
  518.       if Failed_To (Set_Current_Position (Ps, Center)) or else
  519.          Failed_To (Set_Arc_Parameters (Ps, Arc_Params)) or else
  520.          Error = Full_Arc (Ps, Outline_Style, Multiplier) then
  521.           raise Gpi_Error;
  522.       end if;
  523. end Full_Arc;
  524.  
  525. end GPI;
  526.