Native Mac OS X OtaClock replica
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainView.m 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // MainView.m
  3. // OtaClock
  4. //
  5. // Created by Thomas Buck on 16.08.15.
  6. // Copyright (c) 2015 xythobuz. All rights reserved.
  7. //
  8. #import "MainWindow.h"
  9. #import "MainView.h"
  10. #define BASE_IMAGE_RESIZE_FACTOR 0.2
  11. @implementation MainView
  12. @synthesize otaconImage;
  13. -(void)awakeFromNib {
  14. NSLog(@"MainView:awakeFromNib %@ %@", self, [self window]);
  15. // Load background image
  16. self.otaconImage = [NSImage imageNamed:@"Otacon"];
  17. // Set window to a useful default size
  18. NSSize newSize = [otaconImage size];
  19. newSize.width *= BASE_IMAGE_RESIZE_FACTOR;
  20. newSize.height *= BASE_IMAGE_RESIZE_FACTOR;
  21. [(MainWindow*)[self window] setDefaultBackgroundSize:newSize];
  22. }
  23. -(void)drawRect:(NSRect)dirtyRect {
  24. // Clear background
  25. [[NSColor clearColor] set];
  26. NSRectFill([self frame]);
  27. // Draw main image into window bounds
  28. [otaconImage drawInRect:[self bounds]];
  29. }
  30. -(BOOL)acceptsFirstMouse:(NSEvent *)theEvent {
  31. // This is required so we get mouse events even if we don't have focus
  32. // (needed to allow dragging the window without focus)
  33. return YES;
  34. }
  35. @end