Exemple #1
0
SDL_Surface * CMessage::drawDialogBox(int w, int h, PlayerColor playerColor)
{
	//prepare surface
	SDL_Surface * ret = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
	for (int i=0; i<w; i+=background->w)//background
	{
		for (int j=0; j<h; j+=background->h)
		{
			Rect srcR(0,0,background->w, background->h);
			Rect dstR(i,j,w,h);
			CSDL_Ext::blitSurface(background, &srcR, ret, &dstR);
		}
	}
	drawBorder(playerColor, ret, w, h);
	return ret;
}
//--------------------------------------------------------------------
void InterView::Draw(BRect updateRect)
{
	BRect visi(Bounds());

	if (curPicture != NULL)
	{
		BRect picRect(curPicture->Bounds());
		BRect viewRect(visi);

		if (autoScale)
		{
			viewRect.right -= B_V_SCROLL_BAR_WIDTH;
			viewRect.bottom -= B_H_SCROLL_BAR_HEIGHT;
			float dx = picRect.right / viewRect.right;
			float dy = picRect.bottom / viewRect.bottom;
			if (dx > dy)
			{
				float old_height = viewRect.bottom;
				viewRect.bottom = (picRect.bottom / picRect.right) * viewRect.right;

				viewRect.OffsetBy(0., old_height/2 - viewRect.bottom/2);

				FillRect(BRect(0., 0., viewRect.right, viewRect.top-1));
				FillRect(BRect(0., viewRect.bottom, viewRect.right, visi.bottom));

				zoomFactor = 1./dx;
				SendZoomFactorModified();
			}
			else
			{
				float old_width = viewRect.right;
				viewRect.right = (picRect.right / picRect.bottom) * viewRect.bottom;

				viewRect.OffsetBy(old_width/2 - viewRect.right/2, 0.);

				FillRect(BRect(0., viewRect.top, viewRect.left-1, viewRect.bottom));
				FillRect(BRect(viewRect.right+1, viewRect.top, visi.right, viewRect.bottom));

				zoomFactor = 1./dy;
				SendZoomFactorModified();
			}

			DrawBitmap(curPicture, viewRect);
		}
		else
		{
			if (zoomFactor == 1.)
			{
				BPoint pos(viewRect.right/2 - picRect.right/2 - B_V_SCROLL_BAR_WIDTH/2,
						   viewRect.bottom/2 - picRect.bottom/2 - B_H_SCROLL_BAR_HEIGHT/2);
				if (pos.x < 0.)
					pos.x = -xOffs;
				else xOffs = 0.;
//					pos.x = 0;
				if (pos.y < 0.)
					pos.y = -yOffs;
				else yOffs = 0.;
//					pos.y = 0;
			
				DrawBitmap(curPicture, pos);

				FillRect(BRect(0., 0., visi.right, pos.y-1));
				FillRect(BRect(0., visi.bottom - pos.y - B_H_SCROLL_BAR_HEIGHT + 1, visi.right, visi.bottom));
				FillRect(BRect(0., pos.y, pos.x-1, visi.bottom-pos.y));
				FillRect(BRect(visi.right-pos.x-B_V_SCROLL_BAR_WIDTH+1, pos.y, visi.right, visi.bottom-pos.y));
			}
			else
			{
				picRect.right  *= zoomFactor;
				picRect.bottom *= zoomFactor;

				BRect srcR(curPicture->Bounds());

				BRect dstR(viewRect.right/2 - picRect.right/2 - B_V_SCROLL_BAR_WIDTH/2,
						   viewRect.bottom/2 - picRect.bottom/2 - B_H_SCROLL_BAR_HEIGHT/2,
						   viewRect.right/2 + picRect.right/2 + B_V_SCROLL_BAR_WIDTH/2,
						   viewRect.bottom/2 + picRect.bottom/2 + B_H_SCROLL_BAR_HEIGHT/2);

				if (dstR.left < 0.)	// pic wider than view
				{
					dstR.left  = 0.;
					dstR.right = visi.right - B_V_SCROLL_BAR_WIDTH;

					srcR.left  = picRect.left + xOffs/zoomFactor;
					srcR.right = picRect.left + xOffs/zoomFactor + (visi.right - B_V_SCROLL_BAR_WIDTH)/zoomFactor;
				}
				else xOffs = 0.;

				if (dstR.top < 0.) // pic higher than view
				{
					dstR.top = 0.;
					dstR.bottom = visi.bottom - B_H_SCROLL_BAR_HEIGHT;

					srcR.top = picRect.top + yOffs/zoomFactor;
					srcR.bottom = picRect.top + yOffs/zoomFactor + (visi.bottom - B_H_SCROLL_BAR_HEIGHT)/zoomFactor;
				}
				else yOffs = 0.;

				DrawBitmap(curPicture, srcR, dstR);

				FillRect(BRect(0., 0., visi.right, dstR.top-1));					// top
				FillRect(BRect(0., dstR.bottom+1, visi.right, visi.bottom));		// bottom
				FillRect(BRect(0., dstR.top, dstR.left-1, dstR.bottom));			// left
				FillRect(BRect(dstR.right+1, dstR.top, visi.right, dstR.bottom));	// right
			}

		}
	}
	else
		FillRect(Bounds());
}
int CBirchCtrl::DrawNodesRecursive( CDC* pDC, HTREENODE pNode, int y, 
										CPen* linesPen, CPen* marksPen, CRect rFrame )
{
	if (!m_birch)
		return 0;

	if (!pNode->bVisible)
		return (y-1);

	CRect	rNode;

	// The node's location and dimensions on screen
	rNode.left		= m_iIndent*pNode->iNodeLevel+3;
	rNode.top		= y;
	rNode.right		= rFrame.right - m_iPadding;
	rNode.bottom	= y + m_iLineHeight;

	pNode->rNode.CopyRect( rNode );		// Record the rectangle

	if (pNode->pParent==m_birch->GetTopNode())
	{
		CRect rct(0,rNode.top+1,rFrame.right,rNode.bottom-1);
		themeData.DrawThemedRect(pDC,&rct,TRUE);
		pDC->FillSolidRect(rct.left,rct.top-1,rct.Width(),1,GetSysColor(COLOR_3DFACE));
		pDC->FillSolidRect(rct.left,rct.bottom,rct.Width(),1,GetSysColor(COLOR_3DSHADOW));
	}

	int iJointX	= pNode->rNode.left - m_iIndent - 6;
	int iJointY	= pNode->rNode.top + ( m_iLineHeight / 2 );
	int iDispY = iJointY - pNode->pParent->rNode.top - ( m_iLineHeight / 2 );

	if( rNode.bottom > 0 && rNode.top < rFrame.bottom )
	{
		COLORREF cr			= ( pNode->bUseDefaultTextColor )? m_crDefaultTextColor:pNode->crText;
		COLORREF crOldText	= pDC->SetTextColor( cr );

		size_t bmps_cnt = pNode->item_bitmaps.size();
		int  buf_len = 1;

		if (bmps_cnt>0)
		{
			for (size_t jj=0;jj<bmps_cnt;jj++)
			{
				int bw = pNode->item_bitmaps[jj]->GetWidth();
				int bh = pNode->item_bitmaps[jj]->GetHeight();
				CRect destR(pNode->rNode.left+buf_len,
							pNode->rNode.top+m_iLineHeight/2-bh/2,
							pNode->rNode.left+buf_len+bw,
							pNode->rNode.top+m_iLineHeight/2+bh/2);
				CRect srcR(0, 0, bw,bh);
				//pDC->Rectangle(destR);
				pNode->item_bitmaps[jj]->Draw(pDC,&destR,&srcR);
				buf_len += bw+1;
				//CTreeCtrl::CreateDragImage()
			}
		}

		pDC->DrawText( pNode->csLabel, CRect(rNode.left+buf_len+2,rNode.top,
					rNode.right,rNode.bottom), DT_LEFT | DT_SINGLELINE | DT_VCENTER );
	
		pDC->SetTextColor( crOldText );

		// draw lines START
		// If the parent is not the top node, throw a connecting line to it
			if( pNode->pParent != m_birch->GetTopNode() )
			{
				// How far up from the joint is the parent?
				// Use 1 pixel wide rectangles to draw lines
				pDC->SelectObject(linesPen);
				pDC->MoveTo(iJointX, iJointY);
				pDC->LineTo(iJointX+m_iIndent, iJointY);
				//if (pNode==pNode->pParent->pLastChild)
				{
					pDC->MoveTo(iJointX, iJointY);
					pDC->LineTo(iJointX, iJointY-iDispY+5);
				}
			}
			
			pDC->SelectObject(marksPen);
			// Put a solid dot to mark a node
			if (pNode->pFirstChild != NULL)
			{
				pDC->Rectangle(iJointX + m_iIndent - 4, iJointY - 4, iJointX + m_iIndent +5, iJointY +5);
				pDC->MoveTo(iJointX + m_iIndent - 2, iJointY);
				pDC->LineTo(iJointX + m_iIndent + 3, iJointY);
				if (!pNode->bOpen)
				{
					pDC->MoveTo(iJointX + m_iIndent, iJointY - 2);
					pDC->LineTo(iJointX + m_iIndent, iJointY + 3);
				}
			}
			// Hollow out the dot if the node has no childs
			else
			{
				pDC->Ellipse(iJointX + m_iIndent - 1, iJointY - 1, iJointX + m_iIndent +2, iJointY +2);
			}
		// draw lines END
	}
	else
	{
		pDC->SelectObject(linesPen);
		if( pNode->pParent != m_birch->GetTopNode()/* && pNode==pNode->pParent->pLastChild*/)
		{
			pDC->MoveTo(iJointX, iJointY);
			pDC->LineTo(iJointX, iJointY-iDispY+5);
		}
	}


	// If there are no child or siblings, then this branch is done
	if( pNode->pFirstChild == NULL)
		return pNode->rNode.bottom;//pNode->rNode.Height();

	// If the node is open AND it has childs, then draw those
	int iLastNodePos=pNode->rNode.bottom;
	if( pNode->bOpen)
	{
		HTREENODE curTreeNode = pNode->pFirstChild ;
		while (curTreeNode)
		{
			iLastNodePos = DrawNodesRecursive(	pDC, curTreeNode,
				iLastNodePos+1,
				linesPen, marksPen,
				rFrame );
			curTreeNode = curTreeNode->pNextSibling;
		}
	}

	return iLastNodePos;
}
Exemple #4
0
void CMessage::drawBorder(PlayerColor playerColor, SDL_Surface * ret, int w, int h, int x, int y)
{	
	std::vector<SDL_Surface *> &box = piecesOfBox[playerColor.getNum()];

	// Note: this code assumes that the corner dimensions are all the same.

	// Horizontal borders
	int start_x = x + box[0]->w;
	const int stop_x = x + w - box[1]->w;
	const int bottom_y = y+h-box[7]->h+1;
	while (start_x < stop_x) {
		int cur_w = stop_x - start_x;
		if (cur_w > box[6]->w)
			cur_w = box[6]->w;

		// Top border
		Rect srcR(0, 0, cur_w, box[6]->h);
		Rect dstR(start_x, y, 0, 0);
		CSDL_Ext::blitSurface(box[6], &srcR, ret, &dstR);
		
		// Bottom border
		dstR.y = bottom_y;
		CSDL_Ext::blitSurface(box[7], &srcR, ret, &dstR);

		start_x += cur_w;
	}

	// Vertical borders
	int start_y = y + box[0]->h;
	const int stop_y = y + h - box[2]->h+1;
	const int right_x = x+w-box[5]->w;
	while (start_y < stop_y) {
		int cur_h = stop_y - start_y;
		if (cur_h > box[4]->h)
			cur_h = box[4]->h;

		// Left border
		Rect srcR(0, 0, box[4]->w, cur_h);
		Rect dstR(x, start_y, 0, 0);
		CSDL_Ext::blitSurface(box[4], &srcR, ret, &dstR);

		// Right border
		dstR.x = right_x;
		CSDL_Ext::blitSurface(box[5], &srcR, ret, &dstR);

		start_y += cur_h;
	}

	//corners
	Rect dstR(x, y, box[0]->w, box[0]->h);
	CSDL_Ext::blitSurface(box[0], nullptr, ret, &dstR);

	dstR=Rect(x+w-box[1]->w, y,   box[1]->w, box[1]->h);
	CSDL_Ext::blitSurface(box[1], nullptr, ret, &dstR);

	dstR=Rect(x, y+h-box[2]->h+1, box[2]->w, box[2]->h);
	CSDL_Ext::blitSurface(box[2], nullptr, ret, &dstR);

	dstR=Rect(x+w-box[3]->w, y+h-box[3]->h+1, box[3]->w, box[3]->h);
	CSDL_Ext::blitSurface(box[3], nullptr, ret, &dstR);
}