Phoenard
PHNKeyboard.h
Go to the documentation of this file.
1 /*
2 The MIT License (MIT)
3 
4 This file is part of the Phoenard Arduino library
5 Copyright (c) 2014 Phoenard
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 */
25 
31 #include "PHNWidget.h"
32 
33 #ifndef _PHN_KEYBOARD_H_
34 #define _PHN_KEYBOARD_H_
35 
55 class PHN_Keyboard : public PHN_Widget {
56  public:
58  PHN_Keyboard();
60  void setDimension(int columns, int rows);
62  void setSpacing(int spacing);
64  void setSpacing(int spacingW, int spacingH);
66  void setKeys(const char* keyChars);
68  void addKeys(const char* keyChars);
70  void addKeys(const char* formatName, const char* keyChars);
72  void clearKeys();
74  int formatIndex() const { return this->formatIdx; }
76  void setFormatIndex(int index);
78  void nextFormat();
80  char key(int index);
82  int clickedIndex() const { return this->clickedIdx; }
84  char clickedKey();
85 
86  virtual void undraw(void);
87  virtual void update(void);
88  virtual void draw(void);
89  private:
90  void setupCells();
91  char fmt_key(int fmtIndex, int index);
92  void updateCell(int idx, bool drawCell, bool eraseCell);
93  DataBuffer formatChars;
94  DataBuffer formatNames;
95  unsigned char cols, rows;
96  unsigned char cellW, cellH, spacW, spacH;
97  int count;
98  int formatCnt;
99  int formatIdx;
100  int pressedIdx;
101  int clickedIdx;
102 };
103 
104 #endif
PHN_Keyboard()
Initializes a new Keyboard.
Definition: PHNKeyboard.cpp:33
Maintains data stored on the heap and frees it when the class is destructed.
Definition: DataBuffer.h:44
void setSpacing(int spacing)
Sets the horizontal and vertical spacing between buttons.
Definition: PHNKeyboard.cpp:45
The keyboard widget shows character-labeled keys.
Definition: PHNKeyboard.h:55
int formatIndex() const
Gets the currently used format index.
Definition: PHNKeyboard.h:74
int clickedIndex() const
Obtains the key character index clicked, -1 when there is none.
Definition: PHNKeyboard.h:82
void addKeys(const char *keyChars)
Adds a new keyboard format selectable using the key.
Definition: PHNKeyboard.cpp:69
void nextFormat()
Switches the keyboard to the next key format.
Definition: PHNKeyboard.cpp:103
void setFormatIndex(int index)
Sets the currently used format index.
Definition: PHNKeyboard.cpp:107
void clearKeys()
Clears all key formats added.
Definition: PHNKeyboard.cpp:62
void setKeys(const char *keyChars)
Sets all the character keys to display.
Definition: PHNKeyboard.cpp:57
virtual void draw(void)
Draw function routine, where widgets must perform drawing.
Definition: PHNKeyboard.cpp:184
A single widget which covers a rectangular area of the screen.
Definition: PHNWidget.h:145
char clickedKey()
Obtains the key character clicked, NULL when there is none.
Definition: PHNKeyboard.cpp:152
virtual void undraw(void)
Clear draw function routine, where widgets perform un-drawing (to background)
Definition: PHNKeyboard.cpp:192
void setDimension(int columns, int rows)
Sets the amount of columns and rows in the grid.
Definition: PHNKeyboard.cpp:38
Holds the PHN_Widget and PHN_WidgetContainer classes used for managing widgets.
char key(int index)
Obtains the character for a given key index.
Definition: PHNKeyboard.cpp:148
virtual void update(void)
Update function routine, where widget logic must be performed.
Definition: PHNKeyboard.cpp:158