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();
 }
Ejemplo n.º 2
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() );
		}
Ejemplo n.º 3
0
//===============================================
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();
}
Ejemplo n.º 4
0
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);
	}
}
Ejemplo n.º 5
0
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);
}
Ejemplo n.º 6
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
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
// Fills a polygon using a texture, gouraud shading and a normal map given 3 points and a color.
void Rasterizer::FillPolygonTexturedNormalMapped(Vertex v1, Vertex v2, Vertex v3, Gdiplus::Color color, Model3D& model, std::vector<DirectionalLight*> directionalLights, std::vector<AmbientLight*> ambientLights, std::vector<PointLight*> pointLights)
{
	ScanLine* _scanlines = new ScanLine[_height];

	BYTE* texture;
	Gdiplus::Color* palette;
	BYTE* normalTexture;
	Gdiplus::Color* normalPalette;
	int textureWidth;

	// Get the texture properties of the model.
	model.GetTexture(&texture, &palette, &textureWidth); 
	model.GetNormalMapTexture(&normalTexture, &normalPalette, &textureWidth); 
	
	// Set the scanlines to very high and very low values so
	// they will be set on the first set of interpolation.
	for (unsigned int i = 0; i < _height; i++)
	{
		_scanlines[i].xStart = 99999;
		_scanlines[i].xEnd = -99999;
	}

	// Interpolates between each of the vertexs of the polygon and sets the start
	// and end values for each of the scanlines it comes in contact with.
	InterpolateScanline(_scanlines, v1, v2);
	InterpolateScanline(_scanlines, v2, v3);
	InterpolateScanline(_scanlines, v3, v1);

	// Go through each scanline and each pixel in the scanline and 
	// sets its color.
	for (unsigned int y = 0; y < _height; y++)
	{
		// Work out the color and UV differences between the start and end of the scanline.
		float redColorDiff = (_scanlines[y].redEnd - _scanlines[y].redStart);
		float greenColorDiff = (_scanlines[y].greenEnd - _scanlines[y].greenStart);
		float blueColorDiff = (_scanlines[y].blueEnd - _scanlines[y].blueStart);
		float uCoordDiff = _scanlines[y].uEnd - _scanlines[y].uStart;
		float vCoordDiff = _scanlines[y].vEnd - _scanlines[y].vStart;
		float zCoordDiff = _scanlines[y].zEnd - _scanlines[y].zStart;

		float xNormalDiff = (_scanlines[y].xNormalEnd - _scanlines[y].xNormalStart);
		float yNormalDiff = (_scanlines[y].yNormalEnd - _scanlines[y].yNormalStart);
		float zNormalDiff = (_scanlines[y].zNormalEnd - _scanlines[y].zNormalStart);

		float xDiff = (_scanlines[y].pixelXEnd - _scanlines[y].pixelXStart);
		float yDiff = (_scanlines[y].pixelYEnd - _scanlines[y].pixelYStart);
		float zDiff = (_scanlines[y].pixelZEnd - _scanlines[y].pixelZStart);

		float diff = (_scanlines[y].xEnd - _scanlines[y].xStart) + 1;

		for (int x = (int)_scanlines[y].xStart; x <= (int)_scanlines[y].xEnd; x++)
		{
			if (x < 0 || x >= (int)_width)
				continue;

			int offset = (int)(x - _scanlines[y].xStart);
			
			// Work out the UV coordinate of the current pixel.
			float uCoord = _scanlines[y].uStart + ((uCoordDiff / diff) * offset);
			float vCoord = _scanlines[y].vStart + ((vCoordDiff / diff) * offset);
			float zCoord = _scanlines[y].zStart + ((zCoordDiff / diff) * offset);

			uCoord /= zCoord;
			vCoord /= zCoord;

			// Work out the normal of the pixel.
			float xNormal = _scanlines[y].xNormalStart + ((xNormalDiff / diff) * offset);
			float yNormal = _scanlines[y].yNormalStart + ((yNormalDiff / diff) * offset);
			float zNormal = _scanlines[y].zNormalStart + ((zNormalDiff / diff) * offset);

			// Work out the position of the pixel.
			float pixelX = _scanlines[y].pixelXStart + ((xDiff / diff) * offset);
			float pixelY = _scanlines[y].pixelYStart + ((yDiff / diff) * offset);
			float pixelZ = _scanlines[y].pixelZStart + ((zDiff / diff) * offset);

			// Work out the lighting colour of the current pixel.
			//float lightR = (_scanlines[y].redStart + ((redColorDiff / diff) * offset)) / 180.0f;
			//float lightG = (_scanlines[y].greenStart + ((greenColorDiff / diff) * offset)) / 180.0f;
			//float lightB = (_scanlines[y].blueStart + ((blueColorDiff / diff) * offset)) / 180.0f;	

			// Using the UV coordinate work out which pixel in the texture to use to draw this pixel.
			int pixelIndex = (int)vCoord * textureWidth + (int)uCoord;
			if (pixelIndex >= textureWidth * textureWidth || pixelIndex < 0)
			{
				pixelIndex = (textureWidth * textureWidth) - 1;
			}

			int paletteOffset = texture[pixelIndex]; 
			if (paletteOffset >= 255)
				paletteOffset = 255;

			Gdiplus::Color textureColor = palette[paletteOffset];

			// Work out the pixel colour of the normalmap.
			pixelIndex = (int)vCoord * textureWidth + (int)uCoord;
			if (pixelIndex >= textureWidth * textureWidth || pixelIndex < 0)
			{
				pixelIndex = (textureWidth * textureWidth) - 1;
			}

			paletteOffset = normalTexture[pixelIndex]; 
			if (paletteOffset >= 255)
				paletteOffset = 255;

			Gdiplus::Color normalTextureColor = normalPalette[paletteOffset];

			// Calculate normal lighting for the pixel.
			Vector3D heightMapVector = Vector3D(normalTextureColor.GetR() / 180.0f, normalTextureColor.GetG() / 180.0f, normalTextureColor.GetB() / 180.0f); 
			heightMapVector = Vector3D((heightMapVector.GetX() - 0.5f) * 2.0f, (heightMapVector.GetY() - 0.5f) * 2.0f, (heightMapVector.GetZ() - 0.5f) * 2.0f);

			// Work out he pixels normal and position.
			Vector3D pixelNormal = Vector3D(xNormal, yNormal, zNormal);//;Vector3D(heightMapVector.GetX(), heightMapVector.GetY(), heightMapVector.GetZ());
			Vertex pixelPosition = Vertex(pixelX, pixelY, pixelZ, 1, Gdiplus::Color::White, Vector3D(0, 0, 0), 0);

			heightMapVector = Vector3D((pixelNormal.GetX() * heightMapVector.GetX()) , 
										(pixelNormal.GetY() * heightMapVector.GetY()) , 
										(pixelNormal.GetZ() * heightMapVector.GetZ()) );

			// Calculate the sum dot product of all lighting vectors for this pixel and divide by the number
			// of lights.
			float lightDot = 0.0f;
			int count = 0;
			for (unsigned int j = 0; j < pointLights.size(); j++)
			{
				PointLight* light = pointLights[j];
				if (light->GetEnabled() == false)
					continue;
			
				// Work out vector to light source.
				Vector3D lightVector = Vertex::GetVector(pixelPosition, light->GetPosition());
				float distance = lightVector.GetLength();
				lightVector.Normalize();

				// Work out dot product.
				lightDot += Vector3D::DotProduct(heightMapVector, lightVector);
				count++;
			}
			for (unsigned int j = 0; j < directionalLights.size(); j++)
			{
				DirectionalLight* light = directionalLights[j];
				if (light->GetEnabled() == false)
					continue;
			
				// Work out vector to light source.
				Vector3D lightVector = Vertex::GetVector(pixelPosition, light->GetPosition());
				float distance = lightVector.GetLength();
				lightVector.Normalize();

				// Work out dot product.
				lightDot += Vector3D::DotProduct(heightMapVector, lightVector);
				count++;
			}
			lightDot /= count;

			// Adjust texture colour based on the lighting dot product.
			Gdiplus::Color pixelColor = textureColor;
			//pixelColor = model.CalculateLightingAmbientPerPixel(ambientLights, pixelPosition, pixelNormal, pixelColor);
			//pixelColor = model.CalculateLightingDirectionalPerPixel(directionalLights, pixelPosition, pixelNormal, pixelColor);
			//pixelColor = model.CalculateLightingPointPerPixel(pointLights, pixelPosition, pixelNormal, pixelColor);

			float lightR = (_scanlines[y].redStart + ((redColorDiff / diff) * offset)) / 180.0f;
			float lightG = (_scanlines[y].greenStart + ((greenColorDiff / diff) * offset)) / 180.0f;
			float lightB = (_scanlines[y].blueStart + ((blueColorDiff / diff) * offset)) / 180.0f;	

			// Apply the lighting value to the texture colour and use the result to set the colour of the current pixel.
			int finalR = (int)max(0, min(255, (lightR * textureColor.GetR()) - ((lightR * textureColor.GetR()) * lightDot) ));
			int finalG = (int)max(0, min(255, (lightG * textureColor.GetG()) - ((lightG * textureColor.GetG()) * lightDot) ));
			int finalB = (int)max(0, min(255, (lightB * textureColor.GetB()) - ((lightB * textureColor.GetB()) * lightDot) ));

			WritePixel(x, y, Gdiplus::Color(finalR, finalG, finalB));
		}
	}
	
	// Dispose of dynamic objects.
	delete[] _scanlines;

	_polygonsRendered++;
}
Ejemplo n.º 9
0
// Fills a polygon using a texture and gouraud shading given 3 points and a color.
void Rasterizer::FillPolygonTextured(Vertex v1, Vertex v2, Vertex v3, Gdiplus::Color color, Model3D& model)
{
	ScanLine* _scanlines = new ScanLine[_height];

	BYTE* texture;
	Gdiplus::Color* palette;
	int textureWidth;

	// Get the texture properties of the model.
	model.GetTexture(&texture, &palette, &textureWidth); 
	
	// Set the scanlines to very high and very low values so
	// they will be set on the first set of interpolation.
	for (unsigned int i = 0; i < _height; i++)
	{
		_scanlines[i].xStart = 99999;
		_scanlines[i].xEnd = -99999;
	}

	// Interpolates between each of the vertexs of the polygon and sets the start
	// and end values for each of the scanlines it comes in contact with.
	InterpolateScanline(_scanlines, v1, v2);
	InterpolateScanline(_scanlines, v2, v3);
	InterpolateScanline(_scanlines, v3, v1);

	// Go through each scanline and each pixel in the scanline and 
	// sets its color.
	for (unsigned int y = 0; y < _height; y++)
	{
		// Work out the color and UV differences between the start and end of the scanline.
		float redColorDiff = (_scanlines[y].redEnd - _scanlines[y].redStart);
		float greenColorDiff = (_scanlines[y].greenEnd - _scanlines[y].greenStart);
		float blueColorDiff = (_scanlines[y].blueEnd - _scanlines[y].blueStart);
		float uCoordDiff = _scanlines[y].uEnd - _scanlines[y].uStart;
		float vCoordDiff = _scanlines[y].vEnd - _scanlines[y].vStart;
		float zCoordDiff = _scanlines[y].zEnd - _scanlines[y].zStart;
		float diff = (_scanlines[y].xEnd - _scanlines[y].xStart) + 1;

		for (int x = (int)_scanlines[y].xStart; x <= (int)_scanlines[y].xEnd; x++)
		{
			if (x < 0 || x >= (int)_width)
				continue;

			int offset = (int)(x - _scanlines[y].xStart);
			
			// Work out the UV coordinate of the current pixel.
			float uCoord = _scanlines[y].uStart + ((uCoordDiff / diff) * offset);
			float vCoord = _scanlines[y].vStart + ((vCoordDiff / diff) * offset);
			float zCoord = _scanlines[y].zStart + ((zCoordDiff / diff) * offset);

			uCoord /= zCoord;
			vCoord /= zCoord;

			// Work out the lighting colour of the current pixel.
			float lightR = (_scanlines[y].redStart + ((redColorDiff / diff) * offset)) / 180.0f;
			float lightG = (_scanlines[y].greenStart + ((greenColorDiff / diff) * offset)) / 180.0f;
			float lightB = (_scanlines[y].blueStart + ((blueColorDiff / diff) * offset)) / 180.0f;	

			// Using the UV coordinate work out which pixel in the texture to use to draw this pixel.
			int pixelIndex = (int)vCoord * textureWidth + (int)uCoord;
			if (pixelIndex >= textureWidth * textureWidth || pixelIndex < 0)
			{
				pixelIndex = (textureWidth * textureWidth) - 1;
			}

			int paletteOffset = texture[pixelIndex]; 
			if (paletteOffset >= 255)
				paletteOffset = 255;

			Gdiplus::Color textureColor = palette[paletteOffset];

			// Apply the lighting value to the texture colour and use the result to set the colour of the current pixel.
			int finalR = (int)max(0, min(255, textureColor.GetR() * lightR));
			int finalG = (int)max(0, min(255, textureColor.GetG() * lightG));
			int finalB = (int)max(0, min(255, textureColor.GetB() * lightB));

			WritePixel(x, y, Gdiplus::Color(finalR, finalG, finalB));
		}
	}
	
	// Dispose of dynamic objects.
	delete[] _scanlines;

	_polygonsRendered++;
}
Ejemplo n.º 10
0
void CSkinButton2::DrawFrame(Gdiplus::Graphics& gdi,CRect& rect)
{
	if( m_enmuDrawType == NO_FRAME )
	{
		Gdiplus::Pen pen1( m_colFrame1 );
		gdi.DrawLine( &pen1, rect.left+1, rect.top, rect.right-2, rect.top );
		gdi.DrawLine( &pen1, rect.left+1, rect.bottom-1, rect.right-2, rect.bottom-1 );
		gdi.DrawLine( &pen1, rect.left, rect.top+1, rect.left, rect.bottom-2 );
		gdi.DrawLine( &pen1, rect.right-1, rect.top+1, rect.right-1, rect.bottom-2 );

		Gdiplus::Color colpix;
		pen1.GetColor( &colpix );
		colpix.SetValue( Gdiplus::Color::MakeARGB(colpix.GetA()/2,colpix.GetR(),colpix.GetG(),colpix.GetB() ) );
		Gdiplus::Pen penPix1( colpix );
		gdi.DrawLine( &penPix1, rect.left, rect.top, rect.left+1, rect.top );
		gdi.DrawLine( &penPix1, rect.right-1, rect.top, rect.right-1, rect.top+1 );
		gdi.DrawLine( &penPix1, rect.right-1, rect.bottom-1, rect.right-2, rect.bottom-1 );
		gdi.DrawLine( &penPix1, rect.left,  rect.bottom-1, rect.left+1,  rect.bottom-1 );

		CRect rect2 = rect;
		::InflateRect( &rect2, -1,-1 );
		if( !m_bMouseDown )
		{
			Gdiplus::Pen pen2(m_colFrame2);
			if( m_bMouseDown )
				pen2.SetColor(m_colFrame1);
			else
				pen2.SetColor(m_colFrame2);

			gdi.DrawLine( &pen2, rect2.left+1, rect2.top, rect2.right-2, rect2.top );
			gdi.DrawLine( &pen2, rect2.left+1, rect2.bottom-1, rect2.right-2, rect2.bottom-1 );
			gdi.DrawLine( &pen2, rect2.left, rect2.top+1, rect2.left, rect2.bottom-2 );
			gdi.DrawLine( &pen2, rect2.right-1, rect2.top+1, rect2.right-1, rect2.bottom-2 );

			Gdiplus::Color colpix2;
			pen2.GetColor( &colpix2 );
			colpix2.SetValue( Gdiplus::Color::MakeARGB(colpix2.GetA()/2,colpix2.GetR(),colpix2.GetG(),colpix2.GetB() ) );
			Gdiplus::Pen penPix2( colpix2 );
			gdi.DrawLine( &penPix2, rect2.left, rect2.top, rect2.left+1, rect2.top );
			gdi.DrawLine( &penPix2, rect2.right-1, rect2.top, rect2.right-1, rect2.top+1 );
			gdi.DrawLine( &penPix2, rect2.right-1, rect2.bottom-1, rect2.right-2, rect2.bottom-1 );
			gdi.DrawLine( &penPix2, rect2.left,  rect2.bottom-1, rect2.left+1,  rect2.bottom-1 );
		}

		if( m_bMouseDown )
		{
			Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/3 );
			Gdiplus::Color colBrush1,colBrush2;
			colBrush1.SetValue( Gdiplus::Color::MakeARGB(15,1,1,1)  );
			colBrush2.SetValue( Gdiplus::Color::MakeARGB(0,1,1,1)  );

			LinearGradientBrush brush( rc, colBrush1, colBrush2,LinearGradientModeVertical );
			gdi.FillRectangle( &brush, rc );
		}
		else
		{
			Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/2 );
			rc.Inflate(-1,-1);
			LinearGradientBrush brush( rc, m_colBrush1, m_colBrush2,LinearGradientModeVertical );
			gdi.FillRectangle( &brush, rc );
		}

		return;
	}
	else if( m_enmuDrawType == NO_FRAME_SELECT )
	{
		Gdiplus::Pen pen1( m_colFrame1 );
		gdi.DrawLine( &pen1, rect.left+1, rect.top, rect.right-2, rect.top );
		gdi.DrawLine( &pen1, rect.left+1, rect.bottom-1, rect.right-2, rect.bottom-1 );
		gdi.DrawLine( &pen1, rect.left, rect.top+1, rect.left, rect.bottom-2 );
		gdi.DrawLine( &pen1, rect.right-1, rect.top+1, rect.right-1, rect.bottom-2 );

		Gdiplus::Color colpix;
		pen1.GetColor( &colpix );
		colpix.SetValue( Gdiplus::Color::MakeARGB(colpix.GetA()/2,colpix.GetR(),colpix.GetG(),colpix.GetB() ) );
		Gdiplus::Pen penPix1( colpix );
		gdi.DrawLine( &penPix1, rect.left, rect.top, rect.left+1, rect.top );
		gdi.DrawLine( &penPix1, rect.right-1, rect.top, rect.right-1, rect.top+1 );
		gdi.DrawLine( &penPix1, rect.right-1, rect.bottom-1, rect.right-2, rect.bottom-1 );
		gdi.DrawLine( &penPix1, rect.left,  rect.bottom-1, rect.left+1,  rect.bottom-1 );

		CRect rect2 = rect;
		::InflateRect( &rect2, -1,-1 );
		if( !m_bMouseDown )
		{
			Gdiplus::Pen pen2(m_colFrame2);
			if( m_bMouseDown )
				pen2.SetColor(m_colFrame1);
			else
				pen2.SetColor(m_colFrame2);

			gdi.DrawLine( &pen2, rect2.left+1, rect2.top, rect2.right-2, rect2.top );
			gdi.DrawLine( &pen2, rect2.left+1, rect2.bottom-1, rect2.right-2, rect2.bottom-1 );
			gdi.DrawLine( &pen2, rect2.left, rect2.top+1, rect2.left, rect2.bottom-2 );
			gdi.DrawLine( &pen2, rect2.right-1, rect2.top+1, rect2.right-1, rect2.bottom-2 );

			Gdiplus::Color colpix2;
			pen2.GetColor( &colpix2 );
			colpix2.SetValue( Gdiplus::Color::MakeARGB(colpix2.GetA()/2,colpix2.GetR(),colpix2.GetG(),colpix2.GetB() ) );
			Gdiplus::Pen penPix2( colpix2 );
			gdi.DrawLine( &penPix2, rect2.left, rect2.top, rect2.left+1, rect2.top );
			gdi.DrawLine( &penPix2, rect2.right-1, rect2.top, rect2.right-1, rect2.top+1 );
			gdi.DrawLine( &penPix2, rect2.right-1, rect2.bottom-1, rect2.right-2, rect2.bottom-1 );
			gdi.DrawLine( &penPix2, rect2.left,  rect2.bottom-1, rect2.left+1,  rect2.bottom-1 );
		}

	/*	if( m_bMouseDown )
		{
			Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/3 );
			Gdiplus::Color colBrush1,colBrush2;
			colBrush1.SetValue( Gdiplus::Color::MakeARGB(15,1,1,1)  );
			colBrush2.SetValue( Gdiplus::Color::MakeARGB(0,1,1,1)  );

			LinearGradientBrush brush( rc, colBrush1, colBrush2,LinearGradientModeVertical );
			gdi.FillRectangle( &brush, rc );
		}
		else
		{
			Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/2 );
			rc.Inflate(-1,-1);
			LinearGradientBrush brush( rc, m_colBrush1, m_colBrush2,LinearGradientModeVertical );
			gdi.FillRectangle( &brush, rc );
		}*/

		CRect rect3 = rect2;
		::InflateRect( &rect3, -1,-1 );
		Gdiplus::RectF rc( rect3.left, rect3.top, rect3.Width(), rect3.Height() );
		LinearGradientBrush brush( rc, m_colBK, m_colBK,LinearGradientModeVertical );
		gdi.FillRectangle( &brush, rc );

		Gdiplus::Color colBlack1 = Gdiplus::Color::MakeARGB(30,50,50,50);
		Gdiplus::Color colBlack2 = Gdiplus::Color::MakeARGB(15,50,50,50);
	    Gdiplus::RectF rc1( rect3.left, rect3.top+rect3.Height()/2, rect3.Width(), rect3.Height()/2 );
		LinearGradientBrush brush2( rc1, colBlack1, colBlack2,LinearGradientModeVertical );
		gdi.FillRectangle( &brush2, rc1 );
		return;
	}
	if( m_enmuDrawType == TOP_ARC )
	{
		Gdiplus::Pen pen1( m_colFrame1 );
		gdi.DrawLine( &pen1, rect.left+5, rect.top, rect.right-7, rect.top );
		gdi.DrawLine( &pen1, rect.left, rect.bottom-1, rect.right, rect.bottom-1 );
		gdi.DrawLine( &pen1, rect.left, rect.top+5, rect.left, rect.bottom-2 );
		gdi.DrawLine( &pen1, rect.right-1, rect.top+5, rect.right-1, rect.bottom-2 );

		CRect rect2 = rect;
		::InflateRect( &rect2, -1,-1 );
		if( !m_bMouseDown )
		{
			Gdiplus::Pen pen2(m_colFrame2);
			gdi.DrawLine( &pen2, rect2.left+4, rect2.top, rect2.right-5, rect2.top );
			gdi.DrawLine( &pen2, rect2.left, rect2.bottom-1, rect2.right-1, rect2.bottom-1 );
			gdi.DrawLine( &pen2, rect2.left, rect2.top+4, rect2.left, rect2.bottom-2 );
			gdi.DrawLine( &pen2, rect2.right-1, rect2.top+4, rect2.right-1, rect2.bottom-2 );

			Gdiplus::RectF rectLeftTop2;
			rectLeftTop2.X = rect2.left;
			rectLeftTop2.Y  = rect2.top;
			rectLeftTop2.Width = 6;
			rectLeftTop2.Height  = 6;
			gdi.DrawArc(  &pen2, rectLeftTop2,180,90 );

			Gdiplus::RectF rectRightTop2;
			rectRightTop2.X = rect2.right-7;
			rectRightTop2.Y  = rect2.top;
			rectRightTop2.Width = 6;
			rectRightTop2.Height  = 6;
			gdi.DrawArc(  &pen2, rectRightTop2,270,90 );
		}

		Gdiplus::RectF rectLeftTop;
		rectLeftTop.X = rect.left;
		rectLeftTop.Y  = rect.top;
		rectLeftTop.Width = 9;
		rectLeftTop.Height  = 9;
		gdi.DrawArc(  &pen1, rectLeftTop,180,90 );

		Gdiplus::RectF rectRightTop;
		rectRightTop.X = rect.right-10;
		rectRightTop.Y  = rect.top;
		rectRightTop.Width = 9;
		rectRightTop.Height  = 9;
		gdi.DrawArc(  &pen1, rectRightTop,270,90 );

		/*Gdiplus::SolidBrush sb( m_colBrush );
		Gdiplus::Brush *pbrush = sb.Clone();*/
		if( m_bMouseDown )
		{
			Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/3 );
			Gdiplus::Color colBrush1,colBrush2;
			colBrush1.SetValue( Gdiplus::Color::MakeARGB(15,1,1,1)  );
			colBrush2.SetValue( Gdiplus::Color::MakeARGB(0,1,1,1)  );

			LinearGradientBrush brush( rc, colBrush1, colBrush2,LinearGradientModeVertical );
			gdi.FillRectangle( &brush, rc );
		}
		else
		{
			Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/2 );
			rc.Inflate(-1,-1);
			LinearGradientBrush brush( rc, m_colBrush1, m_colBrush2,LinearGradientModeVertical );
			gdi.FillRectangle( &brush, rc );
		}
	}
	else if( m_enmuDrawType == BOTTON_ARC )
	{
	}
	else if( m_enmuDrawType == RIGHT_ARC )
	{
	}
	else if( m_enmuDrawType == LEFT_ARC )
	{
	}
	else if( m_enmuDrawType & (TOP_ARC|BOTTON_ARC) || m_enmuDrawType & (RIGHT_ARC|LEFT_ARC) )
	{
		// 四角都有弧线
	}

	//gdi.DrawString(
}
Ejemplo n.º 11
0
D2D1_COLOR_F ToColorF(const Gdiplus::Color& color)
{
	return D2D1::ColorF(color.GetR() / 255.0f, color.GetG() / 255.0f, color.GetB() / 255.0f, color.GetA() / 255.0f);
}
Ejemplo n.º 12
0
void SelectionHandler::Draw(CDC& offscreenDC)
{
  if (m_selectionState == selstateNoSelection) return;

  COORD coordStart;
  COORD coordEnd;
  SHORT maxX = (m_consoleParams->dwBufferColumns > 0) ?
    static_cast<SHORT>(m_consoleParams->dwBufferColumns - 1) :
    static_cast<SHORT>(m_consoleParams->dwColumns - 1);

  GetSelectionCoordinates(coordStart, coordEnd);

  SMALL_RECT& srWindow = m_consoleInfo->csbi.srWindow;

  if(   coordEnd.Y < srWindow.Top    ||
      coordStart.Y > srWindow.Bottom ) return;

  INT nXStart = (static_cast<INT>(coordStart.X) - static_cast<INT>(srWindow.Left)) * m_nCharWidth  + m_nVInsideBorder;
  INT nYStart = (static_cast<INT>(coordStart.Y) - static_cast<INT>(srWindow.Top) ) * m_nCharHeight + m_nHInsideBorder;
  INT nXEnd   = (static_cast<INT>(  coordEnd.X) - static_cast<INT>(srWindow.Left)) * m_nCharWidth  + m_nVInsideBorder;
  INT nYEnd   = (static_cast<INT>(  coordEnd.Y) - static_cast<INT>(srWindow.Top) ) * m_nCharHeight + m_nHInsideBorder;
  INT nXmin   = (static_cast<INT>(0)            - static_cast<INT>(srWindow.Left)) * m_nCharWidth  + m_nVInsideBorder;
  INT nXmax   = (static_cast<INT>(maxX)         - static_cast<INT>(srWindow.Left)) * m_nCharWidth  + m_nVInsideBorder;

  Gdiplus::Graphics gr(offscreenDC);

  Gdiplus::Color selectionColor;
  selectionColor.SetFromCOLORREF(g_settingsHandler->GetAppearanceSettings().stylesSettings.crSelectionColor);
  Gdiplus::Pen        pen  (selectionColor);
  Gdiplus::SolidBrush brush(Gdiplus::Color(64,  selectionColor.GetR(), selectionColor.GetG(), selectionColor.GetB()));
  Gdiplus::GraphicsPath gp;

  if( nYStart == nYEnd )
  {
    Gdiplus::Rect rect(
      nXStart,
      nYStart,
      (nXEnd - nXStart) + m_nCharWidth,
      m_nCharHeight);
    gp.AddRectangle(rect);
  }
  else
  {
    /*
           2_________3
    0______|         |
    |      1     5___|
    |____________|   4
    7            6
    */

    Gdiplus::Point points[8];

    points[0].X = nXmin;
    points[0].Y = nYStart + m_nCharHeight;

    points[1].X = nXStart;
    points[1].Y = points[0].Y;

    points[2].X = points[1].X;
    points[2].Y = nYStart;

    points[3].X = nXmax + m_nCharWidth;
    points[3].Y = points[2].Y;

    points[4].X = points[3].X;
    points[4].Y = nYEnd;

    points[5].X = nXEnd + m_nCharWidth;
    points[5].Y = points[4].Y;

    points[6].X = points[5].X;
    points[6].Y = nYEnd + m_nCharHeight;

    points[7].X = points[0].X;
    points[7].Y = points[6].Y;

    gp.AddPolygon(points, 8);
  }

  gr.FillPath(&brush, &gp);
  gr.DrawPath(&pen, &gp);
}
Ejemplo n.º 13
0
Color Pen::GetColor() const {
    Gdiplus::Pen* gdiPen = reinterpret_cast<Gdiplus::Pen*>(_private);
    Gdiplus::Color gdiColor;
    gdiPen->GetColor(&gdiColor);
    return Color(gdiColor.GetA(), gdiColor.GetR(), gdiColor.GetG(), gdiColor.GetB());
}