hikari
hikari

Reputation: 3503

Graphics32: conversion from GR32_PolygonsOld

I have been using the GR32 library for a few years, holding onto an old compatibility unit GR32_PolygonsOld that's no longer maintained. At some point they heavily modified the Polygons unit and some things no longer exist like TAntialiasMode and TPolygon32, but there was never any documentation on how to migrate old code to the new procedures and classes.

How can I convert my old code to work with the new methods with the 2.0.0 Alpha onwards versions?

Old code: (new code should not use the unit GR32_PolygonsOld which is no longer part of their repository, but instead GR32_Polygons)

GR32 official library: https://github.com/graphics32/graphics32
Old unit: https://github.com/graphicsmagicteam/graphicsmagic/blob/master/externals/Graphics32_3rd_Party/GR32_PolygonsOld.pas

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls,

  GR32, GR32_PolygonsOld;

type
  TForm1 = class(TForm)
    Image1: TImage;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure b32DoRectangle(bitmap: TBitmap32; Coords: TRect; Color: TColor32; AA: Boolean; AAMode: TAntiAliasMode);
begin
  With TPolygon32.Create do begin
    Antialiased := AA;
    if AA then AntialiasMode := AAMode;
    Add(GR32.FixedPoint(Coords.Left,Coords.Top));
    Add(GR32.FixedPoint(Coords.Right,Coords.Top));
    Add(GR32.FixedPoint(Coords.Right,Coords.Bottom));
    Add(GR32.FixedPoint(Coords.Left,Coords.Bottom));
    DrawFill(bitmap,Color);
    Free;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
Var b32: TBitmap32;
begin
  b32 := TBitmap32.Create;
  b32.Width  := 200;
  b32.Height := 200;
  b32.Clear(clWhite32);

  b32DoRectangle(b32, Rect(20,20,70,70), SetAlpha(clRed32, 20), True, am8times);

  b32.DrawTo(Image1.Canvas.Handle, 0,0);
  b32.Free;
end;

end.

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 397
  ClientWidth = 838
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Image1: TImage
    Left = 32
    Top = 32
    Width = 305
    Height = 209
  end
end

enter image description here

Upvotes: 1

Views: 280

Answers (0)

Related Questions