root/OpenSceneGraph/trunk/examples/osgviewerCocoa/ViewerCocoa.h
@
6901
| Revision 6901, 6.7 kB (checked in by robert, 6 years ago) |
|---|
| Line | |
|---|---|
| 1 | // |
| 2 | // ViewerCocoa.h |
| 3 | // osgviewerCocoa |
| 4 | // |
| 5 | // Created by Eric Wing on 11/12/06. |
| 6 | // Copyright 2006. Released under the OSGPL. |
| 7 | // Ported to osgViewer::Viewer by Martin Lavery 7/06/07 |
| 8 | // |
| 9 | /* This is the class interface for a custom NSView that interfaces with an osgViewer. |
| 10 | * Because Cocoa is written in Objective-C, but OSG is written in C++, we rely on |
| 11 | * Objective-C++ to make the integration easy. |
| 12 | * |
| 13 | * One thing to remember is that any Objective-C files that include this header |
| 14 | * must also be compiled as Objective-C++ because there are C++ constructs in |
| 15 | * this file (such as namespaces) which the normal Objective-C compiler |
| 16 | * won't understand. (The easy way to do this is rename the .m files to .mm.) |
| 17 | * |
| 18 | * In the event that you have a large, pre-existing code base written in |
| 19 | * pure Objective-C and you find that the header include propagates to a |
| 20 | * large number of your files, forcing you to mark many files to be compiled as |
| 21 | * Objective-C++, and you find that you don't want to change these files because |
| 22 | * they are shared with other pure Obj-C projects, you might consider further |
| 23 | * wrapping the C++ code so there are only C or Obj-C constructs in |
| 24 | * this header. There are several different techniques ranging from, wrapping |
| 25 | * the C++ code in pure C interfaces, to simply using void pointers in this |
| 26 | * file for any C++ pointers and casting appropriately in the implementation |
| 27 | * file. |
| 28 | */ |
| 29 | |
| 30 | |
| 31 | #import <Cocoa/Cocoa.h> |
| 32 | |
| 33 | namespace osgViewer |
| 34 | { |
| 35 | // Just a forward declaration so I don't need the #include in the header. |
| 36 | class Viewer; |
| 37 | class GraphicsWindowEmbedded; |
| 38 | } |
| 39 | |
| 40 | // Subclass NSOpenGLView. We could subclass NSView instead, but NSOpenGLView is easy. |
| 41 | @interface ViewerCocoa : NSOpenGLView |
| 42 | { |
| 43 | // Note: In Objective-C++, if you use objects instead of pointers as |
| 44 | // member instance variables, you MUST turn on "Call C++ Default Ctors/Dtors in Objective-C". |
| 45 | // -fobjc-call-cxx-cdtors |
| 46 | // This option makes sure constructors and destructors are run. |
| 47 | // This option is only available for gcc 4.0+ (Mac OS X 10.4+) |
| 48 | |
| 49 | // Is SimpleViewer supposed use ref_ptr? (Doesn't look like it to me.) |
| 50 | // If so, remember ref_ptr is an object on the stack and the cdtors option must be activated. |
| 51 | // We could also make simpleViewer an object instead of a pointer, but again, turn on the option. |
| 52 | osgViewer::Viewer* theViewer; |
| 53 | osgViewer::GraphicsWindowEmbedded* graphicsWindow; |
| 54 | |
| 55 | |
| 56 | // This timer is used to trigger animation callbacks since everything is event driven. |
| 57 | NSTimer* animationTimer; |
| 58 | |
| 59 | // Flags to help track whether ctrl-clicking or option-clicking is being used |
| 60 | BOOL isUsingCtrlClick; |
| 61 | BOOL isUsingOptionClick; |
| 62 | |
| 63 | // Flag to track whether the OpenGL multithreading engine is enabled or not |
| 64 | BOOL isUsingMultithreadedOpenGLEngine; |
| 65 | |
| 66 | } |
| 67 | |
| 68 | // My custom static method to create a basic pixel format |
| 69 | + (NSOpenGLPixelFormat*) basicPixelFormat; |
| 70 | |
| 71 | |
| 72 | // Official init methods |
| 73 | - (id) initWithFrame:(NSRect)frame_rect pixelFormat:(NSOpenGLPixelFormat*)pixel_format; |
| 74 | - (id) initWithCoder:(NSCoder*)the_coder; |
| 75 | - (id) initWithFrame:(NSRect)frame_rect; |
| 76 | |
| 77 | // Official function, overridden by this class to prevent flashing/tearing when in splitviews, scrollviews, etc. |
| 78 | - (void) renewGState; |
| 79 | |
| 80 | // My custom function for minimization. |
| 81 | - (void) prepareForMiniaturization:(NSNotification*)notification; |
| 82 | |
| 83 | |
| 84 | // Custom function to allow users to know if the Multithreaded OpenGL Engine is enabled |
| 85 | - (BOOL) isUsingMultithreadedOpenGLEngine; |
| 86 | |
| 87 | // Private init helper methods |
| 88 | - (void) initSharedOpenGLContext; |
| 89 | - (void) commonInit; |
| 90 | - (void) initOSGViewer; |
| 91 | - (void) initAnimationTimer; |
| 92 | |
| 93 | // Official/Special NSOpenGLView method that gets called for you to prepare your OpenGL state. |
| 94 | - (void) prepareOpenGL; |
| 95 | // Class dealloc method |
| 96 | - (void) dealloc; |
| 97 | - (void) finalize; |
| 98 | |
| 99 | // Official mouse event methods |
| 100 | - (void) mouseDown:(NSEvent*)the_event; |
| 101 | - (void) mouseDragged:(NSEvent*)the_event; |
| 102 | - (void) mouseUp:(NSEvent*)the_event; |
| 103 | - (void) rightMouseDown:(NSEvent*)the_event; |
| 104 | - (void) rightMouseDragged:(NSEvent*)the_event; |
| 105 | - (void) rightMouseUp:(NSEvent*)the_event; |
| 106 | - (void) otherMouseDown:(NSEvent*)the_event; |
| 107 | - (void) otherMouseDragged:(NSEvent*)the_event; |
| 108 | - (void) otherMouseUp:(NSEvent*)the_event; |
| 109 | |
| 110 | // Private setter/getter methods to track ctrl/option-clicking |
| 111 | - (void) setIsUsingCtrlClick:(BOOL)is_using_ctrl_click; |
| 112 | - (BOOL) isUsingCtrlClick; |
| 113 | - (void) setIsUsingOptionClick:(BOOL)is_using_option_click; |
| 114 | - (BOOL) isUsingOptionClick; |
| 115 | // Private helper methods to help deal with mouse events |
| 116 | - (void) doLeftMouseButtonDown:(NSEvent*)the_event; |
| 117 | - (void) doLeftMouseButtonUp:(NSEvent*)the_event; |
| 118 | - (void) doRightMouseButtonDown:(NSEvent*)the_event; |
| 119 | - (void) doRightMouseButtonUp:(NSEvent*)the_event; |
| 120 | - (void) doMiddleMouseButtonDown:(NSEvent*)the_event; |
| 121 | - (void) doExtraMouseButtonDown:(NSEvent*)the_event buttonNumber:(int)button_number; |
| 122 | - (void) doMiddleMouseButtonUp:(NSEvent*)the_event; |
| 123 | - (void) doExtraMouseButtonUp:(NSEvent*)the_event buttonNumber:(int)button_number; |
| 124 | |
| 125 | // Official scrollWheel (scrollball) method |
| 126 | - (void) scrollWheel:(NSEvent*)the_event; |
| 127 | |
| 128 | // Official methods for keyboard events |
| 129 | - (BOOL) acceptsFirstResponder; |
| 130 | - (void) keyDown:(NSEvent*)the_event; |
| 131 | - (void) keyUp:(NSEvent*)the_event; |
| 132 | |
| 133 | // My custom method to handle timer callbacks |
| 134 | - (void) animationCallback; |
| 135 | |
| 136 | // Official methods for view stuff and drawing |
| 137 | - (BOOL) isOpaque; |
| 138 | - (void) resizeViewport; |
| 139 | - (void) reshape; |
| 140 | - (void) drawRect:(NSRect)the_rect; |
| 141 | |
| 142 | // Private helper methods for drawing |
| 143 | - (NSBitmapImageRep*) renderOpenGLSceneToFramebuffer; |
| 144 | - (NSBitmapImageRep*) renderOpenGLSceneToFramebufferAsFormat:(int)gl_format viewWidth:(float)view_width viewHeight:(float)view_height; |
| 145 | - (NSBitmapImageRep*) renderOpenGLSceneToFramebufferAsFormat:(int)gl_format viewWidth:(float)view_width viewHeight:(float)view_height clearColorRed:(float)clear_red clearColorGreen:(float)clear_green clearColorBlue:(float)clear_blue clearColorAlpha:(float)clear_alpha; |
| 146 | - (NSImage*)imageFromBitmapImageRep:(NSBitmapImageRep*)bitmap_image_rep; |
| 147 | |
| 148 | |
| 149 | // Official methods for drag and drop (view as target) |
| 150 | - (unsigned int) draggingEntered:(id <NSDraggingInfo>)the_sender; |
| 151 | - (void) draggingExited:(id <NSDraggingInfo>)the_sender; |
| 152 | - (BOOL) prepareForDragOperation:(id <NSDraggingInfo>)the_sender; |
| 153 | - (BOOL) performDragOperation:(id <NSDraggingInfo>)the_sender; |
| 154 | - (void) concludeDragOperation:(id <NSDraggingInfo>)the_sender; |
| 155 | |
| 156 | // Official method for copy (i.e. copy & paste) |
| 157 | - (IBAction) copy:(id)sender; |
| 158 | |
| 159 | // Private helper methods for drag and drop and copy/paste (view as source) |
| 160 | - (NSData*) dataWithTIFFOfContentView; |
| 161 | - (NSData*) contentsAsDataOfType:(NSString *)pboardType; |
| 162 | - (void) startDragAndDropAsSource:(NSEvent*)the_event; |
| 163 | |
| 164 | |
| 165 | // Examples of providing an action to connect to. |
| 166 | - (IBAction) resetPosition:(id)the_sender; |
| 167 | - (IBAction) takeBackgroundColorFrom:(id)the_sender; |
| 168 | |
| 169 | |
| 170 | @end |
Note: See TracBrowser
for help on using the browser.
