예제 #1
0
void VGraphicPath::SetPosBy(GReal inHoriz, GReal inVert)
{
#if !GRAPHIC_MIXED_GDIPLUS_D2D
	if (!VWinD2DGraphicContext::IsAvailable())
	{
#endif
		Gdiplus::Matrix matrix;
		matrix.Translate(inHoriz, inVert);
		fPath->Transform(&matrix);
#if !GRAPHIC_MIXED_GDIPLUS_D2D
	}
#endif

#if ENABLE_D2D
	if (VWinD2DGraphicContext::IsAvailable() && fPathD2D)
	{
		End();
		
		VAffineTransform mat;
		mat.SetTranslation( inHoriz, inVert);
		D2D1_MATRIX_3X2_F matNative;
		mat.ToNativeMatrix((D2D_MATRIX_REF)&matNative);

		ID2D1Geometry *sourcePath = fPathD2D;
		
		ID2D1TransformedGeometry *thisPath = NULL;
		VWinD2DGraphicContext::GetMutexFactory().Lock();
		bool ok = SUCCEEDED(VWinD2DGraphicContext::GetFactory()->CreateTransformedGeometry( sourcePath, &matNative, &thisPath));
		VWinD2DGraphicContext::GetMutexFactory().Unlock();
		xbox_assert(ok);
		if (ok)
		{
			fPathD2D = thisPath;
			sourcePath->Release();
		}
		else 
			return;
	}
#endif

	fPolygon.SetPosBy(inHoriz, inVert);

	if (fComputeBoundsAccurate)
	{
		VPoint translate( (SmallReal)inHoriz, (SmallReal)inVert);

		if (fPathMin != GP_BOUNDS_MIN_DEFAULT)
			fPathMin += translate;
		if (fPathMax != GP_BOUNDS_MAX_DEFAULT)
			fPathMax += translate;
	}
	_ComputeBounds();

	if (fCreateStorageForCrispEdges)
	{
		fDrawCmds.push_back( VGraphicPathDrawCmd( GPDCT_SET_POS_BY, inHoriz, inVert));
		fCurTransform.Translate( inHoriz, inVert, VAffineTransform::MatrixOrderAppend);
	}
}
예제 #2
0
void VRegion::Inset (GReal inHoriz, GReal inVert)
{
	if (fRegion == NULL)
		SetEmpty();
		
#if !USE_GDIPLUS

	GReal	dstRight = fBounds.GetRight() + inHoriz;
	GReal	dstLeft = fBounds.GetLeft() + inHoriz;
	GReal	dstTop = fBounds.GetTop() + inVert;
	GReal	dstBottom = fBounds.GetBottom() + inVert;
	
#if DEBUG_GDI_LIMITS
	assert(Abs(dstRight) <= kMAX_GDI_RGN_COORD);
	assert(Abs(dstLeft) <= kMIN_GDI_RGN_COORD);
	assert(Abs(dstTop) <= kMIN_GDI_RGN_COORD);
	assert(Abs(dstBottom) <= kMAX_GDI_RGN_COORD);
#endif
	
	// Make sure the region isn't too big for Win32
	if (dstRight > kMAX_GDI_RGN_COORD || dstLeft < kMIN_GDI_RGN_COORD
		|| dstBottom > kMAX_GDI_RGN_COORD || dstTop < kMIN_GDI_RGN_COORD) return;
		
	sLONG	rgnSize = ::GetRegionData(fRegion, sizeof(RGNDATA), 0);
	VHandle	vHandle = VMemory::NewHandle(rgnSize);
	VPtr	vPtr = VMemory::LockHandle(vHandle);
		
	// Create a translate matrix
	rgnSize = ::GetRegionData(fRegion, rgnSize, (RGNDATA*)vPtr);
	
	XFORM xForm;
	xForm.eM11 = inHoriz; 
    xForm.eM12 = 0.0;   
    xForm.eM21 = 0.0;   
    xForm.eM22 = inVert;
    xForm.eDx = 0.0;  
    xForm.eDy = 0.0;
    
	HRGN	tempRgn = ::ExtCreateRegion(&xForm, rgnSize, (RGNDATA*)vPtr);
	if (tempRgn != NULL)
	{
		_Release();
		fRegion = tempRgn;
	}
	
	VMemory::DisposeHandle(vHandle);
	
	_AdjustOrigin();
#else
	Gdiplus::Matrix mat;
	
	mat.Translate(inHoriz,inVert);
	mat.Scale((fBounds.GetWidth()-inHoriz)/(GReal)fBounds.GetWidth(),(fBounds.GetHeight()-inVert)/(GReal)fBounds.GetHeight());
	
	fRegion->Transform(&mat);
#endif

	_ComputeBounds();
}
예제 #3
0
D2D1_MATRIX_3X2_F CanvasD2D::GetCurrentTransform()
{
	D2D1_MATRIX_3X2_F d2dMatrix;
	Gdiplus::Matrix gdipMatrix;
	m_GdipGraphics->GetTransform(&gdipMatrix);
	gdipMatrix.GetElements((Gdiplus::REAL*)&d2dMatrix);
	return d2dMatrix;
}
예제 #4
0
void VRegion::SetSizeBy (GReal inHoriz, GReal inVert)
{
	if (fRegion == NULL)
		SetEmpty();
		
#if USE_GDIPLUS
	Gdiplus::Matrix mat;
	mat.Scale((fBounds.GetWidth()+inHoriz)/(GReal)fBounds.GetWidth(),(fBounds.GetHeight()+inVert)/(GReal)fBounds.GetHeight());
	fRegion->Transform(&mat);
#else

	GReal	dstWidth = fBounds.GetWidth() + inHoriz;
	GReal	dstHeight = fBounds.GetHeight() + inVert;
	
#if DEBUG_GDI_LIMITS
	assert(dstWidth <= kMAX_GDI_RGN_COORD);
	assert(dstHeight <= kMAX_GDI_RGN_COORD);
#endif
	
	// Make sure the region isn't too big for Win32
	if (dstWidth > kMAX_GDI_RGN_COORD || dstHeight > kMAX_GDI_RGN_COORD) return;
		
	sLONG	rgnSize = ::GetRegionData(fRegion, sizeof(RGNDATA), 0);
	VHandle	vHandle = VMemory::NewHandle(rgnSize);
	VPtr	vPtr = VMemory::LockHandle(vHandle);
		
	rgnSize = ::GetRegionData(fRegion, rgnSize, (RGNDATA*)vPtr);
	
	// Create a scale matrix
	XFORM	xForm;
	xForm.eM11 = dstWidth / fBounds.GetWidth(); 
    xForm.eM12 = 0.0;   
    xForm.eM21 = 0.0;   
    xForm.eM22 = dstHeight / fBounds.GetHeight();
    xForm.eDx = 0.0;  
    xForm.eDy = 0.0;

	HRGN	tempRgn = ::ExtCreateRegion(&xForm, rgnSize, (RGNDATA*)vPtr);
	if (tempRgn != NULL)
	{
		_Release();
		fRegion = tempRgn;
		
		// Region scaling move origin, so reset it
		RECT	rgnRect = { 0, 0, 0, 0 };
		::GetRgnBox(fRegion, &rgnRect);
		::OffsetRgn(fRegion, -rgnRect.left, -rgnRect.top);
		fOffset.SetPosBy( rgnRect.left, rgnRect.top);
	}
	
	VMemory::DisposeHandle(vHandle);
	
#endif

	_ComputeBounds();
}
예제 #5
0
void AirSpeed_Indicator::PT::DrawPointer(const PREADING pRading, Gdiplus::Graphics *pg)
{
	Gdiplus::GraphicsPath path;
	path.AddPath(&m_PT, FALSE);
	Gdiplus::Matrix m;
	float a = GetAngle(pRading);
	m.RotateAt(a, Gdiplus::PointF(m_ptRotatePoint.X, m_ptRotatePoint.Y));
	path.Transform(&m);
	Gdiplus::SolidBrush sb(Gdiplus::Color::White);
	pg->FillPath(&sb, &path);
}
예제 #6
0
/* 비트맵 이미지 돌리기 */
void OrGate::Rotate(CClientDC* dc) {
	//이미지 돌려주고 나서 돌리기 전 그 영역의 이미지는 없애고 싶은데...
	Graphics ScreenG(dc->GetSafeHdc());
	Bitmap* pBitmapAND;
	pBitmapAND = Bitmap::FromResource(AfxGetInstanceHandle(), (WCHAR*)MAKEINTRESOURCE(IDB_OR));
	Gdiplus::Matrix matrix;
	matrix.RotateAt(90, Gdiplus::PointF((float)(pBitmapAND->GetWidth() / 2), (float)(pBitmapAND->GetHeight() / 2)));
	ScreenG.SetTransform(&matrix);
	ScreenG.DrawImage(pBitmapAND, 0, 0);

	delete pBitmapAND;
}
예제 #7
0
void CanvasD2D::UpdateTargetTransform()
{
	Gdiplus::Matrix gdipMatrix;
	m_GdipGraphics->GetTransform(&gdipMatrix);

	D2D1_MATRIX_3X2_F d2dMatrix;
	gdipMatrix.GetElements((Gdiplus::REAL*)&d2dMatrix);

	m_Target->SetTransform(d2dMatrix);
	m_CanUseAxisAlignClip =
		d2dMatrix._12 == 0.0f && d2dMatrix._21 == 0.0f &&
		d2dMatrix._31 == 0.0f && d2dMatrix._32 == 0.0f;
}
예제 #8
0
    HDC CanvasGdiplus::BeginPlatformPaint()
    {
        DCHECK(mem_graphics_.get());

        Gdiplus::Matrix matrix;
        mem_graphics_->GetTransform(&matrix);
        Gdiplus::REAL elem[6];
        matrix.GetElements(elem);

        Gdiplus::Region region;
        mem_graphics_->GetClip(&region);
        HRGN hrgn = region.GetHRGN(mem_graphics_.get());

        HDC hdc = mem_graphics_->GetHDC();
        InitializeDC(hdc);

        XFORM xf = { elem[0], elem[1], elem[2], elem[3], elem[4], elem[5] };
        SetWorldTransform(hdc, &xf);

        SelectClipRgn(hdc, hrgn);
        DeleteObject(hrgn);

        return hdc;
    }
