xref: /haiku/src/add-ons/screen_savers/glife/GLifeSaver.cpp (revision 1333f5f77b3556974cac8ef2906ee03c3caf2875)
10b4c5624SAlexander von Gluck IV /*
20b4c5624SAlexander von Gluck IV  * Copyright 2012, Haiku, Inc.
30b4c5624SAlexander von Gluck IV  * Distributed under the terms of the MIT License.
40b4c5624SAlexander von Gluck IV  *
50b4c5624SAlexander von Gluck IV  * Authors:
60b4c5624SAlexander von Gluck IV  * 		Aaron Hill <serac@hillvisions.com>
78bc51beeSAlexander von Gluck IV  *		Alexander von Gluck <kallisti5@unixzen.com>
80b4c5624SAlexander von Gluck IV  */
90b4c5624SAlexander von Gluck IV 
100b4c5624SAlexander von Gluck IV 
114b66f476SAlexander von Gluck IV #include "GLifeSaver.h"
124b66f476SAlexander von Gluck IV 
130b4c5624SAlexander von Gluck IV #include <GLView.h>
140b4c5624SAlexander von Gluck IV #include <ScreenSaver.h>
154b66f476SAlexander von Gluck IV #include <stdio.h>
164b66f476SAlexander von Gluck IV #include <stdlib.h>
170b4c5624SAlexander von Gluck IV #include <View.h>
180b4c5624SAlexander von Gluck IV 
193c94b5cbSAlexander von Gluck IV #include "GLifeGrid.h"
203c94b5cbSAlexander von Gluck IV #include "GLifeState.h"
213c94b5cbSAlexander von Gluck IV #include "GLifeConfig.h"
223c94b5cbSAlexander von Gluck IV #include "GLifeView.h"
234b66f476SAlexander von Gluck IV 
240b4c5624SAlexander von Gluck IV 
250b4c5624SAlexander von Gluck IV // ------------------------------------------------------
260b4c5624SAlexander von Gluck IV //  GLifeSaver Class Constructor Definition
GLifeSaver(BMessage * pbmPrefs,image_id iidImage)270b4c5624SAlexander von Gluck IV GLifeSaver::GLifeSaver(BMessage* pbmPrefs, image_id iidImage)
284b66f476SAlexander von Gluck IV 	:
294b66f476SAlexander von Gluck IV 	BScreenSaver(pbmPrefs, iidImage)
300b4c5624SAlexander von Gluck IV {
310b4c5624SAlexander von Gluck IV 	// Check for preferences
324b66f476SAlexander von Gluck IV 	if (!pbmPrefs->IsEmpty())
330b4c5624SAlexander von Gluck IV 		RestoreState(pbmPrefs);
340b4c5624SAlexander von Gluck IV 
350b4c5624SAlexander von Gluck IV 	// Seed random number generator
360b4c5624SAlexander von Gluck IV 	srandom(system_time());
370b4c5624SAlexander von Gluck IV }
380b4c5624SAlexander von Gluck IV 
394b66f476SAlexander von Gluck IV 
400b4c5624SAlexander von Gluck IV // ------------------------------------------------------
410b4c5624SAlexander von Gluck IV //  GLifeSaver Class SaveState Definition
424b66f476SAlexander von Gluck IV status_t
SaveState(BMessage * pbmPrefs) const434b66f476SAlexander von Gluck IV GLifeSaver::SaveState(BMessage* pbmPrefs) const
440b4c5624SAlexander von Gluck IV {
45f6dff255SAlexander von Gluck IV 	return fGLifeState.SaveState(pbmPrefs);
460b4c5624SAlexander von Gluck IV }
470b4c5624SAlexander von Gluck IV 
484b66f476SAlexander von Gluck IV 
490b4c5624SAlexander von Gluck IV // ------------------------------------------------------
500b4c5624SAlexander von Gluck IV //  GLifeSaver Class RestoreState Definition
514b66f476SAlexander von Gluck IV void
RestoreState(BMessage * pbmPrefs)524b66f476SAlexander von Gluck IV GLifeSaver::RestoreState(BMessage* pbmPrefs)
530b4c5624SAlexander von Gluck IV {
54f6dff255SAlexander von Gluck IV 	fGLifeState.RestoreState(pbmPrefs);
550b4c5624SAlexander von Gluck IV }
560b4c5624SAlexander von Gluck IV 
574b66f476SAlexander von Gluck IV 
580b4c5624SAlexander von Gluck IV // ------------------------------------------------------
590b4c5624SAlexander von Gluck IV //  GLifeSaver Class StartConfig Definition
604b66f476SAlexander von Gluck IV void
StartConfig(BView * pbvView)614b66f476SAlexander von Gluck IV GLifeSaver::StartConfig(BView* pbvView)
620b4c5624SAlexander von Gluck IV {
630b4c5624SAlexander von Gluck IV 	// Setup the "config" class
640b4c5624SAlexander von Gluck IV 	GLifeConfig* pglcConfig = new GLifeConfig(pbvView->Bounds(),
65f6dff255SAlexander von Gluck IV 		&fGLifeState);
66f6dff255SAlexander von Gluck IV 
670b4c5624SAlexander von Gluck IV 	pbvView->AddChild(pglcConfig);
680b4c5624SAlexander von Gluck IV }
690b4c5624SAlexander von Gluck IV 
704b66f476SAlexander von Gluck IV 
710b4c5624SAlexander von Gluck IV // ------------------------------------------------------
720b4c5624SAlexander von Gluck IV //  GLifeSaver Class StartSaver Definition
734b66f476SAlexander von Gluck IV status_t
StartSaver(BView * pbvView,bool bPreview)744b66f476SAlexander von Gluck IV GLifeSaver::StartSaver(BView* pbvView, bool bPreview)
750b4c5624SAlexander von Gluck IV {
760b4c5624SAlexander von Gluck IV 	SetTickSize(c_iTickSize);
770b4c5624SAlexander von Gluck IV 
78f6dff255SAlexander von Gluck IV 	fGLifeViewport = new GLifeView(pbvView->Bounds(),
794b66f476SAlexander von Gluck IV 		"GLifeView", B_FOLLOW_NONE, BGL_RGB | BGL_DEPTH | BGL_DOUBLE,
80f6dff255SAlexander von Gluck IV 		&fGLifeState);
814b66f476SAlexander von Gluck IV 
82f6dff255SAlexander von Gluck IV 	pbvView->AddChild(fGLifeViewport);
830b4c5624SAlexander von Gluck IV 
840b4c5624SAlexander von Gluck IV 	return B_OK;
850b4c5624SAlexander von Gluck IV }
860b4c5624SAlexander von Gluck IV 
874b66f476SAlexander von Gluck IV 
880b4c5624SAlexander von Gluck IV // ------------------------------------------------------
890b4c5624SAlexander von Gluck IV //  GLifeSaver Class StopSaver Definition
904b66f476SAlexander von Gluck IV void
StopSaver(void)914b66f476SAlexander von Gluck IV GLifeSaver::StopSaver(void)
920b4c5624SAlexander von Gluck IV {
93f6dff255SAlexander von Gluck IV 	if (fGLifeViewport != NULL)
944b66f476SAlexander von Gluck IV 		fGLifeViewport->EnableDirectMode(false);
950b4c5624SAlexander von Gluck IV }
960b4c5624SAlexander von Gluck IV 
974b66f476SAlexander von Gluck IV 
980b4c5624SAlexander von Gluck IV // ------------------------------------------------------
990b4c5624SAlexander von Gluck IV //  GLifeSaver Class DirectConnected Definition
1004b66f476SAlexander von Gluck IV void
DirectConnected(direct_buffer_info * pdbiInfo)1014b66f476SAlexander von Gluck IV GLifeSaver::DirectConnected(direct_buffer_info* pdbiInfo)
1020b4c5624SAlexander von Gluck IV {
103cfe5c09aSAlexander von Gluck IV 	// Enable or disable direct rendering
104f6dff255SAlexander von Gluck IV 	if (fGLifeViewport != NULL) {
105f6dff255SAlexander von Gluck IV 		fGLifeViewport->DirectConnected(pdbiInfo);
106f6dff255SAlexander von Gluck IV 		fGLifeViewport->EnableDirectMode(true);
1070b4c5624SAlexander von Gluck IV 	}
108cfe5c09aSAlexander von Gluck IV }
1090b4c5624SAlexander von Gluck IV 
1104b66f476SAlexander von Gluck IV 
1110b4c5624SAlexander von Gluck IV // ------------------------------------------------------
1120b4c5624SAlexander von Gluck IV //  GLifeSaver Class DirectDraw Definition
1134b66f476SAlexander von Gluck IV void
Draw(BView *,int32 iFrame)114*1333f5f7SAdrien Destugues GLifeSaver::Draw(BView*, int32 iFrame)
1150b4c5624SAlexander von Gluck IV {
116f6dff255SAlexander von Gluck IV 	fGLifeViewport->Advance();
1170b4c5624SAlexander von Gluck IV }
1180b4c5624SAlexander von Gluck IV 
1194b66f476SAlexander von Gluck IV 
1200b4c5624SAlexander von Gluck IV // ------------------------------------------------------
1210b4c5624SAlexander von Gluck IV //  Main Instantiation Function
1220b4c5624SAlexander von Gluck IV extern "C" _EXPORT BScreenSaver*
instantiate_screen_saver(BMessage * pbmPrefs,image_id iidImage)1230b4c5624SAlexander von Gluck IV instantiate_screen_saver(BMessage* pbmPrefs, image_id iidImage)
1240b4c5624SAlexander von Gluck IV {
1250b4c5624SAlexander von Gluck IV 	return new GLifeSaver(pbmPrefs, iidImage);
1260b4c5624SAlexander von Gluck IV }
127