Skip to content

Commit

Permalink
Bug 49591
Browse files Browse the repository at this point in the history
  • Loading branch information
OVSharova committed Dec 4, 2023
1 parent fd67e48 commit 97a21b2
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 46 deletions.
139 changes: 127 additions & 12 deletions apps/common/main/lib/component/MultiSliderGradient.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ define([
includeSnap: true,
intervalSnap: 5,
thumbTemplate: '<div class="thumb" style="">' +
'<svg viewBox="-1 -1 15 17">' +
'<use xlink:href="#thumb-color-form" class ="thumb-over" fill="none" stroke="black" stroke-width="2"></use>' +
'<use xlink:href="#thumb-color-form" class ="thumb-inside" stroke="white" stroke-width="3" clip-path="url(#thumb-color-clip)"></use>'+
'</svg>' +
'<canvas style="width: 100%; height: 100%"></canvas>' +
'</div>'
},

Expand All @@ -77,32 +74,53 @@ define([

initialize : function(options) {
this.styleStr = {};
this.tmbOptions={
width: 13,
height: 16,
border:1,
borderColor:'#c0c0c0',
borderColorActive:'#848484'
};
this.colorTable = {
'theme-light' : {borderColor: '#c0c0c0', borderColorActive:'#848484'},
'theme-classic-light':{borderColor: '#cfcfcf', borderColorActive:'#848484'},
'theme-dark':{borderColor: '#666', borderColorActive:'#ccc'},
'theme-contrast-dark':{borderColor: '#696969', borderColorActive:'#b8b8b8'}
};
this.scale = Common.Utils.applicationPixelRatio() >= 1 ? Common.Utils.applicationPixelRatio() : 1,
Common.UI.MultiSlider.prototype.initialize.call(this, options);

},

render : function(parentEl) {
Common.UI.MultiSlider.prototype.render.call(this, parentEl);

var me = this;
me.trackEl = me.cmpEl.find('.track');

me.changeColors(false, (Common.UI.Themes.currentThemeId() || Common.UI.Themes.defaultThemeId()).toLowerCase());
for (var i=0; i<me.thumbs.length; i++) {
me.thumbs[i].thumb.on('dblclick', null, function() {
me.trigger('thumbdblclick', me);
});
me.thumbs[i].thumbcolor = me.thumbs[i].thumb.find('> svg use.thumb-inside');
me.thumbs[i].thumbcolor = me.thumbs[i].thumb.find('> canvas')[0];
me.setSizeThumb(me.thumbs[i].thumb, me.thumbs[i].thumbcolor);
me.thumbs[i].context = me.thumbs[i].thumbcolor.getContext('2d');
me.drawThumb(me.thumbs[i]);
me.setColorValue(me.options.colorValues[i], i);
}

me.changeSliderStyle();
me.changeGradientStyle();
me.on('change', _.bind(me.changeGradientStyle, me));
Common.NotificationCenter.on( {
'window:resize':_.bind(me.onResize, me),
'uitheme:changed': _.bind(me.changeColors,me, true)});
this.on('thumbclick',_.bind(me.onActiveThumb,me));
},

setColorValue: function(color, index) {
var ind = (index!==undefined) ? index : this.currentThumb;
this.thumbs[ind].colorValue = color;
this.thumbs[ind].thumbcolor.css('fill', color);
this.thumbFill(this.thumbs[ind].context,color);
this.changeGradientStyle();
},

Expand Down Expand Up @@ -194,11 +212,103 @@ define([
me.thumbs[index].thumb.on('dblclick', null, function() {
me.trigger('thumbdblclick', me);
});
me.thumbs[index].thumbcolor = me.thumbs[index].thumb.find('> svg use.thumb-inside');
(index>0) && this.setColorValue(this.getColorValue(index-1), index);
me.thumbs[index].thumbcolor = me.thumbs[index].thumb.find('> canvas')[0];
if(index>0) {
me.setSizeThumb(me.thumbs[index].thumb, me.thumbs[index].thumbcolor);
me.thumbs[index].context = me.thumbs[index].thumbcolor.getContext('2d');
this.drawThumb(this.thumbs[index]);
this.setColorValue(this.getColorValue(index - 1), index);
}
me.changeSliderStyle();
},

drawThumb: function (tmb) {
if(!tmb) return;
var ctx = tmb.context,
borderWidth = (this.tmbOptions.border*this.scale + 0.5)>>0,
x1 = borderWidth / 2,
x2 = (((this.tmbOptions.width - this.tmbOptions.border/2)*this.scale + 0.5)>>0) - borderWidth / 2,
x3 = (((this.tmbOptions.width - this.tmbOptions.border)/2*this.scale + 0.5)>>0),
y1 = ((this.tmbOptions.width/2*this.scale + 0.5)>>0) + borderWidth / 2,
y2 = ((this.tmbOptions.height*this.scale + 0.5)>>0) - borderWidth / 2,
y3 = ((this.scale + 0.5)>>0) + borderWidth / 2;
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x1, y2);
ctx.lineTo(x2, y2);
ctx.lineTo(x2, y1);
ctx.lineTo(x3, y3);
ctx.lineTo(x1, y1);
ctx.closePath();
ctx.lineWidth = borderWidth;
ctx.strokeStyle = (tmb.thumb.hasClass('active')) ? this.tmbOptions.borderColorActive : this.tmbOptions.borderColor;
ctx.stroke();
},

thumbFill: function (ctx, color) {

var borderWidth = (this.tmbOptions.border*this.scale + 0.5)>>0,
x1 = 2*borderWidth,
x2 = (((this.tmbOptions.width - this.tmbOptions.border/2)*this.scale + 0.5)>>0) - 2*borderWidth,
x3 = (((this.tmbOptions.width - this.tmbOptions.border)/2*this.scale + 0.5)>>0),
y1 = (((this.tmbOptions.width/2)*this.scale + borderWidth + 0.5)>>0) ,
y2 = ((this.tmbOptions.height*this.scale + 0.5)>>0) - 2*borderWidth,
y3 = ((this.tmbOptions.border*this.scale + 2.5*borderWidth + 0.5)>>0);
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x1, y2);
ctx.lineTo(x2, y2);
ctx.lineTo(x2, y1);
ctx.lineTo(x3, y3);
ctx.lineTo(x1, y1);
ctx.closePath();
ctx.fillStyle = color;
ctx.fill();
},

redrawThumb: function (tmb){
if(!tmb)return;
var ctx = tmb.context;
ctx.clearRect(0,0,tmb.thumbcolor.width, tmb.thumbcolor.height);
this.drawThumb(tmb);
this.thumbFill(tmb.context, tmb.colorValue);
},

onActiveThumb: function (){
this.redrawThumb(this.tmbOptions.activeThumb);
this.tmbOptions.activeThumb = this.thumbs.filter(function (tmb){return tmb.thumb.hasClass('active');})[0];
this.redrawThumb(this.tmbOptions.activeThumb);
},

setSizeThumb: function (tmb, canv){
if(!tmb || !canv) return;
tmb.css({ width: ((this.tmbOptions.width * this.scale)>>0) / this.scale, height: ((this.tmbOptions.height * this.scale) >> 0) / this.scale});
canv.width = this.tmbOptions.width * this.scale;
canv.height = this.tmbOptions.height * this.scale;
},

onResize: function(){
if(!this.thumbs || this.thumbs.length==0) return;
this.scale = Common.Utils.applicationPixelRatio() >= 1 ? Common.Utils.applicationPixelRatio() : 1;
for (var i=0; i<this.thumbs.length; i++) {
this.setSizeThumb(this.thumbs[i].thumb, this.thumbs[i].thumbcolor);
!!this.thumbs[i].context && this.redrawThumb(this.thumbs[i]);
}
},

changeColors: function (redraw, theme) {
if(theme == this.currentTheme)return;
this.currentTheme = (theme !== 'theme-system') ? theme : this.currentTheme = window.uitheme.relevant_theme_id();
this.tmbOptions.borderColor = this.colorTable[this.currentTheme].borderColor;
this.tmbOptions.borderColorActive = this.colorTable[this.currentTheme].borderColorActive;
if(redraw){
for(var i=0; i< this.thumbs.length; i++){
!!this.thumbs[i].context && this.redrawThumb(this.thumbs[i]);
this.tmbOptions.activeThumb = this.thumbs[i];
}
}
},

addNewThumb: function(index, pos, curIndex) {
var me = this,
indexLeftThumb = this.findLeftThumb(pos),
Expand All @@ -215,8 +325,13 @@ define([
var ratio = (pos - this.thumbs[indexLeftThumb].value) * 100 / (this.thumbs[indexLeftThumb + 1].value - this.thumbs[indexLeftThumb].value);
color = ratio < 0 ? this.thumbs[indexLeftThumb].colorValue : this.calculationNewColor(this.thumbs[indexLeftThumb].colorValue, this.thumbs[indexLeftThumb === index - 1 ? indexLeftThumb : indexLeftThumb + 1].colorValue, ratio);
}
me.thumbs[index].thumbcolor = me.thumbs[index].thumb.find('> svg use.thumb-inside');
(index>0) && this.setColorValue('#' + color, index);
me.thumbs[index].thumbcolor = me.thumbs[index].thumb.find('> canvas')[0];
if(index>0) {
me.setSizeThumb(me.thumbs[index].thumb, me.thumbs[index].thumbcolor);
me.thumbs[index].context = me.thumbs[index].thumbcolor.getContext('2d');
me.drawThumb(me.thumbs[index]);
this.setColorValue('#' + color, index);
}
me.sortThumbs();
me.changeSliderStyle();
me.changeGradientStyle();
Expand Down
40 changes: 13 additions & 27 deletions apps/common/main/resources/less/multislider-gradient.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,22 @@
height: 15px;
top: 18px;
background: none;
svg {
width: 13px;
height: 100%;
margin-left:-1px;
margin-left: calc(1px - @scaled-one-px-value);
use.thumb-over{
stroke: @border-regular-control-ie;
stroke: @border-regular-control;
stroke-width: 2px;
stroke-width: @scaled-two-px-value;
stroke-width: calc(1px + @scaled-one-px-value);
}
use.thumb-inside {
stroke: @background-normal-ie;
stroke: @background-normal;
stroke-width: 3px;
stroke-width: calc(2px + @scaled-one-px-value);

}

canvas{
.margin-left(1px);
}
&.active svg use.thumb-over {
stroke: @border-control-focus-ie;
stroke: @border-control-focus;
}
&.remove svg use.thumb-over{

&.remove canvas{
opacity: 0.5;
}
&:hover {
filter: drop-shadow( 0px 2px 3px rgba(0, 0, 0, 0.32));
&:hover::after{
display: block;
content: ' ';
position: absolute;
width: 12px;
height: 10px;
bottom: 0;
box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.32);
.margin-left(1px);
}
}

Expand Down
7 changes: 0 additions & 7 deletions apps/documenteditor/main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,6 @@
var svgpoints = document.querySelectorAll('img.inline-svg');
SVGInjector(svgpoints);
</script>
<svg xmlns="http://www.w3.org/2000/svg">
<defs>
<clipPath id="thumb-color-clip">
<path id="thumb-color-form" d="M 0 5 L 6 0 L 12 5 V 14 Q 12 15 11 15 H 1 Q 0 15 0 14 Z"/>
</clipPath>
</defs>
</svg>

<!-- debug begin -->
<script type="text/javascript">var less=less||{};less.env='development';less.async=true;</script>
Expand Down

0 comments on commit 97a21b2

Please sign in to comment.