From 8e7d2eaa84936cca446c864ace88d98651cd7bd9 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 1 Aug 2016 13:44:38 +0000 Subject: [PATCH] =?UTF-8?q?Implement=20"view=20=E2=86=92=20set=20to=20full?= =?UTF-8?q?=20scale"=20text=20window=20command.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ res/win32/manifest.xml | 5 +++++ src/platform/cocoamain.mm | 9 +++++++++ src/platform/gtkmain.cpp | 4 ++++ src/platform/headless.cpp | 3 +++ src/platform/w32main.cpp | 7 +++++++ src/solvespace.h | 1 + src/ui.h | 1 + src/view.cpp | 6 ++++++ 9 files changed, 38 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e18bccb4..37fd2f0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ New export/import features: Other new features: * New command for measuring total length of selected entities, "Analyze → Measure Perimeter". + * New link to match the on-screen size of the sketch with its actual size, + "view → set to full scale". 2.2 --- diff --git a/res/win32/manifest.xml b/res/win32/manifest.xml index f27a236e..22a78cc8 100644 --- a/res/win32/manifest.xml +++ b/res/win32/manifest.xml @@ -6,6 +6,11 @@ name="JonathanWesthues.3dCAD.SolveSpace" type="win32" /> + + + true + + Parametric 3d CAD tool. diff --git a/src/platform/cocoamain.mm b/src/platform/cocoamain.mm index f4484416..94be0c6e 100644 --- a/src/platform/cocoamain.mm +++ b/src/platform/cocoamain.mm @@ -1045,6 +1045,15 @@ void GetTextWindowSize(int *w, int *h) { *h = (int)size.height; } +double GetScreenDpi() { + NSScreen *screen = [NSScreen mainScreen]; + NSDictionary *description = [screen deviceDescription]; + NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue]; + CGSize displayPhysicalSize = CGDisplayScreenSize( + [[description objectForKey:@"NSScreenNumber"] unsignedIntValue]); + return (displayPixelSize.width / displayPhysicalSize.width) * 25.4f; +} + void InvalidateText(void) { NSSize size = [TWView convertSizeToBacking:[TWView frame].size]; size.height = (SS.TW.top[SS.TW.rows - 1] + 1) * TextWindow::LINE_HEIGHT / 2; diff --git a/src/platform/gtkmain.cpp b/src/platform/gtkmain.cpp index 4f20f508..1b7aa60f 100644 --- a/src/platform/gtkmain.cpp +++ b/src/platform/gtkmain.cpp @@ -1420,6 +1420,10 @@ void GetTextWindowSize(int *w, int *h) { *h = allocation.get_height(); } +double GetScreenDpi() { + return Gdk::Screen::get_default()->get_resolution(); +} + void InvalidateText(void) { TW->get_widget().queue_draw(); } diff --git a/src/platform/headless.cpp b/src/platform/headless.cpp index 9580e0f0..8b949d6e 100644 --- a/src/platform/headless.cpp +++ b/src/platform/headless.cpp @@ -96,6 +96,9 @@ void ScheduleLater() { void GetGraphicsWindowSize(int *w, int *h) { *w = *h = 600; } +double GetScreenDpi() { + return 72; +} void InvalidateGraphics() { } diff --git a/src/platform/w32main.cpp b/src/platform/w32main.cpp index a74a05a7..c4b7e91a 100644 --- a/src/platform/w32main.cpp +++ b/src/platform/w32main.cpp @@ -266,6 +266,13 @@ void SolveSpace::GetTextWindowSize(int *w, int *h) GetWindowSize(TextWnd, w, h); } +double SolveSpace::GetScreenDpi() { + HDC hdc = GetDC(NULL); + double dpi = GetDeviceCaps(hdc, LOGPIXELSX); + ReleaseDC(NULL, hdc); + return dpi; +} + void SolveSpace::OpenWebsite(const char *url) { ShellExecuteW(GraphicsWnd, L"open", Widen(url).c_str(), NULL, NULL, SW_SHOWNORMAL); } diff --git a/src/solvespace.h b/src/solvespace.h index 03c8a6e9..9fbe77e4 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -264,6 +264,7 @@ void ToggleFullScreen(); bool FullScreenIsActive(); void GetGraphicsWindowSize(int *w, int *h); void GetTextWindowSize(int *w, int *h); +double GetScreenDpi(); int64_t GetMilliseconds(); void dbp(const char *str, ...); diff --git a/src/ui.h b/src/ui.h index f1be1940..a2166748 100644 --- a/src/ui.h +++ b/src/ui.h @@ -457,6 +457,7 @@ public: static void ScreenChangeBackgroundImageScale(int link, uint32_t v); static void ScreenChangePasteTransformed(int link, uint32_t v); static void ScreenChangeViewScale(int link, uint32_t v); + static void ScreenChangeViewToFullScale(int link, uint32_t v); static void ScreenChangeViewOrigin(int link, uint32_t v); static void ScreenChangeViewProjection(int link, uint32_t v); diff --git a/src/view.cpp b/src/view.cpp index c1a2bfa3..6f91eb65 100644 --- a/src/view.cpp +++ b/src/view.cpp @@ -14,6 +14,8 @@ void TextWindow::ShowEditView() { SS.GW.scale * SS.MmPerUnit(), SS.UnitName(), &ScreenChangeViewScale); + Printf(false, "%Bd %Fl%Ll%fset to full scale%E", + &ScreenChangeViewToFullScale); Printf(false, ""); Printf(false, "%Bd %Ftorigin (maps to center of screen)%E"); @@ -42,6 +44,10 @@ void TextWindow::ScreenChangeViewScale(int link, uint32_t v) { SS.TW.ShowEditControl(3, ssprintf("%.3f", SS.GW.scale * SS.MmPerUnit())); } +void TextWindow::ScreenChangeViewToFullScale(int link, uint32_t v) { + SS.GW.scale = GetScreenDpi() / 25.4; +} + void TextWindow::ScreenChangeViewOrigin(int link, uint32_t v) { std::string edit_value = ssprintf("%s, %s, %s",