Skip to content

Commit

Permalink
Refactor UI
Browse files Browse the repository at this point in the history
- Make iphone toolpanel right below screen
- Get rid of navigation controller
- Fix ipad layout issues
  • Loading branch information
Chaoji Li committed Oct 4, 2020
1 parent 1c1acbb commit 1888b61
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Resources/iDOS-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>20201001.2211</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
2 changes: 0 additions & 2 deletions dospad/Shared/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

@interface AppDelegate : SDLUIKitDelegate
{
UINavigationController *navController;
SDL_uikitopenglview *screenView;
DOSPadEmulator * emuThread;
int cycles;
int frameskip;
int maxPercent;
Expand Down
53 changes: 16 additions & 37 deletions dospad/Shared/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
#import "ZipArchive.h"
#import "UIViewController+Alert.h"

@interface AppDelegate ()
{
DOSPadBaseViewController *_emulatorController;
}
@end


@implementation AppDelegate
@synthesize frameskip;
@synthesize cycles;
Expand Down Expand Up @@ -71,7 +78,7 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
{
// TODO: show alert can not open while it's running
// quick first.
[navController alert:@"Busy"
[_emulatorController alert:@"Busy"
message:@"Can not launch the iDOS package while emulator is running. Please terminate the app first."];
return NO;
}
Expand Down Expand Up @@ -100,18 +107,7 @@ - (void)applicationWillResignActive:(UIApplication *)application

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Only when we have a DOSPadBaseViewController on the stack
// that we resume the emulator
NSArray *controllers=[navController viewControllers];
for (int i = 0; i < [controllers count]; i++)
{
UIViewController *ctrl=[controllers objectAtIndex:i];
if ([ctrl isKindOfClass:[DOSPadBaseViewController class]])
{
dospad_resume();
break;
}
}
dospad_resume();
}

- (void)applicationDidEnterBackground:(UIApplication *)application
Expand Down Expand Up @@ -209,12 +205,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
error: &activationErr];

screenView = [[SDL_uikitopenglview alloc] initWithFrame:CGRectMake(0,0,640,400)];
DOSPadBaseViewController *dospad = [DOSPadBaseViewController dospadController];
dospad.screenView = screenView;
navController = [[UINavigationController alloc] initWithRootViewController:dospad];
navController.navigationBar.barStyle = UIBarStyleBlack;
navController.navigationBar.translucent=YES;
uiwindow.rootViewController = navController;
_emulatorController = [DOSPadBaseViewController dospadController];
_emulatorController.screenView = screenView;
uiwindow.rootViewController = _emulatorController;
[uiwindow makeKeyAndVisible];
[super applicationDidFinishLaunching:application];
#ifdef THREADED
Expand All @@ -241,28 +234,14 @@ -(void)setWindowTitle:(char *)title
sprintf(buf, "%4d", cycles);
maxPercent = 0;
}
NSArray *controllers=[navController viewControllers];
for (int i = 0; i < [controllers count]; i++) {
UIViewController *ctrl=[controllers objectAtIndex:i];
if ([ctrl respondsToSelector:@selector(updateCpuCycles:)]) {
[ctrl performSelector:@selector(updateCpuCycles:) withObject:@(buf)];
}
if ([ctrl respondsToSelector:@selector(updateFrameskip:)]) {
[ctrl performSelector:@selector(updateFrameskip:)
withObject:[NSNumber numberWithInt:frameskip]];
}
}

[_emulatorController updateCpuCycles:@(buf)];
[_emulatorController updateFrameskip:@(frameskip)];
}

-(void)onLaunchExit
{
NSArray *controllers=[navController viewControllers];
for (int i = 0; i < [controllers count]; i++) {
UIViewController *ctrl=[controllers objectAtIndex:i];
if ([ctrl respondsToSelector:@selector(onLaunchExit)]) {
[ctrl performSelectorOnMainThread:@selector(onLaunchExit) withObject:nil waitUntilDone:NO];
}
}
[_emulatorController onLaunchExit];
}

