-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crop preset review #84
Changes from 1 commit
6ea90ba
1cc54e1
642f5aa
76c3406
a556ef6
d8ec604
67935b3
8478bf7
8da6601
4fee353
7e14b16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,6 @@ class Cropper extends Component { | |
* Start cropping | ||
*/ | ||
start() { | ||
console.log('START - CROPPER'); | ||
if (this._cropzone) { | ||
return; | ||
} | ||
|
@@ -278,55 +277,61 @@ class Cropper extends Component { | |
}; | ||
} | ||
|
||
/* | ||
/** | ||
* Set a cropzone square | ||
* @param {number} factor - preset ratio | ||
* @returns {{left: number, top: number, width: number, height: number}} | ||
*/ | ||
setCropzoneRect(factor) { | ||
|
||
console.log('FACTOR - ', factor); | ||
|
||
_getPresetCropSizePosition(factor) { | ||
const canvas = this.getCanvas(); | ||
canvas.deactivateAll(); | ||
canvas.selection = false; | ||
|
||
const cropzone = this._cropzone; | ||
cropzone.remove(); | ||
|
||
if (!factor) { | ||
return; | ||
} | ||
|
||
const originalWidth = canvas.getWidth(); | ||
const originalHeight = canvas.getHeight(); | ||
|
||
const standardSize = (originalWidth >= originalHeight) ? originalWidth : originalHeight; | ||
const getScale = (value, orignalValue) => (value > orignalValue) ? orignalValue / value : 1; | ||
jungeun-cho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let width = (standardSize * factor); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 괄호 안해도될듯요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 반영하겠습니다. |
||
let height = standardSize; | ||
let scale = 1; | ||
|
||
if (width > originalWidth) { | ||
scale = (originalWidth / width); | ||
width = (width * scale); | ||
height = (height * scale); | ||
} | ||
const scaleWidth = getScale(width, originalWidth); | ||
[width, height] = [width, height].map(sizeValue => (sizeValue * scaleWidth)); | ||
|
||
if (height > originalHeight) { | ||
scale = (originalHeight / height); | ||
width = (width * scale); | ||
height = (height * scale); | ||
} | ||
const scaleHeight = getScale(height, originalHeight); | ||
[width, height] = [width, height].map(sizeValue => (sizeValue * scaleHeight)); | ||
|
||
return { | ||
top: (originalHeight - height) / 2, | ||
left: (originalWidth - width) / 2, | ||
width, | ||
height | ||
}; | ||
} | ||
|
||
/** | ||
* Set a cropzone square | ||
* @param {number} factor - preset ratio | ||
*/ | ||
setCropzoneRect(factor) { | ||
const canvas = this.getCanvas(); | ||
const cropzone = this._cropzone; | ||
|
||
cropzone.set({ | ||
top: 0, | ||
left: 0, | ||
height, | ||
width | ||
canvas.deactivateAll(); | ||
canvas.selection = false; | ||
cropzone.remove(); | ||
|
||
cropzone.set(factor ? this._getPresetCropSizePosition(factor) : { | ||
top: -10, | ||
left: -10, | ||
height: 1, | ||
width: 1 | ||
}); | ||
|
||
canvas.add(cropzone); | ||
canvas.centerObject(cropzone); | ||
canvas.setActiveObject(cropzone); | ||
canvas.selection = true; | ||
|
||
if (factor) { | ||
canvas.setActiveObject(cropzone); | ||
} | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,24 +16,22 @@ class Crop extends Submenu { | |
}); | ||
|
||
this.status = 'active'; | ||
|
||
this._els = { | ||
apply: this.selector('#tie-crop-button .apply'), | ||
cancel: this.selector('#tie-crop-button .cancel'), | ||
'preset-none': this.selector('#tie-crop-button .preset-none'), | ||
'preset-square': this.selector('#tie-crop-button .preset-square'), | ||
'preset-3-2': this.selector('#tie-crop-button .preset-3-2'), | ||
'preset-4-3': this.selector('#tie-crop-button .preset-4-3'), | ||
'preset-5-4': this.selector('#tie-crop-button .preset-5-4'), | ||
'preset-7-5': this.selector('#tie-crop-button .preset-7-5'), | ||
'preset-16-9': this.selector('#tie-crop-button .preset-16-9') | ||
preset: this.selector('#tie-crop-preset-button') | ||
}; | ||
|
||
this.defaultPresetButton = this._els.preset.querySelector('.preset-none'); | ||
} | ||
|
||
/** | ||
* Add event for crop | ||
* @param {Object} actions - actions for crop | ||
* @param {Function} actions.crop - crop action | ||
* @param {Function} actions.cancel - cancel action | ||
* @param {Function} actions.preset - cancel action | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 디스크립션이 잘못된 것 같습니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 |
||
*/ | ||
addEvent(actions) { | ||
this.actions = actions; | ||
|
@@ -47,39 +45,14 @@ class Crop extends Submenu { | |
this._els.apply.classList.remove('active'); | ||
}); | ||
|
||
this._els['preset-none'].addEventListener('click', () => { | ||
this.setPresetButtonActive('preset-none'); | ||
this.actions['preset-none'](); | ||
}); | ||
|
||
this._els['preset-square'].addEventListener('click', () => { | ||
this.setPresetButtonActive('preset-square'); | ||
this.actions['preset-square'](); | ||
}); | ||
|
||
this._els['preset-3-2'].addEventListener('click', () => { | ||
this.setPresetButtonActive('preset-3-2'); | ||
this.actions['preset-3-2'](); | ||
}); | ||
|
||
this._els['preset-4-3'].addEventListener('click', () => { | ||
this.setPresetButtonActive('preset-4-3'); | ||
this.actions['preset-4-3'](); | ||
}); | ||
|
||
this._els['preset-5-4'].addEventListener('click', () => { | ||
this.setPresetButtonActive('preset-5-4'); | ||
this.actions['preset-5-4'](); | ||
}); | ||
|
||
this._els['preset-7-5'].addEventListener('click', () => { | ||
this.setPresetButtonActive('preset-7-5'); | ||
this.actions['preset-7-5'](); | ||
}); | ||
this._els.preset.addEventListener('click', event => { | ||
const button = event.target.closest('.tui-image-editor-button.preset'); | ||
if (button) { | ||
const [presetType] = button.className.match(/preset-[^\s]+/); | ||
|
||
this._els['preset-16-9'].addEventListener('click', () => { | ||
this.setPresetButtonActive('preset-16-9'); | ||
this.actions['preset-16-9'](); | ||
this._setPresetButtonActive(button); | ||
this.actions.preset(presetType); | ||
} | ||
}); | ||
} | ||
|
||
|
@@ -95,7 +68,7 @@ class Crop extends Submenu { | |
*/ | ||
changeStandbyMode() { | ||
this.actions.stopDrawingMode(); | ||
this.setPresetButtonActive(); | ||
this._setPresetButtonActive(); | ||
} | ||
|
||
/** | ||
|
@@ -112,18 +85,17 @@ class Crop extends Submenu { | |
|
||
/** | ||
* Set preset button to active status | ||
* @param {String} preset - preset name | ||
* @param {HTMLElement} button - event target element | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 |
||
*/ | ||
setPresetButtonActive(preset) { | ||
const excludeList = [preset, 'apply', 'cancel']; | ||
Object.keys(this._els).forEach(key => { | ||
if (!excludeList.includes(key)) { | ||
this._els[key].classList.remove('active'); | ||
} | ||
_setPresetButtonActive(button = this.defaultPresetButton) { | ||
const presetButtons = Array.from(this._els.preset.querySelectorAll('.preset')); | ||
|
||
presetButtons.forEach(presetButton => { | ||
presetButton.classList.remove('active'); | ||
}); | ||
|
||
if (preset) { | ||
this._els[preset].classList.add('active'); | ||
if (button) { | ||
button.classList.add('active'); | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export default ({iconStyle: {normal, active}}) => (` | ||
<ul class="tui-image-editor-submenu-item"> | ||
<li id="tie-crop-button"> | ||
<li id="tie-crop-preset-button"> | ||
<div class="tui-image-editor-button preset preset-none active"> | ||
<div> | ||
<svg class="svg_ic-submenu"> | ||
|
@@ -81,6 +81,9 @@ export default ({iconStyle: {normal, active}}) => (` | |
</li> | ||
<li class="tui-image-editor-partition tui-image-editor-newline"> | ||
</li> | ||
<li class="tui-image-editor-partition only-left-right"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이건 용도가 뭔가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메뉴 바 정렬이 left나 right로 되어 있을때만 보여야 하는 라인입니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 가능하면 태그 한줄로 처리하는 방법을 찾아보겠습니다. |
||
<div></div> | ||
</li> | ||
<li id="tie-crop-button" class="action"> | ||
<div class="tui-image-editor-button apply"> | ||
<svg class="svg_ic-menu"> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
factor
->scale
파라미터명 변경[factor]
변경There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네 반영했습니다.