|
@@ -24,6 +24,10 @@ int main( int argc, char** argv ) {
|
24
|
24
|
timespec start, time;
|
25
|
25
|
int cx = 0;
|
26
|
26
|
int cy = 0;
|
|
27
|
+ int cxoffset = 0;
|
|
28
|
+ int cyoffset = 0;
|
|
29
|
+ int woffset = 0;
|
|
30
|
+ int hoffset = 0;
|
27
|
31
|
|
28
|
32
|
// First we set up the x interface and grab the mouse,
|
29
|
33
|
// if we fail for either we exit immediately.
|
|
@@ -93,7 +97,7 @@ int main( int argc, char** argv ) {
|
93
|
97
|
// If xengine has found a window we're hovering over (or if it changed)
|
94
|
98
|
// create a rectangle around it so the user knows he/she can click on it.
|
95
|
99
|
// --but only if the user wants us to
|
96
|
|
- if ( window != xengine->m_hoverXWindow && options->m_window ) {
|
|
100
|
+ if ( window != xengine->m_hoverXWindow && tolerance > 0 ) {
|
97
|
101
|
// Make sure to delete the old selection rectangle.
|
98
|
102
|
if ( windowselection ) {
|
99
|
103
|
xengine->removeRect( windowselection ); // removeRect also dealloc's the rectangle for us.
|
|
@@ -101,8 +105,8 @@ int main( int argc, char** argv ) {
|
101
|
105
|
slop::WindowRectangle t = xengine->m_hoverWindow;
|
102
|
106
|
windowselection = new slop::Rectangle( t.m_x - t.m_border,
|
103
|
107
|
t.m_y - t.m_border,
|
104
|
|
- t.m_width + t.m_border,
|
105
|
|
- t.m_height + t.m_border,
|
|
108
|
+ t.m_width + t.m_border * 2,
|
|
109
|
+ t.m_height + t.m_border * 2,
|
106
|
110
|
borderSize, padding,
|
107
|
111
|
r, g, b );
|
108
|
112
|
xengine->addRect( windowselection );
|
|
@@ -133,31 +137,48 @@ int main( int argc, char** argv ) {
|
133
|
137
|
break;
|
134
|
138
|
}
|
135
|
139
|
// Check to make sure the user actually wants to drag for a selection before creating a rectangle.
|
136
|
|
- int w = xengine->m_mousex - cx + 1;
|
137
|
|
- int h = xengine->m_mousey - cy + 1;
|
138
|
|
- if ( ( std::abs( w ) > tolerance || std::abs( h ) > tolerance ) && !selection ) {
|
|
140
|
+ int w = xengine->m_mousex - cx;
|
|
141
|
+ int h = xengine->m_mousey - cy;
|
|
142
|
+ if ( ( std::abs( w ) >= tolerance || std::abs( h ) >= tolerance ) && !selection ) {
|
139
|
143
|
selection = new slop::Rectangle( cx, cy, 0, 0, borderSize, padding, r, g, b );
|
140
|
144
|
xengine->addRect( selection );
|
141
|
|
- } else if ( std::abs( w ) <= tolerance && std::abs( h ) <= tolerance ) {
|
|
145
|
+ } else if ( !selection ) {
|
142
|
146
|
continue;
|
143
|
147
|
}
|
144
|
|
- // Set the selection rectangle's dimensions to mouse movement.
|
145
|
|
- // We use the function setDim since rectangles can't have negative widths,
|
146
|
|
- // and because the rectangles have borders and padding to worry about.
|
147
|
|
- selection->setDim( w, h );
|
148
|
148
|
// We also detect which way the user is pulling and set the mouse icon accordingly.
|
|
149
|
+ // and offset the rectangle to be accurate, this is because the mouse actually selects a pixel up and to the left.
|
149
|
150
|
bool x = selection->m_flippedx;
|
150
|
151
|
bool y = selection->m_flippedy;
|
151
|
152
|
if ( !x && !y ) {
|
|
153
|
+ cxoffset = 0;
|
|
154
|
+ cyoffset = 0;
|
|
155
|
+ woffset = 1;
|
|
156
|
+ hoffset = 1;
|
152
|
157
|
xengine->setCursor( slop::LowerRightCorner );
|
153
|
158
|
} else if ( x && !y ) {
|
|
159
|
+ cxoffset = 1;
|
|
160
|
+ cyoffset = 0;
|
|
161
|
+ woffset = -1;
|
|
162
|
+ hoffset = 1;
|
154
|
163
|
xengine->setCursor( slop::LowerLeftCorner );
|
155
|
164
|
} else if ( !x && y ) {
|
|
165
|
+ cxoffset = 0;
|
|
166
|
+ cyoffset = 1;
|
|
167
|
+ woffset = 1;
|
|
168
|
+ hoffset = -1;
|
156
|
169
|
xengine->setCursor( slop::UpperRightCorner );
|
157
|
170
|
} else {
|
|
171
|
+ cxoffset = 1;
|
|
172
|
+ cyoffset = 1;
|
|
173
|
+ woffset = -1;
|
|
174
|
+ hoffset = -1;
|
158
|
175
|
xengine->setCursor( slop::UpperLeftCorner );
|
159
|
176
|
}
|
160
|
|
-
|
|
177
|
+ // Set the selection rectangle's dimensions to mouse movement.
|
|
178
|
+ // We use the function setDim since rectangles can't have negative widths,
|
|
179
|
+ // and because the rectangles have borders and padding to worry about.
|
|
180
|
+ selection->setPos( cx + cxoffset, cy + cyoffset );
|
|
181
|
+ selection->setDim( w + woffset, h + hoffset );
|
161
|
182
|
break;
|
162
|
183
|
}
|
163
|
184
|
case 3: {
|
|
@@ -174,10 +195,9 @@ int main( int argc, char** argv ) {
|
174
|
195
|
h = selection->m_height;
|
175
|
196
|
// Delete the rectangle.
|
176
|
197
|
xengine->removeRect( selection );
|
177
|
|
- // If the user simply clicked (and thus made the width and height smaller than
|
178
|
|
- // our tolerance) or if we're not hovering over a window, just print the selection
|
179
|
|
- // rectangle's stuff.
|
180
|
|
- if ( w > tolerance || h > tolerance || xengine->m_hoverXWindow == None ) {
|
|
198
|
+ // if we're not hovering over a window, or our selection is larger than our tolerance
|
|
199
|
+ // just print the selection.
|
|
200
|
+ if ( w >= tolerance || h >= tolerance || xengine->m_hoverXWindow == None ) {
|
181
|
201
|
printf( "X=%i\n", x );
|
182
|
202
|
printf( "Y=%i\n", y );
|
183
|
203
|
printf( "W=%i\n", w );
|
|
@@ -187,12 +207,12 @@ int main( int argc, char** argv ) {
|
187
|
207
|
}
|
188
|
208
|
// Otherwise lets grab the window's dimensions and use those (with padding).
|
189
|
209
|
// --but only if the user lets us, if the user doesn't just select a single pixel there.
|
190
|
|
- if ( options->m_window ) {
|
|
210
|
+ if ( tolerance > 0 ) {
|
191
|
211
|
slop::WindowRectangle t = xengine->m_hoverWindow;
|
192
|
212
|
x = t.m_x - padding - t.m_border;
|
193
|
213
|
y = t.m_y - padding - t.m_border;
|
194
|
|
- w = t.m_width + t.m_border + padding*2;
|
195
|
|
- h = t.m_height + t.m_border + padding*2;
|
|
214
|
+ w = t.m_width + t.m_border * 2 + padding*2;
|
|
215
|
+ h = t.m_height + t.m_border * 2 + padding*2;
|
196
|
216
|
} else {
|
197
|
217
|
x = cx;
|
198
|
218
|
y = cy;
|