//***************************************************************************** // //! Draws a circle. //! //! \param pContext is a pointer to the drawing context to use. //! \param lX is the X coordinate of the center of the circle. //! \param lY is the Y coordinate of the center of the circle. //! \param lRadius is the radius of the circle. //! //! This function draws a circle, utilizing the Bresenham circle drawing //! algorithm. The extent of the circle is from \e lX - \e lRadius to \e lX + //! \e lRadius and \e lY - \e lRadius to \e lY + \e lRadius, inclusive. //! //! \return None. // //***************************************************************************** void GrCircleDraw(const tContext *pContext, long lX, long lY, long lRadius) { long lA, lB, lD, lX1, lY1; // // Check the arguments. // ASSERT(pContext); // // Initialize the variables that control the Bresenham circle drawing // algorithm. // lA = 0; lB = lRadius; lD = 3 - (2 * lRadius); // // Loop until the A delta is greater than the B delta, meaning that the // entire circle has been drawn. // while(lA <= lB) { // // Determine the row when subtracting the A delta. // lY1 = lY - lA; // // See if this row is within the clipping region. // if((lY1 >= pContext->sClipRegion.sYMin) && (lY1 <= pContext->sClipRegion.sYMax)) { // // Determine the column when subtracting the B delta. // lX1 = lX - lB; // // If this column is within the clipping region, then draw a pixel // at that position. // if((lX1 >= pContext->sClipRegion.sXMin) && (lX1 <= pContext->sClipRegion.sXMax)) { GrPixelDraw(pContext, lX1, lY1); } // // Determine the column when adding the B delta. // lX1 = lX + lB; // // If this column is within the clipping region, then draw a pixel // at that position. // if((lX1 >= pContext->sClipRegion.sXMin) && (lX1 <= pContext->sClipRegion.sXMax)) { GrPixelDraw(pContext, lX1, lY1); } } // // Determine the row when adding the A delta. // lY1 = lY + lA; // // See if this row is within the clipping region, and the A delta is // not zero (otherwise, it will be the same row as when the A delta was // subtracted). // if((lY1 >= pContext->sClipRegion.sYMin) && (lY1 <= pContext->sClipRegion.sYMax) && (lA != 0)) { // // Determine the column when subtracting the B delta. // lX1 = lX - lB; // // If this column is within the clipping region, then draw a pixel // at that position. // if((lX1 >= pContext->sClipRegion.sXMin) && (lX1 <= pContext->sClipRegion.sXMax)) { GrPixelDraw(pContext, lX1, lY1); } // // Determine the column when adding the B delta. // lX1 = lX + lB; // // If this column is within the clipping region, then draw a pixel // at that position. // if((lX1 >= pContext->sClipRegion.sXMin) && (lX1 <= pContext->sClipRegion.sXMax)) { GrPixelDraw(pContext, lX1, lY1); } } // // Only draw the complementary pixels if the A and B deltas are // different (otherwise, they describe the same set of pixels). // if(lA != lB) { // // Determine the row when subtracting the B delta. // lY1 = lY - lB; // // See if this row is within the clipping region. // if((lY1 >= pContext->sClipRegion.sYMin) && (lY1 <= pContext->sClipRegion.sYMax)) { // // Determine the column when subtracting the a delta. // lX1 = lX - lA; // // If this column is within the clipping region, then draw a // pixel at that position. // if((lX1 >= pContext->sClipRegion.sXMin) && (lX1 <= pContext->sClipRegion.sXMax)) { GrPixelDraw(pContext, lX1, lY1); } // // Only draw the mirrored pixel if the A delta is non-zero // (otherwise, it will be the same pixel). // if(lA != 0) { // // Determine the column when adding the A delta. // lX1 = lX + lA; // // If this column is within the clipping region, then draw // a pixel at that position. // if((lX1 >= pContext->sClipRegion.sXMin) && (lX1 <= pContext->sClipRegion.sXMax)) { GrPixelDraw(pContext, lX1, lY1); } } } // // Determine the row when adding the B delta. // lY1 = lY + lB; // // See if this row is within the clipping region. // if((lY1 >= pContext->sClipRegion.sYMin) && (lY1 <= pContext->sClipRegion.sYMax)) { // // Determine the column when subtracting the A delta. // lX1 = lX - lA; // // If this column is within the clipping region, then draw a // pixel at that position. // if((lX1 >= pContext->sClipRegion.sXMin) && (lX1 <= pContext->sClipRegion.sXMax)) { GrPixelDraw(pContext, lX1, lY1); } // // Only draw the mirrored pixel if the A delta is non-zero // (otherwise, it will be the same pixel). // if(lA != 0) { // // Determine the column when adding the A delta. // lX1 = lX + lA; // // If this column is within the clipping region, then draw // a pixel at that position. // if((lX1 >= pContext->sClipRegion.sXMin) && (lX1 <= pContext->sClipRegion.sXMax)) { GrPixelDraw(pContext, lX1, lY1); } } } } // // See if the error term is negative. // if(lD < 0) { // // Since the error term is negative, adjust it based on a move in // only the A delta. // lD += (4 * lA) + 6; } else { // // Since the error term is non-negative, adjust it based on a move // in both the A and B deltas. // lD += (4 * (lA - lB)) + 10; // // Decrement the B delta. // lB -= 1; } // // Increment the A delta. // lA++; } }
void main(void) { // Stop WDT WDTCTL = WDTPW + WDTHOLD; // Initialize the boards boardInit(); clockInit(); timerInit(); flashInit(); __bis_SR_register(GIE); // Set up the LCD LCDInit(); GrContextInit(&g_sContext, &g_sharp96x96LCD); GrContextForegroundSet(&g_sContext, ClrBlack); GrContextBackgroundSet(&g_sContext, ClrWhite); GrContextFontSet(&g_sContext, &g_sFontFixed6x8); GrClearDisplay(&g_sContext); GrFlush(&g_sContext); // Intro Screen 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_long(); 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_long(); 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_long(); 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); GrFlush(&g_sContext); Delay_long(); GrClearDisplay(&g_sContext); // Combining Primitive screen GrStringDrawCentered(&g_sContext, "Combining", AUTO_STRING_LENGTH, 48, 15, TRANSPARENT_TEXT); GrStringDrawCentered(&g_sContext, "Primitives to", AUTO_STRING_LENGTH, 48, 35, TRANSPARENT_TEXT); GrStringDrawCentered(&g_sContext, "create menus", AUTO_STRING_LENGTH, 48, 51, TRANSPARENT_TEXT); GrStringDrawCentered(&g_sContext, "and animations", AUTO_STRING_LENGTH, 48, 75, TRANSPARENT_TEXT); GrFlush(&g_sContext); Delay_long(); GrClearDisplay(&g_sContext); // Draw a Menu screen GrStringDrawCentered(&g_sContext, "Create a Menu", AUTO_STRING_LENGTH, 48, 5, TRANSPARENT_TEXT); GrRectDraw(&g_sContext, &myRectangleOption1); GrStringDraw(&g_sContext,"Option #1", 10,15,15,TRANSPARENT_TEXT); GrRectFill(&g_sContext, &myRectangleOption2); GrStringDraw(&g_sContext,"Option #2", 10,15,25,TRANSPARENT_TEXT); GrRectDraw(&g_sContext, &myRectangleOption3); GrStringDraw(&g_sContext,"Option #3", 10,15,35,TRANSPARENT_TEXT); GrRectDraw(&g_sContext, &myRectangleOption4); GrStringDraw(&g_sContext,"Option #4", 10,15,45,TRANSPARENT_TEXT); GrRectDraw(&g_sContext, &myRectangleOption5); GrStringDraw(&g_sContext,"Option #5", 10,15,55,TRANSPARENT_TEXT); GrFlush(&g_sContext); Delay_long(); GrClearDisplay(&g_sContext); // Show progress bar screen // The following animation consist on displaying a progress bar and // updating the progress bar in increments of 25%. GrStringDrawCentered(&g_sContext, "Show progress", AUTO_STRING_LENGTH, 48, 5, TRANSPARENT_TEXT); GrRectDraw(&g_sContext, &myRectangleFrame); GrStringDrawCentered(&g_sContext, "Processing...", AUTO_STRING_LENGTH, 48, 75, TRANSPARENT_TEXT); GrFlush(&g_sContext); Delay_short(); // Update display with 25 %. Initial value of "myRectangleProgress" are set // to update bar with a 25 % increment. GrRectFill(&g_sContext, &myRectangleProgress); GrFlush(&g_sContext); Delay_short(); // Set myRectangleProgress values to update progress bar with 50 % myRectangleProgress.sXMin = 30; myRectangleProgress.sYMin = 40; myRectangleProgress.sXMax = 50; myRectangleProgress.sYMax = 60; GrRectFill(&g_sContext, &myRectangleProgress); GrFlush(&g_sContext); Delay_short(); // Set myRectangleProgress values to update progress bar with 75 % myRectangleProgress.sXMin = 50; myRectangleProgress.sYMin = 40; myRectangleProgress.sXMax = 70; myRectangleProgress.sYMax = 60; GrRectFill(&g_sContext, &myRectangleProgress); GrFlush(&g_sContext); Delay_short(); // Set myRectangleProgress values to update progress bar with 100 % myRectangleProgress.sXMin = 70; myRectangleProgress.sYMin = 40; myRectangleProgress.sXMax = 90; myRectangleProgress.sYMax = 60; GrRectFill(&g_sContext, &myRectangleProgress); GrStringDrawCentered(&g_sContext, "DONE!", AUTO_STRING_LENGTH, 48, 85, TRANSPARENT_TEXT); GrFlush(&g_sContext); Delay_long(); while(1); }
//***************************************************************************** // // A simple demonstration of the features of the TivaWare Graphics Library. // //***************************************************************************** int main(void) { clockInit(); // Set up the LCD Sharp96x96_initDisplay(); GrContextInit(&g_sContext, &g_sharp96x96LCD); GrContextFontSet(&g_sContext, &g_sFontFixed6x8); int step = -1; Sharp96x96_VCOM_count = 10; while(1) { if(Sharp96x96_VCOM_count < 4) { continue; } Sharp96x96_VCOM_count = 0; if(++step >= 5) { step = 0; } BlankScreen(); GrFlush(&g_sContext); switch(step) { case 0: // Intro Screen GrStringDrawCentered(&g_sContext, "How to use", AUTO_STRING_LENGTH, 48, 15, TRANSPARENT_TEXT); GrStringDrawCentered(&g_sContext, "the TivaWare", 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); break; case 1: // 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); break; case 2: // 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); break; case 3: // 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); break; case 4: // 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); break; default: break; } GrFlush(&g_sContext); } }
//***************************************************************************** // //! Draws the strip chart into a drawing context, off-screen buffer. //! //! \param psChartWidget points at the StripsChartWidget being processed. //! \param psContext points to the context where all drawing should be done. //! //! This function renders a strip chart into a drawing context. //! It assumes that the drawing context is an off-screen buffer, and that //! the entire buffer belongs to this widget. //! //! \return None. // //***************************************************************************** void StripChartDraw(tStripChartWidget *psChartWidget, tContext *psContext) { tStripChartAxis *psAxisY; int32_t i32Y; int32_t i32Ygrid; int32_t i32X; int32_t i32GridRange; int32_t i32DispRange; int32_t i32GridMin; int32_t i32DispMax; tStripChartSeries *psSeries; // // Check the parameters // ASSERT(psChartWidget); ASSERT(psContext); ASSERT(psChartWidget->psAxisY); // // Get handy pointer to Y axis // psAxisY = psChartWidget->psAxisY; // // Find the range of Y axis in Y axis units // i32GridRange = psAxisY->i32Max - psAxisY->i32Min; // // Find the range of the Y axis in display units (pixels) // i32DispRange = (psContext->sClipRegion.i16YMax - psContext->sClipRegion.i16YMin); // // Find the minimum Y units value to be shown, and the maximum of the // clipping region. // i32GridMin = psAxisY->i32Min; i32DispMax = psContext->sClipRegion.i16YMax; // // Set the fg color for the rectangle fill to match what we want as the // chart background. // GrContextForegroundSet(psContext, psChartWidget->ui32BackgroundColor); GrRectFill(psContext, &psContext->sClipRegion); // // Draw vertical grid lines // GrContextForegroundSet(psContext, psChartWidget->ui32GridColor); for(i32X = psChartWidget->i32GridX; i32X < psContext->sClipRegion.i16XMax; i32X += psChartWidget->psAxisX->i32GridInterval) { GrLineDrawV(psContext, psContext->sClipRegion.i16XMax - i32X, psContext->sClipRegion.i16YMin, psContext->sClipRegion.i16YMax); } // // Draw horizontal grid lines // for(i32Ygrid = psAxisY->i32Min; i32Ygrid < psAxisY->i32Max; i32Ygrid += psAxisY->i32GridInterval) { i32Y = ((i32Ygrid - i32GridMin) * i32DispRange) / i32GridRange; i32Y = i32DispMax - i32Y; GrLineDrawH(psContext, psContext->sClipRegion.i16XMin, psContext->sClipRegion.i16XMax, i32Y); } // // Compute location of Y=0 line, and draw it // i32Y = ((-i32GridMin) * i32DispRange) / i32GridRange; i32Y = i32DispMax - i32Y; GrLineDrawH(psContext, psContext->sClipRegion.i16XMin, psContext->sClipRegion.i16XMax, i32Y); // // Iterate through each series to draw it // psSeries = psChartWidget->psSeries; while(psSeries) { int idx = 0; // // Find the starting X position on the display for this series. // If the series has less data points than can fit on the display // then starting X can be somewhere in the middle of the screen. // i32X = 1 + psContext->sClipRegion.i16XMax - psSeries->ui16NumItems; // // If the starting X is off the left side of the screen, then the // staring index (idx) for reading data needs to be adjusted to the // first value in the series that will be visible on the screen // if(i32X < psContext->sClipRegion.i16XMin) { idx = psContext->sClipRegion.i16XMin - i32X; i32X = psContext->sClipRegion.i16XMin; } // // Set the drawing color for this series // GrContextForegroundSet(psContext, psSeries->ui32Color); // // Scan through all possible X values, find the Y value, and draw the // pixel. // for(; i32X <= psContext->sClipRegion.i16XMax; i32X++) { // // Find the Y value at each position in the data series. Take into // account the data size and the stride // if(psSeries->ui8DataTypeSize == 1) { i32Y = ((int8_t *)psSeries->pvData)[idx * psSeries->ui8Stride]; } else if(psSeries->ui8DataTypeSize == 2) { i32Y = ((int16_t *)psSeries->pvData)[idx * psSeries->ui8Stride]; } else if(psSeries->ui8DataTypeSize == 4) { i32Y = ((int32_t *)psSeries->pvData)[idx * psSeries->ui8Stride]; } else { // // If there is an invalid data size, then just force Y value // to be off the display // i32Y = i32DispMax + 1; break; } // // Advance to the next position in the data series. // idx++; // // Now scale the Y value according to the axis scaling // i32Y = ((i32Y - i32GridMin) * i32DispRange) / i32GridRange; i32Y = i32DispMax - i32Y; // // Draw the pixel on the display // GrPixelDraw(psContext, i32X, i32Y); } // // Advance to the next series until there are no more. // psSeries = psSeries->psNextSeries; } // // Draw a frame around the entire chart. // GrContextForegroundSet(psContext, psChartWidget->ui32Y0Color); GrRectDraw(psContext, &psContext->sClipRegion); // // Draw titles // GrContextForegroundSet(psContext, psChartWidget->ui32TextColor); GrContextFontSet(psContext, psChartWidget->psFont); // // Draw the chart title, if there is one // if(psChartWidget->pcTitle) { GrStringDrawCentered(psContext, psChartWidget->pcTitle, -1, psContext->sClipRegion.i16XMax / 2, GrFontHeightGet(psChartWidget->psFont), 0); } // // Draw the Y axis max label, if there is one // if(psChartWidget->psAxisY->pcMaxLabel) { GrStringDraw(psContext, psChartWidget->psAxisY->pcMaxLabel, -1, psContext->sClipRegion.i16XMin + GrFontMaxWidthGet(psChartWidget->psFont) / 2, GrFontHeightGet(psChartWidget->psFont) / 2, 0); } // // Draw the Y axis min label, if there is one // if(psChartWidget->psAxisY->pcMinLabel) { GrStringDraw(psContext, psChartWidget->psAxisY->pcMinLabel, -1, psContext->sClipRegion.i16XMin + GrFontMaxWidthGet(psChartWidget->psFont) / 2, psContext->sClipRegion.i16YMax - (GrFontHeightGet(psChartWidget->psFont) + (GrFontHeightGet(psChartWidget->psFont) / 2)), 0); } // // Draw a label for the name of the Y axis, if there is one // if(psChartWidget->psAxisY->pcName) { GrStringDraw(psContext, psChartWidget->psAxisY->pcName, -1, psContext->sClipRegion.i16XMin + 1, (psContext->sClipRegion.i16YMax / 2) - (GrFontHeightGet(psChartWidget->psFont) / 2), 1); } }
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 } }
//***************************************************************************** // // Draws left/right or up/down arrows within the supplied rectangle. // // \param prectOutline is a pointer to a rectangle defining the area of the // control which is to be marked with arrows. // \param bLeftRight is \b true of left and right arrow annotations are to // be drawn or \b false for up and down arrows. // \param ulColor defines the color of the arrows that will be drawn. // // This function is used to annotate a text box with two small arrows // indicating keys that may be used to modify the boxes content. If // \e bLeftRight is \b true, a small arrow pointing left is drawn on the left // side of the rectangle, indented by 2 pixels to avoid the outline rectangle. // A similar, right pointing arrow is drawn on the right side of the // rectangle. If \e bLeftRight is \b false, small up and down pointing arrows // are drawn on the left side of the rectangle. // // \note It is assumed that the caller has set a clip region which includes // the required rectangle prior to calling this function. // // \return None. // //***************************************************************************** void DrawDirectionMarkers(tRectangle *prectOutline, tBoolean bLeftRight, unsigned long ulColor) { short sAverage; // // Set the color we will use for drawing. // GrContextForegroundSet(&g_sContext, ulColor); // // Draw the arrows using 3 pixels each. // if(bLeftRight) { // // Determine the Y coordinate half way between the top and bottom of // the rectangle. // sAverage = (prectOutline->sYMax + prectOutline->sYMin) / 2; // // Draw the left-pointing arrow. // GrPixelDraw(&g_sContext, prectOutline->sXMin + 2, sAverage); GrPixelDraw(&g_sContext, prectOutline->sXMin + 3, sAverage - 1); GrPixelDraw(&g_sContext, prectOutline->sXMin + 3, sAverage + 1); // // Draw the right-pointing arrow. // GrPixelDraw(&g_sContext, prectOutline->sXMax - 2, sAverage); GrPixelDraw(&g_sContext, prectOutline->sXMax - 3, sAverage - 1); GrPixelDraw(&g_sContext, prectOutline->sXMax - 3, sAverage + 1); } else { // // Draw the upward-pointing arrow // GrPixelDraw(&g_sContext, prectOutline->sXMin + 2, prectOutline->sYMin + 3); GrPixelDraw(&g_sContext, prectOutline->sXMin + 3, prectOutline->sYMin + 2); GrPixelDraw(&g_sContext, prectOutline->sXMin + 4, prectOutline->sYMin + 3); // // Draw the downward-pointing arrow. // GrPixelDraw(&g_sContext, prectOutline->sXMin + 2, prectOutline->sYMax - 3); GrPixelDraw(&g_sContext, prectOutline->sXMin + 3, prectOutline->sYMax - 2); GrPixelDraw(&g_sContext, prectOutline->sXMin + 4, prectOutline->sYMax - 3); } }
void main(void) { tRectangle myRectangle1 = { 5, 10, 60, 50}; tRectangle myRectangle2 = { 30, 20, 100, 60}; tRectangle myRectangle3 = { 0, 0, 101, 63}; // Stop WDT WDT_A_hold(WDT_A_BASE); // Basic GPIO initialization Board_init(); Clock_init(); // Set up LCD Dogs102x64_UC1701Init(); GrContextInit(&g_sContext, &g_sDogs102x64_UC1701); GrContextForegroundSet(&g_sContext, ClrBlack); GrContextBackgroundSet(&g_sContext, ClrWhite); GrContextFontSet(&g_sContext, &g_sFontFixed6x8); GrClearDisplay(&g_sContext); // Intro Screen GrStringDrawCentered(&g_sContext, "How to use MSP430", AUTO_STRING_LENGTH, 51, 16, TRANSPARENT_TEXT); GrStringDrawCentered(&g_sContext, "Graphics Library", AUTO_STRING_LENGTH, 51, 32, TRANSPARENT_TEXT); GrStringDrawCentered(&g_sContext, "Primitives", AUTO_STRING_LENGTH, 51, 48, TRANSPARENT_TEXT); Delay(); GrClearDisplay(&g_sContext); // Draw pixels and lines on the display GrStringDraw(&g_sContext, "Draw Pixels", AUTO_STRING_LENGTH, 20, 0, TRANSPARENT_TEXT); GrStringDraw(&g_sContext, "& Lines", AUTO_STRING_LENGTH, 30, 10, TRANSPARENT_TEXT); GrPixelDraw(&g_sContext, 10, 10); GrPixelDraw(&g_sContext, 10, 12); GrPixelDraw(&g_sContext, 12, 12); GrPixelDraw(&g_sContext, 12, 10); GrLineDraw(&g_sContext, 15, 15, 60, 60); GrLineDraw(&g_sContext, 10, 50, 90, 10); GrLineDraw(&g_sContext, 0, GrContextDpyHeightGet(&g_sContext) - 1, GrContextDpyWidthGet(&g_sContext) - 1, GrContextDpyHeightGet(&g_sContext) - 1); Delay(); GrClearDisplay(&g_sContext); // Draw circles on the display GrStringDrawCentered(&g_sContext, "Draw Circles", AUTO_STRING_LENGTH, 51, 5, TRANSPARENT_TEXT); GrCircleDraw(&g_sContext, 30, 50, 10); GrCircleFill(&g_sContext, 65, 37, 23); Delay(); GrClearDisplay(&g_sContext); // Draw rectangles on the display GrStringDrawCentered(&g_sContext, "Draw Rectangles", AUTO_STRING_LENGTH, 51, 5, TRANSPARENT_TEXT); GrRectDraw(&g_sContext, &myRectangle1); GrRectFill(&g_sContext, &myRectangle2); // Text won't be visible on screen due to transparency GrStringDrawCentered(&g_sContext, "Normal Text", AUTO_STRING_LENGTH, 65, 30, TRANSPARENT_TEXT); // Text draws foreground and background for opacity GrStringDrawCentered(&g_sContext, "Opaque Text", AUTO_STRING_LENGTH, 65, 40, OPAQUE_TEXT); GrContextForegroundSet(&g_sContext, ClrWhite); GrContextBackgroundSet(&g_sContext, ClrBlack); // Text draws with inverted color to become visible GrStringDrawCentered(&g_sContext, "Invert Text", AUTO_STRING_LENGTH, 65, 50, TRANSPARENT_TEXT); Delay(); GrClearDisplay(&g_sContext); // 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, 51, 5, TRANSPARENT_TEXT); GrRectDraw(&g_sContext, &myRectangle1); GrRectFill(&g_sContext, &myRectangle2); // Text won't be visible on screen due to transparency GrStringDrawCentered(&g_sContext, "Normal Text", AUTO_STRING_LENGTH, 65, 30, TRANSPARENT_TEXT); // Text draws foreground and background for opacity GrStringDrawCentered(&g_sContext, "Opaque Text", AUTO_STRING_LENGTH, 65, 40, OPAQUE_TEXT); GrContextForegroundSet(&g_sContext, ClrBlack); GrContextBackgroundSet(&g_sContext, ClrWhite); // Text draws with inverted color to become visible GrStringDrawCentered(&g_sContext, "Invert Text", AUTO_STRING_LENGTH, 65, 50, TRANSPARENT_TEXT); 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, 13); Delay(); GrClearDisplay(&g_sContext); GrImageDraw(&g_sContext, &TI_Logo_69x64_1BPP_UNCOMP, 16, 0); while(1) { } }