Skip to content

Instantly share code, notes, and snippets.

@C4Tutorials
Last active December 16, 2015 03:59
Show Gist options
  • Save C4Tutorials/5373415 to your computer and use it in GitHub Desktop.
Save C4Tutorials/5373415 to your computer and use it in GitHub Desktop.
Getting Things On-Screen
//
// C4WorkSpace.m
// Getting Things On-Screen Tutorial
//
// Created by Travis Kirton.
//
#import "C4WorkSpace.h"
/*
UNCOMMENT the camera stuff if you're running this on an iPad.
*/
@implementation C4WorkSpace {
C4Shape *shape;
C4Movie *movie;
C4Image *image;
C4GL *gl;
// C4Camera *camera;
C4Label *label;
C4Button *button;
C4Slider *slider;
C4Stepper *stepper;
C4Switch *onOffSwitch;
C4ScrollView *scrollView;
NSArray *allObjects;
}
-(void)setup {
[self createObjects];
[self setupObjects];
[self positionObjects];
[self individualAdd];
// [self groupAdd];
}
//adding each object individually
-(void)individualAdd {
[self.canvas addShape:shape];
[self.canvas addMovie:movie];
[self.canvas addImage:image];
[self.canvas addGL:gl];
// [self.canvas addCamera:camera];
[self.canvas addLabel:label];
[self.canvas addUIElement:button];
[self.canvas addUIElement:slider];
[self.canvas addUIElement:stepper];
[self.canvas addUIElement:onOffSwitch];
[self.canvas addSubview:scrollView];
}
//adding an array of objects at once
-(void)groupAdd {
[self.canvas addObjects:allObjects];
}
-(void)createObjects {
shape = [C4Shape ellipse:CGRectMake(0, 0, 128, 128)];
movie = [C4Movie movieNamed:@"inception.mov"];
image = [C4Image imageNamed:@"C4Sky"];
gl = [C4GL glWithFrame:CGRectMake(0, 0, 600, 400)];
// camera = [C4Camera cameraWithFrame:shape.frame];
label = [C4Label labelWithText:@"A Label"];
button = [C4Button buttonWithType:ROUNDEDRECT];
slider = [C4Slider slider:CGRectMake(0, 0, 128, 44)];
stepper = [C4Stepper stepper];
onOffSwitch = [C4Switch switch];
scrollView = [C4ScrollView scrollView:CGRectMake(0, 0, 128, 96)];
allObjects = @[shape,
movie,
image,
gl,
// camera,
label,
button,
slider,
stepper,
onOffSwitch,
scrollView];
}
-(void)setupObjects {
movie.height = shape.height;
image.height = movie.height;
gl.frame = CGRectMake(0, 0, 150, 100);
// camera.frame = shape.frame;
// [camera initCapture];
[label sizeToFit];
C4Image *table = [C4Image imageNamed:@"C4Table"];
[scrollView addImage:table];
scrollView.contentSize = table.bounds.size;
}
-(void)positionObjects {
CGPoint currentCenter = CGPointMake(self.canvas.center.x, 20);
for (int i = 0; i < [allObjects count]; i++) {
C4Control *obj = (C4Control *)allObjects[i];
currentCenter.y += obj.height / 2.0f;
obj.center = currentCenter;
currentCenter.y += obj.height/2.0 + 10;
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment