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

📄 gfx_drawcontrol.c

📁 sigmadesign smp8623 gui source code ,bingo
💻 C
📖 第 1 页 / 共 5 页
字号:
				if(status == RM_FATALOUTOFMEMORY){					status = FindFreeSpace(bmpsize, &index);					//if(GetAlternateIndex(i, &index, bmpsize))					{						RMMemset(&g_bitmaps[i], 0, sizeof(RMbitmapdata));						RMCopyAscii(g_bitmaps[index].path, path);						g_bitmaps[index].ispredefinedfont = TRUE;						*fontindex = index;						return setPredefinedFont(pRua, &g_bitmaps[index], &bmpsize);					}				}				break;			}		}		else{			if(RMCompareAscii(g_bitmaps[i].path, path)){				if(predeffont){					*fontindex = i;					return RM_OK;				}			}		}	}	return status;}static inline RMuint8 GetTextBufferIndex(){	RMuint8 temp = (g_textBufferIndex < MAX_STR_BUFFERS - 1 ? g_textBufferIndex + 1 : 0);	g_textBufferIndex = temp;	return g_textBufferIndex;}static inline RMuint8 GetBitmapBufferIndex(RMbool whole){	RMuint8 temp;	if(whole)		temp = (g_bitmapBufferIndex == 0 ? 1 : 0);	else		temp = (g_bitmapBufferIndex < MAX_DRAWING_BUFFER_PARTS ? g_bitmapBufferIndex + 1 : 0);	g_bitmapBufferIndex = temp;	return g_bitmapBufferIndex;}RMstatus gfxGetTextExtents(struct RUA *pRua, Prop *prop, GFXLib_rect *out_rect){//	//	static RMint8 width[2048]={-1,};//	//	static RMint8 size[2048]={-1,};//	//	static RMint8 height[2048]={-1,};//	//	static RMbool init = FALSE;//	//	RMuint64 begin, end;//	struct GFXEngine_GlyphMask_type glyph_param;//	RMuint16 i, l;//	union//	{//		RMuint16 l;//		RMint8 b[2];//	} big;////	//	if(!init)//	//	{//	//		for(l=0; l < 2048; l++)//	//		{//	//			width[l] = -1;//	//			height[l] = -1;//	//			size[l] = -1;//	//		}//	////	//		init = TRUE;//	//	}////	//	begin = RMGetTimeInMicroSeconds();////	if (out_rect == NULL)//		return RM_ERROR;////	out_rect->x = out_rect->y = out_rect->width = out_rect->height = 0;////	l = RMasciiLength(prop->text);////	for (i = 0; i < l; i++)//	{//		GFXLib_rect char_out_rect;//		if ((prop->text[i] & 0x80) == 0)//		{//			big.l = (RMuint16) prop->text[i];//			//		RMDBGLOG((GFXDBG, "One Byte \'%c\'\n", prop->text[i]));//		}//		else if (prop->text[i] & 0xC0)//		{//			RMuint8 _t;//			_t = prop->text[i];//			_t <<= 6;//			_t &= 0xC0;//			big.b[0] = (prop->text[i + 1] & 0x3F) | _t;//			big.b[1] = (prop->text[i] & 0x1f) >> 2;////			i++;//			//		RMDBGLOG((GFXDBG, "TwoBytes \'%X\'\n", big.l));//		}////		//		if(width[big.l] != -1 && (RMint8)prop->scale == size[big.l])//		//		{//		//			char_out_rect.width = width[big.l];//		//			char_out_rect.height = height[big.l];//		////		//		}//		//		else//		//		{//		rtk86_get_tt_char_size(pRua, (RMuint32) big.l, prop->scale, &glyph_param, &char_out_rect);////		//		char_out_rect.width += (prop->scale / 10);//		//		if(prop->scale == subs.sub_size)//		//			{//		//				width[big.l] = char_out_rect.width;//		//				height[big.l] = char_out_rect.height;//		//				size[big.l] = prop->scale;//		//			}//		//		}////		out_rect->width += char_out_rect.width;//		if (prop->scale != subs.sub_size)//			out_rect->width += (prop->scale >> 4);//		else//			out_rect->width += 2;////		if (out_rect->height < char_out_rect.height)//			out_rect->height = char_out_rect.height;////	}////	//	end = RMGetTimeInMicroSeconds();//	//	printf("Time Get text extents %llu\n", end - begin);	RMuint8 fontindex;	RMuint8 predeffontindex;	if(prop->scale >= 18)		GetFontIndex(pRua, "SigmaOSD118x23", &fontindex);	else		GetFontIndex(pRua, "SigmaOSD127x36", &fontindex);	getPredefinedFontIndex(g_bitmaps[fontindex].path, &predeffontindex);	out_rect->height = getFontHeight(predeffontindex);	out_rect->width = getTextWidth(prop->text, predeffontindex);	return RM_OK;}RMstatus DrawTextWithPredefinedFont(	struct RUA *pRua,	GFXLib_rect *rect,	GFXLib_textdata *txt,	RMuint8 fontindex,	RMTextProperties wrap){	RMstatus status = RM_OK;	RMuint32 xpos;	RMuint32 ypos;	RMuint16 width;	RMint32 length;	RMint16 i;	struct GFXEngine_MoveReplaceRectangle_type move_param;	struct GFXEngine_Surface_type surface_param;	RMuint16 charindex;	RMuint32 offset;	RMuint8 predeffontindex;	RMuint8 firstchar;	RMuint8 bufferindex;	RMuint32 bufferbegin;	RMuint8 textgap;	RMuint8 fontheight;	RMbool trunc = FALSE;	union	{		RMuint16 l;		RMint8 b[2];	} big;	if(RMFAILED(getPredefinedFontIndex(g_bitmaps[fontindex].path, &predeffontindex)))		return RM_ERROR;	length = RMasciiLength(txt->text);	// palette and color format previously set!!	bufferindex = GetTextBufferIndex();	bufferbegin = bufferindex * g_bitmaps[fontindex].bmp.uiBufferSize;//	if(txt->input){//		for(i = 0; i < length; i++){//			// check if text is password and replace chars accordingly//			if(txt->password == TRUE)//				txt->text[i] = ((txt->text[i] >= '0' && txt->text[i] <= '9') ? '*' : '#');//		}//	}	fontheight = getFontHeight(predeffontindex);	textgap = 0;//fontheight;	// calculate string width	width = getTextWidth(txt->text, predeffontindex);	if(width > rect->width && wrap == TRUNC_DOTS){		RMascii modText[4 * MAX_STR_LENGTH];		RMMemset(modText, 0, sizeof(modText));		width = getModifiedTextWidth(txt->text, rect->width + 10, modText, predeffontindex, TRUE);		RMCopyAscii(txt->text, modText);		length = RMasciiLength(txt->text);		trunc = TRUE;	}	else if(width + 20U > rect->width && wrap == TRUNC_SIMPLE){		RMascii modText[4 * MAX_STR_LENGTH];		RMMemset(modText, 0, sizeof(modText));		width = getModifiedTextWidth(txt->text, rect->width + 10, modText, predeffontindex, FALSE);		RMCopyAscii(txt->text, modText);		length = RMasciiLength(txt->text);		trunc = TRUE;	}	if(txt->alignment == ALIGN_LEFT){		xpos = rect->x + (textgap / 2);	}	else if(txt->alignment == ALIGN_CENTER){		xpos = rect->x + (rect->width - width) / 2;	}	else{	// ALIGN_RIGHT		xpos = rect->x + (rect->width - width) - (textgap / 2);	}	firstchar = getFontFirstChar(predeffontindex);	RMMemset(g_bitmaps[fontindex].bmp.pData + bufferbegin, 0, g_bitmaps[fontindex].bmp.uiBufferSize);	for(i = 0; i < length; i++){		RMbool double_inc = FALSE;		if ((txt->text[i] & 0x80) == 0)		{			big.l = txt->text[i];		}		else if (txt->text[i] & 0xC0)		{			RMuint8 _t;			_t = txt->text[i];			_t <<= 6;			_t &= 0xC0;			//			printf("draw string: %X %X\n", prop->text[i], prop->text[i+1]);			big.b[0] = (txt->text[i + 1] & 0x3F) | _t;			big.b[1] = (txt->text[i] & 0x1f) >> 2;			//i++			double_inc = TRUE;			//			RMDBGLOG((GFXDBG, "TwoBytes \'%X\'\n", big.l));		}		charindex = /*txt->text[i]*/big.l - firstchar;		getCharData(pRua, &g_bitmaps[fontindex], predeffontindex, charindex, &width, i, length, bufferindex);		if(double_inc)			i++;	}	ypos = rect->y + (rect->height - fontheight) / 2;	offset = 0;	// setup Y surface	surface_param.StartAddress = g_bitmaps[fontindex].pBmpAddr + bufferbegin;	surface_param.TotalWidth = 32 * length; 	surface_param.Tiled = FALSE;	surface_param.SurfaceID = GFX_SURFACE_ID_Y;	status = GFXSurfaceProperty(pRua, &surface_param);	if (RMFAILED(status))		RMDBGLOG((GFXDBG, "Error setting surface parameters\n"));	for(i = 0; i < length; i++){		RMbool double_inc = FALSE;		RMuint32 fcolor = ((i == txt->inputchar && txt->hasfocus) ? txt->selectioncolor : txt->foregroundcolor);		SetTextPalette(pRua, fcolor, txt->backgroundcolor, txt->transparentbackground);		if ((txt->text[i] & 0x80) == 0)		{			big.l = txt->text[i];		}		else if (txt->text[i] & 0xC0)		{			RMuint8 _t;			_t = txt->text[i];			_t <<= 6;			_t &= 0xC0;			//			printf("draw string: %X %X\n", prop->text[i], prop->text[i+1]);			big.b[0] = (txt->text[i + 1] & 0x3F) | _t;			big.b[1] = (txt->text[i] & 0x1f) >> 2;			//i++;			double_inc = TRUE;			//			RMDBGLOG((GFXDBG, "TwoBytes \'%X\'\n", big.l));		}		//printf("letter %X\n", big.l);		charindex = /*txt->text[i]*/big.l - firstchar;		width = getCharWidth(predeffontindex, charindex);		move_param.SrcX = i * 32;		move_param.SrcY = 0;		move_param.AlphaX = 0;		move_param.AlphaY = 0;		move_param.DstX = xpos + offset;		move_param.DstY = ypos;		move_param.Width = width;		move_param.Height = fontheight;		move_param.Merge = FALSE;		status = GFXReplaceRectangleProperty(pRua, &move_param);		offset += width;		if(double_inc)			i++;	}	return trunc ? RM_OK : RM_ERROR;}void ResetNonBackgroundBuffers(){	RMuint8 i;	RMuint32 usedbuffer = 0;	RMEnterCriticalSection(g_cs);	for (i = 1; i < MAX_BITMAPS; i++)	{		if (g_bitmaps[i].path[0] != '\0')		{			usedbuffer += g_bitmaps[i].bmp.uiDataSize;			// clear bmp buffer			RMMemset(&g_bitmaps[i], 0, sizeof(RMbitmapdata));		}		else			break;	}	ResetUsedBuffer(usedbuffer);	RMLeaveCriticalSection(g_cs);}RMstatus GetBitmapIndex(struct RUA *pRua, RMascii* path, RMuint8 *bmpindex, RMbool attemptReload){	RMuint8 i;	RMstatus status;	RMuint32 bmpsize = 0;	RMuint8 index;	RMEnterCriticalSection(g_cs);	// check if we already have the bitmap data from index 1 since 0 is reserved to background image	for (i = 1; i < MAX_BITMAPS; i++)	{		if (g_bitmaps[i].path[0] != '\0')		{			if (RMCompareAscii(g_bitmaps[i].path, path) && g_bitmaps[i].charwidth == 0)			{				*bmpindex = i;				UpdateCache(i);				RMLeaveCriticalSection(g_cs);				return RM_OK;			}			// not loaded			continue;		}		else		{			RMCopyAscii(g_bitmaps[i].path, path);			g_bitmaps[i].charwidth = 0;			*bmpindex = i;			status = LoadImage(pRua, i, &bmpsize);			// check if not background file and try loading again by			// resetting used bitmap buffers one at the time			if (status == RM_FATALOUTOFMEMORY)			{				status = FindFreeSpace(bmpsize, &index);				{					RMCopyAscii(g_bitmaps[index].path, path);					g_bitmaps[index].charwidth = 0;					*bmpindex = index;					status = LoadImage(pRua, index, &bmpsize);				}			}			RMLeaveCriticalSection(g_cs);			return status;		}	}	RMLeaveCriticalSection(g_cs);	// more than MAX_BITMAPS!!!!	return RM_ERROR;}// background is stored at index 0RMstatus LoadPageBackground(struct RUA *pRua, RMascii* path){	// check if we already have the bitmap data	//	printf("%s\n%s\n", path, g_bitmaps[0].path);	if (RMCompareAscii(g_bitmaps[0].path, path))	{		return RM_OK;	}	else	{		RMstatus status;		RMuint32 bmpsize = 0;		RMEnterCriticalSection(g_cs);		RMCopyAscii(g_bitmaps[0].path, path);		g_bitmaps[0].isBackground = TRUE;		printf("load background\n");		status = LoadImage(pRua, 0, &bmpsize);		UpdateCache(0);		RMLeaveCriticalSection(g_cs);		return status;	}	return RM_ERROR;}RMstatus SetTextPalette(struct RUA *pRua, RMuint32 foregroundcolor, RMuint32 backgroundcolor, RMbool transparentbkgnd){	struct GFXEngine_Palette_1BPP_type palette_param;	RMstatus status;	palette_param.Palette[0] = foregroundcolor;	palette_param.Palette[1] = (transparentbkgnd ? backgroundcolor & 0xffffffff : 0);	palette_param.SurfaceID = GFX_SURFACE_ID_Y;	if (CompareTextPalette(&palette_param))	{		//		printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> skipping TEXT palette\n");		return RM_OK;	}	//	printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> setting TEXT palette\n");	status = GFX1BPPPaletteProperty(pRua, &palette_param);	if (RMFAILED(status))		RMDBGLOG((GFXDBG, "Error sending command set palette\n"));	RMMemcpy(&g_lastpal, &palette_param, sizeof(palette_param));	g_last_palbpp = 1;	return status;}RMstatus SetTextColorFormat(struct RUA *pRua){	struct GFXEngine_ColorFormat_type format_param;	RMstatus status;	// color format	format_param.SurfaceID = GFX_SURFACE_ID_Y;	format_param.MainMode = EMhwlibColorMode_LUT_1BPP;	format_param.SubMode = EMhwlibColorFormat_32BPP;	status = GFXColorFormatProperty(pRua, &format_param);	if (RMFAILED(status))		RMDBGLOG((GFXDBG, "Error setting color format parameters\n"));	return status;}

⌨️ 快捷键说明

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