unit MPWedgeItem;
interface
uses
Windows, Classes, GDIPCustomItem, Graphics, GDIPTextItem, AdvGDIP, GDIPFill;
const
MAJ_VER = 1; // Major version nr.
MIN_VER = 0; // Minor version nr.
REL_VER = 0; // Release nr.
BLD_VER = 0; // Build nr.
//v0.9.0.0 : First Beta Release
//v1.0.0.0 : First Release
type
TWedgePosition = (wpLeft, wpRight);
TWedgePositions = set of TWedgePosition;
TMPWedgeItem = class(TTextItem)
private
FWedgePositions: TWedgePositions;
FWedgeSize: integer;
FWedgeStates: TItemStates;
procedure SetWedgePositions(const Value: TWedgePositions);
procedure SetWedgeSize(const Value: integer);
procedure SetWedgeStates(const Value: TItemStates);
protected
function GetVersionNr: integer; override;
procedure DrawFocus(g: TGPGraphics; ARect: TGPRectF; ItemAppearance: TItemAppearance); override;
function GetWedgeRect(ARect: TGPRectF): TGPRectF;
public
constructor Create(AOwner: TComponent); override;
procedure Assign(Source: TPersistent); override;
function CreateNewItem(AOwner: TComponent): TCustomItem; override;
function GetClassType: TComponentClass; override;
class function CustomClassName: String; override;
procedure DrawInRect(g: TGPGraphics; ItemAppearance: TItemAppearance; R: TGPRectF); override;
function DrawText(g: TGPGraphics; ARect: TGPRectF; ItemAppearance: TItemAppearance; DoText: Boolean = true): TGPRectF; override;
published
property WedgePositions: TWedgePositions read FWedgePositions write SetWedgePositions default [wpRight];
property WedgeSize: integer read FWedgeSize write SetWedgeSize default 6;
property WedgeStates: TItemStates read FWedgeStates write SetWedgeStates default [isNormal, isHovered, isDown, isSelected];
end;
procedure Register;
procedure UnRegister;
implementation
procedure Register;
begin
RegisterPolyItem(TMPWedgeItem);
RegisterClass(TMPWedgeItem);
end;
procedure UnRegister;
begin
UnRegisterClass(TMPWedgeItem);
end;
{ TWedgeItem }
procedure TMPWedgeItem.Assign(Source: TPersistent);
begin
inherited;
if Source is TMPWedgeItem then
begin
FWedgePositions := (Source as TMPWedgeItem).WedgePositions;
FWedgeSize := (Source as TMPWedgeItem).WedgeSize;
FWedgeStates := (Source as TMPWedgeItem).WedgeStates;
Changed;
end;
end;
constructor TMPWedgeItem.Create(AOwner: TComponent);
begin
inherited;
FWedgePositions := [wpRight];
FWedgeSize := 6;
FWedgeStates := [isSelected];
Self.CaptionMargin.Left := 10;
end;
function TMPWedgeItem.CreateNewItem(AOwner: TComponent): TCustomItem;
begin
Result := TMPWedgeItem.Create(AOwner);
end;
class function TMPWedgeItem.CustomClassName: String;
begin
Result := 'MPFeuer Wedge Item';
end;
procedure TMPWedgeItem.DrawInRect(g: TGPGraphics; ItemAppearance: TItemAppearance;
R: TGPRectF);
type
TPointArray = array of TGPPointF;
var
rgn: TGPRegion;
f: TGDIPFill;
s: integer;
pth: TGPGraphicsPath;
wdRight, wdLeft: TPointArray;
p: TGPPen;
ir: TGPRectF;
begin
if (WedgePositions <> []) and (self.State in WedgeStates) then
begin
ir := MakeRect(r.x, r.y, r.width + 1, r.height + 1);
f := GetFill(ItemAppearance);
p := TGPPen.Create(MakeColor(f.BorderOpacity, f.BorderColor), f.BorderWidth);
rgn := TGPRegion.Create(ir);
s := WedgeSize;
pth := TGPGraphicsPath.Create;
if wpRight in WedgePositions then
begin
SetLength(wdRight, 3);
wdRight[0] := MakePoint(ir.X + ir.Width, ir.Y - s + (ir.Height - 1) / 2);
wdRight[1] := MakePoint(ir.X + ir.Width - s, ir.Y + (ir.Height - 1) / 2);
wdRight[2] := MakePoint(ir.X + ir.Width, ir.Y + s + (ir.Height - 1) / 2);
pth.AddPolygon(PGPPointF(wdRight), 3);
rgn.Exclude(pth);
end;
if wpLeft in WedgePositions then
begin
SetLength(wdLeft, 3);
wdLeft[0] := MakePoint(ir.X, ir.Y - s + ir.Height / 2);
wdLeft[1] := MakePoint(ir.X + s, ir.Y + ir.Height / 2);
wdLeft[2] := MakePoint(ir.X, ir.Y + s + ir.Height / 2);
pth.AddPolygon(PGPPointF(wdLeft), 3);
rgn.Exclude(pth);
end;
g.SetClip(rgn);
inherited;
g.ResetClip;
pth.Free;
rgn.Free;
if wpRight in WedgePositions then
begin
g.DrawLine(p, wdRight[0].X-1, wdRight[0].Y, wdRight[1].X-1, wdRight[1].Y);
g.DrawLine(p, wdRight[1].X-1, wdRight[1].Y, wdRight[2].X-1, wdRight[2].Y);
end;
if wpLeft in WedgePositions then
begin
g.DrawLine(p, wdleft[0].X, wdleft[0].Y, wdleft[1].X, wdleft[1].Y);
g.DrawLine(p, wdleft[1].X, wdleft[1].Y, wdleft[2].X, wdleft[2].Y);
end;
p.Free;
end
else
inherited;
end;
procedure TMPWedgeItem.DrawFocus(g: TGPGraphics; ARect: TGPRectF;
ItemAppearance: TItemAppearance);
begin
inherited DrawFocus(g, GetWedgeRect(ARect), ItemAppearance);
end;
function TMPWedgeItem.DrawText(g: TGPGraphics; ARect: TGPRectF;
ItemAppearance: TItemAppearance; DoText: Boolean = true): TGPRectF;
begin
Result := inherited DrawText(g, GetWedgeRect(ARect), ItemAppearance, DoText);
end;
function TMPWedgeItem.GetClassType: TComponentClass;
begin
Result := TMPWedgeItem;
end;
function TMPWedgeItem.GetVersionNr: integer;
begin
Result := MakeLong(MakeWord(BLD_VER,REL_VER),MakeWord(MIN_VER,MAJ_VER));
end;
function TMPWedgeItem.GetWedgeRect(ARect: TGPRectF): TGPRectF;
begin
Result := ARect;
if (self.State in WedgeStates) then
begin
if wpRight in WedgePositions then
begin
Result.Width := Result.Width - WedgeSize;
end;
if wpLeft in WedgePositions then
begin
Result.X := Result.X + WedgeSize;
Result.Width := Result.Width - WedgeSize;
end;
end;
end;
procedure TMPWedgeItem.SetWedgePositions(const Value: TWedgePositions);
begin
if FWedgePositions <> Value then
begin
FWedgePositions := Value;
Changed;
end;
end;
procedure TMPWedgeItem.SetWedgeSize(const Value: integer);
begin
if FWedgeSize <> Value then
begin
FWedgeSize := Value;
Changed;
end;
end;
procedure TMPWedgeItem.SetWedgeStates(const Value: TItemStates);
begin
if FWedgeStates <> Value then
begin
FWedgeStates := Value;
Changed;
end;
end;
end.