/** * Zoom in/out based on center of viewing rectangle! * * @param zov : zoom value (value based on current value.) */ boolean zoom(float zov) { zov = _zov * zov; if (zov < WConstants.ZOOM_MIN_VALUE) zov = WConstants.ZOOM_MIN_VALUE; if (zov > WConstants.ZOOM_MAX_VALUE) zov = WConstants.ZOOM_MAX_VALUE; Rect r = _rectA; r.set(_rar); WUtil.expand(r, zov); if (r.width() > _sheet.width()) return false; else { _zov = zov; _ar.set(r); WUtil.adjust(_ar, _sheet.boundary()); float rw = _ar.width() / 2.0f; float rh = _ar.height() / 2.0f; _rar.l = WUtil.roundOff(_ar.l + rw - rw / _zov); _rar.t = WUtil.roundOff(_ar.t + rh - rh / _zov); _rar.r = _rar.l + _sw; _rar.b = _rar.t + _sh; moveActiveRegionTo(this, _ar.l, _ar.t); return true; } }
void shift(int vx, int vy) { // TODO : sliding effect is not implemented yet int absx = (vx > 0) ? vx : -vx; int absy = (vy > 0) ? vy : -vy; int ox = _sw / 4; int oy = _sh / 4; int dx, dy; if (0 == vx) { dx = 0; dy = (vy > 0) ? oy : -oy; } else if (0 == vy) { dy = 0; dx = (vx > 0) ? ox : -ox; } else { if (absy * ox > oy * absx) { dx = absx * oy / absy; dx = (vx > 0) ? dx : -dx; dy = (vy > 0) ? oy : -oy; } else { dy = absy * ox / absx; dy = (vy > 0) ? dy : -dy; dx = (vx > 0) ? ox : -ox; } } Rect tmpR = _rectA; tmpR.set(_ar); tmpR.offset(_c2s(dx), _c2s(dy)); WUtil.adjust(tmpR, _sheet.boundary()); moveActiveRegionTo(this, tmpR.l, tmpR.t); }
void moveActiveRegion(Object trigger_owner, int dx, int dy) { Rect tmpR = _rectA; tmpR.set(_ar); tmpR.offset(_c2s(dx), _c2s(dy)); WUtil.adjust(tmpR, _sheet.boundary()); moveActiveRegionTo(this, tmpR.l, tmpR.t); }
void moveActiveRegionTo(Object trigger_owner, int left, int top) { int dx = left - _ar.l; int dy = top - _ar.t; // we just re-calculate all!!! Rect tmpR = _rectA; // till now, we only consider "l, t" value. D2d.fill(_pixels, _sw, _sh, _bgcolor, 0, 0, _sw, _sh); // erase all. tmpR.set(left, top, _ar.r + dx, _ar.b + dy); _compensateThickness(tmpR, WConstants.LIMIT_THICK); _sheet.draw(_pixels, _sw, _sh, left, top, tmpR.l, tmpR.t, tmpR.r, tmpR.b, _zf()); _ar.offset(dx, dy); _rar.offset(dx, dy); _platboard.invalidatePlatBoard(); if (null != _activie_region_moved_listener) _activie_region_moved_listener.onMoved( trigger_owner, _ar.l / (float) _sheet.width(), _ar.t / (float) _sheet.height(), _ar.r / (float) _sheet.width(), _ar.b / (float) _sheet.height()); }
void drawSheet(int left, int top, int right, int bottom) { getInvalidateArea(_tmpR, left, top, right, bottom, WConstants.LIMIT_THICK); _sheet.draw( _pixels, _sw, _sh, _ar.l, _ar.t, _ar.l + _c2s(_tmpR.l), _ar.t + _c2s(_tmpR.t), _ar.l + _c2s(_tmpR.r), _ar.t + _c2s(_tmpR.b), _zf()); }
void updateCurve(LinkedList<G2d.Point> points, byte thick, int color) { if (!points.isEmpty()) { // Change from board coordinate to sheet coordinate ListIterator<G2d.Point> iter = points.listIterator(); G2d.Point pt; while (iter.hasNext()) { pt = iter.next(); pt.x = _c2s(pt.x) + _ar.l; pt.y = _c2s(pt.y) + _ar.t; } // TODO!!!! --- _sheet.addCurve(points, thick, color); } }
int sheetWidth() { return _sheet.width(); }
void cutoutEnd() { _sheet.actionEnd(); }
void cutoutSheet(int left, int top, int right, int bottom) { _sheet.cutout(_ar.l + _c2s(left), _ar.t + _c2s(top), _ar.l + _c2s(right), _ar.t + _c2s(bottom)); }
int sheetHeight() { return _sheet.height(); }
void saveSheet(String fpath) throws IOException { _sheet.save(fpath); }
void loadSheet(String fpath) throws IOException { if (null != _sheet) _sheet.destroy(); _sheet = WSheet.createWSheet(); _sheet.load(fpath); }
void undo() { _sheet.undo(); }
void redo() { _sheet.redo(); }
void destroy() { _sheet.destroy(); }
void zmvEnd() { _sheet.actionEnd(); }
// Draw active rectangle fully. void drawSheet() { _sheet.draw(_pixels, _sw, _sh, _ar.l, _ar.t, _ar.l, _ar.t, _ar.r, _ar.b, _zf()); }
void cutoutStart() { _sheet.actionStart(WSheet.ACT_CUTOUT); }
void curveEnd() { _sheet.actionEnd(); }
// action interfaces - Just Wrapper!!! void curveStart() { _sheet.actionStart(WSheet.ACT_CURVE); }
void createNew(int divW, int divH, int colN, int rowN) { if (null != _sheet) _sheet.destroy(); _sheet = WSheet.createWSheet(); _sheet.init(divW, divH, colN, rowN); }
void zmvStart() { _sheet.actionStart(WSheet.ACT_ZMV); }
private Rect _compensateThickness(Rect r, byte thick) { WUtil.expand(r, thick, thick); WUtil.adjust(r, _sheet.boundary()); return r; }