FMCPlanner2/FMC Planner 2/ViewControllerKeyboard.m

90 lines
3.3 KiB
Objective-C

//
// ViewControllerKeyboard.m
// FMC Planner 2
//
// Created by Kilian Hofmann on 20.03.16.
// Copyright © 2016 Kilian Hofmann. All rights reserved.
//
#import "ViewController.h"
#import "ViewControllerKeyboard.h"
@implementation ViewControllerKeyboard
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
_alphaOn = true;
_alphabet = [[NSArray alloc]
initWithObjects:@"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I",
@"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R",
@"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z", @"SP",
@"CLR", @"DEL", @"NUM", @"M\nE\nN\nU", @"P\nE\nR\nF",
@"R\nT\nE", nil];
_numeric = [[NSArray alloc]
initWithObjects:@"1", @"2", @"3", @"", @"", @"", @"4", @"5", @"6",
@"", @"", @"", @"7", @"8", @"9", @"", @"", @"",
@".", @"0", @"/", @"", @"", @"", @"", @"", @"SP",
@"CLR", @"DEL", @"LET", @"M\nE\nN\nU", @"P\nE\nR\nF",
@"R\nT\nE", nil];
// Init Board
[self switchKeyboard];
// Round button corners
for (UIButton *but in _Keys) {
but.layer.cornerRadius = 5;
but.layer.masksToBounds = YES;
}
}
- (IBAction)KeyTaps:(UIButton *)sender {
if ([sender.restorationIdentifier isEqualToString:@"Switch"]) {
_alphaOn = !_alphaOn;
[self switchKeyboard];
} else if ([sender.restorationIdentifier isEqualToString:@"Space"]) {
_main.screen.Scratchpad.text =
[_main.screen.Scratchpad.text stringByAppendingString:@" "];
} else if ([sender.restorationIdentifier isEqualToString:@"Clear"]) {
if ([_main.screen.Scratchpad.text isEqualToString:@"DELETE"]) {
_main.screen.Scratchpad.text = @"";
} else if (_main.screen.Scratchpad.text.length > 0) {
_main.screen.Scratchpad.text = [_main.screen.Scratchpad.text
substringToIndex:[_main.screen.Scratchpad.text length] - 1];
}
} else if ([sender.restorationIdentifier isEqualToString:@"Delete"]) {
_main.screen.Scratchpad.text = @"DELETE";
} else if ([sender.restorationIdentifier isEqualToString:@"Top"]) {
[_main.screen loadScreen:@"Menu"];
} else if ([sender.restorationIdentifier isEqualToString:@"Mid"]) {
[_main.screen loadScreen:@"Perf Init"];
} else if ([sender.restorationIdentifier isEqualToString:@"Bot"]) {
[_main.screen loadScreen:@"Route"];
} else {
_main.screen.Scratchpad.text = [_main.screen.Scratchpad.text
stringByAppendingString:sender.titleLabel.text];
}
}
- (void)switchKeyboard {
if (_alphaOn) {
for (int i = 0; i < _Keys.count; i++) {
((UIButton *)_Keys[i]).titleLabel.numberOfLines = 0;
((UIButton *)_Keys[i]).titleLabel.lineBreakMode =
NSLineBreakByCharWrapping;
[((UIButton *)_Keys[i]) setTitle:_alphabet[i]
forState:UIControlStateNormal];
[((UIButton *)_Keys[i]).titleLabel sizeToFit];
}
} else {
for (int i = 0; i < _Keys.count; i++) {
((UIButton *)_Keys[i]).titleLabel.numberOfLines = 0;
((UIButton *)_Keys[i]).titleLabel.lineBreakMode =
NSLineBreakByCharWrapping;
[((UIButton *)_Keys[i]) setTitle:_numeric[i]
forState:UIControlStateNormal];
[((UIButton *)_Keys[i]).titleLabel sizeToFit];
}
}
}
@end