2 * Copyright 2012, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
6 * Aaron Hill <serac@hillvisions.com>
7 * Alexander von Gluck <kallisti5@unixzen.com>
11 #include "GLifeSaver.h"
14 #include <ScreenSaver.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
43 GLifeSaver::SaveState(BMessage
* pbmPrefs
) const
45 return fGLifeState
.SaveState(pbmPrefs
);
49 // ------------------------------------------------------
50 // GLifeSaver Class RestoreState Definition
52 GLifeSaver::RestoreState(BMessage
* pbmPrefs
)
54 fGLifeState
.RestoreState(pbmPrefs
);
58 // ------------------------------------------------------
59 // GLifeSaver Class StartConfig Definition
61 GLifeSaver::StartConfig(BView
* pbvView
)
63 // Setup the "config" class
64 GLifeConfig
* pglcConfig
= new GLifeConfig(pbvView
->Bounds(),
67 pbvView
->AddChild(pglcConfig
);
71 // ------------------------------------------------------
72 // GLifeSaver Class StartSaver Definition
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
,
82 pbvView
->AddChild(fGLifeViewport
);
88 // ------------------------------------------------------
89 // GLifeSaver Class StopSaver Definition
91 GLifeSaver::StopSaver(void)
93 if (fGLifeViewport
!= NULL
)
94 fGLifeViewport
->EnableDirectMode(false);
98 // ------------------------------------------------------
99 // GLifeSaver Class DirectConnected Definition
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
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
);