summaryrefslogtreecommitdiffstats
path: root/kmousetool/kmousetool/mtstroke.h
blob: 171204cb00a7713506db80bccaa9422145aaef21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/***************************************************************************
                          mtstroke.h  -  description
                             -------------------
    begin                : Fri Oct 11 2002
    copyright            : (C) 2002 by Jeff Roush
    email                : jeff@mousetool.com
    copyright            : (C) 2003 by Olaf Schmidt
    email                : ojschmidt@kde.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

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

/**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