Weird drawing trouble, please help me

  • I've made a subclass of NSProgressIndicator and it works very well,
    except for the "scrolling" effect that it usually has. Here is my
    code:

    - (void)_drawProgressArea
    {
    if (progressOrigin >= [progressImage size].width)
    {
      progressOrigin = 0.0;
    }
    else
    {
      progressOrigin += 1.0;
    }

    NSRect drawRect = [self _getProgressFrame];
    drawRect.origin.x -= progressOrigin;
    drawRect.size.width += progressOrigin;

    if (progressImage == nil)
    {
      [self updateImages];
    }

    [self lockFocus];
    [progressImage tileInRect: drawRect];
    [self unlockFocus];
    }

    tileInRect: simply tiles the image side ways across the rect and seems
    to work fine. But the trouble seems to be that the drawRect.size.width
    += progressOrigin; is not working. Even though I've NSLogged it and it
    does increase in size. But if I comment it out nothing changes, it
    still doesn't draw correctly. This "drawing trouble" is that the
    rectangle seems to move over because on screen the picture does but
    the last picture "smears." It looks like the picture is drawn on top
    of itself but 1 pixel over to the left each time. I don't want that
    smeary look. Instead of that smear should appear the edge of another
    picture, same as the rest, and slide with the others.

    Below is - (void)tileInRect:(NSRect)rect for completeness.

    - (void)tileInRect:(NSRect)rect
    {
    float origin = rect.origin.x;
    float width = [self size].width;

    NSRect bounds = NSMakeRect(0, 0, [self size].width, [self size].height);

    while (origin <= (NSWidth(rect) + rect.origin.x))
    {
      [self drawInRect: NSMakeRect(origin, 0, width, NSHeight(rect))
    fromRect: bounds operation: NSCompositeSourceOver fraction: 1.0];

      origin += width;
    }
    }

    I will *greatly* appreciate help. Note that I'm not putting my code up
    for critue but simply to resolve my current problem.
    Peace, Alan
    --
    // Quotes from yours truly -------------------------
    "You don't forget, you just don't remember."
    "Maturity resides in the mind."
    "Silence is the Universe's greatest gift."
  • You shouldn't be overriding private calls. Even if you can get it to
    work now, it will probably break in the future when Apple makes changes
    to their implementation.
    I think you should try a different approach.

    Alan Smith wrote:
    > I've made a subclass of NSProgressIndicator and it works very well,
    > except for the "scrolling" effect that it usually has. Here is my
    > code:
    >
    > - (void)_drawProgressArea
    > {
    > if (progressOrigin >= [progressImage size].width)
    > {
    > progressOrigin = 0.0;
    > }
    > else
    > {
    > progressOrigin += 1.0;
    > }
    >
    > NSRect drawRect = [self _getProgressFrame];
    > drawRect.origin.x -= progressOrigin;
    > drawRect.size.width += progressOrigin;
    >
    > if (progressImage == nil)
    > {
    > [self updateImages];
    > }
    >
    > [self lockFocus];
    > [progressImage tileInRect: drawRect];
    > [self unlockFocus];
    > }
    >
    > tileInRect: simply tiles the image side ways across the rect and seems
    > to work fine. But the trouble seems to be that the drawRect.size.width
    > += progressOrigin; is not working. Even though I've NSLogged it and it
    > does increase in size. But if I comment it out nothing changes, it
    > still doesn't draw correctly. This "drawing trouble" is that the
    > rectangle seems to move over because on screen the picture does but
    > the last picture "smears." It looks like the picture is drawn on top
    > of itself but 1 pixel over to the left each time. I don't want that
    > smeary look. Instead of that smear should appear the edge of another
    > picture, same as the rest, and slide with the others.
    >
    > Below is - (void)tileInRect:(NSRect)rect for completeness.
    >
    > - (void)tileInRect:(NSRect)rect
    > {
    > float origin = rect.origin.x;
    > float width = [self size].width;
    >
    > NSRect bounds = NSMakeRect(0, 0, [self size].width, [self
    > size].height);
    >
    > while (origin <= (NSWidth(rect) + rect.origin.x))
    > {
    > [self drawInRect: NSMakeRect(origin, 0, width, NSHeight(rect))
    > fromRect: bounds operation: NSCompositeSourceOver fraction: 1.0];
    >
    > origin += width;
    > }
    > }
    >
    > I will *greatly* appreciate help. Note that I'm not putting my code up
    > for critue but simply to resolve my current problem.
    > Peace, Alan
  • What would you suggest?

    On 9/30/06, John Stiles <JStiles...> wrote:
    > You shouldn't be overriding private calls. Even if you can get it to
    > work now, it will probably break in the future when Apple makes changes
    > to their implementation.
    > I think you should try a different approach.
    >
    > Alan Smith wrote:
    >> I've made a subclass of NSProgressIndicator and it works very well,
    >> except for the "scrolling" effect that it usually has. Here is my
    >> code:
    >>
    >> - (void)_drawProgressArea
    >> {
    >> if (progressOrigin >= [progressImage size].width)
    >> {
    >> progressOrigin = 0.0;
    >> }
    >> else
    >> {
    >> progressOrigin += 1.0;
    >> }
    >>
    >> NSRect drawRect = [self _getProgressFrame];
    >> drawRect.origin.x -= progressOrigin;
    >> drawRect.size.width += progressOrigin;
    >>
    >> if (progressImage == nil)
    >> {
    >> [self updateImages];
    >> }
    >>
    >> [self lockFocus];
    >> [progressImage tileInRect: drawRect];
    >> [self unlockFocus];
    >> }
    >>
    >> tileInRect: simply tiles the image side ways across the rect and seems
    >> to work fine. But the trouble seems to be that the drawRect.size.width
    >> += progressOrigin; is not working. Even though I've NSLogged it and it
    >> does increase in size. But if I comment it out nothing changes, it
    >> still doesn't draw correctly. This "drawing trouble" is that the
    >> rectangle seems to move over because on screen the picture does but
    >> the last picture "smears." It looks like the picture is drawn on top
    >> of itself but 1 pixel over to the left each time. I don't want that
    >> smeary look. Instead of that smear should appear the edge of another
    >> picture, same as the rest, and slide with the others.
    >>
    >> Below is - (void)tileInRect:(NSRect)rect for completeness.
    >>
    >> - (void)tileInRect:(NSRect)rect
    >> {
    >> float origin = rect.origin.x;
    >> float width = [self size].width;
    >>
    >> NSRect bounds = NSMakeRect(0, 0, [self size].width, [self
    >> size].height);
    >>
    >> while (origin <= (NSWidth(rect) + rect.origin.x))
    >> {
    >> [self drawInRect: NSMakeRect(origin, 0, width, NSHeight(rect))
    >> fromRect: bounds operation: NSCompositeSourceOver fraction: 1.0];
    >>
    >> origin += width;
    >> }
    >> }
    >>
    >> I will *greatly* appreciate help. Note that I'm not putting my code up
    >> for critue but simply to resolve my current problem.
    >> Peace, Alan
    >

    --
    // Quotes from yours truly -------------------------
    "You don't forget, you just don't remember."
    "Maturity resides in the mind."
    "Silence is the Universe's greatest gift."
  • To make a suggestion, I would need to know what your ultimate goal is.

    Alan Smith wrote:
    > What would you suggest?
    >
    > On 9/30/06, John Stiles <JStiles...> wrote:
    >> You shouldn't be overriding private calls. Even if you can get it to
    >> work now, it will probably break in the future when Apple makes changes
    >> to their implementation.
    >> I think you should try a different approach.
    >>
    >> Alan Smith wrote:
    >>> I've made a subclass of NSProgressIndicator and it works very well,
    >>> except for the "scrolling" effect that it usually has. Here is my
    >>> code:
    >>>
    >>> - (void)_drawProgressArea
    >>> {
    >>> if (progressOrigin >= [progressImage size].width)
    >>> {
    >>> progressOrigin = 0.0;
    >>> }
    >>> else
    >>> {
    >>> progressOrigin += 1.0;
    >>> }
    >>>
    >>> NSRect drawRect = [self _getProgressFrame];
    >>> drawRect.origin.x -= progressOrigin;
    >>> drawRect.size.width += progressOrigin;
    >>>
    >>> if (progressImage == nil)
    >>> {
    >>> [self updateImages];
    >>> }
    >>>
    >>> [self lockFocus];
    >>> [progressImage tileInRect: drawRect];
    >>> [self unlockFocus];
    >>> }
    >>>
    >>> tileInRect: simply tiles the image side ways across the rect and seems
    >>> to work fine. But the trouble seems to be that the drawRect.size.width
    >>> += progressOrigin; is not working. Even though I've NSLogged it and it
    >>> does increase in size. But if I comment it out nothing changes, it
    >>> still doesn't draw correctly. This "drawing trouble" is that the
    >>> rectangle seems to move over because on screen the picture does but
    >>> the last picture "smears." It looks like the picture is drawn on top
    >>> of itself but 1 pixel over to the left each time. I don't want that
    >>> smeary look. Instead of that smear should appear the edge of another
    >>> picture, same as the rest, and slide with the others.
    >>>
    >>> Below is - (void)tileInRect:(NSRect)rect for completeness.
    >>>
    >>> - (void)tileInRect:(NSRect)rect
    >>> {
    >>> float origin = rect.origin.x;
    >>> float width = [self size].width;
    >>>
    >>> NSRect bounds = NSMakeRect(0, 0, [self size].width, [self
    >>> size].height);
    >>>
    >>> while (origin <= (NSWidth(rect) + rect.origin.x))
    >>> {
    >>> [self drawInRect: NSMakeRect(origin, 0, width, NSHeight(rect))
    >>> fromRect: bounds operation: NSCompositeSourceOver fraction: 1.0];
    >>>
    >>> origin += width;
    >>> }
    >>> }
    >>>
    >>> I will *greatly* appreciate help. Note that I'm not putting my code up
    >>> for critue but simply to resolve my current problem.
    >>> Peace, Alan
    >>
    >
    >
  • Ah, of course.

    My ultimate goal: To make a framework that has every basic UI widget
    in it that can be "skinned." Meaning: I can tell the widgets what
    pictures to use for their displaying.

    Peace, Alan
    --
    // Quotes from yours truly -------------------------
    "You don't forget, you just don't remember."
    "Maturity resides in the mind."
    "Silence is the Universe's greatest gift."
  • On Oct 1, 2006, at 2:44 PM, Alan Smith wrote:

    > My ultimate goal: To make a framework that has every basic UI widget
    > in it that can be "skinned." Meaning: I can tell the widgets what
    > pictures to use for their displaying.

    This will be a _huge_ undertaking.

    Many existing controls do not yet have the appropriate hooks in place
    to do this easily.  Thus, it may be the case where simple sublclasses
    of the controls/cells will not give you what you want.

    Having said that, be prepared to subclass directly off of NSControl/NS
    [Action]Cell instead.  I've done this myself for my own full-screen
    custom UI apps.  In such subclasses, be prepared to address:

    * behaviors; e.g. control tracking, keyboard events
    * bindings; make sure view-initiated changes do the right thing
    * accessibility; among other things, full keyboard access and
    integration with VoiceOver
    * resolution independence; make sure your custom images/drawings are
    scalable

    Also to consider:

    * IB palettes; to make it easy to author nibs with the custom UI

    ___________________________________________________________
    Ricky A. Sharp        mailto:<rsharp...>
    Instant Interactive(tm)  http://www.instantinteractive.com
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today