implement clipboard on iOS
This commit is contained in:
@@ -35,4 +35,6 @@
|
||||
- (void)share_file:(NSString*)file_path;
|
||||
- (void)tick;
|
||||
- (void)render_loop;
|
||||
- (std::string)clipboard_get_string;
|
||||
- (bool)clipboard_set_string:(const std::string&)s;
|
||||
@end
|
||||
|
||||
@@ -44,6 +44,18 @@ NSThread* lock_thread;
|
||||
std::recursive_mutex lock_mutex;
|
||||
|
||||
@implementation GameViewController
|
||||
- (std::string)clipboard_get_string
|
||||
{
|
||||
NSString* ns = [[UIPasteboard generalPasteboard] string];
|
||||
const char* ptr = [ns cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
return std::string(ptr);
|
||||
}
|
||||
- (bool)clipboard_set_string:(const std::string &)s
|
||||
{
|
||||
NSString* ns = [NSString stringWithUTF8String:s.c_str()];
|
||||
[[UIPasteboard generalPasteboard] setString:ns];
|
||||
return true;
|
||||
}
|
||||
- (void)crash
|
||||
{
|
||||
AppDelegate* app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
|
||||
|
||||
@@ -144,6 +144,8 @@ public:
|
||||
struct android_app* and_app;
|
||||
struct engine* and_engine;
|
||||
#endif
|
||||
std::string clipboard_get_text();
|
||||
bool clipboard_set_text(const std::string& s);
|
||||
void pick_image(std::function<void(std::string path)> callback);
|
||||
void pick_file(std::vector<std::string> types, std::function<void(std::string path)> callback);
|
||||
void pick_dir(std::function<void(std::string path)> callback);
|
||||
|
||||
@@ -8,8 +8,30 @@ void android_pick_file(android_app* mApplication, std::function<void(std::string
|
||||
std::string win32_open_file(const char* filter);
|
||||
std::string win32_open_dir();
|
||||
void win32_show_cursor(bool visible);
|
||||
bool win32_clipboard_set_text(const std::string & s);
|
||||
std::string win32_clipboard_get_text();
|
||||
#endif
|
||||
|
||||
|
||||
std::string App::clipboard_get_text()
|
||||
{
|
||||
#if _WIN32
|
||||
return win32_clipboard_get_text();
|
||||
#elif __IOS__
|
||||
return [ios_view clipboard_get_string];
|
||||
#endif
|
||||
}
|
||||
|
||||
bool App::clipboard_set_text(const std::string& s)
|
||||
{
|
||||
#if _WIN32
|
||||
return win32_clipboard_set_text(s);
|
||||
#elif __IOS__
|
||||
return [ios_view clipboard_set_string:s];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void App::crash_test()
|
||||
{
|
||||
#ifdef __IOS__
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include "pch.h"
|
||||
#include "log.h"
|
||||
#include "util.h"
|
||||
#include "app.h"
|
||||
#include "canvas.h"
|
||||
#include "node_dialog_picker.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
Node* NodeColorPicker::clone_instantiate() const
|
||||
{
|
||||
@@ -90,7 +92,7 @@ void NodeColorPicker::init_controls()
|
||||
|
||||
m_btn_paste->on_click = [this](Node*)
|
||||
{
|
||||
std::string s = clipboard_get_text();
|
||||
std::string s = App::I.clipboard_get_text();
|
||||
std::regex r("#([\\dabcdefABCDEF]{6})");
|
||||
std::smatch m;
|
||||
if (std::regex_search(s, m, r))
|
||||
@@ -106,7 +108,7 @@ void NodeColorPicker::init_controls()
|
||||
|
||||
m_btn_copy->on_click = [this](Node*)
|
||||
{
|
||||
clipboard_set_text(m_txt_hex->m_text);
|
||||
App::I.clipboard_set_text(m_txt_hex->m_text);
|
||||
};
|
||||
|
||||
m_wheel->on_value_changed = [this](Node*, glm::vec3 hsv)
|
||||
@@ -164,7 +166,7 @@ void NodeColorPicker::init_controls()
|
||||
void NodeColorPicker::update_hex(glm::vec3 rgb)
|
||||
{
|
||||
char tmp[32];
|
||||
ultoa(convert_rgb_long(rgb), tmp, 16);
|
||||
snprintf(tmp, sizeof(tmp), "%xul", convert_rgb_long(rgb));
|
||||
m_txt_hex->set_text_format("#%s", tmp);
|
||||
}
|
||||
|
||||
|
||||
18
src/util.cpp
18
src/util.cpp
@@ -610,24 +610,6 @@ std::string str_replace(const std::string& string, const std::string& search, co
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string clipboard_get_text()
|
||||
{
|
||||
#if _WIN32
|
||||
extern std::string win32_clipboard_get_text();
|
||||
return win32_clipboard_get_text();
|
||||
#elif _IOS_
|
||||
#endif
|
||||
}
|
||||
|
||||
bool clipboard_set_text(const std::string& s)
|
||||
{
|
||||
#if _WIN32
|
||||
extern bool win32_clipboard_set_text(const std::string & s);
|
||||
return win32_clipboard_set_text(s);
|
||||
#elif _IOS_
|
||||
#endif
|
||||
}
|
||||
|
||||
static const char* gl2str(GLenum err)
|
||||
{
|
||||
switch (err)
|
||||
|
||||
@@ -82,9 +82,6 @@ std::string wstr2str(const std::wstring& wstr);
|
||||
bool str_iequals(const std::string& a, const std::string& b);
|
||||
std::string str_replace(const std::string& string, const std::string& search, const std::string& replace);
|
||||
|
||||
std::string clipboard_get_text();
|
||||
bool clipboard_set_text(const std::string& s);
|
||||
|
||||
size_t curl_data_handler(void *contents, size_t size, size_t nmemb, void *userp);
|
||||
size_t curl_data_write(void *ptr, size_t size, size_t nmemb, FILE *stream);
|
||||
void check_OpenGLError(const char* stmt, const char* fname, int line);
|
||||
|
||||
Reference in New Issue
Block a user