Ejemplo n.º 1
0
void SDLDraw::drawRectangle(const Int2& pos1, const Int2& pos2, const Color& color, bool fill)
{
	SDL_SetRenderDrawColor(s_sdlRenderer, color.r(), color.g(), color.b(), color.a());
	SDL_Rect rect;
	rect.x = MathUtils::minimum(pos1.x(), pos2.x());
	rect.y = MathUtils::minimum(pos1.y(), pos2.y());
	rect.w = abs(pos2.x()-pos1.x());
	rect.h = abs(pos2.x()-pos1.x());
	if (fill) SDL_RenderFillRect(s_sdlRenderer, &rect);
	else SDL_RenderDrawRect(s_sdlRenderer, &rect);
}
Ejemplo n.º 2
0
void drawLine(const Int2& pos1, const Int2& pos2, const Color& color, float thickness)
{
	glLineWidth(thickness);
	glColor4f(color.r()/256.f, color.g()/256.f, color.b()/256.f, color.a()/256.f);
	glDisable(GL_TEXTURE_2D);

    glMatrixMode(GL_MODELVIEW);

	glBegin(GL_LINES);
    glVertex2i(pos1.x(), pos1.y());
    glVertex2i(pos2.x(), pos2.y());
    glEnd();
	glColor4f(1.f, 1.f, 1.f, 1.f);
}
Ejemplo n.º 3
0
void drawRectangle(const Int2& pos1, const Int2& pos2, const Color& color, float borderSize, bool isFilled)
{
	glLineWidth(borderSize);
	glColor4f(color.r()/256.f, color.g()/256.f, color.b()/256.f, color.a()/256.f);
	//glColor4f(color.r()/255.f, color.g()/255.f, color.b()/255.f, color.a()/255.f);
	glDisable(GL_TEXTURE_2D);

    glMatrixMode(GL_MODELVIEW);

    glBegin(isFilled ? GL_QUADS : GL_LINE_LOOP);
    glVertex2i(pos1.x(), pos1.y());
    glVertex2i(pos2.x(), pos1.y());
    glVertex2i(pos2.x(), pos2.y());
    glVertex2i(pos1.x(), pos2.y());
    glEnd();
	glColor4f(1.f, 1.f, 1.f, 1.f);
}
Ejemplo n.º 4
0
	bool AdvancedBox::isThereIntersectionSlow(const Int2& pointToTest) const
	{
		//cas courant
		if (data[0].y() == data[1].y() && data[2].y() == data[2].y()
			&& data[1].x() == data[2].x() && data[3].x() == data[0].x()
			&& data[0].x() > data[1].x() && data[1].y() > data[2].y())
		{
			return pointToTest.x() < data[0].x() && pointToTest.x() > data[1].x()
				&& pointToTest.y() < data[1].y() && pointToTest.y() > data[2].y();
		}

		Int2 pointBox1InNewReference;
		Int2 pointBox2InNewReference;

		int j = 0;
		for (; j < 4; ++j)
		{
			const Int2& pointBox1 = data[j];
			const Int2& pointBox2 = data[(j + 1) % 4];

			//verifie si pointToTest est du bon cote de la droite (pointBox1, pointBox2)
			pointBox1InNewReference = pointBox1 - pointToTest;
			pointBox2InNewReference = pointBox2 - pointToTest;

			float anglePointBox1 = atan2(-(float)pointBox1InNewReference.y(), (float)pointBox1InNewReference.x());
			float anglePointBox2 = atan2(-(float)pointBox2InNewReference.y(), (float)pointBox2InNewReference.x());

			if (anglePointBox1 > anglePointBox2 + MathUtils::PI)
			{
				anglePointBox1 -= MathUtils::PI * 2;
				Assert(anglePointBox1 <= anglePointBox2 + MathUtils::PI);
			}
			else if (anglePointBox2 > anglePointBox1 + MathUtils::PI)
			{
				anglePointBox2 -= MathUtils::PI * 2;
				Assert(anglePointBox2 <= anglePointBox1 + MathUtils::PI);
			}

			if (anglePointBox1 <= anglePointBox2)
				break;
		}

		return j == 4;
	}
