Unit2.cpp 3.4 KB

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