ManaPlus
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Attributes
Pincode Class Reference

#include <pincode.h>

Inheritance diagram for Pincode:
Container ActionListener WidgetListener BasicContainer2 BasicContainer Widget WidgetDeathListener Widget2

Public Member Functions

 Pincode (const Widget2 *const widget, TextField *const textField)
 
 ~Pincode ()
 
void adjustSize ()
 
void action (const ActionEvent &event)
 
void shuffle (uint32_t seed) const
 
- Public Member Functions inherited from Container
 Container (const Widget2 *const widget)
 
 ~Container ()
 
bool safeRemove (Widget *const widget)
 
void removeControls ()
 
- Public Member Functions inherited from BasicContainer2
 BasicContainer2 (const Widget2 *const widget)
 
 ~BasicContainer2 ()
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
virtual void add (Widget *const widget)
 
void addXY (Widget *const widget, const int x, const int y)
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
Rect getChildrenArea ()
 
void focusNext ()
 
void focusPrevious ()
 
void logic ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget * > &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
virtual void postInit ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetResized (const Event &event)
 
virtual void widgetMoved (const Event &event)
 
virtual void widgetHidden (const Event &event)
 
virtual void widgetShown (const Event &event)
 

Static Public Member Functions

static void finalCleanup ()
 
- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 

Static Public Attributes

static SkinmSkin = 0
 
static int mInstances = 0
 

Protected Member Functions

void addButtons ()
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 

Private Attributes

ButtonmButtons [11]
 
std::string mText
 
TextFieldmTextField
 
int mPadding
 
int mSpacing
 
int mButtonWidth
 
int mButtonHeight
 

Additional Inherited Members

- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Attributes inherited from BasicContainer2
Opaque mOpaque
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

Definition at line 36 of file pincode.h.

Constructor & Destructor Documentation

◆ Pincode()

Pincode::Pincode ( const Widget2 *const  widget,
TextField *const  textField 
)

Definition at line 38 of file pincode.cpp.

