/*
    SPDX-FileCopyrightText: 2002 Jeff Roush <jeff@mousetool.com>
    SPDX-FileCopyrightText: 2003 Olaf Schmidt <ojschmidt@kde.org>
    SPDX-License-Identifier: GPL-2.0-or-later
*/

#ifndef MTSTROKE_H
#define MTSTROKE_H
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <map>
#include <string>
#include <vector>

/**Implements stroke recording for MouseTool.
 *@author Jeff Roush
 */

class Pt
{
public:
    int x, y;
    Pt()
    {
    }
    Pt(const int xx, const int yy)
    {
        x = xx;
        y = yy;
    }
    bool sameAs(Pt pt)
    {
        return (x == pt.x && y == pt.y);
    }
    bool nearTo(Pt pt, int delta)
    {
        return ((std::abs(x - pt.x) < delta) && (std::abs(y - pt.y) < delta));
    }

    void dump();
};

class MTStroke
{
    std::vector<Pt> points;
    //  std::vector<int> sequence;
    std::string sequence;
    std::map<std::string, int> sequenceMap;

    int stroke_minx;
    int stroke_maxx;
    int stroke_miny;
    int stroke_maxy;

    void makeDefaultSequenceMap();

public:
    // stroke types
    static const int bumped_mouse;
    static const int normal;
    static const int RightClick;
    static const int DoubleClick;
    static const int circle;
    static const int DontClick;
    static const int LowerLeftStroke;
    static const int UpperRightStroke;
    static const int LowerRightStroke;
    static const int UpperLeftStroke;

    // Static ints
    static int delta_xy;
    static Pt LowerLeft;
    static Pt LowerRight;
    static Pt UpperLeft;
    static Pt UpperRight;

    // min points before it can be considered a "stroke"
    static const int min_num_points;

    static void setLowerLeft(int x, int y)
    {
        LowerLeft.x = x;
        LowerLeft.y = y;
    }
    static void setLowerRight(int x, int y)
    {
        LowerRight.x = x;
        LowerRight.y = y;
    }
    static void setUpperLeft(int x, int y)
    {
        UpperLeft.x = x;
        UpperLeft.y = y;
    }
    static void setUpperRight(int x, int y)
    {
        UpperRight.x = x;
        UpperRight.y = y;
    }

    void dump();
    void scale();
    void addPt(int, int);
    int max(int, int);
    bool pointsContain(Pt pt);
    int getStrokeType();
    void getExtent();
    //  void getSequence();
    bool readSequence();
    bool writeSequence();
    void readToEndOfLine(std::ifstream &infile);

    void reset()
    {
        points.clear();
        sequence = "";
    }

    MTStroke();
    ~MTStroke();
};

#endif
