📄 jvimagewindow.pas
字号:
begin
inherited MouseMove(Shift, X, Y);
if FShowFrame and Assigned(FImageList) then
DrawFocusFrame(X, Y);
end;
procedure TJvImageWindow.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
iWidth, iHeight: Integer;
begin
if Assigned(FImageList) then
begin
iWidth := Max(imWidth + FMargin * 2, 1);
iHeight := Max(imHeight + FMargin * 2, 1);
{ get index for X and Y }
X := Trunc(X / iWidth);
Y := Trunc(Y / iHeight);
{ convert to imageindex }
FIndex := X + Y * FColCount;
if FIndex > FImageCount - 1 then
FIndex := FImageCount - 1;
if FIndex < 0 then
FIndex := -1;
end;
if Assigned(OnClick) then
OnClick(Self);
// inherited MouseUp(Button,Shift,X,Y);
end;
{$IFDEF COMPILER6_UP}
procedure TJvImageWindow.SetAutoSize(Value: Boolean);
begin
if FAutoSize <> Value then
begin
FAutoSize := Value;
Changed;
end;
end;
{$ENDIF}
{ draw a ghost frame too }
procedure TJvImageWindow.SetGhost(Value: Boolean);
begin
if FGhost <> Value then
begin
FGhost := Value;
Changed;
end;
end;
procedure TJvImageWindow.ImageListChange(Sender: Tobject);
begin
FImageCount := Min(FImageCount, FImageList.Count);
Changed;
end;
procedure TJvImageWindow.SetImageList(Value: TCustomImageList);
begin
if Images <> nil then
Images.UnRegisterChanges(FImageChangeLink);
FImageList := Value;
if Images <> nil then
FImageList.RegisterChanges(FImageChangeLink);
if Assigned(FImageList) then
begin
imWidth := FImageList.Width;
imHeight := FImageList.Height;
FImageCount := Min(FImageCount, FImageList.Count);
end
else
begin
imWidth := 16;
imHeight := 16;
end;
Changed;
end;
{
procedure TJvImageWindow.WMEraseBkgnd(var M : TWMEraseBkgnd);
begin
M.Result := LRESULT(False);
end;
}
procedure TJvImageWindow.SetBackColor(Value: TColor);
begin
if FBackColor <> Value then
begin
FBackColor := Value;
Invalidate;
end;
end;
procedure TJvImageWindow.SetFrontColor(Value: TColor);
begin
if FFrontColor <> Value then
begin
FFrontColor := Value;
Invalidate;
end;
end;
procedure TJvImageWindow.SetGridColor(Value: TColor);
begin
if FGridColor <> Value then
begin
FGridColor := Value;
Invalidate;
end;
end;
procedure TJvImageWindow.SetMargin(Value: TJvMargin);
begin
if FMargin <> Value then
begin
FMargin := Value;
Invalidate;
end;
end;
procedure TJvImageWindow.SetColCount(Value: TJvPositive);
begin
if FColCount <> Value then
begin
FColCount := Value;
if Assigned(FImageList) and (FColCount > FImageCount) then
FColCount := Max(FImageCount, 1);
Changed;
end;
end;
procedure TJvImageWindow.SetImageCount(Value: Integer);
begin
if FImageCount <> Value then
begin
if Assigned(FImageList) then
FImageCount := Min(Value, FImageList.Count)
else
FImageCount := Value;
Changed;
end;
end;
procedure TJvImageWindow.SetShowFrame(Value: Boolean);
begin
if FShowFrame <> Value then
begin
FShowFrame := Value;
Invalidate;
end;
end;
procedure TJvImageWindow.SetShowGrid(Value: Boolean);
begin
if FShowGrid <> Value then
begin
FShowGrid := Value;
Invalidate;
end;
end;
procedure TJvImageWindow.Changed;
var
tmp, FNewHeight, FNewWidth: Integer;
begin
if FOptimal and Assigned(FImageList) then
begin
if ImageCount < 3 then
ColCount := 1
else
ColCount := Max(Ceil(Sqrt(ImageCount)), 1);
end;
if FAutoSize and Assigned(FImageList) then
begin
FColCount := Max(FColCount, 1);
tmp := FImageCount div FColCount + 1;
FNewHeight := imHeight * tmp + FMargin * tmp * 2 + FMargin * 2 + 1;
FNewWidth := imWidth * FColCount + FMargin * FColCount * 2 + FMargin * 2 + 1;
case Align of
alNone:
begin
Height := FNewHeight;
Width := FNewWidth;
end;
alRight, alLeft:
Width := FNewWidth;
alTop, alBottom:
Height := FNewHeight;
end;
end;
Invalidate;
end;
//=== TJvImageSquare =========================================================
constructor TJvImageSquare.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FHiColor := clActiveCaption;
Color := clWindow;
TmpColor := clWindow;
FBackColor := clWindow;
FIndex := 0;
FDown := False;
FShowClick := False;
Width := 36;
Height := 36;
FBorderStyle := bsSingle;
FImageChangeLink := TChangeLink.Create;
FImageChangeLink.OnChange := ImageListChange;
end;
destructor TJvImageSquare.Destroy;
begin
FImageChangeLink.Free;
inherited Destroy;
end;
procedure TJvImageSquare.ImageListChange(Sender: Tobject);
begin
Repaint;
end;
procedure TJvImageSquare.Notification(AComponent: TComponent; Operation: TOperation);
begin
if (aComponent = FImageList) and (Operation = opRemove) then
FImageList := nil;
end;
procedure TJvImageSquare.PaintFrame;
var
R: TRect;
begin
R := GetClientRect;
if FDown and FShowClick then
begin
Frame3d(Canvas, R, cl3DDkShadow, cl3DDkShadow, 1);
Frame3d(Canvas, R, clBtnHighLight, clBtnHighLight, 1);
Frame3d(Canvas, R, cl3DDkShadow, cl3DDkShadow, 1);
end
else
{$IFDEF JVCLThemesEnabled}
if (FBorderStyle = bsSingle) and ThemeServices.ThemesEnabled then
DrawThemedBorder(Self)
else
{$ENDIF}
if FBorderStyle = bsSingle then
begin
Frame3d(Canvas, R, clBtnFace, clBtnFace, 1);
Frame3d(Canvas, R, clBtnShadow, clBtnHighLight, 1);
Frame3d(Canvas, R, cl3DDkShadow, clBtnFace, 1);
end
else
Frame3d(Canvas, R, FHiColor, FHiColor, 3);
end;
procedure TJvImageSquare.Paint;
var
R: TRect;
dX, dY: Integer;
begin
R := Rect(0, 0, Width, Height);
if FBorderStyle = bsSingle then
begin
PaintFrame;
InflateRect(R, -3, -3);
end;
{ fill in the rest }
with Canvas do
begin
Brush.Color := TmpColor;
Brush.Style := bsSolid;
FillRect(R);
end;
if Assigned(FImageList) then
begin
{ draw in middle }
dX := (Width - FImageList.Width) div 2;
dY := (Height - FImageList.Height) div 2;
ImageList_DrawEx(Fimagelist.Handle, FIndex, Canvas.Handle, dx, dy, 0, 0, CLR_NONE, CLR_NONE, ILD_TRANSPARENT);
// FImageList.Draw(Canvas,dX,dY,FIndex);
end;
end;
procedure TJvImageSquare.SetHiColor(Value: TColor);
begin
if FHiColor <> Value then
begin
FHiColor := Value;
Repaint;
end;
end;
procedure TJvImageSquare.SetBorderStyle(Value: TBorderStyle);
begin
if FBorderStyle <> Value then
begin
FBorderStyle := Value;
Repaint;
end;
end;
procedure TJvImageSquare.SetIndex(Value: Integer);
begin
if FIndex <> Value then
begin
FIndex := Value;
Repaint;
end;
end;
procedure TJvImageSquare.SetImageList(Value: TCustomImageList);
begin
if Images <> nil then
Images.UnRegisterChanges(FImageChangeLink);
FImageList := Value;
if Images <> nil then
FImageList.RegisterChanges(FImageChangeLink);
Repaint;
end;
procedure TJvImageSquare.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited MouseUp(Button, Shift, X, y);
FDown := False;
if FShowClick then
PaintFrame;
end;
procedure TJvImageSquare.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited MouseDown(Button, Shift, X, Y);
FDown := True;
if FShowClick then
PaintFrame;
end;
procedure TJvImageSquare.CMMouseEnter(var Msg: TMessage);
begin
inherited;
if (csDesigning in ComponentState) then Exit;
if Assigned(FOnEnter) then
FOnEnter(Self);
if ColorToRGB(TmpColor) <> ColorToRGB(FHiColor) then
begin
TmpColor := FHiColor;
Repaint;
end;
end;
procedure TJvImageSquare.CMMouseLeave(var Msg: TMessage);
begin
inherited;
if (csDesigning in ComponentState) then Exit;
FDown := False;
if Assigned(FOnExit) then
FOnExit(Self);
if ColorToRGB(TmpColor) <> ColorToRGB(FBackColor) then
begin
TmpColor := FBackColor;
Repaint;
end;
end;
procedure TJvImageSquare.CMColorChanged(var Message: TMessage);
begin
inherited;
FBackColor := Color;
TmpColor := Color;
Repaint;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -