-
Notifications
You must be signed in to change notification settings - Fork 28
/
prefs.js
329 lines (271 loc) · 8.06 KB
/
prefs.js
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
'use strict';
const electron = require('electron');
const fonts = require('./fonts.js');
const formats = require('./formats.js');
const tablist = [ 'appear', 'terp' ];
var darklight_flag = false;
/* Set up the initial appearance of the window. This adjusts the controls
and the sample text, but does not send changes to the app (because there
have been no changes yet).
*/
function setup_with_prefs(prefs, isbound)
{
var sel, optel;
// Function-calling function because closures suck.
var setclick = function(val) {
$('#tabbutton-'+val).on('click', function(ev) {
set_tab(val);
ev.preventDefault();
});
}
for (var ix=0; ix<tablist.length; ix++) {
setclick(tablist[ix]);
}
set_tab('appear');
sel = $('#sel-color-theme');
sel.prop('disabled', false);
sel.empty();
for (var ix=0; ix<themelist.length; ix++) {
var theme = themelist[ix];
optel = $('<option>', { value:theme.key }).text(theme.label);
if (prefs.gamewin_colortheme == theme.key)
optel.prop('selected', true);
sel.append(optel);
}
sel.on('change', evhan_color_theme);
apply_color_theme(prefs.gamewin_colortheme);
sel = $('#sel-font');
sel.prop('disabled', false);
sel.empty();
for (var ix=0; ix<fontlist.length; ix++) {
var font = fontlist[ix];
optel = $('<option>', { value:font.key }).text(font.label);
if (prefs.gamewin_font == font.key)
optel.prop('selected', true);
sel.append(optel);
}
sel.on('change', evhan_font);
var inpel = $('#input-font');
if (prefs.gamewin_customfont)
inpel.val(prefs.gamewin_customfont);
inpel.on('change', evhan_font);
apply_font(prefs.gamewin_font, prefs.gamewin_customfont);
sel = $('#range-margin');
sel.attr('step', 1);
sel.attr('min', 0);
sel.attr('max', 7);
sel.on('input', evhan_margin_level);
sel.val(prefs.gamewin_marginlevel);
apply_margin_level(prefs.gamewin_marginlevel);
sel = $('#range-zoom');
sel.attr('step', 1);
sel.attr('min', -6);
sel.attr('max', 6);
sel.on('input', evhan_zoom_level);
sel.val(prefs.gamewin_zoomlevel);
apply_zoom_level(prefs.gamewin_zoomlevel);
if (!isbound) {
sel = $('#sel-glulx-terp');
sel.prop('disabled', false);
sel.empty();
for (var ix=0; ix<formats.formatmap['glulx'].engines.length; ix++) {
var engine = formats.formatmap['glulx'].engines[ix];
optel = $('<option>', { value:engine.id }).text(engine.name);
if (prefs.glulx_terp == engine.id)
optel.prop('selected', true);
sel.append(optel);
}
sel.on('change', evhan_glulx_terp);
}
else {
sel = $('#tabheader');
sel.hide();
}
}
function set_tab(val)
{
switch (val) {
case 'appear':
$('body').removeClass('CurrentTabTerp');
$('body').addClass('CurrentTabAppear');
break;
case 'terp':
$('body').removeClass('CurrentTabAppear');
$('body').addClass('CurrentTabTerp');
break;
default:
$('body').removeClass('CurrentTabAppear');
$('body').removeClass('CurrentTabTerp');
break;
}
}
/* The apply_... functions adjust the sample text in this window, but
do not directly affect the controls or send changes to the app.
A lot of this code is copied from apphooks.js. It has to be kept
in sync.
*/
var themelist = [
{ key:'lightdark', label:'System (Light/Dark)' },
{ key:'sepiaslate', label:'System (Sepia/Slate)' },
{ key:'light', label:'Light' },
{ key:'sepia', label:'Sepia' },
{ key:'slate', label:'Slate' },
{ key:'dark', label:'Dark' }
];
function apply_color_theme(val)
{
// System-reactive themes:
if (val == 'lightdark') {
val = (darklight_flag ? 'dark' : 'light');
}
else if (val == 'sepiaslate') {
val = (darklight_flag ? 'slate' : 'sepia');
}
var bodyel = $('.Sample');
bodyel.removeClass('SepiaTheme');
bodyel.removeClass('SlateTheme');
bodyel.removeClass('DarkTheme');
switch (val) {
case 'sepia':
bodyel.addClass('SepiaTheme');
break;
case 'slate':
bodyel.addClass('SlateTheme');
break;
case 'dark':
bodyel.addClass('DarkTheme');
break;
default:
/* Light theme is the default. */
break;
}
}
var fontlist = [
{ key:'lora', label:'Lora' },
{ key:'gentium', label:'Gentium Book' },
{ key:'georgia', label:'Georgia' },
{ key:'baskerville', label:'Libre Baskerville' },
{ key:'helvetica', label:'Helvetica' },
{ key:'sourcesanspro', label:'Source Sans Pro' },
{ key:'courier', label:'Courier' },
{ key:'custom', label:'Other Font...' }
];
function apply_font(fontkey, customfont)
{
var inpel = $('#input-font');
if (fontkey == 'custom') {
if (inpel.css('display') != 'inline-block') {
inpel.css('display', 'inline-block');
inpel.select();
inpel.focus();
}
}
else {
if (inpel.css('display') != 'none') {
inpel.css('display', 'none');
}
}
//### check if anything's changed
var fontline = fonts.get_fontline(fontkey, customfont);
var el = $('#fontcss');
if (!fontline) {
el.remove();
}
else {
if (!el.length) {
el = $('<style>', { id:'fontcss', type:'text/css' });
$('#bodycss').before(el);
}
var text = '.Sample { font-family: @@; }\n';
text = text.replace(/@@/g, fontline);
el.text(text);
}
}
function apply_margin_level(val)
{
var str = '0px ' + (5*val) + '%';
$('.SampleText').css({'margin':str});
var el = $('#display-margin');
var text = 'None';
if (val > 0)
text = (val*5) + '%';
el.text(text);
}
function apply_zoom_level(val)
{
var factor = 1;
if (val)
factor = Math.exp(val * 0.09531017980432493);
$('.SampleText').css({'font-size':factor+'em'});
var el = $('#display-zoom');
var text = 'Normal';
if (val > 0)
text = 'Zoom In ' + val;
else if (val < 0)
text = 'Zoom Out ' + (-val);
el.text(text);
}
function apply_darklight(val)
{
darklight_flag = val;
var el = $('body');
if (!darklight_flag) {
el.addClass('LightMode');
el.removeClass('DarkMode');
}
else {
el.addClass('DarkMode');
el.removeClass('LightMode');
}
var sel = $('#sel-color-theme');
var val = sel.val();
apply_color_theme(val);
}
/* The evhan_... functions respond to user manipulation of the controls.
They invoke apply_... to adjust the sample text, and then send a
pref update to the app. */
function evhan_color_theme()
{
var sel = $('#sel-color-theme');
var val = sel.val();
apply_color_theme(val);
electron.ipcRenderer.send('pref_color_theme', val);
}
function evhan_font()
{
var fontkey = $('#sel-font').val();
var customfont = $('#input-font').val();
apply_font(fontkey, customfont);
electron.ipcRenderer.send('pref_font', fontkey, customfont);
}
function evhan_margin_level()
{
var sel = $('#range-margin');
var val = Math.round(1 * sel.val()); /* cast to int */
apply_margin_level(val);
electron.ipcRenderer.send('pref_margin_level', val);
}
function evhan_zoom_level()
{
var sel = $('#range-zoom');
var val = Math.round(1 * sel.val()); /*cast to int */
apply_zoom_level(val);
electron.ipcRenderer.send('pref_zoom_level', val);
}
function evhan_glulx_terp()
{
var sel = $('#sel-glulx-terp');
var val = sel.val();
electron.ipcRenderer.send('pref_glulx_terp', val);
}
/* Respond to messages from the app. */
electron.ipcRenderer.on('set-darklight-mode', function(ev, arg) {
apply_darklight(arg);
});
electron.ipcRenderer.on('current-prefs', function(ev, arg) {
setup_with_prefs(arg.prefs, arg.isbound);
});
electron.ipcRenderer.on('set-zoom-level', function(ev, arg) {
$('#range-zoom').val(arg);
apply_zoom_level(arg);
});