You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.3 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 KiCad Developers, see AUTHORS.TXT for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef DPI_SCALING_COMMON__H
  24. #define DPI_SCALING_COMMON__H
  25. #include <kicommon.h>
  26. #include <dpi_scaling.h>
  27. class COMMON_SETTINGS;
  28. class wxWindow;
  29. /**
  30. * Class to handle configuration and automatic determination of the DPI
  31. * scale to use for canvases. This has several sources and the availability of
  32. * some of them are platform dependent.
  33. */
  34. class KICOMMON_API DPI_SCALING_COMMON : public DPI_SCALING
  35. {
  36. public:
  37. /**
  38. * Construct a DPI scale provider.
  39. *
  40. * @param aConfig the config store to check for a user value (can be nullptr,
  41. * in which case on automatically determined values are considered)
  42. * @param aWindow a WX window to use for automatic DPI determination
  43. * @return the scaling factor (1.0 = no scaling)
  44. */
  45. DPI_SCALING_COMMON( COMMON_SETTINGS* aConfig, const wxWindow* aWindow );
  46. /**
  47. * Get the DPI scale from all known sources in order:
  48. *
  49. * * user config, if given
  50. * * user's environment variables, if set and according to platform
  51. * * WX's internal determination of the DPI scaling (WX > 3.1)
  52. */
  53. double GetScaleFactor() const override;
  54. /**
  55. * Get the content scale factor, which may be different from the scale
  56. * factor on some platforms. This value should be used for scaling
  57. * user interface elements (fonts, icons, etc) whereas the scale
  58. * factor should be used for scaling canvases.
  59. */
  60. double GetContentScaleFactor() const override;
  61. /**
  62. * Is the current value auto scaled, or is it user-set in the config
  63. */
  64. bool GetCanvasIsAutoScaled() const override;
  65. /**
  66. * Set the common DPI config in a given config object
  67. *
  68. * The encoding of the automatic/manual nature of the config is handled internally.
  69. *
  70. * @param aAuto store a value meaning "no user-set scale"
  71. * @param aValue the value to store (ignored if aAuto set)
  72. */
  73. void SetDpiConfig( bool aAuto, double aValue ) override;
  74. private:
  75. /**
  76. * The configuration object to use to get/set user setting. nullptr
  77. * if only automatic options are wanted
  78. */
  79. COMMON_SETTINGS* m_config;
  80. /**
  81. * The WX window to use for WX's automatic DPI checking
  82. */
  83. const wxWindow* m_window;
  84. };
  85. #endif // DPI_SCALING__H