[Libreoffice-commits] core.git: 3 commits - ios/experimental

Tor Lillqvist tml at collabora.com
Sun Oct 27 13:11:58 PDT 2013


 ios/experimental/LibreOffice/LibreOffice/AppDelegate.m |    4 
 ios/experimental/LibreOffice/LibreOffice/View.h        |    1 
 ios/experimental/LibreOffice/LibreOffice/View.m        |   76 +++++++++++------
 3 files changed, 54 insertions(+), 27 deletions(-)

New commits:
commit 876111ad316890c3a4bf9dd837246a8af73517c8
Author: Tor Lillqvist <tml at collabora.com>
Date:   Sun Oct 27 22:06:28 2013 +0200

    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

diff --git a/ios/experimental/LibreOffice/LibreOffice/AppDelegate.m b/ios/experimental/LibreOffice/LibreOffice/AppDelegate.m
index a2abfb8..4940165 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 aecc606..61c8169 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 e145c36..f4fec1d 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));
         }
     }
 
commit ee1f43710f460e8c865d97e726163cba2847c815
Author: Tor Lillqvist <tml at collabora.com>
Date:   Sun Oct 27 20:29:09 2013 +0200

    Bin some unnecessary NSLogging
    
    Change-Id: Id4baff53735586345dd6624f3c8b996f1816149a

diff --git a/ios/experimental/LibreOffice/LibreOffice/View.m b/ios/experimental/LibreOffice/LibreOffice/View.m
index cd38ab5..e145c36 100644
--- a/ios/experimental/LibreOffice/LibreOffice/View.m
+++ b/ios/experimental/LibreOffice/LibreOffice/View.m
@@ -190,12 +190,10 @@
     if (gestureRecognizer.state == UIGestureRecognizerStateBegan &&
         gestureRecognizer.numberOfTouches == 1) {
         if ([self topLeftResizeHandleIsCloseTo:location]) {
-            NSLog(@"===> dragging TOPLEFT handle");
             draggedHandle = TOPLEFT;
             dragOffset.x = location.x - self.selectionRectangles[0].origin.x;
             dragOffset.y = location.y - self.selectionRectangles[0].origin.y;
         } else if ([self bottomRightResizeHandleIsCloseTo:location]) {
-            NSLog(@"===> dragging BOTTOMRIGHT handle");
             draggedHandle = BOTTOMRIGHT;
             dragOffset.x = location.x - self.selectionRectangles[N-1].origin.x;
             dragOffset.y = location.y - self.selectionRectangles[N-1].origin.y;
commit 37056560a387360866486396e0adcb80b26edea4
Author: Tor Lillqvist <tml at collabora.com>
Date:   Sun Oct 27 20:26:08 2013 +0200

    Tweak how the resize handles look and make it easier to grab them
    
    Note that this *is* still just an experimental app, not intended to be
    in any way carefully designed for end-user use. I tweaked the look and
    feel a bit just for fun.
    
    Change-Id: I98339d32a8c3ac332fc42b206ab185a61abc4cc6

diff --git a/ios/experimental/LibreOffice/LibreOffice/View.m b/ios/experimental/LibreOffice/LibreOffice/View.m
index 3a9b35b..cd38ab5 100644
--- a/ios/experimental/LibreOffice/LibreOffice/View.m
+++ b/ios/experimental/LibreOffice/LibreOffice/View.m
@@ -16,9 +16,12 @@
 @property int selectionRectangleCount;
 @end
 
-#define HANDLE_BLOB 40
-#define HANDLE_STEM_WIDTH 6
-#define HANDLE_STEM_HEIGHT 40
+#define HANDLE_BLOB 20
+#define DRAG_RADIUS (HANDLE_BLOB + 20)
+#define HANDLE_STEM_WIDTH 4
+#define HANDLE_STEM_HEIGHT 10
+
+#define SQUARE(n) ((n)*(n))
 
 @implementation View
 
@@ -46,6 +49,24 @@
                       HANDLE_BLOB, HANDLE_BLOB);
 }
 
+- (bool) topLeftResizeHandleIsCloseTo:(CGPoint)position
+{
+    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));
+}
+
+- (bool) bottomRightResizeHandleIsCloseTo:(CGPoint)position
+{
+    const int N = self.selectionRectangleCount;
+
+    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 +
+                     self.selectionRectangles[N-1].size.height + HANDLE_STEM_HEIGHT/2 + HANDLE_BLOB/2) - position.y)) <
+            SQUARE(DRAG_RADIUS));
+}
+
 - (void) requestSelectionRedisplay
 {
     if (self.selectionRectangleCount == 0)
@@ -70,19 +91,8 @@
 
     CGContextSetFillColorWithColor(context, [[UIColor colorWithRed:0 green:0 blue:1 alpha:0.5] CGColor]);
 
-#if 0
-    for (int i = 0; i < N; i++) {
-        NSLog(@"UIRectFill: %fx%f@(%f,%f)",
-              self.selectionRectangles[i].size.width, self.selectionRectangles[i].size.height,
-              self.selectionRectangles[i].origin.x, self.selectionRectangles[i].origin.y);
-        UIRectFillUsingBlendMode(CGRectMake(self.selectionRectangles[i].origin.x, self.selectionRectangles[i].origin.y,
-                                            self.selectionRectangles[i].size.width, self.selectionRectangles[i].size.height),
-                                 kCGBlendModeNormal);
-    }
-#else
     CGContextSetBlendMode(context, kCGBlendModeNormal);
     CGContextFillRects(context, self.selectionRectangles, self.selectionRectangleCount);
-#endif
 
     CGContextFillRect(context,
                       CGRectMake(self.selectionRectangles[0].origin.x - HANDLE_STEM_WIDTH,
@@ -95,6 +105,8 @@
                                  self.selectionRectangles[N-1].origin.y,
                                  HANDLE_STEM_WIDTH, self.selectionRectangles[N-1].size.height + HANDLE_STEM_HEIGHT));
 
+    CGContextSetFillColorWithColor(context, [[UIColor colorWithRed:0 green:0 blue:1 alpha:0.8] CGColor]);
+
     CGContextFillEllipseInRect(context, [self topLeftResizeHandle]);
     CGContextFillEllipseInRect(context, [self bottomRightResizeHandle]);
 }
@@ -177,12 +189,12 @@
 
     if (gestureRecognizer.state == UIGestureRecognizerStateBegan &&
         gestureRecognizer.numberOfTouches == 1) {
-        if (CGRectContainsPoint([self topLeftResizeHandle], location)) {
+        if ([self topLeftResizeHandleIsCloseTo:location]) {
             NSLog(@"===> dragging TOPLEFT handle");
             draggedHandle = TOPLEFT;
             dragOffset.x = location.x - self.selectionRectangles[0].origin.x;
             dragOffset.y = location.y - self.selectionRectangles[0].origin.y;
-        } else if (CGRectContainsPoint([self bottomRightResizeHandle], location)) {
+        } else if ([self bottomRightResizeHandleIsCloseTo:location]) {
             NSLog(@"===> dragging BOTTOMRIGHT handle");
             draggedHandle = BOTTOMRIGHT;
             dragOffset.x = location.x - self.selectionRectangles[N-1].origin.x;


More information about the Libreoffice-commits mailing list