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

📄 template.c

📁 这是一个嵌入ARM里的一个游戏源代码。是用ARM_SDT2.51软件开发的感兴趣的人可以下载看看。
💻 C
📖 第 1 页 / 共 2 页
字号:
      int word_pos=0;
      for(i=0,j=0;ch[word_pos]!=0;i++){
      	if(((i+1)*OSFontSize[fnt]+prect->left)>prect->right){
      		i=0;
      		j++;
      		if(((j+1)*OSFontSize[fnt]+prect->top)>prect->bottom){
      			Uart_Printf("Error: No enough space to textout!");
      			return;
      			}
      		}
      	x=(i*OSFontSize[fnt]+prect->left);
      	y=(j*OSFontSize[fnt]+prect->top);
      	CharactorOut(pdc, &x, &y, ch[word_pos], bunicode, fnt);
      	word_pos++;
      	}
}

//////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////  控件函数   //////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
//创建菜单控件
PListCtrl CreateMenu(U32 CtrlID, structRECT* prect, int MaxNum, U32 FontSize, U32 style, PWnd parentWnd)
{
	PListCtrl pListCtrl;
	int i;
	INT8U err;
	
	pListCtrl=(PListCtrl)CreateOSCtrl(CtrlID,CTRLTYPE_MENU,prect, FontSize,style,parentWnd);

	pListCtrl->ListMaxNum=MaxNum;
	pListCtrl->CurrentSel=0;
	pListCtrl->pListText=OSMemGet(pCtrlMem,&err);
	for(i=0;i<MaxNum;i++){
		pListCtrl->pListText[i]=(U16*)OSMemGet(pCtrlMem,&err);//????????????
	}
	pListCtrl->CurrentHead=0;
	pListCtrl->ListNum=0;
	pListCtrl->ListShowNum=MENU_SHOW_NUM;
	return pListCtrl;
}

void DrawMenu(PListCtrl pListCtrl)
{
	structRECT rect;
	PDC pdc;

	pdc=GetCtrlParentDC((POS_Ctrl)pListCtrl);
	if(!pdc)
		return;

	//清空列表框的显示区域
	FillRect2(pdc,&pListCtrl->ListCtrlRect,GRAPH_MODE_NORMAL,COLOR_WHITE);

	CopyRect(&rect, &pListCtrl->ListCtrlRect);

       switch(pListCtrl->style){
	case CTRL_STYLE_DBFRAME:
		Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0));
		InflateRect(&rect, -1,-1);
		Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0));
		InflateRect(&rect, -1,-1);
		Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(0,0,0));
		InflateRect(&rect, -1,-1);
		Draw3DRect2(pdc, &rect, RGB(255,255,255), RGB(255,255,255));
		InflateRect(&rect, -1,-1);
		Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(192,192,192));
		InflateRect(&rect, -1,-1);
		Draw3DRect2(pdc, &rect, RGB(0,0,0), RGB(192,192,192));
		break;
	case CTRL_STYLE_FRAME:
		DrawRectFrame2(pdc,&rect);
		break;
	case CTRL_STYLE_3DUPFRAME:
		Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0));
		InflateRect(&rect, -1,-1);
		Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0));
		InflateRect(&rect, -1,-1);
		Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(0,0,0));
		break;
	case CTRL_STYLE_3DDOWNFRAME:
		Draw3DRect2(pdc, &rect, RGB(255,255,255), RGB(255,255,255));
		InflateRect(&rect, -1,-1);
		Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(192,192,192));
		InflateRect(&rect, -1,-1);
		Draw3DRect2(pdc, &rect, RGB(0,0,0), RGB(192,192,192));
		break;
	case CTRL_STYLE_NOFRAME:
		break;
	}
	
	pListCtrl->ClientRect.left=rect.left;
	pListCtrl->ClientRect.top=rect.top;
	pListCtrl->ClientRect.right=rect.right;
	pListCtrl->ClientRect.bottom=rect.bottom;
	
	MenuDrawClient(pListCtrl, pdc); 
	ReleaseCtrlParentDC((POS_Ctrl)pListCtrl);
}

//绘制菜单的客户区 
void MenuDrawClient(PListCtrl pListCtrl, PDC pdc)   //??????????????????????????????
{
	structRECT textRect;
	int i;
 	for(i=0;i<pListCtrl->ListShowNum;i++){
 		SetRect(&textRect, 
			pListCtrl->ClientRect.left+i*(OSFontSize[pListCtrl->FontSize]*MENU_NAME_NUM+CLEARANCEmenu), //+i*OSFontSize[pListCtrl->FontSize], 
			pListCtrl->ClientRect.top,
			pListCtrl->ClientRect.right+(i+1)*(OSFontSize[pListCtrl->FontSize]*MENU_NAME_NUM+CLEARANCEmenu), 
			pListCtrl->ClientRect.top+OSFontSize[pListCtrl->FontSize]+CLEARANCEmenu);
 		
		if((i+pListCtrl->CurrentHead)>=pListCtrl->ListNum)
			break;
		if((i+pListCtrl->CurrentHead)==pListCtrl->CurrentSel){
			TextOutRect(pdc, &textRect, pListCtrl->pListText[i+pListCtrl->CurrentHead],
				TRUE, pListCtrl->FontSize|FONT_BLACKBK,TEXTOUT_MID_Y);
			}
		else{
			TextOutRect(pdc,&textRect, pListCtrl->pListText[i+pListCtrl->CurrentHead],
				TRUE, pListCtrl->FontSize,TEXTOUT_MID_Y);
			}
		}
}


