📄 gpcdraw.c
字号:
/*************************************************************************
*
* Copyright 2000 National ASIC Center, All right Reserved
*
* FILE NAME: gpcdraw.c
* PROGRAMMER: XuanHui
* Date of Creation:
*
* DESCRIPTION:
*
* NOTE:
*
*
* FUNCTIONS LIST:
* -------------------------------------------------------------------------
*
* GLOBAL VARS LIST:
*
*
**************************************************************************
* MODIFICATION HISTORY
*
* 2001/11/19 by Lingming Bug fixing in param check
* if ( xPos > (pGC->width - 1) ) //we need minus 1
* return GPC_ERR_FAILED;
*************************************************************************/
#include <stdlib.h>
#include <string.h>
#include "ros33.h"
#include "gpc.h"
#include "lmalloc.h"
#include "taskdsp.h"
#include "systsk.h"
#include "vramop.h"
//#include <simdrv\export\driver.h> //by zhuli 2002.2.3
#include "asixapp.h"
#include "bitmap.h"
#define DEFAULT_ENGLISH_FONT GPCFONT11A ////gfd
#define DEFAULT_CHINESE_FONT GPCFONT11K ////gfd
/*
#ifdef SIM_ON_PC
#define DEFAULT_ENGLISH_FONT GPCFONT11A
#define DEFAULT_CHINESE_FONT GPCFONT11K
#else
#define DEFAULT_ENGLISH_FONT ENGLISH_FONT_LIB_START
#define DEFAULT_CHINESE_FONT CHINESE_FONT_LIB_START
#endif
*/ ////gfd
//#define DEFAULT_CHINESE_FONT NULL
//-------------------------------------------------------------------------
// SysInitGC( )
//
// Allocate and initalize a graphic context (GC).
//
// No Parameters
//
// Returns:
// GC pointer. If allcation or intialization fail, pointer is NULL.
//-------------------------------------------------------------------------
DWORD SysInitGC( WORD vramWidth, WORD vramHeight )
{
GC *pGC;
PIXEL index;
if (((SHORT)vramWidth < 0) ||( (SHORT)vramHeight < 0))//by zl 2002.4.3
return GPC_ERR_FAILED;
// pGC = ( GC* )SysLcalloc( sizeof( GC ) );//by zl 2002.4.3因为没有必要多清0的步骤
pGC = ( GC* )SysLmalloc( sizeof( GC ) );
if ( pGC == NULL )
return 0;
seRGBtoIndex(GPC_BLUE , &index);
pGC->frt_color = index; //前景色(默认值为蓝色)
seRGBtoIndex(GPC_WHITE , &index);
pGC->bk_color = index; //背景色(默认值为白色)
pGC->dotwidth = 1; //当前线宽(默认值为1)
pGC->status = 1; //状态(是否拥有LCD?)
pGC->width = vramWidth; //逻辑屏幕宽(默认值为160个像素)
pGC->height = vramHeight; //逻辑屏幕高(默认值为240个像素)
pGC->lcd_x = 0; //物理屏幕在逻辑屏幕上的坐标(默认值为0)
pGC->lcd_y = 0; //物理屏幕在逻辑屏幕上的坐标(默认值为0)
pGC->cursor = NULL; //软光标(默认值为不使用)
pGC->group_operation = 0; //组操作(默认值为不使用) zhuli 2002.2.4
// longn_qi 2001/12/20 added
pGC->symbol = GPC_GC_SYMBOL; //结构标识符0x4743('GC')
pGC->reserved = 0;
// longn_qi 2002/04/05 added
pGC->fillmode = GPC_REPLACE_STYLE;
// pGC->vram = ( PWORD )SysLcalloc( pGC->width * pGC->height * sizeof( WORD ) ); //vram指针 by zl 2002.4.3因为没有必要多清0的步骤
pGC->vram = GetVRAM( pGC->width, pGC->height ); //vram指针
if ( pGC->vram == NULL )
{
SysLfree( pGC );
return 0;
}
pGC->font = ( PFONT )SysLcalloc( sizeof( FONT ) ); //字体结构
if ( pGC->font == NULL )
{
// SysLfree( pGC->vram ); // longn_qi 2001/12/20 added
FreeVRAM( pGC->vram ); // longn_qi 2001/12/20 added
SysLfree( pGC );
return 0;
}
// SysSetFont( ( DWORD )pGC, ( PBYTE )GPCFONT11A, ( PBYTE )GPCFONT11K );//by zl 2002.4.3
SysSetFont( ( DWORD )pGC, ( PBYTE )DEFAULT_ENGLISH_FONT, ( PBYTE )DEFAULT_CHINESE_FONT );
return ( DWORD )pGC;
}
STATUS SysFreeGC( DWORD gc )
{
GC *pGC;
pGC = (GC *)gc;
if ( pGC == NULL || pGC->symbol != GPC_GC_SYMBOL )
return GPC_ERR_FAILED;
if ( pGC->vram != NULL )
// SysLfree( pGC->vram );
FreeVRAM( pGC->vram );
if ( pGC->font != NULL )
SysLfree( pGC->font );
if ( pGC->cursor != NULL )
SysLfree( pGC->cursor );
SysLfree( pGC );
return GPC_ERR_OK;
}
//---------------------------------------------------------------
// SysGetDisplayX()
//
// Get LCD display screen width.
//
// Returns:
// DisplayX
//---------------------------------------------------------------
WORD SysGetDisplayX( void )
{
return PHY_LCD_W ;
}
//---------------------------------------------------------------
// SysGetDisplayY()
//
// Get LCD display screen height.
//
// Returns:
// DisplayY
//---------------------------------------------------------------
WORD SysGetDisplayY( void )
{
return PHY_LCD_H;
}
//---------------------------------------------------------------
// SysGetLogicalX()
//
// Get the current panning screen width.
//
// Parameters:
// gc - Address value of graphic context.
// Returns:
// pGC->width
//---------------------------------------------------------------
WORD SysGetLogicalX( DWORD gc )
{
GC *pGC;
pGC = (GC *)gc;
if ( pGC == NULL || pGC->symbol != GPC_GC_SYMBOL )
return GPC_ERR_FAILED;
return pGC->width;
}
//---------------------------------------------------------------
// SysGetLogicalX()
//
// Get the current panning screen height.
//
// Parameters:
// gc - Address value of graphic context.
// Returns:
// pGC->height
//---------------------------------------------------------------
WORD SysGetLogicalY( DWORD gc )
{
GC *pGC;
pGC = (GC *)gc;
if ( pGC == NULL || pGC->symbol != GPC_GC_SYMBOL )
return GPC_ERR_FAILED;
return pGC->height;
}
//---------------------------------------------------------------
// SysGetGC()
//
// Get a value of point address of graphic context.
//
// Returns:
// &pGC
//---------------------------------------------------------------
DWORD SysGetGC( void )
{
DWORD pGC;
ID id;
get_tid( &id );
pGC = ( DWORD )gSysTcbTbl[id-1].gc;
return pGC;
}
STATUS SysSetColor( DWORD gc, DWORD rgb )
{
GC *pGC;
PIXEL index;
pGC = (GC *)gc;
if ( pGC == NULL || pGC->symbol != GPC_GC_SYMBOL )
return GPC_ERR_FAILED;
seRGBtoIndex(rgb , &index);
pGC->frt_color = index;
return GPC_ERR_OK;
}
STATUS SysSetBkColor( DWORD gc, DWORD rgb )
{
GC *pGC;
PIXEL index;
pGC = (GC *)gc;
if ( pGC == NULL || pGC->symbol != GPC_GC_SYMBOL )
return GPC_ERR_FAILED;
seRGBtoIndex(rgb , &index);
pGC->bk_color = index;
return GPC_ERR_OK;
}
//---------------------------------------------------------------
// SysSetDotWidth()
//
// Set the width of a dot.
//
// Parameters:
// gc - Address value of graphic context.
// newWidth - New dot width.
// oldWidth - Previous dot width.
//
// Returns:
// GPC_ERR_OK
//---------------------------------------------------------------
STATUS SysSetDotWidth( DWORD gc, WORD newWidth, PWORD oldWidth )
{
GC *pGC;
pGC = (GC *)gc;
if ( pGC == NULL || pGC->symbol != GPC_GC_SYMBOL )
return GPC_ERR_FAILED;
if ( newWidth == 0 || newWidth > MAX_DOT_WIDTH )
return GPC_ERR_FAILED;
if ( oldWidth != NULL )
*oldWidth = pGC->dotwidth;
pGC->dotwidth = newWidth;
return GPC_ERR_OK;
}
//---------------------------------------------------------------
// SysGroupOn
// set the group_operation of the graphic context (GC).
//
// Parameters:
// gc - Address value of graphic context.
//
//
// Returns:
// GPC_ERR_OK
//---------------------------------------------------------------
STATUS SysGroupOn( DWORD gc ) //by zhuli 2002.2.4
{
GC *pGC;
pGC = (GC *)gc;
if ( pGC == NULL || pGC->symbol != GPC_GC_SYMBOL )
return GPC_ERR_FAILED;
// if ( pGC->group_operation == 0 )
pGC->group_operation++ ;
return GPC_ERR_OK;
}
//---------------------------------------------------------------
// SysGroupOff
// reposition the group_operation of the graphic context (GC),
// and refresh the LCD with the top-left corner at (xSrc,ySrc)
// and bottom-right corner at (xDest,yDest).
//
// Parameters:
// gc - Address value of graphic context.
//
//
// Returns:
// GPC_ERR_OK
//---------------------------------------------------------------
STATUS SysGroupOff( DWORD gc, WORD xSrc, WORD ySrc, WORD xDest, WORD yDest) //by zhuli 2002.2.4
{
GC *pGC;
pGC = (GC *)gc;
// if ( pGC == NULL || pGC->symbol != GPC_GC_SYMBOL )
// return GPC_ERR_FAILED;
if ( pGC->group_operation > 0 )
pGC->group_operation--;
if ( pGC->group_operation == 0 )
{
if ( xSrc > (pGC->width -1) || xDest > (pGC->width -1) )
return GPC_ERR_FAILED;
if ( ySrc > (pGC->height -1) || yDest > (pGC->height -1) )
return GPC_ERR_FAILED;
if( pGC == gSysTcbTbl[ gLcdOwnerTskId-1 ].gc )
WRITELCD( xSrc, ySrc, xDest, yDest )
// seWrite2LCD( pGC->vram, 0);
}
return GPC_ERR_OK;
}
//---------------------------------------------------------------
// SysClearScreen()
//
// Clear screen with rgb.
//
// Parameters:
// gc - Address value of graphic context.
// rgb - Color of the line.
//
// Returns:
// GPC_ERR_OK
//---------------------------------------------------------------
STATUS SysClearScreen( DWORD gc, DWORD rgb )
{
GC *pGC;
PIXEL index;
pGC = (GC *)gc;
if ( pGC == NULL || pGC->symbol != GPC_GC_SYMBOL )
return GPC_ERR_FAILED;
seRGBtoIndex( rgb, &index ); //turn into colorindex
seClearRec( pGC, 0, 0, pGC->width, pGC->height, index, GPC_REPLACE_STYLE );
if( pGC == gSysTcbTbl[ gLcdOwnerTskId-1 ].gc && pGC->group_operation == 0 )
WRITELCD( 0, 0, pGC->width -1, pGC->height -1)
// seWrite2LCD( pGC->vram, 0);
return GPC_ERR_OK;
}
//---------------------------------------------------------------
// SysDrawDot()
//
// Draw a dot with color(rgb) at position(xPos,yPos) with indicated style.
//
// Parameters:
// gc - Address value of graphic context.
// rgb - Color of the line.
// xPos - Position X of the dot.
// yPos - Position Y of the dot.
// style - Output style.
//
// Returns:
// GPC_ERR_OK
//---------------------------------------------------------------
STATUS SysDrawDot( DWORD gc, DWORD rgb, WORD xPos, WORD yPos, WORD style )//STATUS DrawDot( DWORD gc, DWORD rgb, WORD xPos, WORD yPos, WORD style )
{
GC *pGC;
PIXEL index;
pGC = (GC *)gc;
if ( pGC == NULL || pGC->symbol != GPC_GC_SYMBOL )
return GPC_ERR_FAILED;
if ( xPos > (pGC->width - 1) )
return GPC_ERR_FAILED;
if ( yPos > (pGC->height - 1) )
return GPC_ERR_FAILED;
// if ( style < GPC_REPLACE_STYLE || style > GPC_NOT_STYLE )
// return GPC_ERR_FAILED;
seRGBtoIndex( rgb, &index ); //turn into colorindex
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -