⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jvgbutton.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 4 页
字号:
    end;
    Width := FGlyphInactive.Width + 1;
    Height := FGlyphInactive.Height + 1;
    FShowingAsPushedNow := FPushed and FMouseInControl;
    FActiveNow := True;

    with Img do
    begin
      Width := Self.Width;
      Height := Self.Height;
      Canvas.Brush.Color := clBtnFace;
      Canvas.Brush.Style := bsSolid;
      Canvas.FillRect(ClientRect);
    end;
    GetParentImageRect(Self, Bounds(Left, Top, Width, Height),
      Img.Canvas.Handle);

    if boDelicateInactive in FOptions then
      DrawState := fdsDelicate
    else
      DrawState := fdsDefault;

    if FEnabled then
    begin
      if FMouseInControl then
      begin
        if FPushed then
        begin
          if (boDrawPushedAsFlat in FOptions) and (FDrawMode <>
            dmUseImageList) then
            ApplicateGlyph(Img, fbsOriginal {fbsPushed}, fdsDefault, 3)
          else
          begin
            if FDrawMode = dmAutoFlat then
              I := 2
            else
              I := 0;
            ApplicateGlyph(Img, fbsPushed, fdsDefault, I);
          end;
        end
        else
        begin
          FActiveNow := False;
          if (FDrawMode = dmAutoFlat) then
            I := 1
          else
            I := 0;
          ApplicateGlyph(Img, fbsActive, fdsDefault, I);
        end;
      end
      else
      begin
        if (FDrawMode = dmAutoFlat) and
          ({FPushed or }(not (boRaisedInactive in FOptions))) then
          ApplicateGlyph(Img, fbsOriginal, DrawState, 2)
        else
        begin
          if (FDrawMode = dmAutoFlat) then
            I := 1
          else
            I := 0;
          ApplicateGlyph(Img, fbsInactive, DrawState, I);
        end;
      end;
    end
    else
    begin
      if (FDrawMode = dmAutoFlat) and (boRaisedInactive in Options) then
        I := 1
      else
        I := 0;
      if DrawMode <> dmUseImageList then //...auto disabled
        ApplicateGlyph(Img, fbsDisabled, fdsDisabled, I)
      else
      begin //...user'S disabled
        if FGlyphsIndexes.Disabled = -1 then
          CreateBitmapExt(Img.Canvas.Handle, FGlyphInactive, ClientRect, 0,
            0,
            fwoNone, fdsDisabled, True, FTransparentColor,
            DisabledMaskColor)
        else
          CreateBitmapExt(Img.Canvas.Handle, FGlyphDisabled, ClientRect, 0,
            0,
            fwoNone, fdsDefault, True, FTransparentColor,
            DisabledMaskColor);
      end;
    end;
    Img.Transparent := True;
    Img.TransparentColor := clBtnFace;
    Canvas.Draw(0, 0, Img);
  end;
end;

procedure TJvgButton.Paint_;
begin
  if not Enabled then
    Exit;
  if FChangeColorOnActivate.FromColor <> FChangeColorOnActivate.ToColor then
  begin
    Repaint;
    Exit;
  end;
  if ((FDrawMode = dmAutoCtrl3D) or (FDrawMode = dmAutoShadow)) and
    (not FShowingAsPushedNow) and (not FPushed) and (not (boDelicateInactive in FOptions)) then
    Exit;
  if (FDrawMode = dmAutoFlat) and (not FShowingAsPushedNow) and (not FPushed) and
    (boRaisedInactive in FOptions) and (not (boDelicateInactive in FOptions)) then
    Exit;

  Repaint;
  Exit;

  // (rom) unused code
  if (FDrawMode = dmAutoFlat) and
    (FShowingAsPushedNow or (not (boRaisedInactive in FOptions))) then
  begin
    Repaint;
    Exit;
  end;
  if FPushed then
  begin
    if (boRefreshOnPush in FOptions) or (FDrawMode = dmAutoShadow) then
      Repaint
    else
      Paint;
  end
  else
  if boRefreshOnActivate in FOptions then
    Repaint
  else
    Paint;
end;

procedure TJvgButton.ApplicateGlyph(var TargetBMP: TBitmap; State: TglBtnState;
  DrawState: TglDrawState; S: Integer);
