~holger-seelig/cobweb.js/trunk

« back to all changes in this revision

Viewing changes to cobweb.js/cobweb/Browser/Core/BrowserOptions.js

  • Committer: Holger Seelig
  • Date: 2017-08-22 04:53:24 UTC
  • Revision ID: holger.seelig@yahoo.de-20170822045324-4of4xxgt79669gbt
Switched to npm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: JavaScript; coding: utf-8; tab-width: 3; indent-tabs-mode: tab; c-basic-offset: 3 -*-
2
 
 *******************************************************************************
3
 
 *
4
 
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
 
 *
6
 
 * Copyright create3000, Scheffelstraße 31a, Leipzig, Germany 2011.
7
 
 *
8
 
 * All rights reserved. Holger Seelig <holger.seelig@yahoo.de>.
9
 
 *
10
 
 * The copyright notice above does not evidence any actual of intended
11
 
 * publication of such source code, and is an unpublished work by create3000.
12
 
 * This material contains CONFIDENTIAL INFORMATION that is the property of
13
 
 * create3000.
14
 
 *
15
 
 * No permission is granted to copy, distribute, or create derivative works from
16
 
 * the contents of this software, in whole or in part, without the prior written
17
 
 * permission of create3000.
18
 
 *
19
 
 * NON-MILITARY USE ONLY
20
 
 *
21
 
 * All create3000 software are effectively free software with a non-military use
22
 
 * restriction. It is free. Well commented source is provided. You may reuse the
23
 
 * source in any way you please with the exception anything that uses it must be
24
 
 * marked to indicate is contains 'non-military use only' components.
25
 
 *
26
 
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27
 
 *
28
 
 * Copyright 2015, 2016 Holger Seelig <holger.seelig@yahoo.de>.
29
 
 *
30
 
 * This file is part of the Cobweb Project.
31
 
 *
32
 
 * Cobweb is free software: you can redistribute it and/or modify it under the
33
 
 * terms of the GNU General Public License version 3 only, as published by the
34
 
 * Free Software Foundation.
35
 
 *
36
 
 * Cobweb is distributed in the hope that it will be useful, but WITHOUT ANY
37
 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
38
 
 * A PARTICULAR PURPOSE. See the GNU General Public License version 3 for more
39
 
 * details (a copy is included in the LICENSE file that accompanied this code).
40
 
 *
41
 
 * You should have received a copy of the GNU General Public License version 3
42
 
 * along with Cobweb.  If not, see <http://www.gnu.org/licenses/gpl.html> for a
43
 
 * copy of the GPLv3 License.
44
 
 *
45
 
 * For Silvio, Joy and Adi.
46
 
 *
47
 
 ******************************************************************************/
48
 
 
49
 
 
50
 
