<commit_before>// Copyright eeGeo Ltd (2012-2015), All Rights Reserved

#include "InteriorsExplorerView.h"
#include "UIColors.h"
#include "ImageHelpers.h"
#include "InteriorsExplorerViewInterop.h"
#import "UIView+TouchExclusivity.h"

@implementation InteriorsExplorerView

- (ExampleApp::InteriorsExplorer::View::InteriorsExplorerViewInterop*) getInterop
{
    return m_pInterop;
}

- (id) initWithParams:(float)width :(float)height :(float)pixelScale
{
    if (self = [super init])
    {
        m_pixelScale = 1.f;
        m_screenWidth = width/pixelScale;
        m_screenHeight = height/pixelScale;
        
        m_stateChangeAnimationTimeSeconds = 0.2f;
        
        m_pInterop = new ExampleApp::InteriorsExplorer::View::InteriorsExplorerViewInterop(self);

        self.frame = CGRectMake(0,
                                0,
                                m_screenWidth,
                                m_screenHeight);
        
        
        m_inactiveFloorListXPosition = -50.f;
        m_inactiveDetailPaneYPosition = m_screenHeight;
        
        self.pFloorPanel = [[[UIView alloc] initWithFrame:CGRectMake(m_inactiveFloorListXPosition, m_screenHeight/2.0f, 55, 200)] autorelease];
        [self addSubview:self.pFloorPanel];
        
        self.pFloorPanelTop = [[[UIImageView alloc] initWithImage:ExampleApp::Helpers::ImageHelpers::LoadImage(@"floor_selection_top")] autorelease];
        self.pFloorPanelBottom = [[[UIImageView alloc] initWithImage:ExampleApp::Helpers::ImageHelpers::LoadImage(@"floor_selection_bottom")] autorelease];
        self.pFloorList = [[[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain] autorelease];
        self.pFloorList.delegate = self;
        self.pFloorList.dataSource = self;
        [self.pFloorPanel addSubview:self.pFloorPanelTop];
        [self.pFloorPanel addSubview:self.pFloorList];
        [self.pFloorPanel addSubview:self.pFloorPanelBottom];
        
        float buttonSize = 40.f;
        float labelLength = 200.f;
        float totalPanelLength = buttonSize + labelLength + buttonSize;

        const int micelloLogoWidth = 110;
        const int micelloLogoHeight = 24;
        float totalPanelHeight = micelloLogoHeight + buttonSize;
        
        m_detailsPanelHeight = totalPanelHeight;
        
        self.pDetailsPanel = [[[UIView alloc] initWithFrame:CGRectMake(m_screenWidth * 0.5f - totalPanelLength * 0.5f, m_inactiveDetailPaneYPosition, totalPanelLength, totalPanelHeight)] autorelease];
        
        self.pDismissButton = [[[UIButton alloc] initWithFrame:CGRectMake(0, 0, buttonSize, buttonSize)] autorelease];
        [self.pDismissButton setBackgroundImage:ExampleApp::Helpers::ImageHelpers::LoadImage(@"button_close_place_pin_off") forState:UIControlStateNormal];
        [self.pDismissButton addTarget:self action:@selector(onCancelButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self.pDetailsPanel addSubview:self.pDismissButton];
        
        self.pDetailsPanelBackground = [[[UIImageView alloc] initWithImage:ExampleApp::Helpers::ImageHelpers::LoadImage(@"place_pin_background")] autorelease];
        self.pDetailsPanelBackground.frame = CGRectMake(buttonSize, 0, labelLength, buttonSize);
        [self.pDetailsPanel addSubview:self.pDetailsPanelBackground];

        self.pDetailsPanelRight = [[[UIImageView alloc] initWithImage:ExampleApp::Helpers::ImageHelpers::LoadImage(@"place_pin_right")] autorelease];
        self.pDetailsPanelRight.frame = CGRectMake(buttonSize + labelLength, 0, buttonSize, buttonSize);
        [self.pDetailsPanel addSubview:self.pDetailsPanelRight];
        
        const float textPadding = 2.f;
        
        self.pFloorNameLabel = [[[UILabel alloc] initWithFrame:CGRectMake(buttonSize + textPadding, textPadding, labelLength - textPadding, buttonSize - textPadding)] autorelease];
        self.pFloorNameLabel.textColor = ExampleApp::Helpers::ColorPalette::DarkGreyTone;
        self.pFloorNameLabel.textAlignment = NSTextAlignmentCenter;
        [self.pDetailsPanel addSubview:self.pFloorNameLabel];
        
        self.pMicelloLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, buttonSize, totalPanelLength - micelloLogoWidth, micelloLogoHeight)] autorelease];
        self.pMicelloLabel.backgroundColor = ExampleApp::Helpers::ColorPalette::WhiteTone;
        self.pMicelloLabel.textColor = ExampleApp::Helpers::ColorPalette::GreyTone;
        self.pMicelloLabel.layer.borderWidth = 0;
        self.pMicelloLabel.textAlignment = NSTextAlignmentCenter;
        self.pMicelloLabel.text = @"Indoor data from";
        
        self.pMicelloLogo = [[[UIImageView alloc] initWithImage:ExampleApp::Helpers::ImageHelpers::LoadImage(@"micello_logo")] autorelease];
        self.pMicelloLogo.frame = CGRectMake(totalPanelLength - micelloLogoWidth, buttonSize, micelloLogoWidth, micelloLogoHeight);
        
        [self.pDetailsPanel addSubview:self.pMicelloLabel];
        [self.pDetailsPanel addSubview:self.pMicelloLogo];
        
        
        [self addSubview:self.pDetailsPanel];
        
        m_onScreenParam = 0.f;
        
        [self setHidden:YES];
    }
    
    return self;
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView *hitView = [super hitTest:point withEvent:event];
    if (hitView == self) return nil;
    return hitView;
}

