📄 histogrambox.pas
字号:
(*
Copyright (c) 1998-2007 by HiComponents. All rights reserved.
This software comes without express or implied warranty.
In no case shall the author be liable for any damage or unwanted behavior of any
computer hardware and/or software.
HiComponents grants you the right to include the compiled component
in your application, whether COMMERCIAL, SHAREWARE, or FREEWARE,
BUT YOU MAY NOT DISTRIBUTE THIS SOURCE CODE OR ITS COMPILED .DCU IN ANY FORM.
ImageEn, IEvolution and ImageEn ActiveX may not be included in any commercial,
shareware or freeware libraries or components.
email: support@hicomponents.com
http://www.hicomponents.com
*)
unit histogrambox;
{$R-}
{$Q-}
{$I ie.inc}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, ImageEnProc, hyiedefs;
type
{!!
<FS>THistogramKind
<FM>Declaration<FC>
}
THistogramKind = set of (hkRed, hkGreen, hkBlue, hkGray);
{!!}
{!!
<FS>THistogramLabels
<FM>Declaration<FC>
}
THistogramLabels = set of (hlVertical, hlHorizontal);
{!!}
{!!
<FS>THistogramStyle
<FM>Declaration<FC>
}
THistogramStyle = (hsBars, hsLines);
{!!}
{!!
<FS>THistogramBox
<FM>Description<FN>
THistogramBox can be attached to a <A TImageEnProc> component from which it gets information to compute and display the color channels histogram. THistogramBox is readonly.
<FM>Properties<FN>
<A THistogramBox.AttachedImageEnProc>
<A THistogramBox.Background>
<A THistogramBox.CompBar>
<A THistogramBox.GrayColor>
<A THistogramBox.HistogramKind>
<A THistogramBox.HistogramStyle>
<A THistogramBox.HistogramXPos>
<A THistogramBox.Labels>
<FM>Methods<FN>
<FM>Events<FN>
!!}
THistogramBox = class(TCustomControl)
private
{ Private declarations }
Bitmap: TBitMap;
fBackground: TColor;
fAIEP: TImageEnProc; // abb. fAttachedImageEnProc (!)
fHistKind: THistogramKind;
fLabels: THistogramLabels;
fCompBar: boolean;
fHistogramStyle: THistogramStyle;
fHistogramXPos: integer;
fGrayColor: TColor;
procedure SetBackground(bk: TColor);
procedure SetLabels(v: THistogramLabels);
procedure SetCompBar(v: boolean);
procedure SetHistogramStyle(v: THistogramStyle);
procedure SetHistogramKind(v: THistogramKind);
procedure SetAIEP(v: TImageEnProc);
function GetHistogramKind: THistogramKind;
function GetLabels: THistogramLabels;
protected
{ Protected declarations }
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure WMEraseBkgnd(var Message: TMessage); message WM_ERASEBKGND;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
{ Public declarations }
procedure Paint; override;
constructor Create(Owner: TComponent); override;
destructor Destroy; override;
procedure Update; override;
{!!
<FS>THistogramBox.HistogramXPos
<FM>Declaration<FC>
property HistogramXPos: integer;
<FM>Description<FN>
HistogramXPos is the left X coordinate where the histogram will be painted (with the component).
Read-only
!!}
property HistogramXPos: integer read fHistogramXPos;
published
{ Published declarations }
property AttachedImageEnProc: TImageEnProc read fAIEP write SetAIEP;
property Background: TColor read fBackground write SetBackground default clWhite;
property HistogramKind: THistogramKind read GetHistogramKind write SetHistogramKind default [hkGray];
property Labels: THistogramLabels read GetLabels write SetLabels default [hlVertical, hlHorizontal];
property CompBar: boolean read fCompBar write SetCompBar default true;
property HistogramStyle: THistogramStyle read fHistogramStyle write SetHistogramStyle default hsBars;
{!!
<FS>THistogramBox.GrayColor
<FM>Declaration<FC>
property GrayColor:Tcolor;
<FM>Description<FN>
GrayColor is the color assigned to the gray histogram.
!!}
property GrayColor: TColor read fGrayColor write fGrayColor default clBlack;
property Align;
property DragCursor;
property DragMode;
property Enabled;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Visible;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
property Font;
property Width default 256;
property Height default 105;
end;
implementation
uses hyieutils;
{$R-}
/////////////////////////////////////////////////////////////////////////////////////
constructor THistogramBox.Create(Owner: TComponent);
begin
inherited Create(Owner);
//controlstyle:=controlstyle+[csOpaque];
ControlStyle := ControlStyle + [csOpaque, csAcceptsControls];
fBackground := clWhite;
fHistKind := [hkGray];
fLabels := [hlVertical, hlHorizontal];
fCompBar := true;
fHistogramStyle := hsBars;
fGrayColor := clBlack;
Height := 105;
Width := 256;
bitmap := TBitmap.create;
bitmap.PixelFormat := pf24bit;
bitmap.Width := width;
bitmap.Height := height;
fAIEP := nil;
Update;
end;
/////////////////////////////////////////////////////////////////////////////////////
destructor THistogramBox.Destroy;
begin
FreeAndNil(bitmap);
inherited;
end;
procedure THistogramBox.Paint;
begin
canvas.Draw(0, 0, bitmap);
end;
procedure THistogramBox.WMEraseBkgnd(var Message: TMessage);
begin
Message.Result := 0;
end;
procedure THistogramBox.WMSize(var Message: TWMSize);
begin
inherited;
bitmap.Width := message.Width;
bitmap.Height := message.Height;
Update;
end;
{!!
<FS>THistogramBox.Background
<FM>Declaration<FC>
property Background: TColor;
<FM>Description<FN>
Background is the background color.
!!}
procedure THistogramBox.SetBackground(bk: TColor);
begin
fBackground := bk;
update;
end;
/////////////////////////////////////////////////////////////////////////////////////
// movimento mouse
procedure THistogramBox.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
inherited;
//
end;
/////////////////////////////////////////////////////////////////////////////////////
// pressione di un bottone del mouse
procedure THistogramBox.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited;
if (Button = mbLeft) then
begin
end;
end;
/////////////////////////////////////////////////////////////////////////////////////
// rilascio mouse
// fMouseSel 0=niente 1=capture su sat/val 2=capture su hue
procedure THistogramBox.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited;
//
end;
/////////////////////////////////////////////////////////////////////////////////////
procedure THistogramBox.SetLabels(v: THistogramLabels);
begin
if v <> fLabels then
begin
fLabels := v;
Update;
end;
end;
{!!
<FS>THistogramBox.CompBar
<FM>Declaration<FC>
property CompBar: boolean;
<FM>Description<FN>
If True, THistogramBox shows a gradient bar at the bottom of the component.
!!}
procedure THistogramBox.SetCompBar(v: boolean);
begin
if v <> fCompBar then
begin
fCompBar := v;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -