/
MikeLight
/
Lab
Обзор
Документация
Войти
/
MikeLight
/
Lab
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
lab10/ScreenSaver/fScreenSaver.cpp
188 строк
6 KB
MikeLight
upload files
25 ноя 2025, 23:05
25 ноя 2025, 23:05
046237c
Код
Авторство
О чём код?
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "fScreenSaver.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "GLS.SceneViewer" #pragma link "GLS.BaseClasses" #pragma link "GLS.BitmapFont" #pragma link "GLS.Cadencer" #pragma link "GLS.Coordinates" #pragma link "GLS.FileWAV" #pragma link "GLS.FireFX" #pragma link "GLS.GeomObjects" #pragma link "GLS.HUDObjects" #pragma link "GLS.LensFlare" #pragma link "GLS.Material" #pragma link "GLS.Objects" #pragma link "GLS.ParticleFX" #pragma link "GLS.Scene" #pragma link "GLS.ScreenSaver" #pragma link "GLS.ShadowPlane" #pragma link "GLS.SoundManager" #pragma link "GLS.Sounds.BASS" #pragma link "GLS.VectorFileObjects" #pragma link "GLS.WindowsFont" #pragma link "GLS.File3DS" #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { SetCurrentDir("..\\..\\Assets"); Randomize(); FFFirTree->LoadFromFile("firtree.3ds"); FFFirePlace->LoadFromFile("fireplace.3ds"); fireLight = 0.5; FTYear->Text = ""; } //--------------------------------------------------------------------------- void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { mx = X; my = Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (Shift.Contains(ssLeft)) { Camera->MoveAroundTarget(my - Y, mx - X); } mx = X; my = Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::GLSceneViewer1MouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta, TPoint &MousePos, bool &Handled) { Camera->AdjustDistanceToTarget(Power(1.1, -WheelDelta / 120)); } //--------------------------------------------------------------------------- void __fastcall TForm1::TimerTimer(TObject *Sender) { int i; TDateTime t; String buf; Word y, m, d; bool TheChristmas; TheChristmas = false; Viewer->ResetPerformanceMonitor(); if ((GLSMBASS->Active) && (bStream == 0)) { bStream = BASS_StreamCreateFile(false, PAnsiChar("Jingle_Bells_64.mp3"), 0, 0, BASS_STREAM_AUTOFREE); BASS_ChannelPlay(bStream, false); } DecodeDate(Now(), y, m, d); if (TheChristmas) { t = EncodeDate(y, 12, 25) - Now(); FTCongratulations->Text = "Merry Christmas!"; } else { t = EncodeDate(y + 1, 01, 01) - Now(); FTCongratulations->Text = "Happy New Year!"; FTYear->Text = IntToStr(y + 1); } if ((double)t < 0) FTCountDown->Text = "Merry Christmas!"; if (((double)t < 1) && ((double)t > -1)) DCGifts->Visible = true; if ((double)t >= 2) { buf = IntToStr(Floor((double)t)) + " days, "; i = (Int)(Frac((double)t) * 24); if (i > 1) buf = buf + IntToStr(i) + " hours..."; else buf = buf + IntToStr(i) + " hour..."; FTCountDown->Text = buf; } else { t = (double)t * 24; if ((double)t > 1) { buf = IntToStr((int)t) + " hours, "; i = RoundInt(Frac((double)t) * 60); if (i > 1) buf = buf + IntToStr(i) + " minutes..."; else buf = buf + IntToStr(i) + " minute..."; FTCountDown->Text = buf; } else { t = (double)t * 60; i = RoundInt((float)((double)t - Floor((double)t)) * 60); FTCountDown->Text = IntToStr((int)t) + " minutes, " + IntToStr(i) + " seconds..."; } } } //--------------------------------------------------------------------------- void __fastcall TForm1::CadencerProgress(TObject *Sender, const double DeltaTime, const double NewTime) { fireLight = ClampValue(fireLight + Random() * 0.4 - 0.2, 0, 1); LSFire->Diffuse->Color = VectorLerp(clrYellow, VectorMake(0.5, 0, 0, 1), fireLight); LSFire->Position->Y = fireLight * 0.1; if (inPreview) HUDSprite->Visible = false; if (Visible) { HUDSprite->Material->FrontProperties->Diffuse->Alpha = HUDSprite->Material->FrontProperties->Diffuse->Alpha - DeltaTime * 0.05; if (HUDSprite->Material->FrontProperties->Diffuse->Alpha < 0.01) HUDSprite->Visible = false; } DCFirTree->Turn(DeltaTime); Viewer->Invalidate(); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormResize(TObject *Sender) { Camera->SceneScale = (float)Width / 640; if (Visible) HUDSprite->Position->X = Width - 200; if (Width >= Screen->Width) GLSceneViewer1DblClick(Sender); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormKeyPress(TObject *Sender, System::WideChar &Key) { Key = '\0'; Application->Terminate(); } //--------------------------------------------------------------------------- void __fastcall TForm1::GLSceneViewer1DblClick(TObject *Sender) { if ((!inPreview) && (!inSaver) && (!Application->Terminated) && (BorderStyle != bsNone)) { BorderStyle = bsNone; FormStyle = fsStayOnTop; Align = alClient; } } //--------------------------------------------------------------------------- void __fastcall TForm1::ScreenSaverCloseQuery(TObject *Sender, bool &CanClose) { Application->Terminate(); CanClose = false; } //--------------------------------------------------------------------------- void __fastcall TForm1::ScreenSaverExecute(TObject *Sender) { inSaver = true; } //--------------------------------------------------------------------------- void __fastcall TForm1::ScreenSaverPreview(TObject *Sender, HWND previewHwnd) { inPreview = true; } //---------------------------------------------------------------------------