Skip to content

Commit

Permalink
clear
Browse files Browse the repository at this point in the history
  • Loading branch information
tohashi committed Dec 20, 2015
1 parent 520478d commit 796d735
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 64 deletions.
72 changes: 47 additions & 25 deletions dist/bundle.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/js/actions/textAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export default {
actionType: ActionTypes.IMPORT,
json
});
},

clear() {
Dispatcher.dispatch({
actionType: ActionTypes.CLEAR
});
}
};

74 changes: 38 additions & 36 deletions src/js/components/docImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,49 @@ export default class DocImage extends React.Component {
ctx.clearRect(0, 0, this.props.imageWidth, this.props.imageHeight);
}

scanEdgePoint(data, baseIdx, intervalX, intervalY) {
let scanning = true;
let edgeIdx = baseIdx;
while (scanning) {
if (data[edgeIdx + intervalX + intervalY] > 0) {
edgeIdx += intervalX + intervalY;
} else if (data[edgeIdx + intervalX] > 0) {
edgeIdx += intervalX;
} else if (data[edgeIdx + intervalY] > 0) {
edgeIdx += intervalY;
} else {
scanning = false;
}
}
return edgeIdx;
}

handleClickCanvas(e) {
const rect = {};
const zoom = this.props.previewWidth / this.props.imageWidth;
const x = Math.round((e.pageX - 10) / zoom);
const y = Math.round((e.pageY - 10) / zoom);
const baseDataIdx = (x + y * this.props.imageWidth) * 4;
const data = this.state.imageData.data;
let scanning = true;

let dataIdx = this.scanEdgePoint(data, baseDataIdx, -4, this.state.imageData.width * -4);
rect.x = (dataIdx / 4) % this.state.imageData.width;
rect.y = Math.floor((dataIdx / 4) / this.state.imageData.width);
handleClickCanvas(e) {
const rect = {};
const zoom = this.props.previewWidth / this.props.imageWidth;
const x = Math.round((e.pageX - 10) / zoom);
const y = Math.round((e.pageY - 10) / zoom);
const baseDataIdx = (x + y * this.props.imageWidth) * 4;
const data = this.state.imageData.data;
let scanning = true;

let dataIdx = this.scanEdgePoint(data, baseDataIdx, -4, this.state.imageData.width * -4);
rect.x = (dataIdx / 4) % this.state.imageData.width;
rect.y = Math.floor((dataIdx / 4) / this.state.imageData.width);

dataIdx = this.scanEdgePoint(data, baseDataIdx, 4, this.state.imageData.width * 4);
rect.w = (dataIdx / 4) % this.state.imageData.width - rect.x;
rect.h = Math.floor((dataIdx / 4) / this.state.imageData.width) - rect.y;
dataIdx = this.scanEdgePoint(data, baseDataIdx, 4, this.state.imageData.width * 4);
rect.w = (dataIdx / 4) % this.state.imageData.width - rect.x;
rect.h = Math.floor((dataIdx / 4) / this.state.imageData.width) - rect.y;

this.props.handleUpdateTextParams({
x: Math.round(rect.x * zoom),
y: Math.round(rect.y * zoom),
width: Math.round(rect.w * zoom),
height: Math.round(rect.h * zoom)
}, this.props.handleUpdateText);
this.props.handleUpdateTextParams({
x: Math.round(rect.x * zoom),
y: Math.round(rect.y * zoom),
width: Math.round(rect.w * zoom),
height: Math.round(rect.h * zoom)
}, this.props.handleUpdateText);
}

scanEdgePoint(data, baseIdx, intervalX, intervalY) {
let scanning = true;
let edgeIdx = baseIdx;
while (scanning) {
if (data[edgeIdx + intervalX + intervalY] > 0) {
edgeIdx += intervalX + intervalY;
} else if (data[edgeIdx + intervalX] > 0) {
edgeIdx += intervalX;
} else if (data[edgeIdx + intervalY] > 0) {
edgeIdx += intervalY;
} else {
scanning = false;
}
}
return edgeIdx;
}

isCurrentText(key) {
return key === this.props.text.key;
Expand Down
7 changes: 5 additions & 2 deletions src/js/components/settingPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export default class SettingPanel extends React.Component {
this.props.handleInputChange(params);
}

handleSelect() {
handleClear() {
TextAction.clear();
}

render() {
Expand Down Expand Up @@ -91,7 +92,7 @@ export default class SettingPanel extends React.Component {
})()}
</div>

<Tabs onSlect={this.handleSelect.bind(this)} selectedIndex={0}>
<Tabs selectedIndex={0}>
<TabList>
<Tab>parameters</Tab>
<Tab>publishing</Tab>
Expand All @@ -115,6 +116,7 @@ export default class SettingPanel extends React.Component {
);
})()}
{textList}
<button onClick={this.handleClear.bind(this)}>clear</button>
</TabPanel>
<TabPanel className="tab-panel">
<Publishing
Expand All @@ -125,6 +127,7 @@ export default class SettingPanel extends React.Component {
previewHeight={this.props.previewHeight}
/>
{textList}
<button onClick={this.handleClear.bind(this)}>clear</button>
</TabPanel>
</Tabs>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/js/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const ActionTypes = keyMirror({
COPY_TEXT: null,
UNDO: null,
REDO: null,
IMPORT: null
IMPORT: null,
CLEAR: null
});

export { ActionTypes };
Expand Down
4 changes: 4 additions & 0 deletions src/js/stores/textStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ instance.dispatchToken = Dispatcher.register((action) => {
texts = data;
instance.emitChange();
break;
case ActionTypes.CLEAR:
texts = [];
instance.emitChange();
break;
}

if (TextStore.redoable) {
Expand Down

0 comments on commit 796d735

Please sign in to comment.