Skip to content

Commit e0589c3

Browse files
MarioalexsanChrisThrasher
authored andcommitted
Implement missing functions
1 parent 16ae40d commit e0589c3

File tree

11 files changed

+211
-0
lines changed

11 files changed

+211
-0
lines changed

include/SFML/Graphics/RenderWindow.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,5 +618,18 @@ CSFML_GRAPHICS_API void sfMouse_setPositionRenderWindow(sfVector2i position, con
618618
////////////////////////////////////////////////////////////
619619
CSFML_GRAPHICS_API sfVector2i sfTouch_getPositionRenderWindow(unsigned int finger, const sfRenderWindow* relativeTo);
620620

621+
////////////////////////////////////////////////////////////
622+
/// \brief Create a Vulkan rendering surface
623+
///
624+
/// \param renderWindow RenderWindow object
625+
/// \param instance Vulkan instance
626+
/// \param surface Created surface
627+
/// \param allocator Allocator to use
628+
///
629+
/// \return True if surface creation was successful, false otherwise
630+
///
631+
////////////////////////////////////////////////////////////
632+
CSFML_GRAPHICS_API sfBool sfRenderWindow_createVulkanSurface(sfRenderWindow* renderWindow, const VkInstance* instance, VkSurfaceKHR* surface, const VkAllocationCallbacks* allocator);
633+
621634

622635
#endif // SFML_RENDERWINDOW_H

include/SFML/System/Alloc.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
////////////////////////////////////////////////////////////
2+
//
3+
// SFML - Simple and Fast Multimedia Library
4+
// Copyright (C) 2007-2023 Laurent Gomila ([email protected])
5+
//
6+
// This software is provided 'as-is', without any express or implied warranty.
7+
// In no event will the authors be held liable for any damages arising from the use of this software.
8+
//
9+
// Permission is granted to anyone to use this software for any purpose,
10+
// including commercial applications, and to alter it and redistribute it freely,
11+
// subject to the following restrictions:
12+
//
13+
// 1. The origin of this software must not be misrepresented;
14+
// you must not claim that you wrote the original software.
15+
// If you use this software in a product, an acknowledgment
16+
// in the product documentation would be appreciated but is not required.
17+
//
18+
// 2. Altered source versions must be plainly marked as such,
19+
// and must not be misrepresented as being the original software.
20+
//
21+
// 3. This notice may not be removed or altered from any source distribution.
22+
//
23+
////////////////////////////////////////////////////////////
24+
25+
#ifndef SFML_ALLOC_H
26+
#define SFML_ALLOC_H
27+
28+
////////////////////////////////////////////////////////////
29+
// Headers
30+
////////////////////////////////////////////////////////////
31+
#include <SFML/System/Export.h>
32+
33+
34+
////////////////////////////////////////////////////////////
35+
/// \brief Deallocates memory
36+
///
37+
/// This function deallocates the memory being pointed to
38+
/// using the free function from the C standard library.
39+
///
40+
/// The memory must have been previously allocated using a call
41+
/// to malloc.
42+
///
43+
/// \param ptr Pointer to the memory to deallocate
44+
///
45+
////////////////////////////////////////////////////////////
46+
CSFML_SYSTEM_API void sfFree(void* ptr);
47+
48+
49+
#endif // SFML_ALLOC_H

include/SFML/Window/Mouse.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,30 @@ CSFML_WINDOW_API sfVector2i sfMouse_getPosition(const sfWindow* relativeTo);
9494
////////////////////////////////////////////////////////////
9595
CSFML_WINDOW_API void sfMouse_setPosition(sfVector2i position, const sfWindow* relativeTo);
9696

97+
////////////////////////////////////////////////////////////
98+
/// \brief Get the current position of the mouse relative to a window base
99+
///
100+
/// This function returns the current position of the mouse
101+
/// cursor relative to the given window base, or desktop if NULL is passed.
102+
///
103+
/// \param relativeTo Reference window
104+
///
105+
/// \return Position of the mouse cursor, relative to the given window base
106+
///
107+
////////////////////////////////////////////////////////////
108+
CSFML_WINDOW_API sfVector2i sfMouse_getPositionWindowBase(const sfWindowBase* relativeTo);
109+
110+
////////////////////////////////////////////////////////////
111+
/// \brief Set the current position of the mouse relative to a window base
112+
///
113+
/// This function sets the current position of the mouse
114+
/// cursor relative to the given window base, or desktop if NULL is passed.
115+
///
116+
/// \param position New position of the mouse
117+
/// \param relativeTo Reference window
118+
///
119+
////////////////////////////////////////////////////////////
120+
CSFML_WINDOW_API void sfMouse_setPositionWindowBase(sfVector2i position, const sfWindowBase* relativeTo);
121+
97122

98123
#endif // SFML_MOUSE_H

include/SFML/Window/Touch.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,19 @@ CSFML_WINDOW_API sfBool sfTouch_isDown(unsigned int finger);
5757
////////////////////////////////////////////////////////////
5858
CSFML_WINDOW_API sfVector2i sfTouch_getPosition(unsigned int finger, const sfWindow* relativeTo);
5959

60+
////////////////////////////////////////////////////////////
61+
/// \brief Get the current position of a touch in window coordinates
62+
///
63+
/// This function returns the current touch position
64+
/// relative to the given window base, or desktop if NULL is passed.
65+
///
66+
/// \param finger Finger index
67+
/// \param relativeTo Reference window
68+
///
69+
/// \return Current position of \a finger, or undefined if it's not down
70+
///
71+
////////////////////////////////////////////////////////////
72+
CSFML_WINDOW_API sfVector2i sfTouch_getPositionWindowBase(unsigned int finger, const sfWindowBase* relativeTo);
73+
6074

6175
#endif // SFML_TOUCH_H

include/SFML/Window/Window.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,5 +474,18 @@ CSFML_WINDOW_API void sfWindow_display(sfWindow* window);
474474
////////////////////////////////////////////////////////////
475475
CSFML_WINDOW_API sfWindowHandle sfWindow_getSystemHandle(const sfWindow* window);
476476

477+
////////////////////////////////////////////////////////////
478+
/// \brief Create a Vulkan rendering surface
479+
///
480+
/// \param window Window object
481+
/// \param instance Vulkan instance
482+
/// \param surface Created surface
483+
/// \param allocator Allocator to use
484+
///
485+
/// \return True if surface creation was successful, false otherwise
486+
///
487+
////////////////////////////////////////////////////////////
488+
CSFML_WINDOW_API sfBool sfWindow_createVulkanSurface(sfWindow* window, const VkInstance* instance, VkSurfaceKHR* surface, const VkAllocationCallbacks* allocator);
489+
477490

478491
#endif // SFML_WINDOW_H

src/SFML/Graphics/RenderWindow.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ void sfMouse_setPositionRenderWindow(sfVector2i position, const sfRenderWindow*
561561
sf::Mouse::setPosition(sf::Vector2i(position.x, position.y));
562562
}
563563

564+
564565
////////////////////////////////////////////////////////////
565566
sfVector2i sfTouch_getPositionRenderWindow(unsigned int finger, const sfRenderWindow* relativeTo)
566567
{
@@ -574,3 +575,12 @@ sfVector2i sfTouch_getPositionRenderWindow(unsigned int finger, const sfRenderWi
574575
sfVector2i position = { sfmlPosition.x, sfmlPosition.y };
575576
return position;
576577
}
578+
579+
580+
////////////////////////////////////////////////////////////
581+
sfBool sfRenderWindow_createVulkanSurface(sfRenderWindow* renderWindow, const VkInstance* instance, VkSurfaceKHR* surface, const VkAllocationCallbacks* allocator)
582+
{
583+
CSFML_CHECK_RETURN(instance, sfFalse);
584+
CSFML_CHECK_RETURN(surface, sfFalse);
585+
CSFML_CALL_RETURN(renderWindow, createVulkanSurface(*instance, *surface, allocator), sfFalse);
586+
}

src/SFML/System/Alloc.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
////////////////////////////////////////////////////////////
2+
//
3+
// SFML - Simple and Fast Multimedia Library
4+
// Copyright (C) 2007-2023 Laurent Gomila ([email protected])
5+
//
6+
// This software is provided 'as-is', without any express or implied warranty.
7+
// In no event will the authors be held liable for any damages arising from the use of this software.
8+
//
9+
// Permission is granted to anyone to use this software for any purpose,
10+
// including commercial applications, and to alter it and redistribute it freely,
11+
// subject to the following restrictions:
12+
//
13+
// 1. The origin of this software must not be misrepresented;
14+
// you must not claim that you wrote the original software.
15+
// If you use this software in a product, an acknowledgment
16+
// in the product documentation would be appreciated but is not required.
17+
//
18+
// 2. Altered source versions must be plainly marked as such,
19+
// and must not be misrepresented as being the original software.
20+
//
21+
// 3. This notice may not be removed or altered from any source distribution.
22+
//
23+
////////////////////////////////////////////////////////////
24+
25+
////////////////////////////////////////////////////////////
26+
// Headers
27+
////////////////////////////////////////////////////////////
28+
#include <SFML/System/Alloc.h>
29+
30+
#include <stdlib.h>
31+
32+
33+
////////////////////////////////////////////////////////////
34+
void sfFree(void* ptr)
35+
{
36+
free(ptr);
37+
}

src/SFML/System/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ set(SRCROOT ${PROJECT_SOURCE_DIR}/src/SFML/System)
66
set(SRC
77
${PROJECT_SOURCE_DIR}/include/SFML/GPUPreference.h
88
${INCROOT}/Export.h
9+
${SRCROOT}/Alloc.cpp
10+
${INCROOT}/Alloc.h
911
${SRCROOT}/Buffer.cpp
1012
${SRCROOT}/BufferStruct.h
1113
${INCROOT}/Buffer.h

src/SFML/Window/Mouse.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
// Headers
2727
////////////////////////////////////////////////////////////
2828
#include <SFML/Window/Mouse.h>
29+
#include <SFML/Window/WindowBaseStruct.h>
2930
#include <SFML/Window/WindowStruct.h>
3031
#include <SFML/Window/Mouse.hpp>
3132
#include <SFML/Internal.h>
@@ -60,3 +61,27 @@ void sfMouse_setPosition(sfVector2i position, const sfWindow* relativeTo)
6061
else
6162
sf::Mouse::setPosition(sf::Vector2i(position.x, position.y));
6263
}
64+
65+
66+
////////////////////////////////////////////////////////////
67+
sfVector2i sfMouse_getPositionWindowBase(const sfWindowBase* relativeTo)
68+
{
69+
sf::Vector2i sfmlPos;
70+
if (relativeTo)
71+
sfmlPos = sf::Mouse::getPosition(relativeTo->This);
72+
else
73+
sfmlPos = sf::Mouse::getPosition();
74+
75+
sfVector2i position = { sfmlPos.x, sfmlPos.y };
76+
return position;
77+
}
78+
79+
80+
////////////////////////////////////////////////////////////
81+
void sfMouse_setPositionWindowBase(sfVector2i position, const sfWindowBase* relativeTo)
82+
{
83+
if (relativeTo)
84+
sf::Mouse::setPosition(sf::Vector2i(position.x, position.y), relativeTo->This);
85+
else
86+
sf::Mouse::setPosition(sf::Vector2i(position.x, position.y));
87+
}

src/SFML/Window/Touch.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
////////////////////////////////////////////////////////////
2828
#include <SFML/Window/Touch.h>
2929
#include <SFML/Window/Touch.hpp>
30+
#include <SFML/Window/WindowBaseStruct.h>
3031
#include <SFML/Window/WindowStruct.h>
3132
#include <SFML/Internal.h>
3233

@@ -51,3 +52,16 @@ sfVector2i sfTouch_getPosition(unsigned int finger, const sfWindow* relativeTo)
5152
return position;
5253
}
5354

55+
////////////////////////////////////////////////////////////
56+
sfVector2i sfTouch_getPositionWindowBase(unsigned int finger, const sfWindowBase* relativeTo)
57+
{
58+
sf::Vector2i sfmlPosition;
59+
60+
if (relativeTo)
61+
sfmlPosition = sf::Touch::getPosition(finger, relativeTo->This);
62+
else
63+
sfmlPosition = sf::Touch::getPosition(finger);
64+
65+
sfVector2i position = { sfmlPosition.x, sfmlPosition.y };
66+
return position;
67+
}

0 commit comments

Comments
 (0)