home *** CD-ROM | disk | FTP | other *** search
- //----------------------------------------------------------------------------------------------------
- //
- // ImageView
- //
- // Inherits From: View
- //
- // Declared In: ImageView.h
- //
- // Disclaimer
- //
- // You may freely copy, distribute and reuse this software and its
- // associated documentation. I disclaim any warranty of any kind,
- // expressed or implied, as to its fitness for any particular use.
- //
- //----------------------------------------------------------------------------------------------------
- #import "ImageView.h"
-
-
- @implementation ImageView
-
- //----------------------------------------------------------------------------------------------------
- // Private Methods
- //----------------------------------------------------------------------------------------------------
- - (NXPoint) _calculateCompositePoint
- {
- // Centers image in frame rect. (No longer used as frame becomes
- // image size when image is set).
-
- NXSize imageSize;
- NXPoint centerPoint = { 0.0, 0.0 };
-
- [image getSize: &imageSize];
-
- if ( imageSize.width < NX_WIDTH(&frame))
- centerPoint.x += (NX_WIDTH(&frame) - imageSize.width ) / 2.0;
-
- if ( imageSize.height < NX_HEIGHT(&frame))
- centerPoint.y += (NX_HEIGHT(&frame) - imageSize.height ) / 2.0;
-
- return centerPoint;
- }
-
-
- //----------------------------------------------------------------------------------------------------
- // Initialization and Free Methods
- //----------------------------------------------------------------------------------------------------
- - free
- {
- if (image) [image free];
- return [super free];
- }
-
-
- //----------------------------------------------------------------------------------------------------
- // Accessing the Image
- //----------------------------------------------------------------------------------------------------
- - image
- {
- return image;
- }
-
- - image: anImage
- {
- NXSize imageSize;
- NXRect frameRect;
-
- if (image) [image free];
- image = [anImage copy];
- [image getSize: &imageSize];
- NXSetRect (&frameRect, NX_X(&frame), NX_Y(&frame), imageSize.width, imageSize.height);
- [self setFrame: &frameRect];
- return self;
- }
-
- //----------------------------------------------------------------------------------------------------
- // Drawing
- //----------------------------------------------------------------------------------------------------
- - drawSelf: (const NXRect*) frameRect: (int) rects
- {
- NXPoint toPoint = { 0.0, 0.0 };
- NXSetColor([[self window] backgroundColor]);
- NXRectFill(&frame);
- [image composite: NX_SOVER toPoint: &toPoint];
- return self;
- }
-
-
- @end