| Article: |
Bitmap Image Filters | |
| Subject: | Centering the view. | |
| Date: | 2002-08-12 05:02:38 | |
| From: | infallible | |
|
Response to: Centering the view.
|
||
|
I am looking for a solution for that problem also. 1. Fixing lower-left corner problem is easy, just overwrite one method:
|
||
Showing messages 1 through 2 of 2.
-
Solution here:
2002-08-12 07:30:31 infallible [View]
-
Oh almost forgot
2002-08-12 07:53:03 infallible [View]
This how it should look(without that popup button ofcourse)
http://www.hot.ee/priiware/shot0001.gif
and there may be some bugs when the image width or height isn't a whole number, i fixed that problem with the round() command.
/Infallible da n00b coder



1. Make a subclass of NSScrollView
2. overwrite drawRect, its not needed, but i wanted to make gray background for the image :]. If you won't overwrite it then it will be white
- (void)drawRect:(NSRect)rect
{
[[NSColor whiteColor] set];
NSRectFill(rect);
[[NSColor grayColor] set];
NSRectFill(NSMakeRect(0,0,rect.size.width - 15,rect.size.height - 15));
[self tile];
}
hmm 15 pixels is scroller's width ofcourse, you can make the code sigtly better ofcourse. Like: float scrollerWidth = NSHeight([[self horizontalScroller] frame]);
3. overwrite (void)tile
- (void)tile
{
NSRect newContentRect = [self frame];
NSRect documentRect = [[self documentView] frame];
float scrollerWidth = NSHeight([[self horizontalScroller] frame]); // 15 pixels for normal scrollers
// assuming that both scrollers are always visible! Modify if needed :]
newContentRect = NSMakeRect(0,0,newContentRect.size.width - scrollerWidth, newContentRect.size.height - scrollerWidth);
// use if([self hasHorizontalScroller])/if([self hasVerticalScroller]) also if you need to check if the scrollView has to draw the scrollers
[[self horizontalScroller] setFrame:NSMakeRect(0,newContentRect.size.height,newContentRect.size.width,scrollerWidth)];
[[self verticalScroller] setFrame:NSMakeRect(newContentRect.size.width,0,scrollerWidth,newContentRect.size.height)];
// Now check if centering is needed at all
if( newContentRect.size.width >= documentRect.size.width )
{
newContentRect.origin.x = (newContentRect.size.width - documentRect.size.width) / 2;
newContentRect.size.width = documentRect.size.width;
}
if( newContentRect.size.height >= documentRect.size.height )
{
newContentRect.origin.y = (newContentRect.size.height - documentRect.size.height) / 2;
newContentRect.size.height = documentRect.size.height;
}
// draw the content view
[[self contentView] setFrame:newContentRect];
}
/Infallible da n00b coder