implement window position save and restore in OSX
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "app.h"
|
||||
#include "keymap.h"
|
||||
#include "main.h"
|
||||
#include "settings.h"
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <CoreVideo/CoreVideo.h>
|
||||
@@ -454,11 +455,18 @@
|
||||
App::I->initLog();
|
||||
App::I->create();
|
||||
NSRect r = NSMakeRect(0, 0, App::I->width, App::I->height);
|
||||
if (Settings::has("window-rect"))
|
||||
{
|
||||
glm::ivec4 wr = Settings::value<Serializer::IVec4>("window-rect");
|
||||
r.origin = CGPointMake(wr.x, wr.y);
|
||||
r.size = CGSizeMake(wr.z, wr.w);
|
||||
}
|
||||
|
||||
view = [[View alloc] initWithFrame:r];
|
||||
controller = [[Controller alloc] initWithWindow:window];
|
||||
App::I->osx_view = view;
|
||||
|
||||
App::I->zoom = Settings::value_or<Serializer::Float>("ui-scale", (float)view.layer.contentsScale);
|
||||
|
||||
auto style = NSTitledWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask|NSClosableWindowMask;
|
||||
window = [[Window alloc] initWithContentRect:r styleMask:style backing:NSBackingStoreBuffered defer:NO];
|
||||
[window setDelegate:controller];
|
||||
@@ -486,6 +494,11 @@
|
||||
LOG("app launched");
|
||||
App::I->ui_thread_start();
|
||||
}
|
||||
- (void)save_ui_state
|
||||
{
|
||||
Settings::set("window-rect", Serializer::IVec4({window.frame.origin.x,
|
||||
window.frame.origin.y, window.frame.size.width, window.frame.size.height}));
|
||||
}
|
||||
- (void)init_dirs
|
||||
{
|
||||
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSPicturesDirectory, NSUserDomainMask, YES);
|
||||
|
||||
@@ -39,4 +39,5 @@
|
||||
View* view;
|
||||
}
|
||||
- (void)init_dirs;
|
||||
- (void)save_ui_state;
|
||||
@end
|
||||
|
||||
@@ -315,7 +315,7 @@
|
||||
AD06989620CC6C350010825F /* ZipArchive.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ZipArchive.framework; path = libs/ZipArchive/iOS/ZipArchive.framework; sourceTree = "<group>"; };
|
||||
AD06989920CC6C4C0010825F /* ZipArchive.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ZipArchive.framework; path = libs/ZipArchive/Mac/ZipArchive.framework; sourceTree = "<group>"; };
|
||||
AD0E11921ECA20F200CDA6BB /* app_events.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp.preprocessed; fileEncoding = 4; path = app_events.cpp; sourceTree = "<group>"; };
|
||||
AD0E11931ECA20F200CDA6BB /* app_layout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = app_layout.cpp; sourceTree = "<group>"; };
|
||||
AD0E11931ECA20F200CDA6BB /* app_layout.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = app_layout.cpp; sourceTree = "<group>"; };
|
||||
AD0E11941ECA20F200CDA6BB /* app_shaders.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = app_shaders.cpp; sourceTree = "<group>"; };
|
||||
AD0E11951ECA20F200CDA6BB /* node_scroll.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = node_scroll.cpp; sourceTree = "<group>"; };
|
||||
AD0E11961ECA20F200CDA6BB /* node_scroll.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = node_scroll.h; sourceTree = "<group>"; };
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#import "GameViewController.h"
|
||||
#import <OpenGLES/ES3/glext.h>
|
||||
#include "app.h"
|
||||
#include "settings.h"
|
||||
#import "objc_utils.h"
|
||||
|
||||
std::mutex render_mutex;
|
||||
@@ -433,7 +434,8 @@ std::set<UITouch*> ignored_touch;
|
||||
|
||||
App::I->width = view.frame.size.width * view.contentScaleFactor;
|
||||
App::I->height = view.frame.size.height * view.contentScaleFactor;
|
||||
|
||||
App::I->zoom = Settings::value_or<Serializer::Float>("ui-scale", (float)view.contentScaleFactor);
|
||||
|
||||
App::I->render_thread_start();
|
||||
App::I->ui_thread_start();
|
||||
}
|
||||
|
||||
@@ -1482,6 +1482,8 @@ void App::ui_save()
|
||||
#if _WIN32
|
||||
extern void win32_save_window_state();
|
||||
win32_save_window_state();
|
||||
#elif __OSX__
|
||||
[osx_app save_ui_state];
|
||||
#endif
|
||||
|
||||
Settings::save();
|
||||
|
||||
Reference in New Issue
Block a user