git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

Cocoa/GBWarningPopover.m

      1 #import "GBWarningPopover.h"
      2 
      3 static GBWarningPopover *lastPopover;
      4 
      5 @implementation GBWarningPopover
      6 
      7 + (GBWarningPopover *) popoverWithContents:(NSString *)contents title:(NSString *)title onView:(NSView *)view timeout:(double)seconds preferredEdge:(NSRectEdge)preferredEdge
      8 {
      9     [lastPopover close];
     10     lastPopover = [[self alloc] init];
     11     
     12     [lastPopover setBehavior:NSPopoverBehaviorApplicationDefined];
     13     [lastPopover setAnimates:true];
     14     lastPopover.contentViewController = [[NSViewController alloc] initWithNibName:@"PopoverView" bundle:nil];
     15     NSTextField *field = (NSTextField *)lastPopover.contentViewController.view;
     16     if (!title) {
     17         [field setStringValue:contents];
     18     }
     19     else {
     20         NSMutableAttributedString *fullContents = [[NSMutableAttributedString alloc] initWithString:title
     21                                                                                          attributes:@{NSFontAttributeName: [NSFont boldSystemFontOfSize:[NSFont systemFontSize]]}];
     22         [fullContents appendAttributedString:[[NSAttributedString alloc] initWithString:[@"\n" stringByAppendingString:contents]
     23                                                                              attributes:@{NSFontAttributeName: [NSFont systemFontOfSize:[NSFont systemFontSize]]}]];
     24         [field setAttributedStringValue:fullContents];
     25         
     26     }
     27     NSSize textSize = [field.cell cellSizeForBounds:[field.cell drawingRectForBounds:NSMakeRect(0, 0, 240, CGFLOAT_MAX)]];
     28     textSize.width = ceil(textSize.width) + 16;
     29     textSize.height = ceil(textSize.height) + 12;
     30     [lastPopover setContentSize:textSize];
     31     
     32     if (!view.window.isVisible) {
     33         [view.window setIsVisible:true];
     34     }
     35     
     36     [lastPopover showRelativeToRect:view.bounds
     37                              ofView:view
     38                       preferredEdge:preferredEdge];
     39     
     40     NSRect frame = field.frame;
     41     frame.origin.x += 8;
     42     frame.origin.y += 6;
     43     frame.size.width -= 16;
     44     frame.size.height -= 12;
     45     field.frame = frame;
     46     
     47 
     48     [lastPopover performSelector:@selector(close) withObject:nil afterDelay:3.0];
     49     
     50     return lastPopover;
     51 }
     52 
     53 + (GBWarningPopover *) popoverWithContents:(NSString *)contents onView:(NSView *)view
     54 {
     55     return [self popoverWithContents:contents title:nil onView:view timeout:3.0 preferredEdge:NSMinYEdge];
     56 }
     57 
     58 + (GBWarningPopover *)popoverWithContents:(NSString *)contents onWindow:(NSWindow *)window
     59 {
     60     return [self popoverWithContents:contents onView:window.contentView.superview.subviews.lastObject];
     61 }
     62 
     63 @end

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.