Browse Source

Added Shadow test project.

lainz 11 years ago
parent
commit
5a71e09260

BIN
test/test_extra/shadow/logo.png


+ 91 - 0
test/test_extra/shadow/shadow.lpi

@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CONFIG>
+  <ProjectOptions>
+    <Version Value="9"/>
+    <PathDelim Value="\"/>
+    <General>
+      <SessionStorage Value="InProjectDir"/>
+      <MainUnit Value="0"/>
+      <Title Value="shadow"/>
+      <ResourceType Value="res"/>
+      <UseXPManifest Value="True"/>
+      <Icon Value="0"/>
+    </General>
+    <i18n>
+      <EnableI18N LFM="False"/>
+    </i18n>
+    <VersionInfo>
+      <StringTable ProductVersion=""/>
+    </VersionInfo>
+    <BuildModes Count="1">
+      <Item1 Name="Default" Default="True"/>
+    </BuildModes>
+    <PublishOptions>
+      <Version Value="2"/>
+    </PublishOptions>
+    <RunParams>
+      <local>
+        <FormatVersion Value="1"/>
+      </local>
+    </RunParams>
+    <RequiredPackages Count="2">
+      <Item1>
+        <PackageName Value="bgracontrols"/>
+      </Item1>
+      <Item2>
+        <PackageName Value="LCL"/>
+      </Item2>
+    </RequiredPackages>
+    <Units Count="2">
+      <Unit0>
+        <Filename Value="shadow.lpr"/>
+        <IsPartOfProject Value="True"/>
+        <UnitName Value="shadow"/>
+      </Unit0>
+      <Unit1>
+        <Filename Value="umain.pas"/>
+        <IsPartOfProject Value="True"/>
+        <ComponentName Value="Form1"/>
+        <ResourceBaseClass Value="Form"/>
+        <UnitName Value="umain"/>
+      </Unit1>
+    </Units>
+  </ProjectOptions>
+  <CompilerOptions>
+    <Version Value="11"/>
+    <PathDelim Value="\"/>
+    <Target>
+      <Filename Value="shadow"/>
+    </Target>
+    <SearchPaths>
+      <IncludeFiles Value="$(ProjOutDir)"/>
+      <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
+    </SearchPaths>
+    <Linking>
+      <Options>
+        <Win32>
+          <GraphicApplication Value="True"/>
+        </Win32>
+      </Options>
+    </Linking>
+    <Other>
+      <CompilerMessages>
+        <MsgFileName Value=""/>
+      </CompilerMessages>
+      <CompilerPath Value="$(CompPath)"/>
+    </Other>
+  </CompilerOptions>
+  <Debugging>
+    <Exceptions Count="3">
+      <Item1>
+        <Name Value="EAbort"/>
+      </Item1>
+      <Item2>
+        <Name Value="ECodetoolError"/>
+      </Item2>
+      <Item3>
+        <Name Value="EFOpenError"/>
+      </Item3>
+    </Exceptions>
+  </Debugging>
+</CONFIG>

+ 21 - 0
test/test_extra/shadow/shadow.lpr

@@ -0,0 +1,21 @@
+program shadow;
+
+{$mode objfpc}{$H+}
+
+uses
+  {$IFDEF UNIX}{$IFDEF UseCThreads}
+  cthreads,
+  {$ENDIF}{$ENDIF}
+  Interfaces, // this includes the LCL widgetset
+  Forms, umain
+  { you can add units after this };
+
+{$R *.res}
+
+begin
+  RequireDerivedFormResource := True;
+  Application.Initialize;
+  Application.CreateForm(TForm1, Form1);
+  Application.Run;
+end.
+

+ 24 - 0
test/test_extra/shadow/umain.lfm

@@ -0,0 +1,24 @@
+object Form1: TForm1
+  Left = 720
+  Height = 240
+  Top = 193
+  Width = 320
+  Caption = 'Form1'
+  ClientHeight = 240
+  ClientWidth = 320
+  OnCreate = FormCreate
+  OnDestroy = FormDestroy
+  LCLVersion = '1.2.4.0'
+  object BGRAVirtualScreen1: TBGRAVirtualScreen
+    Left = 0
+    Height = 240
+    Top = 0
+    Width = 320
+    OnRedraw = BGRAVirtualScreen1Redraw
+    Align = alClient
+    Alignment = taLeftJustify
+    Color = clWhite
+    ParentColor = False
+    TabOrder = 0
+  end
+end

+ 83 - 0
test/test_extra/shadow/umain.pas

@@ -0,0 +1,83 @@
+unit umain;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
+  BGRAVirtualScreen, BGRABitmap, BCTypes, BGRABitmapTypes;
+
+type
+
+  { TForm1 }
+
+  TForm1 = class(TForm)
+    BGRAVirtualScreen1: TBGRAVirtualScreen;
+    procedure BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
+    procedure FormCreate(Sender: TObject);
+    procedure FormDestroy(Sender: TObject);
+  private
+    { private declarations }
+  public
+    { public declarations }
+    blurSize: integer;
+    offset: TPoint;
+    logo, logoShadow: TBGRABitmap;
+  end;
+
+var
+  Form1: TForm1;
+
+implementation
+
+{$R *.lfm}
+
+procedure SingleColor(Bitmap: TBGRABitmap; Color: TBGRAPixel);
+var
+  i: integer;
+  p: PBGRAPixel;
+begin
+  p := Bitmap.Data;
+
+  for i := Bitmap.NBPixels - 1 downto 0 do
+  begin
+    p^.red := Color.Red;
+    p^.green := Color.Green;
+    p^.blue := Color.Blue;
+    Inc(p);
+  end;
+end;
+
+function Shadow(Source: TBGRABitmap; Color: TBGRAPixel; Blur: integer): TBGRABitmap;
+begin
+  Result := TBGRABitmap.Create(Source.Width + (2 * Blur), Source.Height + (2 * Blur));
+  Result.PutImage(Blur, Blur, Source, dmDrawWithTransparency);
+  SingleColor(Result, Color);
+  BGRAReplace(Result, Result.FilterBlurRadial(Blur, rbFast));
+end;
+
+{ TForm1 }
+
+procedure TForm1.BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
+begin
+  Bitmap.PutImage(blurSize + offSet.x, blurSize + offset.y, logoShadow,
+    dmDrawWithTransparency);
+  Bitmap.PutImage(blurSize * 2, blurSize * 2, logo, dmDrawWithTransparency);
+end;
+
+procedure TForm1.FormCreate(Sender: TObject);
+begin
+  blurSize := 5;
+  offSet := Point(5, 5);
+  logo := TBGRABitmap.Create('logo.png');
+  logoShadow := Shadow(logo, BGRA(0, 200, 200, 255), blurSize);
+end;
+
+procedure TForm1.FormDestroy(Sender: TObject);
+begin
+  logo.Free;
+  logoShadow.Free;
+end;
+
+end.