home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2002 September
/
Chip_2002-09_cd1.bin
/
zkuste
/
delphi
/
kompon
/
d6
/
YPPARSER.ZIP
/
Components
/
PicBldr.pas
< prev
Wrap
Pascal/Delphi Source File
|
2002-06-14
|
10KB
|
299 lines
{********************************************************}
{ }
{ TPicBldr }
{ IMPORTANT-READ CAREFULLY: }
{ }
{ This End-User License Agreement is a legal }
{ agreement between you (either an individual }
{ or a single entity) and Pisarev Yuriy for }
{ the software product identified above, which }
{ includes computer software and may include }
{ associated media, printed materials, and "online" }
{ or electronic documentation ("SOFTWARE PRODUCT"). }
{ By installing, copying, or otherwise using the }
{ SOFTWARE PRODUCT, you agree to be bound by the }
{ terms of this LICENSE AGREEMENT. }
{ }
{ If you do not agree to the terms of this }
{ LICENSE AGREEMENT, do not install or use }
{ the SOFTWARE PRODUCT. }
{ }
{ License conditions }
{ }
{ No part of the software or the manual may be }
{ multiplied, disseminated or processed in any }
{ way without the written consent of Pisarev }
{ Yuriy. Violations of these conditions will be }
{ prosecuted in every case. }
{ }
{ The use of the software is done at your own }
{ risk. The manufacturer and developer accepts }
{ no liability for any damages, either as direct }
{ or indirect consequence of the use of this }
{ product or software. }
{ }
{ Only observance of these conditions allows you }
{ to use the hardware and software in your computer }
{ system. }
{ }
{ All rights reserved. }
{ Copyright 2002 Pisarev Yuriy }
{ }
{ yuriy_mbox@hotmail.com }
{ }
{********************************************************}
unit PicBldr;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Graphics, DataEditor;
type
TScripts = array of TScript;
TConstrunctEvent = procedure(Sender: TObject; Done: Integer) of object;
TPicBldr = class(TGraphicControl)
private
FShowText: Boolean;
FYValueID: Integer;
FXValueID: Integer;
FIndexID: Integer;
FCurrYValue: Integer;
FCurrXValue: Integer;
FPictureSize: Integer;
FCurrIndex: Integer;
FFileName: string;
FPicture: TBitmap;
FOnConstructing: TConstrunctEvent;
FDataEditor: TDataEditor;
FOnConstruct: TNotifyEvent;
FScripts: TScripts;
FLines: TStrings;
procedure SetLines(const Value: TStrings);
function NumFunction(FunctionID: Integer; TypeID: Integer;
var Value1: Double; Value2, Value3: Double): Boolean;
protected
procedure Paint; override;
property CurrXValue: Integer read FCurrXValue write FCurrXValue;
property CurrYValue: Integer read FCurrYValue write FCurrYValue;
property CurrIndex: Integer read FCurrIndex write FCurrIndex;
property DataEditor: TDataEditor read FDataEditor write FDataEditor;
property IndexID: Integer read FIndexID write FIndexID;
property Scripts: TScripts read FScripts write FScripts;
property XValueID: Integer read FXValueID write FXValueID;
property YValueID: Integer read FYValueID write FYValueID;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Draw; virtual;
procedure LoadFromFile(const FileName: string); virtual;
procedure ClearScripts; virtual;
procedure CalcScripts; virtual;
procedure Construct; virtual;
property Picture: TBitmap read FPicture write FPicture;
property PictureSize: Integer read FPictureSize write FPictureSize;
published
property Align;
property Anchors;
property Color;
property Constraints;
property Cursor;
property Lines: TStrings read FLines write SetLines;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FileName: string read FFileName write FFileName;
property Font;
property Height;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property ShowText: Boolean read FShowText write FShowText;
property Visible;
property Width;
property OnClick;
property OnConstruct: TNotifyEvent read FOnConstruct write FOnConstruct;
property OnConstructing: TConstrunctEvent read FOnConstructing
write FOnConstructing;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
end;
const
ByteCounts: array [pf1Bit..pf32Bit] of Byte = (1, 1, 1, 2, 2, 3, 4);
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TPicBldr]);
end;
{ TPicBldr }
procedure TPicBldr.CalcScripts;
var
I, J: Integer;
NewLines: TStringList;
begin
ClearScripts;
NewLines := TStringList.Create;
try
for I := 0 to FLines.Count - 1 do begin
J := Length(FScripts);
SetLength(FScripts, J + 1);
try
with FDataEditor do begin
StringToNumScript(FLines[I], FScripts[J]);
ExecuteNumScript(FScripts[J]);
end;
NewLines.Add(FLines[I]);
except
FScripts[J] := nil;
SetLength(FScripts, J);
end;
end;
FLines.Assign(NewLines);
finally
NewLines.Free;
end;
end;
procedure TPicBldr.ClearScripts;
var
I: Integer;
begin
for I := Low(FScripts) to High(FScripts) do FScripts[I] := nil;
FScripts := nil;
end;
procedure TPicBldr.Construct;
var
I, J, Index1, Index2, Index3, ScriptsCount: Integer;
Size: TSize;
P: Pointer;
begin
ScriptsCount := Length(FScripts);
if ScriptsCount < ByteCounts[pf24bit] then Exit;
with FPicture do begin
PixelFormat := pf24bit;
Width := ClientWidth - 30;
Height := ClientHeight - 30;
Size.cx := Width * ByteCounts[pf24bit];
Size.cy := Height - 1;
end;
FPictureSize := Size.cx * (Size.cy div ByteCounts[pf24bit]);
if Assigned(FOnConstruct) then FOnConstruct(Self);
Index1 := Random(ScriptsCount);
Index2 := Random(ScriptsCount);
Index3 := Random(ScriptsCount);
FCurrIndex := 0;
for I := 0 to Size.cy do begin
J := 0;
P := FPicture.ScanLine[I];
FCurrYValue := I;
while J < Size.cx do begin
FCurrXValue := J;
with FDataEditor do begin
PByte(Integer(P) + J)^ := Round(ExecuteNumScript(FScripts[Index1]));
PByte(Integer(P) + J + 1)^ := Round(ExecuteNumScript(FScripts[Index2]));
PByte(Integer(P) + J + 2)^ := Round(ExecuteNumScript(FScripts[Index3]));
end;
Inc(J, ByteCounts[pf24bit]);
Inc(FCurrIndex);
if Assigned(FOnConstructing) then FOnConstructing(Self, FCurrIndex);
end;
end;
if FShowText then with FPicture.Canvas do begin
Font.Style := [fsBold];
J := TextHeight('0');
TextOut(10, 10, Format('Red: %s', [FLines[Index3]]));
TextOut(10, 10 + J, Format('Green: %s', [FLines[Index2]]));
TextOut(10, 10 + J * 2, Format('Blue: %s', [FLines[Index1]]));
end;
end;
constructor TPicBldr.Create(AOwner: TComponent);
begin
inherited;
FDataEditor := TDataEditor.Create(Self);
with FDataEditor do begin
OnNumFunction := NumFunction;
RegisterNumFunction(FXValueID, 'x', False, False);
RegisterNumFunction(FYValueID, 'y', False, False);
RegisterNumFunction(FIndexID, 'index', False, False);
SortNumFunctionsData;
end;
FPicture := TBitmap.Create;
with FPicture do PixelFormat := pf24bit;
FLines := TStringList.Create;
Randomize;
end;
destructor TPicBldr.Destroy;
begin
ClearScripts;
FScripts := nil;
FLines.Free;
FPicture.Free;
inherited;
end;
procedure TPicBldr.Draw;
begin
with Canvas do begin
Brush.Color := Color;
Pen.Style := psDot;
Rectangle(10, 10, ClientWidth - 10, ClientHeight - 10);
Draw(15, 15, FPicture);
end;
end;
procedure TPicBldr.LoadFromFile(const FileName: string);
begin
if FileExists(FileName) then FLines.LoadFromFile(FileName);
CalcScripts;
end;
function TPicBldr.NumFunction(FunctionID, TypeID: Integer;
var Value1: Double; Value2, Value3: Double): Boolean;
begin
if FunctionID = FIndexID then Value1 := FCurrIndex
else if FunctionID = FXValueID then Value1 := FCurrXValue
else if FunctionID = FYValueID then Value1 := FCurrYValue
else begin
Result := True;
Exit;
end;
Result := False;
end;
procedure TPicBldr.Paint;
begin
inherited;
Draw;
end;
procedure TPicBldr.SetLines(const Value: TStrings);
begin
FLines.Assign(Value);
ClearScripts;
end;
end.