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