Fix: Just a touch of modernisation

- Fixing OSX Alerts to not use deprecated API
- Fixing missing release for refcounted objects
- Use a more conventional filename for the app delegate
- Fixing some variable types to avoid conversions
This commit is contained in:
mathieu _alkama_ m 2015-12-13 22:28:46 +01:00
parent 95db639603
commit 381abf24ff
11 changed files with 149 additions and 131 deletions

View File

@ -582,7 +582,8 @@ static void toggleMute(void* userData)
else
{
struct track_key defKey;
int i, keysSize = sizeof(struct track_key) * data->syncTrack->num_keys;
int i;
size_t keysSize = sizeof(struct track_key) * data->syncTrack->num_keys;
float currentValue = (float)sync_get_val(data->syncTrack, data->row);
data->track->disabled = true;

View File

@ -182,7 +182,7 @@ static inline int getActiveTrack()
static inline int getTrackCount()
{
return s_editorData.trackData.num_syncTracks;
return (int)s_editorData.trackData.num_syncTracks;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -1631,7 +1631,7 @@ static void onPrevNextKey(bool prevKey, enum Selection selection)
if (idx < 0)
row = track->keys[0].row;
else if (idx > (int)track->num_keys - 2)
else if (idx > track->num_keys - 2)
row = track->keys[track->num_keys - 1].row;
else
row = track->keys[idx + 1].row;

View File

@ -493,7 +493,7 @@ void RemoteConnection_sendKeyFrames(const char* name, struct sync_track* track)
if (!RemoteConnection_connected() || track_id == -1)
return;
for (i = 0; i < (int)track->num_keys; ++i)
for (i = 0; i < track->num_keys; ++i)
sendSetKeyCommandIndex((uint32_t)track_id, &track->keys[i]);
}

View File

@ -338,7 +338,7 @@ static void saveTrackData(mxml_node_t* track, struct track_key* keys, int count)
for (i = 0; i < count; ++i)
{
mxml_node_t* key = mxmlNewElement(track, "key");
setElementInt(key, "row", "%d", (int)keys[i].row);
setElementInt(key, "row", "%d", keys[i].row);
setElementFloat(key, "value", keys[i].value);
setElementInt(key, "interpolation", "%d", (int)keys[i].type);
}
@ -428,7 +428,7 @@ int LoadSave_saveRocketXML(const text_t* path, TrackData* trackData)
}
else
{
saveTrackData(track, t->keys, (int)t->num_keys);
saveTrackData(track, t->keys, t->num_keys);
}
}

View File

@ -10,9 +10,9 @@ int Dialog_open(char* dest)
NSOpenPanel* open = [NSOpenPanel openPanel];
[open setAllowsMultipleSelection:NO];
int result = [open runModal];
NSInteger result = [open runModal];
if (result != NSOKButton)
if (result != NSModalResponseOK)
return false;
// Grab the first file
@ -35,9 +35,9 @@ int Dialog_save(char* dest)
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSSavePanel* open = [NSSavePanel savePanel];
int result = [open runModal];
NSInteger result = [open runModal];
if (result != NSOKButton)
if (result != NSModalResponseOK)
return false;
// Grab the first file
@ -149,7 +149,12 @@ void Dialog_showError(const text_t* text)
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString* message = [[[NSString alloc] initWithUTF8String:text] autorelease];// convert
NSRunAlertPanel(@"Error", message, @"Ok", @"", @"");
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:message];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert runModal];
[alert release];
[pool drain];
}

View File

