⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpgwidget.c

📁 基于TI公司Cortex-M3的uart超级通信开发
💻 C
📖 第 1 页 / 共 3 页
字号:
                    (short)(usHeight - pJPEG->psJPEGInst->usHeight) / 2;
            sSrcY = 0;
            usHeight = pJPEG->psJPEGInst->usHeight;

        }
        else
        {
            //
            // The image is higher so we will fill the window (in the y
            // direction) and clip the image accordingly.
            //
            sDstY = sRect.sYMin;
            sSrcY = (pJPEG->psJPEGInst->usHeight - usHeight) / 2 -
                    pJPEG->psJPEGInst->sYOffset;

            //
            // Ensure we don't wrap the image due to an offset that is too
            // large.
            //
            sSrcY = (sSrcY < 0) ? 0 : sSrcY;
        }

        //
        // Start at the top left of the visible portion of the image (based on the
        // slider settings).
        //
        pusRow = pJPEG->psJPEGInst->pusImage + sSrcX +
                 (sSrcY * pJPEG->psJPEGInst->usWidth);

        //
        // Draw the rows of image data using direct calls to the display driver.
        //
        for(usRow = 0; usRow < usHeight; usRow++)
        {
            sCtx.pDisplay->pfnPixelDrawMultiple(
                                           sCtx.pDisplay->pvDisplayData,
                                           sDstX, sDstY + usRow, 0, usWidth, 16,
                                           (unsigned char *)pusRow, 0);
            pusRow += pJPEG->psJPEGInst->usWidth;
        }
    }

    //
    // See if the JPEG widget text style is selected.
    //
    if(pJPEG->ulStyle & JW_STYLE_TEXT)
    {
        //
        // Compute the center of the JPEG widget.
        //
        sDstX = (sRect.sXMin + ((sRect.sXMax - sRect.sXMin + 1) / 2));
        sDstY = (sRect.sYMin + ((sRect.sYMax - sRect.sYMin + 1) / 2));

        //
        // Draw the text centered in the middle of the JPEG widget.
        //
        GrContextFontSet(&sCtx, pJPEG->pFont);
        GrContextForegroundSet(&sCtx, pJPEG->ulTextColor);
        GrStringDrawCentered(&sCtx, pJPEG->pcText, -1, sDstX, sDstY, 0);
    }
}

//*****************************************************************************
//
// Handles changes required as a result of pointer movement.
//
// \param pJPEG is a pointer to the JPEG widget.
// \param lX is the X coordinate of the pointer event.
// \param lY is the Y coordinate of the pointer event.
//
// This function is called whenever a new pointer message is received which
// may indicate a change in position that requires us to scroll the JPEG image.
// If necessary, the OnScroll callback is made indicating the current offset
// of the image.  This function does not cause any repainting of the widget.
//
// \return Returns \b true if one or other of the image offsets changed as a
// result of the call or \b false if no changes were made.
//
//*****************************************************************************
static tBoolean
JPEGWidgetHandlePtrPos(tJPEGWidget *pJPEG, long lX, long lY)
{
    short sDeltaX, sDeltaY, sXOffset, sYOffset, sMaxX, sMaxY;
    tBoolean bRetcode;

    //
    // Assume nothing changes until we know otherwise.
    //
    bRetcode = false;

    //
    // Do we have an image?
    //
    if(!pJPEG->psJPEGInst->pusImage)
    {
        //
        // No image so just return immediately since there's nothing we can
        // scroll.
        //
        return(false);
    }

    //
    // Did the pointer position change?
    //
    if((pJPEG->psJPEGInst->sXStart == (short)lX) &&
       (pJPEG->psJPEGInst->sYStart == (short)lY))
    {
        //
        // The pointer position didn't change so we have nothing to do.
        //
        return(false);
    }

    //
    // Determine the new offset and apply it to the current total offset.
    //
    sDeltaX = (short)lX - pJPEG->psJPEGInst->sXStart;
    sDeltaY = (short)lY - pJPEG->psJPEGInst->sYStart;

    sXOffset = pJPEG->psJPEGInst->sXOffset + sDeltaX;
    sYOffset = pJPEG->psJPEGInst->sYOffset + sDeltaY;

    //
    // Now check to make sure that neither offset causes the image to move
    // out of the display window and limit them as required.
    //
    sDeltaX = (pJPEG->sBase.sPosition.sXMax - pJPEG->sBase.sPosition.sXMin) + 1;
    sDeltaY = (pJPEG->sBase.sPosition.sYMax - pJPEG->sBase.sPosition.sYMin) + 1;
    sMaxX = abs((pJPEG->psJPEGInst->usWidth - sDeltaX) / 2);
    sMaxY = abs((pJPEG->psJPEGInst->usHeight - sDeltaY) / 2);

    //
    // If the window is wider than the image, we don't allow any scrolling.
    //
    if(sMaxX < 0)
    {
        sXOffset = 0;
    }
    else
    {
        //
        // Make sure that the total offset is not too large for the image we
        // are displaying.
        //
        if(abs(sXOffset) > sMaxX)
        {
            sXOffset = (sXOffset < 0) ? -sMaxX : sMaxX;
        }
    }

    //
    // If the window is higher than the image, we don't allow any scrolling.
    //
    if(sMaxY < 0)
    {
        sYOffset = 0;
    }
    else
    {
        //
        // Make sure that the total offset is not too large for the image we
        // are displaying.
        //
        if(abs(sYOffset) > sMaxY)
        {
            sYOffset = (sYOffset < 0) ? -sMaxY : sMaxY;
        }
    }

    //
    // Now we've calculated the new image offset.  Is it different from the
    // previous offset?
    //
    if((sXOffset != pJPEG->psJPEGInst->sXOffset) ||
       (sYOffset != pJPEG->psJPEGInst->sYOffset))
    {
        //
        // Yes - something changed.
        //
        bRetcode = true;
        pJPEG->psJPEGInst->sXOffset = sXOffset;
        pJPEG->psJPEGInst->sYOffset = sYOffset;

        //
        // Do we need to make a callback?
        //
        if(pJPEG->pfnOnScroll)
        {
            pJPEG->pfnOnScroll((tWidget *)pJPEG, sXOffset, sYOffset);
        }
    }

    //
    // Remember where the pointer was the last time we looked at it.
    //
    pJPEG->psJPEGInst->sXStart = (short)lX;
    pJPEG->psJPEGInst->sYStart = (short)lY;

    //
    // Tell the caller whether anything changed or not.
    //
    return(bRetcode);
}

