HelloTouch.app main.m : Select all

/* HelloTouch.app main.m */ #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> // include for the sdk compiler and open toolchain header #ifndef UIKIT_UIFont_UIColor_H #define UIKIT_UIFont_UIColor_H typedef float CGFloat; #import <UIKit/UIFont.h> #import <UIKit/UIColor.h> #endif #ifndef UIKIT_UISlider_H #define UIKIT_UISlider_H #import <UIKit/UISliderControl.h> @interface UISlider : UISliderControl @property float value; // default 0.0. this value will be pinned to min/max @property float minimumValue; // default 0.0. the current value may change if outside new min value @property float maximumValue; // default 1.0. the current value may change if outside new max value @property(retain) UIImage *minimumValueImage; // default is nil. image that appears to left of control (e.g. speaker off) @property(retain) UIImage *maximumValueImage; // default is nil. image that appears to right of control (e.g. speaker max) @end #endif #ifndef UIKIT_UITouch_UIEvent_H #define UIKIT_UITouch_UIEvent_H typedef unsigned int NSUInteger; #import <UIKit/UITouch.h> #import <UIKit/UIEvent.h> #endif @interface HelloTouch : UIApplication { UIWindow *window; UIImageView *imgView[2]; UIView *mainView; UISlider *slider; } - (void) handleSlider: (id)unused; @end @implementation HelloTouch - (void) applicationDidFinishLaunching: (NSNotification *)aNotification { [UIHardware _setStatusBarHeight:0.0f]; [self setStatusBarMode:2 duration:0.0f]; [self setStatusBarHidden:YES animated:NO]; // hide status bar CGRect rect = [UIHardware fullScreenApplicationContentRect]; rect.origin.x = rect.origin.y = 0.0f; window = [[UIWindow alloc] initWithContentRect: rect]; mainView = [[UIView alloc] initWithFrame:rect]; imgView[0] = [[UIImageView alloc] initWithImage:[UIImage imageAtPath:@"/System/Library/CoreServices/SpringBoard.app/Activate.png"]]; imgView[1] = [[UIImageView alloc] initWithImage:[UIImage imageAtPath:@"/System/Library/CoreServices/SpringBoard.app/applelogo.png"]]; [imgView[0] setBackgroundColor:[UIColor clearColor]]; [imgView[0] setOrigin:CGPointMake(112,0)]; [imgView[1] setOrigin:CGPointMake(125,178)]; [imgView[1] setBackgroundColor:[UIColor clearColor]]; [mainView addSubview: imgView[0] ]; slider = [[UISlider alloc] initWithFrame:CGRectMake(20, 380, 280, 40)]; [slider setShowValue:NO]; [slider addTarget:self action:@selector(handleSlider:) forEvents:7]; // 7=drag, 2=up slider.minimumValue = 0.0; slider.maximumValue = 10.0; slider.value = 1.0; [mainView addSubview:slider]; [mainView becomeFirstResponder]; [window setContentView: mainView]; [window orderFront: self]; [window makeKeyAndVisible]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSUInteger numTaps = [[touches anyObject] tapCount]; if(numTaps >= 2) { if (numTaps == 2) { //double tap if ([slider isEnabled]) { [slider setEnabled:NO]; [slider removeFromSuperview]; } else { [slider setEnabled:YES]; [mainView addSubview:slider]; } } } } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { // Enumerates through all touch objects for (UITouch *touch in touches){ // Check for a swipe. Not all move events are swipes. A swipe can have two directions, such as down, right. if (touch.info & UITouchInfoSwipedDown) { [slider removeFromSuperview]; } else if (touch.info & UITouchInfoSwipedUp ) { [mainView addSubview:slider]; } else if (touch.info & UITouchInfoSwipedRight) { [imgView[0] removeFromSuperview]; [mainView addSubview:imgView[1]]; } else if (touch.info & UITouchInfoSwipedLeft) { [imgView[1] removeFromSuperview]; [mainView addSubview:imgView[0]]; } } } - (void) handleSlider: (id)unused { if (slider.value == 0.0) { [mainView setBackgroundColor:[UIColor whiteColor]]; } else if (slider.value <= 1.0) { [mainView setBackgroundColor:[UIColor grayColor]]; } else if (slider.value <= 2.0) { [mainView setBackgroundColor:[UIColor redColor]]; } else if (slider.value <= 3.0) { [mainView setBackgroundColor:[UIColor greenColor]]; } else if (slider.value <= 4.0) { [mainView setBackgroundColor:[UIColor blueColor]]; } else if (slider.value <= 5.0) { [mainView setBackgroundColor:[UIColor cyanColor]]; } else if (slider.value <= 6.0) { [mainView setBackgroundColor:[UIColor yellowColor]]; } else if (slider.value <= 7.0) { [mainView setBackgroundColor:[UIColor magentaColor]]; } else if (slider.value <= 8.0) { [mainView setBackgroundColor:[UIColor orangeColor]]; } else if (slider.value <= 9.0) { [mainView setBackgroundColor:[UIColor purpleColor]]; } else if (slider.value <= 10.0) { [mainView setBackgroundColor:[UIColor brownColor]]; } else { [mainView setBackgroundColor:[UIColor whiteColor]]; } } @end int main(int argc, char *argv[]) { int returnCode; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; returnCode = UIApplicationMain(argc, argv, [HelloTouch class]); [pool release]; return returnCode; }