@ -1,4 +1,4 @@
#import "delegate.h"
#import "RocketAppDelegate.h"
#include "../Editor.h"
#include "../RemoteConnection.h"
#include "rlog.h"
@ -15,23 +15,33 @@ void Window_buildMenu();
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
NSUInteger exitcode = NSTerminateNow;
if (!Editor_needsSave())
return NSTerminateNow;
return exitcode;
int ret = NSRunAlertPanel(@"Save before exit?", @"Do you want save the work?", @"Yes", @"Cancel", @"No");
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"Yes"];
[alert addButtonWithTitle:@"No"];
[alert addButtonWithTitle:@"Cancel"];
[alert setMessageText:@"Save before exit?"];
[alert setInformativeText:@"Do you want save the work?"];
[alert setAlertStyle:NSWarningAlertStyle];
if (ret == NSAlertDefaultReturn)
NSModalResponse ret = [alert runModal];
if (ret == NSAlertFirstButtonReturn)
{
if (!Editor_saveBeforeExit())
return NSTerminateCancel;
return NSTerminateNow;
exitcode = NSTerminateCancel;
}
if (ret == NSAlertAlternateReturn)
return NSTerminateCancel;
if (ret == NSAlertThirdButtonReturn)
exitcode = NSTerminateCancel;
return NSTerminateNow;
[alert release];
return exitcode;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -87,6 +97,7 @@ void Window_buildMenu();
Editor_destroy();
RemoteConnection_close();
[stringArray release];
}
@end

View File

@ -7,8 +7,8 @@
#include <CoreFoundation/CoreFoundation.h>
#include <Carbon/Carbon.h>
NSOpenGLContext* g_context = 0;
NSWindow* g_window = 0;
NSOpenGLContext* g_context = nil;
NSWindow* g_window = nil;
void Window_setTitle(const char* title);
@ -52,13 +52,14 @@ void Window_setTitle(const char* title);
if (self == nil)
return nil;
NSOpenGLPixelFormatAttribute attributes[4];
attributes[0] = NSOpenGLPFADoubleBuffer;
attributes[1] = 0;
NSOpenGLPixelFormatAttribute attributes[] = {
NSOpenGLPFADoubleBuffer,
0
};
NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
oglContext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:nil];
[format release];
[oglContext makeCurrentContext];
g_context = oglContext;
@ -185,6 +186,7 @@ static int getModifierFlags(int flags)
owner:self
userInfo:nil];
[self addTrackingArea:trackingArea];
[trackingArea release];
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -296,7 +298,7 @@ CFStringRef createStringForKey(CGKeyCode keyCode)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static int s_characterToKeyCode[] =
static CGKeyCode s_characterToKeyCode[] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0x27, // '''
@ -383,11 +385,11 @@ NSString* convertKeyCodeToString(int key)
case EMGUI_KEY_BACKSPACE : return [NSString stringWithFormat:@"%C",(uint16_t)0x232b];
case EMGUI_KEY_TAB : return [NSString stringWithFormat:@"%C",(uint16_t)0x21e4];
case EMGUI_KEY_PAGE_UP : return [NSString stringWithFormat:@"%C",(uint16_t)0x21de];
case EMGUI_KEY_PAGE_DOWN : return [NSString stringWithFormat:@"%C",(uint16_t)0x21df];
case EMGUI_KEY_PAGE_DOWN : return [NSString stringWithFormat:@"%C",(uint16_t)0x21df];
}
}
return 0;
return nil;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -407,8 +409,8 @@ void buildSubMenu(NSMenu* menu, MenuDescriptor menuDesc[])
}
else if (desc->id == EDITOR_MENU_SUB_MENU)
{
MyMenuItem* newItem = [[MyMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:name action:NULL keyEquivalent:@""];
NSMenu* newMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:name];
MyMenuItem* newItem = [[MyMenuItem alloc] initWithTitle:name action:NULL keyEquivalent:@""];
NSMenu* newMenu = [[NSMenu alloc] initWithTitle:name];
[newItem setSubmenu:newMenu];
[newMenu release];
[menu addItem:newItem];
@ -416,7 +418,7 @@ void buildSubMenu(NSMenu* menu, MenuDescriptor menuDesc[])
}
else
{
int mask = 0;
NSUInteger mask = 0;
MyMenuItem* newItem = [[MyMenuItem alloc] initWithTitle:name action:@selector(onMenuPress:) keyEquivalent:@""];
[newItem setTag:desc->id];

View File

@ -1,7 +1,6 @@
#import <OpenGL/OpenGL.h>
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
int main(int argc, const char * argv[])
{
return NSApplicationMain(argc, (const char **) argv);
return NSApplicationMain(argc, argv);
}