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

📄 shintmanager.pas

📁 AlphaControls是一个Delphi标准控件的集合
💻 PAS
📖 第 1 页 / 共 5 页
字号:

  tr := ShadowTransparency;

  RValue := 255 * tr div 100;

  bitBlt(TempBmp.Canvas.Handle, 0, 0, TempBmp.Width, TempBmp.Height, Manager.sStyle.FCacheBmp.Canvas.Handle, 0, 0, SrcCopy);

  delta := (255 - RValue) / (Manager.sStyle.Shadow.Blur + 1);

  // Prepare mask
  TColor(c) := clWhite;
  MaskBmp.Canvas.Pen.Style := psClear;
  MaskBmp.Canvas.Brush.Style := bsSolid;
  MaskBmp.Canvas.Brush.Color := clWhite;

  pMouse := GetArrowPosition;

  k := 0;

  for i := 0 to Manager.sStyle.Shadow.Blur do begin
    c.R := RValue + Round(delta * (Manager.sStyle.Shadow.Blur - i));
    c.G := c.R;
    c.B := c.R;
    MaskBmp.Canvas.Brush.Color := TColor(c);

    MaskBmp.Canvas.Ellipse(R.Left + i,
                           R.Top + i,
                           R.Right - i + 1,
                           R.Bottom - i + 1);

    xcenter := R.Left + WidthOf(R) div 2;// + Manager.sStyle.Shadow.Blur;
    tr := WidthOf(R) div 8 - Round(i * k * 2);
    if tr < 0 then tr := 0;
    case FMousePos of
      mpLeftTop, mpRightTop : begin
        k := (R.Top + HeightOf(R) / 2) / (R.Top + 1);
        MaskBmp.Canvas.Polygon([pMouse,
                         Point(xcenter - tr, R.Top + HeightOf(R) div 2),
                         Point(xcenter + tr, R.Top + HeightOf(R) div 2),
                         pMouse
                        ]);
      end
      else begin
        k := (Height - (R.Bottom - HeightOf(R) / 2)) / (Height - R.Bottom + 1);
        MaskBmp.Canvas.Polygon([pMouse,
                         Point(xcenter - tr, R.Bottom - HeightOf(R) div 2),
                         Point(xcenter + tr, R.Bottom - HeightOf(R) div 2)
                        ]);
      end;
    end;
  end;

//  SumBitmaps(TempBmp, MaskBmp, TsColor(Manager.sStyle.Shadow.Color));
  BlendBmpByMask(TempBmp, MaskBmp, TsColor(Manager.sStyle.Shadow.Color));

  // Copy back
//  BitBlt(Manager.sStyle.FCacheBmp.Canvas.Handle, 0, 0, TempBmp.Width, MaskBmp.Height, MaskBmp.Canvas.Handle, 0, 0, SRCCOPY);
  BitBlt(Manager.sStyle.FCacheBmp.Canvas.Handle, 0, 0, TempBmp.Width, MaskBmp.Height, TempBmp.Canvas.Handle, 0, 0, SRCCOPY);

  finally
    if Assigned(Maskbmp) then FreeAndNil(MaskBmp);
    if Assigned(TempBmp) then FreeAndNil(TempBmp);
  end;
end;

{ TsBalloonHintWindow }

function TsBalloonHintWindow.CalcHintRect(MaxWidth: Integer;
  const AHint: string; AData: Pointer): TRect;
var
  s, {z,} l : real;
begin
  Result := inherited CalcHintRect(MaxWidth, AHint, AData);
  Inc(Result.Bottom, Manager.ExOffset);
  l := Sqrt(Sqr(WidthOf(Result)) + Sqr(HeightOf(Result)));
  s := l - WidthOf(Result);
  dx := Round(s * WidthOf(Result) / HeightOf(Result));
  dy := Round(s * HeightOf(Result) / WidthOf(Result));
  Inc(Result.Right, dx);
  Inc(Result.Bottom, dy);
end;

constructor TsBalloonHintWindow.Create(AOwner: TComponent);
begin
  inherited;
  BalloonCount := 3;
  Divid := 4;
end;

function TsBalloonHintWindow.GetArrowPosition: TPoint;
const
  Offs = 3;
begin
  case FMousePos of
    mpLeftTop: begin
      Result := Point(Offs, Offs);
    end;
    mpRightTop: begin
      Result := Point(Width - Offs, Offs);
    end;
    mpLeftBottom: begin
      Result := Point(Offs, Height - Offs);
    end;
    mpRightBottom: begin
      Result := Point(Width - Offs, Height - Offs);
    end;
  end;
end;

function TsBalloonHintWindow.GetBody: TBitmap;
var
//  P : TPoint;
  R{, rText}: TRect;
//  SmallOffset, ShadowOffset : integer;
//  MaskBmp, BodyBmp: TBitmap;
begin
  Result := CreateBmpLike(Manager.sStyle.FCacheBmp);

  R := ClientRect;
//  ShadowOffset := iffi(Manager.sStyle.Shadow.Enabled, Manager.sStyle.Shadow.Offset, 0);

  PaintBg(Result, ClientRect);

  TextOut(Result);

  PaintBorder(Result);
end;

function TsBalloonHintWindow.GetMask: TBitmap;
begin
  Result := GetCustMask(False);
end;

function TsBalloonHintWindow.GetCustMask(Shadow: boolean): TBitmap;
var
  R, mRect, bRect : TRect;
  RValue, tr, bl, xcenter, ycenter, blur : integer;
  pMouse : TPoint;
  delta{, k}: real;
  c : TsColor;
  //
  j, deltaY, deltaX : integer;

  function MinHeight : real; begin
    Result := HeightOf(mRect) / (Divid * BalloonCount);
  end;

  function AddOffset : integer; begin
    if (FMousePos in [mpLeftBottom, mpRightBottom]) then begin
      Result := iffi(Manager.sStyle.Shadow.Enabled, Manager.sStyle.Shadow.Offset, 0);
//      Result := 0;
    end
    else begin
      Result := 0;
    end;
  end;

  function GetMinDelta : integer;
  var
    i, j : integer;
  begin
    j := 0;
    for i := 0 to BalloonCount - 1 do begin
      j := j + i * 2;
    end;
    Result := Round((Manager.ExOffset - BalloonCount * MinHeight) / j);
  end;

  function GetHeight(i : integer) : integer;
  begin
    Result := Round(MinHeight + GetMinDelta * (i - 1) * 2);
  end;

  function GetTop(i : integer) : integer;
  var
    cur, j : integer;
  begin
    cur := 0;
    for j := 1 to i do begin
      cur := cur + GetHeight(j);
    end;
    Result := Cur - GetHeight(i);
  end;

  function GetBubbleHalfSize(i : integer) : TSize; begin
    Result.cy := GetHeight(i) div 2;
    Result.cx := Round(Result.cy * WidthOf(mRect) / (HeightOf(mRect) * 2) );
  end;

  function GetBubbleCenter(i : integer) : TPoint;
  begin
    case FMousePos of
      mpLeftTop : begin
        Result.x := deltaX * i;
        Result.y := GetTop(i) + GetBubbleHalfSize(i).cy;// div 2;
      end;
      mpRightTop : begin
        Result.x := pMouse.X - deltaX * i;
        Result.y := GetTop(i) + GetBubbleHalfSize(i).cy;// div 2;
      end;
      mpLeftBottom : begin
        Result.x := deltaX * i;
        Result.y := pMouse.Y - deltaY * i;
        Result.y := Height - AddOffset -(GetTop(i) + GetBubbleHalfSize(i).cy)// div 2);
      end;
      mpRightBottom : begin
        Result.x := pMouse.X - deltaX * i - AddOffset;
        Result.y := Height - AddOffset - (GetTop(i) + GetBubbleHalfSize(i).cy)// div 2);
      end;
    end;
  end;
  function GetBubbleRect(i : integer) : TRect;
  var
    bSize : TSize;
    bCenter : TPoint;
  begin
    bSize := GetBubbleHalfSize(i);
    bCenter := GetBubbleCenter(i);
    Result.Left   := Mini(bCenter.x - bSize.cx, bCenter.x);
    Result.Top    := Mini(bCenter.y - bSize.cy, bCenter.y);
    Result.Right  := Maxi(bCenter.x + bSize.cx + 1, bCenter.x + 1);
    Result.Bottom := Maxi(bCenter.y + bSize.cy + 1, bCenter.y + 1);
  end;
begin
  Result := CreateBmpLike(Manager.sStyle.FCacheBmp);

  Result.Canvas.Pen.Style := psClear;
  Result.Canvas.Brush.Color := clWhite;
  Result.Canvas.FillRect(ClientRect);

  R := MainRect;
  xcenter := R.Left + WidthOf(R) div 2;
  ycenter := R.Top + HeightOf(R) div 2;
  case FMousePos of
    mpLeftTop, mpRightTop : begin
      dec(yCenter, HeightOf(MainRect) div 2);
    end;
    mpLeftBottom, mpRightBottom : begin
      inc(yCenter, HeightOf(MainRect) div 2);
    end;
  end;

  if Shadow then begin
    tr := ShadowTransparency;
    blur := Manager.sStyle.Shadow.Blur;
  end
  else begin
    tr := Manager.sStyle.Painting.Transparency * integer(Manager.sStyle.Painting.Transparency > 0);
    blur := Manager.Blur;
  end;

  RValue := 255 * tr div 100;

  delta := (255 - RValue) / (Blur + 1);

  // Prepare mask
  TColor(c) := clWhite;
  Result.Canvas.Pen.Style := psClear;
  Result.Canvas.Brush.Style := bsSolid;

  pMouse := GetArrowPosition;

  mRect := R;
  for bl := 0 to Blur do begin
    c.R := RValue + Round(delta * (Blur - bl));
    c.G := c.R;
    c.B := c.R;
    Result.Canvas.Brush.Color := TColor(c);

    Result.Canvas.Ellipse(R.Left + bl,
                           R.Top + bl,
                           R.Right - bl + 1,
                           R.Bottom - bl + 1);

