summaryrefslogtreecommitdiff
path: root/ios
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2013-10-27 22:06:28 +0200
committerTor Lillqvist <tml@collabora.com>2013-10-27 22:11:19 +0200
commit876111ad316890c3a4bf9dd837246a8af73517c8 (patch)
tree237e4a8d891f528954d993dc32e06c27ef779183 /ios
parentee1f43710f460e8c865d97e726163cba2847c815 (diff)
Fixup glitches in selection handle dragging and coordinate offsets
It is obvious that I don't fully understand how to handle the view coordinates, the applicationFrame etc. Possibly I am doing something slightly wrong... Anyway, add a hack to make the touch input actually refer to the thing under the finger;) Also fix the handling of the selection end dragging. Change-Id: I27a6a978e7fc28759b70d29ebca75bfd6b5f54a1
Diffstat (limited to 'ios')
-rw-r--r--ios/experimental/LibreOffice/LibreOffice/AppDelegate.m4
-rw-r--r--ios/experimental/LibreOffice/LibreOffice/View.h1
-rw-r--r--ios/experimental/LibreOffice/LibreOffice/View.m30
3 files changed, 26 insertions, 9 deletions
diff --git a/ios/experimental/LibreOffice/LibreOffice/AppDelegate.m b/ios/experimental/LibreOffice/LibreOffice/AppDelegate.m
index a2abfb8caf44..49401651e9f2 100644
--- a/ios/experimental/LibreOffice/LibreOffice/AppDelegate.m
+++ b/ios/experimental/LibreOffice/LibreOffice/AppDelegate.m
@@ -46,12 +46,14 @@ static BOOL keyboardShows;
[self.window makeKeyAndVisible];
CGRect r = [self.window frame];
- r.origin = CGPointMake(0, 0);
self.view = [[View alloc] initWithFrame: r];
vc.view = self.view;
theView = self.view;
+ // This is baaad
+ theView->applicationFrame = applicationFrame;
+
self.view->textView = [[UITextView alloc] initWithFrame: r];
self.view->textView.autocapitalizationType = UITextAutocapitalizationTypeNone;
self.view->textView.alpha = 0;
diff --git a/ios/experimental/LibreOffice/LibreOffice/View.h b/ios/experimental/LibreOffice/LibreOffice/View.h
index aecc606425be..61c816923bc8 100644
--- a/ios/experimental/LibreOffice/LibreOffice/View.h
+++ b/ios/experimental/LibreOffice/LibreOffice/View.h
@@ -15,6 +15,7 @@
{
@public
UITextView* textView;
+ CGRect applicationFrame;
}
- (void)drawRect:(CGRect)rect;
- (void)tapGesture:(UITapGestureRecognizer *)gestureRecognizer;
diff --git a/ios/experimental/LibreOffice/LibreOffice/View.m b/ios/experimental/LibreOffice/LibreOffice/View.m
index e145c362dc61..f4fec1df4e35 100644
--- a/ios/experimental/LibreOffice/LibreOffice/View.m
+++ b/ios/experimental/LibreOffice/LibreOffice/View.m
@@ -51,6 +51,9 @@
- (bool) topLeftResizeHandleIsCloseTo:(CGPoint)position
{
+ if (self.selectionRectangleCount == 0)
+ return false;
+
return ((SQUARE((self.selectionRectangles[0].origin.x - HANDLE_STEM_WIDTH/2) - position.x) +
SQUARE((self.selectionRectangles[0].origin.y - HANDLE_STEM_HEIGHT/2 - HANDLE_BLOB/2) - position.y)) <
SQUARE(DRAG_RADIUS));
@@ -60,6 +63,9 @@
{
const int N = self.selectionRectangleCount;
+ if (N == 0)
+ return false;
+
return ((SQUARE((self.selectionRectangles[N-1].origin.x +
self.selectionRectangles[N-1].size.width + HANDLE_STEM_WIDTH/2) - position.x) +
SQUARE((self.selectionRectangles[N-1].origin.y +
@@ -114,6 +120,7 @@
- (void)drawRect:(CGRect)rect
{
// NSLog(@"View drawRect: %dx%d@(%d,%d)", (int) rect.size.width, (int) rect.size.height, (int) rect.origin.x, (int) rect.origin.y);
+ // NSLog(@" self.frame : %dx%d@(%d,%d)", (int) self.frame.size.width, (int) self.frame.size.height, (int) self.frame.origin.x, (int) self.frame.origin.y);
// NSLog(@"statusBarOrientation: %ld", (long)[[UIApplication sharedApplication] statusBarOrientation]);
CGContextRef context = UIGraphicsGetCurrentContext();
@@ -121,7 +128,13 @@
switch ([[UIApplication sharedApplication] statusBarOrientation]) {
case UIInterfaceOrientationPortrait:
- CGContextTranslateCTM(context, 0, self.frame.size.height);
+ // No idea why I need to do this ugly subtraction of
+ // applicationFrame.origin.y here. The handling of View frame
+ // and applicationFrame has been a bit of a mystery to me.
+ // Anyway, unless a Right Way to do this is figured out,
+ // corresponding hacks are needed for the other orientations,
+ // too, obiously.
+ CGContextTranslateCTM(context, 0, self.frame.size.height - applicationFrame.origin.y);
CGContextScaleCTM(context, 1, -1);
break;
case UIInterfaceOrientationLandscapeLeft:
@@ -179,9 +192,7 @@
previous = CGPointMake(0, 0);
}
- CGPoint delta;
- delta.x = translation.x - previous.x;
- delta.y = translation.y - previous.y;
+ CGPoint delta = CGPointMake(translation.x - previous.x, translation.y - previous.y);
// NSLog(@"location: (%f,%f) , drag: (%f,%f)", location.x, location.y, delta.x, delta.y);
@@ -191,12 +202,15 @@
gestureRecognizer.numberOfTouches == 1) {
if ([self topLeftResizeHandleIsCloseTo:location]) {
draggedHandle = TOPLEFT;
- dragOffset.x = location.x - self.selectionRectangles[0].origin.x;
- dragOffset.y = location.y - self.selectionRectangles[0].origin.y;
+ dragOffset = CGPointMake(location.x - self.selectionRectangles[0].origin.x,
+ location.y - (self.selectionRectangles[0].origin.y +
+ self.selectionRectangles[0].size.height/2));
} else if ([self bottomRightResizeHandleIsCloseTo:location]) {
draggedHandle = BOTTOMRIGHT;
- dragOffset.x = location.x - self.selectionRectangles[N-1].origin.x;
- dragOffset.y = location.y - self.selectionRectangles[N-1].origin.y;
+ dragOffset = CGPointMake(location.x - (self.selectionRectangles[N-1].origin.x +
+ self.selectionRectangles[N-1].size.width),
+ location.y - (self.selectionRectangles[N-1].origin.y +
+ self.selectionRectangles[N-1].size.height/2));
}
}