Ejemplo n.º 1
0
//*****************************************************************************
//
//! Paints a menu, menu items on a display.
//!
//! \param psWidget is a pointer to the slide menu widget to be drawn.
//!
//! This function draws the contents of a slide menu on the display.  This is
//! called in response to a \b WIDGET_MSG_PAINT message.
//!
//! \return None.
//
//*****************************************************************************
static void
SlideMenuPaint(tWidget *psWidget)
{
    tSlideMenuWidget *psMenuWidget;
    tContext sContext;

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

    //
    // If this widget has a child widget, that means that the menu has
    // slid off the screen and the child widget is in control.  Therefore
    // there is nothing to paint here.  Just exit and the child widget will
    // be painted.
    //
    if(psWidget->psChild)
    {
        return;
    }

    //
    // Convert the generic widget pointer into a slide menu widget pointer,
    // and get a pointer to its context.
    //
    psMenuWidget = (tSlideMenuWidget *)psWidget;

    //
    // Initialize a context for the primary off-screen drawing buffer.
    // Clip region is set to entire display by default, which is what we want.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayA);

    //
    // Render the menu into the off-screen buffer, using normal vertical
    // position.
    //
    SlideMenuDraw(psMenuWidget, &sContext, 0);

    //
    // Initialize a drawing context for the display where the widget is to be
    // drawn.  This is the physical display, not an off-screen buffer.
    //
    GrContextInit(&sContext, psWidget->psDisplay);

    //
    // Initialize the clipping region on the physical display, based on the
    // extents of this widget.
    //
    GrContextClipRegionSet(&sContext, &(psWidget->sPosition));

    //
    // Now copy the rendered menu into the physical display. This will show
    // the menu on the display.
    //
    GrImageDraw(&sContext, psMenuWidget->psDisplayA->pvDisplayData,
                psWidget->sPosition.i16XMin, psWidget->sPosition.i16YMin);
}
Ejemplo n.º 2
0
static void draw_usbmouse_slide()
{
    const tRectangle rect1 = {50, 48, 430, 228};
    const tRectangle rect2 = {51, 49, 429, 227};
    
    GrImageDraw(&sContextUsbMouse, iconHome, 0, 0);
    GrImageDraw(&sContextUsbMouse, iconBack, 0, HEIGHT - 60);
    GrImageDraw(&sContextUsbMouse, iconNext, WIDTH - 60, HEIGHT - 60);

    /* draw special trackpad graphics instead of standard slide layout */
    GrContextForegroundSet(&sContextUsbMouse, ClrDarkBlue);
    GrRectDraw(&sContextUsbMouse, &rect1);
    GrRectDraw(&sContextUsbMouse, &rect2);
    
    GrContextForegroundSet(&sContextUsbMouse, ClrDarkGray);
    GrContextFontSet(&sContextUsbMouse, &g_sFontCmss22b);
    GrStringDrawCentered(&sContextUsbMouse, "Touch Pad", -1, 240, 140, 0);
    
    GrImageDraw(&sContextUsbMouse, (unsigned char *)usbMouseButtons, 50, 238);
}
Ejemplo n.º 3
0
int main(void)
{
   SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

   Kentec320x240x16_SSD2119Init();
   GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);
   ClrScreen();

   GrImageDraw(&sContext, g_pui8Image, 0, 0);
   GrFlush(&sContext);

   SysCtlDelay(SysCtlClockGet());
   // Later lab steps go between here

   ClrScreen();

   sRect.i16XMin = 1;
   sRect.i16YMin = 1;
   sRect.i16XMax = 318;
   sRect.i16YMax = 238;
   GrContextForegroundSet(&sContext, ClrRed);
   GrContextFontSet(&sContext, &g_sFontCmss30b);
   GrStringDraw(&sContext, "Texas", -1, 110, 2, 0);
   GrStringDraw(&sContext, "Instruments", -1, 80, 32, 0);
   GrStringDraw(&sContext, "Graphics", -1, 100, 62, 0);
   GrStringDraw(&sContext, "Lab", -1, 135, 92, 0);
   GrContextForegroundSet(&sContext, ClrWhite);
   GrRectDraw(&sContext, &sRect);
   GrFlush(&sContext);

   SysCtlDelay(SysCtlClockGet());

   GrContextForegroundSet(&sContext, ClrYellow);
   GrCircleFill(&sContext, 80, 182, 50);

   sRect.i16XMin = 160;
   sRect.i16YMin = 132;
   sRect.i16XMax = 312;
   sRect.i16YMax = 232;
   GrContextForegroundSet(&sContext, ClrGreen);
   GrRectDraw(&sContext, &sRect);

   SysCtlDelay(SysCtlClockGet());

   // and here
   ClrScreen();
   while(1)
   {
   }
}
Ejemplo n.º 4
0
//*****************************************************************************
//
//! Paints the strip chart on the display.
//!
//! \param psWidget is a pointer to the strip chart widget to be drawn.
//!
//! This function draws the contents of a strip chart on the display.  This is
//! called in response to a \b WIDGET_MSG_PAINT message.
//!
//! \return None.
//
//*****************************************************************************
static void
StripChartPaint(tWidget *psWidget)
{
    tStripChartWidget *psChartWidget;
    tContext sContext;

    //
    // Check the arguments.
    //
    ASSERT(psWidget);
    ASSERT(psWidget->psDisplay);

    //
    // Convert the generic widget pointer into a strip chart widget pointer.
    //
    psChartWidget = (tStripChartWidget *)psWidget;

    //
    // Initialize a context for the primary off-screen drawing buffer.
    // Clip region is set to entire display by default, which is what we want.
    //
    ASSERT(psChartWidget->psOffscreenDisplay);
    GrContextInit(&sContext, psChartWidget->psOffscreenDisplay);

    //
    // Render the strip chart into the off-screen buffer
    //
    StripChartDraw(psChartWidget, &sContext);

    //
    // Initialize a drawing context for the display where the widget is to be
    // drawn.  This is the physical display, not an off-screen buffer.
    //
    GrContextInit(&sContext, psWidget->psDisplay);

    //
    // Initialize the clipping region on the physical display, based on the
    // extents of this widget.
    //
    GrContextClipRegionSet(&sContext, &(psWidget->sPosition));

    //
    // Now copy the rendered strip chart into the physical display
    //
    GrImageDraw(&sContext, psChartWidget->psOffscreenDisplay->pvDisplayData,
                psWidget->sPosition.i16XMin, psWidget->sPosition.i16YMin);
}
/*
 *  ======== grlibTaskFxn ========
 *  Drawing task
 *
 *  It is pending for the message either from console task or from button ISR.
 *  Once the messages received, it draws to the screen based on information
 *  contained in the message.
 */
