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

📄 g_keywrd.cpp

📁 在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己的开发
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			TSize innerSize = outerSize - TSize(8,8);
			currentDrawable->SetCursorPosition(origin+TPoint(4,4));
			flag&=0x7; // remove extra flags
			if ((flag==3) || (flag==4))
				{
				innerSize -= TSize(4,4);
				currentDrawable->SetCursorPosition(origin+TPoint(6,6));
				}
			gc.DrawRoundRect(TRect(currentDrawable->CursorPosition(),innerSize),cornerSize);
			currentDrawable->SetCursorPosition(origin);

			if ((flag==2) || (flag==4))
				currentDrawable->DrawGXBorderShadow(outerSize,corner,EFalse);
			else
				currentDrawable->DrawGXBorderShadow(outerSize,corner,ETrue);
			if ((flag==3) || (flag==4))
				{
				outerSize -= TSize(4,4);
				currentDrawable->SetCursorPosition(origin+TPoint(2,2));
				if (flag == 3)
					currentDrawable->DrawGXBorderShadow(outerSize,corner,ETrue);
				else
					currentDrawable->DrawGXBorderShadow(outerSize,corner,EFalse);
				}
			currentDrawable->SetCursorPosition(cursorPos);
			break;
			}
		case 2:
			{
			TGulBorder border((TGulBorder::TBorderType)flag);
			border.Draw(currentDrawable->DrawableGc(),rect);
			break;
			}
		default:
			User::Leave(KErrArgument);
		}
	coll.FlushIfOn();
    }

void OpCode::gXPrint(CStack& aStack, COplRuntime& aRuntime, CFrame* /*  */)
	{
	TInt flag = aStack.PopInt16();
	if (flag<0||flag>6)
		User::Leave(KErrGeneral);
	TPtrC buf = aStack.PopString();
	CDrawablesCollection& coll=aRuntime.DrawablesCollection();
	COplDrawable* currentDrawable = coll.CurrentDrawable();
	TOplDrawMode textMode=currentDrawable->CurrentTextMode();
	currentDrawable->SetTextMode(EModeReplace);
	TBool style = currentDrawable->CurrentStyle();
	TRect rect = currentDrawable->FontRect(buf);
	currentDrawable->SetGcModeInvalid();	// setting GC directly below
	CBitmapContext& gc = currentDrawable->DrawableGc();
	if (flag == 0)
		currentDrawable->Print(buf);
	else
		{
		TOplDrawMode currentTextMode = currentDrawable->CurrentTextMode();
		TOplDrawMode currentDrawMode = currentDrawable->CurrentDrawMode();
		if (style&KStyleInverse)
			{
			if ((flag==5) || (flag==6))
				{
				currentDrawable->SetInverseStyle(ETrue);
				currentDrawable->Print(buf);				// temporarily sets up inverse style
				currentDrawable->SetInverseStyle(EFalse);
				}
			else
				{
				currentDrawable->SetDrawMode(EModeGXPrint);
				currentDrawable->SetTextMode(EModeReplace);
				currentDrawable->Print(buf);
				currentDrawable->SetTextMode(currentTextMode);
				currentDrawable->SetDrawMode(currentDrawMode);
				}
			}
		else
			{
			if ((flag==5) || (flag==6))
				{
				currentDrawable->SetDrawMode(EModeGXPrint);
				currentDrawable->SetTextMode(EModeReplace);
				currentDrawable->Print(buf);
				currentDrawable->SetTextMode(currentTextMode);
				currentDrawable->SetDrawMode(currentDrawMode);
				}
			else
				{
				currentDrawable->SetInverseStyle(ETrue);  // temporarily sets up inverse style
				currentDrawable->Print(buf);
				currentDrawable->SetInverseStyle(EFalse);
				}
			}
		}
	if (((style&KStyleInverse)!=0)^(flag==0))
		gc.SetPenColor(currentDrawable->BackgroundColor());
	else
		gc.SetPenColor(currentDrawable->ForegroundColor());
	if ((flag==1) || (flag==2) || (flag==0))
		{
		rect.Grow(1,1);
		gc.SetBrushStyle(CGraphicsContext::ENullBrush);
		if (flag == 1)
			gc.DrawRect(rect);
		else
			gc.DrawRoundRect(rect,TSize(2,2));
		}
	else if ((flag==5) || (flag==6))
		{
		TInt fontDescent = currentDrawable->Font()->HeightInPixels()-currentDrawable->Font()->AscentInPixels();
		TPoint offset(0,fontDescent);
		if (flag==5)
			gc.DrawLine(currentDrawable->CursorPosition()+offset,rect.iBr);
		else
			{
			offset.SetXY(0,fontDescent-1);
			gc.DrawLine(currentDrawable->CursorPosition()+offset,TPoint(rect.iBr.iX,rect.iBr.iY-1));
			}
		}
	else if (flag==4)
		{
		TPoint topLeft = rect.iTl;
		TPoint offset(1,1);
		TPoint widthOffset(rect.Size().iWidth-1,0);
		TPoint heightOffset(0,rect.Size().iHeight-1);
		gc.SetPenColor(currentDrawable->BackgroundColor());
		gc.DrawLine(topLeft,topLeft-offset);
		gc.DrawLine(topLeft+widthOffset,topLeft+widthOffset-offset);
		gc.DrawLine(topLeft+heightOffset,topLeft+heightOffset+offset);
		gc.DrawLine(topLeft+widthOffset+heightOffset,topLeft+widthOffset+heightOffset-offset);
		}
	currentDrawable->SetTextMode(textMode);
	coll.FlushIfOn();
    }




