Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 221 lines (188 sloc) 9.47 kb
dbea4c3 @ByteProject daddy hacked together a test app!
ByteProject authored
1 //
2 // ALAppDelegate.m
3 // AnsiLoveGUI
4 //
5 // Test app for the AnsiLove.framework
6 //
5bc9363 @ByteProject updated to work with our current framework changes
ByteProject authored
7 // Copyright (c) 2011-2012, Stefan Vogt. All rights reserved.
dbea4c3 @ByteProject daddy hacked together a test app!
ByteProject authored
8 // http://byteproject.net
9 //
89a0c77 @ByteProject removed GPL branding, reference to the new MIT-style license
ByteProject authored
10 // Use of this source code is governed by a MIT-style license.
11 // See the file LICENSE for details.
12 //
c5a4984 @ByteProject reference to the GPL v3 in all project files
ByteProject authored
13
dbea4c3 @ByteProject daddy hacked together a test app!
ByteProject authored
14 #import "ALAppDelegate.h"
15
16 @implementation ALAppDelegate
17
a732847 @ByteProject Revert "Revert 48b6f810104071f9c33bc907b5345d5afba7e398^..HEAD"
ByteProject authored
18 @synthesize window = _window, inputField, outputField, columnsField, fontsField, bitsField,
19 iceColorsCheck, columnsCheck, inputFile, outputFile, columns, font, bits, iceColors,
20 shouldUseIceColors, enableColumnsField;
dbea4c3 @ByteProject daddy hacked together a test app!
ByteProject authored
21
cb025a0 @ByteProject App Sandboxing related actions for user-defined opening / saving of file...
ByteProject authored
22 # pragma mark -
23 # pragma mark initialization
24
dbea4c3 @ByteProject daddy hacked together a test app!
ByteProject authored
25 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
26 {
a732847 @ByteProject Revert "Revert 48b6f810104071f9c33bc907b5345d5afba7e398^..HEAD"
ByteProject authored
27 // When the ANSi source does not make specific use of iCE colors,
28 // you should NOT set this flag. Also: NO is default in AnsiLove. Comprende?
29 self.shouldUseIceColors = NO;
30
31 // The property is bound to the enabled binding of the columnsField. If you check
32 // columns in the GUI, the field gets enabled and you can enter a column value.
e5b1883 @ByteProject bang...! now we have a working framework
ByteProject authored
33 // Note that this has NO educational purpose for the AnsiLove.framework, it's
a732847 @ByteProject Revert "Revert 48b6f810104071f9c33bc907b5345d5afba7e398^..HEAD"
ByteProject authored
34 // just a nice feature I recommend as the columns flag is only needed for .bin files.
35 self.enableColumnsField = NO;
a881ec5 @ByteProject sample code for the AnsiLoveFinishedRendering note
ByteProject authored
36
37 // AnsiLove.framework fires a notification once rendering of given ANSi source files
38 // completed. If this is relevant for your app (e.g. you can't load an instance of an
39 // image as long as it's not created) it should listen to AnsiLoveFinishedRendering.
40 // In this example app I've implemented a simple selector that just posts a message
41 // to NSLog once it recieved the finishedRendering note.
42 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
43 [nc addObserver:self
44 selector:@selector(postFinishedRenderingToLog:)
45 name:@"AnsiLoveFinishedRendering"
46 object:nil];
a732847 @ByteProject Revert "Revert 48b6f810104071f9c33bc907b5345d5afba7e398^..HEAD"
ByteProject authored
47 }
48
cb025a0 @ByteProject App Sandboxing related actions for user-defined opening / saving of file...
ByteProject authored
49 # pragma mark -
50 # pragma mark general actions
51
a732847 @ByteProject Revert "Revert 48b6f810104071f9c33bc907b5345d5afba7e398^..HEAD"
ByteProject authored
52 // This method gets invoked by the 'Generate' button. It collects all the content the user
53 // entered into the text fields and calls the framework. The synthesized string values above
54 // (inputFile, outputFile, columns, font and bits) are all bound to the corresponding
55 // value binding of the text field instances you can see in the UI.
56 - (IBAction)createPNGfromANSi:(id)sender
57 {
58 if (shouldUseIceColors == NO) {
59 // AnsiLove needs all flags as strings, that's why we can't pass the bool value
60 // (or any other integer) directly. You can do something like I did below.
61 self.iceColors = @"0";
62 }
63 else {
64 self.iceColors = @"1";
65 }
66
67 // Let's finally pass all we got to the AnsiLove.framework, it will do the rest.
68 // If you don't want to set a specific flag, like the font flag for example, just
69 // pass nil or an empty NSString like @"". Both will work and AnsiLove will use
70 // it's built-in default values for generating the output PNG.
71 [ALAnsiGenerator createPNGFromAnsiSource:self.inputFile
72 outputFile:self.outputFile
73 font:self.font
74 bits:self.bits
5bc9363 @ByteProject updated to work with our current framework changes
ByteProject authored
75 iceColors:self.iceColors
76 columns:self.columns];
a732847 @ByteProject Revert "Revert 48b6f810104071f9c33bc907b5345d5afba7e398^..HEAD"
ByteProject authored
77 }
78
a881ec5 @ByteProject sample code for the AnsiLoveFinishedRendering note
ByteProject authored
79 - (void)postFinishedRenderingToLog:(NSNotification *)notification
80 {
81 // This selector gets invoked once the AnsiLove.framework finished rendering.
82 NSLog(@"Rendering of the ANSi source file has finished.");
83 }
84
a732847 @ByteProject Revert "Revert 48b6f810104071f9c33bc907b5345d5afba7e398^..HEAD"
ByteProject authored
85 - (IBAction)clearColumnsField:(id)sender
86 {
87 // The method clears the columns field as soon as it get's disabled. That way
88 // we make sure that no content is passed when the columns flag is not needed.
89 if ([columnsField isEnabled] == NO) {
90 self.columns = @"";
91 }
dbea4c3 @ByteProject daddy hacked together a test app!
ByteProject authored
92 }
93
cb025a0 @ByteProject App Sandboxing related actions for user-defined opening / saving of file...
ByteProject authored
94 # pragma mark -
95 # pragma mark sandboxing related actions
96
41aa49b @ByteProject typo correction. Y U NO USE ALL LETTERS?
ByteProject authored
97 // Sandboxed applications require user interaction for opening and saving specific files.
cb025a0 @ByteProject App Sandboxing related actions for user-defined opening / saving of file...
ByteProject authored
98 // We register user-defined files via NSOpenPanel and NSSavePanel. Just entering a path
99 // into the corresponding textfield won't work. That's why the textfields for input and
100 // output are deactivated in AnsiLoveGUI. The user is forced to hit the button and thus
101 // authenticating the whole operation.
102
103 - (IBAction)userDefinedInputFile:(id)sender
104 {
105 NSOpenPanel *openPanel = [NSOpenPanel openPanel];
106
107 // Define a custom 'Open' button first.
108 [openPanel setPrompt:@"Set as Input"];
109
110 // We should limit the extensions available for open files to those supported by
111 // AnsiLove.framework... everything else just doesn't make any sense!
112 NSArray *reqInTypes = [NSArray arrayWithObjects:
113 @"nfo", @"diz", @"asc", @"xb", @"ans", @"idf", @"pcb", @"tnd",
114 @"adf", @"bin", nil];
115 [openPanel setAllowedFileTypes:reqInTypes];
116 [openPanel setAllowsOtherFileTypes:NO];
117
118 // A better title is appreciated!
119 [openPanel setTitle:@"Choose ANSI Source"];
120
121 if ([openPanel runModal] == NSOKButton)
122 {
123 // Get openPanel's URL and create a string from it. Remember to pass strings
124 // to AnsiLove.framework and no URLs.
125 NSURL *inputURL = [openPanel URL];
126 self.inputFile = [inputURL path];
738df64 @ByteProject Some basic testing code for ALSauceMachine
ByteProject authored
127
fbc4f4a @ByteProject now containing a great example how to use ALSauceMachine
ByteProject authored
128 // The following code will explain usage of ALSauceMachine, the framework's
129 // class for handling SAUCE records. Please refer to the documentation for
130 // general specifications of SAUCE. You may wonder why I put this in the
131 // inputFile method? SAUCE records not only contain release informations,
132 // they also contain (among other things) variables that define the data
133 // type, file type, flags. The flag property e.g. can tell you if an ANSi
134 // source uses iCE colors. So it's locical to put it somewhere before
135 // ALAnsiGenerator starts it's rendering process. Many informations you
136 // retrieve from SAUCE records can be passed as flags to ALAnsiGenerator.
137
138 // We create an instance of ALSauceMachine first.
46418b1 @ByteProject create an instance instead of invoking a class method
ByteProject authored
139 ALSauceMachine *sauce = [[ALSauceMachine alloc] init];
fbc4f4a @ByteProject now containing a great example how to use ALSauceMachine
ByteProject authored
140
141 // Now try read SAUCE information from our given file.
46418b1 @ByteProject create an instance instead of invoking a class method
ByteProject authored
142 [sauce readRecordFromFile:self.inputFile];
fbc4f4a @ByteProject now containing a great example how to use ALSauceMachine
ByteProject authored
143
144 // ALSauceMachine comes with some handy BOOL properties, an effective way
145 // for you to check what's going on after you instructed ALSauceMachine
146 // to read SAUCE from a file.
147
148 // The property 'fileHasRecord' will provide information if there is a
149 // SAUCE record in your file at all.
150 if (sauce.fileHasRecord == NO) {
151 // No record means there's no need to continue, we stop here.
152 NSLog(@"%@ does not contain a SAUCE record.\n", self.inputFile);
153 return;
154 }
155 else {
156 // In case ALSauceMachine found a record in your file, we go on.
157 NSLog(@"Found SAUCE record in file %@.\n", self.inputFile);
158
159 // We gonna display the SAUCE in NSLog, we also use the two
160 // properties 'fileHasComment' and 'fileHasFlags' for different
161 // NSLog output, depending on whether the file has comments or
162 // flags. ALSauceMachine already set this properties when it
163 // investigated the file you passed. Convenient, isn't it?
164 NSLog(@"id: %@\n", sauce.ID);
165 NSLog(@"version: %@\n", sauce.version);
166 NSLog(@"title: %@\n", sauce.title);
167 NSLog(@"author: %@\n", sauce.author);
168 NSLog(@"group: %@\n", sauce.group);
169 NSLog(@"date: %@\n", sauce.date);
170 NSLog(@"dataType: %ld\n", sauce.dataType);
171 NSLog(@"fileType: %ld\n", sauce.fileType);
172 NSLog(@"tinfo1: %ld\n", sauce.tinfo1);
173 NSLog(@"tinfo2: %ld\n", sauce.tinfo2);
174 NSLog(@"tinfo3: %ld\n", sauce.tinfo3);
175 NSLog(@"tinfo4: %ld\n", sauce.tinfo4);
176 if (sauce.fileHasComments == YES) {
177 NSLog(@"comments:%@\n", sauce.comments);
178 }
179 else {
180 NSLog(@"comments: no comments\n");
181 }
182 if (sauce.fileHasFlags == YES) {
183 NSLog(@"flags:%ld\n", sauce.flags);
184 }
185 else {
186 NSLog(@"flags: none\n");
187 }
188 }
cb025a0 @ByteProject App Sandboxing related actions for user-defined opening / saving of file...
ByteProject authored
189 }
190 }
191
192 - (IBAction)userDefinedOutputFile:(id)sender
193 {
194 NSSavePanel *savePanel = [NSSavePanel savePanel];
195
196 // We want a custom 'Save' button.
197 [savePanel setPrompt:@"Set as Output"];
198
199 // AnsiLove.framework generates PNG images from ANSi sources. The user should not
200 // be able to specify an extension other than PNG, hence we add a limitation.
201 NSArray *reqOutTypes = [NSArray arrayWithObjects:@"png", nil];
202 [savePanel setAllowedFileTypes:reqOutTypes];
203 [savePanel setAllowsOtherFileTypes:NO];
204
205 // Let's optionally see the PNG extension in savePanel.
206 [savePanel setCanSelectHiddenExtension:YES];
207
208 // There's some need for a better title (though not much better).
209 [savePanel setTitle:@"Save PNG"];
210
211 if ([savePanel runModal] == NSOKButton)
212 {
213 // We need a string, so get the path as string value from savepanel's URL.
214 // The string is now ready for passing to ALAnsiGenerator.
215 NSURL *outputURL = [savePanel URL];
216 self.outputFile = [outputURL path];
217 }
218 }
219
dbea4c3 @ByteProject daddy hacked together a test app!
ByteProject authored
220 @end
Something went wrong with that request. Please try again.