- (void)layoutSubviews
{
    const int borderHeight = 20;
    const int floorPanelWidth = 55;
    CGFloat listHeight = self.pFloorList.contentSize.height;
    CGFloat totalFloorPanelHeight = (borderHeight * 2.f) + listHeight;
    
    CGRect originalFloorPanelFrame = self.pFloorPanel.frame;
    CGFloat newY = m_screenHeight/2.0f - totalFloorPanelHeight/2.0f;
    originalFloorPanelFrame.origin.y = newY;
    originalFloorPanelFrame.size.height = totalFloorPanelHeight;
    
    self.pFloorPanel.frame = originalFloorPanelFrame;
    self.pFloorPanelTop.frame = CGRectMake(0, 0, floorPanelWidth, borderHeight);
    self.pFloorList.frame = CGRectMake(0, borderHeight, floorPanelWidth, listHeight);
    self.pFloorPanelBottom.frame = CGRectMake(0, borderHeight+listHeight-1, floorPanelWidth, borderHeight);
}

- (void)dealloc
{
    delete m_pInterop;

    [self removeFromSuperview];
    [super dealloc];
}

- (void) show
{
    [self setHidden:NO];
}

- (void) hide
{
    [self setHidden:YES];
}

- (void) onCancelButtonPressed:(UIButton *)sender
{
    m_pInterop->Dismiss();
}

- (BOOL)consumesTouch:(UITouch *)touch
{
    return NO;
}

- (void) setFloorName:(const std::string*)name;
{
    self.pFloorNameLabel.text = [NSString stringWithUTF8String:name->c_str()];
}

- (void) updateFloors: (const std::vector<std::string>&) floorShortNames withCurrentFloor: (int) currentlySelectedFloorIndex;<commit_msg>Interiors view controls now consume touch, prevent world panning if dragging on these. Buddy: Malcolm<commit_after>// Copyright eeGeo Ltd (2012-2015), All Rights Reserved

#include "InteriorsExplorerView.h"
#include "UIColors.h"
#include "ImageHelpers.h"
#include "InteriorsExplorerViewInterop.h"
#import "UIView+TouchExclusivity.h"

@implementation InteriorsExplorerView

- (ExampleApp::InteriorsExplorer::View::InteriorsExplorerViewInterop*) getInterop
{
    return m_pInterop;
}

- (id) initWithParams:(float)width :(float)height :(float)pixelScale
{
    if (self = [super init])
    {
        m_pixelScale = 1.f;
        m_screenWidth = width/pixelScale;
        m_screenHeight = height/pixelScale;
        
        m_stateChangeAnimationTimeSeconds = 0.2f;
        
        m_pInterop = new ExampleApp::InteriorsExplorer::View::InteriorsExplorerViewInterop(self);

        self.frame = CGRectMake(0,
                                0,
                                m_screenWidth,
                                m_screenHeight);
        
        
        m_inactiveFloorListXPosition = -50.f;
        m_inactiveDetailPaneYPosition = m_screenHeight;
        
        self.pFloorPanel = [[[UIView alloc] initWithFrame:CGRectMake(m_inactiveFloorListXPosition, m_screenHeight/2.0f, 55, 200)] autorelease];
        [self addSubview:self.pFloorPanel];
        
        self.pFloorPanelTop = [[[UIImageView alloc] initWithImage:ExampleApp::Helpers::ImageHelpers::LoadImage(@"floor_selection_top")] autorelease];
        self.pFloorPanelBottom = [[[UIImageView alloc] initWithImage:ExampleApp::Helpers::ImageHelpers::LoadImage(@"floor_selection_bottom")] autorelease];
        self.pFloorList = [[[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain] autorelease];
        self.pFloorList.delegate = self;
        self.pFloorList.dataSource = self;
        [self.pFloorPanel addSubview:self.pFloorPanelTop];
        [self.pFloorPanel addSubview:self.pFloorList];
        [self.pFloorPanel addSubview:self.pFloorPanelBottom];
        
        float buttonSize = 40.f;
        float labelLength = 200.f;
        float totalPanelLength = buttonSize + labelLength + buttonSize;

        const int micelloLogoWidth = 110;
        const int micelloLogoHeight = 24;
        float totalPanelHeight = micelloLogoHeight + buttonSize;
        
        m_detailsPanelHeight = totalPanelHeight;
        
        self.pDetailsPanel = [[[UIView alloc] initWithFrame:CGRectMake(m_screenWidth * 0.5f - totalPanelLength * 0.5f, m_inactiveDetailPaneYPosition, totalPanelLength, totalPanelHeight)] autorelease];
        
        self.pDismissButton = [[[UIButton alloc] initWithFrame:CGRectMake(0, 0, buttonSize, buttonSize)] autorelease];
        [self.pDismissButton setBackgroundImage:ExampleApp::Helpers::ImageHelpers::LoadImage(@"button_close_place_pin_off") forState:UIControlStateNormal];
        [self.pDismissButton addTarget:self action:@selector(onCancelButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self.pDetailsPanel addSubview:self.pDismissButton];
        
        self.pDetailsPanelBackground = [[[UIImageView alloc] initWithImage:ExampleApp::Helpers::ImageHelpers::LoadImage(@"place_pin_background")] autorelease];
        self.pDetailsPanelBackground.frame = CGRectMake(buttonSize, 0, labelLength, buttonSize);
        [self.pDetailsPanel addSubview:self.pDetailsPanelBackground];

        self.pDetailsPanelRight = [[[UIImageView alloc] initWithImage:ExampleApp::Helpers::ImageHelpers::LoadImage(@"place_pin_right")] autorelease];
        self.pDetailsPanelRight.frame = CGRectMake(buttonSize + labelLength, 0, buttonSize, buttonSize);
        [self.pDetailsPanel addSubview:self.pDetailsPanelRight];
        
        const float textPadding = 2.f;
        
        self.pFloorNameLabel = [[[UILabel alloc] initWithFrame:CGRectMake(buttonSize + textPadding, textPadding, labelLength - textPadding, buttonSize - textPadding)] autorelease];
        self.pFloorNameLabel.textColor = ExampleApp::Helpers::ColorPalette::DarkGreyTone;
        self.pFloorNameLabel.textAlignment = NSTextAlignmentCenter;
        [self.pDetailsPanel addSubview:self.pFloorNameLabel];
        
        self.pMicelloLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, buttonSize, totalPanelLength - micelloLogoWidth, micelloLogoHeight)] autorelease];
        self.pMicelloLabel.backgroundColor = ExampleApp::Helpers::ColorPalette::WhiteTone;
        self.pMicelloLabel.textColor = ExampleApp::Helpers::ColorPalette::GreyTone;
        self.pMicelloLabel.layer.borderWidth = 0;
        self.pMicelloLabel.textAlignment = NSTextAlignmentCenter;
        self.pMicelloLabel.text = @"Indoor data from";
        
        self.pMicelloLogo = [[[UIImageView alloc] initWithImage:ExampleApp::Helpers::ImageHelpers::LoadImage(@"micello_logo")] autorelease];
        self.pMicelloLogo.frame = CGRectMake(totalPanelLength - micelloLogoWidth, buttonSize, micelloLogoWidth, micelloLogoHeight);
        
        [self.pDetailsPanel addSubview:self.pMicelloLabel];
        [self.pDetailsPanel addSubview:self.pMicelloLogo];
        
        
        [self addSubview:self.pDetailsPanel];
        
        m_onScreenParam = 0.f;
        
        [self setHidden:YES];
    }
    
    return self;
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView *hitView = [super hitTest:point withEvent:event];
    if (hitView == self) return nil;
    return hitView;
}

- (void)layoutSubviews
{
    const int borderHeight = 20;
    const int floorPanelWidth = 55;
    CGFloat listHeight = self.pFloorList.contentSize.height;
    CGFloat totalFloorPanelHeight = (borderHeight * 2.f) + listHeight;
    
    CGRect originalFloorPanelFrame = self.pFloorPanel.frame;
    CGFloat newY = m_screenHeight/2.0f - totalFloorPanelHeight/2.0f;
    originalFloorPanelFrame.origin.y = newY;
    originalFloorPanelFrame.size.height = totalFloorPanelHeight;
    
    self.pFloorPanel.frame = originalFloorPanelFrame;
    self.pFloorPanelTop.frame = CGRectMake(0, 0, floorPanelWidth, borderHeight);
    self.pFloorList.frame = CGRectMake(0, borderHeight, floorPanelWidth, listHeight);
    self.pFloorPanelBottom.frame = CGRectMake(0, borderHeight+listHeight-1, floorPanelWidth, borderHeight);
}

- (void)dealloc
{
    delete m_pInterop;

    [self removeFromSuperview];
    [super dealloc];
}

- (void) show
{
    [self setHidden:NO];
}

- (void) hide
{
    [self setHidden:YES];
}

- (void) onCancelButtonPressed:(UIButton *)sender
{
    m_pInterop->Dismiss();
}

- (BOOL)consumesTouch:(UITouch *)touch
{
    CGPoint touchLocation = [touch locationInView:self];
    if (CGRectContainsPoint(self.pFloorPanel.frame, touchLocation))
        return YES;
    if (CGRectContainsPoint(self.pDetailsPanel.frame, touchLocation))
        return YES;
    return  NO;
}

- (void) setFloorName:(const std::string*)name;
{
    self.pFloorNameLabel.text = [NSString stringWithUTF8String:name->c_str()];
}

- (void) updateFloors: (const std::vector<std::string>&) floorShortNames withCurrentFloor: (int) currentlySelectedFloorIndex;
{'fraction_non_alphanumeric': 0.10367604824813326, 'fraction_numerical': 0.009046524985640436, 'mean_word_length': 3.823060941828255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7485344', 'n_tokens_mistral': 4437, 'n_tokens_neox': 4240, 'n_words': 691}