Esempio n. 1
0
void CGradient::DrawGDI(CDC * pDC, CRect rect, COLORREF colorStart, COLORREF colorMid, COLORREF colorEnd, BOOL bHorz/* = TRUE*/)
{
    CRect rect1, rect2;
    SplitRect(rect, rect1, rect2, bHorz);

    DrawGDI(pDC, rect1, colorStart, colorMid, bHorz);
    DrawGDI(pDC, rect2, colorMid, colorEnd, bHorz);
}
Esempio n. 2
0
void CGradient::Draw(CDC * pDC, CRect rect, COLORREF colorStart, COLORREF colorMid, COLORREF colorEnd, BOOL bHorz/* = TRUE*/, UINT nSteps/* = 64*/)
{
    CRect rect1, rect2;
    SplitRect(rect, rect1, rect2, bHorz);

    Draw(pDC, rect1, colorStart, colorMid, bHorz, nSteps/2);
    Draw(pDC, rect2, colorMid, colorEnd, bHorz, nSteps/2);
}
Esempio n. 3
0
bool AreaAllocator::Allocate(int width, int height, int& x, int& y)
{
    if (width < 0)
        width = 0;
    if (height < 0)
        height = 0;
    
    PODVector<IntRect>::Iterator best = freeAreas_.End();
    int bestFreeArea = M_MAX_INT;
    
    for (PODVector<IntRect>::Iterator i = freeAreas_.Begin(); i != freeAreas_.End(); ++i)
    {
        int freeWidth = i->right_ - i->left_;
        int freeHeight = i->bottom_ - i->top_;
        
        if (freeWidth >= width && freeHeight >= height)
        {
            // Calculate rank for free area. Lower is better
            int freeArea = freeWidth * freeHeight;
            
            if (best == freeAreas_.End() || freeArea < bestFreeArea)
            {
                best = i;
                bestFreeArea = freeArea;
            }
        }
    }
    
    if (best == freeAreas_.End())
        return false;
    
    IntRect reserved;
    reserved.left_ = best->left_;
    reserved.top_ = best->top_;
    reserved.right_ = best->left_ + width;
    reserved.bottom_ = best->top_ + height;
    
    x = best->left_;
    y = best->top_;
    
    // Remove the reserved area from all free areas
    for (unsigned i = 0; i < freeAreas_.Size();)
    {
        if (SplitRect(freeAreas_[i], reserved))
            freeAreas_.Erase(i);
        else
            ++i;
    }
    
    Cleanup();
    return true;
}
DisplayError ResourceDefault::SrcSplitConfig(DisplayResourceContext *display_resource_ctx,
                                        const LayerRect &src_rect, const LayerRect &dst_rect,
                                        HWLayerConfig *layer_config) {
  HWPipeInfo *left_pipe = &layer_config->left_pipe;
  HWPipeInfo *right_pipe = &layer_config->right_pipe;
  float src_width = src_rect.right - src_rect.left;
  float dst_width = dst_rect.right - dst_rect.left;

  // Layer cannot qualify for SrcSplit if source or destination width exceeds max pipe width.
  if ((src_width > hw_res_info_.max_pipe_width) || (dst_width > hw_res_info_.max_pipe_width)) {
    SplitRect(src_rect, dst_rect, &left_pipe->src_roi, &left_pipe->dst_roi, &right_pipe->src_roi,
              &right_pipe->dst_roi);
    left_pipe->valid = true;
    right_pipe->valid = true;
  } else {
    left_pipe->src_roi = src_rect;
    left_pipe->dst_roi = dst_rect;
    left_pipe->valid = true;
    right_pipe->Reset();
  }

  return kErrorNone;
}
Esempio n. 5
0
//==============================================================
// ダンジョンを作る
//==============================================================
void CDunHard::Make( CChara *pPlayer)
{
	// 区画の数をリセット
	m_uRectCnt = 0;
	m_pPlayer = pPlayer;

	//-----------------------------------
	// 初期化:一旦すべて壁にする
	//-----------------------------------
	int x, y;
	for(y = 0; y < m_uHeight; y ++) {
		for(x = 0; x < m_uWidth; x ++) {
			GetTile(x, y)->bIsWall = TRUE;
		}
	}
	
	//-----------------------------------
	// 区画を作る
	//-----------------------------------
	// まずは全体を1つの区画にする
	CreateRect(0, 0, m_uWidth - 1, m_uHeight - 1);
	// 再帰でどんどん細かくする
	SplitRect(0, 0);
	
	//-----------------------------------
	// 階段の設置
	//-----------------------------------
	// ランダムな部屋の適当な位置に下階段を配置
	int nStepDownIndex;
	nStepDownIndex = GetRand(m_uRectCnt);
	while (true) {
		RandRoomPoint(nStepDownIndex, &x, &y);
		if (GetTile(x, y)->bIsWall == false) {
			GetTile(x, y)->bIsStepDown = TRUE;
			m_uDownStepX = x;
			m_uDownStepY = y;
			break;
		}
	}

	// 下階段とは違う部屋でランダムな部屋の適当な位置に上階段を配置
	int nStepUpIndex;
	nStepUpIndex = GetRand(m_uRectCnt);
	while(nStepUpIndex == nStepDownIndex) {
		nStepUpIndex = GetRand(m_uRectCnt);
	}
	while (true) {
		RandRoomPoint(nStepUpIndex, &x, &y);
		if (GetTile(x, y)->bIsWall == false) {
			GetTile(x, y)->bIsStepUp = TRUE;
			m_uUpStepX = x;
			m_uUpStepY = y;
			break;
		}
	}

	//-----------------------------------
	// 迷路以外はもう一回区画を塗り直しておく
	//-----------------------------------
	ReFillRoom();

	//-----------------------------------
	// 各部屋にアイテムを配置する
	//-----------------------------------
	CreateItem(60);

	//-----------------------------------
	// 各部屋にモンスターを配置する
	//-----------------------------------
	CreateMob(60);
}
Esempio n. 6
0
//==============================================================
// 区画を分ける
//==============================================================
void CDunHard::SplitRect(int nParentRectIndex, int nFlagHV)
{
	DUNRECT *pParent, *pChild;
	RECT *pRect;
	int nChildIndex1 = 0, nChildIndex2 = 0;

	// わける区画情報を取得
	pParent = &m_Rect[nParentRectIndex];
	pRect   = &pParent->Rect;

	//---------
	// 分割する
	//---------
	if((nFlagHV & 1) == 0) {
		// 横に分割する
		nFlagHV |= 1;

		// 区分を分割できるか?チェック
		if(RECT_W(*pRect) >= (MIN_ROOM_SIZE + 3) * 2 + 1) {
			int a, b, ab, p;
			// 左端のA点を求める
			a = MIN_ROOM_SIZE + 3;

			// 右端のB点を求める
			b = RECT_W(*pRect) - MIN_ROOM_SIZE - 4;

			// ABの距離を求める
			ab = b - a;

			// AB間のどこかに決定する
			p = a + GetRand(ab + 1);

			// 新しく右の区画を作成する
			pChild = CreateRect(pRect->left + p,
								pRect->top,
								pRect->right,
								pRect->bottom);

			// 元の区画の右を p 地点に移動させて、左側の区画とする
			pParent->Rect.right = pChild->Rect.left;

			// 子の部屋をさらに分割する
			nChildIndex1 = DunrectToIndex(pChild);
			SplitRect(nChildIndex1, 0);
		}
	}

	if((nFlagHV & 2) == 0) {
		// 縦に分割する
		nFlagHV |= 2;

		// 区分を分割できるか?チェック
		if( RECT_H(*pRect) >= (MIN_ROOM_SIZE+3)*2+1 ) {
			int a, b, ab, p;
			a = MIN_ROOM_SIZE + 3;
			b = RECT_H(*pRect) - MIN_ROOM_SIZE - 4;
			ab = b - a;

			p = a + GetRand(ab + 1);

			// 新しく下の区画を作成する
			pChild = CreateRect(pRect->left,
								pRect->top + p,
								pRect->right,
								pRect->bottom);

			// 元の区画の下を p 地点に移動させて、上側の区画とする
			pParent->Rect.bottom = pChild->Rect.top;

			// 子の部屋をさらに分割する
			nChildIndex2 = DunrectToIndex(pChild);
			SplitRect(nChildIndex2, 0);
		}
	}

	// 部屋を作る
	CreateRoom(nParentRectIndex);

	// 子供とつなげる
	if(nChildIndex1) {
		CreateRoad( nParentRectIndex, nChildIndex1 );
	}
	if(nChildIndex2) {
		CreateRoad( nParentRectIndex, nChildIndex2 );
	}
}
Esempio n. 7
0
bool AreaAllocator::Allocate(int width, int height, int& x, int& y)
{
    if (width < 0)
        width = 0;
    if (height < 0)
        height = 0;
    
    PODVector<IntRect>::Iterator best;
    int bestFreeArea;
    
    for(;;)
    {
        best = freeAreas_.End();
        bestFreeArea = M_MAX_INT;
        for (PODVector<IntRect>::Iterator i = freeAreas_.Begin(); i != freeAreas_.End(); ++i)
        {
            int freeWidth = i->Width();
            int freeHeight = i->Height();
            
            if (freeWidth >= width && freeHeight >= height)
            {
                // Calculate rank for free area. Lower is better
                int freeArea = freeWidth * freeHeight;
                
                if (freeArea < bestFreeArea)
                {
                    best = i;
                    bestFreeArea = freeArea;
                }
            }
        }
        
        if (best == freeAreas_.End())
        {
            if (doubleWidth_ && size_.x_ < maxSize_.x_)
            {
                int oldWidth = size_.x_;
                size_.x_ <<= 1;
                // If no allocations yet, simply expand the single free area
                IntRect& first = freeAreas_.Front();
                if (freeAreas_.Size() == 1 && first.left_ == 0 && first.top_ == 0 && first.right_ == oldWidth && first.bottom_ == size_.y_)
                    first.right_ = size_.x_;
                else
                {
                    IntRect newArea(oldWidth, 0, size_.x_, size_.y_);
                    freeAreas_.Push(newArea);
                }
            }
            else if (!doubleWidth_ && size_.y_ < maxSize_.y_)
            {
                int oldHeight = size_.y_;
                size_.y_ <<= 1;
                // If no allocations yet, simply expand the single free area
                IntRect& first = freeAreas_.Front();
                if (freeAreas_.Size() == 1 && first.left_ == 0 && first.top_ == 0 && first.right_ == size_.x_ && first.bottom_ == oldHeight)
                    first.bottom_ = size_.y_;
                else
                {
                    IntRect newArea(0, oldHeight, size_.x_, size_.y_);
                    freeAreas_.Push(newArea);
                }
            }
            else
                return false;
            
            doubleWidth_ = !doubleWidth_;
        }
        else
            break;
    }
    
    IntRect reserved(best->left_, best->top_, best->left_ + width, best->top_ + height);
    x = best->left_;
    y = best->top_;
    
    if (fastMode_)
    {
        // Reserve the area by splitting up the remaining free area
        best->left_ = reserved.right_;
        if (best->Height() > 2 * height || height >= size_.y_ / 2)
        {
            IntRect splitArea(reserved.left_, reserved.bottom_, best->right_, best->bottom_);
            best->bottom_ = reserved.bottom_;
            freeAreas_.Push(splitArea);
        }
    }
    else
    {
        // Remove the reserved area from all free areas
        for (unsigned i = 0; i < freeAreas_.Size();)
        {
            if (SplitRect(freeAreas_[i], reserved))
                freeAreas_.Erase(i);
            else
                ++i;
        }
        
        Cleanup();
    }
    
    return true;
}