Einzelnen Beitrag anzeigen

Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.542 Beiträge
 
Delphi 11 Alexandria
 
#1

GDI+ und AntiAliasing: mal geht' s, mal nicht

  Alt 2. Feb 2008, 18:41
Hallöle,

ich wollte meinen runden Button um einen Style erweitern (weitere sind geplant). Leider wird der neue Style nicht rund gezeichnet. Kann mir mal jemand zeigen, wo es hakt?

Paint-Methode:
Delphi-Quellcode:
  for i := Low(TBmType) to High(TBmType) do
    begin
      FStates[i].Width := Self.Width;
      FStates[i].Height := Self.Height;
      FStates[i].Canvas.Brush.Color := FTransparentColor;
      FStates[i].Canvas.FillRect(Rect(0,0,Self.Width,Self.Height));

      graphics[i] := TGPGraphics.Create(FStates[i].Canvas.Handle);
      try
        graphics[i].SetSmoothingMode(SmoothingModeAntiAlias); //<-- explizit eingeschaltet

        case FDrawType of
          dtMembrane: DrawMembrane(i);
          dtBubble : DrawBubble(i);
        end;
        
        DrawGDIPCaption(i);

      finally
        graphics[i].Free;
      end;

      FStates[i].TransparentColor := FStates[i].Canvas.Brush.Color;
      FStates[i].Transparent := True;

    end; //for
DrawMembrane (AntiAliasing funktioniert):
Delphi-Quellcode:
    procedure DrawMembrane(const aState: TBmType);
    begin
      Col1 := FFirstColor;
      Col2 := AddHalfTones(FFirstColor);

      case aState of
        btUp : begin
                       Col1 := AddHalfTones(FFirstColor);
                       Col2 := FFirstColor;
                     end;
        btDisabled: begin
                       Col1 := AddHalfTones(FFirstColor);
                       Col2 := FDisabledColor;
                     end;
      end;

      linGrBrush := TGPLinearGradientBrush.Create(
                         MakePoint(0, 0),
                         MakePoint(Pred(self.Width), Pred(self.Height)),
                         ColorToGPColor(Col1),
                         ColorToGPColor(Col2));

      linGrBrush.SetGammaCorrection(FGammaCorrection);

      try
        graphics[aState].FillEllipse(linGrBrush,0,0,
                                     Self.Width - 1,
                                     Self.Height - 1);
      finally
        linGrBrush.Free;
      end;
    end;
DrawBubble (AntiAliasing funktioniert nicht):
Delphi-Quellcode:
    procedure DrawBubble(const aState: TBmType);
    type TPoints = array[Boolean] of Single;
         Tcolors = array[0..1] of TGPColor;
         THighColors = array[Boolean] of TColor;
    var
      path : TGPGraphicsPath;
      pthGrBrush : TGPPathGradientBrush;
      count : Integer;
      PointsX, PointsY: TPoints;
      colors : Tcolors;
      HighColors : THighColors;
    begin

      if aState = btDisabled then
        colors[0] := ColorToGPColor(FDisabledColor)
      else
        colors[0] := ColorToGPColor(FFirstColor);

      colors[1] := ColorToGPColor(clYellow);

      HighColors[false] := $EAEAEA;
      HighColors[true] := AddHalfTones(FFirstColor);
      
      path:= TGPGraphicsPath.Create;
      try
        path.AddEllipse(0, 0, Self.Width - 1, Self.Height - 1);

        pthGrBrush:= TGPPathGradientBrush.Create(path);
        try

          PointsX[false] := Self.Width / 5;
          PointsY[false] := Self.Height / 5;

          PointsX[true] := Self.Width / 2;
          PointsY[true] := Self.Height / 2;

          pthGrBrush.SetCenterPoint(MakePoint(PointsX[aState = btDown],
                                              PointsY[aState = btDown]));

          pthGrBrush.SetCenterColor(ColorToGPColor(HighColors[aState = btDown]));

          count := 1;
          pthGrBrush.SetSurroundColors(@colors[0], count);
          pthGrBrush.SetGammaCorrection(FGammaCorrection);

          graphics[aState].FillPath(pthGrBrush,path);

          if aState = btDown then
            begin
              pthGrBrush.SetFocusScales(0.85,0.85);
              graphics[aState].FillPath(pthGrBrush,path);
            end;
        finally
          pthGrBrush.Free;
        end;
      finally
        path.Free;
      end;
    end;
Kann das sein, dass es an der Verwendung der Paths liegt? Ich hänge mal eine Demo an, damit man das auch mal sieht.

[edit] Ich vergaß zu sagen, dass die beiden Draw...-Prozeduren Unterprozeduren von Paint sind, die Variablen sind also bekannt. [/edit]
Angehängte Dateien
Dateityp: exe buttondemo_132.exe (410,0 KB, 37x aufgerufen)
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat