1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
unit UnitMA;
interface
uses Windows,Classes,ExtCtrls,types,Graphics,Controls;
type
TSelection=class
private
Anchor: TPoint;
FDotPattern: Byte;
FDashMask: Byte;
FHotRect: TRect;
FStartMask: Byte;
FColor1: TColor;
FWhere:TWinControl;
ATimer:TTimer;
FColor2: TColor;
procedure TimerEvent(Sender:TObject);
procedure SetDotPattern(const Value: Byte);
procedure SetTimerInterval(const Value: Cardinal);
function GetTimerInterval: Cardinal;
function GetAnimate: Boolean;
procedure SetAnimate(const Value: Boolean);
procedure SetStartMask(const Value: Byte);
procedure SetNewHotRect(const Value: TRect);
procedure SetColor1(const Value: TColor);
procedure SetColor(const Value: TColor);
procedure SetColor2(const Value: TColor);
private
procedure PaintHotRect;
public
constructor Create;
destructor Destroy; override;
procedure DrawHotRect;
procedure SetHotRect (Where:TWinControl;X1, Y1, X2, Y2: Integer); overload;
procedure SetHotRect (Where:TWinControl;ARect:TRect); overload;
procedure StopHotRect;
property DotPattern: Byte read FDotPattern write SetDotPattern;
property StartMask: Byte read FStartMask write SetStartMask;
property HotRect: TRect read FHotRect write SetNewHotRect;
property TimerInterval:Cardinal read GetTimerInterval write SetTimerInterval;
property Animate:Boolean read GetAnimate write SetAnimate;
property Color1:TColor read FColor1 write SetColor;
property Color2:TColor read FColor2 write SetColor2;
end;
implementation
{ TSelection }
constructor TSelection.Create;
begin
inherited;
ATimer:=TTimer.Create(nil);
ATimer.Enabled:=False;
ATimer.OnTimer:=TimerEvent;
ATimer.Interval:=100;
FStartMask:= $80;
FDotPattern:=$a0;
end;
destructor TSelection.Destroy;
begin
ATimer.Free;
inherited;
end;
procedure TSelection.DrawHotRect;
begin
ATimer.Enabled:=True;
end;
procedure LineDDAProc(X, Y: Integer;dummy:TSelection); stdcall;
var C: Integer;
FCanvas:TControlCanvas;
begin
with dummy do
begin
FCanvas:=TControlCanvas.Create;
FCanvas.Control:=FWhere;
FCanvas.Lock;
FDashMask := FDashMask shl 1;
if FDashMask = 0 then FDashMask := 1;
if (FDashMask and FDotPattern) <> 0 then C := FColor1 else C := FColor2;
SetPixel(FCanvas.Handle, X, Y, ColorToRGB(C));
FCanvas.Unlock;
FCanvas.Free;
end;
end;
procedure TSelection.SetHotRect(Where:TWinControl;X1, Y1, X2, Y2: Integer);
var Temp: Integer;
begin
// Erase previous rectangle, if any
StopHotRect;
FWhere:=Where;
Anchor.x := X1; Anchor.y := Y1;
if X1 > X2 then begin Temp := X1; X1 := X2; X2 := Temp; end;
if Y1 > Y2 then begin Temp := Y1; Y1 := Y2; Y2 := Temp; end;
FHotRect := Rect (X1, Y1, X2, Y2);
end;
procedure TSelection.TimerEvent(Sender: TObject);
begin
PaintHotRect;
end;
procedure TSelection.PaintHotRect;
begin
if (not Assigned(FWhere)) then Exit;
FStartMask := StartMask shr 1;
if FStartMask = 0 then StartMask := $80;
FDashMask := StartMask;
with HotRect do begin
LineDDA (Left, Top, Right, Top, @LineDDAProc, Integer (Self));
LineDDA (Right, Top, Right, Bottom, @LineDDAProc, Integer (Self));
LineDDA (Right, Bottom, Left, Bottom, @LineDDAProc, Integer (Self));
LineDDA (Left, Bottom, Left, Top, @LineDDAProc, Integer (Self));
end;
end;
procedure TSelection.SetDotPattern(const Value: Byte);
begin
FDotPattern := Value;
end;
procedure TSelection.SetTimerInterval(const Value: Cardinal);
begin
if ATimer<>nil then ATimer.Interval:=Value;
end;
function TSelection.GetTimerInterval: Cardinal;
begin
Result:=0;
if ATimer<>nil then Result:=ATimer.Interval;
end;
function TSelection.GetAnimate: Boolean;
begin
Result:=False;
if ATimer<>nil then Result:=ATimer.Enabled;
end;
procedure TSelection.SetAnimate(const Value: Boolean);
begin
if ATimer<>nil then ATimer.Enabled:=Value;
end;
procedure TSelection.SetStartMask(const Value: Byte);
begin
FStartMask := Value;
end;
procedure TSelection.SetNewHotRect(const Value: TRect);
begin
FHotRect := Value;
end;
procedure TSelection.SetColor(const Value: TColor);
begin
FColor1 := Value;
end;
procedure TSelection.SetHotRect(Where: TWinControl; ARect: TRect);
begin
SetHotRect(Where,ARect.Left,ARect.Top,ARect.Right,ARect.Bottom);
end;
procedure TSelection.StopHotRect;
begin
ATimer.Enabled:=False;
if not IsRectEmpty (FHotRect) then
begin
InflateRect (FHotRect, 1, 1);
InvalidateRect (Fwhere.Handle, @FHotRect, True);
InflateRect (FHotRect, -2, -2);
ValidateRect (Fwhere.Handle, @FHotRect);
UpdateWindow (Fwhere.Handle);
end;
end;
procedure TSelection.SetColor1(const Value: TColor);
begin
FColor1 := Value;
end;
procedure TSelection.SetColor2(const Value: TColor);
begin
FColor2 := Value;
end;
end. |
Partager