Vuo  2.0.2
VuoAppSplashView.m
Go to the documentation of this file.
1 
10 #ifndef NS_RETURNS_INNER_POINTER
11 #define NS_RETURNS_INNER_POINTER
12 #endif
13 #import <AppKit/AppKit.h>
14 
15 #import "VuoAppSplashView.h"
16 #import "VuoAppSplashWindow.h"
17 #import "module.h"
18 
19 #import "vuo-wordmark-teal-cropped.h"
20 
22 NSString *windowURL = @"https://vuo.org/";
24 NSString *windowURLCE = @"https://vuo.org/community-edition";
26 NSString *windowURLLabel = @"vuo.org";
28 NSString *windowURLCELabel = @"vuo.org/community-edition";
29 
30 @implementation VuoAppSplashView
31 
32 - (instancetype)init
33 {
34  if (self = [super init])
35  {
36  _borderVisible = YES;
37  }
38  return self;
39 }
40 
41 - (void)drawRect:(NSRect)rect
42 {
43  double windowWidth = self.bounds.size.width;
44  double windowHeight = self.bounds.size.height;
45  bool large = windowWidth > 320;
46 
47  if (large)
48  [NSColor.controlBackgroundColor setFill];
49  else
50  [NSColor.clearColor setFill];
51  [NSColor.windowBackgroundColor setStroke];
52  NSBezierPath *path = [NSBezierPath bezierPathWithRect:rect];
53  path.lineWidth = 2;
54  [path fill];
55  if (_borderVisible)
56  [path stroke];
57 
58 
59  NSData *logoData = [NSData dataWithBytesNoCopy:vuo_wordmark_teal_cropped_pdf
60  length:vuo_wordmark_teal_cropped_pdf_len
61  freeWhenDone:NO];
62  NSImage *logoImage = [[NSImage alloc] initWithData:logoData];
63 
64  NSMutableParagraphStyle *textStyle = NSMutableParagraphStyle.defaultParagraphStyle.mutableCopy;
65  textStyle.alignment = 2; // NSTextAlignmentCenter
66  NSMutableDictionary *textAttributes = [NSMutableDictionary dictionaryWithObjectsAndKeys:
67  [NSFont fontWithName:@"Helvetica Neue Light" size:(large ? 18 : 13)], NSFontAttributeName,
68  NSColor.secondaryLabelColor, NSForegroundColorAttributeName,
69  textStyle, NSParagraphStyleAttributeName,
70  @2.5, NSKernAttributeName,
71  nil
72  ];
73 
74  [@"Powered by" drawInRect:NSMakeRect(0, windowHeight*5/8, windowWidth, windowHeight/4)
75  withAttributes:textAttributes];
76 
77  // Draw the logo centered in the window.
78  {
79  double imageAspect = logoImage.size.width / logoImage.size.height;
80  double imageScale = .5;
81  [logoImage drawInRect:NSMakeRect(windowWidth/2 - windowWidth*imageScale/2,
82  windowHeight/2 - windowWidth*imageScale/imageAspect/2,
83  windowWidth*imageScale,
84  windowWidth*imageScale/imageAspect)];
85  }
86 
88  textAttributes[NSKernAttributeName] = @0;
89  textAttributes[NSUnderlineStyleAttributeName] = @(NSUnderlineStyleSingle);
90  textAttributes[NSUnderlineColorAttributeName] = NSColor.tertiaryLabelColor;
91  [urlLabel drawInRect:NSMakeRect(0, windowHeight*-1/16, windowWidth, windowHeight/4)
92  withAttributes:textAttributes];
93 
94  [logoImage release];
95  [textStyle release];
96 }
97 
98 - (void)mouseDown:(NSEvent *)event
99 {
100  [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:(VuoShouldShowSplashWindow() ? windowURLCE : windowURL)]];
101 }
102 
103 - (void)resetCursorRects
104 {
105  [self addCursorRect:self.visibleRect cursor:NSCursor.pointingHandCursor];
106 }
107 
108 @end