예제 #9
0
HRESULT ParaEngine::CCCSFaceLoader::ComposeWithGDIPlus()
{
	HRESULT hr = S_OK;
#ifdef USE_DIRECTX_RENDERER
	// DO the texture composition here
	CGDIEngine* pEngine = CAsyncLoader::GetSingleton().GetGDIEngine();
	if (pEngine == NULL)
		return E_FAIL;
	pEngine->SetRenderTarget(pEngine->CreateGetRenderTargetBySize(CCharCustomizeSysSetting::FaceTexSize));
	pEngine->Begin();

	for (int i = 0; i<CFS_TOTAL_NUM; ++i)
	{
		const CharRegionCoords &coords = CCharCustomizeSysSetting::regions[CR_FACE_BASE + i];
		const FaceTextureComponent& component = m_layers[i];

		// load the component texture
		if (component.name.empty())
			continue;
		string componentfilename = component.name;

		AssetFileEntry* pEntry = CAssetManifest::GetSingleton().GetFile(componentfilename);
		if (pEntry)
			componentfilename = pEntry->GetLocalFileName();

		// compute the transform matrix
		Gdiplus::Matrix transformMatrix;
		// scale around the center
		float fScale = component.GetScaling();
		if (fabs(fScale)>0.01f)
		{
			transformMatrix.Scale(fScale + 1.f, fScale + 1.f);
		}

		// rotate around the center
		float fRotation = component.GetRotation();
		if (fabs(fRotation) > 0.01f)
		{
			transformMatrix.Rotate(fRotation);
		}

		// translation
		int x, y;
		component.GetPosition(&x, &y);
		transformMatrix.Translate(coords.xpos + (float)x, coords.ypos + (float)y);
		pEngine->SetTransform(&transformMatrix);

		Color color = component.GetColor();
		pEngine->DrawImage(pEngine->LoadTexture(componentfilename, component.name), (float)(-coords.xsize / 2), (float)(-coords.ysize / 2), (float)coords.xsize, (float)coords.ysize, color);

		// for eye and eye bow, there should be a mirrored image, around the center of the render target
		if (i == CFS_EYE || i == CFS_EYEBROW)
		{
			Gdiplus::Matrix reflectMat(-1.f, 0.f, 0.f, 1.f, CCharCustomizeSysSetting::FaceTexSize - (coords.xpos + (float)x) * 2, 0.f);
			transformMatrix.Multiply(&reflectMat);
			pEngine->SetTransform(&transformMatrix);
			pEngine->DrawImage(pEngine->LoadTexture(componentfilename, component.name), (float)(-coords.xsize / 2), (float)(-coords.ysize / 2), (float)coords.xsize, (float)coords.ysize);
		}
	}
	CParaFile::CreateDirectory(m_sFileName.c_str());
	hr = (pEngine->SaveRenderTarget(m_sFileName, CCharCustomizeSysSetting::FaceTexSize, CCharCustomizeSysSetting::FaceTexSize, false, 0)) ? S_OK : E_FAIL;
	pEngine->End();
#endif
	return hr;
}
예제 #10
0
void CSkinUnitODL::DrawImage(Gdiplus::Graphics& gcDrawer, Gdiplus::GraphicsPath& gcPath, Gdiplus::PointF& ptOffset, Gdiplus::REAL fScale)
{
	if (m_imgSkin)
	{
		if (m_nWrapMode>=4)
		{
			//居中模式
			Gdiplus::RectF rtArea;
			gcPath.GetBounds(&rtArea);
			Gdiplus::GraphicsPath gcDrawPath;
			//图片中间X:(width-imagewidth )/2 + left;
			//Y: (height - imageheight)/2 +top;

			Gdiplus::REAL fX0 = (rtArea.Width - m_fSkinWidth-m_nGroutX) /2.0f + rtArea.X;
			Gdiplus::REAL fY0 = (rtArea.Height - m_fSkinHeight-m_nGroutY) /2.0f + rtArea.Y;
			Gdiplus::REAL fX1 = m_fSkinWidth + m_nGroutX+ fX0;
			Gdiplus::REAL fY1 = m_fSkinHeight +m_nGroutY+ fY0;
			std::vector<Gdiplus::PointF> arrPt;
			arrPt.emplace_back(fX0, fY0);
			arrPt.emplace_back(fX1, fY0);
			arrPt.emplace_back(fX1, fY1);
			arrPt.emplace_back(fX0, fY1);
			Gdiplus::Matrix mx;
			Gdiplus::PointF ptCenter=Gdiplus::PointF((fX1+fX0)/2.0f, (fY1+fY0)/2.0f);
			mx.RotateAt(m_fRotate, ptCenter);
			mx.TransformPoints(arrPt.data(), arrPt.size());
			gcDrawPath.AddPolygon(arrPt.data(),arrPt.size());
			//如果图片的path大于当前区域Path,则居中操作在区域内
			{
				BRepBuilderAPI_MakePolygon ply1;
				for (auto& ptPos:arrPt)
				{
					ply1.Add(gp_Pnt(ptPos.X, 0.0f, ptPos.Y));
				}
				ply1.Close();
				TopoDS_Face face1 = BRepBuilderAPI_MakeFace(ply1.Wire()).Face();
				std::vector<Gdiplus::PointF> arrPic;
				arrPic.resize(gcDrawPath.GetPointCount());
				gcPath.GetPathPoints(arrPic.data(), arrPic.size());

				BRepBuilderAPI_MakePolygon ply2;
				for (auto& ptPos:arrPic)
				{
					ply2.Add(gp_Pnt(ptPos.X, 0.0f, ptPos.Y));
				}
				ply2.Close();
				TopoDS_Face face2 = BRepBuilderAPI_MakeFace(ply2.Wire()).Face();

				BRepAlgoAPI_Common bc(face1, face2);
				auto face = bc.Shape();
				TopExp_Explorer expWire(face, TopAbs_WIRE);
				std::vector<Gdiplus::PointF> arrDraw;
				for ( BRepTools_WireExplorer expVertex(TopoDS::Wire(expWire.Current())); expVertex.More(); expVertex.Next() )
				{
					auto pnt = BRep_Tool::Pnt(expVertex.CurrentVertex());
					arrDraw.emplace_back(static_cast<Gdiplus::REAL>(pnt.X()), static_cast<Gdiplus::REAL>(pnt.Z()));
				}
				gcDrawPath.Reset();
				gcDrawPath.AddPolygon(arrDraw.data(), arrDraw.size());
			}

			Gdiplus::WrapMode wmMode=(Gdiplus::WrapMode)m_nWrapMode;
			if (std::fabs(m_fRotate)<0.001f)
			{
				Gdiplus::TextureBrush brush(m_imgSkin, wmMode);
				mx.Translate(fX0, fY0);
				brush.SetTransform(&mx);
				gcDrawer.FillPath(&brush, &gcDrawPath);
			}
			else
			{
				Gdiplus::TextureBrush brush(m_imgSkin, wmMode);
				mx.Translate(fX0, fY0);
				brush.SetTransform(&mx);
				gcDrawer.FillPath(&brush, &gcDrawPath);
			}
		}
		else
		{
			//铺满模式
			Gdiplus::WrapMode wmMode=(Gdiplus::WrapMode)m_nWrapMode;
			if (std::fabs(m_fRotate)<0.001f)
			{
				Gdiplus::TextureBrush brush(m_imgSkin, wmMode);
				brush.TranslateTransform(ptOffset.X, ptOffset.Y);
				gcDrawer.FillPath(&brush, &gcPath);
			}
			else
			{
				Gdiplus::TextureBrush brush(m_imgSkin, wmMode);
				brush.TranslateTransform(ptOffset.X, ptOffset.Y);
				brush.RotateTransform(m_fRotate);
				gcDrawer.FillPath(&brush, &gcPath);
			}
		}
		
	}
}
예제 #11
0
void __fastcall TTiffBook::FlipCurPage(int n) {
//-------------------------------------------------------------------------------
//               Переворачивает текущую страницу вверх ногами                   |
// n - номер страницы, который надо нанести. <= 0 - только убрать ном стр       |
//-------------------------------------------------------------------------------
    stop++;
    Gdiplus::Graphics *g32;
    TTiffImage *img = GetImagePage(GetPage());
    Gdiplus::Bitmap *fbm = img->fbm;
    Gdiplus::Rect r;
    int w = fbm->GetWidth(), h = fbm->GetHeight();

    // g = new Gdiplus::Graphics(fbm);

    Gdiplus::Bitmap *b32 = new Gdiplus::Bitmap(w, h, PixelFormat32bppARGB);
    g32 = new Gdiplus::Graphics(b32);

    Gdiplus::Matrix matr;
    matr.Rotate(180.0f);                // поворачиваем его на 270 градусов
    g32->SetTransform(&matr);

    //r.X = 0;
    //r.Y = 0;
    //r.Width = w;
    //r.Height = h;

    //r.X = -SaveBitmapH;
    //r.Y = -30;
    //r.Width = SaveBitmapH - 30;
    //r.Height = SaveBitmapW - 30;

    r.X = -w;
    r.Y = -h;
    r.Width = w;
    r.Height = h;

    sres = g32->DrawImage(fbm, r, 0, 0, w, h, Gdiplus::UnitPixel, 0, 0, 0);

    matr.Reset();
    g32->SetTransform(&matr);

    // Удаляем черные полосы сверху и снизу
    Gdiplus::Pen whitePen2(Gdiplus::Color(255, 255, 255, 255), 2);
    g32->DrawLine(&whitePen2, 0, 0, w, 0);
    g32->DrawLine(&whitePen2, 0, h-1, w, h-1);

    // Удаляем старый номер страницы - он теперь внизу
    // Gdiplus::Pen whitePen40(Gdiplus::Color(255, 0, 0, 0), 45);   // ??? Пока черный - для отладки!
    Gdiplus::Pen whitePen40(Gdiplus::Color(255, 255, 255, 255), 45);
    g32->DrawLine(&whitePen40, 0, h - 50, 200, h - 50);

    if (n > 0) {                        // Здесь выводим номер страницы
        AnsiString snum;
        wchar_t wnum[20];
        snum.printf("%d", n);
        snum.WideChar(wnum, 20);
        Gdiplus::Font myFont(L"Arial", 40, Gdiplus::FontStyleBold);
        Gdiplus::PointF origin(w - 160, 20.0f);
        Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0));
        g32->DrawLine(&whitePen40, w - 200, 50, w, 50);
        sres = g32->DrawString(wnum, -1, &myFont, origin, &blackBrush);
    }

    //if (npage > 0) {            // Здесь выводим номер страницы
    //    AnsiString snum;
    //    wchar_t wnum[20];
    //    snum.printf("%d", npage);
    //    snum.WideChar(wnum, 20);
    //    Gdiplus::Font myFont(L"Arial", 40, Gdiplus::FontStyleBold);
    //    Gdiplus::PointF origin(SaveBitmapW - 160, 20.0f);
    //    Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0));
    //    SaveBitmap2TiffGraphics->DrawString(wnum, -1, &myFont, origin, &blackBrush);
    //}

    // ------- строим SaveBitmap2TiffBitmap1
    UINT *pix;
    unsigned char byte, bit, *pix1;

    Gdiplus::Bitmap *b1 = new Gdiplus::Bitmap(w, h, PixelFormat1bppIndexed);
    Gdiplus::Rect BitsRect(0, 0, w, h);
    Gdiplus::BitmapData *bits = new Gdiplus::BitmapData;
    Gdiplus::BitmapData *bits1 = new Gdiplus::BitmapData;
    sres = b32->LockBits(&BitsRect, Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, bits);
    sres = b1->LockBits(&BitsRect, Gdiplus::ImageLockModeWrite, PixelFormat1bppIndexed, bits1);

    for (int y = 0; y < h; y++) {
        pix = (UINT *)((int)bits->Scan0 + bits->Stride * y);
        pix1 = (unsigned char *)((int)bits1->Scan0 + bits1->Stride * y);
        byte = 0;
        for (int x = 0; x < w; x++, pix++) {
            if ((*pix & 0xFF) > 0xD8) {
                bit = 1;
            }
            else bit = 0;
            byte <<= 1; byte |= bit;
            if ((x & 7) == 7) {
                *pix1++ = byte;
                byte = 0;
            }
        }
    }

    b32->UnlockBits(bits); delete bits;
    b1->UnlockBits(bits1); delete bits1;

    delete g32;
    delete b32;

    TTiffPageInfo *pi = GetPageInfo(GetPage());
    if (img->Filn.Length() == 0) {                  // Это уже временный файл!
        delete img->fbm;
        img->fbm = b1;
    } else {                                        // Надо будет заменить страницу на временный файл
        img = new TTiffImage(b1);
        pi->ImageIndex = AppendImage(img);
        pi->PageIndex = 0;
    }

    changed = true;
}