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.

98 lines
3.4 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__H
  24. #define DPI_SCALING__H
  25. #include <wx/window.h>
  26. /**
  27. * Class to handle configuration and automatic determination of the DPI
  28. * scale to use for canvases. This has several sources and the availability of
  29. * some of them are platform dependent.
  30. */
  31. class DPI_SCALING
  32. {
  33. public:
  34. /**
  35. * Construct a DPI scale provider.
  36. *
  37. * @param aConfig the config store to check for a user value (can be nullptr,
  38. * in which case on automatically determined values are considered)
  39. * @param aWindow a WX window to use for automatic DPI determination
  40. * @return the scaling factor (1.0 = no scaling)
  41. */
  42. DPI_SCALING(){};
  43. virtual ~DPI_SCALING() {}
  44. /**
  45. * Get the DPI scale from all known sources in order:
  46. *
  47. * * user config, if given
  48. * * user's environment variables, if set and according to platform
  49. * * WX's internal determination of the DPI scaling (WX > 3.1)
  50. */
  51. virtual double GetScaleFactor() const = 0;
  52. /**
  53. * Get the content scale factor, which may be different from the scale
  54. * factor on some platforms. This value should be used for scaling
  55. * user interface elements (fonts, icons, etc) whereas the scale
  56. * factor should be used for scaling canvases.
  57. */
  58. virtual double GetContentScaleFactor() const = 0;
  59. /**
  60. * Is the current value auto scaled, or is it user-set in the config
  61. */
  62. virtual bool GetCanvasIsAutoScaled() const = 0;
  63. /**
  64. * Set the common DPI config in a given config object
  65. *
  66. * The encoding of the automatic/manual nature of the config is handled internally.
  67. *
  68. * @param aAuto store a value meaning "no user-set scale"
  69. * @param aValue the value to store (ignored if aAuto set)
  70. */
  71. virtual void SetDpiConfig( bool aAuto, double aValue ) = 0;
  72. /*
  73. * Get the maximum scaling factor that should be presented to the user.
  74. * This is only advisory, it has no real technical use other than for validation.
  75. */
  76. static double GetMaxScaleFactor();
  77. /*
  78. * Get the minimum scaling factor that should be presented to the user.
  79. * This is only advisory, it has no real technical use other than for validation.
  80. */
  81. static double GetMinScaleFactor();
  82. /**
  83. * Get the "default" scaling factor to use if not other config is available
  84. */
  85. static double GetDefaultScaleFactor();
  86. };
  87. #endif // DPI_SCALING__H