⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcdsim.c

📁 LCDSIM3.90version
💻 C
📖 第 1 页 / 共 2 页
字号:
	char* lptemp = 0;
	if(BPP == 0)	return;
	color = FilterColor(color, LCDSIM_aLCDColorBlack[0], LCDSIM_aLCDColorWhite[0]);
	lptemp = (char*)pBitmapInfo + 0x28 + Pos * 4;
	*(char*)lptemp++ = (color & 0xff0000) >> 16;
	*(char*)lptemp++ = (color & 0xff00) >> 8;
	*(char*)lptemp = color & 0xff;
	ModifyCnt++;
	LUT_ModifyCnt++;
	if(pFix != 0){
		lptemp = (char*)pFix + 0x3c;
		*lptemp = ModifyCnt;
		lptemp = (char*)pFix + 0x40;	
		// 2005-8-27 13:17:57
		//*lptemp = LUT_ModifyCnt;
		*((int*)lptemp) = LUT_ModifyCnt;
	}
}


///////////////////////////////////////////////////////////////////////
//
// 函数名       : LCDSIM_Index2Color
// 功能描述     : 索引转化成RGB颜色, 分象素点占8位(及8位以下)和大于8位的情况
//				: 在UCGUI官方提供的转换函数中有BUG(大于8位时), 但由于此函数一般
//				: 情况下只被8位的情况下调用, 所以不会导致出错.因为首先调用的是LCDSIM_GetPixelColor.
//				: 对于8的情况, 根据索引直接在调色板去取, 大于8位的则要进行一个转换.
// 参数         : int Index
// 返回值       : int 
//
///////////////////////////////////////////////////////////////////////
int LCDSIM_Index2Color(int Index)
{
	int getColor = 0;

	if(BPP == 0)	return getColor;
	else if(BPP > 8){
		getColor = Convert_Index16IntoIndex32(Index);
	}
	else if(BPP <= 8){
		getColor = *((char*)pBitmapInfo + 0x28 + Index*4) << 16 | *((char*)pBitmapInfo + 0x29 + Index*4) << 8 | *((char*)pBitmapInfo + 0x2a + Index*4);
	}
	return getColor;
}


///////////////////////////////////////////////////////////////////////
//
// 函数名       : LCDSIM_GetPixelColor
// 功能描述     : 取指定象素点颜色, 
// 参数         : int x
// 参数         : int y
// 返回值       : int 
//
///////////////////////////////////////////////////////////////////////
int LCDSIM_GetPixelColor(int x, int y)
{
	int Color = 0;
	if(paaPixel == 0)	return Color;
	if(BPP > 8){
		Color = *((int*)paaPixel + y * BytesPerLine + x * 4);		//直接在显示内存中取, 其值即为该点RGB值.
	}
	else if(BPP <= 8){
		Color = *((char*)paaPixel + BytesPerLine * y + x * 4);
		Color = LCDSIM_Index2Color(LCDSIM_GetPixelIndex(x, y));
	}
	return Color;
}

//此函数有两种实现方法

 static U32 _ColorRef2Color(COLORREF ColorRef) {
  return (ColorRef & (255 << 8)) | ((ColorRef & 255) << 16) | ((ColorRef & (255 << 16)) >> 16);
}

///////////////////////////////////////////////////////////////////////
//
// 函数名       : COLORREF2Index
// 功能描述     : Convert_Index16IntoIndex32的相反功能函数, 用于象素点大于8位的情况
//				: 下转换指定RGB值到Index...
// 参数         : LCD_COLOR color
// 返回值       : int 
//
///////////////////////////////////////////////////////////////////////
int COLORREF2Index(LCD_COLOR color)
{
/* 2005-9-15 23:17:32
	char r = 0, b = 0, g = 0;
	int x = 0, y = 0, z = 0;
	x = FixedPalette / 100;
	y = (FixedPalette / 10) %10;
	z = FixedPalette % 10;
//	r  = (color & 0xff) >> (8 - z);
//	g  = ((color >> 8) & 8) >> (8 - y);
//	b  = (color >> 16) >> (8 - x);
	b  = ((color >> 16) & 0xff) >> (8 - z);
	g  = ((color >> 8) & 0xff) >> (8 - y);
	r  = (color & 0xff) >> (8 - x);
	return r | (g << y) | (b<< (y+x));*/

	//下面一句是正确的代码,有待研究上面不正确的原因...
	return LCD_Color2Index(_ColorRef2Color(color));		//此一句可以底上前面的N句...

/* 2005-6-4 12:31:02
	int Index = 0;
	switch(FixedPalette){
	case 444:
		Index = LCD_Color2Index_444(Index);
		break;
	case 555:
		Index = LCD_Color2Index_555(Index);
		break;
	case -555:
		Index = LCD_Color2Index_M555(Index);
		break;
	case 565:
		Index = LCD_Color2Index_565(Index);
		break;
	case -565:
		Index = LCD_Color2Index_M555(Index);
		break;
	case -444:	//无此项转换...
		break;
	}
	return Index;*/
/* 2005-6-4 12:33:06
	return COLOR2INDEX(color);		//此一句可以底上前面的N句...
*/
}


