feat: you can summary screen shot directly
This commit is contained in:
@@ -15,6 +15,7 @@ extern void nativeOverlayConfirm(int x, int y, int w, int h, const char *annotat
|
||||
extern void nativeOverlayCopy(int x, int y, int w, int h, const char *annotationsJSON);
|
||||
extern void nativeOverlaySave(int x, int y, int w, int h, const char *annotationsJSON, const char *dir);
|
||||
extern void nativeOverlaySaveRemote(int x, int y, int w, int h, const char *annotationsJSON);
|
||||
extern void nativeOverlaySummarize(int x, int y, int w, int h, const char *annotationsJSON);
|
||||
extern void nativeOverlayCancel(void);
|
||||
|
||||
static NSWindow *nativeOverlayWindow = nil;
|
||||
@@ -101,9 +102,8 @@ static id nativeOverlayKeyMonitor = nil;
|
||||
// as returning a +1 retained object.
|
||||
@property(strong) NSButton *clipboardButton;
|
||||
@property(strong) NSButton *saveButton;
|
||||
// `saveRemoteButton` triggers a placeholder action ("not yet supported")
|
||||
// per product spec; the icon comes from save-remote.svg.
|
||||
@property(strong) NSButton *saveRemoteButton;
|
||||
@property(strong) NSButton *summaryButton;
|
||||
@property(strong) NSButton *uploadButton;
|
||||
@property(strong) NSButton *penButton;
|
||||
@property(strong) NSButton *rectButton;
|
||||
@@ -120,6 +120,7 @@ static id nativeOverlayKeyMonitor = nil;
|
||||
- (void)copySelection;
|
||||
- (void)saveSelection;
|
||||
- (void)saveRemoteSelection;
|
||||
- (void)summarizeSelection;
|
||||
- (void)cancelSelection;
|
||||
@end
|
||||
|
||||
@@ -144,6 +145,7 @@ static id nativeOverlayKeyMonitor = nil;
|
||||
_clipboardButton = [SnipHoverButton buttonWithTitle:@"" target:self action:@selector(copySelection)];
|
||||
_saveButton = [SnipHoverButton buttonWithTitle:@"" target:self action:@selector(saveSelection)];
|
||||
_saveRemoteButton = [SnipHoverButton buttonWithTitle:@"" target:self action:@selector(saveRemoteSelection)];
|
||||
_summaryButton = [SnipHoverButton buttonWithTitle:@"" target:self action:@selector(summarizeSelection)];
|
||||
_uploadButton = [SnipHoverButton buttonWithTitle:@"" target:self action:@selector(confirmSelection)];
|
||||
// Tooltip strings shown on hover for each action button.
|
||||
// Localized in Chinese to match the rest of the action UI surface.
|
||||
@@ -151,6 +153,7 @@ static id nativeOverlayKeyMonitor = nil;
|
||||
[_clipboardButton setToolTip:@"复制图片"];
|
||||
[_saveButton setToolTip:@"保存本地"];
|
||||
[_saveRemoteButton setToolTip:@"保存远端"];
|
||||
[_summaryButton setToolTip:@"复制总结"];
|
||||
[_uploadButton setToolTip:@"上传云端"];
|
||||
_penButton = [NSButton buttonWithTitle:@"" target:self action:@selector(selectPen)];
|
||||
_rectButton = [NSButton buttonWithTitle:@"" target:self action:@selector(selectRect)];
|
||||
@@ -171,10 +174,10 @@ static id nativeOverlayKeyMonitor = nil;
|
||||
// Add the action toolbar background BEFORE the buttons so it sits
|
||||
// behind them in the view hierarchy (AppKit z-order = subview order).
|
||||
[self addSubview:_actionToolbarBg];
|
||||
for (NSView *view in @[_cancelButton, _clipboardButton, _saveButton, _saveRemoteButton, _uploadButton, _penButton, _rectButton, _ellipseButton, _colorButton, _undoButton, _paletteView, _sizeLabel, _hintLabel]) {
|
||||
for (NSView *view in @[_cancelButton, _clipboardButton, _saveButton, _saveRemoteButton, _summaryButton, _uploadButton, _penButton, _rectButton, _ellipseButton, _colorButton, _undoButton, _paletteView, _sizeLabel, _hintLabel]) {
|
||||
[self addSubview:view];
|
||||
}
|
||||
for (NSView *view in @[_cancelButton, _clipboardButton, _saveButton, _saveRemoteButton, _uploadButton, _penButton, _rectButton, _ellipseButton, _colorButton, _undoButton, _paletteView, _actionToolbarBg]) {
|
||||
for (NSView *view in @[_cancelButton, _clipboardButton, _saveButton, _saveRemoteButton, _summaryButton, _uploadButton, _penButton, _rectButton, _ellipseButton, _colorButton, _undoButton, _paletteView, _actionToolbarBg]) {
|
||||
[view setHidden:YES];
|
||||
}
|
||||
[_sizeLabel setHidden:YES];
|
||||
@@ -248,6 +251,7 @@ static id nativeOverlayKeyMonitor = nil;
|
||||
// save-remote.svg — provided by the user; its content is the same arrow
|
||||
// icon as the previous upload, so we reuse it verbatim here.
|
||||
NSImage *saveRemoteIcon = [self iconFromSVG:@"<svg viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'><path d='M481.749333 353.792c16.682667-16.64 43.690667-16.64 60.373334 0l120.917333 120.832 3.541333 4.010667a42.666667 42.666667 0 0 1-63.872 56.32L554.666667 486.954667V896a42.666667 42.666667 0 0 1-85.333334 0v-409.173333l-48.170666 48.128a42.666667 42.666667 0 0 1-60.330667 0l-3.541333-4.010667a42.666667 42.666667 0 0 1 3.541333-56.32zM512 85.333333c122.538667 0 227.84 73.813333 273.92 179.370667A213.333333 213.333333 0 0 1 725.333333 682.666667a42.666667 42.666667 0 0 1-4.992-85.034667L725.333333 597.333333a128 128 0 0 0 36.394667-250.794666l-38.144-11.264-15.914667-36.437334a213.376 213.376 0 0 0-407.296 58.026667l-7.381333 58.368-57.173333 13.824A85.418667 85.418667 0 0 0 256 597.333333h42.666667a42.666667 42.666667 0 0 1 0 85.333334H256a170.666667 170.666667 0 0 1-40.277333-336.554667A298.709333 298.709333 0 0 1 512 85.333333z' fill='white'/></svg>"];
|
||||
NSImage *summaryIcon = [self iconFromSVG:@"<svg viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'><path d='M256 128h448l192 192v576H256V128z m64 64v640h512V352H672V192H320z m416 45.248V288h50.752L736 237.248zM384 448h384v64H384v-64z m0 128h384v64H384v-64z m0 128h256v64H384v-64zM192 256v704h512v64H128V256h64z' fill='white'/></svg>"];
|
||||
// upload.svg — newly replaced "send/cloud" icon supplied by the user.
|
||||
NSImage *uploadIcon = [self iconFromSVG:@"<svg viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'><path d='M550.528 544.128L640 539.776V678.4l178.005333-178.005333L640 322.389333v129.024l-72.618667 10.922667c-155.52 23.424-251.733333 73.557333-312.874666 164.437333 84.906667-50.602667 178.261333-76.928 296.021333-82.645333zM554.666667 629.376c-27.392 1.322667-53.034667 3.968-77.141334 7.808l-8.192 1.365333c-136.704 23.637333-224.810667 87.168-310.954666 176.128-26.154667 27.008-51.882667 59.648-51.882667 59.648-14.848 18.176-24.021333 14.037333-20.352-9.173333 0 0 4.394667-31.402667 11.690667-65.792C144.938667 577.066667 250.581333 423.68 554.666667 377.941333V209.066667a38.4 38.4 0 0 1 65.536-27.136l291.328 291.285333a38.4 38.4 0 0 1 0 54.314667l-291.328 291.285333A38.4 38.4 0 0 1 554.666667 791.637333v-162.261333z' fill='white'/></svg>"];
|
||||
|
||||
@@ -255,6 +259,7 @@ static id nativeOverlayKeyMonitor = nil;
|
||||
[self styleIconButton:_clipboardButton image:copyIcon];
|
||||
[self styleIconButton:_saveButton image:saveIcon];
|
||||
[self styleIconButton:_saveRemoteButton image:saveRemoteIcon];
|
||||
[self styleIconButton:_summaryButton image:summaryIcon];
|
||||
[self styleIconButton:_uploadButton image:uploadIcon];
|
||||
|
||||
// Configure hover colors for the 5 action buttons. White is the shared
|
||||
@@ -267,11 +272,13 @@ static id nativeOverlayKeyMonitor = nil;
|
||||
SnipHoverButton *clipboardHB = (SnipHoverButton *)_clipboardButton;
|
||||
SnipHoverButton *saveHB = (SnipHoverButton *)_saveButton;
|
||||
SnipHoverButton *saveRemoteHB = (SnipHoverButton *)_saveRemoteButton;
|
||||
SnipHoverButton *summaryHB = (SnipHoverButton *)_summaryButton;
|
||||
SnipHoverButton *uploadHB = (SnipHoverButton *)_uploadButton;
|
||||
cancelHB.baseColor = baseWhite; cancelHB.hoverColor = hoverRed;
|
||||
clipboardHB.baseColor = baseWhite; clipboardHB.hoverColor = hoverBlue;
|
||||
saveHB.baseColor = baseWhite; saveHB.hoverColor = hoverBlue;
|
||||
saveRemoteHB.baseColor = baseWhite; saveRemoteHB.hoverColor = hoverBlue;
|
||||
summaryHB.baseColor = baseWhite; summaryHB.hoverColor = hoverBlue;
|
||||
uploadHB.baseColor = baseWhite; uploadHB.hoverColor = hoverBlue;
|
||||
|
||||
[self styleIconButton:_penButton image:[self iconFromSVG:@"<svg viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'><path d='M742.72 752.064c-29.696 28.576-42.976 48.96-42.976 77.12 0 98.4 143.776 142.464 229.728 65.536l-21.344-23.84c-66.976 59.936-176.384 26.4-176.384-41.696 0-16.832 9.28-31.104 33.184-54.08l13.44-12.736c61.024-58.016 75.328-102.72 29.312-179.84-43.84-73.44-96.8-88.288-162.784-50.56-47.232 27.04-68.64 47.456-208.32 190.4-70.624 72.288-153.92 77.088-217.344 26.784-59.712-47.328-79.872-127.36-42.176-188.64 24.512-39.84 62.656-72.896 136.64-124.48 5.952-4.192 27.04-18.816 31.104-21.664 12.16-8.448 21.536-15.104 30.4-21.536 107.552-78.272 140.8-139.136 86.048-219.904-76.992-113.472-202.304-90.016-367.744 61.472l21.6 23.616c153.088-140.224 256.896-159.616 319.68-67.104 41.632 61.408 16.896 106.688-78.4 176.032-8.64 6.304-17.92 12.832-29.888 21.184l-31.136 21.632c-77.504 54.08-117.984 89.184-145.536 133.984-46.784 76.032-22.176 173.664 49.536 230.496 76.224 60.416 177.952 54.56 260.096-29.504 136.16-139.36 158.08-160.224 201.312-184.96 50.656-28.96 84.416-19.52 119.424 39.168 36.896 61.824 27.52 91.392-23.808 140.16 0.096-0.064-10.976 10.368-13.632 12.96z' fill='white'/></svg>"]];
|
||||
@@ -591,6 +598,7 @@ static id nativeOverlayKeyMonitor = nil;
|
||||
[_clipboardButton setHidden:!visible];
|
||||
[_saveButton setHidden:!visible];
|
||||
[_saveRemoteButton setHidden:!visible];
|
||||
[_summaryButton setHidden:!visible];
|
||||
[_uploadButton setHidden:!visible];
|
||||
[_actionToolbarBg setHidden:!visible];
|
||||
[_penButton setHidden:!visible];
|
||||
@@ -608,12 +616,12 @@ static id nativeOverlayKeyMonitor = nil;
|
||||
[_sizeLabel setStringValue:[NSString stringWithFormat:@"%.0f × %.0f", _selection.size.width, _selection.size.height]];
|
||||
[_sizeLabel setFrame:NSMakeRect(_selection.origin.x, MAX(0, _selection.origin.y - 26), 110, 22)];
|
||||
|
||||
// Action toolbar layout — 5 icon buttons, each 28x28, separated by 8px,
|
||||
// with 4px outer padding. Total = 5*28 + 4*8 + 2*4 = 180px wide.
|
||||
// Action toolbar layout — 6 icon buttons, each 28x28, separated by 8px,
|
||||
// with 4px outer padding. Total = 6*28 + 5*8 + 2*4 = 216px wide.
|
||||
CGFloat actionBtnSize = 28;
|
||||
CGFloat actionGap = 8;
|
||||
CGFloat actionPad = 4;
|
||||
NSInteger actionCount = 5;
|
||||
NSInteger actionCount = 6;
|
||||
CGFloat toolbarW = actionPad * 2 + actionBtnSize * actionCount + actionGap * (actionCount - 1);
|
||||
CGFloat toolbarH = 40;
|
||||
CGFloat x = _selection.origin.x + _selection.size.width - toolbarW;
|
||||
@@ -631,7 +639,8 @@ static id nativeOverlayKeyMonitor = nil;
|
||||
[_clipboardButton setFrame:NSMakeRect(baseX + (actionBtnSize + actionGap) * 1, btnY, actionBtnSize, actionBtnSize)];
|
||||
[_saveButton setFrame:NSMakeRect(baseX + (actionBtnSize + actionGap) * 2, btnY, actionBtnSize, actionBtnSize)];
|
||||
[_saveRemoteButton setFrame:NSMakeRect(baseX + (actionBtnSize + actionGap) * 3, btnY, actionBtnSize, actionBtnSize)];
|
||||
[_uploadButton setFrame:NSMakeRect(baseX + (actionBtnSize + actionGap) * 4, btnY, actionBtnSize, actionBtnSize)];
|
||||
[_summaryButton setFrame:NSMakeRect(baseX + (actionBtnSize + actionGap) * 4, btnY, actionBtnSize, actionBtnSize)];
|
||||
[_uploadButton setFrame:NSMakeRect(baseX + (actionBtnSize + actionGap) * 5, btnY, actionBtnSize, actionBtnSize)];
|
||||
|
||||
// Mark toolbar sits to the LEFT of the action toolbar (same row) with an
|
||||
// 8px gap between the two groups, so they never overlap on tiny selections.
|
||||
@@ -799,6 +808,18 @@ static id nativeOverlayKeyMonitor = nil;
|
||||
NSString *json = [self annotationsJSON];
|
||||
nativeOverlaySaveRemote((int)llround(r.origin.x), (int)llround(r.origin.y), (int)llround(r.size.width), (int)llround(r.size.height), [json UTF8String]);
|
||||
}
|
||||
|
||||
// `summarizeSelection` uploads the screenshot to S3, sends it to the
|
||||
// configured multimodal model, and copies the generated summary.
|
||||
- (void)summarizeSelection {
|
||||
if (!_hasSelection) {
|
||||
return;
|
||||
}
|
||||
NSRect r = [self globalRectForSelection:_selection];
|
||||
[self closeOverlayWindow];
|
||||
NSString *json = [self annotationsJSON];
|
||||
nativeOverlaySummarize((int)llround(r.origin.x), (int)llround(r.origin.y), (int)llround(r.size.width), (int)llround(r.size.height), [json UTF8String]);
|
||||
}
|
||||
@end
|
||||
|
||||
// screenContainingCursor returns the NSScreen the cursor is currently on,
|
||||
|
||||
Reference in New Issue
Block a user