shun-iwasawa a5c4f3
#pragma once
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
#ifndef GEOMETRICTOOL_H
shun-iwasawa a5c4f3
#define GEOMETRICTOOL_H
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
#include "tgeometry.h"
shun-iwasawa a5c4f3
#include "tproperty.h"
shun-iwasawa a5c4f3
#include "tools/tool.h"
shun-iwasawa a5c4f3
#include "tools/cursors.h"
shun-iwasawa a5c4f3
#include "mypainttoonzbrush.h"
shun-iwasawa a5c4f3
#include "trasterimage.h"
shun-iwasawa a5c4f3
#include <qobject></qobject>
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
// For Qt translation support
shun-iwasawa a5c4f3
#include <qcoreapplication></qcoreapplication>
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
class Primitive;
shun-iwasawa a5c4f3
class FullColorGeometricToolNotifier;
shun-iwasawa a5c4f3
class TTileSaverFullColor;
shun-iwasawa a5c4f3
class TTileSaverCM32;
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
//-----------------------------------------------------------------------------
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
class PrimitiveParam {
shun-iwasawa a5c4f3
  Q_DECLARE_TR_FUNCTIONS(PrimitiveParam)
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
public:
shun-iwasawa a5c4f3
  TDoubleProperty m_toolSize;
shun-iwasawa a5c4f3
  TIntProperty m_rasterToolSize;
shun-iwasawa a5c4f3
  TDoubleProperty m_opacity;
shun-iwasawa a5c4f3
  TDoubleProperty m_hardness;
shun-iwasawa a5c4f3
  TEnumProperty m_type;
shun-iwasawa a5c4f3
  TIntProperty m_edgeCount;
shun-iwasawa a5c4f3
  TBoolProperty m_rotate;
shun-iwasawa a5c4f3
  TBoolProperty m_autogroup;
shun-iwasawa a5c4f3
  TBoolProperty m_autofill;
shun-iwasawa a5c4f3
  TBoolProperty m_smooth;
shun-iwasawa a5c4f3
  TBoolProperty m_selective;
shun-iwasawa a5c4f3
  TBoolProperty m_pencil;
shun-iwasawa a5c4f3
  TEnumProperty m_capStyle;
shun-iwasawa a5c4f3
  TEnumProperty m_joinStyle;
shun-iwasawa a5c4f3
  TIntProperty m_miterJoinLimit;
shun-iwasawa a5c4f3
  TBoolProperty m_snap;
shun-iwasawa a5c4f3
  TEnumProperty m_snapSensitivity;
shun-iwasawa a5c4f3
  // for mypaint styles
shun-iwasawa a5c4f3
  TDoubleProperty m_modifierSize;
shun-iwasawa a5c4f3
  TDoubleProperty m_modifierOpacity;
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
  TPropertyGroup m_prop[2];
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
  int m_targetType;
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
  // for snapping
shun-iwasawa a5c4f3
  int m_strokeIndex1;
shun-iwasawa a5c4f3
  double m_w1, m_pixelSize, m_currThickness, m_minDistance2;
shun-iwasawa a5c4f3
  bool m_foundSnap = false;
shun-iwasawa a5c4f3
  TPointD m_snapPoint;
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
  PrimitiveParam(int targetType);
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
  void updateTranslation();
shun-iwasawa a5c4f3
};
shun-iwasawa a5c4f3
//=============================================================================
shun-iwasawa a5c4f3
// Geometric Tool
shun-iwasawa a5c4f3
//-----------------------------------------------------------------------------
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
class GeometricTool final : public TTool, public RasterController {
shun-iwasawa a5c4f3
protected:
shun-iwasawa a5c4f3
  Primitive* m_primitive;
shun-iwasawa a5c4f3
  std::map<std::wstring, primitive*=""> m_primitiveTable;</std::wstring,>
shun-iwasawa a5c4f3
  PrimitiveParam m_param;
shun-iwasawa a5c4f3
  std::wstring m_typeCode;
shun-iwasawa a5c4f3
  bool m_active;
shun-iwasawa a5c4f3
  bool m_firstTime;
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
  // for both rotation and move
shun-iwasawa a5c4f3
  bool m_isRotatingOrMoving;
shun-iwasawa a5c4f3
  bool m_wasCtrlPressed;
shun-iwasawa a5c4f3
  TStroke* m_rotatedStroke;
shun-iwasawa a5c4f3
  TPointD m_originalCursorPos;
shun-iwasawa a5c4f3
  TPointD m_currentCursorPos;
shun-iwasawa a5c4f3
  TPixel32 m_color;
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
  // for rotation
shun-iwasawa a5c4f3
  double m_lastRotateAngle;
shun-iwasawa a5c4f3
  TPointD m_rotateCenter;
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
  // for move
shun-iwasawa a5c4f3
  TPointD m_lastMoveStrokePos;
shun-iwasawa a5c4f3
  TRect m_strokeRect;
shun-iwasawa a5c4f3
  TRect m_lastRect;
shun-iwasawa a5c4f3
  TRasterP m_workRaster;
shun-iwasawa a5c4f3
  TTileSaverFullColor* m_tileSaver;
shun-iwasawa a5c4f3
  TTileSaverCM32* m_tileSaverCM;
shun-iwasawa a5c4f3
  FullColorGeometricToolNotifier* m_notifier;
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
public:
shun-iwasawa a5c4f3
  GeometricTool(int targetType);
shun-iwasawa a5c4f3
  ~GeometricTool();
shun-iwasawa a5c4f3
  ToolType getToolType() const override { return TTool::LevelWriteTool; }
shun-iwasawa a5c4f3
  void updateTranslation() override;
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
  void addPrimitive(Primitive* p);
shun-iwasawa a5c4f3
  void changeType(std::wstring name);
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
  bool preLeftButtonDown() override;
shun-iwasawa a5c4f3
  void leftButtonDown(const TPointD& p, const TMouseEvent& e) override;
shun-iwasawa a5c4f3
  void leftButtonDrag(const TPointD& p, const TMouseEvent& e) override;
shun-iwasawa a5c4f3
  void leftButtonUp(const TPointD& p, const TMouseEvent& e) override;
shun-iwasawa a5c4f3
  void leftButtonDoubleClick(const TPointD& p, const TMouseEvent& e) override;
shun-iwasawa a5c4f3
  bool keyDown(QKeyEvent* event) override;
shun-iwasawa a5c4f3
  void onImageChanged() override;
shun-iwasawa a5c4f3
  void onColorStyleChanged();
shun-iwasawa a5c4f3
  void rightButtonDown(const TPointD& p, const TMouseEvent& e) override;
shun-iwasawa a5c4f3
  void mouseMove(const TPointD& p, const TMouseEvent& e) override;
shun-iwasawa a5c4f3
  void onActivate() override;
shun-iwasawa a5c4f3
  void onDeactivate() override;
shun-iwasawa a5c4f3
  void onEnter() override;
shun-iwasawa a5c4f3
  void draw() override;
shun-iwasawa a5c4f3
  int getCursorId() const override;
shun-iwasawa a5c4f3
  int getColorClass() const { return 1; }
shun-iwasawa a5c4f3
  TPropertyGroup* getProperties(int idx) override;
shun-iwasawa a5c4f3
  bool onPropertyChanged(std::string propertyName) override;
shun-iwasawa a5c4f3
  void addStroke();
shun-iwasawa a5c4f3
  void addRasterMyPaintStroke(const TToonzImageP& ti, TStroke* stroke,
shun-iwasawa a5c4f3
                              TXshSimpleLevel* sl, const TFrameId& id);
shun-iwasawa a5c4f3
  void addFullColorMyPaintStroke(const TRasterImageP& ri, TStroke* stroke,
shun-iwasawa a5c4f3
                                 TXshSimpleLevel* sl, const TFrameId& id);
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
  void updateWorkRaster(const TRect& rect);
shun-iwasawa a5c4f3
  bool askRead(const TRect& rect) override;
shun-iwasawa a5c4f3
  bool askWrite(const TRect& rect) override;
shun-iwasawa a5c4f3
};
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
//------------------------------------------------------------
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
class FullColorGeometricToolNotifier final : public QObject {
shun-iwasawa a5c4f3
  Q_OBJECT
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
  GeometricTool* m_tool;
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
public:
shun-iwasawa a5c4f3
  FullColorGeometricToolNotifier(GeometricTool* tool);
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
protected slots:
shun-iwasawa a5c4f3
  void onColorStyleChanged() { m_tool->onColorStyleChanged(); }
shun-iwasawa a5c4f3
};
shun-iwasawa a5c4f3
shun-iwasawa a5c4f3
#endif