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

📄 jvqfullcolorctrls.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  Result.X := Round(Radius * Cos(FullAngle) * FBuffer.Width / (Radius1 * 2) + (FBuffer.Width / 2.0)) + CrossSize;
  Result.Y := Round(Radius * Sin(FullAngle) * FBuffer.Height / (Radius1 * 2) + (FBuffer.Height / 2.0)) + CrossSize;
end;

function TJvFullColorCircle.PositionToFullColor(APoint: TPoint): TJvFullColor;
var
  RadiusIndex, AngleIndex: TJvAxisIndex;
  Radius, RadiusMax, RadiusMin, Angle, AngleMax, AngleMin: Integer;
  XPos, YPos: Extended;
begin
  if (FBuffer.Width = 0) or (FBuffer.Height = 0) then
  begin
    Result := fclRGBBlack;
    Exit;
  end;
  with ColorSpace do
  begin
    RadiusIndex := GetIndexAxisX(AxisConfig);
    RadiusMax := AxisMax[RadiusIndex];
    RadiusMin := AxisMin[RadiusIndex];

    AngleIndex := GetIndexAxisY(AxisConfig);
    AngleMax := AxisMax[AngleIndex];
    AngleMin := AxisMin[AngleIndex];
  end;

  XPos := FBuffer.Width / 2.0;
  XPos := (APoint.X - CrossSize - XPos) / XPos;
  YPos := FBuffer.Height / 2.0;
  YPos := (APoint.Y - CrossSize - YPos) / YPos;

  Radius := Round(Sqrt(Sqr(XPos) + Sqr(YPos))*(RadiusMax - RadiusMin));
  Angle := Round((ArcTan2(YPos, XPos) + Pi) * (AngleMax - AngleMin) / 2.0 / Pi);

  if InvertRadius then
    Radius := RadiusMax - Radius
  else
    Radius := Radius + RadiusMin;
  if InvertRotation then
    Angle := AngleMax - Angle
  else
    Angle := Angle + AngleMin;

  Radius := EnsureRange(Radius, RadiusMin, RadiusMax);
  Angle := EnsureRange(Angle, AngleMin, AngleMax);

  Result := SetAxisValue(
    SetAxisValue(
    SetAxisValue(ColorSpace.ID shl 24, GetIndexAxisZ(AxisConfig), ValueZ),
    AngleIndex, Angle), RadiusIndex, Radius);
end;

procedure TJvFullColorCircle.MouseColor(Shift: TShiftState; X, Y: Integer);
var
  LFullColor: TJvFullColor;

  function MoveColor(var AFullColor: TJvFullColor): Boolean;
  var
    Distance: Integer;
    Point: TPoint;
  begin
    Point := FullColorToPosition(AFullColor);
    Distance := Round(Sqrt(Sqr(X - Point.X) + Sqr(Y - Point.Y)));
    if Distance < CrossSize then
    begin
      AFullColor := LFullColor;
      Result := True;
      Invalidate;
    end
    else
      Result := False;
  end;

begin
  LFullColor := PositionToFullColor(Point(X, Y));
  if csShowCommon in Styles then
  begin
    if (ssLeft in Shift) or
      ((cs3ButtonsMouse in Styles) and (cs3ButtonsCommon in Styles)) then
      FullColor := LFullColor;
  end
  else
  if cs3ButtonsMouse in Styles then
  begin
    if (ssLeft in Shift) and (csShowRed in Styles) then
      RedColor := LFullColor;
    if (ssMiddle in Shift) and (csShowGreen in Styles) then
      GreenColor := LFullColor;
    if (ssRight in Shift) and (csShowBlue in Styles) then
      BlueColor := LFullColor;
  end
  else
  begin
    if FDraggingColor = rcGreen then
      GreenColor := LFullColor
    else
    if FDraggingColor = rcRed then
      RedColor := LFullColor
    else
    if FDraggingColor = rcBlue then
      BlueColor := LFullColor
    else
    if FDraggingColor = rcCommon then
    begin
      if (csShowGreen in Styles) and MoveColor(FGreenColor) then
      begin
        FDraggingColor := rcGreen;
        if Assigned(FOnGreenColorChange) then
          FOnGreenColorChange(Self);
      end
      else
      if (csShowRed in Styles) and MoveColor(FRedColor) then
      begin
        FDraggingColor := rcRed;
        if Assigned(FOnRedColorChange) then
          FOnRedColorChange(Self);
      end
      else
      if (csShowBlue in Styles) and MoveColor(FBlueColor) then
      begin
        FDraggingColor := rcBlue;
        if Assigned(FOnBlueColorChange) then
          FOnBlueColorChange(Self);
      end;
    end;
  end;
