First check-in of NxWidgets

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4505 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo
2012-03-22 21:22:59 +00:00
parent 58df24e93f
commit dcd9999711
217 changed files with 66325 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+45
View File
@@ -0,0 +1,45 @@
README
======
This directory contains the documentation automatically generated by Doxygen.
Contents
========
o Installing the necessary packages in Ubuntu
o Generating documentation
Installing the necessary packages in Ubuntu
===========================================
1. Install the following packages.
$ sudo aptitude install doxygen doxygen-doc doxygen-gui dot2tex graphviz
2. (Optional) Install from the latest sourcode.
The Ubuntu package is outdated. The newer the version of Doxygen, the cooler
the documentation looks.
Place yourself in some temporary folder where you can download the source,
and run (http://www.stack.nl/~dimitri/doxygen/download.html):
$ svn co https://doxygen.svn.sourceforge.net/svnroot/doxygen/trunk doxygen-svn
$ cd doxygen-svn
$ ./configure
$ make
$ make install
Generating documentation
========================
1. Position the shell into this folder:
misc/NXWidgets/Doxygen
The file "Doxyfile" contains the configuration of the Doxygen settings
for the run, edit only if necessary.
To generate the documentation type:
$ doxygen Doxyfile
+94
View File
@@ -0,0 +1,94 @@
#!/bin/bash
#################################################################################
# NxWidgets/Doxygen/gendoc.sh
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Jose Pablo Carballo <jcarballo@nx-engineering.com>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
#
# set -x
# Functions
function ShowUsage()
{
echo ""
echo "USAGE: $0 <doxygen-output-directory-path>"
echo ""
echo "Where:"
echo " <doxygen-output-directory-path> is the full, absolut path to place the doxygen output"
echo ""
}
# Input parameters
DOXYGENOUTPUT_DIR=$1
if [ -z "${DOXYGENOUTPUT_DIR}" ]; then
echo "Missing required arguments"
ShowUsage
exit 1
fi
# Check that the directory exist
if [ ! -d "${DOXYGENOUTPUT_DIR}" ]; then
echo "Directory ${DOXYGENOUTPUT_DIR} does not exist"
exit 1
fi
# Find the doxygen configuration file
DOXYFILE="Doxyfile"
if [ ! -e "${DOXYFILE}" ]; then
echo "This script must be executed in the documentation/ directory"
exit 1
fi
doxygen "${DOXYFILE}" || \
{
echo "Failed to run doxygen"; \
exit 1;
}
cp -rf html "${DOXYGENOUTPUT_DIR}" || \
{
echo "Failed to move html output"; \
exit 1;
}
rm -rf html || \
{
echo "Failed to remove the html/ directory"; \
exit 1;
}
echo "open ${DOXYGENOUTPUT_DIR}/html/index.html to start browsing"
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/Unitests/CButton/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx cbuttontest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = cbutton
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+325
View File
@@ -0,0 +1,325 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CButton/cbuttontest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "cbuttontest.hxx"
#include "cbgwindow.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CButtonTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CButtonTest Constructor
CButtonTest::CButtonTest()
{
m_bgWindow = (CBgWindow *)NULL;
m_nxFont = (CNxFont *)NULL;
m_text = (CNxString *)NULL;
}
// CButtonTest Descriptor
CButtonTest::~CButtonTest()
{
disconnect();
}
// Connect to the NX server
bool CButtonTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Create the default font instance
m_nxFont = new CNxFont(NXFONT_DEFAULT,
CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR,
CONFIG_NXWIDGETS_TRANSPARENT_COLOR);
if (!m_nxFont)
{
printf("CButtonTest::connect: Failed to create the default font\n");
}
// Set the background color
if (!setBackgroundColor(CONFIG_CBUTTONTEST_BGCOLOR))
{
printf("CButtonTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CButtonTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// Free the display string
if (m_text)
{
delete m_text;
m_text = (CNxString *)NULL;
}
// Free the default font
if (m_nxFont)
{
delete m_nxFont;
m_nxFont = (CNxFont *)NULL;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CButtonTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
printf("CButtonTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
printf("CButtonTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CButton instance
CButton *CButtonTest::createButton(FAR const char *text)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CButtonTest::createGraphics: Failed to get window size\n");
return (CButton *)NULL;
}
// Create a CNxString instance to contain the C string
m_text = new CNxString(text);
// Get the height and width of the text display area
nxgl_coord_t stringWidth = m_nxFont->getStringWidth(*m_text);
nxgl_coord_t stringHeight = (nxgl_coord_t)m_nxFont->getHeight();
// The default CButton has borders enabled with thickness of the border
// width. Add twice the thickness of the borderto the width and height. (We
// could let CButton do this for us by calling CButton::getPreferredDimensions())
stringWidth += 2 * 1;
stringHeight += 2 * 1;
// Pick an X/Y position such that the button will be centered in the display
nxgl_coord_t buttonX;
if (stringWidth >= windowSize.w)
{
buttonX = 0;
}
else
{
buttonX = (windowSize.w - stringWidth) >> 1;
}
nxgl_coord_t buttonY;
if (stringHeight >= windowSize.h)
{
buttonY = 0;
}
else
{
buttonY = (windowSize.h - stringHeight) >> 1;
}
// Save the center position of the button for use by click and release
m_center.x = buttonX + (stringWidth >> 1);
m_center.y = buttonY + (stringHeight >> 1);
// Now we have enough information to create the button
return new CButton(m_widgetControl, buttonX, buttonY, stringWidth, stringHeight, *m_text);
}
// Draw the button
void CButtonTest::showButton(CButton *button)
{
button->enable(); // Un-necessary, the widget is enabled by default
button->enableDrawing();
button->redraw();
}
// Perform a simulated mouse click on the button. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void CButtonTest::click(void)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// Then inject the mouse click
(void)nx_mousein(handle, m_center.x, m_center.y, NX_MOUSE_LEFTBUTTON);
}
// The counterpart to click. This simulates a button release through
// the same mechanism.
void CButtonTest::release(void)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// Then inject the mouse click
(void)nx_mousein(handle, m_center.x, m_center.y, NX_MOUSE_NOBUTTONS);
}
// Widget events are normally handled in a modal loop (by calling goModal()).
// 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();
}
+167
View File
@@ -0,0 +1,167 @@
/////////////////////////////////////////////////////////////////////////////
// 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_BACKCOLOR
#endif
#ifndef CONFIG_CBUTTONTEST_FONTCOLOR
# define CONFIG_CBUTTONTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME cbutton_main
# define MAIN_STRING "cbutton_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#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
+155
View File
@@ -0,0 +1,155 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/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 MAIN_NAME(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Create an instance of the font test
printf(MAIN_STRING "Create CButtonTest instance\n");
CButtonTest *test = new CButtonTest();
// Connect the NX server
printf(MAIN_STRING "Connect the CButtonTest instance to the NX server\n");
if (!test->connect())
{
printf(MAIN_STRING "Failed to connect the CButtonTest instance to the NX server\n");
delete test;
return 1;
}
// Create a window to draw into
printf(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
printf(MAIN_STRING "Failed to create a window\n");
delete test;
return 1;
}
// Create a CButton instance
CButton *button = test->createButton(g_pushme);
if (!button)
{
printf(MAIN_STRING "Failed to create a button\n");
delete test;
return 1;
}
// Show the button
printf(MAIN_STRING "Show the button\n");
test->showButton(button);
// Wait two seconds, then perform a simulated mouse click on the button
sleep(2);
printf(MAIN_STRING "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(MAIN_STRING "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(MAIN_STRING "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(MAIN_STRING "Clean-up and exit\n");
delete button;
delete test;
return 0;
}
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CButtonArray/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx cbuttonarraytest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = cbuttonarray
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,301 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CButtonArray/cbuttonarraytest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "cbuttonarraytest.hxx"
#include "cbgwindow.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CButtonArrayTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CButtonArrayTest Constructor
CButtonArrayTest::CButtonArrayTest()
{
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CButtonArrayTest Descriptor
CButtonArrayTest::~CButtonArrayTest()
{
disconnect();
}
// Connect to the NX server
bool CButtonArrayTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CBUTTONARRAYTEST_BGCOLOR))
{
message("CButtonArrayTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CButtonArrayTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// Destroy the widget control
if (m_widgetControl)
{
delete m_widgetControl;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CButtonArrayTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CButtonArrayTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CButtonArrayTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CButtonArray instance
CButtonArray *CButtonArrayTest::createButtonArray(void)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
message("CButtonArrayTest::createGraphics: Failed to get window size\n");
return (CButtonArray *)NULL;
}
// Pick an X/Y position such that the button array will be centered in the display
nxgl_coord_t buttonArrayX;
if (BUTTONARRAY_WIDTH >= windowSize.w)
{
buttonArrayX = 0;
}
else
{
buttonArrayX = (windowSize.w - BUTTONARRAY_WIDTH) >> 1;
}
nxgl_coord_t buttonArrayY;
if (BUTTONARRAY_HEIGHT >= windowSize.h)
{
buttonArrayY = 0;
}
else
{
buttonArrayY = (windowSize.h - BUTTONARRAY_HEIGHT) >> 1;
}
// Now we have enough information to create the button array
return new CButtonArray(m_widgetControl,
buttonArrayX, buttonArrayY,
BUTTONARRAY_NCOLUMNS, BUTTONARRAY_NROWS,
BUTTONARRAY_BUTTONWIDTH, BUTTONARRAY_BUTTONHEIGHT);
}
// Draw the button array
void CButtonArrayTest::showButton(CButtonArray *buttonArray)
{
buttonArray->enable(); // Un-necessary, the widget is enabled by default
buttonArray->enableDrawing();
buttonArray->redraw();
}
// Perform a simulated mouse click on a button in the array. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void CButtonArrayTest::click(CButtonArray *buttonArray, int column, int row)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the selected button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// The the coorinates of the center of the button
nxgl_coord_t buttonX = buttonArray->getX() +
column * BUTTONARRAY_BUTTONWIDTH +
BUTTONARRAY_BUTTONWIDTH/2;
nxgl_coord_t buttonY = buttonArray->getY() +
row * BUTTONARRAY_BUTTONHEIGHT +
BUTTONARRAY_BUTTONHEIGHT/2;
// Then inject the mouse click
(void)nx_mousein(handle, buttonX, buttonY, NX_MOUSE_LEFTBUTTON);
}
// The counterpart to click. This simulates a button release through
// the same mechanism.
void CButtonArrayTest::release(CButtonArray *buttonArray, int column, int row)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// The the coorinates of the center of the button
nxgl_coord_t buttonX = buttonArray->getX() +
column * BUTTONARRAY_BUTTONWIDTH +
BUTTONARRAY_BUTTONWIDTH/2;
nxgl_coord_t buttonY = buttonArray->getY() +
row * BUTTONARRAY_BUTTONHEIGHT +
BUTTONARRAY_BUTTONHEIGHT/2;
// Then inject the mouse release
(void)nx_mousein(handle, buttonX, buttonY, NX_MOUSE_NOBUTTONS);
}
// Widget events are normally handled in a modal loop (by calling goModal()).
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
void CButtonArrayTest::poll(CButtonArray *button)
{
// Poll for mouse events
m_widgetControl->pollEvents(button);
}
@@ -0,0 +1,182 @@
/////////////////////////////////////////////////////////////////////////////
// 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_BACKCOLOR
#endif
#ifndef CONFIG_CBUTTONARRAYTEST_FONTCOLOR
# define CONFIG_CBUTTONARRAYTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME cbuttonarray_main
# define MAIN_STRING "cbuttonarray_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
// The geometry of the button array
#define BUTTONARRAY_NCOLUMNS 4
#define BUTTONARRAY_NROWS 7
#define BUTTONARRAY_BUTTONWIDTH 60
#define BUTTONARRAY_BUTTONHEIGHT 32
#define BUTTONARRAY_WIDTH (BUTTONARRAY_BUTTONWIDTH * BUTTONARRAY_NCOLUMNS)
#define BUTTONARRAY_HEIGHT (BUTTONARRAY_BUTTONHEIGHT * BUTTONARRAY_NROWS)
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CButtonArrayTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The widget control for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CButtonArrayTest();
~CButtonArrayTest();
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a CButtonArray instance. This method will show you how to create
// a CButtonArray widget
CButtonArray *createButtonArray(void);
// Draw the button array. This method illustrates how to draw the CButtonArray widget.
void showButton(CButtonArray *buttonArray);
// Perform a simulated mouse click on a button in the array. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void click(CButtonArray *buttonArray, int column, int row);
// The counterpart to click. This simulates a button release through
// the same mechanism.
void release(CButtonArray *buttonArray, int column, int row);
// Widget events are normally handled in a model loop (by calling goModel()).
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
void poll(CButtonArray *buttonArray);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CBUTTONARRAY_CBUTTONARRAYTEST_HXX
+327
View File
@@ -0,0 +1,327 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/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 MAIN_NAME(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("%s: Before: %8d After: %8d Change: %8d\n",
msg, previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmPrevious = mmcurrent.uordblks;
if ((unsigned int)mmcurrent.uordblks > g_mmPeak)
{
g_mmPeak = mmcurrent.uordblks;
}
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmPrevious = mmcurrent.uordblks;
g_mmPeak = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Name: checkHighlighting
/////////////////////////////////////////////////////////////////////////////
static void checkHighlighting(CButtonArray *buttonArray)
{
// Turn highlighting on
buttonArray->setCursorPosition(0, 0);
buttonArray->cursor(true);
// Then test the cursor movement
for (int row = 0; row < BUTTONARRAY_NROWS; row++)
{
for (int column = 0; column < BUTTONARRAY_NCOLUMNS; column++)
{
// Set cursor position
buttonArray->setCursorPosition(column, row);
// Check cursor position
int checkColumn;
int checkRow;
if (buttonArray->isCursorPosition(checkColumn, checkRow))
{
printf("ERROR: Not button selected\n");
printf(" Expected (%d,%d)\n", column, row);
}
else if (checkColumn != column || checkRow != row)
{
printf("ERROR: Wrong button selected\n");
printf(" Expected (%d,%d)\n", column, row);
printf(" Selected (%d,%d)\n", checkColumn, checkRow);
}
// Wait a bit so that we can see the highlighting
usleep(500*1000);
}
}
// Turn highlighting off
buttonArray->cursor(false);
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the button array test
printf(MAIN_STRING "Create CButtonArrayTest instance\n");
CButtonArrayTest *test = new CButtonArrayTest();
updateMemoryUsage(g_mmPrevious, "After creating CButtonArrayTest");
// Connect the NX server
printf(MAIN_STRING "Connect the CButtonArrayTest instance to the NX server\n");
if (!test->connect())
{
printf(MAIN_STRING "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(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
printf(MAIN_STRING "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(MAIN_STRING "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(MAIN_STRING "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(MAIN_STRING "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(MAIN_STRING "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(MAIN_STRING "%s: Button (%d, %d) is clicked\n",
clickColumn == i && clickRow == j ? "OK" : "ERROR",
clickColumn, clickRow);
}
else
{
printf(MAIN_STRING "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(MAIN_STRING "ERROR: Button (%d, %d) is clicked\n",
clickColumn, clickRow);
}
usleep(500*1000);
}
}
updateMemoryUsage(g_mmPrevious, "After pushing buttons");
// Clean up and exit
printf(MAIN_STRING "Clean-up and exit\n");
delete buttonArray;
updateMemoryUsage(g_mmPrevious, "After deleting the button array");
delete test;
updateMemoryUsage(g_mmPrevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
message("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial);
return 0;
}
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CCheckBox/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx ccheckboxtest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = ccheckbox
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,297 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CCheckBox/ccheckboxtest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "cbgwindow.hxx"
#include "ccheckboxtest.hxx"
#include "cbitmap.hxx"
#include "glyphs.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CCheckBoxTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CCheckBoxTest Constructor
CCheckBoxTest::CCheckBoxTest()
{
// Initialize state data
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
m_checkBox = (CCheckBox *)NULL;
}
// CCheckBoxTest Descriptor
CCheckBoxTest::~CCheckBoxTest(void)
{
disconnect();
}
// Connect to the NX server
bool CCheckBoxTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CCHECKBOXTEST_BGCOLOR))
{
message("CCheckBoxTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CCheckBoxTest::disconnect(void)
{
// Free the radiobutton group
if (m_checkBox)
{
delete m_checkBox;
m_checkBox = (CCheckBox *)NULL;
}
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
m_bgWindow = (CBgWindow *)NULL;
}
// Free the widget control instance
if (m_widgetControl)
{
delete m_widgetControl;
m_widgetControl = (CWidgetControl *)NULL;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CCheckBoxTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CCheckBoxTest::createWindow: Failed to create CBgWindow instance\n");
disconnect();
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CCheckBoxTest::createWindow: Failed to open background window\n");
disconnect();
return false;
}
// Get the size of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CCheckBoxTest::createWindow: Failed to get window size\n");
disconnect();
return false;
}
// Use the the size of the ON checkbox glyph. (adding twice the border thickness)
nxgl_coord_t width = g_checkBoxOn.width + 2 * 1;
nxgl_coord_t height = g_checkBoxOn.height + 2 * 1;
nxgl_coord_t checkboxX = (windowSize.w - width) >> 1;
nxgl_coord_t checkboxY = (windowSize.h - height) >> 1;
// Create the checkbox
m_checkBox = new CCheckBox(m_widgetControl, checkboxX, checkboxY,
width, height, (CWidgetStyle *)NULL);
if (!m_checkBox)
{
printf("CCheckBoxTest::createWindow: Failed to create CCheckBox\n");
disconnect();
return false;
}
return true;
}
// (Re-)draw the check box.
void CCheckBoxTest::showCheckBox(void)
{
m_checkBox->enable(); // Un-necessary, the widget is enabled by default
m_checkBox->enableDrawing();
m_checkBox->redraw();
}
// Push the radio button
void CCheckBoxTest::clickCheckBox(void)
{
// Get the checkbox center coordinates
nxgl_coord_t checkboxX = m_checkBox->getX() + (m_checkBox->getWidth() >> 1);
nxgl_coord_t checkboxY = m_checkBox->getY() + (m_checkBox->getHeight() >> 1);
// Click the checkbox by calling nx_mousein. nx_mousein is meant to be
// called by mouse handling software. Here we just inject a left-button click
// directly in the center of the radio button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// Then inject the mouse click
(void)nx_mousein(handle, checkboxX, checkboxY, NX_MOUSE_LEFTBUTTON);
// Poll for mouse events
//
// Widget events are normally handled in a modal loop (by calling goModal()).
// However, for this case we know that we just pressed the mouse button
// so we don't have to poll. We can just perform a one pass poll then
// then check if the mouse event was processed corredly.
m_widgetControl->pollEvents(m_checkBox);
// Then inject the mouse release
(void)nx_mousein(handle, checkboxX, checkboxY, 0);
// And poll for more mouse events
m_widgetControl->pollEvents(m_checkBox);
// And re-draw the buttons (the mouse click event should have automatically
// triggered the re-draw)
//
// showCheckBox();
}
// Show the state of the radio button group
void CCheckBoxTest::showCheckBoxState(void)
{
CCheckBox::CheckBoxState state = m_checkBox->getState();
switch (state)
{
case CCheckBox::CHECK_BOX_STATE_OFF: // Checkbox is unticked
message("CCheckBoxTest::showCheckBoxState Checkbox is in the unticked state\n");
break;
case CCheckBox::CHECK_BOX_STATE_ON: // Checkbox is ticked
message("CCheckBoxTest::showCheckBoxState Check is in the ticked state\n");
break;
default:
case CCheckBox::CHECK_BOX_STATE_MU: // Checkbox is in the third state
message("CCheckBoxTest::showCheckBoxState Checkbox is in the 3rd state\n");
break;
}
}
@@ -0,0 +1,152 @@
/////////////////////////////////////////////////////////////////////////////
// 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_BACKCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME ccheckbox_main
# define MAIN_STRING "ccheckbox_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CCheckBoxTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
CCheckBox *m_checkBox; // Checkgox instance under test
public:
// Constructor/destructors
CCheckBoxTest(void);
~CCheckBoxTest(void);
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// (Re-)draw the checkbox.
void showCheckBox(void);
// Simulate pushing and releasing of the radio button
void clickCheckBox(void);
// Show the state of the radio button group
void showCheckBoxState(void);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CCHECKBOX_CCHECKBOXTEST_HXX
+209
View File
@@ -0,0 +1,209 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/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 MAIN_NAME(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("\n%s:\n", msg);
message(" Before: %8d After: %8d Change: %8d\n\n",
previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the checkbox test
message(MAIN_STRING "Create CCheckBoxTest instance\n");
CCheckBoxTest *test = new CCheckBoxTest();
updateMemoryUsage(g_mmprevious, "After creating CCheckBoxTest");
// Connect the NX server
message(MAIN_STRING "Connect the CCheckBoxTest instance to the NX server\n");
if (!test->connect())
{
message(MAIN_STRING "Failed to connect the CCheckBoxTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After connecting to the server");
// Create a window to draw into
message(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
message(MAIN_STRING "Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a window");
// Show the initial state of the checkbox
test->showCheckBox();
test->showCheckBoxState();
sleep(1);
// Now click the checkbox
message(MAIN_STRING "Click 1\n");
test->clickCheckBox();
usleep(500*1000);
test->showCheckBoxState();
updateMemoryUsage(g_mmprevious, "After click 1");
usleep(500*1000);
message(MAIN_STRING "Click 2\n");
test->clickCheckBox();
usleep(500*1000);
test->showCheckBoxState();
updateMemoryUsage(g_mmprevious, "After click 2");
usleep(500*1000);
message(MAIN_STRING "Click 3\n");
test->clickCheckBox();
usleep(500*1000);
test->showCheckBoxState();
updateMemoryUsage(g_mmprevious, "After click 3");
sleep(2);
// Clean up and exit
message(MAIN_STRING "Clean-up and exit\n");
delete test;
updateMemoryUsage(g_mmprevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
return 0;
}
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CGlyphButton/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx cglyphbuttontest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = cglyphbutton
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,307 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CGlyphButton/cglyphbuttontest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "cglyphbuttontest.hxx"
#include "cbgwindow.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CGlyphButtonTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CGlyphButtonTest Constructor
CGlyphButtonTest::CGlyphButtonTest()
{
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
m_center.x = 0;
m_center.y = 0;
}
// CGlyphButtonTest Descriptor
CGlyphButtonTest::~CGlyphButtonTest()
{
disconnect();
}
// Connect to the NX server
bool CGlyphButtonTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CGLYPHBUTTONTEST_BGCOLOR))
{
message("CGlyphButtonTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CGlyphButtonTest::disconnect(void)
{
// Delete the widget control instance
if (m_widgetControl)
{
delete m_widgetControl;
}
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CGlyphButtonTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CGlyphButtonTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CGlyphButtonTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CGlyphButton instance
CGlyphButton *CGlyphButtonTest::createButton(FAR const struct SBitmap *clickGlyph,
FAR const struct SBitmap *unClickedGlyph)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
message("CGlyphButtonTest::createGraphics: Failed to get window size\n");
return (CGlyphButton *)NULL;
}
// Get the height and width of the glyph display area
nxgl_coord_t glyphWidth = MAX(clickGlyph->width, unClickedGlyph->width);
nxgl_coord_t glyphHeight = MAX(clickGlyph->height, unClickedGlyph->height);
// The default CGlyphButton has borders enabled with thickness of the border
// width. Add twice the thickness of the border to the width and height. (We
// could let CGlyphButton do this for us by calling
// CGlyphButton::getPreferredDimensions())
glyphWidth += 2 * 1;
glyphHeight += 2 * 1;
// Pick an X/Y position such that the button will be centered in the display
nxgl_coord_t buttonX;
if (glyphWidth >= windowSize.w)
{
buttonX = 0;
}
else
{
buttonX = (windowSize.w - glyphWidth) >> 1;
}
nxgl_coord_t buttonY;
if (glyphHeight >= windowSize.h)
{
buttonY = 0;
}
else
{
buttonY = (windowSize.h - glyphHeight) >> 1;
}
// Save the center position of the button for use by click and release
m_center.x = buttonX + (glyphWidth >> 1);
m_center.y = buttonY + (glyphHeight >> 1);
// Now we have enough information to create the button
return new CGlyphButton(m_widgetControl, buttonX, buttonY,
glyphWidth, glyphHeight,
unClickedGlyph, clickGlyph);
}
// Draw the button
void CGlyphButtonTest::showButton(CGlyphButton *button)
{
button->enable(); // Un-necessary, the widget is enabled by default
button->enableDrawing();
button->redraw();
}
// Perform a simulated mouse click on the button. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void CGlyphButtonTest::click(void)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// Then inject the mouse click
(void)nx_mousein(handle, m_center.x, m_center.y, NX_MOUSE_LEFTBUTTON);
}
// The counterpart to click. This simulates a button release through
// the same mechanism.
void CGlyphButtonTest::release(void)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// Then inject the mouse click
(void)nx_mousein(handle, m_center.x, m_center.y, NX_MOUSE_NOBUTTONS);
}
// Widget events are normally handled in a modal loop (by calling goModal()).
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
bool CGlyphButtonTest::poll(CGlyphButton *button)
{
// Poll for mouse events
m_widgetControl->pollEvents(button);
// And return the button clicked state
return button->isClicked();
}
@@ -0,0 +1,182 @@
/////////////////////////////////////////////////////////////////////////////
// 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_BACKCOLOR
#endif
#ifndef CONFIG_CGLYPHBUTTONTEST_FONTCOLOR
# define CONFIG_CGLYPHBUTTONTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME cglyphbutton_main
# define MAIN_STRING "cglyphbutton_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
// Helper macros
#ifndef MAX
# define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CGlyphButtonTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
struct nxgl_point_s m_center; // X, Y position the center of the button
public:
// Constructor/destructors
CGlyphButtonTest();
~CGlyphButtonTest();
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a CGlyphButton instance. This method will show you how to create
// a CGlyphButton widget
CGlyphButton *createButton(FAR const struct SBitmap *clickGlyph,
FAR const struct SBitmap *unClickedGlyph);
// Draw the button. This method illustrates how to draw the CGlyphButton widget.
void showButton(CGlyphButton *button);
// Perform a simulated mouse click on the button. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void click(void);
// The counterpart to click. This simulates a button release through
// the same mechanism.
void release(void);
// Widget events are normally handled in a model loop (by calling goModel()).
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
bool poll(CGlyphButton *button);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CGLYPHBUTTON_CGLYPHBUTTONTEST_HXX
+225
View File
@@ -0,0 +1,225 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/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 MAIN_NAME(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("\n%s:\n", msg);
message(" Before: %8d After: %8d Change: %8d\n\n",
previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the font test
message(MAIN_STRING "Create CGlyphButtonTest instance\n");
CGlyphButtonTest *test = new CGlyphButtonTest();
updateMemoryUsage(g_mmprevious, "After creating CGlyphButtonTest");
// Connect the NX server
message(MAIN_STRING "Connect the CGlyphButtonTest instance to the NX server\n");
if (!test->connect())
{
message(MAIN_STRING "Failed to connect the CGlyphButtonTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "After connecting to the server");
// Create a window to draw into
message(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
message(MAIN_STRING "Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "After creating a window");
// Create a CGlyphButton instance
CGlyphButton *button = test->createButton(&g_arrowDown, &g_arrowUp);
if (!button)
{
message(MAIN_STRING "Failed to create a button\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, "After creating the glyph button");
// Show the button
message(MAIN_STRING "Show the button\n");
test->showButton(button);
updateMemoryUsage(g_mmprevious, "After showing the glyph button");
// Wait two seconds, then perform a simulated mouse click on the button
sleep(2);
message(MAIN_STRING "Click the button\n");
test->click();
updateMemoryUsage(g_mmprevious, "After clicking glyph button");
// Poll for the mouse click event (of course this can hang if something fails)
bool clicked = test->poll(button);
message(MAIN_STRING "Button is %s\n", clicked ? "clicked" : "released");
// Wait a second, then release the mouse buttone
sleep(1);
test->release();
updateMemoryUsage(g_mmprevious, "After releasing glyph button");
// Poll for the mouse release event (of course this can hang if something fails)
clicked = test->poll(button);
message(MAIN_STRING "Button is %s\n", clicked ? "clicked" : "released");
// Wait a few more seconds so that the tester can ponder the result
sleep(3);
// Clean up and exit
message(MAIN_STRING "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;
}
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CImage/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx cimagetest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = cimage
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+240
View File
@@ -0,0 +1,240 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CImage/cimagetest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "ibitmap.hxx"
#include "cbgwindow.hxx"
#include "cimagetest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CImageTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CImageTest Constructor
CImageTest::CImageTest()
{
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CImageTest Descriptor
CImageTest::~CImageTest()
{
disconnect();
}
// Connect to the NX server
bool CImageTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CIMAGETEST_BGCOLOR))
{
message("CImageTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CImageTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// Free the widget control instance
if (m_widgetControl)
{
delete m_widgetControl;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CImageTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CImageTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CImageTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CImage instance
CImage *CImageTest::createImage(IBitmap *bitmap)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
message("CImageTest::createGraphics: Failed to get window size\n");
return (CImage *)NULL;
}
// Get the height and width of the image
nxgl_coord_t imageWidth = bitmap->getWidth();
nxgl_coord_t imageHeight = (nxgl_coord_t)bitmap->getHeight();
// The default CImage has borders enabled with thickness of the border
// width. Add twice the thickness of the border to the width and height. (We
// could let CImage do this for us by calling CImage::getPreferredDimensions())
imageWidth += 2 * 1;
imageHeight += 2 * 1;
// Pick an X/Y position such that the image will be centered in the display
nxgl_coord_t imageX;
if (imageWidth >= windowSize.w)
{
imageX = 0;
}
else
{
imageX = (windowSize.w - imageWidth) >> 1;
}
nxgl_coord_t imageY;
if (imageHeight >= windowSize.h)
{
imageY = 0;
}
else
{
imageY = (windowSize.h - imageHeight) >> 1;
}
// Now we have enough information to create the image
return new CImage(m_widgetControl, imageX, imageY, imageWidth, imageHeight, bitmap);
}
// Draw the image
void CImageTest::showImage(CImage *image)
{
image->enable();
image->enableDrawing();
image->redraw();
image->disableDrawing();
}
+150
View File
@@ -0,0 +1,150 @@
/////////////////////////////////////////////////////////////////////////////
// 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_BACKCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME cimage_main
# define MAIN_STRING "cimage_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CImageTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CImageTest(void);
~CImageTest(void);
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a CImage instance. This method will show you how to create
// a CImage widget
CImage *createImage(IBitmap *bitmap);
// Draw the image. This method illustrates how to draw the CImage widget.
void showImage(CImage *image);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CIMAGE_CIMAGETEST_HXX
+222
View File
@@ -0,0 +1,222 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/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 MAIN_NAME(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: showMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void showMemoryUsage(FAR struct mallinfo *mmbefore,
FAR struct mallinfo *mmafter)
{
message("VARIABLE BEFORE AFTER\n");
message("======== ======== ========\n");
message("arena %8d %8d\n", mmbefore->arena, mmafter->arena);
message("ordblks %8d %8d\n", mmbefore->ordblks, mmafter->ordblks);
message("mxordblk %8d %8d\n", mmbefore->mxordblk, mmafter->mxordblk);
message("uordblks %8d %8d\n", mmbefore->uordblks, mmafter->uordblks);
message("fordblks %8d %8d\n", mmbefore->fordblks, mmafter->fordblks);
}
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(FAR struct mallinfo *previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("\n%s:\n", msg);
showMemoryUsage(previous, &mmcurrent);
/* Set up for the next test */
#ifdef CONFIG_CAN_PASS_STRUCTS
g_mmprevious = mmcurrent;
#else
memcpy(&g_mmprevious, &mmcurrent, sizeof(struct mallinfo));
#endif
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
#ifdef CONFIG_CAN_PASS_STRUCTS
g_mmInitial = mallinfo();
g_mmprevious = g_mmInitial;
#else
(void)mallinfo(&g_mmInitial);
memcpy(&g_mmprevious, &g_mmInitial, sizeof(struct mallinfo));
#endif
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the font test
message(MAIN_STRING "Create CImageTest instance\n");
CImageTest *test = new CImageTest();
updateMemoryUsage(&g_mmprevious, "After creating CImageTest");
// Connect the NX server
message(MAIN_STRING "Connect the CImageTest instance to the NX server\n");
if (!test->connect())
{
message(MAIN_STRING "Failed to connect the CImageTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(&g_mmprevious, "After connecting to the server");
// Create a window to draw into
message(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
message(MAIN_STRING "Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(&g_mmprevious, "After creating a window");
// Create an instance of the NuttX logo
CRlePaletteBitmap *nuttxBitmap = new CRlePaletteBitmap(&g_nuttxBitmap);
updateMemoryUsage(&g_mmprevious, "After creating the bitmap");
// Create a CImage instance
CImage *image = test->createImage(static_cast<IBitmap*>(nuttxBitmap));
if (!image)
{
message(MAIN_STRING "Failed to create a image\n");
delete test;
return 1;
}
updateMemoryUsage(&g_mmprevious, "After creating CImage");
// Show the image
test->showImage(image);
updateMemoryUsage(&g_mmprevious, "After showing the image");
sleep(5);
// Clean up and exit
message(MAIN_STRING "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;
}
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CKeyPad/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx ckeypadtest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = ckeypad
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+458
View File
@@ -0,0 +1,458 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CKeypad/ckeypadtest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "ckeypadtest.hxx"
#include "cbgwindow.hxx"
#include "cnxstring.hxx"
#include "cnxfont.hxx"
#include "crect.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CKeypadTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CKeypadTest Constructor
CKeypadTest::CKeypadTest()
{
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
m_buttonWidth = 0;
m_buttonHeight = 0;
m_displayHeight = 0;
}
// CKeypadTest Descriptor
CKeypadTest::~CKeypadTest()
{
disconnect();
}
// Connect to the NX server
bool CKeypadTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CKEYPADTEST_BGCOLOR))
{
message("CKeypadTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CKeypadTest::disconnect(void)
{
// Destroy the text box
if (m_textbox)
{
delete m_textbox;
}
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// Destroy the widget control
if (m_widgetControl)
{
delete m_widgetControl;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CKeypadTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CKeypadTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CKeypadTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
// Then determine the display size
setDisplaySize();
return true;
}
// Pick size of the display
void CKeypadTest::setDisplaySize(void)
{
// Get the height and width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
message("CKeypadTest::createGraphics: Failed to get window size\n");
return;
}
// Pick a height and width of a button. Here we use inside information
// that the number of rows and columns in the keypad. This should not matter in
// a "real" application.
// Lets aim for a width of 4*60 = 240
if (windowSize.w > KEYPAD_NCOLUMNS*60)
{
m_buttonWidth = 60;
}
else
{
// Otherwise, let's use what we have
m_buttonWidth = windowSize.w >> 2;
}
// Lets aim for a height of 7*32 = 224. But lets bump up the number of rows
// to allow one for the text box.
if (windowSize.h > (KEYPAD_NROWS+1)*32)
{
m_buttonHeight = 32;
m_displayHeight = (KEYPAD_NROWS+1)*32;
}
else
{
// Otherwise, let's use what we have
m_buttonHeight = windowSize.h >> 3;
m_displayHeight = windowSize.h;
}
}
// Create a CKeypad instance
CKeypad *CKeypadTest::createKeypad(void)
{
// Get the height and width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
message("CKeypadTest::createGraphics: Failed to get window size\n");
return (CKeypad *)NULL;
}
// Pick a height and width. Here we use inside information that the number
// of rows in the keypad is 7. This should not matter in a "real" application.
nxgl_coord_t keypadWidth = KEYPAD_NCOLUMNS * m_buttonWidth;
nxgl_coord_t keypadHeight = KEYPAD_NROWS * m_buttonHeight;
// Pick an X/Y position such that the keypad will be centered in the display
nxgl_coord_t keypadOffset = m_displayHeight - keypadHeight;
nxgl_coord_t keypadX = (windowSize.w - keypadWidth) >> 1;
nxgl_coord_t keypadY = keypadOffset + ((windowSize.h - m_displayHeight) >> 1);
// Now we have enough information to create the keypad
CKeypad *keypad = new CKeypad(m_widgetControl, getServer(), keypadX, keypadY,
keypadWidth, keypadHeight);
if (keypad)
{
// Create a text box to catch the keyboard inputs
m_textbox = createTextBox();
if (!m_textbox)
{
delete keypad;
keypad = (CKeypad *)NULL;
}
else
{
// Always show the cursor and wrap the cursor if it goes past the end
m_textbox->showCursor(SHOW_CURSOR_ALWAYS);
m_textbox->wrapCursor(true);
// Align text on the left
m_textbox->setTextAlignmentHoriz(CTextBox::TEXT_ALIGNMENT_HORIZ_LEFT);
// Configure the text box to receive the keyboard input
keypad->addWidgetEventHandler(m_textbox);
}
}
return keypad;
}
// Create a CTextBox instance so that we can see the keypad output
CTextBox *CKeypadTest::createTextBox(void)
{
// Get the height and width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
message("CKeypadTest::createGraphics: Failed to get window size\n");
return (CTextBox *)NULL;
}
// Pick a height and width. Here we use inside information that the number
// of rows in the keypad is 7. This should not matter in a "real" application.
nxgl_coord_t textboxWidth = KEYPAD_NCOLUMNS * m_buttonWidth;
nxgl_coord_t textboxHeight = m_displayHeight - KEYPAD_NROWS * m_buttonHeight;
// Pick an X/Y position such that the keypad will be centered in the display
nxgl_coord_t textboxX = (windowSize.w - textboxWidth) >> 1;
nxgl_coord_t textboxY = (windowSize.h - m_displayHeight) >> 1;
// Now we have enough information to create the TextBox
return new CTextBox(m_widgetControl, textboxX, textboxY,
textboxWidth, textboxHeight, "");
}
// Draw the keypad
void CKeypadTest::showKeypad(CKeypad *keypad)
{
// Re-draw the keypad
keypad->enable(); // Un-necessary, the widget is enabled by default
keypad->enableDrawing();
keypad->redraw();
// Then redraw the text box
m_textbox->enable(); // Un-necessary, the widget is enabled by default
m_textbox->enableDrawing();
m_textbox->redraw();
}
// Perform a simulated mouse click on a button in the array. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void CKeypadTest::click(CKeypad *keypad, int column, int row)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the selected button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// The the coorinates of the center of the button
nxgl_coord_t buttonX = keypad->getX() + column * m_buttonWidth + (m_buttonWidth >> 1);
nxgl_coord_t buttonY = keypad->getY() + row * m_buttonHeight + (m_buttonHeight >> 1);
// Then inject the mouse click
(void)nx_mousein(handle, buttonX, buttonY, NX_MOUSE_LEFTBUTTON);
}
// The counterpart to click. This simulates a button release through
// the same mechanism.
void CKeypadTest::release(CKeypad *keypad, int column, int row)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// The the coorinates of the center of the button
nxgl_coord_t buttonX = keypad->getX() +
column * m_buttonWidth +
m_buttonWidth/2;
nxgl_coord_t buttonY = keypad->getY() +
row * m_buttonHeight +
m_buttonHeight/2;
// Then inject the mouse release
(void)nx_mousein(handle, buttonX, buttonY, NX_MOUSE_NOBUTTONS);
}
// Widget events are normally handled in a modal loop (by calling goModal()).
// 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);
}
}
}
+192
View File
@@ -0,0 +1,192 @@
/////////////////////////////////////////////////////////////////////////////
// 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_BACKCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME ckeypad_main
# define MAIN_STRING "ckeypad_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
// This is the size of the keypad
#define KEYPAD_NROWS 7
#define KEYPAD_NCOLUMNS 4
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CKeypadTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The widget control for the window
CBgWindow *m_bgWindow; // Background window instance
CTextBox *m_textbox; // TextBox to show the key presses
nxgl_coord_t m_buttonWidth; // The width of one button
nxgl_coord_t m_buttonHeight; // The height of one button
nxgl_coord_t m_displayHeight; // The height of the display
// Pick size of the display
void setDisplaySize(void);
// Start with left text alignment. When the text reaches the right sice
// of the text box, switch to right text alignment.
void reverseAlignment(void);
// Create a CTextBox instance so that we can see the keypad output
CTextBox *createTextBox(void);
public:
// Constructor/destructors
CKeypadTest();
~CKeypadTest();
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a CKeypad instance. This method will show you how to create
// a CKeypad widget
CKeypad *createKeypad(void);
// Draw the keypad. This method illustrates how to draw the CKeypad widget.
void showKeypad(CKeypad *keypad);
// Perform a simulated mouse click on a button in the array. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void click(CKeypad *keypad, int column, int row);
// The counterpart to click. This simulates a button release through
// the same mechanism.
void release(CKeypad *keypad, int column, int row);
// Widget events are normally handled in a model loop (by calling goModel()).
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
void poll(CKeypad *keypad);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CKEYPAD_CKEYPADTEST_HXX
+274
View File
@@ -0,0 +1,274 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/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 MAIN_NAME(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("%s: Before: %8d After: %8d Change: %8d\n",
msg, previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmPrevious = mmcurrent.uordblks;
if ((unsigned int)mmcurrent.uordblks > g_mmPeak)
{
g_mmPeak = mmcurrent.uordblks;
}
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmPrevious = mmcurrent.uordblks;
g_mmPeak = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Name: clickButtons
/////////////////////////////////////////////////////////////////////////////
static void clickButtons(CKeypadTest *test, CKeypad *keypad)
{
// Perform a simulated mouse click on a button in the keypad
for (int j = 0; j < KEYPAD_NROWS; j++)
{
for (int i = 0; i < KEYPAD_NCOLUMNS; i++)
{
printf(MAIN_STRING "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(MAIN_STRING "%s: Button (%d, %d) is clicked\n",
clickColumn == i && clickRow == j ? "OK" : "ERROR",
clickColumn, clickRow);
}
else
{
printf(MAIN_STRING "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(MAIN_STRING "ERROR: Button (%d, %d) is clicked\n",
clickColumn, clickRow);
}
usleep(500*1000);
}
}
updateMemoryUsage(g_mmPrevious, "After pushing buttons");
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the keypad test
printf(MAIN_STRING "Create CKeypadTest instance\n");
CKeypadTest *test = new CKeypadTest();
updateMemoryUsage(g_mmPrevious, "After creating CKeypadTest");
// Connect the NX server
printf(MAIN_STRING "Connect the CKeypadTest instance to the NX server\n");
if (!test->connect())
{
printf(MAIN_STRING "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(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
printf(MAIN_STRING "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(MAIN_STRING "Failed to create a keypad\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmPrevious, "After creating CKeypad");
// Show the keypad in alphabetic mode
printf(MAIN_STRING "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(MAIN_STRING "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(MAIN_STRING "Clean-up and exit\n");
delete keypad;
updateMemoryUsage(g_mmPrevious, "After deleting the keypad");
delete test;
updateMemoryUsage(g_mmPrevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
message("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial);
return 0;
}
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CLabel/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx clabeltest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = clabel
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+263
View File
@@ -0,0 +1,263 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CLabel/clabeltest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "clabeltest.hxx"
#include "cbgwindow.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CLabelTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CLabelTest Constructor
CLabelTest::CLabelTest()
{
m_bgWindow = (CBgWindow *)NULL;
m_nxFont = (CNxFont *)NULL;
m_text = (CNxString *)NULL;
}
// CLabelTest Descriptor
CLabelTest::~CLabelTest()
{
disconnect();
}
// Connect to the NX server
bool CLabelTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Create the default font instance
m_nxFont = new CNxFont(NXFONT_DEFAULT,
CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR,
CONFIG_NXWIDGETS_TRANSPARENT_COLOR);
if (!m_nxFont)
{
printf("CLabelTest::connect: Failed to create the default font\n");
}
// Set the background color
if (!setBackgroundColor(CONFIG_CLABELTEST_BGCOLOR))
{
printf("CLabelTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CLabelTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// Free the display string
if (m_text)
{
delete m_text;
m_text = (CNxString *)NULL;
}
// Free the default font
if (m_nxFont)
{
delete m_nxFont;
m_nxFont = (CNxFont *)NULL;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CLabelTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
printf("CLabelTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
printf("CLabelTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CLabel instance
CLabel *CLabelTest::createLabel(FAR const char *text)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CLabelTest::createGraphics: Failed to get window size\n");
return (CLabel *)NULL;
}
// Create a CNxString instance to contain the C string
m_text = new CNxString(text);
// Get the height and width of the text display area
nxgl_coord_t stringWidth = m_nxFont->getStringWidth(*m_text);
nxgl_coord_t stringHeight = (nxgl_coord_t)m_nxFont->getHeight();
// The default CLabel has borders enabled with thickness of the border
// width. Add twice the thickness of the border to the width and height. (We
// could let CLabel do this for us by calling CLabel::getPreferredDimensions())
stringWidth += 2 * 1;
stringHeight += 2 * 1;
// Pick an X/Y position such that the label will be centered in the display
nxgl_coord_t labelX;
if (stringWidth >= windowSize.w)
{
labelX = 0;
}
else
{
labelX = (windowSize.w - stringWidth) >> 1;
}
nxgl_coord_t labelY;
if (stringHeight >= windowSize.h)
{
labelY = 0;
}
else
{
labelY = (windowSize.h - stringHeight) >> 1;
}
// Now we have enough information to create the label
return new CLabel(m_widgetControl, labelX, labelY, stringWidth, stringHeight, *m_text);
}
// Draw the label
void CLabelTest::showLabel(CLabel *label)
{
label->enable();
label->enableDrawing();
label->redraw();
label->disableDrawing();
}
+148
View File
@@ -0,0 +1,148 @@
/////////////////////////////////////////////////////////////////////////////
// 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_BACKCOLOR
#endif
#ifndef CONFIG_CLABELTEST_FONTCOLOR
# define CONFIG_CLABELTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME clabel_main
# define MAIN_STRING "clabel_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#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
+130
View File
@@ -0,0 +1,130 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/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 MAIN_NAME(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Create an instance of the font test
printf(MAIN_STRING "Create CLabelTest instance\n");
CLabelTest *test = new CLabelTest();
// Connect the NX server
printf(MAIN_STRING "Connect the CLabelTest instance to the NX server\n");
if (!test->connect())
{
printf(MAIN_STRING "Failed to connect the CLabelTest instance to the NX server\n");
delete test;
return 1;
}
// Create a window to draw into
printf(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
printf(MAIN_STRING "Failed to create a window\n");
delete test;
return 1;
}
// Create a CLabel instance
CLabel *label = test->createLabel(g_hello);
if (!label)
{
printf(MAIN_STRING "Failed to create a label\n");
delete test;
return 1;
}
// Show the label
test->showLabel(label);
sleep(5);
// Clean up and exit
printf(MAIN_STRING "Clean-up and exit\n");
delete label;
delete test;
return 0;
}
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CLatchButton/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx clatchbuttontest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = clatchbutton
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,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 (by calling goModal()).
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll.
void CLatchButtonTest::poll(CLatchButton *button)
{
// Poll for mouse events
m_widgetControl->pollEvents(button);
}
@@ -0,0 +1,165 @@
/////////////////////////////////////////////////////////////////////////////
// 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_BACKCOLOR
#endif
#ifndef CONFIG_CLATCHBUTTONTEST_FONTCOLOR
# define CONFIG_CLATCHBUTTONTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME clatchbutton_main
# define MAIN_STRING "clatchbutton_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#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
+199
View File
@@ -0,0 +1,199 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/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 MAIN_NAME(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(MAIN_STRING "Button state: %s and %s\n",
nowClicked ? "clicked" : "released",
nowLatched ? "latched" : "unlatched");
if (clicked != nowClicked || latched != nowLatched)
{
printf(MAIN_STRING "ERROR: Expected %s and %s\n",
clicked ? "clicked" : "released",
latched ? "latched" : "unlatched");
clicked = nowClicked;
latched = nowLatched;
}
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Create an instance of the font test
printf(MAIN_STRING "Create CLatchButtonTest instance\n");
CLatchButtonTest *test = new CLatchButtonTest();
// Connect the NX server
printf(MAIN_STRING "Connect the CLatchButtonTest instance to the NX server\n");
if (!test->connect())
{
printf(MAIN_STRING "Failed to connect the CLatchButtonTest instance to the NX server\n");
delete test;
return 1;
}
// Create a window to draw into
printf(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
printf(MAIN_STRING "Failed to create a window\n");
delete test;
return 1;
}
// Create a CLatchButton instance
CLatchButton *button = test->createButton(g_pushme);
if (!button)
{
printf(MAIN_STRING "Failed to create a button\n");
delete test;
return 1;
}
// Show the button
printf(MAIN_STRING "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(MAIN_STRING "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(MAIN_STRING "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(MAIN_STRING "Clean-up and exit\n");
delete button;
delete test;
return 0;
}
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CLatchButtonArray/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx clatchbuttonarraytest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = clatchbuttonarray
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,301 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CLatchButtonArray/clatchbuttonarraytest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "clatchbuttonarraytest.hxx"
#include "cbgwindow.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CLatchButtonArrayTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CLatchButtonArrayTest Constructor
CLatchButtonArrayTest::CLatchButtonArrayTest()
{
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CLatchButtonArrayTest Descriptor
CLatchButtonArrayTest::~CLatchButtonArrayTest()
{
disconnect();
}
// Connect to the NX server
bool CLatchButtonArrayTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CLATCHBUTTONARRAYTEST_BGCOLOR))
{
message("CLatchButtonArrayTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CLatchButtonArrayTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// Destroy the widget control
if (m_widgetControl)
{
delete m_widgetControl;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CLatchButtonArrayTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CLatchButtonArrayTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CLatchButtonArrayTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CLatchButtonArray instance
CLatchButtonArray *CLatchButtonArrayTest::createButtonArray(void)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
message("CLatchButtonArrayTest::createGraphics: Failed to get window size\n");
return (CLatchButtonArray *)NULL;
}
// Pick an X/Y position such that the button array will be centered in the display
nxgl_coord_t buttonArrayX;
if (BUTTONARRAY_WIDTH >= windowSize.w)
{
buttonArrayX = 0;
}
else
{
buttonArrayX = (windowSize.w - BUTTONARRAY_WIDTH) >> 1;
}
nxgl_coord_t buttonArrayY;
if (BUTTONARRAY_HEIGHT >= windowSize.h)
{
buttonArrayY = 0;
}
else
{
buttonArrayY = (windowSize.h - BUTTONARRAY_HEIGHT) >> 1;
}
// Now we have enough information to create the button array
return new CLatchButtonArray(m_widgetControl,
buttonArrayX, buttonArrayY,
BUTTONARRAY_NCOLUMNS, BUTTONARRAY_NROWS,
BUTTONARRAY_BUTTONWIDTH, BUTTONARRAY_BUTTONHEIGHT);
}
// Draw the button array
void CLatchButtonArrayTest::showButton(CLatchButtonArray *buttonArray)
{
buttonArray->enable(); // Un-necessary, the widget is enabled by default
buttonArray->enableDrawing();
buttonArray->redraw();
}
// Perform a simulated mouse click on a button in the array. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void CLatchButtonArrayTest::click(CLatchButtonArray *buttonArray, int column, int row)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the selected button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// The the coorinates of the center of the button
nxgl_coord_t buttonX = buttonArray->getX() +
column * BUTTONARRAY_BUTTONWIDTH +
BUTTONARRAY_BUTTONWIDTH/2;
nxgl_coord_t buttonY = buttonArray->getY() +
row * BUTTONARRAY_BUTTONHEIGHT +
BUTTONARRAY_BUTTONHEIGHT/2;
// Then inject the mouse click
(void)nx_mousein(handle, buttonX, buttonY, NX_MOUSE_LEFTBUTTON);
}
// The counterpart to click. This simulates a button release through
// the same mechanism.
void CLatchButtonArrayTest::release(CLatchButtonArray *buttonArray, int column, int row)
{
// nx_mousein is meant to be called by mouse handling software.
// Here we just inject a left-button click directly in the center of
// the button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// The the coorinates of the center of the button
nxgl_coord_t buttonX = buttonArray->getX() +
column * BUTTONARRAY_BUTTONWIDTH +
BUTTONARRAY_BUTTONWIDTH/2;
nxgl_coord_t buttonY = buttonArray->getY() +
row * BUTTONARRAY_BUTTONHEIGHT +
BUTTONARRAY_BUTTONHEIGHT/2;
// Then inject the mouse release
(void)nx_mousein(handle, buttonX, buttonY, NX_MOUSE_NOBUTTONS);
}
// Widget events are normally handled in a modal loop (by calling goModal()).
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
void CLatchButtonArrayTest::poll(CLatchButtonArray *button)
{
// Poll for mouse events
m_widgetControl->pollEvents(button);
}
@@ -0,0 +1,182 @@
/////////////////////////////////////////////////////////////////////////////
// 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_BACKCOLOR
#endif
#ifndef CONFIG_CLATCHBUTTONARRAYTEST_FONTCOLOR
# define CONFIG_CLATCHBUTTONARRAYTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME clatchbuttonarray_main
# define MAIN_STRING "clatchbuttonarray_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
// The geometry of the button array
#define BUTTONARRAY_NCOLUMNS 4
#define BUTTONARRAY_NROWS 7
#define BUTTONARRAY_BUTTONWIDTH 60
#define BUTTONARRAY_BUTTONHEIGHT 32
#define BUTTONARRAY_WIDTH (BUTTONARRAY_BUTTONWIDTH * BUTTONARRAY_NCOLUMNS)
#define BUTTONARRAY_HEIGHT (BUTTONARRAY_BUTTONHEIGHT * BUTTONARRAY_NROWS)
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CLatchButtonArrayTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The widget control for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CLatchButtonArrayTest();
~CLatchButtonArrayTest();
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a CLatchButtonArray instance. This method will show you how to create
// a CLatchButtonArray widget
CLatchButtonArray *createButtonArray(void);
// Draw the button array. This method illustrates how to draw the CLatchButtonArray widget.
void showButton(CLatchButtonArray *buttonArray);
// Perform a simulated mouse click on a button in the array. This method injects
// the mouse click through the NX heirarchy just as would real mouse
// hardward.
void click(CLatchButtonArray *buttonArray, int column, int row);
// The counterpart to click. This simulates a button release through
// the same mechanism.
void release(CLatchButtonArray *buttonArray, int column, int row);
// Widget events are normally handled in a model loop (by calling goModel()).
// However, for this case we know when there should be press and release
// events so we don't have to poll. We can just perform a one pass poll
// then check if the event was processed corredly.
void poll(CLatchButtonArray *buttonArray);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CLATCHBUTTONARRAY_CLATCHBUTTONARRAYTEST_HXX
@@ -0,0 +1,301 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CLatchButtonArray/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 MAIN_NAME(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(MAIN_STRING "Button(%d,%d) state: %s and %s\n",
i, j,
nowClicked ? "clicked" : "released",
nowLatched ? "latched" : "unlatched");
if (clicked != nowClicked || latched != nowLatched)
{
printf(MAIN_STRING "ERROR: Expected %s and %s\n",
clicked ? "clicked" : "released",
latched ? "latched" : "unlatched");
clicked = nowClicked;
latched = nowLatched;
}
}
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("%s: Before: %8d After: %8d Change: %8d\n",
msg, previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmPrevious = mmcurrent.uordblks;
if ((unsigned int)mmcurrent.uordblks > g_mmPeak)
{
g_mmPeak = mmcurrent.uordblks;
}
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmPrevious = mmcurrent.uordblks;
g_mmPeak = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the button array test
printf(MAIN_STRING "Create CLatchButtonArrayTest instance\n");
CLatchButtonArrayTest *test = new CLatchButtonArrayTest();
updateMemoryUsage(g_mmPrevious, "After creating CLatchButtonArrayTest");
// Connect the NX server
printf(MAIN_STRING "Connect the CLatchButtonArrayTest instance to the NX server\n");
if (!test->connect())
{
printf(MAIN_STRING "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(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
printf(MAIN_STRING "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(MAIN_STRING "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(MAIN_STRING "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(MAIN_STRING "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(MAIN_STRING "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(MAIN_STRING "Clean-up and exit\n");
delete buttonArray;
updateMemoryUsage(g_mmPrevious, "After deleting the button array");
delete test;
updateMemoryUsage(g_mmPrevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
message("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial);
return 0;
}
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CListBox/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx clistboxtest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = clistbox
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,224 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CListBox/clistboxtest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "cbgwindow.hxx"
#include "clistboxtest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CListBoxTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CListBoxTest Constructor
CListBoxTest::CListBoxTest()
{
// Initialize state data
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CListBoxTest Descriptor
CListBoxTest::~CListBoxTest(void)
{
disconnect();
}
// Connect to the NX server
bool CListBoxTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CLISTBOXTEST_BGCOLOR))
{
message("CListBoxTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CListBoxTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
m_bgWindow = (CBgWindow *)NULL;
}
// Free the widget control instance
if (m_widgetControl)
{
delete m_widgetControl;
m_widgetControl = (CWidgetControl *)NULL;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CListBoxTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CListBoxTest::createWindow: Failed to create CBgWindow instance\n");
disconnect();
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CListBoxTest::createWindow: Failed to open background window\n");
disconnect();
return false;
}
return true;
}
// Create a listbox in the center of the window
CListBox *CListBoxTest::createListBox(void)
{
// Get the size of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CListBoxTest::createListBox: Failed to get window size\n");
disconnect();
return false;
}
// Put the listbox in the center of the display
nxgl_coord_t listboxWidth = windowSize.w >> 1;
nxgl_coord_t listboxX = windowSize.w >> 2;
nxgl_coord_t listboxHeight = windowSize.h >> 1;
nxgl_coord_t listboxY = windowSize.h >> 2;
// Create the listbox
CListBox *listbox = new CListBox(m_widgetControl,
listboxX, listboxY,
listboxWidth, listboxHeight);
if (!listbox)
{
printf("CListBoxTest::createListBox: Failed to create CListBox\n");
disconnect();
}
return listbox;
}
// (Re-)draw the listbox.
void CListBoxTest::showListBox(CListBox *listbox)
{
listbox->enable(); // Un-necessary, the widget is enabled by default
listbox->enableDrawing();
listbox->redraw();
}
@@ -0,0 +1,147 @@
/////////////////////////////////////////////////////////////////////////////
// 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_BACKCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME clistbox_main
# define MAIN_STRING "clistbox_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CListBoxTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CListBoxTest(void);
~CListBoxTest(void);
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a listbox in the center of the window
CListBox *createListBox(void);
// (Re-)draw the listbox.
void showListBox(CListBox *listbox);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CLISTBOX_CLISTBOXTEST_HXX
+327
View File
@@ -0,0 +1,327 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/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 MAIN_NAME(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("%s: Before: %8d After: %8d Change: %8d\n",
msg, previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmPrevious = mmcurrent.uordblks;
if ((unsigned int)mmcurrent.uordblks > g_mmPeak)
{
g_mmPeak = mmcurrent.uordblks;
}
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmPrevious = mmcurrent.uordblks;
g_mmPeak = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the listbox test
message(MAIN_STRING "Create CListBoxTest instance\n");
CListBoxTest *test = new CListBoxTest();
updateMemoryUsage(g_mmPrevious, "After creating CListBoxTest");
// Connect the NX server
message(MAIN_STRING "Connect the CListBoxTest instance to the NX server\n");
if (!test->connect())
{
message(MAIN_STRING "Failed to connect the CListBoxTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmPrevious, MAIN_STRING "After connecting to the server");
// Create a window to draw into
message(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
message(MAIN_STRING "Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmPrevious, MAIN_STRING "After creating a window");
// Create a listbox
message(MAIN_STRING "Create a ListBox\n");
CListBox *listbox = test->createListBox();
if (!listbox)
{
message(MAIN_STRING "Failed to create a listbox\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmPrevious, MAIN_STRING "After creating a listbox");
// Show the initial state of the listbox
listbox->setAllowMultipleSelections(true);
test->showListBox(listbox);
sleep(1);
// Now add items to the list box (in reverse alphabetical order)
message(MAIN_STRING "Add options to the ListBox\n");
for (int i = NOPTIONS - 1; i >= 0; i--)
{
listbox->addOption(g_options[i],i);
test->showListBox(listbox);
message(MAIN_STRING "%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, MAIN_STRING "After adding the listbox items");
sleep(1);
// Sort the list box
message(MAIN_STRING "Sort the ListBox\n");
listbox->sort();
test->showListBox(listbox);
updateMemoryUsage(g_mmPrevious, MAIN_STRING "After sorting the listbox");
sleep(1);
// Select and remove items from the listbox
srand(1978);
int nOptions;
while ((nOptions = listbox->getOptionCount()) > 0)
{
message(MAIN_STRING "Option count: %d\n", nOptions);
if (nOptions <= 5)
{
message(MAIN_STRING "Selecting all remaining options\n");
listbox->selectAllOptions();
test->showListBox(listbox);
updateMemoryUsage(g_mmPrevious, MAIN_STRING "After selecting all options");
sleep(1);
message(MAIN_STRING "Removing all remaining options\n");
listbox->removeAllOptions();
updateMemoryUsage(g_mmPrevious, MAIN_STRING "After removing all options");
test->showListBox(listbox);
}
else
{
int selected[5];
message(MAIN_STRING "Selecting five options\n");
for (int i = 0; i < 5; i++)
{
selected[i] = ((nOptions - 1) * rand()) / MAX_RAND;
message(MAIN_STRING "Selecting option %d\n", selected[i]);
listbox->removeOption(selected[i]);
test->showListBox(listbox);
usleep(500000);
}
updateMemoryUsage(g_mmPrevious, MAIN_STRING "After selecting five options");
message(MAIN_STRING "De-selecting options\n");
int index;
int count = 0;
while ((index = listbox->getSelectedIndex()) >= 0)
{
message(MAIN_STRING "De-selecting option %d\n", index);
listbox->deselectOption(index);
test->showListBox(listbox);
count++;
usleep(500000);
}
message(MAIN_STRING "%s: %d options de-selected\n",
count == 5 ? "OK" : "ERROR", count);
updateMemoryUsage(g_mmPrevious, MAIN_STRING "After de-selecting options");
message(MAIN_STRING "Removing the selected options\n");
for (int i = 0; i < 5; i++)
{
message(MAIN_STRING "Removing option %d\n", selected[i]);
listbox->removeOption(selected[i]);
test->showListBox(listbox);
usleep(500000);
}
updateMemoryUsage(g_mmPrevious, MAIN_STRING "After removing five options");
}
sleep(1);
}
updateMemoryUsage(g_mmPrevious, MAIN_STRING "After the listbox is empty again");
sleep(1);
// Clean up and exit
message(MAIN_STRING "Clean-up and exit\n");
delete listbox;
updateMemoryUsage(g_mmPrevious, "After deleting the listbox");
delete test;
updateMemoryUsage(g_mmPrevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
message("Peak memory usage: %8d\n", g_mmPeak - g_mmInitial);
return 0;
}
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CProgressBar/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx cprogressbartest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = cprogressbar
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,224 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/ProgressBar/cprogressbartest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "cbgwindow.hxx"
#include "cprogressbartest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CProgressBarTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CProgressBarTest Constructor
CProgressBarTest::CProgressBarTest()
{
// Initialize state data
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CProgressBarTest Descriptor
CProgressBarTest::~CProgressBarTest(void)
{
disconnect();
}
// Connect to the NX server
bool CProgressBarTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CPROGRESSBARTEST_BGCOLOR))
{
message("CProgressBarTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CProgressBarTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
m_bgWindow = (CBgWindow *)NULL;
}
// Free the widget control instance
if (m_widgetControl)
{
delete m_widgetControl;
m_widgetControl = (CWidgetControl *)NULL;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CProgressBarTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CProgressBarTest::createWindow: Failed to create CBgWindow instance\n");
disconnect();
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CProgressBarTest::createWindow: Failed to open background window\n");
disconnect();
return false;
}
return true;
}
// Create a bar in the center of the window
CProgressBar *CProgressBarTest::createProgressBar(void)
{
// Get the size of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CProgressBarTest::createProgressBar: Failed to get window size\n");
disconnect();
return false;
}
// Put the bar in the center of the display
nxgl_coord_t barWidth = windowSize.w >> 1;
nxgl_coord_t barX = windowSize.w >> 2;
nxgl_coord_t barHeight = 16;
nxgl_coord_t barY = (windowSize.h - barHeight) >> 1;
// Create the bar
CProgressBar *bar = new CProgressBar(m_widgetControl,
barX, barY,
barWidth, barHeight);
if (!bar)
{
printf("CProgressBarTest::createProgressBar: Failed to create CProgressBar\n");
disconnect();
}
return bar;
}
// (Re-)draw the bar.
void CProgressBarTest::showProgressBar(CProgressBar *bar)
{
bar->enable(); // Un-necessary, the widget is enabled by default
bar->enableDrawing();
bar->redraw();
}
@@ -0,0 +1,147 @@
/////////////////////////////////////////////////////////////////////////////
// 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_BACKCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME cprogressbar_main
# define MAIN_STRING "cprogressbar_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CProgressBarTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CProgressBarTest(void);
~CProgressBarTest(void);
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a progress bar in the center of the window
CProgressBar *createProgressBar(void);
// (Re-)draw the progress bar.
void showProgressBar(CProgressBar *bar);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CPROGRESSBAR_CPROGRESSBARTEST_HXX
+238
View File
@@ -0,0 +1,238 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/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 MAIN_NAME(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("\n%s:\n", msg);
message(" Before: %8d After: %8d Change: %8d\n\n",
previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the checkbox test
message(MAIN_STRING "Create CProgressBarTest instance\n");
CProgressBarTest *test = new CProgressBarTest();
updateMemoryUsage(g_mmprevious, "After creating CProgressBarTest");
// Connect the NX server
message(MAIN_STRING "Connect the CProgressBarTest instance to the NX server\n");
if (!test->connect())
{
message(MAIN_STRING "Failed to connect the CProgressBarTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After connecting to the server");
// Create a window to draw into
message(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
message(MAIN_STRING "Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a window");
// Create a progress bar
message(MAIN_STRING "Create a ProgressBar\n");
CProgressBar *bar = test->createProgressBar();
if (!bar)
{
message(MAIN_STRING "Failed to create a progress bar\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a progress bar");
// Set the progress bar minimum and maximum values
bar->setMinimumValue(0);
bar->setMaximumValue(MAX_PROGRESSBAR);
bar->setValue(0);
bar->hidePercentageText();
message(MAIN_STRING "ProgressBar range %d->%d Initial value %d\n",
bar->getMinimumValue(), bar->getMaximumValue(),
bar->getValue());
// Show the initial state of the checkbox
test->showProgressBar(bar);
sleep(1);
// Now move the progress bar up from 0 to 100% (with percentages off)
for (int i = 0; i <= MAX_PROGRESSBAR; i++)
{
bar->setValue(i);
test->showProgressBar(bar);
message(MAIN_STRING "%d. New value %d\n", i, bar->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the progress bar up #1");
usleep(500*1000);
// Now move the progress bar up from 0 to 100% (with percentages off)
bar->showPercentageText();
bar->setValue(0);
test->showProgressBar(bar);
usleep(500*1000);
for (int i = 0; i <= MAX_PROGRESSBAR; i++)
{
bar->setValue(i);
test->showProgressBar(bar);
message(MAIN_STRING "%d. New value %d\n", i, bar->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the progress bar up #2");
sleep(1);
// Clean up and exit
message(MAIN_STRING "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;
}
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CRadioButton/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx cradiobuttontest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = cradiobutton
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,305 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CRadioButton/cradiobuttontest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "cbgwindow.hxx"
#include "cradiobuttontest.hxx"
#include "cbitmap.hxx"
#include "glyphs.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CRadioButtonTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CRadioButtonTest Constructor
CRadioButtonTest::CRadioButtonTest()
{
// Initialize state data
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
// Peek at the radio button glyph to get a good estimate of the size
m_size.w = g_radioButtonOn.width;
m_size.h = g_radioButtonOn.height;
}
// CRadioButtonTest Descriptor
CRadioButtonTest::~CRadioButtonTest(void)
{
disconnect();
}
// Connect to the NX server
bool CRadioButtonTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CRADIOBUTTONTEST_BGCOLOR))
{
message("CRadioButtonTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CRadioButtonTest::disconnect(void)
{
// Free the radiobutton group
if (m_radioButtonGroup)
{
delete m_radioButtonGroup;
m_radioButtonGroup = (CRadioButtonGroup *)NULL;
}
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// Free the widget control instance
if (m_widgetControl)
{
delete m_widgetControl;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CRadioButtonTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CRadioButtonTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CRadioButtonTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CRadioButton instance
CRadioButton *CRadioButtonTest::newRadioButton(void)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
message("CRadioButtonTest::newRadioButton: Failed to get window size\n");
return (CRadioButton *)NULL;
}
// Create the radio button group, if we have not already done so
if (!m_radioButtonGroup)
{
// Start the radio button group in the center of the upper, left
// quadrant. The initial size is 0,0 and the default style is used.
nxgl_coord_t groupX = windowSize.w >> 2;
nxgl_coord_t groupY = windowSize.h >> 2;
m_radioButtonGroup = new CRadioButtonGroup(m_widgetControl, groupX, groupY);
if (!m_radioButtonGroup)
{
message("CRadioButtonTest::newRadioButton: Failed to create the radio button group\n");
return (CRadioButton *)NULL;
}
}
// Create the new radio button at the botton of the radio button group and
// with the size of the ON radio button glyph (they all need to be the same
// size!). Note that coordinates are relative to the parent bounding box.
nxgl_coord_t buttonX = 0;
nxgl_coord_t buttonY = m_radioButtonGroup->getHeight();
return m_radioButtonGroup->newRadioButton(buttonX, buttonY, m_size.w, m_size.h);
}
// (Re-)draw the buttons.
void CRadioButtonTest::showButtons(void)
{
m_radioButtonGroup->enable(); // Un-necessary, the widget is enabled by default
m_radioButtonGroup->enableDrawing();
m_radioButtonGroup->redraw();
}
// Push the radio button
void CRadioButtonTest::pushButton(CRadioButton *button)
{
// Get the button center coordinates
nxgl_coord_t buttonX = button->getX() + (button->getWidth() >> 1);
nxgl_coord_t buttonY = button->getY() + (button->getHeight() >> 1);
// Then push the button by calling nx_mousein. nx_mousein is meant to be
// called by mouse handling software. Here we just inject a left-button click
// directly in the center of the radio button.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level mouse interface
NXHANDLE handle = getServer();
// Then inject the mouse click
(void)nx_mousein(handle, buttonX, buttonY, NX_MOUSE_LEFTBUTTON);
// Poll for mouse events
//
// Widget events are normally handled in a modal loop (by calling goModal()).
// However, for this case we know that we just pressed the mouse button
// so we don't have to poll. We can just perform a one pass poll then
// then check if the mouse event was processed corredly.
m_widgetControl->pollEvents(m_radioButtonGroup);
// Then inject the mouse release
(void)nx_mousein(handle, buttonX, buttonY, 0);
// And poll for more mouse events
m_widgetControl->pollEvents(m_radioButtonGroup);
// And re-draw the buttons (the mouse click event should have automatically
// triggered the re-draw)
//
// showButtons();
}
// Show the state of the radio button group
void CRadioButtonTest::showButtonState(void)
{
int index = m_radioButtonGroup->getSelectedIndex();
if (index < 0)
{
message("CRadioButtonTest::showButtonState No button is pressed\n");
}
else
{
message("CRadioButtonTest::showButtonState button%d is selected\n", index+1);
}
}
@@ -0,0 +1,162 @@
/////////////////////////////////////////////////////////////////////////////
// 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_BACKCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME cradiobutton_main
# define MAIN_STRING "cradiobutton_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CRadioButtonTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
CRadioButtonGroup *m_radioButtonGroup; // The radio button group
// These are the dimensions that we will use for creating new radio buttons
struct nxgl_size_s m_size; // The size of each radio button
public:
// Constructor/destructors
CRadioButtonTest(void);
~CRadioButtonTest(void);
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// (Re-)draw the buttons.
void showButtons(void);
// Create a CRadioButton instance. This method will show you how to create
// a CRadioButton widget
CRadioButton *newRadioButton(void);
// Simulate pushing and releasing of the radio button
void pushButton(CRadioButton *button);
// Show the state of the radio button group
void showButtonState(void);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CRADIOBUTTON_CRADIOBUTTONTEST_HXX
+238
View File
@@ -0,0 +1,238 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/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 MAIN_NAME(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("\n%s:\n", msg);
message(" Before: %8d After: %8d Change: %8d\n\n",
previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the radio button test
message(MAIN_STRING "Create CRadioButtonTest instance\n");
CRadioButtonTest *test = new CRadioButtonTest();
updateMemoryUsage(g_mmprevious, "After creating CRadioButtonTest");
// Connect the NX server
message(MAIN_STRING "Connect the CRadioButtonTest instance to the NX server\n");
if (!test->connect())
{
message(MAIN_STRING "Failed to connect the CRadioButtonTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After connecting to the server");
// Create a window to draw into
message(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
message(MAIN_STRING "Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a window");
// Create three radio buttons
CRadioButton *button1 = test->newRadioButton();
if (!button1)
{
message(MAIN_STRING "Failed to create radio button 1\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating radio button 1");
CRadioButton *button2 = test->newRadioButton();
if (!button2)
{
message(MAIN_STRING "Failed to create radio button 2\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating radio button 2");
CRadioButton *button3 = test->newRadioButton();
if (!button3)
{
message(MAIN_STRING "Failed to create radio button 3\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating radio button 3");
// Show the initial state of the buttons
test->showButtons();
test->showButtonState();
sleep(1);
// Now push some buttons
message(MAIN_STRING "Pushing button 1\n");
test->pushButton(button1);
usleep(500*1000);
test->showButtonState();
updateMemoryUsage(g_mmprevious, "After pushing button 1");
usleep(500*1000);
message(MAIN_STRING "Pushing button 2\n");
test->pushButton(button2);
usleep(500*1000);
test->showButtonState();
updateMemoryUsage(g_mmprevious, "After pushing button 2");
usleep(500*1000);
message(MAIN_STRING "Pushing button 3\n");
test->pushButton(button3);
usleep(500*1000);
test->showButtonState();
updateMemoryUsage(g_mmprevious, "After pushing button 3");
sleep(2);
// Clean up and exit
message(MAIN_STRING "Clean-up and exit\n");
delete test;
updateMemoryUsage(g_mmprevious, "After deleting the test");
updateMemoryUsage(g_mmInitial, "Final memory usage");
return 0;
}
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CScrollbarHorizontal/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx cscrollbarhorizontaltest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = cscrollbarhorizontal
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,225 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "cbgwindow.hxx"
#include "cscrollbarhorizontaltest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CScrollbarHorizontalTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CScrollbarHorizontalTest Constructor
CScrollbarHorizontalTest::CScrollbarHorizontalTest()
{
// Initialize state data
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CScrollbarHorizontalTest Descriptor
CScrollbarHorizontalTest::~CScrollbarHorizontalTest(void)
{
disconnect();
}
// Connect to the NX server
bool CScrollbarHorizontalTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CSCROLLBARHORIZONTALTEST_BGCOLOR))
{
message("CScrollbarHorizontalTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CScrollbarHorizontalTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
m_bgWindow = (CBgWindow *)NULL;
}
// Free the widget control instance
if (m_widgetControl)
{
delete m_widgetControl;
m_widgetControl = (CWidgetControl *)NULL;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CScrollbarHorizontalTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CScrollbarHorizontalTest::createWindow: Failed to create CBgWindow instance\n");
disconnect();
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CScrollbarHorizontalTest::createWindow: Failed to open background window\n");
disconnect();
return false;
}
return true;
}
// Create a scrollbar in the center of the window
CScrollbarHorizontal *CScrollbarHorizontalTest::createScrollbar(void)
{
// Get the size of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CScrollbarHorizontalTest::createScrollbar: Failed to get window size\n");
disconnect();
return false;
}
// Put the scrollbar in the center of the display
nxgl_coord_t scrollbarWidth = windowSize.w >> 1;
nxgl_coord_t scrollbarX = windowSize.w >> 2;
nxgl_coord_t scrollbarHeight = 10;
nxgl_coord_t scrollbarY = (windowSize.h - scrollbarHeight) >> 1;
// Create the scrollbar
CScrollbarHorizontal *scrollbar =
new CScrollbarHorizontal(m_widgetControl,
scrollbarX, scrollbarY,
scrollbarWidth, scrollbarHeight);
if (!scrollbar)
{
printf("CScrollbarHorizontalTest::createScrollbar: Failed to create CScrollbarHorizontal\n");
disconnect();
}
return scrollbar;
}
// (Re-)draw the scrollbar.
void CScrollbarHorizontalTest::showScrollbar(CScrollbarHorizontal *scrollbar)
{
scrollbar->enable(); // Un-necessary, the widget is enabled by default
scrollbar->enableDrawing();
scrollbar->redraw();
}
@@ -0,0 +1,147 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CScrollbarHorizontal/cscrollbarhorizontaltest.hxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __UNITTESTS_CSCROLLBARHORIZONTAL_CSCROLLBARHORIZONTALTEST_HXX
#define __UNITTESTS_CSCROLLBARHORIZONTAL_CSCROLLBARHORIZONTALTEST_HXX
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <semaphore.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "nxconfig.hxx"
#include "cwidgetcontrol.hxx"
#include "ccallback.hxx"
#include "cbgwindow.hxx"
#include "cnxserver.hxx"
#include "cscrollbarhorizontal.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CSCROLLBARHORIZONTALTEST_BGCOLOR
# define CONFIG_CSCROLLBARHORIZONTALTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME cscrollbarhorizontal_main
# define MAIN_STRING "cscrollbarhorizontal_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CScrollbarHorizontalTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CScrollbarHorizontalTest(void);
~CScrollbarHorizontalTest(void);
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a scrollbar in the center of the window
CScrollbarHorizontal *createScrollbar(void);
// (Re-)draw the scrollbar.
void showScrollbar(CScrollbarHorizontal *scrollbar);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CSCROLLBARHORIZONTAL_CSCROLLBARHORIZONTALTEST_HXX
@@ -0,0 +1,231 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/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 MAIN_NAME(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("\n%s:\n", msg);
message(" Before: %8d After: %8d Change: %8d\n\n",
previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the checkbox test
message(MAIN_STRING "Create CScrollbarHorizontalTest instance\n");
CScrollbarHorizontalTest *test = new CScrollbarHorizontalTest();
updateMemoryUsage(g_mmprevious, "After creating CScrollbarHorizontalTest");
// Connect the NX server
message(MAIN_STRING "Connect the CScrollbarHorizontalTest instance to the NX server\n");
if (!test->connect())
{
message(MAIN_STRING "Failed to connect the CScrollbarHorizontalTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After connecting to the server");
// Create a window to draw into
message(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
message(MAIN_STRING "Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a window");
// Create a scrollbar
message(MAIN_STRING "Create a Scrollbar\n");
CScrollbarHorizontal *scrollbar = test->createScrollbar();
if (!scrollbar)
{
message(MAIN_STRING "Failed to create a scrollbar\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a scrollbar");
// Set the scrollbar minimum and maximum values
scrollbar->setMinimumValue(0);
scrollbar->setMaximumValue(MAX_SCROLLBAR);
scrollbar->setValue(0);
message(MAIN_STRING "Scrollbar range %d->%d Initial value %d\n",
scrollbar->getMinimumValue(), scrollbar->getMaximumValue(),
scrollbar->getValue());
// Show the initial state of the checkbox
test->showScrollbar(scrollbar);
sleep(1);
// Now move the scrollbar up
for (int i = 0; i <= MAX_SCROLLBAR; i++)
{
scrollbar->setValue(i);
test->showScrollbar(scrollbar);
message(MAIN_STRING "%d. New value %d\n", i, scrollbar->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the scrollbar up");
// And move the scrollbar down
for (int i = MAX_SCROLLBAR; i >= 0; i--)
{
scrollbar->setValue(i);
test->showScrollbar(scrollbar);
message(MAIN_STRING "%d. New value %d\n", i, scrollbar->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the scrollbar down");
sleep(1);
// Clean up and exit
message(MAIN_STRING "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;
}
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CScrollbarVertical/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx cscrollbarverticaltest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = cscrollbarvertical
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,225 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "cbgwindow.hxx"
#include "cscrollbarverticaltest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CScrollbarVerticalTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CScrollbarVerticalTest Constructor
CScrollbarVerticalTest::CScrollbarVerticalTest()
{
// Initialize state data
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CScrollbarVerticalTest Descriptor
CScrollbarVerticalTest::~CScrollbarVerticalTest(void)
{
disconnect();
}
// Connect to the NX server
bool CScrollbarVerticalTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CSCROLLBARVERTICALTEST_BGCOLOR))
{
message("CScrollbarVerticalTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CScrollbarVerticalTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
m_bgWindow = (CBgWindow *)NULL;
}
// Free the widget control instance
if (m_widgetControl)
{
delete m_widgetControl;
m_widgetControl = (CWidgetControl *)NULL;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CScrollbarVerticalTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CScrollbarVerticalTest::createWindow: Failed to create CBgWindow instance\n");
disconnect();
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CScrollbarVerticalTest::createWindow: Failed to open background window\n");
disconnect();
return false;
}
return true;
}
// Create a scrollbar in the center of the window
CScrollbarVertical *CScrollbarVerticalTest::createScrollbar(void)
{
// Get the size of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CScrollbarVerticalTest::createScrollbar: Failed to get window size\n");
disconnect();
return false;
}
// Put the scrollbar in the center of the display
nxgl_coord_t scrollbarWidth = 10;
nxgl_coord_t scrollbarX = (windowSize.w - scrollbarWidth) >> 1;
nxgl_coord_t scrollbarHeight = windowSize.h >> 1;
nxgl_coord_t scrollbarY = windowSize.h >> 2;
// Create the scrollbar
CScrollbarVertical *scrollbar =
new CScrollbarVertical(m_widgetControl,
scrollbarX, scrollbarY,
scrollbarWidth, scrollbarHeight);
if (!scrollbar)
{
printf("CScrollbarVerticalTest::createScrollbar: Failed to create CScrollbarVertical\n");
disconnect();
}
return scrollbar;
}
// (Re-)draw the scrollbar.
void CScrollbarVerticalTest::showScrollbar(CScrollbarVertical *scrollbar)
{
scrollbar->enable(); // Un-necessary, the widget is enabled by default
scrollbar->enableDrawing();
scrollbar->redraw();
}
@@ -0,0 +1,147 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CScrollbarVertical/cscrollbarverticaltest.hxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __UNITTESTS_CSCROLLBARVERTICAL_CSCROLLBARVERTICALTEST_HXX
#define __UNITTESTS_CSCROLLBARVERTICAL_CSCROLLBARVERTICALTEST_HXX
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <semaphore.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "nxconfig.hxx"
#include "cwidgetcontrol.hxx"
#include "ccallback.hxx"
#include "cbgwindow.hxx"
#include "cnxserver.hxx"
#include "cscrollbarvertical.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CSCROLLBARVERTICALTEST_BGCOLOR
# define CONFIG_CSCROLLBARVERTICALTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME cscrollbarvertical_main
# define MAIN_STRING "cscrollbarvertical_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CScrollbarVerticalTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CScrollbarVerticalTest(void);
~CScrollbarVerticalTest(void);
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a scrollbar in the center of the window
CScrollbarVertical *createScrollbar(void);
// (Re-)draw the scrollbar.
void showScrollbar(CScrollbarVertical *scrollbar);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CSCROLLBARVERTICAL_CSCROLLBARVERTICALTEST_HXX
@@ -0,0 +1,231 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CScrollbarVertical/main.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "cscrollbarverticaltest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
#define MAX_SCROLLBAR 20
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static unsigned int g_mmInitial;
static unsigned int g_mmprevious;
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int MAIN_NAME(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("\n%s:\n", msg);
message(" Before: %8d After: %8d Change: %8d\n\n",
previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the checkbox test
message(MAIN_STRING "Create CScrollbarVerticalTest instance\n");
CScrollbarVerticalTest *test = new CScrollbarVerticalTest();
updateMemoryUsage(g_mmprevious, "After creating CScrollbarVerticalTest");
// Connect the NX server
message(MAIN_STRING "Connect the CScrollbarVerticalTest instance to the NX server\n");
if (!test->connect())
{
message(MAIN_STRING "Failed to connect the CScrollbarVerticalTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After connecting to the server");
// Create a window to draw into
message(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
message(MAIN_STRING "Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a window");
// Create a scrollbar
message(MAIN_STRING "Create a Scrollbar\n");
CScrollbarVertical *scrollbar = test->createScrollbar();
if (!scrollbar)
{
message(MAIN_STRING "Failed to create a scrollbar\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a scrollbar");
// Set the scrollbar minimum and maximum values
scrollbar->setMinimumValue(0);
scrollbar->setMaximumValue(MAX_SCROLLBAR);
scrollbar->setValue(0);
message(MAIN_STRING "Scrollbar range %d->%d Initial value %d\n",
scrollbar->getMinimumValue(), scrollbar->getMaximumValue(),
scrollbar->getValue());
// Show the initial state of the checkbox
test->showScrollbar(scrollbar);
sleep(1);
// Now move the scrollbar up
for (int i = 0; i <= MAX_SCROLLBAR; i++)
{
scrollbar->setValue(i);
test->showScrollbar(scrollbar);
message(MAIN_STRING "%d. New value %d\n", i, scrollbar->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the scrollbar up");
// And move the scrollbar down
for (int i = MAX_SCROLLBAR; i >= 0; i--)
{
scrollbar->setValue(i);
test->showScrollbar(scrollbar);
message(MAIN_STRING "%d. New value %d\n", i, scrollbar->getValue());
usleep(5000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the scrollbar down");
sleep(1);
// Clean up and exit
message(MAIN_STRING "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;
}
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CSliderHorizontal/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx csliderhorizontaltest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = csliderhorizontal
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,224 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CSliderHorizontal/csliderhorizontaltest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "cbgwindow.hxx"
#include "csliderhorizontaltest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CSliderHorizontalTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CSliderHorizontalTest Constructor
CSliderHorizontalTest::CSliderHorizontalTest()
{
// Initialize state data
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CSliderHorizontalTest Descriptor
CSliderHorizontalTest::~CSliderHorizontalTest(void)
{
disconnect();
}
// Connect to the NX server
bool CSliderHorizontalTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CSLIDERHORIZONTALTEST_BGCOLOR))
{
message("CSliderHorizontalTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CSliderHorizontalTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
m_bgWindow = (CBgWindow *)NULL;
}
// Free the widget control instance
if (m_widgetControl)
{
delete m_widgetControl;
m_widgetControl = (CWidgetControl *)NULL;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CSliderHorizontalTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CSliderHorizontalTest::createWindow: Failed to create CBgWindow instance\n");
disconnect();
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CSliderHorizontalTest::createWindow: Failed to open background window\n");
disconnect();
return false;
}
return true;
}
// Create a slider in the center of the window
CSliderHorizontal *CSliderHorizontalTest::createSlider(void)
{
// Get the size of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CSliderHorizontalTest::createSlider: Failed to get window size\n");
disconnect();
return false;
}
// Put the slider in the center of the display
nxgl_coord_t sliderWidth = windowSize.w >> 1;
nxgl_coord_t sliderX = windowSize.w >> 2;
nxgl_coord_t sliderHeight = 10;
nxgl_coord_t sliderY = (windowSize.h - sliderHeight) >> 1;
// Create the slider
CSliderHorizontal *slider = new CSliderHorizontal(m_widgetControl,
sliderX, sliderY,
sliderWidth, sliderHeight);
if (!slider)
{
printf("CSliderHorizontalTest::createSlider: Failed to create CSliderHorizontal\n");
disconnect();
}
return slider;
}
// (Re-)draw the slider.
void CSliderHorizontalTest::showSlider(CSliderHorizontal *slider)
{
slider->enable(); // Un-necessary, the widget is enabled by default
slider->enableDrawing();
slider->redraw();
}
@@ -0,0 +1,147 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CSliderHorizontal/csliderhorizontaltest.hxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __UNITTESTS_CSLIDERHORIZONTAL_CSLIDERHORIZONTALTEST_HXX
#define __UNITTESTS_CSLIDERHORIZONTAL_CSLIDERHORIZONTALTEST_HXX
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <semaphore.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "nxconfig.hxx"
#include "cwidgetcontrol.hxx"
#include "ccallback.hxx"
#include "cbgwindow.hxx"
#include "cnxserver.hxx"
#include "csliderhorizontal.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CSLIDERHORIZONTALTEST_BGCOLOR
# define CONFIG_CSLIDERHORIZONTALTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME csliderhorizontal_main
# define MAIN_STRING "csliderhorizontal_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CSliderHorizontalTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CSliderHorizontalTest(void);
~CSliderHorizontalTest(void);
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a slider in the center of the window
CSliderHorizontal *createSlider(void);
// (Re-)draw the slider.
void showSlider(CSliderHorizontal *slider);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CSLIDERHORIZONTAL_CSLIDERHORIZONTALTEST_HXX
@@ -0,0 +1,231 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CSliderHorizontal/main.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "csliderhorizontaltest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
#define MAX_SLIDER 50
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static unsigned int g_mmInitial;
static unsigned int g_mmprevious;
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int MAIN_NAME(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("\n%s:\n", msg);
message(" Before: %8d After: %8d Change: %8d\n\n",
previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the checkbox test
message(MAIN_STRING "Create CSliderHorizontalTest instance\n");
CSliderHorizontalTest *test = new CSliderHorizontalTest();
updateMemoryUsage(g_mmprevious, "After creating CSliderHorizontalTest");
// Connect the NX server
message(MAIN_STRING "Connect the CSliderHorizontalTest instance to the NX server\n");
if (!test->connect())
{
message(MAIN_STRING "Failed to connect the CSliderHorizontalTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After connecting to the server");
// Create a window to draw into
message(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
message(MAIN_STRING "Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a window");
// Create a slider
message(MAIN_STRING "Create a Slider\n");
CSliderHorizontal *slider = test->createSlider();
if (!slider)
{
message(MAIN_STRING "Failed to create a slider\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a slider");
// Set the slider minimum and maximum values
slider->setMinimumValue(0);
slider->setMaximumValue(MAX_SLIDER);
slider->setValue(0);
message(MAIN_STRING "Slider range %d->%d Initial value %d\n",
slider->getMinimumValue(), slider->getMaximumValue(),
slider->getValue());
// Show the initial state of the checkbox
test->showSlider(slider);
sleep(1);
// Now move the slider up
for (int i = 0; i <= MAX_SLIDER; i++)
{
slider->setValue(i);
test->showSlider(slider);
message(MAIN_STRING "%d. New value %d\n", i, slider->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the slider up");
// And move the slider down
for (int i = MAX_SLIDER; i >= 0; i--)
{
slider->setValue(i);
test->showSlider(slider);
message(MAIN_STRING "%d. New value %d\n", i, slider->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the slider down");
sleep(1);
// Clean up and exit
message(MAIN_STRING "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;
}
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CSliderVertical/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx csliderverticaltest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = cslidervertical
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,225 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CSliderVertical/csliderverticaltest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// modify this software without notice.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "cbgwindow.hxx"
#include "csliderverticaltest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CSliderVerticalTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CSliderVerticalTest Constructor
CSliderVerticalTest::CSliderVerticalTest()
{
// Initialize state data
m_widgetControl = (CWidgetControl *)NULL;
m_bgWindow = (CBgWindow *)NULL;
}
// CSliderVerticalTest Descriptor
CSliderVerticalTest::~CSliderVerticalTest(void)
{
disconnect();
}
// Connect to the NX server
bool CSliderVerticalTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Set the background color
if (!setBackgroundColor(CONFIG_CSLIDERVERTICALTEST_BGCOLOR))
{
message("CSliderVerticalTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CSliderVerticalTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
m_bgWindow = (CBgWindow *)NULL;
}
// Free the widget control instance
if (m_widgetControl)
{
delete m_widgetControl;
m_widgetControl = (CWidgetControl *)NULL;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CSliderVerticalTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
message("CSliderVerticalTest::createWindow: Failed to create CBgWindow instance\n");
disconnect();
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
message("CSliderVerticalTest::createWindow: Failed to open background window\n");
disconnect();
return false;
}
return true;
}
// Create a slider in the center of the window
CSliderVertical *CSliderVerticalTest::createSlider(void)
{
// Get the size of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CSliderVerticalTest::createSlider: Failed to get window size\n");
disconnect();
return false;
}
// Put the slider in the center of the display
nxgl_coord_t sliderWidth = 10;
nxgl_coord_t sliderX = (windowSize.w - sliderWidth) >> 1;
nxgl_coord_t sliderHeight = windowSize.h >> 1;
nxgl_coord_t sliderY = windowSize.h >> 2;
// Create the slider
CSliderVertical *slider = new CSliderVertical(m_widgetControl,
sliderX, sliderY,
sliderWidth, sliderHeight);
if (!slider)
{
printf("CSliderVerticalTest::createSlider: Failed to create CSliderVertical\n");
disconnect();
}
return slider;
}
// (Re-)draw the slider.
void CSliderVerticalTest::showSlider(CSliderVertical *slider)
{
slider->enable(); // Un-necessary, the widget is enabled by default
slider->enableDrawing();
slider->redraw();
}
@@ -0,0 +1,147 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CSliderVertical/csliderverticaltest.hxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __UNITTESTS_CSLIDERVERTICAL_CSLIDERVERTICALTEST_HXX
#define __UNITTESTS_CSLIDERVERTICAL_CSLIDERVERTICALTEST_HXX
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <semaphore.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "nxconfig.hxx"
#include "cwidgetcontrol.hxx"
#include "ccallback.hxx"
#include "cbgwindow.hxx"
#include "cnxserver.hxx"
#include "cslidervertical.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CSLIDERVERTICALTEST_BGCOLOR
# define CONFIG_CSLIDERVERTICALTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME cslidervertical_main
# define MAIN_STRING "cslidervertical_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#endif
// If debug is enabled, use the debug function, lib_rawprintf() instead
// of printf() so that the output is synchronized.
#ifdef CONFIG_DEBUG
# define message lib_lowprintf
#else
# define message printf
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CSliderVerticalTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CBgWindow *m_bgWindow; // Background window instance
public:
// Constructor/destructors
CSliderVerticalTest(void);
~CSliderVerticalTest(void);
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a slider in the center of the window
CSliderVertical *createSlider(void);
// (Re-)draw the slider.
void showSlider(CSliderVertical *slider);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CSLIDERVERTICAL_CSLIDERVERTICALTEST_HXX
@@ -0,0 +1,231 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CSliderVertical/main.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "csliderverticaltest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
#define MAX_SLIDER 50
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static unsigned int g_mmInitial;
static unsigned int g_mmprevious;
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int MAIN_NAME(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Private Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: updateMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void updateMemoryUsage(unsigned int previous,
FAR const char *msg)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
/* Show the change from the previous time */
message("\n%s:\n", msg);
message(" Before: %8d After: %8d Change: %8d\n\n",
previous, mmcurrent.uordblks, mmcurrent.uordblks - previous);
/* Set up for the next test */
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Name: initMemoryUsage
/////////////////////////////////////////////////////////////////////////////
static void initMemoryUsage(void)
{
struct mallinfo mmcurrent;
/* Get the current memory usage */
#ifdef CONFIG_CAN_PASS_STRUCTS
mmcurrent = mallinfo();
#else
(void)mallinfo(&mmcurrent);
#endif
g_mmInitial = mmcurrent.uordblks;
g_mmprevious = mmcurrent.uordblks;
}
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name: user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Initialize memory monitor logic
initMemoryUsage();
// Create an instance of the checkbox test
message(MAIN_STRING "Create CSliderVerticalTest instance\n");
CSliderVerticalTest *test = new CSliderVerticalTest();
updateMemoryUsage(g_mmprevious, "After creating CSliderVerticalTest");
// Connect the NX server
message(MAIN_STRING "Connect the CSliderVerticalTest instance to the NX server\n");
if (!test->connect())
{
message(MAIN_STRING "Failed to connect the CSliderVerticalTest instance to the NX server\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After connecting to the server");
// Create a window to draw into
message(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
message(MAIN_STRING "Failed to create a window\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a window");
// Create a slider
message(MAIN_STRING "Create a Slider\n");
CSliderVertical *slider = test->createSlider();
if (!slider)
{
message(MAIN_STRING "Failed to create a slider\n");
delete test;
return 1;
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After creating a slider");
// Set the slider minimum and maximum values
slider->setMinimumValue(0);
slider->setMaximumValue(MAX_SLIDER);
slider->setValue(0);
message(MAIN_STRING "Slider range %d->%d Initial value %d\n",
slider->getMinimumValue(), slider->getMaximumValue(),
slider->getValue());
// Show the initial state of the checkbox
test->showSlider(slider);
sleep(1);
// Now move the slider up
for (int i = 0; i <= MAX_SLIDER; i++)
{
slider->setValue(i);
test->showSlider(slider);
message(MAIN_STRING "%d. New value %d\n", i, slider->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the slider up");
// And move the slider down
for (int i = MAX_SLIDER; i >= 0; i--)
{
slider->setValue(i);
test->showSlider(slider);
message(MAIN_STRING "%d. New value %d\n", i, slider->getValue());
usleep(1000); // The simulation needs this to let the X11 event loop run
}
updateMemoryUsage(g_mmprevious, MAIN_STRING "After moving the slider down");
sleep(1);
// Clean up and exit
message(MAIN_STRING "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;
}
+172
View File
@@ -0,0 +1,172 @@
#################################################################################
# NxWidgets/UnitTests/CTextBox/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
TESTDIR := ${shell pwd | sed -e 's/ /\\ /g'}
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Add the path to the NXWidget include directory to the CFLAGS
NXWIDGETS_DIR="$(TESTDIR)/../../NXWidgets/libnxwidgets"
NXWIDGETS_INC="$(NXWIDGETS_DIR)/include"
NXWIDGETS_LIB="$(NXWIDGETS_DIR)/libnxwidgets$(LIBEXT)"
INCDIR=$(TOPDIR)/tools/incdir.sh
ifeq ($(WINTOOL),y)
CFLAGS += ${shell $(INCDIR) -w "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) -w "$(CXX)" "$(NXWIDGETS_INC)"}
else
CFLAGS += ${shell $(INCDIR) "$(CC)" "$(NXWIDGETS_INC)"}
CXXFLAGS += ${shell $(INCDIR) "$(CXX)" "$(NXWIDGETS_INC)"}
endif
# Get the path to the archiver tool
TESTTOOL_DIR="$(TESTDIR)/../tools"
ARCHIVER=$(TESTTOOL_DIR)/addobjs.sh
# Hello, World! C++ Example
ASRCS =
CSRCS =
CXXSRCS = main.cxx ctextboxtest.cxx
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
POSIX_BIN = "$(APPDIR)/libapps$(LIBEXT)"
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(POSIX_BIN)}"
else
BIN = $(POSIX_BIN)
endif
ROOTDEPPATH = --dep-path .
# helloxx built-in application info
APPNAME = ctextbox
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 2048
# Common build
VPATH =
all: .built
.PHONY: clean depend context disclean chkcxx chklib
# Object file creation targets
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
# Verify that the NuttX configuration is setup to support C++
chkcxx:
ifneq ($(CONFIG_HAVE_CXX),y)
@echo ""
@echo "In order to use this example, you toolchain must support must"
@echo ""
@echo " (1) Explicitly select CONFIG_HAVE_CXX to build in C++ support"
@echo " (2) Define CXX, CXXFLAGS, and COMPILEXX in the Make.defs file"
@echo " of the configuration that you are using."
@echo ""
@exit 1
endif
# Verify that the NXWidget library has been built
chklib:
@( \
if [ ! -e "$(NXWIDGETS_LIB)" ]; then \
echo "$(NXWIDGETS_LIB) does not exist."; \
echo "Please go to $(NXWIDGETS_DIR)"; \
echo "and rebuild the library"; \
exit 1; \
fi; \
)
# Library creation targets
$(NXWIDGETS_LIB): # Just to keep make happy. chklib does the work.
.built: chkcxx chklib $(OBJS) $(NXWIDGETS_LIB)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
ifeq ($(WINTOOL),y)
@$(ARCHIVER) -w -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
else
@$(ARCHIVER) -p "$(CROSSDEV)" $(BIN) $(NXWIDGETS_DIR)
endif
@touch .built
# Standard housekeeping targets
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
endif
@touch $@
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CXX) -- $(CXXFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
@@ -0,0 +1,287 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CTextBox/ctextboxtest.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <cerrno>
#include <unistd.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxfonts.h>
#include "nxconfig.hxx"
#include "ctextboxtest.hxx"
#include "cbgwindow.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CTextBoxTest Method Implementations
/////////////////////////////////////////////////////////////////////////////
// CTextBoxTest Constructor
CTextBoxTest::CTextBoxTest()
{
m_bgWindow = (CBgWindow *)NULL;
m_nxFont = (CNxFont *)NULL;
m_text = (CNxString *)NULL;
}
// CTextBoxTest Descriptor
CTextBoxTest::~CTextBoxTest()
{
disconnect();
}
// Connect to the NX server
bool CTextBoxTest::connect(void)
{
// Connect to the server
bool nxConnected = CNxServer::connect();
if (nxConnected)
{
// Create the default font instance
m_nxFont = new CNxFont(NXFONT_DEFAULT,
CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR,
CONFIG_NXWIDGETS_TRANSPARENT_COLOR);
if (!m_nxFont)
{
printf("CTextBoxTest::connect: Failed to create the default font\n");
}
// Set the background color
if (!setBackgroundColor(CONFIG_CTEXTBOXTEST_BGCOLOR))
{
printf("CTextBoxTest::connect: setBackgroundColor failed\n");
}
}
return nxConnected;
}
// Disconnect from the NX server
void CTextBoxTest::disconnect(void)
{
// Close the window
if (m_bgWindow)
{
delete m_bgWindow;
}
// Free the display string
if (m_text)
{
delete m_text;
m_text = (CNxString *)NULL;
}
// Free the default font
if (m_nxFont)
{
delete m_nxFont;
m_nxFont = (CNxFont *)NULL;
}
// And disconnect from the server
CNxServer::disconnect();
}
// Create the background window instance. This function illustrates
// the basic steps to instantiate any window:
//
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool CTextBoxTest::createWindow(void)
{
// Initialize the widget control using the default style
m_widgetControl = new CWidgetControl((CWidgetStyle *)NULL);
// Get an (uninitialized) instance of the background window as a class
// that derives from INxWindow.
m_bgWindow = getBgWindow(m_widgetControl);
if (!m_bgWindow)
{
printf("CTextBoxTest::createGraphics: Failed to create CBgWindow instance\n");
delete m_widgetControl;
return false;
}
// Open (and initialize) the window
bool success = m_bgWindow->open();
if (!success)
{
printf("CTextBoxTest::createGraphics: Failed to open background window\n");
delete m_bgWindow;
m_bgWindow = (CBgWindow*)0;
return false;
}
return true;
}
// Create a CTextBox instance
CTextBox *CTextBoxTest::createTextBox(void)
{
// Get the width of the display
struct nxgl_size_s windowSize;
if (!m_bgWindow->getSize(&windowSize))
{
printf("CTextBoxTest::createGraphics: Failed to get window size\n");
return (CTextBox *)NULL;
}
// Create an empty CNxString instance to contain the C string
m_text = new CNxString();
// Get the height and width of the text display area. The width
// is half of the display width and the height is optimized for
// the font height
nxgl_coord_t textBoxWidth = windowSize.w >> 1;
nxgl_coord_t textBoxHeight = (nxgl_coord_t)m_nxFont->getHeight();
// The default CTextBox has borders enabled with thickness of one.
// Add twice the thickness of the border to the height.
textBoxHeight += 2 * 1;
// Pick an X/Y position such that the label will be centered in the display
nxgl_coord_t labelX = windowSize.w >> 2;
nxgl_coord_t labelY = (windowSize.h - textBoxHeight) >> 1;
// Now we have enough information to create the label
return new CTextBox(m_widgetControl, labelX, labelY, textBoxWidth, textBoxHeight, *m_text);
}
// Draw the label
void CTextBoxTest::showTextBox(CTextBox *label)
{
label->enable();
label->enableDrawing();
label->redraw();
}
// Inject simulated keyboard characters into NX.
void CTextBoxTest::injectChars(CTextBox *textbox, int nCh, FAR const uint8_t *string)
{
// nx_kbdin is meant to be called by keyboard handling software.
// Here we just inject the string under unit test control.
// First, get the server handle. Graphics software will never care
// about the server handle. Here we need it to get access to the
// low-level keyboard interface
NXHANDLE handle = getServer();
// The widget must have focus to receive keyboard input
m_widgetControl->setFocusedWidget(textbox);
// Inject the string one character at a time to get a more realistic
// simulation of keyboard behavior. Note the API nx_kbdin() could
// be used to inject the string in its entirety.
for (int i = 0; i < nCh; i++)
{
// Inject the next character
(void)nx_kbdchin(handle, string[i]);
// Widget events are normally handled in a modal loop (by calling goModal()).
// However, for this case we know when there should be keyboard events pending,
// events so we don't have to poll repeatedly. We can just perform a one pass
// poll
m_widgetControl->pollEvents(textbox);
// Sleep a bit, just for the effect (this also gives the X server loop a
// chance to run in the simulated environment.
usleep(500*1000);
}
}
@@ -0,0 +1,152 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CTextBox/ctextboxtest.hxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef __UNITTESTS_CTEXTBOX_CTEXTBOXTEST_HXX
#define __UNITTESTS_CTEXTBOX_CTEXTBOXTEST_HXX
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <semaphore.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "nxconfig.hxx"
#include "cwidgetcontrol.hxx"
#include "ccallback.hxx"
#include "cbgwindow.hxx"
#include "cnxserver.hxx"
#include "cnxfont.hxx"
#include "cnxstring.hxx"
#include "ctextbox.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
// Configuration ////////////////////////////////////////////////////////////
#ifndef CONFIG_HAVE_CXX
# error "CONFIG_HAVE_CXX must be defined"
#endif
#ifndef CONFIG_CTEXTBOXTEST_BGCOLOR
# define CONFIG_CTEXTBOXTEST_BGCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKCOLOR
#endif
#ifndef CONFIG_CTEXTBOXTEST_FONTCOLOR
# define CONFIG_CTEXTBOXTEST_FONTCOLOR CONFIG_NXWIDGETS_DEFAULT_FONTCOLOR
#endif
// What is the entry point called?
#ifdef CONFIG_NSH_BUILTIN_APPS
# define MAIN_NAME ctextbox_main
# define MAIN_STRING "ctextbox_main: "
#else
# define MAIN_NAME user_start
# define MAIN_STRING "user_start: "
#endif
/////////////////////////////////////////////////////////////////////////////
// Public Classes
/////////////////////////////////////////////////////////////////////////////
using namespace NXWidgets;
class CTextBoxTest : public CNxServer
{
private:
CWidgetControl *m_widgetControl; // The controlling widget for the window
CNxFont *m_nxFont; // Default font
CBgWindow *m_bgWindow; // Background window instance
CNxString *m_text; // The label string
public:
// Constructor/destructors
CTextBoxTest();
~CTextBoxTest();
// Initializer/unitializer. These methods encapsulate the basic steps for
// starting and stopping the NX server
bool connect(void);
void disconnect(void);
// Create a window. This method provides the general operations for
// creating a window that you can draw within.
//
// Those general operations are:
// 1) Create a dumb CWigetControl instance
// 2) Pass the dumb CWidgetControl instance to the window constructor
// that inherits from INxWindow. This will "smarten" the CWidgetControl
// instance with some window knowlede
// 3) Call the open() method on the window to display the window.
// 4) After that, the fully smartened CWidgetControl instance can
// be used to generate additional widgets by passing it to the
// widget constructor
bool createWindow(void);
// Create a CTextBox instance. This method will show you how to create
// a CTextBox widget
CTextBox *createTextBox(void);
// Draw the label. This method illustrates how to draw the CTextBox widget.
void showTextBox(CTextBox *label);
// Inject simulated keyboard characters into NX.
void injectChars(CTextBox *textbox, int nCh, FAR const uint8_t *string);
};
/////////////////////////////////////////////////////////////////////////////
// Public Data
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
#endif // __UNITTESTS_CTEXTBOX_CTEXTBOXTEST_HXX
+141
View File
@@ -0,0 +1,141 @@
/////////////////////////////////////////////////////////////////////////////
// NxWidgets/UnitTests/CTextBox/main.cxx
//
// Copyright (C) 2012 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in
// the documentation and/or other materials provided with the
// distribution.
// 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
// me be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include <nuttx/init.h>
#include <cstdio>
#include <unistd.h>
#include <debug.h>
#include <nuttx/nx/nx.h>
#include "ctextboxtest.hxx"
/////////////////////////////////////////////////////////////////////////////
// Definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Classes
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Private Data
/////////////////////////////////////////////////////////////////////////////
static const char string1[] = "Johhn ";
static const char string2[] = "\b\b\bn Doe\r";
/////////////////////////////////////////////////////////////////////////////
// Public Function Prototypes
/////////////////////////////////////////////////////////////////////////////
// Suppress name-mangling
extern "C" int MAIN_NAME(int argc, char *argv[]);
/////////////////////////////////////////////////////////////////////////////
// Public Functions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// user_start/nxheaders_main
/////////////////////////////////////////////////////////////////////////////
int MAIN_NAME(int argc, char *argv[])
{
// Create an instance of the font test
printf(MAIN_STRING "Create CTextBoxTest instance\n");
CTextBoxTest *test = new CTextBoxTest();
// Connect the NX server
printf(MAIN_STRING "Connect the CTextBoxTest instance to the NX server\n");
if (!test->connect())
{
printf(MAIN_STRING "Failed to connect the CTextBoxTest instance to the NX server\n");
delete test;
return 1;
}
// Create a window to draw into
printf(MAIN_STRING "Create a Window\n");
if (!test->createWindow())
{
printf(MAIN_STRING "Failed to create a window\n");
delete test;
return 1;
}
// Create a CTextBox instance
CTextBox *textbox = test->createTextBox();
if (!textbox)
{
printf(MAIN_STRING "Failed to create a text box\n");
delete test;
return 1;
}
// Show the text box
test->showTextBox(textbox);
// Wait a bit, then inject a string with a typo
sleep(1);
test->injectChars(textbox, sizeof(string1), (FAR const uint8_t*)string1);
// Now fix the string with backspaces and finish it correctly
usleep(500*1000);
test->injectChars(textbox, sizeof(string2), (FAR const uint8_t*)string2);
// Clean up and exit
sleep(2);
printf(MAIN_STRING "Clean-up and exit\n");
delete textbox;
delete test;
return 0;
}
+394
View File
@@ -0,0 +1,394 @@
README
======
This directory contains a collection of Unit Tests that can be used to verify
NXWidgets.:
Contents
========
o Installing and Building the Unit Tests
1. Setup NuttX
a) Configure NuttX
b) Enable C++ Support
c) Enable Debug Options
d) Other Possible nuttx/.config changes
e) Other Possible apps/.config changes
2. Configure in the Selected Unit Test
o Work-Arounds
1. Build Issues
2. Stack Size Issues with the X11 Simulation
o Theory of Operation
o Unit Test Directories
o Example
Installing and Building the Unit Tests
======================================
1. Setup NuttX
a) Configure NuttX
Configure NuttX to run one of the target configurations. For example,
let's assume that you are using the sim/nsh2 configuration. The sim/nsh2
configuration was specially created for use NXWidgets on the simulation
platform. A similar, special configuration stm3210e-eval/nsh2 is also
for the STM3210E-EVAL available. However, the unit test can be run on
other configurations (see steps d and e below).
We will assume the sim/nsh2 configuration in this discussion. The
sim/nsh2 configuration is installed as follows:
cd <nuttx-directory-path>
make distclean
cd tools
./configure.sh sim/nsh2
Where:
<nuttx-directory-path> is the full, absolute path to the NuttX build directory
If you are using the sim/nsh2 or stm3210e-eval configurations, then skip
to step 2.
There may be certain requirements for the configuration that you select...
for example, certain widget tests may require touchscreen support or special
font selections. These test-specific requirements are addressed below under
"Unit Test Directories"
b) Enable C++ Support
If you are not using the sim/nsh2 or stm3210e-eval, you will need to add
the following definitions to the nuttx configuration at nuttx/.config to
enable C++ support:
CONFIG_HAVE_CXX=y
Check first, some configurations already have C++ support enabled (As of this
writing *ONLY* the sim/nsh2 and stm321-e-eval configurations have C++ support
pre-enabled).
c) Enable Debug Options
If you are running on a simulated target, then you might also want to
enable debug symbols:
CONFIG_DEBUG_SYMBOLS=y
Then you can run the simulation using GDB or DDD which is a very powerful
debugging environment!
d) Other nuttx/.config changes -- NSH configurations only.
If the configuration that you are using supports NSH and NSH built-in tasks
then all is well. If it is an NSH configuration, then you will have to define
the following in your nuttx/.config file as well (if it is not already defined):
CONFIG_NSH_BUILTIN_APPS=y
sim/nsh2 and stm3210e-eval/nsh2 already has this setting. You do not need
to change anything further in the nuttx/.config file if you are using either
of these configurations.
e) Other apps/.config changes -- NON-NSH configurations only.
For non-NSH configurations (such as the sim/touchscreen) you will have to
remove the CONFIGURED_APPS seting that contains the user_start function so
that you use the user_start in the unit test code instead. So, for example,
with the sim/touchscreen configuration you need to remove the following from
the apps/.config file:
CONFIGURED_APPS += examples/<example> ## REMOVE
The following step will then install the new, correct directory containing
the user_start function for the selected unit test. If you see that NSH
is configured:
CONFIGURED_APPS += examples/nsh ## DO NOT REMOVE
Then DO NOT REMOVE the CONFIGURED_APPS setting. Go back and re-read c)
above. Do either c) or d). Don't do both!
sim/nsh2 and stm3210e-eval/nsh2 both NSH configurations. You do not need
to change anything further in the apps/.config file for any NSH configuration.
2. Configure/Install the Selected Unit Test
Then reconfigure that to use the Unit Test of your choice:
cd <raztek-nxwidgets-directory>/trunk/UnitTests/tools
./install.sh <apps-directory-path> <test-sub-directory>
Where:
<apps-directory-path> is the full, absolute path to the NuttX apps/ directory
<test-sub-directory> is the name of a sub-directory in the UnitTests directory
3. Instantiate the Configuration
Before we can make the NXWidgets Library, we have to instantiate the NuttX
configuration with the installed unit test:
cd <nuttx-directory-path>
. ./setenv.sh
make context
This will create auto-generated files and will setup symbolic links needed
in order to build the NXWidgets Library.
4. Adjust the Stack Size
If using an simulation configuration (like sim/nsh2) and your unit test
uses X11 as its display device, then you would have to increase the size
of unit test stack as described below under "Stack Size Issues with the
X11 Simulation."
5. Build the NXWidgets Library
cd <raztek-nxwidgets-directory>/trunk/NXWidgets/libnxwidgets
make TOPDIR=<nuttx-directory-path>
6. Build NuttX including the unit test and the NXWidget library
cd <nuttx-directory-path>
. ./setenv.sh
make
Work-Arounds
============
Build Issues
------------
1. I have seen this error on Cygwin building C++ code:
LD: nuttx.rel
ld: skipping incompatible /home/patacongo/projects/nuttx/nuttx/trunk/nuttx/libxx//liblibxx.a when searching for -llibxx
ld: cannot find -llibxx
The problem seems to be caused because gcc build code for 32-bit mode and g++ builds code for 64-bit mode. Add the -m32 option to the g++ command line seems to fix the problem. In Make.defs:
CXXFLAGS = -m32 $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) \
$(ARCHCPUFLAGSXX) $(ARCHINCLUDESXX) $(ARCHDEFINES) $(EXTRADEFINES) -pipe
2. Stack Size Issues with the X11 Simulation
When you run the NuttX simulation, it uses stacks allocated by NuttX from the
NuttX heap. The memory management model is exactly the same in the simulation
as it is real, target system. This is good because this produces a higher
fidelity simulation.
However, when the simulation calls into Linux/Cygwin libraries, it will still
use these small simulation stacks. This happens, for example, when you call
into the system to get and put characters to the console window or when you
make x11 calls into the system. The programming model within those libraries
will assume a Linux/Cygwin environment where the stack size grows dynamically
As a consequence, those system libraries may allocate large data structures
on the stack and overflow the small NuttX stacks. X11, in particular,
requires large stacks. If you are using X11 in the simulation, make sure
that you set aside a "lot" of stack for the X11 system calls (maybe 8 or 16Kb).
The stack size for the thread that begins with user start is controlled
by the configuration setting CONFIG_USERMAIN_STACKSIZE; you may need to
increase this value to larger number to survive the X11 system calls.
If you are running X11 applications as NSH add-on programs, then the stack
size of the add-on program is controlled in another way. Here are the
steps for increasing the stack size in that case:
cd ../apps/namedapps # Go to the namedapps directory
vi namedapps_list.h # Edit this file and increase the stack size of the add-on
rm .built *.o # This will force the namedapps logic to rebuild
Theory Of Operation
===================
The NuttX application Makefile at apps/Makefile has some special hooks for
building "external" applications. In particular, it will automatically
build in the contents any directory call "external/" that may appear in the
apps/ directory. There is no external/ directory in the repository. Rather,
this directory may be provided by the user (possibly as a symbolic link) to
add libraries and applications to the standard build from the repository.
The script at tools/install.sh, then, just does a lot of careful validation and
sanity checking. Then it installs the UnitTest test sub-directory in the apps/
directory by creating a symbolic link in the apps/ directory call "external".
That symbolic link will refer to the selected UnitTest sub-directory.
UnitTests
=========
The following provide simple unit tests for each of the NXWidgets. In
addition, these unit tests provide examples for the use of each widget
type.
CButton
Exercises the CButton widget
Depends on CLabel
CButtonArray
Exercises the CButtonArray widget
CCheckBox
Exercises the CCheckBox widget
Depends on CLabel and CButton.
CGlyphButton
Exercises the CGlyphButton widget.
Depends on CLabel and CButton.
CImage
Exercises the CImage widget
CLabel
Exercises the CLabel widget
CProgressBar
Exercises the CProgressBar widget
CRadioButton
Exercises the CRadioButton and CRadioButtonGroup widgets.
Depends on CLabel and CButton
CScrollBarHorizontal
Exercises the ScrollbarHorizontal
Depends on CSliderHorizontal and CGlyphButton
CScrollBarVertical
Exercises the ScrollbarHorizontal
Depends on CSliderVertical and CGlyphButton
CSliderHorizontal
Exercises the CSliderHorizontal
Depends on CSliderHorizontalGrip
CSliderVertical
Exercises the CSliderVertical
Depends on CSliderVerticalGrip
CTextBox
Exercises the CTextBox widget
Depends on CLabel
Example
=======
1. Configure sim/nsh2
Where: nuttx and nuttx/tools directory
$ cd tools/
$ ./configure.sh sim/nsh2
$ cd -
2. Edit nuttx/.config to enable C++ support
Do nothing... sim/nsh2 already has C++ support enabled.
3. Install the CButton C++ application (for example)
Where: NXWidgets/trunk/UnitTests/tool
$ ./install.sh ~/projects/nuttx/nuttx/trunk/apps/ CButton
/home/patacongo/projects/nuttx/nuttx/trunk/apps//external already exists...
Removing the old symbolic link.
Creating symbolic link
- To /home/patacongo/projects/nuttx/gui/raztek-nxwidgets/trunk/UnitTests/tools/../CButton
- At /home/patacongo/projects/nuttx/nuttx/trunk/apps//external
4. Instantiate the Configuration
Where: nuttx directory
$ cd /home/patacongo/projects/nuttx/nuttx/trunk/nuttx
$ . ./setenv.sh
$ make context
This will create auto-generated files and will setup symbolic links needed
in order to build the NXWidgets Library.
6. Adjust the Stack Size
If using an simulation configuration (like sim/nsh2) and your unit test
uses X11 as its display device, then you would have to increase the size
of unit test stack as described above under "Stack Size Issues."
7. Build the NXWdigets Library
Where XWidgets/trunk/NXWidgets/libnxwidgets
$ cd /home/patacongo/projects/nuttx/gui/raztek-nxwidgets/trunkXWidgets/libnxwidgets
$ make TOPDIR=/home/patacongo/projects/nuttx/nuttx/trunk/nuttx
8. Build NuttX
Where: nuttx directory
$ cd /home/patacongo/projects/nuttx/nuttx/trunk/nuttx
$ make
...
8. Run the "bringup" task:
a. Start NuttX
Where: nuttx directory
./nuttx
NuttShell (NSH) NuttX-6.9
nsh>
b. Execute NuttX
Where: NSH command prompt
NOTE that when you run NSH as a simulation, the commands are echoed
twice -- once by Linux/Cygwin and once by NuttX:
nsh> help
help
...
Builtin Apps:
nx
nxhello
tc
bringup
nsh> bringup
bringup
bringup [2:128]
c. Then do a kludgy thing
Where: NSH command prompt
The I/O with the Linux/Cygwin simulation is blocking. So while NSH is
waiting for input nothing can run (see configs/sim/README.txt for more info).
One way to make NSH stop asking for input is to sleep.
nsh> sleep 10
sleep 10
NOTE 1: This is not a problem if CONFIG_SCHED_WAITPID is defined in the
configuration file. If CONFIG_SCHED_WAITPID is defined, NSH will wait
for the unit test to complete and it will not be necessary to sleep.
NOTE 2: CONFIG_SCHED_WAITPID is defined in the sim/nsh2 configuration
so you can probably ignore this kludgy thing.
d. The Unit Test runs
As soon as NSH sleeps, the unit test will run:
bringup_main: Saying hello from the dynamically constructed instance
CHelloWorld::HelloWorld: Hello, World!!
bringup_main: Saying hello from the instance constructed on the stack
CHelloWorld::HelloWorld: Hello, World!!
bringup_main: Saying hello from the statically constructed instance
CHelloWorld::HelloWorld: Hello, World!!
8. Debugging
Where: nuttx directory
In the simulation (only) you can use GDB or, better, the graphic
front-end DDD to debug the code. Most embedded targets do not
have good debugging capabilities.
In order to debug, you have to have build with CONFIG_DEBUG_SYMBOLS=y.
This setting is preselected in the sim/nsh2 configuration so that
you don't have to do anything.
Then under Linux or in a Cygwin X11 window, you can start the graphic
debugger like:
ddd nuttx &
+141
View File
@@ -0,0 +1,141 @@
#!/bin/bash
#################################################################################
# NxWidgets/UnitTests/tools/addobjs.sh
#
# 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.
#
#################################################################################
# set -x
# Get input parameters
usage="Usage: $0 [OPTIONS] <lib-path> <obj-dir>"
advice="Try '$0 -h' for more information"
unset prefix
wintool=n
while [ ! -z "$1" ]; do
case $1 in
-d )
set -x
;;
-p )
shift
prefix=$1
;;
-w )
wintool=y
;;
-h )
echo "$0 will add all object (.o) files in directory to an archive."
echo ""
echo $usage
echo ""
echo "Where:"
echo " <alib-path> is the full, absolute path to the library to use"
echo " <obj-dir> is full path to the directory containing the object files to be added"
echo "OPTIONS include:"
echo " -p Prefix to use. For example, to use arm-elf-ar, add '-p arm-elf-'"
echo " -w Use Windows style paths insted of POSIX paths"
echo " -d Enable script debug"
echo " -h Show this usage information"
exit 0
;;
* )
break;
;;
esac
shift
done
libpath=$1
objdir=$2
archiver="${prefix}"ar
# Verify input parameters
if [ -z "${libpath}" ]; then
echo "Missing required arguments"
echo ""
echo $usage
echo $advice
exit 1
fi
if [ -z "${objdir}" ]; then
echo "Missing required argument <obj-dir>"
echo ""
echo $usage
echo $advice
exit 1
fi
if [ ! -w ${libpath} ]; then
if [ -e ${libpath} ]; then
echo "${libpath} exists but is not a write-able file"
echo $advice
else
echo "${libpath} does not exist"
echo $advice
fi
exit 1
fi
if [ ! -d ${objdir} ]; then
if [ -e ${objdir} ]; then
echo "${objdir} exists but is not a directory"
echo $advice
else
echo "${objdir} does not exist"
echo $advice
fi
exit 1
fi
# Add each object file in <obj-dir> to the archive at <lib-path>
for obj in `ls "${objdir}"/*.o`; do
name=`basename "${obj}"`
if [ "X${wintool}" = "Xy" ]; then
objpath=`cygpath -w "${obj}"`
else
objpath=${obj}
fi
echo "AR: ${name}"
${archiver} rcs ${libpath} ${objpath} || \
{ echo "Failed to archive the object file:"; \
echo " Archive: ${libpath}"; \
echo " Object: ${obj}"; \
exit 1; \
}
done
+152
View File
@@ -0,0 +1,152 @@
#!/bin/bash
#################################################################################
# NxWidgets/UnitTests/tools/install.sh
#
# 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.
#
#################################################################################
#
# set -x
# Functions
function ShowUsage()
{
echo ""
echo "USAGE: $0 <apps-directory-path> <test-sub-directory>"
echo ""
echo "Where:"
echo " <apps-directory-path> is the full, absolute path to the NuttX apps/ directory"
echo " <test-sub-directory> is the name of a sub-directory in the UnitTests directory"
echo ""
}
function ShowTests()
{
for testdir in ${UNITTEST_DIRPATH}/*; do
subdir=`basename ${testdir}`
if [ -d "${UNITTEST_DIRPATH}/${subdir}" ]; then
if [ -f "${UNITTEST_DIRPATH}/${subdir}/Makefile" ]; then
echo $subdir
fi
fi
done
}
# Input parameters
APPS_DIRPATH=$1
TEST_SUBDIR=$2
if [ -z "${APPS_DIRPATH}" ]; then
echo "Missing required arguments"
ShowUsage
exit 1
fi
if [ -z "${TEST_SUBDIR}" ]; then
echo "Missing required argument <test-sub-directory>"
ShowUsage
exit 1
fi
# Make sure that we know where we are and where we are going
WD=`pwd`
if [ -x install.sh ]; then
UNITTEST_DIRPATH="${WD}/.."
TOOLS_DIRPATH="${WD}"
else
if [ -x tools/install.sh ]; then
UNITTEST_DIRPATH="${WD}"
TOOLS_DIRPATH="${WD}/tools"
else
echo "This script must be executed in the UnitTest or UnitTest/tools directory"
ShowUsage
exit 1
fi
fi
if [ ! -d "${APPS_DIRPATH}" ]; then
echo "Directory ${APPS_DIRPATH} does not exist"
ShowUsage
exit 1
fi
if [ ! -f "${APPS_DIRPATH}/Makefile" ]; then
echo "Directory ${APPS_DIRPATH} does not look like a NuttX apps directory"
ShowUsage
exit 1
fi
TEST_PATH="${UNITTEST_DIRPATH}/${TEST_SUBDIR}"
if [ ! -d "${TEST_PATH}" ]; then
echo "Directory ${TEST_PATH} does not exist"
ShowUsage
ShowTests
exit 1
fi
if [ ! -f "${TEST_PATH}/Makefile" ]; then
echo "Directory ${TEST_PATH} does not look like a unit test directory"
ShowUsage
ShowTests
exit 1
fi
# Check if the symbolic link "external" exists in the NuttX apps directory
if [ -e "${APPS_DIRPATH}/external" ]; then
echo "${APPS_DIRPATH}/external already exists..."
if [ -h "${APPS_DIRPATH}/external" ]; then
echo " Removing the old symbolic link."
rm "${APPS_DIRPATH}/external" || \
{ echo " ERROR: Failed to remove old symbolic link"; \
exit 1;
}
else
echo " ERROR: But it is not a symbolic link!"
echo " Please remove ${APPS_DIRPATH}/external"
echo " and run this script again"
fi
fi
# Then set up the symbolic link "external" in the NuttX apps to point to the
# UnitTest subdirectory
echo "Creating symbolic link"
echo " - To ${TEST_PATH}"
echo " - At ${APPS_DIRPATH}/external"
ln -s "${TEST_PATH}" "${APPS_DIRPATH}/external" || \
{ echo "Failed to create symbollic link"; \
exit 1;
}
+70
View File
@@ -0,0 +1,70 @@
/********************************************************************************
* NxWidgets
* Graphical Widgets for the NuttX RTOS
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*******************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in almost all NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
********************************************************************************/
+135
View File
@@ -0,0 +1,135 @@
#################################################################################
# NxWidgets/libnxwidgets/Makefile
#
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
# me be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
NXWDIR := ${shell pwd | sed -e 's/ /\\ /g'}
ASRCS =
CSRCS =
# Infrastructure
CXXSRCS = cbitmap.cxx cbgwindow.cxx ccallback.cxx cgraphicsport.cxx
CXXSRCS += clistdata.cxx clistdataitem.cxx cnxfont.cxx
CXXSRCS += cnxserver.cxx cnxstring.cxx cnxtimer.cxx cnxwidget.cxx cnxwindow.cxx
CXXSRCS += cnxtkwindow.cxx cnxtoolbar.cxx crect.cxx crectcache.cxx
CXXSRCS += crlepalettebitmap.cxx cstringiterator.cxx ctext.cxx cwidgetcontrol.cxx
CXXSRCS += cwidgeteventhandlerlist.cxx singletons.cxx
# Widget APIs
CXXSRCS += cbutton.cxx cbuttonarray.cxx ccheckbox.cxx ccyclebutton.cxx
CXXSRCS += cglyphbutton.cxx cimage.cxx ckeypad.cxx clabel.cxx clatchbutton.cxx
CXXSRCS += clatchbuttonarray.cxx clistbox.cxx clistboxdataitem.cxx cmultilinetextbox.cxx
CXXSRCS += cprogressbar.cxx cradiobutton.cxx cradiobuttongroup.cxx cscrollbarhorizontal.cxx
CXXSRCS += cscrollbarpanel.cxx cscrollbarvertical.cxx cscrollinglistbox.cxx
CXXSRCS += cscrollingpanel.cxx cscrollingtextbox.cxx csliderhorizontal.cxx
CXXSRCS += csliderhorizontalgrip.cxx cslidervertical.cxx csliderverticalgrip.cxx
CXXSRCS += cstickybutton.cxx cstickybuttonarray.cxx ctextbox.cxx
# Images
CXXSRCS += glyph_nxlogo.cxx
CXXSRCS += glyph_arrowdown.cxx glyph_checkboxon.cxx glyph_screendepthup.cxx
CXXSRCS += glyph_arrowleft.cxx glyph_control.cxx glyph_screenflipdown.cxx
CXXSRCS += glyph_arrowright.cxx glyph_cycle.cxx glyph_screenflipup.cxx
CXXSRCS += glyph_arrowup.cxx glyph_radiobuttonoff.cxx glyph_shift.cxx
CXXSRCS += glyph_backspace.cxx glyph_radiobuttonmu.cxx glyph_windowclose.cxx
CXXSRCS += glyph_capslock.cxx glyph_radiobuttonon.cxx glyph_windowdepthdown.cxx
CXXSRCS += glyph_checkboxmu.cxx glyph_return.cxx glyph_windowdepthup.cxx
CXXSRCS += glyph_checkboxoff.cxx glyph_screendepthdown.cxx
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS)
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:.cxx=$(OBJEXT))
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
BIN = libnxwidgets$(LIBEXT)
CFLAGS += -I include
CXXFLAGS += -I include
DEPPATH = --dep-path src
VPATH = src
all: $(BIN)
.PHONY = check_nuttx depend clean distclean export
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(CXXOBJS): %$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)
check_nuttx:
@( \
if [ -z "$(TOPDIR)" ]; then \
echo "The path to the nuttx directory must be provided on the command line."; \
echo "Usage: make -C $(NXWDIR) TOPDIR=\"<nuttx directory>\""; \
exit 1; \
fi; \
if [ ! -d "$(TOPDIR)" ]; then \
echo "The nuttx directory (TOPDIR) does not exist: $(TOPDIR)"; \
exit 1; \
fi; \
if [ ! -f "$(TOPDIR)/.config" ]; then \
echo "The nuttx directory (TOPDIR) has not been configured"; \
echo "Please configure NuttX and try again"; \
exit 1; \
fi; \
)
$(BIN): check_nuttx $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $@, $${obj}); \
done ; )
.depend: Makefile $(SRCS)
@$(MKDEP) $(DEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f $(BIN) *.a *.o *~ .*.sw*
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
export: $(BIN)
zip -r nxwidgets-export.zip include $(BIN) COPYING
-include Make.dep
@@ -0,0 +1,314 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/cbgwindow.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CBGWINDOW_HXX
#define __INCLUDE_CBGWINDOW_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include <nuttx/nx/nx.h>
#include "nxconfig.hxx"
#include "ccallback.hxx"
#include "inxwindow.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
class INxWindow;
struct SBitmap;
/**
* This class defines operations on a the NX background window.
* There are three instances that represent an NX window from the
* perspective of NXWidgets.
*
* - There is one widget control instance per NX window,
* - One CCallback instance per window,
* - One window instance.
*
* There a various kinds of of window instances, but each inherits
* (1) CCallback and dispatches the Windows callbacks and (2) INxWindow
* that describes the common window behavior.
*/
class CBgWindow : protected CCallback, public INxWindow
{
private:
NXHANDLE m_hNxServer; /**< Handle to the NX server. */
NXWINDOW m_hWindow; /**< Handle to the NX background window */
CWidgetControl *m_widgetControl; /**< The controlling widget for the window */
public:
/**
* Constructor. Obtains the background window from server and wraps
* the window as CBgWindow. Creates an uninitialized instance of the
* CBgWindow object. The open() method must be called to initialize
* the instance.
*
* The general steps to create any window include:
* 1) Create a dumb CWigetControl instance
* 2) Pass the dumb CWidgetControl instance to the window constructor
* that inherits from INxWindow.
* 3) The window constructor call CWidgetControl methods to "smarten"
* the CWidgetControl instance with window-specific knowledge.
* 4) Call the open() method on the window to display the window.
* 5) After that, the fully smartend CWidgetControl instance can
* be used to generate additional widgets.
* 6) After that, the fully smartened CWidgetControl instance can
* be used to generate additional widgets by passing it to the
* widget constructor
*
* @param hNxServer Handle to the NX server.
* @param widgetControl Controlling widget for this window.
*/
CBgWindow(NXHANDLE hNxServer, CWidgetControl *widgetControl);
/**
* Destructor. Returns the background window to the server.
*/
virtual ~CBgWindow(void);
/**
* Creates a the new window. Window creation is separate from
* object instantiation so that failures can be reported.
*
* @return True if the window was successfully created.
*/
bool open(void);
/**
* Request the position and size information of the window. The values
* will be returned asynchronously through the client callback method.
* The GetPosition() method may than be called to obtain the positional
* data as provided by the callback.
*
* @return True on success, false on any failure.
*/
bool requestPosition(void);
/**
* Get the position of the window (as reported by the NX callback). NOTE:
* The background window is always positioned at {0,0}
*
* @return The position.
*/
bool getPosition(FAR struct nxgl_point_s *pPos);
/**
* Get the size of the window (as reported by the NX callback). NOTE:
* The size of the background window is always the entire display.
*
* @return The size.
*/
bool getSize(FAR struct nxgl_size_s *pSize);
/**
* Set the position and size of the window.
*
* @param pPos The new position of the window.
* @return True on success, false on any failure.
*/
bool setPosition(FAR const struct nxgl_point_s *pPos);
/**
* Set the size of the selected window. NOTE: The size of the
* background window is always the entire display and cannot be
* changed.
*
* @param pSize The new size of the window.
* @return True on success, false on any failure.
*/
bool setSize(FAR const struct nxgl_size_s *pSize);
/**
* Bring the window to the top of the display. NOTE: The background
* window cannot be raised.
*
* @return True on success, false on any failure.
*/
bool raise(void);
/**
* Lower the window to the bottom of the display. NOTE: The background
* window is always at the bottom of the window hierarchy.
*
* @return True on success, false on any failure.
*/
bool lower(void);
/**
* Set an individual pixel in the window with the specified color.
*
* @param pPos The location of the pixel to be filled.
* @param color The color to use in the fill.
*
* @return True on success; false on failure.
*/
bool setPixel(FAR const struct nxgl_point_s *pPos,
nxgl_mxpixel_t color);
/**
* Fill the specified rectangle in the window with the specified color.
*
* @param pRect The location to be filled.
* @param color The color to use in the fill.
*
* @return True on success; false on failure.
*/
bool fill(FAR const struct nxgl_rect_s *pRect,
nxgl_mxpixel_t color);
/**
* Get the raw contents of graphic memory within a rectangular region. NOTE:
* Since raw graphic memory is returned, the returned memory content may be
* the memory of windows above this one and may not necessarily belong to
* this window unless you assure that this is the top window.
*
* @param rect The location to be copied
* @param dest - The describes the destination bitmap to receive the
* graphics data.
*/
void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest);
/**
* Fill the specified trapezoidal region in the window with the specified
* color.
*
* @param pClip Clipping rectangle relative to window (may be null).
* @param pTrap The trapezoidal region to be filled.
* @param color The color to use in the fill.
*
* @return True on success; false on failure.
*/
bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip,
FAR const struct nxgl_trapezoid_s *pTrap,
nxgl_mxpixel_t color);
/**
* Fill the specified line in the window with the specified color.
*
* @param vector - Describes the line to be drawn
* @param width - The width of the line
* @param color - The color to use to fill the line
*
* @return True on success; false on failure.
*/
bool drawLine(FAR struct nxgl_vector_s *vector,
nxgl_coord_t width,
nxgl_mxpixel_t color);
/**
* Draw a filled circle at the specified position, size, and color.
*
* @param center The window-relative coordinates of the circle center.
* @param radius The radius of the rectangle in pixels.
* @param color The color of the rectangle.
*/
bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius,
nxgl_mxpixel_t color);
/**
* Move a rectangular region within the window.
*
* @param pRect Describes the rectangular region to move.
* @param pOffset The offset to move the region.
*
* @return True on success; false on failure.
*/
bool move(FAR const struct nxgl_rect_s *pRect,
FAR const struct nxgl_point_s *pOffset);
/**
* Copy a rectangular region of a larger image into the rectangle in the
* specified window.
*
* @param pDest Describes the rectangular on the display that will receive
* the bitmap.
* @param pSrc The start of the source image.
* @param pOrigin the pOrigin of the upper, left-most corner of the full
* bitmap. Both pDest and pOrigin are in window coordinates, however,
* pOrigin may lie outside of the display.
* @param stride The width of the full source image in bytes.
*
* @return True on success; false on failure.
*/
bool bitmap(FAR const struct nxgl_rect_s *pDest,
FAR const void *pSrc,
FAR const struct nxgl_point_s *pOrigin,
unsigned int stride);
};
}
#endif // __cplusplus
#endif // __INCLUDE_CBGWINDOW_HXX
+204
View File
@@ -0,0 +1,204 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/cbitmap.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in all NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CBITMAP_HXX
#define __INCLUDE_CBITMAP_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "nxconfig.hxx"
#include "ibitmap.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Bitmap Structure
*/
struct SBitmap
{
uint8_t bpp; /**< Bits per pixel */
uint8_t fmt; /**< Color format */
nxgl_coord_t width; /**< Width in pixels */
nxgl_coord_t height; /**< Height in rows */
uint16_t stride; /**< Width in bytes */
FAR const void *data; /**< Pointer to the beginning of pixel data */
};
/**
* Class providing bitmap accessor for a bitmap represented by SBitmap.
*/
class CBitmap : public IBitmap
{
protected:
const struct SBitmap *m_bitmap; /**< The bitmap that is being managed */
/**
* Copy constructor is protected to prevent usage.
*/
inline CBitmap(const CBitmap &bitmap) { }
public:
/**
* Constructor.
*
* @param bitmap The bitmap structure being wrapped.
*/
CBitmap(const struct SBitmap *bitmap);
/**
* Destructor.
*/
inline ~CBitmap(void) {}
/**
* Get the bitmap's color format.
*
* @return The bitmap's width.
*/
const uint8_t getColorFormat(void) const;
/**
* Get the bitmap's color format.
*
* @return The bitmap's color format.
*/
const uint8_t getBitsPerPixel(void) const;
/**
* Get the bitmap's width (in pixels/columns).
*
* @return The bitmap's pixel depth.
*/
const nxgl_coord_t getWidth(void) const;
/**
* Get the bitmap's height (in rows).
*
* @return The bitmap's height.
*/
const nxgl_coord_t getHeight(void) const;
/**
* Get the bitmap's width (in bytes).
*
* @return The bitmap's width.
*/
const nxgl_coord_t getStride(void) const;
/**
* Get one row from the bit map image.
*
* @param x The offset into the row to get
* @param y The row number to get
* @param width The number of pixels to get from the row
* @param data The memory location provided by the caller
* in which to return the data. This should be at least
* (getWidth()*getBitsPerPixl() + 7)/8 bytes in length
* and properly aligned for the pixel color format.
* @param True if the run was returned successfully.
*/
bool getRun(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width,
FAR void *data);
};
}
#endif // __cplusplus
#endif // __INCLUDE_CBITMAP_HXX
+235
View File
@@ -0,0 +1,235 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/cbutton.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in all NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CBUTTON_HXX
#define __INCLUDE_CBUTTON_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "clabel.hxx"
#include "cwidgetstyle.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Forward references
*/
class CWidgetControl;
/**
* Clickable button widget. Displays text within the button.
*/
class CButton : public CLabel
{
protected:
/**
* Draws the outline of the button.
*
* @param port Graphics port to draw to.
*/
virtual void drawOutline(CGraphicsPort *port);
/**
* Draws the outline of the button.
*
* @param port Graphics port to draw to.
* @param useClicked Present outline using the 'clicked' style
*/
void drawOutline(CGraphicsPort *port, bool useClicked);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawContents(CGraphicsPort *port);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @param useClicked Present contents using the 'clicked' style
* @see redraw()
*/
void drawContents(CGraphicsPort *port, bool useClicked);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawBorder(CGraphicsPort *port);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @param useClicked Present border using the 'clicked' style
* @see redraw()
*/
void drawBorder(CGraphicsPort *port, bool useClicked);
/**
* Redraws the button.
*
* @param x The x coordinate of the click.
* @param y The y coordinate of the click.
*/
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
/**
* Raises an action event and redraws the button.
*
* @param x The x coordinate of the mouse.
* @param y The y coordinate of the mouse.
*/
virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y);
/**
* Redraws the button.
*
* @param x The x coordinate of the mouse.
* @param y The y coordinate of the mouse.
*/
virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y);
/**
* Copy constructor is protected to prevent usage.
*/
inline CButton(const CButton &button) : CLabel(button) { }
public:
/**
* Constructor for buttons that display a string.
*
* @param pWidgetControl The widget control for the display.
* @param x The x coordinate of the button, relative to its parent.
* @param y The y coordinate of the button, relative to its parent.
* @param width The width of the button.
* @param height The height of the button.
* @param text The text for the button to display.
* @param style The style that the button should use. If this is not
* specified, the button will use the global default widget
* style.
*/
CButton(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height, const CNxString &text,
CWidgetStyle *style = (CWidgetStyle *)NULL);
/**
* CButton Destructor.
*/
virtual inline ~CButton() { }
};
}
#endif // __cplusplus
#endif // __INCLUDE_CBUTTON_HXX
@@ -0,0 +1,317 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/cbuttonarray.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CBUTTONARRAY_HXX
#define __INCLUDE_CBUTTONARRAY_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "clabel.hxx"
#include "cwidgetstyle.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Forward references
*/
class CWidgetControl;
class CNxString;
/**
* Manages a two-dimensional array of buttons as one widget. A two-
* dimensional array of buttons might also be called a "keyboard".
*/
class CButtonArray : public CNxWidget
{
protected:
uint8_t m_buttonColumns; /**< The number of columns in one row */
uint8_t m_buttonRows; /**< The number buttons in one column */
bool m_redrawButton; /**< True: Redraw button; False: redraw all */
bool m_cursorOn; /**< Cursor on; hightlighted button displayed */
bool m_cursorChange; /**< True: Redraw cursor button only */
nxgl_coord_t m_buttonWidth; /**< The width of one button in pixels */
nxgl_coord_t m_buttonHeight; /**< The height of one button in rows */
nxgl_coord_t m_clickX; /**< The X position of the last clicked button */
nxgl_coord_t m_clickY; /**< The Y position of the last clicked button */
uint8_t m_cursorColumn; /**< The column index of the highlighted button */
uint8_t m_cursorRow; /**< The row index of the highlighted button */
CNxString *m_buttonText; /**< Text for each button */
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawContents(CGraphicsPort *port);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawBorder(CGraphicsPort *port);
/**
* Redraw only one button
*
* @param port The CGraphicsPort to draw to.
* @param column The button column index
* @param row The button row index
* @param useClicked Draw the button using the 'clicked' button style,
* regardless of the actual button state.
* @see onClick() and onRelease()
*/
virtual void drawButton(CGraphicsPort *port, int column, int row, bool useClicked);
/**
* Redraws the button.
*
* @param x The x coordinate of the click.
* @param y The y coordinate of the click.
*/
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
/**
* Raises an action event and redraws the button.
*
* @param x The x coordinate of the mouse.
* @param y The y coordinate of the mouse.
*/
virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y);
/**
* Redraws the button.
*
* @param x The x coordinate of the mouse.
* @param y The y coordinate of the mouse.
*/
virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y);
/**
* Convert an X/Y position to a button column/row index
*
* @param x The x position
* @param y The y position
* @param column The location to return the column index of the button
* of interest
* @param row The location to return the row index of the button of
* interest
* @return false is the position is invalid
*/
virtual bool posToButton(nxgl_coord_t x, nxgl_coord_t y, int &column, int &row);
/**
* Updates the GUI after the text has changed.
*/
virtual void onTextChange(void);
/**
* Copy constructor is protected to prevent usage.
*/
inline CButtonArray(const CButtonArray &button) : CNxWidget(button) { }
public:
/**
* Constructor for an array of buttons.
*
* @param pWidgetControl The widget control for the display.
* @param x The x coordinate of the button array, relative to its parent.
* @param y The y coordinate of the button array, relative to its parent.
* @param buttonColumns The number of buttons in one row of the button array
* @param buttonRows The number of buttons in one column of the button array
* @param buttonWidth The width of one button
* @param buttonHeight The height of one button
* @param style The style that the button should use. If this is not
* specified, the button will use the global default widget
* style.
*/
CButtonArray(CWidgetControl *pWidgetControl,
nxgl_coord_t x, nxgl_coord_t y,
uint8_t buttonColumns, uint8_t buttonRows,
nxgl_coord_t buttonWidth, nxgl_coord_t buttonHeight,
CWidgetStyle *style = (CWidgetStyle *)NULL);
/**
* CButtonArray Destructor.
*/
~CButtonArray(void);
/**
* Returns the string shown in the label.
*
* @param column The column index of the button of interest
* @param row The row index of the button of interest
* @return The label's text.
*/
virtual const CNxString &getText(int column, int row) const;
/**
* Set the text displayed in the label.
*
* @param column The column index of the button to set
* @param row The row index of the button to set
* @param text String to display.
*/
virtual void setText(int column, int row, const CNxString &text);
/**
* Return the position of the last clicked button (0,0 will be returned
* the no button has every been clicked). The button at this position
* is currently clicked then, in addition, return true.
*
* @param column The location to return the column index of the button
* of interest
* @param row The location to return the row index of the button of
* interest
* @return True if any button in the array is clicked
*/
virtual bool isButtonClicked(int &column, int &row) const;
/**
* Check if this specific button in the array is clicked
*
* @param column The column of the button to check.
* @param row The row of the button to check.
* @return True if this button is clicked
*/
virtual bool isThisButtonClicked(int column, int row) const;
/**
* Control the cursor state.
*
* @param cursorOn True(1), the current cursor position will be highlighted
*/
virtual void cursor(bool cursorOn);
/**
* Return the current cursor position (button indices) and an indication
* if the button at the cursor is currently hightlighted.
*
* @param column The location to return the column index of the button
* of interest
* @param row The location to return the row index of the button of
* interest
* @return True if the cursor is enabled and the button is highlighted
*/
virtual bool getCursorPosition(int &column, int &row) const;
/**
* Set the cursor position (button indices). Note that the cursor
* does not have to be enabled to set the position.
*
* @param column The column index of the button of interest
* @param row The row index of the button of interest
* @return True if the cursor position is valid
*/
virtual bool setCursorPosition(int column, int row);
/**
* Check if this specific button in the array is at the cursor position
* and highlighted.
*
* @param column The column of the button to check.
* @param row The row of the button to check.
* @return True if this button is at the cursor postion and highlighted.
*/
virtual bool isCursorPosition(int column, int row) const;
/**
* Insert the dimensions that this widget wants to have into the rect
* passed in as a parameter. All coordinates are relative to the
* widget's parent.
*
* @param rect Reference to a rect to populate with data.
*/
virtual void getPreferredDimensions(CRect &rect) const;
/**
* Sets the font.
*
* @param font A pointer to the font to use.
*/
virtual void setFont(CNxFont *font);
};
}
#endif // __cplusplus
#endif // __INCLUDE_CBUTTONARRAY_HXX
@@ -0,0 +1,220 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/ccallback.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CCALLBACK_HXX
#define __INCLUDE_CCALLBACK_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxtk.h>
#include "crect.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
class CWidgetControl;
/**
* Callback function proxies. This class receives and dispatches callbacks
* from the NX server. This calls also manages a few lower-level details
* such as keeping track of the reported window handles and window positions
* and sizes.
*
* There are three instances that represent an NX window from the
* perspective of NXWidgets.
*
* - There is one widget control instance per NX window,
* - One CCallback instance per window,
* - One window instance.
*
* There a various kinds of of window instances, but each inherits
* (1) CCallback and dispatches the Windows callbacks and (2) INxWindow
* that describes the common window behavior.
*/
class CCallback
{
private:
struct nx_callback_s m_callbacks; /**< C-callable vtable of callback function pointers */
// Methods in the callback vtable
/**
* Re-Draw Callback. The redraw event is handled by CWidgetControl::redrawEvent.
*
* NOTE: This method runs in the context of the NX callback which may
* either be the context of the owning thread or, in the case of multi-
* user NX, the context of the NX event listener thread.
*
* @param hWindow Handle to a specific NX window.
* @param pRect The rectangle that needs to be re-drawn (in window
* relative coordinates).
* @param bMore true: More re-draw requests will follow.
* @param pvArg User provided argument (see nx_openwindow, nx_requestbg,
* nxtk_openwindow, or nxtk_opentoolbar).
*/
static void redraw(NXHANDLE hWindow, FAR const struct nxgl_rect_s *pRect,
bool bMore, FAR void *pvArg);
/**
* Position Callback. The new positional data is handled by
* CWidgetControl::geometryEvent.
*
* NOTE: This method runs in the context of the NX callback which may
* either be the context of the owning thread or, in the case of multi-
* user NX, the context of the NX event listener thread.
*
* @param hWindow Handle to a specific NX window.
* @param pSize The size of the window.
* @param pPos The position of the upper left hand corner of the window on
* the overall display.
* @param pBounds The bounding rectangle that describes the entire display.
* @param pvArg User provided argument (see nx_openwindow, nx_requestbg,
* nxtk_openwindow, or nxtk_opentoolbar).
*/
static void position(NXHANDLE hWindow, FAR const struct nxgl_size_s *pSize,
FAR const struct nxgl_point_s *pPos,
FAR const struct nxgl_rect_s *pBounds,
FAR void *pvArg);
/**
* New mouse data is available for the window. The new mouse
* data is handled by CWidgetControl::newMouseEvent.
*
* NOTE: This method runs in the context of the NX callback which may
* either be the context of the NX event listener thread (if multi-
* user NX), or possibly in the connects of device driver or even a
* device driver interrupt.
*
* The GUI thread is probably sleeping a semaphore, waiting to be
* awakened by a mouse or keyboard event.
*
* @param hWindow Handle to a specific NX window.
* @param pPos The (x,y) position of the mouse.
* @param buttons See NX_MOUSE_* definitions.
* @param pvArg User provided argument (see nx_openwindow, nx_requestbg,
* nxtk_openwindow, or nxtk_opentoolbar).
*/
#ifdef CONFIG_NX_MOUSE
static void newMouseEvent(NXHANDLE hWindow, FAR const struct nxgl_point_s *pPos,
uint8_t buttons, FAR void *pvArg);
#endif /* CONFIG_NX_MOUSE */
/**
* New keyboard/keypad data is available for the window. The new
* keyboard data is handled by CWidgetControl::newKeyboardEvent.
*
* NOTE: This method runs in the context of the NX callback which may
* either be the context of the NX event listener thread (if multi-
* user NX), or possibly in the connects of device driver or even a
* device driver interrupt.
*
* The GUI thread is probably sleeping a semaphore, waiting to be
* awakened by a mouse or keyboard event.
*
* @param hWindow Handle to a specific NX window.
* @param nCh The number of characters that are available in pStr[].
* @param pStr The array of characters.
* @param pvArg User provided argument (see nx_openwindow, nx_requestbg,
* nxtk_openwindow, or nxtk_opentoolbar).
*/
#ifdef CONFIG_NX_KBD
static void newKeyboardEvent(NXHANDLE hWindow, uint8_t nCh, FAR const uint8_t *pStr,
FAR void *pvArg);
#endif // CONFIG_NX_KBD
public:
/**
* Constructor.
*
* @param pWidgetControl Control object associated with this window
*/
CCallback(CWidgetControl *pWidgetControl);
/**
* Destructor.
*/
inline ~CCallback(void) {}
/**
* Get the callback vtable. This is neeed only by the window
* instance that inherits this class. The window instance needs the
* C-callable vtable in order to create the NX window. Once the
* window is created, this class will begin to receive callbacks via
* the C-callable vtable methods.
*
* @return This method returns the C-callable vtable needed for
* NX window creation.
*/
inline FAR struct nx_callback_s *getCallbackVTable(void)
{
return &m_callbacks;
}
};
}
#endif // __cplusplus
#endif // __INCLUDE_CCALLBACK_HXX
@@ -0,0 +1,210 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/ccheckbox.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in all NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CCHECKBOX_HXX
#define __INCLUDE_CCHECKBOX_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "cbutton.hxx"
#include "cwidgetstyle.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
class CWidgetControl;
/**
* Class representing a checkbox. Like radio buttons, checkboxes
* are tri-state - off, on and "mu". The mu state cannot be enabled by
* a user - it can only be set by the developer.
*/
class CCheckBox : public CButton
{
public:
/**
* Enum listing all possible checkbox states.
*/
enum CheckBoxState
{
CHECK_BOX_STATE_OFF = 0, /**< Checkbox is unticked */
CHECK_BOX_STATE_ON = 1, /**< Checkbox is ticked */
CHECK_BOX_STATE_MU = 2 /**< Checkbox is in the third state */
};
protected:
CheckBoxState m_state; /**< The state of the checkbox */
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawContents(CGraphicsPort *port);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawBorder(CGraphicsPort *port);
/**
* Toggles the state of the checkbox.
*
* @param x The x coordinate of the click.
* @param y The y coordinate of the click.
*/
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
/**
* Copy constructor is protected to prevent usage.
*/
inline CCheckBox(const CCheckBox &checkBox) : CButton(checkBox) { }
public:
/**
* Constructor.
*
* @param pWidgetControl The widget control for the display.
* @param x The x coordinate of the checkbox, relative to its parent.
* @param y The y coordinate of the checkbox, relative to its parent.
* @param width The width of the checkbox.
* @param height The height of the checkbox.
* @param style The style that the widget should use. If this is not
* specified, the widget will use the values stored in the global
* g_defaultWidgetStyle object. The widget will copy the properties of
* the style into its own internal style object.
*/
CCheckBox(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height,
CWidgetStyle *style = (CWidgetStyle *)NULL);
/**
* Destructor.
*/
virtual inline ~CCheckBox(void) { }
/**
* Get the current state of the checkbox.
*
* @return The state of the checkbox.
*/
virtual inline const CheckBoxState getState(void) const
{
return m_state;
}
/**
* Set the state of the checkbox.
*
* @param state The new checkbox state.
*/
virtual void setState(CheckBoxState state);
};
}
#endif // __cplusplus
#endif // __INCLUDE_CCHECKBOX_HXX
@@ -0,0 +1,356 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/ccyclebutton.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in all NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CCYLEBUTTON_HXX
#define __INCLUDE_CCYLEBUTTON_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "cbutton.hxx"
#include "ilistdataeventhandler.hxx"
#include "clistdata.hxx"
#include "clistdataitem.hxx"
#include "cwidgetstyle.hxx"
#include "cnxstring.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Forward references
*/
class CWidgetControl;
/**
* Cycle button widget. Displays text within the button. Clicking it cycles
* through its available options.
*/
class CCycleButton : public CButton, public IListDataEventHandler
{
protected:
CListData m_options; /**< Option storage. */
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawContents(CGraphicsPort *port);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawBorder(CGraphicsPort *port);
/**
* Draws the outline of the button.
*
* @param port Graphics port to draw to.
*/
virtual void drawOutline(CGraphicsPort *port);
/**
* Selects the next option in the list and redraws the button.
*
* @param x The x coordinate of the mouse.
* @param y The y coordinate of the mouse.
*/
virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y);
/**
* Redraws the button.
*
* @param x The x coordinate of the mouse.
* @param y The y coordinate of the mouse.
*/
virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y);
/**
* Prevents the CButton onResize() method from recalculating the text
* positions by overriding it.
*
* @param width The new width.
* @param height The new height.
*/
virtual inline void onResize(nxgl_coord_t width, nxgl_coord_t height) { }
/**
* Override method in Label class to prevent recalculation of text positions.
*/
virtual inline void calculateTextPosition(void) { }
/**
* Destructor.
*/
virtual ~CCycleButton(void) { }
/**
* Copy constructor is protected to prevent usage.
*/
inline CCycleButton(const CCycleButton &cycleButton) : CButton(cycleButton) { }
public:
/**
* Constructor for cycle buttons.
*
* @param pWidgetControl The widget control for the display.
* @param x The x coordinate of the button, relative to its parent.
* @param y The y coordinate of the button, relative to its parent.
* @param width The width of the button.
* @param height The height of the button.
* @param style The style that the button should use. If this is not
* specified, the button will use the values stored in the global
* g_defaultWidgetStyle object. The button will copy the properties of
* the style into its own internal style object.
*/
CCycleButton(CWidgetControl *pWidgetControl,
nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height,
CWidgetStyle *style = (CWidgetStyle *)NULL);
/**
* Add a new option to the widget.
*
* @param text The text of the option.
* @param value The value of the option.
*/
void addOption(const CNxString &text, const uint32_t value);
/**
* Remove an option from the widget by its index.
*
* @param index The index of the option to remove.
*/
virtual void removeOption(const int index);
/**
* Remove all options from the widget.
*/
virtual void removeAllOptions(void);
/**
* Select an option by its index.
* Redraws the widget and raises a value changed event.
*
* @param index The index of the option to select.
*/
virtual void selectOption(const int index);
/**
* Get the selected index. Returns -1 if nothing is selected. If more than one
* option is selected, the index of the first selected option is returned.
*
* @return The selected index.
*/
virtual const int getSelectedIndex(void) const;
/**
* Sets the selected index. Specify -1 to select nothing. Resets any
* other selected options to deselected.
* Redraws the widget and raises a value changed event.
*
* @param index The selected index.
*/
virtual void setSelectedIndex(const int index);
/**
* Get the selected option. Returns NULL if nothing is selected.
*
* @return The selected option.
*/
virtual const CListDataItem *getSelectedOption(void) const;
/**
* Get the value of the current option.
*
* @return Value of the current option.
*/
inline const uint32_t getValue(void) const
{
return getSelectedOption()->getValue();
}
/**
* Get the specified option.
*
* @return The specified option.
*/
virtual inline const CListDataItem *getOption(const int index)
{
return m_options.getItem(index);
}
/**
* Sort the options alphabetically by the text of the options.
*/
virtual void sort(void);
/**
* Get the total number of options.
*
* @return The number of options.
*/
virtual inline const int getOptionCount(void) const
{
return m_options.getItemCount();
}
/**
* Sets whether or not items added to the list are automatically sorted
* on insert or not.
*
* @param sortInsertedItems True to enable sort on insertion.
*/
virtual inline void setSortInsertedItems(const bool sortInsertedItems)
{
m_options.setSortInsertedItems(sortInsertedItems);
}
/**
* Handles list data changed events.
*
* @param e Event arguments.
*/
virtual void handleListDataChangedEvent(const CListDataEventArgs &e);
/**
* Handles list selection changed events.
*
* @param e Event arguments.
*/
virtual void handleListDataSelectionChangedEvent(const CListDataEventArgs &e);
/**
* Insert the dimensions that this widget wants to have into the rect
* passed in as a parameter. All coordinates are relative to the widget's
* parent. Value is based on the length of the largest string in the
* set of options.
*
* @param rect Reference to a rect to populate with data.
*/
virtual void getPreferredDimensions(CRect &rect) const;
};
}
#endif // __cplusplus
#endif // __INCLUDE_CCYLEBUTTON_HXX
@@ -0,0 +1,229 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/cbutton.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in all NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CGLYPHBUTTON_HXX
#define __INCLUDE_CGLYPHBUTTON_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "cnxwidget.hxx"
#include "cwidgetstyle.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Forward references
*/
class CWidgetControl;
struct SBitmap;
/**
* Class representing a button that will display a glyph.
* Class representing a clickable button that contains a bitmap image
* instead of text. Displays two bitmaps, one when the button is clicked,
* and one when it isn't. The bitmaps should be the same size.
*/
class CGlyphButton : public CNxWidget
{
protected:
FAR const struct SBitmap *m_bitmapNormal; /**< Bitmap when button is not clicked */
FAR const struct SBitmap *m_bitmapClicked; /**< Bitmap when button is clicked */
nxgl_coord_t m_bitmapX; /**< X coordinate of the bitmaps */
nxgl_coord_t m_bitmapY; /**< Y coordinate of the bitmaps */
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawContents(CGraphicsPort *port);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawBorder(CGraphicsPort *port);
/**
*
* @param port Graphics port to draw to.
*/
virtual void drawOutline(CGraphicsPort *port);
/**
* Redraws the button.
*
* @param x The x coordinate of the click.
* @param y The y coordinate of the click.
*/
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
/**
* Raises an action event and redraws the button.
*
* @param x The x coordinate of the mouse.
* @param y The y coordinate of the mouse.
*/
virtual void onRelease(nxgl_coord_t x, nxgl_coord_t y);
/**
* Redraws the button.
*
* @param x The x coordinate of the mouse.
* @param y The y coordinate of the mouse.
*/
virtual void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y);
/**
* Copy constructor is protected to prevent usage.
*/
inline CGlyphButton(const CGlyphButton &button) : CNxWidget(button) { }
public:
/**
* Constructor.
*
* @param pWidgetControl The widget control for the display.
* @param x The x coordinate of the button.
* @param y The y coordinate of the button.
* @param width The width of the button.
* @param height The height of the button.
* @param normalGlyph Glyph to display when unclicked.
* @param clickedGlyph Glyph to display when clicked.
* @param bitmapX The x coordinate at which the bitmaps will be drawn.
* @param bitmapY The y coordinate at which the bitmaps will be drawn.
* @param style The style that the button should use. If this is not
* specified, the button will use the values stored in the global
* g_defaultWidgetStyle object. The button will copy the properties of
* the style into its own internal style object.
*/
CGlyphButton(CWidgetControl *pWidgetControl,
nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height,
nxgl_coord_t bitmapX, nxgl_coord_t bitmapY,
FAR const struct SBitmap *normalGlyph,
FAR const struct SBitmap *clickedGlyph,
CWidgetStyle *style = (CWidgetStyle *)NULL);
/**
* Destructor.
*/
virtual inline ~CGlyphButton(void) { }
/**
* Insert the dimensions that this widget wants to have into the rect
* passed in as a parameter. All coordinates are relative to the widget's
* parent.
* @param rect Reference to a rect to populate with data.
*/
virtual void getPreferredDimensions(CRect &rect) const;
};
}
#endif // __cplusplus
#endif // __INCLUDE_CGLYPHBUTTON_HXX
@@ -0,0 +1,411 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/cgraphicsport.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in all NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CGRAPHICSPORT_HXX
#define __INCLUDE_CGRAPHICSPORT_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include "inxwindow.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
class CNxFont;
class CNxString;
class CRect;
struct SBitmap;
/**
* CGraphicsPort is the interface between a NXwidget and NX layer.
*/
class CGraphicsPort
{
private:
INxWindow *m_pNxWnd; /**< NX window interface. */
public:
/**
* Constructor.
*
* @param pNxWnd An instance of the underlying window type.
*/
CGraphicsPort(INxWindow *pNxWnd);
/**
* Destructor.
*/
virtual ~CGraphicsPort();
/**
* Return the absolute x coordinate of the upper left hand corner of the
* underlying window.
*
* @return The x coordinate of the window.
*/
const nxgl_coord_t getX(void) const;
/**
* Return the absolute y coordinate of the upper left hand corner of the
* underlying window.
*
* @return The y coordinate of the window.
*/
const nxgl_coord_t getY(void) const;
/**
* Draw a pixel into the window.
*
* @param x The window-relative x coordinate of the pixel.
* @param y The window-relative y coordinate of the pixel.
* @param color The color of the pixel.
*/
void drawPixel(nxgl_coord_t x, nxgl_coord_t y, nxgl_mxpixel_t color);
/**
* Draw a horizontal line of the specified start position, width, and
* color.
*
* @param x The x coordinate of the line.
* @param y The y coordinate of the top-most end of the line.
* @param width The width of the line in pixels.
* @param color The color of the line.
*/
void drawHorizLine(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width,
nxgl_mxpixel_t color);
/**
* Draw a vertical line of the specified start position, width, and
* color.
*
* @param x The x coordinate of the left-most end of the line.
* @param y The y coordinate of the line.
* @param height The height of the line in rows.
* @param color The color of the line.
*/
void drawVertLine(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t height,
nxgl_mxpixel_t color);
/**
* Draw a line of a fixed color in the window.
*
* @param x1 The x coordinate of the start point of the line.
* @param y1 The y coordinate of the start point of the line.
* @param x2 The x coordinate of the end point of the line.
* @param y2 The y coordinate of the end point of the line.
* @param color The color of the line.
*/
void drawLine(nxgl_coord_t x1, nxgl_coord_t y1,
nxgl_coord_t x2, nxgl_coord_t y2,
nxgl_mxpixel_t color);
/**
* Draw a filled rectangle of the specified start position, end position,
* width, and color.
*
* @param x The window-relative x coordinate of the rectangle.
* @param y The window-relative y coordinate of the rectangle.
* @param width The width of the rectangle in pixels.
* @param height The height of the rectangle in rows.
* @param color The color of the rectangle.
*/
void drawFilledRect(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width,
nxgl_coord_t height, nxgl_mxpixel_t color);
/**
* Draw an unfilled rectangle to the window
*
* @param x The window-relative x coordinate of the rectangle.
* @param y The window-relative y coordinate of the rectangle.
* @param width The width of the rectangle.
* @param height The height of the rectangle.
* @param color The color of the rectangle .
*/
void drawRect(nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width,
nxgl_coord_t height, nxgl_mxpixel_t color);
/**
* Draw a bevelled rectangle to the window.
*
* @param x The x coordinate of the rectangle.
* @param y The y coordinate of the rectangle.
* @param width The width of the rectangle.
* @param height The height of the rectangle.
* @param shineColor The color of the top/left sides.
* @param shadowColor The color of the bottom/right sides.
*/
void drawBevelledRect(nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height,
nxgl_mxpixel_t shineColor,
nxgl_mxpixel_t shadowColor);
/**
* Draw a filled circle at the specified position, size, and color.
*
* @param center The window-relative coordinates of the circle center.
* @param radius The radius of the rectangle in pixels.
* @param color The color of the rectangle.
*/
inline void drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius,
nxgl_mxpixel_t color)
{
(void)m_pNxWnd->drawFilledCircle(center, radius, color);
}
/**
* Draw a string to the window.
* @param pos The window-relative x/y coordinate of the string.
* @param bound The window-relative bounds of the string.
* @param font The font to draw with.
* @param string The string to output.
*/
void drawText(struct nxgl_point_s *pos, CRect *bound, CNxFont *font,
const CNxString &string);
/**
* Draw a particular length of a string to the window in a secific color.
* @param pos The window-relative x/y coordinate of the string.
* @param bound The window-relative bounds of the string.
* @param font The font to draw with.
* @param string The string to output.
* @param startIndex The start index within the string from which
* drawing will commence.
* @param length The number of characters to draw.
* @param color The color of the string.
*/
void drawText(struct nxgl_point_s *pos, CRect *bound, CNxFont *font,
const CNxString &string, int startIndex, int length,
nxgl_mxpixel_t color);
/**
* Draw a portion of a string to the window.
* @param pos The window-relative x/y coordinate of the string.
* @param bound The window-relative bounds of the string.
* @param font The font to draw with.
* @param string The string to output.
* @param startIndex The start index within the string from which
* drawing will commence.
* @param length The number of characters to draw.
*/
void drawText(struct nxgl_point_s *pos, CRect *bound, CNxFont *font,
const CNxString &string, int startIndex, int length);
/**
* Draw an opaque bitmap to the window.
*
* @param x The window-relative x coordinate to draw the bitmap to.
* @param y The window-relative y coordinate to draw the bitmap to.
* @param width The width of the bitmap to draw.
* @param height The height of the bitmap to draw.
* @param bitmap Pointer to the bitmap to draw.
* @param bitmapX The window-relative x coordinate within the supplied
* bitmap to use as the origin.
* @param bitmapY The window-relative y coordinate within the supplied
* bitmap to use as the origin.
*/
void drawBitmap(nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height,
const struct SBitmap *bitmap, int bitmapX, int bitmapY);
/**
* Draw a bitmap to the window, using the supplied transparent
* color as an invisible color.
*
* @param x The window-relative x coordinate to draw the bitmap to.
* @param y The window-relative y coordinate to draw the bitmap to.
* @param width The width of the bitmap to draw.
* @param height The height of the bitmap to draw.
* @param bitmap Pointer to the bitmap to draw.
* @param bitmapX The window-relative x coordinate within the supplied bitmap to use as
* the origin.
* @param bitmapY The window-relative y coordinate within the supplied bitmap to use as
* the origin.
* @param transparentColor The transparent color used in the bitmap.
*/
void drawBitmap(nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height,
const struct SBitmap *bitmap, int bitmapX, int bitmapY,
nxgl_mxpixel_t transparentColor);
/**
* Draw a bitmap to the port in greyscale.
*
* @param x The window-relative x coordinate to draw the bitmap to.
* @param y The window-relative y coordinate to draw the bitmap to.
* @param width The width of the bitmap to draw.
* @param height The height of the bitmap to draw.
* @param bitmap Pointer to the bitmap to draw.
* @param bitmapX The window-relative x coordinate within the supplied bitmap to use as
* the origin.
* @param bitmapY The window-relative y coordinate within the supplied bitmap to use as
* the origin.
*/
void drawBitmapGreyScale(nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height,
const struct SBitmap *bitmap, int bitmapX, int bitmapY);
/**
* Copy a rectangular region from the source coordinateinates to the
* destination coordinateinates.
*
* @param sourceX Source x coordinate.
* @param sourceY Source y coordinate.
* @param destX Destination x coordinate.
* @param destY Destination y coordinate.
* @param width Width of the rectangle to copy.
* @param height Height of the rectangle to copy.
*/
void copy(nxgl_coord_t sourceX, nxgl_coord_t sourceY,
nxgl_coord_t destX, nxgl_coord_t destY,
nxgl_coord_t width, nxgl_coord_t height);
/**
* Move a region by a specified distance in two dimensions.
*
* @param x X coordinate of the source area to move.
* @param y Y coordinate of the source area to move.
* @param deltaX Horizontal distance to move.
* @param deltaY Vertical distance to move.
* @param width Width of the area to move.
* @param height Height of the area to move.
*/
void move(nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t deltaX, nxgl_coord_t deltaY,
nxgl_coord_t width, nxgl_coord_t height);
/**
* Convert the region to greyscale.
*
* @param x X coordinate of the region to change.
* @param y Y coordinate of the region to change.
* @param width Width of the region to change.
* @param height Height of the region to change.
*/
void greyScale(nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height);
/**
* Invert colors in a region. NOTE: This allocates an in-memory
* buffer the size of one row in graphic memory. So it may only be
* useful for inverting small regions and its only current use of for
* the inverted cursor text.
*
* @param x X coordinate of the region to change.
* @param y Y coordinate of the region to change.
* @param width Width of the region to change.
* @param height Height of the region to change.
*/
void invert(nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height);
};
}
#endif // __cplusplus
#endif // __INCLUDE_CGRAPHICSPORT_HXX
+199
View File
@@ -0,0 +1,199 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/cimage.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in all NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CIMAGE_HXX
#define __INCLUDE_CIMAGE_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "cnxwidget.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Forward references
*/
class CWidgetControl;
class IBitmap;
/**
* Simple image widget for present static images in the widget framework.
*/
class CImage : public CNxWidget
{
protected:
FAR IBitmap *m_bitmap; /**< Source bitmap image */
struct nxgl_point_s m_origin; /**< Origin for offset image display position */
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawContents(CGraphicsPort *port);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawBorder(CGraphicsPort *port);
/**
* Copy constructor is protected to prevent usage.
*/
inline CImage(const CImage &label) : CNxWidget(label) { };
public:
/**
* Constructor for a label containing a string.
*
* @param pWidgetControl The controlling widget for the display
* @param x The x coordinate of the image box, relative to its parent.
* @param y The y coordinate of the image box, relative to its parent.
* @param width The width of the textbox.
* @param height The height of the textbox.
* @param bitmap The source bitmap image.
* @param style The style that the widget should use. If this is not
* specified, the button will use the global default widget
* style.
*/
CImage(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height, FAR IBitmap *bitmap,
CWidgetStyle *style = (CWidgetStyle *)NULL);
/**
* Destructor.
*/
virtual inline ~CImage() { }
/**
* Insert the dimensions that this widget wants to have into the rect
* passed in as a parameter. All coordinates are relative to the
* widget's parent.
*
* @param rect Reference to a rect to populate with data.
*/
void getPreferredDimensions(CRect &rect) const;
/**
* Set the horizontal position of the bitmap. Zero is the left edge
* of the bitmap and values >0 will move the bit map to the right.
* This method is useful for horizontal scrolling a large bitmap
* within a smaller window
*/
void setImageLeft(nxgl_coord_t column);
/**
* Set the vertical position of the bitmap. Zero is the top edge
* of the bitmap and values >0 will move the bit map down.
* This method is useful for vertical scrolling a large bitmap
* within a smaller window
*/
void setImageTop(nxgl_coord_t row);
};
}
#endif // __cplusplus
#endif // __INCLUDE_CIMAGE_HXX
+156
View File
@@ -0,0 +1,156 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/ckeypad.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CKEYPAD_HXX
#define __INCLUDE_CKEYPAD_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "cbuttonarray.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Forward references
*/
class CWidgetControl;
class CWidgetStyle;
/**
* Extends the CButtonArray class to support a alphanumeric keypad.
*/
class CKeypad : public CButtonArray
{
protected:
NXHANDLE m_hNxServer; /**< NX server handle */
bool m_numeric; /**< True: Numeric keypad, False: Alpha */
/**
* Configure the keypad for the currenly selected display mode.
*/
void configureKeypadMode(void);
/**
* Copy constructor is protected to prevent usage.
*/
inline CKeypad(const CKeypad &keypad) : CButtonArray(keypad) { }
public:
/**
* Constructor for buttons that display a string.
*
* @param pWidgetControl The widget control for the display.
* @param hNxServer The NX server that will receive the keyboard input
* @param x The x coordinate of the keypad, relative to its parent.
* @param y The y coordinate of the keypad, relative to its parent.
* @param width The width of the keypad
* @param height The height of the keypad
* @param style The style that the button should use. If this is not
* specified, the button will use the global default widget
* style.
*/
CKeypad(CWidgetControl *pWidgetControl, NXHANDLE hNxServer,
nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height,
CWidgetStyle *style = (CWidgetStyle *)NULL);
/**
* CKeypad Destructor.
*/
inline ~CKeypad(void) {}
/**
* Returns the current keypad display mode
*
* @return True: keypad is in numeric mode. False: alphanumeric.
*/
inline const bool isNumericKeypad(void) const
{
return m_numeric;
}
/**
* Returns the current keypad display mode
*
* @param mode True: put keypad in numeric mode. False: in alphanumeric.
*/
inline void setKeypadMode(bool numeric)
{
m_numeric = numeric;
configureKeypadMode();
}
/**
* Catch button clicks.
*
* @param x The x coordinate of the click.
* @param y The y coordinate of the click.
*/
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
};
}
#endif // __cplusplus
#endif // __INCLUDE_CKEYPAD_HXX
+355
View File
@@ -0,0 +1,355 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/clabel.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in all NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CLABEL_HXX
#define __INCLUDE_CLABEL_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "cnxwidget.hxx"
#include "cwidgetstyle.hxx"
#include "cnxstring.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Forward references
*/
class CWidgetControl;
class CRect;
/**
* Single-line label widget. Can align text both vertically and
* horizontally in different ways.
*/
class CLabel : public CNxWidget
{
public:
/**
* Enum of horizontal alignment options.
*/
enum TextAlignmentHoriz
{
TEXT_ALIGNMENT_HORIZ_CENTER = 0, /**< Centre the text */
TEXT_ALIGNMENT_HORIZ_LEFT = 1, /**< Align left */
TEXT_ALIGNMENT_HORIZ_RIGHT = 2 /**< Align right */
};
/**
* Enum of vertical alignment options.
*/
enum TextAlignmentVert
{
TEXT_ALIGNMENT_VERT_CENTER = 0, /**< Align to centre of textbox */
TEXT_ALIGNMENT_VERT_TOP = 1, /**< Align to top of textbox */
TEXT_ALIGNMENT_VERT_BOTTOM = 2 /**< Align to bottom of textbox */
};
protected:
CNxString m_text; /**< Text that the textbox will display */
struct nxgl_point_s m_align; /**< X/Y offset for text alignment */
TextAlignmentHoriz m_hAlignment; /**< Horizontal alignment of the text */
TextAlignmentVert m_vAlignment; /**< Vertical alignment of the text */
bool m_textChange; /**< Redraw is due to a text change */
bool m_highlighted; /**< Label is highlighted */
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
* @param port The CGraphicsPort to draw to.
*
* @see redraw()
*/
virtual void drawContents(CGraphicsPort *port);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawBorder(CGraphicsPort *port);
/**
* Resize the widget to the new dimensions.
*
* @param width The new width.
* @param height The new height.
*/
virtual void onResize(nxgl_coord_t width, nxgl_coord_t height);
/**
* Calculate the vertical position of the string based on the font
*
* height and the alignment options.
*/
virtual void calculateTextPositionVertical(void);
/**
* Calculate the position of the string based on its length and the
* alignment options.
*/
virtual void calculateTextPositionHorizontal(void);
/**
* Updates the GUI after the text has changed.
*/
virtual void onTextChange(void);
/**
* Copy constructor is protected to prevent usage.
*/
inline CLabel(const CLabel &label) : CNxWidget(label) { };
public:
/**
* Constructor for a label containing a string.
*
* @param pWidgetControl The controlling widget for the display
* @param x The x coordinate of the text box, relative to its parent.
* @param y The y coordinate of the text box, relative to its parent.
* @param width The width of the textbox.
* @param height The height of the textbox.
* @param text Pointer to a string to display in the textbox.
* @param style The style that the button should use. If this is not
* specified, the button will use the global default widget
* style.
*/
CLabel(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height, const CNxString &text,
CWidgetStyle *style = (CWidgetStyle *)NULL);
/**
* Destructor.
*/
virtual inline ~CLabel() { }
/**
* Set the horizontal alignment of text within the label.
*
* @param alignment The horizontal position of the text.
*/
virtual void setTextAlignmentHoriz(TextAlignmentHoriz alignment);
/**
* Set the vertical alignment of text within the label.
*
* @param alignment The vertical position of the text.
*/
virtual void setTextAlignmentVert(TextAlignmentVert alignment);
/**
* Set the horizontal alignment of text within the label.
*
* @param alignment The horizontal position of the text.
*/
inline const TextAlignmentHoriz getTextAlignmentHoriz(void) const
{
return m_hAlignment;
}
/**
* Set the vertical alignment of text within the label.
*
* @param alignment The vertical position of the text.
*/
inline const TextAlignmentVert getTextAlignmentVert(void) const
{
return m_vAlignment;
}
/**
* Returns the string shown in the label.
*
* @return The label's text.
*/
virtual inline const CNxString &getText(void) const
{
return m_text;
}
/**
* Set the text displayed in the label.
*
* @param text String to display.
*/
virtual void setText(const CNxString &text);
/**
* Append new text to the end of the current text displayed in the
* label.
*
* @param text String to append.
*/
virtual void appendText(const CNxString &text);
/**
* Insert text at the specified index.
*
* @param text The text to insert.
* @param index Index at which to insert the text.
*/
virtual void insertText(const CNxString &text, const int index);
/**
* Control the highlight state.
*
* @param highlightOn True(1), the label will be highlighted
*/
virtual void highlight(bool highlightOn);
/**
* Return the current highlight state.
*
* @return True if the label is highlighted
*/
virtual inline bool isHighlighted(void) const
{
return m_highlighted;
}
/**
* Insert the dimensions that this widget wants to have into the rect
* passed in as a parameter. All coordinates are relative to the
* widget's parent.
*
* @param rect Reference to a rect to populate with data.
*/
virtual void getPreferredDimensions(CRect &rect) const;
/**
* Sets the font.
*
* @param font A pointer to the font to use.
*/
virtual void setFont(CNxFont *font);
/**
* Is the redraw due to a text-only change?
*
* @return True if the redraw was caused by a text change
*/
virtual inline bool isTextChange(void) const
{
return m_textChange;
}
};
}
#endif // __cplusplus
#endif // __INCLUDE_CLABEL_HXX
@@ -0,0 +1,173 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/clatchbutton.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in all NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CLATCHBUTTON_HXX
#define __INCLUDE_CLATCHBUTTON_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "cstickybutton.hxx"
#include "cwidgetstyle.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
class CWidgetControl;
/**
* CButton that latches down when clicked and unlatches when clicked again.
*/
class CLatchButton : public CStickyButton
{
protected:
/**
* Handles button click events
*
* @param x The x coordinate of the click.
* @param y The y coordinate of the click.
*/
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
/**
* Redraws the button.
*
* @param x The x coordinate of the mouse.
* @param y The y coordinate of the mouse.
*/
/**
* Copy constructor is protected to prevent usage.
*/
inline CLatchButton(const CLatchButton &button) : CStickyButton(button) { }
public:
/**
* Constructor for buttons that display a string.
*
* @param pWidgetControl The controlling widget for the display.
* @param x The x coordinate of the button, relative to its parent.
* @param y The y coordinate of the button, relative to its parent.
* @param width The width of the button.
* @param height The height of the button.
* @param text The text for the button to display.
* @param style The style that the button should use. If this is not
* specified, the button will use the global default widget
* style.
*/
CLatchButton(CWidgetControl *pWidgetControl,
nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height,
const CNxString &text,
CWidgetStyle *style = (CWidgetStyle *)NULL);
/**
* Destructor.
*/
virtual inline ~CLatchButton(void) { }
/**
* Check if the button is latched
*
* @return True if the button is latched
*/
inline const bool isLatched(void) const
{
return isStuckDown();
}
};
}
#endif // __cplusplus
#endif // __INCLUDE_CLATCHBUTTON_HXX
@@ -0,0 +1,170 @@
/****************************************************************************
* include/clatchbuttonarray.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CLATCHBUTTONARRAY_HXX
#define __INCLUDE_CLATCHBUTTONARRAY_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "cstickybuttonarray.hxx"
#include "cwidgetstyle.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Forward references
*/
class CWidgetControl;
class CNxString;
/**
* Manages a two-dimensional array of buttons as one widget. When a button
* is clicked is latches (i.e., it stays pushed after the press is released.
* The behavior is then like radio buttons: Pressing each each button in
* the array unlatches the previous button and latches the new button.
*
* Unlike CLatchButton, pressing the same button more than once has no
* effect.
*/
class CLatchButtonArray : public CStickyButtonArray
{
protected:
/**
* Handles button click events
*
* @param x The x coordinate of the click.
* @param y The y coordinate of the click.
*/
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
/**
* Redraws the button.
*
* @param x The x coordinate of the mouse.
* @param y The y coordinate of the mouse.
*/
/**
* Copy constructor is protected to prevent usage.
*/
inline CLatchButtonArray(const CLatchButtonArray &button) : CStickyButtonArray(button) { }
public:
/**
* Constructor for an array of latch buttons.
*
* @param pWidgetControl The widget control for the display.
* @param x The x coordinate of the button array, relative to its parent.
* @param y The y coordinate of the button array, relative to its parent.
* @param buttonColumns The number of buttons in one row of the button array
* @param buttonRows The number of buttons in one column of the button array
* @param buttonWidth The width of one button
* @param buttonHeight The height of one button
* @param style The style that the button should use. If this is not
* specified, the button will use the global default widget
* style.
*/
CLatchButtonArray(CWidgetControl *pWidgetControl,
nxgl_coord_t x, nxgl_coord_t y,
uint8_t buttonColumns, uint8_t buttonRows,
nxgl_coord_t buttonWidth, nxgl_coord_t buttonHeight,
CWidgetStyle *style = (CWidgetStyle *)NULL);
/**
* CLatchButtonArray Destructor.
*/
virtual inline ~CLatchButtonArray(void) { }
/**
* Return the position of the last latched button (0,0 will be returned
* the no button has every been latched). The button at this position
* is currently latched then, in addition, return true.
*
* @param column The location to return the column index of the button
* of interest
* @param row The location to return the row index of the button of
* interest
* @return True if a button in the array is latched
*/
inline const bool isAnyButtonLatched(int &column, int &row) const
{
return isAnyButtonStuckDown(column, row);
}
/**
* Check if this specific button in the array is latched
*
* @param column The column of the button to check.
* @param row The row of the button to check.
* @return True if this button is clicked
*/
inline const bool isThisButtonLatched(int column, int row) const
{
return isThisButtonStuckDown(column, row);
}
};
}
#endif // __cplusplus
#endif // __INCLUDE_CLATCHBUTTONARRAY_HXX
+431
View File
@@ -0,0 +1,431 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/clistbox.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in all NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CLISTBOX_HXX
#define __INCLUDE_CLISTBOX_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "nxconfig.hxx"
#include "cscrollingpanel.hxx"
#include "ilistdataeventhandler.hxx"
#include "clistdata.hxx"
#include "clistboxdataitem.hxx"
#include "cwidgetstyle.hxx"
#include "ilistbox.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Class providing a scrollable list of options. The CListBox can be set
* up to only allow one selection or multiple selections. Processes
* double-clicks and raises double-click events, so that a double-click
* on an option can be made to automatically select and close a window/etc.
* The options themselves have user-definable text and background colors
* for their selected and unselected states.
*/
class CListBox : public IListBox, public CScrollingPanel,
public IListDataEventHandler
{
protected:
CListData m_options; /**< Option storage. */
uint8_t m_optionPadding; /**< Padding between options. */
int m_lastSelectedIndex; /**< Index of the last option selected. */
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawContents(CGraphicsPort *port);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawBorder(CGraphicsPort *port);
/**
* Determines which item was clicked and selects or deselects it as
* appropriate. Also starts the dragging system.
*
* @param x The x coordinate of the click.
* @param y The y coordinate of the click.
*/
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
/**
* Selects the clicked item and deselects all others.
*
* @param x The x coordinate of the click.
* @param y The y coordinate of the click.
*/
virtual void onDoubleClick(nxgl_coord_t x, nxgl_coord_t y);
/**
* Select or deselect an option by its index. Does not deselect any other
* selected options. Set index to -1 to select nothing. Redraws the widget
* and raises a value changed event.
*
* @param index The index of the option to select.
* @param selected True to select the option, false to deselect it.
*/
virtual void setOptionSelected(const int index, const bool selected);
/**
* Copy constructor is protected to prevent usage.
*/
inline CListBox(const CListBox &listBox) : CScrollingPanel(listBox) { }
public:
/**
* Constructor.
*
* @param pWidgetControl The controlling widget for the display.
* @param x The x coordinate of the widget.
* @param y The y coordinate of the widget.
* @param width The width of the widget.
* @param height The height of the widget.
* @param style The style that the widget should use. If this is not
* specified, the widget will use the values stored in the global
* g_defaultWidgetStyle object. The widget will copy the properties of
* the style into its own internal style object.
*/
CListBox(CWidgetControl *pWidgetControl,
nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height,
CWidgetStyle *style = (CWidgetStyle *)NULL);
/**
* Destructor.
*/
virtual ~CListBox(void);
/**
* Add a new option to the widget using default colors.
*
* @param text Text to show in the option.
* @param value The value of the option.
*/
virtual void addOption(const CNxString &text, const uint32_t value);
/**
* Add an option to the widget.
*
* @param option The option to add.
*/
virtual void addOption(CListBoxDataItem *option);
/**
* Remove an option from the widget by its index.
*
* @param index The index of the option to remove.
*/
virtual void removeOption(const int index);
/**
* Remove all options from the widget.
*/
virtual void removeAllOptions(void);
/**
* Add a new option to the widget.
*
* @param text Text to show in the option.
* @param value The value of the option.
* @param normalTextColor Color to draw the text with when not selected.
* @param normalBackColor Color to draw the background with when not selected.
* @param selectedTextColor Color to draw the text with when selected.
* @param selectedBackColor Color to draw the background with when selected.
*/
virtual void addOption(const CNxString &text, const uint32_t value,
const nxwidget_pixel_t normalTextColor,
const nxwidget_pixel_t normalBackColor,
const nxwidget_pixel_t selectedTextColor,
const nxwidget_pixel_t selectedBackColor);
/**
* Select an option by its index.
* Redraws the widget and raises a value changed event.
*
* @param index The index of the option to select.
*/
virtual void selectOption(const int index);
/**
* Select an option by its index.
* Redraws the widget and raises a value changed event.
*
* @param index The index of the option to select.
*/
virtual void deselectOption(const int index);
/**
* Select all options. Does nothing if the listbox does not allow
* multiple selections. Redraws the widget and raises a value changed
* event.
*/
virtual void selectAllOptions(void);
/**
* Deselect all options.
* Redraws the widget and raises a value changed event.
*/
virtual void deselectAllOptions(void);
/**
* Get the selected index. Returns -1 if nothing is selected. If
* more than one option is selected, the index of the first selected
* option is returned.
*
* @return The selected index.
*/
virtual const int getSelectedIndex(void) const;
/**
* Sets the selected index. Specify -1 to select nothing. Resets any
* other selected options to deselected. Redraws the widget and raises
* a value changed event.
*
* @param index The selected index.
*/
virtual void setSelectedIndex(const int index);
/**
* Get the selected option. Returns NULL if nothing is selected.
*
* @return The selected option.
*/
virtual const CListBoxDataItem *getSelectedOption(void) const;
/**
* Sets whether multiple selections are possible or not.
*
* @param allowMultipleSelections True to allow multiple selections.
*/
virtual inline void
setAllowMultipleSelections(const bool allowMultipleSelections)
{
m_options.setAllowMultipleSelections(allowMultipleSelections);
}
/**
* Sets whether multiple selections are possible or not.
*
* @return True if multiple selections are allowed.
*/
virtual inline const bool allowsMultipleSelections(void) const
{
return m_options.allowsMultipleSelections();
}
/**
* Resize the scrolling canvas to encompass all options.
*/
virtual void resizeCanvas(void);
/**
* Get the specified option.
*
* @return The specified option.
*/
virtual inline const CListBoxDataItem *getOption(const int index)
{
return (const CListBoxDataItem *)m_options.getItem(index);
}
/**
* Sort the options alphabetically by the text of the options.
*/
virtual void sort(void);
/**
* Get the total number of options.
*
* @return The number of options.
*/
virtual inline const int getOptionCount(void) const
{
return m_options.getItemCount();
}
/**
* Get the height of a single option.
*
* @return The height of an option.
*/
virtual const nxgl_coord_t getOptionHeight(void) const;
/**
* Sets whether or not items added to the list are automatically sorted on insert or not.
*
* @param sortInsertedItems True to enable sort on insertion.
*/
virtual inline void setSortInsertedItems(const bool sortInsertedItems)
{
m_options.setSortInsertedItems(sortInsertedItems);
}
/**
* Handles list data changed events.
*
* @param e Event arguments.
*/
virtual void handleListDataChangedEvent(const CListDataEventArgs &e);
/**
* Handles list selection changed events.
*
* @param e Event arguments.
*/
virtual void handleListDataSelectionChangedEvent(const CListDataEventArgs &e);
/**
* Insert the dimensions that this widget wants to have into the rect
* passed in as a parameter. All coordinates are relative to the widget's
* parent. Value is based on the length of the largest string in the
* set of options.
*
* @param rect Reference to a rect to populate with data.
*/
virtual void getPreferredDimensions(CRect &rect) const;
/**
* Check if the click is a double-click.
*
* @param x X coordinate of the click.
* @param y Y coordinate of the click.
* @return True if the click is a double-click.
*/
virtual bool isDoubleClick(nxgl_coord_t x, nxgl_coord_t y);
};
}
#endif // __cplusplus
#endif // __INCLUDE_CLISTBOX_HXX
@@ -0,0 +1,180 @@
/****************************************************************************
* include/clistboxdataitem.hxx
* NxWidgets/libnxwidgets/
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in most NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CLISTBOXDATAITEM_HXX
#define __INCLUDE_CLISTBOXDATAITEM_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "clistdataitem.hxx"
#include "cnxstring.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Class representing a data item within a ListBox.
*/
class CListBoxDataItem : public CListDataItem
{
private:
nxwidget_pixel_t m_normalTextColor; /**< Color used for text when not selected. */
nxwidget_pixel_t m_normalBackColor; /**< Color used for background when not selected. */
nxwidget_pixel_t m_selectedTextColor; /**< Color used for text when selected. */
nxwidget_pixel_t m_selectedBackColor; /**< Color used for background when selected. */
public:
/**
* Constructor.
*
* @param text The text to display in the item.
* @param value The value of the item.
* @param normalTextColor Color to draw the text with when not selected.
* @param normalBackColor Color to draw the background with when not selected.
* @param selectedTextColor Color to draw the text with when selected.
* @param selectedBackColor Color to draw the background with when selected.
*/
CListBoxDataItem(const CNxString &text, const uint32_t value,
const nxwidget_pixel_t normalTextColor,
const nxwidget_pixel_t normalBackColor,
const nxwidget_pixel_t selectedTextColor,
const nxwidget_pixel_t selectedBackColor);
/**
* Get the color used for text when the item is unselected.
*
* @return The text color when the item is unselected.
*/
inline nxwidget_pixel_t getNormalTextColor(void) const
{
return m_normalTextColor;
}
/**
* Get the color used for the background when the item is unselected.
*
* @return The background color when the item is unselected.
*/
inline nxwidget_pixel_t getNormalBackColor(void) const
{
return m_normalBackColor;
}
/**
* Get the color used for text when the item is selected.
*
* @return The text color when the item is selected.
*/
inline nxwidget_pixel_t getSelectedTextColor(void) const
{
return m_selectedTextColor;
}
/**
* Get the color used for the background when the item is selected.
*
* @return The background color when the item is selected.
*/
inline nxwidget_pixel_t getSelectedBackColor(void) const
{
return m_selectedBackColor;
}
};
}
#endif // __cplusplus
#endif // __INCLUDE_CLISTBOXDATAITEM_HXX
@@ -0,0 +1,351 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/clistdata.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in most NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CLISTDATA_HXX
#define __INCLUDE_CLISTDATA_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "tnxarray.hxx"
#include "ilistdataeventhandler.hxx"
#include "clistdataitem.hxx"
#include "cnxstring.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Class representing a list of items. Designed to be used by the
* CListBox class, etc, to store its data. Fires events to notify
* listeners when the list changes or a new selection is made.
*/
class CListData
{
protected:
TNxArray<CListDataItem*> m_items; /**< Collection of list data items. */
TNxArray<IListDataEventHandler*> m_listDataEventhandlers; /**< Collection of event handlers. */
bool m_allowMultipleSelections; /**< If true, multiple options can
be selected. */
bool m_sortInsertedItems; /**< Automatically sorts items on
insertion if true. */
/**
* Quick sort the items using their compareTo() methods.
*
* @param start The index to start sorting at.
* @param end The index to stop sorting at.
*/
virtual void quickSort(const int start, const int end);
/**
* Swap the locations of two items in the array.
*
* @param index1 The index of the first item to swap.
* @param index2 The index of the second item to swap.
*/
virtual void swapItems(const int index1, const int index2);
/**
* Return the index that an item should be inserted at to maintain a sorted list of data.
*
* @param item The item to insert.
* @return The index that the item should be imserted into at.
*/
const int getSortedInsertionIndex(const CListDataItem *item) const;
/**
* Raise a data changed event.
*/
void raiseDataChangedEvent(void);
/**
* Raise a selection changed event.
*/
void raiseSelectionChangedEvent(void);
public:
/**
* Constructor.
*/
CListData(void);
/**
* Destructor.
*/
virtual ~CListData(void);
/**
* Add a new item.
*
* @param text Text to show in the option.
* @param value The value of the option.
*/
virtual void addItem(const CNxString &text, const uint32_t value);
/**
* Add an existing item. CListData becomes the owner of the option and will delete it
* when the list is deleted.
*
* @param item The item to add.
*/
virtual void addItem(CListDataItem *item);
/**
* Remove an item by its index.
*
* @param index The index of the option to remove.
*/
virtual void removeItem(const int index);
/**
* Select an item by its index.
*
* @param index The index of the item to select.
*/
virtual void selectItem(const int index);
/**
* Deselect an item by its index.
*
* @param index The index of the item to select.
*/
virtual void deselectItem(const int index);
/**
* Remove all items.
*/
virtual void removeAllItems(void);
/**
* Get the selected index. Returns -1 if nothing is selected. If more than one
* item is selected, the index of the first selected item is returned.
*
* @return The selected index.
*/
virtual const int getSelectedIndex(void) const;
/**
* Sets the selected index. Specify -1 to select nothing. Resets any
* other selected items to deselected.
*
* @param index The selected index.
*/
virtual void setSelectedIndex(const int index);
/**
* Get the selected item. Returns NULL if nothing is selected.
*
* @return The selected option.
*/
virtual const CListDataItem *getSelectedItem(void) const;
/**
* Sets whether multiple selections are possible or not.
*
* @param allowMultipleSelections True to allow multiple selections.
*/
virtual inline void
setAllowMultipleSelections(const bool allowMultipleSelections)
{
m_allowMultipleSelections = allowMultipleSelections;
}
/**
* Get the specified item.
*
* @return The specified item.
*/
virtual inline const CListDataItem *getItem(const int index) const
{
return m_items[index];
}
/**
* Sort the items using their compareTo() methods.
*/
virtual void sort(void);
/**
* Get the total number of items.
*
* @return The number of items.
*/
virtual inline const int getItemCount(void) const
{
return m_items.size();
}
/**
* Select all items. Does nothing if the list does not allow
* multiple selections.
*/
virtual void selectAllItems(void);
/**
* Deselect all items.
*/
virtual void deselectAllItems(void);
/**
* Select or deselect an item by its index. Does not deselect any
* other selected items. Set index to -1 to select nothing.
*
* @param index The index of the item to select.
* @param selected True to select the item, false to deselect it.
*/
virtual void setItemSelected(const int index, const bool selected);
/**
* Returns whether multiple selections are possible or not.
*
* @return True if multiple selections are allowed.
*/
virtual inline const bool allowsMultipleSelections(void) const
{
return m_allowMultipleSelections;
}
/**
* Sets whether or not items added to the list are automatically
* sorted on insert or not.
*
* @param sortInsertedItems True to enable sort on insertion.
*/
virtual inline void setSortInsertedItems(const bool sortInsertedItems)
{
m_sortInsertedItems = sortInsertedItems;
}
/**
* Add an event handler.
*
* @param eventHandler The event handler to add.
*/
inline void addListDataEventHandler(IListDataEventHandler *eventHandler)
{
m_listDataEventhandlers.push_back(eventHandler);
}
/**
* Remove an event handler.
*
* @param eventHandler The event handler to remove.
*/
void removeListDataEventHandler(IListDataEventHandler *eventHandler);
};
}
#endif // __cplusplus
#endif // __INCLUDE_CLISTDATA_HXX
@@ -0,0 +1,121 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/clistdataeventargs.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in most NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CLISTDATAEVENTARGS_HXX
#define __INCLUDE_CLISTDATAEVENTARGS_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include "teventargs.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
class CListData;
/**
* Event arguments passed to listeners when a CListData object raises an
* event.
*/
class CListDataEventArgs : public TEventArgs<CListData*>
{
public:
/**
* Constructor.
*
* @param source Pointer to the CListData object that raised the event.
*/
inline CListDataEventArgs(CListData *source) : TEventArgs<CListData*>(source)
{
}
};
}
#endif // __cplusplus
#endif // __INCLUDE_CLISTDATAEVENTARGS_HXX
@@ -0,0 +1,189 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/clistdataitem.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in most NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CLISTDATAITEM_HXX
#define __INCLUDE_CLISTDATAITEM_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include "cnxstring.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Class representing a data item within a list. Intended for use within
* the CListData class.
*/
class CListDataItem
{
private:
CNxString m_text; /**< Text to display for option. */
uint32_t m_value; /**< Option value. */
bool m_isSelected; /**< True if the option is selected. */
public:
/**
* Constructor.
*
* @param text The text to display in the item.
* @param value The value of the item.
*/
CListDataItem(const CNxString &text, const uint32_t value);
/**
* Destructor.
*/
virtual ~CListDataItem(void);
/**
* Get the item's text.
*
* @return The item's text.
*/
inline const CNxString &getText(void) const
{
return m_text;
}
/**
* Get the item's value.
*
* @return The item's value.
*/
inline const uint32_t getValue(void) const
{
return m_value;
}
/**
* Get the item's selection state.
*
* @return True if the item is selected; false if not.
*/
inline const bool isSelected(void) const
{
return m_isSelected;
}
/**
* Set the item's selection state.
*
* @param selected True to select the item; false to deselect it.
*/
inline void setSelected(bool selected)
{
m_isSelected = selected;
}
/**
* Compare the item with another. Comparison is based on the text of
* the item. Returns 0 if the text in the two items is the same,
* a value less than 0 if this item is less than the argument, and
* a value greater than 0 if this item is greater than the argument.
*
* @param item An item to compare this object with.
* @return 0 if the text in the two items is the same,
* a value less than 0 if this item is less than the argument, and
* a value greater than 0 if this item is greater than the argument.
*/
virtual int compareTo(const CListDataItem *item) const;
};
}
#endif // __cplusplus
#endif // __INCLUDE_CLISTDATAITEM_HXX
@@ -0,0 +1,621 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/cmultilinetextbox.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in most NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CMULTILINETEXTBOX_HXX
#define __INCLUDE_CMULTILINETEXTBOX_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include <nuttx/nx/nx.h>
#include "cscrollingpanel.hxx"
#include "cwidgetstyle.hxx"
#include "cnxstring.hxx"
#include "ctext.hxx"
#include "cwidgeteventhandler.hxx"
#include "itextbox.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
class CNxTimer;
/**
* Textbox that offers multiple lines of text. Has scrolling
* capability and can be dragged using the mouse. The text
* it contains can be changed or added to. It can remember more
* rows of text than it can display, and these additional
* rows can be scrolled through.
*/
class CMultiLineTextBox : public ITextBox, public CScrollingPanel,
public CWidgetEventHandler
{
public:
/**
* Enum of horizontal alignment options.
*/
enum TextAlignmentHoriz
{
TEXT_ALIGNMENT_HORIZ_CENTER = 0, /**< Centre the text */
TEXT_ALIGNMENT_HORIZ_LEFT = 1, /**< Align left */
TEXT_ALIGNMENT_HORIZ_RIGHT = 2 /**< Align right */
};
/**
* Enum of vertical alignment options.
*/
enum TextAlignmentVert
{
TEXT_ALIGNMENT_VERT_CENTER = 0, /**< Align to centre of textbox */
TEXT_ALIGNMENT_VERT_TOP = 1, /**< Align to top of textbox */
TEXT_ALIGNMENT_VERT_BOTTOM = 2 /**< Align to bottom of textbox */
};
protected:
CText *m_text; /**< CText object that manipulates
and wraps the raw text string. */
uint8_t m_visibleRows; /**< Total number of rows that the
textbox can display at once. */
nxgl_coord_t m_maxRows; /**< Maximum number of rows that the
textbox should buffer. */
int32_t m_topRow; /**< Index of the top row of text
currently displayed. */
TextAlignmentHoriz m_hAlignment; /**< Horizontal alignment of the text. */
TextAlignmentVert m_vAlignment; /**< Vertical alignment of the text. */
int m_cursorPos; /**< Position of the cursor within
the string. */
uint8_t m_showCursor; /**< Cursor visibility. */
bool m_wrapCursor; /**< True wrap cursor at the ends of the text */
/**
* Get the coordinates of the cursor relative to the text.
*
* @param x Will be populated with the x coordinate of the cursor.
* @param y Will be populated with the y coordinate of the cursor.
*/
virtual void getCursorCoordinates(nxgl_coord_t& x, nxgl_coord_t& y) const;
/**
* Gets the index of the character at the specified x coordinate in the
* specified row.
*
* @param x X coordinate of the character.
* @param rowIndex Index of the row containing the character.
* @return The index of the character at the specified coordinate.
*/
virtual int getCharIndexAtCoordinate(nxgl_coord_t x, int rowIndex) const;
/**
* Get the index of the character at the specified coordinates.
*
* @param x X coordinate of the character.
* @param y Y coordinate of the character.
* @return The index of the character at the specified coordinates.
*/
virtual unsigned int getCharIndexAtCoordinates(nxgl_coord_t x, nxgl_coord_t y) const;
/**
* Get the row containing the specified Y coordinate.
*
* @param y Y coordinate to locate.
* @return The index of the row containing the specified Y coordinate.
*/
int getRowContainingCoordinate(nxgl_coord_t y) const;
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawContents(CGraphicsPort *port);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
*
* @param port The CGraphicsPort to draw to.
* @see redraw()
*/
virtual void drawBorder(CGraphicsPort *port);
/**
* Move cursor one character to the left.
*/
virtual void moveCursorLeft(void);
/**
* Move cursor one character to the right.
*/
virtual void moveCursorRight(void);
/**
* Move cursor one row upwards.
*/
virtual void moveCursorUp(void);
/**
* Move cursor one row downwards.
*/
virtual void moveCursorDown(void);
/**
* Ensures that the textbox only contains the maximum allowed
* number of rows by culling any excess rows from the top of
* the text.
*
* @return True if lines were removed from the text; false if not.
*/
virtual bool cullTopLines(void);
/**
* Ensures that the canvas height is the height of the widget,
* if the widget exceeds the size of the text, or the height of
* the text if the text exceeds the size of the widget.
*/
virtual void limitCanvasHeight(void);
/**
* Ensures that the canvas cannot scroll beyond its height.
*/
virtual void limitCanvasY(void);
/**
* Jumps to the cursor coordinates of the text.
*/
void jumpToCursor(void);
/**
* Jumps to the bottom of the text.
*/
void jumpToTextBottom(void);
/**
* Resize the textbox to the new dimensions.
*
* @param width The new width.
* @param height The new height.
*/
virtual void onResize(nxgl_coord_t width, nxgl_coord_t height);
/**
* Starts the dragging system.
*
* @param x The x coordinate of the click.
* @param y The y coordinate of the click.
*/
virtual void onClick(nxgl_coord_t x, nxgl_coord_t y);
/**
* Opens the keyboard on the bottom display.
*
* @param x The x coordinates of the click.
* @param y The y coordinates of the click.
*/
virtual void onDoubleClick(nxgl_coord_t x, nxgl_coord_t y);
/**
* Handles physical button presses. Moves the cursor
* in the direction pressed.
*
* @param key The key that was pressed.
*/
void processPhysicalKey(nxwidget_char_t key);
/**
* Handle a keyboard press event.
*
* @param e The event data.
*/
void handleKeyPressEvent(const CWidgetEventArgs &e);
/**
* Handle a cursor control event. Replaces CWidgetEventHandler method.
*
* @param e The event data.
*/
void handleCursorControlEvent(const CWidgetEventArgs &e);
/**
* Gets the x position of a row of text based on the width of the row and the
* type of horizontal alignment currently set.
*
* @param row The index of the row.
* @return The x coordinate of the row.
*/
nxgl_coord_t getRowX(int row) const;
/**
* Gets the y position of the specified row of text based on the type of
* vertical alignment currently set.
*
* @param row The row number to find the y coordinate of.
* @return The y coordinate of the specified row of text.
*/
nxgl_coord_t getRowY(int row) const;
/**
* Return true if the cursor is visible
*/
virtual bool isCursorVisible(void) const;
/**
* Gets the character under the cursor.
*
* @return The character under the cursor.
*/
nxwidget_char_t getCursorChar(void) const;
/**
* Works out the number of visible rows within the textbox.
*/
void calculateVisibleRows(void);
/**
* Draws text.
*
* @param port The CGraphicsPort to draw to.
*/
void drawText(CGraphicsPort *port);
/**
* Draws the cursor.
*
* @param port The CGraphicsPort to draw to.
*/
void drawCursor(CGraphicsPort *port);
/**
* Draws a single line of text.
*
* @param port The CGraphicsPort to draw to.
* @param row The index of the row to draw.
*/
void drawRow(CGraphicsPort *port, int row);
/**
* Destructor.
*/
inline virtual ~CMultiLineTextBox(void)
{
delete m_text;
m_text = (CText *)NULL;
}
/**
* Copy constructor is protected to prevent usage.
*/
inline CMultiLineTextBox(const CMultiLineTextBox &multiLineTextBox)
: CScrollingPanel(multiLineTextBox) { }
public:
/**
* Constructor.
*
* @param pWidgetControl The widget control for the display.
* @param x The x coordinate of the text box, relative to its parent.
* @param y The y coordinate of the text box, relative to its parent.
* @param width The width of the textbox.
* @param height The height of the textbox.
* @param text Pointer to a string to display in the textbox.
* @param flags Standard widget flag options.
* @param maxRows The maximum number of rows the textbox can track. Adding
* text beyond this number will cause rows at the start of the text to be
* forgotten; text is essentially stored as a queue, and adding to the back
* of a full queue causes the front items to be popped off. Setting this to
* 0 will make the textbox track only the visible rows.
* @param style The style that the widget should use. If this is not
* specified, the widget will use the values stored in the global
* g_defaultWidgetStyle object. The widget will copy the properties of
* the style into its own internal style object.
*/
CMultiLineTextBox(CWidgetControl *pWidgetControl,
nxgl_coord_t x, nxgl_coord_t y,
nxgl_coord_t width, nxgl_coord_t height,
const CNxString &text, uint32_t flags,
nxgl_coord_t maxRows = 0,
CWidgetStyle *style = (CWidgetStyle *)NULL);
/**
* Set the horizontal alignment of text within the textbox.
*
* @param alignment The horizontal position of the text.
*/
virtual void setTextAlignmentHoriz(TextAlignmentHoriz alignment);
/**
* Set the vertical alignment of text within the textbox.
*
* @param alignment The vertical position of the text.
*/
virtual void setTextAlignmentVert(TextAlignmentVert alignment);
/**
* Returns the number of "pages" that the text spans. A page
* is defined as the amount of text that can be displayed within
* the textbox at one time.
*
* @return The page count.
*/
virtual const int getPageCount(void) const;
/**
* Returns the current page.
*
* @return The current page.
* @see getPageCount().
*/
virtual const int getCurrentPage(void) const;
/**
* Returns a pointer to the CText object that contains the
* wrapped text used in the textbox. It is used as the
* pre-processed data source for the textbox, and should
* not be altered.
*
* @return Pointer to the CText object.
*/
virtual inline const CText *getText(void) const
{
return m_text;
}
/**
* Set the text displayed in the textbox.
*
* @param text String to display.
*/
virtual void setText(const CNxString &text);
/**
* Append new text to the end of the current text
* displayed in the textbox.
*
* @param text String to append.
*/
virtual void appendText(const CNxString &text);
/**
* Remove all characters from the string from the start index onwards.
*
* @param startIndex Index to remove from.
*/
virtual void removeText(const unsigned int startIndex);
/**
* Remove specified number of characters from the string from the
* start index onwards.
*
* @param startIndex Index to remove from.
* @param count Number of characters to remove.
*/
virtual void removeText(const unsigned int startIndex, const unsigned int count);
/**
* Set the font used in the textbox.
*
* @param font Pointer to the new font.
*/
virtual void setFont(CNxFont *font);
/**
* Get the length of the text string.
*
* @return The length of the text string.
*/
virtual const int getTextLength(void) const;
/**
* Sets the cursor display mode.
*
* @param cursorMode Determines cursor display mode
*/
virtual void showCursor(EShowCursor cursorMode);
/**
* Shows the cursor in default mode (only when the TextBox has focus).
*/
virtual inline void showCursor(void)
{
showCursor(SHOW_CURSOR_ONFOCUS);
}
/**
* Hides the cursor.
*/
virtual inline void hideCursor(void)
{
showCursor(SHOW_CURSOR_NEVER);
}
/**
* Enables/disables cursor wrapping
*
* @param wrap True enables cursor wrapping
*/
virtual inline void wrapCursor(bool wrap)
{
m_wrapCursor = wrap;
}
/**
* Move the cursor to the text position specified. 0 indicates the start
* of the string. If position is greater than the length of the string,
* the cursor is moved to the end of the string.
*
* @param position The new cursor position.
*/
virtual void moveCursorToPosition(const int position);
/**
* Get the cursor position. This is the index within the string that
* the cursor is currently positioned over.
*
* @return position The cursor position.
*/
virtual inline const int getCursorPosition(void) const
{
return m_cursorPos;
}
/**
* Insert text at the specified index.
*
* @param text The text to insert.
* @param index Index at which to insert the text.
*/
virtual void insertText(const CNxString &text,
const unsigned int index);
/**
* Insert text at the current cursor position.
*
* @param text The text to insert.
*/
virtual void insertTextAtCursor(const CNxString & ext);
};
}
#endif // __cplusplus
#endif // __INCLUDE_CMULTILINETEXTBOX_HXX
+238
View File
@@ -0,0 +1,238 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/cnxfont.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CNXFONT_HXX
#define __INCLUDE_CNXFONT_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
#include <nuttx/nx/nxfonts.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
class CNxString;
struct SBitmap;
/**
* Class defining the properties of one font.
*/
class CNxFont
{
private:
enum nx_fontid_e m_fontId; /**< The font ID. */
NXHANDLE m_fontHandle; /**< The font handle */
FAR const struct nx_font_s *m_pFontSet; /** < The font set metrics */
nxgl_mxpixel_t m_fontColor; /**< Color to draw the font with when rendering. */
nxgl_mxpixel_t m_transparentColor; /**< Background color that should not be rendered. */
public:
/**
* CNxFont Constructor.
*
* @param fontid The font ID to use.
* @param fontColor The font color to use.
* @param transparentColor The color in the font bitmap used as the
* background color.
*/
CNxFont(enum nx_fontid_e fontid, nxgl_mxpixel_t fontColor,
nxgl_mxpixel_t transparentColor);
/**
* CNxFont Destructor.
*/
~CNxFont() { }
/**
* Checks if supplied character is blank in the current font.
*
* @param letter The character to check.
* @return True if the glyph contains any pixels to be drawn. False if
* the glyph is blank.
*/
const bool isCharBlank(const nxwidget_char_t letter) const;
/**
* Gets the color currently being used as the drawing color.
*
* @return The current drawing color.
*/
inline const nxgl_mxpixel_t getColor() const
{
return m_fontColor;
}
/**
* Sets the color to use as the drawing color. If set, this overrides
* the colors present in a non-monochrome font.
* @param color The new drawing color.
*/
inline void setColor(const nxgl_mxpixel_t color)
{
m_fontColor = color;
}
/**
* Get the color currently being used as the transparent background
* color.
* @return The transparent background color.
*/
inline const nxgl_mxpixel_t getTransparentColor() const
{
return m_transparentColor;
}
/**
* Sets the transparent background color to a new value.
* @param color The new background color.
*/
inline void setTransparentColor(const nxgl_mxpixel_t color)
{
m_transparentColor = color;
}
/**
* Draw an individual character of the font to the specified bitmap.
*
* @param bitmap The bitmap to draw to.
* @param letter The character to output.
*/
void drawChar(FAR SBitmap *bitmap, nxwidget_char_t letter);
/**
* Get the width of a string in pixels when drawn with this font.
*
* @param text The string to check.
* @return The width of the string in pixels.
*/
nxgl_coord_t getStringWidth(const CNxString &text) const;
/**
* Get the width of a portion of a string in pixels when drawn with this
* font.
*
* @param text The string to check.
* @param startIndex The start point of the substring within the string.
* @param length The length of the substring in chars.
* @return The width of the substring in pixels.
*/
nxgl_coord_t getStringWidth(const CNxString& text,
int startIndex, int length) const;
/**
* Gets font metrics for a particular character
*
*
* @param letter The character to get the width of.
* @param metrics The location to return the font metrics
*/
void getCharMetrics(nxwidget_char_t letter,
FAR struct nx_fontmetric_s *metrics) const;
/**
* Get the width of an individual character.
*
* @param letter The character to get the width of.
* @return The width of the character in pixels.
*/
nxgl_coord_t getCharWidth(nxwidget_char_t letter) const;
/**
* Get the height of an individual character.
*
* @param letter The letter to get the height of.
* @return The height of the character in pixels.
*/
inline nxgl_coord_t getCharHeight(nxwidget_char_t letter) const;
/**
* Gets the maximum width of the font.
*
* @return The height of the font.
*/
inline const uint8_t getMaxWidth(void) const
{
return m_pFontSet->mxwidth;
}
/**
* Gets the height of the font.
*
* @return The height of the font.
*/
inline const uint8_t getHeight(void) const
{
return m_pFontSet->mxheight;
}
};
}
#endif // __cplusplus
#endif // __INCLUDE_CNXFONT_HXX
@@ -0,0 +1,199 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/cnxserver.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CNXSERVER_HXX
#define __INCLUDE_CNXSERVER_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/nx/nx.h>
#include "cnxwindow.hxx"
#include "cbgwindow.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
/**
* Forward references
*/
class CBgWindow;
/**
* This class represents the NX server. It includes methods to connect to
* and disconnect form the NX server, methods to manage the background, and
* "factory" methods to create window objects on the NX server. NXWidget
* objects them may be created on the window objects.
*/
class CNxServer
{
private:
#ifndef CONFIG_NX_MULTIUSER
FAR NX_DRIVERTYPE *m_hDevice; /**< LCD/Framebuffer device handle */
#endif
NXHANDLE m_hNxServer; /**< NX server handle */
#ifdef CONFIG_NX_MULTIUSER
voilatile bool m_running; /**< True: The listener thread is running */
voilatile bool m_connected; /**< True: Connected to the server */
volatile bool m_stop; /**< True: Waiting for the listener thread to stop */
sem_t m_connsem; /**< Wait for server connection */
#endif
static uint8_t m_nServers; /**< The number of NX server instances */
/**
* This is the entry point of a thread that listeners for and dispatches
* events from the NX server.
*/
#ifdef CONFIG_NX_MULTIUSER
static FAR void *listener(FAR void *arg);
#endif
public:
/**
* CNXServer constructor. The CNxServer is a normally singleton. However, that
* not enforced: This constructor could run more than one in the situation where
* there are multiple physical displays. However, that configuration has never
* been texted.
*/
CNxServer(void);
/**
* CNXServer destructor
*/
~CNxServer(void);
/**
* Connect to the NX Server
*/
virtual bool connect(void);
/**
* Disconnect from the NX Server
*/
virtual void disconnect(void);
/**
* Get the NX server handle
*
* @return The NX server handler (NULL is not connected)
*/
inline NXHANDLE getServer(void)
{
return m_hNxServer;
}
/**
* Test if we are connected to the NX server.
*
* @return True is connected; false is not connected.
*/
inline bool connected(void)
{
#ifdef CONFIG_NX_MULTIUSER
return m_connected;
#else
return true;
#endif
}
/**
* Set the background color
*/
inline bool setBackgroundColor(nxgl_mxpixel_t color)
{
return nx_setbgcolor(m_hNxServer, &color) == OK;
}
/**
* Get an instance of a raw NX window.
*/
inline CNxWindow *createRawWindow(CWidgetControl *widgetControl)
{
return new CNxWindow(m_hNxServer, widgetControl);
}
/**
* Get an instance of the framed NX window.
*/
#if 0 // Not ready for prime time
inline CFramedWindow *createFramedWindow(CWidgetControl *widgetControl)
{
return new CFramedWindow(m_hNxServer, widgetControl);
}
#endif
/**
* Get an instance of the background window.
*/
inline CBgWindow *getBgWindow(CWidgetControl *widgetControl)
{
return new CBgWindow(m_hNxServer, widgetControl);
}
};
}
#endif // __cplusplus
#endif // __INCLUDE_CNXSERVER_HXX
@@ -0,0 +1,484 @@
/****************************************************************************
* include/cnxtring.hxx
* NxWidgets/libnxwidgets/
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in most NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CNXSTRING_HXX
#define __INCLUDE_CNXSTRING_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include "nxconfig.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
class CStringIterator;
/**
* Unicode string class. Uses 16-bt wide-character encoding. For optimal
* performance, use the CStringIterator class to iterate over a CNxString
* instance.
*
* Where possible, the string avoids allocating memory each time the
* string grows or shrinks. This means that the string may consume more
* memory than the number of chars would seem to dictate if the object
* previously contained a large string that has subsequently been truncated.
* It also means that increasing the length of such a string is a cheaper
* operation as memory does not need to allocated and copied.
*
* Additionally, the string increases its array size by m_growAmount every
* time it needs to allocate extra memory, potentially reducing the number
* of reallocs needed.
*
* The string is not null-terminated. Instead, it uses a m_stringLength
* member that stores the number of characters in the string. This saves a
* byte and makes calls to getLength() run in O(1) time instead of O(n).
*/
class CNxString
{
private:
friend class CStringIterator;
int m_stringLength; /**< Number of characters in the string */
int m_allocatedSize; /**< Number of bytes allocated for this string */
int m_growAmount; /**< Number of chars that the string grows by
whenever it needs to get larger */
protected:
FAR nxwidget_char_t *m_text; /**< Raw char array data */
/**
* Allocate memory for the string.
*
* @param chars Number of chars to allocate.
* @param preserve If true, the data in the existing memory will be
* preserved if new memory must be allocated
*/
void allocateMemory(int chars, bool preserve);
/**
* Check if we've got any string data stored or not.
*
* @return True if the string contains any data; false if no data has
* yet been supplied.
*/
inline bool hasData(void) const
{
return m_stringLength > 0;
}
/**
* Get the amount of allocated memory.
*
* @return The number of chars allocated in RAM.
*/
inline int getAllocatedSize(void) const
{
return m_allocatedSize;
}
/**
* Returns a pointer to the raw char array data.
*
* @return Pointer to the char array.
*/
inline FAR const nxwidget_char_t *getCharArray(void) const
{
return m_text;
}
/**
* Return a pointer to the specified character.
*
* @param index Index of the character to retrieve.
*/
FAR nxwidget_char_t *getCharPointer(const int index) const;
public:
/**
* Constructor to create an empty string object.
*/
CNxString();
/**
* Constructor to create a string from a C character array.
*
* @param text Pointer to a char array to use as the basis of the
* string.
*/
CNxString(FAR const char *text);
/**
* Constructor to create a string from a single character.
*
* @param letter Single character to use as the basis of the string.
*/
CNxString(const nxwidget_char_t letter);
/**
* Copy constructor.
* @param string CNxString object to create a copy of.
*/
CNxString(const CNxString &string);
/**
* Destructor.
*/
inline ~CNxString()
{
delete[] m_text;
m_text = (FAR nxwidget_char_t *)NULL;
};
/**
* Creates and returns a new CStringIterator object that will iterate
* over this string. The object must be manually deleted once it is
* no longer needed.
*
* @return A new CStringIterator object.
*/
CStringIterator *newStringIterator(void) const;
/**
* Copy the internal array to the supplied buffer. The buffer must be
* large enough to contain the full text in the string. The
* getByteCount() method can be used to obtain the length of the string.
* Unlike the CNxString class, the char array is null-terminated.
* The buffer must be (getByteCount() + 1) bytes long, in order to
* accommodate the terminator.
*
* @param buffer Buffer to copy the internal char array to.
*/
void copyToCharArray(FAR nxwidget_char_t *buffer) const;
/**
* Set the text in the string.
*
* @param text CNxString containing the new data for this string.
*/
void setText(const CNxString &text);
/**
* Set the text in the string.
*
* @param text Char array to use as the new data for this string.
*/
void setText(FAR const char *text);
/**
* Set the nxwidget_char_t text in the string.
*
* @param text Char array to use as the new data for this string.
*/
void setText(FAR const nxwidget_char_t *text, int nchars);
/**
* Set the 8-bit C-string text in the string.
*
* @param text Character to to use as the new data for this string.
*/
void setText(const nxwidget_char_t text);
/**
* Append text to the end of the string.
*
* @param text String to append.
*/
void append(const CNxString &text);
/**
* Insert text at the specified character index.
*
* @param text The text to insert.
* @param index The index at which to insert the text.
*/
void insert(const CNxString &text, const int index);
/**
* Remove all characters from the string from the start index onwards.
*
* @param startIndex Index to remove from.
*/
void remove(const int startIndex);
/**
* Remove specified number of characters from the string from the
* start index onwards.
*
* @param startIndex Index to remove from.
* @param count Number of characters to remove.
*/
void remove(const int startIndex, const int count);
/**
* Get the of number of letters (ie. the length) of the string.
*
* @return The length of the string.
*/
inline const int getLength(void) const
{
return m_stringLength;
};
/**
* Get the character at the specified index. This function is useful
* for finding the occasional character at an index, but for iterating
* over strings it is exceptionally slow. The newStringIterator()
* method should be used to retrieve an iterator object that can iterate
* over the string efficiently.
*
* @param index The index of the character to retrieve.
* @return The character at the specified index.
*/
const nxwidget_char_t getCharAt(int index) const;
/**
* Returns the first index of the specified letter within the string.
* Will return -1 if the letter is not found.
*
* @param letter Letter to find.
* @return The index of the letter.
*/
const int indexOf(nxwidget_char_t letter) const;
/**
* Returns the first index of the specified letter within the string.
* Will return -1 if the letter is not found. Scans through the string
* from "startIndex" until it has examined all subsequent letters.
* @param letter Letter to find.
*
* @param startIndex The index to start searching from.
* @return The index of the letter.
*/
const int indexOf(nxwidget_char_t letter, int startIndex) const;
/**
* Returns the first index of the specified letter within the string.
* Will return -1 if the letter is not found. Scans through the string
* from "startIndex" until it has examined all letters within the
* range "count".
*
* @param letter Letter to find.
* @param startIndex The index to start searching from.
* @param count The number of characters to examine.
* @return The index of the letter.
*/
const int indexOf(nxwidget_char_t letter, int startIndex, int count) const;
/**
* Returns the last index of the specified letter within the string.
* Will return -1 if the letter is not found.
*
* @param letter Letter to find.
* @return The index of the letter.
*/
const int lastIndexOf(nxwidget_char_t letter) const;
/**
* Returns the last index of the specified letter within the string.
* Will return -1 if the letter is not found. Scans through the string
* backwards from "startIndex" until it has examined all preceding
* letters within the string.
*
* @param letter Letter to find.
* @param startIndex The index to start searching from.
* @return The index of the letter.
*/
const int lastIndexOf(nxwidget_char_t letter, int startIndex) const;
/**
* Returns the last index of the specified letter within the string.
* Will return -1 if the letter is not found. Scans through the string
* backwards from "startIndex" until it has examined all letters within
* the range "count".
* @param letter Letter to find.
* @param startIndex The index to start searching from.
* @param count The number of characters to examine.
* @return The index of the letter.
*/
const int lastIndexOf(nxwidget_char_t letter, int startIndex, int count) const;
/**
* Get a substring from this string. It is the responsibility of the
* caller to delete the substring when it is no longer required.
*
* @param startIndex The starting point of the substring.
* @return A pointer to a new CNxString object containing the
* substring.
*/
CNxString *subString(int startIndex) const;
/**
* Get a substring from this string. It is the responsibility of the
* caller to delete the substring when it is no longer required.
*
* @param startIndex The starting point of the substring.
* @param length The length of the substring.
* @return A pointer to a new CNxString object containing the
* substring.
*/
CNxString *subString(int startIndex, int length) const;
/**
* Overloaded assignment operator. Copies the data within the argument
* string to this string.
*
* @param string The string to copy.
* @return This string.
*/
CNxString &operator=(const CNxString &string);
/**
* Overloaded assignment operator. Copies the data within the argument
* char array to this string.
*
* @param string The string to copy.
* @return This string.
*/
CNxString &operator=(const char *string);
/**
* Overloaded assignment operator. Copies the data from the argument
* char to this string.
*
* @param letter The char to copy.
* @return This string.
*/
CNxString& operator=(nxwidget_char_t letter);
/**
* Compares this string to the argument.
*
* @param string String to compare to.
* @return Zero if both strings are equal. A value greater than zero
* indicates that this string is greater than the argument string. A
* value less than zero indicates the opposite. Note that the return
* value indicates the *byte* that does not match, not the *character*.
*/
int compareTo(const CNxString &string) const;
};
}
#endif // __cplusplus
#endif // __INCLUDE_CNXSTRING_HXX
+220
View File
@@ -0,0 +1,220 @@
/****************************************************************************
* NxWidgets/libnxwidgets/include/cnxtimer.hxx
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
* me be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************
*
* Portions of this package derive from Woopsi (http://woopsi.org/) and
* portions are original efforts. It is difficult to determine at this
* point what parts are original efforts and which parts derive from Woopsi.
* However, in any event, the work of Antony Dzeryn will be acknowledged
* in most NxWidget files. Thanks Antony!
*
* Copyright (c) 2007-2011, Antony Dzeryn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names "Woopsi", "Simian Zombie" nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_CNXTIMER_HXX
#define __INCLUDE_CNXTIMER_HXX
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <ctime>
#include "cnxwidget.hxx"
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Implementation Classes
****************************************************************************/
#if defined(__cplusplus)
namespace NXWidgets
{
class CWidgetcontrol;
/**
* Timer widget. It can drive time-based events, animations, etc.
*
* Using the timer is simple:
* - Create an instance of the CNxTimer and add it as a child to a widget.
* - Call the instance's "start()" method.
* - Catch the timer's action event and call any code that should run.
*/
class CNxTimer : public CNxWidget
{
protected:
FAR timer_t m_timerid; /**< POSIX timer */
uint32_t m_timeout; /**< The timeout value in milliseconds */
bool m_isRunning; /**< Indicates whether or not the timer is running */
bool m_isRepeater; /**< Indicates whether or not the timer repeats */
/**
* The SIGALM signal handler that will be called when the timer goes off
*
* @param signo The signal number call caused the handler to run (SIGALM)
*/
static void signalHandler(int signo);
/**
* Handle an expired timer
*/
void handleTimerExpiration(void);
/**
* Convert a timespec to milliseconds
*
* @param tp The pointer to the timespec to convert
* @return The corresponding time in milliseconds
*/
uint32_t timespecToMilliseconds(FAR const struct timespec *tp);
/**
* Convert milliseconds to a timespec
*
* @param milliseconds The milliseconds to be converted
* @param tp The pointer to the location to store the converted timespec
*/
void millisecondsToTimespec(uint32_t milliseconds, FAR struct timespec *tp);
/**
* Copy constructor is protected to prevent usage.
*/
inline CNxTimer(const CNxTimer &timer) : CNxWidget(timer) { }
public:
/**
* Constructor.
*
* @param pWidgetControl The controlling widget for the display.
* @param timeout Time, in milliseconds, before the timer fires an
* EVENT_ACTION event.
* @param repeat If true, the timer will fire multiple events. If false,
* the timer will fire just once and stop.
*/
CNxTimer(CWidgetControl *pWidgetControl, uint32_t timeout, bool repeat);
/**
* Destructor.
*/
~CNxTimer(void);
/**
* Return the time remaining on this timer.
*
* @return The number of milliseconds that this timer runs before
* firing an event. Zero is returned if the timer is not running.
*/
const uint32_t getTimeout(void);
/**
* Resets the (running) timer to its initial timeout value. This
* call does nothing if the timer is not running.
*/
void reset(void);
/**
* Starts the timer. This call does nothing if the timer is already
* running.
*/
void start(void);
/**
* Stops the timer. Does nothing if the timer is not running.
*/
void stop(void);
/**
* Set the timeout of this timer. This timeout value will not
* take effect until start() or reset() is called.
*
* @param timeout The number of milliseconds that this timer will run
* before firing an event.
*/
inline void setTimeout(uint32_t timeout)
{
m_timeout = timeout;
}
};
}
#endif // __cplusplus
#endif // __INCLUDE_CNXTIMER_HXX

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