NSProgressIndicator selber zeichnen (Problem)

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • NSProgressIndicator selber zeichnen (Problem)

    Guten morgen,

    ich möchte mir selbe einen ProgressIndicator zeichnen und habe eine Subklasse erstellt und drawRect überschrieben.
    Allerdings wird drawRect 2x aufgerufen und scheinbar leicht versetzt was zu Aussehen führt von dem Bild was angehängt ist.

    Hier der Code:

    Quellcode

    1. - (NSBezierPath*)roundBezierPath:(NSRect)theSize {
    2. float CURVERADIUS = 5.0;
    3. float CURVEFACTOR = 0.5;
    4. float actualCornerRadius = MIN(MIN(ABS(theSize.size.width),ABS(theSize.size.height)),CURVERADIUS);
    5. float curveFactor = CURVEFACTOR;
    6. float left = theSize.origin.x;
    7. float right = theSize.origin.x+theSize.size.width;
    8. float bottom = theSize.origin.y;
    9. float top = theSize.origin.y+theSize.size.height;
    10. NSBezierPath* path = [NSBezierPath bezierPath];
    11. [path moveToPoint:NSMakePoint(left,top-actualCornerRadius)];
    12. [path curveToPoint:NSMakePoint(left+actualCornerRadius,top)
    13. controlPoint1:NSMakePoint(left,top-actualCornerRadius*curveFactor)
    14. controlPoint2:NSMakePoint(left+actualCornerRadius*curveFactor,top)];
    15. [path lineToPoint:NSMakePoint(right-actualCornerRadius,top)];
    16. [path curveToPoint:NSMakePoint(right,top-actualCornerRadius)
    17. controlPoint1:NSMakePoint(right-actualCornerRadius*curveFactor,top)
    18. controlPoint2:NSMakePoint(right,top-actualCornerRadius*curveFactor)];
    19. [path lineToPoint:NSMakePoint(right,bottom+actualCornerRadius)];
    20. [path curveToPoint:NSMakePoint(right-actualCornerRadius,bottom)
    21. controlPoint1:NSMakePoint(right,bottom+actualCornerRadius*curveFactor)
    22. controlPoint2:NSMakePoint(right-actualCornerRadius*curveFactor,bottom)];
    23. [path lineToPoint:NSMakePoint(left+actualCornerRadius,bottom)];
    24. [path curveToPoint:NSMakePoint(left,bottom+actualCornerRadius)
    25. controlPoint1:NSMakePoint(left+actualCornerRadius*curveFactor,bottom)
    26. controlPoint2:NSMakePoint(left,bottom+actualCornerRadius*curveFactor)];
    27. [path closePath];
    28. return path;
    29. }
    30. - (void)drawRect:(NSRect)aRect {
    31. NSBezierPath *bp;
    32. bp = [self roundBezierPath:aRect];
    33. [[NSColor whiteColor] set];
    34. [bp setLineWidth:1.0f];
    35. [bp stroke];
    36. }
    Alles anzeigen

    Es liegt auch nicht an der Funktion roundBezierPath zeichne ich ein Rechteck, dann schaut das genau so aus.

    Schon mal jemand einen selber gezeichnet?
    :wq! /dev/null
  • Ich habe da was im Quellcode von VLC gefunden.

    Quellcode

    1. void _drawFrameInRect(NSRect frameRect)
    2. {
    3. // Draw frame
    4. NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width, 1), NSCompositeSourceOver);
    5. NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y + frameRect.size.height-1, frameRect.size.width, 1), NSCompositeSourceOver);
    6. NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
    7. NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x+frameRect.size.width-1, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
    8. }

    damit funktioniert das ganze.
    :wq! /dev/null