From 0e3410171e2881d80c9e35a56d07e8b4f7c12f65 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Sun, 20 Oct 2013 17:31:40 -0700 Subject: [PATCH] Editor: Changing grid colors to match theme. See #3920. I tried using document.stylesheets but there is no event listener for then a element.href is done so it would access the css values too soon. --- editor/js/Editor.js | 10 ++++++++++ editor/js/Menubar.View.js | 6 ++---- editor/js/Viewport.js | 13 +++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/editor/js/Editor.js b/editor/js/Editor.js index 585f5a956f..3a951b6adc 100644 --- a/editor/js/Editor.js +++ b/editor/js/Editor.js @@ -10,6 +10,8 @@ var Editor = function () { // notifications + themeChanged: new SIGNALS.Signal(), + transformModeChanged: new SIGNALS.Signal(), snapChanged: new SIGNALS.Signal(), spaceChanged: new SIGNALS.Signal(), @@ -52,6 +54,14 @@ var Editor = function () { Editor.prototype = { + setTheme: function ( value ) { + + document.getElementById( 'theme' ).href = value; + + this.signals.themeChanged.dispatch( value ); + + }, + setScene: function ( scene ) { this.scene.name = scene.name; diff --git a/editor/js/Menubar.View.js b/editor/js/Menubar.View.js index 8d88f2aea6..6d1a614df6 100644 --- a/editor/js/Menubar.View.js +++ b/editor/js/Menubar.View.js @@ -21,14 +21,12 @@ Menubar.View = function ( editor ) { // themes - var themeLink = document.getElementById( 'theme' ); - var option = new UI.Panel(); option.setClass( 'option' ); option.setTextContent( 'Light theme' ); option.onClick( function () { - themeLink.href = 'css/light.css'; + editor.setTheme( 'css/light.css' ); } ); options.add( option ); @@ -40,7 +38,7 @@ Menubar.View = function ( editor ) { option.setTextContent( 'Dark theme' ); option.onClick( function () { - themeLink.href = 'css/dark.css'; + editor.setTheme( 'css/dark.css' ); } ); options.add( option ); diff --git a/editor/js/Viewport.js b/editor/js/Viewport.js index 12b0086f39..6734408cbf 100644 --- a/editor/js/Viewport.js +++ b/editor/js/Viewport.js @@ -179,6 +179,19 @@ var Viewport = function ( editor ) { // signals + signals.themeChanged.add( function ( value ) { + + switch ( value ) { + + case 'css/light.css': grid.setColors( 0x444444, 0x888888 ); break; + case 'css/dark.css': grid.setColors( 0xbbbbbb, 0x888888 ); break; + + } + + render(); + + } ); + signals.transformModeChanged.add( function ( mode ) { transformControls.setMode( mode ); -- GitLab