diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-07-14 20:37:39 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-07-14 20:37:39 -0600 |
commit | daaa3cba9f05b90c3ee082b0bc03a34b6fdbca5a (patch) | |
tree | 53b1f3c159d80c0cfeab208a7cc3703eb3e52810 /NxWidgets/libnxwidgets | |
parent | c2d5265c7af8a6caafffe485e6a2a1c001ed2fee (diff) | |
download | nuttx-daaa3cba9f05b90c3ee082b0bc03a34b6fdbca5a.tar.gz nuttx-daaa3cba9f05b90c3ee082b0bc03a34b6fdbca5a.tar.bz2 nuttx-daaa3cba9f05b90c3ee082b0bc03a34b6fdbca5a.zip |
NxWidget::CImage: Now supports helper methods to align images in the widget region
Diffstat (limited to 'NxWidgets/libnxwidgets')
-rw-r--r-- | NxWidgets/libnxwidgets/include/cimage.hxx | 66 | ||||
-rw-r--r-- | NxWidgets/libnxwidgets/src/cimage.cxx | 95 |
2 files changed, 159 insertions, 2 deletions
diff --git a/NxWidgets/libnxwidgets/include/cimage.hxx b/NxWidgets/libnxwidgets/include/cimage.hxx index 438ea7267..9daf9f260 100644 --- a/NxWidgets/libnxwidgets/include/cimage.hxx +++ b/NxWidgets/libnxwidgets/include/cimage.hxx @@ -233,6 +233,39 @@ namespace NXWidgets void setImageLeft(nxgl_coord_t column); /** + * Align the image at the left of the widget region. + * + * NOTE: The CImage widget does not support any persistent alignment + * attribute (at least not at the moment). As a result, this alignment + * can be lost if the image is changed or if the widget is resized. + */ + + inline void alignHorizontalLeft(void) + { + setImageLeft(0); + } + + /** + * Align the image at the left of the widget region. + * + * NOTE: The CImage widget does not support any persistent alignment + * attribute (at least not at the moment). As a result, this alignment + * can be lost if the image is changed or if the widget is resized. + */ + + void alignHorizontalCenter(void); + + /** + * Align the image at the left of the widget region. + * + * NOTE: The CImage widget does not support any persistent alignment + * attribute (at least not at the moment). As a result, this alignment + * can be lost if the image is changed or if the widget is resized. + */ + + void alignHorizontalRight(void); + + /** * 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 @@ -242,6 +275,39 @@ namespace NXWidgets void setImageTop(nxgl_coord_t row); /** + * Align the image at the top of the widget region. + * + * NOTE: The CImage widget does not support any persistent alignment + * attribute (at least not at the moment). As a result, this alignment + * can be lost if the image is changed or if the widget is resized. + */ + + inline void alignVerticalTop(void) + { + setImageTop(0); + } + + /** + * Align the image at the middle of the widget region. + * + * NOTE: The CImage widget does not support any persistent alignment + * attribute (at least not at the moment). As a result, this alignment + * can be lost if the image is changed or if the widget is resized. + */ + + void alignVerticalCenter(void); + + /** + * Align the image at the left of the widget region. + * + * NOTE: The CImage widget does not support any persistent alignment + * attribute (at least not at the moment). As a result, this alignment + * can be lost if the image is changed or if the widget is resized. + */ + + void alignVerticalBottom(void); + + /** * Control the highlight state. * * @param highlightOn True(1), the image will be highlighted diff --git a/NxWidgets/libnxwidgets/src/cimage.cxx b/NxWidgets/libnxwidgets/src/cimage.cxx index 043bc1f6f..eb7e5157f 100644 --- a/NxWidgets/libnxwidgets/src/cimage.cxx +++ b/NxWidgets/libnxwidgets/src/cimage.cxx @@ -455,13 +455,58 @@ void CImage::onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y) void CImage::setImageLeft(nxgl_coord_t column) { - if (m_bitmap && column >= 0 && column < getWidth()) + // Get the the drawable region + + CRect rect; + getRect(rect); + + if (m_bitmap && column >= 0 && column < rect.getWidth()) { m_origin.x = column; } } /** + * Align the image at the left of the widget region. + * + * NOTE: The CImage widget does not support any persistent alignment + * attribute (at least not at the moment). As a result, this alignment + * can be lost if the image is changed or if the widget is resized. + */ + +void CImage::alignHorizontalCenter(void) +{ + // Get the the drawable region + + CRect rect; + getRect(rect); + + // Center the image + + setImageLeft((rect.getWidth() - m_bitmap->getWidth()) >> 1); +} + +/** + * Align the image at the left of the widget region. + * + * NOTE: The CImage widget does not support any persistent alignment + * attribute (at least not at the moment). As a result, this alignment + * can be lost if the image is changed or if the widget is resized. + */ + +void CImage::alignHorizontalRight(void) +{ + // Get the the drawable region + + CRect rect; + getRect(rect); + + // Position the image at the right of the widget region + + setImageLeft(rect.getWidth() - m_bitmap->getWidth()); +} + +/** * 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 @@ -472,9 +517,55 @@ void CImage::setImageLeft(nxgl_coord_t column) void CImage::setImageTop(nxgl_coord_t row) { - if (m_bitmap && row >= 0 && row < getHeight()) + // Get the the drawable region + + CRect rect; + getRect(rect); + + // Check the attempted Y position + + if (m_bitmap && row >= 0 && row < rect.getHeight()) { m_origin.y = row; } } +/** + * Align the image at the middle of the widget region. + * + * NOTE: The CImage widget does not support any persistent alignment + * attribute (at least not at the moment). As a result, this alignment + * can be lost if the image is changed or if the widget is resized. + */ + +void CImage::alignVerticalCenter(void) +{ + // Get the the drawable region + + CRect rect; + getRect(rect); + + // Center the image + + setImageTop((rect.getHeight() - m_bitmap->getHeight()) >> 1); +} + +/** + * Align the image at the left of the widget region. + * + * NOTE: The CImage widget does not support any persistent alignment + * attribute (at least not at the moment). As a result, this alignment + * can be lost if the image is changed or if the widget is resized. + */ + +void CImage::alignVerticalBottom(void) +{ + // Get the the drawable region + + CRect rect; + getRect(rect); + + // Position the image at the bottom of the widget region + + setImageTop(rect.getHeight() - m_bitmap->getHeight()); +} |