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
NxWidgets/ChangeLog.txt Normal file
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.

1551
NxWidgets/Doxygen/Doxyfile Normal file

File diff suppressed because it is too large Load Diff

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
NxWidgets/Doxygen/gendoc.sh Executable file
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
NxWidgets/README.txt Normal file
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).

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
NxWidgets/TODO.txt Normal file
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

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

View File

@ -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;
}

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();
}

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

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

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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

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

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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

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

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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

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

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;
}

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();
}

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

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

View File

@ -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;
}

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);
}
}
}

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

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

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;
}

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();
}

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

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

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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

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

View File

@ -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;
}

View File

@ -0,0 +1,224 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CListBox/clistboxtest.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 "clistboxtest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CListBoxTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CListBoxTest Constructor
CListBoxTest::CListBoxTest()
{
// Initialize state data
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CListBoxTest Descriptor
CListBoxTest::~CListBoxTest(void)
{
disconnect();
}
// Connect to the NX server
bool CListBoxTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CLISTBOXTEST_BGCOLOR))
{
message("CListBoxTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CListBoxTest::disconnect(void)
{
// 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 CListBoxTest::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("CListBoxTest::createWindow: Failed to create CBgWindow instance\n");
disconnect();
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CListBoxTest::createWindow: Failed to open background window\n");
disconnect();
return false;
}
return true;
}
// Create a listbox in the center of the window
CListBox *CListBoxTest::createListBox(void)
{
// Get the size of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CListBoxTest::createListBox: Failed to get window size\n");
disconnect();
return false;
}
// Put the listbox in the center of the display
nxgl_coord_t listboxWidth = windowSize.w >> 1;
nxgl_coord_t listboxX = windowSize.w >> 2;
nxgl_coord_t listboxHeight = windowSize.h >> 1;
nxgl_coord_t listboxY = windowSize.h >> 2;
// Create the listbox
CListBox *listbox = new CListBox(m_widgetControl,
listboxX, listboxY,
listboxWidth, listboxHeight);
if (!listbox)
{
printf("CListBoxTest::createListBox: Failed to create CListBox\n");
disconnect();
}
return listbox;
}
// (Re-)draw the listbox.
void CListBoxTest::showListBox(CListBox *listbox)
{
listbox->enable(); // Un-necessary, the widget is enabled by default
listbox->enableDrawing();
listbox->redraw();
}

View File

