11#if !__has_feature(objc_arc)
12#error This file must be compiled with Arc. Use -fobjc-arc flag
15#import <QuartzCore/QuartzCore.h>
16#import <Metal/Metal.h>
17#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
19#import "IGraphicsIOS_view.h"
21#include "IGraphicsCoreText.h"
25extern StaticStorage<CoreTextFontDescriptor> sFontDescriptorCache;
27@implementation IGRAPHICS_UITABLEVC
32 self.tableView = [[UITableView alloc] initWithFrame:self.view.frame];
33 self.tableView.dataSource = self;
34 self.tableView.delegate = self;
35 self.tableView.scrollEnabled = YES;
36 self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
37 self.items = [[NSMutableArray alloc] init];
39 int numItems = mMenu->NItems();
41 NSMutableString* elementTitle;
43 for (
int i = 0; i < numItems; ++i)
47 elementTitle = [[NSMutableString alloc] initWithCString:pMenuItem->GetText() encoding:NSUTF8StringEncoding];
49 if (mMenu->GetPrefix())
51 NSString* prefixString = nil;
53 switch (mMenu->GetPrefix())
55 case 1: prefixString = [NSString stringWithFormat:
@"%1d: ", i+1]; break;
56 case 2: prefixString = [NSString stringWithFormat:
@"%02d: ", i+1]; break;
57 case 3: prefixString = [NSString stringWithFormat:
@"%03d: ", i+1]; break;
60 prefixString = [NSString stringWithUTF8String:
""]; break;
63 [elementTitle insertString:prefixString atIndex:0];
66 [
self.items addObject:elementTitle];
69 [
self.view addSubview:self.tableView];
76 mGraphics = pGraphics;
82- (NSInteger) tableView:(UITableView*) tableView numberOfRowsInSection:(NSInteger) section
84 return self.items.count;
87- (NSInteger) numberOfSectionsInTableView:(UITableView*) tableView
92- (UITableViewCell*) tableView:(UITableView*) tableView cellForRowAtIndexPath:(NSIndexPath*) indexPath
94 static NSString *identifer =
@"cell";
95 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifer];
99 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
102 int cellIndex =
static_cast<int>(indexPath.row);
104 cell.textLabel.text = [NSString stringWithFormat:@"%@", self.items[indexPath.row]];
108 if (pItem->GetChecked())
109 cell.accessoryType = UITableViewCellAccessoryCheckmark;
111 cell.accessoryType = pItem->GetSubmenu() ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
113 cell.textLabel.enabled = cell.userInteractionEnabled = pItem->GetEnabled();
118- (CGFloat) tableView:(UITableView*) tableView heightForRowAtIndexPath:(NSIndexPath*) indexPath
120 int cellIndex =
static_cast<int>(indexPath.row);
124 if (pItem->GetIsSeparator())
127 return self.tableView.rowHeight;
130- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
132 int cellIndex =
static_cast<int>(indexPath.row);
136 if (pItem->GetIsSeparator())
139 return self.tableView.rowHeight;
142- (void) tableView:(UITableView*) tableView didSelectRowAtIndexPath:(NSIndexPath*) indexPath
144 int cellIndex =
static_cast<int>(indexPath.row);
151 IGRAPHICS_UITABLEVC* newViewController = [[IGRAPHICS_UITABLEVC alloc] initWithIPopupMenuAndIGraphics: pSubMenu : mGraphics];
152 [newViewController setTitle:[NSString stringWithUTF8String:CStringHasContents(pSubMenu->GetRootTitle()) ? pSubMenu->GetRootTitle() : pItem->GetText()]];
153 [
self.navigationController pushViewController:newViewController animated:YES];
158 if (pItem->GetIsChoosable())
160 [
self dismissViewControllerAnimated:YES completion:nil];
162 mMenu->SetChosenItemIdx(cellIndex);
164 if (mMenu->GetFunction())
165 mMenu->ExecFunction();
167 mGraphics->SetControlValueAfterPopupMenu(mMenu);
171- (CGSize) preferredContentSize
173 if (self.presentingViewController && self.tableView != nil)
175 CGSize tempSize = self.presentingViewController.view.bounds.size;
176 tempSize.width = 300;
177 CGSize size = [
self.tableView sizeThatFits:tempSize];
180 return [
super preferredContentSize];
184- (void) setPreferredContentSize:(CGSize)preferredContentSize
186 super.preferredContentSize = preferredContentSize;
191@implementation IGRAPHICS_VIEW
197 mGraphics = pGraphics;
198 CGRect r = CGRectMake(0.f, 0.f, (
float) pGraphics->WindowWidth(), (
float) pGraphics->WindowHeight());
199 self = [
super initWithFrame:r];
201#ifdef IGRAPHICS_METAL
202 mMTLLayer = [[CAMetalLayer alloc] init];
203 mMTLLayer.device = MTLCreateSystemDefaultDevice();
204 mMTLLayer.framebufferOnly = YES;
205 mMTLLayer.frame = self.layer.frame;
206 mMTLLayer.opaque = YES;
207 mMTLLayer.contentsScale = [UIScreen mainScreen].scale;
209 [
self.layer addSublayer: mMTLLayer];
212 self.multipleTouchEnabled = NO;
214 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackgroundNotification:) name:UIApplicationDidEnterBackgroundNotification object:nil];
215 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForegroundNotification:) name:UIApplicationWillEnterForegroundNotification object:nil];
216 mColorPickerHandlerFunc =
nullptr;
221- (void) setFrame:(CGRect) frame
223 [
super setFrame:frame];
226 CGFloat scale = [UIScreen mainScreen].scale;
230 scale = self.window.screen.scale;
232 #ifdef IGRAPHICS_METAL
233 [CATransaction begin];
234 [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
235 CGSize drawableSize = self.bounds.size;
236 [
self.layer setFrame:frame];
237 mMTLLayer.frame = self.layer.frame;
239 drawableSize.width *= scale;
240 drawableSize.height *= scale;
242 mMTLLayer.drawableSize = drawableSize;
244 [CATransaction commit];
248- (void) onTouchEvent:(ETouchEvent) eventType withTouches:(NSSet*) touches withEvent:(UIEvent*) event
250 if(mGraphics ==
nullptr)
253 NSEnumerator* pEnumerator = [[event allTouches] objectEnumerator];
256 std::vector<IMouseInfo> points;
258 while ((pTouch = [pEnumerator nextObject]))
260 CGPoint pos = [pTouch locationInView:pTouch.view];
264 auto ds = mGraphics->GetDrawScale();
267 point.ms.touchID =
reinterpret_cast<ITouchID
>(pTouch);
268 point.ms.touchRadius = [pTouch majorRadius];
270 point.x = pos.x / ds;
271 point.y = pos.y / ds;
272 CGPoint posPrev = [pTouch previousLocationInView: self];
273 point.dX = (pos.x - posPrev.x) / ds;
274 point.dY = (pos.y - posPrev.y) / ds;
276 if([touches containsObject:pTouch])
280 points.push_back(point);
286 if(eventType == ETouchEvent::Began)
287 mGraphics->OnMouseDown(points);
289 if(eventType == ETouchEvent::Moved)
290 mGraphics->OnMouseDrag(points);
292 if(eventType == ETouchEvent::Ended)
293 mGraphics->OnMouseUp(points);
295 if(eventType == ETouchEvent::Cancelled)
296 mGraphics->OnTouchCancelled(points);
299- (void) touchesBegan:(NSSet*) touches withEvent:(UIEvent*) event
301 [
self onTouchEvent:ETouchEvent::Began withTouches:touches withEvent:event];
304- (void) touchesMoved:(NSSet*) touches withEvent:(UIEvent*) event
306 [
self onTouchEvent:ETouchEvent::Moved withTouches:touches withEvent:event];
309- (void) touchesEnded:(NSSet*) touches withEvent:(UIEvent*) event
311 [
self onTouchEvent:ETouchEvent::Ended withTouches:touches withEvent:event];
314- (void) touchesCancelled:(NSSet*) touches withEvent:(UIEvent*) event
316 [
self onTouchEvent:ETouchEvent::Cancelled withTouches:touches withEvent:event];
319- (CAMetalLayer*) metalLayer
324- (void) didMoveToSuperview
326 [
super didMoveToSuperview];
329 self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(redraw:)];
330 [
self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
331 self.displayLink.preferredFramesPerSecond = mGraphics->FPS();
335 [
self.displayLink invalidate];
336 self.displayLink = nil;
340- (void) drawRect:(CGRect)rect
346 mGraphics->SetPlatformContext(UIGraphicsGetCurrentContext());
348 if (mGraphics->IsDirty(rects))
350 mGraphics->SetAllControlsClean();
351 mGraphics->Draw(rects);
356- (void) redraw:(CADisplayLink*) displayLink
359 [
self setNeedsDisplay];
361 [
self drawRect:CGRect()];
370- (BOOL) acceptsFirstResponder
375- (BOOL) canBecomeFirstResponder
380- (void) removeFromSuperview
382 [
self.displayLink invalidate];
383 self.displayLink = nil;
386 mMenuTableController = nil;
387 mMenuNavigationController = nil;
388 [mMTLLayer removeFromSuperlayer];
392- (BOOL) textFieldShouldReturn:(UITextField*) textField
394 if (textField == mTextField)
396 mGraphics->SetControlValueAfterTextEdit([[mTextField text] UTF8String]);
397 mGraphics->SetAllControlsDirty();
404- (BOOL) textField:(UITextField*) textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*) string
410 NSString* proposedText = [mTextField.text stringByReplacingCharactersInRange:range withString:string];
412 if (proposedText.length > mTextFieldLength)
415 IControl* pInTextEntry = mGraphics->GetControlInTextEntry();
423 NSMutableCharacterSet *characterSet = [[NSMutableCharacterSet alloc] init];
425 switch ( pParam->
Type() )
427 case IParam::kTypeEnum:
428 case IParam::kTypeInt:
429 case IParam::kTypeBool:
430 [characterSet addCharactersInString:@"0123456789-+"];
432 case IParam::kTypeDouble:
433 [characterSet addCharactersInString:@"0123456789.-+"];
439 if ([
string rangeOfCharacterFromSet:characterSet.invertedSet].location != NSNotFound)
447- (UIModalPresentationStyle) adaptivePresentationStyleForPresentationController:(UIPresentationController*) controller
449 return UIModalPresentationNone;
452- (BOOL) presentationControllerShouldDismiss:(UIPopoverPresentationController*) popoverPresentationController
459 mMenuTableController = [[IGRAPHICS_UITABLEVC alloc] initWithIPopupMenuAndIGraphics:&menu : mGraphics];
460 [mMenuTableController setTitle: [NSString stringWithUTF8String:menu.GetRootTitle()]];
462 mMenuNavigationController = [[UINavigationController alloc] initWithRootViewController:mMenuTableController];
464 mMenuNavigationController.modalPresentationStyle = UIModalPresentationPopover;
465 mMenuNavigationController.popoverPresentationController.sourceView = self;
466 mMenuNavigationController.popoverPresentationController.sourceRect = bounds;
468 mMenuNavigationController.popoverPresentationController.delegate = self;
470 [
self.window.rootViewController presentViewController:mMenuNavigationController animated:YES completion:nil];
475- (void) createTextEntry: (
int) paramIdx : (const
IText&) text : (const
char*) str : (
int) length : (CGRect) areaRect
480 mAlertController = [UIAlertController alertControllerWithTitle:@"Input a value:" message:@"" preferredStyle:UIAlertControllerStyleAlert];
482 __weak IGRAPHICS_VIEW* weakSelf = self;
484 void (^cancelHandler)(UIAlertAction*) = ^(UIAlertAction *action)
486 __strong IGRAPHICS_VIEW* strongSelf = weakSelf;
487 strongSelf->mGraphics->SetAllControlsDirty();
488 [strongSelf endUserInput];
491 UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:cancelHandler];
492 [mAlertController addAction:cancelAction];
494 void (^okHandler)(UIAlertAction*) = ^(UIAlertAction *action)
496 __strong IGRAPHICS_VIEW* strongSelf = weakSelf;
497 strongSelf->mGraphics->SetControlValueAfterTextEdit([[strongSelf->mTextField text] UTF8String]);
498 strongSelf->mGraphics->SetAllControlsDirty();
499 [strongSelf endUserInput];
502 UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:okHandler];
503 [mAlertController addAction:okAction];
504 [mAlertController setPreferredAction:okAction];
506 [mAlertController addTextFieldWithConfigurationHandler:^(UITextField* aTextField) {
507 __strong IGRAPHICS_VIEW* strongSelf = weakSelf;
508 strongSelf->mTextField = aTextField;
509 strongSelf->mTextFieldLength = length;
510 aTextField.delegate = strongSelf;
511 [aTextField setText:[NSString stringWithUTF8String:str]];
513 [
self.window.rootViewController presentViewController:mAlertController animated:YES completion:nil];
518 [
self becomeFirstResponder];
519 [
self.window.rootViewController dismissViewControllerAnimated:NO completion:nil];
520 [mTextField setDelegate: nil];
521 mAlertController =
nullptr;
522 mTextField =
nullptr;
523 mGraphics->ClearInTextEntryControl();
526- (void) showMessageBox: (const
char*) str : (const
char*) title : (EMsgBoxType) type : (IMsgBoxCompletionHandlerFunc) completionHandler
530 NSString* message = [NSString stringWithUTF8String:str];
531 NSString* titleNs = [NSString stringWithUTF8String:title];
533 UIAlertController* alertController = [UIAlertController alertControllerWithTitle:titleNs message:message preferredStyle:UIAlertControllerStyleAlert];
535 void (^handlerBlock)(UIAlertAction*) =
536 ^(UIAlertAction* action) {
538 if (completionHandler !=
nullptr)
540 EMsgBoxResult result = EMsgBoxResult::kCANCEL;
542 if ([action.title isEqualToString:
@"OK"])
543 result = EMsgBoxResult::kOK;
544 if ([action.title isEqualToString:
@"Cancel"])
545 result = EMsgBoxResult::kCANCEL;
546 if ([action.title isEqualToString:
@"Yes"])
547 result = EMsgBoxResult::kYES;
548 if ([action.title isEqualToString:
@"No"])
549 result = EMsgBoxResult::kNO;
550 if ([action.title isEqualToString:
@"Retry"])
551 result = EMsgBoxResult::kRETRY;
553 completionHandler(result);
558 if (type == kMB_OK || type == kMB_OKCANCEL)
560 UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:handlerBlock];
561 [alertController addAction:okAction];
564 if (type == kMB_YESNO || type == kMB_YESNOCANCEL)
566 UIAlertAction* yesAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:handlerBlock];
567 [alertController addAction:yesAction];
569 UIAlertAction* noAction = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDefault handler:handlerBlock];
570 [alertController addAction:noAction];
573 if (type == kMB_RETRYCANCEL)
575 UIAlertAction* retryAction = [UIAlertAction actionWithTitle:@"Retry" style:UIAlertActionStyleDefault handler:handlerBlock];
576 [alertController addAction:retryAction];
579 if (type == kMB_OKCANCEL || type == kMB_YESNOCANCEL || type == kMB_RETRYCANCEL)
581 UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:handlerBlock];
582 [alertController addAction:cancelAction];
585 [[NSOperationQueue mainQueue] addOperationWithBlock:^{
586 [
self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
590- (void) promptForFile: (NSString*) fileName : (NSString*) path : (EFileAction) action : (NSArray*) contentTypes : (IFileDialogCompletionHandlerFunc) completionHandler
594 mFileDialogFunc = completionHandler;
596 UIDocumentPickerViewController* vc = NULL;
597 NSURL* url = [[NSURL alloc] initFileURLWithPath:path];
599 if (action == EFileAction::Open)
601 vc = [[UIDocumentPickerViewController alloc] initForOpeningContentTypes:contentTypes asCopy:YES];
602 [vc setDirectoryURL:url];
606 vc = [[UIDocumentPickerViewController alloc] initForExportingURLs:@[url]];
609 [vc setDelegate:self];
611 [
self.window.rootViewController presentViewController:vc animated:YES completion:nil];
614- (void) promptForDirectory: (NSString*) path : (IFileDialogCompletionHandlerFunc) completionHandler
618 mFileDialogFunc = completionHandler;
620 UIDocumentPickerViewController* vc = NULL;
621 NSURL* url = [[NSURL alloc] initFileURLWithPath:path];
623 NSMutableArray* pFileTypes = [[NSMutableArray alloc] init];
624 UTType* directoryType = [UTType typeWithIdentifier:@"public.folder"];
625 [pFileTypes addObject:directoryType];
627 vc = [[UIDocumentPickerViewController alloc] initForOpeningContentTypes:pFileTypes];
628 [vc setDirectoryURL:url];
630 [vc setDelegate:self];
632 [
self.window.rootViewController presentViewController:vc animated:YES completion:nil];
635- (BOOL) promptForColor: (
IColor&) color : (const
char*) str : (IColorPickerHandlerFunc) func
639 UIColorPickerViewController* colorSelectionController = [[UIColorPickerViewController alloc] init];
641 colorSelectionController.modalPresentationStyle = UIModalPresentationPopover;
642 colorSelectionController.popoverPresentationController.delegate = self;
643 colorSelectionController.popoverPresentationController.sourceView = self;
646 mGraphics->GetMouseLocation(x, y);
647 colorSelectionController.popoverPresentationController.sourceRect = CGRectMake(x, y, 1, 1);
649 colorSelectionController.delegate = self;
650 colorSelectionController.selectedColor = ToUIColor(color);
651 colorSelectionController.supportsAlpha = YES;
653 mColorPickerHandlerFunc = func;
655 [
self.window.rootViewController presentViewController:colorSelectionController animated:YES completion:nil];
660- (void) attachGestureRecognizer: (EGestureType) type
662 UIGestureRecognizer* gestureRecognizer;
666 case EGestureType::DoubleTap:
667 case EGestureType::TripleTap:
669 gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapGesture:)];
670 [(UITapGestureRecognizer*) gestureRecognizer setNumberOfTapsRequired: type == EGestureType::DoubleTap ? 2 : 3];
671 [(UITapGestureRecognizer*) gestureRecognizer setNumberOfTouchesRequired:1];
674 case EGestureType::LongPress1:
675 case EGestureType::LongPress2:
677 gestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onLongPressGesture:)];
678 [(UILongPressGestureRecognizer*) gestureRecognizer setNumberOfTouchesRequired: type == EGestureType::LongPress1 ? 1 : 2];
681 case EGestureType::SwipeLeft:
683 gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
684 [(UISwipeGestureRecognizer*) gestureRecognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
687 case EGestureType::SwipeRight:
689 gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
690 [(UISwipeGestureRecognizer*) gestureRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
693 case EGestureType::SwipeUp:
695 gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
696 [(UISwipeGestureRecognizer*) gestureRecognizer setDirection:UISwipeGestureRecognizerDirectionUp];
699 case EGestureType::SwipeDown:
701 gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
702 [(UISwipeGestureRecognizer*) gestureRecognizer setDirection:UISwipeGestureRecognizerDirectionDown];
705 case EGestureType::Pinch:
707 gestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(onPinchGesture:)];
710 case EGestureType::Rotate:
712 gestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(onRotateGesture:)];
719 gestureRecognizer.delegate = self;
720 gestureRecognizer.cancelsTouchesInView = YES;
721 gestureRecognizer.delaysTouchesBegan = YES;
722 [
self addGestureRecognizer:gestureRecognizer];
725- (void) onTapGesture: (UITapGestureRecognizer*) recognizer
727 CGPoint p = [recognizer locationInView:self];
728 auto ds = mGraphics->GetDrawScale();
732 info.type = recognizer.numberOfTapsRequired == 2 ? EGestureType::DoubleTap : EGestureType::TripleTap;
734 mGraphics->OnGestureRecognized(info);
737- (void) onLongPressGesture: (UILongPressGestureRecognizer*) recognizer
739 CGPoint p = [recognizer locationInView:self];
740 auto ds = mGraphics->GetDrawScale();
744 if(recognizer.state == UIGestureRecognizerStateBegan)
745 info.state = EGestureState::Began;
746 else if(recognizer.state == UIGestureRecognizerStateChanged)
747 info.state = EGestureState::InProcess;
748 else if(recognizer.state == UIGestureRecognizerStateEnded)
749 info.state = EGestureState::Ended;
751 info.type = recognizer.numberOfTouchesRequired == 1 ? EGestureType::LongPress1 : EGestureType::LongPress2;
753 mGraphics->OnGestureRecognized(info);
756- (void) onSwipeGesture: (UISwipeGestureRecognizer*) recognizer
758 CGPoint p = [recognizer locationInView:self];
759 auto ds = mGraphics->GetDrawScale();
764 switch (recognizer.direction) {
765 case UISwipeGestureRecognizerDirectionLeft: info.type = EGestureType::SwipeLeft;
break;
766 case UISwipeGestureRecognizerDirectionRight: info.type = EGestureType::SwipeRight;
break;
767 case UISwipeGestureRecognizerDirectionUp: info.type = EGestureType::SwipeUp;
break;
768 case UISwipeGestureRecognizerDirectionDown: info.type = EGestureType::SwipeDown;
break;
773 mGraphics->OnGestureRecognized(info);
776- (void) onPinchGesture: (UIPinchGestureRecognizer*) recognizer
778 CGPoint p = [recognizer locationInView:self];
779 auto ds = mGraphics->GetDrawScale();
783 info.velocity = recognizer.velocity;
784 info.scale = recognizer.scale;
786 if(recognizer.state == UIGestureRecognizerStateBegan)
787 info.state = EGestureState::Began;
788 else if(recognizer.state == UIGestureRecognizerStateChanged)
789 info.state = EGestureState::InProcess;
790 else if(recognizer.state == UIGestureRecognizerStateEnded)
791 info.state = EGestureState::Ended;
793 info.type = EGestureType::Pinch;
795 mGraphics->OnGestureRecognized(info);
798- (void) onRotateGesture: (UIRotationGestureRecognizer*) recognizer
800 CGPoint p = [recognizer locationInView:self];
801 auto ds = mGraphics->GetDrawScale();
805 info.velocity = recognizer.velocity;
806 info.angle = RadToDeg(recognizer.rotation);
808 if(recognizer.state == UIGestureRecognizerStateBegan)
809 info.state = EGestureState::Began;
810 else if(recognizer.state == UIGestureRecognizerStateChanged)
811 info.state = EGestureState::InProcess;
812 else if(recognizer.state == UIGestureRecognizerStateEnded)
813 info.state = EGestureState::Ended;
815 info.type = EGestureType::Rotate;
817 mGraphics->OnGestureRecognized(info);
820-(BOOL) gestureRecognizer:(UIGestureRecognizer*) gestureRecognizer shouldReceiveTouch:(UITouch*) touch
822 CGPoint pos = [touch locationInView:touch.view];
826 auto ds = mGraphics->GetDrawScale();
828 if (mGraphics->RespondsToGesture(pos.x / ds, pos.y / ds))
837- (void) applicationDidEnterBackgroundNotification:(NSNotification*) notification
839 [
self.displayLink setPaused:YES];
842- (void) applicationWillEnterForegroundNotification:(NSNotification*) notification
844 [
self.displayLink setPaused:NO];
847- (BOOL) delaysContentTouches
852- (void) presentationControllerDidDismiss: (UIPresentationController*) presentationController
854 mGraphics->SetControlValueAfterPopupMenu(
nullptr);
857- (void) documentPicker:(UIDocumentPickerViewController*) controller didPickDocumentsAtURLs:(NSArray <NSURL*>*) urls
859 WDL_String fileName, path;
863 NSURL* pSource = urls[0];
864 NSString* pFullPath = [pSource path];
865 fileName.Set([pFullPath UTF8String]);
867 NSString* pTruncatedPath = [pFullPath stringByDeletingLastPathComponent];
871 path.Set([pTruncatedPath UTF8String]);
876 mFileDialogFunc(fileName, path);
882 mFileDialogFunc(fileName, path);
886- (void) documentPickerWasCancelled:(UIDocumentPickerViewController*) controller
888 WDL_String fileName, path;
891 mFileDialogFunc(fileName, path);
894- (void) colorPickerViewControllerDidSelectColor:(UIColorPickerViewController*) viewController;
896 if (mColorPickerHandlerFunc)
898 IColor c = FromUIColor([viewController selectedColor]);
899 mColorPickerHandlerFunc(c);
903- (void) colorPickerViewControllerDidFinish:(UIColorPickerViewController*) viewController;
905 mColorPickerHandlerFunc =
nullptr;
908- (void) traitCollectionDidChange: (UITraitCollection*) previousTraitCollection
910 [
super traitCollectionDidChange: previousTraitCollection];
914 mGraphics->OnAppearanceChanged([self.traitCollection userInterfaceStyle] == UIUserInterfaceStyleDark ? EUIAppearance::Dark
915 : EUIAppearance::Light);
919- (void) getLastTouchLocation: (
float&) x : (
float&) y
921 const float scale = mGraphics->GetDrawScale();
This file contains the base IControl implementation, along with some base classes for specific types ...
The lowest level base class of an IGraphics control.
const IParam * GetParam(int valIdx=0) const
Get a const pointer to the IParam object (owned by the editor delegate class), associated with this c...
IGraphics platform class for IOS.
EParamType Type() const
Get the parameter's type.
Used to manage a list of rectangular areas and optimize them for drawing to the screen.
Used to describe a particular gesture.
Used to group mouse coordinates with mouse modifier information.
Used to manage color data, independent of draw class/platform.
IText is used to manage font and text/text entry style for a piece of text on the UI,...