-
Notifications
You must be signed in to change notification settings - Fork 1
/
AppController.j
709 lines (599 loc) · 24.5 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
/*
* Created by Gerrit Riessen
* Copyright 2010-2011, Gerrit Riessen
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@import <Foundation/CPObject.j>
@import <AppKit/CPColor.j>
@import <GRKit/GRKit.j>
@import <GRKit/g_r_color_stop_picker.j>
@import "app/app.j"
@import "app/monkeypatch.j"
@import "app/svg_cg_context.j"
GRMaxColorStop = 6;
PatternDoLoopAnimationNotification = "PatternDoLoopAnimationNotification";
PatternStopAnimationNotification = "PatternStopAnimationNotification";
PatternDoStoreAnimationNotification = "PatternDoStoreAnimationNotification";
StoringZipFileNotification = "StoringZipFileNotification"
allPatternClasses = [PatternOne,
PatternEight,
PatternFifteen,
PatternTwentyFour,
PatternTwo,
PatternFive,
PatternTen,
PatternSix,
PatternTwentySix,
PatternThirtyOne,
PatternFourtyNine,
PatternFourtyFive,
PatternSeventySix,
PatternThree,
PatternSeventyTwo,
PatternFour,
PatternFourtySeven,
PatternTwentyTwo,
PatternSeventySeven,
PatternNineteen,
PatternTwentyEight,
PatternSeven,
PatternNine,
PatternSeventyFive,
PatternEleven,
PatternTwenty,
PatternSixtySix,
PatternTwentyOne,
PatternSeventeen,
PatternFourty,
PatternTwelve,
PatternFourteen,
PatternSixtyThree,
PatternThirteen,
PatternEightyFour,
PatternTwentySeven,
PatternFourtyOne,
PatternSixteen,
PatternEighteen,
PatternThirtyNine,
PatternFourtyTwo,
PatternFiftyFour,
PatternFiftyFive,
PatternFiftySix,
PatternTwentyThree,
PatternFiftySeven,
PatternFiftyEight,
PatternThirtyFive,
PatternEightyFive,
PatternThirtySix,
PatternThirtySeven,
PatternFourtySix,
PatternFifty,
PatternThirty,
PatternThirtyEight,
PatternThirtyTwo,
PatternFourtyThree,
PatternSixty,
PatternTwentyFive,
PatternTwentyNine,
PatternEightyThree,
PatternThirtyThree,
PatternFourtyEight,
PatternThirtyFour,
PatternFiftyTwo,
PatternFiftyThree,
PatternSixtyOne,
PatternEightyOne,
PatternFiftyOne,
PatternSeventyNine,
PatternEighty,
PatternSeventy,
PatternSixtyTwo,
PatternFiftyNine,
PatternSeventyThree,
PatternSeventyEight,
PatternSixtyFive,
PatternSixtyFour,
PatternSeventyOne,
PatternSixtySeven,
PatternSixtyEight,
PatternEightyTwo,
PatternSixtyNine,
PatternSeventyFour,
PatternFourtyFour];
/*
These are used on a small display --> smaller cpu --> they display quicker.
>> egrep -o --color "0, \"recurse_depth\"" app/patterns/*.j
*/
var allPatternClassesNoRecursion = [PatternOne,
PatternTwo,
PatternFour,
PatternFive,
PatternSix,
PatternSeven,
PatternTen,
PatternEleven,
PatternTwelve,
PatternThirteen,
PatternFourteen,
PatternSeventeen,
PatternEighteen,
PatternTwenty,
PatternTwentyOne,
PatternTwentyTwo,
PatternTwentyThree,
PatternTwentyFive,
PatternTwentySeven,
PatternTwentyEight,
PatternThirty,
PatternThirtyTwo,
PatternThirtyThree,
PatternFourty,
PatternFourtyOne,
PatternFourtyThree,
PatternFourtyFour,
PatternFourtyFive,
PatternFiftyTwo,
PatternFiftyThree
];
@implementation AppController : CPObject
{
CPView contentView;
PatternView patternView;
PatternSettingsController propertiesController;
CPCollectionView patternListView;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero()
styleMask:CPBorderlessBridgeWindowMask];
contentView = [theWindow contentView];
var bounds = [contentView bounds];
[[CPNotificationCenter defaultCenter] addObserver:self
selector:@selector(resizeHandler:)
name:CPWindowDidResizeNotification
object:theWindow];
if ( bounds.size.width > 500 && bounds.size.height > 500 ) {
[self largeContentView:theWindow bounds:bounds];
} else {
[self smallContentView:theWindow bounds:bounds];
}
}
- (void)resizeHandler:(NSNotification)note
{
var helpButton = [m_toolBar items][5];
[helpButton setLabel:(([contentView bounds].size.width-200) + " x " +
([contentView bounds].size.height+1))];
[m_toolBar toolbarItemDidChange:helpButton];
}
@end
@implementation AppController (ContentViewSize)
- (void)largeContentView:(CPWindow)theWindow bounds:(CGRect)bounds
{
m_toolBar = [[CPToolbar alloc] initWithIdentifier:"PubEditor"];
[m_toolBar setDelegate:self];
[m_toolBar setVisible:true];
[theWindow setToolbar:m_toolBar];
var listScrollView = [[CPScrollView alloc]
initWithFrame:CGRectMake(0, 0, 200, CGRectGetHeight(bounds) - 58)];
[listScrollView setAutohidesScrollers:YES];
[listScrollView setAutoresizingMask:CPViewHeightSizable];
[[listScrollView contentView]
setBackgroundColor:[CPColor colorWithRed:213.0/255.0
green:221.0/255.0 blue:230.0/255.0 alpha:1.0]];
var photosListItem = [[CPCollectionViewItem alloc] init];
[photosListItem setView:[[PatternListCell alloc] initWithFrame:CGRectMakeZero()]];
patternListView = [[CPCollectionView alloc] initWithFrame:CGRectMake(0, 0, 200, 0)];
[patternListView setDelegate:self];
[patternListView setItemPrototype:photosListItem];
[patternListView setMinItemSize:CGSizeMake(15.0, 32.0)];
[patternListView setMaxItemSize:CGSizeMake(1000.0, 32.0)];
[patternListView setMaxNumberOfColumns:1];
[patternListView setVerticalMargin:0.0];
[patternListView setAutoresizingMask:CPViewWidthSizable];
[listScrollView setDocumentView:patternListView];
[patternListView setContent:allPatternClasses];
var showPatternIdx = 0;
var patternClass = [patternListView content][showPatternIdx];
try {
patternClass = eval("Pattern" + window.location.hash.substr(1,100));
showPatternIdx = allPatternClasses.indexOf(patternClass);
} catch ( e ) { }
var pattern = [[patternClass alloc]
initWithConfig:[patternClass defaultConfig]];
[patternListView
setSelectionIndexes:[CPIndexSet indexSetWithIndex:showPatternIdx]];
var rect = CGRectMake(200,0,bounds.size.width - 200, bounds.size.height - 58);
patternView = [[PatternView alloc] initWithFrame:rect];
[patternView setNeedsDisplay:YES];
[patternView setPattern:pattern];
[contentView addSubview:listScrollView];
[contentView addSubview:patternView];
[theWindow orderFront:self];
[AboutPatternsDelegate popupAlertAndHideAfter:12];
}
- (void)smallContentView:(CPWindow)theWindow bounds:(CGRect)bounds
{
var showSlideShow = true;
var patternClass = PatternTwentyEight;
try {
patternClass = eval("Pattern" + window.location.hash.substr(1,100));
showSlideShow = false;
} catch ( e ) { }
var pattern = [[patternClass alloc]
initWithConfig:[patternClass defaultConfig]];
var rect = CGRectMake(0,0,bounds.size.width,bounds.size.height);
patternView = [[PatternView alloc] initWithFrame:rect];
[patternView setPattern:pattern];
[patternView setNeedsDisplay:YES];
[contentView addSubview:patternView];
[theWindow orderFront:self];
if ( showSlideShow ) {
[[PatternSlideShowTimer alloc] initWithPatternView:patternView];
}
}
@end
@implementation AppController (Helpers)
- (void) updateAnimateButton:(SEL)selector label:(CPString)label
{
var animateButton = [m_toolBar items][1];
[animateButton setAction:selector];
[animateButton setLabel:label];
[m_toolBar toolbarItemDidChange:animateButton];
}
- (void)checkForPropertiesController
{
if ( ! propertiesController ) {
propertiesController = [PatternSettingsController alloc];
[propertiesController initWithWindowCibName:"PatternSettings"
patternView:patternView];
}
[propertiesController showWindow:self];
}
- (void)setupToolbarItem:(CPToolbarItem)toolbarItem
selector:(SEL)selector
label:(CPString)label
{
[toolbarItem setLabel:label];
[toolbarItem setTarget:self];
[toolbarItem setAction:selector];
[toolbarItem setMinSize:CGSizeMake(32, 32)];
[toolbarItem setMaxSize:CGSizeMake(32, 32)];
}
@end
@implementation AppController (Actions)
- (CPAction)createRandom:(id)sender
{
var shaObj = new jsSHA("SHA-512", "TEXT");
shaObj.update(""+Math.random());
var hexstr = shaObj.getHash("HEX");
var showPatternIdx =
parseInt(hexstr.substr(0,2),16) % allPatternClasses.length;
var patternClass = [patternListView content][showPatternIdx];
var cfg = [patternClass defaultConfig];
[cfg setObject:(parseInt(hexstr.substr(2,2),16)%200)+20 forKey:"radius"];
[cfg setObject:colorFromString(hexstr, 4) forKey:"background_color"];
[cfg setObject:[colorFromString(hexstr, 12),
colorFromString(hexstr, 20),
colorFromString(hexstr, 28),
colorFromString(hexstr, 36),
colorFromString(hexstr, 44),
colorFromString(hexstr, 52)] forKey:"stroke_colors"];
[cfg setObject:[colorFromString(hexstr, 60),
colorFromString(hexstr, 68),
colorFromString(hexstr, 76),
colorFromString(hexstr, 84),
colorFromString(hexstr, 92),
colorFromString(hexstr, 100)] forKey:"fill_colors"];
[cfg setObject:parseInt(hexstr.substr(108,3),16)%360 forKey:"rotation"];
[cfg setObject:parseInt(hexstr.substr(111,1),16)%2 forKey:"recurse_depth"];
[cfg setObject:(parseInt(hexstr.substr(112,2),16)%40)+1
forKey:"number_of_points"];
[cfg setObject:parseInt(hexstr.substr(114,2),16)/255.0
forKey:"factor_larger"];
[cfg setObject:parseInt(hexstr.substr(116,1),16)>8 forKey:"show_shapes"];
[patternListView
setSelectionIndexes:[CPIndexSet indexSetWithIndex:showPatternIdx]];
[patternView setNeedsDisplay:YES];
[patternView setPattern:[[patternClass alloc] initWithConfig:cfg]];
}
- (CPAction)dumpConfig:(id)sender
{
alert([[patternView pattern] newPattern]);
CPLogConsole("Config: " + [[patternView pattern] newPattern]);
}
- (CPAction)saveToSvg:(id)sender
{
try {
var ctxt = new SvgCgContext([patternView bounds].size.width,
[patternView bounds].size.height);
var pattern = [patternView pattern];
ctxt.rotate = [pattern rotation];
ctxt.bgColor = [pattern bgColor];
ctxt.bgColorDir = [pattern bgColorDirection];
ctxt.title = [pattern className];
ctxt.description = ("Generated using the following configuration:\n"+
[pattern newPattern]);
ctxt.canvas = { clientHeight: [patternView bounds].size.height,
clientWidth: [patternView bounds].size.width };
ctxt.__cpt_of_image__ =
[GRPoint pointWithX:[patternView bounds].size.width/2
Y:[patternView bounds].size.height/2];
[pattern draw:ctxt];
var zip_file = new JSZip();
var zip_generate_options = {
type:"base64",
compression: "DEFLATE",
compressionOptions: { level: 9 }
}
zip_file.file("pattern.svg", ctxt.svg);
zip_file.generateAsync(zip_generate_options).then(function(content) {
window.location = "data:application/zip;base64," + content
});
} catch ( e ) {
console.log(e);
}
}
- (CPAction)viewAsSvg:(id)sender
{
try {
var ctxt = new SvgCgContext([patternView bounds].size.width,
[patternView bounds].size.height);
var pattern = [patternView pattern];
ctxt.rotate = [pattern rotation];
ctxt.bgColor = [pattern bgColor];
ctxt.bgColorDir = [pattern bgColorDirection];
ctxt.title = [pattern className];
ctxt.description = ("Generated using the following configuration:\n"+
[pattern newPattern]);
ctxt.canvas = { clientHeight: [patternView bounds].size.height,
clientWidth: [patternView bounds].size.width };
ctxt.__cpt_of_image__ =
[GRPoint pointWithX:[patternView bounds].size.width/2
Y:[patternView bounds].size.height/2];
[pattern draw:ctxt];
// application/octet-stream ==> download link
// image/svg+xml ==> view in browser
var uriContent =
"data:image/svg+xml," + encodeURIComponent(ctxt.svg);
window.open(uriContent, [pattern className] + ".svg");
} catch ( e ) {
console.log(e);
}
}
- (CPAction)aboutPatterns:(id)sender
{
[AboutPatternsDelegate popupAlert:patternView];
}
- (CPAction)showProperties:(id)sender
{
[self checkForPropertiesController];
}
- (CPAction)stopAnimation:(id)sender
{
[self updateAnimateButton:@selector(doAnimation:) label:"Animate"];
[[CPNotificationCenter defaultCenter]
postNotificationName:PatternStopAnimationNotification
object:nil];
}
- (CPAction)doAnimation:(id)sender
{
[self checkForPropertiesController];
[self updateAnimateButton:@selector(stopAnimation:) label:"Stop Animation"];
[[CPNotificationCenter defaultCenter]
postNotificationName:PatternDoLoopAnimationNotification
object:nil];
}
- (void)resetAnimateButton:(CPNotification)aNotification
{
[self updateAnimateButton:@selector(doAnimation:) label:"Animate"];
[[CPNotificationCenter defaultCenter]
removeObserver:self
name:StoringZipFileNotification
object:nil];
}
- (CPAction)animationSaveAsZip:(id)sender
{
[self checkForPropertiesController];
[self updateAnimateButton:@selector(stopAnimation:) label:"Stop Animation"];
[[CPNotificationCenter defaultCenter]
addObserver:self
selector:@selector(resetAnimateButton:)
name:StoringZipFileNotification
object:nil];
[[CPNotificationCenter defaultCenter]
postNotificationName:PatternDoStoreAnimationNotification
object:nil];
}
@end
@implementation AppController (ToolbarDelegate)
- (CPArray)toolbarAllowedItemIdentifiers:(CPToolbar)aToolbar
{
return [self toolbarDefaultItemIdentifiers:aToolbar];
}
- (CPArray)toolbarDefaultItemIdentifiers:(CPToolbar)aToolbar
{
return ["Properties", "Animate", "Random",
CPToolbarFlexibleSpaceItemIdentifier,
"AnimAsZip", "ViewAsSvg","SaveSvg", "StoreConfig", "AboutPatterns"];
}
- (CPToolbarItem)toolbar:(CPToolbar)aToolbar
itemForItemIdentifier:(CPString)anItemIdentifier
willBeInsertedIntoToolbar:(BOOL)aFlag
{
var toolbarItem = [[CPToolbarItem alloc]
initWithItemIdentifier:anItemIdentifier],
image = nil,
highlighted = nil;
switch ( anItemIdentifier ) {
case "AboutPatterns":
image = [[CPImage alloc] initWithContentsOfFile:"Resources/help.png" size:CPSizeMake(32, 32)];
highlighted = [[CPImage alloc] initWithContentsOfFile:"Resources/help_highlight.png" size:CPSizeMake(32, 32)];
[self setupToolbarItem:toolbarItem
selector:@selector(aboutPatterns:)
label:"About"];
break;
case "Properties":
image = [[CPImage alloc] initWithContentsOfFile:"Resources/property_32.png" size:CPSizeMake(32, 32)];
highlighted = [[CPImage alloc] initWithContentsOfFile:"Resources/property_32_high.png" size:CPSizeMake(32, 32)];
[self setupToolbarItem:toolbarItem
selector:@selector(showProperties:)
label:"Properties"];
break;
case "Random":
image = [[CPImage alloc] initWithContentsOfFile:"Resources/help.png" size:CPSizeMake(32, 32)];
highlighted = [[CPImage alloc] initWithContentsOfFile:"Resources/help_highlight.png" size:CPSizeMake(32, 32)];
[self setupToolbarItem:toolbarItem
selector:@selector(createRandom:)
label:"Random"];
break;
case "Animate":
animateButton = toolbarItem;
image = [[CPImage alloc] initWithContentsOfFile:"Resources/animate.png" size:CPSizeMake(32, 32)];
highlighted = [[CPImage alloc] initWithContentsOfFile:"Resources/animate_high.png" size:CPSizeMake(32, 32)];
[self setupToolbarItem:toolbarItem
selector:@selector(doAnimation:)
label:"Animate"];
break;
case "StoreConfig":
image = [[CPImage alloc] initWithContentsOfFile:"Resources/add.png" size:CPSizeMake(30, 25)];
highlighted = [[CPImage alloc] initWithContentsOfFile:"Resources/addHigh.png" size:CPSizeMake(30, 25)];
[self setupToolbarItem:toolbarItem
selector:@selector(dumpConfig:)
label:"Show Config"];
break;
case "SaveSvg":
image = [[CPImage alloc] initWithContentsOfFile:"Resources/export.png" size:CPSizeMake(32, 32)];
highlighted = [[CPImage alloc] initWithContentsOfFile:"Resources/export_high.png" size:CPSizeMake(32, 32)];
[self setupToolbarItem:toolbarItem
selector:@selector(saveToSvg:)
label:"SVG Export"];
break;
case "ViewAsSvg":
image = [[CPImage alloc] initWithContentsOfFile:"Resources/export.png" size:CPSizeMake(32, 32)];
highlighted = [[CPImage alloc] initWithContentsOfFile:"Resources/export_high.png" size:CPSizeMake(32, 32)];
[self setupToolbarItem:toolbarItem
selector:@selector(viewAsSvg:)
label:"View SVG"];
break;
case "AnimAsZip":
image = [[CPImage alloc] initWithContentsOfFile:"Resources/export.png" size:CPSizeMake(32, 32)];
highlighted = [[CPImage alloc] initWithContentsOfFile:"Resources/export_high.png" size:CPSizeMake(32, 32)];
[self setupToolbarItem:toolbarItem
selector:@selector(animationSaveAsZip:)
label:"Anim. As Zip"];
break;
}
[toolbarItem setImage:image];
[toolbarItem setAlternateImage:highlighted];
return toolbarItem;
}
@end
@implementation AppController (CollectionViewDelegate)
- (void)collectionViewDidChangeSelection:(CPCollectionView)aCollectionView
{
var listIndex = [[aCollectionView selectionIndexes] firstIndex],
key = [aCollectionView content][listIndex];
var pattern = [[key alloc] initWithConfig:[key defaultConfig]];
[patternView setPattern:pattern];
[patternView redisplay];
if ( propertiesController ) {
[propertiesController close];
propertiesController = null;
}
}
@end
@implementation PatternSlideShowTimer : CPObject
{
PatternView m_pattern_view;
CPInvocation m_loadPatternInvoker;
}
- (id)initWithPatternView:(PatternView)aPatternView
{
self = [super init];
if ( self ) {
m_loadPatternInvoker = [[CPInvocation alloc] initWithMethodSignature:nil];
[m_loadPatternInvoker setTarget:self];
[m_loadPatternInvoker setSelector:@selector(showNewPattern)];
[self doneDrawingPattern];
m_pattern_view = aPatternView;
[m_pattern_view setDoneDrawDelegate:self];
}
return self;
}
- (void)doneDrawingPattern
{
[CPTimer scheduledTimerWithTimeInterval:5
invocation:m_loadPatternInvoker
repeats:NO];
}
- (void)showNewPattern
{
var curr_index = [allPatternClassesNoRecursion indexOfObject:[[m_pattern_view pattern] class]],
new_index = (curr_index + 1 ) % [allPatternClassesNoRecursion count],
pattern_class = allPatternClassesNoRecursion[new_index],
new_pattern = [[pattern_class alloc] initWithConfig:[pattern_class defaultConfig]];
[m_pattern_view setPattern:new_pattern];
[m_pattern_view redisplay];
}
@end
@implementation AboutPatternsDelegate : CPObject
+ (void)closeWindow:(id)alertWindow
{
[CPApp stopModal];
[[alertWindow window] close];
}
+ (void)popupAlertAndHideAfter:(int)anInterval
{
var alertObj = [AboutPatternsDelegate popupAlert];
var loadPageInvoker = [[CPInvocation alloc] initWithMethodSignature:nil];
[loadPageInvoker setTarget:self];
[loadPageInvoker setSelector:@selector(closeWindow:)];
[loadPageInvoker setArgument:alertObj atIndex:2];
[CPTimer scheduledTimerWithTimeInterval:anInterval
invocation:loadPageInvoker
repeats:NO];
}
+ (CPAlert)popupAlert:(CPView)patternview
{
var delegate = [[AboutPatternsDelegate alloc] init],
alert = [[CPAlert alloc] init];
var bounds = ("Image Size: " + [patternview bounds].size.width + " x " +
[patternview bounds].size.height);
[alert setMessageText:("Islamic Patterns and their generation using basic geometry.\n\nPattern property can be used to modify patterns but all changes are automagically reset. Property to console will send a copy of the properties to the console (developers only).\n\nCappuccino was used as UI framework. Code and page hosting provided by Github.\n\nNOTE: Depending on you browser, patterns may take some time to display.\n\nNOTE 2: IE will not work, IE only supports 1 bit alpha channel on colors and only rotations of 90,180 or 270 degrees are supported.\n\nCopyright (C) 2011-2018 Gerrit Riessen\n\n" + bounds)];
[alert setTitle:@"About Circle Patterns"];
[alert setAlertStyle:CPInformationalAlertStyle];
[alert setDelegate:delegate];
[alert addButtonWithTitle:@"OK"];
[alert addButtonWithTitle:@"Preview"];
[alert addButtonWithTitle:@"Book"];
[alert addButtonWithTitle:@"Cappuccino"];
[alert runModal];
return alert;
}
-(void)alertDidEnd:(CPAlert)theAlert returnCode:(int)returnCode
{
switch ( returnCode ) {
case 1:
window.open("https://github.com/gorenje/capp_patterns/blob/master/preview.md", "newwindow", '');
break;
case 2:
window.open("https://www.ribabookshops.com/item/islamic-patterns-an-analytical-and-cosmological-approach/929/",'book','');
break;
case 3:
window.open("http://www.cappuccino-project.org",'capp','');
break;
}
}
@end