Ejemplo n.º 1
0
//----------------------------------------------------------------------------//
KeyFrame* Affector::createKeyFrame(float position)
{
    if (d_keyFrames.find(position) != d_keyFrames.end())
    {
        CEGUI_THROW(InvalidRequestException(
                        "Affector::createKeyFrame: Unable to create KeyFrame "
                        "at given position, there already is a KeyFrame "
                        "on that position."));
    }

    KeyFrame* ret = new KeyFrame(this, position);
    d_keyFrames.insert(std::make_pair(position, ret));

    return ret;
}
Ejemplo n.º 2
0
//----------------------------------------------------------------------------//
void OpenGL3Shader::outputProgramLog(GLuint program)
{
    char logBuffer[LOG_BUFFER_SIZE];
    GLsizei length;

    logBuffer[0] = '\0';
    glGetProgramInfoLog(program, LOG_BUFFER_SIZE, &length, logBuffer);

    if (length > 0)
    {
        std::stringstream sstream;
        sstream << "OpenGL3Shader linking has failed.\n" << logBuffer;
        CEGUI_THROW(RendererException(sstream.str()));
    }
};
//----------------------------------------------------------------------------//
void WindowRendererModule::registerFactory(const String& type_name)
{
    FactoryRegistry::iterator i = d_registry.begin();
    for ( ; i != d_registry.end(); ++i)
    {
        if ((*i)->d_type == type_name)
        {
            (*i)->registerFactory();
            return;
        }
    }

    CEGUI_THROW(UnknownObjectException("No factory for WindowRenderere type '" +
        type_name + "' in this module."));
}
Ejemplo n.º 4
0
    //------------------------------------------------------------------------//
    void throwErrorException(int err)
    {
        std::string reason;

        if (err == EINVAL)
            reason = "Incomplete " + d_fromCode + " sequence.";
        else if (err == EILSEQ)
            reason = "Invalid " + d_fromCode + " sequence.";
        else
            reason = "Unknown error.";

        CEGUI_THROW(InvalidRequestException(String(
            "Failed to convert from \"") + d_fromCode.c_str() +
            "\" to \"" + d_toCode.c_str() + "\": " + reason.c_str()));
    }
Ejemplo n.º 5
0
//----------------------------------------------------------------------------//
void OpenGL3Renderer::destroySystem()
{
    System* sys;
    if (!(sys = System::getSingletonPtr()))
        CEGUI_THROW(InvalidRequestException(
            "CEGUI::System object is not created or was already destroyed."));

    OpenGL3Renderer* renderer = static_cast<OpenGL3Renderer*>(sys->getRenderer());
    DefaultResourceProvider* rp =
        static_cast<DefaultResourceProvider*>(sys->getResourceProvider());

    System::destroy();
    delete rp;
    destroy(*renderer);
}
Ejemplo n.º 6
0
//----------------------------------------------------------------------------//
Texture& OpenGL3Renderer::createTexture(const String& name,
                                       const String& filename,
                                       const String& resourceGroup)
{
    if (d_textures.find(name) != d_textures.end())
        CEGUI_THROW(AlreadyExistsException(
            "A texture named '" + name + "' already exists."));

    OpenGL3Texture* tex = new OpenGL3Texture(*this, name, filename, resourceGroup);
    d_textures[name] = tex;

    logTextureCreation(name);

    return *tex;
}
Ejemplo n.º 7
0
//----------------------------------------------------------------------------//
void OpenGL3Shader::outputShaderLog(GLuint shader)
{
    char logBuffer[LOG_BUFFER_SIZE];
    GLsizei length;

    logBuffer[0] = '\0';
    glGetShaderInfoLog(shader, LOG_BUFFER_SIZE, &length, logBuffer);

    if (length > 0)
    {
        std::stringstream ss;
        ss << "OpenGL3Shader compilation has failed.\n" << logBuffer;
          CEGUI_THROW(RendererException(ss.str()));
    }
};
Ejemplo n.º 8
0
//----------------------------------------------------------------------------//
OpenGL3Renderer& OpenGL3Renderer::bootstrapSystem(const Sizef& display_size,
                                                  const int abi)
{
    System::performVersionTest(CEGUI_VERSION_ABI, abi, CEGUI_FUNCTION_NAME);

    if (System::getSingletonPtr())
        CEGUI_THROW(InvalidRequestException(
            "CEGUI::System object is already initialised."));

    OpenGL3Renderer& renderer(create(display_size));
    DefaultResourceProvider* rp = new CEGUI::DefaultResourceProvider();
    System::create(renderer, rp);

    return renderer;
}
Ejemplo n.º 9
0
//----------------------------------------------------------------------------//
Direct3D9ViewportTarget::Direct3D9ViewportTarget(Direct3D9Renderer& owner) :
    Direct3D9RenderTarget<>(owner)
{
    // initialise renderer size
    D3DVIEWPORT9 vp;
    if (FAILED(d_owner.getDevice()->GetViewport(&vp)))
        CEGUI_THROW(RendererException("Unable to access "
            "required view port information from Direct3DDevice9."));

    Rectf area(
        Vector2f(static_cast<float>(vp.X), static_cast<float>(vp.Y)),
        Sizef(static_cast<float>(vp.Width), static_cast<float>(vp.Height))
    );

    setArea(area);
}
Ejemplo n.º 10
0
std::string Utf16ToACP(const std::wstring& utf16text)
{
	const int len = WideCharToMultiByte(CP_ACP, 0, utf16text.c_str(), -1,
		0, 0, 0, 0);
	if (!len)
		CEGUI_THROW(CEGUI::InvalidRequestException(
		"Utf16ToUtf8 - WideCharToMultiByte failed"));

	char* buff = new char[len];
	WideCharToMultiByte(CP_ACP, 0, utf16text.c_str(), -1,
		buff, len, 0, 0);
	const std::string result(buff);
	delete[] buff;

	return result;
}
Ejemplo n.º 11
0
/*************************************************************************
    Add a new WindowRenderer factory
*************************************************************************/
void WindowRendererManager::addFactory(WindowRendererFactory* wr)
{
    if (wr == 0)
    {
        return;
    }
    if (d_wrReg.insert(std::make_pair(wr->getName(), wr)).second == false)
    {
        CEGUI_THROW(AlreadyExistsException("A WindowRendererFactory named '"+wr->getName()+"' already exist"));
    }

    char addr_buff[32];
    sprintf(addr_buff, "(%p)", static_cast<void*>(wr));
    Logger::getSingleton().logEvent("WindowRendererFactory '"+wr->getName()+
        "' added. " + addr_buff);
}
//----------------------------------------------------------------------------//
void AnimationManager::destroyAnimation(const String& name)
{
    AnimationMap::iterator it = d_animations.find(name);

    if (it == d_animations.end())
    {
        CEGUI_THROW(UnknownObjectException("Animation with name '" + name
            + "' not found."));
    }

    Animation* animation = it->second;
    destroyAllInstancesOfAnimation(animation);

    d_animations.erase(it);
    CEGUI_DELETE_AO animation;
}
Ejemplo n.º 13
0
//----------------------------------------------------------------------------//
Texture& DirectFBRenderer::createTexture(const CEGUI::String& name,
                                         const String& filename,
                                         const String& resourceGroup)
{
    if (d_textures.find(name) != d_textures.end())
        CEGUI_THROW(AlreadyExistsException(
            "A texture named '" + name + "' already exists."));

    DirectFBTexture* tex = new DirectFBTexture(d_directfb, name,
                                               filename, resourceGroup);
    d_textures[name] = tex;

    logTextureCreation(tex);

    return *tex;
}
Ejemplo n.º 14
0
CEGUI::String Utf16ToString(const wchar_t* const utf16text)
{
	const int len = WideCharToMultiByte(CP_UTF8, 0, utf16text, -1,
		0, 0, 0, 0);
	if (!len)
		CEGUI_THROW(CEGUI::InvalidRequestException(
		"Utf16ToUtf8 - WideCharToMultiByte failed"));

	CEGUI::utf8* buff = new CEGUI::utf8[len];
	WideCharToMultiByte(CP_UTF8, 0, utf16text, -1,
		reinterpret_cast<char*>(buff), len, 0, 0);
	const CEGUI::String result(buff);
	delete[] buff;

	return result;
}
//----------------------------------------------------------------------------//
void AnimationManager::destroyAnimationInstance(AnimationInstance* instance)
{
    AnimationInstanceMap::iterator it =
        d_animationInstances.find(instance->getDefinition());

    for (; it != d_animationInstances.end(); ++it)
    {
        if (it->second == instance)
        {
            d_animationInstances.erase(it);
            CEGUI_DELETE_AO instance;
            return;
        }
    }

    CEGUI_THROW(InvalidRequestException("Given animation instance not found."));
}
Ejemplo n.º 16
0
//----------------------------------------------------------------------------//
void OpenGLESTexture::loadFromMemory(const void* buffer,
                                     const Sizef& buffer_size,
                                     PixelFormat pixel_format)
{
    if (!isPixelFormatSupported(pixel_format))
        CEGUI_THROW(InvalidRequestException(
            "Data was supplied in an unsupported pixel format."));
    
    initPixelFormatFields(pixel_format);
    setTextureSize_impl(buffer_size);

    // store size of original data we are loading
    d_dataSize = buffer_size;
    updateCachedScaleValues();

    blitFromMemory(buffer, Rectf(Vector2f(0, 0), buffer_size));
}
Ejemplo n.º 17
0
/*************************************************************************
	Constructor
*************************************************************************/
Image::Image(const Imageset* owner, const String& name, const Rect& area, const Point& render_offset, float horzScaling, float vertScaling) :
	d_owner(owner),
	d_area(area),
	d_offset(render_offset),
	d_name(name)
{
	if (!d_owner)
	{
		CEGUI_THROW(NullObjectException("Image::Image - Imageset pointer passed to Image constructor must be valid."));
	}

	// setup initial image scaling
	setHorzScaling(horzScaling);
	setVertScaling(vertScaling);

	// TODO: if we ever store texture co-ordinates, they should be calculated here.
}
Ejemplo n.º 18
0
//----------------------------------------------------------------------------//
void NamedElement::addChild_impl(Element* element)
{
    NamedElement* named_element = dynamic_cast<NamedElement*>(element);

    if (named_element)
    {
        const NamedElement* const existing = getChildByNamePath_impl(named_element->getName());

        if (existing && named_element != existing)
            CEGUI_THROW(AlreadyExistsException("Failed to add "
                "Element named: " + named_element->getName() + " to element at: " +
                getNamePath() + " since an Element with that name is already "
                "attached."));
    }

    Element::addChild_impl(element);
}
Ejemplo n.º 19
0
const WindowFactoryManager::FalagardWindowMapping& WindowFactoryManager::getFalagardMappingForType(const String& type) const
{
    FalagardMapRegistry::const_iterator iter =
        d_falagardRegistry.find(getDereferencedAliasType(type));

    if (iter != d_falagardRegistry.end())
    {
        return (*iter).second;
    }
    // type does not exist as a mapped type (or an alias for one)
    else
    {
        CEGUI_THROW(InvalidRequestException(
            "Window factory type '" + type +
            "' is not a falagard mapped type (or an alias for one)."));
    }
}
Ejemplo n.º 20
0
/*************************************************************************
	Remove a column from the header
*************************************************************************/
void ListHeader::removeColumn(uint column)
{
	if (column >= getColumnCount())
	{
		CEGUI_THROW(InvalidRequestException(
            "specified column index is out of range for this ListHeader."));
	}
	else
	{
		ListHeaderSegment* seg = d_segments[column];

		// remove from the list of segments
		d_segments.erase(d_segments.begin() + column);

		// have we removed the sort column?
		if (d_sortSegment == seg)
		{
			// any other columns?
			if (getColumnCount() > 0)
			{
				// put first column in as sort column
				d_sortDir = ListHeaderSegment::None;
				setSortColumn(0);
			}
			// no columns, set sort segment to NULL
			else
			{
				d_sortSegment = 0;
			}

		}

		// detach segment window from the header (this)
		removeChild(seg);

		// destroy the segment (done in derived class, since that's where it was created).
		destroyListSegment(seg);

		layoutSegments();

		// Fire segment removed event.
		WindowEventArgs args(this);
		onSegmentRemoved(args);
	}

}
Ejemplo n.º 21
0
//----------------------------------------------------------------------------//
void AnimationManager::destroyAnimation(const String& name)
{
    AnimationMap::iterator it = d_animations.find(name);

    if (it == d_animations.end())
    {
        CEGUI_THROW(InvalidRequestException(
            "AnimationManager::destroyAnimation: Animation with given name not "
            "found."));
    }

    Animation* animation = it->second;
    destroyAllInstancesOfAnimation(animation);

    d_animations.erase(it);
    delete animation;
}
Ejemplo n.º 22
0
//----------------------------------------------------------------------------//
void LuaScriptModule::executeString_impl(const String& str, const int err_idx,
    const int top)
{
    // load code into lua and call it
    int error = luaL_loadbuffer(d_state, str.c_str(), str.length(), str.c_str()) ||
                lua_pcall(d_state, 0, 0, err_idx);

    // handle errors
    if (error)
    {
        String errMsg = lua_tostring(d_state,-1);
        lua_settop(d_state,top);
        CEGUI_THROW(ScriptException("Unable to execute Lua script string: '" +
            str + "'\n\n" + errMsg + "\n"));
    }

    lua_settop(d_state,top);
}
Ejemplo n.º 23
0
//----------------------------------------------------------------------------//
void Direct3D9Texture::createDirect3D9Texture(const Sizef sz, D3DFORMAT format)
{
    cleanupDirect3D9Texture();

    const Sizef tex_sz(d_owner.getAdjustedSize(sz));

    HRESULT hr = D3DXCreateTexture(d_owner.getDevice(),
                                   static_cast<UINT>(tex_sz.d_width),
                                   static_cast<UINT>(tex_sz.d_height),
                                   1, 0, format, D3DPOOL_MANAGED, &d_texture);

    if (FAILED(hr))
        CEGUI_THROW(RendererException("D3DXCreateTexture failed."));

    d_dataSize = sz;
    updateTextureSize();
    updateCachedScaleValues();
}
Ejemplo n.º 24
0
//----------------------------------------------------------------------------//
NullRenderer& NullRenderer::bootstrapSystem(const int abi)
{
    System::performVersionTest(CEGUI_VERSION_ABI, abi, CEGUI_FUNCTION_NAME);

    if (System::getSingletonPtr())
        CEGUI_THROW(InvalidRequestException(
            "CEGUI::System object is already initialised."));

	NullRenderer& renderer = create();
	
	DefaultResourceProvider* rp(new DefaultResourceProvider()); 

	// TODO: Create image codec?
	// NullImageCodec& ic = createNullImageCodec();
    System::create(renderer, rp, static_cast<XMLParser*>(0), 0);

    return renderer;
}
Ejemplo n.º 25
0
    bool operator()(const EventArgs& /*args*/) const
    {
        switch (action)
        {
        case CEA_REDRAW:
            window.invalidate(false);
            return true;

        case CEA_LAYOUT:
            window.performChildWindowLayout();
            return true;

        default:
            CEGUI_THROW(InvalidRequestException("invalid action."));
        }

        return false;
    }
//----------------------------------------------------------------------------//
Direct3D11ViewportTarget::Direct3D11ViewportTarget(Direct3D11Renderer& owner) :
    Direct3D11RenderTarget(owner)
{
    // initialise renderer size
    D3D11_VIEWPORT vp;
    UINT vp_count = 1;
    d_device.d_context->RSGetViewports(&vp_count, &vp);
    if (vp_count != 1)
        CEGUI_THROW(RendererException("Direct3D11ViewportTarget: Unable to access "
            "required view port information from ID3D10Device."));

    Rect area(
        Point(static_cast<float>(vp.TopLeftX), static_cast<float>(vp.TopLeftY)),
        Size(static_cast<float>(vp.Width), static_cast<float>(vp.Height))
    );

    setArea(area);
}
Ejemplo n.º 27
0
/*************************************************************************
    Internal version of adding a child window.
*************************************************************************/
void MenuItem::addChild_impl(Element* element)
{
    Window* wnd = dynamic_cast<Window*>(element);

    if (!wnd)
        CEGUI_THROW(InvalidRequestException(
                        "MenuItem can only have Elements of type Window added as children "
                        "(Window path: " + getNamePath() + ")."));

    ItemEntry::addChild_impl(wnd);

    PopupMenu* pop = dynamic_cast<PopupMenu*>(wnd);
    // if this is a PopupMenu we add it like one
    if (pop)
    {
        setPopupMenu_impl(pop, false);
    }
}
//----------------------------------------------------------------------------//
void LayoutContainer::addChild_impl(Element* element)
{
    Window* wnd = dynamic_cast<Window*>(element);
    
    if (!wnd)
        CEGUI_THROW(InvalidRequestException(
            "LayoutContainer can only have Elements of type Window added as "
            "children (Window path: " + getNamePath() + ")."));
    
    Window::addChild_impl(wnd);

    // we have to subscribe to the EventSized for layout updates
    d_eventConnections.insert(std::make_pair(wnd,
        wnd->subscribeEvent(Window::EventSized,
            Event::Subscriber(&LayoutContainer::handleChildSized, this))));
    d_eventConnections.insert(std::make_pair(wnd,
        wnd->subscribeEvent(Window::EventMarginChanged,
            Event::Subscriber(&LayoutContainer::handleChildMarginChanged, this))));
}
Ejemplo n.º 29
0
//----------------------------------------------------------------------------//
void Direct3D11Texture::saveToMemory(void* buffer)
{
    if (!d_texture)
        return;

    String exception_msg;

    D3D11_TEXTURE2D_DESC tex_desc;
    d_texture->GetDesc(&tex_desc);

    tex_desc.Usage = D3D11_USAGE_STAGING;
    tex_desc.BindFlags = 0;
    tex_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;

    ID3D11Texture2D* offscreen;
    if (SUCCEEDED(d_device.d_device->CreateTexture2D(&tex_desc, 0, &offscreen)))
    {
        d_device.d_context->CopyResource(offscreen, d_texture);

        D3D11_MAPPED_SUBRESOURCE mapped_tex;
        if (SUCCEEDED(d_device.d_context->Map(offscreen, 0, D3D11_MAP_READ,
                                              0, &mapped_tex)))
        {
            blitFromSurface(static_cast<uint32*>(mapped_tex.pData),
                            static_cast<uint32*>(buffer),
                            Size(static_cast<float>(tex_desc.Width),
                                   static_cast<float>(tex_desc.Height)),
                            mapped_tex.RowPitch);

            d_device.d_context->Unmap(offscreen, 0);
        }
        else
            exception_msg.assign("ID3D11Texture2D::Map failed.");

        offscreen->Release();
    }
    else
        exception_msg.assign(
            "ID3D11Device::CreateTexture2D failed for 'offscreen'.");

    if (!exception_msg.empty())
        CEGUI_THROW(RendererException(exception_msg));
}
Ejemplo n.º 30
0
//----------------------------------------------------------------------------//
Direct3D10ViewportTarget::Direct3D10ViewportTarget(Direct3D10Renderer& owner) :
    Direct3D10RenderTarget<>(owner)
{
    // initialise renderer size
    D3D10_VIEWPORT vp;
    UINT vp_count = 1;
    d_device.RSGetViewports(&vp_count, &vp);
    if (vp_count != 1)
        CEGUI_THROW(RendererException(
            "Unable to access required view port information from "
            "ID3D10Device."));

    Rectf area(
        Vector2f(static_cast<float>(vp.TopLeftX), static_cast<float>(vp.TopLeftY)),
        Sizef(static_cast<float>(vp.Width), static_cast<float>(vp.Height))
    );

    setArea(area);
}