Ejemplo n.º 5
0
	void drawLine(ID2D1DeviceContext* context, const Float2& zoomRatio, const Int2& pos1, const Int2& pos2, const Color& color, float thickness)
	{
		D2D1::ColorF colorDx(color.r() / 256.f, color.g() / 256.f, color.b() / 256.f, color.a() / 256.f);
		//D2D1::ColorF colorDx = D2D1::ColorF::MidnightBlue;
		ID2D1SolidColorBrush* solidBrush;
		DX::ThrowIfFailed(context->CreateSolidColorBrush(colorDx, &solidBrush));

		D2D1_POINT_2F pt1;
		pt1.x = zoomRatio.x() + (float)pos1.x();
		pt1.y = zoomRatio.y() + (float)pos1.y();
		D2D1_POINT_2F pt2;
		pt2.x = zoomRatio.x() + (float)pos2.x();
		pt2.y = zoomRatio.y() + (float)pos2.y();
		context->SetTransform(D2D1::Matrix3x2F::Identity());
		//s_context->SetDpi(DirectXDraw::getDefaultDpi().x(), DirectXDraw::getDefaultDpi().y());

		context->DrawLine(pt1, pt2, solidBrush, thickness);

		solidBrush->Release();
		//delete solidBrush;
	}
Ejemplo n.º 6
0
	void drawRoundedRectangle(ID2D1DeviceContext* context, const Float2& zoomRatio, const Int2& posLeftTop, const Int2& posRightBottom, const Color& color, float round, float borderSize, bool fill)
	{
		D2D1::ColorF colorDx(color.r() / 256.f, color.g() / 256.f, color.b() / 256.f, color.a() / 256.f);
		ID2D1SolidColorBrush* solidBrush;
		DX::ThrowIfFailed(context->CreateSolidColorBrush(colorDx, &solidBrush));

		D2D1_ROUNDED_RECT rrect;
		rrect.radiusX = round;
		rrect.radiusY = round;
		rrect.rect.left = zoomRatio.x() + (float)posLeftTop.x();
		rrect.rect.top = zoomRatio.y() + (float)posLeftTop.y();
		rrect.rect.right = zoomRatio.x() + (float)posRightBottom.x();
		rrect.rect.bottom = zoomRatio.y() + (float)posRightBottom.y();
		context->SetTransform(D2D1::Matrix3x2F::Identity());

		if (fill) context->FillRoundedRectangle(rrect, solidBrush);
		//if (borderSize > 0.f) 
		context->DrawRoundedRectangle(rrect, solidBrush, borderSize);

		solidBrush->Release();
		//delete solidBrush;
	}
void OpenGLApp_onPointerPressedOrReleased(int button, int state,int x, int y)
{
	Int2 pos = AppSetup::instance().convertRealPositionToVirtualPosition(Int2(x,y));
	if (button==GLUT_WHEEL_UP)
	{
		s_mainClass->onPointerWheelChanged(120, pos.x(), pos.y());
	}
	else if (button==GLUT_WHEEL_DOWN)
	{
		s_mainClass->onPointerWheelChanged(-120, pos.x(), pos.y());
	}
	else if (state==GLUT_DOWN)
	{
		Engine::instance().onPointerPressedInternals(button, x, y);
		s_mainClass->onPointerPressed(button, pos.x(), pos.y());
	}
	else if (state==GLUT_UP)
	{
		Engine::instance().onPointerReleasedInternals(button, x, y);
		s_mainClass->onPointerReleased(button, pos.x(), pos.y());
	}
	s_eventHappened = true;
}
Ejemplo n.º 8
0
void SDLDraw::drawLine(const Int2& pos1, const Int2& pos2, const Color& color)
{
	SDL_SetRenderDrawColor(s_sdlRenderer, color.r(), color.g(), color.b(), color.a());
	SDL_RenderDrawLine(s_sdlRenderer, pos1.x(), pos1.y(), pos2.x(), pos2.y());
}
Ejemplo n.º 9
0
	void AdvancedBox::calculate(const Int2& parPos, const Int2& parSize, const Int2& parHotSpot, float angleDegrees, int xTopDeformation, int xBottomDeformation)
	{
		float angleRadians = angleDegrees * MathUtils::PI / 180.0f;

		data[0] = getRotatedPoint(
			parPos.x() + parSize.width() - parHotSpot.x(), parPos.y() + parSize.height() - parHotSpot.y(),
			angleRadians,
			parPos.x()/*-1*/, parPos.y(), xBottomDeformation);

		data[1] = getRotatedPoint(
			parPos.x() - parHotSpot.x(), parPos.y() + parSize.height() - parHotSpot.y(),
			angleRadians,
			parPos.x(), parPos.y(), xBottomDeformation);

		data[2] = getRotatedPoint(
			parPos.x() - parHotSpot.x(), parPos.y() - parHotSpot.y(),
			angleRadians,
			parPos.x(), parPos.y(), xTopDeformation);

		data[3] = getRotatedPoint(
			parPos.x() + parSize.width() - parHotSpot.x(), parPos.y() - parHotSpot.y(),
			angleRadians,
			parPos.x()/*-1*/, parPos.y(), xTopDeformation);

		/*PrintValue(data[0]);
		PrintValue(data[1]);
		PrintValue(data[2]);
		PrintValue(data[3]);
		Print("");*/
	}
