MMWheel.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:30k
- {========================================================================}
- {= (c) 1995-98 SwiftSoft Ronald Dittrich =}
- {========================================================================}
- {= All Rights Reserved =}
- {========================================================================}
- {= D 01099 Dresden = Tel.: +0351-8012255 =}
- {= Loewenstr.7a = info@swiftsoft.de =}
- {========================================================================}
- {= Actual versions on http://www.swiftsoft.de/mmtools.html =}
- {========================================================================}
- {= This code is for reference purposes only and may not be copied or =}
- {= distributed in any format electronic or otherwise except one copy =}
- {= for backup purposes. =}
- {= =}
- {= No Delphi Component Kit or Component individually or in a collection=}
- {= subclassed or otherwise from the code in this unit, or associated =}
- {= .pas, .dfm, .dcu, .asm or .obj files may be sold or distributed =}
- {= without express permission from SwiftSoft. =}
- {= =}
- {= For more licence informations please refer to the associated =}
- {= HelpFile. =}
- {========================================================================}
- {= $Date: 15.02.98 - 15:32:05 $ =}
- {========================================================================}
- unit MMWheel;
- {$I COMPILER.INC}
- interface
- uses
- {$IFDEF WIN32}
- Windows,
- {$ELSE}
- WinTypes,
- WinProcs,
- {$ENDIF}
- Messages,
- Classes,
- SysUtils,
- Controls,
- ExtCtrls,
- Graphics,
- Menus,
- MMObj,
- MMScale;
- type
- EMMWheelError = class(Exception);
- TMMFocusAction = (faHandleColor,faFrameRect,faAll);
- TMMHandleStyle = (hsEllipse,hsOwnerDraw);
- TMMDrawHandleEvent = procedure(Sender : TObject; Canvas : TCanvas; Rect : TRect;
- Origin : TPoint; Focused : Boolean) of object;
- TMMPaintEvent = procedure(Sender : TObject; Canvas: TCanvas; Rect : TRect) of object;
- const
- {$IFDEF CBUILDER3} {$EXTERNALSYM defMinValue} {$ENDIF}
- defMinValue = 0;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defMaxValue} {$ENDIF}
- defMaxValue = 10;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defValue} {$ENDIF}
- defValue = 0;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defStartAngle} {$ENDIF}
- defStartAngle = 225;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defEndAngle} {$ENDIF}
- defEndAngle = 315;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defWidth} {$ENDIF}
- defWidth = 100;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defHeight} {$ENDIF}
- defHeight = 100;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defAutoSize} {$ENDIF}
- defAutoSize = True;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defHandleColor} {$ENDIF}
- defHandleColor = clMaroon;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defFocusedColor} {$ENDIF}
- defFocusedColor = clRed;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defUpDown} {$ENDIF}
- defUpDown = False;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defScrollSize} {$ENDIF}
- defScrollSize = 160;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defLineStep} {$ENDIF}
- defLineStep = 1;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defPageStep} {$ENDIF}
- defPageStep = 2;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defFocusAction} {$ENDIF}
- defFocusAction = faAll;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defHandleStyle} {$ENDIF}
- defHandleStyle = hsEllipse;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defRadius} {$ENDIF}
- defRadius = 0;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defHandleSize} {$ENDIF}
- defHandleSize = 4;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defHandleMargin} {$ENDIF}
- defHandleMargin = 4;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defFrameSpace} {$ENDIF}
- defFrameSpace = 4;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defScaleMargin} {$ENDIF}
- defScaleMargin = 3;
- {$IFDEF CBUILDER3} {$EXTERNALSYM defTransparent} {$ENDIF}
- defTransparent = True;
- type
- {-- TMMCustomWheel ---------------------------------------------------}
- TMMCustomWheel = class(TMMCustomControl)
- private
- FAutoSize : Boolean;
- FBackBmp : TBitmap;
- FStretched : TBitmap;
- FMinValue : Integer;
- FMaxValue : Integer;
- FValue : Integer;
- FStartAngle : Integer;
- FEndAngle : Integer;
- FHandleColor : TColor;
- FFocusedColor : TColor;
- FUpDown : Boolean;
- FScrollSize : Integer;
- FLineStep : Integer;
- FPageStep : Integer;
- FFocusAction : TMMFocusAction;
- FScale : TMMScale;
- FRadius : Integer;
- FHandleStyle : TMMHandleStyle;
- FHandleSize : Integer;
- FFrameSpace : Integer;
- FScaleMargin : Integer;
- FHandleMargin : Integer;
- FTransparent : Boolean;
- FOnChange : TNotifyEvent;
- FOnDrawHandle : TMMDrawHandleEvent;
- FOnPaint : TMMPaintEvent;
- FAngle : Integer;
- FDragging : Boolean;
- FStartY : Integer;
- FStartValue : Integer;
- procedure SetAutoSize(Value: Boolean);
- procedure SetBackBmp(Value: TBitmap);
- procedure SetMinValue(Value: Integer);
- procedure SetMaxValue(Value: Integer);
- procedure SetValue(aValue: Integer);
- procedure SetStartAngle(Value: Integer);
- procedure SetEndAngle(Value: Integer);
- procedure SetHandleColor(Value: TColor);
- procedure SetFocusedColor(Value: TColor);
- procedure SetFocusAction(Value: TMMFocusAction);
- procedure SetScrollParam(Index: Integer; Value : Integer);
- procedure SetScale(Value: TMMScale);
- procedure SetRadius(Value: Integer);
- function GetRadius: Integer;
- procedure SetHandleStyle(Value: TMMHandleStyle);
- procedure SetHandleSize(Value: Integer);
- procedure SetHandleMargin(Value: Integer);
- procedure SetFrameSpace(Value: Integer);
- procedure SetScaleMargin(Value: Integer);
- procedure SetTransparent(Value: Boolean);
- function GetStretched: TBitmap;
- procedure InitStretched;
- procedure DoneStretched;
- procedure CMColorChanged(var Msg); message CM_COLORCHANGED;
- procedure WMSetFocus(var Msg); message WM_SETFOCUS;
- procedure WMKillFocus(var Msg); message WM_KILLFOCUS;
- procedure ScaleChanged(Sender : TObject);
- protected
- procedure UpdateControl;
- procedure Change; virtual;
- procedure DoChange; dynamic;
- procedure Paint; override;
- procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
- procedure RecalcAngle;
- procedure DrawHandle(Angle : Integer); virtual;
- procedure DoDrawHandle(Rect : TRect; Origin : TPoint; Focused : Boolean); dynamic;
- procedure Loaded; override;
- procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
- procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
- procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
- procedure KeyDown(var Key: Word; Shift: TShiftState); override;
- procedure Rotate(X,Y : Integer);
- procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
- procedure DoAutoSize;
- function ScaleSpace: Integer;
- procedure Changed; override;
- procedure CalcSize(var W, H : Integer);
- property Stretched: TBitmap read GetStretched;
- public
- constructor Create(AOwner : TComponent); override;
- destructor Destroy; override;
- protected
- property TabStop default True;
- property AutoSize : Boolean read FAutoSize write SetAutoSize;
- property BackBmp : TBitmap read FBackBmp write SetBackBmp;
- property MinValue : Integer read FMinValue write SetMinValue default defMinValue;
- property MaxValue : Integer read FMaxValue write SetMaxValue default defMaxValue;
- property Value : Integer read FValue write SetValue default defValue;
- property StartAngle : Integer read FStartAngle write SetStartAngle default defStartAngle;
- property EndAngle : Integer read FEndAngle write SetEndAngle default defEndAngle;
- property HandleColor : TColor read FHandleColor write SetHandleColor default defHandleColor;
- property FocusedColor: TColor read FFocusedColor write SetFocusedColor default defFocusedColor;
- property UpDown : Boolean read FUpDown write FUpDown default defUpDown;
- property ScrollSize : Integer index 0 read FScrollSize write SetScrollParam default defScrollSize;
- property LineStep : Integer index 1 read FLineStep write SetScrollParam default defLineStep;
- property PageStep : Integer index 2 read FPageStep write SetScrollParam default defPageStep;
- property FocusAction : TMMFocusAction read FFocusAction write SetFocusAction default defFocusAction;
- property Scale : TMMScale read FScale write SetScale;
- property Radius : Integer read GetRadius write SetRadius default defRadius;
- property HandleStyle : TMMHandleStyle read FHandleStyle write SetHandleStyle default defHandleStyle;
- property HandleSize : Integer read FHandleSize write SetHandleSize default defHandleSize;
- property HandleMargin: Integer read FHandleMargin write SetHandleMargin default defHandleMargin;
- property FrameSpace : Integer read FFrameSpace write SetFrameSpace default defFrameSpace;
- property ScaleMargin : Integer read FScaleMargin write SetScaleMargin default defScaleMargin;
- property Transparent : Boolean read FTransparent write SetTransparent default defTransparent;
- property OnChange : TNotifyEvent read FOnChange write FOnChange;
- property OnDrawHandle: TMMDrawHandleEvent read FOnDrawHandle write FOnDrawHandle;
- property OnPaint : TMMPaintEvent read FOnPaint write FOnPaint;
- end;
- {-- TMMWheel ---------------------------------------------------------}
- TMMWheel = class(TMMCustomWheel)
- published
- property OnEnter;
- property OnExit;
- property OnKeyDown;
- property OnKeyPress;
- property OnKeyUp;
- property OnChange;
- property OnDrawHandle;
- property OnPaint;
- property Bevel;
- property Visible;
- property Color;
- property Enabled;
- property ParentShowHint;
- property PopupMenu;
- property ShowHint;
- property TabStop;
- property TabOrder;
- property Width;
- property Height;
- property AutoSize;
- property BackBmp;
- property MinValue;
- property MaxValue;
- property Value;
- property StartAngle;
- property EndAngle;
- property HandleColor;
- property FocusedColor;
- property UpDown;
- property ScrollSize;
- property LineStep;
- property PageStep;
- property FocusAction;
- property Scale;
- property Radius;
- property HandleStyle;
- property HandleSize;
- property HandleMargin;
- property FrameSpace;
- property ScaleMargin;
- property Transparent;
- end;
- {=========================================================================}
- implementation
- {$IFDEF WIN32}
- {$R MMWHEEL.D32}
- {$ELSE}
- {$R MMWHEEL.D16}
- {$ENDIF}
- uses
- MMMath,
- MMUtils;
- {== TMMCustomWheel ======================================================}
- constructor TMMCustomWheel.Create(AOwner : TComponent);
- begin
- inherited Create(AOwner);
- ControlStyle := ControlStyle -
- [csAcceptsControls,csFramed,csSetCaption] +
- [csCaptureMouse,csOpaque];
- Width := defWidth;
- Height := defHeight;
- FScale := TMMScale.Create;
- FScale.OnChange := ScaleChanged;
- FBackBmp := TBitmap.Create;
- FBackBmp.Width := defWidth;
- FBackBmp.Height := defHeight;
- BackBmp := nil; { set default bitmap }
- FAutoSize := defAutoSize;
- FMinValue := defMinValue;
- FMaxValue := defMaxValue;
- FValue := defValue;
- FStartAngle := defStartAngle;
- FEndAngle := defEndAngle;
- FHandleColor := defHandleColor;
- FUpDown := defUpDown;
- FScrollSize := defScrollSize;
- FLineStep := defLineStep;
- FPageStep := defPageStep;
- FFocusAction := defFocusAction;
- FFocusedColor := defFocusedColor;
- FHandleStyle := defHandleStyle;
- FHandleSize := defHandleSize;
- FHandleMargin := defHandleMargin;
- FFrameSpace := defFrameSpace;
- FScaleMargin := defScaleMargin;
- FTransparent := defTransparent;
- Bevel.BevelOuter:= bvNone;
- TabStop := True;
- RecalcAngle;
- ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
- if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- destructor TMMCustomWheel.Destroy;
- begin
- DoneStretched;
- FBackBmp.Free;
- FScale.Free;
- inherited Destroy;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetAutoSize(Value : Boolean);
- begin
- if FAutoSize <> Value then
- begin
- FAutoSize := Value;
- if FAutoSize then
- DoAutoSize;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetBackBmp(Value : TBitmap);
- begin
- if (Value <> nil) then
- FBackBmp.Assign(Value)
- else
- FBackBmp.Handle := LoadBitmap(HInstance, 'BM_WHEEL');
- DoneStretched;
- if FAutoSize then
- DoAutoSize;
- Repaint;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetMinValue(Value : Integer);
- begin
- if Value <> FMinValue then
- begin
- FMinValue := Value;
- UpdateControl;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetMaxValue(Value : Integer);
- begin
- if Value <> FMaxValue then
- begin
- FMaxValue := Value;
- UpdateControl;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetValue(aValue : Integer);
- begin
- aValue := MinMax(aValue, FMinValue, FMaxValue);
- if FValue <> aValue then
- begin
- FValue := aValue;
- UpdateControl;
- Change;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetStartAngle(Value : Integer);
- begin
- Value := MinMax(Value, 0, 360);
- if Value <> FStartAngle then
- begin
- FStartAngle := Value;
- UpdateControl;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetEndAngle(Value : Integer);
- begin
- Value := MinMax(Value, 0, 360);
- if Value <> FEndAngle then
- begin
- FEndAngle := Value;
- UpdateControl;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetHandleColor(Value : TColor);
- begin
- if Value <> FHandleColor then
- begin
- FHandleColor := Value;
- UpdateControl;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetTransparent(Value : Boolean);
- begin
- if Value <> FTransparent then
- begin
- FTransparent := Value;
- Invalidate;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetScrollParam(Index : Integer; Value : Integer);
- begin
- if Value <= 0 then
- { TODO: Should be resource id }
- raise EMMWheelError.Create('This parameter should be greater then 0');
- case Index of
- 0 : FScrollSize := Value;
- 1 : FLineStep := Value;
- 2 : FPageStep := Value;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetFocusedColor(Value : TColor);
- begin
- if Value <> FFocusedColor then
- begin
- FFocusedColor := Value;
- UpdateControl;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetFocusAction(Value : TMMFocusAction);
- begin
- if Value <> FFocusAction then
- begin
- FFocusAction := Value;
- UpdateControl;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetScale(Value: TMMScale);
- begin
- FScale.Assign(Value);
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetRadius(Value : Integer);
- begin
- Value := MinMax(Value,0,MaxInt);
- if Value <> FRadius then
- begin
- FRadius := Value;
- UpdateControl;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- function TMMCustomWheel.GetRadius : Integer;
- begin
- if FRadius = 0 then
- Result := Min(Width,Height) div 2 - HandleMargin - BevelExtend - FrameSpace - ScaleSpace
- else
- Result := FRadius;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetHandleStyle(Value : TMMHandleStyle);
- begin
- if FHandleStyle <> Value then
- begin
- FHandleStyle := Value;
- UpdateControl;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetHandleSize(Value : Integer);
- begin
- Value := MinMax(Value, 2, MaxInt);
- if FHandleSize <> Value then
- begin
- FHandleSize := Value;
- UpdateControl;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetHandleMargin(Value : Integer);
- begin
- Value := MinMax(Value, 0, MaxInt);
- if FHandleMargin <> Value then
- begin
- FHandleMargin := Value;
- UpdateControl;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetFrameSpace(Value : Integer);
- begin
- Value := MinMax(Value,0,MaxInt);
- if FFrameSpace <> Value then
- begin
- FFrameSpace := Value;
- DoneStretched;
- if AutoSize then
- DoAutoSize;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetScaleMargin(Value : Integer);
- begin
- Value := MinMax(Value,0,MaxInt);
- if FScaleMargin <> Value then
- begin
- FScaleMargin := Value;
- DoneStretched;
- if AutoSize then
- DoAutoSize;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.ScaleChanged(Sender : TObject);
- begin
- DoneStretched;
- if AutoSize then
- DoAutoSize;
- UpdateControl;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.InitStretched;
- var
- Temp : TBitmap;
- SWidth : Integer;
- SHeight: Integer;
- BWidth : Integer;
- BHeight: Integer;
- R : TRect;
- SRect : TRect;
- begin
- SWidth := Width - BevelExtend * 2;
- SHeight := Height - BevelExtend * 2;
- if SWidth < 0 then
- SWidth := 0;
- if SHeight < 0 then
- SHeight := 0;
- FStretched := TBitmap.Create;
- FStretched.Width := SWidth;
- FStretched.Height := SHeight;
- if (SWidth = 0) or (SHeight = 0) then Exit;
- SRect := Bounds(0,0,SWidth,SHeight);
- FStretched.Canvas.Font:= Font;
- FScale.Canvas := FStretched.Canvas;
- Temp := TBitmap.Create;
- try
- FStretched.Canvas.Brush.Color := Color;
- FStretched.Canvas.FillRect(SRect);
- R := SRect;
- InflateRect(R,-(FrameSpace+ScaleSpace),-(FrameSpace+ScaleSpace));
- BWidth := R.Right - R.Left;
- BHeight := R.Bottom - R.Top;
- if (BWidth > 0) and (BHeight > 0) then
- begin
- Temp.Width := BWidth;
- Temp.Height := BHeight;
- Temp.Canvas.CopyRect(Bounds(0, 0, BWidth, BHeight),
- FBackBmp.Canvas,
- Bounds(0, 0, FBackBmp.Width, FBackBmp.Height));
- if Transparent then
- FStretched.Canvas.BrushCopy(R, Temp,
- Bounds(0, 0, BWidth, BHeight),
- Temp.TransparentColor)
- else
- FStretched.Canvas.CopyRect(R, Temp.Canvas,
- Bounds(0, 0, BWidth, BHeight));
- end;
- finally
- Temp.Free;
- end;
- if FScale.Visible then
- with FScale do
- begin
- MinValue := Self.MinValue;
- MaxValue := Self.MaxValue;
- StartAngle := Self.StartAngle;
- EndAngle := Self.EndAngle;
- R := SRect;
- InflateRect(R,-(FrameSpace),-(FrameSpace));
- DrawElliptic(FStretched.Canvas, R);
- end;
- if ((FocusAction = faFrameRect) or (FocusAction = faAll)) then
- if Focused then
- begin
- R := SRect;
- InflateRect(R,-(FrameSpace-2),-(FrameSpace-2));
- FStretched.Canvas.DrawFocusRect(R);
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.DoneStretched;
- begin
- FStretched.Free;
- FStretched := nil;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.CalcSize(var W, H : Integer);
- var
- Space : Integer;
- begin
- Space := BevelExtend + FrameSpace + ScaleSpace;
- W := FBackBmp.Width + 2*Space;
- H := FBackBmp.Height + 2*Space;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.DoAutoSize;
- var
- W, H: Integer;
- begin
- if csLoading in ComponentState then Exit;
- CalcSize(W,H);
- SetBounds(Left, Top, W, H);
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- function TMMCustomWheel.ScaleSpace : Integer;
- begin
- if Scale.Visible then
- Result := Scale.ScaleHeight + ScaleMargin
- else
- Result := 0;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.UpdateControl;
- begin
- if not (csLoading in ComponentState) then
- begin
- RecalcAngle;
- Invalidate;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.Change;
- begin
- DoChange;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.DoChange;
- begin
- if (csLoading in ComponentState) or
- (csReading in ComponentState) then exit;
- if Assigned(FOnChange) then FOnChange(Self);
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.RecalcAngle;
- var
- dVal : Extended;
- dAng : Extended;
- begin
- if FMinValue >= FMaxValue then
- dVal := 0
- else
- dVal := (FValue - FMinValue) / (FMaxValue - FMinValue);
- if FStartAngle > FEndAngle then
- dAng := 360
- else
- dAng := FStartAngle + (360 - FEndAngle);
- FAngle := Round(FStartAngle - dVal * dAng);
- if FAngle < 0 then
- FAngle := FAngle + 360;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.Paint;
- begin
- with Canvas do
- begin
- { Do not use inherited Paint because we don't need to clear space }
- { before blitting }
- if assigned(FOnPaint) then
- FOnPaint(Self,Canvas,ClientRect)
- else
- begin
- Bevel.PaintBevel(Canvas,ClientRect,True);
- Draw(BevelExtend, BevelExtend, Stretched);
- end;
- DrawHandle(FAngle);
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.DrawHandle(Angle : Integer);
- var
- X, Y: Integer;
- HS : Integer;
- begin
- X := (Width div 2) + Round(Radius * cos(Angle / 180 * Pi));
- Y := (Height div 2) - Round(Radius * sin(Angle / 180 * Pi));
- with Canvas do
- begin
- if Focused and ((FocusAction = faHandleColor) or (FocusAction = faAll)) then
- Brush.Color := FocusedColor
- else
- Brush.Color := HandleColor;
- Brush.Style := bsSolid;
- Pen.Style := psSolid;
- Pen.Color := Brush.Color;
- if HandleStyle = hsOwnerDraw then
- DoDrawHandle(ClientRect, Point(X,Y), Focused)
- else
- begin
- HS := HandleSize div 2;
- Ellipse(X-HS,Y-HS,X+HS,Y+HS);
- end;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.DoDrawHandle(Rect : TRect; Origin : TPoint; Focused : Boolean);
- begin
- if Assigned(FOnDrawHandle) then
- FOnDrawHandle(Self,Canvas,Rect,Origin,Focused);
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.Loaded;
- begin
- inherited Loaded;
- if AutoSize then
- DoAutoSize;
- UpdateControl;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- function TMMCustomWheel.GetStretched: TBitmap;
- begin
- if FStretched = nil then
- InitStretched;
- Result := FStretched;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
- begin
- if AutoSize then
- CalcSize(AWidth,AHeight);
- inherited SetBounds(ALeft,ATop,AWidth,AHeight);
- DoneStretched;
- Invalidate;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.CMColorChanged(var Msg);
- begin
- DoneStretched;
- inherited;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- begin
- if (Button = mbLeft) and not FDragging then
- begin
- FDragging := True;
- SetFocus;
- if not FUpDown then
- Rotate(X,Y)
- else
- begin
- FStartY := Y;
- FStartValue := Value;
- end;
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.MouseMove(Shift: TShiftState; X, Y: Integer);
- begin
- if (ssLeft in Shift) and FDragging then
- if not FUpDown then
- Rotate(X,Y)
- else
- Value := FStartValue + Round((FStartY - Y) * (MaxValue - MinValue) / ScrollSize);
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- begin
- if (Button = mbLeft) and FDragging then
- begin
- FDragging := False;
- if not FUpDown then
- Rotate(X,Y);
- end;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.KeyDown(var Key: Word; Shift: TShiftState);
- begin
- inherited KeyDown(Key,Shift);
- case Key of
- VK_DOWN, VK_LEFT: Value := Value - FLineStep;
- VK_UP, VK_RIGHT : Value := Value + FLineStep;
- VK_NEXT : Value := Value - FPageStep;
- VK_PRIOR : Value := Value + FPageStep;
- VK_HOME : Value := FMaxValue;
- VK_END : Value := FMinValue;
- else
- Exit;
- end;
- Key := 0;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.Rotate(X, Y : Integer);
- var
- dX, dY : Extended;
- dAngle : Extended;
- Ang : Extended;
- S, E : Extended;
- begin
- dX := X - (Width div 2);
- dY := (Height div 2) - Y;
- if (dX = 0) and (dY = 0) then Exit;
- Ang := ArcTan2(dY, dX) / Pi * 180;
- if Ang < 0 then
- Ang := 360 + Ang;
- S := FStartAngle;
- if FStartAngle > FEndAngle then
- E := S
- else
- E := FEndAngle;
- dAngle := S + (360 - E);
- if (Ang > S) and (Ang < E) then
- if (Ang - S) < ((E - S) / 2) then
- Ang := S
- else
- Ang := E;
- Ang := FStartAngle - Ang;
- if Ang < 0 then
- Ang := 360 + Ang;
- if (MaxValue < MinValue) or (dAngle = 0) then
- Value := MinValue
- else
- Value := Round((MaxValue - MinValue) * (Ang / dAngle)) + MinValue;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.WMGetDlgCode(var Message: TWMGetDlgCode);
- begin
- Message.Result := DLGC_WANTARROWS;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.WMSetFocus(var Msg);
- begin
- DoneStretched;
- UpdateControl;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.WMKillFocus(var Msg);
- begin
- DoneStretched;
- UpdateControl;
- end;
- {-- TMMCustomWheel ------------------------------------------------------}
- procedure TMMCustomWheel.Changed;
- begin
- { Looks like bevel has changed }
- DoneStretched;
- if AutoSize then
- DoAutoSize;
- UpdateControl;
- end;
- end.