Exemple #1
0
		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() );
		}
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;
}
Exemple #3
0
//---------------------------------------------------------------------------
int GetCharMaxX(Gdiplus::Bitmap& charBitmap)
{
    using namespace Gdiplus;

	int width  = charBitmap.GetWidth();
	int height = charBitmap.GetHeight();

	for(int x = width-1; x >= 0; --x)
	{
		for(int y = 0; y < height; ++y)
		{
			Color color;
			charBitmap.GetPixel(x, y, &color);
			if(color.GetAlpha() > 0)
			{
				 return x;
			}
		}
	}

	return width-1;
}
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
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
}
Exemple #5
0
void CListViewNode::OnPaint(Gdiplus::Graphics* graphics, INT xPos, INT yPos, INT cBottom, INT cRight)
{
	if ( !m_listView )
		return;

	RECT iconRect; ::CopyRect(&iconRect, &m_iconRect); ::OffsetRect(&iconRect, -xPos, -yPos);
	RECT textRect; ::CopyRect(&textRect, &m_textRect); ::OffsetRect(&textRect, -xPos, -yPos);
	RECT borderRect; ::CopyRect(&borderRect, &m_borderRect); borderRect.right = borderRect.left + cRight; ::OffsetRect(&borderRect, 0, -yPos);
	
	if ( iconRect.bottom < 0 )
		return;
	if ( iconRect.top >= cBottom )
		return;

	Gdiplus::Font* pFont = NULL;
	Gdiplus::Brush* pBrushBackground = NULL;
	Gdiplus::Brush* pBrushForeground = NULL;

	if ( m_selected )
	{
		pFont = m_listView->get_Font(_T(".Font.Selected"), _T("ListView"));
		pBrushBackground = m_listView->get_Brush(_T(".BackgroundColor.Selected"), _T("ListView"), Gdiplus::Color::Blue);
		pBrushForeground = m_listView->get_Brush(_T(".ForegroundColor.Selected"), _T("ListView"), Gdiplus::Color::White);
	}
	else
	{
		pFont = m_listView->get_Font(_T(".Font.Normal"), _T("ListView"));
		pBrushBackground = m_listView->get_Brush(_T(".BackgroundColor.Normal"), _T("ListView"), Gdiplus::Color::White);
		pBrushForeground = m_listView->get_Brush(_T(".ForegroundColor.Normal"), _T("ListView"), Gdiplus::Color::Black);
	}

	Gdiplus::RectF iconRectF; Convert2RectF(&iconRectF, &iconRect);
	Gdiplus::RectF textRectF; Convert2RectF(&textRectF, &textRect);
	Gdiplus::RectF borderRectF; Convert2RectF(&borderRectF, &borderRect);
	Gdiplus::PointF pt; pt.X = textRectF.X; pt.Y = textRectF.Y;

	graphics->FillRectangle(pBrushBackground, borderRectF);

	Gdiplus::Bitmap* image = NULL;
	UINT hImage = 0;

	if ( (m_imageIndex >= 0) && (((dword)m_imageIndex) < m_listView->get_ImageCount()) )
		image = m_listView->get_Image(m_imageIndex);
	if ( image && (image->GetHeight() > 0) )
		hImage = image->GetHeight();
	if ( hImage > 0 )
	{
		Gdiplus::Color transparentcolor;
		Gdiplus::ImageAttributes imAtt;

		image->GetPixel(0, hImage - 1, &transparentcolor);
		imAtt.SetColorKey(transparentcolor, transparentcolor, Gdiplus::ColorAdjustTypeBitmap);

		graphics->DrawImage(image, iconRectF, 0.0, 0.0, Cast(Gdiplus::REAL,hImage), Cast(Gdiplus::REAL,hImage), Gdiplus::UnitPixel, &imAtt);
	}
	if ( !(m_text.IsEmpty()) )
		graphics->DrawString(m_text.GetString(), m_textDisplayLength, pFont, pt, Gdiplus::StringFormat::GenericTypographic(), pBrushForeground);
	if ( m_focused )
	{
		Gdiplus::Pen grayPen(Gdiplus::Color::Gray);
		grayPen.SetDashStyle(Gdiplus::DashStyleDot);

		graphics->DrawRectangle(&grayPen, textRectF);
	}
}