Void grlibTaskFxn(UArg arg0, UArg arg1)
{
    DrawMessage curMsg;
    const UChar *pucCurImage;
    const Char *pcCurStr;
    UInt i = 0;
    UInt fontHeight = GrStringHeightGet(&context);

    while (TRUE) {
        Mailbox_pend(mailboxHandle, &curMsg, BIOS_WAIT_FOREVER);

        /* Clear screen before drawing */
        clearDisplay();

        /* Parse the message and draw */
        switch (curMsg.drawCommand) {
        case IMAGE:
            pucCurImage = image_Gallery[curMsg.drawImageIndex];

            /* Draw image at (0,0) */
            GrImageDraw(&context, pucCurImage, 0, 0);
            break;

        case KeyBoadCOMMAND:

            output(4,curMsg.draw2048);

            break;

        case ScreenCOMMAND:
            pcCurStr = curMsg.drawString;
            GrContextForegroundSetTranslated(&context, 0xFF);
            GrStringDraw(&context, pcCurStr, -1, 0, 0, 0);
            break;

        default:
            break;
        }
    }
}
Ejemplo n.º 6
0
//*****************************************************************************
//
//! Performs the sliding menu operation, in response to the "left" button.
//!
//! \param psWidget is a pointer to the slide menu widget to move to the left.
//!
//! This function will respond to the "left" key/button event.  The left
//! button is used to ascend to the next menu up in the menu tree.  The effect
//! is that the current menu, or active widget, slides off to the right, while
//! the parent menu slides in from the left.
//!
//! This function repeatedly draws the menu onto the display until the sliding
//! animation is finished and will not return to the caller until then.  This
//! function is usually called from the thread context of
//! WidgetMessageQueueProcess().
//!
//! \return Returns a non-zero value if the menu was moved or was not moved
//! because it is already at the last position.  If a child widget is active
//! then this function does nothing and returns a 0.
//
//*****************************************************************************
static int32_t
SlideMenuLeft(tWidget *psWidget)
{
    tSlideMenuWidget *psMenuWidget;
    tSlideMenu *psMenu;
    tSlideMenu *psParentMenu;
    tContext sContext;
    uint32_t ui32X;
    uint32_t ui32MenuWidth;

    //
    // Get handy pointers to the menu widget and active menu, and the parent
    // menu if there is one.
    //
    psMenuWidget = (tSlideMenuWidget *)psWidget;
    psMenu = psMenuWidget->psSlideMenu;
    psParentMenu = psMenu->psParent;

    //
    // Initialize a context for the primary off-screen drawing buffer.
    // Clip region is set to entire display by default, which is what we want.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayB);

    //
    // If this widget has a child, that means that the child widget is in
    // control, and we are requested to go back to the previous menu item.
    // Process the child widget.
    //
    if(psWidget->psChild)
    {
        //
        // Call the widget de-activated callback function.  This notifies the
        // application that the widget is being deactivated.
        //
        if(psMenuWidget->pfnActive)
        {
            psMenuWidget->pfnActive(psWidget->psChild,
                                   &psMenu->psSlideMenuItems[psMenu->ui32FocusIndex],
                                   0);
        }

        //
        // Unlink the child widget from the slide menu widget.  The menu
        // widget will now no longer have a child widget.
        //
        psWidget->psChild->psParent = 0;
        psWidget->psChild = 0;

        //
        // Fill a rectangle with the child widget background color.  This will
        // erase everything else that is shown on the widget but leave the
        // background, which will make the change visually less jarring.
        // This is done in off-screen buffer B, which is the buffer that is
        // going to be slid off the screen.
        //
        GrContextForegroundSet(
            &sContext,
            psMenu->psSlideMenuItems[psMenu->ui32FocusIndex].ui32ChildWidgetColor);
        GrRectFill(&sContext, &sContext.sClipRegion);
    }

    //
    // Otherwise there is not a child widget in control, so process the parent
    // menu, if there is one.
    //
    else if(psParentMenu)
    {
        //
        // Render the current menu into the off-screen buffer B.  This will be
        // the same menu appearance that is currently on the display.
        //
        SlideMenuDraw(psMenuWidget, &sContext, 0);

        //
        // Now switch the widget to the parent menu
        //
        psMenuWidget->psSlideMenu = psParentMenu;
    }

    //
    // Otherwise, we are already at the top level menu and there is nothing
    // else to do.
    //
    else
    {
        return(1);
    }

    //
    // Draw the new menu in the second offscreen buffer.  This is the menu
    // that will be on the display when the animation is over.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayA);
    SlideMenuDraw(psMenuWidget, &sContext, 0);

    //
    // Initialize a drawing context for the display where the widget is to be
    // drawn.  This is the physical display, not an off-screen buffer.
    //
    GrContextInit(&sContext, psWidget->psDisplay);

    //
    // Initialize the clipping region on the physical display, based on the
    // extents of this widget.
    //
    GrContextClipRegionSet(&sContext, &(psWidget->sPosition));

    //
    // Get the width of the menu widget.
    //
    ui32MenuWidth = psMenuWidget->psDisplayA->ui16Width;

    //
    // The following loop draws the two off-screen buffers onto the physical
    // display using a left-to-right.  This will provide an appearance
    // of sliding to the right.  The parent menu will slide in from the left.
    // The "old" child menu is being held in off-screen buffer B and the new
    // one is in buffer A.  So when we are done, the correct image will be in
    // buffer A.
    //
    for(ui32X = 0; ui32X <= ui32MenuWidth; ui32X += 8)
    {
        GrImageDraw(&sContext, psMenuWidget->psDisplayB->pvDisplayData,
                    psWidget->sPosition.i16XMin + ui32X,
                    psWidget->sPosition.i16YMin);
        GrImageDraw(&sContext, psMenuWidget->psDisplayA->pvDisplayData,
                    psWidget->sPosition.i16XMin + ui32X - ui32MenuWidth,
                    psWidget->sPosition.i16YMin);
    }

    //
    // Return indication that we handled the key event.
    //
    return(1);
}
Ejemplo n.º 7
0
//*****************************************************************************
//
//! Performs the sliding menu operation, in response to the "right" button.
//!
//! \param psWidget is a pointer to the slide menu widget to move to the right.
//!
//! This function will respond to the "right" key/button event.  The right
//! button is used to select the next menu level below the current menu item,
//! or a widget that is activated by the menu item.  The effect is that the
//! menu itself slides off to the left, and the new menu or widget slides in
//! from the right.
//!
//! This function repeatedly draws the menu onto the display until the sliding
//! animation is finished and will not return to the caller until then.  This
//! function is usually called from the thread context of
//! WidgetMessageQueueProcess().
//!
//! \return Returns a non-zero value if the menu was moved or was not moved
//! because it is already at the last position.  If a child widget is active
//! then this function does nothing and returns a 0.
//
//*****************************************************************************
static int32_t
SlideMenuRight(tWidget *psWidget)
{
    tSlideMenuWidget *psMenuWidget;
    tSlideMenu *psMenu;
    tSlideMenu *psChildMenu;
    tContext sContext;
    tWidget *psChildWidget;
    uint32_t ui32X;
    uint32_t ui32MenuWidth;

    //
    // If this menu widget has a child widget, that means the child widget
    // is in control of the display, and there is nothing to do here.
    //
    if(psWidget->psChild)
    {
        return(0);
    }

    //
    // Get handy pointers to the menu widget, and the current menu, and the
    // child menu and widget if they exist.
    //
    psMenuWidget = (tSlideMenuWidget *)psWidget;
    psMenu = psMenuWidget->psSlideMenu;
    psChildMenu = psMenu->psSlideMenuItems[psMenu->ui32FocusIndex].psChildMenu;
    psChildWidget = psMenu->psSlideMenuItems[psMenu->ui32FocusIndex].psChildWidget;

    //
    // Initialize a context for the secondary off-screen drawing buffer.
    // Clip region is set to entire display by default, which is what we want.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayB);

    //
    // Render the current menu into off-screen buffer B.  This
    // will be the same menu appearance as is already being shown.
    //
    SlideMenuDraw(psMenuWidget, &sContext, 0);

    //
    // Now set up context for drawing into off-screen buffer A
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayA);

    //
    // Process child menu of this menu item
    //
    if(psChildMenu)
    {
        //
        // Switch the active menu for this SlideMenuWidget to be the child
        // menu
        //
        psMenuWidget->psSlideMenu = psChildMenu;

        //
        // Draw the new (child) menu into off-screen buffer A
        //
        SlideMenuDraw(psMenuWidget, &sContext, 0);
    }

    //
    // Process child widget of this menu item.  This only happens if there
    // is no child menu.
    //
    else if(psChildWidget)
    {
        //
        // Call the widget activated callback function.  This will notify
        // the application that a child widget has been activated by the
        // menu system.
        //
        if(psMenuWidget->pfnActive)
        {
            psMenuWidget->pfnActive(psChildWidget,
                                   &psMenu->psSlideMenuItems[psMenu->ui32FocusIndex],
                                   1);
        }

        //
        // Link the new child widget into this SlideMenuWidget so
        // it appears as a child to this widget.  Normally the menu widget
        // has no child widget.
        //
        psWidget->psChild = psChildWidget;
        psChildWidget->psParent = psWidget;

        //
        // Fill a rectangle with the new child widget background color.
        // This is done in off-screen buffer A.  When the menu slides off,
        // it will be replaced by a blank background that will then be
        // controlled by the new child widget.
        //
        GrContextForegroundSet(
            &sContext,
            psMenu->psSlideMenuItems[psMenu->ui32FocusIndex].ui32ChildWidgetColor);
        GrRectFill(&sContext, &sContext.sClipRegion);

        //
        // Request a repaint for the child widget so it can draw itself once
        // the menu slide is done.
        //
        WidgetPaint(psChildWidget);
    }

    //
    // There is no child menu or child widget, so there is nothing to change
    // on the display.
    //
    else
    {
        return(1);
    }

    //
    // Initialize a drawing context for the display where the widget is to be
    // drawn.  This is the physical display, not an off-screen buffer.
    //
    GrContextInit(&sContext, psWidget->psDisplay);

    //
    // Initialize the clipping region on the physical display, based on the
    // extents of this widget.
    //
    GrContextClipRegionSet(&sContext, &(psWidget->sPosition));

    //
    // Get the width of the menu widget which is used in calculations below
    //
    ui32MenuWidth = psMenuWidget->psDisplayA->ui16Width;

    //
    // The following loop draws the two off-screen buffers onto the physical
    // display using a right-to-left-wipe.  This will provide an appearance
    // of sliding to the left.  The new child menu, or child widget background
    // will slide in from the right.  The "old" menu is being held in
    // off-screen buffer B and the new one is in buffer A.  So when we are
    // done, the correct image will be in buffer A.
    //
    for(ui32X = 0; ui32X <= ui32MenuWidth; ui32X += 8)
    {
        GrImageDraw(&sContext, psMenuWidget->psDisplayB->pvDisplayData,
                    psWidget->sPosition.i16XMin - ui32X,
                    psWidget->sPosition.i16YMin);
        GrImageDraw(&sContext, psMenuWidget->psDisplayA->pvDisplayData,
                    psWidget->sPosition.i16XMin + ui32MenuWidth - ui32X,
                    psWidget->sPosition.i16YMin);
    }

    //
    // Return indication that we handled the key event.
    //
    return(1);
}
Ejemplo n.º 8
0
//*****************************************************************************
//
// Handle the animation when switching between screens.
//
//*****************************************************************************
void
AnimatePanel(uint32_t ui32Color)
{
    int32_t i32Idx;

    GrContextForegroundSet(&g_sContext, ui32Color);

    if(g_i32ScreenIdx == SCREEN_DETAILS) {
        for(i32Idx = BG_MAX_Y; i32Idx >= BG_MIN_Y; i32Idx--) {
            GrLineDrawH(&g_sContext, BG_MIN_X, BG_MAX_X, i32Idx);


            if(i32Idx == 40) {
                WidgetPaint((tWidget *)&g_sHeaderTitle);
                WidgetMessageQueueProcess();
            } else if(i32Idx == 70) {
                WidgetPaint((tWidget *)&g_sHeaderLine1);
                WidgetMessageQueueProcess();
            } else if(i32Idx == 100) {
                WidgetPaint((tWidget *)&g_sHeaderLine2);
                WidgetMessageQueueProcess();
            } else if(i32Idx == 130) {
                WidgetPaint((tWidget *)&g_sHeaderLine3);
                WidgetMessageQueueProcess();
            } else if(i32Idx == 160) {
                WidgetPaint((tWidget *)&g_sHeaderLine4);
                WidgetMessageQueueProcess();
            } else if(i32Idx == 190) {
                WidgetPaint((tWidget *)&g_sHeaderLine5);
                WidgetMessageQueueProcess();
            }

            SysCtlDelay(SCREEN_ANIMATE_DELAY);
        }
    } else if(g_i32ScreenIdx == SCREEN_SUMMARY) {
        for(i32Idx = BG_MAX_Y; i32Idx >= BG_MIN_Y; i32Idx--) {
            GrLineDrawH(&g_sContext, BG_MIN_X, BG_MAX_X, i32Idx);

            if(i32Idx == 210) {
                WidgetPaint((tWidget *)&g_sPayloadLine8);
                WidgetMessageQueueProcess();
            } else if(i32Idx == 195) {
                WidgetPaint((tWidget *)&g_sPayloadLine7);
                WidgetMessageQueueProcess();
            } else if(i32Idx == 180) {
                WidgetPaint((tWidget *)&g_sPayloadLine6);
                WidgetMessageQueueProcess();
            } else if(i32Idx == 165) {
                WidgetPaint((tWidget *)&g_sPayloadLine5);
                WidgetMessageQueueProcess();
            } else if(i32Idx == 150) {
                WidgetPaint((tWidget *)&g_sPayloadLine4);
                WidgetMessageQueueProcess();
            } else if(i32Idx == 135) {
                WidgetPaint((tWidget *)&g_sPayloadLine3);
                WidgetMessageQueueProcess();
            } else if(i32Idx == 120) {
                WidgetPaint((tWidget *)&g_sPayloadLine2);
                WidgetMessageQueueProcess();
            } else if(i32Idx == 105) {
                WidgetPaint((tWidget *)&g_sPayloadLine1);
                WidgetMessageQueueProcess();
            } else if(i32Idx == 75) {
                WidgetPaint((tWidget *)&g_sPayloadTitle);
                WidgetMessageQueueProcess();
            } else if(i32Idx == 40) {
                WidgetPaint((tWidget *)&g_sTag);
                WidgetMessageQueueProcess();
                WidgetPaint((tWidget *)&g_sTagTitle);
                WidgetMessageQueueProcess();
            }

            SysCtlDelay(SCREEN_ANIMATE_DELAY);
        }
    } else if(g_i32ScreenIdx == SCREEN_TI) {
        for(i32Idx = BG_MIN_Y; i32Idx < BG_MAX_Y; i32Idx++) {
            GrLineDrawH(&g_sContext, BG_MIN_X, BG_MAX_X, i32Idx);

            if (i32Idx == 100) {
                GrImageDraw(&g_sContext, g_pui8TILogo, BG_MIN_X,
                            BG_MIN_Y);
            } else if(i32Idx == 140) {
                WidgetPaint((tWidget *)&g_sStatusLine1);
                WidgetMessageQueueProcess();
                GrContextForegroundSet(&g_sContext, ui32Color);
            } else if(i32Idx == 170) {
                //DrawToggle(&sProxyToggle, g_sConfig.bProxyEnabled);
                WidgetPaint((tWidget *)&g_sStatusLine2);
                GrContextForegroundSet(&g_sContext, ui32Color);
                WidgetMessageQueueProcess();
            } else if(i32Idx == 230) {
                WidgetPaint((tWidget *)&g_sTINFCButton);
                WidgetPaint((tWidget *)&g_sEchoNFCButton);
                GrContextForegroundSet(&g_sContext, ui32Color);
                WidgetMessageQueueProcess();
            }
            SysCtlDelay(SCREEN_ANIMATE_DELAY);
        }
    }
}
Ejemplo n.º 9
0
//*****************************************************************************
//
//! Draws a check box widget.
//!
//! \param pWidget is a pointer to the check box 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 check box widget on the display.  This is called in
//! response to a \b #WIDGET_MSG_PAINT message.
//!
//! \return None.
//
//*****************************************************************************
static void
CheckBoxPaint(tWidget *pWidget, unsigned long bClick)
{
    tCheckBoxWidget *pCheck;
    tRectangle sRect;
    tContext sCtx;
    long lY;

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

    //
    // Convert the generic widget pointer into a check box widget pointer.
    //
    pCheck = (tCheckBoxWidget *)pWidget;

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

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

    //
    // See if the check box fill style is selected.
    //
    if((pCheck->usStyle & CB_STYLE_FILL) && !bClick)
    {
        //
        // Fill the check box with the fill color.
        //
        GrContextForegroundSet(&sCtx, pCheck->ulFillColor);
        GrRectFill(&sCtx, &(pWidget->sPosition));
    }

    //
    // See if the check box outline style is selected.
    //
    if((pCheck->usStyle & CB_STYLE_OUTLINE) && !bClick)
    {
        //
        // Outline the check box with the outline color.
        //
        GrContextForegroundSet(&sCtx, pCheck->ulOutlineColor);
        GrRectDraw(&sCtx, &(pWidget->sPosition));
    }

    //
    // Draw the check box.
    //
    sRect.sXMin = pWidget->sPosition.sXMin + 2;
    sRect.sYMin = (pWidget->sPosition.sYMin +
                   ((pWidget->sPosition.sYMax - pWidget->sPosition.sYMin -
                     pCheck->usBoxSize + 1) / 2));
    sRect.sXMax = sRect.sXMin + pCheck->usBoxSize - 1;
    sRect.sYMax = sRect.sYMin + pCheck->usBoxSize - 1;
    if(!bClick)
    {
        GrContextForegroundSet(&sCtx, pCheck->ulOutlineColor);
        GrRectDraw(&sCtx, &sRect);
    }

    //
    // Select the foreground color based on whether or not the check box is
    // selected.
    //
    if(pCheck->usStyle & CB_STYLE_SELECTED)
    {
        GrContextForegroundSet(&sCtx, pCheck->ulOutlineColor);
    }
    else
    {
        GrContextForegroundSet(&sCtx, pCheck->ulFillColor);
    }

    //
    // Draw an "X" in the check box.
    //
    GrLineDraw(&sCtx, sRect.sXMin + 1, sRect.sYMin + 1, sRect.sXMax - 1,
               sRect.sYMax - 1);
    GrLineDraw(&sCtx, sRect.sXMin + 1, sRect.sYMax - 1, sRect.sXMax - 1,
               sRect.sYMin + 1);

    //
    // See if the check box text or image style is selected.
    //
    if((pCheck->usStyle & (CB_STYLE_TEXT | CB_STYLE_IMG)) && !bClick)
    {
        //
        // Shrink the clipping region by the size of the check box so that it
        // is not overwritten by further "decorative" portions of the widget.
        //
        sCtx.sClipRegion.sXMin += pCheck->usBoxSize + 4;

        //
        // If the check box 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(pCheck->usStyle & CB_STYLE_OUTLINE)
        {
            sCtx.sClipRegion.sYMin++;
            sCtx.sClipRegion.sXMax--;
            sCtx.sClipRegion.sYMax--;
        }

        //
        // See if the check box image style is selected.
        //
        if(pCheck->usStyle & CB_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(pCheck->pucImage) >
               (sCtx.sClipRegion.sYMax - sCtx.sClipRegion.sYMin))
            {
                lY = sCtx.sClipRegion.sYMin;
            }
            else
            {
                lY = (sCtx.sClipRegion.sYMin +
                      ((sCtx.sClipRegion.sYMax - sCtx.sClipRegion.sYMin -
                        GrImageHeightGet(pCheck->pucImage) + 1) / 2));
            }

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

            //
            // Draw the image next to the check box.
            //
            GrImageDraw(&sCtx, pCheck->pucImage, sCtx.sClipRegion.sXMin, lY);
        }

        //
        // See if the check box text style is selected.
        //
        if(pCheck->usStyle & CB_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(pCheck->pFont) >
               (sCtx.sClipRegion.sYMax - sCtx.sClipRegion.sYMin))
            {
                lY = sCtx.sClipRegion.sYMin;
            }
            else
            {
                lY = (sCtx.sClipRegion.sYMin +
                      ((sCtx.sClipRegion.sYMax - sCtx.sClipRegion.sYMin -
                        GrFontHeightGet(pCheck->pFont) + 1) / 2));
            }

            //
            // Draw the text next to the check box.
            //
            GrContextFontSet(&sCtx, pCheck->pFont);
            GrContextForegroundSet(&sCtx, pCheck->ulTextColor);
            GrContextBackgroundSet(&sCtx, pCheck->ulFillColor);
            GrStringDraw(&sCtx, pCheck->pcText, -1, sCtx.sClipRegion.sXMin,
                         lY, pCheck->usStyle & CB_STYLE_TEXT_OPAQUE);
        }
    }
}
Ejemplo n.º 10
0
//*****************************************************************************
//
//! Draws an image button.
//!
//! \param pWidget 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 *pWidget)
{
    const unsigned char *pucImage;
    tImageButtonWidget *pPush;
    tContext sCtx;
    long lX, lY;

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

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

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

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

    //
    // Compute the center of the image button.
    //
    lX = (pWidget->sPosition.sXMin +
          ((pWidget->sPosition.sXMax - pWidget->sPosition.sXMin + 1) / 2));
    lY = (pWidget->sPosition.sYMin +
          ((pWidget->sPosition.sYMax - pWidget->sPosition.sYMin + 1) / 2));

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

    //
    // Set the foreground and background colors to use for 1 BPP
    // images and text
    //
    GrContextForegroundSet(&sCtx, pPush->ulForegroundColor);
    GrContextBackgroundSet(&sCtx,
                           ((pPush->ulStyle & IB_STYLE_PRESSED) ?
                            pPush->ulPressedColor :
                            pPush->ulBackgroundColor));

    //
    // Do we need to draw the background image?
    //
    if(!(pPush->ulStyle & IB_STYLE_IMAGE_OFF))
    {
        //
        // Get the background image to be drawn.
        //
        pucImage = ((pPush->ulStyle & IB_STYLE_PRESSED) ?
                    pPush->pucPressImage : pPush->pucImage);

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

    //
    // Adjust the drawing position if the button is pressed.
    //
    lX += ((pPush->ulStyle & IB_STYLE_PRESSED) ? pPush->sXOffset : 0);
    lY += ((pPush->ulStyle & IB_STYLE_PRESSED) ? pPush->sYOffset : 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(pPush->pucKeycapImage && !(pPush->ulStyle & IB_STYLE_KEYCAP_OFF))
    {
        //
        // Draw the keycap image.
        //
        GrImageDraw(&sCtx, pPush->pucKeycapImage,
                    lX - (GrImageWidthGet(pPush->pucKeycapImage) / 2),
                    lY - (GrImageHeightGet(pPush->pucKeycapImage) / 2));
    }

    //
    // See if the button text style is selected.
    //
    if(pPush->ulStyle & IB_STYLE_TEXT)
    {
        //
        // Draw the text centered in the middle of the button with offset
        // applied if the button is currently pressed.
        //
        GrContextFontSet(&sCtx, pPush->pFont);
        GrStringDrawCentered(&sCtx, pPush->pcText, -1, lX, lY, 0);
    }
}
Ejemplo n.º 11
0
//*****************************************************************************
//
// Handles paint requests for the primitives canvas widget.
//
//*****************************************************************************
void
OnPrimitivePaint(tWidget *psWidget, tContext *psContext)
{
    uint32_t ui32Idx;
    tRectangle sRect;

    //
    // Draw a vertical sweep of lines from red to green.
    //
    for(ui32Idx = 0; ui32Idx <= 8; ui32Idx++) {
        GrContextForegroundSet(psContext,
                               (((((10 - ui32Idx) * 255) / 10) << ClrRedShift) |
                                (((ui32Idx * 255) / 10) << ClrGreenShift)));
        GrLineDraw(psContext, 115, 120, 5, 120 - (11 * ui32Idx));
    }

    //
    // Draw a horizontal sweep of lines from green to blue.
    //
    for(ui32Idx = 1; ui32Idx <= 10; ui32Idx++) {
        GrContextForegroundSet(psContext,
                               (((((10 - ui32Idx) * 255) / 10) <<
                                 ClrGreenShift) |
                                (((ui32Idx * 255) / 10) << ClrBlueShift)));
        GrLineDraw(psContext, 115, 120, 5 + (ui32Idx * 11), 29);
    }

    //
    // Draw a filled circle with an overlapping circle.
    //
    GrContextForegroundSet(psContext, ClrBrown);
    GrCircleFill(psContext, 185, 69, 40);
    GrContextForegroundSet(psContext, ClrSkyBlue);
    GrCircleDraw(psContext, 205, 99, 30);

    //
    // Draw a filled rectangle with an overlapping rectangle.
    //
    GrContextForegroundSet(psContext, ClrSlateGray);
    sRect.i16XMin = 20;
    sRect.i16YMin = 100;
    sRect.i16XMax = 75;
    sRect.i16YMax = 160;
    GrRectFill(psContext, &sRect);
    GrContextForegroundSet(psContext, ClrSlateBlue);
    sRect.i16XMin += 40;
    sRect.i16YMin += 40;
    sRect.i16XMax += 30;
    sRect.i16YMax += 28;
    GrRectDraw(psContext, &sRect);

    //
    // Draw a piece of text in fonts of increasing size.
    //
    GrContextForegroundSet(psContext, ClrSilver);
    GrContextFontSet(psContext, &g_sFontCm14);
    GrStringDraw(psContext, "Strings", -1, 125, 110, 0);
    GrContextFontSet(psContext, &g_sFontCm18);
    GrStringDraw(psContext, "Strings", -1, 145, 124, 0);
    GrContextFontSet(psContext, &g_sFontCm22);
    GrStringDraw(psContext, "Strings", -1, 165, 142, 0);
    GrContextFontSet(psContext, &g_sFontCm24);
    GrStringDraw(psContext, "Strings", -1, 185, 162, 0);

    //
    // Draw an image.
    //
    GrImageDraw(psContext, g_pui8Logo, 270, 80);
}
Ejemplo n.º 12
0
//*****************************************************************************
//
// A simple demonstration of the features of the Stellaris Graphics Library.
//
//*****************************************************************************
int
main(void)
{
    unsigned long ulIdx;
    tRectangle sRect;

    //
    // Set the clocking to run from the PLL.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_8MHZ);

    //
    // Initialize the display driver.
    //
    Formike128x128x16Init();

    //
    // Turn on the backlight.
    //
    Formike128x128x16BacklightOn();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sFormike128x128x16);

    //
    // Fill the top 15 rows of the screen with blue to create the banner.
    //
    sRect.sXMin = 0;
    sRect.sYMin = 0;
    sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.sYMax = 14;
    GrContextForegroundSet(&g_sContext, ClrDarkBlue);
    GrRectFill(&g_sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrRectDraw(&g_sContext, &sRect);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, &g_sFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "grlib_demo", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 7, 0);

    //
    // Draw a vertical sweep of lines from red to green.
    //
    for(ulIdx = 0; ulIdx <= 10; ulIdx++)
    {
        GrContextForegroundSet(&g_sContext,
                               (((((10 - ulIdx) * 255) / 10) << ClrRedShift) |
                                (((ulIdx * 255) / 10) << ClrGreenShift)));
        GrLineDraw(&g_sContext, 62, 70, 2, 70 - (5 * ulIdx));
    }

    //
    // Draw a horizontal sweep of lines from green to blue.
    //
    for(ulIdx = 1; ulIdx <= 10; ulIdx++)
    {
        GrContextForegroundSet(&g_sContext,
                               (((((10 - ulIdx) * 255) / 10) <<
                                 ClrGreenShift) |
                                (((ulIdx * 255) / 10) << ClrBlueShift)));
        GrLineDraw(&g_sContext, 62, 70, 2 + (ulIdx * 6), 20);
    }

    //
    // Draw a filled circle with an overlapping circle.
    //
    GrContextForegroundSet(&g_sContext, ClrBrown);
    GrCircleFill(&g_sContext, 88, 37, 17);
    GrContextForegroundSet(&g_sContext, ClrSkyBlue);
    GrCircleDraw(&g_sContext, 104, 45, 17);

    //
    // Draw a filled rectangle with an overlapping rectangle.
    //
    GrContextForegroundSet(&g_sContext, ClrSlateGray);
    sRect.sXMin = 4;
    sRect.sYMin = 84;
    sRect.sXMax = 42;
    sRect.sYMax = 104;
    GrRectFill(&g_sContext, &sRect);
    GrContextForegroundSet(&g_sContext, ClrSlateBlue);
    sRect.sXMin += 12;
    sRect.sYMin += 15;
    sRect.sXMax += 12;
    sRect.sYMax += 15;
    GrRectDraw(&g_sContext, &sRect);

    //
    // Draw a piece of text in fonts of increasing size.
    //
    GrContextForegroundSet(&g_sContext, ClrSilver);
    GrStringDraw(&g_sContext, "Strings", -1, 75, 114, 0);

    //
    // Draw an image.
    //
    GrImageDraw(&g_sContext, g_pucLogo, 80, 77);

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&g_sContext);

    //
    // Loop forever.
    //
    while(1)
    {
    }
}
Ejemplo n.º 13
0
//*****************************************************************************
//
// This function displays the splash screen.
//
//*****************************************************************************
static void
DisplaySplash(void)
{
    unsigned long ulIdx;
    tContext sContext;
    tRectangle sRect;

    //
    // Initialize a drawing context.
    //
    GrContextInit(&sContext, &g_sRIT128x96x4Display);

    //
    // Clear the screen.
    //
    sRect.sXMin = 0;
    sRect.sYMin = 0;
    sRect.sXMax = 127;
    sRect.sYMax = 95;
    GrContextForegroundSet(&sContext, ClrBlack);
    GrRectFill(&sContext, &sRect);

    //
    // Draw the splash screen image on the screen.
    //
    GrImageDraw(&sContext, g_pucSplashImage, 0, 10);

    //
    // Draw some text below the splash screen image.
    //
    GrContextForegroundSet(&sContext, ClrWhite);
    GrContextFontSet(&sContext, g_pFontFixed6x8);
    GrStringDrawCentered(&sContext, "Brushed DC Motor", -1, 63, 73, 0);
    GrStringDrawCentered(&sContext, "Reference Design Kit", -1, 63, 81, 0);

    //
    // Flush the drawing operations to the screen.
    //
    GrFlush(&sContext);

    //
    // Delay for 5 seconds while the splash screen is displayed.
    //
    for(ulIdx = 0; ulIdx < 5000; ulIdx++)
    {
        HWREGBITW(&g_ulFlags, FLAG_TICK) = 0;
        while(HWREGBITW(&g_ulFlags, FLAG_TICK) == 0)
        {
        }
    }

    //
    // Ignore any buttons that were pressed while the splash screen was
    // displayed.
    //
    HWREGBITW(&g_ulFlags, FLAG_UP_PRESSED) = 0;
    HWREGBITW(&g_ulFlags, FLAG_DOWN_PRESSED) = 0;
    HWREGBITW(&g_ulFlags, FLAG_LEFT_PRESSED) = 0;
    HWREGBITW(&g_ulFlags, FLAG_RIGHT_PRESSED) = 0;
    HWREGBITW(&g_ulFlags, FLAG_SELECT_PRESSED) = 0;
}
Ejemplo n.º 14
0
//*****************************************************************************
//
// A simple demonstration of the features of the TivaWare Graphics Library.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32Idx;
    tRectangle sRect;

    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPULazyStackingEnable();

    //
    // Set the clocking to run from the PLL.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

    //
    // Initialize the display driver.
    //
    CFAL96x64x16Init();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sCFAL96x64x16);

    //
    // Fill the top 12 rows of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = 11;
    GrContextForegroundSet(&g_sContext, ClrDarkBlue);
    GrRectFill(&g_sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrRectDraw(&g_sContext, &sRect);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "grlib_demo", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 5, 0);

    //
    // Draw a vertical sweep of lines from red to green.
    //
    for(ui32Idx = 0; ui32Idx <= 8; ui32Idx++)
    {
        GrContextForegroundSet(&g_sContext,
                               (((((10 - ui32Idx) * 255) / 8) << ClrRedShift) |
                                (((ui32Idx * 255) / 8) << ClrGreenShift)));
        GrLineDraw(&g_sContext, 60, 60, 0, 60 - (5 * ui32Idx));
    }

    //
    // Draw a horizontal sweep of lines from green to blue.
    //
    for(ui32Idx = 1; ui32Idx <= 11; ui32Idx++)
    {
        GrContextForegroundSet(&g_sContext,
                               (((((11 - ui32Idx) * 255) / 11) <<
                                 ClrGreenShift) |
                                (((ui32Idx * 255) / 11) << ClrBlueShift)));
        GrLineDraw(&g_sContext, 60, 60, (ui32Idx * 5), 20);
    }

    //
    // Draw a filled circle with an overlapping circle.
    //
    GrContextForegroundSet(&g_sContext, ClrBlue);
    GrCircleFill(&g_sContext, 80, 30, 15);
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrCircleDraw(&g_sContext, 80, 30, 15);

    //
    // Draw a filled rectangle with an overlapping rectangle.
    //
    GrContextForegroundSet(&g_sContext, ClrGray);
    sRect.i16XMin = 8;
    sRect.i16YMin = 45;
    sRect.i16XMax = 46;
    sRect.i16YMax = 51;
    GrRectFill(&g_sContext, &sRect);
    GrContextForegroundSet(&g_sContext, ClrWhite);
    sRect.i16XMin += 4;
    sRect.i16YMin += 4;
    sRect.i16XMax += 4;
    sRect.i16YMax += 4;
    GrRectDraw(&g_sContext, &sRect);

    //
    // Draw a piece of text in fonts of increasing size.
    //
    GrContextForegroundSet(&g_sContext, ClrBlack);
    GrStringDraw(&g_sContext, "Strings", -1, 6, 16, 0);
    GrContextForegroundSet(&g_sContext, ClrSilver);
    GrStringDraw(&g_sContext, "Strings", -1, 7, 17, 0);

    //
    // Draw an image.
    //
    GrTransparentImageDraw(&g_sContext, g_pui8Logo, 64, 34, ClrBlack);
