Glyphs.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Global.h"
  5. #include "Glyphs.h"
  6. #include "Glyphs120.h"
  7. #include "Glyphs144.h"
  8. #include "Glyphs192.h"
  9. #include "Common.h"
  10. #include "GUITools.h"
  11. #include "GUIConfiguration.h"
  12. //---------------------------------------------------------------------------
  13. #pragma package(smart_init)
  14. #pragma link "PngImageList"
  15. #pragma resource "*.dfm"
  16. //---------------------------------------------------------------------------
  17. TGlyphsModule * GlyphsModule;
  18. //---------------------------------------------------------------------------
  19. __fastcall TGlyphsModule::TGlyphsModule(TComponent* Owner)
  20. : TDataModule(Owner)
  21. {
  22. FPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  23. FLargerToolbar = 0;
  24. SetPixelsPerInch(Screen->PixelsPerInch);
  25. }
  26. //---------------------------------------------------------------------------
  27. // Constructor without scaling
  28. __fastcall TGlyphsModule::TGlyphsModule()
  29. : TDataModule(Application)
  30. {
  31. }
  32. //---------------------------------------------------------------------------
  33. void TGlyphsModule::SetPixelsPerInch(int PixelsPerInch)
  34. {
  35. int BasePixelsPerInch = NormalizePixelsPerInch(PixelsPerInch);
  36. if (FBasePixelsPerInch != BasePixelsPerInch)
  37. {
  38. FBasePixelsPerInch = BasePixelsPerInch;
  39. UpdatePixelsPerInch();
  40. }
  41. }
  42. //---------------------------------------------------------------------------
  43. void TGlyphsModule::SetLargerToolbar(int LargerToolbar)
  44. {
  45. if (FLargerToolbar != LargerToolbar)
  46. {
  47. FLargerToolbar = LargerToolbar;
  48. UpdatePixelsPerInch();
  49. }
  50. }
  51. //---------------------------------------------------------------------------
  52. bool TGlyphsModule::GetLargerToolbarPossible()
  53. {
  54. return (LargerPixelsPerInch(FBasePixelsPerInch, 1) > FBasePixelsPerInch);
  55. }
  56. //---------------------------------------------------------------------------
  57. void TGlyphsModule::UpdatePixelsPerInch()
  58. {
  59. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  60. try
  61. {
  62. int PixelsPerInch = LargerPixelsPerInch(FBasePixelsPerInch, FLargerToolbar);
  63. if (FPixelsPerInch != PixelsPerInch)
  64. {
  65. std::unique_ptr<TDataModule> ScaledModule;
  66. if (PixelsPerInch >= 192)
  67. {
  68. ScaledModule.reset(new TGlyphs192Module(Application));
  69. }
  70. else if (PixelsPerInch >= 144)
  71. {
  72. ScaledModule.reset(new TGlyphs144Module(Application));
  73. }
  74. else if (PixelsPerInch >= 120)
  75. {
  76. ScaledModule.reset(new TGlyphs120Module(Application));
  77. }
  78. else
  79. {
  80. // Do not have a separate 96 DPI module, as this module needs to
  81. // have the images loaded as they are used on design time.
  82. // Performance impact of loading 96 DPI images when they are not needed is not that big.
  83. ScaledModule.reset(new TGlyphsModule());
  84. }
  85. if (ScaledModule.get() != NULL)
  86. {
  87. for (int Index = 0; Index < ComponentCount; Index++)
  88. {
  89. TComponent * TargetComponent = Components[Index];
  90. TComponent * SourceComponent = ScaledModule->FindComponent(TargetComponent->Name);
  91. if (DebugAlwaysTrue(SourceComponent != NULL))
  92. {
  93. TargetComponent->Assign(SourceComponent);
  94. }
  95. }
  96. }
  97. FPixelsPerInch = PixelsPerInch;
  98. }
  99. }
  100. __finally
  101. {
  102. GUIConfiguration->ChangeResourceModule(ResourceModule);
  103. }
  104. }