fScreenSaver2C.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fScreenSaver2C.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLS.BaseClasses"
  8. #pragma link "GLS.Behaviours"
  9. #pragma link "GLS.Cadencer"
  10. #pragma link "GLS.Coordinates"
  11. #pragma link "GLS.GeomObjects"
  12. #pragma link "GLS.Objects"
  13. #pragma link "GLS.Scene"
  14. #pragma link "GLS.SpaceText"
  15. #pragma link "GLS.SceneViewer"
  16. #pragma resource "*.dfm"
  17. TForm2* Form2;
  18. const String cSaverRegistryKey =
  19. "Software\\GLScene\\Demos\\utilities\\ScreenSaver";
  20. const String cSaverRegistryMeshResolutions = "MeshResolutions";
  21. //---------------------------------------------------------------------------
  22. __fastcall TForm2::TForm2(TComponent* Owner) : TForm(Owner) {}
  23. //---------------------------------------------------------------------------
  24. int __fastcall GetMeshResolutions()
  25. {
  26. TRegistry* reg;
  27. reg = new TRegistry;
  28. reg->OpenKey(cSaverRegistryKey, true);
  29. // If the value cannot be found, we default to hi-resolution
  30. if (reg->ValueExists(cSaverRegistryMeshResolutions))
  31. return reg->ReadInteger(cSaverRegistryMeshResolutions);
  32. else
  33. return 1;
  34. delete reg;
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall SetMeshResolutions(int MeshResolutions)
  38. {
  39. TRegistry* reg;
  40. reg = new TRegistry;
  41. reg->OpenKey(cSaverRegistryKey, true);
  42. reg->WriteInteger(cSaverRegistryMeshResolutions, MeshResolutions);
  43. delete reg;
  44. }
  45. //---------------------------------------------------------------------------
  46. void __fastcall TForm2::FormCreate(TObject* Sender)
  47. {
  48. // we highlight the current resolution
  49. SetSelected(GetMeshResolutions());
  50. SetHot(-1);
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TForm2::SetSelected(int nb)
  54. {
  55. switch (nb) {
  56. case 0:
  57. Torus1->Material->FrontProperties->Emission->AsWinColor = clNavy;
  58. case 1:
  59. Torus2->Material->FrontProperties->Emission->AsWinColor = clBlue;
  60. break;
  61. default:;
  62. }
  63. }
  64. //---------------------------------------------------------------------------
  65. void __fastcall TForm2::SetHot(int nb)
  66. {
  67. switch (nb) {
  68. case 0:
  69. Torus1->Material->FrontProperties->Diffuse->AsWinColor = clGray;
  70. case 1:
  71. Torus2->Material->FrontProperties->Diffuse->AsWinColor = clWhite;
  72. break;
  73. default:;
  74. }
  75. }
  76. void __fastcall TForm2::GLSceneViewer1MouseMove(
  77. TObject* Sender, TShiftState Shift, int X, int Y)
  78. {
  79. TGLBaseSceneObject* bso;
  80. // Here I used the trick of setting Torus1.Tag=1 and Torus.Tag=2
  81. // other objects have a Tag of 0
  82. bso = GLSceneViewer1->Buffer->GetPickedObject(X, Y);
  83. if (bso && (bso->Tag > 0))
  84. SetHot(bso->Tag - 1);
  85. else
  86. SetHot(-1);
  87. }
  88. //---------------------------------------------------------------------------
  89. void __fastcall TForm2::GLSceneViewer1MouseDown(
  90. TObject* Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  91. {
  92. if (FLastHotNb >= 0) {
  93. SetSelected(FLastHotNb);
  94. SetMeshResolutions(FLastHotNb);
  95. }
  96. }
  97. //---------------------------------------------------------------------------
  98. void __fastcall TForm2::Button2Click(TObject* Sender)
  99. {
  100. // a call to "Form1.ScreenSaver1.SetPassword;" would have done the same
  101. SetScreenSaverPassword;
  102. }
  103. //---------------------------------------------------------------------------