Release v0.4.0: add screen capture and annotation editor
This commit is contained in:
+11
-1
@@ -17,7 +17,8 @@ std::vector<std::pair<int, std::wstring>> shortcuts(const Settings &s)
|
||||
{Case, s.casing},
|
||||
{Translit, s.translit},
|
||||
{Undo, s.undo},
|
||||
{ShowHistory, s.clipboard}};
|
||||
{ShowHistory, s.clipboard},
|
||||
{Screenshot, s.screenshot}};
|
||||
for (size_t i = 0; i < s.direct.size(); ++i)
|
||||
out.emplace_back(Direct + (int)i, s.direct[i]);
|
||||
return out;
|
||||
@@ -586,6 +587,11 @@ void App::dispatch(int command)
|
||||
return;
|
||||
try
|
||||
{
|
||||
if (command == Screenshot)
|
||||
{
|
||||
if (!busy) showScreenshot(*this);
|
||||
return;
|
||||
}
|
||||
if (command == ShowHistory)
|
||||
{
|
||||
showHistory(*this);
|
||||
@@ -1096,6 +1102,7 @@ void App::trayMenu()
|
||||
{
|
||||
HMENU menu = CreatePopupMenu();
|
||||
AppendMenuW(menu, MF_STRING, 10, L"Clipboard history");
|
||||
AppendMenuW(menu, MF_STRING, 24, L"Capture screen region…");
|
||||
AppendMenuW(menu, MF_STRING, 11, L"Settings…");
|
||||
SetMenuDefaultItem(menu, 11, FALSE);
|
||||
AppendMenuW(menu, MF_STRING, 12, L"Snippets…");
|
||||
@@ -1127,6 +1134,9 @@ void App::trayMenu()
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
case 24:
|
||||
dispatch(Screenshot);
|
||||
break;
|
||||
case 10:
|
||||
showHistory(*this);
|
||||
break;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace ks
|
||||
inline constexpr UINT TrayMessage = WM_APP + 1, ErrorMessage = WM_APP + 2, HistoryMessage = WM_APP + 3,
|
||||
SnippetMessage = WM_APP + 4;
|
||||
inline constexpr int Toggle = 1, Case = 2, Translit = 3, Undo = 4, ShowHistory = 5, AutoCorrect = 6,
|
||||
Direct = 100;
|
||||
Screenshot = 7, Direct = 100;
|
||||
inline constexpr UINT AutoCorrectMessage = WM_APP + 6;
|
||||
inline constexpr UINT CaptureHotkeyMessage = WM_APP + 5;
|
||||
struct LastTransform
|
||||
@@ -100,6 +100,7 @@ class App
|
||||
static LRESULT CALLBACK mouseProc(int, WPARAM, LPARAM);
|
||||
};
|
||||
void showHistory(App &);
|
||||
void showScreenshot(App &);
|
||||
void refreshHistory(App &);
|
||||
void showSettings(App &, bool visible = true);
|
||||
void showLogs(App &);
|
||||
|
||||
+2
-1
@@ -59,7 +59,8 @@ struct Settings
|
||||
L"Far", L"ConEmu64", L"putty", L"KeePass", L"KeePassXC", L"1Password", L"Bitwarden"};
|
||||
int maxItems = 500, maxMiB = 200, maxImageMiB = 20;
|
||||
std::wstring toggle = L"Ctrl+Alt+Shift+Space", casing = L"Ctrl+Alt+Shift+C",
|
||||
translit = L"Ctrl+Alt+Shift+T", undo = L"Ctrl+Alt+Shift+Z", clipboard = L"Ctrl+Shift+V";
|
||||
translit = L"Ctrl+Alt+Shift+T", undo = L"Ctrl+Alt+Shift+Z", clipboard = L"Ctrl+Shift+V",
|
||||
screenshot = L"Win+Shift+S";
|
||||
std::vector<std::wstring> cycle, direct, directIds;
|
||||
std::vector<std::wstring> excluded{L"KeePass", L"KeePassXC", L"1Password", L"Bitwarden"};
|
||||
std::vector<Snippet> snippets;
|
||||
|
||||
+3
-1
@@ -31,7 +31,9 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int)
|
||||
HANDLE mutex = CreateMutexW(nullptr, TRUE, L"Local\\KSwitcher.Native.Singleton");
|
||||
bool existing = GetLastError() == ERROR_ALREADY_EXISTS;
|
||||
int cmd = ks::ShowHistory;
|
||||
if (arg == L"--convert")
|
||||
if (arg == L"--capture")
|
||||
cmd = ks::Screenshot;
|
||||
else if (arg == L"--convert")
|
||||
cmd = ks::Toggle;
|
||||
else if (arg == L"--case")
|
||||
cmd = ks::Case;
|
||||
|
||||
+1534
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
#include "platform.h"
|
||||
namespace ks
|
||||
{
|
||||
enum class LineStyle { Solid, Dotted, Dashed, DashDot };
|
||||
enum class LineEnds { End, Start, Both, None };
|
||||
enum class ScreenshotShape { None, Rectangle, Circle, Ellipse };
|
||||
struct ScreenshotOffset { double x, y; };
|
||||
struct ScreenshotMark {
|
||||
POINT from, to; int number; int radius = 15; int thickness = 3;
|
||||
int fromNumber = 0, toNumber = 0;
|
||||
std::vector<POINT> points;
|
||||
COLORREF color = RGB(225,42,50);
|
||||
bool freehand = false;
|
||||
LineStyle style = LineStyle::Solid;
|
||||
LineEnds ends = LineEnds::End;
|
||||
ScreenshotShape shape = ScreenshotShape::None;
|
||||
std::wstring text, fontName=L"Segoe UI";
|
||||
int fontSize=24, fontWeight=FW_NORMAL;
|
||||
bool fontItalic=false;
|
||||
double rotation=0;
|
||||
std::wstring label;
|
||||
ScreenshotOffset labelOffset{0,-24}; // Along the line and perpendicular to it, in image pixels.
|
||||
bool labelRotationManual=false;
|
||||
bool isText() const { return !text.empty(); }
|
||||
bool isHighlight() const { return !points.empty() && !freehand; }
|
||||
bool isLine() const { return !number && !isText() && !isHighlight() && shape==ScreenshotShape::None; }
|
||||
};
|
||||
class ScreenshotHistory {
|
||||
std::deque<std::vector<ScreenshotMark>> past, future;
|
||||
public:
|
||||
void remember(const std::vector<ScreenshotMark> &);
|
||||
bool undo(std::vector<ScreenshotMark> &);
|
||||
bool redo(std::vector<ScreenshotMark> &);
|
||||
bool canUndo() const { return !past.empty(); }
|
||||
bool canRedo() const { return !future.empty(); }
|
||||
};
|
||||
void resolveScreenshotLinks(std::vector<ScreenshotMark> &);
|
||||
void linkScreenshotEndpoint(ScreenshotMark &, bool start, POINT drop,
|
||||
const std::vector<ScreenshotMark> &, double tolerance);
|
||||
enum class MarkPart { None, Body, Start, End, Radius, Thickness, Rotation, Label };
|
||||
POINT screenshotThicknessHandle(const ScreenshotMark &, double clearance = 16);
|
||||
ScreenshotMark cloneScreenshotMark(const ScreenshotMark &, const std::vector<ScreenshotMark> &, int width, int height);
|
||||
int nextScreenshotNumber(const std::vector<ScreenshotMark> &);
|
||||
MarkPart hitScreenshotMark(const ScreenshotMark &, POINT, double tolerance);
|
||||
ScreenshotMark dragScreenshotMark(const ScreenshotMark &, MarkPart, POINT origin, POINT position,
|
||||
int width, int height, bool snapRotation=false);
|
||||
POINT constrainScreenshotShape(ScreenshotShape, POINT anchor, POINT position, int width, int height);
|
||||
RECT screenshotTextBounds(const ScreenshotMark &);
|
||||
POINT screenshotTextRotationHandle(const ScreenshotMark &, double clearance=24);
|
||||
ScreenshotMark screenshotArrowLabel(const ScreenshotMark &);
|
||||
// Render at source resolution; never reads or writes the system clipboard.
|
||||
Clip screenshotClip(HDC source, int width, int height, const std::vector<ScreenshotMark> &marks);
|
||||
}
|
||||
+4
-2
@@ -45,7 +45,7 @@ bool validId(const std::wstring &id)
|
||||
void validateSettings(const Settings &s)
|
||||
{
|
||||
std::vector<Hotkey> used;
|
||||
std::vector<std::wstring> keys{s.toggle, s.casing, s.translit, s.undo, s.clipboard};
|
||||
std::vector<std::wstring> keys{s.toggle, s.casing, s.translit, s.undo, s.clipboard, s.screenshot};
|
||||
keys.insert(keys.end(), s.direct.begin(), s.direct.end());
|
||||
for (auto &text : keys)
|
||||
{
|
||||
@@ -150,6 +150,7 @@ Settings decodeSettings(const Bytes &bytes, const std::vector<Layout> &layouts)
|
||||
s.translit = str(j, "translitHotkey", s.translit);
|
||||
s.undo = str(j, "undoHotkey", s.undo);
|
||||
s.clipboard = str(j, "clipboardHotkey", s.clipboard);
|
||||
s.screenshot = str(j, "screenshotHotkey", s.screenshot);
|
||||
if (j.contains("layouts"))
|
||||
{
|
||||
s.cycle.clear();
|
||||
@@ -203,7 +204,8 @@ Bytes encodeSettings(const Settings &s)
|
||||
{"caseHotkey", utf8(s.casing)},
|
||||
{"translitHotkey", utf8(s.translit)},
|
||||
{"undoHotkey", utf8(s.undo)},
|
||||
{"clipboardHotkey", utf8(s.clipboard)}};
|
||||
{"clipboardHotkey", utf8(s.clipboard)},
|
||||
{"screenshotHotkey", utf8(s.screenshot)}};
|
||||
j["layouts"] = Json::array();
|
||||
for (auto &id : s.cycle)
|
||||
j["layouts"].push_back(utf8(id));
|
||||
|
||||
+11
-7
@@ -255,7 +255,7 @@ void error(HWND w, const std::exception &e)
|
||||
MessageBoxW(w, wide(e.what()).c_str(), L"KSwitcher", MB_OK | MB_ICONWARNING);
|
||||
}
|
||||
HWND makeWindow(App &app, const wchar_t *cls, const wchar_t *title, WNDPROC proc, int width, int height,
|
||||
DWORD extra = 0)
|
||||
DWORD extra = 0, bool resizable = true)
|
||||
{
|
||||
WNDCLASSW wc{};
|
||||
wc.hInstance = app.instance;
|
||||
@@ -267,7 +267,8 @@ HWND makeWindow(App &app, const wchar_t *cls, const wchar_t *title, WNDPROC proc
|
||||
RegisterClassW(&wc);
|
||||
UINT dpi = GetDpiForSystem();
|
||||
RECT rect{0, 0, MulDiv(width, dpi, 96), MulDiv(height, dpi, 96)};
|
||||
DWORD style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_THICKFRAME | WS_MAXIMIZEBOX | extra;
|
||||
DWORD style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | extra;
|
||||
if (resizable) style |= WS_THICKFRAME | WS_MAXIMIZEBOX;
|
||||
AdjustWindowRectExForDpi(&rect, style, FALSE, WS_EX_APPWINDOW, dpi);
|
||||
POINT cursor{};
|
||||
GetCursorPos(&cursor);
|
||||
@@ -822,6 +823,7 @@ void fillSettings(HWND w, SettingsView *v)
|
||||
value(w, 212, s.translit);
|
||||
value(w, 213, s.undo);
|
||||
value(w, 214, s.clipboard);
|
||||
value(w, 215, s.screenshot);
|
||||
value(w, 240, std::to_wstring(s.maxItems));
|
||||
value(w, 241, std::to_wstring(s.maxMiB));
|
||||
value(w, 242, std::to_wstring(s.maxImageMiB));
|
||||
@@ -871,6 +873,7 @@ Settings collectSettings(HWND w, SettingsView *v)
|
||||
s.translit = value(w, 212);
|
||||
s.undo = value(w, 213);
|
||||
s.clipboard = value(w, 214);
|
||||
s.screenshot = value(w, 215);
|
||||
s.maxItems = integer(w, 240);
|
||||
s.maxMiB = integer(w, 241);
|
||||
s.maxImageMiB = integer(w, 242);
|
||||
@@ -1630,7 +1633,7 @@ void showSettings(App &app, bool visible)
|
||||
activateWindow(target);
|
||||
return;
|
||||
}
|
||||
HWND w = makeWindow(app, L"KSwitcher.Settings", L"KSwitcher settings", settingsProc, 780, 660);
|
||||
HWND w = makeWindow(app, L"KSwitcher.Settings", L"KSwitcher settings", settingsProc, 780, 660, 0, false);
|
||||
app.settingsWindow = w;
|
||||
label(w, L"Text conversion", 18, 16);
|
||||
checkbox(w, L"Convert recently typed text when nothing is selected", 201, 18, 43, 390);
|
||||
@@ -1642,13 +1645,13 @@ void showSettings(App &app, bool visible)
|
||||
checkbox(w, L"Write log", 208, 240, 184, 160);
|
||||
label(w, L"Click a shortcut and press the desired keys", 420, 16, 350);
|
||||
const wchar_t *names[] = {L"Next layout", L"Change case", L"Transliterate", L"Undo",
|
||||
L"Clipboard history"};
|
||||
for (int i = 0; i < 5; ++i)
|
||||
L"Clipboard history", L"Screen capture"};
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
label(w, names[i], 420, 48 + i * 30, 115);
|
||||
hotkeyEdit(app, w, 210 + i, 540, 44 + i * 30, 220);
|
||||
}
|
||||
checkbox(w, L"Automatically correct layout (experimental)", 207, 420, 195, 350);
|
||||
checkbox(w, L"Automatically correct layout (experimental)", 207, 420, 211, 350);
|
||||
label(w, L"Layout cycle — top to bottom", 18, 210, 400);
|
||||
control(w, L"LISTBOX", L"", WS_TABSTOP | WS_VSCROLL | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | WS_BORDER, 220,
|
||||
18, 232, 470, 190);
|
||||
@@ -1718,7 +1721,8 @@ void showShortcuts(App &app)
|
||||
{
|
||||
auto &s = app.settings;
|
||||
std::wstring text = L"Next layout: " + s.toggle + L"\nChange case: " + s.casing + L"\nTransliterate: " +
|
||||
s.translit + L"\nUndo: " + s.undo + L"\nClipboard history: " + s.clipboard + L"\n";
|
||||
s.translit + L"\nUndo: " + s.undo + L"\nClipboard history: " + s.clipboard +
|
||||
L"\nScreen capture: " + s.screenshot + L"\n";
|
||||
for (size_t i = 0; i < std::min(app.layouts.size(), s.direct.size()); ++i)
|
||||
if (!s.direct[i].empty())
|
||||
text += L"\n" + app.layouts[i].name + L": " + s.direct[i];
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
#include "platform.h"
|
||||
namespace ks
|
||||
{
|
||||
inline constexpr wchar_t AppVersion[] = L"0.3.0";
|
||||
inline constexpr wchar_t AppVersion[] = L"0.4.0";
|
||||
inline constexpr UINT UpdateMessage = WM_APP + 7;
|
||||
struct UpdateResult
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user