Glyphs.cpp 2.3 KB

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