summaryrefslogtreecommitdiff
path: root/examples/cocoa
diff options
context:
space:
mode:
authorJames Cowgill <james410@cowgill.org.uk>2014-12-09 20:21:40 +0000
committerJames Cowgill <james410@cowgill.org.uk>2014-12-09 20:21:40 +0000
commitfa21c65d0c764705cfc377bf0d0de08fac26874e (patch)
treedbc9e87bbd8684d15e79fc0c8b7a8985389c3b35 /examples/cocoa
parentdd835931261c340acd5f0409341d13fa2670423e (diff)
Imported Upstream version 2.2.0+dfsg
Diffstat (limited to 'examples/cocoa')
-rw-r--r--examples/cocoa/CMakeLists.txt32
-rw-r--r--examples/cocoa/CocoaAppDelegate.h51
-rw-r--r--examples/cocoa/CocoaAppDelegate.mm107
-rw-r--r--examples/cocoa/NSString+stdstring.h8
-rw-r--r--examples/cocoa/NSString+stdstring.mm47
-rw-r--r--examples/cocoa/main.m4
-rw-r--r--examples/cocoa/resources/Cocoa-Info.plist4
7 files changed, 121 insertions, 132 deletions
diff --git a/examples/cocoa/CMakeLists.txt b/examples/cocoa/CMakeLists.txt
index b8b2b4e..6eebf8f 100644
--- a/examples/cocoa/CMakeLists.txt
+++ b/examples/cocoa/CMakeLists.txt
@@ -1,8 +1,8 @@
-
-set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/cocoa)
-
-# all source files
-set(SRC ${SRCROOT}/CocoaAppDelegate.h
+
+set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/cocoa)
+
+# all source files
+set(SRC ${SRCROOT}/CocoaAppDelegate.h
${SRCROOT}/CocoaAppDelegate.mm
${SRCROOT}/NSString+stdstring.h
${SRCROOT}/NSString+stdstring.mm
@@ -28,9 +28,9 @@ set_target_properties(cocoa PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${SRCROOT}/resources/Cocoa-Info.plist)
target_link_libraries(cocoa "-framework Cocoa -framework Foundation"
sfml-system sfml-window sfml-graphics)
-
-# set the target's folder (for IDEs that support it, e.g. Visual Studio)
-set_target_properties(cocoa PROPERTIES FOLDER "Examples")
+
+# set the target's folder (for IDEs that support it, e.g. Visual Studio)
+set_target_properties(cocoa PROPERTIES FOLDER "Examples")
# compile XIB files
find_program(IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin")
@@ -48,20 +48,20 @@ foreach(XIB ${XIBS})
--compile ${XIB_OUTPUT_PATH}/${XIB}.nib
${XIB_INPUT_PATH}/${XIB}.xib
COMMENT "Compiling ${XIB}.xib")
- # deactivated options : --warnings --notices
+ # deactivated options: --warnings --notices
endforeach()
# add install rule
-install(TARGETS cocoa
+install(TARGETS cocoa
BUNDLE DESTINATION ${INSTALL_MISC_DIR}/examples/cocoa
- COMPONENT examples)
+ COMPONENT examples)
-#
+#
# define the cocoa target
# sfml_add_example is not compatible with application bundles !
-#
-#sfml_add_example(cocoa
-# SOURCES ${SRC}
+#
+#sfml_add_example(cocoa
+# SOURCES ${SRC}
# DEPENDS sfml-system sfml-window sfml-graphics)
#
-
+
diff --git a/examples/cocoa/CocoaAppDelegate.h b/examples/cocoa/CocoaAppDelegate.h
index f259a8c..388b395 100644
--- a/examples/cocoa/CocoaAppDelegate.h
+++ b/examples/cocoa/CocoaAppDelegate.h
@@ -1,8 +1,8 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
-// Laurent Gomila (laurent.gom@gmail.com),
+// Copyright (C) 2007-2014 Marco Antognini (antognini.marco@gmail.com),
+// Laurent Gomila (laurent.gom@gmail.com),
//
// 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.
@@ -27,39 +27,36 @@
#import <SFML/Graphics.hpp>
/*
- * NB : We need pointers for C++ objects fields in Obj-C interface !
- * The recomanded way is to use PIMP idiom.
+ * NB: We need pointers for C++ objects fields in Obj-C interface !
+ * The recommended way is to use PIMPL idiom.
*
- * It's elegant. Moreover, we do no constrain
- * other file including this one to be Obj-C++.
+ * It's elegant. Moreover, we do no constrain
+ * other file including this one to be Obj-C++.
*/
struct SFMLmainWindow;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
-@interface CocoaAppDelegate : NSObject <NSApplicationDelegate> {
-#else
-@interface CocoaAppDelegate : NSObject {
-#endif
+@interface CocoaAppDelegate : NSObject <NSApplicationDelegate>
+{
@private
- NSWindow *m_window;
- NSView *m_sfmlView;
- NSTextField *m_textField;
- SFMLmainWindow *m_mainWindow;
- NSTimer *m_renderTimer;
- BOOL m_visible;
- BOOL m_initialized;
+ NSWindow* m_window;
+ NSView* m_sfmlView;
+ NSTextField* m_textField;
+ SFMLmainWindow* m_mainWindow;
+ NSTimer* m_renderTimer;
+ BOOL m_visible;
+ BOOL m_initialized;
}
-@property (retain) IBOutlet NSWindow *window;
-@property (assign) IBOutlet NSView *sfmlView;
-@property (assign) IBOutlet NSTextField *textField;
+@property (retain) IBOutlet NSWindow* window;
+@property (assign) IBOutlet NSView* sfmlView;
+@property (assign) IBOutlet NSTextField* textField;
--(IBAction)colorChanged:(NSPopUpButton *)sender;
--(IBAction)rotationChanged:(NSSlider *)sender;
--(IBAction)visibleChanged:(NSButton *)sender;
--(IBAction)textChanged:(NSTextField *)sender;
--(IBAction)updateText:(NSButton *)sender;
+-(IBAction)colorChanged:(NSPopUpButton*)sender;
+-(IBAction)rotationChanged:(NSSlider*)sender;
+-(IBAction)visibleChanged:(NSButton*)sender;
+-(IBAction)textChanged:(NSTextField*)sender;
+-(IBAction)updateText:(NSButton*)sender;
@end
@@ -69,6 +66,6 @@ struct SFMLmainWindow;
*/
@interface SilentWindow : NSWindow
--(void)keyDown:(NSEvent *)theEvent;
+-(void)keyDown:(NSEvent*)theEvent;
@end
diff --git a/examples/cocoa/CocoaAppDelegate.mm b/examples/cocoa/CocoaAppDelegate.mm
index ff1bc1e..092e391 100644
--- a/examples/cocoa/CocoaAppDelegate.mm
+++ b/examples/cocoa/CocoaAppDelegate.mm
@@ -1,8 +1,8 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
-// Laurent Gomila (laurent.gom@gmail.com),
+// Copyright (C) 2007-2014 Marco Antognini (antognini.marco@gmail.com),
+// Laurent Gomila (laurent.gom@gmail.com),
//
// 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.
@@ -34,35 +34,33 @@
// Our PIMPL
struct SFMLmainWindow
{
- SFMLmainWindow(sf::WindowHandle win)
- : renderWindow(win)
- , background(sf::Color::Blue)
+ SFMLmainWindow(sf::WindowHandle win) :
+ renderWindow(win),
+ background(sf::Color::Blue)
{
std::string resPath = [[[NSBundle mainBundle] resourcePath] tostdstring];
- if (!logo.loadFromFile(resPath + "/logo.png")) {
+ if (!logo.loadFromFile(resPath + "/logo.png"))
NSLog(@"Couldn't load the logo image");
- }
-
+
logo.setSmooth(true);
-
+
sprite.setTexture(logo, true);
sf::FloatRect rect = sprite.getLocalBounds();
sf::Vector2f size(rect.width, rect.height);
sprite.setOrigin(size / 2.f);
sprite.scale(0.3, 0.3);
-
+
unsigned int ww = renderWindow.getSize().x;
unsigned int wh = renderWindow.getSize().y;
sprite.setPosition(sf::Vector2f(ww, wh) / 2.f);
- if (!font.loadFromFile(resPath + "/sansation.ttf")) {
+ if (!font.loadFromFile(resPath + "/sansation.ttf"))
NSLog(@"Couldn't load the font");
- }
-
+
text.setColor(sf::Color::White);
text.setFont(font);
}
-
+
sf::RenderWindow renderWindow;
sf::Font font;
sf::Text text;
@@ -74,13 +72,13 @@ struct SFMLmainWindow
// Private stuff
@interface CocoaAppDelegate ()
-@property (assign) SFMLmainWindow *mainWindow;
-@property (retain) NSTimer *renderTimer;
-@property (assign) BOOL visible;
+@property (assign) SFMLmainWindow* mainWindow;
+@property (retain) NSTimer* renderTimer;
+@property (assign) BOOL visible;
-@property (assign) BOOL initialized;
+@property (assign) BOOL initialized;
--(void)renderMainWindow:(NSTimer *)aTimer;
+-(void)renderMainWindow:(NSTimer*)aTimer;
@end
@@ -98,28 +96,31 @@ struct SFMLmainWindow
@synthesize initialized = m_initialized;
-- (id)init {
+- (id)init
+{
self = [super init];
- if (self) {
+ if (self)
self.initialized = NO;
- }
+
return self;
}
--(void)applicationDidFinishLaunching:(NSNotification *)aNotification
+-(void)applicationDidFinishLaunching:(NSNotification*)aNotification
{
+ (void)aNotification;
+
if (!self.initialized)
{
// Init the SFML render area.
self.mainWindow = new SFMLmainWindow(self.sfmlView);
self.mainWindow->text.setString([self.textField.stringValue tostdwstring]);
self.visible = YES;
-
+
// Launch the timer to periodically display our stuff into the Cocoa view.
self.renderTimer = [NSTimer timerWithTimeInterval:1.f/60.f
target:self
selector:@selector(renderMainWindow:)
- userInfo:nil
+ userInfo:nil
repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:self.renderTimer
forMode:NSDefaultRunLoopMode];
@@ -133,7 +134,7 @@ struct SFMLmainWindow
* while the second mode allows timer firing while he is using a slider
* or a menu.
*/
-
+
self.initialized = YES;
}
}
@@ -142,67 +143,58 @@ struct SFMLmainWindow
{
[self.renderTimer invalidate];
self.mainWindow->renderWindow.close();
-
+
self.window = nil;
self.sfmlView = nil;
self.textField = nil;
-
- delete (SFMLmainWindow *) self.mainWindow;
+
+ delete (SFMLmainWindow*) self.mainWindow;
self.mainWindow = 0;
self.renderTimer = nil;
-
+
[super dealloc];
}
--(void)renderMainWindow:(NSTimer *)aTimer
+-(void)renderMainWindow:(NSTimer*)aTimer
{
+ (void)aTimer;
+
// Scaling
/* /!\ we do this at 60fps so choose low scaling factor! /!\ */
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
- {
self.mainWindow->sprite.scale(1.01f, 1.01f);
- }
+
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
- {
self.mainWindow->sprite.scale(0.99f, 0.99f);
- }
-
+
// Clear the window, display some stuff and display it into our view.
-
+
self.mainWindow->renderWindow.clear(self.mainWindow->background);
-
+
if (self.visible)
- {
self.mainWindow->renderWindow.draw(self.mainWindow->sprite);
- }
-
+
self.mainWindow->renderWindow.draw(self.mainWindow->text);
-
+
self.mainWindow->renderWindow.display();
}
--(IBAction)colorChanged:(NSPopUpButton *)sender
+-(IBAction)colorChanged:(NSPopUpButton*)sender
{
if (self.initialized)
{
// Convert title to color
- NSString *color = [[sender selectedItem] title];
+ NSString* color = [[sender selectedItem] title];
if ([color isEqualToString:BLUE])
- {
self.mainWindow->background = sf::Color::Blue;
- }
else if ([color isEqualToString:GREEN])
- {
self.mainWindow->background = sf::Color::Green;
- }
else
- {
self.mainWindow->background = sf::Color::Red;
- }
}
}
--(IBAction)rotationChanged:(NSSlider *)sender
+-(IBAction)rotationChanged:(NSSlider*)sender
{
if (self.initialized)
{
@@ -211,21 +203,23 @@ struct SFMLmainWindow
}
}
--(IBAction)visibleChanged:(NSButton *)sender
+-(IBAction)visibleChanged:(NSButton*)sender
{
if (self.initialized)
self.visible = [sender state] == NSOnState;
}
--(IBAction)textChanged:(NSTextField *)sender
+-(IBAction)textChanged:(NSTextField*)sender
{
if (self.initialized)
self.mainWindow->text.setString([[sender stringValue] tostdwstring]);
}
-- (IBAction)updateText:(NSButton *)sender
+- (IBAction)updateText:(NSButton*)sender
{
- // Simply simulate textChanged :
+ (void)sender;
+
+ // Simply simulate textChanged:
[self textChanged:self.textField];
}
@@ -233,8 +227,9 @@ struct SFMLmainWindow
@implementation SilentWindow
--(void)keyDown:(NSEvent *)theEvent
+-(void)keyDown:(NSEvent*)theEvent
{
+ (void)theEvent;
// Do nothing except preventing this alert.
}
diff --git a/examples/cocoa/NSString+stdstring.h b/examples/cocoa/NSString+stdstring.h
index 0be2536..8abb567 100644
--- a/examples/cocoa/NSString+stdstring.h
+++ b/examples/cocoa/NSString+stdstring.h
@@ -1,8 +1,8 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
-// Laurent Gomila (laurent.gom@gmail.com),
+// Copyright (C) 2007-2014 Marco Antognini (antognini.marco@gmail.com),
+// Laurent Gomila (laurent.gom@gmail.com),
//
// 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.
@@ -28,9 +28,9 @@
@interface NSString (NSString_stdstring)
-+(id)stringWithstdstring:(std::string const &)string;
++(id)stringWithstdstring:(const std::string&)string;
-+(id)stringWithstdwstring:(std::wstring const &)string;
++(id)stringWithstdwstring:(const std::wstring&)string;
-(std::string)tostdstring;
diff --git a/examples/cocoa/NSString+stdstring.mm b/examples/cocoa/NSString+stdstring.mm
index 367b21a..f39e05c 100644
--- a/examples/cocoa/NSString+stdstring.mm
+++ b/examples/cocoa/NSString+stdstring.mm
@@ -1,8 +1,8 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
-// Laurent Gomila (laurent.gom@gmail.com),
+// Copyright (C) 2007-2014 Marco Antognini (antognini.marco@gmail.com),
+// Laurent Gomila (laurent.gom@gmail.com),
//
// 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.
@@ -28,51 +28,46 @@
@implementation NSString (NSString_stdstring)
-+(id)stringWithstdstring:(std::string const &)string
++(id)stringWithstdstring:(const std::string&)string
{
std::string utf8;
utf8.reserve(string.size() + 1);
-
+
sf::Utf8::fromAnsi(string.begin(), string.end(), std::back_inserter(utf8));
-
- NSString *str = [NSString stringWithCString:utf8.c_str()
+
+ NSString* str = [NSString stringWithCString:utf8.c_str()
encoding:NSUTF8StringEncoding];
return str;
}
++(id)stringWithstdwstring:(const std::wstring&)string
+{
+ char* data = (char*)string.data();
+ unsigned size = string.size() * sizeof(wchar_t);
+
+ NSString* str = [[[NSString alloc] initWithBytes:data length:size
+ encoding:NSUTF32LittleEndianStringEncoding] autorelease];
+ return str;
+}
+
-(std::string)tostdstring
{
// Not sure about the encoding to use. Using [self UTF8String] doesn't
// work for characters like é or à.
const char *cstr = [self cStringUsingEncoding:NSISOLatin1StringEncoding];
-
+
if (cstr != NULL)
- {
- std::string str(cstr);
- return str;
- }
+ return std::string(cstr);
else
- {
return "";
- }
-}
-
-+(id)stringWithstdwstring:(std::wstring const &)string
-{
- char* data = (char *)string.data();
- unsigned size = string.size() * sizeof(wchar_t);
-
- NSString *str = [[[NSString alloc] initWithBytes:data length:size
- encoding:NSUTF32LittleEndianStringEncoding] autorelease];
- return str;
}
-(std::wstring)tostdwstring
{
- // According to wikipedia, Mac OS X is Little Endian on x86 and x86-64
+ // According to Wikipedia, Mac OS X is Little Endian on x86 and x86-64
// http://en.wikipedia.org/wiki/Endianness
NSData* asData = [self dataUsingEncoding:NSUTF32LittleEndianStringEncoding];
- return std::wstring((wchar_t *)[asData bytes], [asData length] / sizeof(wchar_t));
+ return std::wstring((wchar_t*)[asData bytes], [asData length] / sizeof(wchar_t));
}
-@end \ No newline at end of file
+@end
diff --git a/examples/cocoa/main.m b/examples/cocoa/main.m
index 324e284..1d0fe08 100644
--- a/examples/cocoa/main.m
+++ b/examples/cocoa/main.m
@@ -1,8 +1,8 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2012 Marco Antognini (antognini.marco@gmail.com),
-// Laurent Gomila (laurent.gom@gmail.com),
+// Copyright (C) 2007-2014 Marco Antognini (antognini.marco@gmail.com),
+// Laurent Gomila (laurent.gom@gmail.com),
//
// 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.
diff --git a/examples/cocoa/resources/Cocoa-Info.plist b/examples/cocoa/resources/Cocoa-Info.plist
index 3ba45e1..ad972db 100644
--- a/examples/cocoa/resources/Cocoa-Info.plist
+++ b/examples/cocoa/resources/Cocoa-Info.plist
@@ -25,10 +25,12 @@
<key>LSMinimumSystemVersion</key>
<string>10.6</string>
<key>NSHumanReadableCopyright</key>
- <string>Copyright © 2007-2012 Marco Antognini and Laurent Gomila. Shared under zlib/libpng License.</string>
+ <string>Copyright © 2007-2014 Marco Antognini and Laurent Gomila. Shared under zlib/libpng License.</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
+ <key>NSHighResolutionCapable</key>
+ <true/>
</dict>
</plist>