Ejemplo n.º 10
0
	static bool intersectionSegments(const Int2& ptA, const Int2& ptB, const Int2& ptC, const Int2& ptD)
	{
		Float2 ptS;
		if (ptA.x() == ptB.x())
		{
			if (ptC.x() == ptD.x())
				return false;
			else
			{
				float pCD = (float)(ptC.y() - ptD.y()) / (float)(ptC.x() - ptD.x());
				ptS.data[0] = (float)ptA.x();
				ptS.data[1] = pCD*(float)(ptA.x() - ptC.x()) + (float)ptC.y();
			}
		}
		else
		{
			if (ptC.x() == ptD.x())
			{
				float pAB = (float)(ptA.y() - ptB.y()) / (float)(ptA.x() - ptB.x());
				ptS.data[0] = (float)ptC.x();
				ptS.data[1] = pAB*(float)(ptC.x() - ptA.x()) + (float)ptA.y();
			}
			else
			{
				float pCD = (float)(ptC.y() - ptD.y()) / (float)(ptC.x() - ptD.x());
				float pAB = (float)(ptA.y() - ptB.y()) / (float)(ptA.x() - ptB.x());
				float oCD = (float)ptC.y() - pCD*(float)ptC.x();
				float oAB = (float)ptA.y() - pAB*(float)ptA.x();
				ptS.data[0] = (oAB - oCD) / (pCD - pAB);
				ptS.data[1] = pCD*ptS.data[0] + oCD;
			}
		}

		Int2 ptSInt;
		ptSInt.data[0] = (int)ptS.data[0];//roundNumber(ptS.data[0]);
		ptSInt.data[1] = (int)ptS.data[1];//roundNumber(ptS.data[1]);

		if ((ptSInt.x() < ptA.x() && ptSInt.x() < ptB.x())
			|| (ptSInt.x() > ptA.x() && ptSInt.x() > ptB.x())
			|| (ptSInt.x() < ptC.x() && ptSInt.x() < ptD.x())
			|| (ptSInt.x() > ptC.x() && ptSInt.x() > ptD.x())
			|| (ptSInt.y() < ptA.y() && ptSInt.y() < ptB.y())
			|| (ptSInt.y() > ptA.y() && ptSInt.y() > ptB.y())
			|| (ptSInt.y() < ptC.y() && ptSInt.y() < ptD.y())
			|| (ptSInt.y() > ptC.y() && ptSInt.y() > ptD.y()))
		{
			return false;
		}

		return true;
	}
