[JEDI.NET-commits] main/run Jedi.Windows.Forms.Graphics.ShapeControl.pas,NONE,1.1 Jedi.Windows.Forms
Status: Pre-Alpha
Brought to you by:
jedi_mbe
From: Marcel B. <jed...@us...> - 2005-03-07 18:04:17
|
Update of /cvsroot/jedidotnet/main/run In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv924/main/run Added Files: Jedi.Windows.Forms.Graphics.ShapeControl.pas Removed Files: Jedi.Windows.Forms.Visual.pas Log Message: * Renamed unit Jedi.Windows.Forms.Visual to Jedi.Windows.Forms.Graphics.ShapeControl * Provided toolbox bitmap for the Shape control * Created a new assembly for all WinForms graphical controls (contains the Shape control only at the moment) --- Jedi.Windows.Forms.Visual.pas DELETED --- --- NEW FILE: Jedi.Windows.Forms.Graphics.ShapeControl.pas --- {------------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License");you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is: Jedi.Windows.Forms.Visual.pas, released on 2004-07-23. The Initial Developer of the Original Code is Andreas Hausladen Portions created by Andreas Hausladen are Copyright (C) 2004 Andreas Hausladen All Rights Reserved. Contributor(s): You may retrieve the latest version of this file at the JEDI.NET home page, located at http://sourceforge.net/projects/jedidotnet Known Issues: -------------------------------------------------------------------------------} // $Id: Jedi.Windows.Forms.Graphics.ShapeControl.pas,v 1.1 2005/03/07 18:04:00 jedi_mbe Exp $ unit Jedi.Windows.Forms.Graphics.ShapeControl; interface {$REGION 'interface uses'} uses Jedi.System.SourceVersioning, System.ComponentModel, System.Drawing, System.Drawing.Drawing2D, System.Windows.Forms; {$ENDREGION} {$REGION 'Shape control'} type Shape = class; [JediSourceInfo('$Source: /cvsroot/jedidotnet/main/run/Jedi.Windows.Forms.Graphics.ShapeControl.pas,v $', '$Revision: 1.1 $', '$Date: 2005/03/07 18:04:00 $'), ToolboxBitmap(TypeOf(Shape))] Shape = class (Control) {$REGION 'Constructor'} public constructor Create; {$ENDREGION} {$REGION 'ShapeType enumeration'} public type ShapeType = ( stCircle, stEllipse, stRectangle, stRoundRect, stRoundSquare, stSquare ); {$ENDREGION} {$REGION 'Data'} strict private FShape: Shape.ShapeType; FPen: System.Drawing.Pen; FBrush: System.Drawing.Brush; {$ENDREGION} {$REGION 'Property descriptions'} private const SShapeType = 'The type of the Shape.'; SShapePen = 'The pen for line drawing.'; SShapeBrush = 'The brush for filling.'; {$ENDREGION} {$REGION 'Overriden methods'} strict protected procedure OnPaint(e: PaintEventArgs); override; procedure OnResize(e: EventArgs); override; {$ENDREGION} {$REGION 'Property setters'} public procedure set_Brush(value: System.Drawing.Brush); procedure set_Pen(value: System.Drawing.Pen); procedure set_Shape(value: ShapeType); {$ENDREGION} {$REGION 'Properties'} public [Category('Appearance'), Description(SShapeBrush)] property Brush: System.Drawing.Brush read FBrush write set_Brush; [Category('Appearance'), Description(SShapePen)] property Pen: System.Drawing.Pen read FPen write set_Pen; [Category('Appearance'), Description(SShapeType)] property Shape: ShapeType read FShape write set_Shape default stRectangle; {$ENDREGION} end; {$R '..\Resources\Jedi.Windows.Forms.Graphics.Shape.bmp'} [assembly: RuntimeRequiredAttribute(TypeOf(Shape))] {$ENDREGION} implementation {$REGION 'Shape control'} constructor Shape.Create; begin inherited Create; Width := 80; Height := 80; FShape := stRectangle; FPen := System.Drawing.Pen.Create(Color.Black); FBrush := System.Drawing.Brushes.White; end; procedure Shape.OnPaint(e: PaintEventArgs); var X, Y, W, H: Integer; Offset: Integer; begin { Calculate X, Y coordinates } X := 0; Y := 0; W := Width - 1; H := Height - 1; { Invalid size } if (W < 0) or (H < 0) then Exit; Offset := 4; if Width < Offset * 2 then Offset := Width div 2; case Shape of stCircle, stRoundSquare, stSquare: begin if Width > Height then begin W := Height - 1; X := (Width - Height) div 2; end else begin H := Width - 1; Y := (Height - Width) div 2; end; end; end; { Draw shape } case Shape of stCircle, stEllipse: begin e.Graphics.FillEllipse(FBrush, X, Y, W, H); e.Graphics.DrawEllipse(FPen, X, Y, W, H); end; stRectangle, stSquare: begin e.Graphics.FillRectangle(FBrush, X, Y, W, H); e.Graphics.DrawRectangle(FPen, X, Y, W, H); end; stRoundRect, stRoundSquare: begin e.Graphics.FillEllipse(FBrush, X, Y, Offset * 2, Offset * 2); e.Graphics.FillEllipse(FBrush, X, Y + H - Offset * 2, Offset * 2, Offset * 2); e.Graphics.FillEllipse(FBrush, X + W - Offset * 2, Y, Offset * 2, Offset * 2); e.Graphics.FillEllipse(FBrush, X + W - Offset * 2, Y + H - Offset * 2, Offset * 2, Offset * 2); e.Graphics.FillRectangle(FBrush, X, Y + Offset, W, H - Offset * 2); e.Graphics.FillRectangle(FBrush, X + Offset, Y, W - Offset * 2, Offset); e.Graphics.FillRectangle(FBrush, X + Offset, Y + H - Offset, W - Offset * 2, Offset); e.Graphics.DrawArc(FPen, X, Y, Offset * 2, Offset * 2, 180, 90); e.Graphics.DrawArc(FPen, X, Y + H - Offset * 2, Offset * 2, Offset * 2, 90, 90); e.Graphics.DrawArc(FPen, X + W - Offset * 2, Y, Offset * 2, Offset * 2, 270, 90); e.Graphics.DrawArc(FPen, X + W - Offset * 2, Y + H - Offset * 2, Offset * 2, Offset * 2, 0, 90); e.Graphics.DrawLine(FPen, X + Offset, Y, X + W - Offset, Y); e.Graphics.DrawLine(FPen, X + Offset, Y + H, X + W - Offset, Y + H); e.Graphics.DrawLine(FPen, X, Y + Offset, X, Y + H - Offset); e.Graphics.DrawLine(FPen, X + W, Y + Offset, X + W, Y + H - Offset); end; end; end; procedure Shape.OnResize(e: EventArgs); begin inherited OnResize(e); Refresh; end; procedure Shape.set_Brush(value: System.Drawing.Brush); begin if Value <> FBrush then begin FBrush := Value; Invalidate; end; end; procedure Shape.set_Pen(value: System.Drawing.Pen); begin if Value <> FPen then begin FPen := Value; Invalidate; end; end; procedure Shape.set_Shape(value: ShapeType); begin if Value <> FShape then begin FShape := Value; Invalidate; end; end; {$ENDREGION} end. |