var
  I, J: Integer;
  fChangeColor, fCanBlink: Boolean;
  DrawState2: TglDrawState;
begin
  with Glyphs do
  begin
    I := 1;
    J := 1;
    fChangeColor := False;
    fCanBlink := False;
    if DrawState = fdsDisabled then
    begin
      DrawState := fdsDefault;
      DrawState2 := fdsDisabled //DrawState;
    end
    else
      DrawState2 := DrawState;
    case FDrawMode of
      dmAutoCtrl3D:
        if State = fbsPushed then
        begin
          I := 2;
          J := 2;
        end;
      dmUseImageList:
        begin
          I := 0;
          J := 0;
          S := 0;
        end;
    end;

    case State of
      fbsOriginal:
        begin
          CreateBitmapExt(TargetBMP.Canvas.Handle, FGlyph, ClientRect, S,
            S,
            fwoNone, DrawState, True, FTransparentColor,
            DisabledMaskColor);
          Exit;
        end;
      fbsInactive, fbsDisabled:
        begin
          if (DrawMode = dmAutoFlat) and (boRaisedInactive in FOptions) then
            CreateBitmapExt(TargetBMP.Canvas.Handle, FGlyphActive,
              ClientRect, S, S,
              fwoNone, DrawState, True, FTransparentColor,
              DisabledMaskColor)
          else
            CreateBitmapExt(TargetBMP.Canvas.Handle, FGlyphInactive,
              ClientRect, 0, 0,
              fwoNone, DrawState, True, FTransparentColor,
              DisabledMaskColor);

          if State = fbsDisabled then
          begin
            I := 0;
            J := 0;
          end;
          fCanBlink := boBlinkWhenInactive in Options;
        end;
      fbsActive:
        begin
          if (FDrawMode = dmAutoCtrl3D) or (DrawMode = dmAutoShadow) then
            CreateBitmapExt(TargetBMP.Canvas.Handle, FGlyphInactive,
              ClientRect, S, S,
              fwoNone, DrawState, True, FTransparentColor,
              DisabledMaskColor)
          else
            CreateBitmapExt(TargetBMP.Canvas.Handle, FGlyphActive,
              ClientRect, S, S,
              fwoNone, DrawState, True, FTransparentColor,
              DisabledMaskColor);
          fChangeColor := boChangeColorWhenActive in Options;
          fCanBlink := boBlinkWhenActive in Options;
        end;
      fbsPushed:
        begin
          CreateBitmapExt(TargetBMP.Canvas.Handle, FGlyphPushed,
            ClientRect, S, S,
            fwoNone, DrawState, True, FTransparentColor,
            DisabledMaskColor);
          fChangeColor := boChangeColorWhenPushed in Options;
          fCanBlink := boBlinkWhenPushed in Options;
        end;
    end;
    GetBitmap_(FGlyphsIndexes.Inactive, TmpBMP);
    fCanBlink := fCanBlink and FNeedBlink;
    if fCanBlink then
      FBlinked := not FBlinked
    else
    if State = fbsActive then
      FBlinked := FChangeColorOnActivate.FromColor <> FChangeColorOnActivate.ToColor
    else
      FBlinked := FChangeColorOnPush.FromColor <> FChangeColorOnPush.ToColor;

    if fCanBlink then
    begin
      if FBlinked then
        if State = fbsPushed then
          with FChangeColorOnPush do
            ChangeBitmapColor(TmpBMP, FromColor, ToColor)
        else
          with FChangeColorOnActivate do
            ChangeBitmapColor(TmpBMP, FromColor, ToColor);
    end
    else
    if fChangeColor and (FDrawMode <> dmUseImageList) then
      if State = fbsActive then
        with FChangeColorOnActivate do
          ChangeBitmapColor(TmpBMP, FromColor, ToColor)
      else
        with FChangeColorOnPush do
          ChangeBitmapColor(TmpBMP, FromColor, ToColor);
    FNeedBlink := False;
    if (DrawMode = dmAutoShadow) and (State = fbsPushed) or
      (FDrawMode = dmUseImageList) then
      Exit;

    if DrawState2 = fdsDisabled then
    begin
      TmpBMP.Canvas.Brush.Color := FTransparentColor;
      TmpBMP.Canvas.Font.Color := clBtnFace;
      //    SetBkColor(TmpBMP.Canvas.Handle, FTransparentColor);
      TmpBMP.Monochrome := True;
      TmpBMP.Monochrome := False;
      CreateBitmapExt(TargetBMP.Canvas.Handle, TmpBMP, Rect(0, 0,
        TmpBMP.Width, TmpBMP.Height),
        I + S, J + S, fwoNone, fdsDefault, True, FTransparentColor,
        FDisabledMaskColor);
      GetBitmap_(FGlyphsIndexes.Inactive, TmpBMP);
    end;

    CreateBitmapExt(TargetBMP.Canvas.Handle, TmpBMP, Rect(0, 0, TmpBMP.Width,
      TmpBMP.Height),
      I + S, J + S, fwoNone, DrawState2, True, FTransparentColor,
      FDisabledMaskColor);
  end;