//改变菜单参量,然后发送消息,由消息所调用的函数根据新的参量重新绘制菜单.
/*void MenuSelMove(PListCtrl pListCtrl, int moveNum, U8 Redraw)	//列表框高亮度条移,正数下移,负数上移
{
	POSMSG pMsg;
	int oldsel=pListCtrl->CurrentSel;

	if(moveNum<0){	//向上滚动
		if(pListCtrl->CurrentSel+moveNum>=pListCtrl->CurrentHead)
			pListCtrl->CurrentSel+=moveNum;
		else{
			pListCtrl->CurrentSel=MAX(pListCtrl->CurrentSel+moveNum,0);
			pListCtrl->CurrentHead=pListCtrl->CurrentSel;
		}
	}
	else{ //向下滚动
		if(pListCtrl->CurrentSel+moveNum<pListCtrl->CurrentHead+pListCtrl->ListShowNum 
			&& pListCtrl->CurrentSel+moveNum<(pListCtrl->ListNum-1))
			pListCtrl->CurrentSel+=moveNum;
		else{
			pListCtrl->CurrentSel=MIN(pListCtrl->CurrentSel+moveNum,pListCtrl->ListNum-1);
			pListCtrl->CurrentHead=MAX(pListCtrl->CurrentSel-pListCtrl->ListShowNum+1,0);
		}
	}
	if(oldsel==pListCtrl->CurrentSel)
		return;
	if(Redraw)
		DrawMenu(pListCtrl);
	//发送列表框选择改变消息
	pMsg=OSCreateMessage((POS_Ctrl)pListCtrl->parentWnd,OSM_MENU_SELCHANGE, pListCtrl->CtrlID, pListCtrl->CurrentSel);
	SendMessage(pMsg);
}


*/
//以下的一组函数用于实现 ListCtrl2 控件的创建  绘制和消息响应.
//创建: 使用 CreateListCtrl() + CreateListCtrl2Patch() 

void CreateListCtrl2Patch(PListCtrl2 pListCtrl, int Max_Word_Num, u8 IsDraw3DRect)
{
 pListCtrl->Max_Word_Num=Max_Word_Num;
      pListCtrl->IsDraw3DRect=IsDraw3DRect;
}


void DrawListCtrl2(PListCtrl2 pListCtrl)
{ 
       structPOINT Start_Point;
       structRECT textRect;
       PDC pdc;
       int i;

       Start_Point.x=pListCtrl->ListCtrlRect.left;
       Start_Point.y=pListCtrl->ListCtrlRect.top;
       pdc=GetCtrlParentDC((POS_Ctrl) pListCtrl);
       if(!pdc)
       	return;
       for(i=0;i<pListCtrl->ListMaxNum;i++){
       	SetRect(&textRect,
			Start_Point.x,
			Start_Point.y+i*(OSFontSize[FONTSIZE_MIDDLE]+CLEARANCEy),  // word_num
			Start_Point.x+OSFontSize[FONTSIZE_MIDDLE]*5,
			Start_Point.y+(i+1)*(OSFontSize[FONTSIZE_MIDDLE]+CLEARANCEy));
       	FillRect2( pdc, &textRect, GRAPH_MODE_NORMAL, COLOR_WHITE);
		if((i+pListCtrl->CurrentHead)>=pListCtrl->ListMaxNum)
			break;
       	if((i+pListCtrl->CurrentHead)==pListCtrl->CurrentSel){
       		TextOut( pdc,textRect.left, textRect.top, pListCtrl->pListText[i], TRUE, FONTSIZE_MIDDLE|FONT_BLACKBK);
       		if(pListCtrl->IsDraw3DRect){
       			Draw3DUpRect( pdc, textRect.left, textRect.top,pListCtrl->Max_Word_Num, FONTSIZE_MIDDLE);
       			}			
			}
		else{
			TextOut( pdc,textRect.left, textRect.top, pListCtrl->pListText[i], TRUE, FONTSIZE_MIDDLE);
			if(pListCtrl->IsDraw3DRect){
       			Draw3DUpRect( pdc, textRect.left, textRect.top,pListCtrl->Max_Word_Num, FONTSIZE_MIDDLE);
       			}
			}
       	}
	ReleaseCtrlParentDC((POS_Ctrl) pListCtrl);
} 

void ListCtrl2SelMove(PListCtrl2 pListCtrl, int moveNum, U8 Redraw)	//列表框高亮度条移,正数下移,负数上移
{
	POSMSG pMsg;
	int oldsel=pListCtrl->CurrentSel;

	if(moveNum<0){	//向上滚动
		if(pListCtrl->CurrentSel+moveNum>=pListCtrl->CurrentHead)
			pListCtrl->CurrentSel+=moveNum;
		else{
			pListCtrl->CurrentSel=MAX(pListCtrl->CurrentSel+moveNum,0);
			pListCtrl->CurrentHead=pListCtrl->CurrentSel;
		}
	}
	else{ //向下滚动
		if(pListCtrl->CurrentSel+moveNum<pListCtrl->CurrentHead+pListCtrl->ListMaxNum)
			pListCtrl->CurrentSel+=moveNum;
		else{
			pListCtrl->CurrentSel=MIN(pListCtrl->CurrentSel+moveNum,pListCtrl->ListMaxNum-1);
			pListCtrl->CurrentHead=MAX(pListCtrl->CurrentSel-pListCtrl->ListMaxNum+1,0);
		}
	}
	if(oldsel==pListCtrl->CurrentSel)
		return;
	if(Redraw)
		DrawListCtrl2(pListCtrl);
	//发送列表框选择改变消息
	//pMsg=OSCreateMessage((POS_Ctrl)pListCtrl->parentWnd,OSM_LISTCTRL2_SELCHANGE, pListCtrl->CtrlID, pListCtrl->CurrentSel);
	//SendMessage(pMsg);
}



⌨️ 快捷键说明

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