stencil in brush preview

This commit is contained in:
2017-10-22 19:58:20 +01:00
parent 856628162a
commit 2a92beca7b
6 changed files with 49 additions and 20 deletions

View File

@@ -23,18 +23,25 @@
//std::map<
int t_count = 0;
glm::vec2 t_pos;
int lock_count = 0;
NSThread* lock_thread;
@implementation GameViewController
- (void)async_lock
{
[gl_lock lock];
if (lock_thread != [NSThread currentThread] || lock_count == 0)
[gl_lock lock];
lock_thread = [NSThread currentThread];
lock_count++;
[EAGLContext setCurrentContext:self.context];
GLKView* view = (GLKView*)self.view;
//[view bindDrawable];
}
- (void)async_unlock
{
[gl_lock unlock];
lock_count--;
if (lock_count == 0)
[gl_lock unlock];
}
- (void)async_swap
{
@@ -100,11 +107,11 @@ glm::vec2 t_pos;
frame.size.height -= kbSize.height;
view.frame = frame;
[gl_lock lock];
[self async_lock];
App::I.resize(frame.size.width * view.contentScaleFactor,
frame.size.height * view.contentScaleFactor);
App::I.animate = false;
[gl_lock unlock];
[self async_unlock];
}
// Called when the UIKeyboardWillHideNotification is sent
@@ -112,21 +119,21 @@ glm::vec2 t_pos;
{
CGRect frame = [[UIScreen mainScreen] bounds];
self.view.frame = frame;
[gl_lock lock];
[self async_lock];
App::I.resize(frame.size.width * self.view.contentScaleFactor,
frame.size.height * self.view.contentScaleFactor);
App::I.animate = true;
[gl_lock unlock];
[self async_unlock];
}
- (void)reset_touch
{
[gl_lock lock];
[self async_lock];
if (t_count == 2)
App::I.gesture_end();
else
App::I.mouse_cancel(0);
[gl_lock unlock];
[self async_unlock];
t_count = 0;
}
@@ -138,9 +145,9 @@ glm::vec2 t_pos;
float scale = self.view.contentScaleFactor;
kEventSource source = touch.type == UITouchType::UITouchTypeStylus ? kEventSource::Stylus : kEventSource::Touch;
[gl_lock lock];
[self async_lock];
App::I.mouse_down(0, touchLocation.x * scale, touchLocation.y * scale, touch.force, source);
[gl_lock unlock];
[self async_unlock];
t_count = 1;
t_pos = {touchLocation.x * scale, touchLocation.y * scale};
}
@@ -163,7 +170,7 @@ glm::vec2 t_pos;
p1 = glm::vec2(tl1.x * scale, tl1.y * scale);
}
[gl_lock lock];
[self async_lock];
if (n == 2)
{
if (t_count == 1)
@@ -192,7 +199,7 @@ glm::vec2 t_pos;
App::I.mouse_move(touchLocation.x * scale, touchLocation.y * scale, force, source);
}
}
[gl_lock unlock];
[self async_unlock];
t_pos = {tl0.x * scale, tl0.y * scale};
}
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
@@ -203,12 +210,12 @@ glm::vec2 t_pos;
kEventSource source = touch.type == UITouchType::UITouchTypeStylus ? kEventSource::Stylus : kEventSource::Touch;
[gl_lock lock];
[self async_lock];
if (t_count == 2)
App::I.gesture_end();
else
App::I.mouse_up(0, touchLocation.x * scale, touchLocation.y * scale, source);
[gl_lock unlock];
[self async_unlock];
t_count = 0;
t_pos = {touchLocation.x * scale, touchLocation.y * scale};
@@ -216,10 +223,10 @@ glm::vec2 t_pos;
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[gl_lock lock];
[self async_lock];
App::I.resize(size.width * self.view.contentScaleFactor,
size.height * self.view.contentScaleFactor);
[gl_lock unlock];
[self async_unlock];
}
- (void)viewDidAppear:(BOOL)animated