#if 0
    GrImageDraw(&g_sContext, g_pui8Logo, 64, 34);
#endif

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&g_sContext);

    //
    // Loop forever.
    //
    while(1)
    {
    }
}
Ejemplo n.º 15
0
void main(void){

    WDT_A_hold(WDT_A_BASE); // Stop WDT

    boardInit(); // Basic GPIO initialization

    clockInit(8000000); // Config clocks. MCLK=SMCLK=FLL=8MHz; ACLK=REFO=32kHz

    Sharp96x96_LCDInit(); // Set up the LCD


    GrContextInit(&g_sContext, &g_sharp96x96LCD);
  	GrContextForegroundSet(&g_sContext, ClrBlack);
  	GrContextBackgroundSet(&g_sContext, ClrWhite);
  	GrContextFontSet(&g_sContext, &g_sFontFixed6x8);
  	GrClearDisplay(&g_sContext);
  	GrFlush(&g_sContext);

	while(1){
		// Intro Screen
		GrClearDisplay(&g_sContext);
		GrStringDrawCentered(&g_sContext,
							 "How to use",
							 AUTO_STRING_LENGTH,
							 48,
							 15,
							 TRANSPARENT_TEXT);
		GrStringDrawCentered(&g_sContext,
							 "the MSP430",
							 AUTO_STRING_LENGTH,
							 48,
							 35,
							 TRANSPARENT_TEXT);
		GrStringDraw(&g_sContext,
					 "Graphics Library",
					 AUTO_STRING_LENGTH,
					 1,
					 51,
					 TRANSPARENT_TEXT);
		GrStringDrawCentered(&g_sContext,
							 "Primitives",
							 AUTO_STRING_LENGTH,
							 48,
							 75,
							 TRANSPARENT_TEXT);

		GrFlush(&g_sContext);
		Delay();
		GrClearDisplay(&g_sContext);

		// Draw pixels and lines on the display
		GrStringDrawCentered(&g_sContext,
							 "Draw Pixels",
							 AUTO_STRING_LENGTH,
							 48,
							 5,
							 TRANSPARENT_TEXT);
		GrStringDrawCentered(&g_sContext,
							 "& Lines",
							 AUTO_STRING_LENGTH,
							 48,
							 15,
							 TRANSPARENT_TEXT);
		GrPixelDraw(&g_sContext, 30, 30);
		GrPixelDraw(&g_sContext, 30, 32);
		GrPixelDraw(&g_sContext, 32, 32);
		GrPixelDraw(&g_sContext, 32, 30);
		GrLineDraw(&g_sContext, 35, 35, 90, 90);
		GrLineDraw(&g_sContext, 5, 80, 80, 20);
		GrLineDraw(&g_sContext,
				   0,
				   GrContextDpyHeightGet(&g_sContext) - 1,
				   GrContextDpyWidthGet(&g_sContext) - 1,
				   GrContextDpyHeightGet(&g_sContext) - 1);
		GrFlush(&g_sContext);
		Delay();
		GrClearDisplay(&g_sContext);

		// Draw circles on the display
		GrStringDraw(&g_sContext,
					 "Draw Circles",
					 AUTO_STRING_LENGTH,
					 10,
					 5,
					 TRANSPARENT_TEXT);
		GrCircleDraw(&g_sContext,
					 30,
					 70,
					 20);
		GrCircleFill(&g_sContext,
					 60,
					 50,
					 30);
		GrFlush(&g_sContext);
		Delay();
		GrClearDisplay(&g_sContext);

		// Draw rectangles on the display
		GrStringDrawCentered(&g_sContext,
							 "Draw Rectangles",
							 AUTO_STRING_LENGTH,
							 48,
							 5,
							 TRANSPARENT_TEXT);
		GrRectDraw(&g_sContext, &myRectangle1);
		GrRectFill(&g_sContext, &myRectangle2);
		// Text below won't be visible on screen due to transparency
		// (foreground colors match)
		GrStringDrawCentered(&g_sContext,
							 "Normal Text",
							 AUTO_STRING_LENGTH,
							 50,
							 50,
							 TRANSPARENT_TEXT);
		// Text below draws foreground and background for opacity
		GrStringDrawCentered(&g_sContext,
							 "Opaque Text",
							 AUTO_STRING_LENGTH,
							 50,
							 65,
							 OPAQUE_TEXT);
		GrContextForegroundSet(&g_sContext, ClrWhite);
		GrContextBackgroundSet(&g_sContext, ClrBlack);
		GrStringDrawCentered(&g_sContext,
							 "Invert Text",
							 AUTO_STRING_LENGTH,
							 50,
							 80,
							 TRANSPARENT_TEXT);
		GrFlush(&g_sContext);
		Delay();

		// Invert the foreground and background colors
		GrContextForegroundSet(&g_sContext, ClrBlack);
		GrContextBackgroundSet(&g_sContext, ClrWhite);
		GrRectFill(&g_sContext, &myRectangle3);
		GrContextForegroundSet(&g_sContext, ClrWhite);
		GrContextBackgroundSet(&g_sContext, ClrBlack);
		GrStringDrawCentered(&g_sContext,
							 "Invert Colors",
							 AUTO_STRING_LENGTH,
							 48,
							 5,
							 TRANSPARENT_TEXT);
		GrRectDraw(&g_sContext, &myRectangle1);
		GrRectFill(&g_sContext, &myRectangle2);
		// Text below won't be visible on screen due to
		// transparency (foreground colors match)
		GrStringDrawCentered(&g_sContext,
							 "Normal Text",
							 AUTO_STRING_LENGTH,
							 50,
							 50,
							 TRANSPARENT_TEXT);
		// Text below draws foreground and background for opacity
		GrStringDrawCentered(&g_sContext,
							 "Opaque Text",
							 AUTO_STRING_LENGTH,
							 50,
							 65,
							 OPAQUE_TEXT);
		// Text below draws with inverted foreground color to become visible
		GrContextForegroundSet(&g_sContext, ClrBlack);
		GrContextBackgroundSet(&g_sContext, ClrWhite);
		GrStringDrawCentered(&g_sContext,
							 "Invert Text",
							 AUTO_STRING_LENGTH,
							 50,
							 80,
							 TRANSPARENT_TEXT);
		GrFlush(&g_sContext);
		Delay();
		GrContextForegroundSet(&g_sContext, ClrBlack);
		GrContextBackgroundSet(&g_sContext, ClrWhite);
		GrClearDisplay(&g_sContext);

		// Draw Images on the display
		GrImageDraw(&g_sContext, &LPRocket_96x37_1BPP_UNCOMP, 3, 28);
		GrFlush(&g_sContext);
		Delay();
		GrClearDisplay(&g_sContext);
		GrImageDraw(&g_sContext, &TI_Logo_69x64_1BPP_UNCOMP, 15, 15);
		GrFlush(&g_sContext);
		Delay();
		// __bis_SR_register(LPM0_bits+GIE); //enter low power mode 0 with interrupts
	}
}
Ejemplo n.º 16
0
static void draw_menu_slide()
{
    /* draw special menu icons instead of standard text and icon layout */
    GrImageDraw(&sContextMenu, (unsigned char *)iconIntro, 47, 41);
    GrImageDraw(&sContextMenu, (unsigned char *)iconChoice, 155, 41);
    GrImageDraw(&sContextMenu, (unsigned char *)iconMcasp, 263, 41);
    GrImageDraw(&sContextMenu, (unsigned char *)iconSpi, 371, 41);
    
    GrImageDraw(&sContextMenu, (unsigned char *)iconUart, 47, 117);
    GrImageDraw(&sContextMenu, (unsigned char *)iconGpio, 155, 117);
    GrImageDraw(&sContextMenu, (unsigned char *)iconTimer, 263, 117);
    GrImageDraw(&sContextMenu, (unsigned char *)iconI2c, 371, 117);
    
    GrImageDraw(&sContextMenu, (unsigned char *)iconUsbMouse, 47, 193);
    GrImageDraw(&sContextMenu, (unsigned char *)iconRtc, 155, 193);
    GrImageDraw(&sContextMenu, (unsigned char *)iconEthernet, 263, 193);
}
Ejemplo n.º 17
0
//*****************************************************************************
//
// Paint the canvas widget containing the next shape to be played.
//
//*****************************************************************************
void
OnNextPiecePaint(tWidget *pWidget, tContext *pContext)
{
    tRectangle sRect;
    unsigned long ulLoop;
    int iRow, iCol, iOff, iDelta, iXOff, iYOff;

    //
    // Clear the widget background.
    //
    GrContextForegroundSet(pContext, BACKGROUND_COLOR);
    GrRectFill(pContext, &pWidget->sPosition);

    //
    // Although no game piece occupies more than 2 colums in its starting
    // configuration, the definitions actually span 3 colums.  Check for cases
    // that are defined using the second and third columns and move these one
    // block to the left to keep everything in the same 2 columns of the
    // display.  We also use this loop to set the X and Y offset required to
    // center the piece in the canvas widget.
    //
    iDelta = 1;
    iXOff = 0;
    iYOff = GAME_BLOCK_SIZE / 2;

    for(ulLoop = 0; ulLoop < 3; ulLoop++)
    {
        //
        // Does this offset extend into the third column?
        //
        if(nextshape->off[ulLoop] > 2)
        {
            //
            // Yes - we need to move the shape one cell left to keep it
            // within the bounds of the widget.
            //
            iDelta = 0;
            break;
        }

        //
        // If we find an offset of 2, this means we are dealing with the
        // 4-in-a-line shape so we need to muck with the X and Y offset to
        // ensure it is centered in the widget.  Yes - this is a somewhat
        // tacky inference to make but, hey, it works.
        //
        if(nextshape->off[ulLoop] == 2)
        {
            iXOff = -(GAME_BLOCK_SIZE / 2);
            iYOff = 0;
        }
    }

    //
    // Now draw the game piece.  A block at offset (0,0) is always assumed.
    //
    iOff = 0;
    for(ulLoop = 0; ulLoop < 4; ulLoop++)
    {
        //
        // What is the row and column offset for this block in the shape?  This
        // is somewhat awkward since the blocks comprising each shape are
        // defined in terms of index offsets within the board array rather
        // than (x, y) coordinates.
        //
        if(iOff <= -(B_COLS - 1))
        {
            iRow = -1;
            iCol = (iOff + B_COLS);
        }
        else if(iOff >= (B_COLS - 1))
        {
            iRow = 1;
            iCol = (iOff - B_COLS);
        }
        else
        {
            iRow = 0;
            iCol = iOff;
        }

        sRect.sXMin = pWidget->sPosition.sXMin + iXOff +
                      (GAME_BLOCK_SIZE * (iRow + iDelta));
        sRect.sYMin = pWidget->sPosition.sYMin + iYOff +
                      (GAME_BLOCK_SIZE * (iCol + 1));
        sRect.sXMax = sRect.sXMin + (GAME_BLOCK_SIZE - 1);
        sRect.sYMax = sRect.sYMin + (GAME_BLOCK_SIZE - 1);

        //
        // Draw this block of the shape.  We use either an image if one is
        // defined or black otherwise.
        //
        if(g_ppucBlockImages[nextshape->color])
        {
            GrImageDraw(pContext, g_ppucBlockImages[nextshape->color],
                        (long)sRect.sXMin, (long)sRect.sYMin);
        }
        else
        {
            GrContextForegroundSet(pContext, BACKGROUND_COLOR);
            GrRectFill(pContext, &sRect);
        }

        //
        // Get the offset of the next block.
        //
        if(ulLoop < 3)
        {
            iOff = nextshape->off[ulLoop];
        }
    }
}
Ejemplo n.º 18
0
//*****************************************************************************
//
// This task receives messages from the other tasks and updates the display as
// directed.
//
//*****************************************************************************
static void
DisplayTask(void *pvParameters)
{
    tDisplayMessage sMessage;
    tContext sContext;

    //
    // Initialize the graphics library context.
    //
    GrContextInit(&sContext, &g_sKitronix320x240x16_SSD2119);
    GrContextForegroundSet(&sContext, ClrWhite);
    GrContextBackgroundSet(&sContext, ClrBlack);
    GrContextFontSet(&sContext, g_pFontFixed6x8);

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Read the next message from the queue.
        //
        if(xQueueReceive(g_pDisplayQueue, &sMessage, portMAX_DELAY) == pdPASS)
        {
            //
            // Determine the message type.
            //
            switch(sMessage.ulType)
            {
                //
                // The drawing of an image has been requested.
                //
                case DISPLAY_IMAGE:
                {
                    //
                    // Draw this image on the display.
                    //
                    GrImageDraw(&sContext, (unsigned char *)sMessage.pcMessage,
                                sMessage.usX, sMessage.usY);

                    //
                    // This message has been handled.
                    //
                    break;
                }

                //
                // The drawing of a string has been requested.
                //
                case DISPLAY_STRING:
                {
                    //
                    // Draw this string on the display.
                    //
                    GrStringDraw(&sContext, sMessage.pcMessage, -1,
                                 sMessage.usX, sMessage.usY, 1);

                    //
                    // This message has been handled.
                    //
                    break;
                }

                //
                // A move of the pen has been requested.
                //
                case DISPLAY_MOVE:
                {
                    //
                    // Save the new pen position.
                    //
                    g_ulDisplayX = sMessage.usX;
                    g_ulDisplayY = sMessage.usY;

                    //
                    // This message has been handled.
                    //
                    break;
                }

                //
                // A draw with the pen has been requested.
                //
                case DISPLAY_DRAW:
                {
                    //
                    // Draw a line from the previous pen position to the new
                    // pen position.
                    //
                    GrLineDraw(&sContext, g_ulDisplayX, g_ulDisplayY,
                               sMessage.usX, sMessage.usY);

                    //
                    // Save the new pen position.
                    //
                    g_ulDisplayX = sMessage.usX;
                    g_ulDisplayY = sMessage.usY;

                    //
                    // This message has been handled.
                    //
                    break;
                }
            }
        }
    }
}
Ejemplo n.º 19
0
//*****************************************************************************
//
// Paint the blocks in the game play area.
//
//*****************************************************************************
void
OnGameAreaPaint(tWidget *pWidget, tContext *pContext)
{
    static const struct shape *psLastShape;
    static tBoolean bLastMsgShown = false;
    unsigned long ulIndex, ulRow, ulCol;
    tRectangle rectBlock;

    //
    // Update the score if necessary.
    //
    if (score != g_iCurScore)
    {
        usnprintf(g_pcScore, MAX_SCORE_LEN, "  %d  ", score);
        WidgetPaint((tWidget *)&g_sScore);
        g_iCurScore = score;
    }

    //
    // Draw a preview of the next shape if it is different
    //
    if (nextshape != psLastShape)
    {
        WidgetPaint((tWidget *)&g_sNextPiece);
        psLastShape = nextshape;
    }

    //
    // Has the screen just been cleared? If so, we fill the whole background
    // in a single operation rather than doing it cell-by-cell.
    //
    if(g_bScreenCleared)
    {
        //
        // Draw the logo into the background of the game area.
        //
        GrImageDraw(&g_sScreenContext, g_pucTILogo240x120,
                    GAME_AREA_LEFT, GAME_AREA_TOP);
    }

    //
    // Loop through the rows (which are actually columns in our implementation
    // since we've rotated the board).
    //
    for (ulRow = D_FIRST; ulRow < (D_LAST - 1); ulRow++)
    {
        //
        // Get the index of the first block in this row.
        //
        ulIndex = ulRow * B_COLS;

        //
        // Loop through all the displayed colums (rows in our implementation)
        //
        for (ulCol = 1; ulCol < (B_COLS - 1); ulCol++)
        {
            //
            // If the block on the screen is different from the one we have been
            // asked to draw, draw it.  We also force a redraw of everything if
            // we had a message displayed last time we repainted but it has
            // since been removed.
            //
            if ((board[ulIndex + ulCol] != g_psCurScreen[ulIndex + ulCol]) ||
               (bLastMsgShown && !g_bMsgShown))
            {
                //
                // Calculate the coordinates of this block.
                //
                rectBlock.sXMin = GAME_AREA_LEFT +
                                  ((ulRow - D_FIRST) * GAME_BLOCK_SIZE);
                rectBlock.sYMin = GAME_AREA_TOP +
                                  ((ulCol - 1) * GAME_BLOCK_SIZE);
                rectBlock.sXMax = rectBlock.sXMin + (GAME_BLOCK_SIZE - 1);
                rectBlock.sYMax = rectBlock.sYMin + (GAME_BLOCK_SIZE - 1);

                //
                // Remember what we are about to draw into the current cell.
                //
                g_psCurScreen[ulIndex + ulCol] = board[ulIndex + ulCol];

                //
                // Draw this block of the shape.  We use either an image if one
                // is defined or black otherwise.
                //
                if(g_ppucBlockImages[board[ulIndex + ulCol]])
                {
                    //
                    // If we just cleared the whole background, there is no
                    // need to reblit the background blocks.
                    //
                    if(!g_bScreenCleared)
                    {
                        GrImageDraw(&g_sScreenContext,
                                    g_ppucBlockImages[board[ulIndex + ulCol]],
                                    (long)rectBlock.sXMin,
                                    (long)rectBlock.sYMin);
                    }
                }
                else
                {
                    tRectangle sRect;

                    //
                    // Draw the block from the background image.  First save
                    // the existing clipping region.
                    //
                    sRect = g_sScreenContext.sClipRegion;

                    //
                    // Set the new clipping region to the block we are about
                    // to draw.
                    //
                    GrContextClipRegionSet(&g_sScreenContext, &rectBlock);

                    //
                    // Draw the background image into the clipping region.
                    //
                    GrImageDraw(&g_sScreenContext, g_pucTILogo240x120,
                                GAME_AREA_LEFT, GAME_AREA_TOP);

                    //
                    // Restore the previous clip region.
                    //
                    GrContextClipRegionSet(&g_sScreenContext, &sRect);
                }
            }
        }
    }

    //
    // If there is a message to show, draw it on top of the game area.
    //
    if(g_bMsgShown)
    {
        //
        // Determine the center of the game area.
        //
        rectBlock.sXMin = GAME_AREA_LEFT +
                          (GAME_BLOCK_SIZE * ((D_LAST - 1) - D_FIRST)) / 2;
        rectBlock.sYMin = GAME_AREA_TOP +
                          ((GAME_BLOCK_SIZE * (B_COLS - 2)) / 2);

        //
        // Render the required message centered in the game area.
        //
        GrContextFontSet(&g_sScreenContext, g_pFontCmss20b);
        GrContextForegroundSet(&g_sScreenContext, MESSAGE_COLOR);
        GrContextBackgroundSet(&g_sScreenContext, BACKGROUND_COLOR);
        GrStringDrawCentered(&g_sScreenContext, g_pcMessage, -1,
                             rectBlock.sXMin, rectBlock.sYMin, true);
    }

    //
    // Remember whether we displayed the message or not.
    //
    bLastMsgShown = g_bMsgShown;

    //
    // Clear the flag that we use to indicate the first redraw in a new game.
    //
    g_bScreenCleared = false;
}
Ejemplo n.º 20
0
//*****************************************************************************
//
// Handles paint requests for the primitives canvas widget.
//
//*****************************************************************************
void
OnPrimitivePaint(tWidget *pWidget, tContext *pContext)
{
    unsigned long ulIdx;
    tRectangle sRect;

    //
    // Draw a vertical sweep of lines from red to green.
    //
    for(ulIdx = 0; ulIdx <= 8; ulIdx++)
    {
        GrContextForegroundSet(pContext,
                               (((((10 - ulIdx) * 255) / 10) << ClrRedShift) |
                                (((ulIdx * 255) / 10) << ClrGreenShift)));
        GrLineDraw(pContext, 115, 120, 5, 120 - (11 * ulIdx));
    }

    //
    // Draw a horizontal sweep of lines from green to blue.
    //
    for(ulIdx = 1; ulIdx <= 10; ulIdx++)
    {
        GrContextForegroundSet(pContext,
                               (((((10 - ulIdx) * 255) / 10) <<
                                 ClrGreenShift) |
                                (((ulIdx * 255) / 10) << ClrBlueShift)));
        GrLineDraw(pContext, 115, 120, 5 + (ulIdx * 11), 29);
    }

    //
    // Draw a filled circle with an overlapping circle.
    //
    GrContextForegroundSet(pContext, ClrBrown);
    GrCircleFill(pContext, 185, 69, 40);
    GrContextForegroundSet(pContext, ClrSkyBlue);
    GrCircleDraw(pContext, 205, 99, 30);

    //
    // Draw a filled rectangle with an overlapping rectangle.
    //
    GrContextForegroundSet(pContext, ClrSlateGray);
    sRect.sXMin = 20;
    sRect.sYMin = 100;
    sRect.sXMax = 75;
    sRect.sYMax = 160;
    GrRectFill(pContext, &sRect);
    GrContextForegroundSet(pContext, ClrSlateBlue);
    sRect.sXMin += 40;
    sRect.sYMin += 40;
    sRect.sXMax += 30;
    sRect.sYMax += 28;
    GrRectDraw(pContext, &sRect);

    //
    // Draw a piece of text in fonts of increasing size.
    //
    GrContextForegroundSet(pContext, ClrSilver);
    GrContextFontSet(pContext, g_pFontFixed6x8);
    GrStringDraw(pContext, "Strings", -1, 125, 110, 0);
    GrContextFontSet(pContext, g_pFontCmss18b);
    GrStringDraw(pContext, "Strings", -1, 145, 124, 0);
    GrContextFontSet(pContext, g_pFontCmss22b);
    GrStringDraw(pContext, "Strings", -1, 165, 142, 0);

    //
    // Draw an image.
    //
    GrImageDraw(pContext, g_pucTISymbol_80x75, 240, 80);
}
//*****************************************************************************
//
//! 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;
    long 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);
    }
}
Ejemplo n.º 22
0
//*****************************************************************************
//
//! Draws the current menu into a drawing context, off-screen buffer.
//!
//! \param psMenuWidget points at the SlideMenuWidget being processed.
//! \param psContext points to the context where all drawing should be done.
//! \param i32OffsetY is the Y offset for drawing the menu.
//!
//! This function renders a menu (set of menu items), into a drawing context.
//! It assumes that the drawing context is an off-screen buffer, and that
//! the entire buffer belongs to this widget.  The vertical position of the
//! menu can be adjusted by using the parameter i32OffsetY.  This value can be
//! positive or negative and can cause the menu to be rendered above or below
//! the normal position in the display.
//!
//! \return None.
//
//*****************************************************************************
void
SlideMenuDraw(tSlideMenuWidget *psMenuWidget, tContext *psContext,
              int32_t i32OffsetY)
{
    tSlideMenu *psMenu;
    uint32_t ui32Idx;
    tRectangle sRect;

    //
    // Check the arguments
    //
    ASSERT(psMenuWidget);
    ASSERT(psContext);

    //
    // Set the foreground color for the rectangle fill to match what we want
    // as the menu background.
    //
    GrContextForegroundSet(psContext, psMenuWidget->ui32ColorBackground);
    GrRectFill(psContext, &psContext->sClipRegion);

    //
    // Get the current menu that is being displayed
    //
    psMenu = psMenuWidget->psSlideMenu;

    //
    // Set the foreground to the color we want for the menu item boundaries
    // and text color, text font.
    //
    GrContextForegroundSet(psContext, psMenuWidget->ui32ColorForeground);
    GrContextFontSet(psContext, psMenuWidget->psFont);

    //
    // Set the rectangle bounds for the first menu item.
    // The starting Y value is calculated based on which menu item is currently
    // centered.  Y coordinates are subtracted to find the Y start location
    // of the first menu item, which could even be off the display.
    //
    // Set the X coords of the menu item to the extents of the display
    //
    sRect.i16XMin = 0;
    sRect.i16XMax = psContext->sClipRegion.i16XMax;

    //
    // Find the Y coordinate of the centered menu item
    //
    sRect.i16YMin = (psContext->psDisplay->ui16Height / 2) -
                    (psMenuWidget->ui32MenuItemHeight / 2);

    //
    // Adjust to find Y coordinate of first menu item
    //
    sRect.i16YMin -= psMenu->ui32CenterIndex * psMenuWidget->ui32MenuItemHeight;

    //
    // Now adjust for the offset that was passed in by caller.  This allows
    // for drawing menu items above or below the main display.
    //
    sRect.i16YMin += i32OffsetY;

    //
    // Find the ending Y coordinate of first menu item
    //
    sRect.i16YMax = sRect.i16YMin + psMenuWidget->ui32MenuItemHeight - 1;

    //
    // Start the index at the first menu item.  It is possible that this
    // menu item is off the display.
    //
    ui32Idx = 0;

    //
    // Loop through all menu items, drawing on the display.  Note that some
    // may not be on the screen, but they will be clipped.
    //
    while(ui32Idx < psMenu->ui32Items)
    {
        //
        // If this index is the one that is highlighted, then change the
        // background
        //
        if(ui32Idx == psMenu->ui32FocusIndex)
        {
            //
            // Set the foreground to the highlight color, and fill the
            // rectangle of the background of this menu item.
            //
            GrContextForegroundSet(psContext, psMenuWidget->ui32ColorHighlight);
            GrRectFill(psContext, &sRect);

            //
            // Set the new foreground to the normal foreground color, and
            // set the background to the highlight color.  This is so
            // remaining drawing operations will have the correct background
            // and foreground colors for this highlighted menu item cell.
            //
            GrContextForegroundSet(psContext, psMenuWidget->ui32ColorForeground);
            GrContextBackgroundSet(psContext, psMenuWidget->ui32ColorHighlight);

            //
            // If this menu has a parent, then draw a left arrow icon on the
            // focused menu item.
            //
            if(psMenu->psParent)
            {
                GrImageDraw(psContext, g_ui8LtArrow, sRect.i16XMin + 4,
                            sRect.i16YMin +
                            (psMenuWidget->ui32MenuItemHeight / 2) - 4);
            }

            //
            // If this menu has a child menu or child widget, then draw a
            // right arrow icon on the focused menu item.
            //
            if(psMenu->psSlideMenuItems[ui32Idx].psChildMenu ||
               psMenu->psSlideMenuItems[ui32Idx].psChildWidget)
            {
                GrImageDraw(psContext, g_ui8RtArrow, sRect.i16XMax - 8,
                            sRect.i16YMin +
                            (psMenuWidget->ui32MenuItemHeight / 2) - 4);
            }
        }

        //
        // Otherwise this is a normal, non-highlighted menu item cell,
        // so set the normal background color.
        //
        else
        {
            GrContextBackgroundSet(psContext, psMenuWidget->ui32ColorBackground);
        }

        //
        // If the current menu is multi-selectable, then draw a checkbox on
        // the menu item.  Draw a checked or unchecked box depending on whether
        // the item has been selected.
        //
        if(psMenu->bMultiSelectable)
        {
            if(psMenu->ui32SelectedFlags & (1 << ui32Idx))
            {
                GrImageDraw(psContext, g_ui8Checked, sRect.i16XMax - 12,
                            sRect.i16YMin +
                            (psMenuWidget->ui32MenuItemHeight / 2) - 4);
            }
            else
            {
                GrImageDraw(psContext, g_ui8Unchecked, sRect.i16XMax - 12,
                            sRect.i16YMin +
                            (psMenuWidget->ui32MenuItemHeight / 2) - 4);
            }

        }

        //
        // Draw the rectangle representing the menu item
        //
        GrRectDraw(psContext, &sRect);

        //
        // Draw the text for this menu item in the middle of the menu item
        // rectangle (cell).
        //
        GrStringDrawCentered(psContext,
                             psMenu->psSlideMenuItems[ui32Idx].pcText,
                             -1,
                             psMenuWidget->sBase.psDisplay->ui16Width / 2,
                             sRect.i16YMin + \
                             (psMenuWidget->ui32MenuItemHeight / 2) - 1, 0);

        //
        // Advance to the next menu item, and update the menu item rectangle
        // bounds to the next position
        //
        ui32Idx++;
        sRect.i16YMin += psMenuWidget->ui32MenuItemHeight;
        sRect.i16YMax += psMenuWidget->ui32MenuItemHeight;

        //
        // Note that this may attempt to render menu items that run off the
        // bottom of the drawing area, but these will just be clipped and a
        // little bit of processing time is wasted.
        //
    }
}
Ejemplo n.º 23
0
//*****************************************************************************
//
//! Draws a slider.
//!
//! \param pWidget is a pointer to the slider widget to be drawn.
//! \param pDirty 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 *pWidget, tRectangle *pDirty)
{
    tRectangle sClipRect, sValueRect, sEmptyRect, sActiveClip;
    tSliderWidget *pSlider;
    tContext sCtx;
    long lX, lY, bIntersect;
    short sPos;

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

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

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

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

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

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

        if(sClipRect.sYMin == pWidget->sPosition.sYMin)
        {
            sClipRect.sYMin++;
        }

        if(sClipRect.sXMax == pWidget->sPosition.sXMax)
        {
            sClipRect.sXMax--;
        }

        if(sClipRect.sYMax == pWidget->sPosition.sYMax)
        {
            sClipRect.sYMax--;
        }
    }

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

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

    //
    // Determine the rectangles for the active and empty portions of the
    // widget.
    //
    if(pSlider->ulStyle & SL_STYLE_VERTICAL)
    {
        //
        // Determine the rectangle corresponding to the bottom (value) portion
        // of the slider.
        //
        sValueRect.sXMin = pWidget->sPosition.sXMin;
        sValueRect.sXMax = pWidget->sPosition.sXMax;
        sValueRect.sYMin = sPos;
        sValueRect.sYMax = pWidget->sPosition.sYMax;

        //
        // Determine the rectangle corresponding to the top (empty) portion
        // of the slider.
        //
        sEmptyRect.sXMin = pWidget->sPosition.sXMin;
        sEmptyRect.sXMax = pWidget->sPosition.sXMax;
        sEmptyRect.sYMin = pWidget->sPosition.sYMin;
        sEmptyRect.sYMax = max(sEmptyRect.sYMin, sValueRect.sYMin - 1);
    }
    else
    {
        //
        // Determine the rectangle corresponding to the bottom (value) portion
        // of the slider.
        //
        sValueRect.sYMin = pWidget->sPosition.sYMin;
        sValueRect.sYMax = pWidget->sPosition.sYMax;
        sValueRect.sXMin = pWidget->sPosition.sXMin;
        sValueRect.sXMax = sPos;

        //
        // Determine the rectangle corresponding to the top (empty) portion
        // of the slider.
        //
        sEmptyRect.sYMin = pWidget->sPosition.sYMin;
        sEmptyRect.sYMax = pWidget->sPosition.sYMax;
        sEmptyRect.sXMax = pWidget->sPosition.sXMax;
        sEmptyRect.sXMin = min(sEmptyRect.sXMax, sValueRect.sXMax + 1);
    }

    //
    // Compute the center of the slider.  This will be needed later if drawing
    // text or an image.
    //
    lX = (pWidget->sPosition.sXMin +
          ((pWidget->sPosition.sXMax - pWidget->sPosition.sXMin + 1) / 2));
    lY = (pWidget->sPosition.sYMin +
          ((pWidget->sPosition.sYMax - pWidget->sPosition.sYMin + 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->ulStyle & SL_STYLE_FILL)
        {
            GrContextForegroundSet(&sCtx, pSlider->ulFillColor);
            GrRectFill(&sCtx, &sValueRect);
        }

        //
        // Do we need to draw an image in the active area?
        //
        if(pSlider->ulStyle & SL_STYLE_IMG)
        {
            GrContextForegroundSet(&sCtx, pSlider->ulTextColor);
            GrContextBackgroundSet(&sCtx, pSlider->ulFillColor);
            GrImageDraw(&sCtx, pSlider->pucImage,
                        lX - (GrImageWidthGet(pSlider->pucImage) / 2),
                        lY - (GrImageHeightGet(pSlider->pucImage) / 2));
        }

        //
        // Do we need to render a text string over the top of the active area?
        //
        if(pSlider->ulStyle & SL_STYLE_TEXT)
        {
            GrContextFontSet(&sCtx, pSlider->pFont);
            GrContextForegroundSet(&sCtx, pSlider->ulTextColor);
            GrContextBackgroundSet(&sCtx, pSlider->ulFillColor);
            GrStringDrawCentered(&sCtx, pSlider->pcText, -1, lX, lY,
                                 pSlider->ulStyle & 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->ulStyle & SL_STYLE_BACKG_FILL)
        {
            GrContextForegroundSet(&sCtx, pSlider->ulBackgroundFillColor);
            GrRectFill(&sCtx, &sEmptyRect);
        }

        //
        // Do we need to draw an image in the active area?
        //
        if(pSlider->ulStyle & SL_STYLE_BACKG_IMG)
        {
            GrContextForegroundSet(&sCtx, pSlider->ulBackgroundTextColor);
            GrContextBackgroundSet(&sCtx, pSlider->ulBackgroundFillColor);
            GrImageDraw(&sCtx, pSlider->pucBackgroundImage,
                    lX - (GrImageWidthGet(pSlider->pucBackgroundImage) / 2),
                    lY - (GrImageHeightGet(pSlider->pucBackgroundImage) / 2));
        }

        //
        // Do we need to render a text string over the top of the active area?
        //
        if(pSlider->ulStyle & SL_STYLE_BACKG_TEXT)
        {
            GrContextFontSet(&sCtx, pSlider->pFont);
            GrContextForegroundSet(&sCtx, pSlider->ulBackgroundTextColor);
            GrContextBackgroundSet(&sCtx, pSlider->ulBackgroundFillColor);
            GrStringDrawCentered(&sCtx, pSlider->pcText, -1, lX, lY,
                                 pSlider->ulStyle & SL_STYLE_BACKG_TEXT_OPAQUE);
        }
    }
}
Ejemplo n.º 24
0
//*****************************************************************************
//
// Initialize and operate the data logger.
//
//*****************************************************************************
int
main(void)
{
    tContext sDisplayContext, sBufferContext;
    uint32_t ui32HibIntStatus, ui32SysClock, ui32LastTickCount;
    bool bSkipSplash;
    uint8_t ui8ButtonState, ui8ButtonChanged;
    uint_fast8_t ui8X, ui8Y;


    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    MAP_FPULazyStackingEnable();

    //
    // Set the clocking to run at 50 MHz.
    //
    MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);
    ui32SysClock = MAP_SysCtlClockGet();

    //
    // Initialize locals.
    //
    bSkipSplash = false;
    ui32LastTickCount = 0;

    //
    // Initialize the data acquisition module.  This initializes the ADC
    // hardware.
    //
    AcquireInit();

    //
    // Enable access to  the hibernate peripheral.  If the hibernate peripheral
    // was already running then this will have no effect.
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);

    //
    // Check to see if the hiberate module is already active and if so then
    // read the saved configuration state.  If both are okay, then proceed
    // to check and see if we are logging data using sleep mode.
    //
    if(HibernateIsActive() && !GetSavedState(&g_sConfigState))
    {
        //
        // Read the status of the hibernate module.
        //
        ui32HibIntStatus = HibernateIntStatus(1);

        //
        // If this is a pin wake, that means the user pressed the select
        // button and we should terminate the sleep logging.  In this case
        // we will fall out of this conditional section, and go through the
        // normal startup below, but skipping the splash screen so the user
        // gets immediate response.
        //
        if(ui32HibIntStatus & HIBERNATE_INT_PIN_WAKE)
        {
            //
            // Clear the interrupt flag so it is not seen again until another
            // wake.
            //
            HibernateIntClear(HIBERNATE_INT_PIN_WAKE);
            bSkipSplash = true;
        }

        //
        // Otherwise if we are waking from hibernate and it was not a pin
        // wake, then it must be from RTC match.  Check to see if we are
        // sleep logging and if so then go through an abbreviated startup
        // in order to collect the data and go back to sleep.
        //
        else if(g_sConfigState.ui32SleepLogging &&
                (ui32HibIntStatus & HIBERNATE_INT_RTC_MATCH_0))
        {
            //
            // Start logger and pass the configuration.  The logger should
            // configure itself to take one sample.
            //
            AcquireStart(&g_sConfigState);
            g_iLoggerState = eSTATE_LOGGING;

            //
            // Enter a forever loop to run the acquisition.  This will run
            // until a new sample has been taken and stored.
            //
            while(!AcquireRun())
            {
            }

            //
            // Getting here means that a data acquisition was performed and we
            // can now go back to sleep.  Save the configuration and then
            // activate the hibernate.
            //
            SetSavedState(&g_sConfigState);

            //
            // Set wake condition on pin-wake or RTC match.  Then put the
            // processor in hibernation.
            //
            HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC);
            HibernateRequest();

            //
            // Hibernating takes a finite amount of time to occur, so wait
            // here forever until hibernate activates and the processor
            // power is removed.
            //
            for(;;)
            {
            }
        }

        //
        // Otherwise, this was not a pin wake, and we were not sleep logging,
        // so just fall out of this conditional and go through the normal
        // startup below.
        //
    }
    else
    {
        //
        // In this case, either the hibernate module was not already active, or
        // the saved configuration was not valid.  Initialize the configuration
        // to the default state and then go through the normal startup below.
        //
        GetDefaultState(&g_sConfigState);
    }

    //
    // Enable the Hibernate module to run.
    //
    HibernateEnableExpClk(SysCtlClockGet());

    //
    // The hibernate peripheral trim register must be set per silicon
    // erratum 2.1
    //
    HibernateRTCTrimSet(0x7FFF);

    //
    // Start the RTC running.  If it was already running then this will have
    // no effect.
    //
    HibernateRTCEnable();

    //
    // In case we were sleep logging and are now finished (due to user
    // pressing select button), then disable sleep logging so it doesnt
    // try to start up again.
    //
    g_sConfigState.ui32SleepLogging = 0;
    SetSavedState(&g_sConfigState);

    //
    // Initialize the display driver.
    //
    CFAL96x64x16Init();

    //
    // Initialize the buttons driver.
    //
    ButtonsInit();

    //
    // Pass the restored state to the menu system.
    //
    MenuSetState(&g_sConfigState);

    //
    // Enable the USB peripheral
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);

    //
    // Configure the required pins for USB operation.
    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    MAP_GPIOPinConfigure(GPIO_PG4_USB0EPEN);
    MAP_GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
    MAP_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7);
    MAP_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Erratum workaround for silicon revision A1.  VBUS must have pull-down.
    //
    if(CLASS_IS_BLIZZARD && REVISION_IS_A1)
    {
        HWREG(GPIO_PORTB_BASE + GPIO_O_PDR) |= GPIO_PIN_1;
    }

    //
    // Initialize the USB stack mode and pass in a mode callback.
    //
    USBStackModeSet(0, eUSBModeOTG, ModeCallback);

    //
    // Initialize the stack to be used with USB stick.
    //
    USBStickInit();

    //
    // Initialize the stack to be used as a serial device.
    //
    USBSerialInit();

    //
    // Initialize the USB controller for dual mode operation with a 2ms polling
    // rate.
    //
    USBOTGModeInit(0, 2000, g_pui8HCDPool, HCD_MEMORY_SIZE);

    //
    // Initialize the menus module.  This module will control the user
    // interface menuing system.
    //
    MenuInit(WidgetActivated);

    //
    // Configure SysTick to periodically interrupt.
    //
    g_ui32TickCount = 0;
    MAP_SysTickPeriodSet(ui32SysClock / CLOCK_RATE);
    MAP_SysTickIntEnable();
    MAP_SysTickEnable();

    //
    // Initialize the display context and another context that is used
    // as an offscreen drawing buffer for display animation effect
    //
    GrContextInit(&sDisplayContext, &g_sCFAL96x64x16);
    GrContextInit(&sBufferContext, &g_sOffscreenDisplayA);

    //
    // Show the splash screen if we are not skipping it.  The only reason to
    // skip it is if the application was in sleep-logging mode and the user
    // just waked it up with the select button.
    //
    if(!bSkipSplash)
    {
        const uint8_t *pui8SplashLogo = g_pui8Image_TI_Black;

        //
        // Draw the TI logo on the display.  Use an animation effect where the
        // logo will "slide" onto the screen.  Allow select button to break
        // out of animation.
        //
        for(ui8X = 0; ui8X < 96; ui8X++)
        {
            if(ButtonsPoll(0, 0) & SELECT_BUTTON)
            {
                break;
            }
            GrImageDraw(&sDisplayContext, pui8SplashLogo, 95 - ui8X, 0);
        }

        //
        // Leave the logo on the screen for a long duration.  Monitor the
        // buttons so that if the user presses the select button, the logo
        // display is terminated and the application starts immediately.
        //
        while(g_ui32TickCount < 400)
        {
            if(ButtonsPoll(0, 0) & SELECT_BUTTON)
            {
                break;
            }
        }

        //
        // Extended splash sequence
        //
        if(ButtonsPoll(0, 0) & UP_BUTTON)
        {
            for(ui8X = 0; ui8X < 96; ui8X += 4)
            {
                GrImageDraw(&sDisplayContext,
                            g_ppui8Image_Splash[(ui8X / 4) & 3],
                            (int32_t)ui8X - 96L, 0);
                GrImageDraw(&sDisplayContext, pui8SplashLogo, ui8X, 0);
                MAP_SysCtlDelay(ui32SysClock / 12);
            }
            MAP_SysCtlDelay(ui32SysClock / 3);
            pui8SplashLogo = g_ppui8Image_Splash[4];
            GrImageDraw(&sDisplayContext, pui8SplashLogo, 0, 0);
            MAP_SysCtlDelay(ui32SysClock / 12);
        }

        //
        // Draw the initial menu into the offscreen buffer.
        //
        SlideMenuDraw(&g_sMenuWidget, &sBufferContext, 0);

        //
        // Now, draw both the TI logo splash screen (from above) and the initial
        // menu on the screen at the same time, moving the coordinates so that
        // the logo "slides" off the display and the menu "slides" onto the
        // display.
        //
        for(ui8Y = 0; ui8Y < 64; ui8Y++)
        {
            GrImageDraw(&sDisplayContext, pui8SplashLogo, 0, -ui8Y);
            GrImageDraw(&sDisplayContext, g_pui8OffscreenBufA, 0, 63 - ui8Y);
        }
    }

    //
    // Add the menu widget to the widget tree and send an initial paint
    // request.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sMenuWidget);
    WidgetPaint(WIDGET_ROOT);

    //
    // Set the focus handle to the menu widget.  Any button events will be
    // sent to this widget
    //
    g_ui32KeyFocusWidgetHandle = (uint32_t)&g_sMenuWidget;

    //
    // Forever loop to run the application
    //
    while(1)
    {

        //
        // Each time the timer tick occurs, process any button events.
        //
        if(g_ui32TickCount != ui32LastTickCount)
        {
            //
            // Remember last tick count
            //
            ui32LastTickCount = g_ui32TickCount;

            //
            // Read the debounced state of the buttons.
            //
            ui8ButtonState = ButtonsPoll(&ui8ButtonChanged, 0);

            //
            // Pass any button presses through to the widget message
            // processing mechanism.  The widget that has the button event
            // focus (probably the menu widget) will catch these button events.
            //
            if(BUTTON_PRESSED(SELECT_BUTTON, ui8ButtonState, ui8ButtonChanged))
            {
                SendWidgetKeyMessage(WIDGET_MSG_KEY_SELECT);
            }
            if(BUTTON_PRESSED(UP_BUTTON, ui8ButtonState, ui8ButtonChanged))
            {
                SendWidgetKeyMessage(WIDGET_MSG_KEY_UP);
            }
            if(BUTTON_PRESSED(DOWN_BUTTON, ui8ButtonState, ui8ButtonChanged))
            {
                SendWidgetKeyMessage(WIDGET_MSG_KEY_DOWN);
            }
            if(BUTTON_PRESSED(LEFT_BUTTON, ui8ButtonState, ui8ButtonChanged))
            {
                SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT);
            }
            if(BUTTON_PRESSED(RIGHT_BUTTON, ui8ButtonState, ui8ButtonChanged))
            {
                SendWidgetKeyMessage(WIDGET_MSG_KEY_RIGHT);
            }
        }

        //
        // Tell the OTG library code how much time has passed in milliseconds
        // since the last call.
        //
        USBOTGMain(GetTickms());

        //
        // Call functions as needed to keep the host or device mode running.
        //
        if(g_iCurrentUSBMode == eUSBModeDevice)
        {
            USBSerialRun();
        }
        else if(g_iCurrentUSBMode == eUSBModeHost)
        {
            USBStickRun();
        }

        //
        // If in the logging state, then call the logger run function.  This
        // keeps the data acquisition running.
        //
        if((g_iLoggerState == eSTATE_LOGGING) ||
           (g_iLoggerState == eSTATE_VIEWING))
        {
            if(AcquireRun() && g_sConfigState.ui32SleepLogging)
            {
                //
                // If sleep logging is enabled, then at this point we have
                // stored the first data item, now save the state and start
                // hibernation.  Wait for the power to be cut.
                //
                SetSavedState(&g_sConfigState);
                HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC);
                HibernateRequest();
                for(;;)
                {
                }
            }

            //
            // If viewing instead of logging then request a repaint to keep
            // the viewing window updated.
            //
            if(g_iLoggerState == eSTATE_VIEWING)
            {
                WidgetPaint(WIDGET_ROOT);
            }
        }

        //
        // If in the saving state, then save data from flash storage to
        // USB stick.
        //
        if(g_iLoggerState == eSTATE_SAVING)
        {
            //
            // Save data from flash to USB
            //
            FlashStoreSave();

            //
            // Return to idle state
            //
            g_iLoggerState = eSTATE_IDLE;
        }

        //
        // If in the erasing state, then erase the data stored in flash.
        //
        if(g_iLoggerState == eSTATE_ERASING)
        {
            //
            // Save data from flash to USB
            //
            FlashStoreErase();

            //
            // Return to idle state
            //
            g_iLoggerState = eSTATE_IDLE;
        }

        //
        // If in the flash reporting state, then show the report of the amount
        // of used and free flash memory.
        //
        if(g_iLoggerState == eSTATE_FREEFLASH)
        {
            //
            // Report free flash space
            //
            FlashStoreReport();

            //
            // Return to idle state
            //
            g_iLoggerState = eSTATE_IDLE;
        }

        //
        // If we are exiting the clock setting widget, that means that control
        // needs to be given back to the menu system.
        //
        if(g_iLoggerState == eSTATE_CLOCKEXIT)
        {
            //
            // Give the button event focus back to the menu system
            //
            g_ui32KeyFocusWidgetHandle = (uint32_t)&g_sMenuWidget;

            //
            // Send a button event to the menu widget that means the left
            // key was pressed.  This signals the menu widget to deactivate
            // the current child widget (which was the clock setting wigdet).
            // This will cause the menu widget to slide the clock set widget
            // off the screen and resume control of the display.
            //
            SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT);
            g_iLoggerState = eSTATE_IDLE;
        }

        //
        // Process any new messages that are in the widget queue.  This keeps
        // the user interface running.
        //
        WidgetMessageQueueProcess();
    }
}
Ejemplo n.º 25
0
//*****************************************************************************
//
//! Draws a radio button widget.
//!
//! \param psWidget 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 *psWidget, uint32_t bClick)
{
    tRadioButtonWidget *pRadio;
    tContext sCtx;
    int32_t i32X, i32Y;

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

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

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

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

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

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

    //
    // Draw the radio button.
    //
    i32X = psWidget->sPosition.i16XMin + (pRadio->ui16CircleSize / 2) + 2;
    i32Y = (psWidget->sPosition.i16YMin +
            ((psWidget->sPosition.i16YMax - psWidget->sPosition.i16YMin) / 2));
    if(!bClick)
    {
        GrContextForegroundSet(&sCtx, pRadio->ui32OutlineColor);
        GrCircleDraw(&sCtx, i32X, i32Y, pRadio->ui16CircleSize / 2);
    }

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

    //
    // Fill in the radio button.
    //
    GrCircleFill(&sCtx, i32X, i32Y, (pRadio->ui16CircleSize / 2) - 2);

    //
    // See if the radio button text or image style is selected.
    //
    if((pRadio->ui16Style & (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.i16XMin += pRadio->ui16CircleSize + 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->ui16Style & RB_STYLE_OUTLINE)
        {
            sCtx.sClipRegion.i16YMin++;
            sCtx.sClipRegion.i16XMax--;
            sCtx.sClipRegion.i16YMax--;
        }

        //
        // See if the radio button image style is selected.
        //
        if(pRadio->ui16Style & 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->pui8Image) >
                    (sCtx.sClipRegion.i16YMax - sCtx.sClipRegion.i16YMin))
            {
                i32Y = sCtx.sClipRegion.i16YMin;
            }
            else
            {
                i32Y = (sCtx.sClipRegion.i16YMin +
                        ((sCtx.sClipRegion.i16YMax - sCtx.sClipRegion.i16YMin -
                          GrImageHeightGet(pRadio->pui8Image) + 1) / 2));
            }

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

            //
            // Draw the image next to the radio button.
            //
            GrImageDraw(&sCtx, pRadio->pui8Image, sCtx.sClipRegion.i16XMin,
                        i32Y);
        }

        //
        // See if the radio button text style is selected.
        //
        if(pRadio->ui16Style & 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->psFont) >
                    (sCtx.sClipRegion.i16YMax - sCtx.sClipRegion.i16YMin))
            {
                i32Y = sCtx.sClipRegion.i16YMin;
            }
            else
            {
                i32Y = (sCtx.sClipRegion.i16YMin +
                        ((sCtx.sClipRegion.i16YMax - sCtx.sClipRegion.i16YMin -
                          GrFontHeightGet(pRadio->psFont) + 1) / 2));
            }

            //
            // Draw the text next to the radio button.
            //
            GrContextFontSet(&sCtx, pRadio->psFont);
            GrContextForegroundSet(&sCtx, pRadio->ui32TextColor);
            GrContextBackgroundSet(&sCtx, pRadio->ui32FillColor);
            GrStringDraw(&sCtx, pRadio->pcText, -1, sCtx.sClipRegion.i16XMin,
                         i32Y, pRadio->ui16Style & RB_STYLE_TEXT_OPAQUE);
        }
    }
}
Ejemplo n.º 26
0
//*****************************************************************************
//
// The main code for the application.  It sets up the peripherals, displays the
// splash screens, and then manages the interaction between the game and the
// screen saver.
//
//*****************************************************************************
int
main(void)
{
	tRectangle sRect;
#ifndef _TMS320C6X
    unsigned int index;
#endif
	
    SetupIntc();

	
	/* Configuring UART2 instance for serial communication. */
    UARTStdioInit();

#ifdef _TMS320C6X
    CacheEnableMAR((unsigned int)0xC0000000, (unsigned int)0x20000000);
    CacheEnable(L1PCFG_L1PMODE_32K | L1DCFG_L1DMODE_32K | L2CFG_L2MODE_256K);
#else
    /* Sets up 'Level 1" page table entries. 
     * The page table entry consists of the base address of the page
     * and the attributes for the page. The following operation is to
     * setup one-to-one mapping page table for DDR memeory range and set
     * the atributes for the same. The DDR memory range is from 0xC0000000
     * to 0xDFFFFFFF. Thus the base of the page table ranges from 0xC00 to 
     * 0xDFF. Cache(C bit) and Write Buffer(B bit) are enabled  only for
     * those page table entries which maps to DDR RAM and internal RAM.
     * All the pages in the DDR range are provided with R/W permissions
     */
    for(index = 0; index < (4*1024); index++)
    {
         if((index >= 0xC00 && index < 0xE00)|| (index == 0x800))
         {             
              pageTable[index] = (index << 20) | 0x00000C1E;
         }
         else
         {
              pageTable[index] = (index << 20) | 0x00000C12;
         }
    }
     
    /* Configures translation table base register
     * with pagetable base address.
     */
    CP15TtbSet((unsigned int )pageTable);

    /* Enables MMU */
    CP15MMUEnable();
   
	/* Enable Instruction Cache */
    CP15ICacheEnable();

    /* Enable Data Cache */
    CP15DCacheEnable();
#endif

    SetUpLCD();
	
	ConfigureFrameBuffer();
		
	GrOffScreen16BPPInit(&g_sSHARP480x272x16Display0, (unsigned char *)g_pucBuffer0, LCD_WIDTH, LCD_HEIGHT);
	GrOffScreen16BPPInit(&g_sSHARP480x272x16Display1, (unsigned char *)g_pucBuffer1, LCD_WIDTH, LCD_HEIGHT);
	
	// Initialize a drawing context.
	GrContextInit(&sContext0, &g_sSHARP480x272x16Display0);
	GrContextInit(&sContext1, &g_sSHARP480x272x16Display1);

    /* enable End of frame interrupt */
    RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS);

    /* enable raster */
    RasterEnable(SOC_LCDC_0_REGS);

	PeripheralsSetup();
	I2C0IntRegister(4);
    AIC31Init();
    ToneLoopInit();
	/* Start playing the tone */
    ToneLoopStart();
	
    // TS init	
	TouchInit();
	
	GrContextForegroundSet(&sContext0, ClrBlack);
	GrContextForegroundSet(&sContext1, ClrBlack);
    sRect.sXMin = GAME_X - 1;
    sRect.sYMin = GAME_Y - 1;
    sRect.sXMax = GAME_X + GAME_W;
    sRect.sYMax = GAME_Y + GAME_H;
    GrRectFill(&sContext0, &sRect);
    GrRectFill(&sContext1, &sRect);

    GrImageDraw(&sContext0, g_pucTILogo128x96, GAME_X, GAME_Y);
	GrImageDraw(&sContext1, g_pucTILogo128x96, GAME_X, GAME_Y);
	
	Delay(0x5FFFFF);
	
	// Confiure and start timer2
	Timer2Config();
	Timer2Start();

    // Loop forever.
    while(1)
    {
        // Display the main screen.
        if(MainScreen())
        {
            // The button was pressed, so start the game.
            PlayGame();
        }
        else
        {
            // The button was not pressed during the timeout period, so start
            // the screen saver.
            ScreenSaver();
        }
    }
}
Ejemplo n.º 27
0
//*****************************************************************************
//
// Handles paint requests for the primitives canvas widget.
//
//*****************************************************************************
void
OnPrimitivePaint(tWidget *pWidget, tContext *pContext)
{
    unsigned int ulIdx;
    tRectangle sRect;

    //
    // Draw a vertical sweep of lines from red to green.
    //
    for(ulIdx = 0; ulIdx <= 8; ulIdx++)
    {
        GrContextForegroundSet(pContext,
                               (((((10 - ulIdx) * 255) / 10) << ClrRedShift) |
                                (((ulIdx * 255) / 10) << ClrGreenShift)));
        GrLineDraw(pContext, 115+X_OFFSET, 120+Y_OFFSET, 5+X_OFFSET, 120+Y_OFFSET - (11 * ulIdx));
    }

    //
    // Draw a horizontal sweep of lines from green to blue.
    //
    for(ulIdx = 1; ulIdx <= 10; ulIdx++)
    {
        GrContextForegroundSet(pContext,
                               (((((10 - ulIdx) * 255) / 10) <<
                                 ClrGreenShift) |
                                (((ulIdx * 255) / 10) << ClrBlueShift)));
        GrLineDraw(pContext, 115+X_OFFSET, 120+Y_OFFSET, 5 + (ulIdx * 11)+X_OFFSET, 29+Y_OFFSET);
    }

    //
    // Draw a filled circle with an overlapping circle.
    //
    GrContextForegroundSet(pContext, ClrBrown);
    GrCircleFill(pContext, 185+X_OFFSET, 69+Y_OFFSET, 40);
    GrContextForegroundSet(pContext, ClrSkyBlue);
    GrCircleDraw(pContext, 205+X_OFFSET, 99+Y_OFFSET, 30);

    //
    // Draw a filled rectangle with an overlapping rectangle.
    //
    GrContextForegroundSet(pContext, ClrSlateGray);
    sRect.sXMin = 20+X_OFFSET;
    sRect.sYMin = 100+Y_OFFSET;
    sRect.sXMax = 75+X_OFFSET;
    sRect.sYMax = 160+Y_OFFSET;
    GrRectFill(pContext, &sRect);
    GrContextForegroundSet(pContext, ClrSlateBlue);
    sRect.sXMin += 40;
    sRect.sYMin += 40;
    sRect.sXMax += 30;
    sRect.sYMax += 28;
    GrRectDraw(pContext, &sRect);

    //
    // Draw a piece of text in fonts of increasing size.
    //
    GrContextForegroundSet(pContext, ClrSilver);
    GrContextFontSet(pContext, &g_sFontCm14);
    GrStringDraw(pContext, "Strings", -1, 125+X_OFFSET, 110+Y_OFFSET, 0);
    GrContextFontSet(pContext, &g_sFontCm18);
    GrStringDraw(pContext, "Strings", -1, 145+X_OFFSET, 124+Y_OFFSET, 0);
    GrContextFontSet(pContext, &g_sFontCm22);
    GrStringDraw(pContext, "Strings", -1, 165+X_OFFSET, 142+Y_OFFSET, 0);
    GrContextFontSet(pContext, &g_sFontCm24);
    GrStringDraw(pContext, "Strings", -1, 185+X_OFFSET, 162+Y_OFFSET, 0);

    //
    // Draw an image.
    //
    GrImageDraw(pContext, g_TILogo, 240+X_OFFSET, 60+Y_OFFSET);
}
Ejemplo n.º 28
0
//*****************************************************************************
//
// Draw the pop up buttons on the screen.
//
//*****************************************************************************
static void
DrawButtons(int32_t i32Offset, bool bClear)
{
    static const tRectangle sRectTop = {
        140,
        BG_MIN_Y,
        171,
        BG_MIN_Y + 10,
    };
    static const tRectangle sRectRight = {
        BG_MAX_X - 11,
        BG_MIN_Y - 20 + ((BG_MAX_Y - BG_MIN_Y) / 2),
        BG_MAX_X,
        BG_MIN_Y - 20 + ((BG_MAX_Y - BG_MIN_Y) / 2) + 40,
    };
    static const tRectangle sRectLeft = {
        BG_MIN_X,
        BG_MIN_Y - 20 + ((BG_MAX_Y - BG_MIN_Y) / 2),
        BG_MIN_X + 10,
        BG_MIN_Y - 20 + ((BG_MAX_Y - BG_MIN_Y) / 2) + 40,
    };

    //
    // Only draw if they are enabled.
    //
    if(g_sButtons.bEnabled == false) {
        return;
    }

    //
    // Draw the three pop up buttons.
    //
    if(g_i32ScreenIdx == SCREEN_SUMMARY || g_i32ScreenIdx == SCREEN_DETAILS) {
        GrContextForegroundSet(&g_sContext, ClrBlack);
        GrContextBackgroundSet(&g_sContext, ClrGray);

        GrRectFill(&g_sContext, &sRectRight);
        GrRectFill(&g_sContext, &sRectLeft);

        if(bClear == false) {
            GrLineDrawH(&g_sContext, 140, 171, BG_MIN_Y + 10 + i32Offset);

            GrImageDraw(&g_sContext, g_pui8DownTabImage, 140,
                        BG_MIN_Y + i32Offset);

            GrTransparentImageDraw(&g_sContext, g_pui8RightImage,
                                   BG_MAX_X - 10 + i32Offset,
                                   BG_MIN_Y - 20 + ((BG_MAX_Y - BG_MIN_Y) / 2),
                                   1);
            GrTransparentImageDraw(&g_sContext, g_pui8LeftImage,
                                   BG_MIN_X - i32Offset,
                                   BG_MIN_Y - 20 + ((BG_MAX_Y - BG_MIN_Y) / 2),
                                   1);
        } else {
            GrRectFill(&g_sContext, &sRectTop);
        }
    } else if(g_i32ScreenIdx == SCREEN_TI) {
        GrContextForegroundSet(&g_sContext, ClrGray);
        GrContextBackgroundSet(&g_sContext, ClrWhite);
        if(bClear == false) {
            GrLineDrawH(&g_sContext, 140, 171, BG_MAX_Y - 11 - i32Offset);
            GrImageDraw(&g_sContext, g_pui8UpTabImage, 140,
                        BG_MAX_Y - 10 - i32Offset);
        }
    }
}
Ejemplo n.º 29
0
//*****************************************************************************
//
//! Performs the sliding menu operation, in response to the "up" button.
//!
//! \param psWidget is a pointer to the slide menu widget to move up.
//!
//! This function will respond to the "up" key/button event.  The up
//! button is used to select the previous menu item down the list, and the
//! effect is that the menu itself slides down, leaving the highlighted menu
//! item in the middle of the screen.
//!
//! This function repeatedly draws the menu onto the display until the sliding
//! animation is finished and will not return to the caller until then.  This
//! function is usually called from the thread context of
//! WidgetMessageQueueProcess().
//!
//! \return Returns a non-zero value if the menu was moved or was not moved
//! because it is already at the first position.  If a child widget is active
//! then this function does nothing and returns a 0.
//
//*****************************************************************************
static int32_t
SlideMenuUp(tWidget *psWidget)
{
    tSlideMenuWidget *psMenuWidget;
    tSlideMenu *psMenu;
    tContext sContext;
    uint32_t ui32MenuHeight;
    uint32_t ui32Y;

    //
    // If this menu widget has a child widget, that means the child widget
    // is in control of the display, and there is nothing to do here.
    //
    if(psWidget->psChild)
    {
        return(0);
    }

    //
    // Get handy pointers to the menu widget, and the menu that is currently
    // displayed.
    //
    psMenuWidget = (tSlideMenuWidget *)psWidget;
    psMenu = psMenuWidget->psSlideMenu;

    //
    // If we are already at the start of the list of menu items, then there
    // is nothing else to do.
    //
    if(psMenu->ui32FocusIndex == 0)
    {
        return(1);
    }

    //
    // Decrement the focus menu item.  This has the effect of selecting the
    // previous menu item in the list.
    //
    psMenu->ui32FocusIndex--;

    //
    // Initialize a context for the primary off-screen drawing buffer.
    // Clip region is set to entire display by default, which is what we want.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayA);

    //
    // Render the menu into the off-screen buffer.  This will be the same
    // menu appearance as before, except the highlighted item has changed
    // to the previous menu item up.
    //
    SlideMenuDraw(psMenuWidget, &sContext, 0);

    //
    // Draw a continuation of this menu in the second offscreen buffer.
    // This is the part of the menu that would be drawn above this menu if the
    // display were twice as tall.  We are effectively creating a virtual
    // display that is twice as tall as the physical display.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayB);
    SlideMenuDraw(psMenuWidget, &sContext,
                  (psMenuWidget->sBase.sPosition.i16YMax -
                  psMenuWidget->sBase.sPosition.i16YMin));

    //
    // Initialize a drawing context for the display where the widget is to be
    // drawn.  This is the physical display, not an off-screen buffer.
    //
    GrContextInit(&sContext, psWidget->psDisplay);

    //
    // Initialize the clipping region on the physical display, based on the
    // extents of this widget.
    //
    GrContextClipRegionSet(&sContext, &(psWidget->sPosition));

    //
    // Get the height of the displayed part of the menu.
    //
    ui32MenuHeight = psMenuWidget->psDisplayA->ui16Height;

    //
    // Now copy the rendered menu into the physical display
    //
    // Iterate over the Y displacement of one menu item cell.  This loop
    // will repeatedly draw both off screen buffers to the physical display,
    // adjusting the position of each by one pixel each time it is drawn.  Each
    // time the offset is changed so that both buffers are drawn one lower
    // than the previous time.  This will have the effect of "sliding" the
    // entire menu down by the height of one menu item cell.
    // The speed of the animation is controlled entirely by the speed of the
    // processor and the speed of the interface to the physical display.
    //
    for(ui32Y = 0; ui32Y <= psMenuWidget->ui32MenuItemHeight; ui32Y++)
    {
        GrImageDraw(&sContext, psMenuWidget->psDisplayB->pvDisplayData,
                    psWidget->sPosition.i16XMin,
                    psWidget->sPosition.i16YMin + ui32Y - ui32MenuHeight);
        GrImageDraw(&sContext, psMenuWidget->psDisplayA->pvDisplayData,
                    psWidget->sPosition.i16XMin,
                    psWidget->sPosition.i16YMin + ui32Y);
    }

    //
    // Decrement the  centered menu item.  This will now match the menu item
    // with the focus.  When the menu is repainted again, the newly selected
    // menu item will be centered and highlighted.
    //
    psMenu->ui32CenterIndex = psMenu->ui32FocusIndex;

    //
    // Initialize a context for the primary off-screen drawing buffer.
    // Clip region is set to entire display by default, which is what we want.
    //
    GrContextInit(&sContext, psMenuWidget->psDisplayA);

    //
    // Render the menu into the off-screen buffer.  This will be the same
    // menu appearance as before, except the highlighted item has changed
    // to the next menu item up.  Now when a repaint occurs the menu
    // will be redrawn with the newly highlighted menu item.
    //
    SlideMenuDraw(psMenuWidget, &sContext, 0);

    //
    // Return indication that we handled the key event.
    //
    return(1);
}
Ejemplo n.º 30
0
/*
 *  ======== grlibTaskFxn ========
 *  Drawing task
 *
 *  It is pending for the message either from console task or from button ISR.
 *  Once the messages received, it draws to the screen based on information
 *  contained in the message.
 */
Void grlibTaskFxn(UArg arg0, UArg arg1)
{
    DrawMessage curMsg;
    const UChar *pucCurImage;
    UInt key;
    UInt fontHeight = GrStringHeightGet(&context);

    while (TRUE) {
        Mailbox_pend(mailboxHandle, &curMsg, BIOS_WAIT_FOREVER);

        fillBox(4);
        /* Clear screen before drawing */
        clearDisplay();

        /* Parse the message and draw */
        switch (curMsg.drawCommand) {
        case IMAGE:
            pucCurImage = image_Gallery[curMsg.drawImageIndex];

            /* Draw image at (0,0) */
            GrImageDraw(&context, pucCurImage, 0, 0);
            break;

        case KeyBoadCOMMAND:
        	switch(curMsg.MoveCommand){
        	case UP:
        		 // copy the data to message
        			           	key = Gate_enterSystem();
        			            up_remove_blank(4);
        			            up(4);



        			            copyFrom2048ArrayToDrawMessage(4,curMsg.draw2048 , Array2048);
        			            Gate_leaveSystem(key);
        		            break;
        	case DOWN:
        		// copy the data to message
        						key = Gate_enterSystem();
        			        	down_remove_blank(4);
        						down(4);



        						copyFrom2048ArrayToDrawMessage(4,curMsg.draw2048 , Array2048);
        						Gate_leaveSystem(key);
        	        		break;
        	case LEFT:
        		// copy the data to message
        						key = Gate_enterSystem();
        						left_remove_blank(4);
        						left(4);


        						copyFrom2048ArrayToDrawMessage(4,curMsg.draw2048 , Array2048);
        						Gate_leaveSystem(key);
        	        		break;
        	case RIGHT:
        		// copy the data to message
        						key = Gate_enterSystem();
        						right_remove_blank(4);
        						right(4);

        						copyFrom2048ArrayToDrawMessage(4,curMsg.draw2048 , Array2048);
        						Gate_leaveSystem(key);
        	        		break;
        	default:
        	            break;
        	}
        	output(4,curMsg.draw2048);

            break;

        case ScreenCOMMAND:
        	// copy the data to message
        	key = Gate_enterSystem();
        	fillBox(4);
        	Gate_leaveSystem(key);
        	output(4,curMsg.draw2048);
        	System_printf("here\n");
//        	printf("data X %d , data Y %d /n",curMsg.touchPosition[0],curMsg.touchPosition[1]);
        	break;

        default:
            break;
        }
    }
}