1
0

Glyphs.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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::IsLargerToolbarPossible(int Larger)
  53. {
  54. int Prev = LargerPixelsPerInch(FBasePixelsPerInch, Larger - 1);
  55. return (LargerPixelsPerInch(Prev, 1) > Prev);
  56. }
  57. //---------------------------------------------------------------------------
  58. void TGlyphsModule::UpdatePixelsPerInch()
  59. {
  60. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  61. try
  62. {
  63. int PixelsPerInch = LargerPixelsPerInch(FBasePixelsPerInch, FLargerToolbar);
  64. if (FPixelsPerInch != PixelsPerInch)
  65. {
  66. std::unique_ptr<TDataModule> ScaledModule;
  67. if (PixelsPerInch >= 192)
  68. {
  69. ScaledModule.reset(new TGlyphs192Module(Application));
  70. }
  71. else if (PixelsPerInch >= 144)
  72. {
  73. ScaledModule.reset(new TGlyphs144Module(Application));
  74. }
  75. else if (PixelsPerInch >= 120)
  76. {
  77. ScaledModule.reset(new TGlyphs120Module(Application));
  78. }
  79. else
  80. {
  81. // Do not have a separate 96 DPI module, as this module needs to
  82. // have the images loaded as they are used on design time.
  83. // Performance impact of loading 96 DPI images when they are not needed is not that big.
  84. ScaledModule.reset(new TGlyphsModule());
  85. }
  86. if (ScaledModule.get() != NULL)
  87. {
  88. for (int Index = 0; Index < ComponentCount; Index++)
  89. {
  90. TComponent * TargetComponent = Components[Index];
  91. TComponent * SourceComponent = ScaledModule->FindComponent(TargetComponent->Name);
  92. if (DebugAlwaysTrue(SourceComponent != NULL))
  93. {
  94. TargetComponent->Assign(SourceComponent);
  95. }
  96. }
  97. }
  98. FPixelsPerInch = PixelsPerInch;
  99. }
  100. }
  101. __finally
  102. {
  103. GUIConfiguration->ChangeResourceModule(ResourceModule);
  104. }
  105. }