Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Background being inherited?!

Background being inherited?!
Thread Tools
artOf...
Fresh-Faced Recruit
Join Date: Sep 2009
Status: Offline
Reply With Quote
Sep 19, 2009, 06:31 AM
 
Hi all,

the question might seem unclear or too simple at first, so I will elaborate.
In my application I have a window with certain background color, I have put a custom view in the upper area of the window. After that I wrote a class 'DrawBackground' subclassing NSView(in IB I specified the custom view's class to be 'DrawBackground'). This class simply overwrites the method '-drawRect' and places a background picture on the entire area of the custom view. On this custom view I place 10-15 NSImageViews with transparent background color. Everything worked just fine until I decided to attach a timer to one of the pictures and make it animate(I change 2-3 different images via the timer tick: method). This made the background area of the the animated picture, to inherit the background image of the custom view in smaller scale.
Here are some screen shots:

http://i26.tinypic.com/auazpy.jpg //no custom view, no background => no bug(Animation state1)
http://i28.tinypic.com/2u5ximr.jpg //no custom view, no background => no bug(Animation state2)
http://i31.tinypic.com/33fepsy.jpg // custom view with background => bug(Animation state1)
http://i31.tinypic.com/52gebb.jpg // custom view with background => bug(Animation state2)

I guess my question is how can I get rid of the inherited background and just show my blinking picture as it actually is(with transparent background color).
Any suggestions will be appreciated! Thank you.

Kind Regards

artOf...
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Sep 20, 2009, 07:48 PM
 
What does it mean to attach a timer to a picture? It's hard to diagnose a bug without seeing the relevant code.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
artOf...  (op)
Fresh-Faced Recruit
Join Date: Sep 2009
Status: Offline
Reply With Quote
Sep 21, 2009, 08:15 AM
 
Thank you for your answer. Here is the code for my DrawBackground class and beneath it is the code where I use an NSTimer to change the picture in my NSImageView:

Code:
#import <Cocoa/Cocoa.h> @interface DrawBackgroundController : NSView { } @end #import "DrawBackgroundController.h" @implementation DrawBackgroundController - (id)initWithFrame: (NSRect)frame { self = [super initWithFrame:frame]; if (self) { } return self; } - (void)drawRect: (NSRect)rect { // Load the image. NSImage *anImage = [NSImage imageNamed:@"background.png"]; // Find the point at which to draw it. NSPoint backgroundCenter; backgroundCenter.x = [self bounds].size.width / 2; backgroundCenter.y = [self bounds].size.height / 2; NSPoint drawPoint = backgroundCenter; drawPoint.x -= [anImage size].width / 2; drawPoint.y -= [anImage size].height / 2; // Draw it. [anImage drawInRect:rect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0]; } @end //Both functions beneath are called from my main application controller //this function is called when the image should start animating - (void) setPicture { int lb = [[leCamera camProp] lightBalance]; if(lb > 6) { NSTimer* t1 = [NSTimer timerWithTimeInterval: 0.1 target: self selector: @selector(tick: ) userInfo: nil repeats: YES]; [self setLBTimer:t1]; [[NSRunLoop currentRunLoop] addTimer:lbTimer forMode:NSDefaultRunLoopMode]; [lbTimer fire]; } else if (lb < -6) { NSTimer* t1 = [NSTimer timerWithTimeInterval: 0.1 target: self selector: @selector(tick: ) userInfo: nil repeats: YES]; [self setLBTimer:t1]; [[NSRunLoop currentRunLoop] addTimer:lbTimer forMode:NSDefaultRunLoopMode]; [lbTimer fire]; } else { //IBOutlet NSImageView* lightBalanceImage; connected via IB, NSMutableArray* pics = [[NSMutableArray alloc] initWithCapacity:13]; // pics has most of the NSImage objects that I need for my animation [lightBalanceImage setImage: [pics objectAtIndex: (lb + 6)]]; } } //this function is called when my timer is started - (void) tick: (NSTimer*) input { indexOutOfRange++; indexOutOfRange %= 2; if([[leCamera camProp] lightBalance] > 6) { //NSMutableArray* outOfRangeNegPics = [[NSMutableArray alloc] initWithCapacity:2];, contains the rest from the NSImage objects, needed //NSMutableArray* outOfRangePosPics = [[NSMutableArray alloc] initWithCapacity:2];, contains the rest from the NSImage objects, needed [lightBalanceImage setImage:[outOfRangePosPics objectAtIndex:indexOutOfRange]]; } else if([[leCamera camProp] lightBalance] < -6) { [lightBalanceImage setImage:[outOfRangeNegPics objectAtIndex:indexOutOfRange]]; } else { [self setPicture]; } }

Hope that the qustion is clear, if anything else looks wierd I will be happy to clarify. This problem bothers me really, I think, I do something wrong... May be I should define all of the NSImages in my DrawBackground class? I am not sure, thank you.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 05:37 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,