forked from luddep/LPKit-Examples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AppController.j
151 lines (118 loc) · 5.18 KB
/
AppController.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* AppController.j
* LPKit
*
* Created by Ludwig Pettersson on October 12, 2009.
*/
@import <Foundation/CPObject.j>
@import <LPKit/LPKit.j>
@import "ControlsAndViewsView.j"
@import "ChartsView.j"
LPAristo = nil;
var repositoryURL = @"http://github.com/luddep/LPKit";
@implementation AppController : CPObject
{
CPWindow theWindow;
CPSegmentedControl navigation;
LPSlideView slideView;
id controlsAndViewsView;
id chartsView;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask];
[theWindow setAcceptsMouseMovedEvents:YES];
[theWindow orderFront:self];
var lpAristoTheme = [[CPThemeBlend alloc] initWithContentsOfURL:@"LPAristo/Build/Debug/LPAristo.blend"];
[lpAristoTheme loadWithDelegate:self];
}
- (void)blendDidFinishLoading:(CPBundle)aBundle
{
LPAristo = [CPTheme themeNamed:@"LPAristo"];
//[CPTheme setDefaultTheme:[CPTheme themeNamed:@"LPAristo"]];
var contentView = [theWindow contentView],
bounds = [contentView bounds];
[contentView setBackgroundColor:[CPColor colorWithHexString:@"eee"]];
var title = [CPTextField labelWithTitle:@"LPKit Examples"];
[title setFont:[CPFont systemFontOfSize:25]];
[title setTextColor:[CPColor colorWithWhite:0 alpha:0.8]];
[title setTextShadowColor:[CPColor whiteColor]];
[title setTextShadowOffset:CGSizeMake(1,1)];
[title setFrameOrigin:CGPointMake(100,30)];
[title sizeToFit];
[contentView addSubview:title];
var description = [CPTextField labelWithTitle:@"A demo application showing (most) of LPKit."];
[description setFont:[CPFont boldSystemFontOfSize:12]];
[description setTextColor:[CPColor colorWithWhite:0 alpha:0.4]];
[description setTextShadowColor:[CPColor whiteColor]];
[description setTextShadowOffset:CGSizeMake(1,1)];
[description setFrameOrigin:CGPointMake(100, CGRectGetMaxY([title frame]))];
[description sizeToFit];
[contentView addSubview:description];
var githubLink = [LPAnchorButton buttonWithTitle:repositoryURL];
[githubLink setTextColor:[CPColor colorWithWhite:0 alpha:0.3]];
[githubLink setTextHoverColor:[CPColor colorWithWhite:0 alpha:0.6]];
[githubLink setFrameOrigin:CGPointMake(100, CGRectGetMaxY([description frame]) + 2)];
[githubLink openURLOnClick:[CPURL URLWithString:repositoryURL]]
[contentView addSubview:githubLink];
var box = [[CPBox alloc] initWithFrame:CGRectMake(100, 120, CGRectGetWidth(bounds) - 200, CGRectGetHeight(bounds) - 240)];
[box setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[[box contentView] setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[box setCornerRadius:2.0];
[box setBorderType:CPLineBorder];
[box setBorderColor:[CPColor colorWithWhite:0 alpha:0.2]];
[box setBackgroundColor:[CPColor whiteColor]];
[contentView addSubview:box];
// Navigation controller
navigation = [[CPSegmentedControl alloc] initWithFrame:CGRectMake(0,0, 0, 28)];
[navigation setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin];
[navigation setSegmentCount:2];
[navigation setWidth:120.0 forSegment:0];
[navigation setLabel:@"Views & Controls" forSegment:0];
[navigation setTag:@"views" forSegment:0];
[navigation setWidth:60.0 forSegment:1];
[navigation setLabel:@"Charts" forSegment:1];
[navigation setTag:@"charts" forSegment:1];
[navigation setTarget:self];
[navigation setAction:@selector(didClickNavigation:)];
[navigation setCenter:CGPointMake(CGRectGetMidX(bounds), CGRectGetMinY([box frame]))];
[contentView addSubview:navigation];
var boxBounds = [[box contentView] bounds];
slideView = [[LPSlideView alloc] initWithFrame:boxBounds];
[slideView setAnimationCurve:CPAnimationEaseInOut];
[slideView setAnimationDuration:0.5];
[slideView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[[box contentView] addSubview:slideView];
controlsAndViewsView = [[ControlsAndViewsView alloc] initWithFrame:boxBounds];
[slideView addSubview:controlsAndViewsView];
chartsView = [[ChartsView alloc] initWithFrame:boxBounds];
[slideView addSubview:chartsView];
// Register for location changes
[[LPLocationController sharedLocationController] addObserver:self selector:@selector(locationDidChange:)];
}
- (void)didClickNavigation:(id)sender
{
var tag = [sender selectedTag];
// Update location
[[LPLocationController sharedLocationController] setLocation:tag];
[self selectedNavigationItemWithTag:tag];
}
- (void)locationDidChange:(CPString)aLocation
{
[self selectedNavigationItemWithTag:aLocation];
}
- (void)selectedNavigationItemWithTag:(CPString)aTag
{
// Default tag, aTag might be empty
if (!aTag)
aTag = @"views";
[navigation selectSegmentWithTag:aTag];
switch (aTag)
{
case @"views": [slideView slideToView:controlsAndViewsView];
break;
case @"charts": [slideView slideToView:chartsView];
break;
}
}
@end