diff options
author | Tor Lillqvist <tml@collabora.com> | 2013-10-27 20:26:08 +0200 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2013-10-27 22:11:18 +0200 |
commit | 37056560a387360866486396e0adcb80b26edea4 (patch) | |
tree | e4de486b13bbc4e91d5b8ace454105e696b4025c /ios | |
parent | 0ef3db356357a419328b073ae74f92077f426c17 (diff) |
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
Diffstat (limited to 'ios')
-rw-r--r-- | ios/experimental/LibreOffice/LibreOffice/View.m | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/ios/experimental/LibreOffice/LibreOffice/View.m b/ios/experimental/LibreOffice/LibreOffice/View.m index 3a9b35bdbdd4..cd38ab50ba93 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; |