define ([
51
 
        "jquery",
52
 
        "cobweb/Fields",
53
 
        "cobweb/Basic/X3DFieldDefinition",
54
 
        "cobweb/Basic/FieldDefinitionArray",
55
 
        "cobweb/Basic/X3DBaseNode",
56
 
        "cobweb/Bits/X3DConstants",
57
 
        "cobweb/Browser/Core/PrimitiveQuality",
58
 
        "cobweb/Browser/Core/TextureQuality",
59
 
],
60
 
function ($,
61
 
          Fields,
62
 
          X3DFieldDefinition,
63
 
          FieldDefinitionArray,
64
 
          X3DBaseNode,
65
 
          X3DConstants,
66
 
          PrimitiveQuality,
67
 
          TextureQuality)
68
 
{
69
 
"use strict";
70
 
        
71
 
        function BrowserOptions (executionContext)
72
 
        {
73
 
                X3DBaseNode .call (this, executionContext);
74
 
 
75
 
                this .addAlias ("AntiAliased", this .Antialiased_);
76
 
 
77
 
                this .setAttributeSplashScreen ();
78
 
 
79
 
                this .primitiveQuality = PrimitiveQuality .MEDIUM;
80
 
                this .textureQuality   = TextureQuality   .MEDIUM;
81
 
        }
82
 
 
83
 
        BrowserOptions .prototype = $.extend (Object .create (X3DBaseNode .prototype),
84
 
        {
85
 
                constructor: BrowserOptions,
86
 
                fieldDefinitions: new FieldDefinitionArray ([
87
 
                        new X3DFieldDefinition (X3DConstants .inputOutput, "SplashScreen",           new Fields .SFBool (true)),
88
 
                        new X3DFieldDefinition (X3DConstants .inputOutput, "Dashboard",              new Fields .SFBool (true)),
89
 
                        new X3DFieldDefinition (X3DConstants .inputOutput, "Rubberband",             new Fields .SFBool (true)),
90
 
                        new X3DFieldDefinition (X3DConstants .inputOutput, "EnableInlineViewpoints", new Fields .SFBool (true)),
91
 
                        new X3DFieldDefinition (X3DConstants .inputOutput, "Antialiased",            new Fields .SFBool (true)),
92
 
                        new X3DFieldDefinition (X3DConstants .inputOutput, "TextureQuality",         new Fields .SFString ("MEDIUM")),
93
 
                        new X3DFieldDefinition (X3DConstants .inputOutput, "PrimitiveQuality",       new Fields .SFString ("MEDIUM")),
94
 
                        new X3DFieldDefinition (X3DConstants .inputOutput, "QualityWhenMoving",      new Fields .SFString ("MEDIUM")),
95
 
                        new X3DFieldDefinition (X3DConstants .inputOutput, "Shading",                new Fields .SFString ("GOURAUD")),
96
 
                        new X3DFieldDefinition (X3DConstants .inputOutput, "MotionBlur",             new Fields .SFBool ()),
97
 
                        new X3DFieldDefinition (X3DConstants .inputOutput, "Gravity",                new Fields .SFFloat (9.80665)),
98
 
                ]),
99
 
                getTypeName: function ()
100
 
                {
101
 
                        return "BrowserOptions";
102
 
                },
103
 
                getComponentName: function ()
104
 
                {
105
 
                        return "Cobweb";
106
 
                },
107
 
                getContainerField: function ()
108
 
                {
109
 
                        return "browserOptions";
110
 
                },
111
 
                initialize: function ()
112
 
                {
113
 
                        X3DBaseNode .prototype .initialize .call (this);
114
 
                        
115
 
                        this .SplashScreen_              .addInterest ("set_splashScreen__", this);
116
 
                        this .Rubberband_                .addInterest ("set_rubberband__", this);
117
 
                        this .PrimitiveQuality_          .addInterest ("set_primitiveQuality__", this);
118
 
                        this .TextureQuality_            .addInterest ("set_textureQuality__", this);
119
 
                        this .Shading_                   .addInterest ("set_shading__", this);
120
 
                        this .getBrowser () .shutdown () .addInterest ("configure", this);
121
 
 
122
 
                        this .configure ();
123
 
                },
124
 
                configure: function ()
125
 
                {
126
 
                        var fieldDefinitions = this .getFieldDefinitions ();
127
 
 
128
 
                        for (var i = 0; i < fieldDefinitions .length; ++ i)
129
 
                        {
130
 
                                var
131
 
                                        fieldDefinition = fieldDefinitions [i],
132
 
                                        field           = this .getField (fieldDefinition .name);
133
 
 
134
 
                                if (this .getBrowser () .getDataStorage () ["BrowserOptions." + fieldDefinition .name] !== undefined)
135
 
                                        continue;
136
 
 
137
 
                                if (! field .equals (fieldDefinition .value))
138
 
                                        field .setValue (fieldDefinition .value);
139
 
                        }
140
 
 
141
 
                        var
142
 
                                rubberband       = this .getBrowser () .getDataStorage () ["BrowserOptions.Rubberband"],
143
 
                                primitiveQuality = this .getBrowser () .getDataStorage () ["BrowserOptions.PrimitiveQuality"],
144
 
                                textureQuality   = this .getBrowser () .getDataStorage () ["BrowserOptions.TextureQuality"];
145
 
 
146
 
                        this .setAttributeSplashScreen ();
147
 
 
148
 
                        if (rubberband       !== undefined && rubberband       !== this .Rubberband_       .getValue ()) this .Rubberband_       = rubberband;
149
 
                        if (primitiveQuality !== undefined && primitiveQuality !== this .PrimitiveQuality_ .getValue ()) this .PrimitiveQuality_ = primitiveQuality;
150
 
                        if (textureQuality   !== undefined && textureQuality   !== this .TextureQuality_   .getValue ()) this .TextureQuality_   = textureQuality;
151
 
                },
152
 
                setAttributeSplashScreen: function ()
153
 
                {
154
 
                        this .SplashScreen_ .set (this .getSplashScreen ());
155
 
                },
156
 
                getSplashScreen: function ()
157
 
                {
158
 
                        return this .getBrowser () .getElement () .attr ("splashScreen") !== "false";
159
 
                },
160
 
                getNotifications: function ()
161
 
                {
162
 
                        return this .getBrowser () .getElement () .attr ("notifications") !== "false";
163
 
                },
164
 
                getTimings: function ()
165
 
                {
166
 
                        return this .getBrowser () .getElement () .attr ("timings") !== "false";
167
 
                },
168
 
                getContextMenu: function ()
169
 
                {
170
 
                        return this .getBrowser () .getElement () .attr ("contextMenu") !== "false";
171
 
                },
172
 
                getCache: function ()
173
 
                {
174
 
                        return this .getBrowser () .getElement () .attr ("cache") !== "false";
175
 
                },
176
 
                getPrimitiveQuality: function ()
177
 
                {
178
 
                        return this .primitiveQuality;
179
 
                },
180
 
                getTextureQuality: function ()
181
 
                {
182
 
                        return this .textureQuality;
183
 
                },
184
 
                getShading: function ()
185
 
                {
186
 
                        return this .Shading_ .getValue ();
187
 
                },
188
 
                set_splashScreen__: function (splashScreen)
189
 
                {
190
 
                        this .getBrowser () .getElement () .attr ("splashScreen", splashScreen .getValue () ? "true" : "false");
191
 
                },
192
 
                set_rubberband__: function (rubberband)
193
 
                {
194
 
                        this .getBrowser () .getDataStorage () ["BrowserOptions.Rubberband"] = rubberband .getValue ();
195
 
                },
196
 
                set_primitiveQuality__: function (primitiveQuality)
197
 
                {
198
 
                        this .getBrowser () .getDataStorage () ["BrowserOptions.PrimitiveQuality"] = primitiveQuality .getValue ();
199
 
 
200
 
                        var
201
 
                                arc      = this .getBrowser () .getArc2DOptions (),
202
 
                                arcClose = this .getBrowser () .getArcClose2DOptions (),
203
 
                                circle   = this .getBrowser () .getCircle2DOptions (),
204
 
                                disk     = this .getBrowser () .getDisk2DOptions (),
205
 
                                cone     = this .getBrowser () .getConeOptions (),
206
 
                                cylinder = this .getBrowser () .getCylinderOptions (),
207
 
                                sphere   = this .getBrowser () .getSphereOptions ();
208
 
 
209
 
                        switch (primitiveQuality .getValue ())
210
 
                        {
211
 
                                case "LOW":
212
 
                                {
213
 
                                        this .primitiveQuality = PrimitiveQuality .LOW;
214
 
                                
215
 
                                        arc .dimension_      = 20;
216
 
                                        arcClose .dimension_ = 20;
217
 
                                        circle .dimension_   = 20;
218
 
                                        disk .dimension_     = 20;
219
 
 
220
 
                                        cone     .xDimension_ = 16;
221
 
                                        cylinder .xDimension_ = 16;
222
 
 
223
 
                                        sphere .xDimension_ = 20;
224
 
                                        sphere .yDimension_ = 9;
225
 
                                        break;
226
 
                                }
227
 
                                case "HIGH":
228
 
                                {
229
 
                                        this .primitiveQuality = PrimitiveQuality .HIGH;
230
 
 
231
 
                                        arc .dimension_      = 80;
232
 
                                        arcClose .dimension_ = 80;
233
 
                                        circle .dimension_   = 80;
234
 
                                        disk .dimension_     = 80;
235
 
 
236
 
                                        cone     .xDimension_ = 32;
237
 
                                        cylinder .xDimension_ = 32;
238
 
 
239
 
                                        sphere .xDimension_ = 64;
240
 
                                        sphere .yDimension_ = 31;
241
 
                                        break;
242
 
                                }
243
 
                                default:
244
 
                                {
245
 
                                        this .primitiveQuality = PrimitiveQuality .MEDIUM;
246
 
 
247
 
                                        arc .dimension_      = 40;
248
 
                                        arcClose .dimension_ = 40;
249
 
                                        circle .dimension_   = 40;
250
 
                                        disk .dimension_     = 40;
251
 
 
252
 
                                        cone     .xDimension_ = 20;
253
 
                                        cylinder .xDimension_ = 20;
254
 
 
255
 
                                        sphere .xDimension_ = 32;
256
 
                                        sphere .yDimension_ = 15;
257
 
                                        break;
258
 
                                }
259
 
                        }
260
 
                },
261
 
                set_textureQuality__: function (textureQuality)
262
 
                {
263
 
                        this .getBrowser () .getDataStorage () ["BrowserOptions.TextureQuality"] = textureQuality .getValue ();
264
 
 
265
 
                        var textureProperties = this .getBrowser () .getDefaultTextureProperties ();
266
 
 
267
 
                        switch (textureQuality .getValue ())
268
 
                        {
269
 
                                case "LOW":
270
 
                                {
271
 
                                        this .textureQuality = TextureQuality .LOW;
272
 
 
273
 
                                        textureProperties .magnificationFilter_ = "AVG_PIXEL";
274
 
                                        textureProperties .minificationFilter_  = "AVG_PIXEL";
275
 
                                        textureProperties .textureCompression_  = "FASTEST";
276
 
                                        textureProperties .generateMipMaps_     = true;
277
 
 
278
 
                                        //glHint (GL_GENERATE_MIPMAP_HINT,        GL_FASTEST);
279
 
                                        //glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
280
 
                                        break;
281
 
                                }
282
 
                                case "HIGH":
283
 
                                {
284
 
                                        this .textureQuality = TextureQuality .HIGH;
285
 
 
286
 
                                        textureProperties .magnificationFilter_ = "NICEST";
287
 
                                        textureProperties .minificationFilter_  = "NICEST";
288
 
                                        textureProperties .textureCompression_  = "NICEST";
289
 
                                        textureProperties .generateMipMaps_     = true;
290
 
                        
291
 
                                        //glHint (GL_GENERATE_MIPMAP_HINT,        GL_NICEST);
292
 
                                        //glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
293
 
                                        break;
294
 
                                }
295
 
                                default:
296
 
                                {
297
 
                                        this .textureQuality = TextureQuality .MEDIUM;
298
 
 
299
 
                                        textureProperties .magnificationFilter_ = "NICEST";
300
 
                                        textureProperties .minificationFilter_  = "AVG_PIXEL_AVG_MIPMAP";
301
 
                                        textureProperties .textureCompression_  = "NICEST";
302
 
                                        textureProperties .generateMipMaps_     = true;
303
 
 
304
 
                                        //glHint (GL_GENERATE_MIPMAP_HINT,        GL_FASTEST);
305
 
                                        //glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
306
 
                                        break;
307
 
                                }
308
 
                        }
309
 
                },
310
 
                set_shading__: function (shading)
311
 
                {
312
 
                        this .getBrowser () .setShading (shading .getValue ());
313
 
                },
314
 
        });
315
 
 
316
 
        return BrowserOptions;
317
 
});