iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IGraphicsMac_view.h
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#import <Cocoa/Cocoa.h>
12
13#if defined IGRAPHICS_GL
14#import <QuartzCore/QuartzCore.h>
15#endif
16
17#if defined IGRAPHICS_GLES2 || defined IGRAPHICS_GLES3
18#import <libEGL/libEGL.h>
19#import <libGLESv2/angle_gl.h>
20#endif
21
22#include "IGraphicsMac.h"
23#include "IGraphicsStructs.h"
24
25BEGIN_IPLUG_NAMESPACE
26BEGIN_IGRAPHICS_NAMESPACE
27
28inline NSRect ToNSRect(IGraphics* pGraphics, const IRECT& bounds)
29{
30 const float scale = pGraphics->GetDrawScale();
31 const float x = floor(bounds.L * scale);
32 const float y = floor(bounds.T * scale);
33 const float x2 = ceil(bounds.R * scale);
34 const float y2 = ceil(bounds.B * scale);
35
36 return NSMakeRect(x, y, x2 - x, y2 - y);
37}
38
39inline IRECT ToIRECT(IGraphics* pGraphics, const NSRect* pNSRect)
40{
41 const float scale = 1.f/pGraphics->GetDrawScale();
42 const float x = pNSRect->origin.x;
43 const float y = pNSRect->origin.y;
44 const float w = pNSRect->size.width;
45 const float h = pNSRect->size.height;
46
47 return IRECT(x * scale, y * scale, (x + w) * scale, (y + h) * scale);
48}
49
50inline NSColor* ToNSColor(const IColor& c)
51{
52 return [NSColor colorWithDeviceRed:(double) c.R / 255.0 green:(double) c.G / 255.0 blue:(double) c.B / 255.0 alpha:(double) c.A / 255.0];
53}
54
55inline IColor FromNSColor(const NSColor* c)
56{
57 return IColor(c.alphaComponent * 255., c.redComponent* 255., c.greenComponent * 255., c.blueComponent * 255.);
58}
59
60inline int GetMouseOver(IGraphicsMac* pGraphics)
61{
62 return pGraphics->GetMouseOver();
63}
64
65END_IGRAPHICS_NAMESPACE
66END_IPLUG_NAMESPACE
67
68// based on code by Scott Gruby http://blog.gruby.com/2008/03/30/filtering-nstextfield-take-2/
69@interface IGRAPHICS_FORMATTER : NSFormatter
70{
71 NSCharacterSet* filterCharacterSet;
72 int maxLength;
73 int maxValue;
74}
75
76- (void) setAcceptableCharacterSet: (NSCharacterSet*) pCharacterSet;
77- (void) setMaximumLength:(int) inLength;
78- (void) setMaximumValue:(int) inValue;
79
80@end
81
82@interface IGRAPHICS_TEXTFIELDCELL : NSTextFieldCell
83{
84 BOOL mIsEditingOrSelecting;
85}
86
87@end
88
89using namespace iplug;
90using namespace igraphics;
91
92@interface IGRAPHICS_MENU : NSMenu
93{
94 IPopupMenu* mIPopupMenu;
95}
96- (id) initWithIPopupMenuAndReceiver: (IPopupMenu*) pMenu : (NSView*) pView;
97- (IPopupMenu*) iPopupMenu;
98@end
99
100// Dummy view class used to receive Menu Events inline
101@interface IGRAPHICS_MENU_RCVR : NSView
102{
103 NSMenuItem* nsMenuItem;
104}
105- (void) onMenuSelection:(id)sender;
106- (NSMenuItem*) menuItem;
107@end
108
109@interface IGRAPHICS_TEXTFIELD : NSTextField
110{
111}
112- (bool) becomeFirstResponder;
113@end
114
115#if defined IGRAPHICS_GL2 || defined IGRAPHICS_GL3
116#define VIEW_BASE NSOpenGLView
117#else
118#define VIEW_BASE NSView
119#endif
120
121@interface IGRAPHICS_VIEW : VIEW_BASE <NSTextFieldDelegate, NSDraggingSource/*, WKScriptMessageHandler*/>
122{
123 CVDisplayLinkRef mDisplayLink;
124 dispatch_source_t mDisplaySource;
125 NSTimer* mTimer;
126
127 NSTrackingArea* mTrackingArea;
128 IGRAPHICS_TEXTFIELD* mTextFieldView;
129 NSCursor* mMoveCursor;
130 float mPrevX, mPrevY;
131 bool mMouseOutDuringDrag;
132 IRECTList mDirtyRects;
133 IColorPickerHandlerFunc mColorPickerFunc;
134
135#if defined IGRAPHICS_GLES2 || defined IGRAPHICS_GLES3
136 EGLDisplay mEGLDisplay;
137 EGLSurface mEGLSurface;
138 EGLContext mEGLContext;
139#endif
140
141@public
142 IGraphicsMac* mGraphics; // OBJC instance variables have to be pointers
143}
144- (id) initWithIGraphics: (IGraphicsMac*) pGraphics;
145- (BOOL) isOpaque;
146- (BOOL) acceptsFirstResponder;
147- (BOOL) acceptsFirstMouse: (NSEvent*) pEvent;
148- (void) viewDidMoveToWindow;
149- (void) viewDidChangeBackingProperties: (NSNotification*) pNotification;
150- (void) drawRect: (NSRect) bounds;
151- (void) render;
152- (void) killTimer;
153- (void) onTimer: (NSTimer*) pTimer;
154- (void) viewDidChangeEffectiveAppearance;
155//mouse
156- (void) getMouseXY: (NSEvent*) pEvent : (float&) x : (float&) y;
157- (IMouseInfo) getMouseLeft: (NSEvent*) pEvent;
158- (IMouseInfo) getMouseRight: (NSEvent*) pEvent;
159- (void) updateTrackingAreas;
160- (void) mouseEntered:(NSEvent*) pEvent;
161- (void) mouseExited:(NSEvent*) pEvent;
162- (void) mouseDown: (NSEvent*) pEvent;
163- (void) mouseUp: (NSEvent*) pEvent;
164- (void) mouseDragged: (NSEvent*) pEvent;
165- (void) rightMouseDown: (NSEvent*) pEvent;
166- (void) rightMouseUp: (NSEvent*) pEvent;
167- (void) rightMouseDragged: (NSEvent*) pEvent;
168- (void) mouseMoved: (NSEvent*) pEvent;
169- (void) scrollWheel: (NSEvent*) pEvent;
170- (void) keyDown: (NSEvent*) pEvent;
171- (void) keyUp: (NSEvent*) pEvent;
172//text entry
173- (void) removeFromSuperview;
174- (void) controlTextDidEndEditing: (NSNotification*) pNotification;
175- (void) createTextEntry: (int) paramIdx : (const IText&) text : (const char*) str : (int) length : (NSRect) areaRect;
176- (void) endUserInput;
177//pop-up menu
178- (IPopupMenu*) createPopupMenu: (IPopupMenu&) menu : (NSRect) bounds;
179//color picker
180- (BOOL) promptForColor: (IColor&) color : (IColorPickerHandlerFunc) func;
181- (void) onColorPicked: (NSColorPanel*) pColorPanel;
182
183//tooltip
184- (NSString*) view: (NSView*) pView stringForToolTip: (NSToolTipTag) tag point: (NSPoint) point userData: (void*) pData;
185- (void) registerToolTip: (IRECT&) bounds;
186//drag-and-drop
187- (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
188- (BOOL) performDragOperation: (id<NSDraggingInfo>) sender;
189- (NSDragOperation)draggingSession:(NSDraggingSession*) session sourceOperationMaskForDraggingContext:(NSDraggingContext)context;
190
191- (void) setMouseCursor: (ECursor) cursorType;
192
193- (void) swapBuffers;
194- (void) activateGLContext;
195- (void) deactivateGLContext;
196
197#if defined IGRAPHICS_GLES2 || defined IGRAPHICS_GLES3
198- (EGLDisplay) getEGLDisplay;
199- (EGLSurface) getEGLSurface;
200- (EGLContext) getEGLContext;
201#endif
202
203@end
204
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
float GetDrawScale() const
Gets the graphics context scaling factor.
Definition: IGraphics.h:1118
IGraphics platform class for macOS.
Definition: IGraphicsMac.h:24
A class for setting the contents of a pop up menu.
Used to manage a list of rectangular areas and optimize them for drawing to the screen.
Used to group mouse coordinates with mouse modifier information.
Used to manage color data, independent of draw class/platform.
Used to manage a rectangular area, independent of draw class/platform.
IText is used to manage font and text/text entry style for a piece of text on the UI,...