Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
simplepicker.cpp
Go to the documentation of this file.
1 /*
2  * Vega Strike
3  * Copyright (C) 2003 Mike Byron
4  *
5  * http://vegastrike.sourceforge.net/
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21 
22 #include "vegastrike.h"
23 
24 #include "simplepicker.h"
25 
26 static const int CHILD_VECTOR_RESERVE = 20; //Make sure we don't get many re-alloc's.
27 
28 //Add a child to the list of children of this cell.
30 {
32 
33  m_children->addCell( c );
34 }
35 
36 //Make sure there is an empty list for children.
38 {
39  if (m_children == NULL)
41  return m_children;
42 }
43 
44 //Constructor.
45 SimplePickerCell::SimplePickerCell( const std::string &t, const std::string &id, const GFXColor &c, int tag ) :
46  m_text( t )
47  , m_id( id )
48  , m_textColor( c )
49  , m_tag( tag )
50  , m_children( NULL )
51 {}
52 
53 //Destructor.
55 {
56  if (m_children != NULL)
57  delete m_children;
58 }
59 
61 {
62  m_text = cell.m_text;
63  m_id = cell.m_id;
64  m_textColor = cell.m_textColor;
65  m_tag = cell.m_tag;
66  m_children = NULL;
67  if (cell.m_children != NULL)
68  //Need to make a copy of the children.
70  return *this;
71 }
72 
74 {
75  *this = cell;
76 }
77 
79 
80 //Constructor.
82 {
83  m_cells.reserve( CHILD_VECTOR_RESERVE );
84 }
85 
87 {
88  for (size_t i = 0; i < m_cells.size(); ++i)
89  delete m_cells[i];
90  m_cells.clear();
91 }
92 
94 
95 //Clear out all the cells.
96 void SimplePicker::clear( void )
97 {
98  m_cellPressed = NULL;
99  m_selectedCell = NULL;
100  m_highlightedCell = NULL;
101 
102  static_cast< SimplePickerCells* > (m_cells)->clear();
103 
104  setMustRecalc();
105 }
106 
107 //Constructor.
109 {
110  m_cells = new SimplePickerCells();
111 }
112 
114 {
115  clear();
116 }
117