Mac Cocoa |
Author |
Message |
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Sat Jul 23, 2022 4:57 pm Post subject: Nibless Cocoa |
|
|
git - Nibless Cocoa
"A combination of several blog posts / other sites to create a functional Nibless
Cocoa App, a Nibless Cocoa OpenGL App and a Nibless Cocoa Metal App in
macOS Sierra 10.12." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Sat Jul 23, 2022 4:57 pm Post subject: |
|
|
Jeff Johnson - Working without a nib, Part 10: Mac Main Menu
"In a nutshell, to create a Mac main menu programmatically, you just need to
create a new NSMenu instance, populate the menu, and set your instance as
the mainMenu of the application (AKA NSApp)
This can all be done using public API allowed in the Mac App Store. You'll notice
that there is no NSApplicationMain in the app. Instead we call the NSApplication
function run(). The main purpose of NSApplicationMain is to load objects from
your app's main nib or storyboard, so it's not needed when your app is nibless."
Working without a nib, Part 8: The nib awakens
Working without a nib, Part 7: The empire strikes back
Working without a nib, Part 6: Working without a xib
Working without a nib, Part 1 |
|
Back to top |
|
|
XNote Kapetan
Joined: 16 Jun 2006 Posts: 532
|
|
Back to top |
|
|
XNote Kapetan
Joined: 16 Jun 2006 Posts: 532
|
Posted: Sat Jul 23, 2022 7:20 pm Post subject: |
|
|
hyperjeff - Nibless Window Example
"No frills code to bring up a Cocoa window without using nib files" |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Mon Jun 19, 2023 10:31 pm Post subject: |
|
|
sarunw - How to create a new Xcode project without Storyboard
"When you create a new project in Xcode, the default boilerplate includes the
Main.storyboard. If you are going with a no storyboard approach and want to
set everything up in code, there are a few steps you need to take." |
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Thu Aug 10, 2023 2:48 pm Post subject: |
|
|
so - How do I create a Cocoa window programmatically?
"A side note, if you want to programatically instantiate the application
without a main nib, in the main.m file / you can instantiate the AppDelegate
as below. Then in your apps Supporting Files / YourApp.plist Main nib base
file / MainWindow.xib delete this entry. Then use Jason Coco's approach to
attach the window in your AppDelegates init method."
Code: | #import "AppDelegate.h":
int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
AppDelegate *appDelegate = [[AppDelegate alloc] init];
[NSApp setDelegate:appDelegate];
[NSApp run];
[pool release];
return 0;
} |
"This code will create your borderless, blue window at the bottom left of the
screen:"
Code: | NSRect frame = NSMakeRect(0, 0, 200, 200);
NSWindow* window = [[[NSWindow alloc] initWithContentRect:frame
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO] autorelease];
[window setBackgroundColor:[NSColor blueColor]];
[window makeKeyAndOrderFront:NSApp]; |
|
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Mon Aug 14, 2023 4:57 pm Post subject: |
|
|
so - How to create a menu programmatically without any interface builder files in MacOS?
Code: | - (void) menuAction: (id)sender {
NSLog(@"%@", sender);
}
- (void) buildMenu {
// **** Menu Bar **** //
NSMenu *menubar = [NSMenu new];
[NSApp setMainMenu:menubar];
// **** App Menu **** //
NSMenuItem *appMenuItem = [NSMenuItem new];
NSMenu *appMenu = [NSMenu new];
[appMenu addItemWithTitle: @"Quit" action:@selector(terminate:) keyEquivalent:@"q"];
[appMenuItem setSubmenu:appMenu];
[menubar addItem:appMenuItem];
// **** File Menu **** //
NSMenuItem *fileMenuItem = [NSMenuItem new];
NSMenu *fileMenu = [[NSMenu alloc] initWithTitle:@"File"];
[fileMenu addItemWithTitle:@"New" action:@selector(menuAction:) keyEquivalent:@""];
[fileMenu addItemWithTitle:@"Open" action:@selector(menuAction:) keyEquivalent:@""];
[fileMenu addItemWithTitle:@"Save" action:@selector(menuAction:) keyEquivalent:@""];
[fileMenuItem setSubmenu: fileMenu];
[menubar addItem: fileMenuItem];
}
|
|
|
Back to top |
|
|
Ike Kapetan
Joined: 17 Jun 2006 Posts: 3136 Location: Europe
|
Posted: Thu Aug 17, 2023 1:51 pm Post subject: |
|
|
git - SDL-mirror/src/video/cocoa/SDL_cocoaevents.m
Code: | /* Create the application menu */
appName = GetApplicationName();
appleMenu = [[NSMenu alloc] initWithTitle:@""];
/* Add menu items */
title = [@"About " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
[appleMenu addItem:[NSMenuItem separatorItem]];
[appleMenu addItemWithTitle:@"Preferences..." action:nil keyEquivalent:@","];
[appleMenu addItem:[NSMenuItem separatorItem]];
serviceMenu = [[NSMenu alloc] initWithTitle:@""];
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Services" action:nil keyEquivalent:@""];
[menuItem setSubmenu:serviceMenu];
[NSApp setServicesMenu:serviceMenu];
[serviceMenu release];
[appleMenu addItem:[NSMenuItem separatorItem]];
title = [@"Hide " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
[menuItem setKeyEquivalentModifierMask:(NSEventModifierFlagOption|NSEventModifierFlagCommand)];
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
[appleMenu addItem:[NSMenuItem separatorItem]];
title = [@"Quit " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; |
|
|
Back to top |
|
|
|