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 35 of file pincode.h.

Constructor & Destructor Documentation

◆ Pincode()

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

Definition at line 37 of file pincode.cpp.

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.

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

◆ ~Pincode()

Pincode::~Pincode ( )

Definition at line 76 of file pincode.cpp.

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

77 {
78  if (mWindow != nullptr)
80 
81  if (gui != nullptr)
82  gui->removeDragged(this);
83 
84  mInstances --;
85  if (mInstances == 0)
86  {
87  if (theme != nullptr)
88  theme->unload(mSkin);
89  }
90 }
static Skin * mSkin
Definition: pincode.h:53
void unload(Skin *const skin)
Definition: theme.cpp:249
Gui * gui
Definition: gui.cpp:110
static int mInstances
Definition: pincode.h:55
Widget * mWindow
Definition: widget2.h:111
Theme * theme
Definition: theme.cpp:61
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1161
void removeWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:306

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 154 of file pincode.cpp.

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

155 {
156  if (event.getId() == "clear")
157  {
158  mText.clear();
161  return;
162  }
163  if (mText.size() >= 4)
164  return;
165  const Widget *const eventSrc = event.getSource();
166  for (int f = 0; f < 10; f ++)
167  {
168  if (mButtons[f] == eventSrc)
169  {
170  const std::string str = toString(f);
171  mText.append(str);
174  return;
175  }
176  }
177 }
void setText(const std::string &text)
Definition: textfield.cpp:802
TextField * mTextField
Definition: pincode.h:65
std::string mText
Definition: pincode.h:64
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
Button * mButtons[11]
Definition: pincode.h:63
Definition: widget.h:97
void signalEvent()
Definition: textfield.cpp:842

◆ addButtons()

void Pincode::addButtons ( )
protected

Definition at line 92 of file pincode.cpp.

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

Referenced by Pincode().

93 {
94  int buttonWidth = 0;
95  int buttonHeight = 0;
96  for (int f = 0; f < 10; f ++)
97  {
98  const std::string str = toString(f);
99  mButtons[f] = new Button(this,
100  str,
101  str,
103  this);
104  mButtons[f]->adjustSize();
105  const Rect &rect = mButtons[f]->getDimension();
106  if (rect.width > buttonWidth)
107  buttonWidth = rect.width;
108  if (rect.height > buttonHeight)
109  buttonHeight = rect.height;
110  add(mButtons[f]);
111  }
112  int x = 0;
113  int y = 0;
114  const int xSize = buttonWidth + mSpacing;
115  const int ySize = buttonHeight + mSpacing;
116  for (int f = 0; f < 10; f ++)
117  {
118  mButtons[f]->setPosition(mPadding + x * xSize,
119  mPadding + y * ySize);
120  x ++;
121  if (x > 2)
122  {
123  x = 0;
124  y ++;
125  }
126  }
127  mButtons[10] = new Button(this,
128  // TRANSLATORS: clear pin code button
129  _("Clear"),
130  "clear",
132  this);
133  mButtons[10]->adjustSize();
134  add(mButtons[10]);
135  mButtons[10]->setPosition(mPadding + xSize,
136  mPadding + 3 * ySize);
137 
139  mButtonHeight = buttonHeight;
140 }
static const int buttonWidth
Definition: sliderlist.cpp:34
#define _(s)
Definition: gettext.h:34
int width
Definition: rect.h:218
const std::string BUTTON_PIN_SKIN
Definition: button.h:89
Definition: rect.h:72
int mButtonWidth
Definition: pincode.h:68
Definition: button.h:96
void adjustSize()
Definition: button.cpp:798
virtual void add(Widget *const widget)
int mButtonHeight
Definition: pincode.h:69
void setPosition(const int x, const int y)
Definition: widget.cpp:160
int height
Definition: rect.h:223
const Rect & getDimension() const
Definition: widget.h:316
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
Button * mButtons[11]
Definition: pincode.h:63
int mSpacing
Definition: pincode.h:67
int mPadding
Definition: pincode.h:66

◆ adjustSize()

void Pincode::adjustSize ( )

Definition at line 142 of file pincode.cpp.

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

Referenced by Pincode().

143 {
144  const int pad2 = mPadding * 2;
145  setSize(pad2 + 3 * mButtonWidth + 2 * mSpacing,
146  pad2 + 4 * mButtonHeight + 3 * mSpacing);
147 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
int mButtonWidth
Definition: pincode.h:68
int mButtonHeight
Definition: pincode.h:69
int mSpacing
Definition: pincode.h:67
int mPadding
Definition: pincode.h:66

◆ finalCleanup()

void Pincode::finalCleanup ( )
static

Definition at line 149 of file pincode.cpp.

References mSkin.

150 {
151  mSkin = nullptr;
152 }
static Skin * mSkin
Definition: pincode.h:53

◆ shuffle()

void Pincode::shuffle ( uint32_t  seed) const

Definition at line 179 of file pincode.cpp.

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

Referenced by PincodeDialog::PincodeDialog().

180 {
181  int tab[10];
182  const uint32_t multiplier = 0x3498;
183  const uint32_t baseSeed = 0x881234;
184  int k = 2;
185 
186  for (size_t f = 0; f < 10; f ++)
187  tab[f] = CAST_S32(f);
188  for (size_t f = 1; f < 10; f ++)
189  {
190  seed = baseSeed + seed * multiplier;
191  const size_t pos = seed % k;
192  if (f != pos)
193  {
194  const int tmp = tab[f];
195  tab[f] = tab[pos];
196  tab[pos] = tmp;
197  }
198  k = k + 1;
199  }
200  for (size_t f = 0; f < 10; f ++)
201  {
202  const std::string str = toString(tab[f]);
203  mButtons[f]->setCaption(str);
204  }
205 }
void setCaption(const std::string &caption)
Definition: button.h:213
#define CAST_S32
Definition: cast.h:29
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
Button * mButtons[11]
Definition: pincode.h:63

Field Documentation

◆ mButtonHeight

int Pincode::mButtonHeight
private

Definition at line 69 of file pincode.h.

Referenced by addButtons(), and adjustSize().

◆ mButtons

Button* Pincode::mButtons[11]
private

Definition at line 63 of file pincode.h.

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

◆ mButtonWidth

int Pincode::mButtonWidth
private

Definition at line 68 of file pincode.h.

Referenced by addButtons(), and adjustSize().

◆ mInstances

int Pincode::mInstances = 0
static

Definition at line 55 of file pincode.h.

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

◆ mPadding

int Pincode::mPadding
private

Definition at line 66 of file pincode.h.

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

◆ mSkin

Skin * Pincode::mSkin = 0
static

Definition at line 53 of file pincode.h.

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

◆ mSpacing

int Pincode::mSpacing
private

Definition at line 67 of file pincode.h.

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

◆ mText

std::string Pincode::mText
private

Definition at line 64 of file pincode.h.

Referenced by action().

◆ mTextField

TextField* Pincode::mTextField
private

Definition at line 65 of file pincode.h.

Referenced by action().


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