From 96476ca2e5af872c4fc0399be553951c6052254a Mon Sep 17 00:00:00 2001 From: whitequark Date: Wed, 11 Jan 2017 03:40:41 +0000 Subject: [PATCH] GTK: respect the scale factor when computing coordinates. This doesn't bring true HiDPI support yet, since there are no HiDPI assets anyway, but it makes the interface usable. --- res/locales/en_US.po | 8 ++++---- res/locales/uk_UA.po | 8 ++++---- res/messages.pot | 8 ++++---- src/platform/gtkmain.cpp | 18 ++++++++++-------- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/res/locales/en_US.po b/res/locales/en_US.po index 5545ee6..9bd8a73 100644 --- a/res/locales/en_US.po +++ b/res/locales/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: SolveSpace 3.0\n" "Report-Msgid-Bugs-To: whitequark@whitequark.org\n" -"POT-Creation-Date: 2017-01-11 03:01+0000\n" +"POT-Creation-Date: 2017-01-11 03:38+0000\n" "PO-Revision-Date: 2017-01-05 10:30+0000\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -1478,7 +1478,7 @@ msgctxt "button" msgid "OK" msgstr "OK" -#: platform/cocoamain.mm:1208 platform/gtkmain.cpp:1377 +#: platform/cocoamain.mm:1208 platform/gtkmain.cpp:1379 #: platform/w32main.cpp:1395 platform/w32main.cpp:1435 msgctxt "title" msgid "Property Browser" @@ -1573,12 +1573,12 @@ msgctxt "button" msgid "_No" msgstr "_No" -#: platform/gtkmain.cpp:1300 platform/w32main.cpp:176 +#: platform/gtkmain.cpp:1302 platform/w32main.cpp:176 msgctxt "title" msgid "Error" msgstr "Error" -#: platform/gtkmain.cpp:1300 platform/w32main.cpp:176 +#: platform/gtkmain.cpp:1302 platform/w32main.cpp:176 msgctxt "title" msgid "Message" msgstr "Message" diff --git a/res/locales/uk_UA.po b/res/locales/uk_UA.po index 840eb59..0a04d06 100644 --- a/res/locales/uk_UA.po +++ b/res/locales/uk_UA.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: SolveSpace 3.0\n" "Report-Msgid-Bugs-To: whitequark@whitequark.org\n" -"POT-Creation-Date: 2017-01-11 03:01+0000\n" +"POT-Creation-Date: 2017-01-11 03:37+0000\n" "PO-Revision-Date: 2017-01-05 10:30+0000\n" "Last-Translator: appsoft@ua.fm\n" "Language-Team: OpenOrienteeringUkraine\n" @@ -1324,7 +1324,7 @@ msgctxt "button" msgid "OK" msgstr "" -#: platform/cocoamain.mm:1208 platform/gtkmain.cpp:1377 +#: platform/cocoamain.mm:1208 platform/gtkmain.cpp:1379 #: platform/w32main.cpp:1395 platform/w32main.cpp:1435 msgctxt "title" msgid "Property Browser" @@ -1413,12 +1413,12 @@ msgctxt "button" msgid "_No" msgstr "" -#: platform/gtkmain.cpp:1300 platform/w32main.cpp:176 +#: platform/gtkmain.cpp:1302 platform/w32main.cpp:176 msgctxt "title" msgid "Error" msgstr "" -#: platform/gtkmain.cpp:1300 platform/w32main.cpp:176 +#: platform/gtkmain.cpp:1302 platform/w32main.cpp:176 msgctxt "title" msgid "Message" msgstr "" diff --git a/res/messages.pot b/res/messages.pot index 69530cb..ae75d33 100644 --- a/res/messages.pot +++ b/res/messages.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: SolveSpace 3.0\n" "Report-Msgid-Bugs-To: whitequark@whitequark.org\n" -"POT-Creation-Date: 2017-01-11 03:01+0000\n" +"POT-Creation-Date: 2017-01-11 03:38+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1288,7 +1288,7 @@ msgctxt "button" msgid "OK" msgstr "" -#: platform/cocoamain.mm:1208 platform/gtkmain.cpp:1377 platform/w32main.cpp:1395 +#: platform/cocoamain.mm:1208 platform/gtkmain.cpp:1379 platform/w32main.cpp:1395 #: platform/w32main.cpp:1435 msgctxt "title" msgid "Property Browser" @@ -1376,12 +1376,12 @@ msgctxt "button" msgid "_No" msgstr "" -#: platform/gtkmain.cpp:1300 platform/w32main.cpp:176 +#: platform/gtkmain.cpp:1302 platform/w32main.cpp:176 msgctxt "title" msgid "Error" msgstr "" -#: platform/gtkmain.cpp:1300 platform/w32main.cpp:176 +#: platform/gtkmain.cpp:1302 platform/w32main.cpp:176 msgctxt "title" msgid "Message" msgstr "" diff --git a/src/platform/gtkmain.cpp b/src/platform/gtkmain.cpp index 93e6c1d..19365b5 100644 --- a/src/platform/gtkmain.cpp +++ b/src/platform/gtkmain.cpp @@ -424,8 +424,8 @@ private: void ij_to_xy(double i, double j, int &x, int &y) { // Convert to xy (vs. ij) style coordinates, // with (0, 0) at center - x = (int)i - _w / 2; - y = _h / 2 - (int)j; + x = (int)(i * get_scale_factor()) - _w / 2; + y = _h / 2 - (int)(j * get_scale_factor()); } }; @@ -564,8 +564,8 @@ std::unique_ptr GW; void GetGraphicsWindowSize(int *w, int *h) { Gdk::Rectangle allocation = GW->get_widget().get_allocation(); - *w = allocation.get_width(); - *h = allocation.get_height(); + *w = allocation.get_width() * GW->get_scale_factor(); + *h = allocation.get_height() * GW->get_scale_factor(); } void InvalidateGraphics(void) { @@ -1129,7 +1129,8 @@ protected: bool on_motion_notify_event(GdkEventMotion *event) override { SS.TW.MouseEvent(/*leftClick*/ false, /*leftDown*/ event->state & GDK_BUTTON1_MASK, - event->x, event->y); + event->x * get_scale_factor(), + event->y * get_scale_factor()); return true; } @@ -1137,7 +1138,8 @@ protected: bool on_button_press_event(GdkEventButton *event) override { SS.TW.MouseEvent(/*leftClick*/ event->type == GDK_BUTTON_PRESS, /*leftDown*/ event->state & GDK_BUTTON1_MASK, - event->x, event->y); + event->x * get_scale_factor(), + event->y * get_scale_factor()); return true; } @@ -1258,8 +1260,8 @@ void ShowTextWindow(bool visible) { void GetTextWindowSize(int *w, int *h) { Gdk::Rectangle allocation = TW->get_widget().get_allocation(); - *w = allocation.get_width(); - *h = allocation.get_height(); + *w = allocation.get_width() * TW->get_scale_factor(); + *h = allocation.get_height() * TW->get_scale_factor(); } double GetScreenDpi() {