@end
4 changes: 4 additions & 0 deletions dospad/Shared/DOSPadBaseViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ typedef enum {
- (void)createMouseButtons;
- (void)createPianoKeyboard;
- (CGRect)putScreen:(CGRect)availRect;
-(void)updateFrameskip:(NSNumber*)skip;
-(void)updateCpuCycles:(NSString*)title;
- (void)updateScreen;

@end
34 changes: 20 additions & 14 deletions dospad/Shared/DOSPadBaseViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ @implementation DOSPadBaseViewController
@synthesize autoExit;
@synthesize screenView;

- (void)updateScreen
{
NSAssert(FALSE, @"Must be implemented by subclass");
}


// MARK: opengles view delegate
// Screen Resize
-(void)onResize:(CGSize)sizeNew
{
self.screenView.bounds = CGRectMake(0, 0, sizeNew.width, sizeNew.height);
[self updateScreen];
}

// scale the screen view to fill the available rect,
// and keep it at 4:3 unless it's a wide screen (16:10).
// Return the occupied rect.
Expand All @@ -65,8 +79,8 @@ - (CGRect)putScreen:(CGRect)availRect
{
h = w * 3 / 4;
}
self.screenView.center = CGPointMake(cx, cy);
self.screenView.transform = CGAffineTransformMakeScale(w/sw,h/sh);
self.screenView.center = CGPointMake(cx, cy);
return CGRectMake(cx-w/2, cy-h/2, w, h);
}

Expand Down Expand Up @@ -150,14 +164,7 @@ - (void)viewDidLoad
holdIndicator = [[HoldIndicator alloc] initWithFrame:CGRectMake(0,0,100,100)];
holdIndicator.alpha = 0;
//holdIndicator.transform = CGAffineTransformMakeScale(1.5, 1.5);
[self.view addSubview:holdIndicator];

#ifdef IDOS
self.title = @"iDOS";
#else
self.title = @"DOSpad";
#endif

// [self.view addSubview:holdIndicator];

