Add the possibility to set edge color.

This commit is contained in:
kovacsv 2021-12-08 12:17:32 +01:00
parent 619afebd55
commit 65600398b2
3 changed files with 61 additions and 14 deletions

View File

@ -58,6 +58,18 @@ div.ov_sidebar_content div.ov_sidebar_settings_row
overflow: auto; overflow: auto;
} }
div.ov_sidebar_content div.ov_sidebar_settings_details_input
{
width: 30px;
margin-right: 10px;
float: left;
}
div.ov_sidebar_content div.ov_sidebar_settings_details_text
{
float: left;
}
div.ov_sidebar_content div.ov_sidebar_settings_padded div.ov_sidebar_content div.ov_sidebar_settings_padded
{ {
margin: 10px 0px 0px 40px; margin: 10px 0px 0px 40px;

View File

@ -11,7 +11,7 @@ OV.Settings = class
this.defaultColor = new OV.Color (200, 200, 200); this.defaultColor = new OV.Color (200, 200, 200);
this.showEdges = false; this.showEdges = false;
this.edgeColor = new OV.Color (0, 0, 0); this.edgeColor = new OV.Color (0, 0, 0);
this.edgeThreshold = 10; this.edgeThreshold = 1;
this.themeId = OV.Theme.Light; this.themeId = OV.Theme.Light;
} }
@ -21,7 +21,7 @@ OV.Settings = class
this.defaultColor = cookieHandler.GetColorVal ('ov_default_color', new OV.Color (200, 200, 200)); this.defaultColor = cookieHandler.GetColorVal ('ov_default_color', new OV.Color (200, 200, 200));
this.showEdges = cookieHandler.GetBoolVal ('ov_show_edges', false); this.showEdges = cookieHandler.GetBoolVal ('ov_show_edges', false);
this.edgeColor = cookieHandler.GetColorVal ('ov_edge_color', new OV.Color (0, 0, 0)); this.edgeColor = cookieHandler.GetColorVal ('ov_edge_color', new OV.Color (0, 0, 0));
this.edgeThreshold = cookieHandler.GetIntVal ('ov_edge_threshold', 10); this.edgeThreshold = cookieHandler.GetIntVal ('ov_edge_threshold', 1);
this.showEdges = cookieHandler.GetBoolVal ('ov_show_edges', false); this.showEdges = cookieHandler.GetBoolVal ('ov_show_edges', false);
this.themeId = cookieHandler.GetIntVal ('ov_theme_id', OV.Theme.Light); this.themeId = cookieHandler.GetIntVal ('ov_theme_id', OV.Theme.Light);
} }

View File

