www.pudn.com > uCGUI3.24-MemDev-for-3.90a.rar > GUIDEV_Banding.c
/*! @file GUIDEV_Banding.c * Implementation of banding memory devices * * @author hiber modified * @author Copyleft (C) 1981-2006, All Rights Givenup * @date 04/18/2006 * @version * * @note This routine uses a banding memory device to draw the given area flicker free. * It not only draws, but also automatically calculates the size of, creates, moves * and then destroys the memory device. * @attention * @warning * @bug * * @todo * @example* @see */ #include #include "GUI_Protected.h" #include "GUIDebug.h" #if GUI_SUPPORT_MEMDEV extern void * _GUI_ALLOC_h2p_Lock(GUI_HMEM hMem); #define GUI_ALLOC_H2P(h) _GUI_ALLOC_h2p_Lock(h) #define GUI_ALLOC_FREE(handle) GUI_ALLOC_Free(handle) #define GUI_ALLOC_LOCK(handle) _GUI_ALLOC_h2p_Lock(handle) #define GUI_ALLOC_UNLOCK(handle) #ifdef GUI_USAGE_H2P #undef GUI_USAGE_H2P #define GUI_USAGE_H2P(h) ((GUI_USAGE*)_GUI_ALLOC_h2p_Lock(h)) #endif #ifdef GUI_MEMDEV_H2P #undef GUI_MEMDEV_H2P #define GUI_MEMDEV_H2P _GUI_ALLOC_h2p_Lock #endif ////////////////////////////////////////////////////////////////////////// static int Min(int v0, int v1) { if (v0 <= v1) { return v0; } return v1; } //! 防止显示屏闪烁的基本函数 //! @param pRect 所使用的LCD 的一个GUI_RECT 结构的指针。 //! @param pfDraw 执行绘图操作的一个回调函数的指针。 //! @param pData 作为回调函数参数使用的一个数据结构的指针。 //! @param NumLines 0(推荐)或者是存储设备的分段数量。 //! @param Flags 0 或者 GUI_MEMDEV_HASTRANS。 //! @return 如果成功返回0,如果函数执行失败则返回1。 //! @note 如果参数NumLines 为0,则每段中的线段数量由函数自动计算。通过移动存储设备的原 //! 点,函数一段又一段地重复改写输出区域。 int GUI_MEMDEV_Draw(GUI_RECT *pRect, GUI_CALLBACK_VOID_P *pfDraw, void *pData, int NumLines, int Flags) { int x0, y0, x1, y1, xsize, ysize; GUI_MEMDEV_Handle hMD; if (pRect) { x0 = (pRect->x0 < 0) ? 0 : pRect->x0; y0 = (pRect->y0 < 0) ? 0 : pRect->y0; x1 = Min(pRect->x1, LCD_GET_XSIZE() - 1); y1 = Min(pRect->y1, LCD_GET_YSIZE() - 1); xsize = x1 - x0 + 1; ysize = y1 - y0 + 1; } else { x0 = 0; y0 = 0; xsize = LCD_GET_XSIZE(); ysize = LCD_GET_YSIZE(); } if (NumLines == 0) { NumLines = - ysize; /* Request lines ... Less is o.k. */ } if ((xsize <= 0) || (ysize <= 0)) { return 0; } /* Nothing to do ... */ /* Create memory device */ hMD = GUI_MEMDEV_CreateEx(x0, y0, xsize, NumLines, Flags); if (!hMD) { GUI_DEBUG_ERROROUT("GUI_MEMDEV_Draw() Not enough memory ..."); /* Not enough memory ! */ pfDraw(pData); return 1; } NumLines = GUI_MEMDEV_GetYSize(hMD); GUI_MEMDEV_Select(hMD); /* Start drawing ... */ { int i; for (i = 0; i < ysize; i += NumLines) { int RemLines = ysize - i; if (RemLines < NumLines) { GUI_MEMDEV_ReduceYSize(hMD, RemLines); } if (i) { GUI_MEMDEV_SetOrg(hMD, x0, y0 + i); GUI_MEMDEV_Clear(hMD); } pfDraw(pData); GUI_MEMDEV_CopyToLCD(hMD); } } GUI_MEMDEV_Delete(hMD); GUI_MEMDEV_Select(0); return 0; /* Success ! */ } #else void GUIDEV_Banding(void) {} /* avoid empty object files */ #endif /* GUI_MEMDEV_SUPPORT */