Skip to content

Commit

Permalink
Renderer: added scaling reset
Browse files Browse the repository at this point in the history
  • Loading branch information
osy86 committed Apr 22, 2019
1 parent 2c54a46 commit a3e85f1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
2 changes: 0 additions & 2 deletions Renderer/UTMRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ NS_ASSUME_NONNULL_BEGIN

- (nonnull instancetype)initWithMetalKitView:(nonnull MTKView *)mtkView;

- (IBAction)keyboardDonePressed:(UIButton *)sender;

@end

NS_ASSUME_NONNULL_END
4 changes: 2 additions & 2 deletions UTM/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1952,11 +1952,11 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="DZc-Sg-gjO" userLabel="First Responder" sceneMemberID="firstResponder"/>
<view contentMode="scaleToFill" id="H7m-pq-dCg">
<rect key="frame" x="0.0" y="0.0" width="300" height="50"/>
<rect key="frame" x="0.0" y="0.0" width="300" height="40"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="F32-dg-1Zk">
<rect key="frame" x="245" y="10" width="39" height="30"/>
<rect key="frame" x="245" y="5" width="39" height="30"/>
<state key="normal" title="Close"/>
<connections>
<action selector="keyboardDonePressed:" destination="ckC-eO-gxn" eventType="touchUpInside" id="Gwz-Os-LSp"/>
Expand Down
2 changes: 2 additions & 0 deletions Views/VMDisplayMetalViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (weak, nonatomic) IBOutlet UIView *inputAccessoryView;
@property (strong, nonatomic) UISelectionFeedbackGenerator *clickFeedbackGenerator;
@property (strong, nonatomic) UIImpactFeedbackGenerator *resizeFeedbackGenerator;
@property (nonatomic, assign) BOOL lastDisplayChangeResize;

- (IBAction)gesturePan:(UIPanGestureRecognizer *)sender;
- (IBAction)gestureTwoPan:(UIPanGestureRecognizer *)sender;
Expand All @@ -40,6 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
- (IBAction)gestureSwipeUp:(UISwipeGestureRecognizer *)sender;
- (IBAction)gestureSwipeDown:(UISwipeGestureRecognizer *)sender;
- (IBAction)keyboardDonePressed:(UIButton *)sender;
- (IBAction)changeDisplayZoom:(UIButton *)sender;

@end

Expand Down
29 changes: 28 additions & 1 deletion Views/VMDisplayMetalViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ @implementation VMDisplayMetalViewController {
UTMRenderer *_renderer;
CGPoint _lastTwoPanOrigin;
CGPoint _lastCursor;
CGFloat _keyboardViewHeight;
}

@synthesize vmScreenshot;
Expand Down Expand Up @@ -304,10 +305,11 @@ - (IBAction)gestureSwipeDown:(UISwipeGestureRecognizer *)sender {

- (void)keyboardWillShow:(NSNotification *)notification {
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
_keyboardViewHeight = keyboardSize.height;

[UIView animateWithDuration:0.3 animations:^{
CGRect f = self.view.frame;
f.origin.y = -keyboardSize.height;
f.origin.y = -self->_keyboardViewHeight;
self.view.frame = f;
}];
}
Expand All @@ -316,6 +318,7 @@ - (void)keyboardWillHide:(NSNotification *)notification {
[UIView animateWithDuration:0.3 animations:^{
CGRect f = self.view.frame;
f.origin.y = 0.0f;
self->_keyboardViewHeight = 0;
self.view.frame = f;
}];
}
Expand All @@ -332,4 +335,28 @@ - (IBAction)keyboardDonePressed:(UIButton *)sender {
[self.keyboardView resignFirstResponder];
}

#pragma mark - Resize display

- (void)resizeDisplayToFit {
CGSize viewSize = self.mtkView.drawableSize;
CGSize displaySize = self.vmRendering.displaySize;
CGSize scaled = CGSizeMake(viewSize.width / displaySize.width, viewSize.height / displaySize.height);
_renderer.viewportScale = MIN(scaled.width, scaled.height);
_renderer.viewportOrigin = CGPointMake(0, _keyboardViewHeight);
}

- (void)resetDisplay {
_renderer.viewportScale = 1.0;
_renderer.viewportOrigin = CGPointMake(0, _keyboardViewHeight);
}

- (IBAction)changeDisplayZoom:(UIButton *)sender {
if (self.lastDisplayChangeResize) {
[self resetDisplay];
} else {
[self resizeDisplayToFit];
}
self.lastDisplayChangeResize = !self.lastDisplayChangeResize;
}

@end

0 comments on commit a3e85f1

Please sign in to comment.