39  :
40  Container(widget),
43  mButtons(),
44  mText(),
45  mTextField(textField),
46  mPadding(0),
47  mSpacing(2),
48  mButtonWidth(0),
49  mButtonHeight(0)
50 {
51  mAllowLogic = false;
53 
54  if (mInstances == 0)
55  {
56  if (theme != nullptr)
57  {
58  mSkin = theme->load("pin.xml",
59  "",
60  true,
62  }
63  }
64  mInstances ++;
65 
66  if (mSkin != nullptr)
67  {
69  mSpacing = mSkin->getOption("spacing", 2);
70  }
71  setSelectable(false);
72 
73  addButtons();
74  adjustSize();
75 }
void setOpaque(Opaque opaque)
Container(const Widget2 *const widget)
Definition: container.cpp:30
int mSpacing
Definition: pincode.h:68
int mButtonWidth
Definition: pincode.h:69
void addButtons()
Definition: pincode.cpp:93
int mButtonHeight
Definition: pincode.h:70
int mPadding
Definition: pincode.h:67
static Skin * mSkin
Definition: pincode.h:54
std::string mText
Definition: pincode.h:65
void adjustSize()
Definition: pincode.cpp:143
Button * mButtons[11]
Definition: pincode.h:64
static int mInstances
Definition: pincode.h:56
TextField * mTextField
Definition: pincode.h:66
int getOption(const std::string &name) const
Definition: skin.h:106
int getPadding() const
Definition: skin.h:100
static std::string getThemePath()
Definition: theme.h:67
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:179
bool mAllowLogic
Definition: widget.h:1160
void setSelectable(const bool selectable)
Definition: widget.h:948
const bool Opaque_false
Definition: opaque.h:30
Theme * theme
Definition: theme.cpp:62

References addButtons(), adjustSize(), Skin::getOption(), Skin::getPadding(), Theme::getThemePath(), Theme::load(), Widget::mAllowLogic, mInstances, mPadding, mSkin, mSpacing, Opaque_false, BasicContainer2::setOpaque(), Widget::setSelectable(), and theme.

◆ ~Pincode()

Pincode::~Pincode ( )

Definition at line 77 of file pincode.cpp.

78 {
79  if (mWindow != nullptr)
81 
82  if (gui != nullptr)
83  gui->removeDragged(this);
84 
85  mInstances --;
86  if (mInstances == 0)
87  {
88  if (theme != nullptr)
89  theme->unload(mSkin);
90  }
91 }
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1162
void unload(Skin *const skin)
Definition: theme.cpp:250
Widget * mWindow
Definition: widget2.h:112
void removeWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:307
Gui * gui
Definition: gui.cpp:111

References gui, mInstances, mSkin, Widget2::mWindow, Gui::removeDragged(), Widget::removeWidgetListener(), theme, and Theme::unload().

Member Function Documentation

◆ action()

void Pincode::action ( const ActionEvent actionEvent)
virtual

Called when an action is recieved from a widget. It is used to be able to recieve a notification that an action has occured.

Parameters
actionEventThe event of the action.

Implements ActionListener.

Definition at line 155 of file pincode.cpp.

156 {
157  if (event.getId() == "clear")
158  {
159  mText.clear();
162  return;
163  }
164  if (mText.size() >= 4)
165  return;
166  const Widget *const eventSrc = event.getSource();
167  for (int f = 0; f < 10; f ++)
168  {
169  if (mButtons[f] == eventSrc)
170  {
171  const std::string str = toString(f);
172  mText.append(str);
175  return;
176  }
177  }
178 }
void setText(const std::string &text)
Definition: textfield.cpp:803
void signalEvent()
Definition: textfield.cpp:843
Definition: widget.h:99
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774

References ActionEvent::getId(), mButtons, mText, mTextField, TextField::setText(), TextField::signalEvent(), and Catch::toString().

◆ addButtons()

void Pincode::addButtons ( )
protected

Definition at line 93 of file pincode.cpp.

94 {
95  int buttonWidth = 0;
96  int buttonHeight = 0;
97  for (int f = 0; f < 10; f ++)
98  {
99  const std::string str = toString(f);
100  mButtons[f] = new Button(this,
101  str,
102  str,
104  this);
105  mButtons[f]->adjustSize();
106  const Rect &rect = mButtons[f]->getDimension();
107  if (rect.width > buttonWidth)
108  buttonWidth = rect.width;
109  if (rect.height > buttonHeight)
110  buttonHeight = rect.height;
111  add(mButtons[f]);
112  }
113  int x = 0;
114  int y = 0;
115  const int xSize = buttonWidth + mSpacing;
116  const int ySize = buttonHeight + mSpacing;
117  for (int f = 0; f < 10; f ++)
118  {
119  mButtons[f]->setPosition(mPadding + x * xSize,
120  mPadding + y * ySize);
121  x ++;
122  if (x > 2)
123  {
124  x = 0;
125  y ++;
126  }
127  }
128  mButtons[10] = new Button(this,
129  // TRANSLATORS: clear pin code button
130  _("Clear"),
131  "clear",
133  this);
134  mButtons[10]->adjustSize();
135  add(mButtons[10]);
136  mButtons[10]->setPosition(mPadding + xSize,
137  mPadding + 3 * ySize);
138 
140  mButtonHeight = buttonHeight;
141 }
const std::string BUTTON_PIN_SKIN
Definition: button.h:90
virtual void add(Widget *const widget)
Definition: button.h:102
void adjustSize()
Definition: button.cpp:799
Definition: rect.h:74
int width
Definition: rect.h:219
int height
Definition: rect.h:224
const Rect & getDimension() const
Definition: widget.h:317
void setPosition(const int x, const int y)
Definition: widget.cpp:161
#define _(s)
Definition: gettext.h:35
static const int buttonWidth
Definition: sliderlist.cpp:35

References _, BasicContainer2::add(), Button::adjustSize(), BUTTON_PIN_SKIN, buttonWidth, Widget::getDimension(), Rect::height, mButtonHeight, mButtons, mButtonWidth, mPadding, mSpacing, Widget::setPosition(), Catch::toString(), Rect::width, x, and y.

Referenced by Pincode().

◆ adjustSize()

void Pincode::adjustSize ( )

Definition at line 143 of file pincode.cpp.

144 {
145  const int pad2 = mPadding * 2;
146  setSize(pad2 + 3 * mButtonWidth + 2 * mSpacing,
147  pad2 + 4 * mButtonHeight + 3 * mSpacing);
148 }
void setSize(const int width, const int height)
Definition: widget.cpp:367

References mButtonHeight, mButtonWidth, mPadding, mSpacing, and Widget::setSize().

Referenced by Pincode().

◆ finalCleanup()

void Pincode::finalCleanup ( )
static

Definition at line 150 of file pincode.cpp.

151 {
152  mSkin = nullptr;
153 }

References mSkin.

◆ shuffle()

void Pincode::shuffle ( uint32_t  seed) const

Definition at line 180 of file pincode.cpp.

181 {
182  int tab[10];
183  const uint32_t multiplier = 0x3498;
184  const uint32_t baseSeed = 0x881234;
185  int k = 2;
186 
187  for (size_t f = 0; f < 10; f ++)
188  tab[f] = CAST_S32(f);
189  for (size_t f = 1; f < 10; f ++)
190  {
191  seed = baseSeed + seed * multiplier;
192  const size_t pos = seed % k;
193  if (f != pos)
194  {
195  const int tmp = tab[f];
196  tab[f] = tab[pos];
197  tab[pos] = tmp;
198  }
199  k = k + 1;
200  }
201  for (size_t f = 0; f < 10; f ++)
202  {
203  const std::string str = toString(tab[f]);
204  mButtons[f]->setCaption(str);
205  }
206 }
#define CAST_S32
Definition: cast.h:30
void setCaption(const std::string &caption)
Definition: button.h:214

References CAST_S32, mButtons, Button::setCaption(), and Catch::toString().

Referenced by PincodeDialog::PincodeDialog().

Field Documentation

◆ mButtonHeight

int Pincode::mButtonHeight
private

Definition at line 70 of file pincode.h.

Referenced by addButtons(), and adjustSize().

◆ mButtons

Button* Pincode::mButtons[11]
private

Definition at line 64 of file pincode.h.

Referenced by action(), addButtons(), and shuffle().

◆ mButtonWidth

int Pincode::mButtonWidth
private

Definition at line 69 of file pincode.h.

Referenced by addButtons(), and adjustSize().

◆ mInstances

int Pincode::mInstances = 0
static

Definition at line 56 of file pincode.h.

Referenced by Pincode(), and ~Pincode().

◆ mPadding

int Pincode::mPadding
private

Definition at line 67 of file pincode.h.

Referenced by addButtons(), adjustSize(), and Pincode().

◆ mSkin

Skin * Pincode::mSkin = 0
static

Definition at line 54 of file pincode.h.

Referenced by finalCleanup(), Pincode(), and ~Pincode().

◆ mSpacing

int Pincode::mSpacing
private

Definition at line 68 of file pincode.h.

Referenced by addButtons(), adjustSize(), and Pincode().

◆ mText

std::string Pincode::mText
private

Definition at line 65 of file pincode.h.

Referenced by action().

◆ mTextField

TextField* Pincode::mTextField
private

Definition at line 66 of file pincode.h.

Referenced by action().


The documentation for this class was generated from the following files: