Glyphs.cpp 3.4 KB

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