/* TODO: LITCHIE commented out by TVD
vk = [[VKView alloc] initWithFrame:CGRectMake(0,0,1,1)];
Expand Down Expand Up @@ -310,11 +317,6 @@ - (MouseRightClickMode)currentRightClickMode
}
}

-(void)onResize:(CGSize)sizeNew
{
NSLog(@"Warning: onResize not implemented");
}

-(void)updateFrameskip:(NSNumber*)skip
{
NSLog(@"Warning: updateFrameSkip not implemented");
Expand Down Expand Up @@ -652,6 +654,10 @@ - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)butto

// MARK: DOSEmulatorDelegate

- (void)emulatorWillStart:(DOSPadEmulator *)emulator
{
}

- (void)emulator:(DOSPadEmulator *)emulator saveScreenshot:(NSString *)path
{
UIImage *image = [self.screenView capture];
Expand Down
1 change: 1 addition & 0 deletions dospad/Shared/DOSPadEmulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

@protocol DOSPadEmulatorDelegate

- (void)emulatorWillStart:(DOSPadEmulator*)emulator;
- (void)emulator:(DOSPadEmulator*)emulator saveScreenshot:(NSString*)path;
- (void)emulator:(DOSPadEmulator *)emulator open:(NSString*)path;

Expand Down
5 changes: 5 additions & 0 deletions dospad/Shared/DOSPadEmulator.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ - (void)start
// Initalize command history
dospad_init_history();

if (_delegate)
{
[_delegate emulatorWillStart:self];
}

//NSLog(@"Start dosbox in new thread");
started = YES;
[NSThread detachNewThreadSelector:@selector(run) toTarget:self withObject:nil];
Expand Down
64 changes: 31 additions & 33 deletions dospad/iPad/DosPadViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -391,29 +391,28 @@ - (GamePadView*)createGamepadHelper:(GamePadMode)mod
[gpad insertSubview:right atIndex:0];
}

// Make adjustment for screen sizes that are not 768x1024 or 1024x768
// Shift all down towards the bottom,
// and pull right part towards the right edge.
#if 0
CGPoint leftPartOffset = CGPointMake(0, self.view.bounds.size.height - 1024);
CGPoint rightPartOffset = CGPointMake(self.view.bounds.size.width - 768,
self.view.bounds.size.height - 1024);
for (UIView *v in gpad.subviews)
{
if (v.center.x < (isPortrait?768:1024)/2) // left
{
v.frame = CGRectOffset(v.frame, leftPartOffset.x, leftPartOffset.y);
}
else
{
v.frame = CGRectOffset(v.frame, rightPartOffset.x, rightPartOffset.y);
}
}
#endif

gpad.mode = mod;
if (isPortrait)
{
// Make adjustment for screen sizes that are not 768x1024 or 1024x768
// Shift all down towards the bottom,
// and pull right part towards the right edge.
CGPoint leftPartOffset = CGPointMake(0, self.view.bounds.size.height - 1024);
CGPoint rightPartOffset = CGPointMake(self.view.bounds.size.width - 768,
self.view.bounds.size.height - 1024);
for (UIView *v in gpad.subviews)
{
if (v.center.x < (isPortrait?768:1024)/2) // left
{
v.frame = CGRectOffset(v.frame, leftPartOffset.x, leftPartOffset.y);
}
else
{
v.frame = CGRectOffset(v.frame, rightPartOffset.x, rightPartOffset.y);
}
}

[self.view addSubview:gpad];
}
else
Expand Down Expand Up @@ -469,6 +468,16 @@ - (void)updateBackground
[self updateBackground:self.interfaceOrientation];
}

- (void)updateScreen
{
CGFloat vw = self.view.bounds.size.width;
CGFloat vh = self.view.bounds.size.height;

if ([self isFullscreen])
[self putScreen:CGRectMake(0, 0, vw, shouldShrinkScreen ? vh-260 : vh)];
else
[self putScreen:CGRectMake(64, 78, 640, 480)];
}

- (void)updateUI
{
Expand Down Expand Up @@ -502,8 +511,8 @@ - (void)updateUI
[baseView insertSubview:self.screenView atIndex:0];
baseView.alpha = 1;
// Scaling baseView to fill self.view as much as possible
if (baseView.bounds.size.width != self.view.bounds.size.width ||
baseView.bounds.size.height != self.view.bounds.size.height)
// if (baseView.bounds.size.width != self.view.bounds.size.width ||
// baseView.bounds.size.height != self.view.bounds.size.height)
{
float scaleX = self.view.bounds.size.width/baseView.bounds.size.width;
float scaleY = self.view.bounds.size.height/baseView.bounds.size.height;
Expand Down Expand Up @@ -539,10 +548,7 @@ - (void)updateUI
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self updateBackground];
[self updateAlpha];
[self onResize:self.screenView.bounds.size];
[self refreshFullscreenPanel];
[self updateUI];
//[vk becomeFirstResponder]; TODO Litchie commented out by tvd
}

Expand Down Expand Up @@ -624,14 +630,6 @@ - (void)viewDidUnload {
// e.g. self.myOutlet = nil;
}



-(void)onResize:(CGSize)sizeNew
{
self.screenView.bounds = CGRectMake(0, 0, sizeNew.width, sizeNew.height);
[self updateUI];
}

- (void)didFloatingView:(FloatingView *)fltView
{
if ([fltView tag] == TAG_CMD) {
Expand Down
28 changes: 21 additions & 7 deletions dospad/iPhone/DosPadViewController_iPhone.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ - (void)initUI
banner.textColor = [UIColor whiteColor];
banner.textAlignment = NSTextAlignmentCenter;
banner.alpha = 0;
[_rootContainer addSubview:banner];
// [_rootContainer addSubview:banner];

//---------------------------------------------------
// 8. Navigation Bar Show Button
//---------------------------------------------------
#ifdef IDOS
#if 0
if (!autoExit)
{
UIButton *btnTop = [[UIButton alloc] initWithFrame:CGRectMake(0,0,viewRect.size.width,30)];
Expand Down Expand Up @@ -467,6 +467,7 @@ - (GamePadView*)createGamepadHelper:(GamePadMode)mod
if (r.size.height - grect.origin.y > maxHeight)
grect.origin.y = r.size.height - maxHeight;
gpad.frame = grect;
NSAssert(toolPanel.superview == _rootContainer, @"Bad tool panel state");
[_rootContainer insertSubview:gpad belowSubview:toolPanel];
}
else
Expand Down Expand Up @@ -558,18 +559,31 @@ - (void)updateUI
[self updateAlpha];
}

- (void)emulatorWillStart:(DOSPadEmulator *)emulator
{
[self updateUI];
}

// Place toolpanel right below the screen view
- (void)updateToolpanel
{
CGRect screenRect = [_rootContainer convertRect:self.screenView.frame fromView:self.view];
CGFloat scale = screenRect.size.width / toolPanel.bounds.size.width;
CGFloat cx = CGRectGetMidX(screenRect);
CGFloat cy = CGRectGetMaxY(screenRect) + toolPanel.bounds.size.height*scale/2;
toolPanel.center = CGPointMake(cx,cy);
toolPanel.transform = CGAffineTransformMakeScale(scale,scale);
toolPanel.alpha = 1;
}

-(void)updateScreen
{
CGRect viewRect = [self safeRootRect];

if ([self isPortrait])
{
CGRect screenRect = [self putScreen:CGRectMake(viewRect.origin.x, viewRect.origin.y,
viewRect.size.width, viewRect.size.width*3/4)];
CGRect rect = toolPanel.frame ;
rect.origin.x = viewRect.origin.x + (viewRect.size.width-rect.size.width)/2;
rect.origin.y = viewRect.origin.y + screenRect.size.height;
toolPanel.frame = rect;
[self updateToolpanel];
}
else
{
Expand Down

0 comments on commit 1888b61

Please sign in to comment.