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 #ifdef IGRAPHICS_IMGUI 19 #import "imgui_impl_metal.h" 22 #import "IGraphicsIOS_view.h" 24 #include "IGraphicsCoreText.h" 28 extern StaticStorage<CoreTextFontDescriptor> sFontDescriptorCache;
30 @implementation IGRAPHICS_UITABLEVC
35 self.tableView = [[UITableView alloc] initWithFrame:self.view.frame];
36 self.tableView.dataSource =
self;
37 self.tableView.delegate =
self;
38 self.tableView.scrollEnabled = YES;
39 self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
40 self.items = [[NSMutableArray alloc] init];
42 int numItems = mMenu->NItems();
44 NSMutableString* elementTitle;
46 for (
int i = 0; i < numItems; ++i)
50 elementTitle = [[NSMutableString alloc] initWithCString:pMenuItem->GetText() encoding:NSUTF8StringEncoding];
52 if (mMenu->GetPrefix())
54 NSString* prefixString = nil;
56 switch (mMenu->GetPrefix())
58 case 1: prefixString = [NSString stringWithFormat:@"%1d: ", i+1];
break;
59 case 2: prefixString = [NSString stringWithFormat:@"%02d: ", i+1];
break;
60 case 3: prefixString = [NSString stringWithFormat:@"%03d: ", i+1];
break;
63 prefixString = [NSString stringWithUTF8String:""];
break;
66 [elementTitle insertString:prefixString atIndex:0];
69 [
self.items addObject:elementTitle];
72 [
self.view addSubview:self.tableView];
79 mGraphics = pGraphics;
85 - (NSInteger) tableView:(UITableView*) tableView numberOfRowsInSection:(NSInteger) section
87 return self.items.count;
90 - (NSInteger) numberOfSectionsInTableView:(UITableView*) tableView
95 - (UITableViewCell*) tableView:(UITableView*) tableView cellForRowAtIndexPath:(NSIndexPath*) indexPath
97 static NSString *identifer =
@"cell";
98 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifer];
102 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
105 int cellIndex =
static_cast<int>(indexPath.row);
107 cell.textLabel.text = [NSString stringWithFormat:@"%@", self.items[indexPath.row]];
111 if(pItem->GetChecked())
112 cell.accessoryType = UITableViewCellAccessoryCheckmark;
114 cell.accessoryType = pItem->GetSubmenu() ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
116 if(!pItem->GetEnabled())
118 cell.userInteractionEnabled = NO;
119 cell.textLabel.enabled = NO;
125 - (CGFloat) tableView:(UITableView*) tableView heightForRowAtIndexPath:(NSIndexPath*) indexPath
127 int cellIndex =
static_cast<int>(indexPath.row);
131 if(pItem->GetIsSeparator())
134 return self.tableView.rowHeight;
137 - (void) tableView:(UITableView*) tableView didSelectRowAtIndexPath:(NSIndexPath*) indexPath
139 int cellIndex =
static_cast<int>(indexPath.row);
146 IGRAPHICS_UITABLEVC* newViewController = [[IGRAPHICS_UITABLEVC alloc] initWithIPopupMenuAndIGraphics: pSubMenu : mGraphics];
147 [newViewController setTitle:[NSString stringWithUTF8String:CStringHasContents(pSubMenu->GetRootTitle()) ? pSubMenu->GetRootTitle() : pItem->GetText()]];
148 [
self.navigationController pushViewController:newViewController animated:YES];
153 if(pItem->GetIsChoosable())
155 mMenu->SetChosenItemIdx(cellIndex);
157 if(mMenu->GetFunction())
158 mMenu->ExecFunction();
160 mGraphics->SetControlValueAfterPopupMenu(mMenu);
162 [
self dismissViewControllerAnimated:YES completion:nil];
166 - (CGSize) preferredContentSize
168 if (
self.presentingViewController &&
self.tableView != nil)
170 CGSize tempSize =
self.presentingViewController.view.bounds.size;
171 tempSize.width = 300;
172 CGSize size = [
self.tableView sizeThatFits:tempSize];
175 return [
super preferredContentSize];
179 - (void)setPreferredContentSize:(CGSize)preferredContentSize
181 super.preferredContentSize = preferredContentSize;
186 @implementation IGRAPHICS_VIEW
192 mGraphics = pGraphics;
193 CGRect r = CGRectMake(0.f, 0.f, (
float) pGraphics->WindowWidth(), (float) pGraphics->WindowHeight());
194 self = [
super initWithFrame:r];
197 [
self setContentSize:r.size];
198 self.delegate =
self;
199 self.scrollEnabled = NO;
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(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
215 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
216 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackgroundNotification:) name:UIApplicationDidEnterBackgroundNotification object:nil];
217 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForegroundNotification:) name:UIApplicationWillEnterForegroundNotification object:nil];
218 mColorPickerHandlerFunc =
nullptr;
223 - (void) setFrame:(CGRect) frame
225 [
super setFrame:frame];
228 CGFloat scale = [UIScreen mainScreen].scale;
232 scale =
self.window.screen.scale;
234 #ifdef IGRAPHICS_METAL 235 [CATransaction begin];
236 [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
237 CGSize drawableSize =
self.bounds.size;
238 [
self.layer setFrame:frame];
239 mMTLLayer.frame =
self.layer.frame;
241 drawableSize.width *= scale;
242 drawableSize.height *= scale;
244 mMTLLayer.drawableSize = drawableSize;
246 [CATransaction commit];
250 - (void) onTouchEvent:(ETouchEvent) eventType withTouches:(NSSet*) touches withEvent:(UIEvent*) event
252 if(mGraphics ==
nullptr)
255 NSEnumerator* pEnumerator = [[event allTouches] objectEnumerator];
258 std::vector<IMouseInfo> points;
260 while ((pTouch = [pEnumerator nextObject]))
262 CGPoint pos = [pTouch locationInView:pTouch.view];
266 auto ds = mGraphics->GetDrawScale();
269 point.ms.touchID =
reinterpret_cast<ITouchID
>(pTouch);
270 point.ms.touchRadius = [pTouch majorRadius];
272 point.x = pos.x / ds;
273 point.y = pos.y / ds;
274 CGPoint posPrev = [pTouch previousLocationInView: self];
275 point.dX = (pos.x - posPrev.x) / ds;
276 point.dY = (pos.y - posPrev.y) / ds;
278 if([touches containsObject:pTouch])
282 points.push_back(point);
288 if(eventType == ETouchEvent::Began)
289 mGraphics->OnMouseDown(points);
291 if(eventType == ETouchEvent::Moved)
292 mGraphics->OnMouseDrag(points);
294 if(eventType == ETouchEvent::Ended)
295 mGraphics->OnMouseUp(points);
297 if(eventType == ETouchEvent::Cancelled)
298 mGraphics->OnTouchCancelled(points);
301 - (void) touchesBegan:(NSSet*) touches withEvent:(UIEvent*) event
303 [
self onTouchEvent:ETouchEvent::Began withTouches:touches withEvent:event];
306 - (void) touchesMoved:(NSSet*) touches withEvent:(UIEvent*) event
308 [
self onTouchEvent:ETouchEvent::Moved withTouches:touches withEvent:event];
311 - (void) touchesEnded:(NSSet*) touches withEvent:(UIEvent*) event
313 [
self onTouchEvent:ETouchEvent::Ended withTouches:touches withEvent:event];
316 - (void) touchesCancelled:(NSSet*) touches withEvent:(UIEvent*) event
318 [
self onTouchEvent:ETouchEvent::Cancelled withTouches:touches withEvent:event];
321 - (CAMetalLayer*) metalLayer
326 - (void) didMoveToSuperview
328 [
super didMoveToSuperview];
331 self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(redraw:)];
332 [
self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
333 self.displayLink.preferredFramesPerSecond = mGraphics->FPS();
337 [
self.displayLink invalidate];
338 self.displayLink = nil;
342 - (void) drawRect:(CGRect)rect
348 mGraphics->SetPlatformContext(UIGraphicsGetCurrentContext());
350 if (mGraphics->IsDirty(rects))
352 mGraphics->SetAllControlsClean();
353 mGraphics->Draw(rects);
358 - (void) redraw:(CADisplayLink*) displayLink
361 [
self setNeedsDisplay];
363 [
self drawRect:CGRect()];
372 - (BOOL) acceptsFirstResponder
377 - (BOOL) canBecomeFirstResponder
382 - (void) removeFromSuperview
384 [
self.displayLink invalidate];
385 self.displayLink = nil;
388 mMenuTableController = nil;
389 mMenuNavigationController = nil;
390 [mMTLLayer removeFromSuperlayer];
394 - (void) textFieldDidEndEditing:(UITextField*) textField reason:(UITextFieldDidEndEditingReason) reason
396 if(textField == mTextField)
398 mGraphics->SetControlValueAfterTextEdit([[mTextField text] UTF8String]);
399 mGraphics->SetAllControlsDirty();
405 - (BOOL) textFieldShouldReturn:(UITextField*) textField
407 if(textField == mTextField)
409 mGraphics->SetControlValueAfterTextEdit([[mTextField text] UTF8String]);
410 mGraphics->SetAllControlsDirty();
417 - (void) textFieldDidEndEditing:(UITextField*) textField
422 - (BOOL) textField:(UITextField*) textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*) string
428 NSString* proposedText = [mTextField.text stringByReplacingCharactersInRange:range withString:string];
430 if (proposedText.length > mTextFieldLength)
433 IControl* pInTextEntry = mGraphics->GetControlInTextEntry();
441 NSMutableCharacterSet *characterSet = [[NSMutableCharacterSet alloc] init];
443 switch ( pParam->
Type() )
445 case IParam::kTypeEnum:
446 case IParam::kTypeInt:
447 case IParam::kTypeBool:
448 [characterSet addCharactersInString:@"0123456789-+"];
450 case IParam::kTypeDouble:
451 [characterSet addCharactersInString:@"0123456789.-+"];
457 if ([
string rangeOfCharacterFromSet:characterSet.invertedSet].location != NSNotFound)
465 - (UIModalPresentationStyle) adaptivePresentationStyleForPresentationController:(UIPresentationController*) controller
467 return UIModalPresentationNone;
470 - (BOOL) presentationControllerShouldDismiss:(UIPopoverPresentationController*) popoverPresentationController
477 mMenuTableController = [[IGRAPHICS_UITABLEVC alloc] initWithIPopupMenuAndIGraphics:&menu : mGraphics];
478 [mMenuTableController setTitle: [NSString stringWithUTF8String:menu.GetRootTitle()]];
480 mMenuNavigationController = [[UINavigationController alloc] initWithRootViewController:mMenuTableController];
482 mMenuNavigationController.modalPresentationStyle = UIModalPresentationPopover;
483 mMenuNavigationController.popoverPresentationController.sourceView =
self;
484 mMenuNavigationController.popoverPresentationController.sourceRect = bounds;
486 mMenuNavigationController.popoverPresentationController.delegate =
self;
488 [
self.window.rootViewController presentViewController:mMenuNavigationController animated:YES completion:nil];
493 - (void) createTextEntry: (
int) paramIdx : (const
IText&) text : (const
char*) str : (
int) length : (CGRect) areaRect
498 mTextField = [[UITextField alloc] initWithFrame:areaRect];
499 mTextFieldLength = length;
501 CoreTextFontDescriptor* CTFontDescriptor = CoreTextHelpers::GetCTFontDescriptor(text, sFontDescriptorCache);
502 UIFontDescriptor* fontDescriptor = (__bridge UIFontDescriptor*) CTFontDescriptor->GetDescriptor();
503 UIFont* font = [UIFont fontWithDescriptor: fontDescriptor size: text.mSize * 0.75];
504 [mTextField setFont: font];
506 [mTextField setText:[NSString stringWithUTF8String:str]];
507 [mTextField setTextColor:ToUIColor(text.mTextEntryFGColor)];
508 [mTextField setBackgroundColor:ToUIColor(text.mTextEntryBGColor)];
509 [mTextField setAutocorrectionType:UITextAutocorrectionTypeNo];
510 [mTextField setDelegate:self];
512 switch (text.mVAlign)
515 [mTextField setContentVerticalAlignment:UIControlContentVerticalAlignmentTop];
517 case EVAlign::Middle:
518 [mTextField setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
520 case EVAlign::Bottom:
521 [mTextField setContentVerticalAlignment:UIControlContentVerticalAlignmentBottom];
530 [mTextField setTextAlignment: NSTextAlignmentLeft];
533 [mTextField setTextAlignment: NSTextAlignmentCenter];
536 [mTextField setTextAlignment: NSTextAlignmentRight];
542 [
self addSubview: mTextField];
543 [mTextField becomeFirstResponder];
546 - (void) endUserInput
548 [
self becomeFirstResponder];
549 [mTextField setDelegate: nil];
550 [mTextField removeFromSuperview];
551 mTextField =
nullptr;
554 - (void) showMessageBox: (const
char*) str : (const
char*) caption : (EMsgBoxType) type : (IMsgBoxCompletionHanderFunc) completionHandler
556 NSString* titleNString = [NSString stringWithUTF8String:str];
557 NSString* captionNString = [NSString stringWithUTF8String:caption];
559 UIAlertController* alertController = [UIAlertController alertControllerWithTitle:titleNString message:captionNString preferredStyle:UIAlertControllerStyleAlert];
561 void (^handlerBlock)(UIAlertAction*) =
562 ^(UIAlertAction* action) {
564 if(completionHandler !=
nullptr)
566 EMsgBoxResult result = EMsgBoxResult::kCANCEL;
568 if([action.title isEqualToString:
@"OK"])
569 result = EMsgBoxResult::kOK;
570 if([action.title isEqualToString:
@"Cancel"])
571 result = EMsgBoxResult::kCANCEL;
572 if([action.title isEqualToString:
@"Yes"])
573 result = EMsgBoxResult::kYES;
574 if([action.title isEqualToString:
@"No"])
575 result = EMsgBoxResult::kNO;
576 if([action.title isEqualToString:
@"Retry"])
577 result = EMsgBoxResult::kRETRY;
579 completionHandler(result);
584 if(type == kMB_OK || type == kMB_OKCANCEL)
586 UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:handlerBlock];
587 [alertController addAction:okAction];
590 if(type == kMB_YESNO || type == kMB_YESNOCANCEL)
592 UIAlertAction* yesAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:handlerBlock];
593 [alertController addAction:yesAction];
595 UIAlertAction* noAction = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleDefault handler:handlerBlock];
596 [alertController addAction:noAction];
599 if(type == kMB_RETRYCANCEL)
601 UIAlertAction* retryAction = [UIAlertAction actionWithTitle:@"Retry" style:UIAlertActionStyleDefault handler:handlerBlock];
602 [alertController addAction:retryAction];
605 if(type == kMB_OKCANCEL || type == kMB_YESNOCANCEL || type == kMB_RETRYCANCEL)
607 UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:handlerBlock];
608 [alertController addAction:cancelAction];
611 [
self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
614 - (BOOL) promptForColor: (
IColor&) color : (const
char*) str : (IColorPickerHandlerFunc) func
617 UIColorPickerViewController* colorSelectionController = [[UIColorPickerViewController alloc] init];
619 UIUserInterfaceIdiom idiom = [[UIDevice currentDevice] userInterfaceIdiom];
621 if(idiom == UIUserInterfaceIdiomPad)
622 colorSelectionController.modalPresentationStyle = UIModalPresentationPopover;
624 colorSelectionController.modalPresentationStyle = UIModalPresentationPageSheet;
626 colorSelectionController.popoverPresentationController.delegate =
self;
627 colorSelectionController.popoverPresentationController.sourceView =
self;
630 mGraphics->GetMouseLocation(x, y);
631 colorSelectionController.popoverPresentationController.sourceRect = CGRectMake(x, y, 1, 1);
633 colorSelectionController.delegate =
self;
634 colorSelectionController.selectedColor = ToUIColor(color);
635 colorSelectionController.supportsAlpha = YES;
637 mColorPickerHandlerFunc = func;
639 [
self.window.rootViewController presentViewController:colorSelectionController animated:YES completion:nil];
645 - (void) attachGestureRecognizer: (EGestureType) type
647 UIGestureRecognizer* gestureRecognizer;
651 case EGestureType::DoubleTap:
652 case EGestureType::TripleTap:
654 gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapGesture:)];
655 [(UITapGestureRecognizer*) gestureRecognizer setNumberOfTapsRequired: type == EGestureType::DoubleTap ? 2 : 3];
656 [(UITapGestureRecognizer*) gestureRecognizer setNumberOfTouchesRequired:1];
659 case EGestureType::LongPress1:
660 case EGestureType::LongPress2:
662 gestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onLongPressGesture:)];
663 [(UILongPressGestureRecognizer*) gestureRecognizer setNumberOfTouchesRequired: type == EGestureType::LongPress1 ? 1 : 2];
666 case EGestureType::SwipeLeft:
668 gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
669 [(UISwipeGestureRecognizer*) gestureRecognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
672 case EGestureType::SwipeRight:
674 gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
675 [(UISwipeGestureRecognizer*) gestureRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
678 case EGestureType::SwipeUp:
680 gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
681 [(UISwipeGestureRecognizer*) gestureRecognizer setDirection:UISwipeGestureRecognizerDirectionUp];
684 case EGestureType::SwipeDown:
686 gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
687 [(UISwipeGestureRecognizer*) gestureRecognizer setDirection:UISwipeGestureRecognizerDirectionDown];
690 case EGestureType::Pinch:
692 gestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(onPinchGesture:)];
695 case EGestureType::Rotate:
697 gestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(onRotateGesture:)];
704 gestureRecognizer.delegate =
self;
705 gestureRecognizer.cancelsTouchesInView = YES;
706 gestureRecognizer.delaysTouchesBegan = YES;
707 [
self addGestureRecognizer:gestureRecognizer];
710 - (void) onTapGesture: (UITapGestureRecognizer*) recognizer
712 CGPoint p = [recognizer locationInView:self];
713 auto ds = mGraphics->GetDrawScale();
717 info.type = recognizer.numberOfTapsRequired == 2 ? EGestureType::DoubleTap : EGestureType::TripleTap;
719 mGraphics->OnGestureRecognized(info);
722 - (void) onLongPressGesture: (UILongPressGestureRecognizer*) recognizer
724 CGPoint p = [recognizer locationInView:self];
725 auto ds = mGraphics->GetDrawScale();
729 if(recognizer.state == UIGestureRecognizerStateBegan)
730 info.state = EGestureState::Began;
731 else if(recognizer.state == UIGestureRecognizerStateChanged)
732 info.state = EGestureState::InProcess;
733 else if(recognizer.state == UIGestureRecognizerStateEnded)
734 info.state = EGestureState::Ended;
736 info.type = recognizer.numberOfTouchesRequired == 1 ? EGestureType::LongPress1 : EGestureType::LongPress2;
738 mGraphics->OnGestureRecognized(info);
741 - (void) onSwipeGesture: (UISwipeGestureRecognizer*) recognizer
743 CGPoint p = [recognizer locationInView:self];
744 auto ds = mGraphics->GetDrawScale();
749 switch (recognizer.direction) {
750 case UISwipeGestureRecognizerDirectionLeft: info.type = EGestureType::SwipeLeft;
break;
751 case UISwipeGestureRecognizerDirectionRight: info.type = EGestureType::SwipeRight;
break;
752 case UISwipeGestureRecognizerDirectionUp: info.type = EGestureType::SwipeUp;
break;
753 case UISwipeGestureRecognizerDirectionDown: info.type = EGestureType::SwipeDown;
break;
758 mGraphics->OnGestureRecognized(info);
761 - (void) onPinchGesture: (UIPinchGestureRecognizer*) recognizer
763 CGPoint p = [recognizer locationInView:self];
764 auto ds = mGraphics->GetDrawScale();
768 info.velocity = recognizer.velocity;
769 info.scale = recognizer.scale;
771 if(recognizer.state == UIGestureRecognizerStateBegan)
772 info.state = EGestureState::Began;
773 else if(recognizer.state == UIGestureRecognizerStateChanged)
774 info.state = EGestureState::InProcess;
775 else if(recognizer.state == UIGestureRecognizerStateEnded)
776 info.state = EGestureState::Ended;
778 info.type = EGestureType::Pinch;
780 mGraphics->OnGestureRecognized(info);
783 - (void) onRotateGesture: (UIRotationGestureRecognizer*) recognizer
785 CGPoint p = [recognizer locationInView:self];
786 auto ds = mGraphics->GetDrawScale();
790 info.velocity = recognizer.velocity;
791 info.angle = RadToDeg(recognizer.rotation);
793 if(recognizer.state == UIGestureRecognizerStateBegan)
794 info.state = EGestureState::Began;
795 else if(recognizer.state == UIGestureRecognizerStateChanged)
796 info.state = EGestureState::InProcess;
797 else if(recognizer.state == UIGestureRecognizerStateEnded)
798 info.state = EGestureState::Ended;
800 info.type = EGestureType::Rotate;
802 mGraphics->OnGestureRecognized(info);
805 -(BOOL) gestureRecognizer:(UIGestureRecognizer*) gestureRecognizer shouldReceiveTouch:(UITouch*) touch
807 CGPoint pos = [touch locationInView:touch.view];
809 auto ds = mGraphics->GetDrawScale();
811 if(mGraphics->RespondsToGesture(pos.x / ds, pos.y / ds))
817 - (void) keyboardWillShow:(NSNotification*) notification
819 NSDictionary* info = [notification userInfo];
820 CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
822 UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
823 self.contentInset = contentInsets;
824 self.scrollIndicatorInsets = contentInsets;
826 CGRect r =
self.frame;
827 r.size.height -= kbSize.height;
829 if (!CGRectContainsPoint(r, CGPointMake(mTextField.frame.origin.x + mTextField.frame.size.width, mTextField.frame.origin.y + mTextField.frame.size.height)) ) {
830 [
self scrollRectToVisible:mTextField.frame animated:YES];
834 - (void) keyboardWillBeHidden:(NSNotification*) notification
836 UIEdgeInsets contentInsets = UIEdgeInsetsZero;
837 self.contentInset = contentInsets;
838 self.scrollIndicatorInsets = contentInsets;
841 - (void) applicationDidEnterBackgroundNotification:(NSNotification*) notification
843 [
self.displayLink setPaused:YES];
846 - (void) applicationWillEnterForegroundNotification:(NSNotification*) notification
848 [
self.displayLink setPaused:NO];
851 - (BOOL) delaysContentTouches
856 - (void) scrollViewDidScroll:(UIScrollView*) scrollView
858 mGraphics->SetTranslation(0, -
self.contentOffset.y);
859 mGraphics->SetAllControlsDirty();
862 - (void) presentationControllerDidDismiss: (UIPresentationController*) presentationController
864 mGraphics->SetControlValueAfterPopupMenu(
nullptr);
868 - (void) colorPickerViewControllerDidSelectColor:(UIColorPickerViewController*) viewController;
870 if(mColorPickerHandlerFunc)
872 IColor c = FromUIColor([viewController selectedColor]);
873 mColorPickerHandlerFunc(c);
877 - (void) colorPickerViewControllerDidFinish:(UIColorPickerViewController*) viewController;
879 mColorPickerHandlerFunc =
nullptr;
883 - (void) getLastTouchLocation: (
float&) x : (
float&) y
885 const float scale = mGraphics->GetDrawScale();
892 #ifdef IGRAPHICS_IMGUI 894 @implementation IGRAPHICS_IMGUIVIEW
898 - (id) initWithIGraphicsView: (IGraphicsIOS_View*) pView;
901 self = [
super initWithFrame:[pView frame] device: MTLCreateSystemDefaultDevice()];
905 _commandQueue = [
self.device newCommandQueue];
906 self.layer.opaque = NO;
912 - (void) drawRect:(CGRect)rect
914 id<MTLCommandBuffer> commandBuffer = [
self.commandQueue commandBuffer];
916 MTLRenderPassDescriptor *renderPassDescriptor =
self.currentRenderPassDescriptor;
917 if (renderPassDescriptor != nil)
919 renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(0,0,0,0);
921 id <MTLRenderCommandEncoder> renderEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor];
922 [renderEncoder pushDebugGroup:@"ImGui IGraphics"];
924 ImGui_ImplMetal_NewFrame(renderPassDescriptor);
926 mView->mGraphics->mImGuiRenderer->DoFrame();
928 ImDrawData *drawData = ImGui::GetDrawData();
929 ImGui_ImplMetal_RenderDrawData(drawData, commandBuffer, renderEncoder);
931 [renderEncoder popDebugGroup];
932 [renderEncoder endEncoding];
934 [commandBuffer presentDrawable:self.currentDrawable];
936 [commandBuffer commit];
Used to manage a list of rectangular areas and optimize them for drawing to the screen.
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...
IPlug's parameter class.
Used to manage color data, independent of draw class/platform.
Used to describe a particular gesture.
IPlug's parameter class.
This file contains the base IControl implementation, along with some base classes for specific types ...
IText is used to manage font and text/text entry style for a piece of text on the UI...
Used to group mouse coordinates with mouse modifier information.
IGraphics platform class for IOS.
EParamType Type() const
Get the parameter's type.