📄 mmctrl.pas
字号:
{========================================================================}
{= (c) 1995-98 SwiftSoft Ronald Dittrich =}
{========================================================================}
{= All Rights Reserved =}
{========================================================================}
{= D 01099 Dresden = Fax.: +49(0)351-8037944 =}
{= Loewenstr.7a = info@swiftsoft.de =}
{========================================================================}
{= Actual versions on http://www.swiftsoft.de/index.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: 03.11.98 - 21:39:50 $ =}
{========================================================================}
unit MMCtrl;
{$I COMPILER.INC}
interface
uses
{$IFDEF WIN32}
Windows,
{$ELSE}
WinTypes,
WinProcs,
{$ENDIF}
Forms,
SysUtils,
Messages,
Classes,
Graphics,
Controls,
Dialogs,
ExtCtrls,
Menus,
Buttons,
MMObj,
MMUtils,
MMMath,
MMString,
MMBmpLst,
MMObsrv;
type
TMMOrientation = (orVertical,orHorizontal);
TMMZeroPosition = (zpBottomLeft,zpTopRight);
TMMGetGylphIndex = procedure(Sender: TObject; IsDown: Boolean; var Index: integer) of object;
TMMGetBackGround = procedure(Sender: TObject; Bmp: TBitmap; R: TRect) of object;
{-- TMMBitmapSlider ---------------------------------------------------------}
TMMBitmapSlider = class(TMMCustomBitmapListControl)
private
FAutoSize : Boolean;
FDragging : Boolean;
FHandCursor : Boolean;
FThumbCursor : TCursor;
FThumbWidth, FThumbHeight: Byte;
FMax,FMin,FPosition : Longint;
FLineSize : Integer;
FPageSize : Integer;
FZeroPosition : TMMZeroPosition;
FOrientation : TMMOrientation;
FSaveBitmap : TBitmap;
FDragOffset : integer;
FDragVal : Longint;
FThumbRect : TRect;
FSensitivity : integer;
FLogMode : Boolean;
FNeedTrackEnd : Boolean;
FForceChange : Boolean;
FMargin : integer;
FNumGlyphs : integer;
FNumThumbGlyphs : integer;
FBitmapOK : Boolean;
FBitmapThumbIndex : integer;
FThumbMargin : integer;
FOnChange : TNotifyEvent;
FOnTrack : TNotifyEvent;
FOnTrackEnd : TNotifyEvent;
FOnGetGlyphIndex : TMMGetGylphIndex;
FOnGetThumbGlyphIndex : TMMGetGylphIndex;
FOnGetBackground : TMMGetBackGround;
procedure SetBitmapThumbIndex(aValue: integer);
procedure SetMargin(aValue: integer);
procedure SetThumbMargin(aValue: integer);
procedure UpdateSlider;
procedure SetAutoSize(aValue: Boolean);
procedure SetNumThumbGlyphs(aValue: integer);
procedure SetNumGlyphs(aValue: integer);
procedure SetMax(aValue: Longint);
procedure SetMin(aValue: Longint);
procedure SetOrientation(aValue: TMMOrientation);
procedure SetZeroPosition(aValue: TMMZeroPosition);
procedure SetPosition(aValue: Longint);
function GetPosition: Longint;
function UpdatePosition(aValue: Longint): Boolean;
procedure SetSensitivity(aValue: integer);
procedure SetLogMode(aValue: Boolean);
function NewPosition(WhereX,WhereY: Integer): Longint;
function IsVert: Boolean;
function IsInverted: Boolean;
function GetSrcRect(index: integer): TRect;
function GetThumbSrcRect(index: integer): TRect;
procedure DrawBitmapImage(Canvas: TCanvas; Bitmap: TBitmap; X,Y: integer; Src: TRect);
procedure WhereIsThumb(const ClientRect: TRect; var aRect: TRect);
procedure DrawThumb(Canvas: TCanvas; aRect: TRect);
procedure RedrawThumb;
procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
function GetThumbBitmap: TBitmap;
protected
procedure Change; dynamic;
procedure Track; dynamic;
procedure TrackEnd; dynamic;
procedure Paint; override;
procedure BitmapChanged; override;
function FindTransparentColor: TColor; override;
procedure SetBounds(aLeft, aTop, aWidth, aHeight: integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure SetThumbCursor(AtThumb: Boolean);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure SetMinMax(aMin,aMax: Longint);
function ThumbBitmapValid: Boolean;
property ThumbBitmap: TBitmap read GetThumbBitmap;
published
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnStartDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnTrack: TNotifyEvent read FOnTrack write FOnTrack;
property OnTrackEnd: TNotifyEvent read FOnTrackEnd write FOnTrackEnd;
property OnGetGlyphIndex: TMMGetGylphIndex read FOnGetGlyphIndex write FOnGetGlyphIndex;
property OnGetThumbGlyphIndex: TMMGetGylphIndex read FOnGetThumbGlyphIndex write FOnGetThumbGlyphIndex;
property OnGetBackground: TMMGetBackground read FOnGetBackground write FOnGetBackground;
property Width default 200;
property Height default 40;
property DragCursor;
property Visible;
property Enabled;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TransparentColor;
property TransparentMode;
property BitmapList;
property BitmapIndex;
property BitmapBackIndex;
property BitmapThumbIndex: Integer read FBitmapThumbIndex write SetBitmapThumbIndex default -1;
property Margin: integer read FMargin write SetMargin default 2;
property ThumbMargin: integer read FThumbMargin write SetThumbMargin default 0;
property NumGlyphs: integer read FNumGlyphs write SetNumGlyphs default 1;
property NumThumbGlyphs: integer read FNumThumbGlyphs write SetNumThumbGlyphs default 1;
property AutoSize: Boolean read FAutoSize write SetAutoSize default False;
property HandCursor: Boolean read FHandCursor write FHandCursor default False;
property ThumbCursor: TCursor read FThumbCursor write FThumbCursor default crDefault;
property MinValue: Longint read FMin write SetMin default 0;
property MaxValue: Longint read FMax write SetMax default 10;
property LineSize: Integer read FLineSize write FLineSize default 1;
property PageSize: Integer read FPageSize write FPageSize default 5;
property Orientation: TMMOrientation read FOrientation write SetOrientation default orHorizontal;
property ZeroPosition: TMMZeroPosition read FZeroPosition write SetZeroPosition default zpBottomLeft;
property Position: Longint read GetPosition write SetPosition default 0;
property Logarithmic: Boolean read FLogMode write SetLogMode default False;
property Sensitivity: Integer read FSensitivity write SetSensitivity default -24;
property Transparent;
end;
implementation
{== TMMBitmapSlider ===========================================================}
constructor TMMBitmapSlider.Create(AOwner: TComponent);
begin
FBitmapOK := False;
inherited Create(AOwner);
ControlStyle := ControlStyle - [csOpaque];
FAutoSize := False;
FNumGlyphs := 1;
FNumThumbGlyphs := 1;
FBitmapThumbIndex := -1;
FThumbCursor := crDefault;
FForceChange := False;
FSaveBitmap := TBitmap.Create;
SetBounds(0,0,40,200);
FHandCursor := False;
FMin := 0;
FMax := 10;
FLineSize := 1;
FPageSize := 5;
FOrientation := orHorizontal;
FZeroPosition := zpBottomLeft;
FPosition := 0;
FDragging := False;
FDragOffset := 0;
FDragVal := 0;
FSensitivity := -24;
FLogMode := False;
FNeedTrackEnd := False;
FMargin := 2;
FThumbMargin := 0;
ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
end;
{-- TMMBitmapSlider -----------------------------------------------------}
destructor TMMBitmapSlider.Destroy;
begin
FSaveBitmap.Free;
FSaveBitmap := nil;
inherited Destroy;
end;
{-- TMMBitmapSlider -----------------------------------------------------}
procedure TMMBitmapSlider.BitmapChanged;
begin
UpdateSlider;
end;
{-- TMMBitmapSlider -----------------------------------------------------------}
procedure TMMBitmapSlider.SetBitmapThumbIndex(aValue: integer);
begin
if (FBitmapThumbIndex <> aValue) then
begin
FBitmapThumbIndex := Max(aValue,-1);
BitmapChanged;
end;
end;
{-- TMMBitmapSlider -----------------------------------------------------}
function TMMBitmapSlider.ThumbBitmapValid: Boolean;
begin
Result := assigned(BitmapList) and (FBitmapThumbIndex >= 0) and (FBitmapThumbIndex < BitmapList.Count);
end;
{-- TMMBitmapSlider -----------------------------------------------------}
function TMMBitmapSlider.GetThumbBitmap: TBitmap;
begin
if ThumbBitmapValid then
Result := BitmapList[BitmapThumbIndex]
else
Result := nil;
end;
{-- TMMBitmapSlider -----------------------------------------------------}
procedure TMMBitmapSlider.UpdateSlider;
begin
if ThumbBitmapValid then
begin
FThumbWidth := ThumbBitmap.Width div FNumThumbGlyphs;
FThumbHeight:= ThumbBitmap.Height;
end;
if BitmapValid and AutoSize then
begin
{ adjust sizes }
if (Orientation = orHorizontal) then
SetBounds(Left,Top,Width,Height div FNumGlyphs)
else
SetBounds(Left,Top,Width div FNumGlyphs,Height);
end;
FBitmapOK := False;
Invalidate;
end;
{-- TMMBitmapSlider -----------------------------------------------------}
procedure TMMBitmapSlider.SetAutoSize(aValue: Boolean);
begin
if (aValue <> FAutoSize) then
begin
FAutoSize := aValue;
UpdateSlider;
end;
end;
{-- TMMBitmapSlider -----------------------------------------------------}
procedure TMMBitmapSlider.Change;
begin
if (csLoading in ComponentState) or
(csReading in ComponentState) or
(csDestroying in ComponentState) then exit;
if assigned(FOnChange) then FOnChange(Self);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -