graphics/twm4nx/src/cbackground.cxx: Add logic to handle polling for background icon events.

graphics/twm4nx/src/window.cxx:  Add flags to CWindow initializer to support customization of toolbar buttons and other window properties.  Add framework to handle toolbar button presses.  Window minimization (aka, iconification) does not work.

graphics/twm4nx/src/input.cxx:  Add support to scaling touchscreen.  Not needed for the current testing because the touchscreen naturally matches the display size.  But will be needed, along with calibration scren, in the future.
This commit is contained in:
Gregory Nutt 2019-05-05 10:23:46 -06:00
parent f64df4a376
commit 64cf50e2eb
12 changed files with 418 additions and 60 deletions

View file

@ -271,6 +271,7 @@ namespace NxWM
static FAR void *calibration(FAR void *arg);
#ifdef CONFIG_NXWM_CALIBRATION_AVERAGE
/**
* Accumulate and average touch sample data
*
@ -278,7 +279,6 @@ namespace NxWM
* @return True: Average data is available; False: Need to collect more samples
*/
#ifdef CONFIG_NXWM_CALIBRATION_AVERAGE
bool averageSamples(struct nxgl_point_s &average);
#endif

View file

@ -111,7 +111,7 @@ namespace NxWM
static FAR void *listener(FAR void *arg);
/**
* Inject touchscreen data into NX as mouse intput
* Inject touchscreen data into NX as mouse input
*
* @param sample. The buffer where data was collected.
*/
@ -183,7 +183,7 @@ namespace NxWM
* using the calibration data and forward to the NX layer which dispatches the
* touchscreen events in window-relative positions to the correct NX window.
*
* @param data. A reference to the touchscreen data.
* @param caldata. A reference to the touchscreen data.
*/
void setCalibrationData(const struct SCalibrationData &caldata);
@ -201,6 +201,7 @@ namespace NxWM
{
caldata = m_calibData;
}
return m_calibrated;
}

View file

