3rdparty/licenseReport: Add seperate LGPL checks
[haiku.git] / src / add-ons / screen_savers / glife / GLifeSaver.cpp
bloba243bb1dd0b9c11fcdeebbe500c216e656dc95ce
1 /*
2 * Copyright 2012, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Aaron Hill <serac@hillvisions.com>
7 * Alexander von Gluck <kallisti5@unixzen.com>
8 */
11 #include "GLifeSaver.h"
13 #include <GLView.h>
14 #include <ScreenSaver.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <View.h>
19 #include "GLifeGrid.h"
20 #include "GLifeState.h"
21 #include "GLifeConfig.h"
22 #include "GLifeView.h"
25 // ------------------------------------------------------
26 // GLifeSaver Class Constructor Definition
27 GLifeSaver::GLifeSaver(BMessage* pbmPrefs, image_id iidImage)
29 BScreenSaver(pbmPrefs, iidImage)
31 // Check for preferences
32 if (!pbmPrefs->IsEmpty())
33 RestoreState(pbmPrefs);
35 // Seed random number generator
36 srandom(system_time());
40 // ------------------------------------------------------
41 // GLifeSaver Class SaveState Definition
42 status_t
43 GLifeSaver::SaveState(BMessage* pbmPrefs) const
45 return fGLifeState.SaveState(pbmPrefs);
49 // ------------------------------------------------------
50 // GLifeSaver Class RestoreState Definition
51 void
52 GLifeSaver::RestoreState(BMessage* pbmPrefs)
54 fGLifeState.RestoreState(pbmPrefs);
58 // ------------------------------------------------------
59 // GLifeSaver Class StartConfig Definition
60 void
61 GLifeSaver::StartConfig(BView* pbvView)
63 // Setup the "config" class
64 GLifeConfig* pglcConfig = new GLifeConfig(pbvView->Bounds(),
65 &fGLifeState);
67 pbvView->AddChild(pglcConfig);
71 // ------------------------------------------------------
72 // GLifeSaver Class StartSaver Definition
73 status_t
74 GLifeSaver::StartSaver(BView* pbvView, bool bPreview)
76 SetTickSize(c_iTickSize);
78 fGLifeViewport = new GLifeView(pbvView->Bounds(),
79 "GLifeView", B_FOLLOW_NONE, BGL_RGB | BGL_DEPTH | BGL_DOUBLE,
80 &fGLifeState);
82 pbvView->AddChild(fGLifeViewport);
84 return B_OK;
88 // ------------------------------------------------------
89 // GLifeSaver Class StopSaver Definition
90 void
91 GLifeSaver::StopSaver(void)
93 if (fGLifeViewport != NULL)
94 fGLifeViewport->EnableDirectMode(false);
98 // ------------------------------------------------------
99 // GLifeSaver Class DirectConnected Definition
100 void
101 GLifeSaver::DirectConnected(direct_buffer_info* pdbiInfo)
103 // Enable or disable direct rendering
104 if (fGLifeViewport != NULL) {
105 fGLifeViewport->DirectConnected(pdbiInfo);
106 fGLifeViewport->EnableDirectMode(true);
111 // ------------------------------------------------------
112 // GLifeSaver Class DirectDraw Definition
113 void
114 GLifeSaver::Draw(BView*, int32 iFrame)
116 fGLifeViewport->Advance();
120 // ------------------------------------------------------
121 // Main Instantiation Function
122 extern "C" _EXPORT BScreenSaver*
123 instantiate_screen_saver(BMessage* pbmPrefs, image_id iidImage)
125 return new GLifeSaver(pbmPrefs, iidImage);