コード例 #1
0
ファイル: Installer.cpp プロジェクト: phishbulb/sumatrapdf
static void DrawFrame2(Graphics &g, RectI r)
{
    g.SetCompositingQuality(CompositingQualityHighQuality);
    g.SetSmoothingMode(SmoothingModeAntiAlias);
    g.SetPageUnit(UnitPixel);

    Font f(L"Impact", 40, FontStyleRegular);
    CalcLettersLayout(g, &f, r.dx);

    Gdiplus::Color bgCol;
    bgCol.SetFromCOLORREF(WIN_BG_COLOR);
    SolidBrush bgBrush(bgCol);
    Rect r2(r.ToGdipRect());
    r2.Inflate(1, 1);
    g.FillRectangle(&bgBrush, r2);

    Font f2(L"Impact", 16, FontStyleRegular);
    DrawSumatraLetters(g, &f, &f2, 18.f);

    if (gShowOptions)
        return;

    REAL msgY = (REAL)(r.dy / 2);
    if (gMsg)
        msgY += DrawMessage(g, gMsg, msgY, (REAL)r.dx, gMsgColor) + 5;
    if (gMsgError)
        DrawMessage(g, gMsgError, msgY, (REAL)r.dx, COLOR_MSG_FAILED);
}
コード例 #2
0
void PngOutlineText::TextOutline(
	Gdiplus::Color clrText, 
	Gdiplus::Color clrOutline, 
	int nThickness)
{
	TextOutlineStrategy* pStrat = new TextOutlineStrategy();
	pStrat->Init(clrText,clrOutline,nThickness);

	if(m_pTextStrategy)
		delete m_pTextStrategy;

	m_pTextStrategy = pStrat;

	TextOutlineStrategy* pStrat2 = new TextOutlineStrategy();
	pStrat2->Init(
		Gdiplus::Color(clrText.GetAlpha(),255,255,255),
		Gdiplus::Color(clrOutline.GetAlpha(),255,255,255),
		nThickness);

	if(m_pTextStrategyMask)
		delete m_pTextStrategyMask;

	m_pTextStrategyMask = pStrat2;

}
コード例 #3
0
DirectionalLight::DirectionalLight(Gdiplus::Color colour, Vector3D direction)
{
	_redIntensity = colour.GetRed();
	_greenIntensity = colour.GetGreen();
	_blueIntensity = colour.GetBlue();
	_lightDirection = direction;
}
コード例 #4
0
ファイル: ImgStatic.cpp プロジェクト: soundsrc/pwsafe
BOOL CImgStatic::OnEraseBkgnd(CDC *pDC)
{
  if (m_bZooming)
    return TRUE;
  
  if (m_bImageLoaded) {
    RECT rc;
    GetClientRect(&rc);

    // Get Gdiplus graphics object
    Gdiplus::Graphics grp(pDC->GetSafeHdc());

    // Clear rectangle
    Gdiplus::Color gdipColor;
    gdipColor.SetFromCOLORREF(GetSysColor(COLOR_3DFACE));

    Gdiplus::SolidBrush brush(gdipColor);
    grp.FillRectangle(&brush, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
    grp.Flush();

    return TRUE;
  } else {
    return CStatic::OnEraseBkgnd(pDC);
  }
}
コード例 #5
0
ファイル: CBtnRoundImg.cpp プロジェクト: njustccy/NjustTool
HRGN  CBtnRoundImg::GetHRgnFromPNG(CString strImagePath)
{
   Gdiplus::Bitmap  imageBaseRgn(strImagePath);
   if (imageBaseRgn.GetLastStatus() != Ok)
   {
      ASSERT(FALSE);
      return NULL;
   }

   HRGN  hRgnTotal = ::CreateRectRgn(0, 0, 0, 0);
   ASSERT(NULL != hRgnTotal);

   Gdiplus::Color  clrPixel;  //ÏñËصÄÑÕÉ«
   Gdiplus::Status stcGetClr; //״̬
   for (int w = imageBaseRgn.GetWidth() - 1; w >= 0; w--)
   {
      for(int h = imageBaseRgn.GetHeight() - 1; h >= 0; h--)
      {
         stcGetClr = imageBaseRgn.GetPixel(w, h, &clrPixel);
         ASSERT(stcGetClr == Ok);

         int iAlpha = clrPixel.GetAlpha();
         if (iAlpha == 0){
            continue;	//͸Ã÷É«²»´¦Àí
         }

         HRGN  hRgnTemp = ::CreateRectRgn(w, h, w + 1, h + 1);
         ::CombineRgn(hRgnTotal, hRgnTotal, hRgnTemp, RGN_OR);
         ::DeleteObject(hRgnTemp);
      }
   }

   return hRgnTotal;
}
コード例 #6
0
ファイル: utils.cpp プロジェクト: menpo/mesa
void OpenBitmapFromFile(
    const WCHAR *pFilename,
    void **pBuffer,
    uint32_t *width,
    uint32_t *height)
{
    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr);

    Bitmap *bitmap  = new Bitmap(pFilename);

    *width          = bitmap->GetWidth();
    *height         = bitmap->GetHeight();
    *pBuffer        = new BYTE[*width * *height * 4]; // width * height * |RGBA|

    // The folder 'stb_image' contains a PNG open/close module which
    // is far less painful than this is, yo.
    Gdiplus::Color clr;
    for (uint32_t y = 0, idx = 0; y < *height; ++y)
    {
        for (uint32_t x = 0; x < *width; ++x, idx += 4)
        {
            bitmap->GetPixel(x, *height - y - 1, &clr);
            ((BYTE*)*pBuffer)[idx + 0] = clr.GetBlue();
            ((BYTE*)*pBuffer)[idx + 1] = clr.GetGreen();
            ((BYTE*)*pBuffer)[idx + 2] = clr.GetRed();
            ((BYTE*)*pBuffer)[idx + 3] = clr.GetAlpha();
        }
    }

    delete bitmap;
    bitmap = 0;
}
コード例 #7
0
void TextRenderHdc::SetTextColor(Gdiplus::Color col) {
    CrashIf(!hdc);
    if (textColor.GetValue() == col.GetValue()) {
        return;
    }
    textColor = col;
    ::SetTextColor(hdc, col.ToCOLORREF());
}
コード例 #8
0
void TextRenderGdi::SetTextColor(Gdiplus::Color col) {
    if (textColor.GetValue() == col.GetValue()) {
        return;
    }
    textColor = col;
    if (hdcGfxLocked) {
        ::SetTextColor(hdcGfxLocked, col.ToCOLORREF());
    }
}
コード例 #9
0
ファイル: GDIPlus.cpp プロジェクト: charliesome/battlecars
		Gwen::Color GDIPlus::PixelColour( Gwen::Texture* pTexture, unsigned int x, unsigned int y, const Gwen::Color& col_default )
		{
			Gdiplus::Bitmap* pImage = (Gdiplus::Bitmap*) pTexture->data;
			if ( !pImage ) return col_default;

			Gdiplus::Color c;
			pImage->GetPixel( x, y, &c );

			return Gwen::Color( c.GetR(), c.GetG(), c.GetB(), c.GetA() );
		}
