From fbfd97c209f99cf1a9e8190ba835c1b3bef64c2a Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 28 Apr 2012 17:36:53 +0000 Subject: A few pieces of what may become an NX window manager git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4669 42af7a65-404d-4744-a932-0658087f49c3 --- NxWidgets/libnxwidgets/include/cbitmap.hxx | 9 +++ NxWidgets/libnxwidgets/include/cbuttonarray.hxx | 2 +- NxWidgets/libnxwidgets/include/cimage.hxx | 16 +++++- .../libnxwidgets/include/crlepalettebitmap.hxx | 14 ++++- NxWidgets/libnxwidgets/include/ibitmap.hxx | 11 +++- NxWidgets/libnxwidgets/src/cimage.cxx | 64 +++++++++++++++++++--- NxWidgets/libnxwidgets/src/crlepalettebitmap.cxx | 17 +++++- NxWidgets/libnxwidgets/src/glyph_nxlogo.cxx | 5 +- 8 files changed, 120 insertions(+), 18 deletions(-) (limited to 'NxWidgets/libnxwidgets') diff --git a/NxWidgets/libnxwidgets/include/cbitmap.hxx b/NxWidgets/libnxwidgets/include/cbitmap.hxx index 473403aa8..4828ca9cc 100644 --- a/NxWidgets/libnxwidgets/include/cbitmap.hxx +++ b/NxWidgets/libnxwidgets/include/cbitmap.hxx @@ -181,6 +181,15 @@ namespace NXWidgets const nxgl_coord_t getStride(void) const; + /** + * Use the colors associated with a selected image. + * + * @param selected. true: Use colors for a selected widget, + * false: Use normal (default) colors. + */ + + inline void setSelected(bool selected) {} + /** * Get one row from the bit map image. * diff --git a/NxWidgets/libnxwidgets/include/cbuttonarray.hxx b/NxWidgets/libnxwidgets/include/cbuttonarray.hxx index d5f8be449..487a6cb9f 100644 --- a/NxWidgets/libnxwidgets/include/cbuttonarray.hxx +++ b/NxWidgets/libnxwidgets/include/cbuttonarray.hxx @@ -80,7 +80,7 @@ namespace NXWidgets 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_cursorOn; /**< Cursor on; highlighted button displayed */ bool m_cursorChange; /**< True: Redraw cursor button only */ nxgl_coord_t m_buttonWidth; /**< The width of one button in pixels */ nxgl_coord_t m_buttonHeight; /**< The height of one button in rows */ diff --git a/NxWidgets/libnxwidgets/include/cimage.hxx b/NxWidgets/libnxwidgets/include/cimage.hxx index 47f4d557f..a1c282393 100644 --- a/NxWidgets/libnxwidgets/include/cimage.hxx +++ b/NxWidgets/libnxwidgets/include/cimage.hxx @@ -109,8 +109,9 @@ namespace NXWidgets class CImage : public CNxWidget { protected: - FAR IBitmap *m_bitmap; /**< Source bitmap image */ - struct nxgl_point_s m_origin; /**< Origin for offset image display position */ + FAR IBitmap *m_bitmap; /**< Source bitmap image */ + struct nxgl_point_s m_origin; /**< Origin for offset image display position */ + bool m_highlighted; /**< Image is highlighted */ /** * Draw the area of this widget that falls within the clipping region. @@ -191,6 +192,17 @@ namespace NXWidgets */ void setImageTop(nxgl_coord_t row); + + /** + * Control the highlight state. + * + * @param highlightOn True(1), the image will be highlighted + */ + + inline void highlight(bool highlightOn) + { + m_highlighted = highlightOn; + } }; } diff --git a/NxWidgets/libnxwidgets/include/crlepalettebitmap.hxx b/NxWidgets/libnxwidgets/include/crlepalettebitmap.hxx index 2b1e4f065..451b472f4 100644 --- a/NxWidgets/libnxwidgets/include/crlepalettebitmap.hxx +++ b/NxWidgets/libnxwidgets/include/crlepalettebitmap.hxx @@ -84,7 +84,7 @@ namespace NXWidgets uint8_t nlut; /**< Number of colors in the Look-Up Table (LUT) */ nxgl_coord_t width; /**< Width in pixels */ nxgl_coord_t height; /**< Height in rows */ - FAR const void *lut; /**< Pointer to the beginning of the Look-Up Table (LUT) */ + FAR const void *lut[2]; /**< Pointers to the beginning of the Look-Up Tables (LUTs) */ /** * The pointer to the beginning of the RLE data @@ -113,6 +113,7 @@ namespace NXWidgets nxgl_coord_t m_row; /**< Logical row number */ nxgl_coord_t m_col; /**< Logical column number */ uint8_t m_remaining; /**< Number of bytes remaining in current entry */ + FAR const void *m_lut; /**< The selected LUT */ FAR const struct SRlePaletteBitmapEntry *m_rle; /**< RLE entry being processed */ /** @@ -237,7 +238,16 @@ namespace NXWidgets const nxgl_coord_t getStride(void) const; /** - * Get one row from the bit map image. + * Use the colors associated with a selected image. + * + * @param selected. true: Use colors for a selected widget, + * false: Use normal (default) colors. + */ + + void setSelected(bool selected); + + /** + * Get one row from the bit map image using the selected colors. * * @param x The offset into the row to get * @param y The row number to get diff --git a/NxWidgets/libnxwidgets/include/ibitmap.hxx b/NxWidgets/libnxwidgets/include/ibitmap.hxx index c4bb3b5ac..5eaa5b3c9 100644 --- a/NxWidgets/libnxwidgets/include/ibitmap.hxx +++ b/NxWidgets/libnxwidgets/include/ibitmap.hxx @@ -143,7 +143,16 @@ namespace NXWidgets virtual const nxgl_coord_t getStride(void) const = 0; /** - * Get one row from the bit map image. + * Use the colors associated with a selected image. + * + * @param selected. true: Use colors for a selected widget, + * false: Use normal (default) colors. + */ + + virtual void setSelected(bool selected) = 0; + + /** + * Get one row from the bit map image using the selected colors. * * @param x The offset into the row to get * @param y The row number to get diff --git a/NxWidgets/libnxwidgets/src/cimage.cxx b/NxWidgets/libnxwidgets/src/cimage.cxx index 5e46b801b..c905737fd 100644 --- a/NxWidgets/libnxwidgets/src/cimage.cxx +++ b/NxWidgets/libnxwidgets/src/cimage.cxx @@ -156,7 +156,7 @@ void CImage::getPreferredDimensions(CRect &rect) const * @param port The CGraphicsPort to draw to. * @see redraw() */ - + void CImage::drawContents(CGraphicsPort *port) { // Get the the drawable region @@ -178,6 +178,10 @@ void CImage::drawContents(CGraphicsPort *port) bitmap.stride = (rect.getWidth() * m_bitmap->getBitsPerPixel()) >> 3; bitmap.data = buffer; + // Select the correct colorization + + m_bitmap->setSelected(isClicked() || m_highlighted); + // This is the number of rows that we can draw at the top of the display nxgl_coord_t nTopRows = m_bitmap->getHeight() - m_origin.y; @@ -261,12 +265,21 @@ void CImage::drawContents(CGraphicsPort *port) // And put these on the display - port->drawBitmap(rect.getX(), displayRow, rect.getWidth(), 1, - &bitmap, 0, 0); + if (isEnabled()) + { + port->drawBitmap(rect.getX(), displayRow, rect.getWidth(), 1, + &bitmap, 0, 0); + } + else + { + port->drawBitmapGreyScale(rect.getX(),displayRow, + rect.getWidth(), 1, + &bitmap, 0, 0); + } } } - // Are we going to draw any rows at the top of the display? + // Are we going to draw any rows at the bottom of the display? if (nTopRows < rect.getHeight()) { @@ -286,8 +299,18 @@ void CImage::drawContents(CGraphicsPort *port) { // Put the padded row on the display - port->drawBitmap(rect.getX(), displayRow, rect.getWidth(), 1, - &bitmap, 0, 0); + if (isEnabled()) + { + port->drawBitmap(rect.getX(), displayRow, + rect.getWidth(), 1, + &bitmap, 0, 0); + } + else + { + port->drawBitmapGreyScale(rect.getX(),displayRow, + rect.getWidth(), 1, + &bitmap, 0, 0); + } } } @@ -304,11 +327,34 @@ void CImage::drawContents(CGraphicsPort *port) void CImage::drawBorder(CGraphicsPort *port) { - if (!isBorderless()) + // Stop drawing if the widget indicates it should not have an outline + + if (isBorderless()) + { + return; + } + + // Work out which colors to use + + nxgl_coord_t color1; + nxgl_coord_t color2; + + if (isClicked()) + { + // Bevelled into the screen + + color1 = getShadowEdgeColor(); + color2 = getShineEdgeColor(); + } + else { - port->drawBevelledRect(getX(), getY(), getWidth(), getHeight(), - getShadowEdgeColor(), getShineEdgeColor()); + // Bevelled out of the screen + + color1 = getShineEdgeColor(); + color2 = getShadowEdgeColor(); } + + port->drawBevelledRect(getX(), getY(), getWidth(), getHeight(), color1, color2); } /** diff --git a/NxWidgets/libnxwidgets/src/crlepalettebitmap.cxx b/NxWidgets/libnxwidgets/src/crlepalettebitmap.cxx index 25e9473ed..79a614349 100644 --- a/NxWidgets/libnxwidgets/src/crlepalettebitmap.cxx +++ b/NxWidgets/libnxwidgets/src/crlepalettebitmap.cxx @@ -101,6 +101,7 @@ using namespace NXWidgets; CRlePaletteBitmap::CRlePaletteBitmap(const struct SRlePaletteBitmap *bitmap) { m_bitmap = bitmap; + m_lut = bitmap->lut[0]; startOfImage(); } @@ -162,7 +163,19 @@ const nxgl_coord_t CRlePaletteBitmap::getStride(void) const } /** - * Get one row from the bit map image. + * Use the colors associated with a selected image. + * + * @param selected. true: Use colors for a selected widget, + * false: Use normal (default) colors. + */ + +void CRlePaletteBitmap::setSelected(bool selected) +{ + m_lut = m_bitmap->lut[selected ? 1 : 0]; +} + +/** + * Get one row from the bit map image using the selected LUT. * * @param x The offset into the row to get * @param y The row number to get @@ -337,7 +350,7 @@ void CRlePaletteBitmap::copyColor(nxgl_coord_t npixels, FAR void *data) { // Right now, only a single pixel depth is supported - nxwidget_pixel_t *nxlut = (nxwidget_pixel_t *)m_bitmap->lut; + nxwidget_pixel_t *nxlut = (nxwidget_pixel_t *)m_lut; nxwidget_pixel_t color = nxlut[m_rle->lookup]; // Copy the requested pixels diff --git a/NxWidgets/libnxwidgets/src/glyph_nxlogo.cxx b/NxWidgets/libnxwidgets/src/glyph_nxlogo.cxx index 1b3aab143..5f1bd7dbf 100644 --- a/NxWidgets/libnxwidgets/src/glyph_nxlogo.cxx +++ b/NxWidgets/libnxwidgets/src/glyph_nxlogo.cxx @@ -3445,6 +3445,9 @@ const struct SRlePaletteBitmap NXWidgets::g_nuttxBitmap = BITMAP_NLUTCODES, // nlut - Number of colors in the lLook-Up Table (LUT) 160, // width - Width in pixels 160, // height - Height in rows - g_nuttxLut, // lut - Pointer to the beginning of the Look-Up Table (LUT) + { // lut - Pointer to the beginning of the Look-Up Table (LUT) + g_nuttxLut, // Index 0: Unselected LUT + g_nuttxLut, // Index 1: Selected LUT + }, g_nuttxRleEntries // data - Pointer to the beginning of the RLE data }; -- cgit v1.2.3