Commit | Line | Data |
---|---|---|
ef79bbde P |
1 | #import "PluginConfigController.h" |
2 | #include "gpu.h" | |
3 | #include "cfg.h" | |
4 | #include "menu.h" | |
5 | #include "externals.h" | |
6 | ||
7 | #define APP_ID @"net.sf.peops.SoftGpuGLPlugin" | |
8 | #define PrefsKey APP_ID @" Settings" | |
9 | ||
10 | static PluginConfigController *windowController; | |
11 | char * pConfigFile=NULL; | |
12 | ||
13 | void AboutDlgProc() | |
14 | { | |
15 | // Get parent application instance | |
16 | NSApplication *app = [NSApplication sharedApplication]; | |
17 | NSBundle *bundle = [NSBundle bundleWithIdentifier:APP_ID]; | |
18 | ||
19 | // Get Credits.rtf | |
20 | NSString *path = [bundle pathForResource:@"Credits" ofType:@"rtf"]; | |
21 | NSAttributedString *credits; | |
22 | if (path) { | |
23 | credits = [[[NSAttributedString alloc] initWithPath: path | |
24 | documentAttributes:NULL] autorelease]; | |
25 | } else { | |
26 | credits = [[[NSAttributedString alloc] initWithString:@""] autorelease]; | |
27 | } | |
28 | ||
29 | // Get Application Icon | |
30 | NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:[bundle bundlePath]]; | |
31 | NSSize size = NSMakeSize(64, 64); | |
32 | [icon setSize:size]; | |
33 | ||
34 | [app orderFrontStandardAboutPanelWithOptions:[NSDictionary dictionaryWithObjectsAndKeys: | |
35 | [bundle objectForInfoDictionaryKey:@"CFBundleName"], @"ApplicationName", | |
36 | icon, @"ApplicationIcon", | |
37 | [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"], @"ApplicationVersion", | |
38 | [bundle objectForInfoDictionaryKey:@"CFBundleVersion"], @"Version", | |
39 | [bundle objectForInfoDictionaryKey:@"NSHumanReadableCopyright"], @"Copyright", | |
40 | credits, @"Credits", | |
41 | nil]]; | |
42 | } | |
43 | ||
44 | ||
45 | void SoftDlgProc() | |
46 | { | |
47 | NSWindow *window; | |
48 | ||
49 | if (windowController == nil) { | |
50 | windowController = [[PluginConfigController alloc] initWithWindowNibName:@"NetSfPeopsSoftGPUConfig"]; | |
51 | } | |
52 | window = [windowController window]; | |
53 | ||
54 | /* load values */ | |
55 | [windowController loadValues]; | |
56 | ||
57 | [window center]; | |
58 | [window makeKeyAndOrderFront:nil]; | |
59 | } | |
60 | ||
61 | void ReadConfig(void) | |
62 | { | |
63 | NSDictionary *keyValues; | |
64 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
65 | [defaults registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys: | |
66 | [[NSMutableDictionary alloc] initWithObjectsAndKeys: | |
67 | [NSNumber numberWithBool:NO], @"FPS Counter", | |
68 | [NSNumber numberWithBool:NO], @"Auto Full Screen", | |
69 | [NSNumber numberWithBool:NO], @"Frame Skipping", | |
70 | [NSNumber numberWithBool:YES], @"Frame Limit", | |
71 | [NSNumber numberWithBool:NO], @"VSync", | |
72 | [NSNumber numberWithBool:NO], @"Enable Hacks", | |
73 | [NSNumber numberWithInt:1], @"Dither Mode", | |
74 | [NSNumber numberWithLong:0], @"Hacks", | |
75 | nil], PrefsKey, | |
76 | nil]]; | |
77 | ||
78 | keyValues = [defaults dictionaryForKey:PrefsKey]; | |
79 | ||
80 | iShowFPS = [[keyValues objectForKey:@"FPS Counter"] boolValue]; | |
81 | iWindowMode = [[keyValues objectForKey:@"Auto Full Screen"] boolValue] ? 0 : 1; | |
82 | UseFrameSkip = [[keyValues objectForKey:@"Frame Skipping"] boolValue]; | |
83 | UseFrameLimit = [[keyValues objectForKey:@"Frame Limit"] boolValue]; | |
84 | //??? = [[keyValues objectForKey:@"VSync"] boolValue]; | |
85 | iUseFixes = [[keyValues objectForKey:@"Enable Hacks"] boolValue]; | |
86 | ||
87 | iUseDither = [[keyValues objectForKey:@"Dither Mode"] intValue]; | |
88 | dwCfgFixes = [[keyValues objectForKey:@"Hacks"] longValue]; | |
89 | ||
90 | iResX = 640; | |
91 | iResY = 480; | |
92 | iUseNoStretchBlt = 1; | |
93 | ||
94 | fFrameRate = 60; | |
95 | iFrameLimit = 2; | |
96 | ||
97 | if (iShowFPS) | |
98 | ulKeybits|=KEY_SHOWFPS; | |
99 | else | |
100 | ulKeybits&=~KEY_SHOWFPS; | |
101 | ||
102 | // additional checks | |
103 | if(!iColDepth) iColDepth=32; | |
104 | if(iUseFixes) dwActFixes=dwCfgFixes; | |
105 | else dwActFixes=0; | |
106 | SetFixes(); | |
107 | ||
108 | if(iFrameLimit==2) SetAutoFrameCap(); | |
109 | bSkipNextFrame = FALSE; | |
110 | ||
111 | szDispBuf[0]=0; | |
112 | BuildDispMenu(0); | |
113 | } | |
114 | ||
115 | @implementation PluginConfigController | |
116 | ||
117 | - (IBAction)cancel:(id)sender | |
118 | { | |
119 | [self close]; | |
120 | } | |
121 | ||
122 | - (IBAction)ok:(id)sender | |
123 | { | |
124 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
125 | ||
126 | NSMutableDictionary *writeDic = [NSMutableDictionary dictionaryWithDictionary:keyValues]; | |
127 | [writeDic setObject:[NSNumber numberWithInt:[fpsCounter intValue]] forKey:@"FPS Counter"]; | |
128 | [writeDic setObject:[NSNumber numberWithInt:[autoFullScreen intValue]] forKey:@"Auto Full Screen"]; | |
129 | [writeDic setObject:[NSNumber numberWithInt:[frameSkipping intValue]] forKey:@"Frame Skipping"]; | |
130 | //[writeDic setObject:[NSNumber numberWithInt:[frameLimit intValue]] forKey:@"Frame Limit"]; | |
131 | [writeDic setObject:[NSNumber numberWithInt:[vSync intValue]] forKey:@"VSync"]; | |
132 | [writeDic setObject:[NSNumber numberWithInt:[hackEnable intValue]] forKey:@"Enable Hacks"]; | |
133 | ||
134 | [writeDic setObject:[NSNumber numberWithInt:[ditherMode indexOfSelectedItem]] forKey:@"Dither Mode"]; | |
135 | ||
136 | unsigned long hackValues = 0; | |
137 | int i; | |
138 | NSArray *views = [hacksView subviews]; | |
139 | for (i=0; i<[views count]; i++) { | |
140 | NSView *control = [views objectAtIndex:i]; | |
141 | if ([control isKindOfClass:[NSButton class]]) { | |
142 | hackValues |= [(NSControl *)control intValue] << ([control tag] - 1); | |
143 | } | |
144 | } | |
145 | ||
146 | [writeDic setObject:[NSNumber numberWithLong:hackValues] forKey:@"Hacks"]; | |
147 | ||
148 | // write to defaults | |
149 | [defaults setObject:writeDic forKey:PrefsKey]; | |
150 | [defaults synchronize]; | |
151 | ||
152 | // and set global values accordingly | |
153 | ReadConfig(); | |
154 | ||
155 | [self close]; | |
156 | } | |
157 | ||
158 | - (IBAction)reset:(id)sender | |
159 | { | |
160 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
161 | [defaults removeObjectForKey:PrefsKey]; | |
162 | [self loadValues]; | |
163 | } | |
164 | ||
165 | - (IBAction)hackToggle:(id)sender | |
166 | { | |
167 | BOOL enable = [sender intValue] ? YES : NO; | |
168 | int i; | |
169 | NSArray *views = [hacksView subviews]; | |
170 | ||
171 | for (i=0; i<[views count]; i++) { | |
172 | NSView *control = [views objectAtIndex:i]; | |
173 | if ([control isKindOfClass:[NSButton class]]) { | |
174 | [(NSControl *)control setEnabled:enable]; | |
175 | } | |
176 | } | |
177 | } | |
178 | ||
179 | - (void)loadValues | |
180 | { | |
181 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
182 | ||
183 | ReadConfig(); | |
184 | ||
185 | /* load from preferences */ | |
186 | [keyValues release]; | |
187 | keyValues = [[defaults dictionaryForKey:PrefsKey] retain]; | |
188 | ||
189 | [fpsCounter setIntValue:[[keyValues objectForKey:@"FPS Counter"] intValue]]; | |
190 | [autoFullScreen setIntValue:[[keyValues objectForKey:@"Auto Full Screen"] intValue]]; | |
191 | [frameSkipping setIntValue:[[keyValues objectForKey:@"Frame Skipping"] intValue]]; | |
192 | [vSync setIntValue:[[keyValues objectForKey:@"VSync"] intValue]]; | |
193 | [hackEnable setIntValue:[[keyValues objectForKey:@"Enable Hacks"] intValue]]; | |
194 | ||
195 | [ditherMode selectItemAtIndex:[[keyValues objectForKey:@"Dither Mode"] intValue]]; | |
196 | ||
197 | unsigned long hackValues = [[keyValues objectForKey:@"Hacks"] longValue]; | |
198 | ||
199 | int i; | |
200 | NSArray *views = [hacksView subviews]; | |
201 | for (i=0; i<[views count]; i++) { | |
202 | NSView *control = [views objectAtIndex:i]; | |
203 | if ([control isKindOfClass:[NSButton class]]) { | |
204 | [(NSControl *)control setIntValue:(hackValues >> ([control tag] - 1)) & 1]; | |
205 | } | |
206 | } | |
207 | ||
208 | [self hackToggle:hackEnable]; | |
209 | } | |
210 | ||
211 | - (void)awakeFromNib | |
212 | { | |
213 | hacksView = [[hacksView subviews] objectAtIndex:0]; | |
214 | } | |
215 | ||
216 | @end |