@ -113,7 +113,7 @@ namespace Twm4Nx
* @param name The prefix for this icon manager name
*/
bool createWindow(FAR const char *prefix);
bool createIconManagerWindow(FAR const char *prefix);
/**
* Create the button array widget

View file

@ -45,7 +45,9 @@
#include <semaphore.h>
#include <pthread.h>
#include <fixedmath.h>
#include <nuttx/nx/nxglib.h>
#include <nuttx/input/mouse.h>
#include "graphics/nxwidgets/cnxserver.hxx"
@ -58,6 +60,40 @@ namespace Twm4Nx
{
class CTwm4Nx; // Forward reference
#ifdef CONFIG_TWM4NX_TOUCHSCREEN
/**
* Touchscreen calibration data
*/
#ifdef CONFIG_TWM4NX_TOUCHSCREEN_ANISOTROPIC
struct SCalibrationLine
{
float slope; /**< The slope of a line */
float offset; /**< The offset of a line */
};
struct SCalibrationData
{
struct SCalibrationLine left; /**< Describes Y values along left edge */
struct SCalibrationLine right; /**< Describes Y values along right edge */
struct SCalibrationLine top; /**< Describes X values along top */
struct SCalibrationLine bottom; /**< Describes X values along bottom edge */
nxgl_coord_t leftX; /**< Left X value used in calibration */
nxgl_coord_t rightX; /**< Right X value used in calibration */
nxgl_coord_t topY; /**< Top Y value used in calibration */
nxgl_coord_t bottomY; /**< Bottom Y value used in calibration */
};
#else
struct SCalibrationData
{
b16_t xSlope; /**< X conversion: xSlope*(x) + xOffset */
b16_t xOffset;
b16_t ySlope; /**< Y conversion: ySlope*(y) + yOffset */
b16_t yOffset;
};
#endif
#endif // CONFIG_TWM4NX_TOUCHSCREEN
/**
* The CInput class provides receives raw keyboard and mouse inputs and
* injects that input into NX which it can be properly distributed to the
@ -99,6 +135,11 @@ namespace Twm4Nx
volatile enum EListenerState m_state; /**< The state of the listener thread */
sem_t m_waitSem; /**< Used to synchronize with the listener thread */
#ifdef CONFIG_TWM4NX_TOUCHSCREEN
bool m_calib; /**< False: Use raw, uncalibrated touches */
struct SCalibrationData m_calData; /**< Touchscreen calibration data */
#endif
#ifndef CONFIG_TWM4NX_NOKEYBOARD
/**
* Open the keyboard device. Not very interesting for the case of
@ -148,12 +189,26 @@ namespace Twm4Nx
#endif
#ifndef CONFIG_TWM4NX_NOMOUSE
#ifdef CONFIG_TWM4NX_TOUCHSCREEN
/**
* Calibrate raw touchscreen input.
*
* @param raw The raw touch sample
* @param scaled The location to return the scaled touch position
* @return On success, this method returns zero (OK). A negated errno
* value is returned if an irrecoverable error occurs.
*/
int scaleTouchData(FAR const struct touch_point_s &raw,
FAR struct nxgl_point_s &scaled);
#endif
/**
* Read data from the mouse/touchscreen device. If the input device
* is a mouse, then update the cursor position. And, in either case,
* inject the mouse data into NX for proper distribution.
*
* @return On success, then method returns zero (OK). A negated errno
* @return On success, this method returns zero (OK). A negated errno
* value is returned if an irrecoverable error occurs.
*/
@ -209,6 +264,19 @@ namespace Twm4Nx
~CInput(void);
#ifdef CONFIG_TWM4NX_TOUCHSCREEN
/**
* Provide touchscreen calibration data. If calibration data is received (and
* the touchscreen is enabled), then received touchscreen data will be scaled
* using the calibration data and forward to the NX layer which dispatches the
* touchscreen events in window-relative positions to the correct NX window.
*
* @param caldata. A reference to the touchscreen data.
*/
void setCalibrationData(const struct SCalibrationData &caldata);
#endif
/**
* Start the keyboard listener thread.
*

View file

@ -76,11 +76,31 @@
* There is no focus indicator
*/
#define MENU_BUTTON 0 // First on left
#define DELETE_BUTTON 1 // First on right
#define RESIZE_BUTTON 2
#define MINIMIZE_BUTTON 3
#define NTOOLBAR_BUTTONS 4
#define MENU_BUTTON 0 // First on left
#define DELETE_BUTTON 1 // First on right
#define RESIZE_BUTTON 2
#define MINIMIZE_BUTTON 3
#define NTOOLBAR_BUTTONS 4
// Windows may be customized with the flags parameter to the constructor.
// These are the bits fields that may be OR'ed together in the flags.
#define NO_TOOLBAR (NTOOLBAR_BUTTONS + 0)
#define ICONMGR_WINDOW (NTOOLBAR_BUTTONS + 1)
#define WFLAGS_NO_MENU_BUTTON (1 << MENU_BUTTON)
#define WFLAGS_NO_DELETE_BUTTON (1 << DELETE_BUTTON)
#define WFLAGS_NO_RESIZE_BUTTON (1 << RESIZE_BUTTON)
#define WFLAGS_NO_MINIMIZE_BUTTON (1 << MINIMIZE_BUTTON)
#define WFLAGS_NO_TOOLBAR (1 << NO_TOOLBAR)
#define WFLAGS_IS_ICONMGR (1 << ICONMGR_WINDOW)
#define WFLAGS_HAVE_MENU_BUTTON(f) (((f) & WFLAGS_NO_MENU_BUTTON) == 0)
#define WFLAGS_HAVE_DELETE_BUTTON(f) (((f) & WFLAGS_NO_DELETE_BUTTON) == 0)
#define WFLAGS_HAVE_RESIZE_BUTTON(f) (((f) & WFLAGS_NO_RESIZE_BUTTON) == 0)
#define WFLAGS_HAVE_MINIMIZE_BUTTON(f) (((f) & WFLAGS_NO_MINIMIZE_BUTTON) == 0)
#define WFLAGS_HAVE_TOOLBAR(f) (((f) & WFLAGS_NO_TOOLBAR) == 0)
#define WFLAGS_IS_ICONMGR_WINDOW(f) (((f) & WFLAGS_IS_ICONMGR) != 0)
/////////////////////////////////////////////////////////////////////////////
// Implementation Classes
@ -123,7 +143,6 @@ namespace Twm4Nx
FAR CIconWidget *m_iconWidget; /**< The icon widget */
FAR CIconMgr *m_iconMgr; /**< Pointer to it if this is an icon manager */
bool m_isIconMgr; /**< This is an icon manager window */
bool m_iconMoved; /**< User explicitly moved the icon. */
bool m_iconOn; /**< Icon is visible. */
bool m_iconified; /**< Is the window an icon now ? */
@ -135,6 +154,7 @@ namespace Twm4Nx
nxgl_coord_t m_tbHeight; /**< Height of the toolbar */
nxgl_coord_t m_tbLeftX; /**< Rightmost position of left buttons */
nxgl_coord_t m_tbRightX; /**< Leftmost position of right buttons */
uint8_t m_tbFlags; /**< Toolbar button customizations */
// List of all toolbar button images
@ -164,9 +184,13 @@ namespace Twm4Nx
/**
* Create all toolbar buttons
*
* @param flags Toolbar customizations see WFLAGS_NO_* definitions
* @return True if the window was successfully initialize; false on
* any failure,
*/
bool createToolbarButtons(void);
bool createToolbarButtons(uint8_t flags);
/**
* Add buttons and title widgets to the tool bar
@ -321,9 +345,8 @@ namespace Twm4Nx
* @param pos The initial position of the window
* @param size The initial size of the window
* @param sbitmap The Icon bitmap image
* @param isIconMgr Flag to tell if this is an icon manager window
* @param iconMgr Pointer to icon manager instance
* @param noToolbar True: Don't add Title Bar
* @param flags Toolbar customizations see WFLAGS_NO_* definitions
* @return True if the window was successfully initialize; false on
* any failure,
*/
@ -332,7 +355,7 @@ namespace Twm4Nx
FAR const struct nxgl_point_s *pos,
FAR const struct nxgl_size_s *size,
FAR const struct NXWidgets::SRlePaletteBitmap *sbitmap,
bool isIconMgr, FAR CIconMgr *iconMgr, bool noToolbar);
FAR CIconMgr *iconMgr, uint8_t flags = 0);
/**
* Synchronize the window with the NX server. This function will delay
@ -371,7 +394,7 @@ namespace Twm4Nx
inline bool isIconMgr(void)
{
return m_isIconMgr;
return WFLAGS_IS_ICONMGR_WINDOW(m_tbFlags);
}
/**
@ -648,7 +671,12 @@ namespace Twm4Nx
inline bool pollToolbarEvents(void)
{
NXWidgets::CWidgetControl *control = m_toolbar->getWidgetControl();
return control->pollEvents();
// pollEvents() returns true if any interesting event occurred.
// false is not a failure.
(void)control->pollEvents();
return true;
}
/**

View file

@ -139,18 +139,17 @@ namespace Twm4Nx
/**
* Create a new window and add it to the window list.
*
* @param name The window name
* @param name The window name
* @param sbitmap The Icon bitmap
* @param isIconMgr Flag to tell if this is an icon manager window
* @param iconMgr Pointer to icon manager instance
* @param noToolbar True: Don't add Title Bar
* @return Reference to the allocated CWindow instance
* @param iconMgr Pointer to icon manager instance
* @param flags Toolbar customizations see WFLAGS_NO_* definitions
* @return Reference to the allocated CWindow instance
*/
FAR CWindow *
createWindow(FAR const char *name,
FAR const struct NXWidgets::SRlePaletteBitmap *sbitmap,
bool isIconMgr, FAR CIconMgr *iconMgr, bool noToolbar);
FAR CIconMgr *iconMgr, uint8_t flags);
/**
* Handle the EVENT_WINDOW_DELETE event. The logic sequence is as