File indexing completed on 2024-04-28 03:40:30
0001 /* 0002 SPDX-FileCopyrightText: 2002 Jeff Roush <jeff@mousetool.com> 0003 SPDX-FileCopyrightText: 2003 Olaf Schmidt <ojschmidt@kde.org> 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef MTSTROKE_H 0008 #define MTSTROKE_H 0009 #include <cmath> 0010 #include <cstdlib> 0011 #include <fstream> 0012 #include <map> 0013 #include <string> 0014 #include <vector> 0015 0016 /**Implements stroke recording for MouseTool. 0017 *@author Jeff Roush 0018 */ 0019 0020 class Pt 0021 { 0022 public: 0023 int x, y; 0024 Pt() 0025 { 0026 } 0027 Pt(const int xx, const int yy) 0028 { 0029 x = xx; 0030 y = yy; 0031 } 0032 bool sameAs(Pt pt) 0033 { 0034 return (x == pt.x && y == pt.y); 0035 } 0036 bool nearTo(Pt pt, int delta) 0037 { 0038 return ((std::abs(x - pt.x) < delta) && (std::abs(y - pt.y) < delta)); 0039 } 0040 0041 void dump(); 0042 }; 0043 0044 class MTStroke 0045 { 0046 std::vector<Pt> points; 0047 // std::vector<int> sequence; 0048 std::string sequence; 0049 std::map<std::string, int> sequenceMap; 0050 0051 int stroke_minx; 0052 int stroke_maxx; 0053 int stroke_miny; 0054 int stroke_maxy; 0055 0056 void makeDefaultSequenceMap(); 0057 0058 public: 0059 // stroke types 0060 static const int bumped_mouse; 0061 static const int normal; 0062 static const int RightClick; 0063 static const int DoubleClick; 0064 static const int circle; 0065 static const int DontClick; 0066 static const int LowerLeftStroke; 0067 static const int UpperRightStroke; 0068 static const int LowerRightStroke; 0069 static const int UpperLeftStroke; 0070 0071 // Static ints 0072 static int delta_xy; 0073 static Pt LowerLeft; 0074 static Pt LowerRight; 0075 static Pt UpperLeft; 0076 static Pt UpperRight; 0077 0078 // min points before it can be considered a "stroke" 0079 static const int min_num_points; 0080 0081 static void setLowerLeft(int x, int y) 0082 { 0083 LowerLeft.x = x; 0084 LowerLeft.y = y; 0085 } 0086 static void setLowerRight(int x, int y) 0087 { 0088 LowerRight.x = x; 0089 LowerRight.y = y; 0090 } 0091 static void setUpperLeft(int x, int y) 0092 { 0093 UpperLeft.x = x; 0094 UpperLeft.y = y; 0095 } 0096 static void setUpperRight(int x, int y) 0097 { 0098 UpperRight.x = x; 0099 UpperRight.y = y; 0100 } 0101 0102 void dump(); 0103 void scale(); 0104 void addPt(int, int); 0105 int max(int, int); 0106 bool pointsContain(Pt pt); 0107 int getStrokeType(); 0108 void getExtent(); 0109 // void getSequence(); 0110 bool readSequence(); 0111 bool writeSequence(); 0112 void readToEndOfLine(std::ifstream &infile); 0113 0114 void reset() 0115 { 0116 points.clear(); 0117 sequence = ""; 0118 } 0119 0120 MTStroke(); 0121 ~MTStroke(); 0122 }; 0123 0124 #endif