MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AbstractCheckbox.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  AbstractCheckbox.h Boolean button
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 ABSTRACTCHECKBOX_H
29 #define ABSTRACTCHECKBOX_H
30 
31 #include "AbstractButton.h"
32 #include "AssetManager.h"
33 
34 namespace MFM
35 {
36 
41  {
42  public:
49  {
50  AbstractCheckbox::OnceOnly();
51  }
52 
58  AbstractCheckbox(const char* text) :
59  AbstractButton(text)
60  {
61  AbstractCheckbox::OnceOnly();
62  }
63 
64  virtual void PaintBorder(Drawing& d)
65  { /* Don't want to paint a border*/ }
66 
67  virtual void PaintComponent(Drawing& d)
68  {
69  SDL_Surface* icon = GetIcon();
70  d.BlitAsset(GetAsset(), UPoint(0, 0), UPoint(icon->w, icon->h));
71 
73 
75  AbstractButton::GetDimensions());
76  }
77 
78  virtual void OnClick(u8 button)
79  {
81 
82  OnCheck(IsChecked());
83  }
84 
92  virtual void OnCheck(bool value) = 0;
93 
97  virtual bool IsChecked() const = 0;
98 
102  virtual void SetChecked(bool checked) = 0;
103 
104  private:
105 
111  inline Asset GetAsset()
112  {
113  return IsChecked() ?
114  ASSET_CHECKBOX_ICON_ON :
115  ASSET_CHECKBOX_ICON_OFF ;
116  }
117 
126  inline SDL_Surface* GetIcon()
127  {
128  return AssetManager::Get(GetAsset());
129  }
130 
136  void OnceOnly()
137  {
138  Panel::SetForeground(Drawing::WHITE);
139  }
140  };
141 
147  {
148  bool * m_externalPointer;
149 
150  public:
151  AbstractCheckboxExternal(const char * title) :
152  AbstractCheckbox(title),
153  m_externalPointer(0)
154  {
155  }
156 
168  void SetExternalValue(bool * ptr)
169  {
170  m_externalPointer = ptr;
171  }
172 
183  virtual bool IsChecked() const
184  {
185  if (!m_externalPointer)
186  {
187  return false;
188  }
189  return *m_externalPointer;
190  }
191 
200  virtual void SetChecked(bool checked)
201  {
202  MFM_API_ASSERT_NONNULL(m_externalPointer);
203  *m_externalPointer = checked;
204  }
205  };
206 }
207 
208 #endif /* ABSTRACTCHECKBOX_H */
virtual void OnClick(u8 button)
Definition: AbstractCheckbox.h:78
Definition: AbstractCheckbox.h:146
AbstractCheckbox(const char *text)
Definition: AbstractCheckbox.h:58
virtual void PaintComponent(Drawing &d)
Definition: AbstractCheckbox.h:67
void BlitAsset(Asset asset, UPoint loc, UPoint maxSize) const
Definition: Drawing.cpp:167
u32 SetForeground(const u32 color)
Definition: Drawing.h:188
virtual bool IsChecked() const =0
Definition: AbstractButton.h:44
u32 SetForeground(const u32 color)
Definition: Panel.h:256
virtual bool IsChecked() const
Definition: AbstractCheckbox.h:183
virtual void PaintBorder(Drawing &d)
Definition: AbstractCheckbox.h:64
const char * GetText()
Definition: AbstractButton.h:224
virtual void SetChecked(bool checked)
Definition: AbstractCheckbox.h:200
virtual void SetChecked(bool checked)=0
Definition: AbstractCheckbox.h:40
u32 GetForeground() const
Definition: Panel.h:248
AbstractCheckbox()
Definition: AbstractCheckbox.h:47
virtual void OnCheck(bool value)=0
void SetExternalValue(bool *ptr)
Definition: AbstractCheckbox.h:168
void BlitText(const char *message, UPoint loc, UPoint size) const
Definition: Drawing.cpp:172
Definition: Drawing.h:44