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 "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
  19. cSaverRegistryKey = "Software\\GLScene\\Samples\\CPP\\Demos\\ScreenSaver";
  20. const String
  21. cSaverRegistryMeshResolutions = "MeshResolutions";
  22. //---------------------------------------------------------------------------
  23. __fastcall TForm2::TForm2(TComponent* Owner)
  24. : TForm(Owner)
  25. {
  26. }
  27. //---------------------------------------------------------------------------
  28. int __fastcall GetMeshResolutions()
  29. {
  30. TRegistry *reg;
  31. reg = new TRegistry;
  32. reg->OpenKey(cSaverRegistryKey, true);
  33. // If the value cannot be found, we default to hi-resolution
  34. if (reg->ValueExists(cSaverRegistryMeshResolutions))
  35. return reg->ReadInteger(cSaverRegistryMeshResolutions);
  36. else
  37. return 1;
  38. delete reg;
  39. }
  40. //---------------------------------------------------------------------------
  41. void __fastcall SetMeshResolutions(int MeshResolutions)
  42. {
  43. TRegistry *reg;
  44. reg = new TRegistry;
  45. reg->OpenKey(cSaverRegistryKey, true);
  46. reg->WriteInteger(cSaverRegistryMeshResolutions, MeshResolutions);
  47. delete reg;
  48. }
  49. //---------------------------------------------------------------------------
  50. void __fastcall TForm2::FormCreate(TObject *Sender)
  51. {
  52. // we highlight the current resolution
  53. SetSelected(GetMeshResolutions());
  54. SetHot(-1);
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TForm2::SetSelected(int nb)
  58. {
  59. switch (nb)
  60. {
  61. case 0: Torus1->Material->FrontProperties->Emission->AsWinColor = clNavy;
  62. case 1: Torus2->Material->FrontProperties->Emission->AsWinColor = clBlue; break;
  63. default:;
  64. }
  65. }
  66. //---------------------------------------------------------------------------
  67. void __fastcall TForm2::SetHot(int nb)
  68. {
  69. switch (nb)
  70. {
  71. case 0: Torus1->Material->FrontProperties->Diffuse->AsWinColor = clGray;
  72. case 1: Torus2->Material->FrontProperties->Diffuse->AsWinColor = clWhite; break;
  73. default:;
  74. }
  75. }
  76. void __fastcall TForm2::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  77. 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(TObject *Sender, TMouseButton Button,
  90. TShiftState Shift, int X, int Y)
  91. {
  92. if (FLastHotNb >= 0)
  93. {
  94. SetSelected(FLastHotNb);
  95. SetMeshResolutions(FLastHotNb);
  96. }
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TForm2::Button2Click(TObject *Sender)
  100. {
  101. // a call to "Form1.ScreenSaver1.SetPassword;" would have done the same
  102. SetScreenSaverPassword;
  103. }
  104. //---------------------------------------------------------------------------