void VisualColorControl::AttachedToWindow()
{
	BPoint *points = new BPoint[3];
	points[0] = BPoint(0,0);
	points[1] = BPoint(-4,-4);
	points[2] = BPoint(4,-4);

	// calculate the initial ramps
	CalcRamps();

	// create the arrow-pictures
	BeginPicture(new BPicture());
		SetHighColor(100,100,255);
		FillPolygon(points,3);
		SetHighColor(0,0,0);
		StrokePolygon(points,3);
	down_arrow = EndPicture();

	if (Parent() != NULL)
		SetViewColor(Parent()->ViewColor());

	BStringView *sv = new BStringView(BRect(0,COLOR_HEIGHT/2,1,COLOR_HEIGHT/2),"label view",label1);
	AddChild(sv);
	float sv_width = sv->StringWidth(label1);
	sv_width = max_c(sv_width,sv->StringWidth(label2));
	sv_width = max_c(sv_width,sv->StringWidth(label3));
	font_height fHeight;
	sv->GetFontHeight(&fHeight);
	sv->ResizeTo(sv_width,fHeight.ascent+fHeight.descent);
	sv->MoveBy(0,-(fHeight.ascent+fHeight.descent)/2.0);
	BRect sv_frame = sv->Frame();
	sv_frame.OffsetBy(0,COLOR_HEIGHT);
	sv->SetAlignment(B_ALIGN_CENTER);
	sv = new BStringView(sv_frame,"label view",label2);
	AddChild(sv);
	sv->SetAlignment(B_ALIGN_CENTER);
	sv_frame.OffsetBy(0,COLOR_HEIGHT);
	sv = new BStringView(sv_frame,"label view",label3);
	AddChild(sv);
	sv->SetAlignment(B_ALIGN_CENTER);
	sv_frame.OffsetBy(0,COLOR_HEIGHT);
	sv = new BStringView(sv_frame,"label view",label4);
	AddChild(sv);
	sv->SetAlignment(B_ALIGN_CENTER);

	ramp_left_edge = sv->Bounds().IntegerWidth()+2;

	ResizeBy(ramp_left_edge,0);

	delete[] points;
}
void
GameView::Draw(BRect rect)
{
	SetDrawingMode(B_OP_ALPHA);
	
	// Draw slots
	BPoint deckPoints[]={ BPoint(-80,4),BPoint(-80,116),BPoint(0,116),
		BPoint(0,4)};
	BPolygon* deck;
	
	for (int i=0;i<8;i++) {
		if (i==4) {
			for (int j=0;j<4;j++) {
				deckPoints[j].x+=80+4;
			}
		}
		for (int j=0;j<4;j++) {
			deckPoints[j].x+=80+4;
		}
		deck=new BPolygon(deckPoints,4);
		
		StrokePolygon(deck);
		
		if (board[i]!=NULL) {
			DrawBitmap(board[i]->img,deck->Frame());
		}
	}
	// Draw cards
	short row=0;
	short stack=0;
	
	for (short i=8;i<200;i++) {
		BBitmap* img=NULL;
		if (board[i]!=NULL) {
			img=board[i]->img;
		}
		BPoint pt(85*(stack+1),40*(row+4));
		DrawBitmapAsync(img,pt);
		row++;
		if (row==26) {
			row=0;
			stack++;
		}
	}
	Sync();
	
	// Draw Points
	
	BString movesText="";
	movesText << moves;
	
	BFont bigFont;
	bigFont.SetFace(B_BOLD_FACE);
	bigFont.SetSize(18);
	
	BFont smallFont;
	smallFont.SetSize(12);
	
	SetHighColor(255,255,255);

	SetFont(&bigFont);
	DrawString(movesText, BPoint((width+10 - bigFont.StringWidth(movesText)) / 2, height-15));

	SetFont(&smallFont);
	DrawString("Moves", BPoint((width+10   - smallFont.StringWidth("Moves")) / 2, height));
}
Example #3
0
void
WebSafeSelector::Draw(BRect updateRect)
{
	ColorSelector::Draw(updateRect);

	if (fIsHidden) {
		SetHighColor(ViewColor());
		FillRect(updateRect);
		return;
	}

	if (updateRect.Intersects(INDICATOR_RECT)) {
		rgb_color black = (rgb_color){ 0, 0, 0 };
		rgb_color light;
		rgb_color medium;
		rgb_color dark;

		if (fMouseOver) {
			light  = (rgb_color){ 0, 255, 0, 255 };
			medium = (rgb_color){ 255, 0, 0, 255 };
			dark   = (rgb_color){ 0, 0, 255, 255 };
		} else {
			light  = tint_color(black, B_LIGHTEN_MAX_TINT);
			medium = tint_color(black, B_LIGHTEN_2_TINT);
			dark   = tint_color(black, B_LIGHTEN_1_TINT);
		}

		BRect bounds = INDICATOR_RECT;

		BPoint pointList[4];
		pointList[0] = bounds.LeftTop() + BPoint(0, 3);
		pointList[1] = bounds.LeftTop() + BPoint(0, 9);
		pointList[2] = bounds.LeftTop() + BPoint(5, 12);
		pointList[3] = bounds.LeftTop() + BPoint(5, 6);

		BPolygon* rhombus1 = new BPolygon(pointList, 4);
		SetHighColor(dark);
		FillPolygon(rhombus1);
		SetHighColor(black);
		StrokePolygon(rhombus1);
		delete rhombus1;

		pointList[0] = bounds.LeftTop() + BPoint(5, 6);
		pointList[1] = bounds.LeftTop() + BPoint(5, 12);
		pointList[2] = bounds.LeftTop() + BPoint(10, 9);
		pointList[3] = bounds.LeftTop() + BPoint(10, 3);

		BPolygon* rhombus2 = new BPolygon(pointList, 4);
		SetHighColor(light);
		FillPolygon(rhombus2);
		SetHighColor(black);
		StrokePolygon(rhombus2);
		delete rhombus2;

		pointList[0] = bounds.LeftTop() + BPoint(0, 3);
		pointList[1] = bounds.LeftTop() + BPoint(5, 6);
		pointList[2] = bounds.LeftTop() + BPoint(10, 3);
		pointList[3] = bounds.LeftTop() + BPoint(5, 0);

		BPolygon* rhombus3 = new BPolygon(pointList, 4);
		SetHighColor(medium);
		FillPolygon(rhombus3);
		SetHighColor(black);
		StrokePolygon(rhombus3);
		delete rhombus3;
	}
}
/*=============================================================================================*\
|	Draw																						|
+-----------------------------------------------------------------------------------------------+
|	Effet: Redessiner une partie de la view.													|
|	Entre: 																						|
|		BRect frame: Rectagle qui a besoin d'etre redessine.									|
\*=============================================================================================*/
void ShrinkView::Draw(BRect updateRect)
{
	BPoint pPointList[8];		//Utilise pour dessiner les polygone.
	rgb_color color = {0,0,0,0};
	rgb_color colorHigh = {0,0,0,0};
	
	SetDrawingMode(B_OP_COPY);
	if(m_pBmp)
	{
		uint32 * uiBits = (uint32*)m_pBmp->Bits();
		uint32 uiColor = uiBits[141];
		uint32 uiColorHigh = uiBits[289];
		
		color.red = ( uiColor & 0xFF0000) / 0x10000;
		color.green = (uiColor & 0xFF00) / 0x100;
		color.blue = (uiColor & 0xFF) ;
		colorHigh.red = ( uiColorHigh & 0xFF0000) / 0x10000;
		colorHigh.green = (uiColorHigh & 0xFF00) / 0x100;
		colorHigh.blue = (uiColorHigh & 0xFF) ;
			
	}

	//if(updateRect.left < 10)
	{
		if(m_pBmp)
		{
			DrawBitmap(m_pBmp, BRect(140,15,147,15), BRect(Bounds().Width() - 7, 16, Bounds().Width(), Bounds().Height() - 7));				 
		}

	}
	//if(updateRect.right > Bounds().Width()-10)
	{
		if(m_pBmp)
		{
			DrawBitmap(m_pBmp, BRect(140,14,147,14), BRect(0, 16, 7, Bounds().Height() - 7));

		}
	}
	
	
	//Dessiner l'etiquette si necessaire.
	if(updateRect.top < 16 && updateRect.right >= 16)
	{
		
		if(m_pBmp)
		{
			
			if(m_bShrink && m_bMouseOver)
			{
				DrawBitmap(m_pBmp, BRect(80,0,95,15), BRect(Bounds().Width() - 15,0,Bounds().Width(),15));
				DrawBitmap(m_pBmp, BRect(137,0,137,15), BRect(16, 0, Bounds().Width() - 15, 15)); 
			}
			else if(m_bShrink)
			{
				DrawBitmap(m_pBmp, BRect(64,0,79,15), BRect(Bounds().Width() - 15,0,Bounds().Width(),15));
				DrawBitmap(m_pBmp, BRect(136,0,136,15), BRect(16, 0, Bounds().Width() - 15, 15)); 
			}
			else if(m_bMouseOver)
			{
				DrawBitmap(m_pBmp, BRect(112,0,127,15), BRect(Bounds().Width() - 15,0,Bounds().Width(),15));
				DrawBitmap(m_pBmp, BRect(139,0,139,15), BRect(16, 0, Bounds().Width() - 15, 15)); 
			}
			else
			{
				DrawBitmap(m_pBmp, BRect(96,0,111,15), BRect(Bounds().Width() - 15,0,Bounds().Width(),15));
				DrawBitmap(m_pBmp, BRect(138,0,138,15), BRect(16, 0, Bounds().Width() - 15 , 15)); 
			}
			SetFont(be_bold_font);
					
			if(m_bMouseOver)
			{
				SetHighColor(colorHigh);
			}
			else
			{
				SetHighColor(color);
			}	
			SetDrawingMode(B_OP_OVER);
			DrawString(m_pzLabel, BPoint(18,12), NULL);	
			SetDrawingMode(B_OP_COPY);	
		}
		else
		{
			if(m_bShrink)
			{
				DrawDegrader(BRect(16,0,Bounds().Width(),4), 255, 192);
				DrawDegrader(BRect(16,11,Bounds().Width(),15), 192, 128);
			
				//Remplir le milieu de l'etiquette en gris
				SetHighColor(192, 192, 192, 0);
				FillRect(BRect(16, 5, Bounds().Width(), 10));
			}
			else	//Degrader du blanc au gris
			{
				DrawDegrader(BRect(16,0,Bounds().Width(),15), 255, 192);
			}
			SetFont(be_bold_font);
			SetHighColor(0, 0, 0, 0);
			SetDrawingMode(B_OP_OVER);
			DrawString(m_pzLabel, BPoint(18,12), NULL);
		}
	}
		
	//Redessiner le boutton si nessesaire.
	if(updateRect.left < 16 && updateRect.top < 16)
	{
		if(m_pBmp)
		{
			if(m_bShrink && m_bMouseOver)
			{
				DrawBitmap(m_pBmp, BRect(16,0,31,15), BRect(0,0,15,15));
			}
			else if(m_bShrink)
			{
				DrawBitmap(m_pBmp, BRect(0,0,15,15), BRect(0,0,15,15));
			}
			else if(m_bMouseOver)
			{
				DrawBitmap(m_pBmp, BRect(48,0,63,15), BRect(0,0,15,15));
			}
			else
			{
				DrawBitmap(m_pBmp, BRect(32,0,47,15), BRect(0,0,15,15));
			}
		
		}
		else
		{
			//Redessiner le degrader
			if(m_bShrink)
			{
				DrawDegrader(BRect(0, 0, 16, 4), 255, 192);
				DrawDegrader(BRect(0, 11, 16, 15), 192, 128);
			
				//Remplir le milieu de l'etiquette en gris
				SetHighColor(192, 192, 192, 0);
				FillRect(BRect(0, 5, 15, 10));
			}
			else	//Degrader du blanc au gris
			{
				DrawDegrader(BRect(0,0,15,15), 255, 192);
			}
		
			//Dessiner le Boutton si le curseur est au dessus du triangle.
			if( m_bMouseOver)
			{	
			SetHighColor(64, 64, 64, 0);
				pPointList[0] = BPoint(1,3);
				pPointList[1] = BPoint(3,1);
				pPointList[2] = BPoint(12,1);
				pPointList[3] = BPoint(14,3);
				pPointList[4] = BPoint(14,12);
				pPointList[5] = BPoint(12,14);
				pPointList[6] = BPoint(3,14);
				pPointList[7] = BPoint(1,12);
				StrokePolygon(pPointList, 8, true,  B_SOLID_HIGH);	
		
				SetHighColor(255, 255, 255, 0);
				pPointList[0] = BPoint(2,12);
				pPointList[1] = BPoint(2,3);
				pPointList[2] = BPoint(3,2);
				pPointList[3] = BPoint(12,2);
				StrokePolygon(pPointList, 4, false,  B_SOLID_HIGH);	
		
				SetHighColor(192, 192, 192, 0);
				pPointList[0] = BPoint(3,3);
				pPointList[1] = BPoint(12,3);
				pPointList[2] = BPoint(12,12);
				pPointList[3] = BPoint(3,12);
				FillPolygon(pPointList, 4,  B_SOLID_HIGH);	
		
				SetHighColor(128, 128, 128, 0);
				pPointList[0] = BPoint(13,3);
				pPointList[1] = BPoint(13,12);
				pPointList[2] = BPoint(12,13);
				pPointList[3] = BPoint(3,13);
				StrokePolygon(pPointList, 4, false,  B_SOLID_HIGH);	
			}
	
			//Dessiner le triangle vers la droite.
			// La View est reduite.
			if(m_bShrink)
			{
			SetHighColor(0, 0, 0, 256);
				pPointList[0] = BPoint(9,7);
				pPointList[1] = BPoint(6,4);
				pPointList[2] = BPoint(6,11);
				pPointList[3] = BPoint(9,8);
				FillPolygon(pPointList, 4, B_SOLID_HIGH);
			}
			//Dessiner le triangle vers le bas.
			// La View est agrandi.
			else
			{
				SetHighColor(0, 0, 0, 256);
				pPointList[0] = BPoint(7,9);
				pPointList[1] = BPoint(4,6);
				pPointList[2] = BPoint(11,6);
				pPointList[3] = BPoint(8,9);
				FillPolygon(pPointList, 4, B_SOLID_HIGH);
			}
		}
	}
	
	//Redessiner le degrader du bas si necessaire
	if(!m_bShrink && updateRect.bottom > Bounds().Height() - 8)
	{
		if(m_pBmp)
		{
			DrawBitmap(m_pBmp, BRect(128,0,135,7), BRect(0,Bounds().Height()-7,7,Bounds().Height()));
			DrawBitmap(m_pBmp, BRect(128,8,135,15), BRect(Bounds().Width() - 7,Bounds().Height()-7,Bounds().Width(),Bounds().Height()));
			DrawBitmap(m_pBmp, BRect(140,0,140,7), BRect(8, Bounds().Height()-7, Bounds().Width() - 7, Bounds().Height())); 
		}
		else
		{
			DrawDegrader(BRect(0,Bounds().bottom - 8,Bounds().Width(),Bounds().bottom), 192, 128);
		}
	} 
}//End of Draw.
/*=============================================================================================*\
|	Draw																						|
+-----------------------------------------------------------------------------------------------+
|	Effet: Redessine la view selon son status.													|
|																								|
\*=============================================================================================*/
void BeNetButton::Draw(BRect updateRect)
{
	BPoint pPointList[8];
	BPoint cursor;
	uint32 iButton;
	float leftBmp = 0;
	float topBmp = 0;
	float leftLab = 0;
	float topLab = 0;
	bool m_bBorderIn = false;
	bool m_bBorderOut = false;
	BFont font;
	
	GetMouse(&cursor, &iButton);
	
	m_bMouseOver = false;
	if(cursor.x >= 0 && cursor.x < Bounds().Width() && cursor.y >= 0 && cursor.y < Bounds().Height())
	{
		m_bMouseOver = true;
	}

	
	//Mode de dessinement utilisant seulement des bitmap.
	if(m_iDrawMode == BENET_DM_FULL_BMP || (m_iDrawMode == BENET_DM_TOGGLE && !m_bToggle))
	{
		SetDrawingMode(B_OP_COPY);
		//Le bouton est disable.
		if(!IsEnabled())
		{
			DrawBitmap(m_pBitmap, BRect(3 * Bounds().Width(),0, 4 * Bounds().Width()-1,Bounds().Height()-1), BRect(0,0,Bounds().Width()-1,Bounds().Height()-1));
		}	
	
		//Le boutton est enfoncer
		else if(Value())
		{
			DrawBitmap(m_pBitmap, BRect(2 * Bounds().Width(),0, 3 * Bounds().Width()-1,Bounds().Height()-1), BRect(0,0,Bounds().Width()-1,Bounds().Height()-1));
		}
		//La sourie est par dessus le bouton.
		else if(m_bMouseOver)
		{
			DrawBitmap(m_pBitmap, BRect(Bounds().Width(),0, 2 * Bounds().Width()-1,Bounds().Height()-1), BRect(0,0,Bounds().Width()-1,Bounds().Height()-1));
		}
		//boutton par defaut
		else
		{
			DrawBitmap(m_pBitmap, BRect(0,0,Bounds().Width()-1,Bounds().Height()-1), BRect(0,0,Bounds().Width()-1,Bounds().Height()-1));
		}

	}
	else if(m_iDrawMode == BENET_DM_TOGGLE && m_bToggle)
	{
		SetDrawingMode(B_OP_COPY);		//Le bouton est disable.
		if(!IsEnabled())
		{
			DrawBitmap(m_pBitmap, BRect(3 * Bounds().Width(),Bounds().Height(), 4 * Bounds().Width()-1,Bounds().Height()*2-1), BRect(0,0,Bounds().Width()-1,Bounds().Height()-1));
		}	
	
		//Le boutton est enfoncer
		else if(Value())
		{
			DrawBitmap(m_pBitmap, BRect(2 * Bounds().Width(),Bounds().Height(), 3 * Bounds().Width()-1,Bounds().Height()*2-1), BRect(0,0,Bounds().Width()-1,Bounds().Height()-1));
		}
		//La sourie est par dessus le bouton.
		else if(m_bMouseOver)
		{
			DrawBitmap(m_pBitmap, BRect(Bounds().Width(),Bounds().Height(), 2 * Bounds().Width()-1,Bounds().Height()*2-1), BRect(0,0,Bounds().Width()-1,Bounds().Height()-1));
		}
		//boutton par defaut
		else
		{
			DrawBitmap(m_pBitmap, BRect(0,Bounds().Height(),Bounds().Width()-1,Bounds().Height()*2-1), BRect(0,0,Bounds().Width()-1,Bounds().Height()-1));
		}


	}
	

	
	///////////////////////////
	
	// Debut de l'ancient mode de dessinement.
	else if(m_iDrawMode == BENET_DM_DEFAULT)
	{
		//Aller chercher les propriete du font.
		GetFont(&font);		
		font_height height;
		font.GetHeight(&height);
		
		//Trouver le coin superieur gauche du bitmap.
		if(m_bLabel)
		{
			topBmp = 2;
		}
		else
		{
			if(m_bBitmap)topBmp= Bounds().Height() / 2 - m_pBitmap->Bounds().Height() / 2; 
		}
		if(m_bBitmap)leftBmp = Bounds().Width() / 2 - m_pBitmap->Bounds().Width() / 2;
		
		//Trouver le coin inferieur gauche de lu label.
		if(m_bBitmap)
		{
			topLab = Bounds().Height() -2 - height.descent;
		}
		else
		{
			topLab = Bounds().Height() / 2 + font.Size() / 2;
		}
		leftLab = Bounds().Width() / 2 - StringWidth(m_pzLabel) / 2;
		
		
		//Le bouton est disable.
		// Il est a 25% d'intensite.
		if(!IsEnabled())
		{
			SetHighColor(192,192,192,0);
			FillRect(BRect(0,0,Bounds().Width(), Bounds().Height()));
			SetDrawingMode(B_OP_BLEND);
			if(m_bBitmap)
			{
				DrawBitmap(m_pBitmap, BPoint(leftBmp,topBmp));
			}
			if(m_bLabel)
			{
				SetHighColor(0, 0, 0, 0);
				DrawString(m_pzLabel, BPoint(leftLab,topLab));
			}
			SetHighColor(192,192,192,0);
			FillRect(BRect(0,0,Bounds().Width(), Bounds().Height()));
			SetDrawingMode(B_OP_COPY);
		}	
	
		//Le boutton est enfoncer
		// les couleur du boutton sont inverser.
		else if(Value())
		{
			SetHighColor(192, 192, 192, 0);
			FillRect(BRect(2,2,Bounds().Width()-2, Bounds().Height()-2));
			if(m_bBitmap)
			{
				DrawBitmap(m_pBitmap, BPoint(leftBmp,topBmp));
			}
			if(m_bLabel)
			{
				SetHighColor(0, 0, 0, 0);
				DrawString(m_pzLabel, BPoint(leftLab,topLab));
			}			
			m_bBorderIn = true;
			SetDrawingMode(B_OP_INVERT);
			FillRect(BRect(2,2,Bounds().Width()-2, Bounds().Height()-2));
			SetDrawingMode(B_OP_COPY);
		}
		//Le boutton est simplement dessiner
		else 
		{
			if(m_bMouseOver) m_bBorderOut = true;
			SetHighColor(192, 192, 192, 0);
			FillRect(BRect(0,0,Bounds().Width(), Bounds().Height()));
			if(m_bBitmap)
			{
				DrawBitmap(m_pBitmap, BPoint(leftBmp,topBmp));
			}
			if(m_bLabel)
			{
				SetHighColor(0, 0, 0, 0);
				DrawString(m_pzLabel, BPoint(leftLab,topLab));
			}
		}
	

		//Le contour foncer
		if(m_bBorderIn || m_bBorderOut)
		{
			SetHighColor(64, 64, 64, 0);
			pPointList[0] = BPoint(0,2);
			pPointList[1] = BPoint(2,0);
			pPointList[2] = BPoint(Bounds().Width() -2,0);
			pPointList[3] = BPoint(Bounds().Width(),2);
			pPointList[4] = BPoint(Bounds().Width(),Bounds().Height() -2);
			pPointList[5] = BPoint(Bounds().Width() -2,Bounds().Height());
			pPointList[6] = BPoint(2,Bounds().Height());
			pPointList[7] = BPoint(0,Bounds().Height() -2);
			StrokePolygon(pPointList, 8, true,  B_SOLID_HIGH);	
		}

		// Le boutton est enfoncer
		if (m_bBorderIn)
		{
			SetHighColor(128, 128, 128, 0);
			pPointList[0] = BPoint(1,Bounds().Height() -2);
			pPointList[1] = BPoint(1,2);
			pPointList[2] = BPoint(2,1);
			pPointList[3] = BPoint(Bounds().Width() -2,1);
			StrokePolygon(pPointList, 4, false,  B_SOLID_HIGH);	
	
			SetHighColor(255, 255, 255, 0);
			pPointList[0] = BPoint(Bounds().Width() -1,2);
			pPointList[1] = BPoint(Bounds().Width() -1,Bounds().Height() -2);
			pPointList[2] = BPoint(Bounds().Width() -2,Bounds().Height() -1);
			pPointList[3] = BPoint(2,Bounds().Height() -1);
			StrokePolygon(pPointList, 4, false,  B_SOLID_HIGH);
			SetHighColor(192, 192, 192, 0);
		}

		// Le boutton est surelever.
		else if(m_bBorderOut)
		{	
			SetHighColor(255, 255, 255, 0);
			pPointList[0] = BPoint(1,Bounds().Height() -2);
			pPointList[1] = BPoint(1,2);
			pPointList[2] = BPoint(2,1);
			pPointList[3] = BPoint(Bounds().Width() -2,1);
			StrokePolygon(pPointList, 4, false,  B_SOLID_HIGH);	
	
			SetHighColor(128, 128, 128, 0);
			pPointList[0] = BPoint(Bounds().Width() -1,2);
			pPointList[1] = BPoint(Bounds().Width() -1,Bounds().Height() -2);
			pPointList[2] = BPoint(Bounds().Width() -2,Bounds().Height() -1);
			pPointList[3] = BPoint(2,Bounds().Height() -1);
			StrokePolygon(pPointList, 4, false,  B_SOLID_HIGH);
			SetHighColor(192, 192, 192, 0);
		}
	}
}