///////////////////////////////////////////////////////////////////////
//
// 函数名       : LCDSIM_GetPixelIndex
// 功能描述     : 获取指定象素点颜色索引.
// 参数         : int x
// 参数         : int y
// 返回值       : int  
//
///////////////////////////////////////////////////////////////////////
int  LCDSIM_GetPixelIndex(int x, int y)
{
	int Index = 0;
	if(BPP == 0 || paaPixel == 0)	return Index;
	else if(BPP > 8){
		Index = COLORREF2Index(*((int*)((char*)paaPixel + y * BytesPerLine + x*4)));
		Index &= 0xffffff;
	}
	else if(BPP <= 8){
		Index = *((char*)paaPixel + y * BytesPerLine + x);
		Index = (BYTE)Index;
	}
	return Index;
}

/* 2005-6-4 14:11:24
//MOSE消息结构...
typedef struct {
  int x,y;
  unsigned char KeyStat;
} LCD_tMouseState;*/

int  LCDSIM_GetMouseState(LCD_tMouseState *pState)
{
	pState->x = *(int*)((char*)pFix + 0x50);
	pState->y = *(int*)((char*)pFix + 0x54);
	pState->KeyStat = *((char*)pFix + 0x58);
	return 0;
}

void LCDSIM_SetMouseState(int x, int y, int KeyStat)
{
	int* lptemp = 0;
	int Mag_x = 1, Mag_y = 1;
	if(pFix == 0)	return;
	lptemp = (int*)((char*)pFix + 0x50);
	if(LCD_GetXMag() > 0) Mag_x = LCD_GetXMag();
	if(LCD_GetYMag() > 0) Mag_y = LCD_GetYMag();
	*lptemp++ = x / Mag_x;
	*lptemp++ = y / Mag_y;
	*(char*)lptemp = KeyStat;
	mouseMessage.x = x / Mag_x;
	mouseMessage.y = y / Mag_y;
	mouseMessage.KeyStat = KeyStat;
	NotifyMouseState(mouseMessage);
}


///////////////////////////////////////////////////////////////////////
//
// 函数名       : NotifyMouseState
// 功能描述     : 传递消息进GUI内部, 驱动GUI内部的事件机制...
// 参数         : LCD_tMouseState mouseState
// 返回值       : void 
//
///////////////////////////////////////////////////////////////////////
void NotifyMouseState(LCD_tMouseState mouseState)
{
	if(mouseState.KeyStat == 0){
		GUI_TOUCH_StoreState(-1, -1);
	}
	else{
		GUI_TOUCH_StoreState(mouseState.x, mouseState.y);
	}
	GUI_MOUSE_StoreState((const GUI_PID_STATE*)&mouseState);
}


///////////////////////////////////////////////////////////////////////
//
// 函数名       : LCDSIM_CheckMouseState
// 功能描述     : 在lcd窗口函数中的定时器中调用, 用于随时响应外部MOUSE事件,
//				: 如用MOUSE按下左键拖住对话框标题移动...
// 参数         : void
// 返回值       : void 
//
///////////////////////////////////////////////////////////////////////
void LCDSIM_CheckMouseState(void)
{
	int x = 0, y = 0;
	char KeyStat = 0;
	x = *(int*)((char*)pFix + 0x50);
	y = *(int*)((char*)pFix + 0x54);
	KeyStat = *((char*)pFix + 0x58);
	if(x | y | KeyStat){
		mouseMessage.x = x;
		mouseMessage.y = y;
		mouseMessage.KeyStat = KeyStat;
		NotifyMouseState(mouseMessage);
	}
}

