Skip to content

Commit 6a3ba76

Browse files
committed
[[ Cocoa ]] Updated some TODO comments.
[[ Cocoa ]] Implemented screen snapshot of area.
1 parent a0ae95c commit 6a3ba76

File tree

12 files changed

+210
-158
lines changed

12 files changed

+210
-158
lines changed

engine/src/desktop-dc.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,6 @@ void MCScreenDC::listprinters(MCExecPoint& ep)
914914
MCListSystemPrinters(ep);
915915
}
916916

917-
// COCOA-TODO: Printer creation.
918917
MCPrinter *MCScreenDC::createprinter(void)
919918
{
920919
return MCCreateSystemPrinter();

engine/src/desktop-stack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void MCStack::realize(void)
102102
else if (mode == WM_TOOLTIP)
103103
t_window_style = kMCPlatformWindowStyleToolTip;
104104
else if (mode == WM_DRAWER)
105-
; // COCOA-TODO
105+
; // COCOA-TODO: Implement drawers
106106
else
107107
t_window_style = kMCPlatformWindowStyleDocument;
108108

@@ -220,7 +220,7 @@ MCRectangle MCStack::view_platform_setgeom(const MCRectangle &p_rect)
220220

221221
void MCStack::syncscroll(void)
222222
{
223-
// COCOA-TODO: Do something with scroll
223+
// COCOA-TODO: Make sure contained views also scroll (?)
224224
}
225225

226226
void MCStack::start_externals()

engine/src/mac-abort.mm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,10 @@ bool MCPlatformGetAbortKeyPressed(void)
316316

317317
bool MCPlatformInitializeAbortKey(void)
318318
{
319-
// COCOA-TODO: If AX isn't enabled, then we can't use event taps. It does
320-
// seem one can make a process trusted (after a restart at least), we could
321-
// easily integrate this into the IDE.
319+
#ifdef USE_EVENTTAP
322320
if (!AXAPIEnabled())
323321
return true;
322+
#endif
324323

325324
s_abort_key_thread = [[MCAbortKeyThread alloc] init];
326325
[s_abort_key_thread start];

engine/src/mac-core.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,8 @@ MCPlatformModifiers MCMacPlatformMapNSModifiersToModifiers(NSUInteger p_modifier
13161316
if ((p_modifiers & NSCommandKeyMask) != 0)
13171317
t_modifiers |= kMCPlatformModifierControl;
13181318

1319-
// COCOA-TODO: Sort out capslock.
1319+
if ((p_modifiers & NSAlphaShiftKeyMask) != 0)
1320+
t_modifiers |= kMCPlatformModifierCapsLock;
13201321

13211322
return t_modifiers;
13221323
}

engine/src/mac-menu.mm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,6 @@ static void MCPlatformStartUsingMenuAsMenubar(MCPlatformMenuRef p_menu)
654654
if (p_menu -> is_menubar)
655655
return;
656656

657-
// COCOA-TODO: Finish app menu support.
658-
659657
if (s_app_menu_delegate == nil)
660658
s_app_menu_delegate = [[com_runrev_livecode_MCAppMenuDelegate alloc] init];
661659

engine/src/mac-pasteboard.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
{ (NSString *)kUTTypePNG, kMCPlatformPasteboardFlavorPNG, MCMacPasteboardConvertIdentity },
6060
{ (NSString *)kUTTypeTIFF, kMCPlatformPasteboardFlavorPNG, MCMacPasteboardConvertTIFFToPNG },
6161

62-
// COCOA-TODO: Declare these appropriately!
62+
// COCOA-TODO: Declare objects UT type so copy/paste objects works between LiveCode instances.
6363
{ kMCMacPasteboardObjectsUTString, kMCPlatformPasteboardFlavorObjects, MCMacPasteboardConvertIdentity },
6464
//{ @"com.runrev.livecode.text-styled-1", kMCPlatformPasteboardFlavorStyledText, MCMacPasteboardConvertIdentity },
6565
};

engine/src/mac-snapshot.mm

Lines changed: 202 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,181 @@
2828

2929
////////////////////////////////////////////////////////////////////////////////
3030

31+
extern MCRectangle MCU_make_rect(int2 x, int2 y, uint2 w, uint2 h);
32+
33+
static CGPoint s_snapshot_start_point, s_snapshot_end_point;
34+
static bool s_snapshot_done = false;
35+
36+
static float menu_screen_height(void)
37+
{
38+
NSArray *t_screens;
39+
t_screens = [NSScreen screens];
40+
41+
NSScreen *t_screen;
42+
for(uint32_t i = 0; i < [t_screens count]; i++)
43+
{
44+
t_screen = (NSScreen *)[t_screens objectAtIndex: i];
45+
if (NSPointInRect(NSZeroPoint, [t_screen frame]))
46+
break;
47+
}
48+
49+
return NSMaxY([t_screen frame]);
50+
}
51+
52+
static NSPoint cocoa_point_from_carbon(CGFloat x, CGFloat y)
53+
{
54+
return NSMakePoint(x, menu_screen_height() - y);
55+
}
56+
57+
static NSRect cocoa_rect_from_carbon(CGRect p_rect)
58+
{
59+
NSPoint t_top_left, t_bottom_right;
60+
t_top_left = cocoa_point_from_carbon(p_rect . origin . x, p_rect . origin . y + p_rect . size . height);
61+
return NSMakeRect(t_top_left . x, t_top_left . y, p_rect . size . width, p_rect . size . height);
62+
}
63+
64+
static CGPoint carbon_point_from_cocoa(NSPoint p_point)
65+
{
66+
return CGPointMake(p_point . x, menu_screen_height() - p_point . y);
67+
}
68+
69+
static CGRect cgrect_from_points(CGPoint x, CGPoint y)
70+
{
71+
CGFloat l, t, r, b;
72+
l = MCMin(x . x, y . x);
73+
r = MCMax(x . x, y . x);
74+
t = MCMin(x . y, y . y);
75+
b = MCMax(x . y, y . y);
76+
return CGRectMake(l, t, r - l, b - t);
77+
}
78+
79+
static MCRectangle mcrect_from_points(CGPoint x, CGPoint y)
80+
{
81+
CGFloat l, t, r, b;
82+
l = MCMin(x . x, y . x);
83+
r = MCMax(x . x, y . x);
84+
t = MCMin(x . y, y . y);
85+
b = MCMax(x . y, y . y);
86+
return MCU_make_rect(l, t, r - l, b - t);
87+
}
88+
89+
static Rect rect_from_points(CGPoint x, CGPoint y)
90+
{
91+
CGFloat l, t, r, b;
92+
l = MCMin(x . x, y . x);
93+
r = MCMax(x . x, y . x);
94+
t = MCMin(x . y, y . y);
95+
b = MCMax(x . y, y . y);
96+
97+
Rect t_rect;
98+
SetRect(&t_rect, l, t, r, b);
99+
100+
return t_rect;
101+
}
102+
103+
@interface MCSnapshotWindow : NSWindow
104+
{
105+
NSBox *m_region;
106+
}
107+
108+
- (id)init;
109+
- (void)dealloc;
110+
111+
- (void)mouseDown: (NSEvent *)event;
112+
- (void)mouseUp: (NSEvent *)event;
113+
- (void)mouseDragged: (NSEvent *)event;
114+
@end
115+
116+
@implementation MCSnapshotWindow
117+
118+
- (id)init
119+
{
120+
// Compute the desktop bounds.
121+
NSRect t_bounds;
122+
t_bounds = NSZeroRect;
123+
NSArray *t_screens;
124+
t_screens = [NSScreen screens];
125+
for(uint32_t i = 0; i < [t_screens count]; i++)
126+
{
127+
NSScreen *t_screen;
128+
t_screen = (NSScreen *)[t_screens objectAtIndex: i];
129+
t_bounds = NSUnionRect(t_bounds, [t_screen frame]);
130+
}
131+
132+
// Initialize the window.
133+
self = [super initWithContentRect: t_bounds styleMask: NSBorderlessWindowMask backing: NSBackingStoreBuffered defer: NO];
134+
135+
// Make sure the window is not opaque to events, and renders everything
136+
// at 50% transparency.
137+
[self setOpaque: NO];
138+
[self setAlphaValue: 0.5];
139+
[self setBackgroundColor: [NSColor clearColor]];
140+
[self setLevel: NSScreenSaverWindowLevel];
141+
[self setIgnoresMouseEvents: NO];
142+
143+
// Setup the region used to display the selected area.
144+
m_region = [[NSBox alloc] initWithFrame: NSZeroRect];
145+
[m_region setTitlePosition: NSNoTitle];
146+
[m_region setBorderType: NSLineBorder];
147+
[m_region setBoxType: NSBoxCustom];
148+
[m_region setBorderWidth: 1];
149+
[m_region setBorderColor: [NSColor whiteColor]];
150+
[m_region setFillColor: [NSColor grayColor]];
151+
[[self contentView] addSubview: m_region];
152+
153+
// Remember to return the window.
154+
return self;
155+
}
156+
157+
- (void)dealloc
158+
{
159+
[m_region release];
160+
[super dealloc];
161+
}
162+
163+
- (void)mouseDown: (NSEvent *)event
164+
{
165+
// Start the snapshot region.
166+
s_snapshot_start_point = carbon_point_from_cocoa([event locationInWindow]); //CGEventGetLocation([event CGEvent]);
167+
s_snapshot_end_point = s_snapshot_start_point;
168+
}
169+
170+
- (void)mouseUp: (NSEvent *)event
171+
{
172+
// Finish the snapshot region.
173+
s_snapshot_end_point = carbon_point_from_cocoa([event locationInWindow]); //CGEventGetLocation([event CGEvent]);
174+
s_snapshot_done = true;
175+
176+
// Remove the region from display and force an update to ensure in QD mode, we don't get
177+
// partial grayness over the selected area.
178+
[m_region setHidden: YES];
179+
[[self contentView] setNeedsDisplayInRect: [m_region frame]];
180+
[self displayIfNeeded];
181+
}
182+
183+
- (void)mouseDragged: (NSEvent *)event
184+
{
185+
// Update the snapshot end point
186+
s_snapshot_end_point = carbon_point_from_cocoa([event locationInWindow]); //CGEventGetLocation([event CGEvent]);
187+
188+
// Get the old and new frames.
189+
NSRect t_old_frame, t_new_frame;
190+
t_old_frame = [m_region frame];
191+
t_new_frame = cocoa_rect_from_carbon(cgrect_from_points(s_snapshot_start_point, s_snapshot_end_point));
192+
193+
// Update the frames
194+
[m_region setFrame: t_new_frame];
195+
[m_region setNeedsDisplay: YES];
196+
197+
// Make sure the contentview is redrawn in the appropriate places.
198+
[[self contentView] setNeedsDisplayInRect: t_old_frame];
199+
[[self contentView] setNeedsDisplayInRect: t_new_frame];
200+
}
201+
202+
@end
203+
204+
////////////////////////////////////////////////////////////////////////////////
205+
31206
static void MCMacPlatformCGImageToMCImageBitmap(CGImageRef p_image, MCImageBitmap*& r_bitmap)
32207
{
33208
if (p_image != nil)
@@ -54,8 +229,33 @@ static void MCMacPlatformCGImageToMCImageBitmap(CGImageRef p_image, MCImageBitma
54229

55230
void MCPlatformScreenSnapshotOfUserArea(MCImageBitmap*& r_bitmap)
56231
{
57-
// COCOA-TODO: Screen snapshot of area.
58-
r_bitmap = nil;
232+
// Compute the rectangle to grab in screen co-ords.
233+
MCRectangle t_screen_rect;
234+
235+
// Create a window that covers the whole screen.
236+
MCSnapshotWindow *t_window;
237+
t_window = [[MCSnapshotWindow alloc] init];
238+
[t_window orderFront: nil];
239+
240+
// Set the cursor to cross.
241+
[[NSCursor crosshairCursor] push];
242+
243+
// Wait until the mouse has been released.
244+
s_snapshot_done = false;
245+
while(!s_snapshot_done)
246+
MCPlatformWaitForEvent(60.0, false);
247+
248+
// Remove the window from display.
249+
[t_window orderOut: nil];
250+
[t_window release];
251+
252+
// Return the cursor to arrow.
253+
[NSCursor pop];
254+
255+
// Compute the selected rectangle.
256+
t_screen_rect = mcrect_from_points(s_snapshot_start_point, s_snapshot_end_point);
257+
258+
MCPlatformScreenSnapshot(t_screen_rect, r_bitmap);
59259
}
60260

61261
void MCPlatformScreenSnapshotOfWindow(uint32_t p_window_id, MCImageBitmap*& r_bitmap)

0 commit comments

Comments
 (0)