fix SonarPen for iOS
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
openURL:(NSURL *)url
|
||||
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options;
|
||||
- (float)sonarpen_pressure;
|
||||
- (bool)sonarpen_present;
|
||||
- (void)hockeyapp_crash;
|
||||
- (void)sonarpen_start;
|
||||
@end
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
@interface AppDelegate () {
|
||||
GameViewController* view;
|
||||
WTSonarPenDriver* sonarpen_driver;
|
||||
bool sonarpen_started;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -35,6 +36,11 @@
|
||||
[MSCrashes generateTestCrash];
|
||||
}
|
||||
|
||||
- (bool)sonarpen_present
|
||||
{
|
||||
return sonarpen_started && [sonarpen_driver isPenAttached];
|
||||
}
|
||||
|
||||
- (float)sonarpen_pressure
|
||||
{
|
||||
return [sonarpen_driver isPenAttached] ? [sonarpen_driver pressure] : 1.f;
|
||||
@@ -46,29 +52,41 @@
|
||||
case WTSonarPenDriverStateInit:
|
||||
NSLog(@"Status: Initializing"); break;
|
||||
case WTSonarPenDriverStateRunning:
|
||||
NSLog(@"Status: Running"); break;
|
||||
NSLog(@"Status: Running");
|
||||
App::I->message_box("SonarPen", "Your SonarPen is now ready. Have fun!");
|
||||
break;
|
||||
case WTSonarPenDriverStateCalibrating:
|
||||
NSLog(@"Status: Calibrating"); break;
|
||||
case WTSonarPenDriverStateNotSonarPen:
|
||||
NSLog(@"Status: Not a Sonar Pen"); break;
|
||||
NSLog(@"Status: Not a Sonar Pen");
|
||||
App::I->message_box("SonarPen Error", "Couldn't recognize the device attatched to the jack plug as a SonarPen. Please remove it and plug it back in.");
|
||||
break;
|
||||
case WTSonarPenDriverStateCalibratingMax:
|
||||
NSLog(@"Status: Calibrating Max Value"); break;
|
||||
case WTSonarPenDriverStateWaitingForPermission:
|
||||
NSLog(@"Status: Wait for Permission"); break;
|
||||
case WTSonarPenDriverStateNoMicrophonePermission:
|
||||
NSLog(@"Status: No Microphone Permission"); break;
|
||||
NSLog(@"Status: No Microphone Permission");
|
||||
App::I->message_box("SonarPen Error", "SonarPen could not be started because you didn't allow the microphone permission. Please go to Settings -> PanoPainter and enable Microphone.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)sonarpen_start {
|
||||
if (sonarpen_started)
|
||||
return;
|
||||
sonarpen_driver = [[WTSonarPenDriver alloc] initWithApplication:[UIApplication sharedApplication]];
|
||||
[sonarpen_driver start];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(penStatusChanged) name:WTSonarPenDriverStateChangedNotification object:nil];
|
||||
sonarpen_started = true;
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
//[[BITHockeyManager sharedHockeyManager] configureWithIdentifier:@"c2dccca196294ecca8fd5d58af2738cf"];
|
||||
sonarpen_started = false;
|
||||
[MSAppCenter start:@"c2dccca1-9629-4ecc-a8fd-5d58af2738cf" withServices:@[
|
||||
[MSAnalytics class],
|
||||
[MSCrashes class]
|
||||
]];
|
||||
// sonarpen_driver = [[WTSonarPenDriver alloc] initWithApplication:application];
|
||||
// [sonarpen_driver start];
|
||||
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(penStatusChanged) name:WTSonarPenDriverStateChangedNotification object:nil];
|
||||
|
||||
view = (GameViewController*)self.window.rootViewController;
|
||||
return YES;
|
||||
|
||||
@@ -342,11 +342,19 @@ std::set<UITouch*> ignored_touch;
|
||||
CGPoint touchLocation = [touch locationInView:self.view];
|
||||
float scale = self.view.contentScaleFactor;
|
||||
|
||||
kEventSource source = touch.type == UITouchType::UITouchTypeStylus ? kEventSource::Stylus : kEventSource::Touch;
|
||||
if (source == kEventSource::Stylus)
|
||||
float force = touch.force;
|
||||
AppDelegate* app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
|
||||
if ([app sonarpen_present])
|
||||
force = [app sonarpen_pressure];
|
||||
|
||||
kEventSource source = ((touch.type == UITouchType::UITouchTypeStylus) || [app sonarpen_present]) ?
|
||||
kEventSource::Stylus : kEventSource::Touch;
|
||||
|
||||
// apple pencil
|
||||
if (touch.type == UITouchType::UITouchTypeStylus)
|
||||
pen_down = true;
|
||||
|
||||
App::I->ui_task_async([touchLocation, scale, f=touch.force, source] {
|
||||
App::I->ui_task_async([touchLocation, scale, f=force, source] {
|
||||
App::I->mouse_down(0, touchLocation.x * scale, touchLocation.y * scale, f, source, 0);
|
||||
});
|
||||
t_count = 1;
|
||||
@@ -394,7 +402,7 @@ std::set<UITouch*> ignored_touch;
|
||||
App::I->ui_task_async([tt0=t0.type,tt1=t1.type,p0,p1,f0=t0.force,f1=t1.force] {
|
||||
if (tt0 == UITouchType::UITouchTypeStylus)
|
||||
App::I->mouse_move(p0.x, p0.y, f0, kEventSource::Stylus, 0);
|
||||
if (tt1 == UITouchType::UITouchTypeStylus)
|
||||
else if (tt1 == UITouchType::UITouchTypeStylus)
|
||||
App::I->mouse_move(p1.x, p1.y, f1, kEventSource::Stylus, 0);
|
||||
});
|
||||
}
|
||||
@@ -416,8 +424,9 @@ std::set<UITouch*> ignored_touch;
|
||||
UITouch *touch = valid_touches[0];
|
||||
CGPoint touchLocation = [touch locationInView:self.view];
|
||||
float force = touch.type == UITouchType::UITouchTypeStylus ? touch.force : 1.0f;
|
||||
//AppDelegate* app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
|
||||
//force = [app sonarpen_pressure];
|
||||
AppDelegate* app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
|
||||
if ([app sonarpen_present])
|
||||
force = [app sonarpen_pressure];
|
||||
if (t_count == 2)
|
||||
{
|
||||
//App::I->gesture_end();
|
||||
@@ -425,7 +434,8 @@ std::set<UITouch*> ignored_touch;
|
||||
}
|
||||
else
|
||||
{
|
||||
kEventSource source = touch.type == UITouchType::UITouchTypeStylus ? kEventSource::Stylus : kEventSource::Touch;
|
||||
kEventSource source = ((touch.type == UITouchType::UITouchTypeStylus) || [app sonarpen_present]) ?
|
||||
kEventSource::Stylus : kEventSource::Touch;
|
||||
App::I->ui_task_async([touchLocation, scale, source, force] {
|
||||
App::I->mouse_move(touchLocation.x * scale, touchLocation.y * scale, force, source, 0);
|
||||
});
|
||||
@@ -480,6 +490,7 @@ std::set<UITouch*> ignored_touch;
|
||||
input_enabled = NO;
|
||||
App::I = new App;
|
||||
App::I->ios_view = self;
|
||||
App::I->ios_app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
|
||||
App::I->initLog();
|
||||
|
||||
//self.preferredFramesPerSecond = 60;
|
||||
|
||||
@@ -245,6 +245,10 @@
|
||||
<icon icon="arrow_rotate_clockwise" width="20"/>
|
||||
<text id="menu-label" text="Reset Camera" margin="0 0 0 5"/>
|
||||
</button-custom>
|
||||
<button-custom os="ios" id="sonarpen" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
|
||||
<icon icon="pencil" width="20"/>
|
||||
<text id="menu-label" text="Start SonarPen" margin="0 0 0 5"/>
|
||||
</button-custom>
|
||||
</popup-menu>
|
||||
</layout>
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#if defined(__OBJC__) && defined(__IOS__)
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "GameViewController.h"
|
||||
#import "AppDelegate.h"
|
||||
#endif
|
||||
|
||||
#if defined(__OBJC__) && defined(__OSX__)
|
||||
@@ -152,6 +153,7 @@ public:
|
||||
|
||||
#if defined(__IOS__) && defined(__OBJC__)
|
||||
GameViewController* ios_view;
|
||||
AppDelegate* ios_app;
|
||||
#elif defined(__OSX__) && defined(__OBJC__)
|
||||
View* osx_view;
|
||||
AppOSX* osx_app;
|
||||
|
||||
@@ -1012,6 +1012,13 @@ void App::init_menu_tools()
|
||||
popup_exp->destroy();
|
||||
};
|
||||
|
||||
#if __IOS__
|
||||
popup_exp->find<NodeButtonCustom>("sonarpen")->on_click = [this, popup_exp](Node*) {
|
||||
[ios_app sonarpen_start];
|
||||
popup_exp->mouse_release();
|
||||
popup_exp->destroy();
|
||||
};
|
||||
#endif
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,8 @@ bool Asset::create_dir(const std::string& path)
|
||||
return android_create_dir(path);
|
||||
#elif __IOS__ || __OSX__
|
||||
return apple_create_dir(path);
|
||||
else
|
||||
#else
|
||||
// TODO: implement for linux and web
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user