Esempio n. 1
0
//重なっていたらtrueを返す
bool SRect::intersect(const SRect& rc) const
{
    if(rc.l()>m_r) return false;
    if(rc.r()<m_l) return false;
    if(rc.t()>m_b) return false;
    if(rc.b()<m_t) return false;
    return true;
}
bool GraphicsElementManager::InitPrimitiveElement( shared_ptr<PrimitiveElement> pElement,
													const SRect& non_scaled_rect,
												    const SFloatRGBAColor& color,
													int layer_index )
{
	bool res = InitElement( pElement, layer_index );
	if( !res )
		return false;

	pElement->SetColor( 0, color );

	AABB2 non_scaled_aabb;
	non_scaled_aabb.vMin.x = (float)non_scaled_rect.left;
	non_scaled_aabb.vMin.y = (float)non_scaled_rect.top;
	non_scaled_aabb.vMax.x = (float)non_scaled_rect.right;
	non_scaled_aabb.vMax.y = (float)non_scaled_rect.bottom;

	// set as local coord
	// the element is owned by a group: local coord
	// the element is not owned by any group: global coord
	pElement->SetLocalTopLeftPos( non_scaled_rect.GetTopLeftCorner() );

	pElement->SetSizeLTRB( non_scaled_aabb.vMin, non_scaled_aabb.vMax );

	return true;
}
shared_ptr<TextElement> GraphicsElementManager::CreateText( int font_id, const std::string& text,
												  const SRect& textbox, int align_h, int align_v,
												  const SFloatRGBAColor& color, int font_w, int font_h, int layer )
{
/*	int index = GetVacantSlotIndex();

	if( !RegisterToLayer( index, layer ) )
		return shared_ptr<TextElement>();
*/
	AABB2 aabb;
	aabb.vMin = Vector2( (float)textbox.left,  (float)textbox.top );
	aabb.vMax = Vector2( (float)textbox.right, (float)textbox.bottom );
	shared_ptr<TextElement> pTextElement( new TextElement( font_id, text, aabb, align_h, align_v, color ) );
	pTextElement->SetFontSize( font_w, font_h );

	bool res = InitElement( pTextElement, layer );
	if( !res )
		return shared_ptr<TextElement>();

	// manager must be set to the element before calling SetLocalTopLeftPos()
	// because it calls UpdateTextAlignment(), which calls GraphicsElementManager::GetFont()
	pTextElement->SetLocalTopLeftPos( textbox.GetTopLeftCorner() );

	pTextElement->UpdateTextAlignment();

	// need to scale text element?

	return pTextElement;
}
Esempio n. 4
0
//範囲を選択してドラッグ選択を行う
unsigned SXBSchTag::testSelectionForDrag(const SRect& rc)
{
    if( rc.intersect(area()) ) {
        return SELECT_ALL;
    } else {
        return 0;
    }
}
Esempio n. 5
0
//範囲を指定して選択を行う
unsigned SXBSchLabel::testSelection(const SRect& rc)
{
	if( rc.intersect(area()) ){
		return SELECT_ALL;
	}else{
		return 0;
	}
}
//範囲を選択してドラッグ選択を行う
unsigned SXBSchComponent::testSelectionForDrag(const SRect& rc)
{
	if( rc.intersect(bodyArea()) ){
		return SELECT_ALL;
	}else{
		return 0;
	}
}
Esempio n. 7
0
inline void CImageClipper::run()
{
	if( !m_pBitmapImage )
		return;

	// TODO: Add CBitmapImage::GetBPP()
	int bits_per_pixel = FreeImage_GetBPP( m_pBitmapImage->GetFBITMAP() );

	const int dest_w = m_DestRegion.GetWidth();
	const int dest_h = m_DestRegion.GetHeight();
	CBitmapImage img( dest_w, dest_h, bits_per_pixel );

	int src_height = m_pBitmapImage->GetHeight();

	int x, y;
	int sx = m_DestRegion.left;
	int sy = m_DestRegion.top;
	U8 r, g, b, a;
	a = 0xFF;
	RGBQUAD quad;
	for( x=0; x<dest_w; x++)
	{
		for( y=0; y<dest_h; y++)
		{
			// Error - fix this
//			m_pBitmapImage->GetPixel( sx + x, sy + y, r, g, b, a );

			FreeImage_GetPixelColor( m_pBitmapImage->GetFBITMAP(),
				sx + x,
				src_height - ( sy + y ) - 1,
				&quad );
			r = quad.rgbRed;
			g = quad.rgbGreen;
			b = quad.rgbBlue;

			// Error - fix this
//			img.SetPixel( x, y, r, g, b, a );

			FreeImage_SetPixelColor( img.GetFBITMAP(), x, dest_h - y - 1, &quad );
		}
	}

	img.SaveToFile( m_DestFilepath );
}
Esempio n. 8
0
void CWindowOSXQT::PaintToBuffer(tuchar* puchBuffer, tuint32 uiInterleave, const SRect& rUpdate)
{
	int iBytesNeeded = (mSize.iCX + 1) * (mSize.iCY + 1) * 4;
	if (iBytesNeeded > miDrawBufferSize) {
		if (mpcDrawBuffer) {
			delete[] mpcDrawBuffer;
		}

		miDrawBufferSize = iBytesNeeded;
		mpcDrawBuffer = new tuchar[miDrawBufferSize];
	}

	if (mpInvalidater->IsRectInvalidated() == true) {
		// We need to update the buffer
		SRect RectUpdate;
		mpInvalidater->GetInvalidatedRect(RectUpdate);
		mpInvalidater->Reset();

		// Limit update rect to our actual size
		SRect RectThis(SPos(0, 0), mSize);
		RectUpdate.FitInside(RectThis);
		// Limit update rect to, well, the update rect...
		RectUpdate.FitInside(rUpdate);

		GetPane()->OnDraw(RectUpdate);
		if (mpControlOnTop) {
			mpControlOnTop->OnDraw(RectUpdate);
		}
	}

	// Copy to buffer delivered
	tuint uiY;
	for (uiY = rUpdate.iY; uiY < mSize.iCY && uiY < (rUpdate.iY + rUpdate.iCY); uiY++) {
		tuchar* puchDest = puchBuffer + (uiInterleave * uiY);
		tuchar* puchSource = mpcDrawBuffer + (4 * mSize.iCX * uiY);
		tuint uiX;
		for (uiX = rUpdate.iX; uiX < mSize.iCX && uiX < (rUpdate.iX + rUpdate.iCX); uiX++) {
			((tuint32*)puchDest)[uiX] = ((tuint32*)puchSource)[uiX];
		}
	}
}
Esempio n. 9
0
void ScissorClipStack::push( Vec2i const& pos , Vec2i const& size , bool bOverlapPrev )
{
	SRect rect;
	rect.min = pos;
	rect.max = pos + size;

	if ( mStack.empty() )
	{
		mPrevEnable = glIsEnabled( GL_SCISSOR_TEST );
		if ( !mPrevEnable )
			glEnable( GL_SCISSOR_TEST );
	}
	else if ( bOverlapPrev )
	{
		if ( !rect.overlap( mStack.back() ) )
			rect.max = rect.min;
	}
	Vec2i sizeRect = rect.getSize();
	glScissor( rect.min.x , rect.min.y , sizeRect.x , sizeRect.y );
	mStack.push_back( rect );
}
Esempio n. 10
0
//範囲を指定して選択チェックを行う
bool SPtnObjCircle::testIntersect(const SRect& rc)
{
    if(!rc.intersect(m_p0)) return false;
    if(!rc.intersect(m_p1)) return false;
    return true;
}
Esempio n. 11
0
//描画が必要かどうかを返す
bool SXBSchTag::qRedraw(const SRect& rc)
{
    return rc.intersect(area());
}
Esempio n. 12
0
void CWindowOSXQT::OnPaint()
{
	int iBytesNeeded = (mSize.iCX + 1) * (mSize.iCY + 1) * 4;
	if (iBytesNeeded > miDrawBufferSize) {
		if (mpcDrawBuffer) {
			delete[] mpcDrawBuffer;
		}

		miDrawBufferSize = iBytesNeeded;
		mpcDrawBuffer = new tuchar[miDrawBufferSize];
	}

	if (mpInvalidater->IsRectInvalidated() == false) {
		// No updating neccasary
		return;
	}
	SRect RectUpdate;
	mpInvalidater->GetInvalidatedRect(RectUpdate);
	mpInvalidater->Reset();

	// Limit update rect to our actual size
	SRect RectThis(SPos(0, 0), mSize);
	RectUpdate.FitInside(RectThis);

	GetPane()->OnDraw(RectUpdate);
	if (mpControlOnTop) {
		mpControlOnTop->OnDraw(RectUpdate);
	}

	PixMap 			srcbm;
	GrafPtr 		saved;
	Rect 			portBounds;
	GrafPtr 		grafPtrThis;
	BitMapPtr 		dstbitmap;
	PixMapHandle	dstpixmap;

	memset(&srcbm,0,sizeof(PixMap));
	// setup begin
	srcbm.baseAddr = nil;
	srcbm.rowBytes = 0x8000;

	srcbm.bounds.left = 0;
	srcbm.bounds.top = 0;
	srcbm.bounds.right = mSize.iCX - 1;
	srcbm.bounds.bottom = mSize.iCY - 1;
	
	// ???
	int bytesPerRow = mSize.iCX * 4;

	srcbm.pmVersion = 4;
	srcbm.packType = 0;
	srcbm.packSize = 0;
	srcbm.hRes = 0x00480000;
	srcbm.vRes = 0x00480000;
	srcbm.pixelType = 0;
	srcbm.pixelSize = 0;
	srcbm.cmpCount = 0;
	srcbm.cmpSize = 0;
	srcbm.pmTable = nil;
	srcbm.pixelType = RGBDirect;
	srcbm.pixelSize = 32;
	srcbm.cmpCount = 3;
	srcbm.cmpSize = 5;
	srcbm.rowBytes = 0x8000 | (unsigned short) bytesPerRow;
	srcbm.baseAddr = (Ptr)mpcDrawBuffer;
	
	unsigned long ulOffsetX, ulOffsetY;
	ulOffsetX = 0;
	ulOffsetY = 0;
	
	Rect SrcRect;	
	SrcRect.left    = RectUpdate.iX;
	SrcRect.right   = RectUpdate.iX + RectUpdate.iCX - 1;
	SrcRect.top     = RectUpdate.iY;
	SrcRect.bottom  = RectUpdate.iY + RectUpdate.iCY - 1;

	Rect DstRect;
	DstRect = SrcRect;
		
	GetPort(&saved);
	
	grafPtrThis = (GrafPtr)::GetWindowPort(GetWindowRef());

	if (saved != grafPtrThis) {
		SetPort(grafPtrThis);
	}

	GetPortBounds(grafPtrThis, &portBounds);

	int port_offsetX = portBounds.left;
	int port_offsetY = portBounds.top;

	SetOrigin( port_offsetX, port_offsetY );
/*	Rect rctClip;
	rctClip.left = 0;
	rctClip.right = rctClip.left + mSize.iCX;
	rctClip.top = 0;
	rctClip.bottom = rctClip.top + mSize.iCY;
	ClipRect(&rctClip);*/
	
	dstpixmap = ::GetPortPixMap(grafPtrThis);
	
	dstbitmap = (BitMapPtr)(*dstpixmap);
	
	ForeColor(blackColor);
	BackColor(whiteColor);
	
	::CopyBits((BitMapPtr)&srcbm,
		dstbitmap,
		&SrcRect,
		&DstRect,
		srcCopy,
		nil);
		
//	SetOrigin(0, 0);

	if (saved != grafPtrThis) {
		SetPort(saved);
	}
}
Esempio n. 13
0
//範囲を指定して選択を行う
unsigned SXBSchLine::testSelection(const SRect& rc)
{
	unsigned nOutcode1 = SetOutCode(m_p1,rc);
	unsigned nOutcode2 = SetOutCode(m_p2,rc);
	if(nOutcode1 & nOutcode2) return 0;
	if((nOutcode1 == 0 )||(nOutcode2 == 0 )) return SELECT_ALL;
	unsigned nOutcode = nOutcode1 | nOutcode2;
	if(nOutcode == (OUTCODE_LEFT  | OUTCODE_RIGHT)) return SELECT_ALL;
	if(nOutcode == (OUTCODE_UPPER | OUTCODE_LOWER)) return SELECT_ALL;

	int x,y;
	int x1 = m_p1.x();
	int y1 = m_p1.y();
	int x2 = m_p2.x();
	int y2 = m_p2.y();

	if(nOutcode & OUTCODE_LEFT){	//片方が左に出ている
		x=rc.l();
		y=y1+((x-x1)*(y2-y1))/(x2-x1);
		if(y >= rc.t() && y <= rc.b()) return SELECT_ALL;
	}
	if(nOutcode & OUTCODE_RIGHT){	//片方が右に出ている
		x=rc.r();
		y=y1+((x-x1)*(y2-y1))/(x2-x1);
		if(y >= rc.t() && y <= rc.b()) return SELECT_ALL;
	}
	if(nOutcode & OUTCODE_UPPER){	//片方が上に出ている
		y=rc.t();
		x=x1+((y-y1)*(x2-x1))/(y2-y1);
		if(x >= rc.l() && x <= rc.r()) return SELECT_ALL;
	}
	if(nOutcode & OUTCODE_LOWER){	//片方が下に出ている
		y=rc.b();
		x=x1+((y-y1)*(x2-x1))/(y2-y1);
		if(x >= rc.l() && x <= rc.r()) return SELECT_ALL;
	}
	return 0;
}
Esempio n. 14
0
void Character::Update(float deltaTime, const Map& map)
{
	const float kSpeed = 500.0f;

	//Check horizontal movement
	if (Input_IsKeyDown(Keys::RIGHT))
	{
		mVelocity.x = kSpeed * deltaTime;
	}
	else if (Input_IsKeyDown(Keys::LEFT))
	{
		mVelocity.x = -kSpeed * deltaTime;
	}
	else
	{
		mVelocity.x = 0.0f;
	}

	// Check collision
	SRect bb = GetBoundingBox();
	SRect newbb = bb + SVector2(mVelocity.x, 0.0f);
	SRect rightbb = map.GetBoundingBoxFromSegment(newbb.GetRightSegment());
	SRect leftbb = map.GetBoundingBoxFromSegment(newbb.GetLeftSegment());

	// Right collision
	if (mVelocity.x > 0.0f && rightbb.IsValid())
	{
		mPosition.x += (int)(rightbb.min.x - bb.max.x) - 1.0f;
	}
	// Left collision
	else if (mVelocity.x < 0.0f && leftbb.IsValid())
	{
		mPosition.x += (int)(leftbb.max.x - bb.min.x) + 1.0f;
	}
	else
	{
		mPosition.x += (int)mVelocity.x;
	}


	//Check vertical movement
	//if (Input_IsKeyDown(Keys::DOWN))
	//{
	//	mVelocity.y = kSpeed * deltaTime;
	//}
	//else if (Input_IsKeyDown(Keys::UP))
	//{
	//	mVelocity.y = -kSpeed * deltaTime;
	//}
	//else
	//{
	//	mVelocity.y = 0.0f;
	//}

	if(!mJumping && Input_IsKeyPressed(Keys::UP))
	{
		mVelocity.y = -30.0f;
		mJumping = true;
	}
	else
	{
		mVelocity.y += 100.0f * deltaTime;
	}

	mVelocity.y = Min(mVelocity.y, 30.0f);

	// Check collision
	newbb =  bb + SVector2(0.0f, mVelocity.y);
	SRect bottombb = map.GetBoundingBoxFromSegment(newbb.GetBottomSegment());
	SRect topbb = map.GetBoundingBoxFromSegment(newbb.GetTopSegment());

	// Bottom collision
	if(mVelocity.y > 0.0f && bottombb.IsValid())
	{
		mPosition.y += (int)(bottombb.min.y - bb.max.y) - 1.0f;
		mVelocity.y = 0.0f;
		mJumping = false;
	}
	// Top collision
	else if(mVelocity.y < 0.0f && topbb.IsValid())
	{
		mPosition.y += (int)(topbb.max.y - bb.min.y) + 1.0f;
		mVelocity.y = 0.0f;
	}
	else
	{
		mPosition.y += (int)mVelocity.y;
	}



}
Esempio n. 15
0
//描画が必要かどうかを返す
bool SXBSchLine::qRedraw(const SRect& rc)
{
	SRect rcDraw(rc.l()-1,rc.t()-1,rc.r()+1,rc.b()+1);
	if(testSelection(rcDraw)) 	return true;
	else 						return false;
}
Esempio n. 16
0
tbool CScrollBar::OnMouse(EMouseMsg MouseMsg, const SPos& Pos)
{
	if (!IsVisible()) {
		return false;
	}

	if (CPane::OnMouse(MouseMsg, Pos)) {
		return true;
	}

	if (mbScrolling) {
		// We're currently scrolling
		switch(MouseMsg) {
			case MouseMove:
				{
					switch(mType) {
						case TypeHorizontal:
							{
								// Calculate the mouse delta
								tint iMouseDelta = Pos.iX - mMousePosOrg.iX;

								// Calculate where we want the handle to be
								tint iHandlePosX = mScrollBarRectOrg.iX + iMouseDelta;

								// Calculate movememt from mouse delta
								std::list<IControl*>::iterator it = mControls.begin();
								if (mControls.size() > 2) {
									it++;
								}
								IControl* pControl = *it++;
								SRect RctArrowLeft;
								pControl->GetRect(RctArrowLeft);

								// Left-most possible handle position
								SPos PosLeftMost(RctArrowLeft.iX + RctArrowLeft.iCX, RctArrowLeft.iY);

								pControl = *it;
								SPos PosRightArrow;
								pControl->GetPos(PosRightArrow);
								tint iMaxWidth = PosRightArrow.iX - PosLeftMost.iX;

								// Calculate the relative width we occupy
								tfloat64 fWidthRelative = mScrollPos.VisibleRect.iCX / (double)mScrollPos.AreaSize.iCX;

								// Calculate the ralative position to be
								tfloat64 fPositionRelative = (iHandlePosX - PosLeftMost.iX) / (iMaxWidth - (fWidthRelative * iMaxWidth));

								// Update scrolling position
								mScrollPos = mScrollPosOrg;
								mScrollPos.VisibleRect.iX = (int)((fPositionRelative * (mScrollPos.AreaSize.iCX - mScrollPos.VisibleRect.iCX)) + 0.5f);

								// Limit scrolling position
								if (mScrollPos.VisibleRect.iX < 0) {
									mScrollPos.VisibleRect.iX = 0;
								}
								if (mScrollPos.VisibleRect.iX > mScrollPos.AreaSize.iCX - mScrollPos.VisibleRect.iCX) {
									mScrollPos.VisibleRect.iX = mScrollPos.AreaSize.iCX - mScrollPos.VisibleRect.iCX;
								}

								// Redraw and set scroll pos (which will cause scroll pane to redraw)
								CControl::Redraw();
								mpScrollPane->SetScrollPos(mScrollPos);

								SetValue(0);
							}
							break;
						case TypeVertical:
							{
								// Calculate the mouse delta
								tint iMouseDelta = Pos.iY - mMousePosOrg.iY;

								// Calculate where we want the handle to be
								tint iHandlePosY = mScrollBarRectOrg.iY + iMouseDelta;

								// Calculate movememt from mouse delta
								std::list<IControl*>::iterator it = mControls.begin();
								if (mControls.size() > 2) {
									it++;
								}
								IControl* pControl = *it++;
								SRect RctArrowTop;
								pControl->GetRect(RctArrowTop);

								// Top-most possible handle position
								SPos PosTopMost(RctArrowTop.iX, RctArrowTop.iY + RctArrowTop.iCY);

								pControl = *it;
								SPos PosBottomArrow;
								pControl->GetPos(PosBottomArrow);
								tint iMaxHeight = PosBottomArrow.iY - PosTopMost.iY;

								// Calculate the relative height we occupy
								tfloat64 fHeightRelative = mScrollPos.VisibleRect.iCY / (double)mScrollPos.AreaSize.iCY;

								// Calculate the ralative position to be
								tfloat64 fPositionRelative = (iHandlePosY - PosTopMost.iY) / (iMaxHeight - (fHeightRelative * iMaxHeight));

								// Update scrolling position
								mScrollPos = mScrollPosOrg;
								mScrollPos.VisibleRect.iY = (int)((fPositionRelative * (mScrollPos.AreaSize.iCY - mScrollPos.VisibleRect.iCY)) + 0.5f);

								// Limit scrolling position
								if (mScrollPos.VisibleRect.iY < 0) {
									mScrollPos.VisibleRect.iY = 0;
								}
								if (mScrollPos.VisibleRect.iY > mScrollPos.AreaSize.iCY - mScrollPos.VisibleRect.iCY) {
									mScrollPos.VisibleRect.iY = mScrollPos.AreaSize.iCY - mScrollPos.VisibleRect.iCY;
								}

								// Redraw and set scroll pos (which will cause scroll pane to redraw)
								CControl::Redraw();
								mpScrollPane->SetScrollPos(mScrollPos);

								SetValue(0);
							}
							break;
					}
				}
				break;
			case LeftButtonUp:
				{
					dynamic_cast<CWindow*>(GetParentWindow())->ReleaseMouseFocus();

					mbScrolling = false;

					return true;
				}
				break;
		}
	}

	SRect rctHandle = GetHandleRect();
	if (rctHandle.Inside(Pos)) {
		// We hit the handle with the mouse
		if (MouseMsg == LeftButtonDown) {
			mMousePosOrg = Pos;
			mScrollPosOrg = mScrollPos;
			mScrollBarRectOrg = rctHandle;

			dynamic_cast<CWindow*>(GetParentWindow())->GetMouseFocus(dynamic_cast<IControl*>(this));

			mbScrolling = true;

			return true;
		}
	}
	else {
		if (MouseMsg == LeftButtonDown) {
			SRect RctThis;
			GetRect(RctThis);
			if (RctThis.Inside(Pos)) {
				// We hit inside the control (but not the handle)
				switch(mType) {
					case TypeHorizontal:
						{
							// Calculate the mouse delta
							tint iMouseDelta;
							if (Pos.iX < rctHandle.iX) {
								iMouseDelta = -rctHandle.iCX;
							}
							else {
								iMouseDelta = rctHandle.iCX;
							}

							// Calculate where we want the handle to be
							tint iHandlePosX = rctHandle.iX + iMouseDelta;

							// Calculate movememt from mouse delta
							std::list<IControl*>::iterator it = mControls.begin();
							if (mControls.size() > 2) {
								it++;
							}
							IControl* pControl = *it++;
							SRect RctArrowLeft;
							pControl->GetRect(RctArrowLeft);

							// Left-most possible handle position
							SPos PosLeftMost(RctArrowLeft.iX + RctArrowLeft.iCX, RctArrowLeft.iY);

							pControl = *it;
							SPos PosRightArrow;
							pControl->GetPos(PosRightArrow);
							tint iMaxWidth = PosRightArrow.iX - PosLeftMost.iX;

							// Calculate the relative width we occupy
							tfloat64 fWidthRelative = mScrollPos.VisibleRect.iCX / (double)mScrollPos.AreaSize.iCX;

							// Calculate the ralative position to be
							tfloat64 fPositionRelative = (iHandlePosX - PosLeftMost.iX) / (iMaxWidth - (fWidthRelative * iMaxWidth));

							// Update scrolling position
							mScrollPos = mScrollPos;
							mScrollPos.VisibleRect.iX = (int)((fPositionRelative * (mScrollPos.AreaSize.iCX - mScrollPos.VisibleRect.iCX)) + 0.5f);

							// Limit scrolling position
							if (mScrollPos.VisibleRect.iX < 0) {
								mScrollPos.VisibleRect.iX = 0;
							}
							if (mScrollPos.VisibleRect.iX > mScrollPos.AreaSize.iCX - mScrollPos.VisibleRect.iCX) {
								mScrollPos.VisibleRect.iX = mScrollPos.AreaSize.iCX - mScrollPos.VisibleRect.iCX;
							}

							// Redraw and set scroll pos (which will cause scroll pane to redraw)
							CControl::Redraw();
							mpScrollPane->SetScrollPos(mScrollPos);
							
							// Lasse, added 2008-04-17 - bug-fix, didn't fire listeners' EventValueChange
							SetValue(0);
							// .. Lasse
						}
						break;

					case TypeVertical:
						{
							// Calculate the mouse delta
							tint iMouseDelta;
							if (Pos.iY < rctHandle.iY) {
								iMouseDelta = -rctHandle.iCY;
							}
							else {
								iMouseDelta = rctHandle.iCY;
							}

							// Calculate where we want the handle to be
							tint iHandlePosY = rctHandle.iY + iMouseDelta;

							// Calculate movememt from mouse delta
							std::list<IControl*>::iterator it = mControls.begin();
							if (mControls.size() > 2) {
								it++;
							}
							IControl* pControl = *it++;
							SRect RctArrowTop;
							pControl->GetRect(RctArrowTop);

							// Top-most possible handle position
							SPos PosTopMost(RctArrowTop.iX, RctArrowTop.iY + RctArrowTop.iCY);

							pControl = *it;
							SPos PosBottomArrow;
							pControl->GetPos(PosBottomArrow);
							tint iMaxHeight = PosBottomArrow.iY - PosTopMost.iY;

							// Calculate the relative height we occupy
							tfloat64 fHeightRelative = mScrollPos.VisibleRect.iCY / (double)mScrollPos.AreaSize.iCY;

							// Calculate the ralative position to be
							tfloat64 fPositionRelative = (iHandlePosY - PosTopMost.iY) / (iMaxHeight - (fHeightRelative * iMaxHeight));

							// Update scrolling position
							mScrollPos = mScrollPos;
							mScrollPos.VisibleRect.iY = (int)((fPositionRelative * (mScrollPos.AreaSize.iCY - mScrollPos.VisibleRect.iCY)) + 0.5f);

							// Limit scrolling position
							if (mScrollPos.VisibleRect.iY < 0) {
								mScrollPos.VisibleRect.iY = 0;
							}
							if (mScrollPos.VisibleRect.iY > mScrollPos.AreaSize.iCY - mScrollPos.VisibleRect.iCY) {
								mScrollPos.VisibleRect.iY = mScrollPos.AreaSize.iCY - mScrollPos.VisibleRect.iCY;
							}

							// Redraw and set scroll pos (which will cause scroll pane to redraw)
							CControl::Redraw();
							mpScrollPane->SetScrollPos(mScrollPos);
							
							// Lasse, added 2008-04-17 - bug-fix, didn't fire listeners' EventValueChange
							SetValue(0);
							// .. Lasse
						}
						break;
				}
			}
		}
	}

	return false;
}
Esempio n. 17
0
SRect CGM_Slider::GetLocalButtonRectInOwnerDialogCoord()
{
	SRect rect = GetButtonRect();
	rect.Offset( -GetOwnerDialog()->GetBoundingBox().GetTopLeftCorner() );
	return rect;
}
Esempio n. 18
0
void Character::Update(float deltaTime, const Map& map, const SVector2& renderOffset)
{
	const float kSpeed = 256.0f;

	// Check horizontal movement
	if(Input_IsKeyDown(Keys::RIGHT))
	{
		mVelocity.x = kSpeed * deltaTime;
		mSprite.SetRotation(1.575f);
	}
	else if(Input_IsKeyDown(Keys::LEFT))
	{
		mVelocity.x = -kSpeed * deltaTime;
		mSprite.SetRotation(-1.575f);
	}
	else
	{
		mVelocity.x = 0.0f;
	}

	// Check collision
	SRect bb = GetBoundingBox(renderOffset);
	SRect newbb = bb + SVector2(mVelocity.x, 0.0f);

	SLineSegment tempRightLS(newbb.GetRightSegment().from.x - renderOffset.x,
							newbb.GetRightSegment().from.y - renderOffset.y,
							newbb.GetRightSegment().to.x - renderOffset.x,
							newbb.GetRightSegment().to.y - renderOffset.y);
	SLineSegment tempLeftLS(newbb.GetLeftSegment().from.x - renderOffset.x,
							newbb.GetLeftSegment().from.y - renderOffset.y,
							newbb.GetLeftSegment().to.x - renderOffset.x,
							newbb.GetLeftSegment().to.y - renderOffset.y);

	SRect rightbb = map.GetBoudingBoxFromSegment(tempRightLS);
	SRect leftbb = map.GetBoudingBoxFromSegment(tempLeftLS);

	Graphics_DebugRect(bb, 0xF04BC3);
	Graphics_DebugRect(newbb, 0x004BC3);
	Graphics_DebugRect(rightbb, 0xF04B00);
	Graphics_DebugRect(leftbb, 0xF000C3);
	
	// Right Collision
	if(mVelocity.x > 0.0f && rightbb.IsValid())
	{
		mPosition.x += static_cast<int>(rightbb.min.x - bb.max.x) - 1.0f;
	}
	// Left Collision
	else if(mVelocity.x < 0.0f && leftbb.IsValid())
	{
		mPosition.x += static_cast<int>(leftbb.max.x - bb.min.x) + 1.0f;
	}
	else
	{
		mPosition.x += static_cast<int>(mVelocity.x);
	}

	// Check vertical movement
	if(Input_IsKeyDown(Keys::DOWN))
	{
		mVelocity.y = kSpeed * deltaTime;
		mSprite.SetRotation(3.15f);
	}
	else if(Input_IsKeyDown(Keys::UP))
	{
		mVelocity.y = -kSpeed * deltaTime;
		mSprite.SetRotation(0.0f);
	}
	else
	{
		mVelocity.y = 0.0f;
	}

	// Check collision
	newbb = bb + SVector2(0.0f, mVelocity.y);
	SRect topbb = map.GetBoudingBoxFromSegment(newbb.GetTopSegment());
	SRect bottombb = map.GetBoudingBoxFromSegment(newbb.GetBottomSegment());
	
	// Top Collision
	if(mVelocity.y < 0.0f && topbb.IsValid())
	{
		mPosition.y += static_cast<int>(topbb.max.y - bb.min.y) + 1.0f;
	}
	// Bottom Collision
	else if(mVelocity.y > 0.0f && bottombb.IsValid())
	{
		mPosition.y += static_cast<int>(bottombb.min.y - bb.max.y) - 1.0f;
	}
	else
	{
		mPosition.y += static_cast<int>(mVelocity.y);
	}

	mPosition += mVelocity;
}
void CGM_StdSliderRenderer::Init( CGM_Slider& slider )
{
//	CGM_StdStaticRenderer::Init( CGM_Static *pStatic );

	// slider frame
	const SFloatRGBAColor& normal_color = m_aColor[CGM_Control::STATE_NORMAL];
	const SFloatRGBAColor& bg_color     = SFloatRGBAColor(0.0f,0.0f,0.0f,0.6f);
	m_pRect                  = m_pGraphicsElementManager->CreateRect(      slider.GetLocalRect(), bg_color, normal_color, 2 );
//	m_pFrameRect             = m_pGraphicsElementManager->CreateFrameRect( slider.GetLocalRect(), normal_color, 2 );

	// slider button
	SRect btn_rect = slider.GetButtonRect();
	SRect local_btn_rect = RectLTWH( 0, 0, btn_rect.GetWidth(), btn_rect.GetHeight() );
	m_pSliderButtonRect      = m_pGraphicsElementManager->CreateRect(      local_btn_rect,  bg_color, normal_color, 2 );
//	m_pSliderButtonFrameRect = m_pGraphicsElementManager->CreateFrameRect( local_btn_rect,  normal_color, 2 );

	SRect dot_rect = local_btn_rect;
	dot_rect.Inflate( -dot_rect.GetWidth() / 4, -dot_rect.GetHeight() / 4 );
	m_pSliderButtonDot       = m_pGraphicsElementManager->CreateFillRect( dot_rect, normal_color, 2 );

	const SRect slider_rect = slider.GetBoundingBox();
	const SPoint slider_topleft = slider_rect.GetTopLeftCorner(); // global
	const SPoint btn_local_topleft = slider.GetLocalButtonRectInOwnerDialogCoord().GetTopLeftCorner(); // local coord of owner dialog

	// subgroup for slider button
	vector<boost::shared_ptr<GraphicsElement> > vecpButtonElement;
	vecpButtonElement.push_back( m_pSliderButtonRect );
//	vecpButtonElement.push_back( m_pSliderButtonFrameRect );
	vecpButtonElement.push_back( m_pSliderButtonDot );
	m_pSliderButtonRect->SetLocalTopLeftPos( Vector2(0,0) );
//	m_pSliderButtonFrameRect->SetLocalTopLeftPos( SPoint(0,0) );
	m_pSliderButtonDot->SetLocalTopLeftPos( SPoint(0,0) + dot_rect.GetTopLeftCorner() );
	m_pSliderButton = m_pGraphicsElementManager->CreateGroup( vecpButtonElement, btn_local_topleft );


	// For slider button elements, the following 2 things need to be done separately
	// 1. register to parent dialog renderer
	//    - register the subgroup of slider button elements
	// 2. set local layer offsets
	//    - set for each element

	// register the subgroup to the parent dialog renderer
	RegisterGraphicsElementToParentDialog( m_pSliderButton );

	// set different local layer offset for each grouped element
	SetLocalLayerOffset( 0, m_pSliderButtonDot );
//	SetLocalLayerOffset( 0, m_pSliderButtonFrameRect );
	SetLocalLayerOffset( 1, m_pSliderButtonRect );

	// register elements and set local layer offset to determine rendering order
	// - these guys don't belong to any subgroup of the renderer so each of them can be
	//   registered with a single call of RegisterGraphicsElement()
//	RegisterGraphicsElement( 2, m_pFrameRect );
	RegisterGraphicsElement( 3, m_pRect );

	// register elements that chages colors depending on states
//	RegisterColoredElement( m_pFrameRect );
//	RegisterColoredElement( m_pSliderButtonFrameRect );
	RegisterColoredElement( m_pRect->FrameElement() );
	RegisterColoredElement( m_pSliderButtonRect->FrameElement() );

}
Esempio n. 20
0
void NPC::CheckCollision(float fSeconds, Map& map, Character& character) {
	// Check collision
	SRect bb = GetBoundingBox();
	SRect newbb = bb + SVector2(mVelocity.x, 0.0f);
	SRect rightbb = map.GetBoundingBoxFromSegment(newbb.GetRightSegment(),
			*this, character);
	SRect leftbb = map.GetBoundingBoxFromSegment(newbb.GetLeftSegment(), *this,
			character);

	// Right collision
	if (mVelocity.x > 0.0f && rightbb.IsValid()) {
		mNPCData.mPosition.x += static_cast<int>(rightbb.min.x - bb.max.x)
				- 1.0f;
	}
	// Left collision
	else if (mVelocity.x < 0.0f && leftbb.IsValid()) {
		mNPCData.mPosition.x += static_cast<int>(leftbb.max.x - bb.min.x)
				+ 1.0f;
	} else {
		mNPCData.mPosition.x += static_cast<int>(mVelocity.x);
	}

	// Check collision
	newbb = bb + SVector2(0.0f, mVelocity.y);
	SRect bottombb = map.GetBoundingBoxFromSegment(newbb.GetBottomSegment(),
			*this, character);
	SRect topbb = map.GetBoundingBoxFromSegment(newbb.GetTopSegment(), *this,
			character);

	// Bottom collision
	if (mVelocity.y > 0.0f && bottombb.IsValid()) {
		mNPCData.mPosition.y += static_cast<int>(bottombb.min.y - bb.max.y)
				- 1.0f;
		mVelocity.y = 0.0f;
		Graphics_DebugRect(newbb + sOffset, 0xff00ff);
		Graphics_DebugRect(bottombb + sOffset, 0xff0000);
	}

	// Top collision
	else if (mVelocity.y < 0.0f && topbb.IsValid()) {
		mNPCData.mPosition.y += static_cast<int>(topbb.max.y - bb.min.y) + 1.0f;
		mVelocity.y = 0.0f;
		Graphics_DebugRect(newbb + sOffset, 0xff00ff);
		Graphics_DebugRect(topbb + sOffset, 0xff0000);
	} else {
		mNPCData.mPosition.y += static_cast<int>(mVelocity.y);
	}
}