//    tr := WidthOf(R) div 8 - Round(bl * {k *} 2);
//    if tr < 0 then tr := 0;

    deltaX := Round(abs((xCenter - pMouse.x) div (BalloonCount + 1)));
    deltaY := Round(abs((yCenter - pMouse.y) div (BalloonCount + 1)));
    // Arrow painting
    for j := 1 to BalloonCount do begin
      bRect := GetBubbleRect(j);
      if (bRect.Bottom > bRect.Top) and (bRect.Right > bRect.Left) then
        Result.Canvas.Ellipse(bRect.Left + bl,
                              bRect.Top + bl,
                              bRect.Right - bl + 1,
                              bRect.Bottom - bl + 1
                              );
    end;
  end;
end;

function TsBalloonHintWindow.GetMousePosition: TPoint;
var
  m : TMouse;
begin
  m := TMouse.Create;
  Result := m.CursorPos;
  inc(Result.x, 0);
  inc(Result.y, 0);
  FreeAndNil(m);
end;

function TsBalloonHintWindow.MainRect: TRect;
var
  ShadowOffset : integer;
begin
  ShadowOffset := iffi(Manager.sStyle.Shadow.Enabled, Manager.sStyle.Shadow.Offset, 0);
  Result.Left  := 0;
  Result.Right := Width - ShadowOffset;
  case FMousePos of
    mpLeftTop, mpRightTop: begin
      Result.Top := Manager.ExOffset;
      Result.Bottom := Height - ShadowOffset;
    end;
    mpLeftBottom, mpRightBottom: begin
      Result.Top := 0;
      Result.Bottom := Height - ShadowOffset - Manager.ExOffset;
    end;
  end;
end;

procedure TsBalloonHintWindow.PaintBorder(Bmp: TBitmap);
var
//  R: TRect;
  MskBmp : TBitmap;
begin
  if Manager.FBevelWidth > 0 then begin
    MskBmp := GetMask;
    MonoBmp(MskBmp); //!!! Slow
    Bmp.Canvas.Pen.Style := psSolid;
    BorderByMask(Bmp, MskBmp, TsColor(ColorToRGB(Manager.sStyle.Painting.ColorBorderTop)), TsColor(ColorToRGB(Manager.sStyle.Painting.ColorBorderBottom)));
    FreeAndNil(MskBmp);
  end;
end;

procedure TsBalloonHintWindow.PaintShadow;
var
  R : TRect;
  MaskBmp, TempBmp, BodyBmp : TBitmap;
begin
  MaskBmp := CreateBmpLike(Manager.sStyle.FCacheBmp);
  BodyBmp := GetCustMask(True);
  TempBmp := CreateBmpLike(Manager.sStyle.FCacheBmp);

  MaskBmp.Canvas.Pen.Style := psClear;
  MaskBmp.Canvas.Brush.Color := clWhite;
  MaskBmp.Canvas.FillRect(ClientRect);

  R := ClientRect;
  dec(R.Right, Manager.sStyle.Shadow.Offset);
  dec(R.Bottom, Manager.sStyle.Shadow.Offset);
  OffsetRect(R, Manager.sStyle.Shadow.Offset, Manager.sStyle.Shadow.Offset);
  StretchBlt(MaskBmp.Canvas.Handle,
             R.Left,
             R.Top,
             WidthOf(R),
             HeightOf(R),
             BodyBmp.Canvas.Handle,
             0,
             0,
             Width - Manager.sStyle.Shadow.Offset,
             Height - Manager.sStyle.Shadow.Offset,
             srcCopy);


  bitBlt(TempBmp.Canvas.Handle, 0, 0, TempBmp.Width, TempBmp.Height, Manager.sStyle.FCacheBmp.Canvas.Handle, 0, 0, SrcCopy);

//  SumBitmaps(TempBmp, MaskBmp, TsColor(Manager.sStyle.Shadow.Color));
  BlendBmpByMask(TempBmp, MaskBmp, TsColor(Manager.sStyle.Shadow.Color));

  // Copy back
  BitBlt(Manager.sStyle.FCacheBmp.Canvas.Handle, 0, 0, TempBmp.Width, MaskBmp.Height, TempBmp.Canvas.Handle, 0, 0, SRCCOPY);

  FreeAndNil(MaskBmp);
  FreeAndNil(TempBmp);
  FreeAndNil(BodyBmp);
end;

end.


⌨️ 快捷键说明

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