forked from Archive/PX4-Autopilot
NxWM update
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4675 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
parent
84f7d3282f
commit
e1c2c72201
|
@ -90,10 +90,23 @@ namespace NxWM
|
|||
protected:
|
||||
NxWidgets::CNxTkWindow *m_window; /**< The framed window used by the application */
|
||||
NxWidgets::CNxToolbar *m_toolbar; /**< The toolbar */
|
||||
NxWidgets::CImage *m_minimize; /**< The minimize icon */
|
||||
NxWidgets::CImage *m_close; /**< The close icon */
|
||||
NxWidgets::CImage *m_minimizeImage; /**< The minimize icon */
|
||||
NxWidgets::CImage *m_stopImage; /**< The close icon */
|
||||
NxWidgets::CLabel *m_windowLabel; /**< The window title */
|
||||
NxWidgets::CRlePaletteBitmap *m_minimizeBitmap; /**< The minimize icon bitmap */
|
||||
NxWidgets::CRlePaletteBitmap *m_stopBitmap; /**< The stop icon bitmap */
|
||||
NxWidgets::CRlePaletteBitmap *m_minimizeBitmap; /**< The minimize icon bitmap */
|
||||
NxWidgets::CNxFont *m_windowFont; /**< The font used to rend the window label */
|
||||
IApplicationCallback *m_callback; /**< Toolbar action callbacks */
|
||||
|
||||
/**
|
||||
* Configure the standard application toolbar
|
||||
*
|
||||
* @return True if the toolcar was successfully initialized.
|
||||
*/
|
||||
|
||||
bool configureToolbar(void);
|
||||
|
||||
/**
|
||||
* CNxApplicationWindow Destructor
|
||||
*/
|
||||
|
@ -131,6 +144,17 @@ namespace NxWM
|
|||
return m_window;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the window label
|
||||
*
|
||||
* @param appname. The name of the application to place on the window
|
||||
*/
|
||||
|
||||
inline void setWindowLabel(NxWidgets::CNxString &appname)
|
||||
{
|
||||
m_windowLabel->setText(appname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register to receive callbacks when toolbar icons are selected
|
||||
*/
|
||||
|
|
|
@ -56,13 +56,21 @@
|
|||
# warning "NX multi-user support is required (CONFIG_NX_MULTIUSER)"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Default font ID
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_NXWM_DEFAULT_FONTID
|
||||
# define CONFIG_NXWM_DEFAULT_FONTID NXFONT_DEFAULT
|
||||
#endif
|
||||
|
||||
/* Colors *******************************************************************/
|
||||
/**
|
||||
* Normal background color
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_NXWM_DEFAULT_BACKGROUNDCOLOR
|
||||
# define CONFIG_NXWM_DEFAULT_BACKGROUNDCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR
|
||||
# define CONFIG_NXWM_DEFAULT_BACKGROUNDCOLOR CONFIG_NXWM_DEFAULT_BACKGROUNDCOLOR
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -70,7 +78,7 @@
|
|||
*/
|
||||
|
||||
#ifndef CONFIG_NXWM_DEFAULT_SELECTEDBACKGROUNDCOLOR
|
||||
# define CONFIG_NXWM_DEFAULT_SELECTEDBACKGROUNDCOLOR CONFIG_NXWIDGETS_DEFAULT_SELECTEDBACKGROUNDCOLOR
|
||||
# define CONFIG_NXWM_DEFAULT_SELECTEDBACKGROUNDCOLOR CONFIG_NXWM_DEFAULT_SELECTEDBACKGROUNDCOLOR
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -89,6 +97,22 @@
|
|||
# define CONFIG_NXWM_DEFAULT_SELECTEDFOREGROUNDCOLOR MKRGB(248,248,248)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The default font color
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_NXWM_DEFAULT_FONTCOLOR
|
||||
# define CONFIG_NXWM_DEFAULT_FONTCOLOR MKRGB(255,255,255)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The transparent color
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_NXWM_TRANSPARENT_COLOR
|
||||
# define CONFIG_NXWM_TRANSPARENT_COLOR MKRGB(0,0,0)
|
||||
#endif
|
||||
|
||||
/* Task Bar Configuation ***************************************************/
|
||||
/* At present, all icons are 25 pixels in "widgth" and, hence require a
|
||||
* task bar of at least that size.
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <nuttx/config.h>
|
||||
|
||||
#include "nxwmconfig.hxx"
|
||||
#include "nxwmglyphs.hxx"
|
||||
#include "cappliationwinow.hxx"
|
||||
|
||||
/********************************************************************************************
|
||||
|
@ -61,10 +62,25 @@
|
|||
|
||||
CNxApplicationWindow::CNxApplicationWindow(NxWidgets::CNxTkWindow *window);
|
||||
{
|
||||
m_window = (NxWidgets::CNxTkWindow *)0;
|
||||
// Save the window for later use
|
||||
|
||||
m_window = window;
|
||||
|
||||
// These will be created with the open method is called
|
||||
|
||||
m_toolbar = (NxWidgets::CNxToolbar *)0;
|
||||
m_minimize = (NxWidgets::CImage *)0;
|
||||
m_close = (NxWidgets::CImage *)0;
|
||||
|
||||
m_minimizeImage = (NxWidgets::CImage *)0;
|
||||
m_stopImage = (NxWidgets::CImage *)0;
|
||||
m_windowLabel = (NxWidgets::CLabel *)0;
|
||||
|
||||
m_minimizeBitmap = (NxWidgets::CRlePaletteBitmap *)0;
|
||||
m_stopBitmap = (NxWidgets::CRlePaletteBitmap *)0;
|
||||
|
||||
m_windowFont = (NxWidgets::CNxFont *)0;
|
||||
|
||||
// This will be initialized when the registerCallbacks() method is called
|
||||
|
||||
m_callback = (IApplicationCallback *)0;
|
||||
}
|
||||
|
||||
|
@ -76,21 +92,41 @@ CNxApplicationWindow::~CNxApplicationWindow(void)
|
|||
{
|
||||
// Free the resources that we are responsible for
|
||||
|
||||
if (m_minimizeImage)
|
||||
{
|
||||
delete m_minimizeImage;
|
||||
}
|
||||
|
||||
if (m_stopImage)
|
||||
{
|
||||
delete m_stopImage;
|
||||
}
|
||||
|
||||
if (m_windowLabel)
|
||||
{
|
||||
delete m_windowLabel;
|
||||
}
|
||||
|
||||
if (m_minimizeBitmap)
|
||||
{
|
||||
delete m_minimizeBitmap;
|
||||
}
|
||||
|
||||
if (m_stopBitmap)
|
||||
{
|
||||
delete m_stopBitmap;
|
||||
}
|
||||
|
||||
if (m_windowFont)
|
||||
{
|
||||
delete m_windowFont;
|
||||
}
|
||||
|
||||
if (m_toolbar)
|
||||
{
|
||||
delete m_toolbar;
|
||||
}
|
||||
|
||||
if (m_minimize)
|
||||
{
|
||||
delete m_minimize;
|
||||
}
|
||||
|
||||
if (m_close)
|
||||
{
|
||||
delete m_close;
|
||||
}
|
||||
|
||||
// We didn't create the window. That was done by the task bar,
|
||||
// Be we will handle destruction of with window as a courtesy.
|
||||
|
||||
|
@ -109,7 +145,182 @@ CNxApplicationWindow::~CNxApplicationWindow(void)
|
|||
|
||||
bool CNxApplicationWindow::open(void)
|
||||
{
|
||||
/* Configure the toolbar */
|
||||
|
||||
if (!configureToolbar())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the standard application toolbar
|
||||
*
|
||||
* @return True if the toolcar was successfully initialized.
|
||||
*/
|
||||
|
||||
bool configureToolbar(void)
|
||||
{
|
||||
// Open the toolbar
|
||||
|
||||
m_toolbar = m_window->openToolbar();
|
||||
if (!m_toolbar)
|
||||
{
|
||||
// We failed to open the toolbar
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the width of the display
|
||||
|
||||
struct nxgl_size_s windowSize;
|
||||
if (!m_toolbar->getSize(&windowSize))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the CWidgetControl associated with this window
|
||||
|
||||
NxWidgets::CWidgetControl *control = m_toolbar->getWidgetControl();
|
||||
if (control)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create STOP bitmap container
|
||||
|
||||
m_stopBitmap = new NxWidgets::CRlePaletteBitmap(&g_stopBitmap);
|
||||
if (!m_stopBitmap)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the STOP application icon at the right of the toolbar
|
||||
|
||||
nxgl_point_t iconPos;
|
||||
nxgl_size_t iconSize;
|
||||
|
||||
// Get the height and width of the stop bitmap
|
||||
|
||||
iconSize.w = m_stopBitmap->getWidth();
|
||||
iconSize.h = m_stopBitmap->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())
|
||||
|
||||
iconSize.w += 2 * 1;
|
||||
iconSize.h += 2 * 1;
|
||||
|
||||
// Pick an X/Y position such that the image will position at the right of
|
||||
// the toolbar and centered vertically.
|
||||
|
||||
iconPos.x = windowSize.w - iconsize.w;
|
||||
|
||||
if (iconSize.h >= windowSize.h)
|
||||
{
|
||||
iconPos.y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
iconPos.y = (windowSize.h - iconSize.h) >> 1;
|
||||
}
|
||||
|
||||
// Now we have enough information to create the image
|
||||
|
||||
m_stopImage = new CImage(control, iconPos.x, iconPos.y, iconSize.w, iconSize.h, m_stopBitmap);
|
||||
if (!m_stopImage)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create MINIMIZE application bitmap container
|
||||
|
||||
m_minimizeBitmap = new NxWidgets::CRlePaletteBitmap(&g_minimizeBitmap);
|
||||
if (!m_minimizeBitmap)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the height and width of the stop bitmap
|
||||
|
||||
iconSize.w = m_minimizeBitmap->getWidth();
|
||||
iconSize.h = m_minimizeBitmap->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())
|
||||
|
||||
iconSize.w += 2 * 1;
|
||||
iconSize.h += 2 * 1;
|
||||
|
||||
// Pick an X/Y position such that the image will position at the right of
|
||||
// the toolbar and centered vertically.
|
||||
|
||||
iconPos.x -= iconsize.w;
|
||||
|
||||
if (iconSize.h >= windowSize.h)
|
||||
{
|
||||
iconPos.y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
iconPos.y = (windowSize.h - iconSize.h) >> 1;
|
||||
}
|
||||
|
||||
// Now we have enough information to create the image
|
||||
|
||||
m_minimizeImage = new CImage(control, iconPos.x, iconPos.y, iconSize.w, iconSize.h, m_minimizeBitmap);
|
||||
if (!m_minimizeImage)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// The rest of the toolbar will hold the left-justified application label
|
||||
// Create the default font instance
|
||||
|
||||
m_windowFont = new CNxFont(CONFIG_NXWM_DEFAULT_FONTID,
|
||||
CONFIG_NXWM_DEFAULT_FONTCOLOR,
|
||||
CONFIG_NXWM_TRANSPARENT_COLOR);
|
||||
if (!m_windowFont)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Get the height and width of the text display area
|
||||
|
||||
size.w = pos.x
|
||||
size.h = windowSize.h;
|
||||
|
||||
pos.x = 0;
|
||||
pos.y = 0;
|
||||
|
||||
// Now we have enough information to create the label
|
||||
|
||||
m_windowLabel = new CLabel(control, pos.x, pos.y, size.w, size.h, "");
|
||||
if (!m_windowLabel)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Configure the label
|
||||
|
||||
m_windowLabel->setBorderLess(true);
|
||||
m_windowLabel->setTextAlignmentHoriz(NxWidgets::TEXT_ALIGNMENT_HORIZ_LEFT);
|
||||
m_windowLabel->setTextAlignmentVert(NxWidgets::TEXT_ALIGNMENT_VERT_CENTER);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue