diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-07-14 20:09:58 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-07-14 20:09:58 -0600 |
commit | 4a2bcb35eebba45016dd71e8fc426fd616699084 (patch) | |
tree | a71830113b1e5fd3897d0646c5e21d33d2d810af /NxWidgets/libnxwidgets/src | |
parent | 47e8860af751e5596553e73385744666aa93837a (diff) | |
download | nuttx-4a2bcb35eebba45016dd71e8fc426fd616699084.tar.gz nuttx-4a2bcb35eebba45016dd71e8fc426fd616699084.tar.bz2 nuttx-4a2bcb35eebba45016dd71e8fc426fd616699084.zip |
CNxWidgets::CImage: Fix setImageLeft and setImageTop methods.
Diffstat (limited to 'NxWidgets/libnxwidgets/src')
-rw-r--r-- | NxWidgets/libnxwidgets/src/cimage.cxx | 119 |
1 files changed, 62 insertions, 57 deletions
diff --git a/NxWidgets/libnxwidgets/src/cimage.cxx b/NxWidgets/libnxwidgets/src/cimage.cxx index eaf4e3005..043bc1f6f 100644 --- a/NxWidgets/libnxwidgets/src/cimage.cxx +++ b/NxWidgets/libnxwidgets/src/cimage.cxx @@ -122,7 +122,7 @@ CImage::CImage(CWidgetControl *pWidgetControl, nxgl_coord_t x, nxgl_coord_t y, m_highlighted = false; - // Position the top/lef corner of the bitmap in the top/left corner of the display + // Position the top/left corner of the bitmap in the top/left corner of the display m_origin.x = 0; m_origin.y = 0; @@ -203,73 +203,79 @@ void CImage::drawContents(CGraphicsPort *port) m_bitmap->setSelected(isClicked() || m_highlighted); - // This is the number of rows that we can draw at the top of the display + // This is the end row + 1 that we can write into - nxgl_coord_t nTopRows = m_bitmap->getHeight() - m_origin.y; - if (nTopRows > rect.getHeight()) - { - nTopRows = rect.getHeight(); - } - else if (nTopRows < 0) + nxgl_coord_t bottomRow = m_bitmap->getHeight() + m_origin.y; + if (bottomRow > rect.getHeight()) { - nTopRows = 0; + bottomRow = rect.getHeight(); } - // This the starting row in the bitmap image where we will begin drawing. + // Apply padding entire line buffer. - nxgl_coord_t imageRow = m_origin.y; + FAR nxwidget_pixel_t *ptr = buffer; + nxwidget_pixel_t backColor = getBackgroundColor(); + + for (int column = 0; column < rect.getWidth(); column++) + { + *ptr++ = backColor; + } // This the starting row in the display image where we will begin drawing. - nxgl_coord_t displayRow = rect.getY(); + nxgl_coord_t destRow = rect.getY(); - // Are we going to draw any rows at the top of the display? + // Draw any padded rows at the top of the widget before this - if (nTopRows > 0) + for (int padRow = 0; padRow < m_origin.y; padRow++, destRow++) { - // This is the number of columns that we can draw on the left side of - // the display - - nxgl_coord_t nLeftPixels = m_bitmap->getWidth() - m_origin.x; + // Put the padded row on the display - // This is the number of rows that we have to pad on the right if the display - // width is wider than the image width - -#if 0 // Not used - nxgl_coord_t nRightPad; - if (nLeftPixels >= rect.getWidth()) + if (isEnabled()) { - nRightPad = 0; + port->drawBitmap(rect.getX(), destRow, rect.getWidth(), 1, + &bitmap, 0, 0); } else { - nRightPad = rect.getWidth() - nLeftPixels; + port->drawBitmapGreyScale(rect.getX(), destRow, rect.getWidth(), + 1, &bitmap, 0, 0); } -#endif + } - // Apply the padding to the right hand side + // This is the number of rows that we can draw at the top of the display - FAR nxwidget_pixel_t *ptr = &buffer[nLeftPixels]; - nxwidget_pixel_t backColor = getBackgroundColor(); + nxgl_coord_t nTopRows = bottomRow - m_origin.y; - for (int column = nLeftPixels; column < rect.getWidth(); column++) + // Are we going to draw any rows at the top of the display? + + if (nTopRows > 0) + { + // This is the end column + 1 that we can write into + + nxgl_coord_t rightColumn = m_bitmap->getWidth() + m_origin.x; + if (rightColumn > rect.getWidth()) { - *ptr++ = backColor; + rightColumn = rect.getWidth(); } - // The is the row number of the first row that we cannot draw into + // This is the number of columns that we can draw on the left side of + // the display at the offset m_origin.x. - nxgl_coord_t lastTopRow = nTopRows + m_origin.y; + nxgl_coord_t nLeftPixels = rightColumn - m_origin.x; - // Now draw the rows from the offset position + // This is the row number of the first row that we cannot draw into + + nxgl_coord_t lastTopRow = nTopRows + destRow; - for (; imageRow < lastTopRow; imageRow++, displayRow++) + for (int srcRow = 0; destRow < lastTopRow; srcRow++, destRow++) { - // Get the graphics data for the right hand side of this row + // Read the graphics data for the left hand side of this row and + // place it in the row buffer at offset origin.x. - if (!m_bitmap->getRun(m_origin.x, imageRow, nLeftPixels, buffer)) + if (!m_bitmap->getRun(0, srcRow, nLeftPixels, &buffer[m_origin.x])) { - gvdbg("IBitmap::getRun failed at image row\n", imageRow); + gvdbg("IBitmap::getRun failed at image row\n", srcRow); delete buffer; return; } @@ -277,7 +283,7 @@ void CImage::drawContents(CGraphicsPort *port) // Replace any transparent pixels with the background color. // Then we can use the faster opaque drawBitmap() function. - ptr = buffer; + ptr = &buffer[m_origin.x]; for (int i = 0; i < nLeftPixels; i++, ptr++) { if (*ptr == CONFIG_NXWIDGETS_TRANSPARENT_COLOR) @@ -290,14 +296,13 @@ void CImage::drawContents(CGraphicsPort *port) if (isEnabled()) { - port->drawBitmap(rect.getX(), displayRow, rect.getWidth(), 1, + port->drawBitmap(rect.getX(), destRow, rect.getWidth(), 1, &bitmap, 0, 0); } else { - port->drawBitmapGreyScale(rect.getX(), displayRow, - rect.getWidth(), 1, - &bitmap, 0, 0); + port->drawBitmapGreyScale(rect.getX(), destRow, + rect.getWidth(), 1, &bitmap, 0, 0); } } } @@ -308,9 +313,7 @@ void CImage::drawContents(CGraphicsPort *port) { // Pad the entire row - FAR nxwidget_pixel_t *ptr = buffer; - nxwidget_pixel_t backColor = getBackgroundColor(); - + ptr = buffer; for (int column = 0; column < rect.getWidth(); column++) { *ptr++ = backColor; @@ -318,21 +321,19 @@ void CImage::drawContents(CGraphicsPort *port) // Now draw the rows from the offset position - for (; displayRow < rect.getHeight(); displayRow++) + for (; destRow < rect.getHeight(); destRow++) { // Put the padded row on the display if (isEnabled()) { - port->drawBitmap(rect.getX(), displayRow, - rect.getWidth(), 1, + port->drawBitmap(rect.getX(), destRow, rect.getWidth(), 1, &bitmap, 0, 0); } else { - port->drawBitmapGreyScale(rect.getX(),displayRow, - rect.getWidth(), 1, - &bitmap, 0, 0); + port->drawBitmapGreyScale(rect.getX(), destRow, + rect.getWidth(), 1, &bitmap, 0, 0); } } } @@ -445,14 +446,16 @@ void CImage::onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y) /** * 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. + * 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 + * + * REVISIT: m_origin.x should be permitted to go negative. */ void CImage::setImageLeft(nxgl_coord_t column) { - if (m_bitmap && column > 0 && column <= m_bitmap->getWidth()) + if (m_bitmap && column >= 0 && column < getWidth()) { m_origin.x = column; } @@ -463,13 +466,15 @@ void CImage::setImageLeft(nxgl_coord_t column) * 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 + * + * REVISIT: m_origin.y should be permitted to go negative. */ void CImage::setImageTop(nxgl_coord_t row) { - if (m_bitmap && row > 0 && row <= m_bitmap->getHeight()) + if (m_bitmap && row >= 0 && row < getHeight()) { - m_origin.x = row; + m_origin.y = row; } } |