/////////////////////////////////
////  FuncOpCode  functions  ////
/////////////////////////////////
LOCAL_C  void gCreateShare(TInt aGray,CStack& aStack, COplRuntime& aRuntime)
    {
	TInt visible = aStack.PopInt16();
	TRect winRect = COplDrawable::PopRect(aStack);
	TInt id = aRuntime.DrawablesCollection().NextAvailableId();
	COplWindow* newWindow = new(ELeave) COplWindow;
	CleanupStack::PushL(newWindow);
	newWindow->ConstructL(aRuntime,id,winRect.iTl,winRect.Size(),visible,aGray);
	aRuntime.DrawablesCollection().AddDrawableL(newWindow,id);
	CleanupStack::Pop();
	aStack.Push((TInt16)id);
    }

void FuncOpCode::gCreate(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{ // gCREATE(x%,y%,w%,h%,v%) 
    gCreateShare(0,aStack,aRuntime);
    }

void FuncOpCode::gCreateEnhanced(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{ // gCREATE(x%,y%,w%,h%,v%,m%)
	gCreateShare(aStack.PopInt16(),aStack,aRuntime);
    }
    

void FuncOpCode::gCreateBit(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	// gCreateBit(width%,height%[,mode%])    where mode% is the TDisplayMode gray setting
	//
	{
	TInt mode=0;		// 2-colour by default
	if (aRuntime.IP8()==3)
		mode=aStack.PopInt16();			// pop grey mode
	TSize size = COplDrawable::PopSize(aStack);
	TInt id = aRuntime.DrawablesCollection().NextAvailableId();
	COplBitmap* newBitmap = new(ELeave) COplBitmap;
	CleanupStack::PushL(newBitmap);
	newBitmap->ConstructL(size,COplDrawable::DisplayMode(mode));
	aRuntime.DrawablesCollection().AddDrawableL(newBitmap,id);
	CleanupStack::Pop();
	aStack.Push((TInt16)id);
	}

void FuncOpCode::gLoadBit(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	TInt numOfArgs = aRuntime.IP8();
	TInt write = 1; // default - file opened with read/write attribute
	TInt num = 0;  // only one bitmap - default
	if (numOfArgs > 2)
		num = aStack.PopInt16();
	if (numOfArgs > 1)
		write = aStack.PopInt16();
	TPtrC fileName = aStack.PopString();
	TParse parse;
	User::LeaveIfError(aRuntime.ConEnv()->FsSession().Parse(fileName,parse));
	TInt id = aRuntime.DrawablesCollection().NextAvailableId();
	COplBitmap* newBitmap = new(ELeave) COplBitmap;
	CleanupStack::PushL(newBitmap);
	newBitmap->ConstructL(&parse.FullName(),write,num);
	aRuntime.DrawablesCollection().AddDrawableL(newBitmap,id);
	CleanupStack::Pop();
	aStack.Push((TInt16)id);
	}

void FuncOpCode::gIdentity(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	COplDrawable* currentDrawable = aRuntime.DrawablesCollection().CurrentDrawable();
	aStack.Push((TInt16)aRuntime.DrawablesCollection().DrawableId(currentDrawable));
	}

void FuncOpCode::gX(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	aStack.Push((TInt16)aRuntime.DrawablesCollection().CurrentDrawable()->CursorPosition().iX);
	}

void FuncOpCode::gY(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	aStack.Push((TInt16)aRuntime.DrawablesCollection().CurrentDrawable()->CursorPosition().iY);
	}

void FuncOpCode::gWidth(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	aStack.Push((TInt16)aRuntime.DrawablesCollection().CurrentDrawable()->Size().iWidth);
	}

void FuncOpCode::gHeight(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	aStack.Push((TInt16)aRuntime.DrawablesCollection().CurrentDrawable()->Size().iHeight);
	}

void FuncOpCode::gOriginX(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	COplDrawable* currentDrawable = aRuntime.DrawablesCollection().CurrentDrawable();
	// Produce error if drawable is a bitmap...
	if (currentDrawable->DrawableFlag() == EIsOplBitmap)
		User::Leave(KOplErrInvalidWindow);
	aStack.Push((TInt16)((COplWindow*)currentDrawable)->Window().Position().iX);
	}

void FuncOpCode::gOriginY(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	COplDrawable* currentDrawable = aRuntime.DrawablesCollection().CurrentDrawable();
	// Produce error if drawable is a bitmap...
	if (currentDrawable->DrawableFlag() == EIsOplBitmap)
		User::Leave(KOplErrInvalidWindow);
	aStack.Push((TInt16)((COplWindow*)currentDrawable)->Window().Position().iY);
	}

void FuncOpCode::gRank(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	COplDrawable* currentDrawable = aRuntime.DrawablesCollection().CurrentDrawable();
	if (currentDrawable->DrawableFlag() == EIsOplBitmap)
		User::Leave(KOplErrInvalidWindow);
	aStack.Push((TInt16)(((COplWindow*)currentDrawable)->Window().OrdinalPosition()+1));
	}

void FuncOpCode::gPrintClip(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	TInt width = aStack.PopInt16();
	TPtrC buf = aStack.PopString();
	CDrawablesCollection& coll=aRuntime.DrawablesCollection();
	COplDrawable* currentDrawable = coll.CurrentDrawable();
	CFbsFont* currentFont = currentDrawable->Font();
	TInt numOfChars = currentFont->TextCount(buf,width); // the number of characters 
	buf.Set(buf.Ptr(),numOfChars);
//	currentDrawable->PrintAndMoveCursor(buf);
	currentDrawable->Print(buf);
	TPoint curPos=currentDrawable->CursorPosition();
	curPos.iX+=width;
	currentDrawable->SetCursorPosition(curPos);
	aStack.Push((TInt16)numOfChars);
	coll.FlushIfOn();
	}

void FuncOpCode::gTWidth(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	TPtrC text = aStack.PopString();
	TInt width = aRuntime.DrawablesCollection().CurrentDrawable()->Font()->TextWidthInPixels(text);
	aStack.Push((TInt16)width);
	}

void OpCode::gPrintBoxText(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	TInt numOfArgs = aRuntime.IP8();
	TInt margin = 0;
	TInt bottom = 0;
	TInt top = 0;
	CGraphicsContext::TTextAlign alignment = CGraphicsContext::ELeft;
	if (numOfArgs > 4)
		margin = aStack.PopInt16();
	if (numOfArgs > 3)
		bottom = aStack.PopInt16();
	if (numOfArgs > 2)
		top = aStack.PopInt16();
	if (numOfArgs > 1)
		{
		TInt al = aStack.PopInt16();
		if (al < 1)
			User::Leave(KOplErrInvalidArgs);
		switch(al)
			{
		case 1 :
			alignment = CGraphicsContext::ERight;
			break;
		case 3 :
			alignment = CGraphicsContext::ECenter;
			break;
			}
		}
	TInt width = aStack.PopInt16();
	TPtrC buf = aStack.PopString();
	TRect textRect, overallRect;
	CDrawablesCollection& coll=aRuntime.DrawablesCollection();
	COplDrawable* currentDrawable = coll.CurrentDrawable();
	TPoint cursorPos = currentDrawable->CursorPosition();
	CFbsFont* currentFont = currentDrawable->Font();
	TPoint topLeft(cursorPos.iX,cursorPos.iY-currentFont->AscentInPixels()-top);
	TSize size(width,currentFont->HeightInPixels()+top+bottom);
	overallRect.SetRect(topLeft,size);
	topLeft += TPoint(0,top);
	size -= TSize(0,(top+bottom));
	if (margin != NULL) 
		{
		if ((alignment == CGraphicsContext::ELeft) || 
		   ((alignment == CGraphicsContext::ECenter) && (margin > NULL)))
			topLeft.iX += margin;
		else if ((alignment == CGraphicsContext::ECenter) && (margin < NULL))
			margin=(-margin);
		size.iWidth -= margin;
		}
	textRect.SetRect(topLeft,size);
	CBitmapContext& gc = currentDrawable->DrawableGc();
	currentDrawable->SetGcModeInvalid();	// setting GC directly below
	TRgb foreground=currentDrawable->ForegroundColor();
	TRgb background=currentDrawable->BackgroundColor();
	if (currentDrawable->InverseStyle())
		{
		foreground=background;
		background=currentDrawable->ForegroundColor();
		}
	gc.SetPenColor(foreground);
	gc.SetBrushColor(background);
	gc.SetDrawMode(CGraphicsContext::EDrawModePEN);
	gc.SetPenStyle(CGraphicsContext::ENullPen);
	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
	gc.DrawRect(overallRect);
	gc.SetPenStyle(CGraphicsContext::ESolidPen);
	gc.SetBrushStyle(CGraphicsContext::ENullBrush);
	gc.DrawText(buf,textRect,currentDrawable->Font()->AscentInPixels(),alignment);
	coll.FlushIfOn();
	}
	
LOCAL_C CFbsBitmap* getBitmapIfOplDrawable(COplRuntime& aRuntime,CFbsBitmap* bitmap)
	{
	if (bitmap!=NULL && TInt(bitmap)<=KMaxDrawables)
		{
		COplDrawable* drawable=aRuntime.DrawablesCollection().DrawableL(TInt(bitmap));
		if (!drawable)
			User::Leave(KOplErrDrawNotOpen);
		if (drawable->DrawableFlag() == EIsOplBitmap)
			bitmap = &((COplBitmap*)drawable)->FbsBitmap();
		else
			User::Leave(KOplErrInvalidArgs);	// only bitmaps allowed
		}
	return bitmap;
	}


void OpCode::gButton(CStack& aStack, COplRuntime& aRuntime, CFrame* /*  */)
// gBUTTON text$,type%,width%,height%,state% [,bitmap&,mask&,layout%]
// Optionals pushed as last 3 args, IP8() is 3, 2, 1 if args passed or else 0
	{
	CFbsBitmap* bitmap=NULL;
	CFbsBitmap* mask=NULL;

⌨️ 快捷键说明

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