コード例 #1
0
ファイル: windowvx.cpp プロジェクト: Alex223124/mkxp
	void prepare()
	{
		if (base.vertDirty)
		{
			rebuildBaseVert();
			base.vertDirty = false;
			base.texDirty = true;
		}

		if (base.texSizeDirty)
		{
			updateBaseTexSize();
			base.texSizeDirty = false;
			base.texDirty = true;
		}

		if (base.texDirty)
		{
			redrawBaseTex();
			base.texDirty = false;
		}

		if (clipRectDirty)
		{
			updateClipRect();
			clipRectDirty = false;
		}

		if (ctrlVertDirty)
		{
			rebuildCtrlVert();
			updatePauseQuad();
			ctrlVertDirty = false;
		}

		if (ctrlVertArrayDirty)
		{
			ctrlVert.commit();
			ctrlVertArrayDirty = false;
		}

		if (cursorVertDirty)
		{
			rebuildCursorVert();
			updateCursorAlpha();
			cursorVertDirty = false;
		}

		if (cursorVertArrayDirty)
		{
			cursorVert.commit();
			cursorVertArrayDirty = false;
		}
	}
コード例 #2
0
ファイル: windowvx.cpp プロジェクト: Alex223124/mkxp
	void updateCursorAlpha()
	{
		if (cursorVert.count() == 0)
			return;

		Vec4 color(1, 1, 1, cursorAlpha[cursorAlphaIdx] / 255.0f);

		for (size_t i = 0; i < cursorVert.count(); ++i)
			Quad::setColor(&cursorVert.vertices[i*4], color);

		cursorVertArrayDirty = true;
	}
コード例 #3
0
ファイル: windowvx.cpp プロジェクト: Alex223124/mkxp
	WindowVXPrivate(int x, int y, int w, int h)
	    : windowskin(0),
	      contents(0),
	      cursorRect(&tmp.rect),
	      active(true),
	      arrowsVisible(true),
	      pause(false),
	      width(w),
	      height(h),
	      geo(x, y, w, h),
	      padding(DEF_PADDING),
	      paddingBottom(padding),
	      opacity(255),
	      backOpacity(DEF_BACK_OPAC),
	      contentsOpacity(255),
	      openness(255),
	      tone(&tmp.tone),
	      ctrlVertDirty(false),
	      ctrlVertArrayDirty(false),
	      clipRectDirty(false),
	      cursorVertDirty(false),
	      cursorVertArrayDirty(false),
	      pauseAlphaIdx(0),
	      pauseQuadIdx(0),
	      cursorAlphaIdx(0)
	{
		/* 4 scroll arrows + pause */
		ctrlVert.resize(4 + 1);
		pauseVert = &ctrlVert.vertices[4*4];

		base.vertDirty = false;
		base.texSizeDirty = false;
		base.texDirty = false;

		if (w > 0 || h > 0)
		{
			base.vertDirty = true;
			base.texSizeDirty = true;
			clipRectDirty = true;
			ctrlVertDirty = true;
		}

		prepareCon = shState->prepareDraw.connect
			(sigc::mem_fun(this, &WindowVXPrivate::prepare));

		refreshCursorRectCon();
		refreshToneCon();
		updateBaseQuad();
	}