@ -0,0 +1,137 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CListBox/clistboxtest.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_CLISTBOX_CLISTBOXTEST_HXX
#define __UNITTESTS_CLISTBOX_CLISTBOXTEST_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 "clistbox.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CLISTBOXTEST_BGCOLOR
# define CONFIG_CLISTBOXTEST_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 CListBoxTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CListBoxTest(void);
~CListBoxTest(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 listbox in the center of the window
CListBox *createListBox(void);
// (Re-)draw the listbox.
void showListBox(CListBox *listbox);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CLISTBOX_CLISTBOXTEST_HXX

View File

@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CProgressBar/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 = cprogressbar_main.cxx cprogressbartest.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 = cprogressbar
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

View File

@ -0,0 +1,238 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CProgressBar/cprogressbar_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 "cprogressbartest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
#define MAX_PROGRESSBAR 50
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static unsigned int g_mmInitial;
static unsigned int g_mmprevious;
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int cprogressbar_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 cprogressbar_main(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the checkbox test
message("cprogressbar_main: Create CProgressBarTest instance\n");
CProgressBarTest *test = new CProgressBarTest();
updateMemoryUsage(g_mmprevious, "After creating CProgressBarTest");
// Connect the NX server
message("cprogressbar_main: Connect the CProgressBarTest instance to the NX server\n");
if (!test->connect())
{
message("cprogressbar_main: Failed to connect the CProgressBarTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cprogressbar_main: After connecting to the server");
// Create a window to draw into
message("cprogressbar_main: Create a Window\n");
if (!test->createWindow())
{
message("cprogressbar_main: Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cprogressbar_main: After creating a window");
// Create a progress bar
message("cprogressbar_main: Create a ProgressBar\n");
CProgressBar *bar = test->createProgressBar();
if (!bar)
{
message("cprogressbar_main: Failed to create a progress bar\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cprogressbar_main: After creating a progress bar");
// Set the progress bar minimum and maximum values
bar->setMinimumValue(0);
bar->setMaximumValue(MAX_PROGRESSBAR);
bar->setValue(0);
bar->hidePercentageText();
message("cprogressbar_main: ProgressBar range %d->%d Initial value %d\n",
bar->getMinimumValue(), bar->getMaximumValue(),
bar->getValue());
// Show the initial state of the checkbox
test->showProgressBar(bar);
sleep(1);
// Now move the progress bar up from 0 to 100% (with percentages off)
for (int i = 0; i <= MAX_PROGRESSBAR; i++)
{
bar->setValue(i);
test->showProgressBar(bar);
message("cprogressbar_main: %d. New value %d\n", i, bar->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, "cprogressbar_main: After moving the progress bar up #1");
usleep(500*1000);
// Now move the progress bar up from 0 to 100% (with percentages off)
bar->showPercentageText();
bar->setValue(0);
test->showProgressBar(bar);
usleep(500*1000);
for (int i = 0; i <= MAX_PROGRESSBAR; i++)
{
bar->setValue(i);
test->showProgressBar(bar);
message("cprogressbar_main: %d. New value %d\n", i, bar->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, "cprogressbar_main: After moving the progress bar up #2");
sleep(1);
// Clean up and exit
message("cprogressbar_main: Clean-up and exit\n");
delete bar;
updateMemoryUsage(g_mmprevious, "After deleting the progress bar");
delete test;
updateMemoryUsage(g_mmprevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
return 0;
}

View File

@ -0,0 +1,224 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/ProgressBar/cprogressbartest.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 "cprogressbartest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CProgressBarTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CProgressBarTest Constructor
CProgressBarTest::CProgressBarTest()
{
// Initialize state data
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CProgressBarTest Descriptor
CProgressBarTest::~CProgressBarTest(void)
{
disconnect();
}
// Connect to the NX server
bool CProgressBarTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CPROGRESSBARTEST_BGCOLOR))
{
message("CProgressBarTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CProgressBarTest::disconnect(void)
{
// 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 CProgressBarTest::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("CProgressBarTest::createWindow: Failed to create CBgWindow instance\n");
disconnect();
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CProgressBarTest::createWindow: Failed to open background window\n");
disconnect();
return false;
}
return true;
}
// Create a bar in the center of the window
CProgressBar *CProgressBarTest::createProgressBar(void)
{
// Get the size of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CProgressBarTest::createProgressBar: Failed to get window size\n");
disconnect();
return false;
}
// Put the bar in the center of the display
nxgl_coord_t barWidth = windowSize.w >> 1;
nxgl_coord_t barX = windowSize.w >> 2;
nxgl_coord_t barHeight = 16;
nxgl_coord_t barY = (windowSize.h - barHeight) >> 1;
// Create the bar
CProgressBar *bar = new CProgressBar(m_widgetControl,
barX, barY,
barWidth, barHeight);
if (!bar)
{
printf("CProgressBarTest::createProgressBar: Failed to create CProgressBar\n");
disconnect();
}
return bar;
}
// (Re-)draw the bar.
void CProgressBarTest::showProgressBar(CProgressBar *bar)
{
bar->enable(); // Un-necessary, the widget is enabled by default
bar->enableDrawing();
bar->redraw();
}

View File

@ -0,0 +1,137 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CProgressBar/cprogressbartest.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_CPROGRESSBAR_CPROGRESSBARTEST_HXX
#define __UNITTESTS_CPROGRESSBAR_CPROGRESSBARTEST_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 "cprogressbar.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CPROGRESSBARTEST_BGCOLOR
# define CONFIG_CPROGRESSBARTEST_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 CProgressBarTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CProgressBarTest(void);
~CProgressBarTest(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 progress bar in the center of the window
CProgressBar *createProgressBar(void);
// (Re-)draw the progress bar.
void showProgressBar(CProgressBar *bar);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CPROGRESSBAR_CPROGRESSBARTEST_HXX

View File

@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CRadioButton/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 = cradiobutton_main.cxx cradiobuttontest.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 = cradiobutton
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: 32 KiB

View File

@ -0,0 +1,238 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CRadioButton/cradiobutton_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 "cradiobuttontest.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 cradiobutton_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 cradiobutton_main(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the radio button test
message("cradiobutton_main: Create CRadioButtonTest instance\n");
CRadioButtonTest *test = new CRadioButtonTest();
updateMemoryUsage(g_mmprevious, "After creating CRadioButtonTest");
// Connect the NX server
message("cradiobutton_main: Connect the CRadioButtonTest instance to the NX server\n");
if (!test->connect())
{
message("cradiobutton_main: Failed to connect the CRadioButtonTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cradiobutton_main: After connecting to the server");
// Create a window to draw into
message("cradiobutton_main: Create a Window\n");
if (!test->createWindow())
{
message("cradiobutton_main: Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cradiobutton_main: After creating a window");
// Create three radio buttons
CRadioButton *button1 = test->newRadioButton();
if (!button1)
{
message("cradiobutton_main: Failed to create radio button 1\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cradiobutton_main: After creating radio button 1");
CRadioButton *button2 = test->newRadioButton();
if (!button2)
{
message("cradiobutton_main: Failed to create radio button 2\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cradiobutton_main: After creating radio button 2");
CRadioButton *button3 = test->newRadioButton();
if (!button3)
{
message("cradiobutton_main: Failed to create radio button 3\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cradiobutton_main: After creating radio button 3");
// Show the initial state of the buttons
test->showButtons();
test->showButtonState();
sleep(1);
// Now push some buttons
message("cradiobutton_main: Pushing button 1\n");
test->pushButton(button1);
usleep(500*1000);
test->showButtonState();
updateMemoryUsage(g_mmprevious, "After pushing button 1");
usleep(500*1000);
message("cradiobutton_main: Pushing button 2\n");
test->pushButton(button2);
usleep(500*1000);
test->showButtonState();
updateMemoryUsage(g_mmprevious, "After pushing button 2");
usleep(500*1000);
message("cradiobutton_main: Pushing button 3\n");
test->pushButton(button3);
usleep(500*1000);
test->showButtonState();
updateMemoryUsage(g_mmprevious, "After pushing button 3");
sleep(2);
// Clean up and exit
message("cradiobutton_main: Clean-up and exit\n");
delete test;
updateMemoryUsage(g_mmprevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
return 0;
}

View File

@ -0,0 +1,305 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CRadioButton/cradiobuttontest.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 "cradiobuttontest.hxx"
#include "cbitmap.hxx"
#include "glyphs.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CRadioButtonTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CRadioButtonTest Constructor
CRadioButtonTest::CRadioButtonTest()
{
// Initialize state data
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
// Peek at the radio button glyph to get a good estimate of the size
m_size.w = g_radioButtonOn.width;
m_size.h = g_radioButtonOn.height;
}
// CRadioButtonTest Descriptor
CRadioButtonTest::~CRadioButtonTest(void)
{
disconnect();
}
// Connect to the NX server
bool CRadioButtonTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CRADIOBUTTONTEST_BGCOLOR))
{
message("CRadioButtonTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CRadioButtonTest::disconnect(void)
{
// Free the radiobutton group
if (m_radioButtonGroup)
{
delete m_radioButtonGroup;
m_radioButtonGroup = (CRadioButtonGroup *)NULL;
}
// 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 CRadioButtonTest::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("CRadioButtonTest::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("CRadioButtonTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CRadioButton instance
CRadioButton *CRadioButtonTest::newRadioButton(void)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
message("CRadioButtonTest::newRadioButton: Failed to get window size\n");
return (CRadioButton *)NULL;
}
// Create the radio button group, if we have not already done so
if (!m_radioButtonGroup)
{
// Start the radio button group in the center of the upper, left
// quadrant. The initial size is 0,0 and the default style is used.
nxgl_coord_t groupX = windowSize.w >> 2;
nxgl_coord_t groupY = windowSize.h >> 2;
m_radioButtonGroup = new CRadioButtonGroup(m_widgetControl, groupX, groupY);
if (!m_radioButtonGroup)
{
message("CRadioButtonTest::newRadioButton: Failed to create the radio button group\n");
return (CRadioButton *)NULL;
}
}
// Create the new radio button at the botton of the radio button group and
// with the size of the ON radio button glyph (they all need to be the same
// size!). Note that coordinates are relative to the parent bounding box.
nxgl_coord_t buttonX = 0;
nxgl_coord_t buttonY = m_radioButtonGroup->getHeight();
return m_radioButtonGroup->newRadioButton(buttonX, buttonY, m_size.w, m_size.h);
}
// (Re-)draw the buttons.
void CRadioButtonTest::showButtons(void)
{
m_radioButtonGroup->enable(); // Un-necessary, the widget is enabled by default
m_radioButtonGroup->enableDrawing();
m_radioButtonGroup->redraw();
}
// Push the radio button
void CRadioButtonTest::pushButton(CRadioButton *button)
{
// Get the button center coordinates
nxgl_coord_t buttonX = button->getX() + (button->getWidth() >> 1);
nxgl_coord_t buttonY = button->getY() + (button->getHeight() >> 1);
// Then push the button 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, buttonX, buttonY, 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_radioButtonGroup);
// Then inject the mouse release
(void)nx_mousein(handle, buttonX, buttonY, 0);
// And poll for more mouse events
m_widgetControl->pollEvents(m_radioButtonGroup);
// And re-draw the buttons (the mouse click event should have automatically
// triggered the re-draw)
//
// showButtons();
}
// Show the state of the radio button group
void CRadioButtonTest::showButtonState(void)
{
int index = m_radioButtonGroup->getSelectedIndex();
if (index < 0)
{
message("CRadioButtonTest::showButtonState No button is pressed\n");
}
else
{
message("CRadioButtonTest::showButtonState button%d is selected\n", index+1);
}
}

View File

@ -0,0 +1,152 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CRadioButton/cradiobuttontest.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_CRADIOBUTTON_CRADIOBUTTONTEST_HXX
#define __UNITTESTS_CRADIOBUTTON_CRADIOBUTTONTEST_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 "cradiobutton.hxx"
#include "cradiobuttongroup.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CRADIOBUTTONTEST_BGCOLOR
# define CONFIG_CRADIOBUTTONTEST_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 CRadioButtonTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
CRadioButtonGroup *m_radioButtonGroup; // The radio button group
// These are the dimensions that we will use for creating new radio buttons
struct nxgl_size_s m_size; // The size of each radio button
public:
// Constructor/destructors
CRadioButtonTest(void);
~CRadioButtonTest(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 buttons.
void showButtons(void);
// Create a CRadioButton instance. This method will show you how to create
// a CRadioButton widget
CRadioButton *newRadioButton(void);
// Simulate pushing and releasing of the radio button
void pushButton(CRadioButton *button);
// Show the state of the radio button group
void showButtonState(void);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CRADIOBUTTON_CRADIOBUTTONTEST_HXX

View File

@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CScrollbarHorizontal/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 = cscrollbarhorizontal_main.cxx cscrollbarhorizontaltest.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 = cscrollbarhorizontal
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

View File

@ -0,0 +1,231 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontal_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 "cscrollbarhorizontaltest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
#define MAX_SCROLLBAR 50
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static unsigned int g_mmInitial;
static unsigned int g_mmprevious;
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int cscrollbarhorizontal_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 cscrollbarhorizontal_main(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the checkbox test
message("cscrollbarhorizontal_main: Create CScrollbarHorizontalTest instance\n");
CScrollbarHorizontalTest *test = new CScrollbarHorizontalTest();
updateMemoryUsage(g_mmprevious, "After creating CScrollbarHorizontalTest");
// Connect the NX server
message("cscrollbarhorizontal_main: Connect the CScrollbarHorizontalTest instance to the NX server\n");
if (!test->connect())
{
message("cscrollbarhorizontal_main: Failed to connect the CScrollbarHorizontalTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cscrollbarhorizontal_main: After connecting to the server");
// Create a window to draw into
message("cscrollbarhorizontal_main: Create a Window\n");
if (!test->createWindow())
{
message("cscrollbarhorizontal_main: Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cscrollbarhorizontal_main: After creating a window");
// Create a scrollbar
message("cscrollbarhorizontal_main: Create a Scrollbar\n");
CScrollbarHorizontal *scrollbar = test->createScrollbar();
if (!scrollbar)
{
message("cscrollbarhorizontal_main: Failed to create a scrollbar\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cscrollbarhorizontal_main: After creating a scrollbar");
// Set the scrollbar minimum and maximum values
scrollbar->setMinimumValue(0);
scrollbar->setMaximumValue(MAX_SCROLLBAR);
scrollbar->setValue(0);
message("cscrollbarhorizontal_main: Scrollbar range %d->%d Initial value %d\n",
scrollbar->getMinimumValue(), scrollbar->getMaximumValue(),
scrollbar->getValue());
// Show the initial state of the checkbox
test->showScrollbar(scrollbar);
sleep(1);
// Now move the scrollbar up
for (int i = 0; i <= MAX_SCROLLBAR; i++)
{
scrollbar->setValue(i);
test->showScrollbar(scrollbar);
message("cscrollbarhorizontal_main: %d. New value %d\n", i, scrollbar->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, "cscrollbarhorizontal_main: After moving the scrollbar up");
// And move the scrollbar down
for (int i = MAX_SCROLLBAR; i >= 0; i--)
{
scrollbar->setValue(i);
test->showScrollbar(scrollbar);
message("cscrollbarhorizontal_main: %d. New value %d\n", i, scrollbar->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, "cscrollbarhorizontal_main: After moving the scrollbar down");
sleep(1);
// Clean up and exit
message("cscrollbarhorizontal_main: Clean-up and exit\n");
delete scrollbar;
updateMemoryUsage(g_mmprevious, "After deleting the scrollbar");
delete test;
updateMemoryUsage(g_mmprevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
return 0;
}

View File

@ -0,0 +1,225 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.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 "cscrollbarhorizontaltest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CScrollbarHorizontalTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CScrollbarHorizontalTest Constructor
CScrollbarHorizontalTest::CScrollbarHorizontalTest()
{
// Initialize state data
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CScrollbarHorizontalTest Descriptor
CScrollbarHorizontalTest::~CScrollbarHorizontalTest(void)
{
disconnect();
}
// Connect to the NX server
bool CScrollbarHorizontalTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CSCROLLBARHORIZONTALTEST_BGCOLOR))
{
message("CScrollbarHorizontalTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CScrollbarHorizontalTest::disconnect(void)
{
// 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 CScrollbarHorizontalTest::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("CScrollbarHorizontalTest::createWindow: Failed to create CBgWindow instance\n");
disconnect();
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CScrollbarHorizontalTest::createWindow: Failed to open background window\n");
disconnect();
return false;
}
return true;
}
// Create a scrollbar in the center of the window
CScrollbarHorizontal *CScrollbarHorizontalTest::createScrollbar(void)
{
// Get the size of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CScrollbarHorizontalTest::createScrollbar: Failed to get window size\n");
disconnect();
return false;
}
// Put the scrollbar in the center of the display
nxgl_coord_t scrollbarWidth = windowSize.w >> 1;
nxgl_coord_t scrollbarX = windowSize.w >> 2;
nxgl_coord_t scrollbarHeight = 10;
nxgl_coord_t scrollbarY = (windowSize.h - scrollbarHeight) >> 1;
// Create the scrollbar
CScrollbarHorizontal *scrollbar =
new CScrollbarHorizontal(m_widgetControl,
scrollbarX, scrollbarY,
scrollbarWidth, scrollbarHeight);
if (!scrollbar)
{
printf("CScrollbarHorizontalTest::createScrollbar: Failed to create CScrollbarHorizontal\n");
disconnect();
}
return scrollbar;
}
// (Re-)draw the scrollbar.
void CScrollbarHorizontalTest::showScrollbar(CScrollbarHorizontal *scrollbar)
{
scrollbar->enable(); // Un-necessary, the widget is enabled by default
scrollbar->enableDrawing();
scrollbar->redraw();
}

View File

@ -0,0 +1,137 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.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_CSCROLLBARHORIZONTAL_CSCROLLBARHORIZONTALTEST_HXX
#define __UNITTESTS_CSCROLLBARHORIZONTAL_CSCROLLBARHORIZONTALTEST_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 "cscrollbarhorizontal.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CSCROLLBARHORIZONTALTEST_BGCOLOR
# define CONFIG_CSCROLLBARHORIZONTALTEST_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 CScrollbarHorizontalTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CScrollbarHorizontalTest(void);
~CScrollbarHorizontalTest(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 scrollbar in the center of the window
CScrollbarHorizontal *createScrollbar(void);
// (Re-)draw the scrollbar.
void showScrollbar(CScrollbarHorizontal *scrollbar);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CSCROLLBARHORIZONTAL_CSCROLLBARHORIZONTALTEST_HXX

View File

@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CScrollbarVertical/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 = cscrollbarvertical_main.cxx cscrollbarverticaltest.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 = cscrollbarvertical
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: 31 KiB

View File

@ -0,0 +1,231 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CScrollbarVertical/cscrollbarvertical_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 "cscrollbarverticaltest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
#define MAX_SCROLLBAR 20
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static unsigned int g_mmInitial;
static unsigned int g_mmprevious;
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int cscrollbarvertical_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 cscrollbarvertical_main(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the checkbox test
message("cscrollbarvertical_main: Create CScrollbarVerticalTest instance\n");
CScrollbarVerticalTest *test = new CScrollbarVerticalTest();
updateMemoryUsage(g_mmprevious, "After creating CScrollbarVerticalTest");
// Connect the NX server
message("cscrollbarvertical_main: Connect the CScrollbarVerticalTest instance to the NX server\n");
if (!test->connect())
{
message("cscrollbarvertical_main: Failed to connect the CScrollbarVerticalTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cscrollbarvertical_main: After connecting to the server");
// Create a window to draw into
message("cscrollbarvertical_main: Create a Window\n");
if (!test->createWindow())
{
message("cscrollbarvertical_main: Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cscrollbarvertical_main: After creating a window");
// Create a scrollbar
message("cscrollbarvertical_main: Create a Scrollbar\n");
CScrollbarVertical *scrollbar = test->createScrollbar();
if (!scrollbar)
{
message("cscrollbarvertical_main: Failed to create a scrollbar\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cscrollbarvertical_main: After creating a scrollbar");
// Set the scrollbar minimum and maximum values
scrollbar->setMinimumValue(0);
scrollbar->setMaximumValue(MAX_SCROLLBAR);
scrollbar->setValue(0);
message("cscrollbarvertical_main: Scrollbar range %d->%d Initial value %d\n",
scrollbar->getMinimumValue(), scrollbar->getMaximumValue(),
scrollbar->getValue());
// Show the initial state of the checkbox
test->showScrollbar(scrollbar);
sleep(1);
// Now move the scrollbar up
for (int i = 0; i <= MAX_SCROLLBAR; i++)
{
scrollbar->setValue(i);
test->showScrollbar(scrollbar);
message("cscrollbarvertical_main: %d. New value %d\n", i, scrollbar->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, "cscrollbarvertical_main: After moving the scrollbar up");
// And move the scrollbar down
for (int i = MAX_SCROLLBAR; i >= 0; i--)
{
scrollbar->setValue(i);
test->showScrollbar(scrollbar);
message("cscrollbarvertical_main: %d. New value %d\n", i, scrollbar->getValue());
usleep(5000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, "cscrollbarvertical_main: After moving the scrollbar down");
sleep(1);
// Clean up and exit
message("cscrollbarvertical_main: Clean-up and exit\n");
delete scrollbar;
updateMemoryUsage(g_mmprevious, "After deleting the scrollbar");
delete test;
updateMemoryUsage(g_mmprevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
return 0;
}

View File

@ -0,0 +1,225 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.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 "cscrollbarverticaltest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CScrollbarVerticalTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CScrollbarVerticalTest Constructor
CScrollbarVerticalTest::CScrollbarVerticalTest()
{
// Initialize state data
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CScrollbarVerticalTest Descriptor
CScrollbarVerticalTest::~CScrollbarVerticalTest(void)
{
disconnect();
}
// Connect to the NX server
bool CScrollbarVerticalTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CSCROLLBARVERTICALTEST_BGCOLOR))
{
message("CScrollbarVerticalTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CScrollbarVerticalTest::disconnect(void)
{
// 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 CScrollbarVerticalTest::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("CScrollbarVerticalTest::createWindow: Failed to create CBgWindow instance\n");
disconnect();
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CScrollbarVerticalTest::createWindow: Failed to open background window\n");
disconnect();
return false;
}
return true;
}
// Create a scrollbar in the center of the window
CScrollbarVertical *CScrollbarVerticalTest::createScrollbar(void)
{
// Get the size of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CScrollbarVerticalTest::createScrollbar: Failed to get window size\n");
disconnect();
return false;
}
// Put the scrollbar in the center of the display
nxgl_coord_t scrollbarWidth = 10;
nxgl_coord_t scrollbarX = (windowSize.w - scrollbarWidth) >> 1;
nxgl_coord_t scrollbarHeight = windowSize.h >> 1;
nxgl_coord_t scrollbarY = windowSize.h >> 2;
// Create the scrollbar
CScrollbarVertical *scrollbar =
new CScrollbarVertical(m_widgetControl,
scrollbarX, scrollbarY,
scrollbarWidth, scrollbarHeight);
if (!scrollbar)
{
printf("CScrollbarVerticalTest::createScrollbar: Failed to create CScrollbarVertical\n");
disconnect();
}
return scrollbar;
}
// (Re-)draw the scrollbar.
void CScrollbarVerticalTest::showScrollbar(CScrollbarVertical *scrollbar)
{
scrollbar->enable(); // Un-necessary, the widget is enabled by default
scrollbar->enableDrawing();
scrollbar->redraw();
}

View File

@ -0,0 +1,137 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.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_CSCROLLBARVERTICAL_CSCROLLBARVERTICALTEST_HXX
#define __UNITTESTS_CSCROLLBARVERTICAL_CSCROLLBARVERTICALTEST_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 "cscrollbarvertical.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CSCROLLBARVERTICALTEST_BGCOLOR
# define CONFIG_CSCROLLBARVERTICALTEST_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 CScrollbarVerticalTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CScrollbarVerticalTest(void);
~CScrollbarVerticalTest(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 scrollbar in the center of the window
CScrollbarVertical *createScrollbar(void);
// (Re-)draw the scrollbar.
void showScrollbar(CScrollbarVertical *scrollbar);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CSCROLLBARVERTICAL_CSCROLLBARVERTICALTEST_HXX

View File

@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CSliderHorizontal/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 = csliderhorizontal_main.cxx csliderhorizontaltest.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 = csliderhorizontal
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: 21 KiB

View File

@ -0,0 +1,231 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CSliderHorizontal/csliderhorizontal_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 "csliderhorizontaltest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
#define MAX_SLIDER 50
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static unsigned int g_mmInitial;
static unsigned int g_mmprevious;
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int csliderhorizontal_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 csliderhorizontal_main(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the checkbox test
message("csliderhorizontal_main: Create CSliderHorizontalTest instance\n");
CSliderHorizontalTest *test = new CSliderHorizontalTest();
updateMemoryUsage(g_mmprevious, "After creating CSliderHorizontalTest");
// Connect the NX server
message("csliderhorizontal_main: Connect the CSliderHorizontalTest instance to the NX server\n");
if (!test->connect())
{
message("csliderhorizontal_main: Failed to connect the CSliderHorizontalTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "csliderhorizontal_main: After connecting to the server");
// Create a window to draw into
message("csliderhorizontal_main: Create a Window\n");
if (!test->createWindow())
{
message("csliderhorizontal_main: Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "csliderhorizontal_main: After creating a window");
// Create a slider
message("csliderhorizontal_main: Create a Slider\n");
CSliderHorizontal *slider = test->createSlider();
if (!slider)
{
message("csliderhorizontal_main: Failed to create a slider\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "csliderhorizontal_main: After creating a slider");
// Set the slider minimum and maximum values
slider->setMinimumValue(0);
slider->setMaximumValue(MAX_SLIDER);
slider->setValue(0);
message("csliderhorizontal_main: Slider range %d->%d Initial value %d\n",
slider->getMinimumValue(), slider->getMaximumValue(),
slider->getValue());
// Show the initial state of the checkbox
test->showSlider(slider);
sleep(1);
// Now move the slider up
for (int i = 0; i <= MAX_SLIDER; i++)
{
slider->setValue(i);
test->showSlider(slider);
message("csliderhorizontal_main: %d. New value %d\n", i, slider->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, "csliderhorizontal_main: After moving the slider up");
// And move the slider down
for (int i = MAX_SLIDER; i >= 0; i--)
{
slider->setValue(i);
test->showSlider(slider);
message("csliderhorizontal_main: %d. New value %d\n", i, slider->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, "csliderhorizontal_main: After moving the slider down");
sleep(1);
// Clean up and exit
message("csliderhorizontal_main: Clean-up and exit\n");
delete slider;
updateMemoryUsage(g_mmprevious, "After deleting the slider");
delete test;
updateMemoryUsage(g_mmprevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
return 0;
}

View File

@ -0,0 +1,224 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CSliderHorizontal/csliderhorizontaltest.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 "csliderhorizontaltest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CSliderHorizontalTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CSliderHorizontalTest Constructor
CSliderHorizontalTest::CSliderHorizontalTest()
{
// Initialize state data
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CSliderHorizontalTest Descriptor
CSliderHorizontalTest::~CSliderHorizontalTest(void)
{
disconnect();
}
// Connect to the NX server
bool CSliderHorizontalTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CSLIDERHORIZONTALTEST_BGCOLOR))
{
message("CSliderHorizontalTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CSliderHorizontalTest::disconnect(void)
{
// 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 CSliderHorizontalTest::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("CSliderHorizontalTest::createWindow: Failed to create CBgWindow instance\n");
disconnect();
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CSliderHorizontalTest::createWindow: Failed to open background window\n");
disconnect();
return false;
}
return true;
}
// Create a slider in the center of the window
CSliderHorizontal *CSliderHorizontalTest::createSlider(void)
{
// Get the size of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CSliderHorizontalTest::createSlider: Failed to get window size\n");
disconnect();
return false;
}
// Put the slider in the center of the display
nxgl_coord_t sliderWidth = windowSize.w >> 1;
nxgl_coord_t sliderX = windowSize.w >> 2;
nxgl_coord_t sliderHeight = 10;
nxgl_coord_t sliderY = (windowSize.h - sliderHeight) >> 1;
// Create the slider
CSliderHorizontal *slider = new CSliderHorizontal(m_widgetControl,
sliderX, sliderY,
sliderWidth, sliderHeight);
if (!slider)
{
printf("CSliderHorizontalTest::createSlider: Failed to create CSliderHorizontal\n");
disconnect();
}
return slider;
}
// (Re-)draw the slider.
void CSliderHorizontalTest::showSlider(CSliderHorizontal *slider)
{
slider->enable(); // Un-necessary, the widget is enabled by default
slider->enableDrawing();
slider->redraw();
}

View File

@ -0,0 +1,137 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CSliderHorizontal/csliderhorizontaltest.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_CSLIDERHORIZONTAL_CSLIDERHORIZONTALTEST_HXX
#define __UNITTESTS_CSLIDERHORIZONTAL_CSLIDERHORIZONTALTEST_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 "csliderhorizontal.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CSLIDERHORIZONTALTEST_BGCOLOR
# define CONFIG_CSLIDERHORIZONTALTEST_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 CSliderHorizontalTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CSliderHorizontalTest(void);
~CSliderHorizontalTest(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 slider in the center of the window
CSliderHorizontal *createSlider(void);
// (Re-)draw the slider.
void showSlider(CSliderHorizontal *slider);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CSLIDERHORIZONTAL_CSLIDERHORIZONTALTEST_HXX

View File

@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CSliderVertical/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 = cslidervertical_main.cxx csliderverticaltest.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 = cslidervertical
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: 19 KiB

View File

@ -0,0 +1,231 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CSliderVertical/cslidervertical_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 "csliderverticaltest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
#define MAX_SLIDER 50
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static unsigned int g_mmInitial;
static unsigned int g_mmprevious;
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int cslidervertical_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 cslidervertical_main(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the checkbox test
message("cslidervertical_main: Create CSliderVerticalTest instance\n");
CSliderVerticalTest *test = new CSliderVerticalTest();
updateMemoryUsage(g_mmprevious, "After creating CSliderVerticalTest");
// Connect the NX server
message("cslidervertical_main: Connect the CSliderVerticalTest instance to the NX server\n");
if (!test->connect())
{
message("cslidervertical_main: Failed to connect the CSliderVerticalTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cslidervertical_main: After connecting to the server");
// Create a window to draw into
message("cslidervertical_main: Create a Window\n");
if (!test->createWindow())
{
message("cslidervertical_main: Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cslidervertical_main: After creating a window");
// Create a slider
message("cslidervertical_main: Create a Slider\n");
CSliderVertical *slider = test->createSlider();
if (!slider)
{
message("cslidervertical_main: Failed to create a slider\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "cslidervertical_main: After creating a slider");
// Set the slider minimum and maximum values
slider->setMinimumValue(0);
slider->setMaximumValue(MAX_SLIDER);
slider->setValue(0);
message("cslidervertical_main: Slider range %d->%d Initial value %d\n",
slider->getMinimumValue(), slider->getMaximumValue(),
slider->getValue());
// Show the initial state of the checkbox
test->showSlider(slider);
sleep(1);
// Now move the slider up
for (int i = 0; i <= MAX_SLIDER; i++)
{
slider->setValue(i);
test->showSlider(slider);
message("cslidervertical_main: %d. New value %d\n", i, slider->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, "cslidervertical_main: After moving the slider up");
// And move the slider down
for (int i = MAX_SLIDER; i >= 0; i--)
{
slider->setValue(i);
test->showSlider(slider);
message("cslidervertical_main: %d. New value %d\n", i, slider->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, "cslidervertical_main: After moving the slider down");
sleep(1);
// Clean up and exit
message("cslidervertical_main: Clean-up and exit\n");
delete slider;
updateMemoryUsage(g_mmprevious, "After deleting the slider");
delete test;
updateMemoryUsage(g_mmprevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
return 0;
}

View File

@ -0,0 +1,225 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CSliderVertical/csliderverticaltest.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.
// modify this software without notice.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// 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 "csliderverticaltest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CSliderVerticalTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CSliderVerticalTest Constructor
CSliderVerticalTest::CSliderVerticalTest()
{
// Initialize state data
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CSliderVerticalTest Descriptor
CSliderVerticalTest::~CSliderVerticalTest(void)
{
disconnect();
}
// Connect to the NX server
bool CSliderVerticalTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CSLIDERVERTICALTEST_BGCOLOR))
{
message("CSliderVerticalTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CSliderVerticalTest::disconnect(void)
{
// 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 CSliderVerticalTest::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("CSliderVerticalTest::createWindow: Failed to create CBgWindow instance\n");
disconnect();
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CSliderVerticalTest::createWindow: Failed to open background window\n");
disconnect();
return false;
}
return true;
}
// Create a slider in the center of the window
CSliderVertical *CSliderVerticalTest::createSlider(void)
{
// Get the size of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CSliderVerticalTest::createSlider: Failed to get window size\n");
disconnect();
return false;
}
// Put the slider in the center of the display
nxgl_coord_t sliderWidth = 10;
nxgl_coord_t sliderX = (windowSize.w - sliderWidth) >> 1;
nxgl_coord_t sliderHeight = windowSize.h >> 1;
nxgl_coord_t sliderY = windowSize.h >> 2;
// Create the slider
CSliderVertical *slider = new CSliderVertical(m_widgetControl,
sliderX, sliderY,
sliderWidth, sliderHeight);
if (!slider)
{
printf("CSliderVerticalTest::createSlider: Failed to create CSliderVertical\n");
disconnect();
}
return slider;
}
// (Re-)draw the slider.
void CSliderVerticalTest::showSlider(CSliderVertical *slider)
{
slider->enable(); // Un-necessary, the widget is enabled by default
slider->enableDrawing();
slider->redraw();
}

View File

@ -0,0 +1,137 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CSliderVertical/csliderverticaltest.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_CSLIDERVERTICAL_CSLIDERVERTICALTEST_HXX
#define __UNITTESTS_CSLIDERVERTICAL_CSLIDERVERTICALTEST_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 "cslidervertical.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CSLIDERVERTICALTEST_BGCOLOR
# define CONFIG_CSLIDERVERTICALTEST_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 CSliderVerticalTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CSliderVerticalTest(void);
~CSliderVerticalTest(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 slider in the center of the window
CSliderVertical *createSlider(void);
// (Re-)draw the slider.
void showSlider(CSliderVertical *slider);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CSLIDERVERTICAL_CSLIDERVERTICALTEST_HXX

View File

@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CTextBox/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 = ctextbox_main.cxx ctextboxtest.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 = ctextbox
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: 44 KiB

View File

@ -0,0 +1,141 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CTextBox/ctextbox_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 "ctextboxtest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static const char string1[] = "Johhn ";
static const char string2[] = "\b\b\bn Doe\r";
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int ctextbox_main(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int ctextbox_main(int argc, char *argv[])
{
// Create an instance of the font test
printf("ctextbox_main: Create CTextBoxTest instance\n");
CTextBoxTest *test = new CTextBoxTest();
// Connect the NX server
printf("ctextbox_main: Connect the CTextBoxTest instance to the NX server\n");
if (!test->connect())
{
printf("ctextbox_main: Failed to connect the CTextBoxTest instance to the NX server\n");
delete test;
return 1;
}
// Create a window to draw into
printf("ctextbox_main: Create a Window\n");
if (!test->createWindow())
{
printf("ctextbox_main: Failed to create a window\n");
delete test;
return 1;
}
// Create a CTextBox instance
CTextBox *textbox = test->createTextBox();
if (!textbox)
{
printf("ctextbox_main: Failed to create a text box\n");
delete test;
return 1;
}
// Show the text box
test->showTextBox(textbox);
// Wait a bit, then inject a string with a typo
sleep(1);
test->injectChars(textbox, sizeof(string1), (FAR const uint8_t*)string1);
// Now fix the string with backspaces and finish it correctly
usleep(500*1000);
test->injectChars(textbox, sizeof(string2), (FAR const uint8_t*)string2);
// Clean up and exit
sleep(2);
printf("ctextbox_main: Clean-up and exit\n");
delete textbox;
delete test;
return 0;
}

View File

@ -0,0 +1,287 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CTextBox/ctextboxtest.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 <unistd.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "ctextboxtest.hxx"
#include "cbgwindow.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CTextBoxTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CTextBoxTest Constructor
CTextBoxTest::CTextBoxTest()
{
m_bgWindow = (CBgWindow *)NULL;
m_nxFont = (CNxFont *)NULL;
m_text = (CNxString *)NULL;
}
// CTextBoxTest Descriptor
CTextBoxTest::~CTextBoxTest()
{
disconnect();
}
// Connect to the NX server
bool CTextBoxTest::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("CTextBoxTest::connect: Failed to create the default font\n");
}
// Set the background color
if (!setBackgroundColor(CONFIG_CTEXTBOXTEST_BGCOLOR))
{
printf("CTextBoxTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CTextBoxTest::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 CTextBoxTest::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("CTextBoxTest::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("CTextBoxTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CTextBox instance
CTextBox *CTextBoxTest::createTextBox(void)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CTextBoxTest::createGraphics: Failed to get window size\n");
return (CTextBox *)NULL;
}
// Create an empty CNxString instance to contain the C string
m_text = new CNxString();
// Get the height and width of the text display area. The width
// is half of the display width and the height is optimized for
// the font height
nxgl_coord_t textBoxWidth = windowSize.w >> 1;
nxgl_coord_t textBoxHeight = (nxgl_coord_t)m_nxFont->getHeight();
// The default CTextBox has borders enabled with thickness of one.
// Add twice the thickness of the border to the height.
textBoxHeight += 2 * 1;
// Pick an X/Y position such that the label will be centered in the display
nxgl_coord_t labelX = windowSize.w >> 2;
nxgl_coord_t labelY = (windowSize.h - textBoxHeight) >> 1;
// Now we have enough information to create the label
return new CTextBox(m_widgetControl, labelX, labelY, textBoxWidth, textBoxHeight, *m_text);
}
// Draw the label
void CTextBoxTest::showTextBox(CTextBox *label)
{
label->enable();
label->enableDrawing();
label->redraw();
}
// Inject simulated keyboard characters into NX.
void CTextBoxTest::injectChars(CTextBox *textbox, int nCh, FAR const uint8_t *string)
{
// nx_kbdin is meant to be called by keyboard handling software.
// Here we just inject the string under unit test control.
// 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 keyboard interface
NXHANDLE handle = getServer();
// The widget must have focus to receive keyboard input
m_widgetControl->setFocusedWidget(textbox);
// Inject the string one character at a time to get a more realistic
// simulation of keyboard behavior. Note the API nx_kbdin() could
// be used to inject the string in its entirety.
for (int i = 0; i < nCh; i++)
{
// Inject the next character
(void)nx_kbdchin(handle, string[i]);
// Widget events are normally handled in a modal loop.
// However, for this case we know when there should be keyboard events pending,
// events so we don't have to poll repeatedly. We can just perform a one pass
// poll
m_widgetControl->pollEvents(textbox);
// Sleep a bit, just for the effect (this also gives the X server loop a
// chance to run in the simulated environment.
usleep(500*1000);
}
}

View File

@ -0,0 +1,142 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CTextBox/ctextboxtest.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_CTEXTBOX_CTEXTBOXTEST_HXX
#define __UNITTESTS_CTEXTBOX_CTEXTBOXTEST_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"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CTEXTBOXTEST_BGCOLOR
# define CONFIG_CTEXTBOXTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR
#endif
#ifndef CONFIG_CTEXTBOXTEST_FONTCOLOR
# define CONFIG_CTEXTBOXTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CTextBoxTest : 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
CTextBoxTest();
~CTextBoxTest();
// 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 CTextBox instance. This method will show you how to create
// a CTextBox widget
CTextBox *createTextBox(void);
// Draw the label. This method illustrates how to draw the CTextBox widget.
void showTextBox(CTextBox *label);
// Inject simulated keyboard characters into NX.
void injectChars(CTextBox *textbox, int nCh, FAR const uint8_t *string);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CTEXTBOX_CTEXTBOXTEST_HXX

View File

@ -0,0 +1,418 @@
README
======
This directory contains a collection of Unit Tests that can be used to verify
NXWidgets.:
Contents
========
o Installing and Building the Unit Tests
1. Setup NuttX
a) Configure NuttX
b) Enable C++ Support
c) Enable Debug Options
d) Other Possible nuttx/.config changes
e) Other Possible apps/.config changes
2. Configure in the Selected Unit Test
o Work-Arounds
1. Build Issues
2. Stack Size Issues with the X11 Simulation
o Theory of Operation
o Unit Test Directories
o Example
Installing and Building the Unit Tests
======================================
1. Setup NuttX
a) Configure NuttX
Configure NuttX to run one of the target configurations. For example,
let's assume that you are using the sim/nsh2 configuration. The sim/nsh2
configuration was specially created for use NXWidgets on the simulation
platform. A similar, special configuration stm3210e-eval/nsh2 is also
for the STM3210E-EVAL available. However, the unit test can be run on
other configurations (see steps d and e below).
NOTE: There are some other special configurationsrecommended for unit-leveling
testing of NxWM because the configuration is more complex in that case. These
are:
1) sim/nxwmm, or the simulated platform (no touchscreen), and
2) stm3240g-evel, for the STM3240G-EVAL board (with the STMPE11 touchscreen)
We will assume the sim/nsh2 configuration in this discussion. The
sim/nsh2 configuration is installed as follows:
cd <nuttx-directory-path>
make distclean
cd tools
./configure.sh sim/nsh2
Where:
<nuttx-directory-path> is the full, absolute path to the NuttX build directory
If you are using the sim/nsh2 or stm3210e-eval configurations, then skip
to step 2 (Hmmm.. better check 1d) too).
There may be certain requirements for the configuration that you select...
for example, certain widget tests may require touchscreen support or special
font selections. These test-specific requirements are addressed below under
"Unit Test Directories"
b) Enable C++ Support
If you are not using the sim/nsh2 or stm3210e-eval, you will need to add
the following definitions to the nuttx configuration at nuttx/.config to
enable C++ support:
CONFIG_HAVE_CXX=y
Check first, some configurations already have C++ support enabled (As of this
writing *ONLY* the sim/nsh2 and stm321-e-eval configurations have C++ support
pre-enabled).
c) Enable Debug Options
If you are running on a simulated target, then you might also want to
enable debug symbols:
CONFIG_DEBUG_SYMBOLS=y
Then you can run the simulation using GDB or DDD which is a very powerful
debugging environment!
d) Special configuration requirements for the nxwm unit test:
CONFIG_NXCONSOLE=y
CONFIG_NX_MULTIUSER=y
e) Other nuttx/.config changes -- NSH configurations only.
If the configuration that you are using supports NSH and NSH built-in tasks
then all is well. If it is an NSH configuration, then you will have to define
the following in your nuttx/.config file as well (if it is not already defined):
CONFIG_NSH_BUILTIN_APPS=y
sim/nsh2 and stm3210e-eval/nsh2 already has this setting. You do not need
to change anything further in the nuttx/.config file if you are using either
of these configurations.
f) Other apps/.config changes -- NON-NSH configurations only.
For non-NSH configurations (such as the sim/touchscreen) you will have to
remove the CONFIGURED_APPS seting that contains the user_start function so
that you use the user_start in the unit test code instead. So, for example,
with the sim/touchscreen configuration you need to remove the following from
the apps/.config file:
CONFIGURED_APPS += examples/<example> ## REMOVE
The following step will then install the new, correct directory containing
the user_start function for the selected unit test. If you see that NSH
is configured:
CONFIGURED_APPS += examples/nsh ## DO NOT REMOVE
Then DO NOT REMOVE the CONFIGURED_APPS setting. Go back and re-read c)
above. Do either c) or d). Don't do both!
sim/nsh2 and stm3210e-eval/nsh2 both NSH configurations. You do not need
to change anything further in the apps/.config file for any NSH configuration.
2. Configure/Install the Selected Unit Test
Then reconfigure that to use the Unit Test of your choice:
cd <nxwidgets-directory>/tools
./install.sh <apps-directory-path> <test-sub-directory>
Where:
<apps-directory-path> is the full, absolute path to the NuttX apps/ directory
<test-sub-directory> is the name of a sub-directory in the UnitTests directory
3. Instantiate the Configuration
Before we can make the NXWidgets Library, we have to instantiate the NuttX
configuration with the installed unit test:
cd <nuttx-directory-path>
. ./setenv.sh
make context
This will create auto-generated files and will setup symbolic links needed
in order to build the NXWidgets Library.
4. Adjust the Stack Size
If using an simulation configuration (like sim/nsh2) and your unit test
uses X11 as its display device, then you would have to increase the size
of unit test stack as described below under "Stack Size Issues with the
X11 Simulation."
5. Build the NXWidgets Library
cd <nxwidgets-directory>/libnxwidgets
make TOPDIR=<nuttx-directory-path>
6. Build the NxWM library.
The NxWM library (libnxwm.a) is required only for the NxWM unit test at
NxWidgets/UnitTests/nxwm. For other unit tests, skip to step 7.
cd <nxwidgets-directory>/nxwm
make TOPDIR=<nuttx-directory-path>
7. Build NuttX including the unit test and the NXWidgets library
cd <nuttx-directory-path>
. ./setenv.sh
make
Work-Arounds
============
Build Issues
------------
1. I have seen this error on Cygwin building C++ code:
LD: nuttx.rel
ld: skipping incompatible /home/patacongo/projects/nuttx/nuttx/trunk/nuttx/libxx//liblibxx.a when searching for -llibxx
ld: cannot find -llibxx
The problem seems to be caused because gcc build code for 32-bit mode and g++ builds code for 64-bit mode. Add the -m32 option to the g++ command line seems to fix the problem. In Make.defs:
CXXFLAGS = -m32 $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) \
$(ARCHCPUFLAGSXX) $(ARCHINCLUDESXX) $(ARCHDEFINES) $(EXTRADEFINES) -pipe
2. Stack Size Issues with the X11 Simulation
When you run the NuttX simulation, it uses stacks allocated by NuttX from the
NuttX heap. The memory management model is exactly the same in the simulation
as it is real, target system. This is good because this produces a higher
fidelity simulation.
However, when the simulation calls into Linux/Cygwin libraries, it will still
use these small simulation stacks. This happens, for example, when you call
into the system to get and put characters to the console window or when you
make x11 calls into the system. The programming model within those libraries
will assume a Linux/Cygwin environment where the stack size grows dynamically
As a consequence, those system libraries may allocate large data structures
on the stack and overflow the small NuttX stacks. X11, in particular,
requires large stacks. If you are using X11 in the simulation, make sure
that you set aside a "lot" of stack for the X11 system calls (maybe 8 or 16Kb).
The stack size for the thread that begins with user start is controlled
by the configuration setting CONFIG_USERMAIN_STACKSIZE; you may need to
increase this value to larger number to survive the X11 system calls.
If you are running X11 applications as NSH add-on programs, then the stack
size of the add-on program is controlled in another way. Here are the
steps for increasing the stack size in that case:
cd ../apps/namedapps # Go to the namedapps directory
vi namedapps_list.h # Edit this file and increase the stack size of the add-on
rm .built *.o # This will force the namedapps logic to rebuild
Theory Of Operation
===================
The NuttX application Makefile at apps/Makefile has some special hooks for
building "external" applications. In particular, it will automatically
build in the contents any directory call "external/" that may appear in the
apps/ directory. There is no external/ directory in the repository. Rather,
this directory may be provided by the user (possibly as a symbolic link) to
add libraries and applications to the standard build from the repository.
The script at tools/install.sh, then, just does a lot of careful validation and
sanity checking. Then it installs the UnitTest test sub-directory in the apps/
directory by creating a symbolic link in the apps/ directory call "external".
That symbolic link will refer to the selected UnitTest sub-directory.
UnitTests
=========
The following provide simple unit tests for each of the NXWidgets. In
addition, these unit tests provide examples for the use of each widget
type.
CButton
Exercises the CButton widget
Depends on CLabel
CButtonArray
Exercises the CButtonArray widget
CCheckBox
Exercises the CCheckBox widget
Depends on CLabel and CButton.
CGlyphButton
Exercises the CGlyphButton widget.
Depends on CLabel and CButton.
CImage
Exercises the CImage widget
CLabel
Exercises the CLabel widget
CProgressBar
Exercises the CProgressBar widget
CRadioButton
Exercises the CRadioButton and CRadioButtonGroup widgets.
Depends on CLabel and CButton
CScrollBarHorizontal
Exercises the ScrollbarHorizontal
Depends on CSliderHorizontal and CGlyphButton
CScrollBarVertical
Exercises the ScrollbarHorizontal
Depends on CSliderVertical and CGlyphButton
CSliderHorizontal
Exercises the CSliderHorizontal
Depends on CSliderHorizontalGrip
CSliderVertical
Exercises the CSliderVertical
Depends on CSliderVerticalGrip
CTextBox
Exercises the CTextBox widget
Depends on CLabel
nxwm
Exercises the NxWM window manager.
Use the special configurations nuttx/configs/sim/nxwm or nuttx/configs/stm3240g-eval/nxwm.
Example
=======
1. Configure sim/nsh2
Where: nuttx and nuttx/tools directory
$ cd tools/
$ ./configure.sh sim/nsh2
$ cd -
2. Edit nuttx/.config to enable C++ support
Do nothing... sim/nsh2 already has C++ support enabled.
3. Install the CButton C++ application (for example)
Where: <nxwidgets-directory>/tool
$ ./install.sh ~/projects/nuttx/nuttx/trunk/apps/ CButton
/home/patacongo/projects/nuttx/nuttx/trunk/apps//external already exists...
Removing the old symbolic link.
Creating symbolic link
- To /home/patacongo/projects/nuttx/nuttx/trunk/NxWidgets/UnitTests/CButton
- At /home/patacongo/projects/nuttx/nuttx/trunk/apps//external
4. Instantiate the Configuration
Where: nuttx directory
$ cd /home/patacongo/projects/nuttx/nuttx/trunk/nuttx
$ . ./setenv.sh
$ make context
This will create auto-generated files and will setup symbolic links needed
in order to build the NXWidgets Library.
6. Adjust the Stack Size
If using an simulation configuration (like sim/nsh2) and your unit test
uses X11 as its display device, then you would have to increase the size
of unit test stack as described above under "Stack Size Issues."
7. Build the NXWdigets Library
Where <nxwidgets-directory>/libnxwidgets
$ cd /home/patacongo/projects/nuttx/nuttx/trunk/NxWidgets/libnxwidgets
$ make TOPDIR=/home/patacongo/projects/nuttx/nuttx/trunk/nuttx
8. Build NuttX
Where: nuttx directory
$ cd /home/patacongo/projects/nuttx/nuttx/trunk/nuttx
$ make
...
8. Run the "bringup" task:
a. Start NuttX
Where: nuttx directory
./nuttx
NuttShell (NSH) NuttX-6.9
nsh>
b. Execute NuttX
Where: NSH command prompt
NOTE that when you run NSH as a simulation, the commands are echoed
twice -- once by Linux/Cygwin and once by NuttX:
nsh> help
help
...
Builtin Apps:
nx
nxhello
tc
bringup
nsh> bringup
bringup
bringup [2:128]
c. Then do a kludgy thing
Where: NSH command prompt
The I/O with the Linux/Cygwin simulation is blocking. So while NSH is
waiting for input nothing can run (see configs/sim/README.txt for more info).
One way to make NSH stop asking for input is to sleep.
nsh> sleep 10
sleep 10
NOTE 1: This is not a problem if CONFIG_SCHED_WAITPID is defined in the
configuration file. If CONFIG_SCHED_WAITPID is defined, NSH will wait
for the unit test to complete and it will not be necessary to sleep.
NOTE 2: CONFIG_SCHED_WAITPID is defined in the sim/nsh2 configuration
so you can probably ignore this kludgy thing.
d. The Unit Test runs
As soon as NSH sleeps, the unit test will run:
bringup_main: Saying hello from the dynamically constructed instance
CHelloWorld::HelloWorld: Hello, World!!
bringup_main: Saying hello from the instance constructed on the stack
CHelloWorld::HelloWorld: Hello, World!!
bringup_main: Saying hello from the statically constructed instance
CHelloWorld::HelloWorld: Hello, World!!
8. Debugging
Where: nuttx directory
In the simulation (only) you can use GDB or, better, the graphic
front-end DDD to debug the code. Most embedded targets do not
have good debugging capabilities.
In order to debug, you have to have build with CONFIG_DEBUG_SYMBOLS=y.
This setting is preselected in the sim/nsh2 configuration so that
you don't have to do anything.
Then under Linux or in a Cygwin X11 window, you can start the graphic
debugger like:
ddd nuttx &

View File

@ -0,0 +1,59 @@
NxWidgets Test Status
=====================
At this point, the NXWidgets GUI toolkit code complete but still not
completely tested. This is a list of testing issues that still need to be
addressed.
The following Widgets have been have completed unit testing. The level of
unit testing is, however, superficial. Many features have not yet been
tested:
- CLabel
- CTextBox
- CButton
- CButtonArray
- CKeypad
- CRadioButton (and CRadioButtonGoup)
- CGlyphButton
- CLatchButton (and CStickyButton)
- CLatchButtonArray (and CStickyButtonArray)
- CCheckBox
- CProgressBar
- CImage
- CSliderHorizontal (and CSliderHorizontalGrip)
- CSliderVertical (and CSliderVerticalGrip)
- CScrollBarHorizontal (except paging buttons)
- CScrollBarVertical (except paging buttons)
The following components have unit test in place, but do not successfully
pass the test:
- CListBox (and CListBoxDataItem) which also tests:
o CText
o CList and CListDataItem
o CScrollingPanel
The following no unit tests (and, hence, are probably non-functional):
Infrastructure (won't have their own unit tests)
- CScrollBarPanel
Widgets that need unit tests:
- CCycleButton
- CScrollingTextBox
- CMultiLineTextBox
- CScrollingListBox
There are things that require testing after all widgets complete their unit
tests as well. As examples:
- Need to verify that a screen with many widgets works correctly. That
focus is correctly handled when widgets are removed. etc.
- Need to verify that widget with many children work correctly together.
- Need to verfiy that a display with many windows with multiple wigets
per window works okay.
Most unit-level testing was performed in a simulated environment driven by
simulated mouse and keyboard input. So many features are not tested that
require human interaction ... such grabbing and dragging scrollbars.

View File

@ -0,0 +1,202 @@
#################################################################################
# NxWidgets/Unitests/nxwm/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
# Add the path to the NxWM include directory to the CFLAGS
NXWM_DIR="$(TESTDIR)/../../nxwm"
NXWM_INC="$(NXWM_DIR)/include"
NXWM_LIB="$(NXWM_DIR)/libnxwm$(LIBEXT)"
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWM_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWM_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWM_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWM_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# NxWM unit test
ASRCS =
CSRCS =
CXXSRCS = nxwm_main.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 = nxwm
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklibnxwidgets chklibnxwm
# 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
chklibnxwidgets:
@( \
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; \
)
# Verify that the NxWM library has been built
chklibnxwm:
@( \
if [ ! -e "$(NXWM_LIB)" ]; then \
echo "$(NXWM_LIB) does not exist."; \
echo "Please go to $(NXWM_LIB)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklibnxwidgets does the work.
$(NXWM_LIB): # Just to keep make happy. chklibnxwm does the work.
.built: chkcxx chklibnxwidgets chklibnxwm $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWM_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWM_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

View File

@ -0,0 +1,734 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/nxwm/nxwm_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/arch.h>
#include <cstdio>
#include <cstdlib>
#include <cunistd>
#include "ctaskbar.hxx"
#include "cstartwindow.hxx"
#include "cnxconsole.hxx"
#include "chexcalculator.hxx"
#ifdef CONFIG_NXWM_TOUCHSCREEN
# include "ctouchscreen.hxx"
# include "ccalibration.hxx"
#endif
#ifdef CONFIG_NXWM_KEYBOARD
# include "ckeyboard.hxx"
#endif
/////////////////////////////////////////////////////////////////////////////
// Pre-processor Definitions
/////////////////////////////////////////////////////////////////////////////
#ifdef CONFIG_HAVE_FILENAME
# define showTestStepMemory(msg) \
_showTestStepMemory((FAR const char*)__FILE__, (int)__LINE__, msg)
#endif
#ifdef CONFIG_NXWIDGET_MEMMONITOR
# ifdef CONFIG_HAVE_FILENAME
# define showTestCaseMemory(msg) \
_showTestCaseMemory((FAR const char*)__FILE__, (int)__LINE__, msg)
# define showTestMemory(msg) \
_showTestMemory((FAR const char*)__FILE__, (int)__LINE__, msg)
# endif
#else
# define initMemoryUsage()
# define showTestCaseMemory(msg)
# define showTestMemory(msg)
#endif
/////////////////////////////////////////////////////////////////////////////
// Private Types
/////////////////////////////////////////////////////////////////////////////
struct SNxWmTest
{
NxWM::CTaskbar *taskbar; // The task bar
NxWM::CStartWindow *startwindow; // The start window
#ifdef CONFIG_NXWM_TOUCHSCREEN
NxWM::CTouchscreen *touchscreen; // The touchscreen
struct NxWM::SCalibrationData calibData; // Calibration data
#endif
#ifdef CONFIG_NXWIDGET_MEMMONITOR
unsigned int mmInitial; // Initial memory usage
unsigned int mmStep; // Memory Usage at beginning of test step
unsigned int mmSubStep; // Memory Usage at beginning of test sub-step
#endif
};
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static struct SNxWmTest g_nxwmtest;
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int nxwm_main(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
#ifdef CONFIG_NXWIDGET_MEMMONITOR
#ifdef CONFIG_HAVE_FILENAME
static void updateMemoryUsage(unsigned int *previous,
FAR const char *file, int line,
FAR const char *msg)
#else
static void updateMemoryUsage(unsigned int *previous,
FAR const char *msg)
#endif
{
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 */
#ifdef CONFIG_HAVE_FILENAME
printf("File: %s Line: %d : %s\n", file, line, msg);
#else
printf("\n%s:\n", msg);
#endif
printf(" Before: %8u After: %8u Change: %8d\n",
*previous, mmcurrent.uordblks, (int)mmcurrent.uordblks - (int)*previous);
/* Set up for the next test */
*previous = mmcurrent.uordblks;
}
#endif
/////////////////////////////////////////////////////////////////////////////
// Name: showTestCaseMemory
/////////////////////////////////////////////////////////////////////////////
#ifdef CONFIG_NXWIDGET_MEMMONITOR
#ifdef CONFIG_HAVE_FILENAME
static void _showTestCaseMemory(FAR const char *file, int line, FAR const char *msg)
{
updateMemoryUsage(&g_nxwmtest.mmStep, file, line, msg);
g_nxwmtest.mmSubStep = g_nxwmtest.mmInitial;
}
#else
static void showTestCaseMemory(FAR const char *msg)
{
updateMemoryUsage(&g_nxwmtest.mmStep, msg);
g_nxwmtest.mmSubStep = g_nxwmtest.mmInitial;
}
#endif
#endif
/////////////////////////////////////////////////////////////////////////////
// Name: showTestMemory
/////////////////////////////////////////////////////////////////////////////
#ifdef CONFIG_NXWIDGET_MEMMONITOR
#ifdef CONFIG_HAVE_FILENAME
static void _showTestMemory(FAR const char *file, int line, FAR const char *msg)
{
updateMemoryUsage(&g_nxwmtest.mmInitial, file, line, msg);
}
#else
static void showTestMemory(FAR const char *msg)
{
updateMemoryUsage(&g_nxwmtest.mmInitial, msg);
}
#endif
#endif
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
#ifdef CONFIG_NXWIDGET_MEMMONITOR
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_nxwmtest.mmInitial = mmcurrent.uordblks;
g_nxwmtest.mmStep = mmcurrent.uordblks;
g_nxwmtest.mmSubStep = mmcurrent.uordblks;
}
#endif
/////////////////////////////////////////////////////////////////////////////
// Name: cleanup
/////////////////////////////////////////////////////////////////////////////
static void testCleanUpAndExit(int exitCode)
{
#ifdef CONFIG_NXWM_TOUCHSCREEN
if (g_nxwmtest.touchscreen)
{
delete g_nxwmtest.touchscreen;
}
#endif
// Delete the task bar then the start window. the order is important because
// we must bet all of the application references out of the task bar before
// deleting the start window. When the start window is deleted, it will
// also delete of of the resouces contained within the start window.
if (g_nxwmtest.taskbar)
{
delete g_nxwmtest.taskbar;
}
if (g_nxwmtest.startwindow)
{
delete g_nxwmtest.startwindow;
}
// And exit
exit(exitCode);
}
/////////////////////////////////////////////////////////////////////////////
// Name: createTaskbar
/////////////////////////////////////////////////////////////////////////////
static bool createTaskbar(void)
{
// Create an instance of the Task Bar.
//
// The general sequence for initializing the task bar is:
//
// 1. Create the CTaskbar instance,
// 2. Call the CTaskbar::connect() method to connect to the NX server (CTaskbar
// inherits the connect method from CNxServer),
// 3. Call the CTaskbar::initWindowManager() method to initialize the task bar.
// 3. Call CTaskBar::startApplication repeatedly to add applications to the task bar
// 4. Call CTaskBar::startWindowManager to start the display with applications in place
printf("createTaskbar: Create CTaskbar instance\n");
g_nxwmtest.taskbar = new NxWM::CTaskbar();
if (!g_nxwmtest.taskbar)
{
printf("createTaskbar: ERROR: Failed to instantiate CTaskbar\n");
return false;
}
showTestCaseMemory("createTaskbar: After create taskbar");
// Connect to the NX server
printf("createTaskbar: Connect CTaskbar instance to the NX server\n");
if (!g_nxwmtest.taskbar->connect())
{
printf("createTaskbar: ERROR: Failed to connect CTaskbar instance to the NX server\n");
return false;
}
showTestCaseMemory("createTaskbar: After connecting to the server");
// Initialize the task bar
//
// Taskbar::initWindowManager() prepares the task bar to receive applications.
// CTaskBar::startWindowManager() brings the window manager up with those applications
// in place.
printf("createTaskbar: Initialize CTaskbar instance\n");
if (!g_nxwmtest.taskbar->initWindowManager())
{
printf("createTaskbar: ERROR: Failed to intialize CTaskbar instance\n");
return false;
}
showTestCaseMemory("createTaskbar: After initializing window manager");
return true;
}
/////////////////////////////////////////////////////////////////////////////
// Name: createStartWindow
/////////////////////////////////////////////////////////////////////////////
static bool createStartWindow(void)
{
// Create the start window. The start window is unique among applications
// because it has no factory. The general sequence for setting up the
// start window is:
//
// 1. Create and open a CApplicationWindow
// 2. Use the window to create the CStartWindow the start window application
// 2. Call Cstartwindow::addApplication numerous times to install applications
// in the start window.
// 3. Call CTaskBar::startApplication (initially minimized) to start the start
// window application.
//
// NOTE: that the start window should not have a stop button.
NxWM::CApplicationWindow *window = g_nxwmtest.taskbar->openApplicationWindow(NxWM::CApplicationWindow::WINDOW_PERSISTENT);
if (!window)
{
printf("createStartWindow: ERROR: Failed to create CApplicationWindow\n");
return false;
}
showTestCaseMemory("createStartWindow: After creating CApplicationWindow");
// Open the window (it is hot in here)
if (!window->open())
{
printf("createStartWindow: ERROR: Failed to open CApplicationWindow \n");
delete window;
return false;
}
showTestCaseMemory("createStartWindow: After opening CApplicationWindow");
// Instantiate the application, providing the window to the application's
// constructor
g_nxwmtest.startwindow = new NxWM::CStartWindow(g_nxwmtest.taskbar, window);
if (!g_nxwmtest.startwindow)
{
gdbg("ERROR: Failed to instantiate CStartWindow\n");
delete window;
return false;
}
showTestCaseMemory("createStartWindow: After creating CStartWindow");
// Add the CStartWindow application to the task bar (minimized)
printf("createStartWindow: Start the start window application\n");
if (!g_nxwmtest.taskbar->startApplication(g_nxwmtest.startwindow, true))
{
printf("createStartWindow: ERROR: Failed to start the start window application\n");
return false;
}
showTestCaseMemory("createStartWindow: After starting the start window application");
return true;
}
/////////////////////////////////////////////////////////////////////////////
// Name: startWindowManager
/////////////////////////////////////////////////////////////////////////////
static bool startWindowManager(void)
{
// Start the window manager
printf("startWindowManager: Start the window manager\n");
if (!g_nxwmtest.taskbar->startWindowManager())
{
printf("startWindowManager: ERROR: Failed to start the window manager\n");
return false;
}
showTestCaseMemory("startWindowManager: After starting the window manager");
return true;
}
/////////////////////////////////////////////////////////////////////////////
// Name: createTouchScreen
/////////////////////////////////////////////////////////////////////////////
#ifdef CONFIG_NXWM_TOUCHSCREEN
static bool createTouchScreen(void)
{
// Get the physical size of the display in pixels
struct nxgl_size_s displaySize;
(void)g_nxwmtest.taskbar->getDisplaySize(displaySize);
// Create the touchscreen device
printf("createTouchScreen: Creating CTouchscreen\n");
g_nxwmtest.touchscreen = new NxWM::CTouchscreen(g_nxwmtest.taskbar, &displaySize);
if (!g_nxwmtest.touchscreen)
{
printf("createTouchScreen: ERROR: Failed to create CTouchscreen\n");
return false;
}
showTestCaseMemory("createTouchScreen: After creating CTouchscreen");
printf("createTouchScreen: Start touchscreen listener\n");
if (!g_nxwmtest.touchscreen->start())
{
printf("createTouchScreen: ERROR: Failed start the touchscreen listener\n");
delete g_nxwmtest.touchscreen;
return false;
}
showTestCaseMemory("createTouchScreen: After starting the touchscreen listener");
return true;
}
#endif
/////////////////////////////////////////////////////////////////////////////
// Name: createKeyboard
/////////////////////////////////////////////////////////////////////////////
#ifdef CONFIG_NXWM_KEYBOARD
static bool createKeyboard(void)
{
printf("createKeyboard: Creating CKeyboard\n");
NxWM::CKeyboard *keyboard = new NxWM::CKeyboard(g_nxwmtest.taskbar);
if (!keyboard)
{
printf("createKeyboard: ERROR: Failed to create CKeyboard\n");
return false;
}
showTestCaseMemory("createKeyboard After creating CKeyboard");
printf("createKeyboard: Start keyboard listener\n");
if (!keyboard->start())
{
printf("createKeyboard: ERROR: Failed start the keyboard listener\n");
delete keyboard;
return false;
}
showTestCaseMemory("createKeyboard: After starting the keyboard listener");
return true;
}
#endif
/////////////////////////////////////////////////////////////////////////////
// Name: createCalibration
/////////////////////////////////////////////////////////////////////////////
#ifdef CONFIG_NXWM_TOUCHSCREEN
static bool createCalibration(void)
{
// 1Create the CCalibrationFactory application factory
printf("createCalibration: Creating CCalibrationFactory\n");
NxWM::CCalibrationFactory *factory = new NxWM::CCalibrationFactory(g_nxwmtest.taskbar, g_nxwmtest.touchscreen);
if (!factory)
{
printf("createCalibration: ERROR: Failed to create CCalibrationFactory\n");
return false;
}
showTestCaseMemory("createCalibration: After creating CCalibrationFactory");
// Add the calibration application to the start window.
printf("createCalibration: Adding CCalibration to the start window\n");
if (!g_nxwmtest.startwindow->addApplication(factory))
{
printf("createCalibration: ERROR: Failed to add CCalibrationto the start window\n");
delete factory;
return false;
}
showTestCaseMemory("createCalibration: After adding CCalibration");
// Call StartWindowFactory::create to to create the start window application
printf("createCalibration: Creating CCalibration\n");
NxWM::IApplication *calibration = factory->create();
if (!calibration)
{
printf("createCalibration: ERROR: Failed to create CCalibration\n");
return false;
}
showTestCaseMemory("createCalibration: After creating CCalibration");
// Call CTaskBar::startApplication to start the Calibration application. Nothing
// will be displayed because the window manager has not yet been started.
printf("createCalibration: Start the calibration application\n");
if (!g_nxwmtest.taskbar->startApplication(calibration, false))
{
printf("createCalibration ERROR: Failed to start the calibration application\n");
delete calibration;
return false;
}
showTestCaseMemory("createCalibration: After starting the start window application");
return true;
}
#endif
/////////////////////////////////////////////////////////////////////////////
// Name: createNxConsole
/////////////////////////////////////////////////////////////////////////////
static bool createNxConsole(void)
{
// Add the NxConsole application to the start window
printf("createNxConsole: Creating the NxConsole application\n");
NxWM::CNxConsoleFactory *console = new NxWM::CNxConsoleFactory(g_nxwmtest.taskbar);
if (!console)
{
printf("createNxConsole: ERROR: Failed to instantiate CNxConsoleFactory\n");
return false;
}
showTestCaseMemory("createNxConsole: After creating the NxConsole application");
printf("createNxConsole: Adding the NxConsole application to the start window\n");
if (!g_nxwmtest.startwindow->addApplication(console))
{
printf("createNxConsole: ERROR: Failed to add CNxConsoleFactory to the start window\n");
delete console;
return false;
}
showTestCaseMemory("createNxConsole: After adding the NxConsole application");
return true;
}
/////////////////////////////////////////////////////////////////////////////
// Name: createHexCalculator
/////////////////////////////////////////////////////////////////////////////
static bool createHexCalculator(void)
{
// Add the hex calculator application to the start window
printf("createHexCalculator: Creating the hex calculator application\n");
NxWM::CHexCalculatorFactory *calculator = new NxWM::CHexCalculatorFactory(g_nxwmtest.taskbar);
if (!calculator)
{
printf("createHexCalculator: ERROR: Failed to instantiate CHexCalculatorFactory\n");
return false;
}
showTestCaseMemory("createHexCalculator: After creating the hex calculator application");
printf("createHexCalculator: Adding the hex calculator application to the start window\n");
if (!g_nxwmtest.startwindow->addApplication(calculator))
{
printf("createHexCalculator: ERROR: Failed to add CNxConsoleFactory to the start window\n");
delete calculator;
return false;
}
showTestCaseMemory("createHexCalculator: After adding the hex calculator application");
return true;
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: showTestStepMemory
/////////////////////////////////////////////////////////////////////////////
// Called by ad hoc instrumentation in the NxWM/NxWidgets code
#ifdef CONFIG_HAVE_FILENAME
void _showTestStepMemory(FAR const char *file, int line, FAR const char *msg)
{
#ifdef CONFIG_NXWIDGET_MEMMONITOR
updateMemoryUsage(&g_nxwmtest.mmSubStep, file, line, msg);
#endif
}
#else
void showTestStepMemory(FAR const char *msg)
{
#ifdef CONFIG_NXWIDGET_MEMMONITOR
updateMemoryUsage(&g_nxwmtest.mmSubStep, msg);
#endif
}
#endif
/////////////////////////////////////////////////////////////////////////////
// user_start/nxwm_main
/////////////////////////////////////////////////////////////////////////////
int nxwm_main(int argc, char *argv[])
{
// Call all C++ static constructors
#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE)
up_cxxinitialize();
#endif
// Initialize memory monitor logic
initMemoryUsage();
// Initialize the NSH library
printf("nxwm_main: Initialize the NSH library\n");
if (!NxWM::nshlibInitialize())
{
printf("nxwm_main: ERROR: Failed to initialize the NSH library\n");
return EXIT_FAILURE;
}
showTestCaseMemory("nxwm_main: After initializing the NSH library");
// Create the task bar.
if (!createTaskbar())
{
printf("nxwm_main: ERROR: Failed to create the task bar\n");
testCleanUpAndExit(EXIT_FAILURE);
}
// Create the start window.
if (!createStartWindow())
{
printf("nxwm_main: ERROR: Failed to create the start window\n");
testCleanUpAndExit(EXIT_FAILURE);
}
// Create the keyboard device
#ifdef CONFIG_NXWM_KEYBOARD
if (!createKeyboard())
{
printf("nxwm_main: ERROR: Failed to create the keyboard\n");
testCleanUpAndExit(EXIT_FAILURE);
}
#endif
// Create the touchscreen device
#ifdef CONFIG_NXWM_TOUCHSCREEN
if (!createTouchScreen())
{
printf("nxwm_main ERROR: Failed to create the touchscreen\n");
testCleanUpAndExit(EXIT_FAILURE);
}
#endif
// Create the calibration application and add it to the start window
#ifdef CONFIG_NXWM_TOUCHSCREEN
if (!createCalibration())
{
printf("nxwm_main ERROR: Failed to create the calibration application\n");
testCleanUpAndExit(EXIT_FAILURE);
}
#endif
// Create the NxConsole application and add it to the start window
if (!createNxConsole())
{
printf("nxwm_main: ERROR: Failed to create the NxConsole application\n");
testCleanUpAndExit(EXIT_FAILURE);
}
// Create the hex calculator application and add it to the start window
if (!createHexCalculator())
{
printf("nxwm_main: ERROR: Failed to create the hex calculator application\n");
testCleanUpAndExit(EXIT_FAILURE);
}
// Call CTaskBar::startWindowManager to start the display with applications in place.
if (!startWindowManager())
{
printf("nxwm_main: ERROR: Failed to start the window manager\n");
testCleanUpAndExit(EXIT_FAILURE);
}
#ifdef CONFIG_NXWM_TOUCHSCREEN
// Since we started the touchscreen calibration program maximized, it will run
// immediately when we start the window manager. There is no positive handshake
// to know whenthe touchscreen has been calibrated. If we really want to know,
// we have to poll
printf("nxwm_main: Waiting for touchscreen calibration\n");
while (!g_nxwmtest.touchscreen->isCalibrated())
{
std::sleep(2);
}
// This is how we would then recover the calibration data. After the calibration
// application creates the calibration data, it hands it to the touchscreen driver
// After the touchscreen driver gets it, it will report isCalibrated() == true
// and then we can read the calibration data from the touchscreen driver.
printf("nxwm_main: Getting calibration data from the touchscreen\n");
if (!g_nxwmtest.touchscreen->getCalibrationData(g_nxwmtest.calibData))
{
printf("nxwm_main: ERROR: Failed to get calibration data from the touchscreen\n");
}
#endif
// Wait a little bit for the display to stabilize. Then simulate pressing of
// the 'start window' icon in the task bar
#ifndef CONFIG_NXWM_TOUCHSCREEN
sleep(2);
g_nxwmtest.taskbar->clickIcon(0, true);
usleep(500*1000);
g_nxwmtest.taskbar->clickIcon(0, false);
showTestCaseMemory("nxwm_main: After clicking the start window icon");
// Wait bit to see the result of the button press. Then press the first icon
// in the start menu. That should be the NxConsole icon.
sleep(2);
g_nxwmtest.startwindow->clickIcon(0, true);
usleep(500*1000);
g_nxwmtest.startwindow->clickIcon(0, false);
showTestCaseMemory("nxwm_main: After clicking the NxConsole icon");
#endif
// Wait bit to see the result of the button press.
sleep(2);
showTestMemory("nxwm_main: Final memory usage");
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,70 @@
/********************************************************************************
* NxWidgets
* Graphical Widgets for the NuttX RTOS
*
* 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 nor the names of its contributors may 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.
*
*******************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in almost all NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``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 Antony Dzeryn 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.
*
********************************************************************************/

View File

@ -0,0 +1,138 @@
#################################################################################
# NxWidgets/libnxwidgets/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.
#
#################################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
NXWIDGETDIR := ${shell pwd | sed -e 's/ /\\ /g'}
ASRCS =
CSRCS =
# Infrastructure
CXXSRCS = cbitmap.cxx cbgwindow.cxx ccallback.cxx cgraphicsport.cxx
CXXSRCS += clistdata.cxx clistdataitem.cxx cnxfont.cxx
CXXSRCS += cnxserver.cxx cnxstring.cxx cnxtimer.cxx cnxwidget.cxx cnxwindow.cxx
CXXSRCS += cnxtkwindow.cxx cnxtoolbar.cxx crect.cxx crlepalettebitmap.cxx
CXXSRCS += cstringiterator.cxx ctext.cxx cwidgetcontrol.cxx cwidgeteventhandlerlist.cxx
CXXSRCS += cwindoweventhandlerlist.cxx singletons.cxx
# Widget APIs
CXXSRCS += cbutton.cxx cbuttonarray.cxx ccheckbox.cxx ccyclebutton.cxx
CXXSRCS += cglyphbutton.cxx cimage.cxx ckeypad.cxx clabel.cxx clatchbutton.cxx
CXXSRCS += clatchbuttonarray.cxx clistbox.cxx clistboxdataitem.cxx cmultilinetextbox.cxx
CXXSRCS += cprogressbar.cxx cradiobutton.cxx cradiobuttongroup.cxx cscrollbarhorizontal.cxx
CXXSRCS += cscrollbarpanel.cxx cscrollbarvertical.cxx cscrollinglistbox.cxx
CXXSRCS += cscrollingpanel.cxx cscrollingtextbox.cxx csliderhorizontal.cxx
CXXSRCS += csliderhorizontalgrip.cxx cslidervertical.cxx csliderverticalgrip.cxx
CXXSRCS += cstickybutton.cxx cstickybuttonarray.cxx ctextbox.cxx
# Images
CXXSRCS += glyph_nxlogo.cxx
CXXSRCS += glyph_arrowdown.cxx glyph_checkboxon.cxx glyph_screendepthup.cxx
CXXSRCS += glyph_arrowleft.cxx glyph_control.cxx glyph_screenflipdown.cxx
CXXSRCS += glyph_arrowright.cxx glyph_cycle.cxx glyph_screenflipup.cxx
CXXSRCS += glyph_arrowup.cxx glyph_radiobuttonoff.cxx glyph_shift.cxx
CXXSRCS += glyph_backspace.cxx glyph_radiobuttonmu.cxx glyph_windowclose.cxx
CXXSRCS += glyph_capslock.cxx glyph_radiobuttonon.cxx glyph_windowdepthdown.cxx
CXXSRCS += glyph_checkboxmu.cxx glyph_return.cxx glyph_windowdepthup.cxx
CXXSRCS += glyph_checkboxoff.cxx glyph_screendepthdown.cxx
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
BIN = libnxwidgets$(LIBEXT)
ifeq ($(WINTOOL),y)
INCDIROPT = -w
endif
CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(NXWIDGETDIR)/include}
CXXFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(NXWIDGETDIR)/include}
DEPPATH = --dep-path src
VPATH = src
all: $(BIN)
.PHONY = check_nuttx depend clean distclean export
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
check_nuttx:
@( \
if [ -z "$(TOPDIR)" ]; then \
echo "The path to the nuttx directory must be provided on the command line."; \
echo "Usage: make -C $(NXWIDGETDIR) TOPDIR=\"<nuttx directory>\""; \
exit 1; \
fi; \
if [ ! -d "$(TOPDIR)" ]; then \
echo "The nuttx directory (TOPDIR) does not exist: $(TOPDIR)"; \
exit 1; \
fi; \
if [ ! -f "$(TOPDIR)/.config" ]; then \
echo "The nuttx directory (TOPDIR) has not been configured"; \
echo "Please configure NuttX and try again"; \
exit 1; \
fi; \
)
$(BIN): check_nuttx $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $@, $${obj}); \
done ; )
.depend: Makefile $(SRCS)
@$(MKDEP) $(DEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f $(BIN) *.a *.o *~ .*.sw*
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
export: $(BIN)
zip -r nxwidgets-export.zip include $(BIN) COPYING
-include Make.dep

View File

@ -0,0 +1,83 @@
/*! \mainpage NXWidgets Documentation
*
* 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 subystem in order to
* provide graphic objects, or "widgets", in the <a title="NX Graphics
* Subsystem" href="http://nuttx.sourceforge.net/NXGraphicsSubsystem.html">
* NX Graphics Subsystem</a>.
*
* \section feature Features
*
* \subsection conservative_cxx Conservative C++
*
* 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.
*
* \subsection nx_integration NX Integration
*
* Integrates seamlessly with the NX graphics subsytem. Think of the X
* server under Linux... the NX graphics subsystem is like a tiny X server
* that provides windowing under NuttX. By adding NXWidgets, you can
* support graphic objects like buttons and text boxes in the NX windows
* and toolbars.
*
* \subsection small_footprint Small Footprint
*
* 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.
*
* \subsection output_devices Output Devices
*
* NXWidgets will work on the high-end fram buffer devices as well as on
* LCDs connected via serial or parallel port to a small MCU.
*
* \subsection input_devices 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 a very special widget called
* CKeypad that will provide keyboard input via on-screen keypad that can
* be operated via mouse or touchscreen inputs.
*
* \subsection many_graphic_objects 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.
*
* \subsection NXWM\
*
* NxWM isthe tiny window manager based on NX and NxWidgets. NxWM is a 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 applications. 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).
*
* Note 1: NwWM requires NuttX-6.18 or above.
*
* Note 2: Many of the fundamental classes 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.
*/

View File

@ -0,0 +1,344 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/cbgwindow.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 __INCLUDE_CBGWINDOW_HXX
#define __INCLUDE_CBGWINDOW_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include <nuttx/nx/nx.h>
#include "nxconfig.hxx"
#include "ccallback.hxx"
#include "inxwindow.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
class INxWindow;
struct SBitmap;
/**
* This class defines operations on a the NX background window.
* There are three instances that represent an NX window from the
* perspective of NXWidgets.
*
* - There is one widget control instance per NX window,
* - One CCallback instance per window,
* - One window instance.
*
* There a various kinds of of window instances, but each inherits
* (1) CCallback and dispatches the Windows callbacks and (2) INxWindow
* that describes the common window behavior.
*/
class CBgWindow : protected CCallback, public INxWindow
{
private:
NXHANDLE m_hNxServer; /**< Handle to the NX server. */
NXWINDOW m_hWindow; /**< Handle to the NX background window */
CWidgetControl *m_widgetControl; /**< The controlling widget for the window */
public:
/**
* Constructor. Obtains the background window from server and wraps
* the window as CBgWindow. Creates an uninitialized instance of the
* CBgWindow object. The open() method must be called to initialize
* the instance.
*
* The general steps to create any window include:
* 1) Create a dumb CWigetControl instance
* 2) Pass the dumb CWidgetControl instance to the window constructor
* that inherits from INxWindow.
* 3) The window constructor call CWidgetControl methods to "smarten"
* the CWidgetControl instance with window-specific knowledge.
* 4) Call the open() method on the window to display the window.
* 5) After that, the fully smartend CWidgetControl instance can
* be used to generate additional widgets.
* 6) After that, the fully smartened CWidgetControl instance can
* be used to generate additional widgets by passing it to the
* widget constructor
*
* @param hNxServer Handle to the NX server.
* @param widgetControl Controlling widget for this window.
*/
CBgWindow(NXHANDLE hNxServer, CWidgetControl *widgetControl);
/**
* Destructor. Returns the background window to the server.
*/
virtual ~CBgWindow(void);
/**
* Creates a the new window. Window creation is separate from
* object instantiation so that failures can be reported.
*
* @return True if the window was successfully created.
*/
bool open(void);
/**
* Each implementation of INxWindow must provide a method to recover
* the contained CWidgetControl instance.
*
* @return The contained CWidgetControl instance
*/
CWidgetControl *getWidgetControl(void) const;
/**
* Request the position and size information of the window. The values
* will be returned asynchronously through the client callback method.
* The GetPosition() method may than be called to obtain the positional
* data as provided by the callback.
*
* @return True on success, false on any failure.
*/
bool requestPosition(void);
/**
* Get the position of the window (as reported by the NX callback). NOTE:
* The background window is always positioned at {0,0}
*
* @return The position.
*/
bool getPosition(FAR struct nxgl_point_s *pPos);
/**
* Get the size of the window (as reported by the NX callback). NOTE:
* The size of the background window is always the entire display.
*
* @return The size.
*/
bool getSize(FAR struct nxgl_size_s *pSize);
/**
* Set the position and size of the window.
*
* @param pPos The new position of the window.
* @return True on success, false on any failure.
*/
bool setPosition(FAR const struct nxgl_point_s *pPos);
/**
* Set the size of the selected window. NOTE: The size of the
* background window is always the entire display and cannot be
* changed.
*
* @param pSize The new size of the window.
* @return True on success, false on any failure.
*/
bool setSize(FAR const struct nxgl_size_s *pSize);
/**
* Bring the window to the top of the display. NOTE: The background
* window cannot be raised.
*
* @return True on success, false on any failure.
*/
bool raise(void);
/**
* Lower the window to the bottom of the display. NOTE: The background
* window is always at the bottom of the window hierarchy.
*
* @return True on success, false on any failure.
*/
bool lower(void);
/**
* Each window implementation also inherits from CCallback. CCallback,
* by default, forwards NX keyboard input to the various widgets residing
* in the window. But NxConsole is a different usage model; In this case,
* keyboard input needs to be directed to the NxConsole character driver.
* This method can be used to enable (or disable) redirection of NX
* keyboard input from the window widgets to the NxConsole
*
* @param handle. The NXCONSOLE handle. If non-NULL, NX keyboard
* input will be directed to the NxConsole driver using this
* handle; If NULL (the default), NX keyboard input will be
* directed to the widgets within the window.
*/
#ifdef CONFIG_NXCONSOLE_NXKBDIN
inline void redirectNxConsole(NXCONSOLE handle)
{
setNxConsole(handle);
}
#endif
/**
* Set an individual pixel in the window with the specified color.
*
* @param pPos The location of the pixel to be filled.
* @param color The color to use in the fill.
*
* @return True on success; false on failure.
*/
bool setPixel(FAR const struct nxgl_point_s *pPos,
nxgl_mxpixel_t color);
/**
* Fill the specified rectangle in the window with the specified color.
*
* @param pRect The location to be filled.
* @param color The color to use in the fill.
*
* @return True on success; false on failure.
*/
bool fill(FAR const struct nxgl_rect_s *pRect,
nxgl_mxpixel_t color);
/**
* Get the raw contents of graphic memory within a rectangular region. NOTE:
* Since raw graphic memory is returned, the returned memory content may be
* the memory of windows above this one and may not necessarily belong to
* this window unless you assure that this is the top window.
*
* @param rect The location to be copied
* @param dest - The describes the destination bitmap to receive the
* graphics data.
*/
void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest);
/**
* Fill the specified trapezoidal region in the window with the specified
* color.
*
* @param pClip Clipping rectangle relative to window (may be null).
* @param pTrap The trapezoidal region to be filled.
* @param color The color to use in the fill.
*
* @return True on success; false on failure.
*/
bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip,
FAR const struct nxgl_trapezoid_s *pTrap,
nxgl_mxpixel_t color);
/**
* Fill the specified line in the window with the specified color.
*
* @param vector - Describes the line to be drawn
* @param width - The width of the line
* @param color - The color to use to fill the line
*
* @return True on success; false on failure.
*/
bool drawLine(FAR struct nxgl_vector_s *vector,
nxgl_coord_t width,
nxgl_mxpixel_t color);
/**
* Draw a filled circle at the specified position, size, and color.
*
* @param center The window-relative coordinates of the circle center.
* @param radius The radius of the rectangle in pixels.
* @param color The color of the rectangle.
*/
bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius,
nxgl_mxpixel_t color);
/**
* Move a rectangular region within the window.
*
* @param pRect Describes the rectangular region to move.
* @param pOffset The offset to move the region.
*
* @return True on success; false on failure.
*/
bool move(FAR const struct nxgl_rect_s *pRect,
FAR const struct nxgl_point_s *pOffset);
/**
* Copy a rectangular region of a larger image into the rectangle in the
* specified window.
*
* @param pDest Describes the rectangular on the display that will receive
* the bitmap.
* @param pSrc The start of the source image.
* @param pOrigin the pOrigin of the upper, left-most corner of the full
* bitmap. Both pDest and pOrigin are in window coordinates, however,
* pOrigin may lie outside of the display.
* @param stride The width of the full source image in bytes.
*
* @return True on success; false on failure.
*/
bool bitmap(FAR const struct nxgl_rect_s *pDest,
FAR const void *pSrc,
FAR const struct nxgl_point_s *pOrigin,
unsigned int stride);
};
}
#endif // __cplusplus
#endif // __INCLUDE_CBGWINDOW_HXX

View File

@ -0,0 +1,213 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/cbitmap.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.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in all NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``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 Antony Dzeryn 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 __INCLUDE_CBITMAP_HXX
#define __INCLUDE_CBITMAP_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "nxconfig.hxx"
#include "ibitmap.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Bitmap Structure
*/
struct SBitmap
{
uint8_t bpp; /**< Bits per pixel */
uint8_t fmt; /**< Color format */
nxgl_coord_t width; /**< Width in pixels */
nxgl_coord_t height; /**< Height in rows */
uint16_t stride; /**< Width in bytes */
FAR const void *data; /**< Pointer to the beginning of pixel data */
};
/**
* Class providing bitmap accessor for a bitmap represented by SBitmap.
*/
class CBitmap : public IBitmap
{
protected:
const struct SBitmap *m_bitmap; /**< The bitmap that is being managed */
/**
* Copy constructor is protected to prevent usage.
*/
inline CBitmap(const CBitmap &bitmap) { }
public:
/**
* Constructor.
*
* @param bitmap The bitmap structure being wrapped.
*/
CBitmap(const struct SBitmap *bitmap);
/**
* Destructor.
*/
inline ~CBitmap(void) {}
/**
* Get the bitmap's color format.
*
* @return The bitmap's width.
*/
const uint8_t getColorFormat(void) const;
/**
* Get the bitmap's color format.
*
* @return The bitmap's color format.
*/
const uint8_t getBitsPerPixel(void) const;
/**
* Get the bitmap's width (in pixels/columns).
*
* @return The bitmap's pixel depth.
*/
const nxgl_coord_t getWidth(void) const;
/**
* Get the bitmap's height (in rows).
*
* @return The bitmap's height.
*/
const nxgl_coord_t getHeight(void) const;
/**
* Get the bitmap's width (in bytes).
*
* @return The bitmap's width.
*/
const nxgl_coord_t getStride(void) const;
/**
* Use the colors associated with a selected image.
*
* @param selected. true: Use colors for a selected widget,
* false: Use normal (default) colors.
*/
inline void setSelected(bool selected) {}
/**
* Get one row from the bit map image.
*
* @param x The offset into the row to get
* @param y The row number to get
* @param width The number of pixels to get from the row
* @param data The memory location provided by the caller
* in which to return the data. This should be at least
* (getWidth()*getBitsPerPixl() + 7)/8 bytes in length
* and properly aligned for the pixel color format.
* @param True if the run was returned successfully.
*/
bool getRun(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width,
FAR void *data);
};
}
#endif // __cplusplus
#endif // __INCLUDE_CBITMAP_HXX

View File

@ -0,0 +1,244 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/cbutton.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.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in all NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``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 Antony Dzeryn 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 __INCLUDE_CBUTTON_HXX
#define __INCLUDE_CBUTTON_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "clabel.hxx"
#include "cwidgetstyle.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Forward references
*/
class CWidgetControl;
/**
* Clickable button widget. Displays text within the button.
*/
class CButton : public CLabel
{
protected:
/**
* Draws the outline of the button.
*
* @param port Graphics port to draw to.
*/
virtual void drawOutline(CGraphicsPort *port);
/**
* Draws the outline of the button.
*
* @param port Graphics port to draw to.
* @param useClicked Present outline using the 'clicked' style
*/
void drawOutline(CGraphicsPort *port, bool useClicked);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawContents(CGraphicsPort *port);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @param useClicked Present contents using the 'clicked' style
* @see redraw()
*/
void drawContents(CGraphicsPort *port, bool useClicked);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawBorder(CGraphicsPort *port);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @param useClicked Present border using the 'clicked' style
* @see redraw()
*/
void drawBorder(CGraphicsPort *port, bool useClicked);
/**
* Redraws the button.
*
* @param x The x coordinate of the click.
* @param y The y coordinate of the click.
*/
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
/**
* Raises an action.
*
* @param x The x coordinate of the mouse.
* @param y The y coordinate of the mouse.
*/
virtual void onPreRelease(nxgl_coord_t x, nxgl_coord_t y);
/**
* Redraws the button.
*
* @param x The x coordinate of the mouse.
* @param y The y coordinate of the mouse.
*/
virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y);
/**
* Redraws the button.
*
* @param x The x coordinate of the mouse.
* @param y The y coordinate of the mouse.
*/
virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y);
/**
* Copy constructor is protected to prevent usage.
*/
inline CButton(const CButton &button) : CLabel(button) { }
public:
/**
* Constructor for buttons that display a string.
*
* @param pWidgetControl The widget control for the display.
* @param x The x coordinate of the button, relative to its parent.
* @param y The y coordinate of the button, relative to its parent.
* @param width The width of the button.
* @param height The height of the button.
* @param text The text for the button to display.
* @param style The style that the button should use. If this is not
* specified, the button will use the global default widget
* style.
*/
CButton(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height, const CNxString &text,
CWidgetStyle *style = (CWidgetStyle *)NULL);
/**
* CButton Destructor.
*/
virtual inline ~CButton() { }
};
}
#endif // __cplusplus
#endif // __INCLUDE_CBUTTON_HXX

View File

@ -0,0 +1,326 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/cbuttonarray.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 __INCLUDE_CBUTTONARRAY_HXX
#define __INCLUDE_CBUTTONARRAY_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "clabel.hxx"
#include "cwidgetstyle.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Forward references
*/
class CWidgetControl;
class CNxString;
/**
* Manages a two-dimensional array of buttons as one widget. A two-
* dimensional array of buttons might also be called a "keyboard".
*/
class CButtonArray : public CNxWidget
{
protected:
uint8_t m_buttonColumns; /**< The number of columns in one row */
uint8_t m_buttonRows; /**< The number buttons in one column */
bool m_redrawButton; /**< True: Redraw button; False: redraw all */
bool m_cursorOn; /**< Cursor on; highlighted button displayed */
bool m_cursorChange; /**< True: Redraw cursor button only */
nxgl_coord_t m_buttonWidth; /**< The width of one button in pixels */
nxgl_coord_t m_buttonHeight; /**< The height of one button in rows */
nxgl_coord_t m_clickX; /**< The X position of the last clicked button */
nxgl_coord_t m_clickY; /**< The Y position of the last clicked button */
uint8_t m_cursorColumn; /**< The column index of the highlighted button */
uint8_t m_cursorRow; /**< The row index of the highlighted button */
CNxString *m_buttonText; /**< Text for each button */
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawContents(CGraphicsPort *port);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawBorder(CGraphicsPort *port);
/**
* Redraw only one button
*
* @param port The CGraphicsPort to draw to.
* @param column The button column index
* @param row The button row index
* @param useClicked Draw the button using the 'clicked' button style,
* regardless of the actual button state.
* @see onClick() and onRelease()
*/
virtual void drawButton(CGraphicsPort *port, int column, int row, bool useClicked);
/**
* Redraws the button.
*
* @param x The x coordinate of the click.
* @param y The y coordinate of the click.
*/
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
/**
* Raises an action.
*
* @param x The x coordinate of the mouse.
* @param y The y coordinate of the mouse.
*/
virtual void onPreRelease(nxgl_coord_t x, nxgl_coord_t y);
/**
* Redraws the button.
*
* @param x The x coordinate of the mouse.
* @param y The y coordinate of the mouse.
*/
virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y);
/**
* Redraws the button.
*
* @param x The x coordinate of the mouse.
* @param y The y coordinate of the mouse.
*/
virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y);
/**
* Convert an X/Y position to a button column/row index
*
* @param x The x position
* @param y The y position
* @param column The location to return the column index of the button
* of interest
* @param row The location to return the row index of the button of
* interest
* @return false is the position is invalid
*/
virtual bool posToButton(nxgl_coord_t x, nxgl_coord_t y, int &column, int &row);
/**
* Updates the GUI after the text has changed.
*/
virtual void onTextChange(void);
/**
* Copy constructor is protected to prevent usage.
*/
inline CButtonArray(const CButtonArray &button) : CNxWidget(button) { }
public:
/**
* Constructor for an array of buttons.
*
* @param pWidgetControl The widget control for the display.
* @param x The x coordinate of the button array, relative to its parent.
* @param y The y coordinate of the button array, relative to its parent.
* @param buttonColumns The number of buttons in one row of the button array
* @param buttonRows The number of buttons in one column of the button array
* @param buttonWidth The width of one button
* @param buttonHeight The height of one button
* @param style The style that the button should use. If this is not
* specified, the button will use the global default widget
* style.
*/
CButtonArray(CWidgetControl *pWidgetControl,
nxgl_coord_t x, nxgl_coord_t y,
uint8_t buttonColumns, uint8_t buttonRows,
nxgl_coord_t buttonWidth, nxgl_coord_t buttonHeight,
CWidgetStyle *style = (CWidgetStyle *)NULL);
/**
* CButtonArray Destructor.
*/
~CButtonArray(void);
/**
* Returns the string shown in the label.
*
* @param column The column index of the button of interest
* @param row The row index of the button of interest
* @return The label's text.
*/
virtual const CNxString &getText(int column, int row) const;
/**
* Set the text displayed in the label.
*
* @param column The column index of the button to set
* @param row The row index of the button to set
* @param text String to display.
*/
virtual void setText(int column, int row, const CNxString &text);
/**
* Return the position of the last clicked button (0,0 will be returned
* the no button has every been clicked). The button at this position
* is currently clicked then, in addition, return true.
*
* @param column The location to return the column index of the button
* of interest
* @param row The location to return the row index of the button of
* interest
* @return True if any button in the array is clicked
*/
virtual bool isButtonClicked(int &column, int &row) const;
/**
* Check if this specific button in the array is clicked
*
* @param column The column of the button to check.
* @param row The row of the button to check.
* @return True if this button is clicked
*/
virtual bool isThisButtonClicked(int column, int row) const;
/**
* Control the cursor state.
*
* @param cursorOn True(1), the current cursor position will be highlighted
*/
virtual void cursor(bool cursorOn);
/**
* Return the current cursor position (button indices) and an indication
* if the button at the cursor is currently hightlighted.
*
* @param column The location to return the column index of the button
* of interest
* @param row The location to return the row index of the button of
* interest
* @return True if the cursor is enabled and the button is highlighted
*/
virtual bool getCursorPosition(int &column, int &row) const;
/**
* Set the cursor position (button indices). Note that the cursor
* does not have to be enabled to set the position.
*
* @param column The column index of the button of interest
* @param row The row index of the button of interest
* @return True if the cursor position is valid
*/
virtual bool setCursorPosition(int column, int row);
/**
* Check if this specific button in the array is at the cursor position
* and highlighted.
*
* @param column The column of the button to check.
* @param row The row of the button to check.
* @return True if this button is at the cursor postion and highlighted.
*/
virtual bool isCursorPosition(int column, int row) const;
/**
* Insert the dimensions that this widget wants to have into the rect
* passed in as a parameter. All coordinates are relative to the
* widget's parent.
*
* @param rect Reference to a rect to populate with data.
*/
virtual void getPreferredDimensions(CRect &rect) const;
/**
* Sets the font.
*
* @param font A pointer to the font to use.
*/
virtual void setFont(CNxFont *font);
};
}
#endif // __cplusplus
#endif // __INCLUDE_CBUTTONARRAY_HXX

View File

@ -0,0 +1,272 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/ccallback.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 __INCLUDE_CCALLBACK_HXX
#define __INCLUDE_CCALLBACK_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include <nuttx/nx/nx.h>
#ifdef CONFIG_NXCONSOLE_NXKBDIN
# include <nuttx/nx/nxconsole.h>
#endif
#include "crect.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
class CWidgetControl;
/**
* Callback function proxies. This class receives and dispatches callbacks
* from the NX server. This calls also manages a few lower-level details
* such as keeping track of the reported window handles and window positions
* and sizes.
*
* There are three instances that represent an NX window from the
* perspective of NXWidgets.
*
* - There is one widget control instance per NX window,
* - One CCallback instance per window,
* - One window instance.
*
* There a various kinds of of window instances, but each inherits
* (1) CCallback and dispatches the Windows callbacks and (2) INxWindow
* that describes the common window behavior.
*/
class CCallback
{
private:
CWidgetControl *m_widgetControl; /**< The widget control instance for this window */
struct nx_callback_s m_callbacks; /**< C-callable vtable of callback function pointers */
#ifdef CONFIG_NXCONSOLE_NXKBDIN
NXCONSOLE m_nxconsole; /**< The NxConsole handle for redirection of keyboard input */
#endif
// Methods in the callback vtable
/**
* Re-Draw Callback. The redraw event is handled by CWidgetControl::redrawEvent.
*
* NOTE: This method runs in the context of the NX callback which may
* either be the context of the owning thread or, in the case of multi-
* user NX, the context of the NX event listener thread.
*
* @param hwnd Handle to a specific NX window.
* @param rect The rectangle that needs to be re-drawn (in window
* relative coordinates).
* @param bMore true: More re-draw requests will follow.
* @param arg User provided argument (see nx_openwindow, nx_requestbg,
* nxtk_openwindow, or nxtk_opentoolbar).
*/
static void redraw(NXHANDLE hwnd, FAR const struct nxgl_rect_s *rect,
bool bMore, FAR void *arg);
/**
* Position Callback. The new positional data is handled by
* CWidgetControl::geometryEvent.
*
* NOTE: This method runs in the context of the NX callback which may
* either be the context of the owning thread or, in the case of multi-
* user NX, the context of the NX event listener thread.
*
* @param hwnd Handle to a specific NX window.
* @param size The size of the window.
* @param pos The position of the upper left hand corner of the window on
* the overall display.
* @param bounds The bounding rectangle that describes the entire display.
* @param arg User provided argument (see nx_openwindow, nx_requestbg,
* nxtk_openwindow, or nxtk_opentoolbar).
*/
static void position(NXHANDLE hwnd, FAR const struct nxgl_size_s *size,
FAR const struct nxgl_point_s *pos,
FAR const struct nxgl_rect_s *bounds,
FAR void *arg);
/**
* New mouse data is available for the window. The new mouse
* data is handled by CWidgetControl::newMouseEvent.
*
* NOTE: This method runs in the context of the NX callback which may
* either be the context of the NX event listener thread (if multi-
* user NX), or possibly in the connects of device driver or even a
* device driver interrupt.
*
* The GUI thread is probably sleeping a semaphore, waiting to be
* awakened by a mouse or keyboard event.
*
* @param hwnd Handle to a specific NX window.
* @param pos The (x,y) position of the mouse.
* @param buttons See NX_MOUSE_* definitions.
* @param arg User provided argument (see nx_openwindow, nx_requestbg,
* nxtk_openwindow, or nxtk_opentoolbar).
*/
#ifdef CONFIG_NX_MOUSE
static void newMouseEvent(NXHANDLE hwnd,
FAR const struct nxgl_point_s *pos,
uint8_t buttons, FAR void *arg);
#endif /* CONFIG_NX_MOUSE */
/**
* New keyboard/keypad data is available for the window. The new
* keyboard data is handled by CWidgetControl::newKeyboardEvent.
*
* NOTE: This method runs in the context of the NX callback which may
* either be the context of the NX event listener thread (if multi-
* user NX), or possibly in the connects of device driver or even a
* device driver interrupt.
*
* The GUI thread is probably sleeping a semaphore, waiting to be
* awakened by a mouse or keyboard event.
*
* @param hwnd Handle to a specific NX window.
* @param nCh The number of characters that are available in str[].
* @param str The array of characters.
* @param arg User provided argument (see nx_openwindow, nx_requestbg,
* nxtk_openwindow, or nxtk_opentoolbar).
*/
#ifdef CONFIG_NX_KBD
static void newKeyboardEvent(NXHANDLE hwnd, uint8_t nCh,
FAR const uint8_t *str, FAR void *arg);
#endif // CONFIG_NX_KBD
/**
* This callback is the response from nx_block (or nxtk_block). Those
* blocking interfaces are used to assure that no further messages are
* directed to the window. Receipt of the blocked callback signifies
* that (1) there are no further pending callbacks and (2) that the
* window is now 'defunct' and will receive no further callbacks.
*
* This callback supports coordinated destruction of a window in multi-
* user mode. In multi-use mode, the client window logic must stay
* intact until all of the queued callbacks are processed. Then the
* window may be safely closed. Closing the window prior with pending
* callbacks can lead to bad behavior when the callback is executed.
*
* @param hwnd. Window handle of the blocked window
* @param arg1. User provided argument (see nx_openwindow, nx_requestbkgd,
* nxtk_openwindow, or nxtk_opentoolbar)
* @param arg2 - User provided argument (see nx_block or nxtk_block)
*/
#ifdef CONFIG_NX_MULTIUSER
static void windowBlocked(NXWINDOW hwnd, FAR void *arg1, FAR void *arg2);
#endif
public:
/**
* Constructor.
*
* @param widgetControl Control object associated with this window
*/
CCallback(CWidgetControl *widgetControl);
/**
* Destructor.
*/
inline ~CCallback(void) {}
/**
* Get the callback vtable. This is neeed only by the window
* instance that inherits this class. The window instance needs the
* C-callable vtable in order to create the NX window. Once the
* window is created, this class will begin to receive callbacks via
* the C-callable vtable methods.
*
* @return This method returns the C-callable vtable needed for
* NX window creation.
*/
inline FAR struct nx_callback_s *getCallbackVTable(void)
{
return &m_callbacks;
}
/**
* By default, NX keyboard input is given to the various widgets
* residing in the window. But NxConsole is a different usage model;
* In this case, keyboard input needs to be directed to the NxConsole
* character driver. This method can be used to enable (or disable)
* redirection of NX keyboard input from the window widgets to the
* NxConsole
*
* @param handle. The NXCONSOLE handle. If non-NULL, NX keyboard
* input will be directed to the NxConsole driver using this
* handle; If NULL (the default), NX keyboard input will be
* directed to the widgets within the window.
*/
#ifdef CONFIG_NXCONSOLE_NXKBDIN
inline void setNxConsole(NXCONSOLE handle)
{
m_nxconsole = handle;
}
#endif
};
}
#endif // __cplusplus
#endif // __INCLUDE_CCALLBACK_HXX

View File

@ -0,0 +1,210 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/ccheckbox.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.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in all NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``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 Antony Dzeryn 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 __INCLUDE_CCHECKBOX_HXX
#define __INCLUDE_CCHECKBOX_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "cbutton.hxx"
#include "cwidgetstyle.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
class CWidgetControl;
/**
* Class representing a checkbox. Like radio buttons, checkboxes
* are tri-state - off, on and "mu". The mu state cannot be enabled by
* a user - it can only be set by the developer.
*/
class CCheckBox : public CButton
{
public:
/**
* Enum listing all possible checkbox states.
*/
enum CheckBoxState
{
CHECK_BOX_STATE_OFF = 0, /**< Checkbox is unticked */
CHECK_BOX_STATE_ON = 1, /**< Checkbox is ticked */
CHECK_BOX_STATE_MU = 2 /**< Checkbox is in the third state */
};
protected:
CheckBoxState m_state; /**< The state of the checkbox */
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawContents(CGraphicsPort *port);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawBorder(CGraphicsPort *port);
/**
* Toggles the state of the checkbox.
*
* @param x The x coordinate of the click.
* @param y The y coordinate of the click.
*/
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
/**
* Copy constructor is protected to prevent usage.
*/
inline CCheckBox(const CCheckBox &checkBox) : CButton(checkBox) { }
public:
/**
* Constructor.
*
* @param pWidgetControl The widget control for the display.
* @param x The x coordinate of the checkbox, relative to its parent.
* @param y The y coordinate of the checkbox, relative to its parent.
* @param width The width of the checkbox.
* @param height The height of the checkbox.
* @param style The style that the widget should use. If this is not
* specified, the widget will use the values stored in the global
* g_defaultWidgetStyle object. The widget will copy the properties of
* the style into its own internal style object.
*/
CCheckBox(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height,
CWidgetStyle *style = (CWidgetStyle *)NULL);
/**
* Destructor.
*/
virtual inline ~CCheckBox(void) { }
/**
* Get the current state of the checkbox.
*
* @return The state of the checkbox.
*/
virtual inline const CheckBoxState getState(void) const
{
return m_state;
}
/**
* Set the state of the checkbox.
*
* @param state The new checkbox state.
*/
virtual void setState(CheckBoxState state);
};
}
#endif // __cplusplus
#endif // __INCLUDE_CCHECKBOX_HXX

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