void LCDSIM_RLUT_SetPixelIndex(int x, int y, int Index)
{

}

int  LCDSIM_RLUT_GetPixelIndex(int x, int y)
{
	return 0;
}

//填充一个矩形...
//#define FASTTING	1	//定义是否加速, 使用串传送, 注意移值性问题...
void  LCDSIM_FillRect(int x0, int y0, int x1, int y1, int Index)
{
	int step = 1, color = 0;
	int line  = 0, comlum = 0;
	char* lptemp = 0;
	if(BPP == 0)	return;
	if(x1 > XSize)	x1 = XSize - 1;
	if(y1 > YSize)	y1 = YSize - 1;
	if(x0 < 0)	x1 = 1;
	if(y1 < 0)	y1 = 1;
	if(paaPixel == 0)	return;
	if(BPP > 8){
		step = 4;
		color = Convert_Index16IntoIndex32(Index);
	}
	else{
		color = Index;
	}
	comlum = (x1 - x0);
	lptemp = (char*)paaPixel + BytesPerLine * y0 + x0 * step;

	//矩形宽度是否为整行...
#ifdef FASTTING
	if(comlum == XSize){
		comlum = comlum*(y1-y0);
		_asm{
			mov eax, color
			mov ecx, comlum
			mov edi, lptemp
		}
		if(step == 1) __asm rep stosb
		else __asm rep stosd
		return;
	}
#endif

// 2005-8-27 14:35:38 使用串传送指令提高速度...
	for(line = y0; line < (y1 - y0); line++){
#ifdef FASTTING
		_asm{
			mov eax, color
			mov ecx, comlum
			mov edi, lptemp
		}
		if(step == 1) __asm rep stosb
		else __asm rep stosd
		lptemp += BytesPerLine; 
#else
		// 2005-8-27 14:54:02
		for(comlum = x0; comlum < (x1 - x0); comlum++){
			lptemp = (char*)paaPixel + BytesPerLine * line + comlum * step;
			if(step == 4) *((int*)lptemp) = color;
			else *lptemp = color;
		}
#endif
	}
}

int   LCDSIM_GetModifyCnt(void)
{
//	return ModifyCnt;
	return *((char*)pFix + 0x3c);	//在ucgui-view的程序当中, 要从映象中来取数据,一定要注意这一点,
									//与模拟器是有区别的...
}

int   LCDSIM_GetModifyCntInfo(void)
{
//	return LUT_ModifyCnt;
	return *((char*)pFix + 0x40);	//在ucgui-view的程序当中, 要从映象中来取数据,一定要注意这一点,

}


///////////////////////////////////////////////////////////////////////
//
// 函数名       : LCDSIM_CheckInit
// 功能描述     : 检测是否须要重新初始化映象, 及有关LCD显示当中要用到的一些信息XSize/bpp等...
//				: 对于关掉一个GUI应用后. 重新开一个GUI应用时, 则UCGUIVIEW会检测是否要重新初始化...
// 参数         : HWND hwnd
// 返回值       : void 
//
///////////////////////////////////////////////////////////////////////
void LCDSIM_CheckInit(HWND hwnd)
{
	/* 2005-6-5 12:22:11
	XSize = LCD_GetXSize() * LCD_GetXMag();
	YSize = LCD_GetYSize() * LCD_GetYMag();
	VXSize = LCD_GetVXSize();
	VYSize = LCD_GetVYSize();
	NumColors = LCD_GetNumColors();*/
	int		ret = 0;
	int*	lptemp = 0;
	int		newBPP = BPP, newVXSize = VXSize, newVYSize = VYSize, newXSize = XSize, newYSize = YSize;
	unsigned int newFixedPalette = FixedPalette;
	if(pSMemFix !=0){
		lptemp =(int*)((char*)pSMemFix+0x20);		//pSMemFix+0x20开始依次存放以下东西...
		newXSize = *lptemp++;
		newYSize = *lptemp++;
		newVXSize = *lptemp++;
		newVYSize = *lptemp++;
		newFixedPalette = *lptemp++;				//此处暂空闲...
		newBPP = *lptemp++;
		lptemp =(int*)((char*)pSMemFix+0x20);		//pSMemFix+0x20开始依次存放以下东西...
		if(newXSize != XSize || newYSize != YSize || newBPP != BPP || newFixedPalette != FixedPalette){
			(char*)ret = LCDSIM_Init();
			if(ret !=0){
				MessageBox(hWndMain, (char*)ret, BRANDING_GetAppNameShort(), 0);
			}
			else{
				XSize = *lptemp++;
				YSize = *lptemp++;
				VXSize = *lptemp++;
				VYSize = *lptemp++;
				FixedPalette = *lptemp++;			//此处暂空闲...
				BPP = *lptemp++;
				wsprintf(LCDCaption, "LCD %d*%d %dbpp, FixedPalette %d", XSize, YSize, BPP, FixedPalette);
				SetWindowText(hwnd, (LPCSTR)LCDCaption);
			}
		}
		/* 2005-6-5 12:43:24
		*lptemp++ = NumColors;
		BPP = LCD_GetBitsPerPixel();
		FixedPalette = LCD_GetFixedPalette();*/
	}
}

