MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParameterControllerBool.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  ParameterControllerBool.h GUI panel for tweaking Parameter::Bools
3  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
28 #ifndef PARAMETERCONTROLLERBOOL_H
29 #define PARAMETERCONTROLLERBOOL_H
30 
31 #include "AssetManager.h"
32 #include "CharBufferByteSink.h"
33 #include "Drawing.h"
34 #include "Util.h"
35 #include "Parameter.h"
36 #include "ParameterController.h"
37 #include "AbstractCheckbox.h"
38 
39 namespace MFM
40 {
41  template <class CC>
43  {
44  private:
45  typedef typename CC::ATOM_TYPE T;
47 
48  enum
49  {
50  PARAMETERCONTROLLERBOOL_WIDTH = 300,
51  PARAMETERCONTROLLERBOOL_HEIGHT = 40,
52 
53  PARAMETERCONTROLLERBOOL_WIDTH_BIG = 400,
54  PARAMETERCONTROLLERBOOL_HEIGHT_BIG = 50
55  };
56 
57  inline u32 GetScaledWidth()
58  {
59  return Super::m_bigText ?
60  PARAMETERCONTROLLERBOOL_WIDTH_BIG :
61  PARAMETERCONTROLLERBOOL_WIDTH;
62  }
63 
64  inline u32 GetScaledHeight()
65  {
66  return Super::m_bigText ?
67  PARAMETERCONTROLLERBOOL_HEIGHT_BIG :
68  PARAMETERCONTROLLERBOOL_HEIGHT;
69  }
70 
71  class ParmCheckbox : public AbstractCheckbox
72  {
73  private:
74  typedef AbstractCheckbox Super;
75  typedef ParameterControllerBool PCB;
76 
78  bool m_bigText;
79 
80  inline u32 GetScaledWidth()
81  {
82  return m_bigText ?
83  PARAMETERCONTROLLERBOOL_WIDTH_BIG :
84  PARAMETERCONTROLLERBOOL_WIDTH;
85  }
86 
87  inline u32 GetScaledHeight()
88  {
89  return m_bigText ?
90  PARAMETERCONTROLLERBOOL_HEIGHT_BIG :
91  PARAMETERCONTROLLERBOOL_HEIGHT;
92  }
93 
94  public:
95  ParmCheckbox(ParameterControllerBool & bc) : m_bc(bc)
96  { }
97 
98  virtual bool IsChecked() const
99  {
100  return m_bc.GetParameterValue();
101  }
102 
103  virtual void SetChecked(bool value)
104  {
105  m_bc.SetParameterValue(value);
106  }
107 
108  virtual void OnCheck(bool value)
109  {
110  SetChecked(value);
111  }
112 
113  void Init(bool bigText = false)
114  {
115  m_bigText = bigText;
116  this->SetName("ParmCheckBox");
117  this->SetDimensions(SPoint(GetScaledWidth(),
118  GetScaledHeight()));
119  this->SetDesiredSize(U32_MAX, GetScaledHeight());
120  this->SetRenderPoint(SPoint(5, 5));
121  if (m_bc.GetParameter())
122  {
123  this->SetText(m_bc.GetParameter()->GetName());
124  }
125  }
126  };
127 
128  ParmCheckbox m_checkbox;
129 
130  public:
131 
133  m_checkbox(*this)
134  {
135  this->SetName("ParmCtrlBool");
136  Panel::Insert(&m_checkbox, NULL); // This is once-only
137  Init();
138  }
139 
140  void SetParameterValue(bool value)
141  {
142  if (!this->m_parameter || !this->m_patom)
143  {
144  FAIL(ILLEGAL_STATE);
145  }
146  this->m_parameter->SetBitsAsS32(*this->m_patom, value? -1 : 0);
147  }
148 
149  bool GetParameterValue() const
150  {
151  if (!this->m_parameter || !this->m_patom)
152  {
153  FAIL(ILLEGAL_STATE);
154  }
155  bool ret;
156  if (!this->m_parameter->LoadBool(*this->m_patom, ret))
157  {
158  FAIL(ILLEGAL_STATE);
159  }
160  return ret;
161  }
162 
163  void Init()
164  {
165  Panel::SetDimensions(GetScaledWidth() * 2, GetScaledHeight());
166  Panel::SetDesiredSize(10000, GetScaledHeight());
167  Panel::SetBackground(Drawing::GREY60);
168 
169  m_checkbox.Init(Super::m_bigText);
170 
171  LOG.Debug("Innitting %s", Super::m_bigText ? "big" : "normal");
172  }
173  };
174 }
175 
176 #endif /* PARAMETERCONTROLLERBOOL_H */
Definition: ParameterControllerBool.h:42
Definition: ParameterController.h:40
Definition: AbstractCheckbox.h:40
void Debug(const char *format,...)
Definition: Logger.h:301
u32 SetBackground(const u32 color)
Definition: Panel.h:220
#define U32_MAX
Definition: itype.h:95