Merge branch 'master' of github.com:LaurentGomila/SFML

This commit is contained in:
Laurent Gomila 2012-03-11 19:11:00 +01:00
commit 1dad4219a6
5 changed files with 99 additions and 53 deletions

View File

@ -51,8 +51,8 @@ struct SFMLmainWindow
sprite.SetOrigin(size / 2.f);
sprite.Scale(0.3, 0.3);
unsigned int ww = renderWindow.GetWidth();
unsigned int wh = renderWindow.GetHeight();
unsigned int ww = renderWindow.GetSize().x;
unsigned int wh = renderWindow.GetSize().y;
sprite.SetPosition(sf::Vector2f(ww, wh) / 2.f);
text.SetColor(sf::Color::White);
@ -104,7 +104,7 @@ struct SFMLmainWindow
{
if (!self.initialized)
{
// Init the 1st SFML render area.
// Init the SFML render area.
self.mainWindow = new SFMLmainWindow(self.sfmlView);
self.mainWindow->text.SetString([self.textField.stringValue tostdwstring]);
self.visible = YES;
@ -141,7 +141,7 @@ struct SFMLmainWindow
self.sfmlView = nil;
self.textField = nil;
delete self.mainWindow;
delete (SFMLmainWindow *) self.mainWindow;
self.mainWindow = 0;
self.renderTimer = nil;

View File

@ -195,6 +195,18 @@
}
////////////////////////////////////////////////////////////
-(NSPoint)position
{
NSPoint pos = [myView frame].origin;
// Flip screen coodinates
float const screenHeight = NSHeight([[[myView window] screen] frame]);
pos.y = screenHeight - pos.y;
return pos;
}
////////////////////////////////////////////////////////.
-(void)setWindowPositionToX:(unsigned int)x Y:(unsigned int)y
{
@ -202,6 +214,12 @@
}
////////////////////////////////////////////////////////////
-(NSSize)size
{
return [myView frame].size;
}
////////////////////////////////////////////////////////
-(void)resizeTo:(unsigned int)width by:(unsigned int)height
{

View File

@ -289,6 +289,18 @@
}
////////////////////////////////////////////////////////////
-(NSPoint)position
{
NSPoint pos = [myOGLView frame].origin;
// Flip for SFML window coordinate system.
pos.y = [self screenHeight] - pos.y;
return pos;
}
////////////////////////////////////////////////////////.
-(void)setWindowPositionToX:(unsigned int)x Y:(unsigned int)y
{
@ -302,6 +314,13 @@
}
////////////////////////////////////////////////////////
-(NSSize)size
{
return [myOGLView frame].size;
}
////////////////////////////////////////////////////////
-(void)resizeTo:(unsigned int)width by:(unsigned int)height
{

View File

@ -56,19 +56,11 @@ WindowImplCocoa::WindowImplCocoa(WindowHandle handle)
// We have a window.
myDelegate = [[SFWindowController alloc] initWithWindow:nsHandle];
// Don't forget to update our parent (that is, WindowImpl) size :
myWidth = [[nsHandle contentView] frame].size.width;
myHeight = [[nsHandle contentView] frame].size.height;
} else if ([nsHandle isKindOfClass:[NSView class]]) {
// We have a view.
myDelegate = [[SFViewController alloc] initWithView:nsHandle];
// Don't forget to update our parent (that is, WindowImpl) size :
myWidth = [nsHandle frame].size.width;
myHeight = [nsHandle frame].size.height;
} else {
sf::Err()
@ -100,10 +92,6 @@ WindowImplCocoa::WindowImplCocoa(VideoMode mode,
// Ask for a pool.
RetainPool();
// Don't forget to update our parent (that is, WindowImpl) size :
myWidth = mode.Width;
myHeight = mode.Height;
myDelegate = [[SFWindowController alloc] initWithMode:mode andStyle:style];
[myDelegate changeTitle:stringToNSString(title)];
[myDelegate setRequesterTo:this];
@ -173,14 +161,10 @@ void WindowImplCocoa::WindowClosed(void)
////////////////////////////////////////////////////////////
void WindowImplCocoa::WindowResized(unsigned int width, unsigned int height)
{
// Don't forget to update our parent (that is, WindowImpl) size :
myWidth = width;
myHeight = height;
Event event;
event.Type = Event::Resized;
event.Size.Width = myWidth;
event.Size.Height = myHeight;
event.Size.Width = width;
event.Size.Height = height;
PushEvent(event);
}
@ -350,33 +334,32 @@ WindowHandle WindowImplCocoa::GetSystemHandle() const
////////////////////////////////////////////////////////////
void WindowImplCocoa::ShowMouseCursor(bool show)
Vector2i WindowImplCocoa::GetPosition() const
{
myShowCursor = show;
if (myShowCursor) {
[myDelegate showMouseCursor];
} else {
[myDelegate hideMouseCursor];
}
NSPoint pos = [myDelegate position];
return Vector2i(pos.x, pos.y);
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::SetPosition(int x, int y)
void WindowImplCocoa::SetPosition(const Vector2i& position)
{
[myDelegate setWindowPositionToX:x Y:y];
[myDelegate setWindowPositionToX:position.x Y:position.y];
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::SetSize(unsigned int width, unsigned int height)
Vector2u WindowImplCocoa::GetSize() const
{
// Don't forget to update our parent (that is, WindowImpl) size :
myWidth = width;
myHeight = height;
NSSize size = [myDelegate size];
return Vector2u(size.width, size.height);
}
[myDelegate resizeTo:width by:height];
////////////////////////////////////////////////////////////
void WindowImplCocoa::SetSize(const Vector2u& size)
{
[myDelegate resizeTo:size.x by:size.y];
}
@ -388,9 +371,16 @@ void WindowImplCocoa::SetTitle(const std::string& title)
////////////////////////////////////////////////////////////
void WindowImplCocoa::Show(bool show)
void WindowImplCocoa::SetIcon(unsigned int width, unsigned int height, const Uint8* pixels)
{
if (show) {
[myDelegate setIconTo:width by:height with:pixels];
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::SetVisible(bool visible)
{
if (visible) {
[myDelegate showWindow];
} else {
[myDelegate hideWindow];
@ -399,7 +389,20 @@ void WindowImplCocoa::Show(bool show)
////////////////////////////////////////////////////////////
void WindowImplCocoa::EnableKeyRepeat(bool enabled)
void WindowImplCocoa::SetMouseCursorVisible(bool visible)
{
myShowCursor = visible;
if (myShowCursor) {
[myDelegate showMouseCursor];
} else {
[myDelegate hideMouseCursor];
}
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::SetKeyRepeatEnabled(bool enabled)
{
if (enabled) {
[myDelegate enableKeyRepeat];
@ -409,12 +412,6 @@ void WindowImplCocoa::EnableKeyRepeat(bool enabled)
}
////////////////////////////////////////////////////////////
void WindowImplCocoa::SetIcon(unsigned int width, unsigned int height, const Uint8* pixels)
{
[myDelegate setIconTo:width by:height with:pixels];
}
} // namespace priv
} // namespace sf

View File

@ -89,12 +89,24 @@ namespace sf {
////////////////////////////////////////////////////////////
-(void)setCursorPositionToX:(unsigned int)x Y:(unsigned int)y;
////////////////////////////////////////////////////////////
/// Get window's position.
///
////////////////////////////////////////////////////////////
-(NSPoint)position;
////////////////////////////////////////////////////////////
/// Move the window (not the view if we handle not a window) (SFML Coordinates).
///
////////////////////////////////////////////////////////////
-(void)setWindowPositionToX:(unsigned int)x Y:(unsigned int)y;
////////////////////////////////////////////////////////////
/// Get window's size.
///
////////////////////////////////////////////////////////////
-(NSSize)size;
////////////////////////////////////////////////////////////
/// Resize the window/view.
///