コード例 #10
0
void CSettingsRevisionGraphColors::ApplyColor
    ( CMFCColorButton& button
    , CColors::GDIPlusColor color
    , DWORD alpha)
{
    COLORREF value = button.GetColor() == -1
                   ? button.GetAutomaticColor()
                   : button.GetColor();

    Gdiplus::Color temp;
    temp.SetFromCOLORREF (value);
    m_Colors.SetColor (color, (temp.GetValue() & 0xffffff) + (alpha << 24));
}
コード例 #11
0
ファイル: MainFrm.cpp プロジェクト: Rancho06/ProCppProjects
LRESULT CMainFrame::OnPenColor(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// allow users to choose an arbitrary pen color
	Gdiplus::Color currentColor;
	m_view.m_Pen.GetColor(&currentColor);
	COLORREF color = currentColor.ToCOLORREF();
	CColorDialog test(color);
	test.DoModal();
	color = test.GetColor();
	Gdiplus::Color newColor(GetRValue(color), GetGValue(color), GetBValue(color));
	m_view.m_Pen.SetColor(newColor);
	return 0;
}
コード例 #12
0
void CSettingsRevisionGraphColors::ApplyColor
    ( CMFCColorButton& button
    , CColors::GDIPlusColorTable table
    , int index)
{
    COLORREF value = button.GetColor() == -1
                   ? button.GetAutomaticColor()
                   : button.GetColor();

    Gdiplus::Color temp;
    temp.SetFromCOLORREF (value);
    m_Colors.SetColor (table, index, (temp.GetValue() & 0xffffff) + 0xff000000);
}
コード例 #13
0
ファイル: main.cpp プロジェクト: pngcrypt/png-crypt
//===============================================
void LoadPixel(UINT ofs, BYTE* rgba)
//===============================================
{
	// get pixel of current image by offset ofs
	UINT x,y;
	Gdiplus::Color	col;

	PixelToCoord(ofs, &x, &y);
	img->GetPixel(x,y, &col);
	rgba[0] = col.GetR();
	rgba[1] = col.GetG();
	rgba[2] = col.GetB();
	rgba[3] = col.GetA();
}
コード例 #14
0
 bool ColorsEqual(Gdiplus::Color a, Gdiplus::Color b)
 {
     return a.GetR() == b.GetR() &&
         a.GetG() == b.GetG() &&
         a.GetB() == b.GetB() &&
         a.GetA() == b.GetA();
 }
