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;
236- (void) setFrame:(CGRect) frame
238 [
super setFrame:frame];
241 CGFloat scale = [UIScreen mainScreen].scale;
245 scale = self.window.screen.scale;
247 #ifdef IGRAPHICS_METAL
248 [CATransaction begin];
249 [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
250 CGSize drawableSize = self.bounds.size;
251 [
self.layer setFrame:frame];
252 mMTLLayer.frame = self.layer.frame;
254 drawableSize.width *= scale;
255 drawableSize.height *= scale;
257 mMTLLayer.drawableSize = drawableSize;
259 [CATransaction commit];
263- (void) onTouchEvent:(ETouchEvent) eventType withTouches:(NSSet*) touches withEvent:(UIEvent*) event
265 if(mGraphics ==
nullptr)
268 NSEnumerator* pEnumerator = [[event allTouches] objectEnumerator];
271 std::vector<IMouseInfo> points;
273 while ((pTouch = [pEnumerator nextObject]))
275 CGPoint pos = [pTouch locationInView:pTouch.view];
279 auto ds = mGraphics->GetDrawScale();
282 point.ms.touchID =
reinterpret_cast<ITouchID
>(pTouch);
283 point.ms.touchRadius = [pTouch majorRadius];
285 point.x = pos.x / ds;
286 point.y = pos.y / ds;
287 CGPoint posPrev = [pTouch previousLocationInView: self];
288 point.dX = (pos.x - posPrev.x) / ds;
289 point.dY = (pos.y - posPrev.y) / ds;
291 if([touches containsObject:pTouch])
295 points.push_back(point);
301 if(eventType == ETouchEvent::Began)
302 mGraphics->OnMouseDown(points);
304 if(eventType == ETouchEvent::Moved)
305 mGraphics->OnMouseDrag(points);
307 if(eventType == ETouchEvent::Ended)
308 mGraphics->OnMouseUp(points);
310 if(eventType == ETouchEvent::Cancelled)
311 mGraphics->OnTouchCancelled(points);
314- (void) touchesBegan:(NSSet*) touches withEvent:(UIEvent*) event
316 [
self onTouchEvent:ETouchEvent::Began withTouches:touches withEvent:event];
319- (void) touchesMoved:(NSSet*) touches withEvent:(UIEvent*) event
321 [
self onTouchEvent:ETouchEvent::Moved withTouches:touches withEvent:event];
324- (void) touchesEnded:(NSSet*) touches withEvent:(UIEvent*) event
326 [
self onTouchEvent:ETouchEvent::Ended withTouches:touches withEvent:event];
329- (void) touchesCancelled:(NSSet*) touches withEvent:(UIEvent*) event
331 [
self onTouchEvent:ETouchEvent::Cancelled withTouches:touches withEvent:event];
334- (CAMetalLayer*) metalLayer
339- (void) didMoveToSuperview
341 [
super didMoveToSuperview];
344 self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(redraw:)];
345 [
self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
346 self.displayLink.preferredFramesPerSecond = mGraphics->FPS();
350 [
self.displayLink invalidate];
351 self.displayLink = nil;
355- (void) drawRect:(CGRect)rect
361 mGraphics->SetPlatformContext(UIGraphicsGetCurrentContext());
363 if (mGraphics->IsDirty(rects))
365 mGraphics->SetAllControlsClean();
366 mGraphics->Draw(rects);
371- (void) redraw:(CADisplayLink*) displayLink
374 [
self setNeedsDisplay];
376 [
self drawRect:CGRect()];
385- (BOOL) acceptsFirstResponder
390- (BOOL) canBecomeFirstResponder
395- (void) removeFromSuperview
397 [
self.displayLink invalidate];
398 self.displayLink = nil;
401 mMenuTableController = nil;
402 mMenuNavigationController = nil;
403 [mMTLLayer removeFromSuperlayer];
407- (BOOL) textFieldShouldReturn:(UITextField*) textField
409 if (textField == mTextField)
411 mGraphics->SetControlValueAfterTextEdit([[mTextField text] UTF8String]);
412 mGraphics->SetAllControlsDirty();
419- (BOOL) textField:(UITextField*) textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*) string
425 NSString* proposedText = [mTextField.text stringByReplacingCharactersInRange:range withString:string];
427 if (proposedText.length > mTextFieldLength)
430 IControl* pInTextEntry = mGraphics->GetControlInTextEntry();
438 NSMutableCharacterSet *characterSet = [[NSMutableCharacterSet alloc] init];
440 switch ( pParam->
Type() )
442 case IParam::kTypeEnum:
443 case IParam::kTypeInt:
444 case IParam::kTypeBool:
445 [characterSet addCharactersInString:@"0123456789-+"];
447 case IParam::kTypeDouble:
448 [characterSet addCharactersInString:@"0123456789.-+"];
454 if ([
string rangeOfCharacterFromSet:characterSet.invertedSet].location != NSNotFound)
462- (UIModalPresentationStyle) adaptivePresentationStyleForPresentationController:(UIPresentationController*) controller
464 return UIModalPresentationNone;
467- (BOOL) presentationControllerShouldDismiss:(UIPopoverPresentationController*) popoverPresentationController
474 mMenuTableController = [[IGRAPHICS_UITABLEVC alloc] initWithIPopupMenuAndIGraphics:&menu : mGraphics];
475 [mMenuTableController setTitle: [NSString stringWithUTF8String:menu.GetRootTitle()]];
477 mMenuNavigationController = [[UINavigationController alloc] initWithRootViewController:mMenuTableController];
479 mMenuNavigationController.modalPresentationStyle = UIModalPresentationPopover;
480 mMenuNavigationController.popoverPresentationController.sourceView = self;
481 mMenuNavigationController.popoverPresentationController.sourceRect = bounds;
483 mMenuNavigationController.popoverPresentationController.delegate = self;
485 [
self.window.rootViewController presentViewController:mMenuNavigationController animated:YES completion:nil];
490- (void) createTextEntry: (
int) paramIdx : (const
IText&) text : (const
char*) str : (
int) length : (CGRect) areaRect
495 mAlertController = [UIAlertController alertControllerWithTitle:@"Input a value:" message:@"" preferredStyle:UIAlertControllerStyleAlert];
497 __weak IGRAPHICS_VIEW* weakSelf = self;
499 void (^cancelHandler)(UIAlertAction*) = ^(UIAlertAction *action)
501 __strong IGRAPHICS_VIEW* strongSelf = weakSelf;
502 strongSelf->mGraphics->SetAllControlsDirty();
503 [strongSelf endUserInput];
506 UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:cancelHandler];
507 [mAlertController addAction:cancelAction];
509 void (^okHandler)(UIAlertAction*) = ^(UIAlertAction *action)
511 __strong IGRAPHICS_VIEW* strongSelf = weakSelf;
512 strongSelf->mGraphics->SetControlValueAfterTextEdit([[strongSelf->mTextField text] UTF8String]);
513 strongSelf->mGraphics->SetAllControlsDirty();
514 [strongSelf endUserInput];
517 UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:okHandler];
518 [mAlertController addAction:okAction];
519 [mAlertController setPreferredAction:okAction];
521 [mAlertController addTextFieldWithConfigurationHandler:^(UITextField* aTextField) {
522 __strong IGRAPHICS_VIEW* strongSelf = weakSelf;
523 strongSelf->mTextField = aTextField;
524 strongSelf->mTextFieldLength = length;
525 aTextField.delegate = strongSelf;
526 [aTextField setText:[NSString stringWithUTF8String:str]];
528 [
self.window.rootViewController presentViewController:mAlertController animated:YES completion:nil];
533 [
self becomeFirstResponder];
534 [
self.window.rootViewController dismissViewControllerAnimated:NO completion:nil];
535 [mTextField setDelegate: nil];
536 mAlertController =
nullptr;
537 mTextField =
nullptr;
538 mGraphics->ClearInTextEntryControl();
541- (void) showMessageBox: (const
char*) str : (const
char*) title : (EMsgBoxType) type : (IMsgBoxCompletionHandlerFunc) completionHandler
545 NSString* message = [NSString stringWithUTF8String:str];
546 NSString* titleNs = [NSString stringWithUTF8String:title];
548 UIAlertController* alertController = [UIAlertController alertControllerWithTitle:titleNs message:message preferredStyle:UIAlertControllerStyleAlert];
550 void (^handlerBlock)(UIAlertAction*) =
551 ^(UIAlertAction* action) {
553 if (completionHandler !=
nullptr)
555 EMsgBoxResult result = EMsgBoxResult::kCANCEL;
557 if ([action.title isEqualToString:
@"OK"])
558 result = EMsgBoxResult::kOK;
559 if ([action.title isEqualToString:
@"Cancel"])
560 result = EMsgBoxResult::kCANCEL;
561 if ([action.title isEqualToString:
@"Yes"])
562 result = EMsgBoxResult::kYES;
563 if ([action.title isEqualToString:
@"No"])
564 result = EMsgBoxResult::kNO;
565 if ([action.title isEqualToString:
@"Retry"])
566 result = EMsgBoxResult::kRETRY;
568 completionHandler(result);
573 if (type == kMB_OK || type == kMB_OKCANCEL)
575 UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:handlerBlock];
576 [alertController addAction:okAction];
579 if (type == kMB_YESNO || type == kMB_YESNOCANCEL)
581 UIAlertAction* yesAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:handlerBlock];
582 [alertController addAction:yesAction];
584 UIAlertAction* noAction = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDefault handler:handlerBlock];
585 [alertController addAction:noAction];
588 if (type == kMB_RETRYCANCEL)
590 UIAlertAction* retryAction = [UIAlertAction actionWithTitle:@"Retry" style:UIAlertActionStyleDefault handler:handlerBlock];
591 [alertController addAction:retryAction];
594 if (type == kMB_OKCANCEL || type == kMB_YESNOCANCEL || type == kMB_RETRYCANCEL)
596 UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:handlerBlock];
597 [alertController addAction:cancelAction];
600 [[NSOperationQueue mainQueue] addOperationWithBlock:^{
601 [
self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
605- (void) promptForFile: (NSString*) fileName : (NSString*) path : (EFileAction) action : (NSArray*) contentTypes : (IFileDialogCompletionHandlerFunc) completionHandler
609 mFileDialogFunc = completionHandler;
611 UIDocumentPickerViewController* vc = NULL;
612 NSURL* url = [[NSURL alloc] initFileURLWithPath:path];
614 if (action == EFileAction::Open)
616 vc = [[UIDocumentPickerViewController alloc] initForOpeningContentTypes:contentTypes asCopy:YES];
617 [vc setDirectoryURL:url];
621 vc = [[UIDocumentPickerViewController alloc] initForExportingURLs:@[url]];
624 [vc setDelegate:self];
626 [
self.window.rootViewController presentViewController:vc animated:YES completion:nil];
629- (void) promptForDirectory: (NSString*) path : (IFileDialogCompletionHandlerFunc) completionHandler
633 mFileDialogFunc = completionHandler;
635 UIDocumentPickerViewController* vc = NULL;
636 NSURL* url = [[NSURL alloc] initFileURLWithPath:path];
638 NSMutableArray* pFileTypes = [[NSMutableArray alloc] init];
639 UTType* directoryType = [UTType typeWithIdentifier:@"public.folder"];
640 [pFileTypes addObject:directoryType];
642 vc = [[UIDocumentPickerViewController alloc] initForOpeningContentTypes:pFileTypes];
643 [vc setDirectoryURL:url];
645 [vc setDelegate:self];
647 [
self.window.rootViewController presentViewController:vc animated:YES completion:nil];
650- (BOOL) promptForColor: (
IColor&) color : (const
char*) str : (IColorPickerHandlerFunc) func
654 UIColorPickerViewController* colorSelectionController = [[UIColorPickerViewController alloc] init];
656 colorSelectionController.modalPresentationStyle = UIModalPresentationPopover;
657 colorSelectionController.popoverPresentationController.delegate = self;
658 colorSelectionController.popoverPresentationController.sourceView = self;
661 mGraphics->GetMouseLocation(x, y);
662 colorSelectionController.popoverPresentationController.sourceRect = CGRectMake(x, y, 1, 1);
664 colorSelectionController.delegate = self;
665 colorSelectionController.selectedColor = ToUIColor(color);
666 colorSelectionController.supportsAlpha = YES;
668 mColorPickerHandlerFunc = func;
670 [
self.window.rootViewController presentViewController:colorSelectionController animated:YES completion:nil];
675- (void) attachGestureRecognizer: (EGestureType) type
677 UIGestureRecognizer* gestureRecognizer;
681 case EGestureType::DoubleTap:
682 case EGestureType::TripleTap:
684 gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapGesture:)];
685 [(UITapGestureRecognizer*) gestureRecognizer setNumberOfTapsRequired: type == EGestureType::DoubleTap ? 2 : 3];
686 [(UITapGestureRecognizer*) gestureRecognizer setNumberOfTouchesRequired:1];
689 case EGestureType::LongPress1:
690 case EGestureType::LongPress2:
692 gestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onLongPressGesture:)];
693 [(UILongPressGestureRecognizer*) gestureRecognizer setNumberOfTouchesRequired: type == EGestureType::LongPress1 ? 1 : 2];
696 case EGestureType::SwipeLeft:
698 gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
699 [(UISwipeGestureRecognizer*) gestureRecognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
702 case EGestureType::SwipeRight:
704 gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
705 [(UISwipeGestureRecognizer*) gestureRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
708 case EGestureType::SwipeUp:
710 gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
711 [(UISwipeGestureRecognizer*) gestureRecognizer setDirection:UISwipeGestureRecognizerDirectionUp];
714 case EGestureType::SwipeDown:
716 gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
717 [(UISwipeGestureRecognizer*) gestureRecognizer setDirection:UISwipeGestureRecognizerDirectionDown];
720 case EGestureType::Pinch:
722 gestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(onPinchGesture:)];
725 case EGestureType::Rotate:
727 gestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(onRotateGesture:)];
734 gestureRecognizer.delegate = self;
735 gestureRecognizer.cancelsTouchesInView = YES;
736 gestureRecognizer.delaysTouchesBegan = YES;
737 [
self addGestureRecognizer:gestureRecognizer];
740- (void) onTapGesture: (UITapGestureRecognizer*) recognizer
742 CGPoint p = [recognizer locationInView:self];
743 auto ds = mGraphics->GetDrawScale();
747 info.type = recognizer.numberOfTapsRequired == 2 ? EGestureType::DoubleTap : EGestureType::TripleTap;
749 mGraphics->OnGestureRecognized(info);
752- (void) onLongPressGesture: (UILongPressGestureRecognizer*) recognizer
754 CGPoint p = [recognizer locationInView:self];
755 auto ds = mGraphics->GetDrawScale();
759 if(recognizer.state == UIGestureRecognizerStateBegan)
760 info.state = EGestureState::Began;
761 else if(recognizer.state == UIGestureRecognizerStateChanged)
762 info.state = EGestureState::InProcess;
763 else if(recognizer.state == UIGestureRecognizerStateEnded)
764 info.state = EGestureState::Ended;
766 info.type = recognizer.numberOfTouchesRequired == 1 ? EGestureType::LongPress1 : EGestureType::LongPress2;
768 mGraphics->OnGestureRecognized(info);
771- (void) onSwipeGesture: (UISwipeGestureRecognizer*) recognizer
773 CGPoint p = [recognizer locationInView:self];
774 auto ds = mGraphics->GetDrawScale();
779 switch (recognizer.direction) {
780 case UISwipeGestureRecognizerDirectionLeft: info.type = EGestureType::SwipeLeft;
break;
781 case UISwipeGestureRecognizerDirectionRight: info.type = EGestureType::SwipeRight;
break;
782 case UISwipeGestureRecognizerDirectionUp: info.type = EGestureType::SwipeUp;
break;
783 case UISwipeGestureRecognizerDirectionDown: info.type = EGestureType::SwipeDown;
break;
788 mGraphics->OnGestureRecognized(info);
791- (void) onPinchGesture: (UIPinchGestureRecognizer*) recognizer
793 CGPoint p = [recognizer locationInView:self];
794 auto ds = mGraphics->GetDrawScale();
798 info.velocity = recognizer.velocity;
799 info.scale = recognizer.scale;
801 if(recognizer.state == UIGestureRecognizerStateBegan)
802 info.state = EGestureState::Began;
803 else if(recognizer.state == UIGestureRecognizerStateChanged)
804 info.state = EGestureState::InProcess;
805 else if(recognizer.state == UIGestureRecognizerStateEnded)
806 info.state = EGestureState::Ended;
808 info.type = EGestureType::Pinch;
810 mGraphics->OnGestureRecognized(info);
813- (void) onRotateGesture: (UIRotationGestureRecognizer*) recognizer
815 CGPoint p = [recognizer locationInView:self];
816 auto ds = mGraphics->GetDrawScale();
820 info.velocity = recognizer.velocity;
821 info.angle = RadToDeg(recognizer.rotation);
823 if(recognizer.state == UIGestureRecognizerStateBegan)
824 info.state = EGestureState::Began;
825 else if(recognizer.state == UIGestureRecognizerStateChanged)
826 info.state = EGestureState::InProcess;
827 else if(recognizer.state == UIGestureRecognizerStateEnded)
828 info.state = EGestureState::Ended;
830 info.type = EGestureType::Rotate;
832 mGraphics->OnGestureRecognized(info);
835-(BOOL) gestureRecognizer:(UIGestureRecognizer*) gestureRecognizer shouldReceiveTouch:(UITouch*) touch
837 CGPoint pos = [touch locationInView:touch.view];
841 auto ds = mGraphics->GetDrawScale();
843 if (mGraphics->RespondsToGesture(pos.x / ds, pos.y / ds))
852- (void) applicationDidEnterBackgroundNotification:(NSNotification*) notification
854 [
self.displayLink setPaused:YES];
857- (void) applicationWillEnterForegroundNotification:(NSNotification*) notification
859 [
self.displayLink setPaused:NO];
862- (BOOL) delaysContentTouches
867- (void) presentationControllerDidDismiss: (UIPresentationController*) presentationController
869 mGraphics->SetControlValueAfterPopupMenu(
nullptr);
872- (void) documentPicker:(UIDocumentPickerViewController*) controller didPickDocumentsAtURLs:(NSArray <NSURL*>*) urls
874 WDL_String fileName, path;
878 NSURL* pSource = urls[0];
879 NSString* pFullPath = [pSource path];
880 fileName.Set([pFullPath UTF8String]);
882 NSString* pTruncatedPath = [pFullPath stringByDeletingLastPathComponent];
886 path.Set([pTruncatedPath UTF8String]);
891 mFileDialogFunc(fileName, path);
897 mFileDialogFunc(fileName, path);
901- (void) documentPickerWasCancelled:(UIDocumentPickerViewController*) controller
903 WDL_String fileName, path;
906 mFileDialogFunc(fileName, path);
909- (void) colorPickerViewControllerDidSelectColor:(UIColorPickerViewController*) viewController;
911 if (mColorPickerHandlerFunc)
913 IColor c = FromUIColor([viewController selectedColor]);
914 mColorPickerHandlerFunc(c);
918- (void) colorPickerViewControllerDidFinish:(UIColorPickerViewController*) viewController;
920 mColorPickerHandlerFunc =
nullptr;
923- (void) traitCollectionDidChange: (UITraitCollection*) previousTraitCollection
925 [
super traitCollectionDidChange: previousTraitCollection];
929 mGraphics->OnAppearanceChanged([self.traitCollection userInterfaceStyle] == UIUserInterfaceStyleDark ? EUIAppearance::Dark
930 : EUIAppearance::Light);
934- (void) getLastTouchLocation: (
float&) x : (
float&) y
936 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,...