mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-24 21:53:37 +02:00
Deduplicate code for sfContextSettings (#116)
Deduplicate code for sfContextSettings
This commit is contained in:
1 parent
1226d9db94
commit
2e47e5dbda
6 files changed
+134
-58
No files matched your search
@@ -38,6 +38,7 @@
|
||||
#include <SFML/Graphics/ConvertRenderStates.hpp>
|
||||
#include <SFML/Window/Touch.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
#include <SFML/Window/ContextSettingsInternal.h>
|
||||
#include <SFML/ConvertEvent.h>
|
||||
|
||||
|
||||
@@ -51,12 +52,7 @@ sfRenderWindow* sfRenderWindow_create(sfVideoMode mode, const char* title, sfUin
|
||||
sf::ContextSettings params;
|
||||
if (settings)
|
||||
{
|
||||
params.depthBits = settings->depthBits;
|
||||
params.stencilBits = settings->stencilBits;
|
||||
params.antialiasingLevel = settings->antialiasingLevel;
|
||||
params.majorVersion = settings->majorVersion;
|
||||
params.minorVersion = settings->minorVersion;
|
||||
params.attributeFlags = settings->attributeFlags;
|
||||
priv::sfContextSettings_writeToCpp(*settings, params);
|
||||
}
|
||||
|
||||
// Create the window
|
||||
@@ -78,12 +74,7 @@ sfRenderWindow* sfRenderWindow_createUnicode(sfVideoMode mode, const sfUint32* t
|
||||
sf::ContextSettings params;
|
||||
if (settings)
|
||||
{
|
||||
params.depthBits = settings->depthBits;
|
||||
params.stencilBits = settings->stencilBits;
|
||||
params.antialiasingLevel = settings->antialiasingLevel;
|
||||
params.majorVersion = settings->majorVersion;
|
||||
params.minorVersion = settings->minorVersion;
|
||||
params.attributeFlags = settings->attributeFlags;
|
||||
priv::sfContextSettings_writeToCpp(*settings, params);
|
||||
}
|
||||
|
||||
// Create the window
|
||||
@@ -103,12 +94,7 @@ sfRenderWindow* sfRenderWindow_createFromHandle(sfWindowHandle handle, const sfC
|
||||
sf::ContextSettings params;
|
||||
if (settings)
|
||||
{
|
||||
params.depthBits = settings->depthBits;
|
||||
params.stencilBits = settings->stencilBits;
|
||||
params.antialiasingLevel = settings->antialiasingLevel;
|
||||
params.majorVersion = settings->majorVersion;
|
||||
params.minorVersion = settings->minorVersion;
|
||||
params.attributeFlags = settings->attributeFlags;
|
||||
priv::sfContextSettings_writeToCpp(*settings, params);
|
||||
}
|
||||
|
||||
// Create the window
|
||||
@@ -145,16 +131,11 @@ sfBool sfRenderWindow_isOpen(const sfRenderWindow* renderWindow)
|
||||
////////////////////////////////////////////////////////////
|
||||
sfContextSettings sfRenderWindow_getSettings(const sfRenderWindow* renderWindow)
|
||||
{
|
||||
sfContextSettings settings = {0, 0, 0, 2, 0};
|
||||
sfContextSettings settings = priv::sfContextSettings_null();
|
||||
CSFML_CHECK_RETURN(renderWindow, settings);
|
||||
|
||||
const sf::ContextSettings& params = renderWindow->This.getSettings();
|
||||
settings.depthBits = params.depthBits;
|
||||
settings.stencilBits = params.stencilBits;
|
||||
settings.antialiasingLevel = params.antialiasingLevel;
|
||||
settings.majorVersion = params.majorVersion;
|
||||
settings.minorVersion = params.minorVersion;
|
||||
settings.attributeFlags = params.attributeFlags;
|
||||
priv::sfContextSettings_readFromCpp(params, settings);
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ set(SRCROOT ${CMAKE_SOURCE_DIR}/src/SFML/Window)
|
||||
set(SRC
|
||||
${INCROOT}/Export.h
|
||||
${SRCROOT}/Context.cpp
|
||||
${SRCROOT}/ContextSettingsInternal.cpp
|
||||
${SRCROOT}/ContextSettingsInternal.h
|
||||
${SRCROOT}/ContextStruct.h
|
||||
${INCROOT}/Context.h
|
||||
${INCROOT}/Event.h
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <SFML/Window/Context.h>
|
||||
#include <SFML/Window/ContextStruct.h>
|
||||
#include <SFML/Internal.h>
|
||||
#include <SFML/Window/ContextSettingsInternal.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -53,17 +54,11 @@ sfBool sfContext_setActive(sfContext* context, sfBool active)
|
||||
////////////////////////////////////////////////////////////
|
||||
sfContextSettings sfContext_getSettings(const sfContext* context)
|
||||
{
|
||||
sfContextSettings settings = {0, 0, 0, 0, 0};
|
||||
sfContextSettings settings = priv::sfContextSettings_null();
|
||||
CSFML_CHECK_RETURN(context, settings);
|
||||
|
||||
const sf::ContextSettings& params = context->This.getSettings();
|
||||
|
||||
settings.depthBits = params.depthBits;
|
||||
settings.stencilBits = params.stencilBits;
|
||||
settings.antialiasingLevel = params.antialiasingLevel;
|
||||
settings.majorVersion = params.majorVersion;
|
||||
settings.minorVersion = params.minorVersion;
|
||||
settings.attributeFlags = params.attributeFlags;
|
||||
priv::sfContextSettings_readFromCpp(params, settings);
|
||||
|
||||
return settings;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2016 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/ContextSettingsInternal.h>
|
||||
|
||||
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
sfContextSettings sfContextSettings_null()
|
||||
{
|
||||
sfContextSettings settings = {0, 0, 0, 0, 0, 0};
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfContextSettings_readFromCpp(const sf::ContextSettings& from, sfContextSettings& to)
|
||||
{
|
||||
to.depthBits = from.depthBits;
|
||||
to.stencilBits = from.stencilBits;
|
||||
to.antialiasingLevel = from.antialiasingLevel;
|
||||
to.majorVersion = from.majorVersion;
|
||||
to.minorVersion = from.minorVersion;
|
||||
to.attributeFlags = from.attributeFlags;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfContextSettings_writeToCpp(const sfContextSettings& from, sf::ContextSettings& to)
|
||||
{
|
||||
to.depthBits = from.depthBits;
|
||||
to.stencilBits = from.stencilBits;
|
||||
to.antialiasingLevel = from.antialiasingLevel;
|
||||
to.majorVersion = from.majorVersion;
|
||||
to.minorVersion = from.minorVersion;
|
||||
to.attributeFlags = from.attributeFlags;
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
@@ -0,0 +1,52 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2016 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_CONTEXTSETTINGSINTERNAL_H
|
||||
#define SFML_CONTEXTSETTINGSINTERNAL_H
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window.h>
|
||||
#include <SFML/Window.hpp>
|
||||
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
// Create a "null" sfContextSettings that's returned in case of an error.
|
||||
////////////////////////////////////////////////////////////
|
||||
sfContextSettings sfContextSettings_null();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Read the data of an sf::ContextSettings into an sfContextSettings
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfContextSettings_readFromCpp(const sf::ContextSettings& from, sfContextSettings& to);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Write the data of an sfContextSettings into an sf::ContextSettings
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfContextSettings_writeToCpp(const sfContextSettings& from, sf::ContextSettings& to);
|
||||
}
|
||||
|
||||
#endif // SFML_CONTEXTSETTINGSINTERNAL_H
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <SFML/Window/Window.h>
|
||||
#include <SFML/Window/WindowStruct.h>
|
||||
#include <SFML/Internal.h>
|
||||
#include <SFML/Window/ContextSettingsInternal.h>
|
||||
#include <SFML/ConvertEvent.h>
|
||||
|
||||
|
||||
@@ -41,12 +42,7 @@ sfWindow* sfWindow_create(sfVideoMode mode, const char* title, sfUint32 style, c
|
||||
sf::ContextSettings params;
|
||||
if (settings)
|
||||
{
|
||||
params.depthBits = settings->depthBits;
|
||||
params.stencilBits = settings->stencilBits;
|
||||
params.antialiasingLevel = settings->antialiasingLevel;
|
||||
params.majorVersion = settings->majorVersion;
|
||||
params.minorVersion = settings->minorVersion;
|
||||
params.attributeFlags = settings->attributeFlags;
|
||||
priv::sfContextSettings_writeToCpp(*settings, params);
|
||||
}
|
||||
|
||||
// Create the window
|
||||
@@ -66,12 +62,7 @@ sfWindow* sfWindow_createUnicode(sfVideoMode mode, const sfUint32* title, sfUint
|
||||
sf::ContextSettings params;
|
||||
if (settings)
|
||||
{
|
||||
params.depthBits = settings->depthBits;
|
||||
params.stencilBits = settings->stencilBits;
|
||||
params.antialiasingLevel = settings->antialiasingLevel;
|
||||
params.majorVersion = settings->majorVersion;
|
||||
params.minorVersion = settings->minorVersion;
|
||||
params.attributeFlags = settings->attributeFlags;
|
||||
priv::sfContextSettings_writeToCpp(*settings, params);
|
||||
}
|
||||
|
||||
// Create the window
|
||||
@@ -89,12 +80,7 @@ sfWindow* sfWindow_createFromHandle(sfWindowHandle handle, const sfContextSettin
|
||||
sf::ContextSettings params;
|
||||
if (settings)
|
||||
{
|
||||
params.depthBits = settings->depthBits;
|
||||
params.stencilBits = settings->stencilBits;
|
||||
params.antialiasingLevel = settings->antialiasingLevel;
|
||||
params.majorVersion = settings->majorVersion;
|
||||
params.minorVersion = settings->minorVersion;
|
||||
params.attributeFlags = settings->attributeFlags;
|
||||
priv::sfContextSettings_writeToCpp(*settings, params);
|
||||
}
|
||||
|
||||
// Create the window
|
||||
@@ -128,16 +114,11 @@ sfBool sfWindow_isOpen(const sfWindow* window)
|
||||
////////////////////////////////////////////////////////////
|
||||
sfContextSettings sfWindow_getSettings(const sfWindow* window)
|
||||
{
|
||||
sfContextSettings settings = {0, 0, 0, 0, 0};
|
||||
sfContextSettings settings = priv::sfContextSettings_null();
|
||||
CSFML_CHECK_RETURN(window, settings);
|
||||
|
||||
const sf::ContextSettings& params = window->This.getSettings();
|
||||
settings.depthBits = params.depthBits;
|
||||
settings.stencilBits = params.stencilBits;
|
||||
settings.antialiasingLevel = params.antialiasingLevel;
|
||||
settings.majorVersion = params.majorVersion;
|
||||
settings.minorVersion = params.minorVersion;
|
||||
settings.attributeFlags = params.attributeFlags;
|
||||
priv::sfContextSettings_readFromCpp(params, settings);
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user