コード例 #4
0
ファイル: bitmap.cpp プロジェクト: Lobomon/mkxp
void Bitmap::radialBlur(int angle, int divisions)
{
	GUARD_DISPOSED;

	GUARD_MEGA;

	angle     = clamp<int>(angle, 0, 359);
	divisions = clamp<int>(divisions, 2, 100);

	const int _width = width();
	const int _height = height();

	float angleStep = (float) angle / (divisions-1);
	float opacity   = 1.0f / divisions;
	float baseAngle = -((float) angle / 2);

	ColorQuadArray qArray;
	qArray.resize(5);

	std::vector<Vertex> &vert = qArray.vertices;

	int i = 0;

	/* Center */
	FloatRect texRect(0, 0, _width, _height);
	FloatRect posRect(0, 0, _width, _height);

	i += Quad::setTexPosRect(&vert[i*4], texRect, posRect);

	/* Upper */
	posRect = FloatRect(0, 0, _width, -_height);

	i += Quad::setTexPosRect(&vert[i*4], texRect, posRect);

	/* Lower */
	posRect = FloatRect(0, _height*2, _width, -_height);

	i += Quad::setTexPosRect(&vert[i*4], texRect, posRect);

	/* Left */
	posRect = FloatRect(0, 0, -_width, _height);

	i += Quad::setTexPosRect(&vert[i*4], texRect, posRect);

	/* Right */
	posRect = FloatRect(_width*2, 0, -_width, _height);

	i += Quad::setTexPosRect(&vert[i*4], texRect, posRect);

	for (int i = 0; i < 4*5; ++i)
		vert[i].color = Vec4(1, 1, 1, opacity);

	qArray.commit();

	TEXFBO newTex = shState->texPool().request(_width, _height);

	FBO::bind(newTex.fbo, FBO::Draw);

	glState.clearColor.pushSet(Vec4());
	FBO::clear();

	Transform trans;
	trans.setOrigin(Vec2(_width / 2.0f, _height / 2.0f));
	trans.setPosition(Vec2(_width / 2.0f, _height / 2.0f));

	glState.blendMode.pushSet(BlendAddition);

	SimpleMatrixShader &shader = shState->shaders().simpleMatrix;
	shader.bind();

	p->bindTexture(shader);
	TEX::setSmooth(true);

	p->pushSetViewport(shader);

	for (int i = 0; i < divisions; ++i)
	{
		trans.setRotation(baseAngle + i*angleStep);
		shader.setMatrix(trans.getMatrix());
		qArray.draw();
	}

	p->popViewport();

	TEX::setSmooth(false);

	glState.blendMode.pop();
	glState.clearColor.pop();

	shState->texPool().release(p->gl);
	p->gl = newTex;

	modified();
}
コード例 #5
0
ファイル: windowvx.cpp プロジェクト: Alex223124/mkxp
	void draw()
	{
		if (base.tex.tex == TEX::ID(0))
			return;

		bool windowskinValid = !nullOrDisposed(windowskin);
		bool contentsValid = !nullOrDisposed(contents);

		Vec2i trans = geo.pos() + sceneOffset;

		SimpleAlphaShader &shader = shState->shaders().simpleAlpha;
		shader.bind();
		shader.applyViewportProj();

		if (windowskinValid)
		{
			shader.setTranslation(trans);
			shader.setTexSize(Vec2i(base.tex.width, base.tex.height));

			TEX::bind(base.tex.tex);
			base.quad.draw();

			if (openness < 255)
				return;

			windowskin->bindTex(shader);

			TEX::setSmooth(true);
			ctrlVert.draw(0, ctrlQuads);
			TEX::setSmooth(false);
		}

		if (openness < 255)
			return;

		bool drawCursor = cursorVert.count() > 0 && windowskinValid;

		if (drawCursor || contentsValid)
		{
			/* Translate cliprect from local into screen space */
			IntRect clip = clipRect;
			clip.setPos(clip.pos() + trans);

			glState.scissorBox.push();
			glState.scissorTest.pushSet(true);

			if (rgssVer >= 3)
				glState.scissorBox.setIntersect(clip);
			else
				glState.scissorBox.setIntersect(IntRect(trans, geo.size()));

			IntRect pad = padRect;
			pad.setPos(pad.pos() + trans);

			if (drawCursor)
			{
				Vec2i contTrans = pad.pos();
				contTrans.x += cursorRect->x;
				contTrans.y += cursorRect->y;

				if (rgssVer >= 3)
					contTrans -= contentsOff;

				shader.setTranslation(contTrans);

				TEX::setSmooth(true);
				cursorVert.draw();
				TEX::setSmooth(false);
			}

			if (contentsValid)
			{
				if (rgssVer <= 2)
					glState.scissorBox.setIntersect(clip);

				Vec2i contTrans = pad.pos();
				contTrans -= contentsOff;
				shader.setTranslation(contTrans);

				TEX::setSmooth(false); // XXX
				contents->bindTex(shader);
				contentsQuad.draw();
			}

			glState.scissorBox.pop();
			glState.scissorTest.pop();
		}

		TEX::setSmooth(false); // XXX FIND out a way to eliminate
	}
コード例 #6
0
ファイル: windowvx.cpp プロジェクト: Alex223124/mkxp
	void rebuildCursorVert()
	{
		const IntRect rect = cursorRect->toIntRect();
		const CursorSrc &src = cursorSrc;

		cursorVertArrayDirty = true;

		if (rect.w <= 0 || rect.h <= 0)
		{
			cursorVert.clear();
			return;
		}

		const Vec2 corOff(rect.w - 4, rect.h - 4);

		const Corners<FloatRect> cornerPos =
		{
			FloatRect(        0,        0, 4, 4 ), /* Top left */
			FloatRect( corOff.x,        0, 4, 4 ), /* Top right */
			FloatRect(        0, corOff.y, 4, 4 ), /* Bottom left */
			FloatRect( corOff.x, corOff.y, 4, 4 )  /* Bottom right */
		};

		const Vec2i sideLen(rect.w - 4*2, rect.h - 4*2);

		const Sides<FloatRect> sidePos =
		{
		    FloatRect(        0,        4,         4, sideLen.y ), /* Left */
		    FloatRect( corOff.x,        4,         4, sideLen.y ), /* Right */
		    FloatRect(        4,        0, sideLen.x,         4 ), /* Top */
		    FloatRect(        4, corOff.y, sideLen.x,         4 )  /* Bottom */
		};

		const FloatRect bgPos(4, 4, sideLen.x, sideLen.y);

		bool drawSidesLR = rect.h > 8;
		bool drawSidesTB = rect.w > 8;
		bool drawBg = drawSidesLR && drawSidesTB;

		size_t quads = 0;
		quads += 4; /* 4 corners */

		if (drawSidesLR)
			quads += 2;

		if (drawSidesTB)
			quads += 2;

		if (drawBg)
			quads += 1;

		cursorVert.resize(quads);
		Vertex *vert = dataPtr(cursorVert.vertices);
		size_t i = 0;

		i += Quad::setTexPosRect(&vert[i*4], src.corners.tl, cornerPos.tl);
		i += Quad::setTexPosRect(&vert[i*4], src.corners.tr, cornerPos.tr);
		i += Quad::setTexPosRect(&vert[i*4], src.corners.bl, cornerPos.bl);
		i += Quad::setTexPosRect(&vert[i*4], src.corners.br, cornerPos.br);

		if (drawSidesLR)
		{
			i += Quad::setTexPosRect(&vert[i*4], src.border.l, sidePos.l);
			i += Quad::setTexPosRect(&vert[i*4], src.border.r, sidePos.r);
		}

		if (drawSidesTB)
		{
			i += Quad::setTexPosRect(&vert[i*4], src.border.t, sidePos.t);
			i += Quad::setTexPosRect(&vert[i*4], src.border.b, sidePos.b);
		}

		if (drawBg)
			Quad::setTexPosRect(&vert[i*4], src.bg, bgPos);
	}