end;

procedure TJvgButton.MouseMove(Shift: TShiftState; X, Y: Integer);
var
  Pt: TPoint;
  MouseInControl: Boolean;
begin
  inherited MouseMove(Shift, X, Y);
  Pt.X := X;
  Pt.Y := Y;
  if PtInRectExclusive(ClientRect, Pt) then
  begin
    MouseInControl := IsMouseInControl;
    if MouseInControl <> FMouseInControl then
    begin
      {$IFDEF USEJVCL}
      if FMouseInControl then
        if Assigned(OnMouseEnter) then
          OnMouseEnter(Self)
        else
        if Assigned(OnMouseLeave) then
          OnMouseLeave(Self);
      {$ENDIF USEJVCL}
      FMouseInControl := MouseInControl;
      Paint_;
    end;
  end;
end;

{$IFDEF USEJVCL}
procedure TJvgButton.MouseLeave(Control: TControl);
begin
  if MouseOver then
  begin
    inherited MouseLeave(Control);
    FMouseInControl := False;
    Paint_;
  end;
end;
{$ENDIF USEJVCL}

procedure TJvgButton.MouseDown(Button: TMouseButton; Shift: TShiftState;
  X, Y: Integer);
var
  Pt: TPoint;
begin
  inherited MouseDown(Button, Shift, X, Y);
  if (Button <> mbLeft) or (not Enabled) or (not IsMouseInControl) then
    Exit;

  if boShiftMouseOnPush in FOptions then
  begin
    GetCursorPos(Pt);
    SetCursorPos(Pt.X + MShift.X, Pt.Y + MShift.Y);
  end;
  FPushed := True;
  Paint_;
end;

procedure TJvgButton.MouseUp(Button: TMouseButton; Shift: TShiftState;
  X, Y: Integer);
var
  Pt: TPoint;
begin
  inherited MouseUp(Button, Shift, X, Y);
  if FShowingAsPushedNow and Assigned(FOnClick) then
    FOnClick(Self);
  if (boShiftMouseOnPush in FOptions) and IsMouseInControl then
  begin
    GetCursorPos(Pt);
    SetCursorPos(Pt.X - MShift.X, Pt.Y - MShift.Y);
  end;
  FPushed := False;
  Paint_;
end;

procedure TJvgButton.GetBitmaps;
begin
  if not FLoaded then
    Exit;
  with Glyphs do
  begin
    FGlyphInactive.Width := 0;
    FGlyphPushed.Width := 0;
    FGlyphActive.Width := 0;
    FGlyphDisabled.Width := 0;
    FGlyphMask.Width := 0;
    if FDrawMode = dmUseImageList then
    begin
      if not Assigned(FGlyphsList) then
        Exit;
      with FGlyphsList, FGlyphsIndexes do
      begin
        if (Inactive < 0) and (Inactive > Count - 1) then
          Inactive := 0;
        if (Pushed < 0) and (Pushed > Count - 1) then
          Pushed := 1;
        if Active > Count - 1 then
          Active := -1;
        if Mask > Count - 1 then
          Mask := -1;

        if Inactive <> -1 then
          GetBitmap_(Inactive, FGlyphInactive);
        if Pushed <> -1 then
          GetBitmap_(Pushed, FGlyphPushed);
        if Active <> -1 then
          GetBitmap_(Active, FGlyphActive); //...optional bitmap
        if Disabled <> -1 then

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -