diff options
author | vng <viktor.govako@gmail.com> | 2013-06-05 19:43:13 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:57:10 +0300 |
commit | c921a4427b4f82ec5e18102ae563fe791ef79816 (patch) | |
tree | c0b21838ac1638efd0f660f071ac66ce2560a8bd /iphone | |
parent | d8a07db9528440d4ef2a87304f5984e0f43ff110 (diff) |
[iOS] "Lite" embedding of new balloon.
Diffstat (limited to 'iphone')
-rw-r--r-- | iphone/Maps/Bookmarks/AddSetVC.mm | 5 | ||||
-rw-r--r-- | iphone/Maps/Bookmarks/BalloonView.h | 27 | ||||
-rw-r--r-- | iphone/Maps/Bookmarks/BalloonView.mm | 223 | ||||
-rw-r--r-- | iphone/Maps/Bookmarks/PlacePageVC.mm | 2 | ||||
-rw-r--r-- | iphone/Maps/Classes/EAGLView.mm | 3 | ||||
-rw-r--r-- | iphone/Maps/Classes/MapViewController.mm | 41 |
6 files changed, 85 insertions, 216 deletions
diff --git a/iphone/Maps/Bookmarks/AddSetVC.mm b/iphone/Maps/Bookmarks/AddSetVC.mm index bb1b8f4feb..fd04dfe609 100644 --- a/iphone/Maps/Bookmarks/AddSetVC.mm +++ b/iphone/Maps/Bookmarks/AddSetVC.mm @@ -34,9 +34,10 @@ m_balloon.setName = text; [m_balloon deleteBookmark]; - Framework &f = GetFramework(); - size_t pos = f.AddCategory([text UTF8String]); + Framework & f = GetFramework(); + size_t const pos = f.AddCategory([text UTF8String]); [m_balloon addBookmarkToCategory:pos]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) [self.navigationController popToRootViewControllerAnimated:YES]; else diff --git a/iphone/Maps/Bookmarks/BalloonView.h b/iphone/Maps/Bookmarks/BalloonView.h index 8721f84805..922e6b10f3 100644 --- a/iphone/Maps/Bookmarks/BalloonView.h +++ b/iphone/Maps/Bookmarks/BalloonView.h @@ -1,36 +1,33 @@ #import <UIKit/UIKit.h> -#include "Framework.h" +#include "../../../map/bookmark.hpp" +#include "../../../map/bookmark_balloon.hpp" + @interface BalloonView : NSObject { - UIImageView * m_titleView; - id m_target; - SEL m_selector; + shared_ptr<BookmarkBalloon> m_balloon; + + graphics::Image::Info m_images[2]; } @property(nonatomic, retain) NSString * title; // Currently displays bookmark description (notes) @property(nonatomic, retain) NSString * notes; -// Contains feature type(s) -//@property(nonatomic, retain) NSString * type; -@property(nonatomic, retain) UIImageView * pinImage; // Stores displayed bookmark icon file name @property(nonatomic, retain) NSString * color; -// Stores last used bookmark Set name -@property(nonatomic, retain) NSString * setName; -@property(nonatomic, assign, readonly) BOOL isDisplayed; -@property(nonatomic, assign) CGPoint globalPosition; // If we clicked already existing bookmark, it will be here @property(nonatomic, assign) BookmarkAndCategory editedBookmark; -//check if we should move ballon when our location was changed -@property(nonatomic, assign) BOOL isCurrentPosition; + +@property(nonatomic, assign) CGPoint globalPosition; +@property(nonatomic, retain) NSString * setName; + - (id) initWithTarget:(id)target andSelector:(SEL)selector; -- (void) showInView:(UIView *)view atPoint:(CGPoint)pt; -- (void) updatePosition:(UIView *)view atPoint:(CGPoint)pt; +- (void) showInView; - (void) hide; - (void) clear; +- (BOOL) isDisplayed; // Kosher method to add bookmark into the Framework. // It automatically "edits" bookmark if it's already exists diff --git a/iphone/Maps/Bookmarks/BalloonView.mm b/iphone/Maps/Bookmarks/BalloonView.mm index 20572ad174..22b7d6aaa7 100644 --- a/iphone/Maps/Bookmarks/BalloonView.mm +++ b/iphone/Maps/Bookmarks/BalloonView.mm @@ -1,187 +1,93 @@ #import "BalloonView.h" #import <QuartzCore/CALayer.h> -#include "../../../platform/settings.hpp" +#include "Framework.h" + +#include "../../../gui/controller.hpp" @implementation BalloonView -@synthesize globalPosition; @synthesize title; @synthesize notes; -//@synthesize type; -@synthesize pinImage; @synthesize color; -@synthesize setName; -@synthesize isDisplayed; @synthesize editedBookmark; -@synthesize isCurrentPosition; +@synthesize globalPosition; +@synthesize setName; -+ (NSString *) getDefaultSetName -{ - Framework & f = GetFramework(); - int const categoryPos = f.LastEditedCategory(); - return[NSString stringWithUTF8String:f.GetBmCategory(categoryPos)->GetName().c_str()]; -} - (id) initWithTarget:(id)target andSelector:(SEL)selector; { if ((self = [super init])) { - // Default bookmark pin color + // default bookmark pin color self.color = @"placemark-red"; - NSLog(@"Framework initialization started"); - self.setName = [BalloonView getDefaultSetName]; - NSLog(@"Framework initialization ended"); - - // Load bookmarks from kml files - GetFramework().LoadBookmarks(); - self.pinImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:self.color]] autorelease]; - isDisplayed = NO; - m_target = target; - m_selector = selector; - m_titleView = [[UIImageView alloc] init]; - m_titleView.userInteractionEnabled = YES; - isCurrentPosition = NO; - UITapGestureRecognizer * recognizer = [[[UITapGestureRecognizer alloc] - initWithTarget:m_target action:m_selector] autorelease]; - recognizer.numberOfTapsRequired = 1; - recognizer.numberOfTouchesRequired = 1; - recognizer.delaysTouchesBegan = YES; - [m_titleView addGestureRecognizer:recognizer]; + Framework & f = GetFramework(); + + // default bookmark name. + self.title = [NSString stringWithUTF8String:f.GetBmCategory(f.LastEditedCategory())->GetName().c_str()]; + + // Init balloon. + BookmarkBalloon::Params bp; + bp.m_position = graphics::EPosAbove; + bp.m_depth = graphics::maxDepth; + bp.m_pivot = m2::PointD(0, 0); + bp.m_mainText = "Bookmark"; + bp.m_framework = &f; + + m_balloon.reset(new BookmarkBalloon(bp)); + m_balloon->setIsVisible(false); + + typedef void (*fireBalloonFnT)(id, SEL); + fireBalloonFnT fn = (fireBalloonFnT)[target methodForSelector:selector]; + m_balloon->setOnClickListener(bind(fn, target, selector)); + + f.GetGuiController()->AddElement(m_balloon); + + graphics::EDensity const density = graphics::EDensityMDPI;//f.GetRenderPolicy()->Density(); + m_images[0] = graphics::Image::Info("plus.png", density); + m_images[1] = graphics::Image::Info("arrow.png", density); + + [self updateBalloonSize]; + + // load bookmarks from kml files + f.LoadBookmarks(); editedBookmark = MakeEmptyBookmarkAndCategory(); } return self; } +- (void) updateBalloonSize +{ + ScreenBase const & s = GetFramework().GetNavigator().Screen(); + m_balloon->onScreenSize(s.GetWidth(), s.GetHeight()); +} + - (void) dealloc { - [m_titleView release]; - self.pinImage = nil; self.color = nil; - self.setName = nil; self.title = nil; self.notes = nil; -// self.type = nil; - [super dealloc]; -} - -// Returned image SHOULD NOT be released - it's handled automatically by context -- (UIImage *)createPopupImageWithTitle:(NSString *)aTitle andDescription:(NSString *)aDescription -{ - // description becomes a title if title is absent - if (!aTitle && aDescription) - { - aTitle = aDescription; - aDescription = nil; - } - UIImage * left = [UIImage imageNamed:@"left"]; - UIImage * right = [UIImage imageNamed:@"right"]; - UIImage * middle = [UIImage imageNamed:@"middle"]; - UIImage * tail = [UIImage imageNamed:@"tail"]; - UIImage * arrow = [UIImage imageNamed:(IsValid(editedBookmark) ? @"arrow" : @"add")]; - - // Calculate text width and height - UIFont * titleFont = [UIFont boldSystemFontOfSize:[UIFont buttonFontSize]]; - UIFont * descriptionFont = [UIFont systemFontOfSize:[UIFont systemFontSize]]; - - CGSize const defSize = CGSizeMake(arrow.size.width + tail.size.width + left.size.width + right.size.width, - tail.size.height); - CGSize const titleSize = aTitle ? [aTitle sizeWithFont:titleFont] : defSize; - CGSize const descriptionSize = aDescription ? [aDescription sizeWithFont:descriptionFont] : defSize; - - CGFloat const minScreenWidth = MIN([UIScreen mainScreen].applicationFrame.size.width, - [UIScreen mainScreen].applicationFrame.size.height); - - CGFloat const padding = 1.; - - // Generated image size - CGFloat const height = tail.size.height; - CGFloat const additionalPadding = padding * 3 + arrow.size.width + left.size.width + right.size.width; - CGFloat const width = MAX(MIN(minScreenWidth, titleSize.width + additionalPadding), - MIN(minScreenWidth, descriptionSize.width + additionalPadding)); - - UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, height), NO, 0.0); - - // Draw background - [left drawAtPoint:CGPointMake(0, 0)]; - [right drawAtPoint:CGPointMake(width - right.size.width, 0)]; - CGFloat const tailStartsAt = (long)(width - tail.size.width) / 2; - [tail drawAtPoint:CGPointMake(tailStartsAt, 0)]; - [middle drawInRect:CGRectMake(left.size.width, 0, tailStartsAt - left.size.width, middle.size.height)]; - [middle drawInRect:CGRectMake(tailStartsAt + tail.size.width, 0, width - tailStartsAt - tail.size.width - right.size.width, middle.size.height)]; - - // Draw text - CGFloat const textW = width - left.size.width - right.size.width - arrow.size.width; - CGFloat const titleTextH = left.size.height / (aDescription ? 2. : 1.); - [[UIColor whiteColor] set]; - [aTitle drawInRect:CGRectMake(left.size.width, titleTextH / (aDescription ? 8 : 4), textW, titleTextH / 2.) withFont:titleFont lineBreakMode:UILineBreakModeTailTruncation]; - if (aDescription) - { - [[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0] set]; - [aDescription drawInRect:CGRectMake(left.size.width, titleTextH - (titleTextH / 8), textW, titleTextH) withFont:descriptionFont lineBreakMode:UILineBreakModeTailTruncation]; - } - - // Draw Arrow image - CGFloat const arrowPadding = (left.size.height - arrow.size.height) / 2; - [arrow drawAtPoint:CGPointMake(width - arrow.size.width - arrowPadding, arrowPadding)]; - - UIImage * theImage = UIGraphicsGetImageFromCurrentImageContext(); - - UIGraphicsEndImageContext(); - // return the image - return theImage; + [super dealloc]; } -- (void) showInView:(UIView *)view atPoint:(CGPoint)pt +- (void) showInView { - [self hide]; - - isDisplayed = YES; - - CGFloat const h = self.pinImage.bounds.size.height; - // Fix point - if (IsValid(editedBookmark)) - pt.y -= h; - - // Do not show pin if we're editing existing bookmark. - // @TODO move pin (and probably balloon drawing) to cross-platform code - CGSize const s = m_titleView.bounds.size; - m_titleView.frame = CGRectMake(pt.x, pt.y, 1, 1); - - [view addSubview:m_titleView]; - - // Animate balloon from touched point - [UIView transitionWithView:self.pinImage duration:0.1 options:UIViewAnimationOptionCurveEaseIn - animations:^{ m_titleView.frame = CGRectMake(pt.x - s.width/2, pt.y - s.height, s.width, s.height);} - completion:nil]; -} + m_balloon->setImage(m_images[0]); + m_balloon->setBookmarkCaption([title UTF8String], ""); + m_balloon->setGlbPivot(m2::PointD(globalPosition.x, globalPosition.y)); -- (void) updatePosition:(UIView *)view atPoint:(CGPoint)pt -{ - if (isDisplayed) - { - CGFloat const pinHeight = self.pinImage.bounds.size.height; - CGFloat const w2 = m_titleView.bounds.size.width; - CGFloat const h2 = m_titleView.bounds.size.height; - double balloon_y = pt.y - h2; - if (IsValid(editedBookmark)) - balloon_y -= pinHeight; - m_titleView.frame = CGRectMake(pt.x - w2/2, balloon_y, w2, h2); - } + [self updateBalloonSize]; + m_balloon->showAnimated(); } - (void) hide { - if (isDisplayed) - { - isDisplayed = NO; - [m_titleView removeFromSuperview]; - } + m_balloon->hide(); } -(void)clear @@ -190,22 +96,9 @@ self.editedBookmark = MakeEmptyBookmarkAndCategory(); } -// Overrided property setter to reload another pin image -- (void) setColor:(NSString *)newColor +- (BOOL) isDisplayed { - id old = color; - color = [newColor retain]; - [old release]; - self.pinImage.image = [UIImage imageNamed:newColor]; -} - -- (void) setTitle:(NSString *)newTitle -{ - id old = title; - title = [newTitle retain]; - [old release]; - m_titleView.image = [self createPopupImageWithTitle:newTitle andDescription:notes]; - [m_titleView sizeToFit]; + return m_balloon->isVisible(); } - (void) addOrEditBookmark @@ -243,18 +136,18 @@ cat->DeleteBookmark(editedBookmark.second); cat->SaveToKMLFile(); } - // Clear! + editedBookmark = MakeEmptyBookmarkAndCategory(); } } - (void) addBookmarkToCategory:(size_t)index { - Framework &f = GetFramework(); - Bookmark bm(m2::PointD(globalPosition.x, globalPosition.y), - [title UTF8String], [color UTF8String]); - size_t newPosition = f.AddBookmark(index, bm); - self.editedBookmark = pair <int, int> (index, newPosition); + Framework & f = GetFramework(); + Bookmark bm(m2::PointD(globalPosition.x, globalPosition.y), [title UTF8String], [color UTF8String]); + size_t const pos = f.AddBookmark(index, bm); + + self.editedBookmark = pair<int, int>(index, pos); self.setName = [NSString stringWithUTF8String:f.GetBmCategory(index)->GetName().c_str()]; } diff --git a/iphone/Maps/Bookmarks/PlacePageVC.mm b/iphone/Maps/Bookmarks/PlacePageVC.mm index 86a3264549..5d8053ed92 100644 --- a/iphone/Maps/Bookmarks/PlacePageVC.mm +++ b/iphone/Maps/Bookmarks/PlacePageVC.mm @@ -95,7 +95,6 @@ static NSString * const g_colors [] = { m_balloon = view; self.title = m_balloon.title; - m_balloon.isCurrentPosition = NO; NSMutableArray * viewArray = [[NSMutableArray alloc] init]; @@ -515,7 +514,6 @@ static NSString * const g_colors [] = { if (![m_balloon.color isEqualToString:g_colors[selectedRow]]) { - m_balloon.pinImage.image = [UIImage imageNamed:g_colors[selectedRow]]; [[Statistics instance] logEvent:@"Select Bookmark color"]; m_balloon.color = g_colors[selectedRow]; [self.tableView reloadData]; diff --git a/iphone/Maps/Classes/EAGLView.mm b/iphone/Maps/Classes/EAGLView.mm index 6222f24472..affbc76f46 100644 --- a/iphone/Maps/Classes/EAGLView.mm +++ b/iphone/Maps/Classes/EAGLView.mm @@ -164,9 +164,6 @@ Framework & f = GetFramework(); if (f.NeedRedraw()) { - if (balloonView.isDisplayed) - [balloonView updatePosition:self atPoint:[self globalPoint2ViewPoint:balloonView.globalPosition]]; - f.SetNeedRedraw(false); f.BeginPaint(pe); f.DoPaint(pe); diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index e836f5c111..71748e196b 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -96,13 +96,6 @@ const long long LITE_IDL = 431183278L; f.OnLocationUpdate(info); - if (m_balloonView.isCurrentPosition && m_balloonView.isDisplayed) - { - m2::PointD newCenter(MercatorBounds::LonToX(info.m_longitude), - MercatorBounds::LatToY(info.m_latitude)); - m_balloonView.globalPosition = CGPointMake(newCenter.x, newCenter.y); - [m_balloonView updatePosition:self.view atPoint:[(EAGLView *)self.view globalPoint2ViewPoint:m_balloonView.globalPosition]]; - } [self showPopoverFromBalloonData]; } @@ -142,11 +135,11 @@ const long long LITE_IDL = 431183278L; return; } } + [m_balloonView clear]; - m_balloonView.isCurrentPosition = YES; [m_balloonView setTitle:NSLocalizedString(@"my_position", nil)]; m_balloonView.globalPosition = CGPointMake(point.x, point.y); - [m_balloonView showInView:self.view atPoint:[(EAGLView *)self.view globalPoint2ViewPoint:m_balloonView.globalPosition]]; + [m_balloonView showInView]; } //******************************************************************************************** @@ -332,7 +325,7 @@ const long long LITE_IDL = 431183278L; - (void) processMapClickAtPoint:(CGPoint)point longClick:(BOOL)isLongClick { BOOL wasBalloonDisplayed; - if (m_balloonView.isDisplayed) + if ([m_balloonView isDisplayed]) { [m_balloonView hide]; [m_balloonView clear]; @@ -341,12 +334,10 @@ const long long LITE_IDL = 431183278L; else wasBalloonDisplayed = NO; - m_balloonView.isCurrentPosition = NO; - // Try to check if we've clicked on bookmark Framework & f = GetFramework(); CGFloat const scaleFactor = self.view.contentScaleFactor; - // @TODO Refactor point transformation + m2::PointD pxClicked(point.x * scaleFactor, point.y * scaleFactor); Framework::AddressInfo addrInfo; m2::PointD pxPivot; @@ -362,17 +353,16 @@ const long long LITE_IDL = 431183278L; m2::PointD const gPivot = f.PtoG(pxPivot); m_balloonView.globalPosition = CGPointMake(gPivot.x, gPivot.y); [self updatePinTexts:addrInfo]; - [m_balloonView showInView:self.view atPoint:CGPointMake(pxPivot.x / scaleFactor, pxPivot.y / scaleFactor)]; + [m_balloonView showInView]; } break; default: if (isLongClick) { f.GetAddressInfo(pxClicked, addrInfo); - // @TODO Refactor point transformation m_balloonView.globalPosition = [(EAGLView *)self.view viewPoint2GlobalPoint:point]; [self updatePinTexts:addrInfo]; - [m_balloonView showInView:self.view atPoint:point]; + [m_balloonView showInView]; } break; } @@ -392,9 +382,8 @@ const long long LITE_IDL = 431183278L; { [m_balloonView clear]; m_balloonView.globalPosition = CGPointMake(pt.x, pt.y); - m_balloonView.isCurrentPosition = NO; [self updatePinTexts:info]; - [m_balloonView showInView:self.view atPoint:[(EAGLView *)self.view globalPoint2ViewPoint:m_balloonView.globalPosition]]; + [m_balloonView showInView]; } - (void) dealloc @@ -739,7 +728,6 @@ NSInteger compareAddress(id l, id r, void * context) m2::PointD const globalPos = bm->GetOrg(); // Set it before changing balloon title to display different images in case of creating/editing Bookmark m_balloonView.editedBookmark = bmAndCat; - m_balloonView.isCurrentPosition = NO; m_balloonView.globalPosition = CGPointMake(globalPos.x, globalPos.y); // Reset description BEFORE title, as title's setter also takes it into an account for Balloon text generation string const & descr = bm->GetDescription(); @@ -747,10 +735,11 @@ NSInteger compareAddress(id l, id r, void * context) m_balloonView.notes = [NSString stringWithUTF8String:descr.c_str()]; else m_balloonView.notes = nil; + m_balloonView.title = [NSString stringWithUTF8String:bm->GetName().c_str()]; m_balloonView.color = [NSString stringWithUTF8String:bm->GetType().c_str()]; m_balloonView.setName = [NSString stringWithUTF8String:cat->GetName().c_str()]; - [m_balloonView showInView:self.view atPoint:[(EAGLView *)self.view globalPoint2ViewPoint:m_balloonView.globalPosition]]; + [m_balloonView showInView]; } } } @@ -855,11 +844,7 @@ NSInteger compareAddress(id l, id r, void * context) [m_balloonView clear]; m_balloonView.globalPosition = CGPointMake(point.x, point.y); m_balloonView.title = text; - m_balloonView.isCurrentPosition = NO; - CGFloat const scaleFactor = self.view.contentScaleFactor; - - point = GetFramework().GtoP(point); - [m_balloonView showInView:self.view atPoint:CGPointMake(point.x / scaleFactor, point.y / scaleFactor)]; + [m_balloonView showInView]; } - (void) destroyPopover @@ -887,12 +872,10 @@ NSInteger compareAddress(id l, id r, void * context) -(void)showPopoverFromBalloonData { m2::PointD pt = GetFramework().GtoP(m2::PointD(m_balloonView.globalPosition.x, m_balloonView.globalPosition.y)); - if (IsValid(m_balloonView.editedBookmark)) - pt.y -= m_balloonView.pinImage.frame.size.height; - //TODO We should always remember about scale factor, solve this problem - double sf = self.view.contentScaleFactor; + double const sf = self.view.contentScaleFactor; pt.x /= sf; pt.y /= sf; + [popover presentPopoverFromRect:CGRectMake(pt.x, pt.y, 1, 1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } |