📄 jvgbutton.pas
字号:
GetBitmap_(Disabled, FGlyphDisabled); //...optional bitmap
if Mask <> -1 then
GetBitmap_(Mask, FGlyphMask); //...optional bitmap
FNumGlyphs := Count;
FBitmapsCreated := not (FGlyphInactive.Empty or FGlyphPushed.Empty);
end;
end
else
CreateBitmaps;
FBitmapsCreated := True;
case FDrawMode of
dmAutoShadow:
if boDrawPushedAsFlat in FOptions then
begin
MShift.X := 1;
MShift.Y := 1;
end
else
begin
MShift.X := FShadowDepth - 1;
MShift.Y := FShadowDepth - 1;
end;
dmAutoCtrl3D:
begin
MShift.X := 2;
MShift.Y := 2;
end;
dmAutoFlat:
begin
MShift.X := 1;
MShift.Y := 1;
end;
else
begin
MShift.X := FShiftMaskWhenPushed.X;
MShift.Y := FShiftMaskWhenPushed.Y;
end;
end;
Width := FGlyphInactive.Width;
Height := FGlyphInactive.Height;
end;
end;
procedure TJvgButton.CreateBitmaps; //...based on Inactive Glyph
var
MonoBMP, OldMonoBMP: HBITMAP;
MonoDC: HDC;
I: Word;
procedure RemakeTmpBMP;
begin
SetBkColor(TmpBMP.Canvas.Handle, ColorToRGB(FTransparentColor));
BitBlt(TmpBMP.Canvas.Handle, 0, 0, TmpBMP.Width, TmpBMP.Height, MonoDC, 0,
0, SRCCOPY);
end;
begin
with FGlyphs, FGlyphsList, FGlyphsIndexes do
begin
FInactive := 0;
FPushed := -1;
FActive := -1;
FDisabled := -1;
FMask := -1;
GetBitmap_(Inactive, TmpBMP);
MonoDC := CreateCompatibleDC(TmpBMP.Canvas.Handle);
MonoBMP := CreateBitmap(TmpBMP.Width, TmpBMP.Height, 1, 1, nil);
OldMonoBMP := SelectObject(MonoDC, MonoBMP);
// SetMapMode( MonoDC, GetMapMode(TmpBMP.Canvas.Handle) );
SetBkColor(TmpBMP.Canvas.Handle, ColorToRGB(FTransparentColor));
BitBlt(MonoDC, 0, 0, TmpBMP.Width, TmpBMP.Height,
TmpBMP.Canvas.Handle, 0, 0, SRCCOPY);
//SetBkColor(TmpBMP.Canvas.Handle, OldBkColor);
try
if FDrawMode = dmAutoShadow then
begin
with FGlyphInactive do
begin
Width := TmpBMP.Width + FShadowDepth;
Height := TmpBMP.Height + FShadowDepth;
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := FTransparentColor;
Canvas.FillRect(Rect(0, 0, Width, Height));
end;
with FGlyphPushed do
begin
Width := TmpBMP.Width + FShadowDepth;
Height := TmpBMP.Height + FShadowDepth;
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := FTransparentColor;
Canvas.FillRect(Rect(0, 0, Width, Height));
end;
BitBlt(FGlyphPushed.Canvas.Handle, FShadowDepth, FShadowDepth,
TmpBMP.Width, TmpBMP.Height, TmpBMP.Canvas.Handle, 0, 0,
SRCCOPY);
RemakeTmpBMP;
ChangeBitmapColor(TmpBMP, clBlack, FColorShadow);
CreateBitmapExt(FGlyphInactive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
FShadowDepth, FShadowDepth, fwoNone, fdsDefault, True,
FTransparentColor, FDisabledMaskColor);
Exit;
end;
if FDrawMode = dmAutoCtrl3D then
I := 3
else
I := 3;
with FGlyphInactive do
begin
Width := TmpBMP.Width + I;
Height := TmpBMP.Height + I;
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := FTransparentColor;
Canvas.FillRect(Rect(0, 0, Width, Height));
end;
if not (boDrawPushedAsFlat in FOptions) then
with FGlyphPushed do
begin
Width := TmpBMP.Width + I;
Height := TmpBMP.Height + I;
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := FTransparentColor;
Canvas.FillRect(Rect(0, 0, Width, Height));
end;
with FGlyphActive do
begin
Width := TmpBMP.Width + I;
Height := TmpBMP.Height + I;
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := FTransparentColor;
Canvas.FillRect(Rect(0, 0, Width, Height));
end;
if FDrawMode = dmAutoCtrl3D then //...add 3d border to inactive
begin
RemakeTmpBMP;
if clBlack <> FColorDarkShadow then
ChangeBitmapColor(TmpBMP, clBlack, FColorDarkShadow);
if boShadowSurround in FOptions then
begin
CreateBitmapExt(FGlyphInactive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
0, 3, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
CreateBitmapExt(FGlyphInactive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
3, 0, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
end;
CreateBitmapExt(FGlyphInactive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
3, 3, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
RemakeTmpBMP;
ChangeBitmapColor(TmpBMP, clBlack, FColorHighlight);
CreateBitmapExt(FGlyphInactive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
0, 0, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
if boShadowSurround in FOptions then
begin
CreateBitmapExt(FGlyphInactive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
2, 0, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
CreateBitmapExt(FGlyphInactive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
0, 2, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
end;
RemakeTmpBMP;
ChangeBitmapColor(TmpBMP, clBlack, FColorShadow);
if boShadowSurround in FOptions then
begin
CreateBitmapExt(FGlyphInactive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
1, 2, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
CreateBitmapExt(FGlyphInactive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
2, 1, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
end;
CreateBitmapExt(FGlyphInactive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
2, 2, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
if boDrawPushedAsFlat in FOptions then
Exit;
RemakeTmpBMP;
ChangeBitmapColor(TmpBMP, clBlack, FColorHighlight);
if boShadowSurround in FOptions then
begin
CreateBitmapExt(FGlyphPushed.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
0, 3, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
CreateBitmapExt(FGlyphPushed.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
3, 0, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
end;
CreateBitmapExt(FGlyphPushed.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
3, 3, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
RemakeTmpBMP;
if clBlack <> FColorDarkShadow then
ChangeBitmapColor(TmpBMP, clBlack, FColorDarkShadow);
CreateBitmapExt(FGlyphPushed.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
0, 0, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
if boShadowSurround in FOptions then
begin
CreateBitmapExt(FGlyphPushed.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
2, 0, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
CreateBitmapExt(FGlyphPushed.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
0, 2, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
end;
RemakeTmpBMP;
ChangeBitmapColor(TmpBMP, clBlack, FColorShadow);
if boShadowSurround in FOptions then
begin
CreateBitmapExt(FGlyphPushed.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
1, 2, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
CreateBitmapExt(FGlyphPushed.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
2, 1, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
end;
CreateBitmapExt(FGlyphPushed.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
1, 1, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
RemakeTmpBMP;
Exit;
end;
if FDrawMode = dmAutoFlat then
begin
CreateBitmapExt(FGlyphInactive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
0, 0, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
RemakeTmpBMP;
ChangeBitmapColor(TmpBMP, clBlack, FColorShadow);
if boShadowSurround in FOptions then
begin
CreateBitmapExt(FGlyphActive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
0, 2, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
CreateBitmapExt(FGlyphActive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
2, 0, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
end;
CreateBitmapExt(FGlyphActive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
2, 2, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
RemakeTmpBMP;
ChangeBitmapColor(TmpBMP, clBlack, FColorHighlight);
CreateBitmapExt(FGlyphActive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
0, 0, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
if boShadowSurround in FOptions then
begin
CreateBitmapExt(FGlyphActive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
1, 0, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
CreateBitmapExt(FGlyphActive.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
0, 1, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
end;
RemakeTmpBMP;
end;
if boDrawPushedAsFlat in FOptions then
Exit;
RemakeTmpBMP;
ChangeBitmapColor(TmpBMP, clBlack, FColorHighlight);
if boShadowSurround in FOptions then
begin
CreateBitmapExt(FGlyphPushed.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
0, 2, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
CreateBitmapExt(FGlyphPushed.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
2, 0, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
end;
CreateBitmapExt(FGlyphPushed.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
2, 2, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
RemakeTmpBMP;
if clBlack <> FColorShadow then
ChangeBitmapColor(TmpBMP, clBlack, FColorShadow);
CreateBitmapExt(FGlyphPushed.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
0, 0, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
if boShadowSurround in FOptions then
begin
CreateBitmapExt(FGlyphPushed.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
1, 0, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
CreateBitmapExt(FGlyphPushed.Canvas.Handle, TmpBMP, Rect(0, 0,
TmpBMP.Width, TmpBMP.Height),
0, 1, fwoNone, fdsDefault, True, FTransparentColor,
FDisabledMaskColor);
end;
RemakeTmpBMP;
finally
DeleteObject(SelectObject(MonoDC, OldMonoBMP));
end;
end;
end;
function TJvgButton.IsMouseInControl: Boolean;
var
Pt: TPoint;
PixelColor: TColorRef;
begin
GetCursorPos(Pt);
Pt := ScreenToClient(Pt);
if FShowingAsPushedNow and FPushed then
begin
Dec(Pt.X, FShiftMaskWhenPushed.X);
Dec(Pt.Y, FShiftMaskWhenPushed.Y);
end
else
if FDrawMode = dmAutoShadow then
begin
Inc(Pt.X, FShadowDepth);
Inc(Pt.Y, FShadowDepth);
end;
Dec(Pt.X);
Dec(Pt.Y);
if FGlyphsIndexes.Mask = -1 then //...__mask is absent_
begin
with FGlyphs do
case FDrawMode of
dmAutoShadow:
PixelColor := GetPixel(FGlyphPushed.Canvas.Handle, Pt.X, Pt.Y);
dmAutoFlat:
PixelColor := GetPixel(FGlyphActive.Canvas.Handle, Pt.X, Pt.Y);
else
PixelColor := GetPixel(FGlyphInactive.Canvas.Handle, Pt.X, Pt.Y);
end;
Result := (PixelColor <> TColorRef(FTransparentColor)) and (PixelColor <> DWORD(-1));
end
else //...__use mask_
begin
with FGlyphs do
PixelColor := GetPixel(FGlyphMask.Canvas.Handle, Pt.X, Pt.Y);
Result := (PixelColor = TColorRef(clWhite)) and (PixelColor <> DWORD(-1));
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -