Skip to content

Commit

Permalink
Fix the resize problem for the subset of hosts who remember window size
Browse files Browse the repository at this point in the history
  • Loading branch information
baconpaul committed Dec 15, 2018
1 parent 4dec747 commit 7784cf4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
60 changes: 41 additions & 19 deletions src/au/aulayer_cocoaui.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ @interface SurgeNSView : NSView
SurgeGUIEditor *editController;
CFRunLoopTimerRef idleTimer;
float lastScale;
NSSize underlyingUISize;
}

- (id) initWithSurge: (SurgeGUIEditor *) cont preferredSize: (NSSize) size;
- (void) doIdle;
- (void) dealloc;
- (void) setFrame:(NSRect)newSize;

@end

Expand All @@ -63,6 +65,7 @@ - (NSView *) uiViewForAudioUnit: (AudioUnit) inAudioUnit
{
// Remember we end up being called here because that's what AUCocoaUIView does in the initiation collaboration with hosts
AULOG::log( "uiViewForAudioUnit %s on %s\n", __TIME__, __DATE__ );
AULOG::log( "prefSize is %f %f\n", inPreferredSize.width, inPreferredSize.height );

SurgeGUIEditor* editController = 0;
UInt32 size = sizeof (SurgeGUIEditor *);
Expand Down Expand Up @@ -99,35 +102,33 @@ - (id) initWithSurge: (SurgeGUIEditor *) cont preferredSize: (NSSize) size
lastScale = cont->getZoomFactor() / 100.0;
if (self)
{
AULOG::log( "Opening new editor view\n" );
cont->open( self );

ERect *vr;
if (cont->getRect(&vr))
{
float zf = cont->getZoomFactor() / 100.0;
NSRect newSize = NSMakeRect (0, 0, vr->right - vr->left, vr->bottom - vr->top);
underlyingUISize = newSize.size;
[self setFrame:newSize];
}

cont->setZoomCallback( [cont,self]() {
AULOG::log( "In the Zoom Callback back in Cocoa to %d\n", cont->getZoomFactor() );
ERect *vr;
float zf = cont->getZoomFactor() / 100.0;
if (cont->getRect(&vr))
{
NSRect newSize = NSMakeRect (0, 0,
(int)( (vr->right - vr->left) * zf ),
(int)( (vr->bottom - vr->top) * zf ) );
AULOG::log( "Scalining display and unit square by %lf\n", zf );
[self scaleUnitSquareToSize:NSMakeSize( zf / lastScale, zf / lastScale )];
lastScale = zf;

AULOG::log( "Resetting window size\n" );
[self setFrame:newSize];
}

}
);
ERect *vr;
float zf = cont->getZoomFactor() / 100.0;
if (cont->getRect(&vr))
{
NSRect newSize = NSMakeRect (0, 0,
(int)( (vr->right - vr->left) * zf ),
(int)( (vr->bottom - vr->top) * zf ) );
[self scaleUnitSquareToSize:NSMakeSize( zf / lastScale, zf / lastScale )];
lastScale = zf;

[self setFrame:newSize];
}

}
);

CFTimeInterval TIMER_INTERVAL = .05; // In SurgeGUISynthesizer.h it uses 50 ms
CFRunLoopTimerContext TimerContext = {0, self, NULL, NULL, NULL};
Expand Down Expand Up @@ -161,6 +162,27 @@ - (void) dealloc
[super dealloc];
}

- (void) setFrame: (NSRect) newSize
{
/*
* I override setFrame because hosts have independent views of window sizes which are saved.
* this needs to be found when the host resizes after creation to set the zoomFactor properly.
* Teensy bit gross, but works. Seems AU Lab does this but Logic Pro does not.
*
* the other option is to make zoom a parameter but then its in a patch and that seems wrong.
*/
NSSize targetSize = newSize.size;

if( fabs( targetSize.width - underlyingUISize.width * lastScale ) > 2 )
{
// so what's my apparent ratio
float apparentZoom = targetSize.width / ( underlyingUISize.width * lastScale );
int azi = roundf( apparentZoom * 10 ) * 10; // this is a bit gross. I know the zoom is incremented by 10s
editController->setZoomFactor( azi );
}
[super setFrame:newSize];
}

@end


Expand Down
1 change: 1 addition & 0 deletions src/common/gui/SurgeGUIEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class SurgeGUIEditor : public EditorType, public IControlListener, public IKeybo
public:
void setZoomCallback( std::function< void() > f ) { zoom_callback = f; }
int getZoomFactor() { return zoomFactor; }
void setZoomFactor( int zf ) { zoomFactor = zf; zoom_callback(); }
private:
std::function< void() > zoom_callback;

Expand Down

0 comments on commit 7784cf4

Please sign in to comment.