Release 0.1  Copyright ã1994 by Todd Thomas.  All Wrongs Reversed.

MiscImageView

Inherits From:	MiscDragView : View : Responder : Object

Declared In:	misckit/MiscImageView.h

Protocols:	none

Class Description

MiscImageView is a simple View that allows the display of a single NXImage. If the image is too small for the view it is automatically centered; if the view is too small for the image, the image is scaled while preserving the original aspect ratio. You can also surround the view with the same border types that are used for appkit's Box class. The default is NX_BEZEL. The background color of the view is also changeable, and the default is NX_COLORLTGRAY.

Though it does inherit from DragView, it does not override any of the methods necessary to do either source or destination dragging. Therefore, used as is, it will allow an image to be set through either setImage: or setImageByFilename: only.

Instance Variables

id ivImage;
NXSize ivSize;
NXSize scaledSize;
NXColor backgroundColor;
int border;
BOOL drawBackground;

ivImage 	Pointer to an NXImage that is displayed in the view.

ivSize 	The original size of the NXImage.

scaledSize	The scaled size of the NXImage (if it is scaled).

backgroundColor	The background color of the MiscImageView.

border	The current border type surrounding the view.

drawBackground	Determines if the background is drawn along with the image.

Method Types

Initializing a MiscImageView	± initFrame:

Setting an image	± setImage:
	± setImageByFilename:
	± image
	
Setting characteristics	± setBackgroundColor:
	± backgroundColor
	± setBorderType:
	± borderType
	± setDrawBackground:
	± drawBackground	
	
Displaying the view	±drawSelf::

Saving to a file	± read:
	± write:

Instance Methods

backgroundColor
- (NXColor)backgroundColor

Returns the current background color of the view.

See also:  -setBackgroundColor

borderType
- (int)borderType

Returns one of NX_NOBORDER, NX_BEZEL, NX_LINE, NX_GROOVE depending upon which is the current border surrounding the view.

See also:  -setBorderType

drawBackground
- (BOOL)drawBackground

Returns YES if during a display message, the border and the background color are drawn, along with the image.

See also:  -setDrawBackground

drawSelf
- drawSelf: (const NXRect *)rects :(int)rectcount

If drawBackground is YES, the chosen border is drawn, then the background is filled with the current color. If the image needs scaling, all the scaling is calculated, and the image is composited. I did have the scaling code in sizeTo::, but view did not seem to always call it when it was needed. I should move it though, so the scaling can be easily overridden (just in case you happen to have a better scaling algorithm). Returns self.

image
- (NXImage *)image

Returns the current image displayed in the view or nil if there is no current image.

See also:  -setImage,  -setImageByFilename

initFrame:
- initFrame: (NXRect *)frameRect

Calls super initFrame, then initializes the instance variables. The defaults are listed in the Class Description.

See also:  -awake

read:
- read:(NXTypedStream *)stream

Reads an archive MiscImageView from a stream.  

See also:  -write:

setBackgroundColor:
- setBackgroundColor: (NXColor)someColor

Sets the view's background to someColor. The view is updated immediately to reflect the change. Returns self.

See also:  -backgroundColor

setBorderType:
- setBorderType: (int)aType

Sets the border type to aType, which should be one of NX_BEZEL (the default), NX_LINE, NX_GROOVE, or NX_NOBORDER. The display method is called immediately to update any change in the border type. Returns self.

See also:  -borderType

setDrawBackground: 
- setDrawBackground: (BOOL)aBool

Sets whether or not the background and border should be drawn. This is useful if you use a method like writePSCodeInside:: and would only like to capture the image within the view. Returns self.

See also:  -drawBackground

setImage:
- setImage: (NXImage *)anImage

Sets the image to anImage if it is not nil, and frees the previous image. This method also does some messing around because of the dragImage image from MiscDragView. It tries to take care of cases where ivImage has been set to NULL (which happens when retainData is NO) but the old image still has to be freed. If anyone has any better ideas, please let me know. Returns  self.

See also:  -image

setImageByFilename
- setImageByFilename: (char *)aFilename

Allows the image to be set by giving an absolute filename. Though it uses the initFromFile: method from NXImage, which states it will accept either relative or absolute filenames, I recommend sticking to absolute, as I did have problems using relative pathnames. Returns self.

See also:  -setImage

write
- write:(NXTypedStream *)stream

Archives the MiscImageView to a stream.  

See also:  -read