xref: /haiku/src/add-ons/screen_savers/glife/GLifeState.h (revision 3c94b5cb05058d92687da398daedfe91634e1b34)
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
13 const int32 c_iDefGridWidth = 60;
14 const int32 c_iDefGridHeight = 40;
15 const int32 c_iDefBorder = 0;
16 
17 // GLifeState Class Declaration & Definition
18 class GLifeState
19 {
20 private:
21 	int32	m_iGridWidth;
22 	int32	m_iGridHeight;
23 	int32	m_iBorder;
24 
25 public:
26 	// Constructor
27 				GLifeState( void ) : m_iGridWidth(c_iDefGridWidth),
28 									 m_iGridHeight(c_iDefGridHeight),
29 									 m_iBorder(c_iDefBorder) { };
30 
31 	// Save/Restore State Methods
32 	status_t	SaveState( BMessage* pbmPrefs ) const
33 	{
34 		// Store current preferences
35 		pbmPrefs->AddInt32( "m_iGridWidth", m_iGridWidth );
36 		pbmPrefs->AddInt32( "m_iGridHeight", m_iGridHeight );
37 		pbmPrefs->AddInt32( "m_iBorder", m_iBorder );
38 
39 		return B_OK;
40 	};
41 
42 	void		RestoreState( BMessage* pbmPrefs )
43 	{
44 		// Retrieve preferences, substituting defaults
45 		if ( pbmPrefs->FindInt32( "m_iGridWidth",
46 								  &m_iGridWidth ) != B_OK )
47 			m_iGridWidth = c_iDefGridWidth;
48 		if ( pbmPrefs->FindInt32( "m_iGridHeight",
49 								  &m_iGridHeight ) != B_OK )
50 			m_iGridHeight = c_iDefGridHeight;
51 		if ( pbmPrefs->FindInt32( "m_iBorder",
52 								  &m_iBorder ) != B_OK )
53 			m_iBorder = c_iDefBorder;
54 	};
55 
56 	// Accessor Methods
57 	int32&		GridWidth( void ) { return m_iGridWidth; };
58 	int32&		GridHeight( void ) { return m_iGridHeight; };
59 	int32&		Border( void ) { return m_iBorder; };
60 };
61 
62 
63 #endif /* _GLIFE_GLIFESTATE_H */
64