Phoenard
PHNButtonGrid.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 #include "PHNButton.h"
33 
34 #ifndef _PHN_WIDGET_BUTTON_GRID_H_
35 #define _PHN_WIDGET_BUTTON_GRID_H_
36 
53 class PHN_ButtonGrid : public PHN_Widget {
54  public:
56  PHN_ButtonGrid(void);
58  void setDimension(int columns, int rows);
60  void setSpacing(int spacing);
62  void setSpacing(int spacingW, int spacingH);
63 
65  int buttonCount() const { return count; }
66 
68  PHN_Button &button(int index) { return *((PHN_Button*) widget(index)); }
70  PHN_Button &button(int column, int row) { return button(getIndex(column, row)); }
71 
73  int getTouchedColumn(void);
75  int getTouchedRow(void);
77  int getTouchedIndex(void);
78 
80  int getClickedColumn(void);
82  int getClickedRow(void);
84  int getClickedIndex(void);
85 
86  virtual void update(void);
87  virtual void draw(void);
88  protected:
89  int cols, rows, count, cellW, cellH, spacW, spacH;
90  int getIndex(int col, int row);
91  private:
92  void setupCells();
93 };
94 
95 #endif
int buttonCount() const
Gets the amount of buttons stored.
Definition: PHNButtonGrid.h:65
int getTouchedIndex(void)
Gets the index of the cell pressed, -1 if none is pressed.
Definition: PHNButtonGrid.cpp:88
Contains the PHN_Button widget; a pressable three-state button.
int getTouchedRow(void)
Gets the row of the cell pressed, -1 if none is pressed.
Definition: PHNButtonGrid.cpp:84
void setSpacing(int spacing)
Sets the horizontal and vertical spacing between buttons.
Definition: PHNButtonGrid.cpp:41
virtual void update(void)
Update function routine, where widget logic must be performed.
Definition: PHNButtonGrid.cpp:115
PHN_Widget * widget(int index)
Gets the widget stored at an index.
Definition: PHNWidget.h:102
PHN_ButtonGrid(void)
Basic constructor to set the initial rows/columns to 0.
Definition: PHNButtonGrid.cpp:28
int getTouchedColumn(void)
Gets the column of the cell pressed, -1 if none is pressed.
Definition: PHNButtonGrid.cpp:80
int getClickedIndex(void)
Gets the index of the cell clicked, -1 if none is clicked.
Definition: PHNButtonGrid.cpp:103
A single widget which covers a rectangular area of the screen.
Definition: PHNWidget.h:145
int getClickedRow(void)
Gets the row of the cell clicked, -1 if none is clicked.
Definition: PHNButtonGrid.cpp:99
virtual void draw(void)
Draw function routine, where widgets must perform drawing.
Definition: PHNButtonGrid.cpp:119
The button widget can be clicked by the user, showing three states.
Definition: PHNButton.h:45
int getClickedColumn(void)
Gets the column of the cell clicked, -1 if none is clicked.
Definition: PHNButtonGrid.cpp:95
void setDimension(int columns, int rows)
Sets the amount of columns and rows in the grid.
Definition: PHNButtonGrid.cpp:35
Holds the PHN_Widget and PHN_WidgetContainer classes used for managing widgets.
PHN_Button & button(int column, int row)
Accesses a single button in the grid by column and row.
Definition: PHNButtonGrid.h:70
Holds multiple rows and columns of buttons.
Definition: PHNButtonGrid.h:53
PHN_Button & button(int index)
Accesses a single button in the grid by index.
Definition: PHNButtonGrid.h:68