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.

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