NXWidgets  1.19
clatchbuttonarray.hxx
Go to the documentation of this file.
1 /****************************************************************************
2  * include/clatchbuttonarray.hxx
3  *
4  * Copyright (C) 2012 Gregory Nutt. All rights reserved.
5  * Author: Gregory Nutt <gnutt@nuttx.org>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
18  * me be used to endorse or promote products derived from this software
19  * without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  ****************************************************************************/
35 
36 #ifndef __INCLUDE_CLATCHBUTTONARRAY_HXX
37 #define __INCLUDE_CLATCHBUTTONARRAY_HXX
38 
39 /****************************************************************************
40  * Included Files
41  ****************************************************************************/
42 
43 #include <nuttx/config.h>
44 
45 #include <stdint.h>
46 #include <stdbool.h>
47 
48 #include <nuttx/nx/nxglib.h>
49 
50 #include "cstickybuttonarray.hxx"
51 #include "cwidgetstyle.hxx"
52 
53 /****************************************************************************
54  * Pre-Processor Definitions
55  ****************************************************************************/
56 
57 /****************************************************************************
58  * Implementation Classes
59  ****************************************************************************/
60 
61 #if defined(__cplusplus)
62 
63 namespace NXWidgets
64 {
65  /**
66  * Forward references
67  */
68 
69  class CWidgetControl;
70  class CNxString;
71 
72  /**
73  * Manages a two-dimensional array of buttons as one widget. When a button
74  * is clicked is latches (i.e., it stays pushed after the press is released.
75  * The behavior is then like radio buttons: Pressing each each button in
76  * the array unlatches the previous button and latches the new button.
77  *
78  * Unlike CLatchButton, pressing the same button more than once has no
79  * effect.
80  */
81 
83  {
84  protected:
85  /**
86  * Handles button click events
87  *
88  * @param x The x coordinate of the click.
89  * @param y The y coordinate of the click.
90  */
91 
92  virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
93 
94  /**
95  * Redraws the button.
96  *
97  * @param x The x coordinate of the mouse.
98  * @param y The y coordinate of the mouse.
99  */
100 
101  /**
102  * Copy constructor is protected to prevent usage.
103  */
104 
105  inline CLatchButtonArray(const CLatchButtonArray &button) : CStickyButtonArray(button) { }
106 
107  public:
108 
109  /**
110  * Constructor for an array of latch buttons.
111  *
112  * @param pWidgetControl The widget control for the display.
113  * @param x The x coordinate of the button array, relative to its parent.
114  * @param y The y coordinate of the button array, relative to its parent.
115  * @param buttonColumns The number of buttons in one row of the button array
116  * @param buttonRows The number of buttons in one column of the button array
117  * @param buttonWidth The width of one button
118  * @param buttonHeight The height of one button
119  * @param style The style that the button should use. If this is not
120  * specified, the button will use the global default widget
121  * style.
122  */
123 
124  CLatchButtonArray(CWidgetControl *pWidgetControl,
125  nxgl_coord_t x, nxgl_coord_t y,
126  uint8_t buttonColumns, uint8_t buttonRows,
127  nxgl_coord_t buttonWidth, nxgl_coord_t buttonHeight,
128  CWidgetStyle *style = (CWidgetStyle *)NULL);
129 
130  /**
131  * CLatchButtonArray Destructor.
132  */
133 
134  virtual inline ~CLatchButtonArray(void) { }
135 
136  /**
137  * Return the position of the last latched button (0,0 will be returned
138  * the no button has every been latched). The button at this position
139  * is currently latched then, in addition, return true.
140  *
141  * @param column The location to return the column index of the button
142  * of interest
143  * @param row The location to return the row index of the button of
144  * interest
145  * @return True if a button in the array is latched
146  */
147 
148  inline const bool isAnyButtonLatched(int &column, int &row) const
149  {
150  return isAnyButtonStuckDown(column, row);
151  }
152 
153  /**
154  * Check if this specific button in the array is latched
155  *
156  * @param column The column of the button to check.
157  * @param row The row of the button to check.
158  * @return True if this button is clicked
159  */
160 
161  inline const bool isThisButtonLatched(int column, int row) const
162  {
163  return isThisButtonStuckDown(column, row);
164  }
165  };
166 }
167 
168 #endif // __cplusplus
169 
170 #endif // __INCLUDE_CLATCHBUTTONARRAY_HXX
const bool isThisButtonLatched(int column, int row) const
CLatchButtonArray(const CLatchButtonArray &button)
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y)
const bool isAnyButtonLatched(int &column, int &row) const
virtual bool isAnyButtonStuckDown(int &column, int &row) const
virtual bool isThisButtonStuckDown(int column, int row) const