WONButtonPtr WinSkin::CalcCheckButton(const char *theBitmapName, WONButton *orig)
{
	WONButtonPtr aCheckbox = new WONButton;
	aCheckbox->SetPushOffsets(0,0);
	aCheckbox->SetHasCheck(true);
	aCheckbox->SetScaleImage(false);

	RawImagePtr aButtonMasterImage = GetRawImage("Buttons",theBitmapName);
	int aNumPictures = GetIntParam("Buttons","EnhancedMode")?5:4;
	if(aButtonMasterImage.get()==NULL)
		return orig;

	int aWidth = aButtonMasterImage->GetWidth()/aNumPictures;
	aCheckbox->SetTextPadding(aWidth + 4,2,2,2);

	int aColor = GetColor("Buttons","NormalColour");
	FontPtr aFont = GetFont("Buttons","NormalFont");
	if(aFont.get()==NULL)
		aFont = mWindow->GetWindowManager()->GetNamedFont("MSButton");
	if(aColor==-1)
		aColor = 0;

	CropImageFilterPtr aCrop = new CropImageFilter;
	aCrop->SetSize(aWidth,aButtonMasterImage->GetHeight());
	for(int i=0; i<4; i++)
	{
		aCrop->SetPos(i*aWidth,0);
		RawImagePtr aRawImage = aCrop->Filter(aButtonMasterImage);
		NativeImagePtr aNativeImage = aRawImage->GetNative(mWindow->GetDisplayContext());

		bool checked = i&1?true:false;
		int anIndex = i>=2?2:0;

		aCheckbox->SetButtonState(anIndex,aNativeImage,aColor,aFont,checked);
		if(anIndex==0)
		{
			RawImagePtr aRawImage2 = (RawImage*)aRawImage->Duplicate().get();
			TintImageFilterPtr aTint = new TintImageFilter(100,100,150);
			aTint->Filter(aRawImage);
			aNativeImage = aRawImage->GetNative(mWindow->GetDisplayContext());

			aCheckbox->SetButtonState(3,aNativeImage,aColor,aFont,checked);

			aTint = new TintImageFilter(100,150,100);
			aTint->Filter(aRawImage2);
			aNativeImage = aRawImage2->GetNative(mWindow->GetDisplayContext());

			aCheckbox->SetButtonState(1,aNativeImage,aColor,aFont,checked);
		}
	}
	return aCheckbox;
}
void
DrawingContext::draw_text(FontPtr font, const std::string& text,
                          const Vector& position, FontAlignment alignment, int layer, Color color)
{
  DrawingRequest* request = new(obst) DrawingRequest();

  request->target = target;
  request->type = TEXT;
  request->pos = transform.apply(position);
  request->layer = layer;
  request->drawing_effect = transform.drawing_effect;
  request->alpha = transform.alpha;
  request->color = color;

  TextRequest* textrequest = new(obst) TextRequest();
  textrequest->font = font.get();
  textrequest->text = text;
  textrequest->alignment = alignment;
  request->request_data = textrequest;

  requests->push_back(request);
}
WONButtonPtr WinSkin::CalcButton(const char *theSection, const char *theBitmapName, WONButton *orig)
{
	RawImagePtr aButtonMasterImage = GetRawImage(theSection,theBitmapName);
	if(aButtonMasterImage.get()==NULL)
		return orig;

	bool isTab = false;
	bool isHeader = false;

	if(stricmp(theSection,"HeaderBar")==0)
	{
		isHeader = true;
		mSkin->mListCtrl->SetHeaderHeight(aButtonMasterImage->GetHeight());
	}
	else if(stricmp(theSection,"Tabs")==0)
	{
		mSkin->mTabCtrl->SetTabBarHeight(aButtonMasterImage->GetHeight());
		isTab = true;
	}

	WONButtonPtr aButton;
	if(isHeader)
		aButton = new WONHeaderButton;
	else
		aButton = new WONButton;

	int leftWidth = GetIntParam(theSection,"LeftWidth");
	int topHeight = GetIntParam(theSection,"TopHeight");
	int rightWidth = GetIntParam(theSection,"RightWidth");
	int bottomHeight = GetIntParam(theSection,"BottomHeight");
	int tile = GetIntParam(theSection,"Tile");
	bool mouseOver = GetIntParam(theSection,"MouseOver")?true:false;
	aButton->SetButtonFlags(ButtonFlag_InvalidateOnMouseOver,mouseOver);
//	aButton->SetTextPaddingAtLeast(leftWidth+2,topHeight+2,rightWidth+2,bottomHeight+2);

	int aNumFrames = GetIntParam(theSection,"FrameCount");
	if(aNumFrames<5)
		aNumFrames = 5;

	int aWidth = aButtonMasterImage->GetWidth()/aNumFrames;

	const char *colornames[] = { "NormalColour", "PressedColour", "DisabledColour", "FocusColour", "DefaultColour" };
	const char *fontnames[] = { "NormalFont", "PressedFont", "DisabledFont", "FocusFont", "DefaultFont" };

	CropImageFilterPtr aCrop = new CropImageFilter;
	aCrop->SetSize(aWidth,aButtonMasterImage->GetHeight());
	for(int i=0; i<5; i++)
	{
		StretchImagePtr aStretchImage = NULL;
		if(i<5)
		{
			aCrop->SetPos(i*aWidth,0);
			RawImagePtr aRawImage = aCrop->Filter(aButtonMasterImage);

			aStretchImage = new StretchImage(aRawImage,leftWidth,topHeight,rightWidth,bottomHeight);
			switch(tile)
			{
				case 0: aStretchImage->SetTile(false,false); break;
				case 1: aStretchImage->SetTile(true,true); break;
				case 2: aStretchImage->SetTile(true,false); break;
				case 3: aStretchImage->SetTile(false,true); break;
			}
		}

		int aColor = GetColor(theSection,colornames[i]);
		FontPtr aFont = GetFont(theSection,fontnames[i]);
		if(i==0)
		{
			if(aFont.get()==NULL)
				aFont = mWindow->GetWindowManager()->GetNamedFont("MSButton");
			if(aColor==-1)
				aColor = 0;
		}

		if(i==1 && isTab)
		{
			aButton->SetHasCheck(true);
			aButton->SetButtonState(0,aStretchImage,aColor,aFont,true);
		}
		else
			aButton->SetButtonState(i,aStretchImage,aColor,aFont);
	}

	aButton->SetTransparent(aButtonMasterImage->HasTransparency());
	return aButton;
}