dialogs.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: life/dialogs.cpp
  3. // Purpose: Life! dialogs
  4. // Author: Guillermo Rodriguez Garcia, <guille@iies.es>
  5. // Modified by:
  6. // Created: Jan/2000
  7. // Copyright: (c) 2000, Guillermo Rodriguez Garcia
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. // ==========================================================================
  11. // headers, declarations, constants
  12. // ==========================================================================
  13. // For compilers that support precompilation, includes "wx/wx.h".
  14. #include "wx/wxprec.h"
  15. #ifdef __BORLANDC__
  16. #pragma hdrstop
  17. #endif
  18. #ifndef WX_PRECOMP
  19. #include "wx/wx.h"
  20. #endif
  21. #include "wx/statline.h"
  22. #include "wx/minifram.h"
  23. #include "wx/settings.h"
  24. #include "dialogs.h"
  25. #include "life.h"
  26. #include "game.h"
  27. // --------------------------------------------------------------------------
  28. // resources
  29. // --------------------------------------------------------------------------
  30. #include "bitmaps/life.xpm"
  31. // sample configurations
  32. #include "samples.inc"
  33. // --------------------------------------------------------------------------
  34. // constants
  35. // --------------------------------------------------------------------------
  36. // IDs for the controls and the menu commands
  37. enum
  38. {
  39. // listbox in samples dialog
  40. ID_LISTBOX
  41. };
  42. // --------------------------------------------------------------------------
  43. // event tables and other macros for wxWidgets
  44. // --------------------------------------------------------------------------
  45. // Event tables
  46. BEGIN_EVENT_TABLE(LifeSamplesDialog, wxDialog)
  47. EVT_LISTBOX (ID_LISTBOX, LifeSamplesDialog::OnListBox)
  48. END_EVENT_TABLE()
  49. // ==========================================================================
  50. // implementation
  51. // ==========================================================================
  52. // --------------------------------------------------------------------------
  53. // LifeSamplesDialog
  54. // --------------------------------------------------------------------------
  55. LifeSamplesDialog::LifeSamplesDialog(wxWindow *parent)
  56. : wxDialog(parent, wxID_ANY, _("Sample games"),
  57. wxDefaultPosition, wxDefaultSize)
  58. {
  59. m_value = 0;
  60. wxSize listSize = wxDefaultSize;
  61. bool isPDA = wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA;
  62. // Screens are generally horizontal in orientation,
  63. // but PDAs are generally vertical.
  64. bool screenIsHorizontal = true;
  65. if (isPDA &&
  66. wxSystemSettings::GetMetric(wxSYS_SCREEN_X) < wxSystemSettings::GetMetric(wxSYS_SCREEN_Y))
  67. {
  68. listSize = wxSize(wxDefaultCoord, 50);
  69. screenIsHorizontal = false;
  70. }
  71. // create and populate the list of available samples
  72. m_list = new wxListBox( this, ID_LISTBOX,
  73. wxDefaultPosition,
  74. listSize,
  75. 0, NULL,
  76. wxLB_SINGLE | wxLB_NEEDED_SB | wxLB_HSCROLL );
  77. for (unsigned i = 0; i < (sizeof(g_patterns) / sizeof(LifePattern)); i++)
  78. m_list->Append(g_patterns[i].m_name);
  79. // descriptions
  80. wxStaticBox *statbox = new wxStaticBox( this, wxID_ANY, _("Description"));
  81. m_life = new Life();
  82. m_life->SetPattern(g_patterns[0]);
  83. m_canvas = new LifeCanvas( this, m_life, false );
  84. m_text = new wxTextCtrl( this, wxID_ANY,
  85. g_patterns[0].m_description,
  86. wxDefaultPosition,
  87. wxSize(300, 60),
  88. wxTE_MULTILINE | wxTE_READONLY);
  89. // layout components
  90. wxStaticBoxSizer *sizer1 = new wxStaticBoxSizer( statbox, wxVERTICAL );
  91. sizer1->Add( m_canvas, 2, wxGROW | wxALL, 5);
  92. sizer1->Add( m_text, 1, wxGROW | wxALL, 5 );
  93. wxBoxSizer *sizer2 = new wxBoxSizer( screenIsHorizontal ? wxHORIZONTAL : wxVERTICAL );
  94. sizer2->Add( m_list, 0, wxGROW | wxALL, 5 );
  95. sizer2->Add( sizer1, 1, wxGROW | wxALL, 5 );
  96. wxBoxSizer *sizer3 = new wxBoxSizer( wxVERTICAL );
  97. sizer3->Add( CreateTextSizer(_("Select a configuration")), 0, wxALL|wxCENTRE, isPDA ? 2 : 10 );
  98. #if wxUSE_STATLINE
  99. if (!isPDA)
  100. sizer3->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 10 );
  101. #endif // wxUSE_STATLINE
  102. sizer3->Add( sizer2, 1, wxGROW | wxALL, 5 );
  103. wxSizer *sizerBtns = CreateButtonSizer(wxOK|wxCANCEL);
  104. if ( sizerBtns )
  105. {
  106. sizer3->Add(sizerBtns, wxSizerFlags().Expand().Border());
  107. }
  108. // activate
  109. SetSizer(sizer3);
  110. #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
  111. sizer3->SetSizeHints(this);
  112. sizer3->Fit(this);
  113. Centre(wxBOTH | wxCENTRE_ON_SCREEN);
  114. #endif
  115. }
  116. LifeSamplesDialog::~LifeSamplesDialog()
  117. {
  118. m_canvas->Destroy();
  119. }
  120. const LifePattern& LifeSamplesDialog::GetPattern()
  121. {
  122. return g_patterns[m_value];
  123. }
  124. void LifeSamplesDialog::OnListBox(wxCommandEvent& event)
  125. {
  126. int sel = event.GetSelection();
  127. if (sel != -1)
  128. {
  129. m_value = m_list->GetSelection();
  130. m_text->SetValue(g_patterns[ sel ].m_description);
  131. m_life->SetPattern(g_patterns[ sel ]);
  132. // these values shouldn't be hardcoded...
  133. if ((size_t)sel < (sizeof(g_patterns) / sizeof(LifePattern)) - 3)
  134. m_canvas->SetCellSize(8);
  135. else
  136. m_canvas->SetCellSize(2);
  137. }
  138. }
  139. // --------------------------------------------------------------------------
  140. // LifeAboutDialog
  141. // --------------------------------------------------------------------------
  142. LifeAboutDialog::LifeAboutDialog(wxWindow *parent)
  143. : wxDialog(parent, wxID_ANY, _("About Life!"),
  144. wxDefaultPosition, wxDefaultSize)
  145. {
  146. // logo
  147. wxStaticBitmap *sbmp = new wxStaticBitmap(this, wxID_ANY, wxBitmap(life_xpm));
  148. // layout components
  149. wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
  150. sizer->Add( sbmp, 0, wxCENTRE | wxALL, 10 );
  151. #if wxUSE_STATLINE
  152. sizer->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 5 );
  153. #endif // wxUSE_STATLINE
  154. sizer->Add( CreateTextSizer(_("Life! version 2.2 for wxWidgets\n\n\
  155. (c) 2000 Guillermo Rodriguez Garcia\n\n\
  156. <guille@iies.es>\n\n\
  157. Portions of the code are based in XLife;\n\
  158. XLife is (c) 1989 by Jon Bennett et al.")),
  159. 0, wxCENTRE | wxRIGHT|wxLEFT|wxTOP, 20 );
  160. // buttons if any
  161. wxSizer *sizerBtns = CreateButtonSizer(wxOK);
  162. if ( sizerBtns )
  163. {
  164. sizer->Add(sizerBtns, wxSizerFlags().Expand().Border());
  165. }
  166. // activate
  167. SetSizer(sizer);
  168. #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
  169. sizer->SetSizeHints(this);
  170. sizer->Fit(this);
  171. Centre(wxBOTH | wxCENTRE_ON_SCREEN);
  172. #endif
  173. }