W
wk_knife
Unregistered / Unconfirmed
GUEST, unregistred user!
最近利用零碎时间在做一个矢量图软件。作了很多内容了。
创建图元时用到了鼠标的左键单、双击。
这几天在合并一开始做的一些图元,象把直线和折线合成了一个折线图元。在把圆和椭圆合并时,突然想到一个问题,如何区分时画圆还是椭圆。在PHOTOSHOP中记得是用CTRL或SHIFT。但是按我目前的框架。实现这个有点难度。我的图元的方法中不包含对鼠标、键盘的处理,所有的处理都集中在控制类中。编写新的图元类考虑鼠标、键盘的动作。
记得曾经在一本VC的书上看到图元类中还包括对鼠标处理的方法,当时觉得这样的图元类很累赘。但现在看来也不无好处。
所以想问问大家,如果让你们选择,你们会选择在图元中包括鼠标处理的方法呢,还是不包括?
附上我的类的大致定义
控制类(窗口类)
TCustomWKControl = class(TCustomControl)
private
................
procedure WMEraseBKgnd( var Message: TWMErasebkgnd); message WM_ERASEBKGND;
procedure WMHScroll( var Message: TWMHScroll); message WM_HSCROLL;
procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LBUTTONDBLCLK;
procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LBUTTONUP;
procedure WMMouseMove(var Message: TWMMouseMove); message WM_MOUSEMOVE;
procedure WMRButtonDown(var Message: TWMRButtonDown); message WM_RBUTTONDOWN;
procedure WMRButtonUp(var Message: TWMRButtonUp); message WM_RBUTTONUP;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure WMVScroll( var Message: TWMVScroll); message WM_VSCROLL;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure DefineProperties(Filer: TFiler); override;
procedure DoAfterDrawNewObject(AObject : TWKObject); virtual;
procedure DoAfterObjectMove(AObject : TWKObject); virtual;
procedure DoObjectClick(AObject : TWKObject); virtual;
procedure DoObjectDblClick(AObject : TWKObject); virtual;
procedure DoObjectMouseEnter(AObject : TWKObject); virtual;
procedure DoObjectMouseLeave(AObject : TWKObject); virtual;
procedure DoObjectMouseMove(AObject : TWKObject; Shift: TShiftState; X, Y: Integer); virtual;
procedure Resize; override;
public
...................................
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
procedure CreateWnd;override;
procedure Assign(Source : TPersistent); override;
procedure CancelDrawNewObject;
function CanRedo:Boolean;
function CanUndo:Boolean;
procedure Clear;
function CopyToClipboard:Boolean;virtual;
procedure CutToClipboard;virtual;
procedure BringtoFront(AObject:TWKObject=nil);
procedure SendToBack(AObject:TWKObject=nil);
Function DrawNewObject(AObjectClass : TWKObjectClass):TWKObject;
procedure InitViewMode(AViewModeClass:TViewModeClass);
procedure LoadFromFile(Const FileName:string);virtual;
procedure LoadFromStream(AStream:TStream);virtual;
procedure Paint;override;
procedure PaintToCanvas(AViewMode:TViewMode; UpdateRect:TRect); // 0.91
procedure PasteFromClipboard;virtual;
procedure Print;overload; //打印所有
procedure Print(FromPage,ToPage:integer);overload; //按页打印
procedure Print(FromPoint,ToPoint:TRPoint);overload; //打印从一个位置到另一个位置
procedure Redo;virtual;
procedure SavetoFile(Const FileName:string);virtual;
procedure SaveToStream(AStream:TStream);virtual;
procedure Undo;virtual;
procedure Composite;virtual;
procedure DoComposite;virtual;
function CanComposite:Boolean;
procedure UnComposite;virtual;
procedure DoUnComposite;virtual;
function CanUnComposite:Boolean;
property ActiveObject:TWKObject read FActiveObject write SetActiveObject;
procedure SetSelectedObjsLock(const ALock:Boolean);
property Canvas;
property ChildrenClipping : Boolean read FChildrenClipping write SetChildrenClipping;
property ClipRect: TRect read GetClipRect write SetCliprect;
property ContextClipping:Boolean read FContextClipping write SetContextClipping;
property ContextLengthouble read GetContextLength write SetContextLength; /////////////
property ContextWidthouble read GetContextWidth write SetContextWidth; ///////////
property CurrentLayer : TWKLayer read FCurLayer write SetCurLayer stored False;//当前图层
property Layers: TWKLayers read FItems;//图层列表类
property LimitUndo:integer read FLimitUndo write SetLimitUndo;
property Modified:Boolean read FModified write SetModified;
property OnAfterDrawNewObject : TNotifyEvent read FAfterDrawNewObject write FAfterDrawNewObject;
property OnAfterObjectMove : TNotifyEvent read FAfterObjectMove write FAfterObjectMove;
property OnObjectClick : TNotifyEvent read FObjectClick write FObjectClick;
property OnObjectDblClick : TNotifyEvent read FObjectDblClick write FObjectDblClick;
property OnObjectMouseEnter : TNotifyEvent read FObjectMouseEnter write FObjectMouseEnter;
property OnObjectMouseLeave : TNotifyEvent read FObjectMouseLeave write FObjectMouseLeave;
property OnObjectMouseMove : TMouseMoveEvent read FObjectMouseMove write FObjectMouseMove;
property ReadOnly : Boolean read FReadOnly write SetReadOnly;
property Zoomouble read GetZoom write SetZoom; //缩放比 设备/逻辑 ///////////////////////
end;
图元类的基类
TWKObject=class(TInterfacedPersistent,IWKObject, ISitePersist, IDataPersist)
private
..........................
FOwner : TCustomWKControl;
FObjectList : TList;
FData : pointer;
FLayer : TWKLayer;
FParent : TWKObject;
FSelected : Boolean;
FLock : Boolean;
FCursor : TCursor;
public
constructor Create(AOwner : TCustomWKControl); virtual;
destructor Destroy;override;
procedure Assign(Source:TPersistent); override;
function Clone: TWKObject; virtual;abstract;
function Add(const AObject:TWKObject):Integer;virtual;
function IndexOf(const Value:TWKObject):Integer;virtual;
procedure Delete(Const Index:Integer);virtual;
function Remove(const AObject:TWKObject):integer;virtual;
procedure Clear; virtual;
property Objects[Index : Integer] : TWKObject read GetObject write SetObject; default;//子图元列表
property Count:Integer read GetCount;
procedure LoadFromStream(Stream:TStream);virtual;
procedure SaveToStream(Stream:TStream);virtual;
property Layer:TWKLayer read FLayer write SetLayer; //图层
property Parent:TWKObject read FParent write SetParent;//父图元
property Dataointer read fdata write fdata;//额外数据指针
property Cursor : TCursor read GetCursor write SetCursor;
function AddPoint(const CoordX,CoordY:Integer;MouseAct:TMouseAct=maMouseMove):Boolean;virtual;abstract;
procedure Draw(ACanvas:TCanvas);virtual;
function ObjectFromCoord(Const CoordX,CoordY: Integer; var MarginType : TMarginType):TWKObject;virtual;
function GetClippingRgn : HRGN;virtual;
function GetDisplayRect(withChild:Boolean=False;UseAsClip:Boolean=False):TRect;virtual;//abstract;
function HasInternalPoint(const CoordX,CoordY:Integer):Boolean;virtual;abstract;
function HasMarginPoint(const CoordX,CoordY:Integer;var MarginType:TMarginType):Boolean;virtual;abstract;
procedure Move(const CoordX,CoordY:Integer);virtual;
function InClippingRgn:Boolean;virtual;
procedure NeedRepaint;virtual;abstract;
procedure ReadData(Stream: TStream);virtual;
procedure ReadSite(Stream: TStream);virtual;
procedure WriteData(Stream: TStream);virtual;
procedure WriteSite(Stream: TStream);virtual;
procedure Resize(const CoordX,CoordY:Integer);virtual;abstract;
procedure SaveCoords;virtual;
procedure Select;virtual;
procedure UnSelect;virtual;
property Owner:TCustomWKControl read FOwner;
property Name: string read GetName write SetName;
property ReadOnly: Boolean read GetReadOnly write SetReadOnly;
property Visible: Boolean read Getvisible write Setvisible;
property Lock: Boolean read GetLock write SetLock;
property Selected: Boolean read GetSelected write SetSelected;
end;
创建图元时用到了鼠标的左键单、双击。
这几天在合并一开始做的一些图元,象把直线和折线合成了一个折线图元。在把圆和椭圆合并时,突然想到一个问题,如何区分时画圆还是椭圆。在PHOTOSHOP中记得是用CTRL或SHIFT。但是按我目前的框架。实现这个有点难度。我的图元的方法中不包含对鼠标、键盘的处理,所有的处理都集中在控制类中。编写新的图元类考虑鼠标、键盘的动作。
记得曾经在一本VC的书上看到图元类中还包括对鼠标处理的方法,当时觉得这样的图元类很累赘。但现在看来也不无好处。
所以想问问大家,如果让你们选择,你们会选择在图元中包括鼠标处理的方法呢,还是不包括?
附上我的类的大致定义
控制类(窗口类)
TCustomWKControl = class(TCustomControl)
private
................
procedure WMEraseBKgnd( var Message: TWMErasebkgnd); message WM_ERASEBKGND;
procedure WMHScroll( var Message: TWMHScroll); message WM_HSCROLL;
procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LBUTTONDBLCLK;
procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LBUTTONUP;
procedure WMMouseMove(var Message: TWMMouseMove); message WM_MOUSEMOVE;
procedure WMRButtonDown(var Message: TWMRButtonDown); message WM_RBUTTONDOWN;
procedure WMRButtonUp(var Message: TWMRButtonUp); message WM_RBUTTONUP;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure WMVScroll( var Message: TWMVScroll); message WM_VSCROLL;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure DefineProperties(Filer: TFiler); override;
procedure DoAfterDrawNewObject(AObject : TWKObject); virtual;
procedure DoAfterObjectMove(AObject : TWKObject); virtual;
procedure DoObjectClick(AObject : TWKObject); virtual;
procedure DoObjectDblClick(AObject : TWKObject); virtual;
procedure DoObjectMouseEnter(AObject : TWKObject); virtual;
procedure DoObjectMouseLeave(AObject : TWKObject); virtual;
procedure DoObjectMouseMove(AObject : TWKObject; Shift: TShiftState; X, Y: Integer); virtual;
procedure Resize; override;
public
...................................
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
procedure CreateWnd;override;
procedure Assign(Source : TPersistent); override;
procedure CancelDrawNewObject;
function CanRedo:Boolean;
function CanUndo:Boolean;
procedure Clear;
function CopyToClipboard:Boolean;virtual;
procedure CutToClipboard;virtual;
procedure BringtoFront(AObject:TWKObject=nil);
procedure SendToBack(AObject:TWKObject=nil);
Function DrawNewObject(AObjectClass : TWKObjectClass):TWKObject;
procedure InitViewMode(AViewModeClass:TViewModeClass);
procedure LoadFromFile(Const FileName:string);virtual;
procedure LoadFromStream(AStream:TStream);virtual;
procedure Paint;override;
procedure PaintToCanvas(AViewMode:TViewMode; UpdateRect:TRect); // 0.91
procedure PasteFromClipboard;virtual;
procedure Print;overload; //打印所有
procedure Print(FromPage,ToPage:integer);overload; //按页打印
procedure Print(FromPoint,ToPoint:TRPoint);overload; //打印从一个位置到另一个位置
procedure Redo;virtual;
procedure SavetoFile(Const FileName:string);virtual;
procedure SaveToStream(AStream:TStream);virtual;
procedure Undo;virtual;
procedure Composite;virtual;
procedure DoComposite;virtual;
function CanComposite:Boolean;
procedure UnComposite;virtual;
procedure DoUnComposite;virtual;
function CanUnComposite:Boolean;
property ActiveObject:TWKObject read FActiveObject write SetActiveObject;
procedure SetSelectedObjsLock(const ALock:Boolean);
property Canvas;
property ChildrenClipping : Boolean read FChildrenClipping write SetChildrenClipping;
property ClipRect: TRect read GetClipRect write SetCliprect;
property ContextClipping:Boolean read FContextClipping write SetContextClipping;
property ContextLengthouble read GetContextLength write SetContextLength; /////////////
property ContextWidthouble read GetContextWidth write SetContextWidth; ///////////
property CurrentLayer : TWKLayer read FCurLayer write SetCurLayer stored False;//当前图层
property Layers: TWKLayers read FItems;//图层列表类
property LimitUndo:integer read FLimitUndo write SetLimitUndo;
property Modified:Boolean read FModified write SetModified;
property OnAfterDrawNewObject : TNotifyEvent read FAfterDrawNewObject write FAfterDrawNewObject;
property OnAfterObjectMove : TNotifyEvent read FAfterObjectMove write FAfterObjectMove;
property OnObjectClick : TNotifyEvent read FObjectClick write FObjectClick;
property OnObjectDblClick : TNotifyEvent read FObjectDblClick write FObjectDblClick;
property OnObjectMouseEnter : TNotifyEvent read FObjectMouseEnter write FObjectMouseEnter;
property OnObjectMouseLeave : TNotifyEvent read FObjectMouseLeave write FObjectMouseLeave;
property OnObjectMouseMove : TMouseMoveEvent read FObjectMouseMove write FObjectMouseMove;
property ReadOnly : Boolean read FReadOnly write SetReadOnly;
property Zoomouble read GetZoom write SetZoom; //缩放比 设备/逻辑 ///////////////////////
end;
图元类的基类
TWKObject=class(TInterfacedPersistent,IWKObject, ISitePersist, IDataPersist)
private
..........................
FOwner : TCustomWKControl;
FObjectList : TList;
FData : pointer;
FLayer : TWKLayer;
FParent : TWKObject;
FSelected : Boolean;
FLock : Boolean;
FCursor : TCursor;
public
constructor Create(AOwner : TCustomWKControl); virtual;
destructor Destroy;override;
procedure Assign(Source:TPersistent); override;
function Clone: TWKObject; virtual;abstract;
function Add(const AObject:TWKObject):Integer;virtual;
function IndexOf(const Value:TWKObject):Integer;virtual;
procedure Delete(Const Index:Integer);virtual;
function Remove(const AObject:TWKObject):integer;virtual;
procedure Clear; virtual;
property Objects[Index : Integer] : TWKObject read GetObject write SetObject; default;//子图元列表
property Count:Integer read GetCount;
procedure LoadFromStream(Stream:TStream);virtual;
procedure SaveToStream(Stream:TStream);virtual;
property Layer:TWKLayer read FLayer write SetLayer; //图层
property Parent:TWKObject read FParent write SetParent;//父图元
property Dataointer read fdata write fdata;//额外数据指针
property Cursor : TCursor read GetCursor write SetCursor;
function AddPoint(const CoordX,CoordY:Integer;MouseAct:TMouseAct=maMouseMove):Boolean;virtual;abstract;
procedure Draw(ACanvas:TCanvas);virtual;
function ObjectFromCoord(Const CoordX,CoordY: Integer; var MarginType : TMarginType):TWKObject;virtual;
function GetClippingRgn : HRGN;virtual;
function GetDisplayRect(withChild:Boolean=False;UseAsClip:Boolean=False):TRect;virtual;//abstract;
function HasInternalPoint(const CoordX,CoordY:Integer):Boolean;virtual;abstract;
function HasMarginPoint(const CoordX,CoordY:Integer;var MarginType:TMarginType):Boolean;virtual;abstract;
procedure Move(const CoordX,CoordY:Integer);virtual;
function InClippingRgn:Boolean;virtual;
procedure NeedRepaint;virtual;abstract;
procedure ReadData(Stream: TStream);virtual;
procedure ReadSite(Stream: TStream);virtual;
procedure WriteData(Stream: TStream);virtual;
procedure WriteSite(Stream: TStream);virtual;
procedure Resize(const CoordX,CoordY:Integer);virtual;abstract;
procedure SaveCoords;virtual;
procedure Select;virtual;
procedure UnSelect;virtual;
property Owner:TCustomWKControl read FOwner;
property Name: string read GetName write SetName;
property ReadOnly: Boolean read GetReadOnly write SetReadOnly;
property Visible: Boolean read Getvisible write Setvisible;
property Lock: Boolean read GetLock write SetLock;
property Selected: Boolean read GetSelected write SetSelected;
end;