mirror of
https://github.com/touchHLE/touchHLE.git
synced 2026-01-31 01:25:24 +01:00
Split TestApp GUI tests into multiple screens/classes
Change-Id: If98473a050bd56819f4e2ccaed1d0d7adf4731f7
This commit is contained in:
11
tests/TestApp_source/GUITestsAppDelegate.h
Normal file
11
tests/TestApp_source/GUITestsAppDelegate.h
Normal file
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "system_headers.h"
|
||||
|
||||
@interface GUITestsAppDelegate : NSObject
|
||||
- (void)setMainView:(UIView *)view;
|
||||
@end
|
||||
42
tests/TestApp_source/GUITestsAppDelegate.m
Normal file
42
tests/TestApp_source/GUITestsAppDelegate.m
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "system_headers.h"
|
||||
|
||||
#include "GUITestsAppDelegate.h"
|
||||
#include "GUITestsMainMenu.h"
|
||||
|
||||
@implementation GUITestsAppDelegate : NSObject
|
||||
UIWindow *window;
|
||||
UIView *mainView;
|
||||
|
||||
- (void)applicationDidFinishLaunching:(id)app {
|
||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||
window =
|
||||
[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
|
||||
[self setMainView:[[[GUITestsMainMenu alloc] initWithFrame:[window bounds]]
|
||||
autorelease]];
|
||||
[pool drain];
|
||||
[window makeKeyAndVisible];
|
||||
}
|
||||
|
||||
// This is a clumsy way to swap out views to switch between different sections
|
||||
// of the app. A proper implementation would probably involve UIViewController,
|
||||
// but touchHLE's implementation of it is quite incomplete. This'll do for now.
|
||||
- (void)setMainView:(UIView *)view {
|
||||
[view retain];
|
||||
[mainView removeFromSuperview];
|
||||
[mainView release];
|
||||
mainView = view;
|
||||
[window addSubview:view];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[mainView release];
|
||||
[window release];
|
||||
[super dealloc];
|
||||
}
|
||||
@end
|
||||
10
tests/TestApp_source/GUITestsCALayerTestsView.h
Normal file
10
tests/TestApp_source/GUITestsCALayerTestsView.h
Normal file
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "system_headers.h"
|
||||
|
||||
@interface GUITestsCALayerTestsView : UIView
|
||||
@end
|
||||
24
tests/TestApp_source/GUITestsCALayerTestsView.m
Normal file
24
tests/TestApp_source/GUITestsCALayerTestsView.m
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "system_headers.h"
|
||||
|
||||
#include "GUITestsCALayerTestsView.h"
|
||||
|
||||
@implementation GUITestsCALayerTestsView : UIView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
[super initWithFrame:frame];
|
||||
|
||||
UILabel *label = [[[UILabel alloc] initWithFrame:[self bounds]] autorelease];
|
||||
label.text = [NSString stringWithUTF8String:"TODO"];
|
||||
label.textAlignment = UITextAlignmentCenter;
|
||||
[self addSubview:label];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
10
tests/TestApp_source/GUITestsMainMenu.h
Normal file
10
tests/TestApp_source/GUITestsMainMenu.h
Normal file
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "system_headers.h"
|
||||
|
||||
@interface GUITestsMainMenu : UIView
|
||||
@end
|
||||
100
tests/TestApp_source/GUITestsMainMenu.m
Normal file
100
tests/TestApp_source/GUITestsMainMenu.m
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "system_headers.h"
|
||||
|
||||
#include "GUITestsAppDelegate.h"
|
||||
#include "GUITestsCALayerTestsView.h"
|
||||
#include "GUITestsMainMenu.h"
|
||||
|
||||
@implementation GUITestsMainMenu : UIView
|
||||
|
||||
UIView *ball;
|
||||
CGFloat ballXVelocity;
|
||||
CGFloat ballYVelocity;
|
||||
NSTimer *timer;
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
[super initWithFrame:frame];
|
||||
|
||||
UILabel *label = [[[UILabel alloc] initWithFrame:[self bounds]] autorelease];
|
||||
label.text = [NSString stringWithUTF8String:"hello, world! 🌏"];
|
||||
label.textAlignment = UITextAlignmentCenter;
|
||||
[self addSubview:label];
|
||||
ball = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
|
||||
ball.layer.cornerRadius = ball.frame.size.width / 2;
|
||||
ball.backgroundColor = [UIColor redColor];
|
||||
[self addSubview:ball];
|
||||
ballXVelocity = 5;
|
||||
ballYVelocity = 5;
|
||||
timer = [[NSTimer scheduledTimerWithTimeInterval:(1.0 / 60.0)
|
||||
target:self
|
||||
selector:@selector(moveBall:)
|
||||
userInfo:nil
|
||||
repeats:YES] retain];
|
||||
|
||||
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
|
||||
[button1 setTitle:[NSString stringWithUTF8String:"CALayer tests"]
|
||||
forState:UIControlStateNormal];
|
||||
[button1 setFrame:CGRectMake(40, 300, 240, 40)];
|
||||
[button1 addTarget:self
|
||||
action:@selector(goToCALayerTests)
|
||||
forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
[self addSubview:button1];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[timer invalidate];
|
||||
[timer release];
|
||||
[ball release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)moveBall:(NSTimer *)timer {
|
||||
CGRect windowFrame = [self bounds];
|
||||
CGRect ballFrame = [ball frame];
|
||||
ballFrame.origin.x += ballXVelocity;
|
||||
ballFrame.origin.y += ballYVelocity;
|
||||
CGFloat oldXVelocity = ballXVelocity;
|
||||
CGFloat oldYVelocity = ballYVelocity;
|
||||
if (CGRectGetMaxX(ballFrame) >= CGRectGetMaxX(windowFrame)) {
|
||||
ballXVelocity = -ballXVelocity;
|
||||
ballFrame.origin.x = CGRectGetMaxX(windowFrame) - ballFrame.size.width;
|
||||
} else if (CGRectGetMinX(ballFrame) <= CGRectGetMinX(windowFrame)) {
|
||||
ballXVelocity = -ballXVelocity;
|
||||
ballFrame.origin.x = CGRectGetMinX(windowFrame);
|
||||
}
|
||||
if (CGRectGetMaxY(ballFrame) >= CGRectGetMaxY(windowFrame)) {
|
||||
ballYVelocity = -ballYVelocity;
|
||||
ballFrame.origin.y = CGRectGetMaxY(windowFrame) - ballFrame.size.height;
|
||||
} else if (CGRectGetMinY(ballFrame) <= CGRectGetMinY(windowFrame)) {
|
||||
ballYVelocity = -ballYVelocity;
|
||||
ballFrame.origin.y = CGRectGetMinY(windowFrame);
|
||||
}
|
||||
if (oldXVelocity != ballXVelocity || oldYVelocity != ballYVelocity)
|
||||
ball.backgroundColor =
|
||||
[UIColor colorWithRed:(ballFrame.origin.x / windowFrame.size.width)
|
||||
green:((ballXVelocity + ballYVelocity) / 10.0 + 0.5)
|
||||
blue:(ballFrame.origin.y / windowFrame.size.height)
|
||||
alpha:1.0];
|
||||
ball.frame = ballFrame;
|
||||
}
|
||||
|
||||
- (void)goToCALayerTests {
|
||||
// break the strong reference cycle
|
||||
[timer invalidate];
|
||||
[timer release];
|
||||
timer = nil;
|
||||
|
||||
[((GUITestsAppDelegate *)[[UIApplication sharedApplication]
|
||||
delegate]) setMainView:[[[GUITestsCALayerTestsView alloc]
|
||||
initWithFrame:[self frame]] autorelease]];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -7,70 +7,12 @@
|
||||
#include "system_headers.h"
|
||||
#include <stdio.h>
|
||||
|
||||
@interface TestAppDelegate : NSObject
|
||||
@end
|
||||
@implementation TestAppDelegate : NSObject
|
||||
UIWindow *window;
|
||||
UIView *ball;
|
||||
CGFloat ballXVelocity;
|
||||
CGFloat ballYVelocity;
|
||||
- (void)applicationDidFinishLaunching:(id)app {
|
||||
window =
|
||||
[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
|
||||
UILabel *label = [[UILabel alloc] initWithFrame:[window bounds]];
|
||||
label.text = [NSString stringWithUTF8String:"hello, world! 🌏"];
|
||||
label.textAlignment = UITextAlignmentCenter;
|
||||
[window addSubview:label];
|
||||
ball = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
|
||||
ball.layer.cornerRadius = ball.frame.size.width / 2;
|
||||
ball.backgroundColor = [UIColor redColor];
|
||||
[window addSubview:ball];
|
||||
[window makeKeyAndVisible];
|
||||
|
||||
ballXVelocity = 5;
|
||||
ballYVelocity = 5;
|
||||
[NSTimer scheduledTimerWithTimeInterval:(1.0 / 60.0)
|
||||
target:self
|
||||
selector:@selector(moveBall:)
|
||||
userInfo:nil
|
||||
repeats:YES];
|
||||
}
|
||||
|
||||
- (void)moveBall:(NSTimer *)timer {
|
||||
CGRect windowFrame = [window bounds];
|
||||
CGRect ballFrame = [ball frame];
|
||||
ballFrame.origin.x += ballXVelocity;
|
||||
ballFrame.origin.y += ballYVelocity;
|
||||
CGFloat oldXVelocity = ballXVelocity;
|
||||
CGFloat oldYVelocity = ballYVelocity;
|
||||
if (CGRectGetMaxX(ballFrame) >= CGRectGetMaxX(windowFrame)) {
|
||||
ballXVelocity = -ballXVelocity;
|
||||
ballFrame.origin.x = CGRectGetMaxX(windowFrame) - ballFrame.size.width;
|
||||
} else if (CGRectGetMinX(ballFrame) <= CGRectGetMinX(windowFrame)) {
|
||||
ballXVelocity = -ballXVelocity;
|
||||
ballFrame.origin.x = CGRectGetMinX(windowFrame);
|
||||
}
|
||||
if (CGRectGetMaxY(ballFrame) >= CGRectGetMaxY(windowFrame)) {
|
||||
ballYVelocity = -ballYVelocity;
|
||||
ballFrame.origin.y = CGRectGetMaxY(windowFrame) - ballFrame.size.height;
|
||||
} else if (CGRectGetMinY(ballFrame) <= CGRectGetMinY(windowFrame)) {
|
||||
ballYVelocity = -ballYVelocity;
|
||||
ballFrame.origin.y = CGRectGetMinY(windowFrame);
|
||||
}
|
||||
if (oldXVelocity != ballXVelocity || oldYVelocity != ballYVelocity)
|
||||
ball.backgroundColor =
|
||||
[UIColor colorWithRed:(ballFrame.origin.x / windowFrame.size.width)
|
||||
green:((ballXVelocity + ballYVelocity) / 10.0 + 0.5)
|
||||
blue:(ballFrame.origin.y / windowFrame.size.height)
|
||||
alpha:1.0];
|
||||
ball.frame = ballFrame;
|
||||
}
|
||||
@end
|
||||
#include "GUITestsAppDelegate.h"
|
||||
|
||||
int TestApp_gui_tests_main(int argc, char **argv) {
|
||||
id pool = [NSAutoreleasePool new];
|
||||
int res = UIApplicationMain(argc, argv, NULL,
|
||||
NSStringFromClass([TestAppDelegate class]));
|
||||
NSStringFromClass([GUITestsAppDelegate class]));
|
||||
[pool release];
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ typedef double NSTimeInterval;
|
||||
selector:(SEL)selector
|
||||
userInfo:(id)user_info
|
||||
repeats:(BOOL)repeats;
|
||||
- (void)invalidate;
|
||||
@end
|
||||
|
||||
// Core Graphics
|
||||
@@ -164,6 +165,22 @@ typedef enum {
|
||||
UITextAlignmentRight = 2,
|
||||
} UITextAlignment;
|
||||
|
||||
typedef enum {
|
||||
UIButtonTypeRoundedRect = 1,
|
||||
} UIButtonType;
|
||||
|
||||
typedef enum {
|
||||
UIControlStateNormal = 0,
|
||||
} UIControlState;
|
||||
|
||||
typedef enum {
|
||||
UIControlEventTouchUpInside = 1 << 6,
|
||||
} UIControlEvents;
|
||||
|
||||
@interface UIApplication : NSObject
|
||||
+ (instancetype)sharedApplication;
|
||||
- (id)delegate;
|
||||
@end
|
||||
@interface UIScreen : NSObject
|
||||
+ (instancetype)mainScreen;
|
||||
- (CGRect)applicationFrame;
|
||||
@@ -197,6 +214,7 @@ typedef enum {
|
||||
- (CGRect)frame;
|
||||
- (void)setFrame:(CGRect)frame;
|
||||
- (void)addSubview:(UIView *)view;
|
||||
- (void)removeFromSuperview;
|
||||
- (void)setBackgroundColor:(UIColor *)color;
|
||||
@end
|
||||
@interface UIWindow : UIView
|
||||
@@ -206,6 +224,15 @@ typedef enum {
|
||||
- (void)setText:(NSString *)text;
|
||||
- (void)setTextAlignment:(UITextAlignment)alignment;
|
||||
@end
|
||||
@interface UIControl : UIView
|
||||
- (void)addTarget:(id)target
|
||||
action:(SEL)action
|
||||
forControlEvents:(UIControlEvents)events;
|
||||
@end
|
||||
@interface UIButton : UIControl
|
||||
+ (instancetype)buttonWithType:(UIButtonType)type;
|
||||
- (void)setTitle:(NSString *)title forState:(UIControlState)state;
|
||||
@end
|
||||
|
||||
int UIApplicationMain(int, char **, NSString *, NSString *);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user