mirror of
https://github.com/obsqrbtz/clrsync.git
synced 2026-04-08 20:19:04 +03:00
chore: got build working on mac (kind of)
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
namespace clrsync::core
|
||||
{
|
||||
|
||||
const std::string GIT_SEMVER = "0.1.5+git.gd4ff415";
|
||||
const std::string GIT_SEMVER = "0.1.6+git.g57c3c55";
|
||||
|
||||
const std::string version_string();
|
||||
} // namespace clrsync::core
|
||||
|
||||
@@ -15,6 +15,9 @@ set(GUI_SOURCES
|
||||
file_browser.cpp
|
||||
${CMAKE_SOURCE_DIR}/lib/color_text_edit/TextEditor.cpp
|
||||
)
|
||||
if(APPLE)
|
||||
list(APPEND GUI_SOURCES file_browser_macos.mm)
|
||||
endif()
|
||||
|
||||
add_executable(clrsync_gui ${GUI_SOURCES})
|
||||
|
||||
|
||||
@@ -138,85 +138,7 @@ std::string select_folder_dialog(const std::string& title,
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
namespace file_dialogs {
|
||||
|
||||
std::string open_file_dialog(const std::string& title,
|
||||
const std::string& initial_path,
|
||||
const std::vector<std::string>& filters) {
|
||||
@autoreleasepool {
|
||||
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
||||
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
|
||||
[panel setCanChooseFiles:YES];
|
||||
[panel setCanChooseDirectories:NO];
|
||||
[panel setAllowsMultipleSelection:NO];
|
||||
|
||||
if (!initial_path.empty()) {
|
||||
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:initial_path.c_str()]];
|
||||
[panel setDirectoryURL:url];
|
||||
}
|
||||
|
||||
if ([panel runModal] == NSModalResponseOK) {
|
||||
NSURL* url = [[panel URLs] objectAtIndex:0];
|
||||
return std::string([[url path] UTF8String]);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string save_file_dialog(const std::string& title,
|
||||
const std::string& initial_path,
|
||||
const std::vector<std::string>& filters) {
|
||||
@autoreleasepool {
|
||||
NSSavePanel* panel = [NSSavePanel savePanel];
|
||||
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
|
||||
|
||||
if (!initial_path.empty()) {
|
||||
std::filesystem::path p(initial_path);
|
||||
if (std::filesystem::exists(p.parent_path())) {
|
||||
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:p.parent_path().c_str()]];
|
||||
[panel setDirectoryURL:url];
|
||||
[panel setNameFieldStringValue:[NSString stringWithUTF8String:p.filename().c_str()]];
|
||||
}
|
||||
}
|
||||
|
||||
if ([panel runModal] == NSModalResponseOK) {
|
||||
NSURL* url = [panel URL];
|
||||
return std::string([[url path] UTF8String]);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string select_folder_dialog(const std::string& title,
|
||||
const std::string& initial_path) {
|
||||
@autoreleasepool {
|
||||
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
||||
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
|
||||
[panel setCanChooseFiles:NO];
|
||||
[panel setCanChooseDirectories:YES];
|
||||
[panel setAllowsMultipleSelection:NO];
|
||||
|
||||
if (!initial_path.empty()) {
|
||||
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:initial_path.c_str()]];
|
||||
[panel setDirectoryURL:url];
|
||||
}
|
||||
|
||||
if ([panel runModal] == NSModalResponseOK) {
|
||||
NSURL* url = [[panel URLs] objectAtIndex:0];
|
||||
return std::string([[url path] UTF8String]);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
#elif !defined(__APPLE__)
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
@@ -338,6 +260,4 @@ std::string select_folder_dialog(const std::string& title,
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
80
src/gui/file_browser_macos.mm
Normal file
80
src/gui/file_browser_macos.mm
Normal file
@@ -0,0 +1,80 @@
|
||||
#include "file_browser.hpp"
|
||||
#include <filesystem>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
namespace file_dialogs {
|
||||
|
||||
std::string open_file_dialog(const std::string& title,
|
||||
const std::string& initial_path,
|
||||
const std::vector<std::string>& filters) {
|
||||
@autoreleasepool {
|
||||
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
||||
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
|
||||
[panel setCanChooseFiles:YES];
|
||||
[panel setCanChooseDirectories:NO];
|
||||
[panel setAllowsMultipleSelection:NO];
|
||||
|
||||
if (!initial_path.empty()) {
|
||||
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:initial_path.c_str()]];
|
||||
[panel setDirectoryURL:url];
|
||||
}
|
||||
|
||||
if ([panel runModal] == NSModalResponseOK) {
|
||||
NSURL* url = [[panel URLs] objectAtIndex:0];
|
||||
return std::string([[url path] UTF8String]);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string save_file_dialog(const std::string& title,
|
||||
const std::string& initial_path,
|
||||
const std::vector<std::string>& filters) {
|
||||
@autoreleasepool {
|
||||
NSSavePanel* panel = [NSSavePanel savePanel];
|
||||
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
|
||||
|
||||
if (!initial_path.empty()) {
|
||||
std::filesystem::path p(initial_path);
|
||||
if (std::filesystem::exists(p.parent_path())) {
|
||||
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:p.parent_path().c_str()]];
|
||||
[panel setDirectoryURL:url];
|
||||
[panel setNameFieldStringValue:[NSString stringWithUTF8String:p.filename().c_str()]];
|
||||
}
|
||||
}
|
||||
|
||||
if ([panel runModal] == NSModalResponseOK) {
|
||||
NSURL* url = [panel URL];
|
||||
return std::string([[url path] UTF8String]);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string select_folder_dialog(const std::string& title,
|
||||
const std::string& initial_path) {
|
||||
@autoreleasepool {
|
||||
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
||||
[panel setTitle:[NSString stringWithUTF8String:title.c_str()]];
|
||||
[panel setCanChooseFiles:NO];
|
||||
[panel setCanChooseDirectories:YES];
|
||||
[panel setAllowsMultipleSelection:NO];
|
||||
|
||||
if (!initial_path.empty()) {
|
||||
NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:initial_path.c_str()]];
|
||||
[panel setDirectoryURL:url];
|
||||
}
|
||||
|
||||
if ([panel runModal] == NSModalResponseOK) {
|
||||
NSURL* url = [[panel URLs] objectAtIndex:0];
|
||||
return std::string([[url path] UTF8String]);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -123,25 +123,27 @@ std::vector<unsigned char> font_loader::load_font_macos(const char* font_name)
|
||||
if (!desc)
|
||||
return out;
|
||||
|
||||
CTFontRef font = CTFontCreateWithFontDescriptor(desc, 0, nullptr);
|
||||
CFURLRef url = (CFURLRef)CTFontDescriptorCopyAttribute(desc, kCTFontURLAttribute);
|
||||
CFRelease(desc);
|
||||
|
||||
if (!font)
|
||||
if (!url)
|
||||
return out;
|
||||
|
||||
CFDataRef data = CTFontCopyTable(font, kCTFontTableCFF, 0);
|
||||
if (!data)
|
||||
data = CTFontCopyTable(font, kCTFontTableHead, 0);
|
||||
CFDataRef data = nullptr;
|
||||
Boolean success = CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, url, &data, nullptr, nullptr, nullptr);
|
||||
CFRelease(url);
|
||||
|
||||
if (data)
|
||||
if (success && data)
|
||||
{
|
||||
CFIndex size = CFDataGetLength(data);
|
||||
out.resize(size);
|
||||
CFDataGetBytes(data, CFRangeMake(0, size), out.data());
|
||||
if (size > 100)
|
||||
{
|
||||
out.resize(size);
|
||||
CFDataGetBytes(data, CFRangeMake(0, size), out.data());
|
||||
}
|
||||
CFRelease(data);
|
||||
}
|
||||
|
||||
CFRelease(font);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,11 @@ GLFWwindow * init_glfw()
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
#ifdef __APPLE__
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
||||
#else
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
#endif
|
||||
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
|
||||
|
||||
GLFWwindow* w = glfwCreateWindow(1280, 720, "clrsync", nullptr, nullptr);
|
||||
@@ -49,7 +53,11 @@ void init_imgui(GLFWwindow* window, const std::string& ini_path)
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||
ImGui_ImplOpenGL3_Init("#version 130");
|
||||
#ifdef __APPLE__
|
||||
ImGui_ImplOpenGL3_Init("#version 150");
|
||||
#else
|
||||
ImGui_ImplOpenGL3_Init("#version 120");
|
||||
#endif
|
||||
}
|
||||
|
||||
void begin_frame()
|
||||
|
||||
Reference in New Issue
Block a user