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
29- (int) menuIndexFromIndexPath: (NSIndexPath*) indexPath
31 return [
self.items[indexPath.row][1] intValue];
37 self.tableView = [[UITableView alloc] initWithFrame:self.view.frame];
38 self.tableView.dataSource = self;
39 self.tableView.delegate = self;
40 self.tableView.scrollEnabled = YES;
41 self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
42 self.items = [[NSMutableArray alloc] init];
44 int numItems = mMenu->NItems();
46 NSMutableString* elementTitle;
48 for (
int i = 0; i < numItems; ++i)
52 elementTitle = [[NSMutableString alloc] initWithUTF8String: pMenuItem->GetText()];
54 if (mMenu->GetPrefix())
56 NSString* prefixString = nil;
58 switch (mMenu->GetPrefix())
60 case 1: prefixString = [NSString stringWithFormat:
@"%1d: ", i+1]; break;
61 case 2: prefixString = [NSString stringWithFormat:
@"%02d: ", i+1]; break;
62 case 3: prefixString = [NSString stringWithFormat:
@"%03d: ", i+1]; break;
65 prefixString = [NSString stringWithUTF8String:
""]; break;
68 [elementTitle insertString:prefixString atIndex:0];
71 [
self.items addObject: @[elementTitle, [NSNumber numberWithInt:i]]];
74 [
self.view addSubview:self.tableView];
81 mGraphics = pGraphics;
87- (NSInteger) tableView: (UITableView*) tableView numberOfRowsInSection : (NSInteger) section
89 return self.items.count;
92- (NSInteger) numberOfSectionsInTableView: (UITableView*) tableView
97- (UITableViewCell*) tableView: (UITableView*) tableView cellForRowAtIndexPath: (NSIndexPath*) indexPath
99 static NSString *identifer =
@"cell";
100 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifer];
104 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
107 cell.textLabel.text = [NSString stringWithFormat:@"%@", self.items[indexPath.row][0]];
109 IPopupMenu::Item* pItem = mMenu->GetItem([self menuIndexFromIndexPath:indexPath]);
111 if (pItem->GetChecked())
112 cell.accessoryType = UITableViewCellAccessoryCheckmark;
114 cell.accessoryType = pItem->GetSubmenu() ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
116 cell.textLabel.enabled = cell.userInteractionEnabled = pItem->GetEnabled();
121- (CGFloat) tableView:(UITableView*) tableView heightForRowAtIndexPath: (NSIndexPath*) indexPath
124 IPopupMenu::Item* pItem = mMenu->GetItem([self menuIndexFromIndexPath:indexPath]);
126 if (pItem->GetIsSeparator())
129 return self.tableView.rowHeight;
132- (CGFloat) tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
134 IPopupMenu::Item* pItem = mMenu->GetItem([self menuIndexFromIndexPath:indexPath]);
136 if (pItem->GetIsSeparator())
139 return self.tableView.rowHeight;
142- (void) tableView:(UITableView*) tableView didSelectRowAtIndexPath:(NSIndexPath*) indexPath
144 int menuIdx = [
self menuIndexFromIndexPath:indexPath];
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(menuIdx);
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;
189- (void) tableView: (UITableView *) tableView commitEditingStyle: (UITableViewCellEditingStyle) editingStyle forRowAtIndexPath: (NSIndexPath*) indexPath
191 if (editingStyle == UITableViewCellEditingStyleDelete)
193 mGraphics->DeleteFromPopupMenu(mMenu, [self menuIndexFromIndexPath:indexPath]);
194 [
self.items removeObjectAtIndex:indexPath.row];
195 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
199- (BOOL) tableView: (UITableView *) tableView canEditRowAtIndexPath: (NSIndexPath*) indexPath
201 return mMenu->GetItem([self menuIndexFromIndexPath:indexPath])->GetIsDeletable();
206@implementation IGRAPHICS_VIEW
212 mGraphics = pGraphics;
213 CGRect r = CGRectMake(0.f, 0.f, (
float) pGraphics->WindowWidth(), (
float) pGraphics->WindowHeight());
214 self = [
super initWithFrame:r];
216#ifdef IGRAPHICS_METAL
217 mMTLLayer = [[CAMetalLayer alloc] init];
218 mMTLLayer.device = MTLCreateSystemDefaultDevice();
219 mMTLLayer.framebufferOnly = YES;
220 mMTLLayer.frame = self.layer.frame;
221 mMTLLayer.opaque = YES;
222 mMTLLayer.contentsScale = [UIScreen mainScreen].scale;
224 [
self.layer addSublayer: mMTLLayer];
227 self.multipleTouchEnabled = NO;
229 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackgroundNotification:) name:UIApplicationDidEnterBackgroundNotification object:nil];
230 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForegroundNotification:) name:UIApplicationWillEnterForegroundNotification object:nil];
231 mColorPickerHandlerFunc =
nullptr;
233 UIHoverGestureRecognizer* hoverGestureRecognizer =
234 [[UIHoverGestureRecognizer alloc] initWithTarget:self action:@selector(onHoverGesture:)];
235 [
self addGestureRecognizer: hoverGestureRecognizer];
240- (void) setFrame:(CGRect) frame
242 [
super setFrame:frame];
245 CGFloat scale = [UIScreen mainScreen].scale;
249 scale = self.window.screen.scale;
251 #ifdef IGRAPHICS_METAL
252 [CATransaction begin];
253 [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
254 CGSize drawableSize = self.bounds.size;
255 [
self.layer setFrame:frame];
256 mMTLLayer.frame = self.layer.frame;
258 drawableSize.width *= scale;
259 drawableSize.height *= scale;
261 mMTLLayer.drawableSize = drawableSize;
263 [CATransaction commit];
267- (void) onTouchEvent:(ETouchEvent) eventType withTouches:(NSSet*) touches withEvent:(UIEvent*) event
269 if(mGraphics ==
nullptr)
272 NSEnumerator* pEnumerator = [[event allTouches] objectEnumerator];
275 std::vector<IMouseInfo> points;
277 while ((pTouch = [pEnumerator nextObject]))
279 CGPoint pos = [pTouch locationInView:pTouch.view];
283 auto ds = mGraphics->GetDrawScale();
286 point.ms.touchID =
reinterpret_cast<ITouchID
>(pTouch);
287 point.ms.touchRadius = [pTouch majorRadius];
289 point.x = pos.x / ds;
290 point.y = pos.y / ds;
291 CGPoint posPrev = [pTouch previousLocationInView: self];
292 point.dX = (pos.x - posPrev.x) / ds;
293 point.dY = (pos.y - posPrev.y) / ds;
295 if([touches containsObject:pTouch])
299 points.push_back(point);
305 if(eventType == ETouchEvent::Began)
306 mGraphics->OnMouseDown(points);
308 if(eventType == ETouchEvent::Moved)
309 mGraphics->OnMouseDrag(points);
311 if(eventType == ETouchEvent::Ended)
312 mGraphics->OnMouseUp(points);
314 if(eventType == ETouchEvent::Cancelled)
315 mGraphics->OnTouchCancelled(points);
318- (void) touchesBegan:(NSSet*) touches withEvent:(UIEvent*) event
320 [
self onTouchEvent:ETouchEvent::Began withTouches:touches withEvent:event];
323- (void) touchesMoved:(NSSet*) touches withEvent:(UIEvent*) event
325 [
self onTouchEvent:ETouchEvent::Moved withTouches:touches withEvent:event];
328- (void) touchesEnded:(NSSet*) touches withEvent:(UIEvent*) event
330 [
self onTouchEvent:ETouchEvent::Ended withTouches:touches withEvent:event];
333- (void) touchesCancelled:(NSSet*) touches withEvent:(UIEvent*) event
335 [
self onTouchEvent:ETouchEvent::Cancelled withTouches:touches withEvent:event];
338- (CAMetalLayer*) metalLayer
343- (void) didMoveToSuperview
345 [
super didMoveToSuperview];
348 self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(redraw:)];
349 [
self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
350 self.displayLink.preferredFramesPerSecond = mGraphics->FPS();
354 [
self.displayLink invalidate];
355 self.displayLink = nil;
359- (void) drawRect:(CGRect)rect
365 mGraphics->SetPlatformContext(UIGraphicsGetCurrentContext());
367 if (mGraphics->IsDirty(rects))
369 mGraphics->SetAllControlsClean();
370 mGraphics->Draw(rects);
375- (void) redraw:(CADisplayLink*) displayLink
378 [
self setNeedsDisplay];
380 [
self drawRect:CGRect()];
389- (BOOL) acceptsFirstResponder
394- (BOOL) canBecomeFirstResponder
399- (void) removeFromSuperview
401 [
self.displayLink invalidate];
402 self.displayLink = nil;
405 mMenuTableController = nil;
406 mMenuNavigationController = nil;
407 [mMTLLayer removeFromSuperlayer];
411- (BOOL) textFieldShouldReturn:(UITextField*) textField
413 if (textField == mTextField)
415 mGraphics->SetControlValueAfterTextEdit([[mTextField text] UTF8String]);
416 mGraphics->SetAllControlsDirty();
423- (BOOL) textField:(UITextField*) textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*) string
429 NSString* proposedText = [mTextField.text stringByReplacingCharactersInRange:range withString:string];
431 if (proposedText.length > mTextFieldLength)
434 IControl* pInTextEntry = mGraphics->GetControlInTextEntry();
442 NSMutableCharacterSet *characterSet = [[NSMutableCharacterSet alloc] init];
444 switch ( pParam->
Type() )
446 case IParam::kTypeEnum:
447 case IParam::kTypeInt:
448 case IParam::kTypeBool:
449 [characterSet addCharactersInString:@"0123456789-+"];
451 case IParam::kTypeDouble:
452 [characterSet addCharactersInString:@"0123456789.-+"];
458 if ([
string rangeOfCharacterFromSet:characterSet.invertedSet].location != NSNotFound)
466- (UIModalPresentationStyle) adaptivePresentationStyleForPresentationController:(UIPresentationController*) controller
468 return UIModalPresentationNone;
471- (BOOL) presentationControllerShouldDismiss:(UIPopoverPresentationController*) popoverPresentationController
478 mMenuTableController = [[IGRAPHICS_UITABLEVC alloc] initWithIPopupMenuAndIGraphics:&menu : mGraphics];
479 [mMenuTableController setTitle: [NSString stringWithUTF8String:menu.GetRootTitle()]];
481 mMenuNavigationController = [[UINavigationController alloc] initWithRootViewController:mMenuTableController];
483 mMenuNavigationController.modalPresentationStyle = UIModalPresentationPopover;
484 mMenuNavigationController.popoverPresentationController.sourceView = self;
485 mMenuNavigationController.popoverPresentationController.sourceRect = bounds;
487 mMenuNavigationController.popoverPresentationController.delegate = self;
489 [
self.window.rootViewController presentViewController:mMenuNavigationController animated:YES completion:nil];
494- (void) createTextEntry: (
int) paramIdx : (const
IText&) text : (const
char*) str : (
int) length : (CGRect) areaRect
499 mAlertController = [UIAlertController alertControllerWithTitle:@"Input a value:" message:@"" preferredStyle:UIAlertControllerStyleAlert];
501 __weak IGRAPHICS_VIEW* weakSelf = self;
503 void (^cancelHandler)(UIAlertAction*) = ^(UIAlertAction *action)
505 __strong IGRAPHICS_VIEW* strongSelf = weakSelf;
506 strongSelf->mGraphics->SetAllControlsDirty();
507 [strongSelf endUserInput];
510 UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:cancelHandler];
511 [mAlertController addAction:cancelAction];
513 void (^okHandler)(UIAlertAction*) = ^(UIAlertAction *action)
515 __strong IGRAPHICS_VIEW* strongSelf = weakSelf;
516 strongSelf->mGraphics->SetControlValueAfterTextEdit([[strongSelf->mTextField text] UTF8String]);
517 strongSelf->mGraphics->SetAllControlsDirty();
518 [strongSelf endUserInput];
521 UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:okHandler];
522 [mAlertController addAction:okAction];
523 [mAlertController setPreferredAction:okAction];
525 [mAlertController addTextFieldWithConfigurationHandler:^(UITextField* aTextField) {
526 __strong IGRAPHICS_VIEW* strongSelf = weakSelf;
527 strongSelf->mTextField = aTextField;
528 strongSelf->mTextFieldLength = length;
529 aTextField.delegate = strongSelf;
530 [aTextField setText:[NSString stringWithUTF8String:str]];
532 [
self.window.rootViewController presentViewController:mAlertController animated:YES completion:nil];
537 [
self becomeFirstResponder];
538 [
self.window.rootViewController dismissViewControllerAnimated:NO completion:nil];
539 [mTextField setDelegate: nil];
540 mAlertController =
nullptr;
541 mTextField =
nullptr;
542 mGraphics->ClearInTextEntryControl();
545- (void) showMessageBox: (const
char*) str : (const
char*) title : (EMsgBoxType) type : (IMsgBoxCompletionHandlerFunc) completionHandler
549 NSString* message = [NSString stringWithUTF8String:str];
550 NSString* titleNs = [NSString stringWithUTF8String:title];
552 UIAlertController* alertController = [UIAlertController alertControllerWithTitle:titleNs message:message preferredStyle:UIAlertControllerStyleAlert];
554 void (^handlerBlock)(UIAlertAction*) =
555 ^(UIAlertAction* action) {
557 if (completionHandler !=
nullptr)
559 EMsgBoxResult result = EMsgBoxResult::kCANCEL;
561 if ([action.title isEqualToString:
@"OK"])
562 result = EMsgBoxResult::kOK;
563 if ([action.title isEqualToString:
@"Cancel"])
564 result = EMsgBoxResult::kCANCEL;
565 if ([action.title isEqualToString:
@"Yes"])
566 result = EMsgBoxResult::kYES;
567 if ([action.title isEqualToString:
@"No"])
568 result = EMsgBoxResult::kNO;
569 if ([action.title isEqualToString:
@"Retry"])
570 result = EMsgBoxResult::kRETRY;
572 completionHandler(result);
577 if (type == kMB_OK || type == kMB_OKCANCEL)
579 UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:handlerBlock];
580 [alertController addAction:okAction];
583 if (type == kMB_YESNO || type == kMB_YESNOCANCEL)
585 UIAlertAction* yesAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:handlerBlock];
586 [alertController addAction:yesAction];
588 UIAlertAction* noAction = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDefault handler:handlerBlock];
589 [alertController addAction:noAction];
592 if (type == kMB_RETRYCANCEL)
594 UIAlertAction* retryAction = [UIAlertAction actionWithTitle:@"Retry" style:UIAlertActionStyleDefault handler:handlerBlock];
595 [alertController addAction:retryAction];
598 if (type == kMB_OKCANCEL || type == kMB_YESNOCANCEL || type == kMB_RETRYCANCEL)
600 UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:handlerBlock];
601 [alertController addAction:cancelAction];
604 [[NSOperationQueue mainQueue] addOperationWithBlock:^{
605 [
self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
609- (void) promptForFile: (NSString*) fileName : (NSString*) path : (EFileAction) action : (NSArray*) contentTypes : (IFileDialogCompletionHandlerFunc) completionHandler
613 mFileDialogFunc = completionHandler;
615 UIDocumentPickerViewController* vc = NULL;
616 NSURL* url = [[NSURL alloc] initFileURLWithPath:path];
618 if (action == EFileAction::Open)
620 vc = [[UIDocumentPickerViewController alloc] initForOpeningContentTypes:contentTypes asCopy:YES];
621 [vc setDirectoryURL:url];
625 vc = [[UIDocumentPickerViewController alloc] initForExportingURLs:@[url]];
628 [vc setDelegate:self];
630 [
self.window.rootViewController presentViewController:vc animated:YES completion:nil];
633- (void) promptForDirectory: (NSString*) path : (IFileDialogCompletionHandlerFunc) completionHandler
637 mFileDialogFunc = completionHandler;
639 UIDocumentPickerViewController* vc = NULL;
640 NSURL* url = [[NSURL alloc] initFileURLWithPath:path];
642 NSMutableArray* pFileTypes = [[NSMutableArray alloc] init];
643 UTType* directoryType = [UTType typeWithIdentifier:@"public.folder"];
644 [pFileTypes addObject:directoryType];
646 vc = [[UIDocumentPickerViewController alloc] initForOpeningContentTypes:pFileTypes];
647 [vc setDirectoryURL:url];
649 [vc setDelegate:self];
651 [
self.window.rootViewController presentViewController:vc animated:YES completion:nil];
654- (BOOL) promptForColor: (
IColor&) color : (const
char*) str : (IColorPickerHandlerFunc) func
658 UIColorPickerViewController* colorSelectionController = [[UIColorPickerViewController alloc] init];
660 colorSelectionController.modalPresentationStyle = UIModalPresentationPopover;
661 colorSelectionController.popoverPresentationController.delegate = self;
662 colorSelectionController.popoverPresentationController.sourceView = self;
665 mGraphics->GetMouseLocation(x, y);
666 colorSelectionController.popoverPresentationController.sourceRect = CGRectMake(x, y, 1, 1);
668 colorSelectionController.delegate = self;
669 colorSelectionController.selectedColor = ToUIColor(color);
670 colorSelectionController.supportsAlpha = YES;
672 mColorPickerHandlerFunc = func;
674 [
self.window.rootViewController presentViewController:colorSelectionController animated:YES completion:nil];
679- (void) attachGestureRecognizer: (EGestureType) type
681 UIGestureRecognizer* gestureRecognizer;
685 case EGestureType::DoubleTap:
686 case EGestureType::TripleTap:
688 gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapGesture:)];
689 [(UITapGestureRecognizer*) gestureRecognizer setNumberOfTapsRequired: type == EGestureType::DoubleTap ? 2 : 3];
690 [(UITapGestureRecognizer*) gestureRecognizer setNumberOfTouchesRequired:1];
693 case EGestureType::LongPress1:
694 case EGestureType::LongPress2:
696 gestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onLongPressGesture:)];
697 [(UILongPressGestureRecognizer*) gestureRecognizer setNumberOfTouchesRequired: type == EGestureType::LongPress1 ? 1 : 2];
700 case EGestureType::SwipeLeft:
702 gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
703 [(UISwipeGestureRecognizer*) gestureRecognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
706 case EGestureType::SwipeRight:
708 gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
709 [(UISwipeGestureRecognizer*) gestureRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
712 case EGestureType::SwipeUp:
714 gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
715 [(UISwipeGestureRecognizer*) gestureRecognizer setDirection:UISwipeGestureRecognizerDirectionUp];
718 case EGestureType::SwipeDown:
720 gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
721 [(UISwipeGestureRecognizer*) gestureRecognizer setDirection:UISwipeGestureRecognizerDirectionDown];
724 case EGestureType::Pinch:
726 gestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(onPinchGesture:)];
729 case EGestureType::Rotate:
731 gestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(onRotateGesture:)];
738 gestureRecognizer.delegate = self;
739 gestureRecognizer.cancelsTouchesInView = YES;
740 gestureRecognizer.delaysTouchesBegan = YES;
741 [
self addGestureRecognizer:gestureRecognizer];
744- (void) onTapGesture: (UITapGestureRecognizer*) recognizer
746 CGPoint p = [recognizer locationInView:self];
747 auto ds = mGraphics->GetDrawScale();
751 info.type = recognizer.numberOfTapsRequired == 2 ? EGestureType::DoubleTap : EGestureType::TripleTap;
753 mGraphics->OnGestureRecognized(info);
756- (void) onLongPressGesture: (UILongPressGestureRecognizer*) recognizer
758 CGPoint p = [recognizer locationInView:self];
759 auto ds = mGraphics->GetDrawScale();
763 if(recognizer.state == UIGestureRecognizerStateBegan)
764 info.state = EGestureState::Began;
765 else if(recognizer.state == UIGestureRecognizerStateChanged)
766 info.state = EGestureState::InProcess;
767 else if(recognizer.state == UIGestureRecognizerStateEnded)
768 info.state = EGestureState::Ended;
770 info.type = recognizer.numberOfTouchesRequired == 1 ? EGestureType::LongPress1 : EGestureType::LongPress2;
772 mGraphics->OnGestureRecognized(info);
775- (void) onSwipeGesture: (UISwipeGestureRecognizer*) recognizer
777 CGPoint p = [recognizer locationInView:self];
778 auto ds = mGraphics->GetDrawScale();
783 switch (recognizer.direction) {
784 case UISwipeGestureRecognizerDirectionLeft: info.type = EGestureType::SwipeLeft;
break;
785 case UISwipeGestureRecognizerDirectionRight: info.type = EGestureType::SwipeRight;
break;
786 case UISwipeGestureRecognizerDirectionUp: info.type = EGestureType::SwipeUp;
break;
787 case UISwipeGestureRecognizerDirectionDown: info.type = EGestureType::SwipeDown;
break;
792 mGraphics->OnGestureRecognized(info);
795- (void) onPinchGesture: (UIPinchGestureRecognizer*) recognizer
797 CGPoint p = [recognizer locationInView:self];
798 auto ds = mGraphics->GetDrawScale();
802 info.velocity = recognizer.velocity;
803 info.scale = recognizer.scale;
805 if(recognizer.state == UIGestureRecognizerStateBegan)
806 info.state = EGestureState::Began;
807 else if(recognizer.state == UIGestureRecognizerStateChanged)
808 info.state = EGestureState::InProcess;
809 else if(recognizer.state == UIGestureRecognizerStateEnded)
810 info.state = EGestureState::Ended;
812 info.type = EGestureType::Pinch;
814 mGraphics->OnGestureRecognized(info);
817- (void) onRotateGesture: (UIRotationGestureRecognizer*) recognizer
819 CGPoint p = [recognizer locationInView:self];
820 auto ds = mGraphics->GetDrawScale();
824 info.velocity = recognizer.velocity;
825 info.angle = RadToDeg(recognizer.rotation);
827 if(recognizer.state == UIGestureRecognizerStateBegan)
828 info.state = EGestureState::Began;
829 else if(recognizer.state == UIGestureRecognizerStateChanged)
830 info.state = EGestureState::InProcess;
831 else if(recognizer.state == UIGestureRecognizerStateEnded)
832 info.state = EGestureState::Ended;
834 info.type = EGestureType::Rotate;
836 mGraphics->OnGestureRecognized(info);
839- (void) onHoverGesture: (UIHoverGestureRecognizer*) recognizer
841 CGPoint pos = [recognizer locationInView:self];
845 auto ds = mGraphics->GetDrawScale();
850 mGraphics->OnMouseOver(info.x, info.y, info.ms);
853-(BOOL) gestureRecognizer:(UIGestureRecognizer*) gestureRecognizer shouldReceiveTouch:(UITouch*) touch
855 CGPoint pos = [touch locationInView:touch.view];
859 auto ds = mGraphics->GetDrawScale();
861 if (mGraphics->RespondsToGesture(pos.x / ds, pos.y / ds))
870- (void) applicationDidEnterBackgroundNotification:(NSNotification*) notification
872 [
self.displayLink setPaused:YES];
875- (void) applicationWillEnterForegroundNotification:(NSNotification*) notification
877 [
self.displayLink setPaused:NO];
880- (BOOL) delaysContentTouches
885- (void) presentationControllerDidDismiss: (UIPresentationController*) presentationController
887 mGraphics->SetControlValueAfterPopupMenu(
nullptr);
890- (void) documentPicker:(UIDocumentPickerViewController*) controller didPickDocumentsAtURLs:(NSArray <NSURL*>*) urls
892 WDL_String fileName, path;
896 NSURL* pSource = urls[0];
897 NSString* pFullPath = [pSource path];
898 fileName.Set([pFullPath UTF8String]);
900 NSString* pTruncatedPath = [pFullPath stringByDeletingLastPathComponent];
904 path.Set([pTruncatedPath UTF8String]);
909 mFileDialogFunc(fileName, path);
915 mFileDialogFunc(fileName, path);
919- (void) documentPickerWasCancelled:(UIDocumentPickerViewController*) controller
921 WDL_String fileName, path;
924 mFileDialogFunc(fileName, path);
927- (void) colorPickerViewControllerDidSelectColor:(UIColorPickerViewController*) viewController;
929 if (mColorPickerHandlerFunc)
931 IColor c = FromUIColor([viewController selectedColor]);
932 mColorPickerHandlerFunc(c);
936- (void) colorPickerViewControllerDidFinish:(UIColorPickerViewController*) viewController;
938 mColorPickerHandlerFunc =
nullptr;
941- (void) traitCollectionDidChange: (UITraitCollection*) previousTraitCollection
943 [
super traitCollectionDidChange: previousTraitCollection];
947 mGraphics->OnAppearanceChanged([self.traitCollection userInterfaceStyle] == UIUserInterfaceStyleDark ? EUIAppearance::Dark
948 : EUIAppearance::Light);
952- (void) getLastTouchLocation: (
float&) x : (
float&) y
954 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,...