コード例 #15
0
ファイル: OutlineText.cpp プロジェクト: lorichen/xgame
void OutlineText::Extrude(
	Gdiplus::Color color, 
	int nThickness,
	Gdiplus::Point ptOffset)
{
	ExtrudeStrategy* pStrat = new ExtrudeStrategy();
	pStrat->Init(Gdiplus::Color(0,0,0,0),color,nThickness,ptOffset.X,ptOffset.Y);

	m_clrShadow = color;

	if(m_pFontBodyShadow)
		delete m_pFontBodyShadow;

	ExtrudeStrategy* pFontBodyShadow = new ExtrudeStrategy();
	pFontBodyShadow->Init(Gdiplus::Color(color.GetA(),255,255),Gdiplus::Color(0,0,0,0),0,ptOffset.X,ptOffset.Y);
	m_pFontBodyShadow = pFontBodyShadow;

	if(m_pShadowStrategy)
		delete m_pShadowStrategy;

	m_ptShadowOffset = ptOffset;
	m_pShadowStrategy = pStrat;
	m_bExtrudeShadow = true;
	m_bDiffuseShadow = false;
	m_nShadowThickness = nThickness;
}
コード例 #16
0
ファイル: Utils.cpp プロジェクト: vladios13/image-uploader
// hack for stupid GDIplus
void Gdip_RemoveAlpha(Gdiplus::Bitmap& source, Gdiplus::Color color )
{
	using namespace Gdiplus;
	Rect r( 0, 0, source.GetWidth(),source.GetHeight() );
	BitmapData  bdSrc;
	source.LockBits( &r,  ImageLockModeRead , PixelFormat32bppARGB,&bdSrc);

	BYTE* bpSrc = (BYTE*)bdSrc.Scan0;

	//bpSrc += (int)sourceChannel;


	for ( int i = r.Height * r.Width; i > 0; i-- )
	{
		BGRA_COLOR * c = (BGRA_COLOR *)bpSrc;

		if(c->a!=255)
		{
			//c = 255;

			DWORD * d= (DWORD*)bpSrc;
			*d= color.ToCOLORREF();
			c ->a= 255;
		}
		bpSrc += 4;

	}
	source.UnlockBits( &bdSrc );
}
コード例 #17
0
void PngOutlineText::DiffusedShadow(
	Gdiplus::Color color, 
	int nThickness,
	Gdiplus::Point ptOffset)
{
	DiffusedShadowStrategy* pStrat = new DiffusedShadowStrategy();
	pStrat->Init(Gdiplus::Color(0,0,0,0),color,nThickness,false);

	if(m_pShadowStrategy)
		delete m_pShadowStrategy;

	m_ptShadowOffset = ptOffset;
	m_pShadowStrategy = pStrat;

	DiffusedShadowStrategy* pStrat2 = new DiffusedShadowStrategy();
	pStrat2->Init(
		Gdiplus::Color(0,0,0,0),
		Gdiplus::Color(color.GetAlpha(),255,255,255),
		nThickness,
		true);

	if(m_pShadowStrategyMask)
		delete m_pShadowStrategyMask;

	m_pShadowStrategyMask = pStrat2;

	m_clrShadow = color;

	if(m_pFontBodyShadow)
		delete m_pFontBodyShadow;

	DiffusedShadowStrategy* pFontBodyShadow = new DiffusedShadowStrategy();
	pFontBodyShadow->Init(Gdiplus::Color(255,255,255),Gdiplus::Color(0,0,0,0),nThickness,false);

	m_pFontBodyShadow = pFontBodyShadow;

	if(m_pFontBodyShadowMask)
		delete m_pFontBodyShadowMask;

	DiffusedShadowStrategy* pFontBodyShadowMask = new DiffusedShadowStrategy();
	pFontBodyShadowMask->Init(Gdiplus::Color(color.GetAlpha(),255,255,255),Gdiplus::Color(0,0,0,0),
		nThickness,false);

	m_pFontBodyShadowMask = pFontBodyShadowMask;
	m_bDiffuseShadow = true;
	m_nShadowThickness = nThickness;
}
コード例 #18
0
ファイル: ImgStatic.cpp プロジェクト: soundsrc/pwsafe
void CImgStatic::ClearImage()
{
  // Get rid of image and return it back to empty CStatic control
  FreeStream();

  RECT rc;
  GetClientRect(&rc);
  Gdiplus::Graphics grp(GetDC()->GetSafeHdc());

  // Clear rectangle
  Gdiplus::Color gdipColor;
  gdipColor.SetFromCOLORREF(GetSysColor(COLOR_3DFACE));

  Gdiplus::SolidBrush brush(gdipColor);
  grp.FillRectangle(&brush, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
  grp.Flush();
}
コード例 #19
0
ファイル: Colors.cpp プロジェクト: TortoiseGit/tortoisesvn
void CColors::SetColor (GDIPlusColorTable id, int index, Gdiplus::Color color)
{
    CRegDWORDList* setting = GetRegistrySetting (id);
    if (setting == NULL)
        return;

    (*setting)[index] = color.GetValue();
}
コード例 #20
0
void TextRenderGdiplus::SetTextColor(Gdiplus::Color col) {
    if (textColor.GetValue() == col.GetValue()) {
        return;
    }
    textColor = col;
    ::delete textColorBrush;
    textColorBrush = ::new SolidBrush(col);
}
コード例 #21
0
int DxFont::GetCharMaxX(Gdiplus::Bitmap & charBitmap)
{
    int width  = charBitmap.GetWidth( );
    int height = charBitmap.GetHeight( );

    for(int x = width - 1; x >= 0; --x )
    {
        for(int y = 0; y < height; ++y)
        {
            Gdiplus::Color color;

            charBitmap.GetPixel(x, y, &color);
            if( color.GetAlpha() > 0)
                return x;
        }
    }

    return width - 1;
}
コード例 #22
0
ファイル: PenWeight.cpp プロジェクト: Rancho06/ProCppProjects
// if an identical pen is set up already, find and use it
// if no such pen is set up, create one and save it for future use
std::shared_ptr<Gdiplus::Pen> PenWeight::GetPen(Gdiplus::Color color, float width) 
{
	std::stringstream newStream;
	newStream << "(" << color.GetRed() << ",";
	newStream << color.GetGreen() << ",";
	newStream << color.GetBlue() << ");";
	newStream << std::setprecision(2) << width;
	std::string newString = newStream.str();
	// when an identical pen is found
	if (this->pens.find(newString) != this->pens.end()) {
		return pens.at(newString);
	}
	// no identical pens are found
	else {
		std::shared_ptr<Gdiplus::Pen> newPen = std::make_shared<Gdiplus::Pen>(color, width);
		pens.insert(std::pair<std::string, std::shared_ptr<Gdiplus::Pen>>(newString, newPen));
		return newPen;
	}
}
コード例 #23
0
ファイル: PointGridIndex.cpp プロジェクト: mapmatching/Lab
void PointGridIndex::drawGridLine(Gdiplus::Color color, MapDrawer& md)
{
	//////////////////////////////////////////////////////////////////////////
	///在图片上画出网格线 
	//////////////////////////////////////////////////////////////////////////
	Gdiplus::ARGB argb = Gdiplus::Color::MakeARGB(90, color.GetR(), color.GetG(), color.GetB());
	color.SetValue(argb);
	double delta = 0.0000001;
	for (int i = 0; i < gridHeight; i++)
	{
		double lat = area->minLat + gridSizeDeg * i;
		md.drawLine(color, lat, area->minLon + delta, lat, area->maxLon - delta);
	}
	for (int i = 0; i < gridWidth; i++)
	{
		double lon = area->minLon + gridSizeDeg * i;
		md.drawLine(color, area->minLat + delta, lon, area->maxLat - delta, lon);
	}
}
コード例 #24
0
ファイル: CanvasGDIP.cpp プロジェクト: AlfiyaZi/rainmeter
void CanvasGDIP::Clear(const Gdiplus::Color& color)
{
	if (color.GetValue() == 0x00000000)
	{
		memset(m_DIBSectionBufferPixels, 0, m_W * m_H * 4);
	}
	else
	{
		m_Graphics->Clear(color);
	}
}
コード例 #25
0
bool TextInlineFormat_Color::CompareAndUpdateProperties(const std::wstring& pattern, const Gdiplus::Color& color)
{
	if (_wcsicmp(GetPattern().c_str(), pattern.c_str()) != 0 || m_Color.GetValue() != color.GetValue())
	{
		SetPattern(pattern);
		m_Color = color;
		return true;
	}

	return false;
}
コード例 #26
0
ファイル: CSurface.cpp プロジェクト: patrickmortensen/Elektro
void CSurface::Init(char* filename)
{
	Gdiplus::GdiplusStartupInput startupInput;
	ULONG_PTR token;
	GdiplusStartup(&token, &startupInput, NULL);

	int len = strlen(filename);
	wchar_t* temp = new wchar_t[len + 1];
	for (int i = 0; i < len; i++)
	{
		temp[i] = filename[i];
	}
	temp[len] = '\0';
	Gdiplus::Bitmap bitmap(temp);
	Gdiplus::Color pixel;

	if (bitmap.GetWidth() <= 0)
		return;
	if (bitmap.GetHeight() <= 0)
		return;

	m_width = bitmap.GetWidth();
	m_height = bitmap.GetHeight();

	m_pPixels = new CVector4[m_width * m_height];

	for (int x = 0; x < m_width; x++)
	{
		for (int y = 0; y < m_height; y++)
		{
			bitmap.GetPixel(x, y, &pixel);
			m_pPixels[x + y * m_width] = CVector4(pixel.GetR(), pixel.GetG(), pixel.GetB(), pixel.GetA());
		}
	}

	if (!m_pPixels)
		return;

	STRING::Copy(m_pFilename, filename);
}
コード例 #27
0
bool TextInlineFormat_Shadow::CompareAndUpdateProperties(const std::wstring& pattern, const FLOAT& blur,
	const D2D1_POINT_2F& offset, const Gdiplus::Color& color)
{
	if (_wcsicmp(GetPattern().c_str(), pattern.c_str()) != 0 || m_Color.GetValue() != color.GetValue())
	{
		SetPattern(pattern);
		m_Offset = offset;
		m_Color = color;
		return true;
	}

	return false;
}
コード例 #28
0
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
bool PngTextureLoader::Load(void* data, int32_t size, bool rev)
{
#if __PNG_DDI
	auto global = GlobalAlloc(GMEM_MOVEABLE,size);
	auto buf = GlobalLock(global);
	CopyMemory(buf, data, size);
	GlobalUnlock(global);
	LPSTREAM stream = NULL;
	CreateStreamOnHGlobal( global, false, &stream);
	Gdiplus::Bitmap* bmp = Gdiplus::Bitmap::FromStream(stream);
	ES_SAFE_RELEASE(stream);
	GlobalFree(global);


	if( bmp != NULL && bmp->GetLastStatus() == Gdiplus::Ok )
	{
		textureWidth = bmp->GetWidth();
		textureHeight = bmp->GetHeight();
		textureData.resize(textureWidth * textureHeight * 4);

		if(rev)
		{
			for(auto y = 0; y < textureHeight; y++ )
			{
				for(auto x = 0; x < textureWidth; x++ )
				{
					Gdiplus::Color  color;
					bmp->GetPixel(x, textureHeight - y - 1, &color);

					textureData[(x + y * textureWidth) * 4 + 0] = color.GetR();
					textureData[(x + y * textureWidth) * 4 + 1] = color.GetG();
					textureData[(x + y * textureWidth) * 4 + 2] = color.GetB();
					textureData[(x + y * textureWidth) * 4 + 3] = color.GetA();
				}
			}
		}
		else
		{
			for(auto y = 0; y < textureHeight; y++ )
			{
				for(auto x = 0; x < textureWidth; x++ )
				{
					Gdiplus::Color  color;
					bmp->GetPixel(x, y, &color);

					textureData[(x + y * textureWidth) * 4 + 0] = color.GetR();
					textureData[(x + y * textureWidth) * 4 + 1] = color.GetG();
					textureData[(x + y * textureWidth) * 4 + 2] = color.GetB();
					textureData[(x + y * textureWidth) * 4 + 3] = color.GetA();
				}
			}
		}
		
		return true;
	}
	else
	{
		ES_SAFE_DELETE(bmp);
		return false;
	}
#else
	uint8_t* data_ = (uint8_t*) data;

	/* pngアクセス構造体を作成 */
	png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
	
	/* リードコールバック関数指定 */
	png_set_read_fn(png, &data_, &PngReadData);

	/* png画像情報構造体を作成 */
	png_infop png_info = png_create_info_struct(png);

	/* エラーハンドリング */
	if (setjmp(png_jmpbuf(png)))
	{
		png_destroy_read_struct(&png, &png_info, NULL);
		return false;
	}

	/* IHDRチャンク情報を取得 */
	png_read_info(png, png_info);
	png_uint_32 width, height;
	int bit_depth, color_type, interlace_type, comp_type, filter_type;
	png_get_IHDR(png, png_info, &width, &height, &bit_depth, &color_type, &interlace_type,
				 &comp_type, &filter_type);

	/* RGBA8888フォーマットに変換する */
	if (bit_depth < 8)
	{
		png_set_packing(png);
	}
	else if (bit_depth == 16)
	{
		png_set_strip_16(png);
	}

	uint32_t pixelBytes = 4;
	switch (color_type)
	{
	case PNG_COLOR_TYPE_PALETTE:
		png_set_palette_to_rgb(png);
		pixelBytes = 4;
		break;
	case PNG_COLOR_TYPE_GRAY:
		png_set_expand_gray_1_2_4_to_8(png);
		pixelBytes = 3;
		break;
	case PNG_COLOR_TYPE_RGB:
		pixelBytes = 3;
		break;
	case PNG_COLOR_TYPE_RGBA:
		break;
	}

	uint8_t* image = new uint8_t[width * height * pixelBytes];
	uint32_t pitch = width * pixelBytes;

	/* イメージデータを読み込む */

	textureWidth = width;
	textureHeight = height;
	textureData.resize(textureWidth * textureHeight * 4);

	if (rev)
	{
		for (uint32_t i = 0; i < height; i++)
		{
			png_read_row(png, &image[(height - 1 - i) * pitch], NULL);
		}
	}
	else
	{
		for (uint32_t i = 0; i < height; i++)
		{
			png_read_row(png, &image[i * pitch], NULL);
		}
	}

	if (pixelBytes == 4)
	{
		memcpy(textureData.data(), image, width * height * pixelBytes);
	}
	else
	{
		for (int32_t y = 0; y < height; y++)
		{
			for (int32_t x = 0; x < width; x++)
			{
				int32_t src = (x + y * width) * 3;
				int32_t dst = (x + y * width) * 4;
				textureData[dst + 0] = image[src + 0];
				textureData[dst + 1] = image[src + 1];
				textureData[dst + 2] = image[src + 2];
				textureData[dst + 3] = 255;
			}
		}
	}
	
	delete [] image;
	png_destroy_read_struct(&png, &png_info, NULL);

	return true;
#endif
}
コード例 #29
0
void SpriteFont::Initialize(const wchar *fontName, float fontSize, UINT fontStyle, bool antiAliased, ID3D11Device *device) {
	m_size = fontSize;

	Gdiplus::TextRenderingHint hint = antiAliased ? Gdiplus::TextRenderingHintAntiAliasGridFit : Gdiplus::TextRenderingHintSingleBitPerPixelGridFit;

	// Init GDI+
	ULONG_PTR token = NULL;
	Gdiplus::GdiplusStartupInput startupInput(NULL, true, true);
	Gdiplus::GdiplusStartupOutput startupOutput;
	HR(GdiplusStartup(&token, &startupInput, &startupOutput));

	// Create the font
	Gdiplus::Font font(fontName, fontSize, fontStyle, Gdiplus::UnitPixel, NULL);

	// Check for error during construction
	HR(font.GetLastStatus());

	// Create a temporary Bitmap and Graphics for figuring out the rough size required
	// for drawing all of the characters
	int size = static_cast<int>(fontSize * NumChars * 2) + 1;
	Gdiplus::Bitmap sizeBitmap(size, size, PixelFormat32bppARGB);
	HR(sizeBitmap.GetLastStatus());

	Gdiplus::Graphics sizeGraphics(&sizeBitmap);
	HR(sizeGraphics.GetLastStatus());
	HR(sizeGraphics.SetTextRenderingHint(hint));

	m_charHeight = font.GetHeight(&sizeGraphics) * 1.5f;

	wchar allChars[NumChars + 1];
	for (wchar i = 0; i < NumChars; ++i) {
		allChars[i] = i + StartChar;
	}
	allChars[NumChars] = 0;

	Gdiplus::RectF sizeRect;
	HR(sizeGraphics.MeasureString(allChars, NumChars, &font, Gdiplus::PointF(0, 0), &sizeRect));
	int numRows = static_cast<int>(sizeRect.Width / TexWidth) + 1;
	int texHeight = static_cast<int>(numRows * m_charHeight) + 1;

	// Create a temporary Bitmap and Graphics for drawing the characters one by one
	int tempSize = static_cast<int>(fontSize * 2);
	Gdiplus::Bitmap drawBitmap(tempSize, tempSize, PixelFormat32bppARGB);
	HR(drawBitmap.GetLastStatus());

	Gdiplus::Graphics drawGraphics(&drawBitmap);
	HR(drawGraphics.GetLastStatus());
	HR(drawGraphics.SetTextRenderingHint(hint));

	// Create a temporary Bitmap + Graphics for creating a full character set
	Gdiplus::Bitmap textBitmap(TexWidth, texHeight, PixelFormat32bppARGB);
	HR(textBitmap.GetLastStatus());

	Gdiplus::Graphics textGraphics(&textBitmap);
	HR(textGraphics.GetLastStatus());
	HR(textGraphics.Clear(Gdiplus::Color(0, 255, 255, 255)));
	HR(textGraphics.SetCompositingMode(Gdiplus::CompositingModeSourceCopy));

	// Solid brush for text rendering
	Gdiplus::SolidBrush brush(Gdiplus::Color(255, 255, 255, 255));
	HR(brush.GetLastStatus());

	// Draw all of the characters, and copy them to the full character set
	wchar charString [2];
	charString[1] = 0;
	int currentX = 0;
	int currentY = 0;
	for (uint64 i = 0; i < NumChars; ++i) {
		charString[0] = static_cast<wchar>(i + StartChar);

		// Draw the character
		HR(drawGraphics.Clear(Gdiplus::Color(0, 255, 255, 255)));
		HR(drawGraphics.DrawString(charString, 1, &font, Gdiplus::PointF(0, 0), &brush));

		// Figure out the amount of blank space before the character
		int minX = 0;
		for (int x = 0; x < tempSize; ++x) {
			for (int y = 0; y < tempSize; ++y) {
				Gdiplus::Color color;
				HR(drawBitmap.GetPixel(x, y, &color));
				if (color.GetAlpha() > 0) {
					minX = x;
					x = tempSize;
					break;
				}
			}
		}

		// Figure out the amount of blank space after the character
		int maxX = tempSize - 1;
		for (int x = tempSize - 1; x >= 0; --x) {
			for (int y = 0; y < tempSize; ++y) {
				Gdiplus::Color color;
				HR(drawBitmap.GetPixel(x, y, &color));
				if (color.GetAlpha() > 0) {
					maxX = x;
					x = -1;
					break;
				}
			}
		}

		int charWidth = maxX - minX + 1;

		// Figure out if we need to move to the next row
		if (currentX + charWidth >= TexWidth) {
			currentX = 0;
			currentY += static_cast<int>(m_charHeight) + 1;
		}

		// Fill out the structure describing the character position
		m_charDescs[i].X = static_cast<float>(currentX);
		m_charDescs[i].Y = static_cast<float>(currentY);
		m_charDescs[i].Width = static_cast<float>(charWidth);
		m_charDescs[i].Height = static_cast<float>(m_charHeight);

		// Copy the character over
		int height = static_cast<int>(m_charHeight + 1);
		HR(textGraphics.DrawImage(&drawBitmap, currentX, currentY, minX, 0, charWidth, height, Gdiplus::UnitPixel));

		currentX += charWidth + 1;
	}

	// Figure out the width of a space character
	charString[0] = ' ';
	charString[1] = 0;
	HR(drawGraphics.MeasureString(charString, 1, &font, Gdiplus::PointF(0, 0), &sizeRect));
	m_spaceWidth = sizeRect.Width;

	// Lock the bitmap for direct memory access
	Gdiplus::BitmapData bmData;
	HR(textBitmap.LockBits(&Gdiplus::Rect(0, 0, TexWidth, texHeight), Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, &bmData));

	// Create a D3D texture, initalized with the bitmap data
	D3D11_TEXTURE2D_DESC texDesc;
	texDesc.Width = TexWidth;
	texDesc.Height = texHeight;
	texDesc.MipLevels = 1;
	texDesc.ArraySize = 1;
	texDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
	texDesc.SampleDesc.Count = 1;
	texDesc.SampleDesc.Quality = 0;
	texDesc.Usage = D3D11_USAGE_IMMUTABLE;
	texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
	texDesc.CPUAccessFlags = 0;
	texDesc.MiscFlags = 0;

	D3D11_SUBRESOURCE_DATA data;
	data.pSysMem = bmData.Scan0;
	data.SysMemPitch = TexWidth * 4;
	data.SysMemSlicePitch = 0;

	HR(device->CreateTexture2D(&texDesc, &data, &m_texture));

	HR(textBitmap.UnlockBits(&bmData));

	// Create the shader resource view
	D3D11_SHADER_RESOURCE_VIEW_DESC srDesc;
	srDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
	srDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
	srDesc.Texture2D.MipLevels = 1;
	srDesc.Texture2D.MostDetailedMip = 0;

	HR(device->CreateShaderResourceView(m_texture, &srDesc, &m_SRV));

	// Shutdown GDI+
	//Gdiplus::GdiplusShutdown(token);
	// TODO: Figure out why this throws exceptions
}
コード例 #30
0
ファイル: Settings.cpp プロジェクト: vladios13/image-uploader
inline std::string myToString(const Gdiplus::Color& value)
{
	char buffer[30];
	sprintf(buffer,"rgba(%d,%d,%d,%1.4f)", (int)value.GetR(), (int)value.GetG(), (int)value.GetB(), (float)(value.GetA()/255.0));
	return buffer;
}