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