Merge remote-tracking branch 'NxWidgets/master'
10
.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
*.o
|
||||
*.a
|
||||
*.d
|
||||
*.i
|
||||
*~
|
||||
.swp
|
||||
.*.swp
|
||||
core
|
||||
.gdbinit
|
||||
cscope.out
|
650
ChangeLog.txt
Normal file
@ -0,0 +1,650 @@
|
||||
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-09-29 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.
|
||||
* Kconfig: Added a mconfig configuration file. Eventually, NxWidgets
|
||||
needs to get hooked into the NuttX mconf configuration. Still not
|
||||
exactly sure how to do that.
|
||||
* libnxwidgets/Makefile and NxWidgets/nxwm/Makefile: Need updates
|
||||
for consistency with recent changes to NuttX build system (>= 6.22)
|
||||
* Kconfig: Add option to turn on the memory monitor feature of the
|
||||
NxWidgets/NxWM unit tests.
|
||||
|
||||
1.4 2012-12-20 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* libnxwidgets/Makefile, NxWidgets/nxwm/Makefile, and
|
||||
NxWidgets/UnitTests/nxwm/Makefile: Makefile improvements from
|
||||
submitted by Petteri Aimonen. Other Makefiles in the UnitTests
|
||||
directory probably also need these changes.
|
||||
* libnxwidgets/src/ccallback.cxx: Fix misplaced #endif. Provided
|
||||
by Petteri Aimonen.
|
||||
* libnxwidgets/src/cnxserver.cxx: Reduce delay to allow NX server
|
||||
to start. One second was un-necessarily long. Reduced to 50 MS.
|
||||
Reduction suggested by Petteri Aimonen.
|
||||
* tools/bitmap_converter.py: This script converts from any image type
|
||||
supported by Python imaging library to the RLE-encoded format used by
|
||||
NxWidgets.
|
||||
* NxWidgets/nxwm/src/capplicationwindow.cxx: If the "desktop" is empty,
|
||||
users have no need to minimize any windows. If the buttons are small,
|
||||
it's easy to hit minimize button accidentally when trying to close an
|
||||
application. Contributed by Petteri Aimonen.
|
||||
* NxWidgets/nxwm/src/ctaskbar.cxx: Add an option to eliminate the
|
||||
background image. Contributed by Petteri Aimonen.
|
||||
* NxWidgets/nxwm/src/chexcalculator.cxx and NxWidgets/nxwm/src/cstartwindow.cxx:
|
||||
The config settings CONFIG_NXWM_STARTWINDOW_ICON and CONFIG_NXWM_HEXCALCULATOR_ICON
|
||||
allow changing the icons used for these applications. However, to declare symbols
|
||||
for these icons user would need to modify NxWidgets header files.
|
||||
This commit adds a simple forward declaration to the relevant files, based on the
|
||||
configured icon. If the icon does not exist, linker will give an error about it.
|
||||
Contributed by Petteri Aimonen.
|
||||
* NxWidgets::CTaskBar: Highlight the current window in the task bar.
|
||||
Contributed by Petteri Aimonen.
|
||||
* NxWidgets/libnxwidgets/src/glyph_cycle.cxx: Width of glyph_cycle was wrong;
|
||||
Destructor needs to by public. From Petteri Aimonen.
|
||||
* NxWidgets::CNumericEdit. This is basically a label with plus and minus buttons.
|
||||
Contributed by Petteri, Aimonen.
|
||||
* NxWM::CStartWindow: Fix mq_receive error handling with signal is recieved.
|
||||
From Petteri Aimonen.
|
||||
* NxWidgets::CNxTimer: Replace the original (apparently non-functional) signal-
|
||||
based solution with a work queue-based solution. This raises some isses about
|
||||
using the internal work queues from user space. I have decided to implemented
|
||||
user-space work queues (someday) in order to accomplish that functionaliy.
|
||||
Submitted by Petteri Aimonen.
|
||||
* NxWidgets:CText and NxWidgets:CNumericEdite: Fix some memory freeing bugs
|
||||
(from Petteri Aimonen).
|
||||
* NxWidgets::CScrollingPanel: Usability improvements. It is borderless for now,
|
||||
because there was no easy way to redraw only the required part of the border.
|
||||
Contributed by Petteri Aimonen.
|
||||
* NxWidgets::CNxWidgets and NxWM::CStartWindow: Small changes to make sub-
|
||||
classing easier (from Petteri Aimonen).
|
||||
|
||||
1.5 2013-02-01 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* NxWidgets::CGraphicsPort::move(): Fix typo bug in bounding rectangle
|
||||
calculation (from Petteri Aimonen).
|
||||
* NxWM::CScrollingPanel::scrollChildren(): Avoid unnecessary redraws in
|
||||
CScrollingPanel (contributed by Petteri Aimonen).
|
||||
* NxWM::CCycleButton: Remove the separator from CCycleButton. It draws in
|
||||
wrong place, and doesnt look very good in the correct place either.
|
||||
(from Petteri Aimonen).
|
||||
* NxWidgets::CGraphicsPort: Many times we only want a constant background.
|
||||
In that case the old code fills the background, reads it back, renders
|
||||
the text and then writes it back. When used with LCD's (instead of
|
||||
framebuffers) this causes unnecessary delay and screen flicker.
|
||||
This commit adds a variant of drawText that takes background color,
|
||||
so that the background and text can both be rendered at one go.
|
||||
The old functions still function as before (Petteri Aimonen).
|
||||
* NxWidgets::CLabel: The label was drawn as a single rectangular region,
|
||||
then a text was added to the on top of this. The result is that the
|
||||
text would flicker when the CLabel was updated. With this change, the
|
||||
two step update is replaced with a five step update: The background
|
||||
is updated as four rectangulear regions (leaving the previous text in
|
||||
place), then the new text is updated. This eliminates the flicker
|
||||
(Petteri Aimonen).
|
||||
* Kconfig: Many NxWidgets/NxWM settings do not have meaningful, generic
|
||||
default values. Colors, for example, depend on pixel depth. Some
|
||||
geometry settings depending on other geometry settings. Font IDs are
|
||||
not know-able by the configuration system. etc. In these cases, it
|
||||
is best if the settings are just not undefined so that the system can
|
||||
calculate a reasonable default. however, if no default is provided
|
||||
in the .config file, mconf will complain and generate errors. So work
|
||||
around this, I added several "enabling" settings to override the
|
||||
default setting. This is awkward and I preferred the configuration as
|
||||
it was before, but this avoids the mconf errors and warnings.
|
||||
* UnitTests: Changed occurrences of lib_rawprintf() and lib_lowprintf()
|
||||
to match recent changes to NuttX (will be in NuttX-6.25)
|
||||
* CGraphicsPort::_drawText: Renamed from CGraphicsPort::drawText in order
|
||||
to eliminate some naming collisions when overloaded in some configurations
|
||||
(i.e., when both bool and nx_pixel_t are uint8_t). From Petteri Aimonen.
|
||||
* CNxWidgets::drawContents: Change base drawContents from a do-nothing
|
||||
function to a function that fills the widget with the background color.
|
||||
This is useful when using CNxWidgets as a "panel" , i.e. a container
|
||||
for other widgets. Subclasses will override drawContents and decide
|
||||
themselves how to draw the background.
|
||||
* CNxWidgets::CTabPanel: A new widget contributed by Petteri Aimonen.
|
||||
This widget provides a tab panel, which has a button bar at the top
|
||||
and panels below it. Pressing a button will select the corresponding
|
||||
panel.
|
||||
|
||||
1.6 2013-03-15 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* Type of argv[] has changed from const char ** to char * const *
|
||||
* NXWidgets::CNxWidget: Add an inline function to get the current style.
|
||||
* NxWM::CTaskBar: Make a some methods of CTaskbar virtual to allow
|
||||
customizations. From Petteri Aimonen.
|
||||
* NXWidgets::CCycleButton: Make CCycleButton change state in onPreRelease().
|
||||
This way the new value is already available when a listener gets the
|
||||
action event. From Petteri Aimonen.
|
||||
* NxWidgets/tools/bitmap_converter.py: Fix bitmap_converter.py so that
|
||||
it works with indexed input images.
|
||||
* NxWidgets::CLabel: Fix backward conditional compilation in the
|
||||
"flicker free" logic.
|
||||
* NxWidgets::CNxTimer: Previously repeated timers were re-enabled after
|
||||
the timer action event. Consequently, if the action event handler tried
|
||||
to stop the timer, the request would be ignored. Changes the order
|
||||
so that the timer is re-enabled before the callback. There is still
|
||||
no risk of re-entrancy, because everything executes on the USRWORK work
|
||||
queue. From Petteri Aimonen.
|
||||
* NxWidgets::CMultiLineTestBox: Fix text placement error. From Petteri
|
||||
Aimonen.
|
||||
* NxWidgets::CWidgetControl: Added another semaphore, boundssem, which
|
||||
is set as soon as the screen bounds are known. This corrects two
|
||||
problems:
|
||||
1) Due to the way nxgl_rectsize computes the size, it will never
|
||||
be 0,0 like CWidgetControl expects. Therefore the size is considered
|
||||
valid even though it has not been set yet.
|
||||
2) After the check is fixed to test for > 1, NxWM window creation will
|
||||
hang. This is due to the fact that it uses the screen bounds for
|
||||
determining window size. This was being blocked on geosem, which
|
||||
is only posted after the size has been set.
|
||||
From Petteri Aimonen.
|
||||
* NxWidgets::CImage: Two enhancements:
|
||||
1) Allow changing the bitmap even after the control has been created.
|
||||
2) Allow giving 'null' to have the control draw no image at all.
|
||||
From Petteri Aimonen.
|
||||
* NxWM::CTaskBar: Allow windows with null icon. This makes sense for e.g.
|
||||
full screen windows. From Petteri Aimonen.
|
||||
* NxWM::CApplicationWindow: Add config options to override NxWM
|
||||
stop/minimize icons. From Petteri Aimonen.
|
||||
* NwWM::CStartWindow, NxWM::CWindowMessenger: Get rid of the start window
|
||||
thread. Instead, handle all events through the USRWORK work queue.
|
||||
For me, this was necessary because I would open some files in button
|
||||
handlers and close them in NxTimer handlers. If these belonged to
|
||||
different tasks, the close operation would fail. Further benefits:
|
||||
+ Gets rid of one task and message queue.
|
||||
+ Reduces the amount of code required
|
||||
+ Decouples CStartWindow from everything else - now it is just a window
|
||||
with application icons, not an integral part of the event logic.
|
||||
+ All events come from the same thread, which reduces the possibility of
|
||||
multithreading errors in user code.
|
||||
+ The user code can also send events to USRWORK, so that everything gets
|
||||
serialized nicely without having to use so many mutexes.
|
||||
Drawbacks:
|
||||
- Currently the work state structure is malloc()ed, causing one allocation
|
||||
and free per each input event. Could add a memory pool for these later, but
|
||||
the speed difference doesn't seem noticeable.
|
||||
- The work queue will add ~50 ms latency to input events. This is however
|
||||
configurable, and the delay is anyway short enough that it is unnoticeable.
|
||||
From Petteri Aimonen.
|
||||
|
||||
1.7 2013-04-28 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* NxWidgets bitmap_converter.py: Fix bug when image width > 255. From
|
||||
Petteri Aimonen (2013-4-22).
|
||||
* NxWM::CScrollbarPanel: Fix spelling error in class name: CScollbarPanel
|
||||
should be CScrollbarPanel. From Petteri Aimonen (2013-4-22).
|
||||
* NxWidgets:: CGlyphButton: Generate action event, like CButton does.
|
||||
From Petteri Aimonen (2013-4-22).
|
||||
* NxWidgets:: CGlyphButton: Prevent drawing outside of the bitmap size.
|
||||
From Petteri Aimonen (2013-4-22).
|
||||
* NxWM::CTaskBar: Add option CONFIG_NXWM_TASKBAR_NO_BORDER to suppress
|
||||
drawing of the border on the taskbar. From Petteri Aimonen (2013-4-22).
|
||||
* NxWidgets::CNxTimer: Add function to check if CNxTimer is running.
|
||||
From Petteri Aimonen (2013-4-22).
|
||||
* NxWidgets::CNxWidgets: Allow overriding of the checkCollision() method.
|
||||
From Petteri Aimonen (2013-4-22).
|
||||
|
||||
1.8 2013-06-14 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* NxWM::CMediaPlayer: shell application for an MP3 Media Player with
|
||||
Kconfig settings to enable it. I plan to write this app to help
|
||||
develop and test the MP3 codec chip driver. It really doesn't do
|
||||
anything yet except display a text box saying "Coming soon", and I
|
||||
need to minimize the icon size a bit. From Ken Pettit (2013-5-11).
|
||||
* NxWidgets/nxwm/src/glyph_mediaplayer.cxx: Smaller version of the
|
||||
media player glyph. From Ken Pettit (2013-5-12).
|
||||
* NxWidgets/nxwm/include/ccalibration.hxx and src/ccalibration.cxx:
|
||||
Fix a race condition that would cause the calibration screen
|
||||
to fail to come up when its icon was touched (From Ken Pettit,
|
||||
2013-5-12).
|
||||
* Kconfig: Default priorities for NxWidget and NxWM threads
|
||||
should be 100, not 50, to be consistent with other default priorities.
|
||||
* NxWidgets::CGlyphSliderHorizontal and NxWidgets::CGlyphSliderHorizontalGrip:
|
||||
New widgets added by Ken Pettit (2013-5-15).
|
||||
* NxWidgets/UnitTests/CGlyphSliderHorizontal: Adds a unit test for the
|
||||
NxWidgets::CGlyphSliderHorizontal class. From Ken Pettit (2013-5-17) .
|
||||
* NxWidgets::CGlyphSliderHorizontal: Fix a drawing error. From Ken
|
||||
Pettit (2013-5-17).
|
||||
* UnitTests/*/Makefile and .gitignore: Update the way that NSH
|
||||
the Unit Tests are registered as built-in NSH applications (2013-5-30).
|
||||
* NxWidgets::CImage: Allow a NULL pointer for a bitmap. Add protection
|
||||
to prevent dereferencing the NULL pointer. From Petteri Aimonen
|
||||
(2013-6-4).
|
||||
* NxWidgets::CNumericEdit: Delay before auto-incrementing now varies:
|
||||
A longer delay is required to start auto-incrementing and speed increases
|
||||
while pressed. From Petteri Aimonen (2013-6-4).
|
||||
* NxWM::CTaskbar: Add a method to redraw the taskbar and the current
|
||||
application. This should only be necessary if the display loses
|
||||
state due to e.g. powerdown or other manual intervention. From
|
||||
Petteri Aimonen (2013-6-4).
|
||||
|
||||
1.9 2013-10-28 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* NxWM::CCalibration.cxx/hxx: If CONFIG_NXWM_CALIBRATION_MESSAGES is
|
||||
defined then CCalibration will provide some instructions in the center
|
||||
of the display (2013-10-14).
|
||||
* NxWM::CCalibration.cxx/hxx: Add options to collect and average
|
||||
multiple samples at each location. Also logic to discard the most
|
||||
extreme samples before averaging (2013-10-14).
|
||||
* NxWidgets::CScaledBitmap: This new class is a wrapper for an class
|
||||
the exports IBitMap. It will perform scaling via bi-linear interpolation
|
||||
so that images can be scaled to any size desired (2013-10-15).
|
||||
* NxWM::CTaskbar:: Can now be configured to scale taskbar icons using
|
||||
NxWidgets::CScaledBitmap (2013-10-15)
|
||||
* NxWidgets/libnxwidgets/src/glyph_nxlogo320x320.cxx: Add a big, 320x320
|
||||
NuttX logo image. The older, smaller NuttX logo was renamed from
|
||||
nxlogo to nxlogo160x160 in all places (2015-10-15).
|
||||
* NxWM::CCalibration and NxWM::CTouchscreen: Add a complex touchscreen
|
||||
scaling algorithm to handling the case where the measured X values also
|
||||
vary with y position (and vice versa) (2013-10-17).
|
||||
|
||||
1.10 2013-12-07 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* Kconfig and UnitTests/nxwm: Add logic to enable saving and recovering
|
||||
touchscreen calibration data. This depends upon having platform-dependent
|
||||
support for storage of configuration data. Portions suggested by
|
||||
Ken Pettit (2013-10-30).
|
||||
* NxWM:Calibration: Saving of calibration data must be performed in
|
||||
CCalibration, not in UnitTests/nxwm. Why? Because the touchscreen
|
||||
calibration could also be initiated from other ways other than through
|
||||
the one-time, start-up initialization logic (2013-10-30).
|
||||
|
||||
1.11 2014-01-30 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* NxWidgets/Kconfig and NxWidgets::CNxServer: Server initialization can
|
||||
now be disabled in the configuration (in fact, it is disabled by default).
|
||||
This is because in the kernel build mode, the NX server must be initialized
|
||||
in kernel mode by the RTOS before applications using the server run in
|
||||
user mode.
|
||||
* NxWm: Added CONFIG_NXWM_NXTERM that can be used to disable the NxConsole
|
||||
window (2013-12-30).
|
||||
* NxWm::CTouchscreen: Added CONFIG_NXWM_TOUCHSCREEN_DEVINIT that can be used
|
||||
to suppress calls to initialize the touchscreen device from the listener
|
||||
thread. This is necessary if the kernel mode build is used: In that case,
|
||||
the touchscreen must be initialized in kernel space before NxWM is started
|
||||
(2013-12-30).
|
||||
|
||||
1.12 2014-08-15 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* libnxwidgets/include/nxconfig.hxx and libnxwidgets/src/cscaledbitmap.cxx:
|
||||
Fix typo RBG -> RGB. This makes NxWidgets incompatible with versions of
|
||||
NuttX 7.2 and below.
|
||||
* nxwm/src/glyph_*.cxx: Rename all ICON glyph files to include the size of the
|
||||
ICON as part of the file name. This is in preparation for supporting a
|
||||
set of larger ICONs (2014-7-12).
|
||||
* nxwm/src/glyph_play48x48.cxx: Add a larger NxWM play icon (2014-7-12).
|
||||
* nxwm/src/glyph_caclulator47x49.cxx: Add a larger NxWM calculator icon
|
||||
(2014-7-13).
|
||||
* nxwm/src/glyph_cmd49x43.cxx: Add a larger NxWM NxConsole icon (2014-7-13).
|
||||
* nxwm/src/glyph_calibration48x42.cxx: Add a larger NxWM Calibration icon
|
||||
(2014-7-13).
|
||||
* nxwm/src/glyph_minimize42x42.cxx: Add a larger NxWM minimize icon
|
||||
(2014-7-13).
|
||||
* nxwm/src/glyph_stop42x42.cxx: Add a larger NxWM close icon (2014-8-13).
|
||||
* nxwm/src/glyph_mediaplayer44x50.cxx: Add a larger NxWM media player icon
|
||||
(2014-7-14).
|
||||
* Kconfig, nxwm/include/nxwmconfig.hxx, nxwm/src/capplicationwindow.cxx:
|
||||
Toolbar font ID can now be separately configured (2014-7-14).
|
||||
* nxwm/src/cmediaplayer.cxx: Will now dynamically position player controls
|
||||
based on the display and image sizes (2014-7-14).
|
||||
* nxwm/src/glyph_mediagrip30x30.cxx and glyph_mplayer_controls43x41.cxx: Add
|
||||
larger images for the media player (2014-7-14).
|
||||
* Kconfig, nxwm/src/cmediaplayer.cxx: Add options to manage spacing of media
|
||||
player buttons and borders vs. borderless buttons (2014-7-14).
|
||||
* NxWidgets::CImage: Fix setImageLeft and setImageTop methods (2014-7-14).
|
||||
* NxWidget::CImage: Now supports helper methods to align images in the
|
||||
widget region (2014-7-14).
|
||||
* NxWM::CMediaPlayer now uses the new CImage methods to align media controls
|
||||
in buttons (2014-7-14).
|
||||
* NxWidgets::CStickyImage: A version of CImage that sticks in the selected
|
||||
state when clicked (2014-7-15).
|
||||
* NxMW::CMediaPlayer: Now supports a pause button (2014-7-15).
|
||||
* NxMW::CMediaPlayer: Fix some memory leaks (2014-7-16).
|
||||
* NxMW::CMediaPlayer: Change spacing, make text region big enough to support
|
||||
a multi-line, scrollable region (2014-7-16).
|
||||
* NxMW::CMediaPlayer: Correctly catch the volume level change event
|
||||
(2014-7-16).
|
||||
* NxMW::CMediaPlayer: Convert CLabel to a CListBox to support selection of
|
||||
one of many media files to play. This should be a CScrollingTextBox to
|
||||
support an indefinitely large number of media files (2014-7-16).
|
||||
* NxWidgets::CGraphicsPort: Fix drawBitmapGreyScale method. Actually drew
|
||||
nothing because of several errors in positioning and buffer usage
|
||||
(2014-7-17)
|
||||
* NxWidgets::CImage: Should not attempt to draw the "empty" regions at the
|
||||
top and the bottom of the image box in greyscale (2014-7-17).
|
||||
* NxWM::CMediaPlayer: Fix some state-related bugs introduced yesterday.
|
||||
Improved state-related button displayes. Now correctly catches and
|
||||
handles file selection events (2014-7-17).
|
||||
* NxWidgets::CImage: Cannot use NxWidgets::CGraphicsPort:drawBitmapGreyScale()
|
||||
because it does not respect transparent or background colors in its current
|
||||
form. The end result is that makes the image background grey as well as the
|
||||
image (2014-7-17).
|
||||
* NxWM::CMediaPlayer: State variable was left in a bad state and caused some
|
||||
problems down the road (2014-7-17).
|
||||
* NxWidgets::CGlyphSliderHorizontal: No longer uses a hard-coded slider
|
||||
height; the slider height is now provided as a parameter, replacing the
|
||||
widget height which is now calculated from the glip image height
|
||||
(2014-7-17).
|
||||
* NxWM::CMediaPlayer: Now calculates the volume slider height from the grip
|
||||
image height (2014-7-17).
|
||||
* NxWM::CApplicationWindow: Created the custom font for the toolbar title,
|
||||
but never used it! (2014-7-17).
|
||||
* NxWidgets::CNxString: Make destructor virtual. From Petteri Aimonen
|
||||
(2014-7-22).
|
||||
* NxWidgets::CTaskbar: Fix type of return value fromopenRawWindow()
|
||||
method. From Petteri Aimonen (2014-7-22).
|
||||
* NxWidgets::CTabPanel: Modify behavior in showPage() method. Eliminate a
|
||||
duplicate redraw that caused flickering; re-order some logic so that
|
||||
widgets are hidden before operated on. From Petteri Aimonen (2014-7-22).
|
||||
* NxWidgets:CTabPanel: Make CTabPanel raise action event when tab is
|
||||
changed. Also add a function for getting the currently selected tab
|
||||
index. From Petteri Aimonen (2014-7-22).
|
||||
* NxWidgets::CNxTimer: Make CNxTimer stop itself before destruction.
|
||||
Otherwise a call to an invalid work queue entry may occur. From Petteri
|
||||
Aimonen (2014-7-22).
|
||||
* NxWidgets/Kconfig: Add configuration options to filter CMediaPlayer files
|
||||
based on extension (2014-7-23)
|
||||
* NxWM::CMediaPlayer: Add logic to read files from the media mountpoint,
|
||||
filter them by extension, and display the file names in the listbox (2014-7-23).
|
||||
* NxWM::CMediaPlayer: Beginning integration of NxPlayer into Nxwm::MediaPlayer.
|
||||
Gets handle, sets device, and releases handle. Lots more to be done
|
||||
(2014-7-23).
|
||||
* NxWidgets::CNxString: Add a getAllocSize() method to make it easier to
|
||||
convert CNxStrings to NUL-terminated C strings (2014-7-24).
|
||||
* NxWM::IApplicationFactory: dd a do-nothing, virtual destructor to
|
||||
eliminate a warning (2014-7-24).
|
||||
* NxWM::CMediaPlayer: Lots of changes to integrate with Ken's NxPlayer
|
||||
(2014-7-24).
|
||||
* NxWM::CMediaPlayer: Revise state logic. We need an additional state for
|
||||
the case where a file is selected, but playing has not yet start. Several
|
||||
other state-related fixes (2014-7-25).
|
||||
* NxWM::CMediaPlayer: Need to remember last text box selection or else each
|
||||
new Value Change event from the volume slider is confused with a new file
|
||||
selection (2014-7-27).
|
||||
* NxWM::CMediaPlayer: Correct handling of increments to sub-sampling rate
|
||||
(2014-7-27).
|
||||
* NxWidgets::CNxWidget: Remove an unused bit field (2014-7-28).
|
||||
* NxWM::CMediaPlayer: Add a CLabel that show the current fast forward/rewind
|
||||
speed (2014-7-28).
|
||||
* NxWM::CKeyboard: Add support for a USB keyboard as the NxConsole and text
|
||||
widget input. Not fully functional as of this initial check-in. Basic
|
||||
functionality is there, but there are conditions were the keyboard gets
|
||||
lost (2014-7-30).
|
||||
|
||||
1.13 2014-09-28 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* Change all references to NxConsole to NxTerm. This introduces an
|
||||
incompatibility with versions prior to NuttX-7.5 (2014-9-20).
|
||||
|
||||
1.14 2014-11-26 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* Fix all UnitTest/ files to account for the corrected syslog() prototype.
|
||||
This change to the NuttX syslog introduces an incompatibility between
|
||||
NuttX 7.6 and previous versions of the UnitTest code.
|
||||
|
||||
1.15 2015-04-14 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* In NuttX 7.9, the interface arch_tcinitialize() was replaced with the
|
||||
boardctl() interface. Old versions of NxWM will then be incompatible
|
||||
with Versions of NuttX at 7.9 and beyond (2015-03-31).
|
||||
* NxWidgets::CNxServer: More renaming: up_lcdinitialize->board_lcd_initialize,
|
||||
up_lcdgetdev->board_lcd_getdev, up_lcduninitialize->board_lcd_uninitialize
|
||||
(2015-04-04).
|
||||
* NxWidgets:: INxWindow, CNxWindow, CBgWindow, CNxTkWindow, CNxToolbar,
|
||||
CGraphicsPort: Add a capped parameter to all drawLine() methods. Pass on
|
||||
to NX nx_drawline() and NXTK nxtk_drawlinetoolbar() and nxtk_drawlinewindow()
|
||||
functions (2015-04-05).
|
||||
|
||||
1.16 2016-06-01 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* NxWM::CTouchscreen: When boardctl() fails, need to print errno not the
|
||||
returned value which will always be -1 (2015-04-16).
|
||||
* NxWidgets::CNxServer: Correct use of the BOARDIOC_GRAPHICS_SETUP
|
||||
boardctl() call (2015-04-16).
|
||||
* CListBox unit test: Should use RAND_MAX, not MAX_RAND (2015-04-16).
|
||||
* The NxWidgets/ directory has been removed from the NuttX GIT repository
|
||||
and now stands alone in its own repository (2015-06-27).
|
||||
* Framebuffer driver parameters have changed. This introduces an
|
||||
incompatibility with versions of NuttX prior to 7.16 (2016-04-14).
|
||||
* UnitTests: Add Make.defs files to all UnitTests directories. This is
|
||||
required by the current apps/Makefile. Hmmm.. This means that no one
|
||||
has built the NxWidgets packages in the last several realeases!
|
||||
(2016-04-23).
|
||||
* UnitTests: Add some default definitions to handle the (unusual) case
|
||||
where 'make clean' is called with no .config or Make.defs file installed
|
||||
(2016-05-10).
|
||||
|
||||
1.17 2016-07-25 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* UnitTests: Back conditional logic out of UnitTest Make.defs files. It
|
||||
does not belong there and causes link failures like "Cannot find nxwm_main"
|
||||
(2016-06-05).
|
||||
* Change dbg() and vdbg() to err() and info() (2016-06-11).
|
||||
* Change some *err() message to *info() messages if what was a *dbg()
|
||||
message does not indicate and error condition (2016-06-14).
|
||||
* Add _ to front of debug macros (2016-06-16).
|
||||
* Unittests: All Makefiles must provided a (dummy) prefconfig target to be
|
||||
compatible with changes to the apps/ configuration system that will be
|
||||
be released in NuttX-7.17 (2016-06-29).
|
||||
* Changes to pre-processor include statments needed to handle reorganization
|
||||
of the apps/include directory (2016-07-01).
|
||||
* Update include paths to adapt to changes made to apps/ include path logic
|
||||
(2016-07-22).
|
||||
|
||||
1.18 2016-12-26 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* NxWM needs the path to the apps/include directory (2016-07-28).
|
||||
* NxWidgets: Fix CListBox crash when clicked below the last item. From
|
||||
Petteri Aimonen (2016-09-22).
|
||||
* libnxwdigets: Fix memory leak in CNxWindow and make behaviour match
|
||||
CNxTkWindow. From Petteri Aimonen (2016-09-22).
|
||||
* libnxwidgets: Fix default text colors in NxWidgets::CListBox. From
|
||||
Petteri Aimonen (2016-09-22).
|
||||
* libnxwidgets: Avoid unnecessary redraw in NxWidgets::CListBox. The
|
||||
ListData will raise an event that will cause a redraw anyway. Redrawing
|
||||
in click() caused double redraws. From Petteri Aimonen (2016-09-22).
|
||||
* libnxwidgets: Fix coordinate handling in NxWidgets::CMultiLineTextBox.
|
||||
Related to 'Thu Feb 21 16:47:01 2013 Fix text placement in
|
||||
CMultiLineTextbox.' There was a few similar bugs remaining in calculating
|
||||
of rows to show and in clearing the background. From Petteri Aimonen
|
||||
(2016-09-22).
|
||||
* libnxwidgets: Allow NxWidgets::CListDataItems subclasses access to text
|
||||
and value. From Petteri Aimonen (2016-09-22).
|
||||
* Add setting task name via prctl() to NxWidgets::CNxServer and
|
||||
NxWM:CTouchScreen. From Petteri Aimonen (2016-09-22).
|
||||
* libnxwidgets: In NxWidgets::CText, allow setting negative line spacing.
|
||||
This is useful to have text take up less space, as quite many fonts have
|
||||
large line spacings built-in. From Petteri Aimonen (2016-09-22).
|
||||
* libnxwidgets: Allow setting line spacing in NxWidgets::CMultiLineTextBox.
|
||||
From Petteri Aimonen (2016-09-22).
|
||||
* CNxServer: Remove NX server task. Now calls nx_start (indirectly through
|
||||
boardctrl(BOARDIOC_NX_START) to start the NX Server kernel thread
|
||||
(2016-12-01).
|
||||
* CNxServer: Can't use printf in this context (2016-12-01)
|
||||
|
||||
1.19 2018-03-02 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* Correct NX Server message queue names. Should not be /dev/nx*. They must
|
||||
be relative to /dev/mqueue so "nxabc" will appear at "/var/nxabc"
|
||||
(2017-01-08).
|
||||
* strcasecmp, strncasecmp, bzero, bcmp, and bcopy should be defined in
|
||||
strings.h, not string.h. bzero, bcmp, and bcopy are legacy functions; the
|
||||
contemporary counterparts should be used instead (2017-02-16).
|
||||
* Unitests/nxwm: Change includes because up_cxxinitialize() is now
|
||||
prototyped in apps/include/platfor/cxxinitialize.h (2017-05-13).
|
||||
* Prototype of nsh_telnetstart() has changed (2017-07-05).
|
||||
* NxWidgets: fix work_s initialization in cwindowmessenger.hxx. From Sakari
|
||||
Kapanen (2017-09-24).
|
||||
* Remove all support for single user mode (2017-10-14).
|
||||
* Remove unused CONFIG_NXWIDGETS_EXTERNINIT configuration variable
|
||||
(2017-10-15).
|
||||
* CTaskBar: Fix type checking issue with GCC 6 From Sakari Kapanen
|
||||
(2017-11-08).
|
||||
* nxwm: Eliminate BOARDIOC_TSCTEST_SETUP (2018-01-17).
|
||||
* In NxWM unit test, call boardctl(BOARDIOC_INIT) if available and
|
||||
appropriate (2018-01-17).
|
||||
* Fix a dependency in Kconfig: CONFIG_NXWIDGET_SERVERINIT is definitely
|
||||
supported in the PROTECTED and KERNEL build modes (2018-01-18).
|
||||
|
||||
1.20 2018-xx-xx Gregory Nutt <gnutt@nuttx.org>
|
1551
Doxygen/Doxyfile
Normal file
64
Doxygen/README.txt
Normal 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
Doxygen/gendoc.sh
Executable 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"
|
||||
|
100
README.txt
Normal file
@ -0,0 +1,100 @@
|
||||
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
|
||||
===================
|
||||
|
||||
Kconfig
|
||||
|
||||
This is a Kconfig file that should be provided at apps/NxWidgets/Kconfig.
|
||||
When copied to that location, it will be used by the NuttX configuration
|
||||
systems to configure settings for NxWidgets and NxWM
|
||||
|
||||
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 NxTerm. 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-7.19 or above to work with the current
|
||||
NxWidgets-1.18 release.
|
642
ReleaseNotes.txt
Normal file
@ -0,0 +1,642 @@
|
||||
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 was 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 was 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)
|
||||
|
||||
NxWidgets-1.3
|
||||
=============
|
||||
|
||||
The 4th release of the NxWidgets package was made on September 29, 2012. This
|
||||
release depends on NuttX-6.22 or above and should not be used with older
|
||||
NuttX releases.
|
||||
|
||||
There are no functional changes in this release of NxWidgets. This release
|
||||
is required in order to retain compatibility with the most recent versions
|
||||
of NuttX. These comptibility changes include:
|
||||
|
||||
* Naming of function entry points
|
||||
* Build system changes
|
||||
* Changes needed for the NuttX configuration tool
|
||||
|
||||
NxWidgets-1.4
|
||||
=============
|
||||
|
||||
The 5th release of the NxWidgets package was made on December 20, 2012. This
|
||||
release depends on NuttX-6.24 or above and should not be used with older
|
||||
NuttX releases. This release corresponds to SVN revision r5447.
|
||||
|
||||
Note: Nearly all changes between 1.3 and 1.4 were the result of the efforts
|
||||
of Petteri Aimonen.
|
||||
|
||||
Additional new features and extended functionality in Version 1.4:
|
||||
|
||||
* NxWdigets::CNxServer: Reduce start-up delay
|
||||
* NxWM::CApplicationWindow: Option to eliminate minimize button.
|
||||
* NxWM::CTaskbar: Option to eliminte the background image; highlight current
|
||||
icon in the task bar.
|
||||
* NxWidgets::CNumericEdit: New widget. Basically a CLabel with +/- buttons.
|
||||
* NxWidgets::CNxTimer: Replace the original signal-based solution with a
|
||||
work queue-based solution. This raises some isses about using the
|
||||
internal work queues from user space.
|
||||
* Build System: Misc improvements.
|
||||
* Tools: bitmap_converter.py will convert images to NxWidgets RLE-encoded format.
|
||||
|
||||
Bugfixes (see the change log for details). Some of these are very important
|
||||
(marked *critical*):
|
||||
|
||||
* NxWidgets::CCallback: Misplaced #endif
|
||||
* NxWM::CCalculator and NxWM::CStartWindow: Add forward declaration for icon images.
|
||||
* glych_cycle: Correct width, destructor needs to be public.
|
||||
* NxWidgets:CText and NxWidgets:CNumericEdite: Fix some memory freeing bugs
|
||||
* NxWidgets::CScrollingPanel: It is borderless for now because there was no
|
||||
easy way to redraw only the required part of the border.
|
||||
|
||||
NxWidgets-1.5
|
||||
=============
|
||||
|
||||
The 6th release of the NxWidgets package was made on February 1, 2013. This
|
||||
release depends on NuttX-6.25 or above and should not be used with older
|
||||
NuttX releases. This release corresponds to SVN revision r5595.
|
||||
|
||||
Note: Nearly all of the changes between 1.4 and 1.5 were the result of the
|
||||
efforts of Petteri Aimonen.
|
||||
|
||||
Additional new features and extended functionality in Version 1.5:
|
||||
|
||||
* CNxWidgets::CTabPanel: A new widget contributed by Petteri Aimonen.
|
||||
This widget provides a tab panel, which has a button bar at the top
|
||||
and panels below it. Pressing a button will select the corresponding
|
||||
panel.
|
||||
* NxWidgets::CGraphicsPort: Many times we only want a constant background.
|
||||
In that case the old code filled the background, read it back, rendered
|
||||
the text and then wrote it back. When used with an LCD this causes
|
||||
some screen flicker. Added a variant of drawText that takes background
|
||||
color, so that the background and text can both be rendered at one go.
|
||||
* NxWM::CScrollingPanel::scrollChildren(): Avoid unnecessary redraws in
|
||||
CScrollingPanel
|
||||
* Kconfig: Added several "enabling" settings that must be selected to
|
||||
override the default setting.
|
||||
* UnitTests: Changes for compatibility with NuttX-6.25
|
||||
|
||||
Bugfixes:
|
||||
|
||||
* NxWidgets::CGraphicsPort::move(): Fix typo bug in bounding rectangle
|
||||
calculation.
|
||||
* NxWM::CCycleButton: Remove the separator from CCycleButton. It draws in
|
||||
wrong place, and doesn't look very good in the correct place either.
|
||||
* NxWidgets::CLabel: The label was drawn as a single rectangular region,
|
||||
then a text was added to the on top of this. The result is that the
|
||||
text would flicker when the CLabel was updated. With this change, the
|
||||
two step update is replaced with a five step update: The background
|
||||
is updated as four rectangulear regions (leaving the previous text in
|
||||
place), then the new text is updated. This eliminates the flicker.
|
||||
* CGraphicsPort::_drawText: Renamed from CGraphicsPort::drawText in order
|
||||
to eliminate some naming collisions when overloaded in some configurations
|
||||
(i.e., when both bool and nx_pixel_t are uint8_t).
|
||||
|
||||
NxWidgets-1.6
|
||||
=============
|
||||
|
||||
The 7th release of the NxWidgets package was made on March 15, 2013. This
|
||||
release depends on NuttX-6.26 or above and should not be used with older
|
||||
NuttX releases. This release corresponds to SVN revision r5745.
|
||||
|
||||
Note: All of the changes between 1.5 and 1.6 were the result of the
|
||||
efforts of Petteri Aimonen.
|
||||
|
||||
Additional new features and extended functionality in Version 1.6:
|
||||
|
||||
* NXWidgets::CNxWidget: Add an inline function to get the current style.
|
||||
* NXWidgets::CCycleButton: Make CCycleButton change state in onPreRelease().
|
||||
This way the new value is already available when a listener gets the
|
||||
action event.
|
||||
* NxWidgets::CImage: Two enhancements:
|
||||
1) Allow changing the bitmap even after the control has been created.
|
||||
2) Allow giving 'null' to have the control draw no image at all.
|
||||
|
||||
* NxWM::CTaskBar: Make a some methods of CTaskbar virtual to allow
|
||||
customizations.
|
||||
* NxWM::CTaskBar: Allow windows with null icon. This makes sense for e.g.
|
||||
full screen windows.
|
||||
* NxWM::CApplicationWindow: Add config options to override NxWM
|
||||
stop/minimize icons.
|
||||
* NwWM::CStartWindow, NxWM::CWindowMessenger: Get rid of the start window
|
||||
thread. Instead, handle all events through the USRWORK work queue.
|
||||
For me, this was necessary because I would open some files in button
|
||||
handlers and close them in NxTimer handlers. If these belonged to
|
||||
different tasks, the close operation would fail. Further benefits:
|
||||
+ Gets rid of one task and message queue.
|
||||
+ Reduces the amount of code required
|
||||
+ Decouples CStartWindow from everything else - now it is just a window
|
||||
with application icons, not an integral part of the event logic.
|
||||
+ All events come from the same thread, which reduces the possibility of
|
||||
multithreading errors in user code.
|
||||
+ The user code can also send events to USRWORK, so that everything gets
|
||||
serialized nicely without having to use so many mutexes.
|
||||
Drawbacks:
|
||||
- Currently the work state structure is malloc()ed, causing one allocation
|
||||
and free per each input event. Could add a memory pool for these later, but
|
||||
the speed difference doesn't seem noticeable.
|
||||
- The work queue will add ~50 ms latency to input events. This is however
|
||||
configurable, and the delay is anyway short enough that it is unnoticeable.
|
||||
|
||||
Bugfixes:
|
||||
|
||||
* NxWidgets::CWidgetControl: Added another semaphore, boundssem, which
|
||||
is set as soon as the screen bounds are known. This corrects two
|
||||
problems:
|
||||
1) Due to the way nxgl_rectsize computes the size, it will never
|
||||
be 0,0 like CWidgetControl expects. Therefore the size is considered
|
||||
valid even though it has not been set yet.
|
||||
2) After the check is fixed to test for > 1, NxWM window creation will
|
||||
hang. This is due to the fact that it uses the screen bounds for
|
||||
determining window size. This was being blocked on geosem, which
|
||||
is only posted after the size has been set.
|
||||
* NxWidgets::CNxTimer: Previously repeated timers were re-enabled after
|
||||
the timer action event. Consequently, if the action event handler tried
|
||||
to stop the timer, the request would be ignored. Changes the order
|
||||
so that the timer is re-enabled before the callback. There is still
|
||||
no risk of re-entrancy, because everything executes on the USRWORK work
|
||||
queue.
|
||||
* NxWidgets::CLabel: Fix backward conditional compilation in the "flicker
|
||||
free" logic.
|
||||
* NxWidgets::CMultiLineTestBox: Fix text placement error. From Petteri
|
||||
Aimonen.
|
||||
|
||||
* NxWidgets/tools/bitmap_converter.py: Fix bitmap_converter.py so that
|
||||
it works with indexed input images.
|
||||
|
||||
NxWidgets-1.7
|
||||
=============
|
||||
|
||||
The 8th release of the NxWidgets package was made on April 28, 2013. This
|
||||
release depends on NuttX-6.26 or above and should not be used with older
|
||||
NuttX releases.
|
||||
|
||||
Note: All of the changes between 1.6 and 1.7 were the result of the
|
||||
efforts of Petteri Aimonen.
|
||||
|
||||
Additional new features and extended functionality in Version 1.7:
|
||||
|
||||
* NxWidgets::CGlyphButton: Generate action event, like CButton does.
|
||||
* NxWM::CTaskBar: Add option CONFIG_NXWM_TASKBAR_NO_BORDER to suppress
|
||||
drawing of the border on the taskbar.
|
||||
* NxWidgets::CNxTimer: Add function to check if CNxTimer is running.
|
||||
* NxWidgets::CNxWidgets: Allow overriding of the checkCollision() method.
|
||||
|
||||
Bugfixes:
|
||||
|
||||
* NxWidgets bitmap_converter.py: Fix bug when image width > 255
|
||||
* NxWM::CScrollbarPanel: Fix spelling error in class name: CScollbarPanel
|
||||
should be CScrollbarPanel
|
||||
* NxWidgets::CGlyphButton: Prevent drawing outside of the bitmap size.
|
||||
|
||||
NxWidgets-1.8
|
||||
=============
|
||||
|
||||
The 9th release of the NxWidgets package was made on June 14, 2013. This
|
||||
release depends on NuttX-6.26 or above and should not be used with older
|
||||
NuttX releases.
|
||||
|
||||
Note: Most of the changes between 1.7 and 1.8 were the result of the
|
||||
efforts of Ken Pettit and Petteri Aimonen.
|
||||
|
||||
Additional new features and extended functionality in Version 1.8:
|
||||
|
||||
* NxWM::CMediaPlayer: Shell application for an MP3 Media Player (from Ken
|
||||
Pettit).
|
||||
* NxWidgets::CGlyphSliderHorizontal and NxWidgets::CGlyphSliderHorizontalGrip:
|
||||
New widgets added by Ken Pettit. Includes a Unit Test.
|
||||
* NxWidgets::CImage: Allow a NULL pointer for a bitmap (from Petteri
|
||||
Aimonen).
|
||||
* NxWidgets::CNumericEdit: Delay before auto-incrementing now varies: A
|
||||
longer delay is required to start auto-incrementing and speed increases
|
||||
while pressed (from Petteri Aimonen).
|
||||
* NxWM::CTaskbar: Add a method to redraw the taskbar and the current
|
||||
application. This should only be necessary if the display loses state due
|
||||
to e.g. powerdown or other manual intervention (from Petteri Aimonen).
|
||||
|
||||
Bugfixes:
|
||||
|
||||
* NxWM::CCalibration: Fix a race condition that would cause the calibration
|
||||
screen to fail to come up when its icon was touched (from Ken Pettit).
|
||||
* Default priorities for NxWidget and NxWM threads should be 100, not 50, to
|
||||
be consistent with other default priorities.
|
||||
* NxWidgets::CGlyphSliderHorizontal: Fix a drawing error (from Ken Pettit).
|
||||
* Update the way that NSH the Unit Tests are registered as built-in NSH
|
||||
applications.
|
||||
|
||||
NxWidgets-1.9
|
||||
=============
|
||||
|
||||
The 10th release of the NxWidgets package was made on October 28, 2013. This
|
||||
release depends on NuttX-6.26 or above and should not be used with older
|
||||
NuttX releases.
|
||||
|
||||
Additional new features and extended functionality in Version 1.9:
|
||||
|
||||
* NxWM::CCalibration.cxx/hxx: If CONFIG_NXWM_CALIBRATION_MESSAGES is
|
||||
defined then CCalibration will provide some instructions in the center
|
||||
of the display.
|
||||
* NxWM::CCalibration.cxx/hxx: Add options to collect and average
|
||||
multiple samples at each location. Also logic to discard the most
|
||||
extreme samples before averaging.
|
||||
* NxWidgets::CScaledBitmap: This new class is a wrapper for an class
|
||||
the exports IBitMap. It will perform scaling via bi-linear interpolation
|
||||
so that images can be scaled to any size desired.
|
||||
* NxWM::CTaskbar:: Can now be configured to scale taskbar icons using
|
||||
NxWidgets::CScaledBitmap.
|
||||
* NxWidgets/libnxwidgets/src/glyph_nxlogo320x320.cxx: Add a big, 320x320
|
||||
NuttX logo image. The older, smaller NuttX logo was renamed from
|
||||
nxlogo to nxlogo160x160 in all places.
|
||||
* NxWM::CCalibration and NxWM::CTouchscreen: Add a complex touchscreen
|
||||
scaling algorithm to handling the case where the measured X values also
|
||||
vary with y position (and vice versa).
|
||||
|
||||
Bugfixes:
|
||||
|
||||
(There are no bugfixes recorded for this release).
|
||||
|
||||
NxWidgets-1.10
|
||||
==============
|
||||
|
||||
The 11th release of the NxWidgets package was made on December 7, 2013. This
|
||||
release depends on NuttX-6.26 or above and should not be used with older
|
||||
NuttX releases.
|
||||
|
||||
Additional new features and extended functionality in Version 1.10:
|
||||
|
||||
* NxWM:Calibration and UnitTests/nxwm: Add logic to enable saving and
|
||||
recovering touchscreen calibration data. This depends upon having
|
||||
platform-dependent support for storage of configuration data. Portions
|
||||
suggested by Ken Pettit.
|
||||
|
||||
NxWidgets-1.11
|
||||
==============
|
||||
|
||||
The 12th release of the NxWidgets package was made on January 20, 2014. This
|
||||
release depends on NuttX-6.33 or above and should not be used with older
|
||||
NuttX releases.
|
||||
|
||||
Additional new features and extended functionality in Version 1.11:
|
||||
|
||||
* Primarily changes associated with the NuttX kernel build where the
|
||||
graphics application lies in user space and the graphics server lies in
|
||||
protected kernel space. This change is mostly a matter of repartitioning
|
||||
functionality and should not cause in any functional differences.
|
||||
|
||||
NxWidgets-1.12
|
||||
==============
|
||||
|
||||
The 13th release of the NxWidgets package was made on August 14, 2014. This
|
||||
release depends on NuttX-7.3 or above and should not be used with older
|
||||
NuttX releases.
|
||||
|
||||
Additional new features and extended functionality in Version 1.12:
|
||||
|
||||
* NxWM: Rename all ICON glyph files to include the size of the ICON as part
|
||||
of the file name. This allows us to support different sizes for the same
|
||||
ICON
|
||||
* NxWM: Add larger versions (approx 50x50) versions of all ICONs.
|
||||
* NxWM::CToolBar: Toolbar font ID can now be separately configured.
|
||||
* NxWM::CMediaPlayer: Will now dynamically position player controls
|
||||
based on the display and image sizes.
|
||||
* NxWM::CMediaPlayer: Add options to manage spacing of media player
|
||||
buttons and borders vs. borderless buttons.
|
||||
* NxWidget::CImage: Now includes methods to align images in the widget
|
||||
region.
|
||||
* NxWM::CMediaPlayer now uses the new CImage methods to align media controls
|
||||
in buttons.
|
||||
* NxWidgets::CStickyImage: A version of CImage that sticks in the selected
|
||||
state when clicked.
|
||||
* NxMW::CMediaPlayer: Now supports a pause button.
|
||||
* NxMW::CMediaPlayer: Convert CLabel to a CListBox to support selection of
|
||||
one of many media files to play. This should be a CScrollingTextBox to
|
||||
support an indefinitely large number of media files.
|
||||
* NxWidgets::CGlyphSliderHorizontal: No longer uses a hard-coded slider
|
||||
height; the slider height is now provided as a parameter, replacing the
|
||||
widget height which is now calculated from the glip image height.
|
||||
* NxWM::CMediaPlayer: Now calculates the volume slider height from the grip
|
||||
image height.
|
||||
* NxWidgets:CTabPanel: Make CTabPanel raise action event when tab is
|
||||
changed. Also add a function for getting the currently selected tab
|
||||
index. From Petteri Aimonen.
|
||||
* NxWidgets/Kconfig: Add configuration options to filter CMediaPlayer files
|
||||
based on extension.
|
||||
* NxWM::CMediaPlayer: Add logic to read files from the media mountpoint,
|
||||
filter them by extension, and display the file names in the listbox.
|
||||
* NxWM::CMediaPlayer: Now integrated with the NxPlayer library.
|
||||
* NxWidgets::CNxString: Add a getAllocSize() method to make it easier to
|
||||
convert CNxStrings to NUL-terminated C strings.
|
||||
* NxWM::CMediaPlayer: Add a CLabel that show the current fast forward/rewind
|
||||
speed.
|
||||
* NxWM::CKeyboard: Add support for a USB keyboard as the NxConsole and text
|
||||
widget input.
|
||||
|
||||
Bugfixes:
|
||||
|
||||
* NxWidgets: Fix typo RBG -> RGB. This makes NxWidgets incompatible with
|
||||
versions of NuttX 7.2 and below.
|
||||
* NxWidgets::CImage: Fix setImageLeft and setImageTop methods
|
||||
* NxMW::CMediaPlayer: Correctly catch the volume level change event.
|
||||
* NxWidgets::CGraphicsPort: Fix drawBitmapGreyScale method. Actually drew
|
||||
nothing because of several errors in positioning and buffer usage.
|
||||
* NxWidgets::CImage: Should not attempt to draw the "empty" regions at the
|
||||
top and the bottom of the image box in greyscale.
|
||||
* NxWidgets::CNxString: Make destructor virtual. From Petteri Aimonen.
|
||||
* NxWidgets::CTaskbar: Fix type of return value from openRawWindow()
|
||||
method. From Petteri Aimonen.
|
||||
* NxWidgets::CTabPanel: Modify behavior in showPage() method. Eliminate a
|
||||
duplicate redraw that caused flickering; re-order some logic so that
|
||||
widgets are hidden before operated on. From Petteri Aimonen.
|
||||
* NxWidgets::CNxTimer: Make CNxTimer stop itself before destruction.
|
||||
Otherwise a call to an invalid work queue entry may occur. From Petteri
|
||||
Aimonen.
|
||||
* NxWM::IApplicationFactory: Add a do-nothing, virtual destructor to
|
||||
eliminate a warning.
|
||||
* XWidgets::CNxWidget: Remove an unused bit field.
|
||||
|
||||
NxWidgets-1.13
|
||||
==============
|
||||
|
||||
The 14th release of the NxWidgets package was made on September 28, 2014. This
|
||||
release depends on NuttX-7.5 or above and should not be used with older
|
||||
NuttX releases.
|
||||
|
||||
Additional new features and extended functionality in Version 1.13:
|
||||
|
||||
* There are no new features in this release. This release simply updates
|
||||
some naming that is necessary for NxWidgets to build successfully with
|
||||
NuttX-7.5 and above.
|
||||
|
||||
Bugfixes:
|
||||
|
||||
* There are no new bug fixes in this release.
|
||||
|
||||
NxWidgets-1.14
|
||||
==============
|
||||
|
||||
The 15th release of the NxWidgets package was made on November 26, 2014. This
|
||||
release depends on NuttX-7.6 or above and should not be used with older
|
||||
NuttX releases.
|
||||
|
||||
Additional new features and extended functionality in Version 1.14:
|
||||
|
||||
* There are no new features in this release. This release simply correct
|
||||
all UnitTest/ files to account for the corrected syslog() prototype in
|
||||
NuttX 7.6. That change introduced an incompatibility between NuttX 7.6
|
||||
and previous versions of the UnitTest code.
|
||||
|
||||
Bugfixes:
|
||||
|
||||
* There are no new bug fixes in this release.
|
||||
|
||||
|
||||
NxWidgets-1.15
|
||||
==============
|
||||
|
||||
The 16th release of the NxWidgets package was made on April 14, 2015. This
|
||||
release depends on NuttX-7.24 or above and should not be used with older
|
||||
NuttX releases.
|
||||
|
||||
Additional new features and extended functionality in Version 1.15:
|
||||
|
||||
* The primary purpose of this release is update the NxWidgets and NxWM
|
||||
implementations to reflect changes in naming and interfaces in the
|
||||
NuttX 7.24 release
|
||||
* NxWidgets:: INxWindow, CNxWindow, CBgWindow, CNxTkWindow, CNxToolbar,
|
||||
CGraphicsPort updated to include a "caps" parameter in all drawLine()
|
||||
methods. This permits drawing a circular cap at the end of lines and
|
||||
better supports joining of line segments.
|
||||
|
||||
Bugfixes:
|
||||
|
||||
* There are no new bug fixes in this release.
|
||||
|
||||
NxWidgets-1.16
|
||||
==============
|
||||
|
||||
The 17th release of the NxWidgets package was made on June 1, 2016. This
|
||||
release depends on NuttX-7.16 or above and should not be used with older
|
||||
NuttX releases.
|
||||
|
||||
The TAG for this release is nuttx-7.16
|
||||
|
||||
Additional new features and extended functionality in Version 1.15:
|
||||
|
||||
* The NxWidgets/ directory has been removed from the NuttX GIT repository
|
||||
and now stands alone in its own repository (2015-06-27).
|
||||
|
||||
Bugfixes\:
|
||||
|
||||
* NxWM::CTouchscreen: When boardctl() fails, need to print errno not the
|
||||
returned value which will always be -1.
|
||||
* NxWidgets::CNxServer: Correct use of the BOARDIOC_GRAPHICS_SETUP
|
||||
boardctl() call.
|
||||
* CListBox unit test: Should use RAND_MAX, not MAX_RAND.
|
||||
* Framebuffer driver parameters have changed. This introduces an
|
||||
incompatibility with versions of NuttX prior to 7.16.
|
||||
* UnitTests: Add Make.defs files to all UnitTests directories. This is
|
||||
required by the current apps/Makefile. Hmmm.. This means that no one
|
||||
has built the NxWidgets packages in the last several realeases!
|
||||
* UnitTests: Add some default definitions to handle the (unusual) case
|
||||
where 'make clean' is called with no .config or Make.defs file installed
|
||||
|
||||
NxWidgets-1.17
|
||||
==============
|
||||
|
||||
The 18th release of the NxWidgets package was made on July 25, 2016. This
|
||||
release depends on NuttX-7.17 or above and should not be used with older
|
||||
NuttX releases.
|
||||
|
||||
The TAG for this release is nuttx-7.17
|
||||
|
||||
Additional new features and extended functionality in Version 1.17:
|
||||
|
||||
* There are no new features in this release. There are only updates
|
||||
necessary to use NxWidgets with other changes to NuttX-7.17. These
|
||||
changes include:
|
||||
|
||||
- Changes to debug macro names. dbg() and vdbg() are replaces with
|
||||
info(), warn(), and err().
|
||||
- Changes to Unittests/ Makefiles to deal with changes in the apps/
|
||||
build system.
|
||||
- Changes to pre-processor include statments needed to handle
|
||||
reorganization of the apps/include directory.
|
||||
- Update include paths to adapt to changes made to apps/ include path
|
||||
logic
|
||||
|
||||
Bugfixes\:
|
||||
|
||||
* None in this release
|
||||
|
||||
NxWidgets-1.18
|
||||
==============
|
||||
|
||||
The 19th release of the NxWidgets package was made on December 26, 2016. This
|
||||
release depends on NuttX-7.19 or above and should not be used with older
|
||||
NuttX releases.
|
||||
|
||||
The TAG for this release is nuttx-7.19
|
||||
|
||||
Additional new features and extended functionality in Version 1.18:
|
||||
|
||||
* libnxwidgets: Allow NxWidgets::CListDataItems subclasses access to text
|
||||
and value. From Petteri Aimonen.
|
||||
* Add setting task name via prctl() to NxWidgets::CNxServer and
|
||||
NxWM:CTouchScreen. From Petteri Aimonen.
|
||||
* libnxwidgets: In NxWidgets::CText, allow setting negative line spacing.
|
||||
This is useful to have text take up less space, as quite many fonts have
|
||||
large line spacings built-in. From Petteri Aimonen.
|
||||
* libnxwidgets: Allow setting line spacing in NxWidgets::CMultiLineTextBox.
|
||||
From Petteri Aimonen.
|
||||
* CNxServer: Remove NX server task. Now calls nx_start (indirectly through
|
||||
boardctrl(BOARDIOC_NX_START) to start the NX Server kernel thread.
|
||||
|
||||
Bugfixes:
|
||||
|
||||
* NxWM needs the path to the apps/include directory.
|
||||
* NxWidgets: Fix CListBox crash when clicked below the last item. From
|
||||
Petteri Aimonen.
|
||||
* libnxwdigets: Fix memory leak in CNxWindow and make behaviour match
|
||||
CNxTkWindow. From Petteri Aimonen.
|
||||
* libnxwidgets: Fix default text colors in NxWidgets::CListBox. From
|
||||
Petteri Aimonen.
|
||||
* libnxwidgets: Avoid unnecessary redraw in NxWidgets::CListBox. The
|
||||
ListData will raise an event that will cause a redraw anyway. Redrawing
|
||||
in click() caused double redraws. From Petteri Aimonen.
|
||||
* libnxwidgets: Fix coordinate handling in NxWidgets::CMultiLineTextBox.
|
||||
Related to 'Thu Feb 21 16:47:01 2013 Fix text placement in
|
||||
CMultiLineTextbox.' There was a few similar bugs remaining in calculating
|
||||
of rows to show and in clearing the background. From Petteri Aimonen.
|
||||
* CNxServer: Can't use printf in this context.
|
||||
|
||||
NxWidgets-1.19
|
||||
==============
|
||||
|
||||
The 20th release of the NxWidgets package was made on March 2, 2018. This
|
||||
release depends on NuttX-7.24 or above and should not be used with older
|
||||
NuttX releases.
|
||||
|
||||
The TAG for this release is nuttx-7.24
|
||||
|
||||
Additional new features and extended functionality in Version 1.19:
|
||||
|
||||
(There are no new graphics features. This release is for NuttX
|
||||
compatibility only and includes a few additional bugfixes)
|
||||
|
||||
Bugfixes and Updates for Compatibility with NuttX-7.24:
|
||||
|
||||
* Correct NX Server message queue names. Should not be /dev/nx*. They must
|
||||
be relative to /dev/mqueue so "nxabc" will appear at "/var/nxabc".
|
||||
* strcasecmp, strncasecmp, bzero, bcmp, and bcopy should be defined in
|
||||
strings.h, not string.h. bzero, bcmp, and bcopy are legacy functions; the
|
||||
contemporary counterparts should be used instead.
|
||||
* Unitests/nxwm: Change includes because up_cxxinitialize() is now
|
||||
prototyped in apps/include/platfor/cxxinitialize.h.
|
||||
* Prototype of nsh_telnetstart() has changed.
|
||||
* NxWidgets: Fix work_s initialization in cwindowmessenger.hxx. From Sakari
|
||||
Kapanen.
|
||||
* Remove all support for single user mode.
|
||||
* Remove unused CONFIG_NXWIDGETS_EXTERNINIT configuration variable.
|
||||
* CTaskBar: Fix type checking issue with GCC 6 From Sakari Kapanen.
|
||||
* nxwm: Eliminate BOARDIOC_TSCTEST_SETUP (2018-01-17).
|
||||
* In NxWM unit test, call boardctl(BOARDIOC_INIT) if available and
|
||||
appropriate (2018-01-17).
|
||||
* Fix a dependency in Kconfig: CONFIG_NXWIDGET_SERVERINIT is definitely
|
||||
supported in the PROTECTED and KERNEL build modes (2018-01-18).
|
||||
|
131
TODO.txt
Normal file
@ -0,0 +1,131 @@
|
||||
NxWidgets
|
||||
---------
|
||||
|
||||
Title: LARGE BITMAP SUPPORT
|
||||
Description: In CImage, m_origin.x and .y need to be allowed to go
|
||||
negative so that you can pan through a large image.
|
||||
Status: Open
|
||||
Priority: Low
|
||||
|
||||
Title: GLYPH BACKGROUNDS
|
||||
Description: For most glyphs, background could is set to the currently
|
||||
selected background color. An option should be to set the
|
||||
background of glyphs (only) to transparent.
|
||||
Status: Open
|
||||
Priority: Low for now
|
||||
|
||||
Title: MESSAGE BOX
|
||||
Description: Need the moral equivalent of a Windows message box: A
|
||||
simple, model window that provides a message a button to
|
||||
dismiss the message. This would be helpful, for example,
|
||||
to handle behaviors on errors instead of just failing
|
||||
quietly.
|
||||
Status: Open
|
||||
Priority: Low. Nothing depends on this now.
|
||||
|
||||
NxWM
|
||||
----
|
||||
|
||||
(4) General NxWMIssues
|
||||
(0) NxTerm Issues
|
||||
(0) CHexCalculator Issues
|
||||
(3) CMediaPlayer 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 drawn momentarily. This 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: 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 NxTerm Issues
|
||||
----------------
|
||||
|
||||
o CHexCalculator Issues
|
||||
---------------------
|
||||
|
||||
o CMediaPlayer Issues
|
||||
-------------------
|
||||
|
||||
Title: SCROLLING FILE LIST
|
||||
Description: Current implementation uses a CListBox which can only show a
|
||||
fixed number of files. Perhaps CMediaPlayer should use
|
||||
something like CScrollingTextBox.
|
||||
Status: Open
|
||||
Priority: Low for now
|
||||
|
||||
Title: PLAY PROGRESS FEEDBACK
|
||||
Decription: Need a way to know the position in the file, how long the
|
||||
file is (in minutes), and an indication when playing
|
||||
complete.
|
||||
Status: Open
|
||||
Priorit: Medium. Certain affect usability.
|
||||
|
||||
Title: NO BALANCE/TONE/EQUALIZER CONTORLS
|
||||
Description: The title says it all
|
||||
Status: Open
|
||||
Priority: Medium. That is big functional limitation.
|
||||
|
||||
o Platform specific Issues
|
||||
------------------------
|
||||
|
||||
Title: BUGS WHEN CANNOT READ FROM LCD
|
||||
Description: There is a kludge in the code 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
|
||||
|
10
UnitTests/CButton/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
38
UnitTests/CButton/Make.defs
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# NxWidgets/UnitTests/CButton/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
CONFIGURED_APPS += external
|
||||
|
179
UnitTests/CButton/Makefile
Normal file
@ -0,0 +1,179 @@
|
||||
#################################################################################
|
||||
# NxWidgets/Unitests/CButton/Makefile
|
||||
#
|
||||
# Copyright (C) 2012-2013, 2016 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)/Make.defs
|
||||
|
||||
OBJEXT ?= .o
|
||||
DELIM ?= /
|
||||
|
||||
include $(APPDIR)$(DELIM)Make.defs
|
||||
|
||||
# Add the path to the NXWidget include directory to the CFLAGS
|
||||
|
||||
NXWIDGETS_DIR="$(TESTDIR)$(DELIM)..$(DELIM)..$(DELIM)libnxwidgets"
|
||||
NXWIDGETS_INC="$(NXWIDGETS_DIR)$(DELIM)include"
|
||||
NXWIDGETS_LIB="$(NXWIDGETS_DIR)$(DELIM)libnxwidgets$(LIBEXT)"
|
||||
|
||||
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)$(DELIM)..$(DELIM)..$(DELIM)tools"
|
||||
ARCHIVER=$(TESTTOOL_DIR)$(DELIM)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)$(DELIM)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:
|
||||
$(Q) ( \
|
||||
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)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
ifeq ($(WINTOOL),y)
|
||||
$(Q) $(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
else
|
||||
$(Q) $(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
endif
|
||||
$(Q) touch .built
|
||||
|
||||
# Register NSH built-in application
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
||||
preconfig:
|
||||
|
||||
# Standard housekeeping targets
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(Q) $(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat)
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
BIN
UnitTests/CButton/cbutton-pushed.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
UnitTests/CButton/cbutton-released.png
Normal file
After Width: | Height: | Size: 19 KiB |
155
UnitTests/CButton/cbutton_main.cxx
Normal 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
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// nxheaders_main
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int cbutton_main(int argc, char *argv[])
|
||||
{
|
||||
// Create an instance of the font test
|
||||
|
||||
printf("cbutton_main: Create CButtonTest instance\n");
|
||||
CButtonTest *test = new CButtonTest();
|
||||
|
||||
// Connect the NX server
|
||||
|
||||
printf("cbutton_main: Connect the CButtonTest instance to the NX server\n");
|
||||
if (!test->connect())
|
||||
{
|
||||
printf("cbutton_main: Failed to connect the CButtonTest instance to the NX server\n");
|
||||
delete test;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Create a window to draw into
|
||||
|
||||
printf("cbutton_main: Create a Window\n");
|
||||
if (!test->createWindow())
|
||||
{
|
||||
printf("cbutton_main: Failed to create a window\n");
|
||||
delete test;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Create a CButton instance
|
||||
|
||||
CButton *button = test->createButton(g_pushme);
|
||||
if (!button)
|
||||
{
|
||||
printf("cbutton_main: Failed to create a button\n");
|
||||
delete test;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Show the button
|
||||
|
||||
printf("cbutton_main: Show the button\n");
|
||||
test->showButton(button);
|
||||
|
||||
// Wait two seconds, then perform a simulated mouse click on the button
|
||||
|
||||
sleep(2);
|
||||
printf("cbutton_main: Click the button\n");
|
||||
test->click();
|
||||
|
||||
// Poll for the mouse click event (of course this can hang if something fails)
|
||||
|
||||
bool clicked = test->poll(button);
|
||||
printf("cbutton_main: Button is %s\n", clicked ? "clicked" : "released");
|
||||
|
||||
// Wait a second, then release the mouse buttone
|
||||
|
||||
sleep(1);
|
||||
test->release();
|
||||
|
||||
// Poll for the mouse release event (of course this can hang if something fails)
|
||||
|
||||
clicked = test->poll(button);
|
||||
printf("cbutton_main: Button is %s\n", clicked ? "clicked" : "released");
|
||||
|
||||
// Wait a few more seconds so that the tester can ponder the result
|
||||
|
||||
sleep(3);
|
||||
|
||||
// Clean up and exit
|
||||
|
||||
printf("cbutton_main: Clean-up and exit\n");
|
||||
delete button;
|
||||
delete test;
|
||||
return 0;
|
||||
}
|
||||
|
325
UnitTests/CButton/cbuttontest.cxx
Normal file
@ -0,0 +1,325 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// NxWidgets/UnitTests/CButton/cbuttontest.cxx
|
||||
//
|
||||
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
// Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
|
||||
// me be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Included Files
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <nuttx/init.h>
|
||||
#include <cstdio>
|
||||
#include <cerrno>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/nx/nx.h>
|
||||
#include <nuttx/nx/nxfonts.h>
|
||||
|
||||
#include "nxconfig.hxx"
|
||||
#include "cbuttontest.hxx"
|
||||
#include "cbgwindow.hxx"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Private Classes
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Public Data
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Public Function Prototypes
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CButtonTest Method Implementations
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// CButtonTest Constructor
|
||||
|
||||
CButtonTest::CButtonTest()
|
||||
{
|
||||
m_bgWindow = (CBgWindow *)NULL;
|
||||
m_nxFont = (CNxFont *)NULL;
|
||||
m_text = (CNxString *)NULL;
|
||||
}
|
||||
|
||||
// CButtonTest Descriptor
|
||||
|
||||
CButtonTest::~CButtonTest()
|
||||
{
|
||||
disconnect();
|
||||
}
|
||||
|
||||
// Connect to the NX server
|
||||
|
||||
bool CButtonTest::connect(void)
|
||||
{
|
||||
// Connect to the server
|
||||
|
||||
bool nxConnected = CNxServer::connect();
|
||||
if (nxConnected)
|
||||
{
|
||||
// Create the default font instance
|
||||
|
||||
m_nxFont = new CNxFont(NXFONT_DEFAULT,
|
||||
CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR,
|
||||
CONFIG_NXWIDGETS_TRANSPARENT_COLOR);
|
||||
if (!m_nxFont)
|
||||
{
|
||||
printf("CButtonTest::connect: Failed to create the default font\n");
|
||||
}
|
||||
|
||||
// Set the background color
|
||||
|
||||
if (!setBackgroundColor(CONFIG_CBUTTONTEST_BGCOLOR))
|
||||
{
|
||||
printf("CButtonTest::connect: setBackgroundColor failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
return nxConnected;
|
||||
}
|
||||
|
||||
// Disconnect from the NX server
|
||||
|
||||
void CButtonTest::disconnect(void)
|
||||
{
|
||||
// Close the window
|
||||
|
||||
if (m_bgWindow)
|
||||
{
|
||||
delete m_bgWindow;
|
||||
}
|
||||
|
||||
// Free the display string
|
||||
|
||||
if (m_text)
|
||||
{
|
||||
delete m_text;
|
||||
m_text = (CNxString *)NULL;
|
||||
}
|
||||
|
||||
// Free the default font
|
||||
|
||||
if (m_nxFont)
|
||||
{
|
||||
delete m_nxFont;
|
||||
m_nxFont = (CNxFont *)NULL;
|
||||
}
|
||||
|
||||
// And disconnect from the server
|
||||
|
||||
CNxServer::disconnect();
|
||||
}
|
||||
|
||||
// Create the background window instance. This function illustrates
|
||||
// the basic steps to instantiate any window:
|
||||
//
|
||||
// 1) Create a dumb CWigetControl instance
|
||||
// 2) Pass the dumb CWidgetControl instance to the window constructor
|
||||
// that inherits from INxWindow. This will "smarten" the CWidgetControl
|
||||
// instance with some window knowlede
|
||||
// 3) Call the open() method on the window to display the window.
|
||||
// 4) After that, the fully smartened CWidgetControl instance can
|
||||
// be used to generate additional widgets by passing it to the
|
||||
// widget constructor
|
||||
|
||||
bool CButtonTest::createWindow(void)
|
||||
{
|
||||
// Initialize the widget control using the default style
|
||||
|
||||
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
|
||||
|
||||
// Get an (uninitialized) instance of the background window as a class
|
||||
// that derives from INxWindow.
|
||||
|
||||
m_bgWindow = getBgWindow(m_widgetControl);
|
||||
if (!m_bgWindow)
|
||||
{
|
||||
printf("CButtonTest::createGraphics: Failed to create CBgWindow instance\n");
|
||||
delete m_widgetControl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open (and initialize) the window
|
||||
|
||||
bool success = m_bgWindow->open();
|
||||
if (!success)
|
||||
{
|
||||
printf("CButtonTest::createGraphics: Failed to open background window\n");
|
||||
delete m_bgWindow;
|
||||
m_bgWindow = (CBgWindow*)0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Create a CButton instance
|
||||
|
||||
CButton *CButtonTest::createButton(FAR const char *text)
|
||||
{
|
||||
// Get the width of the display
|
||||
|
||||
struct nxgl_size_s windowSize;
|
||||
if (!m_bgWindow->getSize(&windowSize))
|
||||
{
|
||||
printf("CButtonTest::createGraphics: Failed to get window size\n");
|
||||
return (CButton *)NULL;
|
||||
}
|
||||
|
||||
// Create a CNxString instance to contain the C string
|
||||
|
||||
m_text = new CNxString(text);
|
||||
|
||||
// Get the height and width of the text display area
|
||||
|
||||
nxgl_coord_t stringWidth = m_nxFont->getStringWidth(*m_text);
|
||||
nxgl_coord_t stringHeight = (nxgl_coord_t)m_nxFont->getHeight();
|
||||
|
||||
// The default CButton has borders enabled with thickness of the border
|
||||
// width. Add twice the thickness of the borderto the width and height. (We
|
||||
// could let CButton do this for us by calling CButton::getPreferredDimensions())
|
||||
|
||||
stringWidth += 2 * 1;
|
||||
stringHeight += 2 * 1;
|
||||
|
||||
// Pick an X/Y position such that the button will be centered in the display
|
||||
|
||||
nxgl_coord_t buttonX;
|
||||
if (stringWidth >= windowSize.w)
|
||||
{
|
||||
buttonX = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonX = (windowSize.w - stringWidth) >> 1;
|
||||
}
|
||||
|
||||
nxgl_coord_t buttonY;
|
||||
if (stringHeight >= windowSize.h)
|
||||
{
|
||||
buttonY = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonY = (windowSize.h - stringHeight) >> 1;
|
||||
}
|
||||
|
||||
// Save the center position of the button for use by click and release
|
||||
|
||||
m_center.x = buttonX + (stringWidth >> 1);
|
||||
m_center.y = buttonY + (stringHeight >> 1);
|
||||
|
||||
// Now we have enough information to create the button
|
||||
|
||||
return new CButton(m_widgetControl, buttonX, buttonY, stringWidth, stringHeight, *m_text);
|
||||
}
|
||||
|
||||
// Draw the button
|
||||
|
||||
void CButtonTest::showButton(CButton *button)
|
||||
{
|
||||
button->enable(); // Un-necessary, the widget is enabled by default
|
||||
button->enableDrawing();
|
||||
button->redraw();
|
||||
}
|
||||
|
||||
// Perform a simulated mouse click on the button. This method injects
|
||||
// the mouse click through the NX heirarchy just as would real mouse
|
||||
// hardward.
|
||||
|
||||
void CButtonTest::click(void)
|
||||
{
|
||||
// nx_mousein is meant to be called by mouse handling software.
|
||||
// Here we just inject a left-button click directly in the center of
|
||||
// the button.
|
||||
|
||||
// First, get the server handle. Graphics software will never care
|
||||
// about the server handle. Here we need it to get access to the
|
||||
// low-level mouse interface
|
||||
|
||||
NXHANDLE handle = getServer();
|
||||
|
||||
// Then inject the mouse click
|
||||
|
||||
(void)nx_mousein(handle, m_center.x, m_center.y, NX_MOUSE_LEFTBUTTON);
|
||||
}
|
||||
|
||||
// The counterpart to click. This simulates a button release through
|
||||
// the same mechanism.
|
||||
|
||||
void CButtonTest::release(void)
|
||||
{
|
||||
// nx_mousein is meant to be called by mouse handling software.
|
||||
// Here we just inject a left-button click directly in the center of
|
||||
// the button.
|
||||
|
||||
// First, get the server handle. Graphics software will never care
|
||||
// about the server handle. Here we need it to get access to the
|
||||
// low-level mouse interface
|
||||
|
||||
NXHANDLE handle = getServer();
|
||||
|
||||
// Then inject the mouse click
|
||||
|
||||
(void)nx_mousein(handle, m_center.x, m_center.y, NX_MOUSE_NOBUTTONS);
|
||||
}
|
||||
|
||||
// Widget events are normally handled in a modal loop.
|
||||
// However, for this case we know when there should be press and release
|
||||
// events so we don't have to poll. We can just perform a one pass poll
|
||||
// then check if the event was processed corredly.
|
||||
|
||||
bool CButtonTest::poll(CButton *button)
|
||||
{
|
||||
// Poll for mouse events
|
||||
|
||||
m_widgetControl->pollEvents(button);
|
||||
|
||||
// And return the button clicked state
|
||||
|
||||
return button->isClicked();
|
||||
}
|
||||
|
157
UnitTests/CButton/cbuttontest.hxx
Normal 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
|
10
UnitTests/CButtonArray/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
38
UnitTests/CButtonArray/Make.defs
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# NxWidgets/UnitTests/CButtonArray/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
CONFIGURED_APPS += external
|
||||
|
179
UnitTests/CButtonArray/Makefile
Normal file
@ -0,0 +1,179 @@
|
||||
#################################################################################
|
||||
# NxWidgets/UnitTests/CButtonArray/Makefile
|
||||
#
|
||||
# Copyright (C) 2012-2013, 2016 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)/Make.defs
|
||||
|
||||
OBJEXT ?= .o
|
||||
DELIM ?= /
|
||||
|
||||
include $(APPDIR)$(DELIM)Make.defs
|
||||
|
||||
# Add the path to the NXWidget include directory to the CFLAGS
|
||||
|
||||
NXWIDGETS_DIR="$(TESTDIR)$(DELIM)..$(DELIM)..$(DELIM)libnxwidgets"
|
||||
NXWIDGETS_INC="$(NXWIDGETS_DIR)$(DELIM)include"
|
||||
NXWIDGETS_LIB="$(NXWIDGETS_DIR)$(DELIM)libnxwidgets$(LIBEXT)"
|
||||
|
||||
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)$(DELIM)..$(DELIM)..$(DELIM)tools"
|
||||
ARCHIVER=$(TESTTOOL_DIR)$(DELIM)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)$(DELIM)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:
|
||||
$(Q) ( \
|
||||
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)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
ifeq ($(WINTOOL),y)
|
||||
$(Q) $(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
else
|
||||
$(Q) $(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
endif
|
||||
$(Q) touch .built
|
||||
|
||||
# Register NSH built-in application
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
||||
preconfig:
|
||||
|
||||
# Standard housekeeping targets
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(Q) $(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat)
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
BIN
UnitTests/CButtonArray/cbuttonarray.png
Normal file
After Width: | Height: | Size: 35 KiB |
327
UnitTests/CButtonArray/cbuttonarray_main.cxx
Normal 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 */
|
||||
|
||||
printf("%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
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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");
|
||||
printf("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial);
|
||||
return 0;
|
||||
}
|
||||
|
301
UnitTests/CButtonArray/cbuttonarraytest.cxx
Normal 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))
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("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))
|
||||
{
|
||||
printf("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);
|
||||
}
|
||||
|
163
UnitTests/CButtonArray/cbuttonarraytest.hxx
Normal file
@ -0,0 +1,163 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
|
||||
// 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
|
10
UnitTests/CCheckBox/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
38
UnitTests/CCheckBox/Make.defs
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# NxWidgets/UnitTests/CCheckBox/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
CONFIGURED_APPS += external
|
||||
|
179
UnitTests/CCheckBox/Makefile
Normal file
@ -0,0 +1,179 @@
|
||||
#################################################################################
|
||||
# NxWidgets/UnitTests/CCheckBox/Makefile
|
||||
#
|
||||
# Copyright (C) 2012-2013, 2016 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)/Make.defs
|
||||
|
||||
OBJEXT ?= .o
|
||||
DELIM ?= /
|
||||
|
||||
include $(APPDIR)$(DELIM)Make.defs
|
||||
|
||||
# Add the path to the NXWidget include directory to the CFLAGS
|
||||
|
||||
NXWIDGETS_DIR="$(TESTDIR)$(DELIM)..$(DELIM)..$(DELIM)libnxwidgets"
|
||||
NXWIDGETS_INC="$(NXWIDGETS_DIR)$(DELIM)include"
|
||||
NXWIDGETS_LIB="$(NXWIDGETS_DIR)$(DELIM)libnxwidgets$(LIBEXT)"
|
||||
|
||||
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)$(DELIM)..$(DELIM)..$(DELIM)tools"
|
||||
ARCHIVER=$(TESTTOOL_DIR)$(DELIM)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)$(DELIM)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:
|
||||
$(Q) ( \
|
||||
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)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
ifeq ($(WINTOOL),y)
|
||||
$(Q) $(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
else
|
||||
$(Q) $(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
endif
|
||||
$(Q) touch .built
|
||||
|
||||
# Register NSH built-in application
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
||||
preconfig:
|
||||
|
||||
# Standard housekeeping targets
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(Q) $(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat)
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
BIN
UnitTests/CCheckBox/ccheckbox.png
Normal file
After Width: | Height: | Size: 20 KiB |
208
UnitTests/CCheckBox/ccheckbox_main.cxx
Normal file
@ -0,0 +1,208 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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 */
|
||||
|
||||
printf("\n%s:\n", msg);
|
||||
printf(" 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: nxheaders_main
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int ccheckbox_main(int argc, char *argv[])
|
||||
{
|
||||
// Initialize memory monitor logic
|
||||
|
||||
initMemoryUsage();
|
||||
|
||||
// Create an instance of the checkbox test
|
||||
|
||||
printf("ccheckbox_main: Create CCheckBoxTest instance\n");
|
||||
CCheckBoxTest *test = new CCheckBoxTest();
|
||||
updateMemoryUsage(g_mmprevious, "After creating CCheckBoxTest");
|
||||
|
||||
// Connect the NX server
|
||||
|
||||
printf("ccheckbox_main: Connect the CCheckBoxTest instance to the NX server\n");
|
||||
if (!test->connect())
|
||||
{
|
||||
printf("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
|
||||
|
||||
printf("ccheckbox_main: Create a Window\n");
|
||||
if (!test->createWindow())
|
||||
{
|
||||
printf("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
|
||||
|
||||
printf("ccheckbox_main: Click 1\n");
|
||||
test->clickCheckBox();
|
||||
usleep(500*1000);
|
||||
test->showCheckBoxState();
|
||||
updateMemoryUsage(g_mmprevious, "After click 1");
|
||||
usleep(500*1000);
|
||||
|
||||
printf("ccheckbox_main: Click 2\n");
|
||||
test->clickCheckBox();
|
||||
usleep(500*1000);
|
||||
test->showCheckBoxState();
|
||||
updateMemoryUsage(g_mmprevious, "After click 2");
|
||||
usleep(500*1000);
|
||||
|
||||
printf("ccheckbox_main: Click 3\n");
|
||||
test->clickCheckBox();
|
||||
usleep(500*1000);
|
||||
test->showCheckBoxState();
|
||||
updateMemoryUsage(g_mmprevious, "After click 3");
|
||||
sleep(2);
|
||||
|
||||
// Clean up and exit
|
||||
|
||||
printf("ccheckbox_main: Clean-up and exit\n");
|
||||
delete test;
|
||||
updateMemoryUsage(g_mmprevious, "After deleting the test");
|
||||
updateMemoryUsage(g_mmInitial, "Final memory usage");
|
||||
return 0;
|
||||
}
|
297
UnitTests/CCheckBox/ccheckboxtest.cxx
Normal 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))
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("CCheckBoxTest::createWindow: Failed to create CBgWindow instance\n");
|
||||
disconnect();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open (and initialize) the window
|
||||
|
||||
bool success = m_bgWindow->open();
|
||||
if (!success)
|
||||
{
|
||||
printf("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
|
||||
printf("CCheckBoxTest::showCheckBoxState Checkbox is in the unticked state\n");
|
||||
break;
|
||||
|
||||
case CCheckBox::CHECK_BOX_STATE_ON: // Checkbox is ticked
|
||||
printf("CCheckBoxTest::showCheckBoxState Check is in the ticked state\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
case CCheckBox::CHECK_BOX_STATE_MU: // Checkbox is in the third state
|
||||
printf("CCheckBoxTest::showCheckBoxState Checkbox is in the 3rd state\n");
|
||||
break;
|
||||
}
|
||||
}
|
133
UnitTests/CCheckBox/ccheckboxtest.hxx
Normal file
@ -0,0 +1,133 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
10
UnitTests/CGlyphButton/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
38
UnitTests/CGlyphButton/Make.defs
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# NxWidgets/UnitTests/CGlyphButton/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
CONFIGURED_APPS += external
|
||||
|
179
UnitTests/CGlyphButton/Makefile
Normal file
@ -0,0 +1,179 @@
|
||||
#################################################################################
|
||||
# NxWidgets/UnitTests/CGlyphButton/Makefile
|
||||
#
|
||||
# Copyright (C) 2012-2013, 2016 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)/Make.defs
|
||||
|
||||
OBJEXT ?= .o
|
||||
DELIM ?= /
|
||||
|
||||
include $(APPDIR)$(DELIM)Make.defs
|
||||
|
||||
# Add the path to the NXWidget include directory to the CFLAGS
|
||||
|
||||
NXWIDGETS_DIR="$(TESTDIR)$(DELIM)..$(DELIM)..$(DELIM)libnxwidgets"
|
||||
NXWIDGETS_INC="$(NXWIDGETS_DIR)$(DELIM)include"
|
||||
NXWIDGETS_LIB="$(NXWIDGETS_DIR)$(DELIM)libnxwidgets$(LIBEXT)"
|
||||
|
||||
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)$(DELIM)..$(DELIM)..$(DELIM)tools"
|
||||
ARCHIVER=$(TESTTOOL_DIR)$(DELIM)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)$(DELIM)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:
|
||||
$(Q) ( \
|
||||
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)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
ifeq ($(WINTOOL),y)
|
||||
$(Q) $(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
else
|
||||
$(Q) $(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
endif
|
||||
$(Q) touch .built
|
||||
|
||||
# Register NSH built-in application
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
||||
preconfig:
|
||||
|
||||
# Standard housekeeping targets
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(Q) $(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat)
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
225
UnitTests/CGlyphButton/cglyphbutton_main.cxx
Normal 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 */
|
||||
|
||||
printf("\n%s:\n", msg);
|
||||
printf(" 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
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// nxheaders_main
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int cglyphbutton_main(int argc, char *argv[])
|
||||
{
|
||||
// Initialize memory monitor logic
|
||||
|
||||
initMemoryUsage();
|
||||
|
||||
// Create an instance of the font test
|
||||
|
||||
printf("cglyphbutton_main: Create CGlyphButtonTest instance\n");
|
||||
CGlyphButtonTest *test = new CGlyphButtonTest();
|
||||
updateMemoryUsage(g_mmprevious, "After creating CGlyphButtonTest");
|
||||
|
||||
// Connect the NX server
|
||||
|
||||
printf("cglyphbutton_main: Connect the CGlyphButtonTest instance to the NX server\n");
|
||||
if (!test->connect())
|
||||
{
|
||||
printf("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
|
||||
|
||||
printf("cglyphbutton_main: Create a Window\n");
|
||||
if (!test->createWindow())
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("cglyphbutton_main: Failed to create a button\n");
|
||||
delete test;
|
||||
return 1;
|
||||
}
|
||||
updateMemoryUsage(g_mmprevious, "After creating the glyph button");
|
||||
|
||||
// Show the button
|
||||
|
||||
printf("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);
|
||||
printf("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);
|
||||
printf("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);
|
||||
printf("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
|
||||
|
||||
printf("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;
|
||||
}
|
||||
|
307
UnitTests/CGlyphButton/cglyphbuttontest.cxx
Normal 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))
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("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))
|
||||
{
|
||||
printf("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();
|
||||
}
|
||||
|
163
UnitTests/CGlyphButton/cglyphbuttontest.hxx
Normal file
@ -0,0 +1,163 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
|
||||
// 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
|
10
UnitTests/CGlyphSliderHorizontal/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
38
UnitTests/CGlyphSliderHorizontal/Make.defs
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# NxWidgets/UnitTests/CGlyphSliderHorizontal/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
CONFIGURED_APPS += external
|
||||
|
179
UnitTests/CGlyphSliderHorizontal/Makefile
Normal file
@ -0,0 +1,179 @@
|
||||
#################################################################################
|
||||
# NxWidgets/UnitTests/CGlyphSliderHorizontal/Makefile
|
||||
#
|
||||
# Copyright (C) 2012-2013, 2016 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)/Make.defs
|
||||
|
||||
OBJEXT ?= .o
|
||||
DELIM ?= /
|
||||
|
||||
include $(APPDIR)$(DELIM)Make.defs
|
||||
|
||||
# Add the path to the NXWidget include directory to the CFLAGS
|
||||
|
||||
NXWIDGETS_DIR="$(TESTDIR)$(DELIM)..$(DELIM)..$(DELIM)libnxwidgets"
|
||||
NXWIDGETS_INC="$(NXWIDGETS_DIR)$(DELIM)include"
|
||||
NXWIDGETS_LIB="$(NXWIDGETS_DIR)$(DELIM)libnxwidgets$(LIBEXT)"
|
||||
|
||||
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)$(DELIM)..$(DELIM)..$(DELIM)tools"
|
||||
ARCHIVER=$(TESTTOOL_DIR)$(DELIM)addobjs.sh
|
||||
|
||||
# Hello, World! C++ Example
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
CXXSRCS = cglyphsliderhorizontal_main.cxx cglyphsliderhorizontaltest.cxx
|
||||
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
|
||||
|
||||
POSIX_BIN = "$(APPDIR)$(DELIM)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 = cglyphsliderhorizontal
|
||||
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:
|
||||
$(Q) ( \
|
||||
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)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
ifeq ($(WINTOOL),y)
|
||||
$(Q) $(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
else
|
||||
$(Q) $(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
endif
|
||||
$(Q) touch .built
|
||||
|
||||
# Register NSH built-in application
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
||||
preconfig:
|
||||
|
||||
# Standard housekeeping targets
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(Q) $(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat)
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
230
UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontal_main.cxx
Normal file
@ -0,0 +1,230 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// NxWidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontal_main.cxx
|
||||
//
|
||||
// Copyright (C) 2012-2013 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 "cglyphsliderhorizontaltest.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 cglyphsliderhorizontal_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 */
|
||||
|
||||
printf("\n%s:\n", msg);
|
||||
printf(" 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: nxheaders_main
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int cglyphsliderhorizontal_main(int argc, char *argv[])
|
||||
{
|
||||
// Initialize memory monitor logic
|
||||
|
||||
initMemoryUsage();
|
||||
|
||||
// Create an instance of the checkbox test
|
||||
|
||||
printf("csliderhorizontal_main: Create CGlyphSliderHorizontalTest instance\n");
|
||||
CGlyphSliderHorizontalTest *test = new CGlyphSliderHorizontalTest();
|
||||
updateMemoryUsage(g_mmprevious, "After creating CGlyphSliderHorizontalTest");
|
||||
|
||||
// Connect the NX server
|
||||
|
||||
printf("csliderhorizontal_main: Connect the CGlyphSliderHorizontalTest instance to the NX server\n");
|
||||
if (!test->connect())
|
||||
{
|
||||
printf("csliderhorizontal_main: Failed to connect the CGlyphSliderHorizontalTest 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
|
||||
|
||||
printf("csliderhorizontal_main: Create a Window\n");
|
||||
if (!test->createWindow())
|
||||
{
|
||||
printf("csliderhorizontal_main: Failed to create a window\n");
|
||||
delete test;
|
||||
return 1;
|
||||
}
|
||||
updateMemoryUsage(g_mmprevious, "csliderhorizontal_main: After creating a window");
|
||||
|
||||
// Create a slider
|
||||
|
||||
printf("csliderhorizontal_main: Create a Slider\n");
|
||||
CGlyphSliderHorizontal *slider = test->createSlider();
|
||||
if (!slider)
|
||||
{
|
||||
printf("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);
|
||||
printf("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);
|
||||
|
||||
// Now move the slider up
|
||||
|
||||
for (int i = 0; i <= MAX_SLIDER; i++)
|
||||
{
|
||||
slider->setValue(i);
|
||||
test->showSlider(slider);
|
||||
printf("csliderhorizontal_main: %d. New value %d\n", i, slider->getValue());
|
||||
usleep(1000 * 50); // 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);
|
||||
printf("csliderhorizontal_main: %d. New value %d\n", i, slider->getValue());
|
||||
usleep(1000 * 50); // 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
|
||||
|
||||
printf("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;
|
||||
}
|
276
UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontaltest.cxx
Normal file
@ -0,0 +1,276 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// NxWidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontaltest.cxx
|
||||
//
|
||||
// Copyright (C) 2012-2013 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 "crlepalettebitmap.hxx"
|
||||
#include "cbgwindow.hxx"
|
||||
#include "cglyphsliderhorizontaltest.hxx"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Private Classes
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const NXWidgets::nxwidget_pixel_t hilight_palette[8] =
|
||||
{
|
||||
CONFIG_CGLYPHSLIDERHORIZONTALTEST_BGCOLOR, MKRGB( 61, 74,158), MKRGB(113,140,242), MKRGB(171,186,255),
|
||||
MKRGB(255,255,255), MKRGB(119,130,199), MKRGB(177,219,255), MKRGB(202,224,255),
|
||||
};
|
||||
|
||||
static const NXWidgets::SRlePaletteBitmapEntry vol_bitmap[] =
|
||||
{
|
||||
{ 22, 0}, /* Row 0 */
|
||||
{ 9, 0}, { 5, 7}, { 8, 0}, /* Row 1 */
|
||||
{ 6, 0}, { 2, 6}, { 6, 7}, { 2, 6}, { 1, 7}, { 5, 0}, /* Row 2 */
|
||||
{ 4, 0}, { 2, 3}, { 9, 6}, { 3, 3}, { 4, 0}, /* Row 3 */
|
||||
{ 3, 0}, { 5, 3}, { 6, 6}, { 5, 3}, { 3, 0}, /* Row 4 */
|
||||
{ 3, 0}, { 16, 3}, { 3, 0}, /* Row 5 */
|
||||
{ 2, 0}, { 2, 2}, { 13, 3}, { 3, 2}, { 2, 0}, /* Row 6 */
|
||||
{ 1, 0}, { 1, 5}, { 4, 2}, { 10, 3}, { 4, 2}, { 1, 5},
|
||||
{ 1, 0}, /* Row 7 */
|
||||
{ 1, 0}, { 2, 5}, { 15, 2}, { 3, 5}, { 1, 0}, /* Row 8 */
|
||||
{ 1, 0}, { 5, 5}, { 10, 2}, { 5, 5}, { 1, 0}, /* Row 9 */
|
||||
{ 1, 0}, { 2, 1}, { 15, 5}, { 3, 1}, { 1, 0}, /* Row 10 */
|
||||
{ 1, 0}, { 5, 1}, { 10, 5}, { 5, 1}, { 1, 0}, /* Row 11 */
|
||||
{ 1, 0}, { 20, 1}, { 1, 0}, /* Row 12 */
|
||||
{ 1, 0}, { 20, 1}, { 1, 0}, /* Row 13 */
|
||||
{ 1, 0}, { 19, 1}, { 1, 5}, { 1, 0}, /* Row 14 */
|
||||
{ 1, 0}, { 1, 5}, { 7, 1}, { 1, 5}, { 4, 2}, { 6, 1},
|
||||
{ 2, 0}, /* Row 15 */
|
||||
{ 2, 0}, { 5, 1}, { 8, 2}, { 4, 1}, { 1, 5}, { 2, 0}, /* Row 16 */
|
||||
{ 3, 0}, { 2, 1}, { 12, 2}, { 2, 1}, { 3, 0}, /* Row 17 */
|
||||
{ 3, 0}, { 1, 5}, { 1, 1}, { 13, 2}, { 1, 5}, { 3, 0}, /* Row 18 */
|
||||
{ 6, 0}, { 10, 2}, { 1, 5}, { 5, 0}, /* Row 19 */
|
||||
{ 6, 0}, { 1, 5}, { 8, 2}, { 7, 0}, /* Row 20 */
|
||||
{ 22, 0}, /* Row 21 */
|
||||
};
|
||||
|
||||
const struct NXWidgets::SRlePaletteBitmap g_mplayerVolBitmap =
|
||||
{
|
||||
16,
|
||||
CONFIG_NXWIDGETS_FMT,
|
||||
8,
|
||||
22,
|
||||
22,
|
||||
{hilight_palette, hilight_palette},
|
||||
vol_bitmap
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Public Data
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Public Function Prototypes
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CGlyphSliderHorizontalTest Method Implementations
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// CGlyphSliderHorizontalTest Constructor
|
||||
|
||||
CGlyphSliderHorizontalTest::CGlyphSliderHorizontalTest()
|
||||
{
|
||||
// Initialize state data
|
||||
|
||||
m_widgetControl = (CWidgetControl *)NULL;
|
||||
m_bgWindow = (CBgWindow *)NULL;
|
||||
}
|
||||
|
||||
// CGlyphSliderHorizontalTest Descriptor
|
||||
|
||||
CGlyphSliderHorizontalTest::~CGlyphSliderHorizontalTest(void)
|
||||
{
|
||||
disconnect();
|
||||
}
|
||||
|
||||
// Connect to the NX server
|
||||
|
||||
bool CGlyphSliderHorizontalTest::connect(void)
|
||||
{
|
||||
// Connect to the server
|
||||
|
||||
bool nxConnected = CNxServer::connect();
|
||||
if (nxConnected)
|
||||
{
|
||||
// Set the background color
|
||||
|
||||
if (!setBackgroundColor(CONFIG_CGLYPHSLIDERHORIZONTALTEST_BGCOLOR))
|
||||
{
|
||||
printf("CGlyphSliderHorizontalTest::connect: setBackgroundColor failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
return nxConnected;
|
||||
}
|
||||
|
||||
// Disconnect from the NX server
|
||||
|
||||
void CGlyphSliderHorizontalTest::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 CGlyphSliderHorizontalTest::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("CGlyphSliderHorizontalTest::createWindow: Failed to create CBgWindow instance\n");
|
||||
disconnect();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open (and initialize) the window
|
||||
|
||||
bool success = m_bgWindow->open();
|
||||
if (!success)
|
||||
{
|
||||
printf("CGlyphSliderHorizontalTest::createWindow: Failed to open background window\n");
|
||||
disconnect();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Create a slider in the center of the window
|
||||
|
||||
CGlyphSliderHorizontal *CGlyphSliderHorizontalTest::createSlider(void)
|
||||
{
|
||||
// Get the size of the display
|
||||
|
||||
struct nxgl_size_s windowSize;
|
||||
if (!m_bgWindow->getSize(&windowSize))
|
||||
{
|
||||
printf("CGlyphSliderHorizontalTest::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 = 26;
|
||||
nxgl_coord_t sliderY = (windowSize.h - sliderHeight) >> 1;
|
||||
|
||||
// Create the bitmap for the slider grip
|
||||
|
||||
NXWidgets::CRlePaletteBitmap *pBitmap = new NXWidgets::
|
||||
CRlePaletteBitmap(&g_mplayerVolBitmap);
|
||||
|
||||
// Create the slider
|
||||
|
||||
CGlyphSliderHorizontal *slider = new CGlyphSliderHorizontal(m_widgetControl,
|
||||
sliderX, sliderY,
|
||||
sliderWidth, sliderHeight,
|
||||
pBitmap, MKRGB(63, 90, 192));
|
||||
if (!slider)
|
||||
{
|
||||
printf("CGlyphSliderHorizontalTest::createSlider: Failed to create CGlyphSliderHorizontal\n");
|
||||
disconnect();
|
||||
}
|
||||
return slider;
|
||||
}
|
||||
|
||||
// (Re-)draw the slider.
|
||||
|
||||
void CGlyphSliderHorizontalTest::showSlider(CGlyphSliderHorizontal *slider)
|
||||
{
|
||||
slider->enable(); // Un-necessary, the widget is enabled by default
|
||||
slider->enableDrawing();
|
||||
slider->redraw();
|
||||
}
|
128
UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontaltest.hxx
Normal file
@ -0,0 +1,128 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// NxWidgets/UnitTests/CGlyphSliderHorizontal/cglyphsliderhorizontaltest.hxx
|
||||
//
|
||||
// Copyright (C) 2012-2013 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_CGLYPHSLIDERHORIZONTAL_CGLYPHSLIDERHORIZONTALTEST_HXX
|
||||
#define __UNITTESTS_CGLYPHSLIDERHORIZONTAL_CGLYPHSLIDERHORIZONTALTEST_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 "cglyphsliderhorizontal.hxx"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Configuration ////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef CONFIG_HAVE_CXX
|
||||
# error "CONFIG_HAVE_CXX must be defined"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_CGLYPHSLIDERHORIZONTALTEST_BGCOLOR
|
||||
# define CONFIG_CGLYPHSLIDERHORIZONTALTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Public Classes
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using namespace NXWidgets;
|
||||
|
||||
class CGlyphSliderHorizontalTest : public CNxServer
|
||||
{
|
||||
private:
|
||||
CWidgetControl *m_widgetControl; // The controlling widget for the window
|
||||
CBgWindow *m_bgWindow; // Background window instance
|
||||
|
||||
public:
|
||||
// Constructor/destructors
|
||||
|
||||
CGlyphSliderHorizontalTest(void);
|
||||
~CGlyphSliderHorizontalTest(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
|
||||
|
||||
CGlyphSliderHorizontal *createSlider(void);
|
||||
|
||||
// (Re-)draw the slider.
|
||||
|
||||
void showSlider(CGlyphSliderHorizontal *slider);
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Public Data
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Public Function Prototypes
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // __UNITTESTS_CGLYPHSLIDERHORIZONTAL_CGLYPHSLIDERHORIZONTALTEST_HXX
|
10
UnitTests/CImage/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
38
UnitTests/CImage/Make.defs
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# NxWidgets/UnitTests/CImage/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
CONFIGURED_APPS += external
|
||||
|
179
UnitTests/CImage/Makefile
Normal file
@ -0,0 +1,179 @@
|
||||
#################################################################################
|
||||
# NxWidgets/UnitTests/CImage/Makefile
|
||||
#
|
||||
# Copyright (C) 2012-2013, 2016 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)/Make.defs
|
||||
|
||||
OBJEXT ?= .o
|
||||
DELIM ?= /
|
||||
|
||||
include $(APPDIR)$(DELIM)Make.defs
|
||||
|
||||
# Add the path to the NXWidget include directory to the CFLAGS
|
||||
|
||||
NXWIDGETS_DIR="$(TESTDIR)$(DELIM)..$(DELIM)..$(DELIM)libnxwidgets"
|
||||
NXWIDGETS_INC="$(NXWIDGETS_DIR)$(DELIM)include"
|
||||
NXWIDGETS_LIB="$(NXWIDGETS_DIR)$(DELIM)libnxwidgets$(LIBEXT)"
|
||||
|
||||
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)$(DELIM)..$(DELIM)..$(DELIM)tools"
|
||||
ARCHIVER=$(TESTTOOL_DIR)$(DELIM)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)$(DELIM)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:
|
||||
$(Q) ( \
|
||||
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)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
ifeq ($(WINTOOL),y)
|
||||
$(Q) $(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
else
|
||||
$(Q) $(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
endif
|
||||
$(Q) touch .built
|
||||
|
||||
# Register NSH built-in application
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
||||
preconfig:
|
||||
|
||||
# Standard housekeeping targets
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(Q) $(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat)
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
222
UnitTests/CImage/cimage_main.cxx
Normal 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)
|
||||
{
|
||||
printf("VARIABLE BEFORE AFTER\n");
|
||||
printf("======== ======== ========\n");
|
||||
printf("arena %8d %8d\n", mmbefore->arena, mmafter->arena);
|
||||
printf("ordblks %8d %8d\n", mmbefore->ordblks, mmafter->ordblks);
|
||||
printf("mxordblk %8d %8d\n", mmbefore->mxordblk, mmafter->mxordblk);
|
||||
printf("uordblks %8d %8d\n", mmbefore->uordblks, mmafter->uordblks);
|
||||
printf("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 */
|
||||
|
||||
printf("\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: nxheaders_main
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int cimage_main(int argc, char *argv[])
|
||||
{
|
||||
// Initialize memory monitor logic
|
||||
|
||||
initMemoryUsage();
|
||||
|
||||
// Create an instance of the font test
|
||||
|
||||
printf("cimage_main: Create CImageTest instance\n");
|
||||
CImageTest *test = new CImageTest();
|
||||
updateMemoryUsage(&g_mmprevious, "After creating CImageTest");
|
||||
|
||||
// Connect the NX server
|
||||
|
||||
printf("cimage_main: Connect the CImageTest instance to the NX server\n");
|
||||
if (!test->connect())
|
||||
{
|
||||
printf("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
|
||||
|
||||
printf("cimage_main: Create a Window\n");
|
||||
if (!test->createWindow())
|
||||
{
|
||||
printf("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_nuttxBitmap160x160);
|
||||
updateMemoryUsage(&g_mmprevious, "After creating the bitmap");
|
||||
|
||||
// Create a CImage instance
|
||||
|
||||
CImage *image = test->createImage(static_cast<IBitmap*>(nuttxBitmap));
|
||||
if (!image)
|
||||
{
|
||||
printf("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
|
||||
|
||||
printf("cimage_main: Clean-up and exit\n");
|
||||
delete image;
|
||||
updateMemoryUsage(&g_mmprevious, "After deleting CImage");
|
||||
|
||||
delete nuttxBitmap;
|
||||
updateMemoryUsage(&g_mmprevious, "After deleting the bitmap");
|
||||
|
||||
delete test;
|
||||
updateMemoryUsage(&g_mmprevious, "After deleting the test");
|
||||
updateMemoryUsage(&g_mmInitial, "Final memory usage");
|
||||
return 0;
|
||||
}
|
||||
|
240
UnitTests/CImage/cimagetest.cxx
Normal 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))
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("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))
|
||||
{
|
||||
printf("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();
|
||||
}
|
131
UnitTests/CImage/cimagetest.hxx
Normal file
@ -0,0 +1,131 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
10
UnitTests/CKeypad/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
38
UnitTests/CKeypad/Make.defs
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# NxWidgets/UnitTests/CKeypad/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
CONFIGURED_APPS += external
|
||||
|
179
UnitTests/CKeypad/Makefile
Normal file
@ -0,0 +1,179 @@
|
||||
#################################################################################
|
||||
# NxWidgets/UnitTests/CKeyPad/Makefile
|
||||
#
|
||||
# Copyright (C) 2012-2013, 2016 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)/Make.defs
|
||||
|
||||
OBJEXT ?= .o
|
||||
DELIM ?= /
|
||||
|
||||
include $(APPDIR)$(DELIM)Make.defs
|
||||
|
||||
# Add the path to the NXWidget include directory to the CFLAGS
|
||||
|
||||
NXWIDGETS_DIR="$(TESTDIR)$(DELIM)..$(DELIM)..$(DELIM)libnxwidgets"
|
||||
NXWIDGETS_INC="$(NXWIDGETS_DIR)$(DELIM)include"
|
||||
NXWIDGETS_LIB="$(NXWIDGETS_DIR)$(DELIM)libnxwidgets$(LIBEXT)"
|
||||
|
||||
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)$(DELIM)..$(DELIM)..$(DELIM)tools"
|
||||
ARCHIVER=$(TESTTOOL_DIR)$(DELIM)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)$(DELIM)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:
|
||||
$(Q) ( \
|
||||
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)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
ifeq ($(WINTOOL),y)
|
||||
$(Q) $(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
else
|
||||
$(Q) $(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
endif
|
||||
$(Q) touch .built
|
||||
|
||||
# Register NSH built-in application
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
||||
preconfig:
|
||||
|
||||
# Standard housekeeping targets
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(Q) $(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat)
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
274
UnitTests/CKeypad/ckeypad_main.cxx
Normal 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 */
|
||||
|
||||
printf("%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
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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");
|
||||
printf("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial);
|
||||
return 0;
|
||||
}
|
||||
|
458
UnitTests/CKeypad/ckeypadtest.cxx
Normal 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))
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("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))
|
||||
{
|
||||
printf("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))
|
||||
{
|
||||
printf("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))
|
||||
{
|
||||
printf("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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
173
UnitTests/CKeypad/ckeypadtest.hxx
Normal file
@ -0,0 +1,173 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
|
||||
// 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
|
10
UnitTests/CLabel/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
38
UnitTests/CLabel/Make.defs
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# NxWidgets/UnitTests/CLabel/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
CONFIGURED_APPS += external
|
||||
|
179
UnitTests/CLabel/Makefile
Normal file
@ -0,0 +1,179 @@
|
||||
#################################################################################
|
||||
# NxWidgets/UnitTests/CLabel/Makefile
|
||||
#
|
||||
# Copyright (C) 2012-2013, 2016 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)/Make.defs
|
||||
|
||||
OBJEXT ?= .o
|
||||
DELIM ?= /
|
||||
|
||||
include $(APPDIR)$(DELIM)Make.defs
|
||||
|
||||
# Add the path to the NXWidget include directory to the CFLAGS
|
||||
|
||||
NXWIDGETS_DIR="$(TESTDIR)$(DELIM)..$(DELIM)..$(DELIM)libnxwidgets"
|
||||
NXWIDGETS_INC="$(NXWIDGETS_DIR)$(DELIM)include"
|
||||
NXWIDGETS_LIB="$(NXWIDGETS_DIR)$(DELIM)libnxwidgets$(LIBEXT)"
|
||||
|
||||
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)$(DELIM)..$(DELIM)..$(DELIM)tools"
|
||||
ARCHIVER=$(TESTTOOL_DIR)$(DELIM)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)$(DELIM)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:
|
||||
$(Q) ( \
|
||||
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)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
ifeq ($(WINTOOL),y)
|
||||
$(Q) $(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
else
|
||||
$(Q) $(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
endif
|
||||
$(Q) touch .built
|
||||
|
||||
# Register NSH built-in application
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
||||
preconfig:
|
||||
|
||||
# Standard housekeeping targets
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(Q) $(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat)
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
BIN
UnitTests/CLabel/clabel.png
Normal file
After Width: | Height: | Size: 18 KiB |
130
UnitTests/CLabel/clabel_main.cxx
Normal 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
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// nxheaders_main
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int clabel_main(int argc, char *argv[])
|
||||
{
|
||||
// Create an instance of the font test
|
||||
|
||||
printf("clabel_main: Create CLabelTest instance\n");
|
||||
CLabelTest *test = new CLabelTest();
|
||||
|
||||
// Connect the NX server
|
||||
|
||||
printf("clabel_main: Connect the CLabelTest instance to the NX server\n");
|
||||
if (!test->connect())
|
||||
{
|
||||
printf("clabel_main: Failed to connect the CLabelTest instance to the NX server\n");
|
||||
delete test;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Create a window to draw into
|
||||
|
||||
printf("clabel_main: Create a Window\n");
|
||||
if (!test->createWindow())
|
||||
{
|
||||
printf("clabel_main: Failed to create a window\n");
|
||||
delete test;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Create a CLabel instance
|
||||
|
||||
CLabel *label = test->createLabel(g_hello);
|
||||
if (!label)
|
||||
{
|
||||
printf("clabel_main: Failed to create a label\n");
|
||||
delete test;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Show the label
|
||||
|
||||
test->showLabel(label);
|
||||
sleep(5);
|
||||
|
||||
// Clean up and exit
|
||||
|
||||
printf("clabel_main: Clean-up and exit\n");
|
||||
delete label;
|
||||
delete test;
|
||||
return 0;
|
||||
}
|
||||
|
263
UnitTests/CLabel/clabeltest.cxx
Normal file
@ -0,0 +1,263 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// NxWidgets/UnitTests/CLabel/clabeltest.cxx
|
||||
//
|
||||
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
// Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
|
||||
// me be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Included Files
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <nuttx/init.h>
|
||||
#include <cstdio>
|
||||
#include <cerrno>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/nx/nx.h>
|
||||
#include <nuttx/nx/nxfonts.h>
|
||||
|
||||
#include "nxconfig.hxx"
|
||||
#include "clabeltest.hxx"
|
||||
#include "cbgwindow.hxx"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Definitions
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Private Classes
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Public Data
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Public Function Prototypes
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CLabelTest Method Implementations
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// CLabelTest Constructor
|
||||
|
||||
CLabelTest::CLabelTest()
|
||||
{
|
||||
m_bgWindow = (CBgWindow *)NULL;
|
||||
m_nxFont = (CNxFont *)NULL;
|
||||
m_text = (CNxString *)NULL;
|
||||
}
|
||||
|
||||
// CLabelTest Descriptor
|
||||
|
||||
CLabelTest::~CLabelTest()
|
||||
{
|
||||
disconnect();
|
||||
}
|
||||
|
||||
// Connect to the NX server
|
||||
|
||||
bool CLabelTest::connect(void)
|
||||
{
|
||||
// Connect to the server
|
||||
|
||||
bool nxConnected = CNxServer::connect();
|
||||
if (nxConnected)
|
||||
{
|
||||
// Create the default font instance
|
||||
|
||||
m_nxFont = new CNxFont(NXFONT_DEFAULT,
|
||||
CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR,
|
||||
CONFIG_NXWIDGETS_TRANSPARENT_COLOR);
|
||||
if (!m_nxFont)
|
||||
{
|
||||
printf("CLabelTest::connect: Failed to create the default font\n");
|
||||
}
|
||||
|
||||
// Set the background color
|
||||
|
||||
if (!setBackgroundColor(CONFIG_CLABELTEST_BGCOLOR))
|
||||
{
|
||||
printf("CLabelTest::connect: setBackgroundColor failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
return nxConnected;
|
||||
}
|
||||
|
||||
// Disconnect from the NX server
|
||||
|
||||
void CLabelTest::disconnect(void)
|
||||
{
|
||||
// Close the window
|
||||
|
||||
if (m_bgWindow)
|
||||
{
|
||||
delete m_bgWindow;
|
||||
}
|
||||
|
||||
// Free the display string
|
||||
|
||||
if (m_text)
|
||||
{
|
||||
delete m_text;
|
||||
m_text = (CNxString *)NULL;
|
||||
}
|
||||
|
||||
// Free the default font
|
||||
|
||||
if (m_nxFont)
|
||||
{
|
||||
delete m_nxFont;
|
||||
m_nxFont = (CNxFont *)NULL;
|
||||
}
|
||||
|
||||
// And disconnect from the server
|
||||
|
||||
CNxServer::disconnect();
|
||||
}
|
||||
|
||||
// Create the background window instance. This function illustrates
|
||||
// the basic steps to instantiate any window:
|
||||
//
|
||||
// 1) Create a dumb CWigetControl instance
|
||||
// 2) Pass the dumb CWidgetControl instance to the window constructor
|
||||
// that inherits from INxWindow. This will "smarten" the CWidgetControl
|
||||
// instance with some window knowlede
|
||||
// 3) Call the open() method on the window to display the window.
|
||||
// 4) After that, the fully smartened CWidgetControl instance can
|
||||
// be used to generate additional widgets by passing it to the
|
||||
// widget constructor
|
||||
|
||||
bool CLabelTest::createWindow(void)
|
||||
{
|
||||
// Initialize the widget control using the default style
|
||||
|
||||
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
|
||||
|
||||
// Get an (uninitialized) instance of the background window as a class
|
||||
// that derives from INxWindow.
|
||||
|
||||
m_bgWindow = getBgWindow(m_widgetControl);
|
||||
if (!m_bgWindow)
|
||||
{
|
||||
printf("CLabelTest::createGraphics: Failed to create CBgWindow instance\n");
|
||||
delete m_widgetControl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open (and initialize) the window
|
||||
|
||||
bool success = m_bgWindow->open();
|
||||
if (!success)
|
||||
{
|
||||
printf("CLabelTest::createGraphics: Failed to open background window\n");
|
||||
delete m_bgWindow;
|
||||
m_bgWindow = (CBgWindow*)0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Create a CLabel instance
|
||||
|
||||
CLabel *CLabelTest::createLabel(FAR const char *text)
|
||||
{
|
||||
// Get the width of the display
|
||||
|
||||
struct nxgl_size_s windowSize;
|
||||
if (!m_bgWindow->getSize(&windowSize))
|
||||
{
|
||||
printf("CLabelTest::createGraphics: Failed to get window size\n");
|
||||
return (CLabel *)NULL;
|
||||
}
|
||||
|
||||
// Create a CNxString instance to contain the C string
|
||||
|
||||
m_text = new CNxString(text);
|
||||
|
||||
// Get the height and width of the text display area
|
||||
|
||||
nxgl_coord_t stringWidth = m_nxFont->getStringWidth(*m_text);
|
||||
nxgl_coord_t stringHeight = (nxgl_coord_t)m_nxFont->getHeight();
|
||||
|
||||
// The default CLabel has borders enabled with thickness of the border
|
||||
// width. Add twice the thickness of the border to the width and height. (We
|
||||
// could let CLabel do this for us by calling CLabel::getPreferredDimensions())
|
||||
|
||||
stringWidth += 2 * 1;
|
||||
stringHeight += 2 * 1;
|
||||
|
||||
// Pick an X/Y position such that the label will be centered in the display
|
||||
|
||||
nxgl_coord_t labelX;
|
||||
if (stringWidth >= windowSize.w)
|
||||
{
|
||||
labelX = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
labelX = (windowSize.w - stringWidth) >> 1;
|
||||
}
|
||||
|
||||
nxgl_coord_t labelY;
|
||||
if (stringHeight >= windowSize.h)
|
||||
{
|
||||
labelY = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
labelY = (windowSize.h - stringHeight) >> 1;
|
||||
}
|
||||
|
||||
// Now we have enough information to create the label
|
||||
|
||||
return new CLabel(m_widgetControl, labelX, labelY, stringWidth, stringHeight, *m_text);
|
||||
}
|
||||
|
||||
// Draw the label
|
||||
|
||||
void CLabelTest::showLabel(CLabel *label)
|
||||
{
|
||||
label->enable();
|
||||
label->enableDrawing();
|
||||
label->redraw();
|
||||
label->disableDrawing();
|
||||
}
|
138
UnitTests/CLabel/clabeltest.hxx
Normal 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
|
10
UnitTests/CLatchButton/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
38
UnitTests/CLatchButton/Make.defs
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# NxWidgets/UnitTests/CLatchButton/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
CONFIGURED_APPS += external
|
||||
|
179
UnitTests/CLatchButton/Makefile
Normal file
@ -0,0 +1,179 @@
|
||||
#################################################################################
|
||||
# NxWidgets/UnitTests/CLatchButton/Makefile
|
||||
#
|
||||
# Copyright (C) 2012-2013, 2016 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)/Make.defs
|
||||
|
||||
OBJEXT ?= .o
|
||||
DELIM ?= /
|
||||
|
||||
include $(APPDIR)$(DELIM)Make.defs
|
||||
|
||||
# Add the path to the NXWidget include directory to the CFLAGS
|
||||
|
||||
NXWIDGETS_DIR="$(TESTDIR)$(DELIM)..$(DELIM)..$(DELIM)libnxwidgets"
|
||||
NXWIDGETS_INC="$(NXWIDGETS_DIR)$(DELIM)include"
|
||||
NXWIDGETS_LIB="$(NXWIDGETS_DIR)$(DELIM)libnxwidgets$(LIBEXT)"
|
||||
|
||||
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)$(DELIM)..$(DELIM)..$(DELIM)tools"
|
||||
ARCHIVER=$(TESTTOOL_DIR)$(DELIM)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)$(DELIM)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:
|
||||
$(Q) ( \
|
||||
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)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
ifeq ($(WINTOOL),y)
|
||||
$(Q) $(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
else
|
||||
$(Q) $(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
endif
|
||||
$(Q) touch .built
|
||||
|
||||
# Register NSH built-in application
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
||||
preconfig:
|
||||
|
||||
# Standard housekeeping targets
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(Q) $(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat)
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
199
UnitTests/CLatchButton/clatchbutton_main.cxx
Normal 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
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
}
|
||||
|
321
UnitTests/CLatchButton/clatchbuttontest.cxx
Normal 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);
|
||||
}
|
||||
|
155
UnitTests/CLatchButton/clatchbuttontest.hxx
Normal 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
|
10
UnitTests/CLatchButtonArray/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
38
UnitTests/CLatchButtonArray/Make.defs
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# NxWidgets/UnitTests/CLatchButtonArray/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
CONFIGURED_APPS += external
|
||||
|
179
UnitTests/CLatchButtonArray/Makefile
Normal file
@ -0,0 +1,179 @@
|
||||
#################################################################################
|
||||
# NxWidgets/UnitTests/CLatchButtonArray/Makefile
|
||||
#
|
||||
# Copyright (C) 2012-2013, 2016 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)/Make.defs
|
||||
|
||||
OBJEXT ?= .o
|
||||
DELIM ?= /
|
||||
|
||||
include $(APPDIR)$(DELIM)Make.defs
|
||||
|
||||
# Add the path to the NXWidget include directory to the CFLAGS
|
||||
|
||||
NXWIDGETS_DIR="$(TESTDIR)$(DELIM)..$(DELIM)..$(DELIM)libnxwidgets"
|
||||
NXWIDGETS_INC="$(NXWIDGETS_DIR)$(DELIM)include"
|
||||
NXWIDGETS_LIB="$(NXWIDGETS_DIR)$(DELIM)libnxwidgets$(LIBEXT)"
|
||||
|
||||
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)$(DELIM)..$(DELIM)..$(DELIM)tools"
|
||||
ARCHIVER=$(TESTTOOL_DIR)$(DELIM)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)$(DELIM)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:
|
||||
$(Q) ( \
|
||||
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)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
ifeq ($(WINTOOL),y)
|
||||
$(Q) $(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
else
|
||||
$(Q) $(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
endif
|
||||
$(Q) touch .built
|
||||
|
||||
# Register NSH built-in application
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
||||
preconfig:
|
||||
|
||||
# Standard housekeeping targets
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(Q) $(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat)
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
301
UnitTests/CLatchButtonArray/clatchbuttonarray_main.cxx
Normal 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 */
|
||||
|
||||
printf("%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
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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");
|
||||
printf("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial);
|
||||
return 0;
|
||||
}
|
||||
|
301
UnitTests/CLatchButtonArray/clatchbuttonarraytest.cxx
Normal 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))
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("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))
|
||||
{
|
||||
printf("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);
|
||||
}
|
||||
|
163
UnitTests/CLatchButtonArray/clatchbuttonarraytest.hxx
Normal file
@ -0,0 +1,163 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
|
||||
// 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
|
10
UnitTests/CListBox/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
38
UnitTests/CListBox/Make.defs
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# NxWidgets/UnitTests/CListBox/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
CONFIGURED_APPS += external
|
||||
|
179
UnitTests/CListBox/Makefile
Normal file
@ -0,0 +1,179 @@
|
||||
#################################################################################
|
||||
# NxWidgets/UnitTests/CListBox/Makefile
|
||||
#
|
||||
# Copyright (C) 2012-2013, 2016 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)/Make.defs
|
||||
|
||||
OBJEXT ?= .o
|
||||
DELIM ?= /
|
||||
|
||||
include $(APPDIR)$(DELIM)Make.defs
|
||||
|
||||
# Add the path to the NXWidget include directory to the CFLAGS
|
||||
|
||||
NXWIDGETS_DIR="$(TESTDIR)$(DELIM)..$(DELIM)..$(DELIM)libnxwidgets"
|
||||
NXWIDGETS_INC="$(NXWIDGETS_DIR)$(DELIM)include"
|
||||
NXWIDGETS_LIB="$(NXWIDGETS_DIR)$(DELIM)libnxwidgets$(LIBEXT)"
|
||||
|
||||
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)$(DELIM)..$(DELIM)..$(DELIM)tools"
|
||||
ARCHIVER=$(TESTTOOL_DIR)$(DELIM)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)$(DELIM)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:
|
||||
$(Q) ( \
|
||||
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)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
ifeq ($(WINTOOL),y)
|
||||
$(Q) $(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
else
|
||||
$(Q) $(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
endif
|
||||
$(Q) touch .built
|
||||
|
||||
# Register NSH built-in application
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
||||
preconfig:
|
||||
|
||||
# Standard housekeeping targets
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(Q) $(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat)
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
327
UnitTests/CListBox/clistbox_main.cxx
Normal 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 */
|
||||
|
||||
printf("%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: nxheaders_main
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int clistbox_main(int argc, char *argv[])
|
||||
{
|
||||
// Initialize memory monitor logic
|
||||
|
||||
initMemoryUsage();
|
||||
|
||||
// Create an instance of the listbox test
|
||||
|
||||
printf("clistbox_main: Create CListBoxTest instance\n");
|
||||
CListBoxTest *test = new CListBoxTest();
|
||||
updateMemoryUsage(g_mmPrevious, "After creating CListBoxTest");
|
||||
|
||||
// Connect the NX server
|
||||
|
||||
printf("clistbox_main: Connect the CListBoxTest instance to the NX server\n");
|
||||
if (!test->connect())
|
||||
{
|
||||
printf("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
|
||||
|
||||
printf("clistbox_main: Create a Window\n");
|
||||
if (!test->createWindow())
|
||||
{
|
||||
printf("clistbox_main: Failed to create a window\n");
|
||||
delete test;
|
||||
return 1;
|
||||
}
|
||||
updateMemoryUsage(g_mmPrevious, "clistbox_main: After creating a window");
|
||||
|
||||
// Create a listbox
|
||||
|
||||
printf("clistbox_main: Create a ListBox\n");
|
||||
CListBox *listbox = test->createListBox();
|
||||
if (!listbox)
|
||||
{
|
||||
printf("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)
|
||||
|
||||
printf("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);
|
||||
printf("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
|
||||
|
||||
printf("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)
|
||||
{
|
||||
printf("clistbox_main: Option count: %d\n", nOptions);
|
||||
if (nOptions <= 5)
|
||||
{
|
||||
printf("clistbox_main: Selecting all remaining options\n");
|
||||
listbox->selectAllOptions();
|
||||
test->showListBox(listbox);
|
||||
updateMemoryUsage(g_mmPrevious, "clistbox_main: After selecting all options");
|
||||
sleep(1);
|
||||
|
||||
printf("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];
|
||||
|
||||
printf("clistbox_main: Selecting five options\n");
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
selected[i] = ((nOptions - 1) * rand()) / RAND_MAX;
|
||||
printf("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");
|
||||
|
||||
printf("clistbox_main: De-selecting options\n");
|
||||
int index;
|
||||
int count = 0;
|
||||
while ((index = listbox->getSelectedIndex()) >= 0)
|
||||
{
|
||||
printf("clistbox_main: De-selecting option %d\n", index);
|
||||
listbox->deselectOption(index);
|
||||
test->showListBox(listbox);
|
||||
count++;
|
||||
usleep(500000);
|
||||
}
|
||||
|
||||
printf("clistbox_main: %s: %d options de-selected\n",
|
||||
count == 5 ? "OK" : "ERROR", count);
|
||||
updateMemoryUsage(g_mmPrevious, "clistbox_main: After de-selecting options");
|
||||
|
||||
printf("clistbox_main: Removing the selected options\n");
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
printf("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
|
||||
|
||||
printf("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");
|
||||
printf("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial);
|
||||
return 0;
|
||||
}
|
||||
|
224
UnitTests/CListBox/clistboxtest.cxx
Normal 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))
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("CListBoxTest::createWindow: Failed to create CBgWindow instance\n");
|
||||
disconnect();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open (and initialize) the window
|
||||
|
||||
bool success = m_bgWindow->open();
|
||||
if (!success)
|
||||
{
|
||||
printf("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();
|
||||
}
|
128
UnitTests/CListBox/clistboxtest.hxx
Normal file
@ -0,0 +1,128 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
10
UnitTests/CProgressBar/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
38
UnitTests/CProgressBar/Make.defs
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# NxWidgets/UnitTests/CProgressBar/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
CONFIGURED_APPS += external
|
||||
|
179
UnitTests/CProgressBar/Makefile
Normal file
@ -0,0 +1,179 @@
|
||||
#################################################################################
|
||||
# NxWidgets/UnitTests/CProgressBar/Makefile
|
||||
#
|
||||
# Copyright (C) 2012-2013, 2016 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)/Make.defs
|
||||
|
||||
OBJEXT ?= .o
|
||||
DELIM ?= /
|
||||
|
||||
include $(APPDIR)$(DELIM)Make.defs
|
||||
|
||||
# Add the path to the NXWidget include directory to the CFLAGS
|
||||
|
||||
NXWIDGETS_DIR="$(TESTDIR)$(DELIM)..$(DELIM)..$(DELIM)libnxwidgets"
|
||||
NXWIDGETS_INC="$(NXWIDGETS_DIR)$(DELIM)include"
|
||||
NXWIDGETS_LIB="$(NXWIDGETS_DIR)$(DELIM)libnxwidgets$(LIBEXT)"
|
||||
|
||||
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)$(DELIM)..$(DELIM)..$(DELIM)tools"
|
||||
ARCHIVER=$(TESTTOOL_DIR)$(DELIM)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)$(DELIM)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:
|
||||
$(Q) ( \
|
||||
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)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
ifeq ($(WINTOOL),y)
|
||||
$(Q) $(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
else
|
||||
$(Q) $(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
endif
|
||||
$(Q) touch .built
|
||||
|
||||
# Register NSH built-in application
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
||||
preconfig:
|
||||
|
||||
# Standard housekeeping targets
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(Q) $(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat)
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
BIN
UnitTests/CProgressBar/cprogressbar.png
Normal file
After Width: | Height: | Size: 20 KiB |
238
UnitTests/CProgressBar/cprogressbar_main.cxx
Normal 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 */
|
||||
|
||||
printf("\n%s:\n", msg);
|
||||
printf(" 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: nxheaders_main
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int cprogressbar_main(int argc, char *argv[])
|
||||
{
|
||||
// Initialize memory monitor logic
|
||||
|
||||
initMemoryUsage();
|
||||
|
||||
// Create an instance of the checkbox test
|
||||
|
||||
printf("cprogressbar_main: Create CProgressBarTest instance\n");
|
||||
CProgressBarTest *test = new CProgressBarTest();
|
||||
updateMemoryUsage(g_mmprevious, "After creating CProgressBarTest");
|
||||
|
||||
// Connect the NX server
|
||||
|
||||
printf("cprogressbar_main: Connect the CProgressBarTest instance to the NX server\n");
|
||||
if (!test->connect())
|
||||
{
|
||||
printf("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
|
||||
|
||||
printf("cprogressbar_main: Create a Window\n");
|
||||
if (!test->createWindow())
|
||||
{
|
||||
printf("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
|
||||
|
||||
printf("cprogressbar_main: Create a ProgressBar\n");
|
||||
CProgressBar *bar = test->createProgressBar();
|
||||
if (!bar)
|
||||
{
|
||||
printf("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();
|
||||
printf("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);
|
||||
printf("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);
|
||||
printf("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
|
||||
|
||||
printf("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;
|
||||
}
|
||||
|
224
UnitTests/CProgressBar/cprogressbartest.cxx
Normal 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))
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("CProgressBarTest::createWindow: Failed to create CBgWindow instance\n");
|
||||
disconnect();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open (and initialize) the window
|
||||
|
||||
bool success = m_bgWindow->open();
|
||||
if (!success)
|
||||
{
|
||||
printf("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();
|
||||
}
|
128
UnitTests/CProgressBar/cprogressbartest.hxx
Normal file
@ -0,0 +1,128 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
10
UnitTests/CRadioButton/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
38
UnitTests/CRadioButton/Make.defs
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# NxWidgets/UnitTests/CRadioButton/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
CONFIGURED_APPS += external
|
||||
|
179
UnitTests/CRadioButton/Makefile
Normal file
@ -0,0 +1,179 @@
|
||||
#################################################################################
|
||||
# NxWidgets/UnitTests/CRadioButton/Makefile
|
||||
#
|
||||
# Copyright (C) 2012-2013, 2016 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)/Make.defs
|
||||
|
||||
OBJEXT ?= .o
|
||||
DELIM ?= /
|
||||
|
||||
include $(APPDIR)$(DELIM)Make.defs
|
||||
|
||||
# Add the path to the NXWidget include directory to the CFLAGS
|
||||
|
||||
NXWIDGETS_DIR="$(TESTDIR)$(DELIM)..$(DELIM)..$(DELIM)libnxwidgets"
|
||||
NXWIDGETS_INC="$(NXWIDGETS_DIR)$(DELIM)include"
|
||||
NXWIDGETS_LIB="$(NXWIDGETS_DIR)$(DELIM)libnxwidgets$(LIBEXT)"
|
||||
|
||||
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)$(DELIM)..$(DELIM)..$(DELIM)tools"
|
||||
ARCHIVER=$(TESTTOOL_DIR)$(DELIM)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)$(DELIM)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:
|
||||
$(Q) ( \
|
||||
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)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
ifeq ($(WINTOOL),y)
|
||||
$(Q) $(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
else
|
||||
$(Q) $(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
endif
|
||||
$(Q) touch .built
|
||||
|
||||
# Register NSH built-in application
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
||||
preconfig:
|
||||
|
||||
# Standard housekeeping targets
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(Q) $(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat)
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
BIN
UnitTests/CRadioButton/cradiobutton.png
Normal file
After Width: | Height: | Size: 32 KiB |
238
UnitTests/CRadioButton/cradiobutton_main.cxx
Normal 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 */
|
||||
|
||||
printf("\n%s:\n", msg);
|
||||
printf(" 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: nxheaders_main
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int cradiobutton_main(int argc, char *argv[])
|
||||
{
|
||||
// Initialize memory monitor logic
|
||||
|
||||
initMemoryUsage();
|
||||
|
||||
// Create an instance of the radio button test
|
||||
|
||||
printf("cradiobutton_main: Create CRadioButtonTest instance\n");
|
||||
CRadioButtonTest *test = new CRadioButtonTest();
|
||||
updateMemoryUsage(g_mmprevious, "After creating CRadioButtonTest");
|
||||
|
||||
// Connect the NX server
|
||||
|
||||
printf("cradiobutton_main: Connect the CRadioButtonTest instance to the NX server\n");
|
||||
if (!test->connect())
|
||||
{
|
||||
printf("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
|
||||
|
||||
printf("cradiobutton_main: Create a Window\n");
|
||||
if (!test->createWindow())
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("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
|
||||
|
||||
printf("cradiobutton_main: Pushing button 1\n");
|
||||
test->pushButton(button1);
|
||||
usleep(500*1000);
|
||||
test->showButtonState();
|
||||
updateMemoryUsage(g_mmprevious, "After pushing button 1");
|
||||
usleep(500*1000);
|
||||
|
||||
printf("cradiobutton_main: Pushing button 2\n");
|
||||
test->pushButton(button2);
|
||||
usleep(500*1000);
|
||||
test->showButtonState();
|
||||
updateMemoryUsage(g_mmprevious, "After pushing button 2");
|
||||
usleep(500*1000);
|
||||
|
||||
printf("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
|
||||
|
||||
printf("cradiobutton_main: Clean-up and exit\n");
|
||||
delete test;
|
||||
updateMemoryUsage(g_mmprevious, "After deleting the test");
|
||||
updateMemoryUsage(g_mmInitial, "Final memory usage");
|
||||
return 0;
|
||||
}
|
||||
|
305
UnitTests/CRadioButton/cradiobuttontest.cxx
Normal 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))
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("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))
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("CRadioButtonTest::showButtonState No button is pressed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("CRadioButtonTest::showButtonState button%d is selected\n", index+1);
|
||||
}
|
||||
}
|
143
UnitTests/CRadioButton/cradiobuttontest.hxx
Normal file
@ -0,0 +1,143 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
10
UnitTests/CScrollbarHorizontal/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
38
UnitTests/CScrollbarHorizontal/Make.defs
Normal file
@ -0,0 +1,38 @@
|
||||
############################################################################
|
||||
# NxWidgets/UnitTests/CScrollbarHorizontal/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
CONFIGURED_APPS += external
|
||||
|
179
UnitTests/CScrollbarHorizontal/Makefile
Normal file
@ -0,0 +1,179 @@
|
||||
#################################################################################
|
||||
# NxWidgets/UnitTests/CScrollbarHorizontal/Makefile
|
||||
#
|
||||
# Copyright (C) 2012-2013, 2016 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)/Make.defs
|
||||
|
||||
OBJEXT ?= .o
|
||||
DELIM ?= /
|
||||
|
||||
include $(APPDIR)$(DELIM)Make.defs
|
||||
|
||||
# Add the path to the NXWidget include directory to the CFLAGS
|
||||
|
||||
NXWIDGETS_DIR="$(TESTDIR)$(DELIM)..$(DELIM)..$(DELIM)libnxwidgets"
|
||||
NXWIDGETS_INC="$(NXWIDGETS_DIR)$(DELIM)include"
|
||||
NXWIDGETS_LIB="$(NXWIDGETS_DIR)$(DELIM)libnxwidgets$(LIBEXT)"
|
||||
|
||||
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)$(DELIM)..$(DELIM)..$(DELIM)tools"
|
||||
ARCHIVER=$(TESTTOOL_DIR)$(DELIM)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)$(DELIM)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:
|
||||
$(Q) ( \
|
||||
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)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
ifeq ($(WINTOOL),y)
|
||||
$(Q) $(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
else
|
||||
$(Q) $(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
|
||||
endif
|
||||
$(Q) touch .built
|
||||
|
||||
# Register NSH built-in application
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
||||
preconfig:
|
||||
|
||||
# Standard housekeeping targets
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
|
||||
@touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat)
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
BIN
UnitTests/CScrollbarHorizontal/cscrollbarhorizontal.png
Normal file
After Width: | Height: | Size: 20 KiB |
231
UnitTests/CScrollbarHorizontal/cscrollbarhorizontal_main.cxx
Normal 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 */
|
||||
|
||||
printf("\n%s:\n", msg);
|
||||
printf(" 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: nxheaders_main
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int cscrollbarhorizontal_main(int argc, char *argv[])
|
||||
{
|
||||
// Initialize memory monitor logic
|
||||
|
||||
initMemoryUsage();
|
||||
|
||||
// Create an instance of the checkbox test
|
||||
|
||||
printf("cscrollbarhorizontal_main: Create CScrollbarHorizontalTest instance\n");
|
||||
CScrollbarHorizontalTest *test = new CScrollbarHorizontalTest();
|
||||
updateMemoryUsage(g_mmprevious, "After creating CScrollbarHorizontalTest");
|
||||
|
||||
// Connect the NX server
|
||||
|
||||
printf("cscrollbarhorizontal_main: Connect the CScrollbarHorizontalTest instance to the NX server\n");
|
||||
if (!test->connect())
|
||||
{
|
||||
printf("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
|
||||
|
||||
printf("cscrollbarhorizontal_main: Create a Window\n");
|
||||
if (!test->createWindow())
|
||||
{
|
||||
printf("cscrollbarhorizontal_main: Failed to create a window\n");
|
||||
delete test;
|
||||
return 1;
|
||||
}
|
||||
updateMemoryUsage(g_mmprevious, "cscrollbarhorizontal_main: After creating a window");
|
||||
|
||||
// Create a scrollbar
|
||||
|
||||
printf("cscrollbarhorizontal_main: Create a Scrollbar\n");
|
||||
CScrollbarHorizontal *scrollbar = test->createScrollbar();
|
||||
if (!scrollbar)
|
||||
{
|
||||
printf("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);
|
||||
printf("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);
|
||||
printf("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);
|
||||
printf("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
|
||||
|
||||
printf("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;
|
||||
}
|
||||
|
225
UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.cxx
Normal 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))
|
||||
{
|
||||
printf("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)
|
||||
{
|
||||
printf("CScrollbarHorizontalTest::createWindow: Failed to create CBgWindow instance\n");
|
||||
disconnect();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open (and initialize) the window
|
||||
|
||||
bool success = m_bgWindow->open();
|
||||
if (!success)
|
||||
{
|
||||
printf("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();
|
||||
}
|