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#include "IGraphicsMac.h"
18#include "IGraphicsStructs.h"
19
20BEGIN_IPLUG_NAMESPACE
21BEGIN_IGRAPHICS_NAMESPACE
22
23inline NSRect ToNSRect(IGraphics* pGraphics, const IRECT& bounds)
24{
25 const float scale = pGraphics->GetDrawScale();
26 const float x = floor(bounds.L * scale);
27 const float y = floor(bounds.T * scale);
28 const float x2 = ceil(bounds.R * scale);
29 const float y2 = ceil(bounds.B * scale);
30
31 return NSMakeRect(x, y, x2 - x, y2 - y);
32}
33
34inline IRECT ToIRECT(IGraphics* pGraphics, const NSRect* pNSRect)
35{
36 const float scale = 1.f/pGraphics->GetDrawScale();
37 const float x = pNSRect->origin.x;
38 const float y = pNSRect->origin.y;
39 const float w = pNSRect->size.width;
40 const float h = pNSRect->size.height;
41
42 return IRECT(x * scale, y * scale, (x + w) * scale, (y + h) * scale);
43}
44
45inline NSColor* ToNSColor(const IColor& c)
46{
47 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];
48}
49
50inline IColor FromNSColor(const NSColor* c)
51{
52 return IColor(c.alphaComponent * 255., c.redComponent* 255., c.greenComponent * 255., c.blueComponent * 255.);
53}
54
55inline int GetMouseOver(IGraphicsMac* pGraphics)
56{
57 return pGraphics->GetMouseOver();
58}
59
60END_IGRAPHICS_NAMESPACE
61END_IPLUG_NAMESPACE
62
63// based on code by Scott Gruby http://blog.gruby.com/2008/03/30/filtering-nstextfield-take-2/
64@interface IGRAPHICS_FORMATTER : NSFormatter
65{
66 NSCharacterSet* filterCharacterSet;
67 int maxLength;
68 int maxValue;
69}
70
71- (void) setAcceptableCharacterSet: (NSCharacterSet*) pCharacterSet;
72- (void) setMaximumLength:(int) inLength;
73- (void) setMaximumValue:(int) inValue;
74
75@end
76
77@interface IGRAPHICS_TEXTFIELDCELL : NSTextFieldCell
78{
79 BOOL mIsEditingOrSelecting;
80}
81
82@end
83
84using namespace iplug;
85using namespace igraphics;
86
87@interface IGRAPHICS_MENU : NSMenu
88{
89 IPopupMenu* mIPopupMenu;
90}
91- (id) initWithIPopupMenuAndReceiver: (IPopupMenu*) pMenu : (NSView*) pView;
92- (IPopupMenu*) iPopupMenu;
93@end
94
95// Dummy view class used to receive Menu Events inline
96@interface IGRAPHICS_MENU_RCVR : NSView
97{
98 NSMenuItem* nsMenuItem;
99}
100- (void) onMenuSelection:(id)sender;
101- (NSMenuItem*) menuItem;
102@end
103
104@interface IGRAPHICS_TEXTFIELD : NSTextField
105{
106}
107- (bool) becomeFirstResponder;
108@end
109
110#ifdef IGRAPHICS_GL
111#define VIEW_BASE NSOpenGLView
112#else
113#define VIEW_BASE NSView
114#endif
115
116@interface IGRAPHICS_VIEW : VIEW_BASE <NSTextFieldDelegate, NSDraggingSource/*, WKScriptMessageHandler*/>
117{
118 CVDisplayLinkRef mDisplayLink;
119 dispatch_source_t mDisplaySource;
120 NSTimer* mTimer;
121
122 NSTrackingArea* mTrackingArea;
123 IGRAPHICS_TEXTFIELD* mTextFieldView;
124 NSCursor* mMoveCursor;
125 float mPrevX, mPrevY;
126 bool mMouseOutDuringDrag;
127 IRECTList mDirtyRects;
128 IColorPickerHandlerFunc mColorPickerFunc;
129@public
130 IGraphicsMac* mGraphics; // OBJC instance variables have to be pointers
131}
132- (id) initWithIGraphics: (IGraphicsMac*) pGraphics;
133- (BOOL) isOpaque;
134- (BOOL) acceptsFirstResponder;
135- (BOOL) acceptsFirstMouse: (NSEvent*) pEvent;
136- (void) viewDidMoveToWindow;
137- (void) viewDidChangeBackingProperties: (NSNotification*) pNotification;
138- (void) drawRect: (NSRect) bounds;
139- (void) render;
140- (void) killTimer;
141- (void) onTimer: (NSTimer*) pTimer;
142- (void) viewDidChangeEffectiveAppearance;
143//mouse
144- (void) getMouseXY: (NSEvent*) pEvent : (float&) x : (float&) y;
145- (IMouseInfo) getMouseLeft: (NSEvent*) pEvent;
146- (IMouseInfo) getMouseRight: (NSEvent*) pEvent;
147- (void) updateTrackingAreas;
148- (void) mouseEntered:(NSEvent*) pEvent;
149- (void) mouseExited:(NSEvent*) pEvent;
150- (void) mouseDown: (NSEvent*) pEvent;
151- (void) mouseUp: (NSEvent*) pEvent;
152- (void) mouseDragged: (NSEvent*) pEvent;
153- (void) rightMouseDown: (NSEvent*) pEvent;
154- (void) rightMouseUp: (NSEvent*) pEvent;
155- (void) rightMouseDragged: (NSEvent*) pEvent;
156- (void) mouseMoved: (NSEvent*) pEvent;
157- (void) scrollWheel: (NSEvent*) pEvent;
158- (void) keyDown: (NSEvent*) pEvent;
159- (void) keyUp: (NSEvent*) pEvent;
160//text entry
161- (void) removeFromSuperview;
162- (void) controlTextDidEndEditing: (NSNotification*) pNotification;
163- (void) createTextEntry: (int) paramIdx : (const IText&) text : (const char*) str : (int) length : (NSRect) areaRect;
164- (void) endUserInput;
165//pop-up menu
166- (IPopupMenu*) createPopupMenu: (IPopupMenu&) menu : (NSRect) bounds;
167//color picker
168- (BOOL) promptForColor: (IColor&) color : (IColorPickerHandlerFunc) func;
169- (void) onColorPicked: (NSColorPanel*) pColorPanel;
170
171//tooltip
172- (NSString*) view: (NSView*) pView stringForToolTip: (NSToolTipTag) tag point: (NSPoint) point userData: (void*) pData;
173- (void) registerToolTip: (IRECT&) bounds;
174//drag-and-drop
175- (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
176- (BOOL) performDragOperation: (id<NSDraggingInfo>) sender;
177- (NSDragOperation)draggingSession:(NSDraggingSession*) session sourceOperationMaskForDraggingContext:(NSDraggingContext)context;
178//
179- (void) setMouseCursor: (ECursor) cursorType;
180@end
181
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:1101
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,...