end;

procedure TJvFullColorCircle.MouseUp(Button: TMouseButton; Shift: TShiftState;
  X, Y: Integer);
begin
  FDraggingColor := rcCommon;
  inherited MouseUp(Button, Shift, X, Y);
end;

procedure TJvFullColorCircle.KeyMove(KeyCode: TJvKeyCode;
  MoveCount: Integer);
begin
  // (outchy) todo implementation but how to select a cursor ???
end;

procedure TJvFullColorCircle.PenChanged(Sender: TObject);
begin
  WantDrawBuffer := True;
end;

procedure TJvFullColorCircle.ConvertToID(NewFullColor: TJvFullColor);
var
  ColorID: TJvFullColorSpaceID;
  Change: Boolean;
begin
  with ColorSpaceManager do
  begin
    ColorID := GetColorSpaceID(NewFullColor);
    Change := ColorID <> GetColorSpaceID(FullColor);

    if Change then
    begin
      FFullColor := ConvertToID(FullColor, ColorID);
      FRedColor := ConvertToID(RedColor, ColorID);
      FGreenColor := ConvertToID(GreenColor, ColorID);
      FBlueColor := ConvertToID(BlueColor, ColorID);
      ColorSpaceChange;
    end;
  end;
end;

procedure TJvFullColorCircle.InvalidateColors(AColor1, AColor2: TJvFullColor);
var
  AxisX, AxisY: TJvAxisIndex;
  APosition1,
    APosition2: TPoint;
  ARect: TRect;
  CenterX, CenterY: Integer;
begin
  AxisX := GetIndexAxisX(AxisConfig);
  AxisY := GetIndexAxisY(AxisConfig);

  if (GetAxisValue(AColor1, AxisX) <> GetAxisValue(AColor2, AxisX)) or
    (GetAxisValue(AColor1, AxisY) <> GetAxisValue(AColor2, AxisY)) then
  begin
    APosition1 := FullColorToPosition(AColor1);
    APosition2 := FullColorToPosition(AColor2);
    if APosition1.X < APosition2.X then
    begin
      ARect.Left := APosition1.X;
      ARect.Right := APosition2.X;
    end
    else
    begin
      ARect.Left := APosition2.X;
      ARect.Right := APosition1.X;
    end;
    if APosition1.Y < APosition2.Y then
    begin
      ARect.Top := APosition1.Y;
      ARect.Bottom := APosition2.Y;
    end
    else
    begin
      ARect.Top := APosition2.Y;
      ARect.Bottom := APosition1.Y;
    end;

    CenterX := Width div 2;
    CenterY := Height div 2;
    if (ARect.Left > CenterX) then
      ARect.Left := CenterX;
    if (ARect.Top > CenterY) then
      ARect.Top := CenterY;
    if (ARect.Right < CenterX) then
      ARect.Right := CenterX;
    if (ARect.Bottom < CenterY) then
      ARect.Bottom := CenterY;

    ARect.Left := ARect.Left - CrossStyle.Width - CrossSize;
    ARect.Top := ARect.Top - CrossStyle.Width - CrossSize;
    ARect.Right := ARect.Right + CrossStyle.Width + CrossSize;
    ARect.Bottom := ARect.Bottom + CrossStyle.Width + CrossSize;

    QWindows.InvalidateRect(Handle, @ARect, False);
  end;
end;

procedure TJvFullColorCircle.SetFullColor(const Value: TJvFullColor);
var
  OldColor: TJvFullColor;
begin
  ConvertToID(Value);

  OldColor := FullColor;
  inherited SetFullColor(Value);

  if Assigned(FCommonColorTrackBar) and not FColorChanging then
  begin
    FColorChanging := True;
    FCommonColorTrackBar.FullColor := Value;
    FColorChanging := False;
  end;

  InvalidateColors(OldColor, FullColor);

  if ColorSpaceManager.GetColorSpaceID(OldColor) <> ColorSpaceManager.GetColorSpaceID(FullColor) then
    CalcSize;
end;

