NXWidgets  1.19
clatchbuttonarray.cxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/libnxwidgets/src/clatchbuttonarray.cxx
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 /****************************************************************************
37  * Included Files
38  ****************************************************************************/
39 
40 #include <nuttx/config.h>
41 
42 #include <sys/types.h>
43 #include <stdint.h>
44 #include <stdbool.h>
45 
46 #include <nuttx/nx/nxglib.h>
47 
48 #include "cstickybuttonarray.hxx"
49 #include "clatchbuttonarray.hxx"
50 #include "cgraphicsport.hxx"
51 
52 /****************************************************************************
53  * Pre-Processor Definitions
54  ****************************************************************************/
55 
56 /****************************************************************************
57  * CButton Method Implementations
58  ****************************************************************************/
59 
60 using namespace NXWidgets;
61 
62 /**
63  * Constructor for an array of latch buttons.
64  *
65  * @param pWidgetControl The widget control for the display.
66  * @param x The x coordinate of the button array, relative to its parent.
67  * @param y The y coordinate of the button array, relative to its parent.
68  * @param buttonColumns The number of buttons in one row of the button array
69  * @param buttonRows The number of buttons in one column of the button array
70  * @param buttonWidth The width of one button
71  * @param buttonHeight The height of one button
72  * @param style The style that the button should use. If this is not
73  * specified, the button will use the global default widget
74  * style.
75  */
76 
78  nxgl_coord_t x, nxgl_coord_t y,
79  uint8_t buttonColumns, uint8_t buttonRows,
80  nxgl_coord_t buttonWidth, nxgl_coord_t buttonHeight,
81  CWidgetStyle *style)
82 : CStickyButtonArray(pWidgetControl, x, y, buttonColumns, buttonRows, buttonWidth, buttonHeight, style)
83 {
84 }
85 
86 /**
87  * Handles button click events
88  *
89  * @param x The x coordinate of the click.
90  * @param y The y coordinate of the click.
91  */
92 
93 void CLatchButtonArray::onClick(nxgl_coord_t x, nxgl_coord_t y)
94 {
95  // We need to save the button position so that when CButtonArray
96  // gets the release, it will have the correct position. This would
97  // look nicer if we just called CButtonArray::onClock() but that
98  // would cause duplicate redraw()
99 
100  m_clickX = x;
101  m_clickY = y;
102 
103  // Convert the new key press to row/columin indices
104 
105  int column;
106  int row;
107 
108  if (posToButton(x, y, column, row))
109  {
110  // Change the stuck down button on each in-range button press
111  // NOTE that normally button click events are not processed (but
112  // button release events will be processed).
113 
114  stickDown(column, row);
115  }
116 }
CLatchButtonArray(const CLatchButtonArray &button)
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y)
virtual bool stickDown(int column, int row)
virtual bool posToButton(nxgl_coord_t x, nxgl_coord_t y, int &column, int &row)