Glyphs.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 "GUITools.h"
  10. //---------------------------------------------------------------------------
  11. #pragma package(smart_init)
  12. #pragma link "PngImageList"
  13. #ifndef NO_RESOURCES
  14. #pragma resource "*.dfm"
  15. #endif
  16. //---------------------------------------------------------------------------
  17. TGlyphsModule * GlyphsModule;
  18. //---------------------------------------------------------------------------
  19. __fastcall TGlyphsModule::TGlyphsModule(TComponent* Owner)
  20. : TDataModule(Owner)
  21. {
  22. FPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
  23. SetPixelsPerInch(Screen->PixelsPerInch);
  24. }
  25. //---------------------------------------------------------------------------
  26. // Contructor without scaling
  27. __fastcall TGlyphsModule::TGlyphsModule()
  28. : TDataModule(Application)
  29. {
  30. }
  31. //---------------------------------------------------------------------------
  32. void __fastcall TGlyphsModule::SetPixelsPerInch(int PixelsPerInch)
  33. {
  34. PixelsPerInch = NormalizePixelsPerInch(PixelsPerInch);
  35. if (FPixelsPerInch != PixelsPerInch)
  36. {
  37. std::unique_ptr<TDataModule> ScaledModule;
  38. if (PixelsPerInch >= 192)
  39. {
  40. ScaledModule.reset(new TGlyphs192Module(Application));
  41. }
  42. else if (PixelsPerInch >= 144)
  43. {
  44. ScaledModule.reset(new TGlyphs144Module(Application));
  45. }
  46. else if (PixelsPerInch >= 120)
  47. {
  48. ScaledModule.reset(new TGlyphs120Module(Application));
  49. }
  50. else
  51. {
  52. // Do not have a separate 96 DPI module, as this module needs to
  53. // have the images loaded as they are used on design time.
  54. // Performance impact of loading 96 DPI images when they are not needed is not that big.
  55. ScaledModule.reset(new TGlyphsModule());
  56. }
  57. if (ScaledModule.get() != NULL)
  58. {
  59. for (int Index = 0; Index < ComponentCount; Index++)
  60. {
  61. TComponent * TargetComponent = Components[Index];
  62. TComponent * SourceComponent = ScaledModule->FindComponent(TargetComponent->Name);
  63. if (DebugAlwaysTrue(SourceComponent != NULL))
  64. {
  65. TargetComponent->Assign(SourceComponent);
  66. }
  67. }
  68. }
  69. FPixelsPerInch = PixelsPerInch;
  70. }
  71. }