procedure TJvFullColorCircle.SetBlueColor(const Value: TJvFullColor);
var
  OldColor: TJvFullColor;
begin
  ConvertToID(Value);

  OldColor := BlueColor;
  FBlueColor := Value;

  if Assigned(FBlueColorTrackBar) and not FColorChanging then
  begin
    FColorChanging := True;
    FBlueColorTrackBar.FullColor := Value;
    FColorChanging := False;
  end;

  InvalidateColors(OldColor, BlueColor);

  if Assigned(FOnBlueColorChange) then
    FOnBlueColorChange(Self);
end;

procedure TJvFullColorCircle.SetGreenColor(const Value: TJvFullColor);
var
  OldColor: TJvFullColor;
begin
  ConvertToID(Value);

  OldColor := GreenColor;
  FGreenColor := Value;

  if Assigned(FGreenColorTrackBar) and not FColorChanging then
  begin
    FColorChanging := True;
    FGreenColorTrackBar.FullColor := Value;
    FColorChanging := False;
  end;

  InvalidateColors(OldColor, GreenColor);

  if Assigned(FOnGreenColorChange) then
    FOnGreenColorChange(Self);
end;

procedure TJvFullColorCircle.SetRedColor(const Value: TJvFullColor);
var
  OldColor: TJvFullColor;
begin
  ConvertToID(Value);

  OldColor := RedColor;
  FRedColor := Value;

  if Assigned(FRedColorTrackBar) and not FColorChanging then
  begin
    FColorChanging := True;
    FRedColorTrackBar.FullColor := Value;
    FColorChanging := False;
  end;

  InvalidateColors(OldColor, RedColor);

  if Assigned(FOnRedColorChange) then
    FOnRedColorChange(Self);
end;

procedure TJvFullColorCircle.SetCrossCenter(Value: Integer);
begin
  if Value < 0 then
    Value := 0;
  if Value >= CrossSize then
    Value := CrossSize - 1;
  if FCrossCenter <> Value then
  begin
    FCrossCenter := Value;
    Invalidate;
  end;
end;

procedure TJvFullColorCircle.SetCrossSize(Value: Integer);
begin
  if Value < 0 then
    Value := 0;
  if FCrossSize <> Value then
  begin
    FCrossSize := Value;
    CalcSize;
  end;
end;

procedure TJvFullColorCircle.SetCrossStyle(const Value: TPen);
begin
  FCrossStyle.Assign(Value);
  Invalidate;
end;

procedure TJvFullColorCircle.SetInvertRadius(const Value: Boolean);
begin
  if FInvertRadius <> Value then
  begin
    FInvertRadius := Value;
    WantDrawBuffer := True;
  end;
end;

procedure TJvFullColorCircle.SetInvertRotation(const Value: Boolean);
begin
  if FInvertRotation <> Value then
  begin
    FInvertRotation := Value;
    WantDrawBuffer := True;
  end;
end;

procedure TJvFullColorCircle.SetLineWidth(Value: Integer);
begin
  if Value < 0 then
    Value := 0;
  if FLineWidth <> Value then
  begin
    FLineWidth := Value;
    WantDrawBuffer := True;
  end;
end;

procedure TJvFullColorCircle.SetStyles(const Value: TJvFullColorCircleStyles);
begin
  if FStyles <> Value then
  begin
    FStyles := Value;
    WantDrawBuffer := True;
  end;
end;

procedure TJvFullColorCircle.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  if Operation = opRemove then
    if AComponent = RedTrackBar then
      RedTrackBar := nil
    else
    if AComponent = GreenTrackBar then
      GreenTrackBar := nil
    else
    if AComponent = BlueTrackBar then
      BlueTrackBar := nil
    else
    if AComponent = CommonTrackBar then
      CommonTrackBar := nil;
  inherited Notification(AComponent, Operation);
end;

procedure TJvFullColorCircle.SetBlueColorTrackBar(const Value: TJvFullColorTrackBar);
begin
  if (Value <> nil) and (Value <> FBlueColorTrackBar) and Value.Linked then
    raise EJvFullColorError.CreateResFmt(@Rs_EDuplicateTrackBar, [Value.LinkerName]);

  if Assigned(FBlueColorTrackBar) then
  begin
    FBlueColorTrackBar.OnColorChange := nil;
    FBlueColorTr

⌨️ 快捷键说明

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