void OpenGLApp_onPointerMovingPassive(int x,int y)
{
	Int2 pos = AppSetup::instance().convertRealPositionToVirtualPosition(Int2(x,y));
	Engine::instance().onPointerMovedInternals(false, pos.x(), pos.y());
	s_mainClass->onPointerMoved(false, pos.x(), pos.y());
}
Ejemplo n.º 12
0
	void drawBitmap(
		ID2D1DeviceContext* context, const Float2& zoomRatio, const Float2& m_defaultDpi, 
		ID2D1Bitmap* bitmap, const Float2& position, const Float2& scale, float opacity, D2D1_RECT_F* rectSource, D2D1_RECT_F* rectDest, float angleDegree, const Int2& rotationCenterPos, 
		bool horizontalMirror, bool verticalMirror)
	{
		D2D1_MATRIX_3X2_F transformTmp;
		context->GetTransform(&transformTmp);

		D2D1::Matrix3x2F matTranslation = D2D1::Matrix3x2F::Translation(zoomRatio.x() + position.x(), zoomRatio.y() + position.y());//  / scale.x() / scale.y()
		
		if (angleDegree != 0.f || horizontalMirror || verticalMirror)
		{
			D2D1::Matrix3x2F matMirroring = D2D1::Matrix3x2F::Scale(horizontalMirror ? -1.f : 1.f, verticalMirror ? -1.f : 1.f);
			D2D1_POINT_2F imageRotationCenterPos = D2D1::Point2F((float)rotationCenterPos.x(), (float)rotationCenterPos.y());
			D2D1::Matrix3x2F matRotation = D2D1::Matrix3x2F::Rotation(angleDegree, imageRotationCenterPos);
			context->SetTransform(matMirroring * matRotation * matTranslation);
		}
		else
		{
			context->SetTransform(matTranslation);// * s_ppp.x() * s_ppp.y()
		}

		//Assert(scale.x() > 0.f && scale.y() > 0.f);
		
		// note about bitmaps: https://msdn.microsoft.com/en-us/library/windows/desktop/dd371150%28v=vs.85%29.aspx
		Float2 dpiBitmap;
		bitmap->GetDpi(&dpiBitmap.data[0], &dpiBitmap.data[1]);

		Float2 scaleToApply = dpiBitmap / m_defaultDpi * scale;//s_ppp * dpiBitmap / dpiContext * scale;

		D2D1_RECT_F rectDestFinal;
		if (rectDest == 0)
		{
			D2D1_SIZE_F sz = bitmap->GetSize();
			rectDestFinal.left = 0.f;
			rectDestFinal.top = 0.f;
			rectDestFinal.right = sz.width * scaleToApply.x();
			rectDestFinal.bottom = sz.height *scaleToApply.y();

			context->DrawBitmap(bitmap, &rectDestFinal, opacity, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, rectSource);
		}
		else
		{
			rectDestFinal = *rectDest;
			rectDestFinal.left *= scaleToApply.x();
			rectDestFinal.top *= scaleToApply.y();
			rectDestFinal.right *= scaleToApply.x();
			rectDestFinal.bottom *= scaleToApply.y();

			Float2 srcScaleToApply = dpiBitmap / m_defaultDpi;

			D2D1_RECT_F rectSourceFinal;
			rectSourceFinal = *rectSource;
			rectSourceFinal.left /= srcScaleToApply.x();
			rectSourceFinal.top /= srcScaleToApply.y();
			rectSourceFinal.right /= srcScaleToApply.x();
			rectSourceFinal.bottom /= srcScaleToApply.y();

			context->DrawBitmap(bitmap, &rectDestFinal, opacity, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, &rectSourceFinal);
		}

		context->SetTransform(transformTmp);//D2D1::Matrix3x2F::Translation(0.f, 0.f));
		//s_context->Flush();
	}
Ejemplo n.º 13
0
	void drawTextLayout(ID2D1DeviceContext* context, const Float2& zoomRatio, ID2D1SolidColorBrush* solidBrush, IDWriteTextLayout* textLayout, const Int2& position, const Float2& scale)
	{
		D2D1_MATRIX_3X2_F transformTmp;
		context->GetTransform(&transformTmp);
		context->SetTransform(D2D1::Matrix3x2F::Translation(zoomRatio.x() + (float)position.x() / scale.x(), zoomRatio.y() + (float)position.y() / scale.y()));// * s_ppp.x() * s_ppp.y(
		// TODO scale with s_ppp

		context->DrawTextLayout(D2D1::Point2F(0.0f, 0.0f), textLayout, solidBrush);

		context->SetTransform(transformTmp);
	}