diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-12-21 20:09:32 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-12-21 20:09:32 +0000 |
commit | 1b917134adffafb33057be34683b5f73807aeca8 (patch) | |
tree | a548cfe35af25a0d7b7b3a8a304784c334aecdb6 /NxWidgets/libnxwidgets | |
parent | 2e885817755dbb96fa4183a312ea181b28bb70b1 (diff) | |
download | px4-nuttx-1b917134adffafb33057be34683b5f73807aeca8.tar.gz px4-nuttx-1b917134adffafb33057be34683b5f73807aeca8.tar.bz2 px4-nuttx-1b917134adffafb33057be34683b5f73807aeca8.zip |
Patches from Petteri Aimonen (plus a few other things)
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5448 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'NxWidgets/libnxwidgets')
-rw-r--r-- | NxWidgets/libnxwidgets/include/cgraphicsport.hxx | 34 | ||||
-rw-r--r-- | NxWidgets/libnxwidgets/include/cscrollingpanel.hxx | 3 | ||||
-rw-r--r-- | NxWidgets/libnxwidgets/src/ccyclebutton.cxx | 19 | ||||
-rw-r--r-- | NxWidgets/libnxwidgets/src/cgraphicsport.cxx | 108 | ||||
-rw-r--r-- | NxWidgets/libnxwidgets/src/clabel.cxx | 23 | ||||
-rw-r--r-- | NxWidgets/libnxwidgets/src/cscrollingpanel.cxx | 40 |
6 files changed, 174 insertions, 53 deletions
diff --git a/NxWidgets/libnxwidgets/include/cgraphicsport.hxx b/NxWidgets/libnxwidgets/include/cgraphicsport.hxx index b9fbc4d41..d3d9e6114 100644 --- a/NxWidgets/libnxwidgets/include/cgraphicsport.hxx +++ b/NxWidgets/libnxwidgets/include/cgraphicsport.hxx @@ -111,6 +111,22 @@ namespace NXWidgets nxgl_mxpixel_t m_backColor; /**< The background color to use */ #endif + /** + * The underlying implementation for drawText functions + * @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 background Color to use for background if transparent is false. + * @param transparent Whether to fill the background. + */ + void drawText(struct nxgl_point_s *pos, CRect *bound, CNxFont *font, + const CNxString &string, int startIndex, int length, + nxgl_mxpixel_t background, bool transparent); + public: /** * Constructor. @@ -330,6 +346,24 @@ namespace NXWidgets const CNxString &string, int startIndex, int length); /** + * Draw a portion of a string to the window and fill the background + * in one go. + * @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 Foreground color + * @param background Background color + */ + + void drawText(struct nxgl_point_s *pos, CRect *bound, CNxFont *font, + const CNxString &string, int startIndex, int length, + nxgl_mxpixel_t color, nxgl_mxpixel_t background); + + /** * Draw an opaque bitmap to the window. * * @param x The window-relative x coordinate to draw the bitmap to. diff --git a/NxWidgets/libnxwidgets/include/cscrollingpanel.hxx b/NxWidgets/libnxwidgets/include/cscrollingpanel.hxx index 90dcc1ac9..b27176e2f 100644 --- a/NxWidgets/libnxwidgets/include/cscrollingpanel.hxx +++ b/NxWidgets/libnxwidgets/include/cscrollingpanel.hxx @@ -168,9 +168,10 @@ namespace NXWidgets * * @param dx The horizontal distance to scroll. * @param dy The vertical distance to scroll. + * @param do_redraw Redraw widgets after moving. */ - void scrollChildren(int32_t dx, int32_t dy); + void scrollChildren(int32_t dx, int32_t dy, bool do_redraw); /** * Destructor. diff --git a/NxWidgets/libnxwidgets/src/ccyclebutton.cxx b/NxWidgets/libnxwidgets/src/ccyclebutton.cxx index b5f96683d..0fdbba73c 100644 --- a/NxWidgets/libnxwidgets/src/ccyclebutton.cxx +++ b/NxWidgets/libnxwidgets/src/ccyclebutton.cxx @@ -309,30 +309,21 @@ void CCycleButton::drawContents(CGraphicsPort *port) CRect rect; getRect(rect); - nxgl_coord_t glyphSpace = m_borderSize.left - 1; nxgl_coord_t glyphYOffset = (rect.getHeight() - g_cycle.height) >> 1; nxwidget_pixel_t textColor; - nxwidget_pixel_t separatorLeftColor; - nxwidget_pixel_t separatorRightColor; if (!isEnabled()) { textColor = getDisabledTextColor(); - separatorLeftColor = getShadowEdgeColor(); - separatorRightColor = getShineEdgeColor(); } else if (!isClicked()) { textColor = getEnabledTextColor(); - separatorLeftColor = getShadowEdgeColor(); - separatorRightColor = getShineEdgeColor(); } else { textColor = getSelectedTextColor(); - separatorLeftColor = getShineEdgeColor(); - separatorRightColor = getShadowEdgeColor(); } // Draw cycle glyph @@ -341,16 +332,6 @@ void CCycleButton::drawContents(CGraphicsPort *port) g_cycle.width, g_cycle.height, &g_cycle, 0, 0, CONFIG_NXWIDGETS_TRANSPARENT_COLOR); - // Draw separator - - nxgl_coord_t x = getX() + glyphSpace + g_cycle.width; - nxgl_coord_t y = getY(); - nxgl_coord_t w = glyphSpace + g_cycle.width; - nxgl_coord_t h = rect.getHeight() - 1; - - port->drawLine(x, y, w, h, separatorLeftColor); - port->drawLine(x+1, y, w+1, h, separatorRightColor); - // Only draw text if option is selected if (m_options.getSelectedItem() != NULL) diff --git a/NxWidgets/libnxwidgets/src/cgraphicsport.cxx b/NxWidgets/libnxwidgets/src/cgraphicsport.cxx index d43f3bdfa..73f2352eb 100644 --- a/NxWidgets/libnxwidgets/src/cgraphicsport.cxx +++ b/NxWidgets/libnxwidgets/src/cgraphicsport.cxx @@ -654,6 +654,55 @@ void CGraphicsPort::drawText(struct nxgl_point_s *pos, CRect *bound, CNxFont *font, const CNxString &string, int startIndex, int length) { + drawText(pos, bound, font, string, startIndex, length, 0, true); +} + +/** + * Draw a portion of a string to the window and fill the background + * in one go. + * @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 Foreground color + * @param background Background color + */ + +void CGraphicsPort::drawText(struct nxgl_point_s *pos, CRect *bound, + CNxFont *font, const CNxString &string, + int startIndex, int length, + nxgl_mxpixel_t color, + nxgl_mxpixel_t background) +{ + nxgl_mxpixel_t savedColor = font->getColor(); + font->setColor(color); + + drawText(pos, bound, font, string, startIndex, length, background, false); + + font->setColor(savedColor); +} + +/** + * The underlying implementation for drawText functions + * @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 background Color to use for background if transparent is false. + * @param transparent Whether to fill the background. + */ +void CGraphicsPort::drawText(struct nxgl_point_s *pos, CRect *bound, + CNxFont *font, const CNxString &string, + int startIndex, int length, + nxgl_mxpixel_t background, + bool transparent) +{ // Verify index and length int stringLength = string.getLength(); @@ -668,6 +717,16 @@ void CGraphicsPort::drawText(struct nxgl_point_s *pos, CRect *bound, endIndex = stringLength; } +#ifdef CONFIG_NX_WRITEONLY + if (transparent) + { + // Can't render transparently without reading memory. + + transparent = false; + background = m_backColor; + } +#endif + // Allocate a bit of memory to hold the largest rendered font unsigned int bmWidth = ((unsigned int)font->getMaxWidth() * CONFIG_NXWIDGETS_BPP + 7) >> 3; @@ -680,7 +739,7 @@ void CGraphicsPort::drawText(struct nxgl_point_s *pos, CRect *bound, struct nxgl_rect_s boundingBox; bound->getNxRect(&boundingBox); - + // Loop setup struct SBitmap bitmap; @@ -707,16 +766,12 @@ void CGraphicsPort::drawText(struct nxgl_point_s *pos, CRect *bound, // Does the letter have height? Spaces have width, but no height - if (metrics.height > 0) + if (metrics.height > 0 || !transparent) { - // Get the height of the font - - nxgl_coord_t fontHeight = (nxgl_coord_t)(metrics.height + metrics.yoffset); - // Set the current, effective size of the bitmap bitmap.width = fontWidth; - bitmap.height = fontHeight; + bitmap.height = bmHeight; bitmap.stride = (fontWidth * bitmap.bpp + 7) >> 3; // Describe the destination of the font as a bounding box @@ -725,7 +780,7 @@ void CGraphicsPort::drawText(struct nxgl_point_s *pos, CRect *bound, dest.pt1.x = pos->x; dest.pt1.y = pos->y; dest.pt2.x = pos->x + fontWidth - 1; - dest.pt2.y = pos->y + fontHeight - 1; + dest.pt2.y = pos->y + bmHeight - 1; // Get the interection of the font box and the bounding box @@ -737,25 +792,28 @@ void CGraphicsPort::drawText(struct nxgl_point_s *pos, CRect *bound, if (!nxgl_nullrect(&intersection)) { - // Initialize the bitmap memory by reading from the display. The - // font renderer always renders the fonts on a transparent background. - // Sometimes a solid background works, sometimes not. But reading - // from graphics memory always works. - -#ifdef CONFIG_NX_WRITEONLY - // Set the glyph memory to the background color - - nxwidget_pixel_t *bmPtr = (nxwidget_pixel_t *)bitmap.data; - unsigned int npixels = fontWidth * fontHeight; - for (unsigned int j = 0; j < npixels; j++) + // If we have been given a background color, use it to fill the array. + // Otherwise initialize the bitmap memory by reading from the display. + // The font renderer always renders the fonts on a transparent background. + + if (!transparent) { - *bmPtr++ = m_backColor; + // Set the glyph memory to the background color + + nxwidget_pixel_t *bmPtr = (nxwidget_pixel_t *)bitmap.data; + unsigned int npixels = fontWidth * bmHeight; + for (unsigned int j = 0; j < npixels; j++) + { + *bmPtr++ = background; + } + } + else + { + // Read the current contents of the destination into the glyph memory + + m_pNxWnd->getRectangle(&dest, &bitmap); } -#else - // Read the current contents of the destination into the glyph memory - m_pNxWnd->getRectangle(&dest, &bitmap); -#endif // Render the font into the initialized bitmap font->drawChar(&bitmap, letter); @@ -827,7 +885,7 @@ void CGraphicsPort::move(nxgl_coord_t x, nxgl_coord_t y, rect.pt1.x = x; rect.pt1.y = y; rect.pt2.x = x + width - 1; - rect.pt2.y = y = height -1; + rect.pt2.y = y + height - 1; struct nxgl_point_s offset; offset.x = deltaX; diff --git a/NxWidgets/libnxwidgets/src/clabel.cxx b/NxWidgets/libnxwidgets/src/clabel.cxx index 4c7ea3554..be4fe902d 100644 --- a/NxWidgets/libnxwidgets/src/clabel.cxx +++ b/NxWidgets/libnxwidgets/src/clabel.cxx @@ -303,8 +303,10 @@ void CLabel::drawContents(CGraphicsPort *port) // Draw the background (excluding the border) +#ifdef CONFIG_NXWIDGETS_FLICKERFREE port->drawFilledRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight(), backColor); +#endif // Get the X/Y position of the text within the Label @@ -312,10 +314,27 @@ void CLabel::drawContents(CGraphicsPort *port) pos.x = rect.getX() + m_align.x; pos.y = rect.getY() + m_align.y; - // Add the text using the selected color +#ifdef CONFIG_NXWIDGETS_FLICKERFREE + CNxFont* font = getFont(); + int height = font->getHeight(); + int width = font->getStringWidth(m_text); + + // Draw the background (excluding the border and the text area) + + port->drawFilledRect(rect.getX(), rect.getY(), + pos.x - rect.getX(), rect.getHeight(), backColor); // Left + port->drawFilledRect(pos.x + width, rect.getY(), + rect.getX2() - (pos.x + width) + 1, rect.getHeight(), backColor); // Right + port->drawFilledRect(pos.x, rect.getY(), + width, pos.y - rect.getY(), backColor); // Top + port->drawFilledRect(pos.x, pos.y + height, + width, rect.getY2() - (pos.y + height) + 1, backColor); // Bottom +#endif + + // Add the text using the selected color and background color port->drawText(&pos, &rect, getFont(), m_text, 0, m_text.getLength(), - textColor); + textColor, backColor); } /** diff --git a/NxWidgets/libnxwidgets/src/cscrollingpanel.cxx b/NxWidgets/libnxwidgets/src/cscrollingpanel.cxx index b7c507bb2..2541bb572 100644 --- a/NxWidgets/libnxwidgets/src/cscrollingpanel.cxx +++ b/NxWidgets/libnxwidgets/src/cscrollingpanel.cxx @@ -215,10 +215,13 @@ void CScrollingPanel::scroll(int32_t dx, int32_t dy) m_canvasY += dy; m_canvasX += dx; + // Move children but do not redraw. + + scrollChildren(dx, dy, false); + if (revealedRects.size() > 0) { // Draw background to revealed sections - // Children will redraw themselves in moveTo. for (int i = 0; i < revealedRects.size(); ++i) { @@ -231,6 +234,18 @@ void CScrollingPanel::scroll(int32_t dx, int32_t dy) port->drawFilledRect(rrect.getX(), rrect.getY(), rrect.getWidth(), rrect.getHeight(), getBackgroundColor()); + + // Check if any children intersect this region. + // If it does, it should be redrawn. + + for (int j = 0; j < m_children.size(); ++j) + { + CRect crect = m_children[j]->getBoundingBox(); + if (crect.intersects(rrect)) + { + m_children[j]->redraw(); + } + } } } } @@ -240,11 +255,11 @@ void CScrollingPanel::scroll(int32_t dx, int32_t dy) m_canvasY += dy; m_canvasX += dx; - } - - // Scroll all child widgets + + // Scroll all child widgets and redraw them - scrollChildren(dx, dy); + scrollChildren(dx, dy, true); + } // Notify event handlers @@ -332,9 +347,10 @@ void CScrollingPanel::onClick(nxgl_coord_t x, nxgl_coord_t y) * * @param dx The horizontal distance to scroll. * @param dy The vertical distance to scroll. + * @param do_redraw Redraw widgets after moving. */ -void CScrollingPanel::scrollChildren(int32_t dx, int32_t dy) +void CScrollingPanel::scrollChildren(int32_t dx, int32_t dy, bool do_redraw) { nxgl_coord_t widgetX = 0; nxgl_coord_t widgetY = 0; @@ -345,8 +361,20 @@ void CScrollingPanel::scrollChildren(int32_t dx, int32_t dy) for (int32_t i = 0; i < m_children.size(); i++) { widget = m_children[i]; + bool oldstate = widget->isDrawingEnabled(); + + if (!do_redraw) + { + widget->disableDrawing(); + } + widgetX = (widget->getX() - thisX) + dx; widgetY = (widget->getY() - thisY) + dy; widget->moveTo(widgetX, widgetY); + + if (!do_redraw && oldstate) + { + widget->enableDrawing(); + } } } |