1/*
2 * Copyright 2012, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * 		Aaron Hill <serac@hillvisions.com>
7 */
8#ifndef _GLIFE_GLIFESTATE_H
9#define _GLIFE_GLIFESTATE_H
10
11
12// Constants
13const int32 kDefGridWidth = 60;
14const int32 kDefGridHeight = 40;
15const int32 kDefGridBorder = 0;
16const int32 kDefGridDelay = 2;
17
18
19// GLifeState Class Declaration & Definition
20class GLifeState
21{
22private:
23	int32	fGridWidth;
24	int32	fGridHeight;
25	int32	fGridBorder;
26	int32	fGridDelay;
27
28public:
29	// Constructor
30				GLifeState( void ) : fGridWidth(kDefGridWidth),
31									 fGridHeight(kDefGridHeight),
32									 fGridBorder(kDefGridBorder),
33									 fGridDelay(kDefGridDelay) { };
34
35	// Save/Restore State Methods
36	status_t SaveState(BMessage* pbmPrefs) const {
37		// Store current preferences
38		pbmPrefs->AddInt32("gridWidth", fGridWidth);
39		pbmPrefs->AddInt32("gridHeight", fGridHeight);
40		pbmPrefs->AddInt32("gridBorder", fGridBorder);
41		pbmPrefs->AddInt32("gridDelay", fGridDelay);
42
43		return B_OK;
44	};
45
46	void RestoreState( BMessage* pbmPrefs )
47	{
48		// Retrieve preferences, substituting defaults
49		if (pbmPrefs->FindInt32("gridWidth", &fGridWidth) != B_OK)
50			fGridWidth = kDefGridWidth;
51		if (pbmPrefs->FindInt32("gridHeight", &fGridHeight) != B_OK)
52			fGridHeight = kDefGridHeight;
53		if (pbmPrefs->FindInt32("gridBorder", &fGridBorder) != B_OK)
54			fGridBorder = kDefGridBorder;
55		if (pbmPrefs->FindInt32("gridDelay", &fGridDelay) != B_OK)
56			fGridDelay = kDefGridDelay;
57	};
58
59	// Accessor Methods
60	int32&		GridWidth(void) { return fGridWidth; };
61	int32&		GridHeight(void) { return fGridHeight; };
62	int32&		GridBorder(void) { return fGridBorder; };
63	int32&		GridDelay(void) { return fGridDelay; };
64};
65
66
67#endif /* _GLIFE_GLIFESTATE_H */
68