Implement "view → set to full scale" text window command.

pull/33/head
whitequark 2016-08-01 13:44:38 +00:00
parent ff23a4a471
commit 8e7d2eaa84
9 changed files with 38 additions and 0 deletions

View File

@ -11,6 +11,8 @@ New export/import features:
Other new features: Other new features:
* New command for measuring total length of selected entities, * New command for measuring total length of selected entities,
"Analyze → Measure Perimeter". "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 2.2
--- ---

View File

@ -6,6 +6,11 @@
name="JonathanWesthues.3dCAD.SolveSpace" name="JonathanWesthues.3dCAD.SolveSpace"
type="win32" type="win32"
/> />
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
<description>Parametric 3d CAD tool.</description> <description>Parametric 3d CAD tool.</description>
<dependency> <dependency>
<dependentAssembly> <dependentAssembly>

View File

@ -1045,6 +1045,15 @@ void GetTextWindowSize(int *w, int *h) {
*h = (int)size.height; *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) { void InvalidateText(void) {
NSSize size = [TWView convertSizeToBacking:[TWView frame].size]; NSSize size = [TWView convertSizeToBacking:[TWView frame].size];
size.height = (SS.TW.top[SS.TW.rows - 1] + 1) * TextWindow::LINE_HEIGHT / 2; size.height = (SS.TW.top[SS.TW.rows - 1] + 1) * TextWindow::LINE_HEIGHT / 2;

View File

@ -1420,6 +1420,10 @@ void GetTextWindowSize(int *w, int *h) {
*h = allocation.get_height(); *h = allocation.get_height();
} }
double GetScreenDpi() {
return Gdk::Screen::get_default()->get_resolution();
}
void InvalidateText(void) { void InvalidateText(void) {
TW->get_widget().queue_draw(); TW->get_widget().queue_draw();
} }

View File

@ -96,6 +96,9 @@ void ScheduleLater() {
void GetGraphicsWindowSize(int *w, int *h) { void GetGraphicsWindowSize(int *w, int *h) {
*w = *h = 600; *w = *h = 600;
} }
double GetScreenDpi() {
return 72;
}
void InvalidateGraphics() { void InvalidateGraphics() {
} }

View File

@ -266,6 +266,13 @@ void SolveSpace::GetTextWindowSize(int *w, int *h)
GetWindowSize(TextWnd, w, 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) { void SolveSpace::OpenWebsite(const char *url) {
ShellExecuteW(GraphicsWnd, L"open", Widen(url).c_str(), NULL, NULL, SW_SHOWNORMAL); ShellExecuteW(GraphicsWnd, L"open", Widen(url).c_str(), NULL, NULL, SW_SHOWNORMAL);
} }

View File

@ -264,6 +264,7 @@ void ToggleFullScreen();
bool FullScreenIsActive(); bool FullScreenIsActive();
void GetGraphicsWindowSize(int *w, int *h); void GetGraphicsWindowSize(int *w, int *h);
void GetTextWindowSize(int *w, int *h); void GetTextWindowSize(int *w, int *h);
double GetScreenDpi();
int64_t GetMilliseconds(); int64_t GetMilliseconds();
void dbp(const char *str, ...); void dbp(const char *str, ...);

View File

@ -457,6 +457,7 @@ public:
static void ScreenChangeBackgroundImageScale(int link, uint32_t v); static void ScreenChangeBackgroundImageScale(int link, uint32_t v);
static void ScreenChangePasteTransformed(int link, uint32_t v); static void ScreenChangePasteTransformed(int link, uint32_t v);
static void ScreenChangeViewScale(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 ScreenChangeViewOrigin(int link, uint32_t v);
static void ScreenChangeViewProjection(int link, uint32_t v); static void ScreenChangeViewProjection(int link, uint32_t v);

View File

@ -14,6 +14,8 @@ void TextWindow::ShowEditView() {
SS.GW.scale * SS.MmPerUnit(), SS.GW.scale * SS.MmPerUnit(),
SS.UnitName(), SS.UnitName(),
&ScreenChangeViewScale); &ScreenChangeViewScale);
Printf(false, "%Bd %Fl%Ll%fset to full scale%E",
&ScreenChangeViewToFullScale);
Printf(false, ""); Printf(false, "");
Printf(false, "%Bd %Ftorigin (maps to center of screen)%E"); 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())); 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) { void TextWindow::ScreenChangeViewOrigin(int link, uint32_t v) {
std::string edit_value = std::string edit_value =
ssprintf("%s, %s, %s", ssprintf("%s, %s, %s",