@ -237,8 +237,8 @@ OV.SettingsSidebarPanel = class extends OV.SidebarPanel
'Background Color', 'Background Color',
'Affects only the visualization.', 'Affects only the visualization.',
null, null,
['#ffffff', '#e3e3e3', '#c9c9c9', '#898989', '#5f5f5f', '#494949', '#383838', '#0f0f0f'],
this.settings.backgroundColor, this.settings.backgroundColor,
['#ffffff', '#e3e3e3', '#c9c9c9', '#898989', '#5f5f5f', '#494949', '#383838', '#0f0f0f'],
(newColor) => { (newColor) => {
this.SetBackgroundColor (newColor, false); this.SetBackgroundColor (newColor, false);
} }
@ -247,8 +247,8 @@ OV.SettingsSidebarPanel = class extends OV.SidebarPanel
'Default Color', 'Default Color',
'Appears when the model doesn\'t have materials.', 'Appears when the model doesn\'t have materials.',
'Has no effect on the currently loaded file.', 'Has no effect on the currently loaded file.',
['#ffffff', '#e3e3e3', '#cc3333', '#fac832', '#4caf50', '#3393bd', '#9b27b0', '#fda4b8'],
this.settings.defaultColor, this.settings.defaultColor,
['#ffffff', '#e3e3e3', '#cc3333', '#fac832', '#4caf50', '#3393bd', '#9b27b0', '#fda4b8'],
(newColor) => { (newColor) => {
this.SetDefaultColor (newColor, false); this.SetDefaultColor (newColor, false);
} }
@ -288,19 +288,15 @@ OV.SettingsSidebarPanel = class extends OV.SidebarPanel
} }
} }
AddColorParameter (title, description, warningText, predefinedColors, defaultValue, onChange) AddColorPicker (parentDiv, defaultColor, predefinedColors, onChange)
{ {
let contentDiv = OV.AddDiv (this.contentDiv, 'ov_sidebar_settings_content'); let pickr = Pickr.create ({
let titleDiv = OV.AddDiv (contentDiv, 'ov_sidebar_subtitle'); el : parentDiv,
let colorInput = OV.AddDiv (titleDiv, 'color-picker');
OV.AddDiv (titleDiv, 'ov_sidebar_subtitle', title);
const pickr = Pickr.create ({
el : colorInput,
theme : 'monolith', theme : 'monolith',
position : 'left-start', position : 'left-start',
swatches : predefinedColors, swatches : predefinedColors,
comparison : false, comparison : false,
default : '#' + OV.ColorToHexString (defaultValue), default : '#' + OV.ColorToHexString (defaultColor),
components : { components : {
preview : false, preview : false,
opacity : false, opacity : false,
@ -326,6 +322,18 @@ OV.SettingsSidebarPanel = class extends OV.SidebarPanel
); );
onChange (ovColor); onChange (ovColor);
}); });
return pickr;
}
AddColorParameter (title, description, warningText, defaultColor, predefinedColors, onChange)
{
let contentDiv = OV.AddDiv (this.contentDiv, 'ov_sidebar_settings_content');
let titleDiv = OV.AddDiv (contentDiv, 'ov_sidebar_subtitle');
let colorInput = OV.AddDiv (titleDiv, 'color-picker');
OV.AddDiv (titleDiv, 'ov_sidebar_subtitle', title);
let pickr = this.AddColorPicker (colorInput, defaultColor, predefinedColors, (color) => {
onChange (color);
});
OV.AddDiv (contentDiv, 'ov_sidebar_settings_padded', description); OV.AddDiv (contentDiv, 'ov_sidebar_settings_padded', description);
let warningDiv = null; let warningDiv = null;
if (warningText !== null) { if (warningText !== null) {
@ -340,7 +348,7 @@ OV.SettingsSidebarPanel = class extends OV.SidebarPanel
}; };
} }
AddEdgeDisplayParameter (show, edgeColor, edgeThreshold) AddEdgeDisplayParameter (defaultShowEdges, defaultEdgeColor, defaultEdgeThreshold)
{ {
function AddRadioButton (contentDiv, id, text, onChange) function AddRadioButton (contentDiv, id, text, onChange)
{ {
@ -348,28 +356,54 @@ OV.SettingsSidebarPanel = class extends OV.SidebarPanel
return OV.AddRadioButton (row, 'edge_display', id, text, onChange); return OV.AddRadioButton (row, 'edge_display', id, text, onChange);
} }
function ShowEdgeSettings (edgeSettingsDiv, show)
{
if (show) {
OV.ShowDomElement (edgeSettingsDiv);
} else {
OV.HideDomElement (edgeSettingsDiv);
}
}
let contentDiv = OV.AddDiv (this.contentDiv, 'ov_sidebar_settings_content'); let contentDiv = OV.AddDiv (this.contentDiv, 'ov_sidebar_settings_content');
let titleDiv = OV.AddDiv (contentDiv, 'ov_sidebar_subtitle'); let titleDiv = OV.AddDiv (contentDiv, 'ov_sidebar_subtitle');
OV.AddSvgIconElement (titleDiv, 'edges', 'ov_sidebar_subtitle_icon'); OV.AddSvgIconElement (titleDiv, 'edges', 'ov_sidebar_subtitle_icon');
OV.AddDiv (titleDiv, 'ov_sidebar_subtitle_text', 'Edge Display'); OV.AddDiv (titleDiv, 'ov_sidebar_subtitle_text', 'Edge Display');
let buttonsDiv = OV.AddDiv (contentDiv, 'ov_sidebar_settings_padded'); let buttonsDiv = OV.AddDiv (contentDiv, 'ov_sidebar_settings_padded');
let edgeSettingsDiv = OV.AddDiv (contentDiv, 'ov_sidebar_settings_padded');
let colorRow = OV.AddDiv (edgeSettingsDiv, 'ov_sidebar_settings_row');
let colorInputDiv = OV.AddDiv (colorRow, 'ov_sidebar_settings_details_input');
OV.AddDiv (colorRow, 'ov_sidebar_settings_details_text', 'Edge Color');
let predefinedEdgeColors = ['#ffffff', '#e3e3e3', '#c9c9c9', '#898989', '#5f5f5f', '#494949', '#383838', '#0f0f0f'];
let colorInput = OV.AddDiv (colorInputDiv);
let pickr = this.AddColorPicker (colorInput, defaultEdgeColor, predefinedEdgeColors, (color) => {
this.settings.edgeColor = color;
this.callbacks.onEdgeDisplayChange ();
});
let buttons = []; let buttons = [];
let offButton = AddRadioButton (buttonsDiv, 'off', 'Don\'t Show Edges', () => { let offButton = AddRadioButton (buttonsDiv, 'off', 'Don\'t Show Edges', () => {
OV.HideDomElement (edgeSettingsDiv);
this.settings.showEdges = false; this.settings.showEdges = false;
this.callbacks.onEdgeDisplayChange (); this.callbacks.onEdgeDisplayChange ();
}); });
let onButton = AddRadioButton (buttonsDiv, 'on', 'Show Edges', () => { let onButton = AddRadioButton (buttonsDiv, 'on', 'Show Edges', () => {
OV.ShowDomElement (edgeSettingsDiv);
this.settings.showEdges = true; this.settings.showEdges = true;
this.callbacks.onEdgeDisplayChange (); this.callbacks.onEdgeDisplayChange ();
}); });
buttons.push (offButton); buttons.push (offButton);
buttons.push (onButton); buttons.push (onButton);
OV.SelectRadioButton (buttons, show ? 'on' : 'off'); OV.SelectRadioButton (buttons, defaultShowEdges ? 'on' : 'off');
ShowEdgeSettings (edgeSettingsDiv, defaultShowEdges);
return { return {
pickr : pickr,
select : (value) => { select : (value) => {
OV.SelectRadioButton (buttons, value ? 'on' : 'off'); OV.SelectRadioButton (buttons, value ? 'on' : 'off');
ShowEdgeSettings (edgeSettingsDiv, value);
} }
}; };
} }
@ -425,6 +459,7 @@ OV.SettingsSidebarPanel = class extends OV.SidebarPanel
this.settings.showEdges = defaultSettings.showEdges; this.settings.showEdges = defaultSettings.showEdges;
this.settings.edgeColor = defaultSettings.edgeColor; this.settings.edgeColor = defaultSettings.edgeColor;
this.settings.edgeThreshold = defaultSettings.edgeThreshold; this.settings.edgeThreshold = defaultSettings.edgeThreshold;
this.edgeDisplayInput.pickr.setColor ('#' + OV.ColorToHexString (defaultSettings.edgeColor));
this.edgeDisplayInput.select (this.settings.showEdges); this.edgeDisplayInput.select (this.settings.showEdges);
this.callbacks.onEdgeDisplayChange (); this.callbacks.onEdgeDisplayChange ();