Gitlab CSE Unil

Commit 2d13371b authored by M. Chardon's avatar M. Chardon
Browse files

correction bug mantis 231

parent fd36af35
......@@ -46,7 +46,8 @@ define(["paper", "jquery"], function (paper, $) {
};
// ----- Initialisations ------------------------------
var _noop = function(){};
var _noop = function () {
};
// ----- Item's event listeners -----------------------
function itemMouseDown(event) {
......@@ -65,7 +66,7 @@ define(["paper", "jquery"], function (paper, $) {
var _dragOpts = {};
var _dragModified = false; // this is set to true if a drag event changed the item and need to emmit a change event
function setDragMode(mode, opts) {
if (! (mode in DRAG_MODES)) {
if (!(mode in DRAG_MODES)) {
_dragMode = null;
_dragOpts = {};
_dragModified = false;
......@@ -85,7 +86,7 @@ define(["paper", "jquery"], function (paper, $) {
height = (_dragOpts.nameParts[0] === 'top') ?
bounds.bottom - event.point.y :
event.point.y - bounds.top,
fontSize = height / 1.2,
fontSize = height / 1.2,
offset = [0, 0];
if (_dragOpts.nameParts[0] === 'bottom') {
offset[1] = height - bounds.height;
......@@ -94,7 +95,7 @@ define(["paper", "jquery"], function (paper, $) {
setFontSize.call(_dragOpts.item, fontSize);
}
_dragOpts.item.translate(offset);
break;
break;
case DRAG_MODES.FULL_DRAG:
default:
this.translate(event.delta);
......@@ -109,7 +110,7 @@ define(["paper", "jquery"], function (paper, $) {
item.data.prop[p] = hitOptions[p];
}
item.oGetSelected = function() {
item.oGetSelected = function () {
return this.children[1].selected;
// for (var i = 0, l = this.children.length; i<l; i++) {
// if (!this.children.selected)
......@@ -117,7 +118,7 @@ define(["paper", "jquery"], function (paper, $) {
// }
// return true;
};
item.oSetSelected = function(selected) {
item.oSetSelected = function (selected) {
//this.children.map(function(c) {c.selected = selected});
this.children[1].selected = selected;
};
......@@ -136,7 +137,9 @@ define(["paper", "jquery"], function (paper, $) {
// ----- Functions ------------------------------------
function _startEdit(myText) {
if (edit) { _terminateEdit(false); }
if (edit) {
_terminateEdit(false);
}
if (_ro) return;
edit = true;
......@@ -150,18 +153,24 @@ define(["paper", "jquery"], function (paper, $) {
style: "display:none;position:absolute;top:0;left:0;padding:10px;border:0;border-radius:5px;background:rgba(255,255,255,0.75);"
}
)
.appendTo(paper.project.view.element.parentNode)
.on("blur", function(){ if(edit) _terminateEdit(); })
.on("keydown", function(event){ if(event.which === 27 || event.which == 13) _terminateEdit(); })
.autoGrowInput();
.appendTo(paper.project.view.element.parentNode)
.on("blur", function () {
if (edit) _terminateEdit();
})
.on("keydown", function (event) {
if (event.which === 27 || event.which == 13) _terminateEdit();
})
.autoGrowInput();
overlay = overlay || $("<div>").css({
zIndex: 999,
position: "fixed", display: "none",
top: "-10px", left: "-10px",
width: "5000px", height: "5000px"
})
.click(function(){ _terminateEdit() });
zIndex: 999,
position: "fixed", display: "none",
top: "-10px", left: "-10px",
width: "5000px", height: "5000px"
})
.click(function () {
_terminateEdit()
});
input.before(overlay);
}
myText.selected = false;
......@@ -193,13 +202,13 @@ define(["paper", "jquery"], function (paper, $) {
letterSpacing: input.css('letterSpacing')
});
tester.text( (myText.data.content === "") ? input.attr("placeholder") : myText.data.content);
input.width(tester.width()+30);
tester.text((myText.data.content === "") ? input.attr("placeholder") : myText.data.content);
input.width(tester.width() + 30);
gText = myText;
setTimeout(function(){
setTimeout(function () {
input.focus();
},100);
}, 100);
}
/**
......@@ -223,7 +232,7 @@ define(["paper", "jquery"], function (paper, $) {
gText.children[1].content = textVal;
gText.visible = true;
if(selectAfter)
if (selectAfter)
if (_events.annotationSelected && typeof _events.annotationSelected.dispatch === 'function') {
_events.annotationSelected.dispatch(gText);
}
......@@ -252,15 +261,53 @@ define(["paper", "jquery"], function (paper, $) {
var textGroup = this;
var changed = textGroup.children[1].fillColor !== color;
textGroup.children[1].fillColor = color;
console.log(color);
textGroup.children[0].strokeColor = getBackgroundColor(color, 0.3);
textGroup.data.color = color;
return changed;
}
/**
* get background color tint form main fill color
* @param color hexa or rgb color
* @param lum tint factor
* @returns {string} rgb color
*/
function getBackgroundColor(color, lum) {
var red = null;
var green = null;
var blue = null;
var resulthexa = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(color);
if (resulthexa) {
//on a une couleur en hexa
red = parseInt(resulthexa[1], 16);
green = parseInt(resulthexa[2], 16);
blue = parseInt(resulthexa[3], 16);
} else {
//couleur en rgb
var digits = /(.*?)rgb\((\d+), (\d+), (\d+)\)/.exec(color);
red = parseInt(digits[2]);
green = parseInt(digits[3]);
blue = parseInt(digits[4]);
}
lum = lum || 0;
red = red + (255 - red) * lum;
green = green + (255 - green) * lum;
blue = blue + (255 - blue) * lum;
return 'rgb(' + red + ', ' + green + ', ' + blue + ')';
}
function setFontSize(size) {
var textGroup = this;
var sw = size / 10;
if (sw < 3) { sw = 3; }
if (sw < 3) {
sw = 3;
}
textGroup.children[0].fontSize = size;
textGroup.children[0].strokeWidth = sw;
textGroup.children[1].fontSize = size;
......@@ -280,15 +327,14 @@ define(["paper", "jquery"], function (paper, $) {
// ----- Tool Def -------------------------------------
var toolDef = {
onMouseDown: function(event){
onMouseDown: function (event) {
if (_ro) return;
var hitResult = paper.project.activeLayer.hitTest(event.point, hitOptions);
if (hitResult) {
var hitGroup = hitResult.item.parent;
_startEdit(hitGroup);
}
else {
} else {
var fontSize = paper.project.currentStyle.fontSize;
if (!edit) {
......@@ -300,12 +346,9 @@ define(["paper", "jquery"], function (paper, $) {
var txtBg = new paper.PointText({
point: textPoint,
fillColor: 'white',
strokeColor: 'white',
strokeWidth: fontSize/6,
//strokeColor: 'white',
strokeWidth: fontSize / 6,
strokeJoin: 'round',
// shadowColor: 'black',
// shadowBlur: 10,
// shadowOffset: new paper.Point([5, 3]),
content: ""
});
......@@ -316,11 +359,11 @@ define(["paper", "jquery"], function (paper, $) {
var txtFg = new paper.PointText({
point: textPoint,
fillColor: c,
strokeColor: c,
//strokeColor: c,
strokeWidth: 0,
content: ""
});
txtFg.on('doubleclick', function(){
txtFg.on('doubleclick', function () {
_startEdit(this.parent);
});
......@@ -362,7 +405,7 @@ define(["paper", "jquery"], function (paper, $) {
});
attachListeners(gText);
if (!!listening) {
gText.children[1].on('doubleclick', function(){
gText.children[1].on('doubleclick', function () {
_startEdit(this.parent);
});
}
......@@ -373,17 +416,17 @@ define(["paper", "jquery"], function (paper, $) {
function exportJSON(param) {
var wasSelected = this.selected;
this.selected = false;
var json = this.exportJSON({asString:false});
var json = this.exportJSON({asString: false});
$.each(json[1].children, function(i, c) {
delete(c[1].leading);
$.each(json[1].children, function (i, c) {
delete (c[1].leading);
});
// console.log(json);
json = (param && param.asString === false) ? json : JSON.stringify(json);
if (wasSelected) { this.selected = wasSelected; }
if (wasSelected) {
this.selected = wasSelected;
}
return json;
}
......@@ -401,6 +444,8 @@ define(["paper", "jquery"], function (paper, $) {
setRo: _setRo,
exportJSON: exportJSON,
importJSON: importJSON,
registerEvent: function(eventName, evt) { _events[eventName] = evt; }
registerEvent: function (eventName, evt) {
_events[eventName] = evt;
}
};
});
\ No newline at end of file
......@@ -342,12 +342,9 @@ define(["paper", "jquery","adim/category"], function (paper, $, Category) {
var txtBg = new paper.PointText({
point: textPoint,
fillColor: 'white',
strokeColor: 'white',
//strokeColor: 'white',
strokeWidth: fontSize/6,
strokeJoin: 'round',
// shadowColor: 'black',
// shadowBlur: 10,
// shadowOffset: new paper.Point([5, 3]),
content: ""
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment