示例#1
0
void ColorSample::setColor(KrRGBA color) 
{
	KrRGBA *pixels = getCanvasResource()->Pixels();
	int width = Actor::Width(), height = Actor::Height();

	r = color.c.red; 
	g = color.c.green; 
	b = color.c.blue; 
	color.c.alpha = 255;

	for(int i = 0; i < width; i++)
	{
		for(int j = 0; j < height; j++)
		{
			pixels[ j*width + i ] = color;			
		}
	}

	getCanvasResource()->Refresh();

	if(rEdit)
	{
		rEdit->SetText(r);
		gEdit->SetText(g);
		bEdit->SetText(b);
	}
}
示例#2
0
bool ColorCanvas::OnMouseButtonDown(int x, int y, Uint8 button)
{
	KrVector2T< GlFixed > object;
	getImage()->ScreenToObject( x, y, &object );

	KrRGBA *pixels = getCanvasResource()->Pixels(), color;
	color = pixels[ object.y.ToInt()*Width() + object.x.ToInt() ];

	((ColorPicker *)getParent())->SetColor(color.c.red, color.c.green, color.c.blue);
	SetPointer(object.x.ToInt(), object.y.ToInt());

	canPick = true;

	getCanvasResource()->Refresh();
	return false;
}
示例#3
0
void ColorCanvas::OnMouseMove(int x, int y)
{
	if(canPick)
	{
		KrVector2T< GlFixed > object;
		getImage()->ScreenToObject( x, y, &object );

		if(object.x >= 0 && object.y >= 0 && object.x < Width() && object.y < Height())
		{
			KrRGBA *pixels = getCanvasResource()->Pixels(), color;
			color = pixels[ object.y.ToInt()*Width() + object.x.ToInt() ];
			
			((ColorPicker *)getParent())->SetColor(color.c.red, color.c.green, color.c.blue);
			SetPointer(object.x.ToInt(), object.y.ToInt());

			getCanvasResource()->Refresh();
		}
	}
}
示例#4
0
ColorSampleOfPicker::ColorSampleOfPicker(Actor *parent)
	: Actor(getRandomName(), parent, CANVAS, 104, 32)
{
	KrRGBA *pixels = getCanvasResource()->Pixels(), color;
	color.Set(255, 255, 255, 255);

	for(int i = 0; i < Width(); i++)
	{
		for(int j = 0; j < Height(); j++)
		{
			pixels[ j*Width() + i ] = color;			
		}
	}
}
示例#5
0
int Panel::DrawHLine(int y, int xi, int w)
{
	int height = getCanvasResource()->Height(),
		 width = getCanvasResource()->Width();

	
	
	if(y < 0 || y >= height - 4)
		return y;

	if(w <= 0) w = width;

	if(flags.IsSet(FLAG_HASSHADOWS))
	{
		w -= SHADOW_THICKNESS;		
	}

	if(firstHorizontalLine == -1) firstHorizontalLine = y;

	KrRGBA *pixels = getCanvasResource()->Pixels();

	for(int i = xi; i < w; i++)
	{
		if(i < width - 1) pixels[ y*width + i ] = colorDown;
		
		pixels[ (y+1)*width + i ] = colorDown;
		pixels[ (y+2)*width + i ] = colorUp;

		if(i > 0) pixels[ (y+3)*width + i ] = colorUp;
	}

	//Call set focus here: solve the Tutorial key loss
	SetFocus(0);

	getCanvasResource()->Refresh();
	return y + 8;
}
示例#6
0
ActorTip::ActorTip(const gedString *tip)
	: Actor(ACTOR_TIP_NAME, NULL, CANVAS, Text::GetDimensions(*tip).Width() + 6, Text::GetDimensions(*tip).Height() + 4, true)
{
	getImage()->SetZDepth(CURSOR_DEPTH - 1);

	int x = GameControl::Get()->getMouseX() + 20, 
		y = GameControl::Get()->getMouseY() + 20, 
		width = Width(), 
		height = Height();

	if(x + width > GameControl::Get()->Width())
		x -= x + width - GameControl::Get()->Width();

	if(y + height > GameControl::Get()->Height())
		y -= y + height - GameControl::Get()->Height();

	getImage()->SetPos(x, y);

	
	//Draw
	KrRGBA *pixels = getCanvasResource()->Pixels(), colorBack, colorBlack;

	colorBack.c.red		= 255;
	colorBack.c.green	= 255;
	colorBack.c.blue	= 225;
	colorBack.c.alpha	= 255;

	colorBlack.Set(0, 0, 0);

	//Fill background
	int i;
	for(i = 0; i < width; i++)
	{
		for(int j = 0; j < height; j++)
		{
			if(i == 0 || j == 0 || i == width-1 || j == height - 1)
				pixels[ j*width + i ] = colorBlack;
			else
				pixels[ j*width + i ] = colorBack;
		}
	}

	//Text
	AddText(*tip, 3, 2);

	SetTransparency(.1);
}
示例#7
0
ColorPointer::ColorPointer(Actor *parent)
	: Actor("PointerColorPickerCanvas", parent, CANVAS, 11, 11)
{
	//Create pointer
	KrRGBA *pixels = getCanvasResource()->Pixels(), black, white, color;
	black.Set(0, 0, 0, 255);
	white.Set(255, 255, 255, 255);
	color.Set(0, 0, 0, 0);

	int i;
	for(i = 0; i < Width(); i++)
	{
		for(int j = 0; j < Height(); j++)
		{
			pixels[ j*Width() + i ] = color;			
		}
	}

	for(i = 0; i < Width(); i++)
	{
		if(i != Width()/2)
		{
			color = (i % 2)?black:white;
			pixels[ (Height()/2)*Width() + i ] = color;					
		}
	}

	for(int j = 0; j < Height(); j++)
	{
		if(j != Height() /2)
		{
			color = (j % 2)?black:white;
			pixels[ j*Width() + (Width()/2) ] = color;			
		}
	}
}
示例#8
0
void Panel::Draw() 
{
	//Draw panel
	KrRGBA *pixels = getCanvasResource()->Pixels();
	ColorScheme* cs = get_color_scheme();
	int width = Width(), height = Height();

	if(flags.IsSet(FLAG_HASSHADOWS))
	{
		  width -= SHADOW_THICKNESS;
		  height -= SHADOW_THICKNESS;
	}

	if(bInvertBevel)
	{
		KrRGBA aux;
		aux = colorUp;
		colorUp = colorDown;
		colorDown = aux;
	}
		

	//Fill background
	int i, j;
	
	for(j = 0; j < height; j++)
	{
		KrRGBA color(SlowCanvas::MixColors(Panel::getColorUp(), Panel::getColorDown(), j/(double)height));
		for(i = 0; i < width; i++)
		{
			pixels[ j*Width() + i ] = color;
		}
	}

	
	//Glass effect
	if(height < 55)
	{
		KrRGBA glass(cs->editor_glass_r, cs->editor_glass_g, cs->editor_glass_b);
		int hm = height/2;
		for(j = 0; j < hm; j++)
		{
			for(i = 0; i < width; i++)
			{
				pixels[ j*Width() + i ] = SlowCanvas::MixColors(pixels[ j*Width() + i ], glass, .8*j/(double)hm);
			}
		}
	}

	KrRGBA colorBorder(cs->editor_border_r, cs->editor_border_g, cs->editor_border_b);	

		//Horizontal lines
		for(i = 0; i < width; i++)
		{
			pixels[  i ] = colorBorder;	
			pixels[ (height-1)*Width() + i ] = colorBorder;
		}
		
		//Vertical lines
		for(j = 0; j < height; j++)
		{
			pixels[ j*Width() ] = colorBorder;		
			pixels[ j*Width() + (width-1) ] = colorBorder;
		}

	//Corner pixels
	pixels[ 1 + 1*Width() ] = colorBorder;
	pixels[ (width - 2) + 1*Width() ] = colorBorder;
	pixels[ (width - 2) + (height - 2)*Width() ] = colorBorder;
	pixels[ 1 + (height - 2)*Width() ] = colorBorder;


	

	//Restore colors
	if(bInvertBevel)
	{
		KrRGBA aux;
		aux = colorUp;
		colorUp = colorDown;
		colorDown = aux;
	}

	//Make trasparent corners
	KrRGBA transp(0, 0, 0, 0);

	pixels[ 0 + 0*Width() ] = transp;
	pixels[ 1 + 0*Width() ] = transp;
	pixels[ 0 + 1*Width() ] = transp;

	pixels[ (width - 1) + 0*Width() ] = transp;
	pixels[ (width - 2) + 0*Width() ] = transp;
	pixels[ (width - 1) + 1*Width() ] = transp;

	if(!flags.IsSet(FLAG_HASSHADOWS))
	{
		pixels[ (width - 1) + (height - 1)*Width() ] = transp;
		pixels[ (width - 2) + (height - 1)*Width() ] = transp;
		pixels[ (width - 1) + (height - 2)*Width() ] = transp;
	}

	pixels[ 0 + (height - 1)*Width() ] = transp;
	pixels[ 1 + (height - 1)*Width() ] = transp;
	pixels[ 0 + (height - 2)*Width() ] = transp;

	if(flags.IsSet(FLAG_HASSHADOWS))
	{
		KrRGBA colorShadow;	
		double shadowFactor;
			
		colorShadow.c.red	= cs->editor_shadow_r;
		colorShadow.c.green	= cs->editor_shadow_g;
		colorShadow.c.blue	= cs->editor_shadow_b;
		colorShadow.c.alpha	= SHADOW_MAX;

		//Corner
		pixels[ (width - 1) + (height - 1)*Width() ] = colorShadow;
		pixels[ (width - 2) + (height - 1)*Width() ] = colorShadow;
		pixels[ (width - 1) + (height - 2)*Width() ] = colorShadow;
		
		//Vertical shadow
		for(i = width; i < Width(); i++)
		{
			for(int j = SHADOW_THICKNESS; j < Height(); j++)
			{
				shadowFactor = 1.0 - (i - width)/(double)SHADOW_THICKNESS;
				shadowFactor *= (j >= height)?(1.0 - (j - height)/(double)SHADOW_THICKNESS):1.0;
				shadowFactor *= (j - SHADOW_THICKNESS < SHADOW_FADE)?(j - SHADOW_THICKNESS)/(double)SHADOW_FADE:1.0;

				colorShadow.c.alpha	= SHADOW_MAX*shadowFactor;

				pixels[ j*Width() + i ] = colorShadow;
			}
		}
		
		//Horizontal shadow
		for(i = SHADOW_THICKNESS; i < Width() - SHADOW_THICKNESS; i++)
		{
			for(int j = height; j < Height(); j++)
			{
				shadowFactor = 1.0 - (j - height)/(double)SHADOW_THICKNESS;
				shadowFactor *= (i - SHADOW_THICKNESS < SHADOW_FADE)?(i - SHADOW_THICKNESS)/(double)SHADOW_FADE:1.0;

				colorShadow.c.alpha	= SHADOW_MAX*shadowFactor;

				pixels[ j*Width() + i ] = colorShadow;
			}
		}
	}

	

	getCanvasResource()->Refresh();
}