Resync new repository with old repo r5166

git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5153 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2012-09-17 18:18:44 +00:00
commit 57623d42eb
5691 changed files with 1361853 additions and 0 deletions
+165
View File
@@ -0,0 +1,165 @@
1.0 2012-03-22 Gregory Nutt <gnutt@nuttx.org>
* The initial release of the NxWidgets package
1.1 2012-05-19 Gregory Nutt <gnutt@nuttx.org>
* Updated and verified the NxWidgets DOxygen documentation. Contributed
by Jose Pablo Carballo.
* IBitmap, CRlePalettBitmap: Extended class to support differnt LUTs
for selected and non-selected images.
* CImage: If selected, uses different LUTs based, different borders.
CImage is now basically a button type.
* CImage: Add logic to hightlight an CImage (using the selected LUT).
* nxwm: The tiny NX window manager (NxWM) is being developed in this directory.
* UnitTests/nxwm: A unit test for the NX window manager.
* CWidgetControl: Add a semaphore to force clients to wait if the
size or position of the window is not yet known (multi-user mode only).
* During integration of NxWM, corrected numerous problems with NxWidgets
running on toolbars and framed windows. That capability was commented
out in the 1.0 release but is verfied functional in 1.1.
* CRlePalettBitmap: Fix an error in the text that determines if we
need to "rewind" to the beginning of the image.
* CRlePalettBitmap: Fixe a positioning problem. It was actually losing
the last row of every image!
* CNxWidget: Removed support for "shelving" widgets. I will be removing
some lesser used feature over time in order to reduce the NxWidgets
footprint.
* CNxWidget: Removed support for reference constants and close types.
The goal is to ge the base widget class as small as possible.
* CNxTkWindow: Fix uninitialized pointer value.
* CNxToolbar: Need to "fake" the fix position callback to avoid
deadlock waits for the callback that won't happen.
* CNxTkWindow: Fix toolbar background color
* CWidgetControl: Don't declare the the geometry is good until a non-NULL
window size is received.
* CGraphicsPort and CWidgetControl: If the underlying graphics device
is write-only, then we have to render fonts a little differently.
* CNxWidgets, CWidgetControl, and CRectCache: Big change! Remove all support
for widgets in a "vertical" hierarchy. Now widgets exist in a flat,
two-dimensional space and should not overlap. This should greatly
reduce the memory requirements and, since, NuttX already supports
a hierarchical windowing system, does not result in loss of functionality.
* CNxWidgets and CWidgetControl. Remove specific built-in support for
modal loops. There are too many different control mechanisms that might
be needed. Replace with hooks to control widget events from totally
external logic.
* CWindowEventHandler, CWindowEventHandlerList, CWidgetControl: New
callback classes to receive notifications about window events.
* NxWM::CFullScreenWindow and NxWM::CTaskbar: Add support in NxWM for full
screen window applications.
* All application windows now use CWindowEventHandler and CWindowEventHandlerList
to get notifications about mouse and keyboard events. These class will
then automatically handle polling (with no need for a modal loop).
* NxWM::CTouchscreen and NxWM::CCalibration: Add touchscreen support (still a long
way to go).
* NxWM::g_playBitmp: Change the play icon again. These tiny touch icons
must be very simple.
* NxWM::CCalibration: Beef up touch input handling logic. Now changes the
color of the touch circle to yellow when it is touched.
* NxWM::CTouchscreen: Do not read touchscreen data when there is no consumer.
* NxWM::CWindowControl: Add new class to wrap CWidgetControl and provide
some special mouse and keyboard input event handling.
* NxWM::CTaskbar: Correct the calculation of the physical size of the
display.
* NxWM::CCalibration: run method must clear m_stop when returning, or you can
never restart the Calibration window.
* NxWM::CTaskbar: On a failure to start an application, the application icon
CImage was being deleted twice.
* NXWidgets::CImage: Now handles mouse click callbacks. CImage is now really
a button. Probably should separate basic imaging functionality as CImage
and create a new CImageButton.
* NxWM::CStartWindow: Now ignores any close application button presses
(You can't close the start window).
* NxWM::CCalibration: The calibration application now has its own thread.
This was necessary for a proper integration with the taskbar.
* NxWM::CCalibration and NxWM:CTouchscreen: Changed the mechanism use
to report calbration data. It is now reported directly from CCalibration
to CTouchscreen. If external logic needs calibration, it can now get it
from CTouchscreen instead of CCalibration. This change was necessary
to make the termination conditions of CCalibration clean (it used to
have to persist until some external logic got the Calibration data).
* IApplication, IApplicationWindow, and all classes that inherit from
these: Now support method to report if the application is a full-screen
or a normal application. This is necessary to prevent CTaskbar from
displaying a task bar on top of a full-screen window.
* NxWM::CTaskbar: Ooops... minimizing the wrong application!
* NxWM::CNxConsole: Add a on_exit() exit handler that will close the
NxConsole window when the NSH thread exits. A correct build now depends
on having CONFIG_SCHED_ONEXIT defined.
* NXWidgets::CNxWidget: Add a new onPreRelease() method.
* NXWidgets::CButton, CButtonArry, CImage now post action event at pre-release time.
* NxWM: ICON touches are now drive by action events instead of click events.
* NXWidgets::CNxTkWindow: Reported size of a framed window must exclude the
height of the tool bar (if present)
* TODO.txt: Add a file to keep track of issues.
* NxWM::CStartWindow and IApplicationFactory: This is a substantial
redesign. IApplication wraps an application. However, if we want to
be able to start multiple copies of an application, then we need to
be able to create multiple IApplication instances from the start window.
Enter IApplicationFactory. Icons in the start window now correspond
to application factories; icons in the task bar no correspond to
application instances.
* NxWM::CStartWindow and CWindowControl: The above change necessitated
another architectural change: When create applications, it is sometimes
necessary to wait for windows events. The above change moved the
application creation to the window event thread, hence, causing deadlocks
wheneven the logic tried to wait for a window event. The solution was
to create a new thread, called the start window thread, that runs
asynchronously and can wait for windoew events.
* doc/NxWM-ThreadingModel.ppt: Documented the now rather complex NxWM
threading model.
1.2 2012-06-15 Gregory Nutt <gnutt@nuttx.org>
* NXWidgets::CCallback: callback arguement is now type CCallback and not
CWidgetControl; Added a method to redirect keyboard contacts to either
the widgets in the window (via CWidgetControl) or to an NxConsole (via
nxcon_kbdin()).
* NXWidgets::INxWindow, CBgWindow, CNxTkWindow, CNxToolbar, CNxWindow:
Now pass the CCallback intances as the callback argument instead of
the CWidgetControl instance. New method redirectNxConsole() will
support redirection of any window keyboard input to the NxConsole
(via CCallback).
* NxWM:CNxConsole: Configures the NxConsole window to redirection keyboard
input to the NxConsole; redirects standard input to the NxConsole
device driver.
* NxWM:CKeyboard: Add a new class that implements a keyboard listener
thread. This thread reads from /dev/console and injects the keyboard
input into NX. NX will determine which window is at the top of the
heirarchy and re-direct the keyboard input to only that top window.
This solves an important problem with, for example, running multiple
copies of the NxConsole: On the copy of the NxConsole at the top of
the heirarchy should get the keyboard input.
* UnitTests/nxwm/main.cxx: Now starts the keyboard thread if
CONFIG_NXWM_KEYBOARD is defined.
* NxWM::CTaskbar: After drawing the task bar, need to raise the
application window otherwise the taskbar will be on the top and
keyboard input will not be received by the top application.
* NxWM::CTaskbar: Bugfix... previous window should not be minimized
when a new window is started. It should stay in a maximized state
so that it will re-appear with the window above it is closed or
minimized.
* NxWM::CHexCalculator: Add a hexadecimal/decimal calculator
example.
* NXWidgets::CNxTkWindow: Back out height adjustment in the getSize()
method. The code was correct as it was before.
* NXWidgets::CButtonArray and NXWidgets::CGraphicsPort: There is
a kludge in there to handle the case where we cannot read the
background data because the LCD does not support read operations.
In that case, we just use the default background color. However,
that doesn't work either for the case where the background color
changes when the widget is selected. Then the background color
in the font is wrong. Fixed in CButtonArrary, but the problem
probably exists in other places as well.
* NxWM: Increase default spacing of icons on the Start Window.
* NxWM::CHexCalculator: Fix some non-standard calculator behavior
after = is pressed. Use upper case hex. Increase font size.
* nxwm/Makefile: Fix error that creapt in during some other
recent check-ins.
1.3 2012-xx-xx Gregory Nutt <gnutt@nuttx.org>
* UnitTests/*/main.cxx: Change entry point name to be consistent
with with entry point naming conventions introduced in NuttX
6.22.
File diff suppressed because it is too large Load Diff
+64
View File
@@ -0,0 +1,64 @@
README
======
This directory contains the documentation automatically generated by Doxygen.
Contents
========
o Installing the necessary packages in Ubuntu
o Generating documentation
o References
Installing the necessary packages in Ubuntu
===========================================
1. Install the following packages.
$ sudo aptitude install doxygen doxygen-doc doxygen-gui dot2tex graphviz
2. (Optional) Install Doxygen from the latest sourcode.
The Ubuntu package is outdated. The newer the version of Doxygen, the better
the documentation looks.
Place yourself in some temporary folder where you can download the source,
and run [1]:
$ svn co https://doxygen.svn.sourceforge.net/svnroot/doxygen/trunk doxygen-svn
$ cd doxygen-svn
$ ./configure
$ make
$ make install
Generating documentation
========================
Two ways described here:
1. Use the provided gendoc.sh script.
trunk/NXWidgets/Doxygen/gendoc.sh
The script only needs the argument to the absolute path where to place the
generated documentation. I.e.:
$ cd /path/to/nuttx/trunk/NXWidgets/Doxygen/
$ mkdir doc
$ ./gendoc.sh $PWD/doc
2. Using the Doxyfile directly:
The file "Doxyfile" contains the configuration of the Doxygen settings
for the run, edit only if necessary.
To generate the documentation type:
$ cd /path/to/nuttx/trunk/NXWidgets/Doxygen/
$ doxygen Doxyfile
References
==========
[1] http://www.stack.nl/~dimitri/doxygen/download.html
+94
View File
@@ -0,0 +1,94 @@
#!/bin/bash
#################################################################################
# NxWidgets/Doxygen/gendoc.sh
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Jose Pablo Carballo <jcarballo@nx-engineering.com>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
#
# set -x
# Functions
function ShowUsage()
{
echo ""
echo "USAGE: $0 <doxygen-output-directory-path>"
echo ""
echo "Where:"
echo " <doxygen-output-directory-path> is the full, absolut path to place the doxygen output"
echo ""
}
# Input parameters
DOXYGENOUTPUT_DIR=$1
if [ -z "${DOXYGENOUTPUT_DIR}" ]; then
echo "Missing required arguments"
ShowUsage
exit 1
fi
# Check that the directory exist
if [ ! -d "${DOXYGENOUTPUT_DIR}" ]; then
echo "Directory ${DOXYGENOUTPUT_DIR} does not exist"
exit 1
fi
# Find the doxygen configuration file
DOXYFILE="Doxyfile"
if [ ! -e "${DOXYFILE}" ]; then
echo "This script must be executed in the documentation/ directory"
exit 1
fi
doxygen "${DOXYFILE}" || \
{
echo "Failed to run doxygen"; \
exit 1;
}
cp -rf html "${DOXYGENOUTPUT_DIR}" || \
{
echo "Failed to move html output"; \
exit 1;
}
rm -rf html || \
{
echo "Failed to remove the html/ directory"; \
exit 1;
}
echo "open ${DOXYGENOUTPUT_DIR}/html/index.html to start browsing"
+91
View File
@@ -0,0 +1,91 @@
NXWidgets
=========
In order to better support NuttX based platforms, a special graphical user
interface has been created called NXWidgets. NXWidgets is written in C++
and integrates seamlessly with the NuttX NX graphics subsystem in order
to provide graphic objects, or "widgets," in the NX Graphics Subsystem
Some of the features of NXWidgets include:
o Conservative C++
NXWidgets is written entirely in C++ but using only selected “embedded
friendly” C++ constructs that are fully supported under NuttX. No
additional C++ support libraries are required.
o NX Integration
NXWidgets integrate seamlessly with the NX graphics system. Think of the
X server under Linux … the NX graphics system is like a tiny X server
that provides windowing under NuttX. By adding NXWidgets, you can support
graphics objects like buttons and text boxes in the NX windows and toolbars.
o Small Footprint
NXWidgets is tailored for use MCUs in embedded applications. It is ideally
suited for mid- and upper-range of most MCU families. A complete NXWidgets
is possible in as little as 40Kb of FLASH and maybe 4Kb of SRAM.
o Output Devices
NXWidgets will work on the high-end frame buffer devices as well as on LCDs
connected via serial or parallel ports to a small MCU.
o Input Devices
NXWidgets will accept position and selection inputs from a mouse or a
touchscreen. It will also support character input from a keyboard such as a
USB keyboard. NXWidgets supports on very special widget called CKeypad that
will provide keyboard input via an on-screen keypad that can be operated
via mouse or touchscreen inputs.
o Many Graphic Objects
Some of the graphic objects supported by NXWidgets include labels, buttons,
text boxes, button arrays, check boxes, cycle buttons, images, sliders,
scrollable list boxes, progress bars, and more.
Note: Many of the fundamental classed in NxWidgets derive from the Antony
Dzeryn's "Woopsi" project: http://woopsi.org/ which also has a BSD style
license. See the COPYING file for details.
Directory Structure
===================
libnxwidgets
The source code, header files, and build environment for NxWidgets is
provided in this directory.
UnitTests
Provides a collection of unit-level tests for many of the individual
widgets provided by libnxwidgets.
nxwm
This directory holds a tiny desktop for small embedded devices with a
touchscreen,. NxWM. NxWM is true multiple window manager but only one
window is displayed at a time. This simplification helps performance on
LCD based products (in the same way that a tiled window manager helps)
and also makes the best use of small displays. It is awkward from a
human factors point-of-view trying to manage multiple windows on a
small display.
The window manager consists of a task bar with icons representing the
running tasks. If you touch the task's icon, it comes to the top. Each
window has a toolbar with (1) a title, (2) a minimize button, and (3) a
stop application button using the standard icons for these things.
There is always a start window that is available in the task bar. When
you touch the start window icon, it brings up the start window containing
icons representing all of the available applications. If you touch an
icon in the start window, it will be started and added to the task bar.
There is a base class that defines an add-on application and an
interface that supports incorporation of new application. The only
application that is provided is NxConsole. This is an NSH session
running in a window. You should be able to select the NX icon in the start
menu and create as many NSH sessions in windows as you want. (keybard input
still comes through serial).
+99
View File
@@ -0,0 +1,99 @@
NxWidgets-1.0
=============
The initial version of NxWidgets was released on March 22, 2012. This
package has been used in several projects prior to its release to open
source and is considered stable its initial release (although not all
features have been fully verified).
NxWidgets-1.1
=============
The 2nd release of the NxWidgets package as made on May 19, 2012. The
headline new feature in this release is:
* NxWM, the tiny window manager based on NX and NxWidgets. NxWM is true
multiple window manager but only one window is displayed at a time.
This simplification helps performance on LCD based products (in the
same way that a tiled window manager helps) and also makes the best
use of small displays. It is awkward from a human factors point-of-view
trying to manage multiple windows on a small display.
The window manager consists of a task bar with icons representing the
running tasks. If you touch the task's icon, it comes to the top. Each
window has a toolbar with (1) a title, (2) a minimize button, and (3) a
stop application button using the standard icons for these things. User
input via a touchscreen or mouse and keyboard is supported.
There is always a start window that is available in the task bar. When
you touch the start window icon, it brings up the start window containing
icons representing all of the available applications. If you touch an
icon in the start window, it will be started and added to the task bar.
There is a base class that defines an add-on application and an
interface that supports incorporation of new application. The only
application that is provided is NxConsole. This is an NSH session
running in a window. You should be able to select the NX icon in the start
menu and create as many NSH sessions in windows as you want. (keybard input
still comes through serial).
This initial realease of NxWM should be considered an alpha release.
All know issues are listed in the top-level TODO list.
Other important new features include:
* NxWidgets::IBitmap and NxWidgets::CRlePalettBitmap: Extended to
support different color look-up-tables (LUTs). This allows images
to be highlighted when touched, for example.
* NxWidgets::CImage: Extended to support button-like behavior. CImage
widgets now work well as touchable icons.
* NxWidgets::CWidgetControl: Add a semaphore to force clients to wait if the
size or position of the window is not yet known (multi-user mode only).
Enabled and verified creation of framed windows.
* NxWidgets::CWindowEventHandler and NxWidgets::CWindowEventHandler: Add
support for getting callbacks for window events.
* DOxygen documentation support. Contributed by Jose Pablo Carballo.
An effort is underway to simplify NxWidgets and reduce its memory footprint:
* NxWidgets::CNxWidget: Removed support for "shelving" widgets, reference
constants, and close types. Remove all support for widgets in a "vertical"
hierarchy. Now widgets exist in a flat, two-dimensional space and should
not overlap. Removed built-in modal loops.
Bug fixes include changes to the following (see the ChangeLog for details):
* NxWidgets::CRlePalettBitmap, NxWidgets::CRlePalettBitmap,
NxWidgets::CGraphicsPort, NxWidgets::CWidgetControl
NxWidgets-1.2
=============
The 3rd release of the NxWidgets package as made on June 15, 2012. This
release depends on NuttX-6.19 or above and should not be used with older
NuttX releases.
New features and enhancements include:
* NxWM::CNxConsole: The NxWM NxConsole windows now correctly receive keyboard
input. In version 1.1, NxConsoles received input from /dev/console. That,
of course, leads to chaos when there a multiple windows trying to get input
from the same device. There is now a keyboard listener task that will
accept input from /dev/console and inject that input into the NX keyboard
interface. NX will give the keyboard input only to the top window that
has focus, eliminating the chaos.
* NxWM::CHexcalculator: The NxWM demonstration/unit test now includes a hex
calculator applications. This demonstrates the use of arrays of buttons
within a window.
Bugfixes:
* NxWM::CTaskbar: Was inappropriately minimizing some windows. Fixes
some window raising/lowering bugs.
* NXWidgets::CButtonArray: Fix some coloring problems when rending button
text in cases where we cannot read from the display device.
As well as other, less critical bugs (see the ChangeLog for details)
+158
View File
@@ -0,0 +1,158 @@
NxWidgets
---------
NxWM
----
(4) General Issues
(3) NxConsole Issues
(1) CHexCalculator Issues
(1) Platform specific Issues
See also the NuttX TODO list graphics/ section for related issues.
o General NxWM Issues
-------------------
Title: DISPLAY INTIALIZATION
Description: During the initialization of the display, the basic frame of the
start window is draw momentarily. The is just the empty window
frame. This is a consequence of how NX creates windows: The
are enabled all of the time so the windows are visible when they
are being created. The solution would be to add some disable
logic in NX so that that nothing gets displayed when a window
is created until it is fully initialized and enable.
Status: Open
Priority: Medium
Title: DRAGGING ACROSS WINDOWS
Description: Need some indication if the touch/mouse drags from one window to
another then is release. Release event is lost in this case.
Status: Open
Priority: Low. ICON just stays selected and must be touched again.
Title: AUTO-RAISE DISABLED
Description: Auto-raise is currently disabled in nuttx for NX multi-server
mode. The
reason is complex:
- Most touchscreen controls send touch data a high rates
- In multi-server mode, touch events get queued in a message
queue.
- The logic that receives the messages performs the auto-raise.
But it can do stupid things after the first auto-raise as
it opperates on the stale data in the message queue.
I am thinking that auto-raise ought to be removed from NuttX
and moved out into a graphics layer (like NxWM) that knows
more about the appropriate context to do the autoraise.
Status: Open
Priority: Medium low
Title: THREAD SAFETY
Description: I am not sure how thread-safe the NxWidgets are. There is
is very little mutli-thread in the widgets now. The "NX listener"
thread interacts to update mouse (and keyboard) data but all
of the heavy work is done on the "start window" thread. I think
everything is okay now, but it may be necessary in the future
to introduce some semaphore protection in theCWidgetControl methods
to make them thread safe.
Status: Open
Priority: Low
Title: COMBINE CTouchscreen AND CKeyboard THREADS
Description: Right now, two separate threads handle touchscreen and keyboard/
console input. Each just waits on read() and when toushcscreen
or keyboard input is received, it injects the data into NX.
These two threads should be combined into one thread that waits
on poll for read data from either device. Then when read data
becomes ready for either device, it could perform the read and
data inject from a single thread.
Status: Open
Priority: Low, this is not a product but a text example. If NxWM were
to be productized, this change should be done in order to reduce
stack memory consumption.
o NxConsole Issues
----------------
Title: MULTIPLE COPIES OF AN NxCONSOLE
Description: From the start window, you an create multiple copies of the
NxConsole. However, there is a problem in the current
implementation: Each NxConsole receives its input from the
serial console so, for example, it you enter text one character
will go to one NxConsole instance and the next character goes
to a different instance. That is correct behavior within the
current design, but not very usable. We need a mechanism to
assure that the top window is the one that receives all
eyboard input. NX already provides this capability with its
nx_kbdin interface(), but that is not currently used. At present,
NxConsoles get their input from /dev/console which is the serial
port. The necessary change is to create an NX input device for
/dev/console that will get its input from NX.
Status: Closed with was fixed with the check-in of 5/20/2012 (about
SVN version 4755). The fixed version is available in SVN but
won't be in a released version until NxWidgets-1.2 is released.
Priority: Medium high, basically prohibits the use of multiple NSH windows.
Title: CLOSING AN NxCONSOLE
Description: If you open multiple NxConsole applications, they all receive
serial input (as noted in the previous bug). However, if
you close one of the NxConsoles, then the others no longer
received input (or no long generate output -- that cannot be
distinguished).
Status: Closed with was fixed with the check-in of 5/20/2012 (about
SVN version 4755). The fixed version is available in SVN but
won't be in a released version until NxWidgets-1.2 is released.
Priority: Medium high, basically prohibits the use of multiple NSH windows.
Title: DOUBLE DISPLAY UPDATES
Description: When the NxConsole window is first opened, there are usually
double updates, i.e., the display forms twice.
Status: Open
Priorioty: Low, this would be necessary to fix to productize the windows.
o CHexCalculator Issues
---------------------
Title: NEW DATA ENTRY IS APPENDED TO PREVIOUS RESULT
Description: For example 1+2= and 3 is shown. But if you enter 4, then
34 is shown. You have to manually clear the calculator ("C")
before entering the next number.
Status: Open
Priority: Low, this is only a demo. This would, of course, have to be
fixed if you wanted a production quality calculator (but then
you would probably also want to add quite a few more features
as well).
o Platform specific Issues
------------------------
Title: MISSING TOUCH RELEASE
Description: Using the STM3240G-EVAL board with the STMPE11 touchscreen, you
will find that there are occasional missing indications of when
you release a icon. This is believed to be a data overrun in the
STPMPE11 data path. The STMPE11 generates data a very high
rate and it is believe that it sometimes misses the interrupt
that indicates that the touch is released. The symptom in NxWM
is that you touch an icon, it is highlighted but when you release
the touch nothing happens. The icon stays highlighted. Touching
the icon again usually works around this problem.
Status: Closed with was fixed with the check-in of 5/21/2012 (about
SVN version 4758). The was change made to NuttX, not NxWidgets.
The fixed version is available in SVN but won't be in a released
version until NuttX-6.198 is released.
Priorioty: Low, but really annoying.
Title: BUGS WHEN CANNOT READ FROM LCD
Description: There is a kludge in there to handle the case where we cannot
read the background data because the LCD does not support read
operations. You cannot read from the STM3240G-EVAL LCD right
now (it might be possible, but I have not figured out how yet).
In that case, we just use the default background color. However,
that doesn't work either for the case where the background color
changes when the widget is selected. Then the background color
in the font is wrong. There is a hack in in CButtonArrary that
fixed this problem, but the problem certainly exists in other
places as well and begs for a better solution.
Status: Open
Priority: Medium-Low
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/Unitests/CButton/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = cbutton_main.cxx cbuttontest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = cbutton
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

@@ -0,0 +1,155 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CButton/cbutton_main.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <unistd.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "cbuttontest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static const char g_pushme[] = "Push Me";
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int cbutton_main(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int cbutton_main(int argc, char *argv[])
{
// Create an instance of the font test
printf("cbutton_main: Create CButtonTest instance\n");
CButtonTest *test = new CButtonTest();
// Connect the NX server
printf("cbutton_main: Connect the CButtonTest instance to the NX server\n");
if (!test->connect())
{
printf("cbutton_main: Failed to connect the CButtonTest instance to the NX server\n");
delete test;
return 1;
}
// Create a window to draw into
printf("cbutton_main: Create a Window\n");
if (!test->createWindow())
{
printf("cbutton_main: Failed to create a window\n");
delete test;
return 1;
}
// Create a CButton instance
CButton *button = test->createButton(g_pushme);
if (!button)
{
printf("cbutton_main: Failed to create a button\n");
delete test;
return 1;
}
// Show the button
printf("cbutton_main: Show the button\n");
test->showButton(button);
// Wait two seconds, then perform a simulated mouse click on the button
sleep(2);
printf("cbutton_main: Click the button\n");
test->click();
// Poll for the mouse click event (of course this can hang if something fails)
bool clicked = test->poll(button);
printf("cbutton_main: Button is %s\n", clicked ? "clicked" : "released");
// Wait a second, then release the mouse buttone
sleep(1);
test->release();
// Poll for the mouse release event (of course this can hang if something fails)
clicked = test->poll(button);
printf("cbutton_main: Button is %s\n", clicked ? "clicked" : "released");
// Wait a few more seconds so that the tester can ponder the result
sleep(3);
// Clean up and exit
printf("cbutton_main: Clean-up and exit\n");
delete button;
delete test;
return 0;
}
+325
View File
@@ -0,0 +1,325 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CButton/cbuttontest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "cbuttontest.hxx"
#include "cbgwindow.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CButtonTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CButtonTest Constructor
CButtonTest::CButtonTest()
{
m_bgWindow = (CBgWindow *)NULL;
m_nxFont = (CNxFont *)NULL;
m_text = (CNxString *)NULL;
}
// CButtonTest Descriptor
CButtonTest::~CButtonTest()
{
disconnect();
}
// Connect to the NX server
bool CButtonTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Create the default font instance
m_nxFont = new CNxFont(NXFONT_DEFAULT,
CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR,
CONFIG_NXWIDGETS_TRANSPARENT_COLOR);
if (!m_nxFont)
{
printf("CButtonTest::connect: Failed to create the default font\n");
}
// Set the background color
if (!setBackgroundColor(CONFIG_CBUTTONTEST_BGCOLOR))
{
printf("CButtonTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CButtonTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// Free the display string
if (m_text)
{
delete m_text;
m_text = (CNxString *)NULL;
}
// Free the default font
if (m_nxFont)
{
delete m_nxFont;
m_nxFont = (CNxFont *)NULL;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CButtonTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
printf("CButtonTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
printf("CButtonTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CButton instance
CButton *CButtonTest::createButton(FAR const char *text)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CButtonTest::createGraphics: Failed to get window size\n");
return (CButton *)NULL;
}
// Create a CNxString instance to contain the C string
m_text = new CNxString(text);
// Get the height and width of the text display area
nxgl_coord_t stringWidth = m_nxFont->getStringWidth(*m_text);
nxgl_coord_t stringHeight = (nxgl_coord_t)m_nxFont->getHeight();
// The default CButton has borders enabled with thickness of the border
// width. Add twice the thickness of the borderto the width and height. (We
// could let CButton do this for us by calling CButton::getPreferredDimensions())
stringWidth += 2 * 1;
stringHeight += 2 * 1;
// Pick an X/Y position such that the button will be centered in the display
nxgl_coord_t buttonX;
if (stringWidth >= windowSize.w)
{
buttonX = 0;
}
else
{
buttonX = (windowSize.w - stringWidth) >> 1;
}
nxgl_coord_t buttonY;
if (stringHeight >= windowSize.h)
{
buttonY = 0;
}
else
{
buttonY = (windowSize.h - stringHeight) >> 1;
}
// Save the center position of the button for use by click and release
m_center.x = buttonX + (stringWidth >> 1);
m_center.y = buttonY + (stringHeight >> 1);
// Now we have enough information to create the button
return new CButton(m_widgetControl, buttonX, buttonY, stringWidth, stringHeight, *m_text);
}
// Draw the button
void CButtonTest::showButton(CButton *button)
{
button->enable(); // Un-necessary, the widget is enabled by default
button->enableDrawing();
button->redraw();
}
// Perform a simulated mouse click on the button. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void CButtonTest::click(void)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// Then inject the mouse click
(void)nx_mousein(handle, m_center.x, m_center.y, NX_MOUSE_LEFTBUTTON);
}
// The counterpart to click. This simulates a button release through
// the same mechanism.
void CButtonTest::release(void)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// Then inject the mouse click
(void)nx_mousein(handle, m_center.x, m_center.y, NX_MOUSE_NOBUTTONS);
}
// Widget events are normally handled in a modal loop.
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
bool CButtonTest::poll(CButton *button)
{
// Poll for mouse events
m_widgetControl->pollEvents(button);
// And return the button clicked state
return button->isClicked();
}
+157
View File
@@ -0,0 +1,157 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CButton/cbuttontest.hxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __UNITTESTS_CBUTTON_CBUTTONTEST_HXX
#define __UNITTESTS_CBUTTON_CBUTTONTEST_HXX
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <semaphore.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "nxconfig.hxx"
#include "cwidgetcontrol.hxx"
#include "ccallback.hxx"
#include "cbgwindow.hxx"
#include "cnxserver.hxx"
#include "cnxfont.hxx"
#include "cnxstring.hxx"
#include "cbutton.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CBUTTONTEST_BGCOLOR
# define CONFIG_CBUTTONTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR
#endif
#ifndef CONFIG_CBUTTONTEST_FONTCOLOR
# define CONFIG_CBUTTONTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CButtonTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CNxFont *m_nxFont; // Default font
CBgWindow *m_bgWindow; // Background window instance
CNxString *m_text; // The button string
struct nxgl_point_s m_center; // X, Y position the center of the button
public:
// Constructor/destructors
CButtonTest();
~CButtonTest();
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a CButton instance. This method will show you how to create
// a CButton widget
CButton *createButton(FAR const char *text);
// Draw the button. This method illustrates how to draw the CButton widget.
void showButton(CButton *button);
// Perform a simulated mouse click on the button. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void click(void);
// The counterpart to click. This simulates a button release through
// the same mechanism.
void release(void);
// Widget events are normally handled in a model loop (by calling goModel()).
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
bool poll(CButton *button);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CBUTTON_CBUTTONTEST_HXX
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CButtonArray/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = cbuttonarray_main.cxx cbuttonarraytest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = cbuttonarray
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

@@ -0,0 +1,327 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CButtonArray/cbuttonarray_main.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "cnxstring.hxx"
#include "cbuttonarraytest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static unsigned int g_mmInitial;
static unsigned int g_mmPrevious;
static unsigned int g_mmPeak;
static FAR const char *g_buttonLabels[BUTTONARRAY_NCOLUMNS*BUTTONARRAY_NROWS] = {
"=>", "A", "B", "<DEL",
"C", "D", "E", "F",
"G", "H", "I", "J",
"K", "L", "M", "N",
"O", "P", "Q", "R",
"S", "T", "U", "V",
"W", "X", "Y", "Z"
};
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int cbuttonarray_main(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("%s: Before: %8d After: %8d Change: %8d\n",
msg, previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmPrevious = mmcurrent.uordblks;
if ((unsigned int)mmcurrent.uordblks > g_mmPeak)
{
g_mmPeak = mmcurrent.uordblks;
}
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmPrevious = mmcurrent.uordblks;
g_mmPeak = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Name: checkHighlighting
/////////////////////////////////////////////////////////////////////////////
static void checkHighlighting(CButtonArray *buttonArray)
{
// Turn highlighting on
buttonArray->setCursorPosition(0, 0);
buttonArray->cursor(true);
// Then test the cursor movement
for (int row = 0; row < BUTTONARRAY_NROWS; row++)
{
for (int column = 0; column < BUTTONARRAY_NCOLUMNS; column++)
{
// Set cursor position
buttonArray->setCursorPosition(column, row);
// Check cursor position
int checkColumn;
int checkRow;
if (buttonArray->isCursorPosition(checkColumn, checkRow))
{
printf("ERROR: Not button selected\n");
printf(" Expected (%d,%d)\n", column, row);
}
else if (checkColumn != column || checkRow != row)
{
printf("ERROR: Wrong button selected\n");
printf(" Expected (%d,%d)\n", column, row);
printf(" Selected (%d,%d)\n", checkColumn, checkRow);
}
// Wait a bit so that we can see the highlighting
usleep(500*1000);
}
}
// Turn highlighting off
buttonArray->cursor(false);
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int cbuttonarray_main(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the button array test
printf("cbuttonarray_main: Create CButtonArrayTest instance\n");
CButtonArrayTest *test = new CButtonArrayTest();
updateMemoryUsage(g_mmPrevious, "After creating CButtonArrayTest");
// Connect the NX server
printf("cbuttonarray_main: Connect the CButtonArrayTest instance to the NX server\n");
if (!test->connect())
{
printf("cbuttonarray_main: Failed to connect the CButtonArrayTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmPrevious, "After connecting to the server");
// Create a window to draw into
printf("cbuttonarray_main: Create a Window\n");
if (!test->createWindow())
{
printf("cbuttonarray_main: Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmPrevious, "After creating a window");
// Create a CButtonArray instance
CButtonArray *buttonArray = test->createButtonArray();
if (!buttonArray)
{
printf("cbuttonarray_main: Failed to create a button array\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmPrevious, "After creating CButtonArray");
// Add the labels to each button
FAR const char **ptr = g_buttonLabels;
for (int j = 0; j < BUTTONARRAY_NROWS; j++)
{
for (int i = 0; i < BUTTONARRAY_NCOLUMNS; i++)
{
printf("cbuttonarray_main: Label (%d,%d): %s\n", i, j, *ptr);
CNxString string = *ptr++;
buttonArray->setText(i, j, string);
}
}
updateMemoryUsage(g_mmPrevious, "After adding labels to the buttons");
// Show the button array
printf("cbuttonarray_main: Show the button array\n");
test->showButton(buttonArray);
sleep(1);
// Verify that button highlighting works
checkHighlighting(buttonArray);
updateMemoryUsage(g_mmPrevious, "After highliting");
// Then perform a simulated mouse click on a button in the array
for (int j = 0; j < BUTTONARRAY_NROWS; j++)
{
for (int i = 0; i < BUTTONARRAY_NCOLUMNS; i++)
{
printf("cbuttonarray_main: Click the button (%d,%d)\n", i, j);
test->click(buttonArray, i, j);
// Poll for the mouse click event
test->poll(buttonArray);
// Is anything clicked?
int clickColumn;
int clickRow;
if (buttonArray->isButtonClicked(clickColumn, clickRow))
{
printf("cbuttonarray_main: %s: Button (%d, %d) is clicked\n",
clickColumn == i && clickRow == j ? "OK" : "ERROR",
clickColumn, clickRow);
}
else
{
printf("cbuttonarray_main: ERROR: No button is clicked\n");
}
// Wait a bit, then release the mouse button
usleep(500*1000);
test->release(buttonArray, i, j);
// Poll for the mouse release event (of course this can hang if something fails)
test->poll(buttonArray);
if (buttonArray->isButtonClicked(clickColumn, clickRow))
{
printf("cbuttonarray_main: ERROR: Button (%d, %d) is clicked\n",
clickColumn, clickRow);
}
usleep(500*1000);
}
}
updateMemoryUsage(g_mmPrevious, "After pushing buttons");
// Clean up and exit
printf("cbuttonarray_main: Clean-up and exit\n");
delete buttonArray;
updateMemoryUsage(g_mmPrevious, "After deleting the button array");
delete test;
updateMemoryUsage(g_mmPrevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
message("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial);
return 0;
}
@@ -0,0 +1,301 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CButtonArray/cbuttonarraytest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "cbuttonarraytest.hxx"
#include "cbgwindow.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CButtonArrayTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CButtonArrayTest Constructor
CButtonArrayTest::CButtonArrayTest()
{
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CButtonArrayTest Descriptor
CButtonArrayTest::~CButtonArrayTest()
{
disconnect();
}
// Connect to the NX server
bool CButtonArrayTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CBUTTONARRAYTEST_BGCOLOR))
{
message("CButtonArrayTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CButtonArrayTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// Destroy the widget control
if (m_widgetControl)
{
delete m_widgetControl;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CButtonArrayTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CButtonArrayTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CButtonArrayTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CButtonArray instance
CButtonArray *CButtonArrayTest::createButtonArray(void)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
message("CButtonArrayTest::createGraphics: Failed to get window size\n");
return (CButtonArray *)NULL;
}
// Pick an X/Y position such that the button array will be centered in the display
nxgl_coord_t buttonArrayX;
if (BUTTONARRAY_WIDTH >= windowSize.w)
{
buttonArrayX = 0;
}
else
{
buttonArrayX = (windowSize.w - BUTTONARRAY_WIDTH) >> 1;
}
nxgl_coord_t buttonArrayY;
if (BUTTONARRAY_HEIGHT >= windowSize.h)
{
buttonArrayY = 0;
}
else
{
buttonArrayY = (windowSize.h - BUTTONARRAY_HEIGHT) >> 1;
}
// Now we have enough information to create the button array
return new CButtonArray(m_widgetControl,
buttonArrayX, buttonArrayY,
BUTTONARRAY_NCOLUMNS, BUTTONARRAY_NROWS,
BUTTONARRAY_BUTTONWIDTH, BUTTONARRAY_BUTTONHEIGHT);
}
// Draw the button array
void CButtonArrayTest::showButton(CButtonArray *buttonArray)
{
buttonArray->enable(); // Un-necessary, the widget is enabled by default
buttonArray->enableDrawing();
buttonArray->redraw();
}
// Perform a simulated mouse click on a button in the array. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void CButtonArrayTest::click(CButtonArray *buttonArray, int column, int row)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the selected button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// The the coorinates of the center of the button
nxgl_coord_t buttonX = buttonArray->getX() +
column * BUTTONARRAY_BUTTONWIDTH +
BUTTONARRAY_BUTTONWIDTH/2;
nxgl_coord_t buttonY = buttonArray->getY() +
row * BUTTONARRAY_BUTTONHEIGHT +
BUTTONARRAY_BUTTONHEIGHT/2;
// Then inject the mouse click
(void)nx_mousein(handle, buttonX, buttonY, NX_MOUSE_LEFTBUTTON);
}
// The counterpart to click. This simulates a button release through
// the same mechanism.
void CButtonArrayTest::release(CButtonArray *buttonArray, int column, int row)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// The the coorinates of the center of the button
nxgl_coord_t buttonX = buttonArray->getX() +
column * BUTTONARRAY_BUTTONWIDTH +
BUTTONARRAY_BUTTONWIDTH/2;
nxgl_coord_t buttonY = buttonArray->getY() +
row * BUTTONARRAY_BUTTONHEIGHT +
BUTTONARRAY_BUTTONHEIGHT/2;
// Then inject the mouse release
(void)nx_mousein(handle, buttonX, buttonY, NX_MOUSE_NOBUTTONS);
}
// Widget events are normally handled in a modal loop.
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
void CButtonArrayTest::poll(CButtonArray *button)
{
// Poll for mouse events
m_widgetControl->pollEvents(button);
}
@@ -0,0 +1,172 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CButtonArray/cbuttonarraytest.hxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __UNITTESTS_CBUTTONARRAY_CBUTTONARRAYTEST_HXX
#define __UNITTESTS_CBUTTONARRAY_CBUTTONARRAYTEST_HXX
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <semaphore.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "nxconfig.hxx"
#include "cwidgetcontrol.hxx"
#include "ccallback.hxx"
#include "cbgwindow.hxx"
#include "cnxserver.hxx"
#include "cnxfont.hxx"
#include "cnxstring.hxx"
#include "cbuttonarray.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CBUTTONARRAYTEST_BGCOLOR
# define CONFIG_CBUTTONARRAYTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR
#endif
#ifndef CONFIG_CBUTTONARRAYTEST_FONTCOLOR
# define CONFIG_CBUTTONARRAYTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
// The geometry of the button array
#define BUTTONARRAY_NCOLUMNS 4
#define BUTTONARRAY_NROWS 7
#define BUTTONARRAY_BUTTONWIDTH 60
#define BUTTONARRAY_BUTTONHEIGHT 32
#define BUTTONARRAY_WIDTH (BUTTONARRAY_BUTTONWIDTH * BUTTONARRAY_NCOLUMNS)
#define BUTTONARRAY_HEIGHT (BUTTONARRAY_BUTTONHEIGHT * BUTTONARRAY_NROWS)
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CButtonArrayTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The widget control for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CButtonArrayTest();
~CButtonArrayTest();
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a CButtonArray instance. This method will show you how to create
// a CButtonArray widget
CButtonArray *createButtonArray(void);
// Draw the button array. This method illustrates how to draw the CButtonArray widget.
void showButton(CButtonArray *buttonArray);
// Perform a simulated mouse click on a button in the array. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void click(CButtonArray *buttonArray, int column, int row);
// The counterpart to click. This simulates a button release through
// the same mechanism.
void release(CButtonArray *buttonArray, int column, int row);
// Widget events are normally handled in a model loop (by calling goModel()).
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
void poll(CButtonArray *buttonArray);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CBUTTONARRAY_CBUTTONARRAYTEST_HXX
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CCheckBox/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = ccheckbox_main.cxx ccheckboxtest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = ccheckbox
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

@@ -0,0 +1,209 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CCheckBox/ccheckbox_main.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "crlepalettebitmap.hxx"
#include "glyphs.hxx"
#include "ccheckboxtest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static unsigned int g_mmInitial;
static unsigned int g_mmprevious;
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int ccheckbox_main(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("\n%s:\n", msg);
message(" Before: %8d After: %8d Change: %8d\n\n",
previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int ccheckbox_main(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the checkbox test
message("ccheckbox_main: Create CCheckBoxTest instance\n");
CCheckBoxTest *test = new CCheckBoxTest();
updateMemoryUsage(g_mmprevious, "After creating CCheckBoxTest");
// Connect the NX server
message("ccheckbox_main: Connect the CCheckBoxTest instance to the NX server\n");
if (!test->connect())
{
message("ccheckbox_main: Failed to connect the CCheckBoxTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "ccheckbox_main: After connecting to the server");
// Create a window to draw into
message("ccheckbox_main: Create a Window\n");
if (!test->createWindow())
{
message("ccheckbox_main: Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "ccheckbox_main: After creating a window");
// Show the initial state of the checkbox
test->showCheckBox();
test->showCheckBoxState();
sleep(1);
// Now click the checkbox
message("ccheckbox_main: Click 1\n");
test->clickCheckBox();
usleep(500*1000);
test->showCheckBoxState();
updateMemoryUsage(g_mmprevious, "After click 1");
usleep(500*1000);
message("ccheckbox_main: Click 2\n");
test->clickCheckBox();
usleep(500*1000);
test->showCheckBoxState();
updateMemoryUsage(g_mmprevious, "After click 2");
usleep(500*1000);
message("ccheckbox_main: Click 3\n");
test->clickCheckBox();
usleep(500*1000);
test->showCheckBoxState();
updateMemoryUsage(g_mmprevious, "After click 3");
sleep(2);
// Clean up and exit
message("ccheckbox_main: Clean-up and exit\n");
delete test;
updateMemoryUsage(g_mmprevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
return 0;
}
@@ -0,0 +1,297 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CCheckBox/ccheckboxtest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "cbgwindow.hxx"
#include "ccheckboxtest.hxx"
#include "cbitmap.hxx"
#include "glyphs.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CCheckBoxTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CCheckBoxTest Constructor
CCheckBoxTest::CCheckBoxTest()
{
// Initialize state data
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
m_checkBox = (CCheckBox *)NULL;
}
// CCheckBoxTest Descriptor
CCheckBoxTest::~CCheckBoxTest(void)
{
disconnect();
}
// Connect to the NX server
bool CCheckBoxTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CCHECKBOXTEST_BGCOLOR))
{
message("CCheckBoxTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CCheckBoxTest::disconnect(void)
{
// Free the radiobutton group
if (m_checkBox)
{
delete m_checkBox;
m_checkBox = (CCheckBox *)NULL;
}
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
m_bgWindow = (CBgWindow *)NULL;
}
// Free the widget control instance
if (m_widgetControl)
{
delete m_widgetControl;
m_widgetControl = (CWidgetControl *)NULL;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CCheckBoxTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CCheckBoxTest::createWindow: Failed to create CBgWindow instance\n");
disconnect();
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CCheckBoxTest::createWindow: Failed to open background window\n");
disconnect();
return false;
}
// Get the size of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CCheckBoxTest::createWindow: Failed to get window size\n");
disconnect();
return false;
}
// Use the the size of the ON checkbox glyph. (adding twice the border thickness)
nxgl_coord_t width = g_checkBoxOn.width + 2 * 1;
nxgl_coord_t height = g_checkBoxOn.height + 2 * 1;
nxgl_coord_t checkboxX = (windowSize.w - width) >> 1;
nxgl_coord_t checkboxY = (windowSize.h - height) >> 1;
// Create the checkbox
m_checkBox = new CCheckBox(m_widgetControl, checkboxX, checkboxY,
width, height, (CWidgetStyle *)NULL);
if (!m_checkBox)
{
printf("CCheckBoxTest::createWindow: Failed to create CCheckBox\n");
disconnect();
return false;
}
return true;
}
// (Re-)draw the check box.
void CCheckBoxTest::showCheckBox(void)
{
m_checkBox->enable(); // Un-necessary, the widget is enabled by default
m_checkBox->enableDrawing();
m_checkBox->redraw();
}
// Push the radio button
void CCheckBoxTest::clickCheckBox(void)
{
// Get the checkbox center coordinates
nxgl_coord_t checkboxX = m_checkBox->getX() + (m_checkBox->getWidth() >> 1);
nxgl_coord_t checkboxY = m_checkBox->getY() + (m_checkBox->getHeight() >> 1);
// Click the checkbox by calling nx_mousein. nx_mousein is meant to be
// called by mouse handling software. Here we just inject a left-button click
// directly in the center of the radio button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// Then inject the mouse click
(void)nx_mousein(handle, checkboxX, checkboxY, NX_MOUSE_LEFTBUTTON);
// Poll for mouse events
//
// Widget events are normally handled in a modal loop.
// However, for this case we know that we just pressed the mouse button
// so we don't have to poll. We can just perform a one pass poll then
// then check if the mouse event was processed corredly.
m_widgetControl->pollEvents(m_checkBox);
// Then inject the mouse release
(void)nx_mousein(handle, checkboxX, checkboxY, 0);
// And poll for more mouse events
m_widgetControl->pollEvents(m_checkBox);
// And re-draw the buttons (the mouse click event should have automatically
// triggered the re-draw)
//
// showCheckBox();
}
// Show the state of the radio button group
void CCheckBoxTest::showCheckBoxState(void)
{
CCheckBox::CheckBoxState state = m_checkBox->getState();
switch (state)
{
case CCheckBox::CHECK_BOX_STATE_OFF: // Checkbox is unticked
message("CCheckBoxTest::showCheckBoxState Checkbox is in the unticked state\n");
break;
case CCheckBox::CHECK_BOX_STATE_ON: // Checkbox is ticked
message("CCheckBoxTest::showCheckBoxState Check is in the ticked state\n");
break;
default:
case CCheckBox::CHECK_BOX_STATE_MU: // Checkbox is in the third state
message("CCheckBoxTest::showCheckBoxState Checkbox is in the 3rd state\n");
break;
}
}
@@ -0,0 +1,142 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CCheckBox/ccheckboxtest.hxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __UNITTESTS_CCHECKBOX_CCHECKBOXTEST_HXX
#define __UNITTESTS_CCHECKBOX_CCHECKBOXTEST_HXX
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <semaphore.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "nxconfig.hxx"
#include "cwidgetcontrol.hxx"
#include "ccallback.hxx"
#include "cbgwindow.hxx"
#include "cnxserver.hxx"
#include "ccheckbox.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CCHECKBOXTEST_BGCOLOR
# define CONFIG_CCHECKBOXTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CCheckBoxTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
CCheckBox *m_checkBox; // Checkgox instance under test
public:
// Constructor/destructors
CCheckBoxTest(void);
~CCheckBoxTest(void);
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// (Re-)draw the checkbox.
void showCheckBox(void);
// Simulate pushing and releasing of the radio button
void clickCheckBox(void);
// Show the state of the radio button group
void showCheckBoxState(void);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CCHECKBOX_CCHECKBOXTEST_HXX
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CGlyphButton/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = cglyphbutton_main.cxx cglyphbuttontest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = cglyphbutton
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,225 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CGlyphButton/cglyphbutton_main.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "cglyphbuttontest.hxx"
#include "glyphs.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static unsigned int g_mmInitial;
static unsigned int g_mmprevious;
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int cglyphbutton_main(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("\n%s:\n", msg);
message(" Before: %8d After: %8d Change: %8d\n\n",
previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int cglyphbutton_main(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the font test
message("cglyphbutton_main: Create CGlyphButtonTest instance\n");
CGlyphButtonTest *test = new CGlyphButtonTest();
updateMemoryUsage(g_mmprevious, "After creating CGlyphButtonTest");
// Connect the NX server
message("cglyphbutton_main: Connect the CGlyphButtonTest instance to the NX server\n");
if (!test->connect())
{
message("cglyphbutton_main: Failed to connect the CGlyphButtonTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "After connecting to the server");
// Create a window to draw into
message("cglyphbutton_main: Create a Window\n");
if (!test->createWindow())
{
message("cglyphbutton_main: Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "After creating a window");
// Create a CGlyphButton instance
CGlyphButton *button = test->createButton(&g_arrowDown, &g_arrowUp);
if (!button)
{
message("cglyphbutton_main: Failed to create a button\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "After creating the glyph button");
// Show the button
message("cglyphbutton_main: Show the button\n");
test->showButton(button);
updateMemoryUsage(g_mmprevious, "After showing the glyph button");
// Wait two seconds, then perform a simulated mouse click on the button
sleep(2);
message("cglyphbutton_main: Click the button\n");
test->click();
updateMemoryUsage(g_mmprevious, "After clicking glyph button");
// Poll for the mouse click event (of course this can hang if something fails)
bool clicked = test->poll(button);
message("cglyphbutton_main: Button is %s\n", clicked ? "clicked" : "released");
// Wait a second, then release the mouse buttone
sleep(1);
test->release();
updateMemoryUsage(g_mmprevious, "After releasing glyph button");
// Poll for the mouse release event (of course this can hang if something fails)
clicked = test->poll(button);
message("cglyphbutton_main: Button is %s\n", clicked ? "clicked" : "released");
// Wait a few more seconds so that the tester can ponder the result
sleep(3);
// Clean up and exit
message("cglyphbutton_main: Clean-up and exit\n");
delete button;
updateMemoryUsage(g_mmprevious, "After deleting the glyph button");
delete test;
updateMemoryUsage(g_mmprevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
return 0;
}
@@ -0,0 +1,307 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CGlyphButton/cglyphbuttontest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "cglyphbuttontest.hxx"
#include "cbgwindow.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CGlyphButtonTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CGlyphButtonTest Constructor
CGlyphButtonTest::CGlyphButtonTest()
{
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
m_center.x = 0;
m_center.y = 0;
}
// CGlyphButtonTest Descriptor
CGlyphButtonTest::~CGlyphButtonTest()
{
disconnect();
}
// Connect to the NX server
bool CGlyphButtonTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CGLYPHBUTTONTEST_BGCOLOR))
{
message("CGlyphButtonTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CGlyphButtonTest::disconnect(void)
{
// Delete the widget control instance
if (m_widgetControl)
{
delete m_widgetControl;
}
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CGlyphButtonTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CGlyphButtonTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CGlyphButtonTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CGlyphButton instance
CGlyphButton *CGlyphButtonTest::createButton(FAR const struct SBitmap *clickGlyph,
FAR const struct SBitmap *unClickedGlyph)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
message("CGlyphButtonTest::createGraphics: Failed to get window size\n");
return (CGlyphButton *)NULL;
}
// Get the height and width of the glyph display area
nxgl_coord_t glyphWidth = MAX(clickGlyph->width, unClickedGlyph->width);
nxgl_coord_t glyphHeight = MAX(clickGlyph->height, unClickedGlyph->height);
// The default CGlyphButton has borders enabled with thickness of the border
// width. Add twice the thickness of the border to the width and height. (We
// could let CGlyphButton do this for us by calling
// CGlyphButton::getPreferredDimensions())
glyphWidth += 2 * 1;
glyphHeight += 2 * 1;
// Pick an X/Y position such that the button will be centered in the display
nxgl_coord_t buttonX;
if (glyphWidth >= windowSize.w)
{
buttonX = 0;
}
else
{
buttonX = (windowSize.w - glyphWidth) >> 1;
}
nxgl_coord_t buttonY;
if (glyphHeight >= windowSize.h)
{
buttonY = 0;
}
else
{
buttonY = (windowSize.h - glyphHeight) >> 1;
}
// Save the center position of the button for use by click and release
m_center.x = buttonX + (glyphWidth >> 1);
m_center.y = buttonY + (glyphHeight >> 1);
// Now we have enough information to create the button
return new CGlyphButton(m_widgetControl, buttonX, buttonY,
glyphWidth, glyphHeight,
unClickedGlyph, clickGlyph);
}
// Draw the button
void CGlyphButtonTest::showButton(CGlyphButton *button)
{
button->enable(); // Un-necessary, the widget is enabled by default
button->enableDrawing();
button->redraw();
}
// Perform a simulated mouse click on the button. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void CGlyphButtonTest::click(void)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// Then inject the mouse click
(void)nx_mousein(handle, m_center.x, m_center.y, NX_MOUSE_LEFTBUTTON);
}
// The counterpart to click. This simulates a button release through
// the same mechanism.
void CGlyphButtonTest::release(void)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// Then inject the mouse click
(void)nx_mousein(handle, m_center.x, m_center.y, NX_MOUSE_NOBUTTONS);
}
// Widget events are normally handled in a modal loop.
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
bool CGlyphButtonTest::poll(CGlyphButton *button)
{
// Poll for mouse events
m_widgetControl->pollEvents(button);
// And return the button clicked state
return button->isClicked();
}
@@ -0,0 +1,172 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CGlyphButton/cglyphbuttontest.hxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __UNITTESTS_CGLYPHBUTTON_CGLYPHBUTTONTEST_HXX
#define __UNITTESTS_CGLYPHBUTTON_CGLYPHBUTTONTEST_HXX
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <semaphore.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "nxconfig.hxx"
#include "cwidgetcontrol.hxx"
#include "ccallback.hxx"
#include "cbgwindow.hxx"
#include "cnxserver.hxx"
#include "cnxfont.hxx"
#include "cnxstring.hxx"
#include "cglyphbutton.hxx"
#include "cbitmap.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CGLYPHBUTTONTEST_BGCOLOR
# define CONFIG_CGLYPHBUTTONTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR
#endif
#ifndef CONFIG_CGLYPHBUTTONTEST_FONTCOLOR
# define CONFIG_CGLYPHBUTTONTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
// Helper macros
#ifndef MAX
# define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CGlyphButtonTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
struct nxgl_point_s m_center; // X, Y position the center of the button
public:
// Constructor/destructors
CGlyphButtonTest();
~CGlyphButtonTest();
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a CGlyphButton instance. This method will show you how to create
// a CGlyphButton widget
CGlyphButton *createButton(FAR const struct SBitmap *clickGlyph,
FAR const struct SBitmap *unClickedGlyph);
// Draw the button. This method illustrates how to draw the CGlyphButton widget.
void showButton(CGlyphButton *button);
// Perform a simulated mouse click on the button. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void click(void);
// The counterpart to click. This simulates a button release through
// the same mechanism.
void release(void);
// Widget events are normally handled in a model loop (by calling goModel()).
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
bool poll(CGlyphButton *button);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CGLYPHBUTTON_CGLYPHBUTTONTEST_HXX
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CImage/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = cimage_main.cxx cimagetest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = cimage
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+222
View File
@@ -0,0 +1,222 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CImage/cimage_main.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "crlepalettebitmap.hxx"
#include "glyphs.hxx"
#include "cimagetest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static struct mallinfo g_mmInitial;
static struct mallinfo g_mmprevious;
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int cimage_main(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: showMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void showMemoryUsage(FAR struct mallinfo *mmbefore,
FAR struct mallinfo *mmafter)
{
message("VARIABLE BEFORE AFTER\n");
message("======== ======== ========\n");
message("arena %8d %8d\n", mmbefore->arena, mmafter->arena);
message("ordblks %8d %8d\n", mmbefore->ordblks, mmafter->ordblks);
message("mxordblk %8d %8d\n", mmbefore->mxordblk, mmafter->mxordblk);
message("uordblks %8d %8d\n", mmbefore->uordblks, mmafter->uordblks);
message("fordblks %8d %8d\n", mmbefore->fordblks, mmafter->fordblks);
}
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(FAR struct mallinfo *previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("\n%s:\n", msg);
showMemoryUsage(previous, &mmcurrent);
/* Set up for the next test */
#ifdef CONFIG_CAN_PASS_STRUCTS
g_mmprevious = mmcurrent;
#else
memcpy(&g_mmprevious, &mmcurrent, sizeof(struct mallinfo));
#endif
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
#ifdef CONFIG_CAN_PASS_STRUCTS
g_mmInitial = mallinfo();
g_mmprevious = g_mmInitial;
#else
(void)mallinfo(&g_mmInitial);
memcpy(&g_mmprevious, &g_mmInitial, sizeof(struct mallinfo));
#endif
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int cimage_main(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the font test
message("cimage_main: Create CImageTest instance\n");
CImageTest *test = new CImageTest();
updateMemoryUsage(&g_mmprevious, "After creating CImageTest");
// Connect the NX server
message("cimage_main: Connect the CImageTest instance to the NX server\n");
if (!test->connect())
{
message("cimage_main: Failed to connect the CImageTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(&g_mmprevious, "After connecting to the server");
// Create a window to draw into
message("cimage_main: Create a Window\n");
if (!test->createWindow())
{
message("cimage_main: Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(&g_mmprevious, "After creating a window");
// Create an instance of the NuttX logo
CRlePaletteBitmap *nuttxBitmap = new CRlePaletteBitmap(&g_nuttxBitmap);
updateMemoryUsage(&g_mmprevious, "After creating the bitmap");
// Create a CImage instance
CImage *image = test->createImage(static_cast<IBitmap*>(nuttxBitmap));
if (!image)
{
message("cimage_main: Failed to create a image\n");
delete test;
return 1;
}
updateMemoryUsage(&g_mmprevious, "After creating CImage");
// Show the image
test->showImage(image);
updateMemoryUsage(&g_mmprevious, "After showing the image");
sleep(5);
// Clean up and exit
message("cimage_main: Clean-up and exit\n");
delete image;
updateMemoryUsage(&g_mmprevious, "After deleting CImage");
delete nuttxBitmap;
updateMemoryUsage(&g_mmprevious, "After deleting the bitmap");
delete test;
updateMemoryUsage(&g_mmprevious, "After deleting the test");
updateMemoryUsage(&g_mmInitial, "Final memory usage");
return 0;
}
+240
View File
@@ -0,0 +1,240 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CImage/cimagetest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "ibitmap.hxx"
#include "cbgwindow.hxx"
#include "cimagetest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CImageTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CImageTest Constructor
CImageTest::CImageTest()
{
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CImageTest Descriptor
CImageTest::~CImageTest()
{
disconnect();
}
// Connect to the NX server
bool CImageTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CIMAGETEST_BGCOLOR))
{
message("CImageTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CImageTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// Free the widget control instance
if (m_widgetControl)
{
delete m_widgetControl;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CImageTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CImageTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CImageTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CImage instance
CImage *CImageTest::createImage(IBitmap *bitmap)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
message("CImageTest::createGraphics: Failed to get window size\n");
return (CImage *)NULL;
}
// Get the height and width of the image
nxgl_coord_t imageWidth = bitmap->getWidth();
nxgl_coord_t imageHeight = (nxgl_coord_t)bitmap->getHeight();
// The default CImage has borders enabled with thickness of the border
// width. Add twice the thickness of the border to the width and height. (We
// could let CImage do this for us by calling CImage::getPreferredDimensions())
imageWidth += 2 * 1;
imageHeight += 2 * 1;
// Pick an X/Y position such that the image will be centered in the display
nxgl_coord_t imageX;
if (imageWidth >= windowSize.w)
{
imageX = 0;
}
else
{
imageX = (windowSize.w - imageWidth) >> 1;
}
nxgl_coord_t imageY;
if (imageHeight >= windowSize.h)
{
imageY = 0;
}
else
{
imageY = (windowSize.h - imageHeight) >> 1;
}
// Now we have enough information to create the image
return new CImage(m_widgetControl, imageX, imageY, imageWidth, imageHeight, bitmap);
}
// Draw the image
void CImageTest::showImage(CImage *image)
{
image->enable();
image->enableDrawing();
image->redraw();
image->disableDrawing();
}
+140
View File
@@ -0,0 +1,140 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CImage/cimagetest.hxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __UNITTESTS_CIMAGE_CIMAGETEST_HXX
#define __UNITTESTS_CIMAGE_CIMAGETEST_HXX
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <semaphore.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "nxconfig.hxx"
#include "cwidgetcontrol.hxx"
#include "ccallback.hxx"
#include "cbgwindow.hxx"
#include "cnxserver.hxx"
#include "cnxfont.hxx"
#include "cnxstring.hxx"
#include "cimage.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CIMAGETEST_BGCOLOR
# define CONFIG_CIMAGETEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CImageTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CImageTest(void);
~CImageTest(void);
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a CImage instance. This method will show you how to create
// a CImage widget
CImage *createImage(IBitmap *bitmap);
// Draw the image. This method illustrates how to draw the CImage widget.
void showImage(CImage *image);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CIMAGE_CIMAGETEST_HXX
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CKeyPad/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = ckeypad_main.cxx ckeypadtest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = ckeypad
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,274 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CKeypad/ckeypad_main.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "cnxstring.hxx"
#include "ckeypadtest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static unsigned int g_mmInitial;
static unsigned int g_mmPrevious;
static unsigned int g_mmPeak;
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int ckeypad_main(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("%s: Before: %8d After: %8d Change: %8d\n",
msg, previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmPrevious = mmcurrent.uordblks;
if ((unsigned int)mmcurrent.uordblks > g_mmPeak)
{
g_mmPeak = mmcurrent.uordblks;
}
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmPrevious = mmcurrent.uordblks;
g_mmPeak = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Name: clickButtons
/////////////////////////////////////////////////////////////////////////////
static void clickButtons(CKeypadTest *test, CKeypad *keypad)
{
// Perform a simulated mouse click on a button in the keypad
for (int j = 0; j < KEYPAD_NROWS; j++)
{
for (int i = 0; i < KEYPAD_NCOLUMNS; i++)
{
printf("clickButtons: Click the button (%d,%d)\n", i, j);
test->click(keypad, i, j);
// Poll for the mouse click event
test->poll(keypad);
// Is anything clicked?
int clickColumn;
int clickRow;
if (keypad->isButtonClicked(clickColumn, clickRow))
{
printf("clickButtons: %s: Button (%d, %d) is clicked\n",
clickColumn == i && clickRow == j ? "OK" : "ERROR",
clickColumn, clickRow);
}
else
{
printf("clickButtons: ERROR: No button is clicked\n");
}
// Wait a bit, then release the mouse button
usleep(250*1000);
test->release(keypad, i, j);
// Poll for the mouse release event (of course this can hang if something fails)
test->poll(keypad);
if (keypad->isButtonClicked(clickColumn, clickRow))
{
printf("clickButtons: ERROR: Button (%d, %d) is clicked\n",
clickColumn, clickRow);
}
usleep(500*1000);
}
}
updateMemoryUsage(g_mmPrevious, "After pushing buttons");
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int ckeypad_main(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the keypad test
printf("ckeypad_main: Create CKeypadTest instance\n");
CKeypadTest *test = new CKeypadTest();
updateMemoryUsage(g_mmPrevious, "After creating CKeypadTest");
// Connect the NX server
printf("ckeypad_main: Connect the CKeypadTest instance to the NX server\n");
if (!test->connect())
{
printf("ckeypad_main: Failed to connect the CKeypadTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmPrevious, "After connecting to the server");
// Create a window to draw into
printf("ckeypad_main: Create a Window\n");
if (!test->createWindow())
{
printf("ckeypad_main: Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmPrevious, "After creating a window");
// Create a CKeypad instance
CKeypad *keypad = test->createKeypad();
if (!keypad)
{
printf("ckeypad_main: Failed to create a keypad\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmPrevious, "After creating CKeypad");
// Show the keypad in alphabetic mode
printf("ckeypad_main: Show the keypad in alphabetic mode\n");
keypad->setKeypadMode(false);
test->showKeypad(keypad);
sleep(1);
// Then click some buttons
clickButtons(test, keypad);
sleep(1);
// Show the keypad in numeric mode
printf("ckeypad_main: Show the keypad in numeric mode\n");
keypad->setKeypadMode(true);
sleep(1);
// Then click some buttons
clickButtons(test, keypad);
sleep(1);
// Clean up and exit
printf("ckeypad_main: Clean-up and exit\n");
delete keypad;
updateMemoryUsage(g_mmPrevious, "After deleting the keypad");
delete test;
updateMemoryUsage(g_mmPrevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
message("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial);
return 0;
}
+458
View File
@@ -0,0 +1,458 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CKeypad/ckeypadtest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "ckeypadtest.hxx"
#include "cbgwindow.hxx"
#include "cnxstring.hxx"
#include "cnxfont.hxx"
#include "crect.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CKeypadTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CKeypadTest Constructor
CKeypadTest::CKeypadTest()
{
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
m_buttonWidth = 0;
m_buttonHeight = 0;
m_displayHeight = 0;
}
// CKeypadTest Descriptor
CKeypadTest::~CKeypadTest()
{
disconnect();
}
// Connect to the NX server
bool CKeypadTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CKEYPADTEST_BGCOLOR))
{
message("CKeypadTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CKeypadTest::disconnect(void)
{
// Destroy the text box
if (m_textbox)
{
delete m_textbox;
}
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// Destroy the widget control
if (m_widgetControl)
{
delete m_widgetControl;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CKeypadTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CKeypadTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CKeypadTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
// Then determine the display size
setDisplaySize();
return true;
}
// Pick size of the display
void CKeypadTest::setDisplaySize(void)
{
// Get the height and width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
message("CKeypadTest::createGraphics: Failed to get window size\n");
return;
}
// Pick a height and width of a button. Here we use inside information
// that the number of rows and columns in the keypad. This should not matter in
// a "real" application.
// Lets aim for a width of 4*60 = 240
if (windowSize.w > KEYPAD_NCOLUMNS*60)
{
m_buttonWidth = 60;
}
else
{
// Otherwise, let's use what we have
m_buttonWidth = windowSize.w >> 2;
}
// Lets aim for a height of 7*32 = 224. But lets bump up the number of rows
// to allow one for the text box.
if (windowSize.h > (KEYPAD_NROWS+1)*32)
{
m_buttonHeight = 32;
m_displayHeight = (KEYPAD_NROWS+1)*32;
}
else
{
// Otherwise, let's use what we have
m_buttonHeight = windowSize.h >> 3;
m_displayHeight = windowSize.h;
}
}
// Create a CKeypad instance
CKeypad *CKeypadTest::createKeypad(void)
{
// Get the height and width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
message("CKeypadTest::createGraphics: Failed to get window size\n");
return (CKeypad *)NULL;
}
// Pick a height and width. Here we use inside information that the number
// of rows in the keypad is 7. This should not matter in a "real" application.
nxgl_coord_t keypadWidth = KEYPAD_NCOLUMNS * m_buttonWidth;
nxgl_coord_t keypadHeight = KEYPAD_NROWS * m_buttonHeight;
// Pick an X/Y position such that the keypad will be centered in the display
nxgl_coord_t keypadOffset = m_displayHeight - keypadHeight;
nxgl_coord_t keypadX = (windowSize.w - keypadWidth) >> 1;
nxgl_coord_t keypadY = keypadOffset + ((windowSize.h - m_displayHeight) >> 1);
// Now we have enough information to create the keypad
CKeypad *keypad = new CKeypad(m_widgetControl, getServer(), keypadX, keypadY,
keypadWidth, keypadHeight);
if (keypad)
{
// Create a text box to catch the keyboard inputs
m_textbox = createTextBox();
if (!m_textbox)
{
delete keypad;
keypad = (CKeypad *)NULL;
}
else
{
// Always show the cursor and wrap the cursor if it goes past the end
m_textbox->showCursor(SHOW_CURSOR_ALWAYS);
m_textbox->wrapCursor(true);
// Align text on the left
m_textbox->setTextAlignmentHoriz(CTextBox::TEXT_ALIGNMENT_HORIZ_LEFT);
// Configure the text box to receive the keyboard input
keypad->addWidgetEventHandler(m_textbox);
}
}
return keypad;
}
// Create a CTextBox instance so that we can see the keypad output
CTextBox *CKeypadTest::createTextBox(void)
{
// Get the height and width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
message("CKeypadTest::createGraphics: Failed to get window size\n");
return (CTextBox *)NULL;
}
// Pick a height and width. Here we use inside information that the number
// of rows in the keypad is 7. This should not matter in a "real" application.
nxgl_coord_t textboxWidth = KEYPAD_NCOLUMNS * m_buttonWidth;
nxgl_coord_t textboxHeight = m_displayHeight - KEYPAD_NROWS * m_buttonHeight;
// Pick an X/Y position such that the keypad will be centered in the display
nxgl_coord_t textboxX = (windowSize.w - textboxWidth) >> 1;
nxgl_coord_t textboxY = (windowSize.h - m_displayHeight) >> 1;
// Now we have enough information to create the TextBox
return new CTextBox(m_widgetControl, textboxX, textboxY,
textboxWidth, textboxHeight, "");
}
// Draw the keypad
void CKeypadTest::showKeypad(CKeypad *keypad)
{
// Re-draw the keypad
keypad->enable(); // Un-necessary, the widget is enabled by default
keypad->enableDrawing();
keypad->redraw();
// Then redraw the text box
m_textbox->enable(); // Un-necessary, the widget is enabled by default
m_textbox->enableDrawing();
m_textbox->redraw();
}
// Perform a simulated mouse click on a button in the array. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void CKeypadTest::click(CKeypad *keypad, int column, int row)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the selected button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// The the coorinates of the center of the button
nxgl_coord_t buttonX = keypad->getX() + column * m_buttonWidth + (m_buttonWidth >> 1);
nxgl_coord_t buttonY = keypad->getY() + row * m_buttonHeight + (m_buttonHeight >> 1);
// Then inject the mouse click
(void)nx_mousein(handle, buttonX, buttonY, NX_MOUSE_LEFTBUTTON);
}
// The counterpart to click. This simulates a button release through
// the same mechanism.
void CKeypadTest::release(CKeypad *keypad, int column, int row)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// The the coorinates of the center of the button
nxgl_coord_t buttonX = keypad->getX() +
column * m_buttonWidth +
m_buttonWidth/2;
nxgl_coord_t buttonY = keypad->getY() +
row * m_buttonHeight +
m_buttonHeight/2;
// Then inject the mouse release
(void)nx_mousein(handle, buttonX, buttonY, NX_MOUSE_NOBUTTONS);
}
// Widget events are normally handled in a modal loop.
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
void CKeypadTest::poll(CKeypad *button)
{
// Poll for mouse events
m_widgetControl->pollEvents(button);
// Limit the amount of text in the TextBox
reverseAlignment();
}
// Start with left text alignment. When the text reaches the right sice
// of the text box, switch to right text alignment.
void CKeypadTest::reverseAlignment(void)
{
// Get the current horizontal text alignment
CTextBox::TextAlignmentHoriz hAlign = m_textbox->getTextAlignmentHoriz();
// Are we still using left text alignment?
if (hAlign == CTextBox::TEXT_ALIGNMENT_HORIZ_LEFT)
{
// Yes.. Get the string in the text box
CNxString string = m_textbox->getText();
// Get the font
CNxFont *font = m_textbox->getFont();
// Get the TextBox bounding box
CRect rect;
m_textbox->getRect(rect);
// When the length of string approaches the width of the display
// region, then switch to right text alignment
int mxWidth = font->getMaxWidth();
if (font->getStringWidth(string) + mxWidth >= rect.getWidth())
{
// Switch to right text alignment
m_textbox->setTextAlignmentHoriz(CTextBox::TEXT_ALIGNMENT_HORIZ_RIGHT);
}
}
}
+182
View File
@@ -0,0 +1,182 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CKeypad/ckeypadtest.hxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __UNITTESTS_CKEYPAD_CKEYPADTEST_HXX
#define __UNITTESTS_CKEYPAD_CKEYPADTEST_HXX
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <semaphore.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "nxconfig.hxx"
#include "cwidgetcontrol.hxx"
#include "ccallback.hxx"
#include "cbgwindow.hxx"
#include "cnxserver.hxx"
#include "cnxfont.hxx"
#include "cnxstring.hxx"
#include "ctextbox.hxx"
#include "ckeypad.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CKEYPADTEST_BGCOLOR
# define CONFIG_CKEYPADTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
// This is the size of the keypad
#define KEYPAD_NROWS 7
#define KEYPAD_NCOLUMNS 4
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CKeypadTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The widget control for the window
CBgWindow *m_bgWindow; // Background window instance
CTextBox *m_textbox; // TextBox to show the key presses
nxgl_coord_t m_buttonWidth; // The width of one button
nxgl_coord_t m_buttonHeight; // The height of one button
nxgl_coord_t m_displayHeight; // The height of the display
// Pick size of the display
void setDisplaySize(void);
// Start with left text alignment. When the text reaches the right sice
// of the text box, switch to right text alignment.
void reverseAlignment(void);
// Create a CTextBox instance so that we can see the keypad output
CTextBox *createTextBox(void);
public:
// Constructor/destructors
CKeypadTest();
~CKeypadTest();
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a CKeypad instance. This method will show you how to create
// a CKeypad widget
CKeypad *createKeypad(void);
// Draw the keypad. This method illustrates how to draw the CKeypad widget.
void showKeypad(CKeypad *keypad);
// Perform a simulated mouse click on a button in the array. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void click(CKeypad *keypad, int column, int row);
// The counterpart to click. This simulates a button release through
// the same mechanism.
void release(CKeypad *keypad, int column, int row);
// Widget events are normally handled in a model loop (by calling goModel()).
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
void poll(CKeypad *keypad);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CKEYPAD_CKEYPADTEST_HXX
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CLabel/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = clabel_main.cxx clabeltest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = clabel
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

+130
View File
@@ -0,0 +1,130 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CLabel/clabel_main.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <unistd.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "clabeltest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static const char g_hello[] = "Hello, World!";
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int clabel_main(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int clabel_main(int argc, char *argv[])
{
// Create an instance of the font test
printf("clabel_main: Create CLabelTest instance\n");
CLabelTest *test = new CLabelTest();
// Connect the NX server
printf("clabel_main: Connect the CLabelTest instance to the NX server\n");
if (!test->connect())
{
printf("clabel_main: Failed to connect the CLabelTest instance to the NX server\n");
delete test;
return 1;
}
// Create a window to draw into
printf("clabel_main: Create a Window\n");
if (!test->createWindow())
{
printf("clabel_main: Failed to create a window\n");
delete test;
return 1;
}
// Create a CLabel instance
CLabel *label = test->createLabel(g_hello);
if (!label)
{
printf("clabel_main: Failed to create a label\n");
delete test;
return 1;
}
// Show the label
test->showLabel(label);
sleep(5);
// Clean up and exit
printf("clabel_main: Clean-up and exit\n");
delete label;
delete test;
return 0;
}
+263
View File
@@ -0,0 +1,263 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CLabel/clabeltest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "clabeltest.hxx"
#include "cbgwindow.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CLabelTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CLabelTest Constructor
CLabelTest::CLabelTest()
{
m_bgWindow = (CBgWindow *)NULL;
m_nxFont = (CNxFont *)NULL;
m_text = (CNxString *)NULL;
}
// CLabelTest Descriptor
CLabelTest::~CLabelTest()
{
disconnect();
}
// Connect to the NX server
bool CLabelTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Create the default font instance
m_nxFont = new CNxFont(NXFONT_DEFAULT,
CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR,
CONFIG_NXWIDGETS_TRANSPARENT_COLOR);
if (!m_nxFont)
{
printf("CLabelTest::connect: Failed to create the default font\n");
}
// Set the background color
if (!setBackgroundColor(CONFIG_CLABELTEST_BGCOLOR))
{
printf("CLabelTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CLabelTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// Free the display string
if (m_text)
{
delete m_text;
m_text = (CNxString *)NULL;
}
// Free the default font
if (m_nxFont)
{
delete m_nxFont;
m_nxFont = (CNxFont *)NULL;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CLabelTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
printf("CLabelTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
printf("CLabelTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CLabel instance
CLabel *CLabelTest::createLabel(FAR const char *text)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CLabelTest::createGraphics: Failed to get window size\n");
return (CLabel *)NULL;
}
// Create a CNxString instance to contain the C string
m_text = new CNxString(text);
// Get the height and width of the text display area
nxgl_coord_t stringWidth = m_nxFont->getStringWidth(*m_text);
nxgl_coord_t stringHeight = (nxgl_coord_t)m_nxFont->getHeight();
// The default CLabel has borders enabled with thickness of the border
// width. Add twice the thickness of the border to the width and height. (We
// could let CLabel do this for us by calling CLabel::getPreferredDimensions())
stringWidth += 2 * 1;
stringHeight += 2 * 1;
// Pick an X/Y position such that the label will be centered in the display
nxgl_coord_t labelX;
if (stringWidth >= windowSize.w)
{
labelX = 0;
}
else
{
labelX = (windowSize.w - stringWidth) >> 1;
}
nxgl_coord_t labelY;
if (stringHeight >= windowSize.h)
{
labelY = 0;
}
else
{
labelY = (windowSize.h - stringHeight) >> 1;
}
// Now we have enough information to create the label
return new CLabel(m_widgetControl, labelX, labelY, stringWidth, stringHeight, *m_text);
}
// Draw the label
void CLabelTest::showLabel(CLabel *label)
{
label->enable();
label->enableDrawing();
label->redraw();
label->disableDrawing();
}
+138
View File
@@ -0,0 +1,138 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CLabel/clabeltest.hxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __UNITTESTS_CLABEL_CLABELTEST_HXX
#define __UNITTESTS_CLABEL_CLABELTEST_HXX
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <semaphore.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "nxconfig.hxx"
#include "cwidgetcontrol.hxx"
#include "ccallback.hxx"
#include "cbgwindow.hxx"
#include "cnxserver.hxx"
#include "cnxfont.hxx"
#include "cnxstring.hxx"
#include "clabel.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CLABELTEST_BGCOLOR
# define CONFIG_CLABELTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR
#endif
#ifndef CONFIG_CLABELTEST_FONTCOLOR
# define CONFIG_CLABELTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CLabelTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CNxFont *m_nxFont; // Default font
CBgWindow *m_bgWindow; // Background window instance
CNxString *m_text; // The label string
public:
// Constructor/destructors
CLabelTest();
~CLabelTest();
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a CLabel instance. This method will show you how to create
// a CLabel widget
CLabel *createLabel(FAR const char *text);
// Draw the label. This method illustrates how to draw the CLabel widget.
void showLabel(CLabel *label);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CLABEL_CLABELTEST_HXX
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CLatchButton/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = clatchbutton_main.cxx clatchbuttontest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = clatchbutton
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,199 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CLatchButton/clatchbutton_main.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <unistd.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "clatchbuttontest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static const char g_pushme[] = "Push Me";
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int clatchbutton_main(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: showButtonState
/////////////////////////////////////////////////////////////////////////////
static void showButtonState(CLatchButton *button, bool &clicked, bool &latched)
{
bool nowClicked = button->isClicked();
bool nowLatched = button->isLatched();
printf("showButtonState: Button state: %s and %s\n",
nowClicked ? "clicked" : "released",
nowLatched ? "latched" : "unlatched");
if (clicked != nowClicked || latched != nowLatched)
{
printf("showButtonState: ERROR: Expected %s and %s\n",
clicked ? "clicked" : "released",
latched ? "latched" : "unlatched");
clicked = nowClicked;
latched = nowLatched;
}
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int clatchbutton_main(int argc, char *argv[])
{
// Create an instance of the font test
printf("clatchbutton_main: Create CLatchButtonTest instance\n");
CLatchButtonTest *test = new CLatchButtonTest();
// Connect the NX server
printf("clatchbutton_main: Connect the CLatchButtonTest instance to the NX server\n");
if (!test->connect())
{
printf("clatchbutton_main: Failed to connect the CLatchButtonTest instance to the NX server\n");
delete test;
return 1;
}
// Create a window to draw into
printf("clatchbutton_main: Create a Window\n");
if (!test->createWindow())
{
printf("clatchbutton_main: Failed to create a window\n");
delete test;
return 1;
}
// Create a CLatchButton instance
CLatchButton *button = test->createButton(g_pushme);
if (!button)
{
printf("clatchbutton_main: Failed to create a button\n");
delete test;
return 1;
}
// Show the button
printf("clatchbutton_main: Show the button\n");
test->showButton(button);
bool clicked = false;
bool latched = false;
showButtonState(button, clicked, latched);
// Toggle the button state a few times
for (int i = 0; i < 8; i++)
{
// Wait two seconds, then perform a simulated mouse click on the button
sleep(2);
printf("clatchbutton_main: Click the button\n");
test->click();
test->poll(button);
// Test the button state it should be clicked with the latch state
// toggled
clicked = true;
latched = !latched;
showButtonState(button, clicked, latched);
// And release the button after 0.5 seconds
usleep(500 * 1000);
printf("clatchbutton_main: Release the button\n");
test->release();
test->poll(button);
// Test the button state it should be unclicked with the latch state
// unchanged
clicked = false;
showButtonState(button, clicked, latched);
fflush(stdout);
}
// Wait a few more seconds so that the tester can ponder the result
sleep(3);
// Clean up and exit
printf("clatchbutton_main: Clean-up and exit\n");
delete button;
delete test;
return 0;
}
@@ -0,0 +1,321 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CLatchButton/clatchbuttontest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "clatchbuttontest.hxx"
#include "cbgwindow.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CLatchButtonTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CLatchButtonTest Constructor
CLatchButtonTest::CLatchButtonTest()
{
m_bgWindow = (CBgWindow *)NULL;
m_nxFont = (CNxFont *)NULL;
m_text = (CNxString *)NULL;
}
// CLatchButtonTest Descriptor
CLatchButtonTest::~CLatchButtonTest()
{
disconnect();
}
// Connect to the NX server
bool CLatchButtonTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Create the default font instance
m_nxFont = new CNxFont(NXFONT_DEFAULT,
CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR,
CONFIG_NXWIDGETS_TRANSPARENT_COLOR);
if (!m_nxFont)
{
printf("CLatchButtonTest::connect: Failed to create the default font\n");
}
// Set the background color
if (!setBackgroundColor(CONFIG_CLATCHBUTTONTEST_BGCOLOR))
{
printf("CLatchButtonTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CLatchButtonTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// Free the display string
if (m_text)
{
delete m_text;
m_text = (CNxString *)NULL;
}
// Free the default font
if (m_nxFont)
{
delete m_nxFont;
m_nxFont = (CNxFont *)NULL;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CLatchButtonTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
printf("CLatchButtonTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
printf("CLatchButtonTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CLatchButton instance
CLatchButton *CLatchButtonTest::createButton(FAR const char *text)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CLatchButtonTest::createGraphics: Failed to get window size\n");
return (CLatchButton *)NULL;
}
// Create a CNxString instance to contain the C string
m_text = new CNxString(text);
// Get the height and width of the text display area
nxgl_coord_t stringWidth = m_nxFont->getStringWidth(*m_text);
nxgl_coord_t stringHeight = (nxgl_coord_t)m_nxFont->getHeight();
// The default CLatchButton has borders enabled with thickness of the border
// width. Add twice the thickness of border the to the width and height. (We
// could let CLatchButton do this for us by calling
// CLatchButton::getPreferredDimensions())
stringWidth += 2 * 1;
stringHeight += 2 * 1;
// Pick an X/Y position such that the button will be centered in the display
nxgl_coord_t buttonX;
if (stringWidth >= windowSize.w)
{
buttonX = 0;
}
else
{
buttonX = (windowSize.w - stringWidth) >> 1;
}
nxgl_coord_t buttonY;
if (stringHeight >= windowSize.h)
{
buttonY = 0;
}
else
{
buttonY = (windowSize.h - stringHeight) >> 1;
}
// Save the center position of the button for use by click and release
m_center.x = buttonX + (stringWidth >> 1);
m_center.y = buttonY + (stringHeight >> 1);
// Now we have enough information to create the button
return new CLatchButton(m_widgetControl, buttonX, buttonY, stringWidth, stringHeight, *m_text);
}
// Draw the button
void CLatchButtonTest::showButton(CLatchButton *button)
{
button->enable(); // Un-necessary, the widget is enabled by default
button->enableDrawing();
button->redraw();
}
// Perform a simulated mouse click on the button. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void CLatchButtonTest::click(void)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// Then inject the mouse click
(void)nx_mousein(handle, m_center.x, m_center.y, NX_MOUSE_LEFTBUTTON);
}
// The counterpart to click. This simulates a button release through
// the same mechanism.
void CLatchButtonTest::release(void)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// Then inject the mouse click
(void)nx_mousein(handle, m_center.x, m_center.y, NX_MOUSE_NOBUTTONS);
}
// Widget events are normally handled in a modal loop.
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll.
void CLatchButtonTest::poll(CLatchButton *button)
{
// Poll for mouse events
m_widgetControl->pollEvents(button);
}
@@ -0,0 +1,155 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CLatchButton/clatchbuttontest.hxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __UNITTESTS_CLATCHBUTTON_CLATCHBUTTONTEST_HXX
#define __UNITTESTS_CLATCHBUTTON_CLATCHBUTTONTEST_HXX
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <semaphore.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "nxconfig.hxx"
#include "cwidgetcontrol.hxx"
#include "ccallback.hxx"
#include "cbgwindow.hxx"
#include "cnxserver.hxx"
#include "cnxfont.hxx"
#include "cnxstring.hxx"
#include "clatchbutton.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CLATCHBUTTONTEST_BGCOLOR
# define CONFIG_CLATCHBUTTONTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR
#endif
#ifndef CONFIG_CLATCHBUTTONTEST_FONTCOLOR
# define CONFIG_CLATCHBUTTONTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CLatchButtonTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CNxFont *m_nxFont; // Default font
CBgWindow *m_bgWindow; // Background window instance
CNxString *m_text; // The button string
struct nxgl_point_s m_center; // X, Y position the center of the button
public:
// Constructor/destructors
CLatchButtonTest(void);
~CLatchButtonTest(void);
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a CLatchButton instance. This method will show you how to create
// a CLatchButton widget
CLatchButton *createButton(FAR const char *text);
// Draw the button. This method illustrates how to draw the CLatchButton widget.
void showButton(CLatchButton *button);
// Perform a simulated mouse click on the button. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void click(void);
// The counterpart to click. This simulates a button release through
// the same mechanism.
void release(void);
// Widget events are normally handled in a model loop (by calling goModel()).
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll.
void poll(CLatchButton *button);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CLATCHBUTTON_CLATCHBUTTONTEST_HXX
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CLatchButtonArray/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = clatchbuttonarray_main.cxx clatchbuttonarraytest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = clatchbuttonarray
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,301 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarry_main.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "cnxstring.hxx"
#include "clatchbuttonarraytest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static unsigned int g_mmInitial;
static unsigned int g_mmPrevious;
static unsigned int g_mmPeak;
static FAR const char *g_buttonLabels[BUTTONARRAY_NCOLUMNS*BUTTONARRAY_NROWS] = {
"=>", "A", "B", "<DEL",
"C", "D", "E", "F",
"G", "H", "I", "J",
"K", "L", "M", "N",
"O", "P", "Q", "R",
"S", "T", "U", "V",
"W", "X", "Y", "Z"
};
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int clatchbuttonarray_main(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: showButtonState
/////////////////////////////////////////////////////////////////////////////
static void showButtonState(CLatchButtonArray *buttonArray, int i, int j,
bool &clicked, bool &latched)
{
bool nowClicked = buttonArray->isThisButtonClicked(i,j);
bool nowLatched = buttonArray->isThisButtonLatched(i,j);
printf("showButtonState: Button(%d,%d) state: %s and %s\n",
i, j,
nowClicked ? "clicked" : "released",
nowLatched ? "latched" : "unlatched");
if (clicked != nowClicked || latched != nowLatched)
{
printf("showButtonState: ERROR: Expected %s and %s\n",
clicked ? "clicked" : "released",
latched ? "latched" : "unlatched");
clicked = nowClicked;
latched = nowLatched;
}
}
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("%s: Before: %8d After: %8d Change: %8d\n",
msg, previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmPrevious = mmcurrent.uordblks;
if ((unsigned int)mmcurrent.uordblks > g_mmPeak)
{
g_mmPeak = mmcurrent.uordblks;
}
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmPrevious = mmcurrent.uordblks;
g_mmPeak = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int clatchbuttonarray_main(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the button array test
printf("clatchbuttonarray_main: Create CLatchButtonArrayTest instance\n");
CLatchButtonArrayTest *test = new CLatchButtonArrayTest();
updateMemoryUsage(g_mmPrevious, "After creating CLatchButtonArrayTest");
// Connect the NX server
printf("clatchbuttonarray_main: Connect the CLatchButtonArrayTest instance to the NX server\n");
if (!test->connect())
{
printf("clatchbuttonarray_main: Failed to connect the CLatchButtonArrayTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmPrevious, "After connecting to the server");
// Create a window to draw into
printf("clatchbuttonarray_main: Create a Window\n");
if (!test->createWindow())
{
printf("clatchbuttonarray_main: Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmPrevious, "After creating a window");
// Create a CLatchButtonArray instance
CLatchButtonArray *buttonArray = test->createButtonArray();
if (!buttonArray)
{
printf("clatchbuttonarray_main: Failed to create a button array\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmPrevious, "After creating CLatchButtonArray");
// Add the labels to each button
FAR const char **ptr = g_buttonLabels;
for (int j = 0; j < BUTTONARRAY_NROWS; j++)
{
for (int i = 0; i < BUTTONARRAY_NCOLUMNS; i++)
{
printf("clatchbuttonarray_main: Label (%d,%d): %s\n", i, j, *ptr);
CNxString string = *ptr++;
buttonArray->setText(i, j, string);
}
}
updateMemoryUsage(g_mmPrevious, "After adding labels to the buttons");
// Show the button array
printf("clatchbuttonarray_main: Show the button array\n");
test->showButton(buttonArray);
sleep(1);
// Then perform a simulated mouse click on a button in the array
bool clicked = false;
bool latched = false;
for (int j = 0; j < BUTTONARRAY_NROWS; j++)
{
for (int i = 0; i < BUTTONARRAY_NCOLUMNS; i++)
{
// Initially, this button should be neither clicked nor latched
clicked = false;
latched = false;
showButtonState(buttonArray, i, j, clicked, latched);
printf("clatchbuttonarray_main: Click the button (%d,%d)\n", i, j);
test->click(buttonArray, i, j);
// Poll for the mouse click event
test->poll(buttonArray);
// Now it should be clicked and latched
clicked = true;
latched = true;
showButtonState(buttonArray, i, j, clicked, latched);
// Wait a bit, then release the mouse button
usleep(200*1000);
test->release(buttonArray, i, j);
// Poll for the mouse release event (of course this can hang if something fails)
test->poll(buttonArray);
// Now it should be un-clicked and latched
clicked = false;
latched = true;
showButtonState(buttonArray, i, j, clicked, latched);
usleep(300*1000);
}
}
updateMemoryUsage(g_mmPrevious, "After pushing buttons");
// Clean up and exit
printf("clatchbuttonarray_main: Clean-up and exit\n");
delete buttonArray;
updateMemoryUsage(g_mmPrevious, "After deleting the button array");
delete test;
updateMemoryUsage(g_mmPrevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
message("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial);
return 0;
}
@@ -0,0 +1,301 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "clatchbuttonarraytest.hxx"
#include "cbgwindow.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CLatchButtonArrayTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CLatchButtonArrayTest Constructor
CLatchButtonArrayTest::CLatchButtonArrayTest()
{
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CLatchButtonArrayTest Descriptor
CLatchButtonArrayTest::~CLatchButtonArrayTest()
{
disconnect();
}
// Connect to the NX server
bool CLatchButtonArrayTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CLATCHBUTTONARRAYTEST_BGCOLOR))
{
message("CLatchButtonArrayTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CLatchButtonArrayTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// Destroy the widget control
if (m_widgetControl)
{
delete m_widgetControl;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CLatchButtonArrayTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CLatchButtonArrayTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CLatchButtonArrayTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CLatchButtonArray instance
CLatchButtonArray *CLatchButtonArrayTest::createButtonArray(void)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
message("CLatchButtonArrayTest::createGraphics: Failed to get window size\n");
return (CLatchButtonArray *)NULL;
}
// Pick an X/Y position such that the button array will be centered in the display
nxgl_coord_t buttonArrayX;
if (BUTTONARRAY_WIDTH >= windowSize.w)
{
buttonArrayX = 0;
}
else
{
buttonArrayX = (windowSize.w - BUTTONARRAY_WIDTH) >> 1;
}
nxgl_coord_t buttonArrayY;
if (BUTTONARRAY_HEIGHT >= windowSize.h)
{
buttonArrayY = 0;
}
else
{
buttonArrayY = (windowSize.h - BUTTONARRAY_HEIGHT) >> 1;
}
// Now we have enough information to create the button array
return new CLatchButtonArray(m_widgetControl,
buttonArrayX, buttonArrayY,
BUTTONARRAY_NCOLUMNS, BUTTONARRAY_NROWS,
BUTTONARRAY_BUTTONWIDTH, BUTTONARRAY_BUTTONHEIGHT);
}
// Draw the button array
void CLatchButtonArrayTest::showButton(CLatchButtonArray *buttonArray)
{
buttonArray->enable(); // Un-necessary, the widget is enabled by default
buttonArray->enableDrawing();
buttonArray->redraw();
}
// Perform a simulated mouse click on a button in the array. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void CLatchButtonArrayTest::click(CLatchButtonArray *buttonArray, int column, int row)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the selected button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// The the coorinates of the center of the button
nxgl_coord_t buttonX = buttonArray->getX() +
column * BUTTONARRAY_BUTTONWIDTH +
BUTTONARRAY_BUTTONWIDTH/2;
nxgl_coord_t buttonY = buttonArray->getY() +
row * BUTTONARRAY_BUTTONHEIGHT +
BUTTONARRAY_BUTTONHEIGHT/2;
// Then inject the mouse click
(void)nx_mousein(handle, buttonX, buttonY, NX_MOUSE_LEFTBUTTON);
}
// The counterpart to click. This simulates a button release through
// the same mechanism.
void CLatchButtonArrayTest::release(CLatchButtonArray *buttonArray, int column, int row)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// The the coorinates of the center of the button
nxgl_coord_t buttonX = buttonArray->getX() +
column * BUTTONARRAY_BUTTONWIDTH +
BUTTONARRAY_BUTTONWIDTH/2;
nxgl_coord_t buttonY = buttonArray->getY() +
row * BUTTONARRAY_BUTTONHEIGHT +
BUTTONARRAY_BUTTONHEIGHT/2;
// Then inject the mouse release
(void)nx_mousein(handle, buttonX, buttonY, NX_MOUSE_NOBUTTONS);
}
// Widget events are normally handled in a modal loop.
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
void CLatchButtonArrayTest::poll(CLatchButtonArray *button)
{
// Poll for mouse events
m_widgetControl->pollEvents(button);
}
@@ -0,0 +1,172 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.hxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __UNITTESTS_CLATCHBUTTONARRAY_CLATCHBUTTONARRAYTEST_HXX
#define __UNITTESTS_CLATCHBUTTONARRAY_CLATCHBUTTONARRAYTEST_HXX
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <semaphore.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "nxconfig.hxx"
#include "cwidgetcontrol.hxx"
#include "ccallback.hxx"
#include "cbgwindow.hxx"
#include "cnxserver.hxx"
#include "cnxfont.hxx"
#include "cnxstring.hxx"
#include "clatchbuttonarray.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CLATCHBUTTONARRAYTEST_BGCOLOR
# define CONFIG_CLATCHBUTTONARRAYTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR
#endif
#ifndef CONFIG_CLATCHBUTTONARRAYTEST_FONTCOLOR
# define CONFIG_CLATCHBUTTONARRAYTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
// The geometry of the button array
#define BUTTONARRAY_NCOLUMNS 4
#define BUTTONARRAY_NROWS 7
#define BUTTONARRAY_BUTTONWIDTH 60
#define BUTTONARRAY_BUTTONHEIGHT 32
#define BUTTONARRAY_WIDTH (BUTTONARRAY_BUTTONWIDTH * BUTTONARRAY_NCOLUMNS)
#define BUTTONARRAY_HEIGHT (BUTTONARRAY_BUTTONHEIGHT * BUTTONARRAY_NROWS)
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CLatchButtonArrayTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The widget control for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CLatchButtonArrayTest();
~CLatchButtonArrayTest();
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a CLatchButtonArray instance. This method will show you how to create
// a CLatchButtonArray widget
CLatchButtonArray *createButtonArray(void);
// Draw the button array. This method illustrates how to draw the CLatchButtonArray widget.
void showButton(CLatchButtonArray *buttonArray);
// Perform a simulated mouse click on a button in the array. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void click(CLatchButtonArray *buttonArray, int column, int row);
// The counterpart to click. This simulates a button release through
// the same mechanism.
void release(CLatchButtonArray *buttonArray, int column, int row);
// Widget events are normally handled in a model loop (by calling goModel()).
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
void poll(CLatchButtonArray *buttonArray);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CLATCHBUTTONARRAY_CLATCHBUTTONARRAYTEST_HXX
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CListBox/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = clistbox_main.cxx clistboxtest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = clistbox
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,327 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CListBox/clistbox_main.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "clistboxtest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static unsigned int g_mmInitial;
static unsigned int g_mmPrevious;
static unsigned int g_mmPeak;
static FAR const char *g_options[] =
{
"American groundnut (Apios americana)",
"Azuki bean (Vigna angularis)",
"Black-eyed pea (Vigna unguiculata subsp. unguiculata)",
"Chickpea (Cicer arietinum)",
"Common bean (Phaseolus vulgaris)",
"Drumstick (Moringa oleifera)",
"Dolichos bean (Lablab purpureus)",
"Fava bean (Vicia faba)",
"Garbanzo (Cicer arietinum)",
"Green bean (Phaseolus vulgaris)",
"Guar (Cyamopsis tetragonoloba)",
"Gumbo (Abelmoschus esculentus)",
"Horse gram (Macrotyloma uniflorum)",
"Indian pea (Lathyrus sativus)",
"Lentil (Lens culinaris)",
"Lima Bean (Phaseolus lunatus)",
"Moth bean (Vigna acontifolia)",
"Mung bean (Vigna radiata)",
"Okra (Abelmoschus esculentus)",
"Pea (Pisum sativum)",
"Peanut (Arachis hypogaea)",
"Pigeon pea (Cajanus cajan)",
"Ricebean (Vigna umbellata)",
"Runner bean (Phaseolus coccineus)",
"Soybean (Glycine max)",
"Tarwi (tarhui, chocho; Lupinus mutabilis)",
"Tepary bean (Phaseolus acutifolius)",
"Urad bean (Vigna mungo)",
"Velvet bean (Mucuna pruriens)",
"Winged bean (Psophocarpus tetragonolobus)",
"Yardlong bean (Vigna unguiculata subsp. sesquipedalis)"
};
#define NOPTIONS (sizeof(g_options)/sizeof(FAR const char *))
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int clistbox_main(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("%s: Before: %8d After: %8d Change: %8d\n",
msg, previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmPrevious = mmcurrent.uordblks;
if ((unsigned int)mmcurrent.uordblks > g_mmPeak)
{
g_mmPeak = mmcurrent.uordblks;
}
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmPrevious = mmcurrent.uordblks;
g_mmPeak = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int clistbox_main(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the listbox test
message("clistbox_main: Create CListBoxTest instance\n");
CListBoxTest *test = new CListBoxTest();
updateMemoryUsage(g_mmPrevious, "After creating CListBoxTest");
// Connect the NX server
message("clistbox_main: Connect the CListBoxTest instance to the NX server\n");
if (!test->connect())
{
message("clistbox_main: Failed to connect the CListBoxTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmPrevious, "clistbox_main: After connecting to the server");
// Create a window to draw into
message("clistbox_main: Create a Window\n");
if (!test->createWindow())
{
message("clistbox_main: Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmPrevious, "clistbox_main: After creating a window");
// Create a listbox
message("clistbox_main: Create a ListBox\n");
CListBox *listbox = test->createListBox();
if (!listbox)
{
message("clistbox_main: Failed to create a listbox\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmPrevious, "clistbox_main: After creating a listbox");
// Show the initial state of the listbox
listbox->setAllowMultipleSelections(true);
test->showListBox(listbox);
sleep(1);
// Now add items to the list box (in reverse alphabetical order)
message("clistbox_main: Add options to the ListBox\n");
for (int i = NOPTIONS - 1; i >= 0; i--)
{
listbox->addOption(g_options[i],i);
test->showListBox(listbox);
message("clistbox_main: %d. New option %s\n", i, g_options[i]);
usleep(500000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmPrevious, "clistbox_main: After adding the listbox items");
sleep(1);
// Sort the list box
message("clistbox_main: Sort the ListBox\n");
listbox->sort();
test->showListBox(listbox);
updateMemoryUsage(g_mmPrevious, "clistbox_main: After sorting the listbox");
sleep(1);
// Select and remove items from the listbox
srand(1978);
int nOptions;
while ((nOptions = listbox->getOptionCount()) > 0)
{
message("clistbox_main: Option count: %d\n", nOptions);
if (nOptions <= 5)
{
message("clistbox_main: Selecting all remaining options\n");
listbox->selectAllOptions();
test->showListBox(listbox);
updateMemoryUsage(g_mmPrevious, "clistbox_main: After selecting all options");
sleep(1);
message("clistbox_main: Removing all remaining options\n");
listbox->removeAllOptions();
updateMemoryUsage(g_mmPrevious, "clistbox_main: After removing all options");
test->showListBox(listbox);
}
else
{
int selected[5];
message("clistbox_main: Selecting five options\n");
for (int i = 0; i < 5; i++)
{
selected[i] = ((nOptions - 1) * rand()) / MAX_RAND;
message("clistbox_main: Selecting option %d\n", selected[i]);
listbox->removeOption(selected[i]);
test->showListBox(listbox);
usleep(500000);
}
updateMemoryUsage(g_mmPrevious, "clistbox_main: After selecting five options");
message("clistbox_main: De-selecting options\n");
int index;
int count = 0;
while ((index = listbox->getSelectedIndex()) >= 0)
{
message("clistbox_main: De-selecting option %d\n", index);
listbox->deselectOption(index);
test->showListBox(listbox);
count++;
usleep(500000);
}
message("clistbox_main: %s: %d options de-selected\n",
count == 5 ? "OK" : "ERROR", count);
updateMemoryUsage(g_mmPrevious, "clistbox_main: After de-selecting options");
message("clistbox_main: Removing the selected options\n");
for (int i = 0; i < 5; i++)
{
message("clistbox_main: Removing option %d\n", selected[i]);
listbox->removeOption(selected[i]);
test->showListBox(listbox);
usleep(500000);
}
updateMemoryUsage(g_mmPrevious, "clistbox_main: After removing five options");
}
sleep(1);
}
updateMemoryUsage(g_mmPrevious, "clistbox_main: After the listbox is empty again");
sleep(1);
// Clean up and exit
message("clistbox_main: Clean-up and exit\n");
delete listbox;
updateMemoryUsage(g_mmPrevious, "After deleting the listbox");
delete test;
updateMemoryUsage(g_mmPrevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
message("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial);
return 0;
}

Some files were not shown because too many files have changed in this diff Show More