コード例 #1
0
ファイル: canvas.c プロジェクト: OS-Project/Divers
//*****************************************************************************
//
//! Draws the contents of a canvas.
//!
//! \param pWidget is a pointer to the canvas widget to be drawn.
//!
//! This function draws the contents of a canvas on the display.  This is
//! called in response to a \b #WIDGET_MSG_PAINT message.
//!
//! \return None.
//
//*****************************************************************************
static void
CanvasPaint(tWidget *pWidget)
{
    tCanvasWidget *pCanvas;
    tContext sCtx;
    int lX, lY, lSize;

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

    //
    // Convert the generic widget pointer into a canvas widget pointer.
    //
    pCanvas = (tCanvasWidget *)pWidget;

    //
    // Initialize a drawing context.
    //
    GrContextInit(&sCtx, pWidget->pDisplay);

    //
    // Initialize the clipping region based on the extents of this canvas.
    //
    GrContextClipRegionSet(&sCtx, &(pWidget->sPosition));

    //
    // See if the canvas fill style is selected.
    //
    if(pCanvas->ulStyle & CANVAS_STYLE_FILL)
    {
        //
        // Fill the canvas with the fill color.
        //
        GrContextForegroundSet(&sCtx, pCanvas->ulFillColor);
        GrRectFill(&sCtx, &(pWidget->sPosition));
    }

    //
    // See if the canvas outline style is selected.
    //
    if(pCanvas->ulStyle & CANVAS_STYLE_OUTLINE)
    {
        //
        // Outline the canvas with the outline color.
        //
        GrContextForegroundSet(&sCtx, pCanvas->ulOutlineColor);
        GrRectDraw(&sCtx, &(pWidget->sPosition));
    }

    //
    // See if the canvas text or image style is selected.
    //
    if(pCanvas->ulStyle & (CANVAS_STYLE_TEXT | CANVAS_STYLE_IMG))
    {
        //
        // Compute the center of the canvas.
        //
        lX = (pWidget->sPosition.sXMin +
              ((pWidget->sPosition.sXMax - pWidget->sPosition.sXMin + 1) / 2));
        lY = (pWidget->sPosition.sYMin +
              ((pWidget->sPosition.sYMax - pWidget->sPosition.sYMin + 1) / 2));

        //
        // If the canvas outline style is selected then shrink the clipping
        // region by one pixel on each side so that the outline is not
        // overwritten by the text or image.
        //
        if(pCanvas->ulStyle & CANVAS_STYLE_OUTLINE)
        {
            sCtx.sClipRegion.sXMin++;
            sCtx.sClipRegion.sYMin++;
            sCtx.sClipRegion.sXMax--;
            sCtx.sClipRegion.sYMax--;
        }

        //
        // See if the canvas image style is selected.
        //
        if(pCanvas->ulStyle & CANVAS_STYLE_IMG)
        {
            //
            // Set the foreground and background colors to use for 1 BPP
            // images.
            //
            GrContextForegroundSet(&sCtx, pCanvas->ulTextColor);
            GrContextBackgroundSet(&sCtx, pCanvas->ulFillColor);

            //
            // Draw the image centered in the canvas.
            //
            GrImageDraw(&sCtx, pCanvas->pucImage,
                        lX - (GrImageWidthGet(pCanvas->pucImage) / 2),
                        lY - (GrImageHeightGet(pCanvas->pucImage) / 2));
        }

        //
        // See if the canvas text style is selected.
        //
        if(pCanvas->ulStyle & CANVAS_STYLE_TEXT)
        {
            //
            // Set the relevant font and colors.
            //
            GrContextFontSet(&sCtx, pCanvas->pFont);
            GrContextForegroundSet(&sCtx, pCanvas->ulTextColor);
            GrContextBackgroundSet(&sCtx, pCanvas->ulFillColor);

            //
            // Determine the drawing position for the string based on the
            // text alignment style.  First consider the horizontal case.  We
            // enter this section with lX set to the center of the widget.
            //

            //
            // How wide is the string?
            //
            lSize = GrStringWidthGet(&sCtx, pCanvas->pcText, -1);

            if(pCanvas->ulStyle & CANVAS_STYLE_TEXT_LEFT)
            {
                //
                // The string is to be aligned with the left edge of
                // the widget.  Use the clipping rectangle as reference
                // since this will ensure that the string doesn't
                // encroach on any border that is set.
                //
                lX = sCtx.sClipRegion.sXMin;
            }
            else
            {
                if(pCanvas->ulStyle & CANVAS_STYLE_TEXT_RIGHT)
                {
                    //
                    // The string is to be aligned with the right edge of
                    // the widget.  Use the clipping rectangle as reference
                    // since this will ensure that the string doesn't
                    // encroach on any border that is set.
                    //
                    lX = sCtx.sClipRegion.sXMax - lSize;
                }
                else
                {
                    //
                    // We are centering the string horizontally so adjust
                    // the position accordingly to take into account the
                    // width of the string.
                    //
                    lX -= (lSize / 2);
                }
            }

            //
            // Now consider the horizontal case.  We enter this section with lY
            // set to the center of the widget.
            //
            // How tall is the string?
            //
            lSize = GrStringHeightGet(&sCtx);

            if(pCanvas->ulStyle & CANVAS_STYLE_TEXT_TOP)
            {
                //
                // The string is to be aligned with the top edge of
                // the widget.  Use the clipping rectangle as reference
                // since this will ensure that the string doesn't
                // encroach on any border that is set.
                //
                lY = sCtx.sClipRegion.sYMin;
            }
            else
            {
                if(pCanvas->ulStyle & CANVAS_STYLE_TEXT_BOTTOM)
                {
                    //
                    // The string is to be aligned with the bottom edge of
                    // the widget.  Use the clipping rectangle as reference
                    // since this will ensure that the string doesn't
                    // encroach on any border that is set.
                    //
                    lY = sCtx.sClipRegion.sYMax - lSize;
                }
                else
                {
                    //
                    // We are centering the string vertically so adjust
                    // the position accordingly to take into account the
                    // height of the string.
                    //
                    lY -= (lSize / 2);
                }
            }

            //
            // Now draw the string.
            //
            GrStringDraw(&sCtx, pCanvas->pcText, -1, lX, lY,
                         pCanvas->ulStyle & CANVAS_STYLE_TEXT_OPAQUE);
        }
    }

    //
    // See if the application-drawn style is selected.
    //
    if(pCanvas->ulStyle & CANVAS_STYLE_APP_DRAWN)
    {
        //
        // Call the application-supplied function to draw the canvas.
        //
        pCanvas->pfnOnPaint(pWidget, &sCtx);
    }
}
コード例 #2
0
ファイル: slider.c プロジェクト: Anil8590/tiva-c
//*****************************************************************************
//
//! Draws a slider.
//!
//! \param psWidget is a pointer to the slider widget to be drawn.
//! \param psDirty is the subrectangle of the widget which is to be redrawn.
//! This is expressed in screen coordinates.
//!
//! This function draws a slider on the display.  This is called in response to
//! a \b #WIDGET_MSG_PAINT message or when the slider position changes.
//!
//! \return None.
//
//*****************************************************************************
static void
SliderPaint(tWidget *psWidget, tRectangle *psDirty)
{
    tRectangle sClipRect, sValueRect, sEmptyRect, sActiveClip;
    tSliderWidget *pSlider;
    tContext sCtx;
    int32_t i32X, i32Y;
    bool bIntersect;
    int16_t i16Pos;

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

    //
    // Convert the generic widget pointer into a slider widget pointer.
    //
    pSlider = (tSliderWidget *)psWidget;

    //
    // Initialize a drawing context.
    //
    GrContextInit(&sCtx, psWidget->psDisplay);

    //
    // Initialize the clipping region based on the update rectangle passed.
    //
    bIntersect = GrRectIntersectGet(psDirty, &(pSlider->sBase.sPosition),
                                    &sClipRect);
    GrContextClipRegionSet(&sCtx, &sClipRect);

    //
    // Draw the control outline if necessary.
    //
    if(pSlider->ui32Style & SL_STYLE_OUTLINE)
    {
        //
        // Outline the slider with the outline color.
        //
        GrContextForegroundSet(&sCtx, pSlider->ui32OutlineColor);
        GrRectDraw(&sCtx, &(psWidget->sPosition));

        //
        // Adjust the clipping rectangle to prevent the outline from being
        // corrupted later.
        //
        if(sClipRect.i16XMin == psWidget->sPosition.i16XMin)
        {
            sClipRect.i16XMin++;
        }

        if(sClipRect.i16YMin == psWidget->sPosition.i16YMin)
        {
            sClipRect.i16YMin++;
        }

        if(sClipRect.i16XMax == psWidget->sPosition.i16XMax)
        {
            sClipRect.i16XMax--;
        }

        if(sClipRect.i16YMax == psWidget->sPosition.i16YMax)
        {
            sClipRect.i16YMax--;
        }
    }

    //
    // Determine the position associated with the current slider value.
    //
    i16Pos = SliderValueToPosition(pSlider, pSlider->i32Value);

    //
    // Remember this so that the dirty rectangle code in the click handler
    // draws the correct thing the first time it is called.
    //
    pSlider->i16Pos = i16Pos;

    //
    // Determine the rectangles for the active and empty portions of the
    // widget.
    //
    if(pSlider->ui32Style & SL_STYLE_VERTICAL)
    {
        //
        // Determine the rectangle corresponding to the bottom (value) portion
        // of the slider.
        //
        sValueRect.i16XMin = psWidget->sPosition.i16XMin;
        sValueRect.i16XMax = psWidget->sPosition.i16XMax;
        sValueRect.i16YMin = i16Pos;
        sValueRect.i16YMax = psWidget->sPosition.i16YMax;

        //
        // Determine the rectangle corresponding to the top (empty) portion
        // of the slider.
        //
        sEmptyRect.i16XMin = psWidget->sPosition.i16XMin;
        sEmptyRect.i16XMax = psWidget->sPosition.i16XMax;
        sEmptyRect.i16YMin = psWidget->sPosition.i16YMin;
        sEmptyRect.i16YMax = max(sEmptyRect.i16YMin, sValueRect.i16YMin - 1);
    }
    else
    {
        //
        // Determine the rectangle corresponding to the bottom (value) portion
        // of the slider.
        //
        sValueRect.i16YMin = psWidget->sPosition.i16YMin;
        sValueRect.i16YMax = psWidget->sPosition.i16YMax;
        sValueRect.i16XMin = psWidget->sPosition.i16XMin;
        sValueRect.i16XMax = i16Pos;

        //
        // Determine the rectangle corresponding to the top (empty) portion
        // of the slider.
        //
        sEmptyRect.i16YMin = psWidget->sPosition.i16YMin;
        sEmptyRect.i16YMax = psWidget->sPosition.i16YMax;
        sEmptyRect.i16XMax = psWidget->sPosition.i16XMax;
        sEmptyRect.i16XMin = min(sEmptyRect.i16XMax, sValueRect.i16XMax + 1);
    }

    //
    // Compute the center of the slider.  This will be needed later if drawing
    // text or an image.
    //
    i32X = (psWidget->sPosition.i16XMin +
          ((psWidget->sPosition.i16XMax -
            psWidget->sPosition.i16XMin + 1) / 2));
    i32Y = (psWidget->sPosition.i16YMin +
          ((psWidget->sPosition.i16YMax -
            psWidget->sPosition.i16YMin + 1) / 2));

    //
    // Get the required clipping rectangle for the active/value part of
    // the slider.
    //
    bIntersect = GrRectIntersectGet(&sClipRect, &sValueRect, &sActiveClip);

    //
    // Does any part of the value rectangle intersect with the region we are
    // supposed to be redrawing?
    //
    if(bIntersect)
    {
        //
        // Yes - we have something to draw.
        //

        //
        // Set the new clipping rectangle.
        //
        GrContextClipRegionSet(&sCtx, &sActiveClip);

        //
        // Do we need to fill the active area with a color?
        //
        if(pSlider->ui32Style & SL_STYLE_FILL)
        {
            GrContextForegroundSet(&sCtx, pSlider->ui32FillColor);
            GrRectFill(&sCtx, &sValueRect);
        }

        //
        // Do we need to draw an image in the active area?
        //
        if(pSlider->ui32Style & SL_STYLE_IMG)
        {
            GrContextForegroundSet(&sCtx, pSlider->ui32TextColor);
            GrContextBackgroundSet(&sCtx, pSlider->ui32FillColor);
            GrImageDraw(&sCtx, pSlider->pui8Image,
                        i32X - (GrImageWidthGet(pSlider->pui8Image) / 2),
                        i32Y - (GrImageHeightGet(pSlider->pui8Image) / 2));
        }

        //
        // Do we need to render a text string over the top of the active area?
        //
        if(pSlider->ui32Style & SL_STYLE_TEXT)
        {
            GrContextFontSet(&sCtx, pSlider->psFont);
            GrContextForegroundSet(&sCtx, pSlider->ui32TextColor);
            GrContextBackgroundSet(&sCtx, pSlider->ui32FillColor);
            GrStringDrawCentered(&sCtx, pSlider->pcText, -1, i32X, i32Y,
                                 pSlider->ui32Style & SL_STYLE_TEXT_OPAQUE);
        }
    }

    //
    // Now get the required clipping rectangle for the background portion of
    // the slider.
    //
    bIntersect = GrRectIntersectGet(&sClipRect, &sEmptyRect, &sActiveClip);

    //
    // Does any part of the background rectangle intersect with the region we
    // are supposed to be redrawing?
    //
    if(bIntersect)
    {
        //
        // Yes - we have something to draw.
        //

        //
        // Set the new clipping rectangle.
        //
        GrContextClipRegionSet(&sCtx, &sActiveClip);

        //
        // Do we need to fill the active area with a color?
        //
        if(pSlider->ui32Style & SL_STYLE_BACKG_FILL)
        {
            GrContextForegroundSet(&sCtx, pSlider->ui32BackgroundFillColor);
            GrRectFill(&sCtx, &sEmptyRect);
        }

        //
        // Do we need to draw an image in the active area?
        //
        if(pSlider->ui32Style & SL_STYLE_BACKG_IMG)
        {
            GrContextForegroundSet(&sCtx, pSlider->ui32BackgroundTextColor);
            GrContextBackgroundSet(&sCtx, pSlider->ui32BackgroundFillColor);
            GrImageDraw(&sCtx, pSlider->pui8BackgroundImage,
                  i32X - (GrImageWidthGet(pSlider->pui8BackgroundImage) / 2),
                  i32Y - (GrImageHeightGet(pSlider->pui8BackgroundImage) / 2));
        }

        //
        // Do we need to render a text string over the top of the active area?
        //
        if(pSlider->ui32Style & SL_STYLE_BACKG_TEXT)
        {
            GrContextFontSet(&sCtx, pSlider->psFont);
            GrContextForegroundSet(&sCtx, pSlider->ui32BackgroundTextColor);
            GrContextBackgroundSet(&sCtx, pSlider->ui32BackgroundFillColor);
            GrStringDrawCentered(&sCtx, pSlider->pcText, -1, i32X, i32Y,
                              pSlider->ui32Style & SL_STYLE_BACKG_TEXT_OPAQUE);
        }
    }
}
コード例 #3
0
ファイル: pushbutton.c プロジェクト: shadowpho/Chalk-Bot
//*****************************************************************************
//
//! Draws a circular push button.
//!
//! \param pWidget is a pointer to the push button widget to be drawn.
//!
//! This function draws a circular push button on the display.  This is called
//! in response to a \b #WIDGET_MSG_PAINT message.
//!
//! \return None.
//
//*****************************************************************************
static void
CircularButtonPaint(tWidget *pWidget)
{
    const unsigned char *pucImage;
    tPushButtonWidget *pPush;
    tContext sCtx;
    long lX, lY, lR;

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

    //
    // Convert the generic widget pointer into a push button widget pointer.
    //
    pPush = (tPushButtonWidget *)pWidget;

    //
    // Initialize a drawing context.
    //
    GrContextInit(&sCtx, pWidget->pDisplay);

    //
    // Initialize the clipping region based on the extents of this circular
    // push button.
    //
    GrContextClipRegionSet(&sCtx, &(pWidget->sPosition));

    //
    // Get the radius of the circular push button, along with the X and Y
    // coordinates for its center.
    //
    lR = (pWidget->sPosition.sXMax - pWidget->sPosition.sXMin + 1) / 2;
    lX = pWidget->sPosition.sXMin + lR;
    lY = pWidget->sPosition.sYMin + lR;

    //
    // See if the push button fill style is selected.
    //
    if(pPush->ulStyle & PB_STYLE_FILL)
    {
        //
        // Fill the push button with the fill color.
        //
        GrContextForegroundSet(&sCtx, ((pPush->ulStyle & PB_STYLE_PRESSED) ?
                                       pPush->ulPressFillColor :
                                       pPush->ulFillColor));
        GrCircleFill(&sCtx, lX, lY, lR);
    }

    //
    // See if the push button outline style is selected.
    //
    if(pPush->ulStyle & PB_STYLE_OUTLINE)
    {
        //
        // Outline the push button with the outline color.
        //
        GrContextForegroundSet(&sCtx, pPush->ulOutlineColor);
        GrCircleDraw(&sCtx, lX, lY, lR);
    }

    //
    // See if the push button text or image style is selected.
    //
    if(pPush->ulStyle & (PB_STYLE_TEXT | PB_STYLE_IMG))
    {
        //
        // If the push button outline style is selected then shrink the
        // clipping region by one pixel on each side so that the outline is not
        // overwritten by the text or image.
        //
        if(pPush->ulStyle & PB_STYLE_OUTLINE)
        {
            sCtx.sClipRegion.sXMin++;
            sCtx.sClipRegion.sYMin++;
            sCtx.sClipRegion.sXMax--;
            sCtx.sClipRegion.sYMax--;
        }

        //
        // See if the push button image style is selected.
        //
        if(pPush->ulStyle & PB_STYLE_IMG)
        {
            //
            // Set the foreground and background colors to use for 1 BPP
            // images.
            //
            GrContextForegroundSet(&sCtx, pPush->ulTextColor);
            GrContextBackgroundSet(&sCtx,
                                   ((pPush->ulStyle & PB_STYLE_PRESSED) ?
                                    pPush->ulPressFillColor :
                                    pPush->ulFillColor));

            //
            // Get the image to be drawn.
            //
            pucImage = (((pPush->ulStyle & PB_STYLE_PRESSED) &&
                         pPush->pucPressImage) ?
                        pPush->pucPressImage : pPush->pucImage);

            //
            // Draw the image centered in the push button.
            //
            GrImageDraw(&sCtx, pucImage, lX - (GrImageWidthGet(pucImage) / 2),
                        lY - (GrImageHeightGet(pucImage) / 2));
        }

        //
        // See if the push button text style is selected.
        //
        if(pPush->ulStyle & PB_STYLE_TEXT)
        {
            //
            // Draw the text centered in the middle of the push button.
            //
            GrContextFontSet(&sCtx, pPush->pFont);
            GrContextForegroundSet(&sCtx, pPush->ulTextColor);
            GrContextBackgroundSet(&sCtx,
                                   ((pPush->ulStyle & PB_STYLE_PRESSED) ?
                                    pPush->ulPressFillColor :
                                    pPush->ulFillColor));
            GrStringDrawCentered(&sCtx, pPush->pcText, -1, lX, lY,
                                 pPush->ulStyle & PB_STYLE_TEXT_OPAQUE);
        }
    }
}
コード例 #4
0
ファイル: pushbutton.c プロジェクト: Lboyve/TM4C129X-EPI-uDMA
//*****************************************************************************
//
//! Draws a rectangular push button.
//!
//! \param psWidget is a pointer to the push button widget to be drawn.
//!
//! This function draws a rectangular push button on the display.  This is
//! called in response to a \b #WIDGET_MSG_PAINT message.
//!
//! \return None.
//
//*****************************************************************************
static void
RectangularButtonPaint(tWidget *psWidget)
{
    const uint8_t *pui8Image;
    tPushButtonWidget *pPush;
    tContext sCtx;
    int32_t i32X, i32Y;

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

    //
    // Convert the generic widget pointer into a push button widget pointer.
    //
    pPush = (tPushButtonWidget *)psWidget;

    //
    // Initialize a drawing context.
    //
    GrContextInit(&sCtx, psWidget->psDisplay);

    //
    // Initialize the clipping region based on the extents of this rectangular
    // push button.
    //
    GrContextClipRegionSet(&sCtx, &(psWidget->sPosition));

    //
    // See if the push button fill style is selected.
    //
    if(pPush->ui32Style & PB_STYLE_FILL)
    {
        //
        // Fill the push button with the fill color.
        //
        GrContextForegroundSet(&sCtx, ((pPush->ui32Style & PB_STYLE_PRESSED) ?
                                       pPush->ui32PressFillColor :
                                       pPush->ui32FillColor));
        GrRectFill(&sCtx, &(psWidget->sPosition));
    }

    //
    // See if the push button outline style is selected.
    //
    if(pPush->ui32Style & PB_STYLE_OUTLINE)
    {
        //
        // Outline the push button with the outline color.
        //
        GrContextForegroundSet(&sCtx, pPush->ui32OutlineColor);
        GrRectDraw(&sCtx, &(psWidget->sPosition));
    }

    //
    // See if the push button text or image style is selected.
    //
    if(pPush->ui32Style & (PB_STYLE_TEXT | PB_STYLE_IMG))
    {
        //
        // Compute the center of the push button.
        //
        i32X = (psWidget->sPosition.i16XMin +
              ((psWidget->sPosition.i16XMax -
                psWidget->sPosition.i16XMin + 1) / 2));
        i32Y = (psWidget->sPosition.i16YMin +
              ((psWidget->sPosition.i16YMax -
                psWidget->sPosition.i16YMin + 1) / 2));

        //
        // If the push button outline style is selected then shrink the
        // clipping region by one pixel on each side so that the outline is not
        // overwritten by the text or image.
        //
        if(pPush->ui32Style & PB_STYLE_OUTLINE)
        {
            sCtx.sClipRegion.i16XMin++;
            sCtx.sClipRegion.i16YMin++;
            sCtx.sClipRegion.i16XMax--;
            sCtx.sClipRegion.i16YMax--;
        }

        //
        // See if the push button image style is selected.
        //
        if(pPush->ui32Style & PB_STYLE_IMG)
        {
            //
            // Set the foreground and background colors to use for 1 BPP
            // images.
            //
            GrContextForegroundSet(&sCtx, pPush->ui32TextColor);
            GrContextBackgroundSet(&sCtx,
                                   ((pPush->ui32Style & PB_STYLE_PRESSED) ?
                                    pPush->ui32PressFillColor :
                                    pPush->ui32FillColor));

            //
            // Get the image to be drawn.
            //
            pui8Image = (((pPush->ui32Style & PB_STYLE_PRESSED) &&
                         pPush->pui8PressImage) ?
                        pPush->pui8PressImage : pPush->pui8Image);

            //
            // Draw the image centered in the push button.
            //
            GrImageDraw(&sCtx, pui8Image,
                        i32X - (GrImageWidthGet(pui8Image) / 2),
                        i32Y - (GrImageHeightGet(pui8Image) / 2));
        }

        //
        // See if the push button text style is selected.
        //
        if(pPush->ui32Style & PB_STYLE_TEXT)
        {
            //
            // Draw the text centered in the middle of the push button.
            //
            GrContextFontSet(&sCtx, pPush->psFont);
            GrContextForegroundSet(&sCtx, pPush->ui32TextColor);
            GrContextBackgroundSet(&sCtx,
                                   ((pPush->ui32Style & PB_STYLE_PRESSED) ?
                                    pPush->ui32PressFillColor :
                                    pPush->ui32FillColor));
            GrStringDrawCentered(&sCtx, pPush->pcText, -1, i32X, i32Y,
                                 pPush->ui32Style & PB_STYLE_TEXT_OPAQUE);
        }
    }
}
コード例 #5
0
ファイル: imgbutton.c プロジェクト: Lboyve/TM4C129X-EPI-uDMA
//*****************************************************************************
//
//! Draws an image button.
//!
//! \param psWidget is a pointer to the image button widget to be drawn.
//!
//! This function draws a rectangular image button on the display.  This is
//! called in response to a \b #WIDGET_MSG_PAINT message.
//!
//! \return None.
//
//*****************************************************************************
static void
ImageButtonPaint(tWidget *psWidget)
{
    const uint8_t *pui8Image;
    tImageButtonWidget *psPush;
    tContext sCtx;
    int32_t i32X, i32Y;

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

    //
    // Convert the generic widget pointer into a image button widget pointer.
    //
    psPush = (tImageButtonWidget *)psWidget;

    //
    // Initialize a drawing context.
    //
    GrContextInit(&sCtx, psWidget->psDisplay);

    //
    // Initialize the clipping region based on the extents of this rectangular
    // image button.
    //
    GrContextClipRegionSet(&sCtx, &(psWidget->sPosition));

    //
    // Compute the center of the image button.
    //
    i32X = (psWidget->sPosition.i16XMin +
          ((psWidget->sPosition.i16XMax -
            psWidget->sPosition.i16XMin + 1) / 2));
    i32Y = (psWidget->sPosition.i16YMin +
          ((psWidget->sPosition.i16YMax -
            psWidget->sPosition.i16YMin + 1) / 2));

    //
    // Do we need to fill the widget background with a color?
    //
    if(psPush->ui32Style & IB_STYLE_FILL)
    {
        //
        // Yes. Set the appropriate color depending upon whether or not
        // the widget is currently pressed.
        //
        GrContextForegroundSet(&sCtx,
                               ((psPush->ui32Style & IB_STYLE_PRESSED) ?
                                psPush->ui32PressedColor :
                                psPush->ui32BackgroundColor));
        GrRectFill(&sCtx, &(psWidget->sPosition));
    }

    //
    // Set the foreground and background colors to use for 1 BPP
    // images and text
    //
    GrContextForegroundSet(&sCtx, psPush->ui32ForegroundColor);
    GrContextBackgroundSet(&sCtx,
                           ((psPush->ui32Style & IB_STYLE_PRESSED) ?
                            psPush->ui32PressedColor :
                            psPush->ui32BackgroundColor));

    //
    // Do we need to draw the background image?
    //
    if(!(psPush->ui32Style & IB_STYLE_IMAGE_OFF))
    {
        //
        // Get the background image to be drawn.
        //
        pui8Image = ((psPush->ui32Style & IB_STYLE_PRESSED) ?
                    psPush->pui8PressImage : psPush->pui8Image);

        //
        // Draw the image centered in the image button.
        //
        GrImageDraw(&sCtx, pui8Image, i32X - (GrImageWidthGet(pui8Image) / 2),
                    i32Y - (GrImageHeightGet(pui8Image) / 2));
    }

    //
    // Adjust the drawing position if the button is pressed.
    //
    i32X += ((psPush->ui32Style & IB_STYLE_PRESSED) ? psPush->i16XOffset : 0);
    i32Y += ((psPush->ui32Style & IB_STYLE_PRESSED) ? psPush->i16YOffset : 0);

    //
    // If there is a keycap image and it is not disabled, center this on the
    // top of the button, applying any offset defined if the button is
    // currently pressed.
    //
    if(psPush->pui8KeycapImage && !(psPush->ui32Style & IB_STYLE_KEYCAP_OFF))
    {
        //
        // Draw the keycap image.
        //
        GrImageDraw(&sCtx, psPush->pui8KeycapImage,
                    i32X - (GrImageWidthGet(psPush->pui8KeycapImage) / 2),
                    i32Y - (GrImageHeightGet(psPush->pui8KeycapImage) / 2));
    }

    //
    // See if the button text style is selected.
    //
    if(psPush->ui32Style & IB_STYLE_TEXT)
    {
        //
        // Draw the text centered in the middle of the button with offset
        // applied if the button is currently pressed.
        //
        GrContextFontSet(&sCtx, psPush->psFont);
        GrStringDrawCentered(&sCtx, psPush->pcText, -1, i32X, i32Y, 0);
    }
}
コード例 #6
0
ファイル: radiobutton.c プロジェクト: Ziul/OLED-Firmware
//*****************************************************************************
//
//! Draws a radio button widget.
//!
//! \param pWidget is a pointer to the radio button widget to be drawn.
//! \param bClick is a boolean that is \b true if the paint request is a result
//! of a pointer click and \b false if not.
//!
//! This function draws a radio button widget on the display.  This is called
//! in response to a \b #WIDGET_MSG_PAINT message.
//!
//! \return None.
//
//*****************************************************************************
static void
RadioButtonPaint(tWidget *pWidget, int bClick)
{
    tRadioButtonWidget *pRadio;
    tContext sCtx;
    long lX, lY;

    //
    // Convert the generic widget pointer into a radio button widget pointer.
    //
    pRadio = (tRadioButtonWidget *)pWidget;

    //
    // Initialize a drawing context.
    //
    GrContextInit(&sCtx, pWidget->pDisplay);

    //
    // Initialize the clipping region based on the extents of this radio
    // button.
    //
    GrContextClipRegionSet(&sCtx, &(pWidget->sPosition));

    //
    // See if the radio button fill style is selected.
    //
    if((pRadio->usStyle & RB_STYLE_FILL) && !bClick)
    {
        //
        // Fill the radio button with the fill color.
        //
        GrContextForegroundSet(&sCtx, pRadio->ulFillColor);
        GrRectFill(&sCtx, &(pWidget->sPosition));
    }

    //
    // See if the radio button outline style is selected.
    //
    if((pRadio->usStyle & RB_STYLE_OUTLINE) && !bClick)
    {
        //
        // Outline the radio button with the outline color.
        //
        GrContextForegroundSet(&sCtx, pRadio->ulOutlineColor);
        GrRectDraw(&sCtx, &(pWidget->sPosition));
    }

    //
    // Draw the radio button.
    //
    lX = pWidget->sPosition.sXMin + (pRadio->usCircleSize / 2) + 2;
    lY = (pWidget->sPosition.sYMin +
          ((pWidget->sPosition.sYMax - pWidget->sPosition.sYMin) / 2));
    if(!bClick)
    {
        GrContextForegroundSet(&sCtx, pRadio->ulOutlineColor);
        GrCircleDraw(&sCtx, lX, lY, pRadio->usCircleSize / 2);
    }

    //
    // Select the foreground color based on whether or not the radio button is
    // selected.
    //
    if(pRadio->usStyle & RB_STYLE_SELECTED)
    {
        GrContextForegroundSet(&sCtx, pRadio->ulOutlineColor);
    }
    else
    {
        GrContextForegroundSet(&sCtx, pRadio->ulFillColor);
    }

    //
    // Fill in the radio button.
    //
    GrCircleFill(&sCtx, lX, lY, (pRadio->usCircleSize / 2) - 2);

    //
    // See if the radio button text or image style is selected.
    //
    if((pRadio->usStyle & (RB_STYLE_TEXT | RB_STYLE_IMG)) && !bClick)
    {
        //
        // Shrink the clipping region by the size of the radio button so that
        // it is not overwritten by further "decorative" portions of the
        // widget.
        //
        sCtx.sClipRegion.sXMin += pRadio->usCircleSize + 4;

        //
        // If the radio button outline style is selected then shrink the
        // clipping region by one pixel on each side so that the outline is not
        // overwritten by the text or image.
        //
        if(pRadio->usStyle & RB_STYLE_OUTLINE)
        {
            sCtx.sClipRegion.sYMin++;
            sCtx.sClipRegion.sXMax--;
            sCtx.sClipRegion.sYMax--;
        }

        //
        // See if the radio button image style is selected.
        //
        if(pRadio->usStyle & RB_STYLE_IMG)
        {
            //
            // Determine where along the Y extent of the widget to draw the
            // image.  It is drawn at the top if it takes all (or more than
            // all) of the Y extent of the widget, and it is drawn centered if
            // it takes less than the Y extent.
            //
            if(GrImageHeightGet(pRadio->pucImage) >
               (sCtx.sClipRegion.sYMax - sCtx.sClipRegion.sYMin))
            {
                lY = sCtx.sClipRegion.sYMin;
            }
            else
            {
                lY = (sCtx.sClipRegion.sYMin +
                      ((sCtx.sClipRegion.sYMax - sCtx.sClipRegion.sYMin -
                        GrImageHeightGet(pRadio->pucImage) + 1) / 2));
            }

            //
            // Set the foreground and background colors to use for 1 BPP
            // images.
            //
            GrContextForegroundSet(&sCtx, pRadio->ulTextColor);
            GrContextBackgroundSet(&sCtx, pRadio->ulFillColor);

            //
            // Draw the image next to the radio button.
            //
            GrImageDraw(&sCtx, pRadio->pucImage, sCtx.sClipRegion.sXMin, lY);
        }

        //
        // See if the radio button text style is selected.
        //
        if(pRadio->usStyle & RB_STYLE_TEXT)
        {
            //
            // Determine where along the Y extent of the widget to draw the
            // string.  It is drawn at the top if it takes all (or more than
            // all) of the Y extent of the widget, and it is drawn centered if
            // it takes less than the Y extent.
            //
            if(GrFontHeightGet(pRadio->pFont) >
               (sCtx.sClipRegion.sYMax - sCtx.sClipRegion.sYMin))
            {
                lY = sCtx.sClipRegion.sYMin;
            }
            else
            {
                lY = (sCtx.sClipRegion.sYMin +
                      ((sCtx.sClipRegion.sYMax - sCtx.sClipRegion.sYMin -
                        GrFontHeightGet(pRadio->pFont) + 1) / 2));
            }

            //
            // Draw the text next to the radio button.
            //
            GrContextFontSet(&sCtx, pRadio->pFont);
            GrContextForegroundSet(&sCtx, pRadio->ulTextColor);
            GrContextBackgroundSet(&sCtx, pRadio->ulFillColor);
            GrStringDraw(&sCtx, pRadio->pcText, -1, sCtx.sClipRegion.sXMin, lY,
                         pRadio->usStyle & RB_STYLE_TEXT_OPAQUE);
        }
    }
}