//*****************************************************************************
//
// context.c - Routines for handling drawing contexts.
//
// Copyright (c) 2007-2009 Luminary Micro, Inc. All rights reserved.
// Software License Agreement
//
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
// exclusively on LMI's microcontroller products.
//
// The software is owned by LMI and/or its suppliers, and is protected under
// applicable copyright laws. All rights are reserved. You may not combine
// this software with "viral" open-source software in order to form a larger
// program. Any use in violation of the foregoing restrictions may subject
// the user to criminal sanctions under applicable laws, as well as to civil
// liability for the breach of the terms and conditions of this license.
//
// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 5228 of the Stellaris Graphics Library.
//
//*****************************************************************************
#include "driverlib/debug.h"
#include "grlib/grlib.h"
//*****************************************************************************
//
//! \addtogroup primitives_api
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
//! Initializes a drawing context.
//!
//! \param pContext is a pointer to the drawing context to initialize.
//! \param pDisplay is a pointer to the tDisplayInfo structure that describes
//! the display driver to use.
//!
//! This function initializes a drawing context, preparing it for use. The
//! provided display driver will be used for all subsequent graphics
//! operations, and the default clipping region will be set to the extent of
//! the screen.
//!
//! \return None.
//初始化一个绘图环境
//pContext绘图环境
//pDisplay 绘图环境所使用的显示驱动
//*****************************************************************************
void
GrContextInit(tContext *pContext, const tDisplay *pDisplay)
{
//
// Check the arguments.
//
ASSERT(pContext);
ASSERT(pDisplay);
//
// Set the size of the context.
//
pContext->lSize = sizeof(tContext);
//
// Save the pointer to the display.
//
pContext->pDisplay = pDisplay;//赋值显示驱动
//
// Initialize the extent of the clipping region to the extents of the
// screen.
//
pContext->sClipRegion.sXMin = 0;//根据显示驱动初始化显示的区域
pContext->sClipRegion.sYMin = 0;
pContext->sClipRegion.sXMax = pDisplay->usWidth - 1;
pContext->sClipRegion.sYMax = pDisplay->usHeight - 1;
//
// Provide a default color and font.
//
pContext->ulForeground = 0;
pContext->ulBackground = 0;
pContext->pFont = 0;//设置颜色字体
}
//*****************************************************************************
//
//! Sets the extents of the clipping region.
//!
//! \param pContext is a pointer to the drawing context to use.
//! \param pRect is a pointer to the structure containing the extents of the
//! clipping region.
//!
//! This function sets the extents of the clipping region. The clipping region
//! is not allowed to exceed the extents of the screen, but may be a portion of
//! the screen.
//!
//! The supplied coordinate are inclusive; \e sXMin of 1 and \e sXMax of 1 will
//! define a clipping region that will display only the pixels in the X = 1
//! column. A consequence of this is that the clipping region must contain
//! at least one row and one column.
//!
//! \return None.
//
//设置显示区域
//pContext绘图环境
//pRect绘图区域
//*****************************************************************************
void
GrContextClipRegionSet(tContext *pContext, tRectangle *pRect)
{
unsigned long ulW, ulH;
//
// Check the arguments.
//
ASSERT(pContext);
ASSERT(pRect);
//
// Get the width and height of the display.
//
ulW = DpyWidthGet(pContext->pDisplay);
ulH = DpyHeightGet(pContext->pDisplay);
//
// Set the extents of the clipping region, forcing them to reside within
// the extents of the screen.
//
/*
首先判断参数是否正确,不正确赋值为0
然后比较此时的最小值是否要比所设置的最小值要小,小则不变,大则变。
设置最大值,则是比较现有值是否比所要设置的值大,大则不变,小则变
*/
pContext->sClipRegion.sXMin = ((pRect->sXMin < 0) ? 0 :
((pRect->sXMin >= ulW) ? (ulW - 1) :
pRect->sXMin));
pContext->sClipRegion.sYMin = ((pRect->sYMin < 0) ? 0 :
((pRect->sYMin >= ulH) ? (ulH - 1) :
pRect->sYMin));
pContext->sClipRegion.sXMax = ((pRect->sXMax < 0) ? 0 :
((pRect->sXMax >= ulW) ? (ulW - 1) :
pRect->sXMax));
pContext->sClipRegion.sYMax = ((pRect->sYMax < 0) ? 0 :
((pRect->sYMax >= ulH) ? (ulH - 1) :
pRect->sYMax));
}
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************