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 > Need Help with insering icons into my NIB file

Need Help with insering icons into my NIB file
Thread Tools
Mac Enthusiast
Join Date: Mar 2001
Location: Minneapolis, MN
Status: Offline
Reply With Quote
Jun 1, 2001, 12:10 AM
 
I'm programming a simple game of Connect Four for my OOD class (which is due in a couple of days), and would like to make it my first Obj-C program. The main question I have is simply an interface one. I would like to represent the board visually, with a square either being empty, have a red piece, or have a black piece. What is the best/easiest way to do this? Can I just make a matrix of rectangular buttons and somehow cause them to display an image that I include in a .gif or .jpg file?

Any help would be greatly appreciated, especially messages and classes necessary since that is that part of objC I am most uncomfortable with.

Many Thanks.


Crunch Something
     
tie
Professional Poster
Join Date: Feb 2001
Status: Offline
Reply With Quote
Jun 1, 2001, 01:42 AM
 
Try using tiff files. Make one big image for the board, including partially transparent shadows (love that alpha channel) and others for the pieces.
The 4 o'clock train will be a bus.
It will depart at 20 minutes to 5.
     
Mac Enthusiast
Join Date: Mar 2001
Location: Minneapolis, MN
Status: Offline
Reply With Quote
Jun 1, 2001, 09:38 AM
 
Right, but how do I do that? It's mainly the coding aspects of it that I don't know.


Thanks for your reply, though. I'm just a little stressed with the deadline for this thing.

[This message has been edited by The_Equivocator (edited 06-01-2001).]


Crunch Something
     
tie
Professional Poster
Join Date: Feb 2001
Status: Offline
Reply With Quote
Jun 1, 2001, 03:53 PM
 
Sorry with these forums down I can't help much. What I would do is put in an NSImageView in Interface Builder and then write some code like this:

<pre><font size = 1 face = courier>
IBOutlet NSImageView *view;
NSImage *redImage, *blackImage;

-&#40;<font color = green>void</font>&#41; loadImages {
redImage = [NSImage imageNamed&#58;<font color = orange>@"red.tiff"</font>];
blackImage = [NSImage imageNamed&#58;<font color = orange>@"black.tiff"</font>;
image = [NSImage imageNamed&#58;<font color = orange>@"bg.tiff"</font>]
[view setImage&#58;image];
}

-&#40;<font color = green>void</font>&#41; drawMoveAtRow&#58;&#40;<font color = green>int</font>&#41; row col&#58;&#40;<font color = green>int</font>&#41; col {
NSRect rect = [<font color = purple>self</font> rectForRow&#58;row col&#58;col];
[image lockFocus];
[redImage compositeToPoint&#58;rect.origin operation&#58;NSCompositeSourceOver];
[image unlockFocus];
[view setNeedsDisplayInRect&#58;rect];
}
</font></pre>

This draws in the coordinates of the background image, so if you set the NSImageView up properly, it will handle all the resizing for you. Anyway, these are the classes you will probably use.
The 4 o'clock train will be a bus.
It will depart at 20 minutes to 5.
     
   
Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:09 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2