示例#1
0
bool CCanvas::ApplyRenderers(CCanvasRendererStorage& storage,
        CCanvas* source,
        const CCanvas* target,
        const CRectangle* dstRect,
        const CRectangle* srcRect) const {
    if(!source->m_vecRendererVault.empty()) {
        std::vector<CCanvasRendererStorage::iterator> removeList;

        CCanvasRendererStorage::iterator end = storage.end();
        CRectangle rdstRect;
        CRectangle rsrcRect;

        if(dstRect) {
            rdstRect = CRectangle(*dstRect);
        }

        if(srcRect) {
            rsrcRect = CRectangle(*srcRect);
        }

        CCanvasRenderModifierData mdata(&rsrcRect, &rdstRect);

        for(CCanvasRendererStorage::iterator it = storage.begin(); it < end; ++it)
        {
            (*it)(target, const_cast<CCanvas *>(source), mdata);
            if(mdata.markedForDeletion) {
                CCanvasRendererStorage::iterator it2 = it;
                removeList.push_back(it2);
            }
        }
        BOOST_FOREACH(CCanvasRendererStorage::iterator itpos, removeList)
        {
            storage.erase(itpos);
        }
示例#2
0
void CLabel::draw()
{
    m_params.rec = CRectangle(getX(), getY(), getWidth(), getHeight());

    // Affichage du texte
    switch (m_align)
    {
        default:
        case AlignLeft:
            break;

        case AlignCenter:
        {
            TVector2UI txtdim = Game::fontManager->getTextSize(m_params);
            m_params.rec.setX(m_params.rec.getX() + (getWidth() - txtdim.X) / 2);
            break;
        }

        case AlignRight:
        {
            TVector2UI txtdim = Game::fontManager->getTextSize(m_params);
            m_params.rec.setX(m_params.rec.getX() + getWidth() - txtdim.X);
            break;
        }
    }

    Game::guiEngine->drawText(m_params);
}
示例#3
0
/////////////////////////////////////////////////////////////
/// Met à jour les pixels de la texture
///
/// \param Rect : Rectangle à mettre à jour dans la texture
///
////////////////////////////////////////////////////////////
void DX9Texture::Update(const CRectangle& Rect)
{
    CA_ASSERT(CRectangle(0, 0, m_Size.x, m_Size.y).Intersects(Rect) == INT_IN, "DX9Texture::Update() : rectangle out of bounds");

    // Si le format des pixels à copier est le même que celui de la texture on fait une simple copie,
	// sinon on effectue une conversion
    if (m_Format == m_Data.GetFormat())
    {
        // Verrouillage de la texture
        D3DLOCKED_RECT LockedRect;
        RECT Lock = {Rect.Left(), Rect.Top(), Rect.Right(), Rect.Bottom()};
        DXCheck(m_Texture->LockRect(0, &LockedRect, &Lock, 0));

        // Copie des pixels
        UpdateSurface(LockedRect, Rect);

        // Déverrouillage de la texture
        m_Texture->UnlockRect(0);
    }
    else
    {
        // Récupération du device
        SmartPtr<IDirect3DDevice9, CResourceCOM> Device;
        m_Texture->GetDevice(&GetPtr(Device));

        // Création d'une texture en mémoire système pour y copier les pixels
        SmartPtr<IDirect3DSurface9, CResourceCOM> Src;
        if (FAILED(Device->CreateOffscreenPlainSurface(Rect.Width(), Rect.Height(), DX9Enum::Get(m_Data.GetFormat()), D3DPOOL_SYSTEMMEM, &GetPtr(Src), nullptr)))
            throw DX9Exception("CreateOffscreenPlainSurface", "DX9Texture::Update");

        // Verrouillage de la texture temporaire
        D3DLOCKED_RECT LockedRect;
        Src->LockRect(&LockedRect, nullptr, 0);

        // Copie des pixels
        UpdateSurface(LockedRect, Rect);

        // Déverrouillage de la texture temporaire
        Src->UnlockRect();

        // Récupération de la surface de niveau 0 de la texture
        SmartPtr<IDirect3DSurface9, CResourceCOM> Dest;
        m_Texture->GetSurfaceLevel(0, &GetPtr(Dest));

        // Copie de la surface Src sur la surface Dest (c'est ici qu'est effectuée la conversion de format)
        RECT DestRect = {Rect.Left(), Rect.Top(), Rect.Right(), Rect.Bottom()};
        if (FAILED(D3DXLoadSurfaceFromSurface(Dest, nullptr, &DestRect, Src, nullptr, nullptr, D3DX_DEFAULT, 0)))
            throw DX9Exception("D3DXLoadSurfaceFromSurface", "DX9Texture::Update");
    }

    // Génération des niveaux de mipmapping si nécessaire
    if (m_HasMipmaps)
    {
        if (m_AutoMipmaps)
            m_Texture->GenerateMipSubLevels();
        else
            D3DXFilterTexture(m_Texture, nullptr, D3DX_DEFAULT, D3DX_DEFAULT);
    }
}
示例#4
0
文件: Canvas.cpp 项目: Jedzia/Humbug
bool CCanvas::ApplyRenderers(CCanvasRendererStorage& storage,
        CCanvas* source,
        const CCanvas* target,
        const CRectangle* dstRect,
        const CRectangle* srcRect) const {
    if(!source->m_vecRendererVault.empty()) {
        std::vector<CCanvasRendererStorage::iterator> removeList;

        CCanvasRendererStorage::iterator end = storage.end();
        CRectangle rdstRect;
        CRectangle rsrcRect;

        if(dstRect) {
            rdstRect = CRectangle(*dstRect);
        }

        if(srcRect) {
            rsrcRect = CRectangle(*srcRect);
        }

        CCanvasRenderModifierData mdata(&rsrcRect, &rdstRect);

        for(CCanvasRendererStorage::iterator it = storage.begin(); it < end; ++it)
        {
            (*it)(target, const_cast<CCanvas *>(source), mdata);
            if(mdata.markedForDeletion) {
                CCanvasRendererStorage::iterator it2 = it;
                // it has to be checked, if removing has no side effects. see CSpriteManager::OnIdle
                // for a solution with "while".
                //removeList.push_back(it2);
                removeList.insert(removeList.begin(), it2);
            }
        }
        BOOST_FOREACH(CCanvasRendererStorage::iterator itpos, removeList)
        {
            storage.erase(itpos);
        }
示例#5
0
文件: CMap.cpp 项目: pkkj/CraEngine
void CMap::selectFeature(QRect screenRect, bool clear) {
	double x1, y1, x2, y2;
	screenRect = screenRect.normalized();
	x1 = screenRect.left(), y1 = screenRect.bottom();
	x2 = screenRect.right(), y2 = screenRect.top();
	CRectangle rect = CRectangle(x1, y1, x2, y2);
	for (size_t i = 0; i < mLayers.size(); i++) {
		CFeatureLayer *pFeatLayer = dynamic_cast<CFeatureLayer*> (mLayers[i]);
		if (pFeatLayer != NULL) {
			if (pFeatLayer->getSelectable())
				pFeatLayer->selectFeature(rect, clear);
		}

	}
}
示例#6
0
/////////////////////////////////////////////////////////////
/// Constructeur
///
/// \param Size :        Dimensions de la texture
/// \param Format :      Format de pixel de la texture
/// \param HasMipmaps :  Indique si la texture a des niveaux de mip
/// \param AutoMipmaps : Indique si la texture peut générer ses mips en HW
/// \param Texture :     ID de la texture Dx
///
////////////////////////////////////////////////////////////
DX9Texture::DX9Texture(
	const Vector2I& Size, 
	PixelFormat::TPixelFormat Format, 
	bool HasMipmaps, 
	bool AutoMipmaps, 
	IDirect3DTexture9* Texture,
	const unsigned char* pData_) :
		ITextureBase(Size, Format, HasMipmaps, AutoMipmaps),
		m_Texture(Texture)
{
	if (pData_ != nullptr)
	{
		m_Data.CopyImage(CImage(Size, Format, pData_));
		Update(CRectangle(0, 0, Size.x, Size.y));
	}
}
示例#7
0
void AddRectangle(const std::vector<std::string> & inputParts, std::vector<std::shared_ptr<CShape>> & figures, std::vector<std::shared_ptr<sf::Shape>> & shapes)
{
	double x = std::stod(inputParts[1]);
	double y = std::stod(inputParts[2]);
	double width = std::stod(inputParts[3]);
	double height = std::stod(inputParts[4]);

	if (width <= 0 || height <= 0)
	{
		throw std::invalid_argument("Error: width and height of rectangle must be positive");
	}

	std::string outlineColor = inputParts[5];
	std::string fillColor = inputParts[6];
	CRectangle rectangle = CRectangle(CPoint(x, y), width, height, outlineColor, fillColor);
	sf::RectangleShape drawingRectangle(sf::Vector2f((float)width, (float)height));
	drawingRectangle.setPosition((float)x, (float)y);
	drawingRectangle.setFillColor(ConvertHexToRgb(fillColor));
	drawingRectangle.setOutlineColor(ConvertHexToRgb(outlineColor));
	drawingRectangle.setOutlineThickness(3.f);
	figures.push_back(std::make_shared<CRectangle>(rectangle));
	shapes.push_back(std::make_shared<sf::RectangleShape>(drawingRectangle));
}
示例#8
0
    /** HopperScreen, OnInit:
     *  Detailed description.
     *  @param argc TODO
     * @param argv TODO
     * @return TODO
     */
    bool HopperScreen::OnInit( int argc, char* argv[] ){
        // Master()->GetMainCanvas();
        CMainCanvas* m_pMainCanvas = Master()->GetMainCanvas();

        //m_pBackground = CCanvas::CreateRGBCompatible(NULL, 1024, 768 - 320);
        //m_pBackground = CCanvas::CreateRGBCompatible(NULL, NULL, NULL);
        // Todo: c:\program files\graphviz 2.28\bin\LIBFREETYPE-6.DLL copy from DEPS
        m_pArialfont = m_Loader.FL_LOADFONT("Fonts/ARIAL.TTF", 24);
        //m_pArialfont =
        // TTF_OpenFont("E:/Projects/C++/Humbug/projects/Humbug/Resources/Fonts/ARIAL.TTF", 24);
        mcol = CColor::White();
        SDL_Surface* tmpfsurf = ( m_Loader.FL_LOADIMG("Intro/HopperScreenBg.png") );

        //SDL_SetColorKey(tmpfsurf, SDL_TRUE, 0xff00ff);
        //SDL_SetColorKey(m_pMainCanvas->GetSurface(), SDL_TRUE, 0xff00ff);
        //SDL_SetSurfaceAlphaMod(tmpfsurf, 0);
        //SDL_SetSurfaceAlphaMod(m_pMainCanvas->GetSurface(), 128);
        m_pBackground.reset( new CCanvas( tmpfsurf ) );

        //CCanvas tmpCanvas( tmpfsurf );
        m_Loader.FreeLast();

        //m_pMainCanvas->Blit(m_pMainCanvas->GetDimension(), tmpCanvas, tmpCanvas.GetDimension());
        //m_pBackground->Blit(m_pBackground->GetDimension(), tmpCanvas, tmpCanvas.GetDimension());
        m_pMainCanvas->AddUpdateRect( m_pBackground->GetDimension() );

        //"\r\n"
        CColor m_colText = CColor::White();
        std::ostringstream outstring;
        outstring << "Jedzia";
        outstring << " .................... ";
        outstring << "328.123.847";

        CText* text = new CText(m_pArialfont, outstring.str(), m_colText);

        //const boost::function<void(CCanvas*, int)> textMo = mtextfloat;
        //text->AddAnimator(boost::ref( mtextfloat ));
        text->AddAnimator( WavyTextFloat(64) );
        m_pScrollText.reset(text);

        // ### Sprites ###
        m_pSprEye = new CSprite(m_Loader, "Sprites/male_sprites.png", m_pMainCanvas, CPoint(64, 0),
                CRectangle(0, 0, 64, 64) );
        m_pSprMgr->AddSprite(m_pSprEye, "mytag", hspriv::EyeMover(160, 8));
        //m_pSprMgr->AddSprite(m_pSprEye, boost::ref( pimpl_->eyemover ) );
        //m_pSprMgr->AddSprite(m_pSprEye);
        CSprite* m_pSprWormler = new CSprite(m_Loader, "Sprites/wormtiles.png", m_pMainCanvas, CPoint(0, 64),
                CRectangle(0, 0, 256, 64) );
        m_pSprWormler->SetColorAndAlpha(0xff00ff, 128);
        m_pSprMgr->AddSprite(m_pSprWormler, "mytag", hspriv::EyeMover(260, 40));

        //_CrtSetBreakAlloc(pimpl_->allocReqNum+4);
        //_crtBreakAlloc = pimpl_->allocReqNum+4;

        shost::ScriptHost shost;
        //shost.RunScript2(m_Loader.FL_LOADASSTRING("Lua/hello.lua"));
        // shost.RunScript(m_Loader.FL_LOADASSTRING("Lua/funcret.lua"));
        //shost.RunScript4(m_Loader.FL_LOADASSTRING("Lua/iowrite.lua"));
        //shost.RunScript(m_Loader.FL_LOADASSTRING("Lua/globalclass.lua"));
        //shost.RunScript6( m_Loader.FL_LOADASSTRING("Lua/globalclass.lua") );
		//shost.RunScript7( m_Loader.FL_LOADASSTRING("Lua/--FREE--.lua") );

		typedef shost::LuaScript<int, double, double> ScriptType;
		ScriptType::Script s = shost.generate<int, double, double>( m_Loader.FL_LOADASSTRING(
			"Lua/sprite1.lua"), "Ticks", "X", "Y" );
		pimpl_->script = s;

        world.FPS = CApplication::FramesCap();
        CRectangle screenRect = m_pMainCanvas->GetDimension();
        world.ScreenX = screenRect.GetW();
        world.ScreenY = screenRect.GetH();

		// Todo maybe an functor to initialize more global stuff
		(*s->AddStatic(world))("World")
			.def("greet", &greetHopper)
			.def_readonly("FPS", &World::FPS)
			.def_readonly("ScreenX", &World::ScreenX)
			.def_readonly("ScreenY", &World::ScreenY);



		ScriptType::Script sprInit = shost.generate<int, double, double>( m_Loader.FL_LOADASSTRING(
			"Sprites/male_sprites.spr"), "Ticks", "X", "Y" );
		//ScriptType::Script sprInit = shost.generate<int, double, double>( m_Loader.FL_LOADASSTRING(
		//	"Sprites/male_sprites.spr"), "Ticks", "X", "Y" );

		TestClass st(12,99);

		(*sprInit->AddStatic(st))("TestClass", "tc")
			.def(luabind::constructor<std::vector<int> >())
			.def(luabind::constructor<int, int>())
			.def("get", &TestClass::get);

		//boost::shared_ptr<shost::LuaScript::register_binder<SpriteFrame >>& bla=
		int xyz = 55;

		typedef shost::LuaVarCapsule<luabind::class_<SpriteFrame>> SprCapsule;
		SprCapsule maleSpriteCap = shost::makeFarm(sprInit,
		(*sprInit->Register<SpriteFrame>())("SpriteFrame")
			.def(luabind::constructor<int, int>())
			.def("X", &SpriteFrame::X)
			.def("Y", &SpriteFrame::Y));

		(*sprInit->Register<SpriteMovieOld>())("SpriteMovieOld")
			.def(luabind::constructor<std::string, SpriteFrame>())
			.def("X", &SpriteMovieOld::X)
			.def("Y", &SpriteMovieOld::Y);

		(*sprInit->Register<SpriteMovie>())("SpriteMovie")
			.def(luabind::constructor<std::string, std::vector<SpriteFrame>>())
			.def("X", &SpriteMovie::X)
			.def("Y", &SpriteMovie::Y);

		//luabind::class_<SpriteFrame>& xasd = maleSpriteCap.Value();
		//SprCapsule::ObjType mmy(1,2);
		//mmy.X();

		/*luabind::module(sprInit->L())
			[
				luabind::class_<TestClass>("TestClass_")
				.def(luabind::constructor<std::vector<int> >())
				.def(luabind::constructor<int, int>())
				.def("get", &TestClass::get)
			];*/


		int success = sprInit->run_script(99);

		luabind::object o3(luabind::globals(sprInit->L())["tcx"]);
		if (o3)
		{
			// is_valid
			// ...

			int luatype = luabind::type(o3);
			if (luabind::type(o3) == LUA_TUSERDATA)
			{
				TestClass otherValue = luabind::object_cast<TestClass>(o3);
				int abc = 4;
				abc++;
			}
		}

		SpriteFrame otherValue2(0,0);
		bool success3 = maleSpriteCap.GetLuaValue("spf", otherValue2);
		SpriteFrame otherValuex = maleSpriteCap.GetLuaValue("spf");

		SpriteFrame otherValue3(0,0);
		bool fsuccess = sprInit->GetLuaValue<SpriteFrame>("spf", otherValue3);

		luabind::object o4(luabind::globals(sprInit->L())["spf"]);
		if (o4)
		{
			// is_valid
			// ...

			int luatype = luabind::type(o4);
			if (luabind::type(o4) == LUA_TUSERDATA)
			{
				SpriteFrame otherValue = luabind::object_cast<SpriteFrame>(o4);
				int abc = 4;
				abc++;
			}
		}




		//SpriteMovie otherValue3(0,0);
		//fsuccess = sprInit->GetLuaValue<SpriteMovie>("spMovie", otherValue3);
		SpriteMovieOld smovieOld = sprInit->GetLuaValue<SpriteMovieOld>("spMovieOld");
		SpriteMovie smovie = sprInit->GetLuaValue<SpriteMovie>("spMovie");

		//int *x = new int(666);

        return Screen::OnInit(argc, argv);
    } // OnInit
示例#9
0
CRectangle::CRectangle(CCoordinate & p1, CCoordinate & p2) {
	CRectangle(p1.x, p1.y, p2.x, p2.y);

}
示例#10
0
/////////////////////////////////////////////////////////////
/// Met à jour les pixels de la texture
///
/// \param Rect : Rectangle à mettre à jour dans la texture
///
////////////////////////////////////////////////////////////
void GLTexture::Update(const CRectangle& Rect)
{
    CA_ASSERT(CRectangle(0, 0, m_Size.x, m_Size.y).Intersects(Rect) != INT_OUT, "GLTexture::Update() : rectangle out of bounds");

	 GLCheck(glBindTexture(GL_TEXTURE_2D, m_Texture));

    GLEnum::TPixelFmt TexFmt = GLEnum::Get(m_Format);
    GLEnum::TPixelFmt ImgFmt = GLEnum::Get(m_Data.GetFormat());

    if (FormatCompressed(m_Data.GetFormat()))
    {
#if CA_PLATFORM_DESKTOP

        // Format de pixel compressé - on utilise une extension pour uploader les pixels
        unsigned long DataSize = Rect.Width() * Rect.Height() * GetBytesPerPixel(m_Data.GetFormat());
        if (Rect.Width() == m_Size.x && Rect.Height() == m_Size.y)
        {
            // Le rectangle source couvre la totalité de l'image : on envoie directement les données
            GLRenderer::glCompressedTexSubImage2DARB(GL_TEXTURE_2D, 0, Rect.Left(), Rect.Top(), Rect.Width(), Rect.Height(), ImgFmt.Format, DataSize, m_Data.GetData());
        }
        else
        {
            // Le rectangle source ne couvre qu'une partie de l'image : on envoie une sous-image de l'image en mémoire
            CImage SubData = m_Data.SubImage(Rect);
            GLRenderer::glCompressedTexSubImage2DARB(GL_TEXTURE_2D, 0, Rect.Left(), Rect.Top(), Rect.Width(), Rect.Height(), ImgFmt.Format, DataSize, SubData.GetData());
        }

#else

		throw NEW_AO CNotImplementedException("GLTexture::Update() : compressed format is not supported\n");

#endif // CA_PLATFORM_DESKTOP

    }
    else
    {
		GLint pixelStore = 0;

		switch (m_Data.GetFormat())
		{
		case PixelFormat::L_8:		///< Luminosity 8 bits (1 byte)
			pixelStore = 1;
			break;

		case PixelFormat::AL_88:		///< Alpha and luminosity 16 bits (2 bytes)
		case PixelFormat::ARGB_1555:	///< RGB 16 bits 1555 (2 bytes)
		case PixelFormat::ARGB_4444:	///< RGB 16 bits 4444 (2 bytes)
		case PixelFormat::PVRTC2:		///< PVR texture compression. Each pixel is 2 bits.
			pixelStore = 2;
			break;

		case PixelFormat::RGB_888:	///< RGB 24 bits 888 (3 bytes)
		case PixelFormat::RGB_DXT1:   ///< S3 DXT1 texture compression (RGB)
			//
		case PixelFormat::ARGB_8888:	///< ARGB 32 bits 8888 (4 bytes)
		case PixelFormat::PVRTC4:	  ///< PVR texture compression. Each pixel is 4 bits.
		case PixelFormat::RGBA_DXT1:  ///< S3 DXT1 texture compression (RGBA)
		case PixelFormat::RGBA_DXT3:  ///< S3 DXT3 texture compression (RGBA)
		case PixelFormat::RGBA_DXT5:  ///< S3 DXT5 texture compression (RGBA)
			pixelStore = 4;
			break;
		}

		GLCheck(glPixelStorei(GL_PACK_ALIGNMENT, pixelStore));

        if (!m_HasMipmaps || m_AutoMipmaps)
        {
            // Pas de mipmap ou génération hardware : on ne met à jour que le premier niveau
            if ((Rect.Width() == m_Size.x) && (Rect.Height() == m_Size.y))
            {
				GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0,
					0, 0, Rect.Width(), Rect.Height(), ImgFmt.Format, ImgFmt.Type, m_Data.GetData()));
            }
            else
            {
                CImage SubData = m_Data.SubImage(Rect);
				GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0,
					Rect.Left(), Rect.Top(), Rect.Width(), Rect.Height(), ImgFmt.Format, ImgFmt.Type, SubData.GetData()));
            }
        }
        else
        {

#if CA_PLATFORM_DESKTOP
            // Plusieurs niveaux de mipmapping et génération software : on met à jour tous les niveaux
            GLCheck(gluBuild2DMipmaps(GL_TEXTURE_2D, TexFmt.Internal, m_Size.x, m_Size.y, ImgFmt.Format, ImgFmt.Type, m_Data.GetData()));

#else
			if ((Rect.Width() == m_Size.x) && (Rect.Height() == m_Size.y))
			{
				GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0,
					0, 0, Rect.Width(), Rect.Height(), ImgFmt.Format, ImgFmt.Type, m_Data.GetData()));
			}
			else
			{
				CImage SubData = m_Data.SubImage(Rect);
				GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0,
					Rect.Left(), Rect.Top(), Rect.Width(), Rect.Height(), ImgFmt.Format, ImgFmt.Type, SubData.GetData()));
			}

#endif // CA_PLATFORM_DESKTOP

			GLCheck(glGenerateMipmap(GL_TEXTURE_2D));

        }
    }

    GLCheck(glBindTexture(GL_TEXTURE_2D, 0));
}
示例#11
0
void CText::RenderPut(const CCanvas* canvas) {
    RenderPut(canvas, CRectangle(GetPosition(), GetCanvas()->GetDimension()), GetCanvas()->GetDimension());
}