//*****************************************************************************
//
//! Handles pointer events for a JPEG widget.
//!
//! \param pWidget is a pointer to the JPEG widget.
//! \param ulMsg is the pointer event message.
//! \param lX is the X coordinate of the pointer event.
//! \param lY is the Y coordinate of the pointer event.
//!
//! This function processes pointer event messages for a JPEG widget.
//! This is called in response to a \b WIDGET_MSG_PTR_DOWN,
//! \b WIDGET_MSG_PTR_MOVE, and \b WIDGET_MSG_PTR_UP messages.
//!
//! If the widget has the \b #JW_STYLE_LOCKED flag set, the input is ignored
//! and this function returns immediately.
//!
//! If the widget is a button type (having style flag \b #JW_STYLE_BUTTON set),
//! and the mouse message is within the extent of the widget, the OnClick
//! callback function will be called on \b WIDGET_MSG_PTR_DOWN if style flag
//! \b #JW_STYLE_RELEASE_NOTIFY is not set or on \b WIDGET_MSG_PTR_UP if
//! \b #JW_STYLE_RELEASE_NOTIFY is set.
//!
//! If the widget is a canvas type (style flag \b #JW_STYLE_BUTTON not set),
//! pointer messages are used to control scrolling of the JPEG image within
//! the area of the widget.  In this case, any pointer movement that will cause
//! a change in the image position is reported to the client via the OnScroll
//! callback function.
//!
//! \return Returns 1 if the coordinates are within the extents of the widget
//! and 0 otherwise.
//
//*****************************************************************************
static long
JPEGWidgetClick(tWidget *pWidget, unsigned long ulMsg, long lX, long lY)
{
    tJPEGWidget *pJPEG;
    tBoolean bWithinWidget, bChanged;

    //
    // Check the arguments.
    //
    ASSERT(pWidget);

    //
    // Convert the generic widget pointer into a JPEG widget pointer.
    //
    pJPEG = (tJPEGWidget *)pWidget;

    //
    // Is the widget currently locked?
    //
    if(pJPEG->ulStyle & JW_STYLE_LOCKED)
    {
        //
        // We ignore this message and have the widget manager pass it back
        // up the tree.
        //
        return(0);
    }

    //
    // Does this event occur within the bounds of this widget?
    //
    bWithinWidget = GrRectContainsPoint(&pWidget->sPosition, lX, lY);

    //
    // Is this widget a button type?
    //
    if(pJPEG->ulStyle & JW_STYLE_BUTTON)
    {
        //
        // Yes - it's a button.  In this case, we only look for PTR_UP and
        // PTR_DOWN messages so that we can trigger the OnClick callback.
        //
        if(pJPEG->pfnOnClick)
        {
            //
            // Call the click callback if the screen has been pressed and we
            // are notifying on press or if the screen has been released and
            // we are notifying on release.
            //
            if(((ulMsg == WIDGET_MSG_PTR_UP) &&
               (pJPEG->ulStyle & JW_STYLE_RELEASE_NOTIFY)) ||
               ((ulMsg == WIDGET_MSG_PTR_DOWN) &&
               !(pJPEG->ulStyle & JW_STYLE_RELEASE_NOTIFY)))
            {
                pJPEG->pfnOnClick(pWidget);
            }
        }
    }
    else
    {
        //
        // This is a canvas style JPEG widget so we track mouse movement to
        // allow us to scroll the image based on touchscreen gestures.
        //
        switch(ulMsg)
        {
            //
            // The user has pressed the touchscreen.
            //
            case WIDGET_MSG_PTR_DOWN:
            {
                //
                // Did this event occur within the bounds of this particular
                // widget?
                //
                if(bWithinWidget)
                {
                    //
                    // Yes, it's our press so remember where it occurred and
                    // remember that the touchscreen is pressed.
                    //
                    pJPEG->ulStyle |= JW_STYLE_PRESSED;
                    pJPEG->psJPEGInst->sXStart = (short)lX;
                    pJPEG->psJPEGInst->sYStart = (short)lY;
                }

                break;
            }

            //
            // The touchscreen has been released.
            //
            case WIDGET_MSG_PTR_UP:
            {
                //
                // Remember that the touchscreen is no longer pressed.
                //
                pJPEG->ulStyle &= ~ JW_STYLE_PRESSED;

                //
                // Has the pointer moved since the last time we looked?  If so
                // handle it appropriately.
                //

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -