viewport.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #if defined(Hiro_Viewport)
  2. @implementation CocoaViewport : NSView
  3. -(id) initWith:(hiro::mViewport&)viewportReference {
  4. if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
  5. viewport = &viewportReference;
  6. }
  7. return self;
  8. }
  9. -(void) resetCursorRects {
  10. if(auto mouseCursor = NSMakeCursor(viewport->mouseCursor())) {
  11. [self addCursorRect:self.bounds cursor:mouseCursor];
  12. }
  13. }
  14. -(void) drawRect:(NSRect)rect {
  15. [[NSColor blackColor] setFill];
  16. NSRectFillUsingOperation(rect, NSCompositeSourceOver);
  17. }
  18. -(BOOL) acceptsFirstResponder {
  19. return YES;
  20. }
  21. -(NSDragOperation) draggingEntered:(id<NSDraggingInfo>)sender {
  22. return DropPathsOperation(sender);
  23. }
  24. -(BOOL) performDragOperation:(id<NSDraggingInfo>)sender {
  25. auto paths = DropPaths(sender);
  26. if(!paths) return NO;
  27. viewport->doDrop(paths);
  28. return YES;
  29. }
  30. -(void) keyDown:(NSEvent*)event {
  31. }
  32. -(void) keyUp:(NSEvent*)event {
  33. }
  34. @end
  35. namespace hiro {
  36. auto pViewport::construct() -> void {
  37. @autoreleasepool {
  38. cocoaView = cocoaViewport = [[CocoaViewport alloc] initWith:self()];
  39. pWidget::construct();
  40. }
  41. }
  42. auto pViewport::destruct() -> void {
  43. @autoreleasepool {
  44. [cocoaView removeFromSuperview];
  45. [cocoaView release];
  46. }
  47. }
  48. auto pViewport::handle() const -> uintptr_t {
  49. return (uintptr_t)cocoaViewport;
  50. }
  51. auto pViewport::setDroppable(bool droppable) -> void {
  52. @autoreleasepool {
  53. if(droppable) {
  54. [cocoaViewport registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
  55. } else {
  56. [cocoaViewport unregisterDraggedTypes];
  57. }
  58. }
  59. }
  60. auto pViewport::setFocusable(bool focusable) -> void {
  61. //TODO
  62. }
  63. }
  64. #endif