add support for Apple Pencil and build for iOS

This commit is contained in:
2017-07-28 20:35:59 +01:00
parent e32329ea98
commit 0907429a60
15 changed files with 236 additions and 35 deletions

View File

@@ -4,6 +4,10 @@
#include "node_icon.h"
#include "node_dialog_open.h"
#ifdef __APPLE__
#include <Foundation/Foundation.h>
#endif
using namespace ui;
App App::I; // singleton
@@ -84,7 +88,13 @@ void App::init()
LOG("Screen Resolution: %dx%d", (int)width, (int)height);
zoom = ceilf(width / 1000.f);
zoom = ceilf(width / 2000.f);
#ifdef __IOS__
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* docpath = [paths objectAtIndex:0];
data_path = [docpath cStringUsingEncoding:NSASCIIStringEncoding];
#endif
glDisable(GL_DEPTH_TEST);
#if defined(_WIN32) || defined(__OSX__)

View File

@@ -15,6 +15,11 @@
#include "node_panel_stroke.h"
#include "node_canvas.h"
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import "GameViewController.h"
#endif
class App
{
public:
@@ -51,6 +56,12 @@ public:
#else
float zoom = 1.0;
#endif // __ANDROID__
#if defined(__IOS__) && defined(__OBJC__)
GameViewController* ios_view;
#endif
void showKeyboard();
void hideKeyboard();
void initLog();
void init();
void initShaders();

View File

@@ -11,6 +11,20 @@ void App::resize(float w, float h)
main->update(w , h, zoom);
}
void App::showKeyboard()
{
#ifdef __IOS__
[ios_view becomeFirstResponder];
#endif
}
void App::hideKeyboard()
{
#ifdef __IOS__
[ios_view resignFirstResponder];
#endif
}
bool App::mouse_down(int button, float x, float y, float pressure)
{
MouseEvent e;

View File

@@ -16,7 +16,7 @@ bool Font::load(const char* ttf, int font_size)
LOG("Font::load loaded");
auto bitmap = std::make_unique<uint8_t[]>(w*h);
chars.resize(num_chars);
stbtt_BakeFontBitmap(file.m_data, 0, (float)font_size, bitmap.get(), w, h, start_char, num_chars, chars.data());
stbtt_BakeFontBitmap(file.m_data, 0, (float)font_size*2, bitmap.get(), w, h, start_char, num_chars, chars.data());
font_tex.create(w, h, GL_R8, GL_RED, bitmap.get());
file.close();
return true;
@@ -75,18 +75,18 @@ void TextMesh::update(kFont id, const char* text)
stbtt_aligned_quad q;
stbtt_GetBakedQuad((stbtt_bakedchar*)f.chars.data(), f.w, f.h, c, &x, &y, &q, true);
auto n = (int)v.size();
v.emplace_back(q.x0, q.y1, q.s0, q.t1);
v.emplace_back(q.x0, q.y0, q.s0, q.t0);
v.emplace_back(q.x1, q.y0, q.s1, q.t0);
v.emplace_back(q.x1, q.y1, q.s1, q.t1);
v.emplace_back(q.x0/2.f, q.y1/2.f, q.s0, q.t1);
v.emplace_back(q.x0/2.f, q.y0/2.f, q.s0, q.t0);
v.emplace_back(q.x1/2.f, q.y0/2.f, q.s1, q.t0);
v.emplace_back(q.x1/2.f, q.y1/2.f, q.s1, q.t1);
idx.push_back(n+0);
idx.push_back(n+1);
idx.push_back(n+2);
idx.push_back(n+0);
idx.push_back(n+2);
idx.push_back(n+3);
bbmin = glm::min(bbmin, { q.x0, q.y0 });
bbmax = glm::max(bbmax, { q.x1, q.y1 });
bbmin = glm::min(bbmin, { q.x0/2.f, q.y0/2.f });
bbmax = glm::max(bbmax, { q.x1/2.f, q.y1/2.f });
}
for (int i = 0; i < len*4; i++)
{

View File

@@ -11,7 +11,7 @@ void NodeCanvas::init()
{
m_mouse_ignore = false;
m_canvas = std::make_unique<ui::Canvas>();
m_canvas->create(2048, 2048);
m_canvas->create(512, 512);
m_sampler.create(GL_NEAREST);
m_face_plane.create<1>(2, 2);
m_line.create();
@@ -25,7 +25,7 @@ void NodeCanvas::init()
void NodeCanvas::restore_context()
{
Node::restore_context();
m_canvas->create(2048, 2048);
m_canvas->create(512, 512);
m_sampler.create(GL_NEAREST);
m_face_plane.create<1>(2, 2);
m_canvas->snapshot_restore();

View File

@@ -3,6 +3,10 @@
#include "node_panel_brush.h"
#include "asset.h"
#ifdef __APPLE__
#include <Foundation/Foundation.h>
#endif
Node* NodeButtonBrush::clone_instantiate() const
{
return new NodeButtonBrush();
@@ -99,9 +103,13 @@ std::vector<std::string> NodePanelBrush::FindAllBrushes(std::string folder)
}
AAssetDir_close(dir);
#else
NSString* bundle_path = [[NSBundle mainBundle] resourcePath];
std::string base = [bundle_path cStringUsingEncoding:1];
std::string abs_path = base + "/" + folder;
DIR *dp;
struct dirent *ep;
dp = opendir(folder.c_str());
dp = opendir(abs_path.c_str());
if (dp != NULL)
{

View File

@@ -1,4 +1,5 @@
#include "pch.h"
#include "app.h"
#include "log.h"
#include "node_text_input.h"
@@ -41,6 +42,7 @@ kEventResult NodeTextInput::handle_event(Event* e)
switch (e->m_type)
{
case kEventType::MouseDownL:
App::I.showKeyboard();
break;
case kEventType::MouseUpL:
key_capture();

View File

@@ -14,7 +14,12 @@
#include <OpenGLES/ES3/glext.h>
#define SHADER_VERSION "#version 300 es\n"
#elif TARGET_OS_IPHONE
// define something for iphone
#define TARGET_OS_IOS 1
#define __IOS__ 1
#include <CoreFoundation/CoreFoundation.h>
#include <OpenGLES/ES3/gl.h>
#include <OpenGLES/ES3/glext.h>
#define SHADER_VERSION "#version 300 es\n"
#else
#define TARGET_OS_OSX 1
#define __OSX__ 1