Get scale changes halfway working.

Translation is still wrong, but changing scale to (eg) 200% and back to
100% works correctly.
This commit is contained in:
Bill Currie 2010-09-21 23:07:21 +09:00
parent 380460be82
commit ad0cd004b7

View file

@ -117,75 +117,77 @@ initWithFrame:
return scale; return scale;
} }
/* - (NSRect) adjustScroll: (NSRect)newVisible
v {
*/ Sys_Printf ("newVisible: %g %g %g %g\n",
newVisible.origin.x, newVisible.origin.y,
newVisible.size.width, newVisible.size.height);
return newVisible;
}
-setOrigin:(NSPoint)pt scale:(float) sc -setOrigin:(NSPoint)pt scale:(float) sc
{ {
NSRect sframe; NSRect sframe;
NSRect newbounds; NSRect bounds;
NSClipView *cv = (NSClipView *) _super_view; NSClipView *cv = (NSClipView *) _super_view;
// // calculate the area visible in the cliprect
// calculate the area visible in the cliprect
//
scale = sc; scale = sc;
sframe = [_super_view frame]; bounds = [_super_view bounds];
newbounds = [_super_view frame]; bounds.origin = pt;
newbounds.origin = pt; bounds.size.width /= scale;
newbounds.size.width /= scale; bounds.size.height /= scale;
newbounds.size.height /= scale;
sframe.size.width /= scale;
sframe.size.height /= scale;
// // union with the realbounds
// union with the realbounds bounds = NSUnionRect (realbounds, bounds);
// sframe = bounds;
newbounds = NSUnionRect (realbounds, newbounds); sframe.origin.x *= scale;
sframe.origin.y *= scale;
sframe.size.width *= scale;
sframe.size.height *= scale;
// // redisplay everything
// redisplay everything //[self setPostsFrameChangedNotifications:NO];
// //[self setPostsBoundsChangedNotifications:NO];
// XXX[quakeed_i disableDisplay];
// // size this view
// size this view [self setFrame: sframe];
// if (_boundsMatrix) {
[self setFrameSize:newbounds.size]; //FIXME workaround for a bug in GNUstep
[self setFrameOrigin:newbounds.origin]; NSAffineTransformStruct t = [_boundsMatrix transformStruct];
// XXX[self moveTo: newbounds.origin.x : newbounds.origin.y]; t.m11 = t.m22 = 1;
[_boundsMatrix setTransformStruct: t];
}
[self setBounds: bounds];
// //[self setPostsFrameChangedNotifications:YES];
// scroll and scale the clip view //[self setPostsBoundsChangedNotifications:YES];
//
[cv setBoundsSize:sframe.size];
[cv scrollToPoint:pt];
// XXX[quakeed_i reenableDisplay]; // scroll and scale the clip view
pt.x *= scale;
pt.y *= scale;
[cv setBoundsOrigin:pt];
[scrollview_i reflectScrolledClipView: cv];
[scrollview_i display]; [scrollview_i display];
[[_super_view superview] reflectScrolledClipView: cv];
return self; return self;
} }
-centerOn:(vec3_t) org -centerOn:(vec3_t) org
{ {
NSRect sbounds; NSRect sbounds;
NSPoint mid, delta; NSPoint mid, origin;
sbounds =[[xyview_i superview] bounds]; sbounds = [_super_view bounds];
mid.x = sbounds.origin.x + sbounds.size.width / 2; mid.x = sbounds.size.width / 2;
mid.y = sbounds.origin.y + sbounds.size.height / 2; mid.y = sbounds.size.height / 2;
delta.x = org[0] - mid.x; origin.x = org[0] - mid.x / scale;
delta.y = org[1] - mid.y; origin.y = org[1] - mid.y / scale;
sbounds.origin.x += delta.x; [self setOrigin: origin scale:scale];
sbounds.origin.y += delta.y;
[self setOrigin: sbounds.origin scale:scale];
return self; return self;
} }
@ -217,39 +219,41 @@ If realbounds has shrunk, nothing will change.
*/ */
-newRealBounds:(NSRect) nb -newRealBounds:(NSRect) nb
{ {
NSRect sbounds; NSRect bounds;
NSRect sframe;
realbounds = nb; realbounds = nb;
Sys_Printf ("realbounds: %g %g %g %g\n",
realbounds.origin.x, realbounds.origin.y,
realbounds.size.width, realbounds.size.height);
// // calculate the area visible in the cliprect
// calculate the area visible in the cliprect bounds = [_super_view bounds];
// bounds.origin.x /= scale;
sbounds = [[self superview] bounds]; bounds.origin.y /= scale;
Sys_Printf ("sbounds: %g %g %g %g\n", bounds.size.width /= scale;
sbounds.origin.x, sbounds.origin.y, bounds.size.height /= scale;
sbounds.size.width, sbounds.size.height); bounds = NSUnionRect (realbounds, bounds);
sbounds = NSUnionRect (nb, sbounds); sframe = bounds;
sframe.origin.x *= scale;
sframe.origin.y *= scale;
sframe.size.width *= scale;
sframe.size.height *= scale;
// // size this view
// size this view //[self setPostsFrameChangedNotifications:NO];
// //[self setPostsBoundsChangedNotifications:NO];
// XXX[quakeed_i disableDisplay];
[self setPostsBoundsChangedNotifications:NO]; [self setFrame: sframe];
[self setFrameSize:sbounds.size]; if (_boundsMatrix) {
[self setFrameOrigin:sbounds.origin]; //FIXME workaround for a bug in GNUstep
// XXX[self moveTo: sbounds.origin.x : sbounds.origin.y]; NSAffineTransformStruct t = [_boundsMatrix transformStruct];
[self setPostsBoundsChangedNotifications:YES]; t.m11 = t.m22 = 1;
[_boundsMatrix setTransformStruct: t];
}
[self setBounds: bounds];
//[self setPostsBoundsChangedNotifications:YES];
//[self setPostsFrameChangedNotifications:YES];
[scrollview_i reflectScrolledClipView:[scrollview_i contentView]]; [scrollview_i reflectScrolledClipView:[scrollview_i contentView]];
// XXX[quakeed_i reenableDisplay];
//[[scrollview_i horizontalScroller] display];
//[[scrollview_i verticalScroller] display];
return self; return self;
} }
@ -265,7 +269,8 @@ Called when the scaler popup on the window is used
-scaleMenuTarget:sender -scaleMenuTarget:sender
{ {
char const *item; char const *item;
NSRect visrect, sframe; NSRect rect;
NSPoint mid, org, origin;
float nscale; float nscale;
item =[[[sender selectedCell] title] cString]; item =[[[sender selectedCell] title] cString];
@ -275,16 +280,18 @@ Called when the scaler popup on the window is used
if (nscale == scale) if (nscale == scale)
return NULL; return NULL;
// keep the center of the view constant // keep the center of the view constant
visrect =[[self superview] bounds]; rect = [_super_view bounds];
sframe =[[self superview] frame]; mid.x = rect.size.width / 2;
visrect.origin.x += visrect.size.width / 2; mid.y = rect.size.height / 2;
visrect.origin.y += visrect.size.height / 2;
visrect.origin.x -= sframe.size.width / 2 / nscale; org.x = (rect.origin.x + mid.x) / scale;
visrect.origin.y -= sframe.size.height / 2 / nscale; org.y = (rect.origin.y + mid.y) / scale;
[self setOrigin: visrect.origin scale:nscale]; origin.x = org.x - mid.x / nscale;
origin.y = org.y - mid.y / nscale;
[self setOrigin: origin scale:nscale];
return self; return self;
} }
@ -807,7 +814,7 @@ NSRect xy_draw_rect;
// setup for text // setup for text
// PSselectfont("Helvetica-Medium",10/scale); // PSselectfont("Helvetica-Medium",10/scale);
[[NSFont systemFontOfSize: 10 / scale] set]; [[NSFont systemFontOfSize: 10 * scale] set];
PSrotate (0); PSrotate (0);
if (drawmode == dr_texture || drawmode == dr_flat) if (drawmode == dr_texture || drawmode == dr_flat)