Пример #1
0
BPolygon BPolygon::copy(int i, int j) const {
    BPolygon p;
    while(j < i) j += size();
    p.reserve(j - i + 1);
    for(; i <= j; ++i) {
        p.append(at(i));
    }
    return p;
}
Пример #2
0
BPolygon *TPolygon::GetBPolygon()
{			
	//	Create new BPolygon
	BPolygon *thePolygon = new BPolygon();
	
	BPoint *tmpPt;
	
	for (int32 index = 0; index < m_PointList->CountItems(); index++)
	{
		tmpPt = (BPoint *)m_PointList->ItemAt(index);
		thePolygon->AddPoints(tmpPt, 1);
	}
	
	return thePolygon;
}
Пример #3
0
AttribPolygon::AttribPolygon ()
: AttribView (BRect (0, 0, 148, 90), lstring (30, "Polygons"))
{
	SetViewColor (LightGrey);
	lSlid = new Slider (BRect (8, 8, 140, 26), 60, lstring (310, "Pen Size"), 1, 50, 1, new BMessage ('ALpc'));
	AddChild (lSlid);
	fPenSize = 1;
	fType = POLYGON_OUTFILL;
	BBox *type = new BBox (BRect (18, 32, 130, 82), "type");
	type->SetLabel (lstring (311, "Type"));
	AddChild (type);

	BPoint pointArray[] = {
		BPoint ( 2,  8),
		BPoint ( 9,  2),
		BPoint (27, 12),
		BPoint (19, 28),
		BPoint (14, 20),
		BPoint ( 9, 26)
		};
	BPolygon *poly = new BPolygon();
	poly->AddPoints(pointArray, 6);

	BWindow *picWindow = new BWindow (BRect (0, 0, 100, 100), "Temp Pic Window", B_BORDERED_WINDOW, uint32 (NULL), uint32 (NULL));
	BView *bg = new BView (BRect (0, 0, 100, 100), "Temp Pic View", uint32 (NULL), uint32 (NULL));
	picWindow->AddChild (bg);
	
	BPicture *p10;
	bg->BeginPicture (new BPicture);
	bg->SetLowColor (LightGrey);
	bg->FillRect (BRect (0, 0, 32, 32), B_SOLID_LOW);
	bg->SetLowColor (White);
	bg->FillPolygon (poly, B_SOLID_LOW);
	bg->StrokePolygon (poly);
	p10 = bg->EndPicture();
	
	BPicture *p20;
	bg->BeginPicture (new BPicture);
	bg->SetLowColor (LightGrey);
	bg->FillRect (BRect (0, 0, 32, 32), B_SOLID_LOW);
	bg->SetHighColor (Black);
	bg->SetLowColor (White);
	bg->FillPolygon (poly, B_SOLID_LOW);
	p20 = bg->EndPicture();
	
	BPicture *p30;
	bg->BeginPicture (new BPicture);
	bg->SetLowColor (LightGrey);
	bg->FillRect (BRect (0, 0, 32, 32), B_SOLID_LOW);
	bg->SetHighColor (Black);
	bg->SetLowColor (White);
	bg->StrokePolygon (poly);
	p30 = bg->EndPicture();

	BPicture *p11;
	bg->BeginPicture (new BPicture);
	bg->SetLowColor (DarkGrey);
	bg->FillRect (BRect (0, 0, 32, 32), B_SOLID_LOW);
	bg->SetHighColor (Black);
	bg->SetLowColor (White);
	bg->FillPolygon (poly, B_SOLID_LOW);
	bg->StrokePolygon (poly);
	p11 = bg->EndPicture();
	
	BPicture *p21;
	bg->BeginPicture (new BPicture);
	bg->SetLowColor (DarkGrey);
	bg->FillRect (BRect (0, 0, 32, 32), B_SOLID_LOW);
	bg->SetHighColor (Black);
	bg->SetLowColor (White);
	bg->FillPolygon (poly, B_SOLID_LOW);
	p21 = bg->EndPicture();
	
	BPicture *p31;
	bg->BeginPicture (new BPicture);
	bg->SetLowColor (DarkGrey);
	bg->FillRect (BRect (0, 0, 32, 32), B_SOLID_LOW);
	bg->SetHighColor (Black);
	bg->SetLowColor (White);
	bg->StrokePolygon (poly);
	p31 = bg->EndPicture();
	
	delete poly;
	delete picWindow;
	
	SetViewColor (LightGrey);
	
	pT1 = new BPictureButton (BRect (4, 15, 34, 45), "APVt1", p10, p11, new BMessage ('pvT1'), B_TWO_STATE_BUTTON);
	pT2 = new BPictureButton (BRect (40, 15, 70, 45), "APVt2", p20, p21, new BMessage ('pvT2'), B_TWO_STATE_BUTTON);
	pT3 = new BPictureButton (BRect (76, 15, 106, 45), "APVt3", p30, p31, new BMessage ('pvT3'), B_TWO_STATE_BUTTON);
	type->AddChild (pT1);
	type->AddChild (pT2);
	type->AddChild (pT3);
	pT1->SetValue (B_CONTROL_ON);
	fCurrentProperty = 0;
}
Пример #4
0
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));
}
Пример #5
0
void
GameView::MouseUp(BPoint point)
{
	mouselock=false;
	if(selected==NULL)
		return;
	card* card=NULL;
	short row=0;
	short stack=0;
	short saved=-1;
	bool special=false;
	for (short i=8;i<200;i++) {
		BPoint pt(85*(stack+1),40*(row+4));
		BRect rect(pt,BPoint(pt.x+80,pt.y+116));
		if (board[i]!=NULL) {
			if (rect.Contains(point)) {
				saved=i;
			}
		}
		row++;
		if (row==26) {
			row=0;
			stack++;
		}
	}
	
	BPoint deckPoints[]={ BPoint(-80,4),BPoint(-80,116),BPoint(0,116),
		BPoint(0,4)};
	BPolygon* deck;
	
	for (short 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);
		if (deck->Frame().Contains(point)) {
			special=true;
			saved=i;
		}
	}
	if (special) {
		if (saved<4) {	
			if (selected->fNextCard==NULL && board[saved]==NULL) {
				board[saved]=selected;
				board[selected->oldNumber]=NULL;
				moves++;
			}
		}else{
			if (selected->fNextCard==NULL) {
				if (board[saved]==NULL && selected->fValue==1 ) {
					goto putCardInStack;
				}
				if (board[saved]==NULL)
					return;
				if (board[saved]->fValue == selected->fValue-1 
					&& selected->fColor == board[saved]->fColor) {
						putCardInStack:
						board[saved]=selected;
						board[selected->oldNumber]=NULL;
						moves++;
					
						if (board[4]->fValue==13 && board[5]->fValue==13 
							&& board[6]->fValue==13 
							&& board[7]->fValue==13) {
								BString winText="";
								winText << "WIN!!!\n\n";
								winText << "Congratulations, you have won";
								winText << "SuperFreeCell!!\n\n";
								winText << "Moves: " << moves;
								BAlert* win=new BAlert("Win",winText,"OK");
								win->Go();
						}
				}
			}
		}
		Invalidate();
		selected=NULL;
		return;
	}

	for (short j=0;j<8;j++) {
		if (board[j*26+8]==NULL) {
			BPoint pt(85*(j+1),40*(4));
			BRect rect(pt,BPoint(pt.x+80,pt.y+116));
			if (rect.Contains(point)) {
				board[j*26+8]=selected;
				board[selected->oldNumber]=NULL;
				moves++;
				
				short k=0;
				while (selected->fNextCard!=NULL) {
					board[j*26+8+k+1]=selected->fNextCard;
					k++;
					struct card* temp_card=selected->fNextCard;
					selected->fNextCard=NULL;
					selected=temp_card;
					board[selected->oldNumber]=NULL;
				}
				Invalidate();
				selected=NULL;
				return;
			}
		}
	}
	if (saved>=0 && saved<200) {
		if (board[saved+1]==NULL 
			&& (board[saved]->fValue -1 == selected->fValue)) {
				
			if (this->CheckSuite(selected->fColor,board[saved]->fColor)) {
				short j=1;
				board[saved+1]=selected;
				board[selected->oldNumber]=NULL;
				moves++;
				
				while (selected->fNextCard!=NULL) {
					board[saved+j+1]=selected->fNextCard;
					j++;
					struct card* temp_card=selected->fNextCard;
					selected->fNextCard=NULL;
					selected=temp_card;
					board[selected->oldNumber]=NULL;
				}
			}
		}
	}
	Invalidate();
	selected=NULL;
}
Пример #6
0
void
GameView::MouseDown(BPoint point)
{
	if(mouselock)
		return;
		
	mouselock=true;
	card* card=NULL;
	short row=0;
	short stack=0;
	short saved=-1;
	bool special=false;
	
	for (short i=8;i<200;i++) {
		BPoint pt(85*(stack+1),40*(row+4));
		BRect rect(pt,BPoint(pt.x+80,pt.y+116));
		if (board[i]!=NULL) {
			if (rect.Contains(point)) {
				saved=i;
			}
		}
		row++;
		if (row==26) {
			row=0;
			stack++;
		}
	}

	BPoint deckPoints[]={ BPoint(-80,4),BPoint(-80,116),BPoint(0,116),
		BPoint(0,4)};
	BPolygon* deck;
	
	for (short 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);
		if (deck->Frame().Contains(point)) {
			special=true;
			saved=i;
		}
	}
	if (special) {
		if (saved<4) {
			if (board[saved]==NULL)
				return;
			selected=board[saved];
			selected->oldNumber=saved;
			DragMessage(new BMessage(B_SIMPLE_DATA),new BBitmap(selected->img),
				B_OP_BLEND,BPoint(0,0));
		}
		return;
	}
	
	
	if (saved>=0 && this->CheckStack(saved)) {
		short j=0;
		while (board[saved+j+1]!=NULL) {
			board[saved+j+1]->oldNumber=saved+j+1;
			board[saved+j]->fNextCard=board[saved+j+1];
			j++;
		}
		selected=board[saved];
		selected->oldNumber=saved;
		DragMessage(new BMessage(B_SIMPLE_DATA),new BBitmap(selected->img),
			B_OP_BLEND,BPoint(0,0));
	}
}