Glyphs.cpp 3.4 KB

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