mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Use sf::Vector2
s for expressing sizes and positions
This commit is contained in:
parent
8509f0fddd
commit
cf3f4e8d89
@ -147,10 +147,9 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////.
|
////////////////////////////////////////////////////////.
|
||||||
- (void)setWindowPositionToX:(int)x Y:(int)y
|
- (void)setWindowPositionTo:(sf::Vector2i)position
|
||||||
{
|
{
|
||||||
(void)x;
|
(void)position;
|
||||||
(void)y;
|
|
||||||
sf::err() << "Cannot move SFML area when SFML is integrated in a NSView. Use the view handler directly instead."
|
sf::err() << "Cannot move SFML area when SFML is integrated in a NSView. Use the view handler directly instead."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
@ -164,9 +163,9 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
- (void)resizeTo:(unsigned int)width by:(unsigned int)height
|
- (void)resizeTo:(sf::Vector2u)size
|
||||||
{
|
{
|
||||||
NSRect frame = NSMakeRect([m_view frame].origin.x, [m_view frame].origin.y, width, height);
|
NSRect frame = NSMakeRect([m_view frame].origin.x, [m_view frame].origin.y, size.x, size.y);
|
||||||
|
|
||||||
[m_view setFrame:frame];
|
[m_view setFrame:frame];
|
||||||
[m_oglView setFrame:frame];
|
[m_oglView setFrame:frame];
|
||||||
@ -249,10 +248,9 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
- (void)setIconTo:(unsigned int)width by:(unsigned int)height with:(const std::uint8_t*)pixels
|
- (void)setIconTo:(sf::Vector2u)size with:(const std::uint8_t*)pixels
|
||||||
{
|
{
|
||||||
(void)width;
|
(void)size;
|
||||||
(void)height;
|
|
||||||
(void)pixels;
|
(void)pixels;
|
||||||
sf::err() << "Cannot set an icon when SFML is integrated in a NSView." << std::endl;
|
sf::err() << "Cannot set an icon when SFML is integrated in a NSView." << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -404,9 +404,9 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
- (void)setWindowPositionToX:(int)x Y:(int)y
|
- (void)setWindowPositionTo:(sf::Vector2i)position
|
||||||
{
|
{
|
||||||
NSPoint point = NSMakePoint(x, y);
|
NSPoint point = NSMakePoint(position.x, position.y);
|
||||||
|
|
||||||
// Flip for SFML window coordinate system and take titlebar into account
|
// Flip for SFML window coordinate system and take titlebar into account
|
||||||
point.y = static_cast<double>([self screenHeight]) - point.y + static_cast<double>([self titlebarHeight]);
|
point.y = static_cast<double>([self screenHeight]) - point.y + static_cast<double>([self titlebarHeight]);
|
||||||
@ -427,7 +427,7 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
- (void)resizeTo:(unsigned int)width by:(unsigned int)height
|
- (void)resizeTo:(sf::Vector2u)size
|
||||||
{
|
{
|
||||||
if (m_fullscreen)
|
if (m_fullscreen)
|
||||||
{
|
{
|
||||||
@ -436,12 +436,11 @@
|
|||||||
sf::VideoMode desktop = sf::VideoMode::getDesktopMode();
|
sf::VideoMode desktop = sf::VideoMode::getDesktopMode();
|
||||||
sf::priv::scaleInXY(desktop.size, nil);
|
sf::priv::scaleInXY(desktop.size, nil);
|
||||||
|
|
||||||
width = std::min(width, desktop.size.x);
|
size.x = std::min(size.x, desktop.size.x);
|
||||||
height = std::min(height, desktop.size.y);
|
size.y = std::min(size.y, desktop.size.y);
|
||||||
|
|
||||||
CGFloat x = (desktop.size.x - width) / 2.0;
|
const auto origin = sf::Vector2<CGFloat>(desktop.size - size) / CGFloat{2};
|
||||||
CGFloat y = (desktop.size.y - height) / 2.0;
|
NSRect oglRect = NSMakeRect(origin.x, origin.y, size.x, size.y);
|
||||||
NSRect oglRect = NSMakeRect(x, y, width, height);
|
|
||||||
|
|
||||||
[m_oglView setFrame:oglRect];
|
[m_oglView setFrame:oglRect];
|
||||||
[m_oglView setNeedsDisplay:YES];
|
[m_oglView setNeedsDisplay:YES];
|
||||||
@ -455,19 +454,19 @@
|
|||||||
[m_window setStyleMask:styleMask ^ NSResizableWindowMask];
|
[m_window setStyleMask:styleMask ^ NSResizableWindowMask];
|
||||||
|
|
||||||
// Add titlebar height.
|
// Add titlebar height.
|
||||||
height += static_cast<unsigned int>([self titlebarHeight]);
|
size.y += static_cast<unsigned int>([self titlebarHeight]);
|
||||||
|
|
||||||
// Corner case: don't set the window height bigger than the screen height
|
// Corner case: don't set the window height bigger than the screen height
|
||||||
// or the view will be resized _later_ without generating a resize event.
|
// or the view will be resized _later_ without generating a resize event.
|
||||||
NSRect screenFrame = [[NSScreen mainScreen] visibleFrame];
|
NSRect screenFrame = [[NSScreen mainScreen] visibleFrame];
|
||||||
CGFloat maxVisibleHeight = screenFrame.size.height;
|
CGFloat maxVisibleHeight = screenFrame.size.height;
|
||||||
if (height > maxVisibleHeight)
|
if (size.y > maxVisibleHeight)
|
||||||
height = static_cast<unsigned int>(maxVisibleHeight);
|
size.y = static_cast<unsigned int>(maxVisibleHeight);
|
||||||
|
|
||||||
if (m_requester != nil)
|
if (m_requester != nil)
|
||||||
m_requester->windowResized({width, height - static_cast<unsigned int>([self titlebarHeight])});
|
m_requester->windowResized({size.x, size.y - static_cast<unsigned int>([self titlebarHeight])});
|
||||||
|
|
||||||
NSRect frame = NSMakeRect([m_window frame].origin.x, [m_window frame].origin.y, width, height);
|
NSRect frame = NSMakeRect([m_window frame].origin.x, [m_window frame].origin.y, size.x, size.y);
|
||||||
|
|
||||||
[m_window setFrame:frame display:YES];
|
[m_window setFrame:frame display:YES];
|
||||||
|
|
||||||
@ -555,10 +554,10 @@
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
- (void)setIconTo:(unsigned int)width by:(unsigned int)height with:(const std::uint8_t*)pixels
|
- (void)setIconTo:(sf::Vector2u)size with:(const std::uint8_t*)pixels
|
||||||
{
|
{
|
||||||
// Load image and set app icon.
|
// Load image and set app icon.
|
||||||
NSImage* icon = [NSImage imageWithRawData:pixels andSize:NSMakeSize(width, height)];
|
NSImage* icon = [NSImage imageWithRawData:pixels andSize:NSMakeSize(size.x, size.y)];
|
||||||
|
|
||||||
[[SFApplication sharedApplication] setApplicationIconImage:icon];
|
[[SFApplication sharedApplication] setApplicationIconImage:icon];
|
||||||
|
|
||||||
|
@ -428,7 +428,7 @@ void WindowImplCocoa::setPosition(const Vector2i& position)
|
|||||||
const AutoreleasePool pool;
|
const AutoreleasePool pool;
|
||||||
sf::Vector2i backingPosition = position;
|
sf::Vector2i backingPosition = position;
|
||||||
scaleInXY(backingPosition, m_delegate);
|
scaleInXY(backingPosition, m_delegate);
|
||||||
[m_delegate setWindowPositionToX:backingPosition.x Y:backingPosition.y];
|
[m_delegate setWindowPositionTo:backingPosition];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -448,7 +448,7 @@ void WindowImplCocoa::setSize(const Vector2u& size)
|
|||||||
{
|
{
|
||||||
sf::Vector2u backingSize = size;
|
sf::Vector2u backingSize = size;
|
||||||
scaleInXY(backingSize, m_delegate);
|
scaleInXY(backingSize, m_delegate);
|
||||||
[m_delegate resizeTo:backingSize.x by:backingSize.y];
|
[m_delegate resizeTo:backingSize];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -485,7 +485,7 @@ void WindowImplCocoa::setTitle(const String& title)
|
|||||||
void WindowImplCocoa::setIcon(const Vector2u& size, const std::uint8_t* pixels)
|
void WindowImplCocoa::setIcon(const Vector2u& size, const std::uint8_t* pixels)
|
||||||
{
|
{
|
||||||
const AutoreleasePool pool;
|
const AutoreleasePool pool;
|
||||||
[m_delegate setIconTo:size.x by:size.y with:pixels];
|
[m_delegate setIconTo:size with:pixels];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
|
|
||||||
#include <SFML/Window/WindowHandle.hpp>
|
#include <SFML/Window/WindowHandle.hpp>
|
||||||
|
|
||||||
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
|
||||||
#import <AppKit/AppKit.h>
|
#import <AppKit/AppKit.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@ -128,11 +130,10 @@ class WindowImplCocoa;
|
|||||||
///
|
///
|
||||||
/// Doesn't apply if the implementation is 'only' a view.
|
/// Doesn't apply if the implementation is 'only' a view.
|
||||||
///
|
///
|
||||||
/// \param x x position in SFML coordinates
|
/// \param position x and y position in SFML coordinates
|
||||||
/// \param y y position in SFML coordinates
|
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
- (void)setWindowPositionToX:(int)x Y:(int)y;
|
- (void)setWindowPositionTo:(sf::Vector2i)position;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get window/view's size
|
/// \brief Get window/view's size
|
||||||
@ -145,11 +146,10 @@ class WindowImplCocoa;
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Resize the window/view
|
/// \brief Resize the window/view
|
||||||
///
|
///
|
||||||
/// \param width new width
|
/// \param size new width and height
|
||||||
/// \param height new height
|
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
- (void)resizeTo:(unsigned int)width by:(unsigned int)height;
|
- (void)resizeTo:(sf::Vector2u)size;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set the minimize window/view size
|
/// \brief Set the minimize window/view size
|
||||||
@ -231,12 +231,11 @@ class WindowImplCocoa;
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Set an icon to the application
|
/// \brief Set an icon to the application
|
||||||
///
|
///
|
||||||
/// \param width icon's width
|
/// \param size icon's width and height
|
||||||
/// \param height icon's height
|
|
||||||
/// \param pixels icon's data
|
/// \param pixels icon's data
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
- (void)setIconTo:(unsigned int)width by:(unsigned int)height with:(const std::uint8_t*)pixels;
|
- (void)setIconTo:(sf::Vector2u)size with:(const std::uint8_t*)pixels;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Fetch new event
|
/// \brief Fetch new event
|
||||||
|
Loading…
Reference in New Issue
Block a user