void LCDSIM_Paint(HDC hDC)
{
//	LCDSIM_CheckInit();		//检查是否需要重新初始化,如更改了每个象素的位数,或LCD宽高等...
	LCDSIM_PaintAt(hDC, 0, 0);
}

void LCDSIM_PaintAt(HDC hDC, int x, int y)
{
	RECT RectDest, RectSrc;
	RectDest.left = 0;
	RectDest.top = 0;
	RectDest.right = XSize - 1;
	RectDest.bottom = YSize - 1;
	RectSrc = RectDest;
	RectSrc.left = x;
	RectSrc.right += x;
	RectSrc.top = y;
	RectSrc.bottom += y;
	LCDSIM_PaintEx(hDC, &RectDest, &RectSrc);
}


///////////////////////////////////////////////////////////////////////
//
// 函数名       : LCDSIM_PaintEx
// 功能描述     : 将内存映象中用作LCD显示屏幕中的数据(一幅位图)显示出来..
//				: 会自动判断是否须要拉伸显示....
// 参数         : HDC hDC
// 参数         : LPRECT pRectDest
// 参数         : LPRECT pRectSrc
// 返回值       : void 
//
///////////////////////////////////////////////////////////////////////
void LCDSIM_PaintEx(HDC hDC, LPRECT pRectDest, LPRECT pRectSrc)
{
	int i  = 0;
	int* lptemp = 0;
	int DestWidth = 0, DestHeight = 0;
	int SrcWidth = 0, SrcHeight = 0;

	if(BPP == 0)	return;
	lptemp = (int*)pBitmapInfo;
	if(lptemp == 0)	return;
	for(i = 0; i < 10; i++)
		*lptemp++ = 0;
	lptemp = (int*)pBitmapInfo;
	*lptemp++ = 0x28;
	*lptemp++ = XSize;
	_asm{
		mov eax, YSize;
		neg eax;
		push esi;
		lea esi, lptemp;
	//	mov [esi], eax;
		mov esi, lptemp;
		mov [esi], eax;
		pop esi;
	}
	lptemp++;
	*((short int*)lptemp)++ = 1;
	if(BPP > 8){
		*((short int*)lptemp)++ = 0x20;
	}
	else{
		*((short int*)lptemp)++ = 8;
	}
	*lptemp++ = 0;
	SetStretchBltMode(hDC, STRETCH_DELETESCANS);
	DestWidth = pRectDest->right - pRectDest->left;
	DestHeight = pRectDest->bottom - pRectDest->top;
	SrcWidth = pRectSrc->right - pRectSrc->left;
	SrcHeight = pRectSrc->top - pRectSrc->bottom;
	//按比例显示显示位图...
	if((DestWidth != SrcWidth)|| (SrcHeight != SrcHeight)){
		StretchDIBits(hDC, pRectDest->left, pRectDest->top, DestWidth, SrcHeight, pRectSrc->left, pRectSrc->right, SrcWidth, SrcHeight+1, paaPixel, pBitmapInfo,0, 0x0CC0020);
	}
	else{
		SetDIBitsToDevice(hDC, pRectDest->left, pRectDest->top, DestWidth, DestHeight, pRectSrc->left, YSize - pRectSrc->bottom - 1, 0, YSize, paaPixel, pBitmapInfo, 0);
	}
}



/* 2005-5-30 23:56:22
int	SIM_SetMag(int simmag)
{
	int Oldsimmag = Mag;
	Mag = simmag;
	return Oldsimmag;
}

int	SIM_SetMag(int simmag)
{
	return timeGetTime()-timeStartup;
}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -