Updated CSFML to properly handle the new way of storing views in render targets

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1322 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2010-01-05 19:15:20 +00:00
parent bc6beac402
commit 4472f81469
8 changed files with 48 additions and 78 deletions

View File

@ -168,7 +168,7 @@ CSFML_API const sfView* sfRenderImage_GetView(const sfRenderImage* renderImage);
/// \return Default view of the renderimage /// \return Default view of the renderimage
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfView* sfRenderImage_GetDefaultView(sfRenderImage* renderImage); CSFML_API const sfView* sfRenderImage_GetDefaultView(const sfRenderImage* renderImage);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the viewport of a view applied to this target /// Get the viewport of a view applied to this target

View File

@ -348,7 +348,7 @@ CSFML_API const sfView* sfRenderWindow_GetView(const sfRenderWindow* renderWindo
/// \return Default view of the render window /// \return Default view of the render window
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfView* sfRenderWindow_GetDefaultView(sfRenderWindow* renderWindow); CSFML_API const sfView* sfRenderWindow_GetDefaultView(const sfRenderWindow* renderWindow);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the viewport of a view applied to this target /// Get the viewport of a view applied to this target

View File

@ -42,8 +42,8 @@ sfRenderImage* sfRenderImage_Create(unsigned int width, unsigned int height, sfB
sfRenderImage* renderImage = new sfRenderImage; sfRenderImage* renderImage = new sfRenderImage;
renderImage->This.Create(width, height, depthBuffer == sfTrue); renderImage->This.Create(width, height, depthBuffer == sfTrue);
renderImage->Target = new sfImage(const_cast<sf::Image*>(&renderImage->This.GetImage())); renderImage->Target = new sfImage(const_cast<sf::Image*>(&renderImage->This.GetImage()));
renderImage->DefaultView = new sfView(const_cast<sf::View*>(&renderImage->This.GetDefaultView())); renderImage->DefaultView.This = renderImage->This.GetDefaultView();
renderImage->CurrentView = renderImage->DefaultView; renderImage->CurrentView.This = renderImage->This.GetView();
return renderImage; return renderImage;
} }
@ -54,7 +54,6 @@ sfRenderImage* sfRenderImage_Create(unsigned int width, unsigned int height, sfB
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfRenderImage_Destroy(sfRenderImage* renderImage) void sfRenderImage_Destroy(sfRenderImage* renderImage)
{ {
delete renderImage->DefaultView;
delete renderImage->Target; delete renderImage->Target;
delete renderImage; delete renderImage;
} }
@ -175,8 +174,8 @@ void sfRenderImage_Clear(sfRenderImage* renderImage, sfColor color)
void sfRenderImage_SetView(sfRenderImage* renderImage, const sfView* view) void sfRenderImage_SetView(sfRenderImage* renderImage, const sfView* view)
{ {
CSFML_CHECK(view); CSFML_CHECK(view);
CSFML_CALL(renderImage, SetView(*view->This)); CSFML_CALL(renderImage, SetView(view->This));
renderImage->CurrentView = view; renderImage->CurrentView.This = view->This;
} }
@ -187,18 +186,18 @@ const sfView* sfRenderImage_GetView(const sfRenderImage* renderImage)
{ {
CSFML_CHECK_RETURN(renderImage, NULL); CSFML_CHECK_RETURN(renderImage, NULL);
return renderImage->CurrentView; return &renderImage->CurrentView;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the default view of a renderimage /// Get the default view of a renderimage
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfView* sfRenderImage_GetDefaultView(sfRenderImage* renderImage) const sfView* sfRenderImage_GetDefaultView(const sfRenderImage* renderImage)
{ {
CSFML_CHECK_RETURN(renderImage, NULL); CSFML_CHECK_RETURN(renderImage, NULL);
return renderImage->DefaultView; return &renderImage->DefaultView;
} }
@ -211,7 +210,7 @@ sfIntRect sfRenderImage_GetViewport(const sfRenderImage* renderImage, const sfVi
CSFML_CHECK_RETURN(view, rect); CSFML_CHECK_RETURN(view, rect);
CSFML_CHECK_RETURN(renderImage, rect); CSFML_CHECK_RETURN(renderImage, rect);
sf::IntRect SFMLrect = renderImage->This.GetViewport(*view->This); sf::IntRect SFMLrect = renderImage->This.GetViewport(view->This);
rect.Left = SFMLrect.Left; rect.Left = SFMLrect.Left;
rect.Top = SFMLrect.Top; rect.Top = SFMLrect.Top;
rect.Right = SFMLrect.Right; rect.Right = SFMLrect.Right;
@ -230,7 +229,7 @@ void sfRenderImage_ConvertCoords(const sfRenderImage* renderImage, unsigned int
sf::Vector2f point; sf::Vector2f point;
if (targetView) if (targetView)
point = renderImage->This.ConvertCoords(imageX, imageY, *targetView->This); point = renderImage->This.ConvertCoords(imageX, imageY, targetView->This);
else else
point = renderImage->This.ConvertCoords(imageX, imageY); point = renderImage->This.ConvertCoords(imageX, imageY);

View File

@ -41,8 +41,8 @@ struct sfRenderImage
{ {
sf::RenderImage This; sf::RenderImage This;
const sfImage* Target; const sfImage* Target;
sfView* DefaultView; sfView DefaultView;
const sfView* CurrentView; sfView CurrentView;
}; };

View File

@ -59,8 +59,8 @@ sfRenderWindow* sfRenderWindow_Create(sfVideoMode mode, const char* title, unsig
sfRenderWindow* renderWindow = new sfRenderWindow; sfRenderWindow* renderWindow = new sfRenderWindow;
renderWindow->This.Create(videoMode, title, style, params); renderWindow->This.Create(videoMode, title, style, params);
renderWindow->Input.This = &renderWindow->This.GetInput(); renderWindow->Input.This = &renderWindow->This.GetInput();
renderWindow->DefaultView = new sfView(const_cast<sf::View*>(&renderWindow->This.GetDefaultView())); renderWindow->DefaultView.This = renderWindow->This.GetDefaultView();
renderWindow->CurrentView = renderWindow->DefaultView; renderWindow->CurrentView.This = renderWindow->This.GetView();
return renderWindow; return renderWindow;
} }
@ -86,8 +86,8 @@ sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle handle, const sfC
sfRenderWindow* renderWindow = new sfRenderWindow; sfRenderWindow* renderWindow = new sfRenderWindow;
renderWindow->This.Create(handle, params); renderWindow->This.Create(handle, params);
renderWindow->Input.This = &renderWindow->This.GetInput(); renderWindow->Input.This = &renderWindow->This.GetInput();
renderWindow->DefaultView = new sfView(const_cast<sf::View*>(&renderWindow->This.GetDefaultView())); renderWindow->DefaultView.This = renderWindow->This.GetDefaultView();
renderWindow->CurrentView = renderWindow->DefaultView; renderWindow->CurrentView.This = renderWindow->This.GetView();
return renderWindow; return renderWindow;
} }
@ -98,7 +98,6 @@ sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle handle, const sfC
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfRenderWindow_Destroy(sfRenderWindow* renderWindow) void sfRenderWindow_Destroy(sfRenderWindow* renderWindow)
{ {
delete renderWindow->DefaultView;
delete renderWindow; delete renderWindow;
} }
@ -413,8 +412,8 @@ void sfRenderWindow_Clear(sfRenderWindow* renderWindow, sfColor color)
void sfRenderWindow_SetView(sfRenderWindow* renderWindow, const sfView* view) void sfRenderWindow_SetView(sfRenderWindow* renderWindow, const sfView* view)
{ {
CSFML_CHECK(view); CSFML_CHECK(view);
CSFML_CALL(renderWindow, SetView(*view->This)); CSFML_CALL(renderWindow, SetView(view->This));
renderWindow->CurrentView = view; renderWindow->CurrentView.This = view->This;
} }
@ -425,18 +424,18 @@ const sfView* sfRenderWindow_GetView(const sfRenderWindow* renderWindow)
{ {
CSFML_CHECK_RETURN(renderWindow, NULL); CSFML_CHECK_RETURN(renderWindow, NULL);
return renderWindow->CurrentView; return &renderWindow->CurrentView;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the default view of a renderwindow /// Get the default view of a renderwindow
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfView* sfRenderWindow_GetDefaultView(sfRenderWindow* renderWindow) const sfView* sfRenderWindow_GetDefaultView(const sfRenderWindow* renderWindow)
{ {
CSFML_CHECK_RETURN(renderWindow, NULL); CSFML_CHECK_RETURN(renderWindow, NULL);
return renderWindow->DefaultView; return &renderWindow->DefaultView;
} }
@ -449,7 +448,7 @@ sfIntRect sfRenderWindow_GetViewport(const sfRenderWindow* renderWindow, const s
CSFML_CHECK_RETURN(view, rect); CSFML_CHECK_RETURN(view, rect);
CSFML_CHECK_RETURN(renderWindow, rect); CSFML_CHECK_RETURN(renderWindow, rect);
sf::IntRect SFMLrect = renderWindow->This.GetViewport(*view->This); sf::IntRect SFMLrect = renderWindow->This.GetViewport(view->This);
rect.Left = SFMLrect.Left; rect.Left = SFMLrect.Left;
rect.Top = SFMLrect.Top; rect.Top = SFMLrect.Top;
rect.Right = SFMLrect.Right; rect.Right = SFMLrect.Right;
@ -468,7 +467,7 @@ void sfRenderWindow_ConvertCoords(const sfRenderWindow* renderWindow, unsigned i
sf::Vector2f point; sf::Vector2f point;
if (targetView) if (targetView)
point = renderWindow->This.ConvertCoords(windowX, windowY, *targetView->This); point = renderWindow->This.ConvertCoords(windowX, windowY, targetView->This);
else else
point = renderWindow->This.ConvertCoords(windowX, windowY); point = renderWindow->This.ConvertCoords(windowX, windowY);

View File

@ -40,8 +40,8 @@ struct sfRenderWindow
{ {
sf::RenderWindow This; sf::RenderWindow This;
sfInput Input; sfInput Input;
sfView* DefaultView; sfView DefaultView;
const sfView* CurrentView; sfView CurrentView;
}; };

View File

@ -44,7 +44,10 @@ sfView* sfView_Create()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfView* sfView_CreateFromRect(sfFloatRect rectangle) sfView* sfView_CreateFromRect(sfFloatRect rectangle)
{ {
return new sfView(rectangle); sfView* view = new sfView;
sfView_Reset(view, rectangle);
return view;
} }
@ -73,7 +76,7 @@ void sfView_Destroy(sfView* view)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfView_SetCenter(sfView* view, float x, float y) void sfView_SetCenter(sfView* view, float x, float y)
{ {
CSFML_CALL_PTR(view, SetCenter(x, y)); CSFML_CALL(view, SetCenter(x, y));
} }
@ -82,7 +85,7 @@ void sfView_SetCenter(sfView* view, float x, float y)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfView_SetSize(sfView* view, float width, float height) void sfView_SetSize(sfView* view, float width, float height)
{ {
CSFML_CALL_PTR(view, SetSize(width, height)); CSFML_CALL(view, SetSize(width, height));
} }
@ -91,7 +94,7 @@ void sfView_SetSize(sfView* view, float width, float height)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfView_SetRotation(sfView* view, float angle) void sfView_SetRotation(sfView* view, float angle)
{ {
CSFML_CALL_PTR(view, SetRotation(angle)); CSFML_CALL(view, SetRotation(angle));
} }
@ -100,7 +103,7 @@ void sfView_SetRotation(sfView* view, float angle)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfView_SetViewport(sfView* view, sfFloatRect viewport) void sfView_SetViewport(sfView* view, sfFloatRect viewport)
{ {
CSFML_CALL_PTR(view, SetViewport(sf::FloatRect(viewport.Left, viewport.Top, viewport.Right, viewport.Bottom))); CSFML_CALL(view, SetViewport(sf::FloatRect(viewport.Left, viewport.Top, viewport.Right, viewport.Bottom)));
} }
@ -110,7 +113,7 @@ void sfView_SetViewport(sfView* view, sfFloatRect viewport)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfView_Reset(sfView* view, sfFloatRect rectangle) void sfView_Reset(sfView* view, sfFloatRect rectangle)
{ {
CSFML_CALL_PTR(view, Reset(sf::FloatRect(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom))); CSFML_CALL(view, Reset(sf::FloatRect(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom)));
} }
@ -121,7 +124,7 @@ float sfView_GetCenterX(const sfView* view)
{ {
CSFML_CHECK_RETURN(view, 0.f); CSFML_CHECK_RETURN(view, 0.f);
return view->This->GetCenter().x; return view->This.GetCenter().x;
} }
@ -132,7 +135,7 @@ float sfView_GetCenterY(const sfView* view)
{ {
CSFML_CHECK_RETURN(view, 0.f); CSFML_CHECK_RETURN(view, 0.f);
return view->This->GetCenter().y; return view->This.GetCenter().y;
} }
@ -143,7 +146,7 @@ float sfView_GetWidth(const sfView* view)
{ {
CSFML_CHECK_RETURN(view, 0.f); CSFML_CHECK_RETURN(view, 0.f);
return view->This->GetSize().x; return view->This.GetSize().x;
} }
@ -154,7 +157,7 @@ float sfView_GetHeight(const sfView* view)
{ {
CSFML_CHECK_RETURN(view, 0.f); CSFML_CHECK_RETURN(view, 0.f);
return view->This->GetSize().y; return view->This.GetSize().y;
} }
@ -163,7 +166,7 @@ float sfView_GetHeight(const sfView* view)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
float sfView_GetRotation(const sfView* view) float sfView_GetRotation(const sfView* view)
{ {
CSFML_CALL_PTR_RETURN(view, GetRotation(), 0.f); CSFML_CALL_RETURN(view, GetRotation(), 0.f);
} }
@ -175,7 +178,7 @@ sfFloatRect sfView_GetViewport(const sfView* view)
sfFloatRect rect = {0, 0, 0, 0}; sfFloatRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(view, rect); CSFML_CHECK_RETURN(view, rect);
sf::FloatRect SFMLRect = view->This->GetViewport(); sf::FloatRect SFMLRect = view->This.GetViewport();
rect.Left = SFMLRect.Left; rect.Left = SFMLRect.Left;
rect.Top = SFMLRect.Top; rect.Top = SFMLRect.Top;
rect.Right = SFMLRect.Right; rect.Right = SFMLRect.Right;
@ -190,7 +193,7 @@ sfFloatRect sfView_GetViewport(const sfView* view)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfView_Move(sfView* view, float offsetX, float offsetY) void sfView_Move(sfView* view, float offsetX, float offsetY)
{ {
CSFML_CALL_PTR(view, Move(offsetX, offsetY)); CSFML_CALL(view, Move(offsetX, offsetY));
} }
@ -199,7 +202,7 @@ void sfView_Move(sfView* view, float offsetX, float offsetY)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfView_Rotate(sfView* view, float angle) void sfView_Rotate(sfView* view, float angle)
{ {
CSFML_CALL_PTR(view, Rotate(angle)); CSFML_CALL(view, Rotate(angle));
} }
@ -208,5 +211,5 @@ void sfView_Rotate(sfView* view, float angle)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfView_Zoom(sfView* view, float factor) void sfView_Zoom(sfView* view, float factor)
{ {
CSFML_CALL_PTR(view, Zoom(factor)); CSFML_CALL(view, Zoom(factor));
} }

View File

@ -36,38 +36,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
struct sfView struct sfView
{ {
sfView() : sf::View This;
This(new sf::View),
OwnInstance(true)
{
}
sfView(sfFloatRect Rect) :
This(new sf::View(sf::FloatRect(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom))),
OwnInstance(true)
{
}
sfView(sf::View* View) :
This(View),
OwnInstance(false)
{
}
sfView(const sfView& View) :
This(View.This ? new sf::View(*View.This) : NULL),
OwnInstance(true)
{
}
~sfView()
{
if (OwnInstance)
delete This;
}
sf::View* This; // pointer needed for RenderWindow
bool OwnInstance;
}; };